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

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.dvsubject.DvSubjectDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.moldplanmaintenance.MoldPlanMaintenanceDO;
import com.alibaba.excel.util.StringUtils;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.mes.controller.admin.moldplanmaintenance.vo.*;

/**
 * 方案维护 Mapper
 *
 * @author 内蒙必硕
 */
@Mapper
public interface MoldPlanMaintenanceMapper extends BaseMapperX<MoldPlanMaintenanceDO> {

    default PageResult<MoldPlanMaintenanceDO> selectPage(MoldPlanMaintenancePageReqVO reqVO) {

        LambdaQueryWrapperX<MoldPlanMaintenanceDO> moldplanMaintenanceDOLambdaQueryWrapperX = new LambdaQueryWrapperX<>();
        moldplanMaintenanceDOLambdaQueryWrapperX
                .likeIfPresent(MoldPlanMaintenanceDO::getPlanName, reqVO.getPlanName())
                .eqIfPresent(MoldPlanMaintenanceDO::getPlanType, reqVO.getPlanType())
                .eqIfPresent(MoldPlanMaintenanceDO::getDescription, reqVO.getDescription())
                .betweenIfPresent(MoldPlanMaintenanceDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(MoldPlanMaintenanceDO::getCreateTime);

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


        return moldplanMaintenanceDOPageResult;
    }

}