package cn.iocoder.yudao.module.mes.dal.mysql.dvsubject;

import java.util.*;
import java.util.stream.Collectors;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.mes.dal.dataobject.deviceledger.DeviceLedgerDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.dvsubject.DvSubjectDO;
import com.alibaba.excel.util.StringUtils;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.mes.controller.admin.dvsubject.vo.*;

/**
 * 维保项目 Mapper
 *
 * @author 内蒙必硕
 */
@Mapper
public interface DvSubjectMapper extends BaseMapperX<DvSubjectDO> {

    default PageResult<DvSubjectDO> selectPage(DvSubjectPageReqVO reqVO) {


        LambdaQueryWrapperX<DvSubjectDO> dvSubjectDOLambdaQueryWrapperX = new LambdaQueryWrapperX<>();
        dvSubjectDOLambdaQueryWrapperX
                .likeIfPresent(DvSubjectDO::getInspectionMethod, reqVO.getInspectionMethod())
                .likeIfPresent(DvSubjectDO::getValueType, reqVO.getValueType())
                .likeIfPresent(DvSubjectDO::getJudgmentCriteria, reqVO.getJudgmentCriteria())
                .likeIfPresent(DvSubjectDO::getSubjectCode, reqVO.getSubjectCode())
                .likeIfPresent(DvSubjectDO::getSubjectName, reqVO.getSubjectName())
                .eqIfPresent(DvSubjectDO::getSubjectType, reqVO.getSubjectType())
                .eqIfPresent(DvSubjectDO::getSubjectContent, reqVO.getSubjectContent())
                .eqIfPresent(DvSubjectDO::getSubjectStandard, reqVO.getSubjectStandard())
                .eqIfPresent(DvSubjectDO::getIsEnable, reqVO.getIsEnable())
                .betweenIfPresent(DvSubjectDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(DvSubjectDO::getCreateTime);

        // 单独处理 ids 条件
        if (StringUtils.isNotBlank(reqVO.getIds())) {
            List<Long> idList = Arrays.stream(reqVO.getIds().split(","))
                    .map(String::trim)
                    .map(Long::valueOf)
                    .collect(Collectors.toList());
            dvSubjectDOLambdaQueryWrapperX.in(DvSubjectDO::getId, idList);
        }

        return selectPage(reqVO, dvSubjectDOLambdaQueryWrapperX);
    }

}