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

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.common.dal.dataobject.moldrepair.MoldRepairDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.zjitem.ZjItemDO;
import com.alibaba.excel.util.StringUtils;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.mes.controller.admin.zjitem.vo.*;

/**
 * 质量管理-检验项目 Mapper
 *
 * @author 内蒙必硕
 */
@Mapper
public interface ZjItemMapper extends BaseMapperX<ZjItemDO> {

    default PageResult<ZjItemDO> selectPage(ZjItemPageReqVO reqVO) {
        LambdaQueryWrapperX<ZjItemDO> zjItemDOLambdaQueryWrapperX = new LambdaQueryWrapperX<>();
        zjItemDOLambdaQueryWrapperX
                .eqIfPresent(ZjItemDO::getZjType, reqVO.getZjType())
                .likeIfPresent(ZjItemDO::getName, reqVO.getName())
                .likeIfPresent(ZjItemDO::getRemark, reqVO.getRemark())
                .eqIfPresent(ZjItemDO::getTool, reqVO.getTool())
                .eqIfPresent(ZjItemDO::getStandardVal, reqVO.getStandardVal())
                .eqIfPresent(ZjItemDO::getUnit, reqVO.getUnit())
                .eqIfPresent(ZjItemDO::getUpperVal, reqVO.getUpperVal())
                .eqIfPresent(ZjItemDO::getLowerVal, reqVO.getLowerVal())
                .betweenIfPresent(ZjItemDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ZjItemDO::getId);

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

        return selectPage(reqVO,zjItemDOLambdaQueryWrapperX );
    }

}