package com.blueland.service.impl;


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

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.blueland.model.TPfSysTimetask;
import com.blueland.service.SysTimetaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.blueland.bo.SysTimetaskEntity;
import com.blueland.dao.SysTimetaskDao;

@Service
public class SysTimetaskServiceImpl extends ServiceImpl<SysTimetaskDao, TPfSysTimetask> implements SysTimetaskService {
    @Autowired
    //SysTimetask对应的DAO类,主要用于数据库的增删改查等操作
    private SysTimetaskDao sysTimetaskDao;

    /**
     * 根据条件查询列表(分页)
     */
    @Override
    public Page<SysTimetaskEntity> findSysTimetaskPageListByParams(Map<String, Object> tagSysTimetask, int curPage, int pageSize) {
        Page<SysTimetaskEntity> page = new Page<>(curPage, pageSize);
        Page<SysTimetaskEntity> list = sysTimetaskDao.findSysTimetaskPageByParams(page, tagSysTimetask);

        return list;
    }

    @Override
    public TPfSysTimetask get(SysTimetaskEntity bo) {
        return this.baseMapper.selectOne(buildQueryWrapper(bo));
    }

    @Override
    public List<SysTimetaskEntity> findList(SysTimetaskEntity bo) {
        return this.baseMapper.findList(bo);
    }

    @Override
    public Page<SysTimetaskEntity> findPage(SysTimetaskEntity bo) {
        Page<SysTimetaskEntity> page = new Page(bo.getPageNum(), bo.getPageSize());
        return this.baseMapper.findPage(page, bo);
    }

    @Override
    public Long count(SysTimetaskEntity bo) {
        return this.baseMapper.selectCount(buildQueryWrapper(bo));
    }

    private LambdaQueryWrapper<TPfSysTimetask> buildQueryWrapper(SysTimetaskEntity bo) {
        LambdaQueryWrapper<TPfSysTimetask> lqw = Wrappers.lambdaQuery();
        lqw.eq(ObjectUtil.isNotEmpty(bo.getId()), TPfSysTimetask::getId, bo.getId());
        lqw.eq(ObjectUtil.isNotEmpty(bo.getTaskType()), TPfSysTimetask::getTaskType, bo.getTaskType());
        lqw.eq(ObjectUtil.isNotEmpty(bo.getTaskCode()), TPfSysTimetask::getTaskCode, bo.getTaskCode());
        lqw.like(ObjectUtil.isNotEmpty(bo.getDescription()), TPfSysTimetask::getDescription, bo.getDescription());
        lqw.eq(ObjectUtil.isNotEmpty(bo.getCronExp()), TPfSysTimetask::getCronExp, bo.getCronExp());
        lqw.eq(ObjectUtil.isNotEmpty(bo.getAction()), TPfSysTimetask::getAction, bo.getAction());
        lqw.eq(ObjectUtil.isNotEmpty(bo.getStatus()), TPfSysTimetask::getStatus, bo.getStatus());
        lqw.eq(ObjectUtil.isNotEmpty(bo.getAppId()), TPfSysTimetask::getAppId, bo.getAppId());
        lqw.eq(ObjectUtil.isNotEmpty(bo.getCreateId()), TPfSysTimetask::getCreateId, bo.getCreateId());
        lqw.eq(ObjectUtil.isNotEmpty(bo.getUpdateId()), TPfSysTimetask::getUpdateId, bo.getUpdateId());
        lqw.like(ObjectUtil.isNotEmpty(bo.getRemark()), TPfSysTimetask::getRemark, bo.getRemark());
        return lqw;
    }

}
