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

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.moldsubject.MoldSubjectDO;
import com.alibaba.excel.util.StringUtils;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.mes.controller.admin.moldsubject.vo.*;

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

    default PageResult<MoldSubjectDO> selectPage(MoldSubjectPageReqVO reqVO) {


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

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

        return selectPage(reqVO, moldSubjectDOLambdaQueryWrapperX);
    }

}