package cn.superdesk.uniorder.service.scheduler.impl;

import cn.superdesk.uniorder.common.exception.utils.AssertUtils;
import cn.superdesk.uniorder.common.numerical.AnBeanUtils;
import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.dao.entity.scheduler.SysQuartzLog;
import cn.superdesk.uniorder.dao.entity.scheduler.SysQuartzLogExample;
import cn.superdesk.uniorder.dao.mapper.scheduler.SysQuartzLogMapper;
import cn.superdesk.uniorder.service.scheduler.SysQuartzLogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Description: 定时任务日志
 * @Author: linjinyu
 * @Email linjinyu@avic-s.com
 * @CreateDate: 2020-12-17 16:35:26
 * @UpdateUser: linjinyu
 * @UpdateDate: 2020-12-17 16:35:26
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Service
public class SysQuartzLogServiceImpl implements SysQuartzLogService {

    @Autowired
    private SysQuartzLogMapper sysQuartzLogMapper;


    /****************************************** extends BaseService 部分 start ******************************************/

    @Override
    public int insertSelective(SysQuartzLog entity) {
        return sysQuartzLogMapper.insertSelective(entity);
    }

    @Override
    public int updateByPrimaryKeySelective(SysQuartzLog entity) {
        return sysQuartzLogMapper.updateByPrimaryKeySelective(entity);
    }

    @Override
    public void deleteObj(Long id) {
    }

    @Override
    public SysQuartzLog findById(Long id) {
        return sysQuartzLogMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo<SysQuartzLog> findByPaging(Map<String, Object> conditions, Integer pageNun, Integer pageSize) {
        return null;
    }

    @Override
    public List<SysQuartzLog> findAll(Map<String, Object> queryMap) {
        return null;
    }

    /****************************************** extends BaseService 部分   end ******************************************/


    public void addSysQuartzLog(SysQuartzLog entity) {
        sysQuartzLogMapper.insertSelective(entity);
    }

    public void updateSysQuartzLog(SysQuartzLog entity) {
        SysQuartzLog originEntity = sysQuartzLogMapper.selectByPrimaryKey(entity.getId());
        AssertUtils.notNull(originEntity);
        AnBeanUtils.copy(entity, originEntity);
        sysQuartzLogMapper.updateByPrimaryKey(originEntity);
    }

    public void deleteSysQuartzLog(Long id) {
        sysQuartzLogMapper.deleteByPrimaryKey(id);
    }

    public SysQuartzLog findSysQuartzLogById(Long id) {
        SysQuartzLog entity = sysQuartzLogMapper.selectByPrimaryKey(id);
        AssertUtils.notNull(entity);
        return entity;
    }

    public R<List<SysQuartzLog>> pageQuery(Map<String, Object> conditions, int pageNun, int pageSize) {

        // 样例 保留
//		SysQuartzLog sysQuartzLogConditions = AnBeanUtils.mapToBean(conditions,SysQuartzLog.class);

        SysQuartzLogExample          example  = new SysQuartzLogExample();
        SysQuartzLogExample.Criteria criteria = example.createCriteria();

        PageHelper.startPage(pageNun, pageSize);
        List<SysQuartzLog>     resultList = sysQuartzLogMapper.selectByExample(example);
        PageInfo<SysQuartzLog> page       = new PageInfo<SysQuartzLog>(resultList);
        PageHelper.clearPage();

        return new R<List<SysQuartzLog>>(page.getPageNum(), page.getPageSize(), (int) page.getTotal(), resultList);

    }

}