package cn.estsh.i3plus.core.apiservice.controller.busi;

import cn.estsh.i3plus.core.api.iservice.busi.ISysLogTaskTimeService;
import cn.estsh.i3plus.platform.common.util.PlatformConstWords;
import cn.estsh.i3plus.pojo.base.bean.ListPager;
import cn.estsh.i3plus.pojo.base.common.Pager;
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
import cn.estsh.i3plus.pojo.platform.platbean.SysLogTaskTime;
import cn.estsh.impp.framework.base.controller.CoreBaseController;
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
import cn.estsh.impp.framework.boot.util.ResultBean;
import cn.estsh.impp.framework.boot.util.ValidatorBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description : 定时任务日志服务
 * @Reference :
 * @Author : yunhao
 * @Date : 2019-01-04
 * @Modify :
 **/
@RestController
@Api(description = "定时任务日志服务")
@RequestMapping(PlatformConstWords.BASE_URL +"/sys-log-task-time")
public class SysLogTaskTimeController extends CoreBaseController{
    public static final Logger LOGGER = LoggerFactory.getLogger(SysLogTaskTimeController.class);

    @Autowired
    private ISysLogTaskTimeService logTaskTimeService;

    @PostMapping(value = "/insert")
    @ApiOperation(value="新增定时任务日志",notes = "新增定时任务日志")
    public ResultBean insertSyslogTaskTime(SysLogTaskTime sysLogTaskTime) {
        try {
            logTaskTimeService.insertSysLogTaskTime(sysLogTaskTime);
            return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        }catch(ImppBusiException busExcep){
            return ResultBean.fail(busExcep);
        }catch(Exception e){
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @DeleteMapping(value = "/delete")
    @ApiOperation(value = "删除定时任务日志",notes = "删除定时任务日志")
    public ResultBean deleteSysLogTaskTimeById(String id) {
        try {
            // 条件校验
            ValidatorBean.checkNotNull(id,"id不能为空");

            logTaskTimeService.deleteSysLogTaskTimeById(Long.parseLong(id));
            return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        }catch(ImppBusiException busExcep){
            return ResultBean.fail(busExcep);
        }catch(Exception e){
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping(value = "/get")
    @ApiOperation(value = "根据id查询定时任务日志",notes = "根据id查询定时任务日志")
    public ResultBean getSysLogTaskTimeById(String id){
        try {
            SysLogTaskTime logTaskTime = logTaskTimeService.getSysLogTaskTimeById(Long.parseLong(id));
            if (logTaskTime != null) {
                return ResultBean.success("操作成功").setResultObject(logTaskTime).setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
            }else {
                return ResultBean.fail("日志不存在").setCode(ResourceEnumUtil.MESSAGE.EMPTY.getCode());
            }
        }catch(ImppBusiException busExcep){
            return ResultBean.fail(busExcep);
        }catch(Exception e){
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    /**
     * 定时任务日志分页复杂查询
     * @param sysLogTaskTime
     * @param pager
     * @return
     */
    @GetMapping("/query")
    @ApiOperation(value = "定时任务日志分页复杂查询",notes = "定时任务日志分页复杂查询")
    public ResultBean querySysLogSystemByPager(SysLogTaskTime sysLogTaskTime, Pager pager){
        try {
            ListPager logSystemList = logTaskTimeService.querySysLogTaskTimeByPager(sysLogTaskTime, pager);
            return ResultBean.success("操作成功").setListPager(logSystemList).setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        }catch(ImppBusiException busExcep){
            return ResultBean.fail(busExcep);
        }catch(Exception e){
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }
}
