package com.zt.plat.module.qms.resource.material.dal.mapper;

import com.github.yulichang.wrapper.MPJLambdaWrapper;
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.framework.mybatis.core.query.MPJLambdaWrapperX;
import com.zt.plat.module.qms.business.config.dal.dataobject.ConfigWarehouseLocationDO;
import com.zt.plat.module.qms.resource.material.controller.vo.MaterialInventoryCheckDetailPageReqVO;
import com.zt.plat.module.qms.resource.material.controller.vo.MaterialInventoryCheckDetailRespVO;
import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialBatchDO;
import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialInfomationDO;
import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialInventoryCheckDetailDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * 库存盘点明细 Mapper
 *
 * @author 后台管理
 */
@Mapper
public interface MaterialInventoryCheckDetailMapper extends BaseMapperX<MaterialInventoryCheckDetailDO> {

    default PageResult<MaterialInventoryCheckDetailDO> selectPage(MaterialInventoryCheckDetailPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<MaterialInventoryCheckDetailDO>()
                .eqIfPresent(MaterialInventoryCheckDetailDO::getItemId, reqVO.getItemId())
                .eqIfPresent(MaterialInventoryCheckDetailDO::getInfomationId, reqVO.getInfomationId())
                .eqIfPresent(MaterialInventoryCheckDetailDO::getPresent, reqVO.getPresent())
                .eqIfPresent(MaterialInventoryCheckDetailDO::getCurrentQuantity, reqVO.getCurrentQuantity())
                .eqIfPresent(MaterialInventoryCheckDetailDO::getStatus, reqVO.getStatus())
                .eqIfPresent(MaterialInventoryCheckDetailDO::getDisposalMethod, reqVO.getDisposalMethod())
                .eqIfPresent(MaterialInventoryCheckDetailDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode())
                .eqIfPresent(MaterialInventoryCheckDetailDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(MaterialInventoryCheckDetailDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(MaterialInventoryCheckDetailDO::getId));
    }

    default PageResult<MaterialInventoryCheckDetailRespVO> selectPageWithInf(MaterialInventoryCheckDetailPageReqVO reqVO) {
        MPJLambdaWrapper<MaterialInventoryCheckDetailDO> wrapper = new MPJLambdaWrapperX<MaterialInventoryCheckDetailDO>()
                .selectAll(MaterialInventoryCheckDetailDO.class)
                .selectAs(MaterialInfomationDO::getCode, MaterialInventoryCheckDetailRespVO::getInfomationCode)
                .selectAs(MaterialInfomationDO::getName, MaterialInventoryCheckDetailRespVO::getInfomationName)
                .selectAs(MaterialBatchDO::getBatchNo, MaterialInventoryCheckDetailRespVO::getBatchNo)
                .selectAs(ConfigWarehouseLocationDO::getName, MaterialInventoryCheckDetailRespVO::getLocationName)
                .selectAs(ConfigWarehouseLocationDO::getCode, MaterialInventoryCheckDetailRespVO::getLocationCode)
                .leftJoin(MaterialInfomationDO.class, MaterialInfomationDO::getId, MaterialInventoryCheckDetailDO::getInfomationId)
                .leftJoin(MaterialBatchDO.class, MaterialBatchDO::getId, MaterialInfomationDO::getBatchId)
                .leftJoin(ConfigWarehouseLocationDO.class, ConfigWarehouseLocationDO::getId, MaterialInfomationDO::getLocationId)
                .eqIfPresent(MaterialInventoryCheckDetailDO::getCheckId, reqVO.getCheckId())
                .eqIfPresent(MaterialInventoryCheckDetailDO::getItemId, reqVO.getItemId())
                .eqIfPresent(MaterialInventoryCheckDetailDO::getInfomationId, reqVO.getInfomationId())
                .eqIfPresent(MaterialInventoryCheckDetailDO::getPresent, reqVO.getPresent())
                .eqIfPresent(MaterialInventoryCheckDetailDO::getStatus, reqVO.getStatus())
                .eqIfPresent(MaterialInventoryCheckDetailDO::getDisposalMethod, reqVO.getDisposalMethod())
                .eqIfPresent(MaterialInventoryCheckDetailDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode())
                .betweenIfPresent(MaterialInventoryCheckDetailDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(MaterialInventoryCheckDetailDO::getPresent)
                .orderByDesc(MaterialInventoryCheckDetailDO::getId);

        return selectJoinPage(reqVO, MaterialInventoryCheckDetailRespVO.class, wrapper);
    }
}