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.module.qms.business.config.controller.vo.*;
import com.zt.plat.module.qms.business.config.dal.dataobject.ConfigRuleDO;
import com.zt.plat.module.qms.enums.QmsCommonConstant;
import com.zt.plat.framework.mybatis.core.mapper.BaseMapperX;
import org.apache.ibatis.annotations.Mapper;

/**
 * 规则配置 Mapper
 *
 * @author 后台管理
 */
@Mapper
public interface ConfigRuleMapper extends BaseMapperX<ConfigRuleDO> {

    default PageResult<ConfigRuleDO> selectPage(ConfigRulePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ConfigRuleDO>()
                .eqIfPresent(ConfigRuleDO::getCode, reqVO.getCode())
                .likeIfPresent(ConfigRuleDO::getName, reqVO.getName())
                .eqIfPresent(ConfigRuleDO::getDescription, reqVO.getDescription())
                .eqIfPresent(ConfigRuleDO::getType, reqVO.getType())
                .eqIfPresent(ConfigRuleDO::getExpression, reqVO.getExpression())
                .eqIfPresent(ConfigRuleDO::getVersion, reqVO.getVersion())
                .eqIfPresent(ConfigRuleDO::getIsLast, reqVO.getIsLast())
                .eqIfPresent(ConfigRuleDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode())
                .betweenIfPresent(ConfigRuleDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(ConfigRuleDO::getRemark, reqVO.getRemark())
                .orderByDesc(ConfigRuleDO::getId));
    }

    default ConfigRuleDO selectLatestConfigRuleByCode(String code) {
    	return selectOne(new LambdaQueryWrapperX<ConfigRuleDO>()
    			.eq(ConfigRuleDO::getCode, code).eq(ConfigRuleDO::getIsLast, QmsCommonConstant.YES));
    }
}