package easydo.technology.controller;

import java.sql.Connection;
import java.util.Map;

import javax.annotation.Resource;
import javax.sql.DataSource;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import easydo.technology.annotation.WebLog;
import easydo.technology.components.JdbcClient;
import easydo.technology.exception.BizException;
import easydo.technology.model.Message;

@RestController
@RequestMapping("/message")
public class MessageController {
    @Resource
    JdbcClient jdbcClient;
    @Resource
    DataSource dataSource;

    @WebLog
    @RequestMapping(value = "/getPage")
    public Object getPage(@RequestBody Map<String, Object> map) throws Exception{
        Connection connection = null;
        try {
            connection = dataSource.getConnection();
            Map<String, Object> page = jdbcClient.getJdbcPage(map, Message.class, connection);

            return new ResponseEntity<>(page, HttpStatus.OK);
        } catch (Exception e) {
            throw e;
        } finally {
            jdbcClient.finallyExecute(connection);
        }
    }
}
