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

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.controller.admin.dashboard.vo.dashboard.EventStatisticsVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.dvrepair.DvRepairDO;
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.dvrepair.vo.*;

/**
 * 设备维修记录 Mapper
 *
 * @author 内蒙必硕
 */
@Mapper
public interface DvRepairMapper extends BaseMapperX<DvRepairDO> {

    default PageResult<DvRepairDO> selectPage(DvRepairPageReqVO reqVO) {


        LambdaQueryWrapperX<DvRepairDO> dvRepairDOLambdaQueryWrapperX = new LambdaQueryWrapperX<>();
        dvRepairDOLambdaQueryWrapperX
                .eqIfPresent(DvRepairDO::getRepairCode, reqVO.getRepairCode())
                .likeIfPresent(DvRepairDO::getRepairName, reqVO.getRepairName())
                .eqIfPresent(DvRepairDO::getMachineryId, reqVO.getMachineryId())
                .eqIfPresent(DvRepairDO::getMachineryCode, reqVO.getMachineryCode())
                .likeIfPresent(DvRepairDO::getMachineryName, reqVO.getMachineryName())
                .eqIfPresent(DvRepairDO::getMachineryBrand, reqVO.getMachineryBrand())
                .eqIfPresent(DvRepairDO::getMachinerySpec, reqVO.getMachinerySpec())
                .eqIfPresent(DvRepairDO::getMachineryTypeId, reqVO.getMachineryTypeId())
                .betweenIfPresent(DvRepairDO::getRequireDate, reqVO.getRequireDate())
                .betweenIfPresent(DvRepairDO::getFinishDate, reqVO.getFinishDate())
                .betweenIfPresent(DvRepairDO::getConfirmDate, reqVO.getConfirmDate())
                .eqIfPresent(DvRepairDO::getRepairResult, reqVO.getRepairResult())
                .eqIfPresent(DvRepairDO::getAcceptedBy, reqVO.getAcceptedBy())
                .eqIfPresent(DvRepairDO::getConfirmBy, reqVO.getConfirmBy())
                .eqIfPresent(DvRepairDO::getStatus, reqVO.getStatus())
                .eqIfPresent(DvRepairDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(DvRepairDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(DvRepairDO::getCreateTime);

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

        return selectPage(reqVO,dvRepairDOLambdaQueryWrapperX );
    }

    void selectDeviceRepair(EventStatisticsVO eventStatisticsVO);
}