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

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.resource.device.dal.dataobject.DeviceInfomationDO;
import com.zt.plat.module.qms.resource.material.controller.vo.MaterialStandardSolutionPageReqVO;
import com.zt.plat.module.qms.resource.material.controller.vo.MaterialStandardSolutionRespVO;
import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialInfomationDO;
import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialProductDO;
import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialStandardSolutionDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * 标液,标准溶液，包含配置信息 Mapper
 *
 * @author 后台管理
 */
@Mapper
public interface MaterialStandardSolutionMapper extends BaseMapperX<MaterialStandardSolutionDO> {

    default PageResult<MaterialStandardSolutionDO> selectPage(MaterialStandardSolutionPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<MaterialStandardSolutionDO>()
                .eqIfPresent(MaterialStandardSolutionDO::getDetailId, reqVO.getDetailId())
                .eqIfPresent(MaterialStandardSolutionDO::getInfomationId, reqVO.getInfomationId())
                .eqIfPresent(MaterialStandardSolutionDO::getMakeUser, reqVO.getMakeUser())
                .eqIfPresent(MaterialStandardSolutionDO::getMakeUserId, reqVO.getMakeUserId())
                .betweenIfPresent(MaterialStandardSolutionDO::getMakeDate, reqVO.getMakeDate())
                .eqIfPresent(MaterialStandardSolutionDO::getVolumeTotal, reqVO.getVolumeTotal())
                .eqIfPresent(MaterialStandardSolutionDO::getMakeRecord, reqVO.getMakeRecord())
                .eqIfPresent(MaterialStandardSolutionDO::getDue, reqVO.getDue())
                .betweenIfPresent(MaterialStandardSolutionDO::getDueDate, reqVO.getDueDate())
                .eqIfPresent(MaterialStandardSolutionDO::getBuretteNo, reqVO.getBuretteNo())
                .eqIfPresent(MaterialStandardSolutionDO::getConcentration, reqVO.getConcentration())
                .eqIfPresent(MaterialStandardSolutionDO::getTiter, reqVO.getTiter())
                .eqIfPresent(MaterialStandardSolutionDO::getStandardFlowType, reqVO.getStandardFlowType())
                .eqIfPresent(MaterialStandardSolutionDO::getStandardFlow, reqVO.getStandardFlow())
                .eqIfPresent(MaterialStandardSolutionDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode())
                .eqIfPresent(MaterialStandardSolutionDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(MaterialStandardSolutionDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(MaterialStandardSolutionDO::getId));
    }

    default PageResult<MaterialStandardSolutionRespVO> selectPageWithMaterialInfo(MaterialStandardSolutionPageReqVO reqVO) {
        MPJLambdaWrapperX<MaterialStandardSolutionDO> wrapperX = new MPJLambdaWrapperX<MaterialStandardSolutionDO>()
                .selectAll(MaterialStandardSolutionDO.class)
                .selectAs(MaterialInfomationDO::getCode, MaterialStandardSolutionRespVO::getInfomationCode)
                .selectAs(MaterialProductDO::getName, MaterialStandardSolutionRespVO::getInfomationName)
                .selectAs(DeviceInfomationDO::getDeviceName, MaterialStandardSolutionRespVO::getBuretteNo)
                .leftJoin(MaterialInfomationDO.class, MaterialInfomationDO::getId, MaterialStandardSolutionDO::getInfomationId)
                .leftJoin(MaterialProductDO.class, MaterialProductDO::getId, MaterialInfomationDO::getProductId)
                .leftJoin(DeviceInfomationDO.class, DeviceInfomationDO::getId, MaterialStandardSolutionDO::getBuretteId)
                .eqIfPresent(MaterialStandardSolutionDO::getDetailId, reqVO.getDetailId())
                .eqIfPresent(MaterialStandardSolutionDO::getInfomationId, reqVO.getInfomationId())
                .eqIfPresent(MaterialStandardSolutionDO::getMakeUser, reqVO.getMakeUser())
                .eqIfPresent(MaterialStandardSolutionDO::getMakeUserId, reqVO.getMakeUserId())
                .betweenIfPresent(MaterialStandardSolutionDO::getMakeDate, reqVO.getMakeDate())
                .eqIfPresent(MaterialStandardSolutionDO::getVolumeTotal, reqVO.getVolumeTotal())
                .eqIfPresent(MaterialStandardSolutionDO::getMakeRecord, reqVO.getMakeRecord())
                .eqIfPresent(MaterialStandardSolutionDO::getDue, reqVO.getDue())
                .betweenIfPresent(MaterialStandardSolutionDO::getDueDate, reqVO.getDueDate())
                .eqIfPresent(MaterialStandardSolutionDO::getBuretteNo, reqVO.getBuretteNo())
                .eqIfPresent(MaterialStandardSolutionDO::getConcentration, reqVO.getConcentration())
                .eqIfPresent(MaterialStandardSolutionDO::getTiter, reqVO.getTiter())
                .eqIfPresent(MaterialStandardSolutionDO::getStandardFlowType, reqVO.getStandardFlowType())
                .eqIfPresent(MaterialStandardSolutionDO::getStandardFlow, reqVO.getStandardFlow())
                .eqIfPresent(MaterialStandardSolutionDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode())
                .eqIfPresent(MaterialStandardSolutionDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(MaterialStandardSolutionDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(MaterialStandardSolutionDO::getId);
        return selectJoinPage(reqVO, MaterialStandardSolutionRespVO.class, wrapperX);
    }

    default MaterialStandardSolutionRespVO selectStandardSolutionWithMaterialInfoById(Long id) {
        return selectJoinOne(MaterialStandardSolutionRespVO.class, new MPJLambdaWrapperX<MaterialStandardSolutionDO>()
                .selectAll(MaterialStandardSolutionDO.class)
                .selectAs(MaterialInfomationDO::getCode, MaterialStandardSolutionRespVO::getInfomationCode)
                .selectAs(MaterialProductDO::getName, MaterialStandardSolutionRespVO::getInfomationName)
                .leftJoin(MaterialInfomationDO.class, MaterialInfomationDO::getId, MaterialStandardSolutionDO::getInfomationId)
                .leftJoin(MaterialProductDO.class, MaterialProductDO::getId, MaterialInfomationDO::getProductId)
                .eq(MaterialStandardSolutionDO::getId, id)
        );
    }
}