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

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

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

    default PageResult<PlanMaintenanceDO> selectPage(PlanMaintenancePageReqVO reqVO) {

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

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


        return planMaintenanceDOPageResult;
    }

}