package com.sunyard.ssp.modules.monitor.log.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sunyard.ssp.common.Result;
import com.sunyard.ssp.modules.monitor.log.entity.SysLog;
import com.sunyard.ssp.modules.monitor.log.service.ISysLogService;
import com.sunyard.ssp.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author fyc
 * @since 2020-03-31
 */
@Controller
@Slf4j
@Api(description = "系统日志",tags ="系统日志")
@RequestMapping("/monitor/sysLog")
@Transactional
public class SysLogController {

    @Autowired
    private ISysLogService iSysLogService;



    @RequestMapping(value = "/queryList",method = RequestMethod.GET)
    @ApiOperation(value = "获取系统日志列表")
    @ResponseBody
    public Result<IPage<SysLog>> queryList(@RequestParam Integer pageNumber,
                                          @RequestParam Integer pageSize,
                                          String keyWord,
                                          String startTime,
                                          String endTime){

        IPage<SysLog> sysLogIPage = iSysLogService.queryList(pageNumber,pageSize,keyWord,startTime,endTime);
        return new ResultUtil<IPage<SysLog>>().setData(sysLogIPage);
    }



    @RequestMapping(value = "/deleteByIds",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "批量通过id删除")
    public Result<Object> delAllByIds(@RequestParam Integer[] ids){

        for(Integer id:ids){
            iSysLogService.removeById(id);
        }
        return new ResultUtil<Object>().setSuccessMsg("批量通过id删除数据成功");
    }

    @RequestMapping(value = "/truncateTable",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "清空表")
    public Result<Object> truncateTable(){
        boolean result = iSysLogService.truncateTable();
        if(result){
            return new ResultUtil<Object>().setSuccessMsg("清空表成功");
        }
       return new ResultUtil<Object>().setErrorMsg("清空表失败");
    }
}
