package cn.iocoder.yudao.module.common.dal.mysql.mold;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.common.controller.admin.mold.vo.MoldBrandPageReqVO;
import cn.iocoder.yudao.module.common.dal.dataobject.mold.MoldBrandDO;
import com.alibaba.excel.util.StringUtils;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.common.controller.admin.mold.vo.*;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 模具型号 Mapper
 *
 * @author 内蒙必硕
 */
@Mapper
public interface MoldBrandMapper extends BaseMapperX<MoldBrandDO> {

    default PageResult<MoldBrandDO> selectPage(MoldBrandPageReqVO reqVO) {

        LambdaQueryWrapperX<MoldBrandDO> moldBrandDOLambdaQueryWrapperX = new LambdaQueryWrapperX<>();
        moldBrandDOLambdaQueryWrapperX
                .eqIfPresent(MoldBrandDO::getCode, reqVO.getCode())
                .likeIfPresent(MoldBrandDO::getName, reqVO.getName())
                .eqIfPresent(MoldBrandDO::getMoldType, reqVO.getMoldType())
                .eqIfPresent(MoldBrandDO::getProductId, reqVO.getProductId())
                .eqIfPresent(MoldBrandDO::getUseTime, reqVO.getUseTime())
                .eqIfPresent(MoldBrandDO::getMaintainType, reqVO.getMaintainType())
                .eqIfPresent(MoldBrandDO::getMaintainTime, reqVO.getMaintainTime())
                .eqIfPresent(MoldBrandDO::getMoldSize, reqVO.getMoldSize())
                .eqIfPresent(MoldBrandDO::getRemark, reqVO.getRemark())
                .eqIfPresent(MoldBrandDO::getIsEnable, reqVO.getIsEnable())
                .eqIfPresent(MoldBrandDO::getOrgType, reqVO.getOrgType())
                .betweenIfPresent(MoldBrandDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(MoldBrandDO::getId);

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

        return selectPage(reqVO, moldBrandDOLambdaQueryWrapperX);




    }
    default List<MoldBrandDO> selectBy(MoldBrandPageReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<MoldBrandDO>()
                .eqIfPresent(MoldBrandDO::getCode, reqVO.getCode())
                .likeIfPresent(MoldBrandDO::getName, reqVO.getName())
                .eqIfPresent(MoldBrandDO::getMoldType, reqVO.getMoldType())
                .eqIfPresent(MoldBrandDO::getProductId, reqVO.getProductId())
                .eqIfPresent(MoldBrandDO::getUseTime, reqVO.getUseTime())
                .eqIfPresent(MoldBrandDO::getMaintainType, reqVO.getMaintainType())
                .eqIfPresent(MoldBrandDO::getMaintainTime, reqVO.getMaintainTime())
                .eqIfPresent(MoldBrandDO::getMoldSize, reqVO.getMoldSize())
                .eqIfPresent(MoldBrandDO::getRemark, reqVO.getRemark())
                .eqIfPresent(MoldBrandDO::getIsEnable, reqVO.getIsEnable())
                .eqIfPresent(MoldBrandDO::getOrgType, reqVO.getOrgType())
                .betweenIfPresent(MoldBrandDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(MoldBrandDO::getId));
    }
}