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.business.config.dal.dataobject.ConfigBaseSampleDO;
import com.zt.plat.module.qms.resource.material.controller.vo.MaterialCorrelationAssayPageReqVO;
import com.zt.plat.module.qms.resource.material.controller.vo.MaterialCorrelationAssayRespVO;
import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialCorrelationAssayDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 物料检化验关联信息 Mapper
 *
 * @author 后台管理
 */
@Mapper
public interface MaterialCorrelationAssayMapper extends BaseMapperX<MaterialCorrelationAssayDO> {

    default PageResult<MaterialCorrelationAssayDO> selectPage(MaterialCorrelationAssayPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<MaterialCorrelationAssayDO>()
                .eqIfPresent(MaterialCorrelationAssayDO::getEntrustId, reqVO.getEntrustId())
                .eqIfPresent(MaterialCorrelationAssayDO::getBusinessType, reqVO.getBusinessType())
                .eqIfPresent(MaterialCorrelationAssayDO::getSource, reqVO.getSource())
                .eqIfPresent(MaterialCorrelationAssayDO::getProductId, reqVO.getProductId())
                .eqIfPresent(MaterialCorrelationAssayDO::getSampleId, reqVO.getSampleId())
                .eqIfPresent(MaterialCorrelationAssayDO::getBatchId, reqVO.getBatchId())
                .eqIfPresent(MaterialCorrelationAssayDO::getGongduanId, reqVO.getGongduanId())
                .eqIfPresent(MaterialCorrelationAssayDO::getItem, reqVO.getItem())
                .eqIfPresent(MaterialCorrelationAssayDO::getAssayStatus, reqVO.getAssayStatus())
                .eqIfPresent(MaterialCorrelationAssayDO::getResult, reqVO.getResult())
                .eqIfPresent(MaterialCorrelationAssayDO::getQualified, reqVO.getQualified())
                .eqIfPresent(MaterialCorrelationAssayDO::getReason, reqVO.getReason())
                .eqIfPresent(MaterialCorrelationAssayDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode())
                .eqIfPresent(MaterialCorrelationAssayDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(MaterialCorrelationAssayDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(MaterialCorrelationAssayDO::getId));
    }

    default List<MaterialCorrelationAssayRespVO> selectRespListByIds(List<Long> ids) {
        MPJLambdaWrapperX<MaterialCorrelationAssayDO> wrapper = new MPJLambdaWrapperX<MaterialCorrelationAssayDO>()
                .selectAll(MaterialCorrelationAssayDO.class)
                .selectAs(ConfigBaseSampleDO::getPrintTemplate, MaterialCorrelationAssayRespVO::getSampleLabelTemplate)
                .leftJoin(ConfigBaseSampleDO.class, ConfigBaseSampleDO::getBaseSampleId, MaterialCorrelationAssayDO::getSampleId)
                .inIfPresent(MaterialCorrelationAssayDO::getId, ids);
        return selectJoinList(MaterialCorrelationAssayRespVO.class, wrapper);
    }
}