package com.engine.organization.util.coderule;

import com.engine.hrm.entity.RuleCodeType;
import com.engine.hrm.util.CodeRuleManager;

/**
 * @description:
 * @author:dxfeng
 * @createTime: 2022/06/06
 * @version: 1.0
 */
public class CodeRuleUtil {
    /**
     * 自动编号
     *
     * @param ruleCodeType
     * @param code
     * @return
     */
    public static String generateCode(RuleCodeType ruleCodeType, String code) {
        try {
            return CodeRuleManager.getCodeRuleManager().generateRuleCode(ruleCodeType, code);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 复制过程 自动生成编号
     *
     * @param ruleCodeType
     * @param code
     * @param isCopy
     * @return
     */
    public static String generateCode(RuleCodeType ruleCodeType, String code, boolean isCopy) {
        if (isCopy) {
            return generateCode(ruleCodeType, code);
        } else {
            return generateCode(ruleCodeType, code + "_cp");
        }
    }
}
