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

import cn.estsh.i3plus.core.api.iservice.busi.ISysLogTaskTimeService;
import cn.estsh.i3plus.pojo.base.bean.ListPager;
import cn.estsh.i3plus.pojo.base.common.Pager;
import cn.estsh.i3plus.pojo.base.common.PagerHelper;
import cn.estsh.i3plus.pojo.platform.platbean.SysLogSystem;
import cn.estsh.i3plus.pojo.platform.platbean.SysLogTaskTime;
import cn.estsh.i3plus.pojo.platform.platrepositorymongo.SysLogTaskTimeRepository;
import cn.estsh.i3plus.pojo.platform.sqlpack.CoreBsonPack;
import io.swagger.annotations.ApiOperation;
import org.bson.conversions.Bson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description : 定时任务服务接口实现
 * @Reference :
 * @Author : yunhao
 * @CreateDate : 2019-01-04 15:10
 * @Modify:
 **/
@Service
public class SysLogTaskTimeService implements ISysLogTaskTimeService {
    public static final Logger LOGGER = LoggerFactory.getLogger(SysLogTaskTimeService.class);

    @Autowired
    private SysLogTaskTimeRepository sysLogTaskTimeRDao;

    @Override
    @ApiOperation(value = "添加定时任务日志",notes = "添加定时任务日志")
    public void insertSysLogTaskTime(SysLogTaskTime sysLogTaskTime) {
        sysLogTaskTimeRDao.insert(sysLogTaskTime);
    }

    @Override
    @ApiOperation(value = "删除定时任务日志",notes = "删除定时任务日志")
    public void deleteSysLogTaskTimeById(Long id) {
        sysLogTaskTimeRDao.deleteById(id);
    }

    @Override
    @ApiOperation(value = "根据id查询定时任务日志",notes = "根据id查询定时任务日志")
    public SysLogTaskTime getSysLogTaskTimeById(Long id) {
        return sysLogTaskTimeRDao.getById(id);
    }

    @Override
    @ApiOperation(value = "定时任务日志分页复杂查询",notes = "定时任务日志分页复杂查询")
    public ListPager querySysLogTaskTimeByPager(SysLogTaskTime sysLogTaskTime, Pager pager) {
        if (sysLogTaskTime == null) {
            pager = PagerHelper.getPager(pager,sysLogTaskTimeRDao.listCount());
            return new ListPager(sysLogTaskTimeRDao.listPager(pager),pager);
        } else {
            Bson bson = CoreBsonPack.packBsonByLogTaskTime(sysLogTaskTime);
            pager = PagerHelper.getPager(pager,sysLogTaskTimeRDao.findByBsonCount(bson));
            return new ListPager(sysLogTaskTimeRDao.findByBsonPager(bson,pager,sysLogTaskTime.getOrderByParam()
                    ,sysLogTaskTime.getAscOrDesc()),pager);
        }
    }
}
