package com.engine.kq.biz;

import weaver.cache.*;
import weaver.conn.RecordSet;
import weaver.general.Util;

/**
 * @Auther: Administrator
 * @Date: 2019-03-08 16:23
 * @Description:
 */
public class KQLeaveRulesDetailComInfo extends CacheBase {

    /**
     * 数据来源
     */
    protected static String TABLE_NAME = "kq_leaveRulesDetail";
    /**
     * sql中的where信息，不要以where开始
     */
    protected static String TABLE_WHERE = " (isDelete is null or isDelete !=1) ";
    /**
     * sql中的order by信息，不要以order by开始
     */
    protected static String TABLE_ORDER = "id";

    /**
     * 主键
     */
    @PKColumn(type = CacheColumnType.NUMBER)
    protected static String PK_NAME = "id";

    /**
     * 假期规则的ID
     */
    @CacheColumn(name = "id")
    protected static int id;

    /**
     * 假期类型的ID
     */
    @CacheColumn(name = "ruleId")
    protected static int ruleId;

    /**
     * 假期规则名称
     */
    @CacheColumn(name = "ruleName")
    protected static int ruleName;

    /**
     * 应用范围：0-总部、1-分部
     */
    @CacheColumn(name = "scopeType")
    protected static int scopeType;

    /**
     * 分部ID(当应用范围为分部时选择的分部ID)
     */
    @CacheColumn(name = "scopeValue")
    protected static int scopeValue;

    /**
     * 余额发放方式：
     * 1-手动发放
     * 2-按司龄自动发放
     * 3-按工龄自动发放
     * 4-每年自动发放固定天数
     * 5-加班时长自动计入余额
     * 6-按司龄+工龄自动发放
     */
    @CacheColumn(name = "distributionMode")
    protected static int distributionMode;

    /**
     * 每人发放小时（天）数
     * 注：当余额发放方式为"4-每年自动发放固定天数"时有效
     */
    @CacheColumn(name = "annualAmount")
    protected static int annualAmount;

    /**
     * 法定年假的规则：(当【余额发放方式】选择【6-按司龄+工龄自动发放】才有效)
     * 0-工龄(默认)
     * 1-司龄
     * 2-司龄+工龄
     */
    @CacheColumn(name = "legalKey")
    protected static int legalKey;

    /**
     * 福利年假的规则：(当【余额发放方式】选择【6-按司龄+工龄自动发放】才有效)
     * 0-工龄
     * 1-司龄(默认)
     * 2-司龄+工龄
     */
    @CacheColumn(name = "welfareKey")
    protected static int welfareKey;

    /**
     * 扣减优先级：(当【余额发放方式】选择【6-按司龄+工龄自动发放】才有效)
     * 1-法定年假
     * 2-福利年假
     */
    @CacheColumn(name = "priority")
    protected static int priority;

    /**
     * 计算方式
     */
    @CacheColumn(name = "calcMethod")
    protected static int calcMethod;

    /**
     * //假期基数的发放日期
     *     //1--每年的1月1号
     *     //2--入职日期
     *     //3--参加工作日期
     */
    @CacheColumn(name = "baseAmountReleaseDate")
    protected static int baseAmountReleaseDate;

    /**
     * //假期基数的变动日期
     *     //1--每年的1月1号
     *     //2--入职日期
     *     //3--参加工作日期
     */
    @CacheColumn(name = "baseAmountChangeDate")
    protected static int baseAmountChangeDate;

    /**
     * 假期基数折算方式
     * 0--不折算
     * 1--四舍五入
     * 2--向上取整
     * 3--向下取整
     * 4--向上取0.5的倍数
     * 5--向下取0.5的倍数
     */
    @CacheColumn(name = "convertMode")
    protected static int convertMode;

    /**
     * 折算后保留的小数点位数
     */
    @CacheColumn(name = "decimalDigit")
    protected static int decimalDigit;

    /**
     * 有效期规则
     * 0-永久有效
     * 1-按自然年(1月1日-12月31日)
     * 2-按入职日期起12个月
     * 3-自定义次年失效日期
     * 4-按天数失效
     * 5-按季度失效
     * 6-按月数失效
     */
    @CacheColumn(name = "validityRule")
    protected static int validityRule;

    /**
     * 失效日期-月
     */
    @CacheColumn(name = "expirationMonth")
    protected static int expirationMonth;

    /**
     * 失效日期-日
     */
    @CacheColumn(name = "expirationDay")
    protected static int expirationDay;

    /**
     * 有效天数
     */
    @CacheColumn(name = "effectiveDays")
    protected static int effectiveDays;

    /**
     * 有效月数
     */
    @CacheColumn(name = "effectiveMonths")
    protected static int effectiveMonths;

    /**
     * 是否允许延长有效期
     * 0-不允许
     * 1-允许
     */
    @CacheColumn(name = "extensionEnable")
    protected static int extensionEnable;

    /**
     * 允许延长的有效期天数
     */
    @CacheColumn(name = "extendedDays")
    protected static int extendedDays;

    /**
     * 释放规则
     * 0-不限制
     * 1-按天释放
     * 2-按月释放
     */
    @CacheColumn(name = "releaseRule")
    protected static int releaseRule;

    /**
     * 假期类型
     */
    @CacheColumn(name = "leaveCode")
    protected static int leaveCode;

    /**
     * 是否需要排除次账号
     * 0--不排除，即次账号正常享受年假
     * 1--排除，即次账号不能享受年假
     */
    @CacheColumn(name = "excludeSubAccount")
    protected static int excludeSubAccount;

    /**
     * 转正之前是否允许发放假期余额
     * 0--不允许
     * 1--允许
     */
    @CacheColumn(name = "beforeFormal")
    protected static int beforeFormal;

    @Override
    public CacheMap initCache() throws Exception {
        CacheMap localData = super.createCacheMap();
        RecordSet rs = new RecordSet();
        String sql = "select * from kq_leaveRulesDetail where (isDelete is null or isDelete<>1) order by id";
        rs.executeQuery(sql);
        while (rs.next()) {
            String _id = rs.getString("id");
            String _ruleId = rs.getString("ruleId");//假期类型的ID
            String _ruleName = rs.getString("ruleName");//假期类型的ID
            String _scopeType = rs.getString("scopeType");//假期类型的流程可见范围
            String _scopeValue = rs.getString("scopeValue");//流程可见范围为分部时勾选的分部ID
            String _distributionMode = rs.getString("distributionMode");
            String _annualAmount = rs.getString("annualAmount");
            String _legalKey = rs.getString("legalKey");
            String _welfareKey = rs.getString("welfareKey");
            String _priority = rs.getString("priority");
            String _calcMethod = rs.getString("calcMethod");
            String _baseAmountReleaseDate = rs.getString("baseAmountReleaseDate");
            String _baseAmountChangeDate = rs.getString("baseAmountChangeDate");
            String _convertMode = rs.getString("convertMode");
            String _decimalDigit = rs.getString("decimalDigit");
            String _validityRule = rs.getString("validityRule");
            String _expirationMonth = rs.getString("expirationMonth");
            String _expirationDay = rs.getString("expirationDay");
            String _effectiveDays = rs.getString("effectiveDays");
            String _effectiveMonths = rs.getString("effectiveMonths");
            String _extensionEnable = rs.getString("extensionEnable");
            String _extendedDays = rs.getString("extendedDays");
            String _releaseRule = rs.getString("releaseRule");
            String _leaveCode = rs.getString("leaveCode");
            String _excludeSubAccount = rs.getString("excludeSubAccount");
            String _beforeFormal = rs.getString("beforeFormal");
            if (_scopeType.equals("1")) {
                String[] scopeValueArr = _scopeValue.split(",");
                for (int i = 0; i < scopeValueArr.length; i++) {
                    String PK = _ruleId + "|" + _scopeType + "|" + scopeValueArr[i];


                    CacheItem row = createCacheItem();
                    row.set(PK_INDEX, PK);
                    row.set(id, _id);
                    row.set(ruleId, _ruleId);
                    row.set(ruleName, _ruleName);
                    row.set(scopeType, _scopeType);
                    row.set(scopeValue, _scopeValue);
                    row.set(distributionMode, _distributionMode);
                    row.set(annualAmount, _annualAmount);
                    row.set(legalKey, _legalKey);
                    row.set(welfareKey, _welfareKey);
                    row.set(priority, _priority);
                    row.set(calcMethod, _calcMethod);
                    row.set(baseAmountReleaseDate, _baseAmountReleaseDate);
                    row.set(baseAmountChangeDate, _baseAmountChangeDate);
                    row.set(convertMode, _convertMode);
                    row.set(decimalDigit, _decimalDigit);
                    row.set(validityRule, _validityRule);
                    row.set(expirationMonth, _expirationMonth);
                    row.set(expirationDay, _expirationDay);
                    row.set(effectiveDays, _effectiveDays);
                    row.set(effectiveMonths, _effectiveMonths);
                    row.set(extensionEnable, _extensionEnable);
                    row.set(extendedDays, _extendedDays);
                    row.set(releaseRule, _releaseRule);
                    row.set(leaveCode, _leaveCode);
                    row.set(excludeSubAccount, _excludeSubAccount);
                    row.set(beforeFormal, _beforeFormal);
                    modifyCacheItem(PK, row);
                    localData.put(PK, row);
                }
            } else {
                String PK = ruleId + "|" + scopeType;

                CacheItem row = createCacheItem();
                row.set(PK_INDEX, PK);
                row.set(id, _id);
                row.set(ruleId, _ruleId);
                row.set(ruleName, _ruleName);
                row.set(scopeType, _scopeType);
                row.set(scopeValue, _scopeValue);
                row.set(distributionMode, _distributionMode);
                row.set(annualAmount, _annualAmount);
                row.set(legalKey, _legalKey);
                row.set(welfareKey, _welfareKey);
                row.set(priority, _priority);
                row.set(calcMethod, _calcMethod);
                row.set(baseAmountReleaseDate, _baseAmountReleaseDate);
                row.set(baseAmountChangeDate, _baseAmountChangeDate);
                row.set(convertMode, _convertMode);
                row.set(decimalDigit, _decimalDigit);
                row.set(validityRule, _validityRule);
                row.set(expirationMonth, _expirationMonth);
                row.set(expirationDay, _expirationDay);
                row.set(effectiveDays, _effectiveDays);
                row.set(effectiveMonths, _effectiveMonths);
                row.set(extensionEnable, _extensionEnable);
                row.set(extendedDays, _extendedDays);
                row.set(releaseRule, _releaseRule);
                row.set(leaveCode, _leaveCode);
                row.set(excludeSubAccount, _excludeSubAccount);
                row.set(beforeFormal, _beforeFormal);
                modifyCacheItem(PK, row);
                localData.put(PK, row);
            }
        }
        return localData;
    }

    @Override
    public CacheItem initCache(String key) {
        if (key == null || "".equals(key.trim())) {
            return null;
        }

        String ruleIdTemp = "";//假期类型的ID
        String scopeTypeTemp = "";//假期类型的流程可见范围
        String scopeValueTemp = "";//流程可见范围为分部时勾选的分部ID
        String PK = "";

        String[] keyArr = key.split("\\|");
        String sql = "";
        RecordSet rs = new RecordSet();
        if (keyArr.length == 2) {
            ruleIdTemp = keyArr[0];
            scopeTypeTemp = keyArr[1];
            PK = ruleIdTemp + "|0";

            sql = "select * from kq_leaveRulesDetail where (isDelete is null or isDelete<>1) and ruleId=" + ruleIdTemp + " and scopeType=" + scopeTypeTemp + " order by id";
        }
        if (keyArr.length == 3) {
            ruleIdTemp = keyArr[0];
            scopeTypeTemp = keyArr[1];
            scopeValueTemp = keyArr[2];
            PK = ruleIdTemp + "|1|" + scopeValueTemp;

            sql = "select * from kq_leaveRulesDetail where (isDelete is null or isDelete<>1) and ruleId=" + ruleIdTemp + " and scopeType=" + scopeTypeTemp;
            if (rs.getDBType().equalsIgnoreCase("sqlserver")) {
                sql += " and ','+scopeValue+',' like '%," + scopeValueTemp + ",%'";
            } else if (rs.getDBType().equalsIgnoreCase("mysql")) {
                sql += " and concat(',',scopeValue,',') like '%," + scopeValueTemp + ",%'";
            } else {
                sql += " and ','||scopeValue||',' like '%," + scopeValueTemp + ",%'";
            }
            sql += " order by id ";
        }
        rs.executeQuery(sql);
        if (rs.next()) {
            String _id = rs.getString("id");
            String _ruleId = rs.getString("ruleId");//假期类型的ID
            String _ruleName = rs.getString("ruleName");//假期类型的ID
            String _scopeType = rs.getString("scopeType");//假期类型的流程可见范围
            String _scopeValue = rs.getString("scopeValue");//流程可见范围为分部时勾选的分部ID
            String _distributionMode = rs.getString("distributionMode");
            String _annualAmount = rs.getString("annualAmount");
            String _legalKey = rs.getString("legalKey");
            String _welfareKey = rs.getString("welfareKey");
            String _priority = rs.getString("priority");
            String _calcMethod = rs.getString("calcMethod");
            String _baseAmountReleaseDate = rs.getString("baseAmountReleaseDate");
            String _baseAmountChangeDate = rs.getString("baseAmountChangeDate");
            String _convertMode = rs.getString("convertMode");
            String _decimalDigit = rs.getString("decimalDigit");
            String _validityRule = rs.getString("validityRule");
            String _expirationMonth = rs.getString("expirationMonth");
            String _expirationDay = rs.getString("expirationDay");
            String _effectiveDays = rs.getString("effectiveDays");
            String _effectiveMonths = rs.getString("effectiveMonths");
            String _extensionEnable = rs.getString("extensionEnable");
            String _extendedDays = rs.getString("extendedDays");
            String _releaseRule = rs.getString("releaseRule");
            String _leaveCode = rs.getString("leaveCode");
            String _excludeSubAccount = rs.getString("excludeSubAccount");
            String _beforeFormal = rs.getString("beforeFormal");

            CacheItem row = createCacheItem();
            row.set(PK_INDEX, PK);
            row.set(id, _id);
            row.set(ruleId, _ruleId);
            row.set(ruleName, _ruleName);
            row.set(scopeType, _scopeType);
            row.set(scopeValue, _scopeValue);
            row.set(distributionMode, _distributionMode);
            row.set(annualAmount, _annualAmount);
            row.set(legalKey, _legalKey);
            row.set(welfareKey, _welfareKey);
            row.set(priority, _priority);
            row.set(calcMethod, _calcMethod);
            row.set(baseAmountReleaseDate, _baseAmountReleaseDate);
            row.set(baseAmountChangeDate, _baseAmountChangeDate);
            row.set(convertMode, _convertMode);
            row.set(decimalDigit, _decimalDigit);
            row.set(validityRule, _validityRule);
            row.set(expirationMonth, _expirationMonth);
            row.set(expirationDay, _expirationDay);
            row.set(effectiveDays, _effectiveDays);
            row.set(effectiveMonths, _effectiveMonths);
            row.set(extensionEnable, _extensionEnable);
            row.set(extendedDays, _extendedDays);
            row.set(releaseRule, _releaseRule);
            row.set(leaveCode, _leaveCode);
            row.set(excludeSubAccount, _excludeSubAccount);
            row.set(beforeFormal, _beforeFormal);
            modifyCacheItem(key, row);
            return row;
        } else {
            CacheItem row = createCacheItem();
            modifyCacheItem(key, row);
            return row;
        }
    }

    private String getId(String key) {
        return (String) getValue(id, key);
    }

    public String getId(String ruleId, String subcompanyId) {
        String PK = ruleId + "|1|" + subcompanyId;
        String id = getId(PK);
        if (id == null || id == "") {
            PK = ruleId + "|0";
            id = getId(PK);
        }
        return id;
    }

    private String getRuleId(String key) {
        return (String) getValue(ruleId, key);
    }

    private String getRuleName(String key) {
        return (String) getValue(ruleName, key);
    }

    public String getRuleName(String ruleId, String subcompanyId) {
        String PK = ruleId + "|1|" + subcompanyId;
        String ruleName = getRuleName(PK);
        if (ruleName == null || ruleName == "") {
            PK = ruleId + "|0";
            ruleName = getRuleName(PK);
        }
        return ruleName;
    }

    private String getScopeType(String key) {
        return (String) getValue(scopeType, key);
    }

    public String getScopeType(String ruleId, String subcompanyId) {
        String PK = ruleId + "|1|" + subcompanyId;
        String scopeType = getScopeType(PK);
        if (scopeType == null || scopeType == "") {
            PK = ruleId + "|0";
            scopeType = getScopeType(PK);
        }
        return scopeType;
    }

    private String getScopeValue(String key) {
        return (String) getValue(scopeValue, key);
    }

    public String getScopeValue(String ruleId, String subcompanyId) {
        String PK = ruleId + "|1|" + subcompanyId;
        String scopeValue = getScopeValue(PK);
        if (scopeValue == null || scopeValue == "") {
            PK = ruleId + "|0";
            scopeValue = getScopeValue(PK);
        }
        return scopeValue;
    }

    private String getDistributionMode(String key) {
        return (String) getValue(distributionMode, key);
    }

    public String getDistributionMode(String ruleId, String subcompanyId) {
        String PK = ruleId + "|1|" + subcompanyId;
        String distributionMode = getDistributionMode(PK);
        if (distributionMode == null || distributionMode == "") {
            PK = ruleId + "|0";
            distributionMode = getDistributionMode(PK);
        }
        return distributionMode;
    }

    private String getAnnualAmount(String key) {
        return (String) getValue(annualAmount, key);
    }

    public String getAnnualAmount(String ruleId, String subcompanyId) {
        String PK = ruleId + "|1|" + subcompanyId;
        String annualAmount = getAnnualAmount(PK);
        if (annualAmount == null || annualAmount == "") {
            PK = ruleId + "|0";
            annualAmount = getAnnualAmount(PK);
        }
        return annualAmount;
    }

    private String getLegalKey(String key) {
        return (String) getValue(legalKey, key);
    }

    public String getLegalKey(String ruleId, String subcompanyId) {
        String PK = ruleId + "|1|" + subcompanyId;
        String legalKey = getLegalKey(PK);
        if (legalKey == null || legalKey == "") {
            PK = ruleId + "|0";
            legalKey = getLegalKey(PK);
        }
        return legalKey;
    }

    private String getWelfareKey(String key) {
        return (String) getValue(welfareKey, key);
    }

    public String getWelfareKey(String ruleId, String subcompanyId) {
        String PK = ruleId + "|1|" + subcompanyId;
        String welfareKey = getWelfareKey(PK);
        if (welfareKey == null || welfareKey == "") {
            PK = ruleId + "|0";
            welfareKey = getWelfareKey(PK);
        }
        return welfareKey;
    }

    private String getPriority(String key) {
        return (String) getValue(priority, key);
    }

    public String getPriority(String ruleId, String subcompanyId) {
        String PK = ruleId + "|1|" + subcompanyId;
        String priority = getPriority(PK);
        if (priority == null || priority == "") {
            PK = ruleId + "|0";
            priority = getPriority(PK);
        }
        return priority;
    }

    private String getValidityRule(String key) {
        return (String) getValue(validityRule, key);
    }

    public String getValidityRule(String ruleId, String subcompanyId) {
        String PK = ruleId + "|1|" + subcompanyId;
        String validityRule = getValidityRule(PK);
        if (validityRule == null || validityRule == "") {
            PK = ruleId + "|0";
            validityRule = getValidityRule(PK);
        }
        return validityRule;
    }

    private String getExpirationMonth(String key) {
        return (String) getValue(expirationMonth, key);
    }

    public String getExpirationMonth(String ruleId, String subcompanyId) {
        String PK = ruleId + "|1|" + subcompanyId;
        String expirationMonth = getExpirationMonth(PK);
        if (expirationMonth == null || expirationMonth == "") {
            PK = ruleId + "|0";
            expirationMonth = getExpirationMonth(PK);
        }
        if (expirationMonth.length() == 1) {
            expirationMonth = "0" + expirationMonth;
        }
        return expirationMonth;
    }

    private String getExpirationDay(String key) {
        return (String) getValue(expirationDay, key);
    }

    public String getExpirationDay(String ruleId, String subcompanyId) {
        String PK = ruleId + "|1|" + subcompanyId;
        String expirationDay = getExpirationDay(PK);
        if (expirationDay == null || expirationDay == "") {
            PK = ruleId + "|0";
            expirationDay = getExpirationDay(PK);
        }
        if (expirationDay.length() == 1) {
            expirationDay = "0" + expirationDay;
        }
        return expirationDay;
    }

    private String getEffectiveDays(String key) {
        return (String) getValue(effectiveDays, key);
    }

    public String getEffectiveDays(String ruleId, String subcompanyId) {
        String PK = ruleId + "|1|" + subcompanyId;
        String effectiveDays = getEffectiveDays(PK);
        if (effectiveDays == null || effectiveDays == "") {
            PK = ruleId + "|0";
            effectiveDays = getEffectiveDays(PK);
        }
        if (Util.getIntValue(effectiveDays, 0) < 1) {
            effectiveDays = "1";
        }
        return effectiveDays;
    }

    private String getEffectiveMonths(String key) {
        return (String) getValue(effectiveMonths, key);
    }

    public String getEffectiveMonths(String ruleId, String subcompanyId) {
        String PK = ruleId + "|1|" + subcompanyId;
        String effectiveMonths = getEffectiveMonths(PK);
        if (effectiveMonths == null || effectiveMonths == "") {
            PK = ruleId + "|0";
            effectiveMonths = getEffectiveMonths(PK);
        }
        if (Util.getIntValue(effectiveMonths, 0) < 1) {
            effectiveMonths = "1";
        }
        return effectiveMonths;
    }

    private String getExtensionEnable(String key) {
        return (String) getValue(extensionEnable, key);
    }

    public String getExtensionEnable(String ruleId, String subcompanyId) {
        String PK = ruleId + "|1|" + subcompanyId;
        String extensionEnable = getExtensionEnable(PK);
        if (extensionEnable == null || extensionEnable == "") {
            PK = ruleId + "|0";
            extensionEnable = getExtensionEnable(PK);
        }
        return extensionEnable;
    }

    private String getExtendedDays(String key) {
        return (String) getValue(extendedDays, key);
    }

    public String getExtendedDays(String ruleId, String subcompanyId) {
        String PK = ruleId + "|1|" + subcompanyId;
        String extendedDays = getExtendedDays(PK);
        if (extendedDays == null || extendedDays == "") {
            PK = ruleId + "|0";
            extendedDays = getExtendedDays(PK);
        }
        return extendedDays;
    }

    private String getReleaseRule(String key) {
        return (String) getValue(releaseRule, key);
    }

    public String getReleaseRule(String ruleId, String subcompanyId) {
        String PK = ruleId + "|1|" + subcompanyId;
        String releaseRule = getReleaseRule(PK);
        if (releaseRule == null || releaseRule == "") {
            PK = ruleId + "|0";
            releaseRule = getReleaseRule(PK);
        }
        return releaseRule;
    }

    private String getLeaveCode(String key) {
        return (String) getValue(leaveCode, key);
    }

    public String getLeaveCode(String ruleId, String subcompanyId) {
        String PK = ruleId + "|1|" + subcompanyId;
        String leaveCode = getLeaveCode(PK);
        if (leaveCode == null || leaveCode == "") {
            PK = ruleId + "|0";
            leaveCode = getLeaveCode(PK);
        }
        return leaveCode;
    }

    private String getCalcMethod(String key) {
        return (String) getValue(calcMethod, key);
    }

    public String getCalcMethod(String ruleId, String subcompanyId) {
        String PK = ruleId + "|1|" + subcompanyId;
        String calcMethod = getCalcMethod(PK);
        if (calcMethod == null || calcMethod == "") {
            PK = ruleId + "|0";
            calcMethod = getCalcMethod(PK);
        }
        return calcMethod;
    }

    private String getBaseAmountReleaseDate(String key) {
        return (String) getValue(baseAmountReleaseDate, key);
    }

    public String getBaseAmountReleaseDate(String ruleId, String subcompanyId){
        String PK = ruleId + "|1|" + subcompanyId;
        String baseAmountReleaseDate = getBaseAmountReleaseDate(PK);
        if (baseAmountReleaseDate == null || baseAmountReleaseDate == "") {
            PK = ruleId + "|0";
            baseAmountReleaseDate = getBaseAmountReleaseDate(PK);
        }
        return baseAmountReleaseDate;
    }

    private String getBaseAmountChangeDate(String key) {
        return (String) getValue(baseAmountChangeDate, key);
    }

    public String getBaseAmountChangeDate(String ruleId, String subcompanyId){
        String PK = ruleId + "|1|" + subcompanyId;
        String baseAmountChangeDate = getBaseAmountChangeDate(PK);
        if (baseAmountChangeDate == null || baseAmountChangeDate == "") {
            PK = ruleId + "|0";
            baseAmountChangeDate = getBaseAmountChangeDate(PK);
        }
        return baseAmountChangeDate;
    }

    private String getConvertMode(String key) {
        return (String) getValue(convertMode, key);
    }

    public String getConvertMode(String ruleId, String subcompanyId){
        String PK = ruleId + "|1|" + subcompanyId;
        String convertMode = getConvertMode(PK);
        if (convertMode == null || convertMode == "") {
            PK = ruleId + "|0";
            convertMode = getConvertMode(PK);
        }
        if (convertMode == null || convertMode.equals("")) {
            convertMode = "1";
        }
        return convertMode;
    }

    private String getDecimalDigit(String key) {
        return (String) getValue(decimalDigit, key);
    }

    public String getDecimalDigit(String ruleId, String subcompanyId){
        String PK = ruleId + "|1|" + subcompanyId;
        String decimalDigit = getDecimalDigit(PK);
        if (decimalDigit == null || decimalDigit == "") {
            PK = ruleId + "|0";
            decimalDigit = getDecimalDigit(PK);
        }
        if (decimalDigit == null || decimalDigit == "" || Util.getIntValue(decimalDigit, 0) < 2) {
            decimalDigit = "2";
        }
        return decimalDigit;
    }

    private String getExcludeSubAccount(String key) {
        return (String) getValue(excludeSubAccount, key);
    }

    public String getExcludeSubAccount(String ruleId, String subcompanyId){
        String PK = ruleId + "|1|" + subcompanyId;
        String excludeSubAccount = getExcludeSubAccount(PK);
        if (excludeSubAccount == null || excludeSubAccount == "") {
            PK = ruleId + "|0";
            excludeSubAccount = getExcludeSubAccount(PK);
        }
        return excludeSubAccount;
    }

    private String getBeforeFormal(String key) {
        return (String) getValue(beforeFormal, key);
    }

    public String getBeforeFormal(String ruleId, String subcompanyId){
        String PK = ruleId + "|1|" + subcompanyId;
        String beforeFormal = getBeforeFormal(PK);
        if (beforeFormal == null || beforeFormal == "") {
            PK = ruleId + "|0";
            beforeFormal = getBeforeFormal(PK);
        }
        return beforeFormal;
    }
}
