package com.zt.plat.module.qms.business.bus.dal.mapper;

import java.util.*;

import com.zt.plat.framework.common.pojo.PageResult;
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.bus.controller.vo.*;
import com.zt.plat.module.qms.business.bus.controller.vo.BusinessSubSampleExtendRespVO;
import com.zt.plat.module.qms.business.bus.controller.vo.BusinessSubSamplePageReqVO;
import com.zt.plat.module.qms.business.bus.controller.vo.BusinessSubSampleReqVO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessAssayTaskDataDO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessSubSampleDO;
import com.zt.plat.module.qms.common.dic.dal.dataobject.DictionaryBusinessDO;
import com.zt.plat.module.qms.enums.QmsCommonConstant;
import jakarta.validation.Valid;
import com.zt.plat.framework.mybatis.core.mapper.BaseMapperX;
import org.apache.ibatis.annotations.Mapper;

/**
 * 子样业务 Mapper
 *
 * @author 后台管理
 */
@Mapper
public interface BusinessSubSampleMapper extends BaseMapperX<BusinessSubSampleDO> {

    default PageResult<BusinessSubSampleExtendRespVO> selectPage(BusinessSubSamplePageReqVO reqVO) {
        return selectJoinPage(reqVO, BusinessSubSampleExtendRespVO.class, new MPJLambdaWrapperX<BusinessSubSampleDO>()
        		.selectSub(BusinessAssayTaskDataDO.class, s -> s.selectCount(BusinessAssayTaskDataDO::getId).eq(BusinessAssayTaskDataDO::getBusinessSubSampleId, BusinessSubSampleDO::getId), BusinessSubSampleExtendRespVO::getAssayTaskCount)
        		.leftJoin(DictionaryBusinessDO.class, DictionaryBusinessDO::getId, BusinessSubSampleDO::getDictionaryBusinessId)
        		.selectAll(BusinessSubSampleDO.class)
        		.selectAs(DictionaryBusinessDO::getName, BusinessSubSampleExtendRespVO::getDictionaryBusinessName)
                .eqIfPresent(BusinessSubSampleDO::getBusinessBaseSampleId, reqVO.getBusinessBaseSampleId())
                .eqIfPresent(BusinessSubSampleDO::getBusinessSubParentSampleId, reqVO.getBusinessSubParentSampleId())
                .eqIfPresent(BusinessSubSampleDO::getConfigSubSampleId, reqVO.getConfigSubSampleId())
                .eqIfPresent(BusinessSubSampleDO::getDictionaryBusinessId, reqVO.getDictionaryBusinessId())
                .eqIfPresent(BusinessSubSampleDO::getConfigWarehouseLocationInfomationId, reqVO.getConfigWarehouseLocationInfomationId())
                .eqIfPresent(BusinessSubSampleDO::getSampleId, reqVO.getSampleId())
                .eqIfPresent(BusinessSubSampleDO::getGroupId, reqVO.getGroupId())
                .likeIfPresent(BusinessSubSampleDO::getSampleName, reqVO.getSampleName())
                .eqIfPresent(BusinessSubSampleDO::getSampleCode, reqVO.getSampleCode())
                .eqIfPresent(BusinessSubSampleDO::getSampleAssayCode, reqVO.getSampleAssayCode())
                .eqIfPresent(BusinessSubSampleDO::getSampleReturnCode, reqVO.getSampleReturnCode())
                .eqIfPresent(BusinessSubSampleDO::getIsWeighing, reqVO.getIsWeighing())
                .eqIfPresent(BusinessSubSampleDO::getLastSampleWeight, reqVO.getLastSampleWeight())
                .eqIfPresent(BusinessSubSampleDO::getLastBalanceCode, reqVO.getLastBalanceCode())
                .eqIfPresent(BusinessSubSampleDO::getConfigSampleFlowId, reqVO.getConfigSampleFlowId())
                .eqIfPresent(BusinessSubSampleDO::getSampleFlowNodeKey, reqVO.getSampleFlowNodeKey())
                .betweenIfPresent(BusinessSubSampleDO::getSampleFlowNodeTime, reqVO.getSampleFlowNodeTime())
                .eqIfPresent(BusinessSubSampleDO::getNextSampleFlowNode, reqVO.getNextSampleFlowNode())
                .eqIfPresent(BusinessSubSampleDO::getSampleStatus, reqVO.getSampleStatus())
                .eqIfPresent(BusinessSubSampleDO::getAssayOperator, reqVO.getAssayOperator())
                .eqIfPresent(BusinessSubSampleDO::getIsAssignTasked, reqVO.getIsAssignTasked())
                .betweenIfPresent(BusinessSubSampleDO::getAssignTaskTime, reqVO.getAssignTaskTime())
                .eqIfPresent(BusinessSubSampleDO::getIsReported, reqVO.getIsReported())
                .eqIfPresent(BusinessSubSampleDO::getReporter, reqVO.getReporter())
                .betweenIfPresent(BusinessSubSampleDO::getReportTime, reqVO.getReportTime())
                .betweenIfPresent(BusinessSubSampleDO::getReturnTime, reqVO.getReturnTime())
                .eqIfPresent(BusinessSubSampleDO::getReturnStatus, reqVO.getReturnStatus())
                .eqIfPresent(BusinessSubSampleDO::getReturnCodePrintCount, reqVO.getReturnCodePrintCount())
                .betweenIfPresent(BusinessSubSampleDO::getPrintLastTime, reqVO.getPrintLastTime())
                .eqIfPresent(BusinessSubSampleDO::getUpSampleRecordId, reqVO.getUpSampleRecordId())
                .eqIfPresent(BusinessSubSampleDO::getAnalysisRemark, reqVO.getAnalysisRemark())
                .eqIfPresent(BusinessSubSampleDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode())
                .betweenIfPresent(BusinessSubSampleDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(BusinessSubSampleDO::getUpdateCount, reqVO.getUpdateCount())
                .eqIfPresent(BusinessSubSampleDO::getRemark, reqVO.getRemark())
                .eqIfPresent(BusinessSubSampleDO::getUpSampleRecordId, reqVO.getUpSampleRecordId())
                .orderByDesc(BusinessSubSampleDO::getSampleFlowNodeTime).orderByAsc(BusinessSubSampleDO::getSampleCode));
    }

	default List<BusinessSubSampleExtendRespVO> selectList(@Valid BusinessSubSampleReqVO reqVO) {
		return selectJoinList(BusinessSubSampleExtendRespVO.class, new MPJLambdaWrapperX<BusinessSubSampleDO>()
        		.leftJoin(DictionaryBusinessDO.class, DictionaryBusinessDO::getId, BusinessSubSampleDO::getDictionaryBusinessId)
        		.selectAll(BusinessSubSampleDO.class)
        		.selectAs(DictionaryBusinessDO::getName, BusinessSubSampleExtendRespVO::getDictionaryBusinessName)
                .eqIfPresent(BusinessSubSampleDO::getBusinessBaseSampleId, reqVO.getBusinessBaseSampleId())
                .eqIfPresent(BusinessSubSampleDO::getBusinessSubParentSampleId, reqVO.getBusinessSubParentSampleId())
                .eqIfPresent(BusinessSubSampleDO::getConfigSubSampleId, reqVO.getConfigSubSampleId())
                .eqIfPresent(BusinessSubSampleDO::getDictionaryBusinessId, reqVO.getDictionaryBusinessId())
                .eqIfPresent(BusinessSubSampleDO::getConfigWarehouseLocationInfomationId, reqVO.getConfigWarehouseLocationInfomationId())
                .eqIfPresent(BusinessSubSampleDO::getSampleId, reqVO.getSampleId())
                .eqIfPresent(BusinessSubSampleDO::getGroupId, reqVO.getGroupId())
                .likeIfPresent(BusinessSubSampleDO::getSampleName, reqVO.getSampleName())
                .eqIfPresent(BusinessSubSampleDO::getSampleCode, reqVO.getSampleCode())
                .eqIfPresent(BusinessSubSampleDO::getSampleAssayCode, reqVO.getSampleAssayCode())
                .eqIfPresent(BusinessSubSampleDO::getSampleReturnCode, reqVO.getSampleReturnCode())
                .eqIfPresent(BusinessSubSampleDO::getIsWeighing, reqVO.getIsWeighing())
                .eqIfPresent(BusinessSubSampleDO::getLastSampleWeight, reqVO.getLastSampleWeight())
                .eqIfPresent(BusinessSubSampleDO::getLastBalanceCode, reqVO.getLastBalanceCode())
                .eqIfPresent(BusinessSubSampleDO::getConfigSampleFlowId, reqVO.getConfigSampleFlowId())
                .eqIfPresent(BusinessSubSampleDO::getSampleFlowNodeKey, reqVO.getSampleFlowNodeKey())
                .betweenIfPresent(BusinessSubSampleDO::getSampleFlowNodeTime, reqVO.getSampleFlowNodeTime())
                .eqIfPresent(BusinessSubSampleDO::getNextSampleFlowNode, reqVO.getNextSampleFlowNode())
                .eqIfPresent(BusinessSubSampleDO::getSampleStatus, reqVO.getSampleStatus())
                .eqIfPresent(BusinessSubSampleDO::getAssayOperator, reqVO.getAssayOperator())
                .eqIfPresent(BusinessSubSampleDO::getIsAssignTasked, reqVO.getIsAssignTasked())
                .betweenIfPresent(BusinessSubSampleDO::getAssignTaskTime, reqVO.getAssignTaskTime())
                .eqIfPresent(BusinessSubSampleDO::getIsReported, reqVO.getIsReported())
                .eqIfPresent(BusinessSubSampleDO::getReporter, reqVO.getReporter())
                .betweenIfPresent(BusinessSubSampleDO::getReportTime, reqVO.getReportTime())
                .betweenIfPresent(BusinessSubSampleDO::getReturnTime, reqVO.getReturnTime())
                .eqIfPresent(BusinessSubSampleDO::getReturnStatus, reqVO.getReturnStatus())
                .eqIfPresent(BusinessSubSampleDO::getReturnCodePrintCount, reqVO.getReturnCodePrintCount())
                .betweenIfPresent(BusinessSubSampleDO::getPrintLastTime, reqVO.getPrintLastTime())
                .eqIfPresent(BusinessSubSampleDO::getUpSampleRecordId, reqVO.getUpSampleRecordId())
                .eqIfPresent(BusinessSubSampleDO::getAnalysisRemark, reqVO.getAnalysisRemark())
                .eqIfPresent(BusinessSubSampleDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode())
                .betweenIfPresent(BusinessSubSampleDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(BusinessSubSampleDO::getUpdateCount, reqVO.getUpdateCount())
                .eqIfPresent(BusinessSubSampleDO::getRemark, reqVO.getRemark())
                .eqIfPresent(BusinessSubSampleDO::getUpSampleRecordId, reqVO.getUpSampleRecordId())
                .orderByDesc(BusinessSubSampleDO::getId));
	}

	default BusinessSubSampleExtendRespVO getBySampleCodeAndFlowKey(@Valid BusinessSubSampleReqVO reqVO) {
		return selectJoinOne(BusinessSubSampleExtendRespVO.class, new MPJLambdaWrapperX<BusinessSubSampleDO>()
        		.leftJoin(DictionaryBusinessDO.class, DictionaryBusinessDO::getId, BusinessSubSampleDO::getDictionaryBusinessId)
        		.selectAll(BusinessSubSampleDO.class)
        		.selectAs(DictionaryBusinessDO::getName, BusinessSubSampleExtendRespVO::getDictionaryBusinessName)
                .eqIfPresent(BusinessSubSampleDO::getSampleCode, reqVO.getSampleCode())
                .eqIfPresent(BusinessSubSampleDO::getSampleFlowNodeKey, reqVO.getSampleFlowNodeKey())
                .eqIfPresent(BusinessSubSampleDO::getSampleStatus, QmsCommonConstant.NORMAL)
                .eqIfPresent(BusinessSubSampleDO::getIsEnabled, QmsCommonConstant.YES)
                .orderByDesc(BusinessSubSampleDO::getId));
	}

}