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

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.dal.dataobject.BusinessStandardSampleDO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessStandardSampleProjectDO;
import com.zt.plat.module.qms.enums.QmsCommonConstant;
import com.zt.plat.framework.mybatis.core.mapper.BaseMapperX;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;

/**
 * 定值样业务 Mapper
 *
 * @author 后台管理
 */
@Mapper
public interface BusinessStandardSampleMapper extends BaseMapperX<BusinessStandardSampleDO> {

    default PageResult<BusinessStandardSampleDO> selectPage(BusinessStandardSamplePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BusinessStandardSampleDO>()
                .eqIfPresent(BusinessStandardSampleDO::getIdPath, reqVO.getIdPath())
                .eqIfPresent(BusinessStandardSampleDO::getParentId, reqVO.getParentId())
                .likeIfPresent(BusinessStandardSampleDO::getName, reqVO.getName())
                .eqIfPresent(BusinessStandardSampleDO::getCode, reqVO.getCode())
                .eqIfPresent(BusinessStandardSampleDO::getIsUse, reqVO.getIsUse())
                .eqIfPresent(BusinessStandardSampleDO::getIsPublish, reqVO.getIsPublish())
                .eqIfPresent(BusinessStandardSampleDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode())
                .betweenIfPresent(BusinessStandardSampleDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(BusinessStandardSampleDO::getRemark, reqVO.getRemark())
                .orderByDesc(BusinessStandardSampleDO::getId));
    }

    
//    default List<BusinessStandardSampleExtendRespVO> selectByConfigQCSampleMethodId(Long configQCSampleMethodId) {
//    	return selectJoinList(BusinessStandardSampleExtendRespVO.class, new MPJLambdaWrapperX<BusinessStandardSampleDO>()
//    			.rightJoin(ConfigQCStandardSampleDO.class, ConfigQCStandardSampleDO::getBusinessStandardSampleId, BusinessStandardSampleDO::getId)
//    			.selectAll(BusinessStandardSampleDO.class)
//    			.selectAs(ConfigQCStandardSampleDO::getConfigQCSampleMethodId, BusinessStandardSampleExtendRespVO::getConfigQCSampleMethodId)
//    			.selectCollection(BusinessStandardSampleProjectDO.class, BusinessStandardSampleExtendRespVO::getStandardSampleProjectList)
//    			.leftJoin(BusinessStandardSampleProjectDO.class, BusinessStandardSampleProjectDO::getBusinessStandardSampleId, BusinessStandardSampleDO::getId)
//                .eq(ConfigQCStandardSampleDO::getConfigQCSampleMethodId, configQCSampleMethodId)
//                .eq(BusinessStandardSampleDO::getIsPublish, QmsCommonConstant.YES)
//                .eq(BusinessStandardSampleDO::getIsUse, QmsCommonConstant.YES));
//    }


	default List<BusinessStandardSampleExtendRespVO> getBusinessStandardSampleLeafList() {
    	return selectJoinList(BusinessStandardSampleExtendRespVO.class, new MPJLambdaWrapperX<BusinessStandardSampleDO>()
    			.selectAll(BusinessStandardSampleDO.class)
    			.selectCollection(BusinessStandardSampleProjectDO.class, BusinessStandardSampleExtendRespVO::getStandardSampleProjectList)
    			.leftJoin(BusinessStandardSampleProjectDO.class, BusinessStandardSampleProjectDO::getBusinessStandardSampleId, BusinessStandardSampleDO::getId)
    			.ne(BusinessStandardSampleDO::getParentId, 0)
                .eq(BusinessStandardSampleDO::getIsPublish, QmsCommonConstant.YES)
                .eq(BusinessStandardSampleDO::getIsUse, QmsCommonConstant.YES));
	}
}