Переглянути джерело

页面推送模式静态知识缓存

gaodm 5 роки тому
батько
коміт
ec7d881357

+ 38 - 0
data-service/src/main/java/com/diagbot/facade/ConceptDetailCacheFacade.java

@@ -0,0 +1,38 @@
+package com.diagbot.facade;
+
+import com.diagbot.client.AiptServiceClient;
+import com.diagbot.dto.ConceptIntroduceDTO;
+import com.diagbot.dto.RespDTO;
+import com.diagbot.util.ListUtil;
+import com.diagbot.util.RespDTOUtil;
+import com.diagbot.vo.ConceptIntroduceVO;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @Description:
+ * @Author:zhaops
+ * @time: 2019/5/14 9:49
+ */
+@Component
+public class ConceptDetailCacheFacade {
+    @Autowired
+    private AiptServiceClient aiptServiceClient;
+
+    /**
+     * 获取提示信息
+     *
+     * @param conceptIntroduceVO
+     * @return
+     */
+    @Cacheable(value = "data-service", key = "'ConceptDetail:name_' + #conceptIntroduceVO.name + '_type_' + #conceptIntroduceVO.type+ '_pos_' + #conceptIntroduceVO.position")
+    public ConceptIntroduceDTO getConceptDetail(ConceptIntroduceVO conceptIntroduceVO) {
+        RespDTO<ConceptIntroduceDTO> res = aiptServiceClient.getConceptDetail(conceptIntroduceVO);
+        RespDTOUtil.respNGDeal(res, "获取静态知识失败");
+        return res.data;
+    }
+}

+ 15 - 10
data-service/src/main/java/com/diagbot/facade/ConceptDetailFacade.java

@@ -1,13 +1,12 @@
 package com.diagbot.facade;
 
-import com.diagbot.client.AiptServiceClient;
 import com.diagbot.dto.ConceptIntroduceDTO;
-import com.diagbot.dto.RespDTO;
-import com.diagbot.util.RespDTOUtil;
+import com.diagbot.util.ListUtil;
 import com.diagbot.vo.ConceptIntroduceVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -18,7 +17,7 @@ import java.util.List;
 @Component
 public class ConceptDetailFacade {
     @Autowired
-    private AiptServiceClient aiptServiceClient;
+    private ConceptDetailCacheFacade conceptDetailCacheFacade;
 
     /**
      * 获取提示信息
@@ -27,9 +26,7 @@ public class ConceptDetailFacade {
      * @return
      */
     public ConceptIntroduceDTO getConceptDetail(ConceptIntroduceVO conceptIntroduceVO) {
-        RespDTO<ConceptIntroduceDTO> res = aiptServiceClient.getConceptDetail(conceptIntroduceVO);
-        RespDTOUtil.respNGDeal(res, "获取静态知识失败");
-        return res.data;
+        return conceptDetailCacheFacade.getConceptDetail(conceptIntroduceVO);
     }
 
     /**
@@ -39,8 +36,16 @@ public class ConceptDetailFacade {
      * @return
      */
     public List<ConceptIntroduceDTO> getConceptDetails(List<ConceptIntroduceVO> conceptIntroduceVOList) {
-        RespDTO<List<ConceptIntroduceDTO>> res = aiptServiceClient.getConceptDetails(conceptIntroduceVOList);
-        RespDTOUtil.respNGDeal(res, "获取静态知识失败");
-        return res.data;
+        List<ConceptIntroduceDTO> res = new ArrayList<>();
+        if (ListUtil.isNotEmpty(conceptIntroduceVOList)) {
+            for (ConceptIntroduceVO conceptIntroduceVO : conceptIntroduceVOList) {
+                ConceptIntroduceDTO conceptIntroduceDTO
+                        = conceptDetailCacheFacade.getConceptDetail(conceptIntroduceVO);
+                if (null != conceptIntroduceDTO) {
+                    res.add(conceptIntroduceDTO);
+                }
+            }
+        }
+        return res;
     }
 }

+ 2 - 2
data-service/src/main/java/com/diagbot/web/ConceptDetailController.java

@@ -30,7 +30,7 @@ public class ConceptDetailController {
     @Autowired
     private ConceptDetailFacade conceptDetailFacade;
 
-    @ApiOperation(value = "获取提示信息[by:zhaops]",
+    @ApiOperation(value = "[已加缓存]获取提示信息[by:zhaops]",
             notes = "name: 标签名称,必填<br>" +
                     "type:标签类型(1-症状,5-化验,6-辅检,7-诊断,8-药品,9-药品大类,10-不良反应,11-药品小类,12-化验公表项,22-指标,25-手术),单选必填<br>" +
                     "titles:提示信息标题列表,数组选填<br>" +
@@ -42,7 +42,7 @@ public class ConceptDetailController {
         return RespDTO.onSuc(data);
     }
 
-    @ApiOperation(value = "批量获取提示信息[by:zhaops]",
+    @ApiOperation(value = "[已加缓存]批量获取提示信息[by:zhaops]",
             notes = "conceptIntorduces:数组,必填<br>" +
                     "name: 标签名称,必填<br>" +
                     "type:标签类型(1-症状,5-化验,6-辅检,7-诊断,8-药品,9-药品大类,10-不良反应,11-药品小类,12-化验公表项,22-指标,25-手术),单选必填<br>" +