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.BusinessSampleEntrustProjectExtendRespVO;
import com.zt.plat.module.qms.business.bus.controller.vo.BusinessSampleEntrustProjectPageReqVO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessSampleEntrustProjectDO;
import com.zt.plat.module.qms.business.dic.dal.dataobject.DictionaryProjectDO;
import com.zt.plat.framework.mybatis.core.mapper.BaseMapperX;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

/**
 * 委检登记样品检测项目 Mapper
 *
 * @author 后台管理
 */
@Mapper
public interface BusinessSampleEntrustProjectMapper extends BaseMapperX<BusinessSampleEntrustProjectDO> {

    default PageResult<BusinessSampleEntrustProjectDO> selectPage(BusinessSampleEntrustProjectPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BusinessSampleEntrustProjectDO>()
                .eqIfPresent(BusinessSampleEntrustProjectDO::getBusinessSampleEntrustDetailId, reqVO.getBusinessSampleEntrustDetailId())
                .eqIfPresent(BusinessSampleEntrustProjectDO::getMaterialAssayStandardDetailId, reqVO.getMaterialAssayStandardDetailId())
                .eqIfPresent(BusinessSampleEntrustProjectDO::getDictionaryProjectId, reqVO.getDictionaryProjectId())
                .eqIfPresent(BusinessSampleEntrustProjectDO::getIsEnabled, reqVO.getIsEnabled())
                .eqIfPresent(BusinessSampleEntrustProjectDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode())
                .betweenIfPresent(BusinessSampleEntrustProjectDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(BusinessSampleEntrustProjectDO::getUpdateCount, reqVO.getUpdateCount())
                .eqIfPresent(BusinessSampleEntrustProjectDO::getRemark, reqVO.getRemark())
                .orderByDesc(BusinessSampleEntrustProjectDO::getId));
    }
    
    default List<BusinessSampleEntrustProjectExtendRespVO> selectByBusinessSampleEntrustDetailId(Long businessSampleEntrustDetailId) {
    	return selectJoinList(BusinessSampleEntrustProjectExtendRespVO.class, new MPJLambdaWrapperX<BusinessSampleEntrustProjectDO>()
				.selectAll(BusinessSampleEntrustProjectDO.class)
				.selectAs(DictionaryProjectDO::getCode, BusinessSampleEntrustProjectExtendRespVO::getProjectCode)
				.selectAs(DictionaryProjectDO::getName, BusinessSampleEntrustProjectExtendRespVO::getProjectName)
				.selectAs(DictionaryProjectDO::getSimpleName, BusinessSampleEntrustProjectExtendRespVO::getProjectSimpleName)
				.selectAs(DictionaryProjectDO::getShowName, BusinessSampleEntrustProjectExtendRespVO::getProjectShowName)
				.leftJoin(DictionaryProjectDO.class, DictionaryProjectDO::getId, BusinessSampleEntrustProjectDO::getDictionaryProjectId)
				.eq(BusinessSampleEntrustProjectDO::getBusinessSampleEntrustDetailId, businessSampleEntrustDetailId));
    }
    
    default List<BusinessSampleEntrustProjectDO> selectByBusinessSampleEntrustDetailIds(List<Long> businessSampleEntrustDetailIdList) {
    	return selectList(new LambdaQueryWrapperX<BusinessSampleEntrustProjectDO>()
				.in(BusinessSampleEntrustProjectDO::getBusinessSampleEntrustDetailId, businessSampleEntrustDetailIdList));
    }

    /**
     * 物理批量删除删除
     * @param idList
     * @return
     */
    int physicalDeleteByIds(@Param("idList") List<Long> idList);

}