package com.zt.plat.module.base.dal.mysql.base;

import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.mybatis.core.mapper.BaseMapperX;
import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.zt.plat.module.api.dto.MaterialOtherDTO;
import com.zt.plat.module.base.controller.admin.base.vo.MaterialOtherPageReqVO;
import com.zt.plat.module.base.dal.dataobject.base.MaterialOtherDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 物料拓展数据 Mapper
 *
 * @author 后台管理
 */
@Mapper
public interface MaterialOtherMapper extends BaseMapperX<MaterialOtherDO> {

    default PageResult<MaterialOtherDO> selectPage(MaterialOtherPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<MaterialOtherDO>()
                .likeIfPresent(MaterialOtherDO::getMaterialNumber, reqVO.getMaterialNumber())
                .likeIfPresent(MaterialOtherDO::getMaterialName, reqVO.getMaterialName())
                .likeIfPresent(MaterialOtherDO::getErpMaterialNumber, reqVO.getErpMaterialNumber())
                .likeIfPresent(MaterialOtherDO::getErpMaterialName, reqVO.getErpMaterialName())
                .eqIfPresent(MaterialOtherDO::getUnit, reqVO.getUnit())
                .eqIfPresent(MaterialOtherDO::getAbbreviation, reqVO.getAbbreviation())
                .likeIfPresent(MaterialOtherDO::getName, reqVO.getName())
                .eqIfPresent(MaterialOtherDO::getCoding, reqVO.getCoding())
                .eqIfPresent(MaterialOtherDO::getGradeUnit, reqVO.getGradeUnit())
                .betweenIfPresent(MaterialOtherDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(MaterialOtherDO::getDecimalValue, reqVO.getDecimalValue())
                .eqIfPresent(MaterialOtherDO::getIsEnable, reqVO.getIsEnable())
                .orderByDesc(MaterialOtherDO::getId));
    }

    default List<MaterialOtherDO> selectList(MaterialOtherDTO dto) {
        return selectList(new LambdaQueryWrapperX<MaterialOtherDO>()
                .eqIfPresent(MaterialOtherDO::getMaterialNumber, dto.getMaterialNumber())
                .likeIfPresent(MaterialOtherDO::getMaterialName, dto.getMaterialName())
                .eqIfPresent(MaterialOtherDO::getErpMaterialNumber, dto.getErpMaterialNumber())
                .likeIfPresent(MaterialOtherDO::getErpMaterialName, dto.getErpMaterialName())
                .eqIfPresent(MaterialOtherDO::getUnit, dto.getUnit())
                .eqIfPresent(MaterialOtherDO::getAbbreviation, dto.getAbbreviation())
                .likeIfPresent(MaterialOtherDO::getName, dto.getName())
                .eqIfPresent(MaterialOtherDO::getCoding, dto.getCoding())
                .eqIfPresent(MaterialOtherDO::getGradeUnit, dto.getGradeUnit())
                .betweenIfPresent(MaterialOtherDO::getCreateTime, dto.getCreateTime())
                .eqIfPresent(MaterialOtherDO::getDecimalValue, dto.getDecimalValue())
                .eqIfPresent(MaterialOtherDO::getIsEnable, dto.getIsEnable())
                .orderByDesc(MaterialOtherDO::getId));
    }
}