package com.zt.plat.module.qms.business.config.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.mapper.BaseMapperX;
import com.zt.plat.module.qms.business.config.controller.vo.ConfigSampleFlowPageReqVO;
import com.zt.plat.module.qms.business.config.dal.dataobject.ConfigSampleFlowDO;
import com.zt.plat.module.qms.enums.QmsCommonConstant;

import org.apache.ibatis.annotations.Mapper;
import com.zt.plat.module.qms.business.config.controller.vo.*;

/**
 * 样品流程配置 Mapper
 *
 * @author 后台管理
 */
@Mapper
public interface ConfigSampleFlowMapper extends BaseMapperX<ConfigSampleFlowDO> {

    default PageResult<ConfigSampleFlowDO> selectPage(ConfigSampleFlowPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ConfigSampleFlowDO>()
                .likeIfPresent(ConfigSampleFlowDO::getName, reqVO.getName())
                .eqIfPresent(ConfigSampleFlowDO::getKey, reqVO.getKey())
                .eqIfPresent(ConfigSampleFlowDO::getContent, reqVO.getContent())
                .eqIfPresent(ConfigSampleFlowDO::getDescription, reqVO.getDescription())
                .eqIfPresent(ConfigSampleFlowDO::getType, reqVO.getType())
                .eqIfPresent(ConfigSampleFlowDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode())
                .betweenIfPresent(ConfigSampleFlowDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(ConfigSampleFlowDO::getRemark, reqVO.getRemark())
                .eqIfPresent(ConfigSampleFlowDO::getVersion, reqVO.getVersion())
                .eq(ConfigSampleFlowDO::getIsLast, QmsCommonConstant.YES)
                .orderByDesc(ConfigSampleFlowDO::getId));
    }


	default List<ConfigSampleFlowDO> selectHistoryConfigSampleByKey(String key) {
		return selectList(new LambdaQueryWrapperX<ConfigSampleFlowDO>().eq(ConfigSampleFlowDO::getKey, key).eq(ConfigSampleFlowDO::getIsLast, QmsCommonConstant.NO).orderByDesc(ConfigSampleFlowDO::getVersion));
	}
    
    default ConfigSampleFlowDO selectLatestConfigSampleByKey(String key) {
    	return selectOne(new LambdaQueryWrapperX<ConfigSampleFlowDO>()
    			.eq(ConfigSampleFlowDO::getKey, key).eq(ConfigSampleFlowDO::getIsLast, QmsCommonConstant.YES));
    }

	default List<ConfigSampleFlowDO> selectLatestConfigSampleFlowListByKeys(List<String> keyList) {
		return selectList(new LambdaQueryWrapperX<ConfigSampleFlowDO>().in(ConfigSampleFlowDO::getKey, keyList).eq(ConfigSampleFlowDO::getIsLast, QmsCommonConstant.YES));
	}

}