瀏覽代碼

年龄工具类从common调用

zhoutg 3 年之前
父節點
當前提交
348f573409

+ 2 - 1
src/main/java/com/diagbot/facade/CommonFacade.java

@@ -30,6 +30,7 @@ import com.diagbot.model.label.PastLabel;
 import com.diagbot.model.label.PresentLabel;
 import com.diagbot.model.label.VitalLabel;
 import com.diagbot.rule.CommonRule;
+import com.diagbot.util.AgeUtil;
 import com.diagbot.util.BeanUtil;
 import com.diagbot.util.CoreUtil;
 import com.diagbot.util.ListUtil;
@@ -120,7 +121,7 @@ public class CommonFacade {
         if (searchData.getAgeNum() != null) {
             wordCrfDTO.setAgeNum(searchData.getAgeNum());
         } else {
-            wordCrfDTO.setAgeNum(CoreUtil.convertAge(searchData.getAge()));
+            wordCrfDTO.setAgeNum(AgeUtil.convertAge(searchData.getAge()));
         }
         wordCrfDTO.setAge(searchData.getAge());
         wordCrfDTO.setSex(searchData.getSex());

+ 2 - 1
src/main/java/com/diagbot/facade/PushFacade.java

@@ -13,6 +13,7 @@ import com.diagbot.exception.CommonErrorCode;
 import com.diagbot.exception.CommonException;
 import com.diagbot.model.entity.Diag;
 import com.diagbot.process.PushProcess;
+import com.diagbot.util.AgeUtil;
 import com.diagbot.util.CoreUtil;
 import com.diagbot.util.ListUtil;
 import com.diagbot.util.ParamUtil;
@@ -101,7 +102,7 @@ public class PushFacade {
     public PushDTO processAggreate(PushVO pushVo) {
         // 年龄容错处理
         if (pushVo.getAgeNum() == null) {
-            pushVo.setAgeNum(CoreUtil.convertAge(pushVo.getAge()));
+            pushVo.setAgeNum(AgeUtil.convertAge(pushVo.getAge()));
         }
         PushDTO pushDTO = new PushDTO();
         pushDTO = this.pushFacIcss(pushVo);

+ 0 - 98
src/main/java/com/diagbot/util/CoreUtil.java

@@ -19,7 +19,6 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 
 import java.lang.reflect.Field;
-import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Date;
@@ -680,69 +679,6 @@ public class CoreUtil {
         debugMap.put(msg, error);
     }
 
-    /**
-     * 年龄字符串转换成double类型
-     *
-     * @param ageStr
-     * @return
-     */
-    public static Double convertAge(String ageStr) {
-        try {
-            // 防止程序出错
-            if (StringUtil.isEmpty(ageStr)) {
-                return 20.0;
-            }
-            // 数值,当成年龄处理
-            if (isNumbers(ageStr)) {
-                return Double.parseDouble(ageStr);
-            }
-            // 20日 | 20天
-            if (ageStr.endsWith("日") || ageStr.endsWith("天")) {
-                return getHalfUp((Double.parseDouble(ageStr.substring(0, ageStr.length() - 1))) / 365);
-            }
-            // 3岁
-            if (ageStr.endsWith("岁")) {
-                return Double.parseDouble(ageStr.substring(0, ageStr.length() - 1));
-            }
-            // 3岁7个月 | 3岁7月
-            if (ageSuiYue(ageStr)) {
-                String[] ageArr = new String[2];
-                int indexSui = ageStr.indexOf("岁");
-                ageArr[0] = ageStr.substring(0, indexSui);
-                if (ageStr.indexOf("个月") > -1) { // 3岁7个月
-                    ageArr[1] = ageStr.substring(indexSui + 1, ageStr.indexOf("个月"));
-                } else { // 3岁7月
-                    ageArr[1] = ageStr.substring(indexSui + 1, ageStr.indexOf("月"));
-                }
-                return Double.parseDouble(ageArr[0]) + getHalfUp(Double.parseDouble(ageArr[1]) / 12);
-            }
-            // 1.08月 | .11月 | 3月
-            if (ageYue(ageStr)) {
-                String noUnit = ageStr.substring(0, ageStr.length() - 1);
-                // String[] ageArr = new String[2];
-                // String[] splitArr = noUnit.split("\\.");
-                // if (splitArr.length == 1) {
-                //     ageArr[0] = splitArr[0];
-                // } else if (splitArr.length == 2) {
-                //     ageArr[0] = splitArr[0];
-                //     ageArr[1] = splitArr[1];
-                // }
-                // Double daySum = 0.0D;
-                // if (StringUtil.isNotBlank(ageArr[0])) {
-                //     daySum += Double.parseDouble(ageArr[0]) * 30;
-                // }
-                // if (StringUtil.isNotBlank(ageArr[1])) {
-                //     daySum += Double.parseDouble(ageArr[1]);
-                // }
-                return getHalfUp(Double.parseDouble(noUnit) / 12);
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-            return 20.0;
-        }
-        return 20.0;
-    }
-
     /**
      * 判断字符串是否 仅 包含数字
      *
@@ -765,40 +701,6 @@ public class CoreUtil {
         return str.matches(regex);
     }
 
-
-    /**
-     * 判断年龄字符串:1.08月
-     *
-     * @param str
-     * @return
-     */
-    public static boolean ageYue(String str) {
-        String regex = "^[0-9]*[\\.]*[0-9]{1,2}月$";
-        return str.matches(regex);
-    }
-
-    /**
-     * 判断年龄字符串:3岁7个月
-     *
-     * @param str
-     * @return
-     */
-    public static boolean ageSuiYue(String str) {
-        String regex = "^[0-9]{1,3}岁[0-9]{1,2}个{0,1}月$";
-        return str.matches(regex);
-    }
-
-    /**
-     * 四舍五入保留2位小数
-     *
-     * @param ageStr
-     * @return
-     */
-    public static Double getHalfUp(Double ageStr) {
-        BigDecimal bg = new BigDecimal(String.valueOf(ageStr));
-        return bg.setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
-    }
-
     /**
      * 替换首位的标点符号(例如:既往史提取“铁)
      *