Browse Source

报告状态更新为已发布时,推送微信消息给患者

lighter 10 months ago
parent
commit
3d18c71180

+ 63 - 1
src/main/java/thyyxxk/webserver/controller/api/medicallaboratory/MedicalLaboratoryController.java

@@ -1,15 +1,22 @@
 package thyyxxk.webserver.controller.api.medicallaboratory;
 
+import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 import thyyxxk.webserver.config.auth.PassToken;
+import thyyxxk.webserver.config.exception.BizException;
 import thyyxxk.webserver.config.exception.ExceptionEnum;
+import thyyxxk.webserver.controller.api.medicallaboratory.model.Category;
 import thyyxxk.webserver.controller.api.medicallaboratory.model.State;
 import thyyxxk.webserver.dao.his.api.MedicalLaboratoryDao;
 import thyyxxk.webserver.entity.ResultVo;
+import thyyxxk.webserver.service.externalhttp.WxServer;
+import thyyxxk.webserver.utils.DateUtil;
 import thyyxxk.webserver.utils.ResultVoUtil;
 import thyyxxk.webserver.utils.StringUtil;
 
@@ -19,10 +26,12 @@ import java.util.Date;
 @RequestMapping("/medicalLaboratory")
 public class MedicalLaboratoryController {
     private final MedicalLaboratoryDao dao;
+    private final WxServer wxServer;
 
     @Autowired
-    public MedicalLaboratoryController(MedicalLaboratoryDao dao) {
+    public MedicalLaboratoryController(MedicalLaboratoryDao dao, WxServer wxServer) {
         this.dao = dao;
+        this.wxServer = wxServer;
     }
 
     @PassToken
@@ -67,6 +76,7 @@ public class MedicalLaboratoryController {
             if (null == body.getPublishTime()) {
                 return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "报告状态为[发布]时,发布时间不能为空。");
             }
+            pushWxMessage(body);
         }
         MedicalLaboratoryState existOne = dao.selectById(body.getReqNo());
         if (null == existOne) {
@@ -77,4 +87,56 @@ public class MedicalLaboratoryController {
         dao.updateById(body);
         return ResultVoUtil.success(body.getReqNo());
     }
+
+    private void pushWxMessage(MedicalLaboratoryState body) {
+        String xmLabel = getLabel(body.getCategory());
+        String firstData = StrUtil.format("您之前进行的{}项目已生成{}报告,详情如下:", xmLabel, xmLabel);
+        String pbtime = DateUtil.formatDate(body.getPublishTime());
+        String redirect = "https://staticweb.hnthyy.cn/wxserver/redirect/pathEntry?path=" + getPath(body);
+        String msgContent = "{\"touser\":\"\",\"data\":" +
+                "{" +
+                "\"first\":{\"color\":\"#FF0000\",\"value\":\"" + firstData + "\"}," +
+                "\"keyword1\":{\"color\":\"#173177\",\"value\":\"长沙泰和医院\"}," +
+                "\"keyword2\":{\"color\":\"#173177\",\"value\":\"" + body.getPatName() + "\"}," +
+                "\"keyword3\":{\"color\":\"#173177\",\"value\":\"" + body.getReportTitle() + "\"}," +
+                "\"keyword4\":{\"color\":\"#173177\",\"value\":\"" + pbtime + "\"}," +
+                "\"remark\":{\"color\":\"#FF0000\",\"value\":\"感谢您的使用,祝您健康!\"}," +
+                "}," +
+                "\"template_id\":\"5lfTTP5Iwx4dEwTB9ihhCDWm0PTkMDTzOUQVsyNaM50\"," +
+                "\"url\":\"" + redirect + "\"}";
+
+        JSONObject obj = new JSONObject();
+        obj.put("cardNo", body.getPatNo());
+        obj.put("msgContext", JSON.parseObject(msgContent));
+        wxServer.pushWxMessage(obj);
+    }
+
+    private String getLabel(Category category) {
+        switch (category) {
+            case JY:
+                return "检验";
+            case JC:
+                return "检查";
+            case XD:
+                return "心电";
+            case BL:
+                return "病理";
+        }
+        throw new BizException("不合法的项目类型!");
+    }
+
+    private String getPath(MedicalLaboratoryState body) {
+        String suffix = "_" + body.getPatNo();
+        switch (body.getCategory()) {
+            case JY:
+                return "checkExamIndex" + suffix;
+            case JC:
+                return "checkTestIndex" + suffix;
+            case XD:
+                return "checkElectroIndex" + suffix;
+            case BL:
+                return "checkPathologyIndex" + suffix;
+        }
+        throw new BizException("不合法的项目类型!");
+    }
 }

+ 1 - 2
src/main/java/thyyxxk/webserver/service/externalhttp/WxServer.java

@@ -15,10 +15,9 @@ public interface WxServer {
      * @author: lihong
      * @date: 2023/6/7 10:39
      * @param: obj
-     * @return: com.alibaba.fastjson.JSONObject
      **/
     @Post(url = "https://staticweb.hnthyy.cn/wxserver/wxApi/pushMessage")
-    JSONObject pushMessagePreBedNo(@JSONBody JSONObject obj);
+    void pushWxMessage(@JSONBody JSONObject obj);
 
     @Post(url = "https://staticweb.hnthyy.cn/wxserver/wxApi/pushMessage2")
     String pushMessage2(@JSONBody JSONObject obj);

+ 1 - 1
src/main/java/thyyxxk/webserver/service/medicaladvice/patientinfo/AdjustBedService.java

@@ -294,7 +294,7 @@ public class AdjustBedService {
         jsonObject.put("isCardNoPatientId", true);
         jsonObject.put("msgContext", JSON.parseObject(msgContentJson));
         log.info("调用微信接口参数入参{}", JSON.toJSONString(jsonObject));
-        wxServer.pushMessagePreBedNo(jsonObject);
+        wxServer.pushWxMessage(jsonObject);
     }
 
 }