ShyLogController.java 2.1 KB
package com.cnlive.shenhe.controller;

import com.alibaba.fastjson.JSON;
import com.cnlive.shenhe.bean.ErrorEnum;
import com.cnlive.shenhe.bean.ResponseBean;
import com.cnlive.shenhe.dto.ShyLogDTO;
import com.cnlive.shenhe.entity.ShyLog;
import com.cnlive.shenhe.service.ShyLogService;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author 王言钊
 * @author shkstart
 * @create 2022-05-16 11:36
 */
@Controller
@RequestMapping("/log")
public class ShyLogController {
    private static Logger logger = LoggerFactory.getLogger(ShyLogController.class);

    @Autowired
    private ShyLogService shyLogService;

    /**
     * 获取分页列表数据
     *
     * @param shyLogDTO
     * @param model
     * @return
     */
    @GetMapping("/page")
    public String getShyLog(ShyLogDTO shyLogDTO, Model model) {
        logger.info("进入查询日志方法,接受的对象为,ShyLogDTO:{}", JSON.toJSONString(shyLogDTO));
        PageInfo<ShyLog> shyLogPageInfo = shyLogService.selectByExample(shyLogDTO);
        model.addAttribute("shyLogPageInfo", shyLogPageInfo);
        return "page/log.html";
    }

    /**
     * 添加日志
     *
     * @param shyLog
     * @return
     */
    @PostMapping("/add")
    @ResponseBody
    public ResponseBean insterShyLog(ShyLog shyLog) {
        logger.info("访问了日志添加方法,接受的对象为,ShyLog:{}", JSON.toJSONString(shyLog));
        Boolean result = shyLogService.addShyLog(shyLog);
        if (result) {
            return new ResponseBean(ErrorEnum.SUCCESS.getErrorCode(), "当前日志添加成功");
        }
        return new ResponseBean(ErrorEnum.ERROR.getErrorCode(), "日志添加失败,请重试");
    }
}