package com.docus.server.archivefile.infrastructure.dao.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.docus.infrastructure.core.db.dao.impl.BaseDaoImpl;
import com.docus.infrastructure.web.request.SearchRequest;
import com.docus.infrastructure.web.response.PageResult;
import com.docus.server.archivefile.infrastructure.dao.ITaskConfigTestDao;
import com.docus.server.archivefile.infrastructure.mapper.TaskConfigTestMapper;
import com.docus.server.entity.auth.TaskConfigTest;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 主动任务测试对象 TaskConfigTestDaoImpl 数据访问实现类
 * </p>
 *
 * @author AutoGenerator
 * @since 2023-07-05
 */
@Repository
public class TaskConfigTestDaoImpl extends BaseDaoImpl<TaskConfigTestMapper, TaskConfigTest> implements ITaskConfigTestDao {

    /**
     * 按主键查询
     *
     * @param id 主键Id
     * @return 实体
     */
    @Override
    public TaskConfigTest findById(String id) {
        return super.findById(id);
    }

    /**
     * 新增
     *
     * @param taskConfigTest 编辑参数
     * @return 成功或失败
     */
    @Override
    public boolean add(TaskConfigTest taskConfigTest) {
        return super.save(taskConfigTest);
    }

    /**
     * 编辑
     *
     * @param taskConfigTest 编辑参数
     * @return 成功或失败
     */
    @Override
    public boolean edit(TaskConfigTest taskConfigTest) {
        return super.updateById(taskConfigTest);
    }

    /**
     * 批量删除
     *
     * @param ids 主键ids
     * @return 成功或失败
     */
    @Override
    public int delete(List<String> ids) {
        return super.deleteByIds(ids);
    }

    /**
     * 关键字搜素
     *
     * @param searchRequest 搜索参数
     * @return 分页列表
     */
    @Override
    public PageResult<TaskConfigTest> search(SearchRequest searchRequest) {
        //分页
        PageHelper.startPage(searchRequest.getPageNum(), searchRequest.getPageSize());
        LambdaQueryWrapper<TaskConfigTest> query = Wrappers.lambdaQuery();
        //时间范围，默认按createTime
        if (searchRequest.getBeginTime() != null) {
            query.ge(TaskConfigTest::getCreateTime, searchRequest.getBeginTime());
        }
        if (searchRequest.getEndTime() != null) {
            Date endTime = searchRequest.getEndTime();
            query.le(TaskConfigTest::getCreateTime, endTime);
        }
        //关键字比较，多个列or
        //if (!StringUtils.isEmpty(searchRequest.getKeyword())) {
        //单个列用like
        //query. like(TaskConfigTest::getxxx, searchRequest. getKeyword());
        //多个列用like
        //query. and(sub -> sub.like(TaskConfigTest::getxx1, searchRequest. getKeyword())
        // оr(). like(TaskConfigTest::getXX2, searchRequest. getKeyword()))
        //);
        //}
        //默认createTime倒序排序
        query.orderByDesc(TaskConfigTest::getCreateTime);
        List<TaskConfigTest> list = super.find(query);
        return new PageResult<>(list);
    }

}
