Explorar o código

增加 数据库函数、处理功能导入的问题,解决数据库脚本执行过程中变量无法替换的问题,处理表外配置可能为空的问题。

CodeLife Leno hai 2 meses
pai
achega
a8f8b3e2e0

+ 41 - 0
DBScript/李庚谱/003-FUNCTION.sql

@@ -9,4 +9,45 @@ BEGIN
     RETURN str;
 END //
 
+
+DROP FUNCTION IF EXISTS `nextval`;
+delimiter //
+CREATE FUNCTION nextval(sequence_name varchar(64)) RETURNS int(11)
+BEGIN
+    declare current integer;
+    set current = 0;
+    select t.value into current from t_sequence t where t.sequence_name = sequence_name for update;
+    update t_sequence t set t.value = t.value + 1 where t.sequence_name = sequence_name;
+    set current = current + 1;
+    return current;
+end//
+
+
+-- (匹配两个以逗号分隔的字符串是否存在相同的字符串)函数 用于发布信息查询
+DROP FUNCTION IF EXISTS `func_haveSameContent`;
+CREATE FUNCTION `func_haveSameContent` (setA varchar(255),setB varchar(255)) RETURNS int(1)
+BEGIN
+    DECLARE idx INT DEFAULT 0 ;
+    DECLARE len INT DEFAULT 0;
+    DECLARE llen INT DEFAULT 0;
+    DECLARE clen INT DEFAULT 0;
+    DECLARE tmpStr varchar(255);
+    DECLARE curt varchar(255);
+    SET len = LENGTH(setB);
+    WHILE idx < len DO
+        SET idx = idx + 1;
+        SET tmpStr = SUBSTRING_INDEX(setB,",",idx);
+        SET clen = LENGTH(tmpStr);
+        IF idx = 1 THEN SET curt = tmpStr;
+        ELSE SET curt = SUBSTRING(setB,llen+2,clen-llen-1);
+        END IF;
+        IF FIND_IN_SET(curt,setA) > 0 THEN RETURN 1;
+        END IF;
+        IF clen <= llen THEN RETURN 0;
+        END IF;
+        SET llen = clen;
+    END WHILE;
+    RETURN 0;
+end//
+
 delimiter ;

+ 2 - 2
Procedure/backend/project/src/main/java/com/sundata/product/rwa/calc/service/CalcRunningService.java

@@ -36,10 +36,10 @@ public class CalcRunningService {
 
         if (!context.containsKey("dataDate")) {
             String dataDate = (String) context.get("dataDate");
-            DateChecker.isSimpleDateFormat(dataDate);
+//            DateChecker.isSHORTDateFormat(dataDate);
             throw new CalcException("缺少必要参数 dataDate,请在传入参数中必要的传入 dataDate");
         }
-        Calendar calendar = DateChecker.getSimpleCalendar((String) context.get("dataDate"));
+        Calendar calendar = DateChecker.getShortCalendar((String) context.get("dataDate"));
         if (!context.containsKey("SDATE") || StrUtil.isBlank(context.get("SDATE").toString())) {
             log.warn("没有传入 SDATE 通过 dataDate 转换获取");
             context.put("SDATE", FastDateFormat.getInstance(DateChecker.SHORT_DATE_PATTERN).format(calendar.getTime()));

+ 16 - 3
Procedure/backend/project/src/main/java/com/sundata/product/rwa/calc/service/implement/units/GeneralLedgerGetterUnit.java

@@ -109,7 +109,15 @@ public class GeneralLedgerGetterUnit extends CalcUnit {
     @Override
     public void calc(CalcResult<String, Object> thisResult, String calculateInstanceNumber, Map<String, Object> context, Map<CalcUnit, CalcResult<String, Object>> sourceResults) {
         // 计算过程中,需要循环配置表并将每一个数据进行处理
-        StringSubstitutor sub = new StringSubstitutor(context);
+        Map<String,Object> newContext = new HashMap<>();
+        for (String key: context.keySet()) {
+            Object value = context.get(key);
+            if (value instanceof String) {
+                value = "'"+ value +"'";
+            }
+            newContext.put(key, value);
+        }
+        StringSubstitutor sub = new StringSubstitutor(newContext);
         JdbcTemplate jdbcTemplate = SpringUtil.getBean(JdbcTemplate.class);
         if (jdbcTemplate == null) {
             jdbcTemplate = new JdbcTemplate(SpringUtil.getBean(DataSource.class));
@@ -188,7 +196,7 @@ public class GeneralLedgerGetterUnit extends CalcUnit {
             Map<String, Object> map = ledgerConfigs.get(i);
 
             String getterSql = (String) DataUtil.getDataDefault(map.get("LEDGER_GETDATA_RULE"), String.class);
-            getterSql = getterSql.replace("#{dataDate}","'#{dataDate}‘");
+            getterSql = getterSql.replace("#{","${"); // 处理所有的配置转为 可被替换的 $
             String LEDGER_GETDATA_RULE_SQL = sub.replace(getterSql);
             String BALANCE_Str = DBExecutor.doQuery(LEDGER_GETDATA_RULE_SQL);
             String LOAN_REFERENCE_NO = "ZZQS" + DataUtil.getDataDefault(map.get("SUBJECT_CODES"), String.class);
@@ -198,7 +206,12 @@ public class GeneralLedgerGetterUnit extends CalcUnit {
             BigDecimal BALANCE = (BigDecimal) DataUtil.getDataDefault(BALANCE_Str, BigDecimal.class);
             String CURRENCY = "CNY";
             String LEDGER_OFFOBJECT_NO = (String) DataUtil.getDataDefault(map.get("LEDGER_OFFOBJECT_NO"), String.class);
-            String LEDGER_OFFOBJECT_NAME = (String) DataUtil.getDataDefault(infoListModel.get(LEDGER_OFFOBJECT_NO).getOffobjectName(), String.class);
+            String LEDGER_OFFOBJECT_NAME;
+            if (infoListModel.get(LEDGER_OFFOBJECT_NO) == null || map.get("LEDGER_OFFOBJECT_NO") == null){
+                LEDGER_OFFOBJECT_NAME = "";
+            }else{
+                LEDGER_OFFOBJECT_NAME = (String) DataUtil.getDataDefault(infoListModel.get(LEDGER_OFFOBJECT_NO).getOffobjectName(), String.class);
+            }
             BigDecimal CCF = infoListModel.get(LEDGER_OFFOBJECT_NO).getCcf();
             String RISK_EXPOSURE_LEV01_CODE = "";
             String RISK_EXPOSURE_LEV01_CODE_NAME = "";

+ 15 - 3
Procedure/backend/project/src/main/java/com/sundata/product/rwa/calc/service/implement/units/GeneralLedgerUnit.java

@@ -119,7 +119,18 @@ public class GeneralLedgerUnit extends CalcUnit {
     @Override
     public void calc(CalcResult<String, Object> thisResult, String calculateInstanceNumber, Map<String, Object> context, Map<CalcUnit, CalcResult<String, Object>> sourceResults) {
         // 计算过程中,需要循环配置表并将每一个数据进行处理
-        StringSubstitutor sub = new StringSubstitutor(context);
+
+
+        Map<String,Object> newContext = new HashMap<>();
+        for (String key: context.keySet()) {
+            Object value = context.get(key);
+            if (value instanceof String) {
+                value = "'"+ value +"'";
+            }
+            newContext.put(key, value);
+        }
+        StringSubstitutor sub = new StringSubstitutor(newContext);
+
         JdbcTemplate jdbcTemplate = SpringUtil.getBean(JdbcTemplate.class);
         if (jdbcTemplate == null) {
             jdbcTemplate = new JdbcTemplate(SpringUtil.getBean(DataSource.class));
@@ -181,8 +192,9 @@ public class GeneralLedgerUnit extends CalcUnit {
 
         for (RuleListModel ruleListModel : ruleListModels) {
 
-            String subjectSql = sub.replace(ruleListModel.getSubjectSql());
-            String productSql = sub.replace(ruleListModel.getProductSql());
+            String subjectSql = sub.replace(ruleListModel.getSubjectSql().replace("#{","${")); // 处理所有的配置转为 可被替换的 $);
+            String productSql = sub.replace(ruleListModel.getProductSql().replace("#{","${")); // 处理所有的配置转为 可被替换的 $);
+
             String subjectSum = DBExecutor.doQuery(subjectSql);
             String productSum = DBExecutor.doQuery(productSql);
             if (!NumberUtil.isNumber(subjectSum)) {

+ 11 - 0
Procedure/backend/project/src/main/java/com/sundata/product/rwa/calc/utils/DateChecker.java

@@ -19,6 +19,10 @@ public class DateChecker {
     public static final String SHORT_MONTH_PATTERN = "yyyyMM";
 
 
+    public static void isSHORTDateFormat(String dateStr) {
+        isDateFormat(dateStr, SHORT_DATE_PATTERN);
+    }
+
     public static void isSimpleDateFormat(String dateStr) {
         isDateFormat(dateStr, NORM_DATE_REGEX);
     }
@@ -32,6 +36,13 @@ public class DateChecker {
         }
     }
 
+    public static Calendar getShortCalendar(String dateStr) {
+        isSimpleDateFormat(dateStr);
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(DateUtil.parse(dateStr,SHORT_DATE_PATTERN));
+        return calendar;
+    }
+
     public static Calendar getSimpleCalendar(String dateStr) {
         isSimpleDateFormat(dateStr);
         Calendar calendar = Calendar.getInstance();