zhoutg před 4 roky
rodič
revize
7f059ea000
1 změnil soubory, kde provedl 70 přidání a 66 odebrání
  1. 70 66
      src/main/java/com/diagbot/util/CoreUtil.java

+ 70 - 66
src/main/java/com/diagbot/util/CoreUtil.java

@@ -56,7 +56,7 @@ public class CoreUtil {
         }
         for (T t : list) {
             try {
-                String val = (String)getFieldValue(t, propertyName);
+                String val = (String) getFieldValue(t, propertyName);
                 if (StringUtil.isNotBlank(val)) {
                     res.add(val);
                 }
@@ -101,8 +101,8 @@ public class CoreUtil {
         return res;
     }
 
-    public static <T> void  setPropertyList(T list, String propertyName, String standName, Map<String, String> map) {
-        if(list == null){
+    public static <T> void setPropertyList(T list, String propertyName, String standName, Map<String, String> map) {
+        if (list == null) {
             return;
         }
         try {
@@ -127,19 +127,20 @@ public class CoreUtil {
 
     /**
      * 循环向上转型, 获取对象的 DeclaredField
-     * @param object : 子类对象
+     *
+     * @param object    : 子类对象
      * @param fieldName : 父类中的属性名
      * @return 父类中的属性对象
      */
-    public static Field getDeclaredField(Object object, String fieldName){
-        Field field = null ;
+    public static Field getDeclaredField(Object object, String fieldName) {
+        Field field = null;
 
-        Class<?> clazz = object.getClass() ;
+        Class<?> clazz = object.getClass();
 
-        for(; clazz != Object.class ; clazz = clazz.getSuperclass()) {
+        for (; clazz != Object.class; clazz = clazz.getSuperclass()) {
             try {
-                field = clazz.getDeclaredField(fieldName) ;
-                return field ;
+                field = clazz.getDeclaredField(fieldName);
+                return field;
             } catch (Exception e) {
                 //这里甚么都不要做!并且这里的异常必须这样写,不能抛出去。
                 //如果这里的异常打印或者往外抛,则就不会执行clazz = clazz.getSuperclass(),最后就不会进入到父类中了
@@ -151,49 +152,51 @@ public class CoreUtil {
 
     /**
      * 直接读取对象的属性值, 忽略 private/protected 修饰符, 也不经过 getter
-     * @param object : 子类对象
+     *
+     * @param object    : 子类对象
      * @param fieldName : 父类中的属性名
      * @return : 父类中的属性值
      */
-    public static Object getFieldValue(Object object, String fieldName){
+    public static Object getFieldValue(Object object, String fieldName) {
         //根据 对象和属性名通过反射 调用上面的方法获取 Field对象
-        Field field = getDeclaredField(object, fieldName) ;
+        Field field = getDeclaredField(object, fieldName);
 
         //抑制Java对其的检查
-        field.setAccessible(true) ;
+        field.setAccessible(true);
 
         try {
             //获取 object 中 field 所代表的属性值
-            return field.get(object) ;
+            return field.get(object);
 
-        } catch(Exception e) {
-            e.printStackTrace() ;
+        } catch (Exception e) {
+            e.printStackTrace();
         }
         return null;
     }
 
     /**
      * 直接设置对象属性值, 忽略 private/protected 修饰符, 也不经过 setter
-     * @param object : 子类对象
-     * @param name : 父类中的属性名
+     *
+     * @param object    : 子类对象
+     * @param name      : 父类中的属性名
      * @param standName : 要替换的属性名
-     * @param value : 将要设置的值
+     * @param value     : 将要设置的值
      */
-    public static void setFieldValue(Object object, String name, String standName, Map<String, String> value){
+    public static void setFieldValue(Object object, String name, String standName, Map<String, String> value) {
         //根据 对象和属性名通过反射 调用上面的方法获取 Field对象
-        Field field = getDeclaredField(object, name) ;
+        Field field = getDeclaredField(object, name);
 
         //抑制Java对其的检查
-        field.setAccessible(true) ;
+        field.setAccessible(true);
 
         try {
             //将 object 中 field 所代表的值 设置为 value
-            String key = (String)field.get(object);
+            String key = (String) field.get(object);
             if (value != null && value.get(key) != null) {
-                Field standField = getDeclaredField(object, standName) ;
+                Field standField = getDeclaredField(object, standName);
                 standField.setAccessible(true);
                 if ("uniqueName".equals(standName)) {
-                    String uniqueName = (String)standField.get(object);
+                    String uniqueName = (String) standField.get(object);
                     if (StringUtil.isBlank(uniqueName)) {
                         standField.set(object, value.get(key));
                     }
@@ -209,14 +212,14 @@ public class CoreUtil {
 
     }
 
-    public static <T> List<String> setPropertyList(List<T> list, String name, String detailName,String uniqueName, Map<String, String> map) {
+    public static <T> List<String> setPropertyList(List<T> list, String name, String detailName, String uniqueName, Map<String, String> map) {
         List<String> res = new ArrayList<>();
         if (ListUtil.isEmpty(list)) {
             return res;
         }
         for (T t : list) {
             try {
-                setFieldValue(t, name, detailName,uniqueName, map);
+                setFieldValue(t, name, detailName, uniqueName, map);
             } catch (Exception e) {
                 e.printStackTrace();
             }
@@ -224,23 +227,23 @@ public class CoreUtil {
         return res;
     }
 
-    public static void setFieldValue(Object object, String name, String standName,String unique, Map<String, String> value){
+    public static void setFieldValue(Object object, String name, String standName, String unique, Map<String, String> value) {
         //根据 对象和属性名通过反射 调用上面的方法获取 Field对象
-        Field field = getDeclaredField(object, name) ;
-        Field field1 = getDeclaredField(object, standName) ;
+        Field field = getDeclaredField(object, name);
+        Field field1 = getDeclaredField(object, standName);
         //抑制Java对其的检查
-        field.setAccessible(true) ;
-        field1.setAccessible(true) ;
+        field.setAccessible(true);
+        field1.setAccessible(true);
 
         try {
             //将 object 中 field 所代表的值 设置为 value
-            String key = (String)field.get(object);
-            String key1 = (String)field1.get(object);
-//            String lis_c = key+key1;
+            String key = (String) field.get(object);
+            String key1 = (String) field1.get(object);
+            //            String lis_c = key+key1;
             String lis_c = key1;
             if (value != null && value.get(lis_c) != null) {
-                Field standField = getDeclaredField(object, unique) ;
-                standField.setAccessible(true) ;
+                Field standField = getDeclaredField(object, unique);
+                standField.setAccessible(true);
                 standField.set(object, value.get(lis_c));
             }
         } catch (IllegalArgumentException e) {
@@ -286,7 +289,7 @@ public class CoreUtil {
             Map mapLis = CoreUtil.compareLis(ruleBaseDTO, lis);
             if (CoreUtil.getMapFlag(mapLis)) {
                 flag = true;
-                msgList.add((String)mapLis.get("msg"));
+                msgList.add((String) mapLis.get("msg"));
             }
         }
         map.put("flag", flag);
@@ -416,7 +419,7 @@ public class CoreUtil {
                 if (value < max) {
                     maxFlag = true;
                 }
-            } else if ("<=".equals(ruleBaseDTO.getBaseMaxOperator())){
+            } else if ("<=".equals(ruleBaseDTO.getBaseMaxOperator())) {
                 if (value <= max) {
                     maxFlag = true;
                 }
@@ -427,7 +430,7 @@ public class CoreUtil {
                 if (value > min) {
                     minFlag = true;
                 }
-            } else if (">=".equals(ruleBaseDTO.getBaseMinOperator())){
+            } else if (">=".equals(ruleBaseDTO.getBaseMinOperator())) {
                 if (value >= min) {
                     minFlag = true;
                 }
@@ -455,8 +458,8 @@ public class CoreUtil {
         return flag;
     }
 
-    public static String subZeroAndDot(String s){
-        if(s.indexOf(".") > 0){
+    public static String subZeroAndDot(String s) {
+        if (s.indexOf(".") > 0) {
             s = s.replaceAll("0+?$", "");//去掉多余的0
             s = s.replaceAll("[.]$", "");//如最后一位是.则去掉
         }
@@ -465,10 +468,11 @@ public class CoreUtil {
 
     /**
      * list 转 string
+     *
      * @param list
      * @return
      */
-    public static  String listConvertString(List<String> list){
+    public static String listConvertString(List<String> list) {
         return StringUtils.join(list, ",");
     }
 
@@ -481,7 +485,7 @@ public class CoreUtil {
      */
     public static void getDebugStr(long start, String msg, Map<String, Object> debugMap) {
         long end = System.currentTimeMillis();
-        debugMap.put(msg,  + (end - start) / 1000.0 + "秒");
+        debugMap.put(msg, +(end - start) / 1000.0 + "秒");
     }
 
     /**
@@ -517,7 +521,7 @@ public class CoreUtil {
      * @param debugMap
      */
     public static void getDebugStr(String msg, Object error, Map<String, Object> debugMap) {
-        debugMap.put(msg,  error);
+        debugMap.put(msg, error);
     }
 
     /**
@@ -549,7 +553,7 @@ public class CoreUtil {
                 String[] ageArr = new String[2];
                 int indexSui = ageStr.indexOf("岁");
                 ageArr[0] = ageStr.substring(0, indexSui);
-                ageArr[1] = ageStr.substring(indexSui + 1,ageStr.indexOf("个月"));
+                ageArr[1] = ageStr.substring(indexSui + 1, ageStr.indexOf("个月"));
                 return Double.parseDouble(ageArr[0]) + getHalfUp(Double.parseDouble(ageArr[1]) / 12);
             }
             // 1.08月 | .11月 | 3月
@@ -674,7 +678,7 @@ public class CoreUtil {
     public static <T> void addAllConvert(List<Item> source, List<T> convertList) {
         List<Item> other = convertItem(convertList);
         if (ListUtil.isEmpty(other)) {
-            return ;
+            return;
         }
         if (source == null) {
             source = new ArrayList<>();
@@ -692,11 +696,11 @@ public class CoreUtil {
         List<Item> itemList = new ArrayList<>();
         if (ListUtil.isNotEmpty(convertList)) {
             for (T t : convertList) {
-                Negative negative = (Negative)CoreUtil.getFieldValue(t, "negative");
+                Negative negative = (Negative) CoreUtil.getFieldValue(t, "negative");
                 if (negative == null) {
                     Item item = new Item();
-                    item.setName((String)CoreUtil.getFieldValue(t, "name"));
-                    item.setUniqueName((String)CoreUtil.getFieldValue(t, "standName"));
+                    item.setName((String) CoreUtil.getFieldValue(t, "name"));
+                    item.setUniqueName((String) CoreUtil.getFieldValue(t, "standName"));
                     itemList.add(item);
                 }
             }
@@ -725,7 +729,7 @@ public class CoreUtil {
      */
     public static List<String> getMapMsgList(Map map) {
         if (map != null && map.get("flag") != null && (Boolean) map.get("flag") == true) {
-            List<String> msgList = (List<String>)map.get("msgList");
+            List<String> msgList = (List<String>) map.get("msgList");
             if (ListUtil.isEmpty(msgList)) {
                 return new ArrayList<>();
             } else {
@@ -744,7 +748,7 @@ public class CoreUtil {
      */
     public static <T> void addList(List<T> source, List<? extends T> addList) {
         if (source == null) {
-            return ;
+            return;
         }
         if (ListUtil.isNotEmpty(addList)) {
             source.addAll(addList);
@@ -760,7 +764,7 @@ public class CoreUtil {
      */
     public static <T> void addSet(Set<T> source, List<? extends T> addList) {
         if (source == null) {
-            return ;
+            return;
         }
         if (ListUtil.isNotEmpty(addList)) {
             source.addAll(addList);
@@ -779,8 +783,8 @@ public class CoreUtil {
             return new ArrayList<>();
         }
         return list.stream()
-                .filter(r -> StringUtil.isBlank((String)getFieldValue(r, "uniqueName")))
-                .map(r -> (String)getFieldValue(r, targetProperty))
+                .filter(r -> StringUtil.isBlank((String) getFieldValue(r, "uniqueName")))
+                .map(r -> (String) getFieldValue(r, targetProperty))
                 .collect(Collectors.toList());
     }
 
@@ -796,8 +800,8 @@ public class CoreUtil {
             return new ArrayList<>();
         }
         return list.stream()
-                .filter(r -> StringUtil.isNotBlank((String)getFieldValue(r, "name")))
-                .map(r -> (String)getFieldValue(r, "name"))
+                .filter(r -> StringUtil.isNotBlank((String) getFieldValue(r, "name")))
+                .map(r -> (String) getFieldValue(r, "name"))
                 .collect(Collectors.toList());
     }
 
@@ -819,7 +823,7 @@ public class CoreUtil {
             if (StringUtil.isNotBlank(name)) {
                 res.add(name);
             }
-            BodyPart bodyPart = (BodyPart)getFieldValue(t, "bodyPart");
+            BodyPart bodyPart = (BodyPart) getFieldValue(t, "bodyPart");
             if (bodyPart != null && StringUtil.isNotBlank(bodyPart.getName())) {
                 res.add(bodyPart.getName() + name);
             }
@@ -841,7 +845,7 @@ public class CoreUtil {
         }
         for (T t : list) {
             // 刨去体温,脉搏,数值类型的体征数据
-            PD pd = (PD)getFieldValue(t, "pd");
+            PD pd = (PD) getFieldValue(t, "pd");
             if (pd == null || (pd != null && StringUtil.isNotBlank(pd.getUnit()))) {
                 continue;
             }
@@ -851,7 +855,7 @@ public class CoreUtil {
                 // 查体结果
                 res.add(name + pd.getName());
                 // 查体部位 + 查体结果
-                BodyPart bodyPart = (BodyPart)getFieldValue(t, "bodyPart");
+                BodyPart bodyPart = (BodyPart) getFieldValue(t, "bodyPart");
                 if (bodyPart != null && StringUtil.isNotBlank(bodyPart.getName())) {
                     res.add(bodyPart.getName() + name + pd.getName());
                 }
@@ -872,8 +876,8 @@ public class CoreUtil {
             return new ArrayList<>();
         }
         return list.stream()
-                .filter(r -> StringUtil.isBlank((String)getFieldValue(r, "uniqueName")))
-                .map(r -> (String)getFieldValue(r, "name"))
+                .filter(r -> StringUtil.isBlank((String) getFieldValue(r, "uniqueName")))
+                .map(r -> (String) getFieldValue(r, "name"))
                 .collect(Collectors.toList());
     }
 
@@ -881,8 +885,8 @@ public class CoreUtil {
         Map<String, List<V>> map = new LinkedHashMap();
         if (ListUtil.isNotEmpty(list)) {
             for (V v : list) {
-                String value1 = (String)CoreUtil.getFieldValue(v, field1);
-                String value2 = (String)CoreUtil.getFieldValue(v, field2);
+                String value1 = (String) CoreUtil.getFieldValue(v, field1);
+                String value2 = (String) CoreUtil.getFieldValue(v, field2);
                 String unionKey = "";
                 if (StringUtil.isNotBlank(value1)) {
                     unionKey += value1;
@@ -891,7 +895,7 @@ public class CoreUtil {
                 if (StringUtil.isNotBlank(value2)) {
                     unionKey += value2;
                 }
-                List<V> groupList = (List<V>)map.get(unionKey);
+                List<V> groupList = (List<V>) map.get(unionKey);
                 if (groupList == null) {
                     groupList = new ArrayList();
                 }