package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.base;

import cn.estsh.i3plus.ext.mes.pcn.api.base.INumberRuleExtService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesNumberRuleExt;
import cn.estsh.i3plus.ext.mes.pcn.pojo.repository.MesNumberRuleExtRepository;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author wangjie
 * @version 1.0
 * @date 2021/1/13 9:28
 **/
@Slf4j
@Service
public class NumberRuleExtService implements INumberRuleExtService {

    @Autowired
    private MesNumberRuleExtRepository numberRuleExtRepository;

    @Override
    public MesNumberRuleExt getNumberRuleExtByRuleCode(String organizeCode, String ruleCode) {
        if (StringUtils.isEmpty(organizeCode) || StringUtils.isEmpty(ruleCode)) {
            return null;
        }
        return numberRuleExtRepository.getByProperty(
                new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, MesPcnExtConstWords.RULE_CODE},
                new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), ruleCode});
    }
}
