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.base.controller.admin.base.vo.WarehousePageReqVO;
import com.zt.plat.module.base.dal.dataobject.base.WarehouseDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * 仓库 Mapper
 *
 * @author 后台管理
 */
@Mapper
public interface WarehouseMapper extends BaseMapperX<WarehouseDO> {

    default PageResult<WarehouseDO> selectPage(WarehousePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<WarehouseDO>()
                .likeIfPresent(WarehouseDO::getFactoryNumber, reqVO.getFactoryNumber())
                .likeIfPresent(WarehouseDO::getCpnName, reqVO.getCpnName())
                .likeIfPresent(WarehouseDO::getErpFactoryName, reqVO.getErpFactoryName())
                .eqIfPresent(WarehouseDO::getErpFactoryNumber, reqVO.getErpFactoryNumber())
                .likeIfPresent(WarehouseDO::getName, reqVO.getName())
                .eqIfPresent(WarehouseDO::getCoding, reqVO.getCoding())
                .betweenIfPresent(WarehouseDO::getCreateTime, reqVO.getCreateTime())
                .likeIfPresent(WarehouseDO::getFactoryName, reqVO.getFactoryName())
                .eqIfPresent(WarehouseDO::getIsEnable, reqVO.getIsEnable())
                .likeIfPresent(WarehouseDO::getCompanyNumber, reqVO.getCompanyNumber())
                .likeIfPresent(WarehouseDO::getErpCoding, reqVO.getErpCoding())
                .likeIfPresent(WarehouseDO::getErpName, reqVO.getErpName())
                .orderByDesc(WarehouseDO::getId));
    }

    String selectMaxCode();

    default WarehouseDO selectByCode(String code){
        return selectOne(new LambdaQueryWrapperX<WarehouseDO>()
                .eq(WarehouseDO::getCoding, code)
                .last("LIMIT 1"));
    };
}