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

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.mybatis.core.query.MPJLambdaWrapperX;
import com.zt.plat.module.qms.business.bus.controller.vo.BusinessHandoverRecordSubExtendRespVO;
import com.zt.plat.module.qms.business.bus.controller.vo.BusinessHandoverRecordSubPageReqVO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessHandoverRecordSubDO;
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.framework.mybatis.core.mapper.BaseMapperX;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;

/**
 * 子样交接记录业务 Mapper
 *
 * @author 后台管理
 */
@Mapper
public interface BusinessHandoverRecordSubMapper extends BaseMapperX<BusinessHandoverRecordSubDO> {

    default PageResult<BusinessHandoverRecordSubExtendRespVO> selectPage(BusinessHandoverRecordSubPageReqVO reqVO) {
        return selectJoinPage(reqVO, BusinessHandoverRecordSubExtendRespVO.class, new MPJLambdaWrapperX<BusinessHandoverRecordSubDO>()
        		.leftJoin(BusinessSubSampleDO.class, BusinessSubSampleDO::getId, BusinessHandoverRecordSubDO::getBusinessSubSampleId)
        		.leftJoin(DictionaryBusinessDO.class, DictionaryBusinessDO::getId, BusinessSubSampleDO::getDictionaryBusinessId)
        		.selectAll(BusinessHandoverRecordSubDO.class)
        		.selectAs(BusinessSubSampleDO::getSampleName, BusinessHandoverRecordSubExtendRespVO::getSampleName)
        		.selectAs(BusinessSubSampleDO::getSampleAssayCode, BusinessHandoverRecordSubExtendRespVO::getSampleAssayCode)
        		.selectAs(BusinessSubSampleDO::getSampleReturnCode, BusinessHandoverRecordSubExtendRespVO::getSampleReturnCode)
        		.selectAs(DictionaryBusinessDO::getName, BusinessHandoverRecordSubExtendRespVO::getDictionaryBusinessName)
                .eqIfPresent(BusinessHandoverRecordSubDO::getBusinessSubSampleId, reqVO.getBusinessSubSampleId())
                .eqIfPresent(BusinessHandoverRecordSubDO::getConfigSampleFlowId, reqVO.getConfigSampleFlowId())
                .eqIfPresent(BusinessHandoverRecordSubDO::getSampleFlowNodeKey, reqVO.getSampleFlowNodeKey())
                .eqIfPresent(BusinessHandoverRecordSubDO::getSampleCode, reqVO.getSampleCode())
                .eqIfPresent(BusinessHandoverRecordSubDO::getSampleWeight, reqVO.getSampleWeight())
                .eqIfPresent(BusinessHandoverRecordSubDO::getBalanceCode, reqVO.getBalanceCode())
                .betweenIfPresent(BusinessHandoverRecordSubDO::getOperationTime, reqVO.getOperationTime())
                .eqIfPresent(BusinessHandoverRecordSubDO::getOperator, reqVO.getOperator())
                .eqIfPresent(BusinessHandoverRecordSubDO::getOperatorId, reqVO.getOperatorId())
                .eqIfPresent(BusinessHandoverRecordSubDO::getSendSampleOperator, reqVO.getSendSampleOperator())
                .eqIfPresent(BusinessHandoverRecordSubDO::getReceiveSampleOperator, reqVO.getReceiveSampleOperator())
                .eqIfPresent(BusinessHandoverRecordSubDO::getUpSampleRecordId, reqVO.getUpSampleRecordId())
                .eqIfPresent(BusinessHandoverRecordSubDO::getNextSampleRecordId, reqVO.getNextSampleRecordId())
                .eqIfPresent(BusinessHandoverRecordSubDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode())
                .betweenIfPresent(BusinessHandoverRecordSubDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(BusinessHandoverRecordSubDO::getRemark, reqVO.getRemark())
                .eqIfPresent(BusinessSubSampleDO::getSampleAssayCode, reqVO.getSampleAssayCode())
                .eqIfPresent(BusinessSubSampleDO::getSampleReturnCode, reqVO.getSampleReturnCode())
                .likeIfPresent(BusinessSubSampleDO::getSampleName, reqVO.getSampleName())
                .eqIfPresent(BusinessHandoverRecordSubDO::getDeptId, reqVO.getDeptId())
                .orderByDesc(BusinessHandoverRecordSubDO::getCreateTime));
    }
    
    default List<BusinessHandoverRecordSubDO> selectByBusinessSubSampleId(Long businessSubSampleId) {
    	return selectList(new LambdaQueryWrapper<BusinessHandoverRecordSubDO>()
                .eq(BusinessHandoverRecordSubDO::getBusinessSubSampleId, businessSubSampleId)
    			.orderByDesc(BusinessHandoverRecordSubDO::getCreateTime));
    }
    
    default List<BusinessHandoverRecordSubDO> selectByBusinessSubSampleIds(List<Long> businessSubSampleIds) {
    	return selectList(new LambdaQueryWrapper<BusinessHandoverRecordSubDO>()
                .in(BusinessHandoverRecordSubDO::getBusinessSubSampleId, businessSubSampleIds)
    			.orderByDesc(BusinessHandoverRecordSubDO::getCreateTime));
    }

}