Browse Source

区分事中,事后规则

0027005599 1 year ago
parent
commit
3abe332bbb

+ 5 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/medical/common/CommonUtil.java

@@ -41,6 +41,11 @@ public class CommonUtil {
         return new String[]{value.toString(), name.toString()};
     }
 
+    public static Object getNameByCode(String value){
+        Object name = redisTemplate.opsForHash().get(Constant.MEDICAL_CODE_NAME_KEY, value);
+        return name;
+    }
+
     public static boolean checkProjectCodeInItems(String projectCode){
         Object value = redisTemplate.opsForHash().get(Constant.HIS_MEDICAL_DICT_KEY, projectCode);
         if (value == null) {

+ 6 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/medical/entity/AfterwardsAuditDetail.java

@@ -2,6 +2,7 @@ package org.jeecg.modules.medical.entity;
 
 import java.io.Serializable;
 import java.math.BigDecimal;
+import java.util.Date;
 
 import com.baomidou.mybatisplus.annotation.*;
 import lombok.Data;
@@ -164,6 +165,11 @@ public class AfterwardsAuditDetail implements Serializable {
     private java.lang.Integer medicalRuleProjectId;
 
     private java.lang.Integer afterIncidentDetailLogId;
+
+    @ApiModelProperty(value = "项目使用时间")
+    private String projectUseTime;
+    @ApiModelProperty(value = "用药天数")
+    private Integer useDay;
     @TableField(exist = false)
     private String startTime;
     @TableField(exist = false)

+ 78 - 53
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/medical/ruleengine/FactorEnchangeFactory.java

@@ -1,6 +1,7 @@
 package org.jeecg.modules.medical.ruleengine;
 
 import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.date.DateUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import lombok.extern.slf4j.Slf4j;
@@ -10,6 +11,7 @@ import org.jeecg.common.util.SpringContextUtils;
 import org.jeecg.modules.medical.Constant;
 import org.jeecg.modules.medical.EnchanceTypeEnum;
 import org.jeecg.modules.medical.SystemEventAttrConstant;
+import org.jeecg.modules.medical.common.CommonUtil;
 import org.jeecg.modules.medical.entity.AdvanceWarningAudit;
 import org.jeecg.modules.medical.entity.AdvanceWarningAuditDetail;
 import org.jeecg.modules.medical.entity.AfterwardsAudit;
@@ -93,7 +95,6 @@ public class FactorEnchangeFactory {
 
     public Map<Integer, List<FactorAttrRela>> factorEnhanceIdAndListMap = new HashMap<>();
 
-    public static ThreadLocal<Map<String, Object>> currentThreadLocalMap = new ThreadLocal<>();
 
     public void init() {
         log.info("进入初始化FactorEnchangeFactory");
@@ -125,62 +126,59 @@ public class FactorEnchangeFactory {
         }
         Map<Integer, FactorEnchance> factorEnchanceMap = factorEnchanceList.stream().collect(Collectors.toMap(FactorEnchance::getId, v -> v, (v1, v2) -> v1));
         boolean result = false;
-        try {
-            localMap.put(Constant.ADESC, localMap.getOrDefault(SystemEventAttrConstant.MEDICAL_PROJECT_NAME_KEY,""));
-            currentThreadLocalMap.set(localMap);
-            for (RuleFactorRela ruleFactorRela : ruleFactorRelaList) {
-                Integer factorEnchanceId = ruleFactorRela.getFactorEnhanceId();
-                FactorEnchance factorEnchance = factorEnchanceMap.get(factorEnchanceId);
-                if (null == factorEnchance) {
-                    continue;
-                }
 
-                EnchanceTypeEnum enchanceTypeEnum = EnchanceTypeEnum.getType(factorEnchance.getEnhanceType());
-                switch (enchanceTypeEnum) {
-                    case SQL:
-                        Map<Integer, List<FactorAttrRela>> ioTypeMap = getIoMap(factorEnchanceId);
-                        sqlUtil.setSqlResultByFactorEnchance(localMap, ioTypeMap, factorEnchance, medicalInfoRuleInfoId);
-                        break;
-                    case EXPRESSION:
+        localMap.put(Constant.ADESC, localMap.getOrDefault(SystemEventAttrConstant.MEDICAL_PROJECT_NAME_KEY, ""));
+        for (RuleFactorRela ruleFactorRela : ruleFactorRelaList) {
+            Integer factorEnchanceId = ruleFactorRela.getFactorEnhanceId();
+            FactorEnchance factorEnchance = factorEnchanceMap.get(factorEnchanceId);
+            if (null == factorEnchance) {
+                continue;
+            }
+
+            EnchanceTypeEnum enchanceTypeEnum = EnchanceTypeEnum.getType(factorEnchance.getEnhanceType());
+            switch (enchanceTypeEnum) {
+                case SQL:
+                    Map<Integer, List<FactorAttrRela>> ioTypeMap = getIoMap(factorEnchanceId);
+                    sqlUtil.setSqlResultByFactorEnchance(localMap, ioTypeMap, factorEnchance, medicalInfoRuleInfoId);
+                    break;
+                case EXPRESSION:
 //                    setLogicalExpressionResultByFactorEnchance(localMap, ioTypeMap, factorEnchance, medicalInfoRuleInfoId);
-                        break;
-                    case DICT:
-                        dictUtil.transferData(localMap, factorEnchance, medicalInfoRuleInfoId);
-                        break;
-                    case PLUGIN:
-                        Map<Integer, List<FactorAttrRela>> ioTypeMap1 = getIoMap(factorEnchanceId);
-                        PluginInterface pluginInterface = (PluginInterface) SpringContextUtils.getBean(factorEnchance.getEnhanceValue());
-                        pluginInterface.plugin(localMap, ioTypeMap1, factorEnchance, medicalInfoRuleInfoId);
-                        break;
-                    case CONSTANT:
-                        localMap.put(getParamName(factorEnchance.getEventAttrId()), factorEnchance.getExtAttr1());
-                        break;
-                    case LOGICAL_EXPRESSION:
-                        result = setLogicalExpressionResultByFactorEnchance(localMap, factorEnchance);
-                        if (Constant.WARING_EVENT_ATTR_ID == factorEnchance.getEventAttrId()) {
-                            if (result) {
-                                insertWarningDetail(localMap, medicalInsRuleInfo, audit, itemList);
-                            }
-                        } else {
-                            localMap.put(getParamName(factorEnchance.getEventAttrId()), result);
+                    break;
+                case DICT:
+                    dictUtil.transferData(localMap, factorEnchance, medicalInfoRuleInfoId);
+                    break;
+                case PLUGIN:
+                    Map<Integer, List<FactorAttrRela>> ioTypeMap1 = getIoMap(factorEnchanceId);
+                    PluginInterface pluginInterface = (PluginInterface) SpringContextUtils.getBean(factorEnchance.getEnhanceValue());
+                    pluginInterface.plugin(localMap, ioTypeMap1, factorEnchance, medicalInfoRuleInfoId);
+                    break;
+                case CONSTANT:
+                    localMap.put(getParamName(factorEnchance.getEventAttrId()), factorEnchance.getExtAttr1());
+                    break;
+                case LOGICAL_EXPRESSION:
+                    result = setLogicalExpressionResultByFactorEnchance(localMap, factorEnchance);
+                    if (Constant.WARING_EVENT_ATTR_ID == factorEnchance.getEventAttrId()) {
+                        if (result) {
+                            insertWarningDetail(localMap, medicalInsRuleInfo, audit, itemList);
                         }
-                        break;
-                    case PROPERTIES:
-                        Object valueTemp = localMap.get(getParamName(Integer.parseInt(factorEnchance.getExtAttr1())));
-                        if (null == valueTemp) {
-                            log.error("要素提取:{} 规则ID:{} 常量赋值:{} 配置的属性:{}无值", factorEnchance.getId(), medicalInfoRuleInfoId, factorEnchance.getRuleEnchanceName(), factorEnchance.getExtAttr1());
-                        } else {
-                            localMap.put(getParamName(factorEnchance.getEventAttrId()), valueTemp);
-                        }
-                        break;
-                    default:
-                        log.error("有配置的未处理类型");
-                        break;
-                }
+                    } else {
+                        localMap.put(getParamName(factorEnchance.getEventAttrId()), result);
+                    }
+                    break;
+                case PROPERTIES:
+                    Object valueTemp = localMap.get(getParamName(Integer.parseInt(factorEnchance.getExtAttr1())));
+                    if (null == valueTemp) {
+                        log.error("要素提取:{} 规则ID:{} 常量赋值:{} 配置的属性:{}无值", factorEnchance.getId(), medicalInfoRuleInfoId, factorEnchance.getRuleEnchanceName(), factorEnchance.getExtAttr1());
+                    } else {
+                        localMap.put(getParamName(factorEnchance.getEventAttrId()), valueTemp);
+                    }
+                    break;
+                default:
+                    log.error("有配置的未处理类型");
+                    break;
             }
-        } finally {
-            currentThreadLocalMap.remove();
         }
+
         return result;
     }
 
@@ -285,6 +283,12 @@ public class FactorEnchangeFactory {
                 if (priceObj != null) {
                     afterwardsAuditDetail.setPrice(new BigDecimal(priceObj.toString()));
                 }
+                Object projectUseTime = otherMap.get(SystemEventAttrConstant.PROJECT_USE_TIME);
+                if (null != projectUseTime) {
+                    String projectUseTimeStr = DateUtil.formatDateTime((Date) projectUseTime);
+                    afterwardsAuditDetail.setProjectUseTime(projectUseTimeStr);
+                }
+
                 afterwardsAuditDetail.setCreateBy("auto");
                 afterwardsAuditDetail.setQuantity(otherMap.get(SystemEventAttrConstant.QUANTITY) != null ? Integer.parseInt(otherMap.get(SystemEventAttrConstant.QUANTITY).toString()) : 1);
                 afterwardsAuditDetail.setMedicalInsuranceMark(otherMap.get(Constant.MEDICAL_INSURANCE_MARK_KEY) != null ? otherMap.get(Constant.MEDICAL_INSURANCE_MARK_KEY).toString() : "0");
@@ -450,7 +454,28 @@ public class FactorEnchangeFactory {
             desc = descObject.toString();
         }
         if (null != desc && desc.contains("#")) {
-            Map<String,Object> itemMapTemp = currentThreadLocalMap.get();
+            Map<String, Object> itemMapTemp = new HashMap<>();
+            Object BProjectCode = SPELUtil.concurrentHashMap.get(Thread.currentThread().getName());
+            Object BProjectName = CommonUtil.getNameByCode(BProjectCode.toString());
+
+            if (null != BProjectName) {
+                itemMapTemp.put(Constant.BDESC, BProjectName);
+            } else {
+                List<String> projectCodeList = (List<String>) itemMap.get(SystemEventAttrConstant.MEDICAL_PROJECT_CODE_LSIT);
+                List<String> projectNameList = (List<String>) itemMap.get(SystemEventAttrConstant.MEDICAL_PROJECT_NAME_LIST);
+
+                for (int i = 0; i < projectCodeList.size(); i++) {
+                    String projectCode = projectCodeList.get(i);
+                    if (BProjectCode.toString().equals(projectCode)) {
+                        BProjectName = projectNameList.get(i);
+                    }
+                }
+                if (null == BProjectName) {
+                    BProjectName = BProjectCode;
+                }
+                itemMapTemp.put(Constant.BDESC, BProjectName);
+            }
+
             Object descSpel = spelUtil.getExpressionStr(itemMapTemp, desc);
             return descSpel.toString();
         }

+ 4 - 4
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/medical/ruleengine/RuleEngine.java

@@ -839,8 +839,8 @@ public class RuleEngine {
      * 把当前明细记录的主单下的所有项目编码设置到当前项目记录
      */
     public void setItemCodeListToItemMap(List<Map<String, Object>> itemList, Map<String, Object> itemMap) {
-        Set<String> medicalProjectCodeList = new HashSet<>();
-        Set<String> medicalProjectNameList = new HashSet<>();
+        List<String> medicalProjectCodeList = new ArrayList<>();
+        List<String> medicalProjectNameList = new ArrayList<>();
         for (Map<String, Object> itemTempMap : itemList) {
             Object medicalProjectCode = itemTempMap.get(SystemEventAttrConstant.MEDICAL_PROJECT_CODE_KEY);
             Object medicalProjectName = itemTempMap.get(SystemEventAttrConstant.MEDICAL_PROJECT_NAME_KEY);
@@ -849,8 +849,8 @@ public class RuleEngine {
                 medicalProjectNameList.add(medicalProjectName.toString());
             }
         }
-        itemMap.put(SystemEventAttrConstant.MEDICAL_PROJECT_NAME_LIST, new ArrayList<>(medicalProjectNameList));
-        itemMap.put(SystemEventAttrConstant.MEDICAL_PROJECT_CODE_LSIT, new ArrayList<>(medicalProjectCodeList));
+        itemMap.put(SystemEventAttrConstant.MEDICAL_PROJECT_NAME_LIST, medicalProjectNameList);
+        itemMap.put(SystemEventAttrConstant.MEDICAL_PROJECT_CODE_LSIT, medicalProjectCodeList);
     }
 
 

+ 6 - 31
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/medical/ruleengine/SPELUtil.java

@@ -27,6 +27,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -41,6 +42,9 @@ public class SPELUtil {
     @Autowired
     IEventAttrService eventAttrService;
 
+    public static ConcurrentHashMap concurrentHashMap = new ConcurrentHashMap();
+
+
     public String getSPELString(FactorCondRela factorCondRela, Map<Integer, EventAttr> enchanceAttrMap) {
         Integer operater = factorCondRela.getOperator();
         OperaterEnum operaterEnum = OperaterEnum.getType(operater);
@@ -284,38 +288,11 @@ public class SPELUtil {
 
         if (null != srcObj && null != memberObj) {
             boolean srcFlag = srcObj.toString().startsWith(memberObj.toString());
-            FactorEnchangeFactory.currentThreadLocalMap.get().put(Constant.ADESC, srcObj.toString());
-            FactorEnchangeFactory.currentThreadLocalMap.get().put(Constant.BDESC, memberObj.toString());
             return srcFlag;
         }
         return false;
     }
 
-    public static Boolean isMemberLeftObjectByList(Object inValue, List<Object> memberList) {
-
-        if (null != inValue && CollectionUtil.isNotEmpty(memberList)) {
-
-            if (inValue instanceof List) {
-                List<Object> lList = (List<Object>) inValue;
-                for (Object value : lList) {
-                    boolean flag = isMemberLeftObject(value, memberList);
-                    if (flag) {
-                        return true;
-                    }
-                }
-            }
-            if (memberList.contains(inValue)) {
-
-                return true;
-            }
-            for (Object member : memberList) {
-                if (startWithKey(member.toString(), inValue.toString())) {
-                    return true;
-                }
-            }
-        }
-        return false;
-    }
 
 
     public static Boolean isMemberLeftObject(Object inValue, List<Object> memberList) {
@@ -354,13 +331,11 @@ public class SPELUtil {
         if (CollectionUtil.isEmpty(rList) || CollectionUtil.isEmpty(lList)) {
             return false;
         }
-        List<String> medicalProjectNameList = (List<String>) FactorEnchangeFactory.currentThreadLocalMap.get().get(SystemEventAttrConstant.MEDICAL_PROJECT_NAME_LIST);
         for (int i=0;i<rList.size();i++) {
             Object value = rList.get(i);
-            Object valueName = medicalProjectNameList.get(i);
-            boolean flag = isMemberLeftObjectByList(value, lList);
+            concurrentHashMap.put(Thread.currentThread().getName(), value);
+            boolean flag = isMemberLeftObject(value, lList);
             if (flag) {
-                FactorEnchangeFactory.currentThreadLocalMap.get().put(Constant.BDESC, valueName);
                 return true;
             }
         }

+ 0 - 1
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/medical/ruleengine/plugin/GroupbyProjectCodeNumPlugin.java

@@ -41,7 +41,6 @@ public class GroupbyProjectCodeNumPlugin implements PluginInterface {
                     String projectCode = adviceMap.getOrDefault(SystemEventAttrConstant.MEDICAL_PROJECT_CODE_KEY, "").toString();
                     Object projectUseTime = adviceMap.get(SystemEventAttrConstant.PROJECT_USE_TIME);
                     String projectUseDay = CommonUtil.getProjectUseDay(projectUseTime);
-                    log.info("同批其他项目编码:{} 项目使用时间:{} 原始项目编码:{} 原始项目使用时间:{}", projectCode, projectUseDay, srcProjectCode, srcProjectUseDay);
                     Integer quaity = (Integer) adviceMap.getOrDefault(SystemEventAttrConstant.QUANTITY, 1);
                     if (StringUtils.isNotBlank(projectCode) && null != projectUseTime && projectCode.equals(srcProjectCode) && srcProjectUseDay.equals(projectUseDay)) {
                         projectNum = projectNum + quaity;