Преглед на файлове

代码优化,方法优化

gaodm преди 6 години
родител
ревизия
d38ec12e5a

+ 10 - 0
common/src/main/java/com/diagbot/util/ArrayUtil.java

@@ -18,6 +18,16 @@ public class ArrayUtil {
         return ArrayUtils.isEmpty(array);
     }
 
+    /**
+     * 判断数组是否不为空
+     *
+     * @param array 数组
+     * @return 是否为空
+     */
+    public static boolean isNotEmpty(Object[] array) {
+        return !ArrayUtils.isEmpty(array);
+    }
+
     /**
      * 数组合并
      *

+ 41 - 0
common/src/main/java/com/diagbot/util/RespDTOUtil.java

@@ -0,0 +1,41 @@
+package com.diagbot.util;
+
+import com.diagbot.dto.RespDTO;
+import com.diagbot.exception.CommonErrorCode;
+
+/**
+ * @Description: 结果验证工具类
+ * @author: gaodm
+ * @time: 2019/3/12 18:25
+ */
+public class RespDTOUtil {
+
+    /**
+     * 远程调度是否成功
+     * @param respDTO 返回结果
+     * @param <T> 泛型
+     * @return 是否成功
+     */
+    public static <T> boolean respIsOK(RespDTO<T> respDTO){
+        if (respDTO == null
+                || !CommonErrorCode.OK.getCode().equals(respDTO.code)) {
+            return false;
+        }
+        return true;
+    }
+
+
+    /**
+     * 远程调度是否不成功
+     * @param respDTO 返回结果
+     * @param <T> 泛型
+     * @return 是否成功
+     */
+    public static <T> boolean respIsNG(RespDTO<T> respDTO){
+        if (respDTO == null
+                || !CommonErrorCode.OK.getCode().equals(respDTO.code)) {
+            return true;
+        }
+        return false;
+    }
+}

+ 17 - 5
icss-service/src/main/java/com/diagbot/facade/IntroduceInfoFacade.java

@@ -14,8 +14,10 @@ import com.diagbot.enums.QuestionTypeEnum;
 import com.diagbot.exception.CommonErrorCode;
 import com.diagbot.exception.CommonException;
 import com.diagbot.service.impl.IntroduceInfoServiceImpl;
+import com.diagbot.util.ArrayUtil;
 import com.diagbot.util.BeanUtil;
 import com.diagbot.util.ListUtil;
+import com.diagbot.util.RespDTOUtil;
 import com.diagbot.util.StringUtil;
 import com.diagbot.vo.EMRIntroduceVO;
 import com.diagbot.vo.HosCodeVO;
@@ -161,18 +163,28 @@ public class IntroduceInfoFacade extends IntroduceInfoServiceImpl {
         String uniqueName = "";
         Integer type = emrIntroduceVO.getType();
         if (type.equals(QuestionTypeEnum.Lis.getKey())) {
-            if (StringUtil.isNotBlank(emrIntroduceVO.getName()))
+            if (StringUtil.isNotBlank(emrIntroduceVO.getName())) {
                 if (StringUtil.isNotBlank(emrIntroduceVO.getDetailName())) {
                     RespDTO<Map<String, Map<String, String>>> respLisConfigMap = tranServiceClient.getLisConfigByHosCode_NotEmptyItemName(hosCodeVO);
+                    if (RespDTOUtil.respIsNG(respLisConfigMap)) {
+                        throw new CommonException(CommonErrorCode.RPC_ERROR);
+                    }
                     Map<String, Map<String, String>> lisConfigMap = respLisConfigMap.data;
                     uniqueName = lisConfigMap.get(emrIntroduceVO.getName()).get(emrIntroduceVO.getDetailName());
                 } else {
                     RespDTO<Map<String, String>> respLisConfigMap_emptyItemName = tranServiceClient.getLisConfigByHosCode_EmptyItemName(hosCodeVO);
+                    if (RespDTOUtil.respIsNG(respLisConfigMap_emptyItemName)) {
+                        throw new CommonException(CommonErrorCode.RPC_ERROR);
+                    }
                     Map<String, String> lisConfigMap_emptyItemName = respLisConfigMap_emptyItemName.data;
                     uniqueName = lisConfigMap_emptyItemName.get(emrIntroduceVO.getName());
                 }
+            }
         } else if (type.equals(QuestionTypeEnum.Pacs.getKey())) {
             RespDTO<Map<String, String>> respPacsConfigMap = tranServiceClient.getPacsConfigByHosCode(hosCodeVO);
+            if (RespDTOUtil.respIsNG(respPacsConfigMap)) {
+                throw new CommonException(CommonErrorCode.RPC_ERROR);
+            }
             Map<String, String> pacsConfigMap = respPacsConfigMap.data;
             uniqueName = pacsConfigMap.get(emrIntroduceVO.getName());
         }
@@ -187,7 +199,7 @@ public class IntroduceInfoFacade extends IntroduceInfoServiceImpl {
         String[] titles = emrIntroduceVO.getTitles();
         Map<String, String> titleMapping = new LinkedHashMap<>();
         List<String> uniqueTitleList = Lists.newLinkedList();
-        if (titles.length > 0) {
+        if (ArrayUtil.isNotEmpty(titles)) {
             for (String title : titles) {
                 String uniqueTitle = titleMappingMap.get(title);
                 titleMapping.put(title, uniqueTitle);
@@ -220,8 +232,8 @@ public class IntroduceInfoFacade extends IntroduceInfoServiceImpl {
                 eq("introduce_id", introduceMap.getIntroduceId()).
                 orderByAsc("order_no");
         //如果标题列表未传,全部返回
-        if (emrIntroduceVO.getTitles().length > 0) {
-            if (uniqueTitleList.size() > 0) {
+        if (ArrayUtil.isNotEmpty(emrIntroduceVO.getTitles())) {
+            if (ListUtil.isNotEmpty(uniqueTitleList)) {
                 introduceDetailQueryWrapper.in("title", uniqueTitleList);
             } else {
                 //标题未匹配上,不返回数据,加一个不成立的条件
@@ -230,7 +242,7 @@ public class IntroduceInfoFacade extends IntroduceInfoServiceImpl {
         }
         List<IntroduceDetail> introduceDetailList = introduceDetailFacade.list(introduceDetailQueryWrapper);
         List<EMRIntroduceDetailDTO> retList = Lists.newLinkedList();
-        if (emrIntroduceVO.getTitles().length > 0) {
+        if (ArrayUtil.isNotEmpty(emrIntroduceVO.getTitles())) {
             for (Map.Entry<String, String> entry : titleMapping.entrySet()) {
                 EMRIntroduceDetailDTO detailDTO = new EMRIntroduceDetailDTO();
                 detailDTO.setTitle(entry.getKey());

+ 2 - 1
icss-service/src/main/java/com/diagbot/web/EMRController.java

@@ -20,13 +20,14 @@ import javax.validation.Valid;
 import java.util.List;
 
 /**
- * @Description:
+ * @Description: 电子病历评级
  * @Author:zhaops
  * @time: 2019/3/12 15:07
  */
 @RestController
 @RequestMapping("/emr")
 @Api(value = "电子病历评级相关API", tags = { "电子病历评级相关API" })
+@SuppressWarnings("unchecked")
 public class EMRController {
     @Autowired
     IntroduceInfoFacade introduceInfoFacade;