新增和HIS交互的接口

master
wangsq 2 years ago
parent 6772f8942a
commit 949b63c5bb
  1. 23
      pom.xml
  2. 14
      src/main/java/com/ynxbd/push/controller/BusinessController.java
  3. 35
      src/main/java/com/ynxbd/push/entity/enums/HisApiEnum.java
  4. 159
      src/main/java/com/ynxbd/push/entity/enums/MsgParamEnum.java
  5. 4
      src/main/java/com/ynxbd/push/entity/response/ResponseResult.java
  6. 38
      src/main/java/com/ynxbd/push/entity/tencent/SendTemplate.java
  7. 19
      src/main/java/com/ynxbd/push/entity/type/MessageTypeEnum.java
  8. 4
      src/main/java/com/ynxbd/push/helper/DesEncryptHelper.java
  9. 81
      src/main/java/com/ynxbd/push/helper/MapHelper.java
  10. 99
      src/main/java/com/ynxbd/push/helper/MessageApiHelper.java
  11. 79
      src/main/java/com/ynxbd/push/rabbit/receive/RabbitReceiver.java
  12. 15
      src/main/java/com/ynxbd/push/rabbit/send/RabbitSender.java
  13. 281
      src/main/java/com/ynxbd/push/service/HisUniversalService.java

@ -17,7 +17,7 @@
<properties> <properties>
<java.version>1.8</java.version> <java.version>1.8</java.version>
<swagger.version>3.0.0</swagger.version> <swagger.version>3.0.0</swagger.version>
<logback.version>1.2.11</logback.version> <logback.version>1.2.12</logback.version>
<fastjson.version>1.2.83</fastjson.version> <fastjson.version>1.2.83</fastjson.version>
</properties> </properties>
@ -40,16 +40,18 @@
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>3.9.9</version>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId> <artifactId>spring-boot-starter-amqp</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>3.10.8</version>
</dependency>
<dependency> <dependency>
<groupId>io.lettuce</groupId> <groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId> <artifactId>lettuce-core</artifactId>
@ -58,24 +60,22 @@
<!-- https://mvnrepository.com/artifact/com.rabbitmq/amqp-client --> <!-- https://mvnrepository.com/artifact/com.rabbitmq/amqp-client -->
<dependency> <dependency>
<groupId>ch.qos.logback</groupId> <groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId> <artifactId>logback-classic</artifactId>
<version>1.2.9</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>commons-codec</groupId> <groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId> <artifactId>commons-codec</artifactId>
<version>1.15</version> <version>1.16.0</version>
</dependency> </dependency>
<!--dom4j--> <!--dom4j-->
<dependency> <dependency>
<groupId>org.dom4j</groupId> <groupId>org.dom4j</groupId>
<artifactId>dom4j</artifactId> <artifactId>dom4j</artifactId>
<version>2.1.3</version> <version>2.1.4</version>
</dependency> </dependency>
<dependency> <dependency>
@ -90,11 +90,10 @@
<version>${fastjson.version}</version> <version>${fastjson.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId> <artifactId>commons-lang3</artifactId>
<version>3.4</version> <version>3.14.0</version>
</dependency> </dependency>
<dependency> <dependency>

@ -1,9 +1,11 @@
package com.ynxbd.push.controller; package com.ynxbd.push.controller;
import com.alibaba.fastjson.JSONObject;
import com.ynxbd.push.entity.type.MessageTypeEnum; import com.ynxbd.push.entity.type.MessageTypeEnum;
import com.ynxbd.push.entity.response.ResponseResult; import com.ynxbd.push.entity.response.ResponseResult;
import com.ynxbd.push.helper.BusinessHelper; import com.ynxbd.push.helper.BusinessHelper;
import com.ynxbd.push.rabbit.send.RabbitSender; import com.ynxbd.push.rabbit.send.RabbitSender;
import com.ynxbd.push.service.HisUniversalService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
@ -26,8 +28,8 @@ public class BusinessController {
@Autowired @Autowired
private RabbitSender rabbitSender; private RabbitSender rabbitSender;
@Autowired
private HisUniversalService hisUniversalService;
@GetMapping(value = "report") @GetMapping(value = "report")
@ResponseBody @ResponseBody
@ -143,4 +145,12 @@ public class BusinessController {
rabbitSender.TipSend(message); rabbitSender.TipSend(message);
return ResponseResult.JOIN_QUEUE.toMessResult(); return ResponseResult.JOIN_QUEUE.toMessResult();
} }
@PostMapping("hisUniversal")
@ResponseBody
public MessageSendResult hisUniversal(@RequestBody Map<String, String> paramsMap) {
log.info("进入接口-[HIS推送接口],params=[{}]", JSONObject.toJSONString(paramsMap));
return hisUniversalService.hisUniversal(paramsMap);
}
} }

@ -0,0 +1,35 @@
package com.ynxbd.push.entity.enums;
import org.springframework.util.ObjectUtils;
public enum HisApiEnum {
// 数字后缀为[_参数个数][__编号(模板名称相同,参数个数相同,但参数名称不一致)]
reg_success_04__001("reg_success_04__001", "预约挂号成功通知", "就诊人、就诊科室、预约时间、就诊地点"),
payment_end_04__001("payment_end_04__001", "缴费完成通知", "就诊人、缴费时间、缴费金额、治疗地点"),
payment_remind_04__001("payment_remind_04__001", "缴费提醒", "患者姓名、开单时间、缴费项目、金额"),
report_notice_05__001("report_notice_05__001", "检验检查报告通知", "就诊卡号、就诊人、单号、检查时间、项目名称"),
work_order_remind_02__001("work_order_remind_02__001", "工单处理提醒", "提交时间、工单名称"),
;
public final String CODE;
public final String TITLE;
public final String KEYWORD;
HisApiEnum(String CODE, String TITLE, String KEYWORD) {
this.CODE = CODE;
this.TITLE = TITLE;
this.KEYWORD = KEYWORD;
}
public static HisApiEnum toEnum(String code) {
if (ObjectUtils.isEmpty(code)) {
return null;
}
for (HisApiEnum item : HisApiEnum.values()) {
if (code.equals(item.CODE)) {
return item;
}
}
return null;
}
}

@ -0,0 +1,159 @@
package com.ynxbd.push.entity.enums;
import lombok.ToString;
import org.springframework.util.ObjectUtils;
import java.util.HashMap;
import java.util.Map;
/**
* 枚举类目模板消息参数值内容限制说明
*/
@ToString
public enum MsgParamEnum {
THING(20, "thing", "【事物】可汉字、数字、字母或符号组合"),
CHARACTER_STRING(32, "character_string", "【字符串】可数字、字母或符号组合"),
TIME(32, "time", "【时间】24小时制时间格式(支持+年月日),支持填时间段,两个时间点之间用“~”符号连接【例如:15:01,或:2019年10月1日 15:01】"),
AMOUNT(32, "amount", "【金额】1个币种符号+12位以内纯数字,可带小数,结尾可带“元” 可带小数"),
PHONE_NUMBER(17, "phone_number", "【电话】(数字、符号) 电话号码,例:+86-0766-66888866"),
CAR_NUMBER(8, "car_number", "【车牌】第一位与最后一位可为汉字,其余为字母或数字 例:车牌号码:粤A8Z888挂"),
CONST(20, "const", "【常量】超过无法下发注:需枚举(需将内容提交平台审核,审核通过可下发)只能下发审核通过的字符串和空串"),
// 锁定的参数名-----------------------
URL(1024, "url", "跳转链接"),
TEMPLATE_ID(100, "template_id", "跳转链接"),
TIP(200, "tip", "模板类型"),
TITLE(200, "title", "模板标题"),
;
// 字符串限制长度
public final int LENGTH;
// code开头
public final String CODE;
// 备注说明
public final String REMARK;
MsgParamEnum(int LENGTH, String CODE, String REMARK) {
this.LENGTH = LENGTH;
this.CODE = CODE;
this.REMARK = REMARK;
}
/**
* 获取参数
*
* @param paramsMap 参数集
* @param key 参数key
* @param canNull 可以为空
*/
public String getStrValue(Map<String, String> paramsMap, String key, boolean canNull) throws Exception {
if (ObjectUtils.isEmpty(key)) {
throw new Exception("参数key缺失");
}
String value = paramsMap.get(key);
// 可以为空
if (canNull) {
if (ObjectUtils.isEmpty(value)) {
return "";
}
} else {
if (ObjectUtils.isEmpty(value)) {
throw new Exception(key + "参数为空");
}
}
// 判断长度是否合法
if (value.length() > LENGTH) {
throw new Exception(key + "参数长度过长");
}
return value;
}
/**
* 获取参数
*
* @param paramsMap 参数集
* @param key 参数key
*/
public Map<String, String> getMapValue(Map<String, String> paramsMap, String key) throws Exception {
return getMapValue(paramsMap, key, false, null);
}
/**
* 获取参数
*
* @param paramsMap 参数集
* @param key 参数key
* @param color 颜色
*/
public Map<String, String> getMapValue(Map<String, String> paramsMap, String key, String color) throws Exception {
return getMapValue(paramsMap, key, false, color);
}
/**
* 获取参数
*
* @param paramsMap 参数集
* @param key 参数key
* @param canNull 是否可以为空
*/
public Map<String, String> getMapValue(Map<String, String> paramsMap, String key, boolean canNull, String color) throws Exception {
if (ObjectUtils.isEmpty(key)) {
throw new Exception("参数key缺失");
}
Map<String, String> keyMap = new HashMap<>();
String value = getStrValue(paramsMap, key, canNull);
keyMap.put("value", value);
if (!ObjectUtils.isEmpty(color)) {
keyMap.put("color", color);
}
return keyMap;
}
/**
* 组织成key
*/
public String toKey(String keyNum) throws Exception {
if (ObjectUtils.isEmpty(keyNum)) {
throw new Exception("keyNum为空");
}
return CODE + keyNum;
}
/**
* 模板参数组装
*
* @param paramsMap 入参map
* @param tempData 模板
* @param paramName 参数名称
* @param keyNum key的编号time21入参就为21
*/
public void put(Map<String, String> paramsMap, Map<String, Object> tempData, String paramName, Integer keyNum) throws Exception {
put(paramsMap, tempData, paramName, keyNum, false, null);
}
/**
* 模板参数组装
*
* @param paramsMap 入参map
* @param tempData 模板
* @param paramName 参数名称
* @param keyNum key的编号time21入参就为21
* @param canNull 是否可以为空
* @param color 颜色
*/
public void put(Map<String, String> paramsMap, Map<String, Object> tempData, String paramName, Integer keyNum, boolean canNull, String color) throws Exception {
if (keyNum == null) {
throw new Exception("keyNum is null");
}
String keyNumStr = String.valueOf(keyNum);
tempData.put(this.toKey(keyNumStr), this.getMapValue(paramsMap, paramName, canNull, color));
}
}

@ -13,14 +13,14 @@ public enum ResponseResult {
JOIN_QUEUE("0", "已经接收消息,进入处理程序"), JOIN_QUEUE("0", "已经接收消息,进入处理程序"),
ORGANIZE_IS_NULL("50001", "组织机构代码无效"), ORGANIZE_IS_NULL("50001", "组织机构代码无效"),
PARAMETER_IS_NULL("50003", "参数无效"), PARAMETER_IS_NULL("50003", "参数无效"),
DOCTOR_NOT_BIND("50004", "医生未绑定"), DOCTOR_NOT_BIND("50004", "医生未绑定"),
CALL_NO_IS_NOT_FIND("50011", "调用码未找到"),
TEMPLATE_ID_IS_NOT_FIND("50010", "模板ID未找到"),
CODE_INVALIDATION("40001", "token无效"), CODE_INVALIDATION("40001", "token无效"),

@ -0,0 +1,38 @@
package com.ynxbd.push.entity.tencent;
import lombok.*;
import lombok.experimental.Tolerate;
import java.util.Map;
@Getter
@Setter
@Builder
@ToString
public class SendTemplate {
private String title;
public String message_id;
public String code;
public String template_id;
private String template_name;
private String touser;
private String url;
private String appId;
private String pagePath;
private String messageType;
private int count;
private Map<String, Object> data;
@Tolerate
SendTemplate() {
}
}

@ -1,5 +1,7 @@
package com.ynxbd.push.entity.type; package com.ynxbd.push.entity.type;
import org.springframework.util.ObjectUtils;
/** /**
* @author 李进才 * @author 李进才
* @ClassName MessageTypeEnum * @ClassName MessageTypeEnum
@ -13,8 +15,8 @@ public enum MessageTypeEnum {
MEDICAL_RECORD("MedicalRecord","病历复印"), MEDICAL_RECORD("MedicalRecord","病历复印"),
TREAT_PLAN("treatPlan","诊疗计划提醒"), TREAT_PLAN("treatPlan","诊疗计划提醒"),
UNIVERSAL("Universal","通用模版推送-绑定通知"); UNIVERSAL("Universal","通用模版推送-绑定通知"),
COMMON("COMMON","COMMON");
public final String CODE; public final String CODE;
public final String MESSAGE; public final String MESSAGE;
@ -25,4 +27,17 @@ public enum MessageTypeEnum {
this.MESSAGE = message; this.MESSAGE = message;
} }
public static MessageTypeEnum toEnum(String code) {
if (ObjectUtils.isEmpty(code)) {
return null;
}
for (MessageTypeEnum item : MessageTypeEnum.values()) {
if (item.CODE.equals(code)) {
return item;
}
}
return null;
}
} }

@ -77,5 +77,9 @@ public class DesEncryptHelper {
System.out.println(DesEncryptHelper.enCode("xbd_CVMS", KEY)); System.out.println(DesEncryptHelper.enCode("xbd_CVMS", KEY));
System.out.println(DesEncryptHelper.deCode("C23A7500D2C35F9A85B72795B86F02AFD62A5ECBD06DC050DF47EFA26AA846E3E3FF998FFA576283C021712DD1CAA7EEF74898A8CDFE9ABA8C06C1851574CB802FA096B4B0D8ED791559DEEDFE0BD497AC5365E6370223EF3D706F0BC2427619C762C77B776510D566A36F439CB579A5C55674435F0D800BC44B3299BF484B716D121601D32E26E2", KEY)); System.out.println(DesEncryptHelper.deCode("C23A7500D2C35F9A85B72795B86F02AFD62A5ECBD06DC050DF47EFA26AA846E3E3FF998FFA576283C021712DD1CAA7EEF74898A8CDFE9ABA8C06C1851574CB802FA096B4B0D8ED791559DEEDFE0BD497AC5365E6370223EF3D706F0BC2427619C762C77B776510D566A36F439CB579A5C55674435F0D800BC44B3299BF484B716D121601D32E26E2", KEY));
System.out.println("---");
System.out.println(DesEncryptHelper.enCode("永胜县人民医院"));
System.out.println("---------");
System.out.println(DesEncryptHelper.deCode(DesEncryptHelper.enCode("永胜县人民医院")));
} }
} }

@ -0,0 +1,81 @@
package com.ynxbd.push.helper;
import com.alibaba.fastjson.JSONObject;
import org.springframework.util.ObjectUtils;
import java.util.HashMap;
import java.util.Map;
/**
* map转换工具类
*/
public class MapHelper {
/**
* obj类型map转str类型map
*
* @param objMap obj类型map
* @return str类型map
*/
public static Map<String, String> objMapToStrMap(Map<String, Object> objMap) {
Map<String, String> strMap = new HashMap<>();
for (Map.Entry<String, Object> item : objMap.entrySet()) {
String key = item.getKey();
if (ObjectUtils.isEmpty(key)) {
continue;
}
Object value = item.getValue();
if (ObjectUtils.isEmpty(value)) {
strMap.put(key, null);
continue;
}
if (value instanceof Map) {
strMap.put(key, JSONObject.toJSONString(value));
} else {
strMap.put(key, value.toString());
}
}
return strMap;
}
/**
* str类型map转obj类型map
*
* @param strMap str类型map
* @return obj类型map
*/
public static Map<String, Object> strMapToObjMap(Map<String, String> strMap) {
Map<String, Object> objMap = new HashMap<>();
for (Map.Entry<String, String> item : strMap.entrySet()) {
String key = item.getKey();
if (key == null) {
continue;
}
String value = item.getValue();
if (value == null) {
objMap.put(key, "");
} else {
objMap.put(key, getJsonVal(value));
}
}
return objMap;
}
/**
* 获取Json值
*
* @param value
* @return Object
*/
public static Object getJsonVal(String value) {
if (ObjectUtils.isEmpty(value)) {
return "";
}
try {
return JSONObject.parse(value);
} catch (Exception e) {
return "";
}
}
}

@ -1,10 +1,11 @@
package com.ynxbd.push.helper; package com.ynxbd.push.helper;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.sun.jndi.toolkit.url.UrlUtil;
import com.ynxbd.push.config.IniConfig; import com.ynxbd.push.config.IniConfig;
import com.ynxbd.push.entity.*; import com.ynxbd.push.entity.*;
import com.ynxbd.push.entity.enums.MsgParamEnum;
import com.ynxbd.push.entity.response.ResponseResult; import com.ynxbd.push.entity.response.ResponseResult;
import com.ynxbd.push.entity.tencent.*; import com.ynxbd.push.entity.tencent.*;
import com.ynxbd.push.httpRequest.tencent.WeChatDataRequest; import com.ynxbd.push.httpRequest.tencent.WeChatDataRequest;
@ -20,6 +21,7 @@ import org.apache.http.concurrent.FutureCallback;
import org.apache.http.entity.StringEntity; import org.apache.http.entity.StringEntity;
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.web.util.UriUtils; import org.springframework.web.util.UriUtils;
import weixin.popular.api.API; import weixin.popular.api.API;
import weixin.popular.api.MessageAPI; import weixin.popular.api.MessageAPI;
@ -150,6 +152,7 @@ public class MessageApiHelper {
/** /**
* 根据患者ID或者医生ID推送模版消息 * 根据患者ID或者医生ID推送模版消息
*
* @param organizeName * @param organizeName
* @param idCard * @param idCard
* @param title * @param title
@ -497,4 +500,98 @@ public class MessageApiHelper {
// } // }
/**
* 请求微信获取openId
*
* @param title 标题
* @param patientId 患者ID
* @param cardNo 身份证号码
* @return openId
*/
public static String reqWxOpenId(String title, String patientId, String cardNo) throws Exception {
log.info("[外部组织对接推送]发送{}消息", title);
String weChatUrl = "http://127.0.0.1/wx/";
HttpUriRequest httpUriRequest = RequestBuilder
.get()
.setHeader(jsonHeader)
.setUri(new StringBuilder()
.append(weChatUrl)
.append(patientId != null ? "patient/getOpenIdsByPatientId.do" : "patient/getOpenIdsByCardNo.do").toString())
.addParameter(patientId != null ? "patientId" : "cardNo", !ObjectUtils.isEmpty(patientId) ? patientId : cardNo)
.addParameter("algorithm", "des")
.addParameter("isEncryptComma", "false")
.addParameter("isLastBind", "true")
.build();
WeChatResponse weChatResponse = LocalHttpClient.executeJsonResult(httpUriRequest, WeChatResponse.class);
if (weChatResponse.getData() == null) {
throw new Exception(ResponseResult.NOT_FIND_DATA.ERR_MSG);
}
String openId = DesEncryptHelper.deCode(weChatResponse.getData().get(0));
if (ObjectUtils.isEmpty(openId)) {
throw new Exception("[推送]未找到openId");
}
return openId;
}
/**
* 根据患者ID或者医生ID推送模版消息
*/
public static MessageSendResult templateMessageForCode02(Map<String, String> strTemp) {
String code = strTemp.get("tip");
String messageId = strTemp.get("message_id");
if (IniConfig.getInstance("templateVersion") == null) {
code = ""; // tip
}
String url = strTemp.get(MsgParamEnum.URL.CODE);
String title = strTemp.get(MsgParamEnum.TITLE.CODE);
String templateId = strTemp.get(MsgParamEnum.TEMPLATE_ID.CODE);
String doctorCode = strTemp.get("doctorCode");
String patientId = strTemp.get("patientId");
String cardNo = strTemp.get("cardNo");
Map<String, Object> temp = MapHelper.strMapToObjMap(strTemp);
if (doctorCode != null) {
List<String> allDoctorCodeList = WeChatDataRequest.getAllOpenIdForDoctorCode(doctorCode);
if (allDoctorCodeList.isEmpty()) {
log.info("[{}]未绑定微官网,doctorCode:{}", title, doctorCode);
return ResponseResult.NOT_FIND_DATA.toMessResult();
}
for (String interfaceOpenId : allDoctorCodeList) {
String openId = AesCodeHelper.deCode(interfaceOpenId);
SendTemplate sendTemplate = SendTemplate.builder()
.template_id(templateId)
.message_id(messageId)
.touser(openId)
.code(code)
.url(url)
.data(temp)
.build();
MessageSendResult messageSendResult = templateMessageSend(JSONObject.toJSONString(sendTemplate));
log.info("[{}]医生账号消息推送,推送结果代码-{},推送结果-{}", title, messageSendResult.getErrcode(), messageSendResult.getErrmsg());
}
return ResponseResult.JOIN_QUEUE.toMessResult();
}
try {
String openId = reqWxOpenId(title, patientId, cardNo);
SendTemplate sendTemplate = SendTemplate.builder()
.template_id(templateId)
.message_id(messageId)
.touser(openId)
.code(code)
.url(url)
.data(temp)
.build();
log.info("组合数据[{}]", JSONObject.toJSONString(sendTemplate));
return templateMessageSend(JSONObject.toJSONString(sendTemplate));
} catch (Exception e) {
return ResponseResult.NOT_FIND_DATA.toMessResult();
}
}
} }

@ -1,8 +1,9 @@
package com.ynxbd.push.rabbit.receive; package com.ynxbd.push.rabbit.receive;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject;
import com.ynxbd.push.config.IniConfig; import com.ynxbd.push.config.IniConfig;
import com.ynxbd.push.entity.response.ResponseResult; import com.ynxbd.push.entity.response.ResponseResult;
import com.ynxbd.push.entity.type.MessageTypeEnum;
import com.ynxbd.push.helper.MessageApiHelper; import com.ynxbd.push.helper.MessageApiHelper;
import com.ynxbd.push.rabbit.send.RabbitSender; import com.ynxbd.push.rabbit.send.RabbitSender;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -16,10 +17,7 @@ import weixin.popular.bean.message.MessageSendResult;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Base64; import java.util.*;
import java.util.Date;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
/** /**
@ -36,13 +34,12 @@ public class RabbitReceiver {
@Autowired @Autowired
private RabbitSender rabbitSender; private RabbitSender rabbitSender;
private final static String REPORT_TIP = "ReportTip"; // private final static String REPORT_TIP = "ReportTip";
private final static String QUEUE_TIP = "QueueTip"; // private final static String QUEUE_TIP = "QueueTip";
private final static String MEDICAL_RECORD = "MedicalRecord"; // private final static String MEDICAL_RECORD = "MedicalRecord";
private final static String TREAT_PLAN = "treatPlan"; // private final static String TREAT_PLAN = "treatPlan";
//
private final static String UNIVERSAL = "Universal"; // private final static String UNIVERSAL = "Universal";
@RabbitHandler @RabbitHandler
public void receive(Map<String, String> receiveMessage) { public void receive(Map<String, String> receiveMessage) {
@ -51,7 +48,17 @@ public class RabbitReceiver {
if (Integer.parseInt(receiveMessage.get("count")) > 2) { if (Integer.parseInt(receiveMessage.get("count")) > 2) {
return; return;
} }
switch (receiveMessage.get("tip")) {
String tip = receiveMessage.get("tip");
log.info("map=[{}]", JSONObject.toJSONString(receiveMessage));
log.warn("tip={}", tip);
MessageTypeEnum msgTypeEnum = MessageTypeEnum.toEnum(tip);
if (msgTypeEnum == null) {
log.info("未找到消息推送类型[{}]", tip);
return;
}
switch (msgTypeEnum) {
case REPORT_TIP: case REPORT_TIP:
reportTip(receiveMessage); reportTip(receiveMessage);
break; break;
@ -67,13 +74,39 @@ public class RabbitReceiver {
case UNIVERSAL: case UNIVERSAL:
universal(receiveMessage); universal(receiveMessage);
break; break;
case COMMON:
his(receiveMessage);
break;
default: default:
log.info("未找到消息类型进行推送,类型-{}", receiveMessage.get("tip")); log.info("未找到消息类型进行推送,类型-{}", tip);
break; break;
} }
}
catch (Exception e){ // switch (tip) {
// case REPORT_TIP:
// reportTip(receiveMessage);
// break;
// case QUEUE_TIP:
// queueTip(receiveMessage);
// break;
// case MEDICAL_RECORD:
// medicalRecord(receiveMessage);
// break;
// case TREAT_PLAN:
// treatPlan(receiveMessage);
// break;
// case UNIVERSAL:
// universal(receiveMessage);
// break;
//
//
// default:
// log.info("未找到消息类型进行推送,类型-{}", tip);
// break;
// }
} catch (Exception e) {
e.printStackTrace();
log.error("消息消费出错:{},内容-{}", e, receiveMessage); log.error("消息消费出错:{},内容-{}", e, receiveMessage);
} }
} }
@ -100,6 +133,7 @@ public class RabbitReceiver {
weChatUrl + IniConfig.getInstance("reportUrl") + "/all-result.html", messageId), receiveMessage); weChatUrl + IniConfig.getInstance("reportUrl") + "/all-result.html", messageId), receiveMessage);
} }
private void queueTip(Map<String, String> receiveMessage) { private void queueTip(Map<String, String> receiveMessage) {
try { try {
String organizeName = receiveMessage.get("organizeName"); String organizeName = receiveMessage.get("organizeName");
@ -114,8 +148,7 @@ public class RabbitReceiver {
String selfNumber = receiveMessage.get("selfNumber") == null ? "" : receiveMessage.get("selfNumber"); String selfNumber = receiveMessage.get("selfNumber") == null ? "" : receiveMessage.get("selfNumber");
String waitNumber = receiveMessage.get("waitNumber") == null ? "" : receiveMessage.get("waitNumber"); String waitNumber = receiveMessage.get("waitNumber") == null ? "" : receiveMessage.get("waitNumber");
retry(MessageApiHelper.TemplateMessageForCode(organizeName, code, idCard, "排队叫号提醒", patientId, null, patientName + ",您已进入候诊队列,请及时查看", deptName, doctorName, currentNumber, selfNumber, waitNumber, "请合理安排好时间就诊,以免过号", null, messageId), receiveMessage); retry(MessageApiHelper.TemplateMessageForCode(organizeName, code, idCard, "排队叫号提醒", patientId, null, patientName + ",您已进入候诊队列,请及时查看", deptName, doctorName, currentNumber, selfNumber, waitNumber, "请合理安排好时间就诊,以免过号", null, messageId), receiveMessage);
} } catch (Exception e) {
catch (Exception e){
log.error("[推送消息组织出错]params-{}, error-{}", receiveMessage, e.toString()); log.error("[推送消息组织出错]params-{}, error-{}", receiveMessage, e.toString());
} }
} }
@ -168,6 +201,7 @@ public class RabbitReceiver {
content = content.substring(0, 16) + "……"; content = content.substring(0, 16) + "……";
} }
retry(MessageApiHelper.TemplateMessageForCode(organizeName, code, IdCard, IniConfig.getInstance("templateVersion") == null ? "绑定通知" : "工单处理提醒", patientId, doctorCode, null, sdf.format(date), content, null, null, null, null, viewUrl, messageId), receiveMessage); retry(MessageApiHelper.TemplateMessageForCode(organizeName, code, IdCard, IniConfig.getInstance("templateVersion") == null ? "绑定通知" : "工单处理提醒", patientId, doctorCode, null, sdf.format(date), content, null, null, null, null, viewUrl, messageId), receiveMessage);
} }
private void retry(MessageSendResult messageSendResult, Map<String, String> message) { private void retry(MessageSendResult messageSendResult, Map<String, String> message) {
@ -177,11 +211,18 @@ public class RabbitReceiver {
message.put("count", String.valueOf((count + 1))); message.put("count", String.valueOf((count + 1)));
rabbitSender.send(message); rabbitSender.send(message);
} }
} }
public static void main(String[] args) throws IOException, TimeoutException { public static void main(String[] args) throws IOException, TimeoutException {
System.out.println(Base64.getEncoder().encodeToString("尊敬的患者,您本次就诊有如下费用需要支付:\\n 药品处方:\\n 共1张,金额:0.13元;\\n".getBytes(StandardCharsets.UTF_8))); System.out.println(Base64.getEncoder().encodeToString("尊敬的患者,您本次就诊有如下费用需要支付:\\n 药品处方:\\n 共1张,金额:0.13元;\\n".getBytes(StandardCharsets.UTF_8)));
System.out.println(new String(Base64.getDecoder().decode("JUU1JUIwJThBJUU2JTk1JUFDJUU3JTlBJTg0JUU2JTgyJUEzJUU4JTgwJTg1JUU2JTgyJUE4JUU1JUE1JUJEJUVGJUJDJThDJUU2JTgyJUE4JUU3JTlBJTg0JUU1JUE0JTg0JUU2JTk2JUI5JUU1JUI3JUIyJUU3JUJCJThGJUU1JTg3JUJBJUU1JTg1JUI3JUVGJUJDJThDJUU4JUFGJUI3JUU0JUJEJUEwJUU1JTlDJUE4JUU4JUE3JTg0JUU1JUFFJTlBJUU2JTk3JUI2JUU5JTk3JUI0JUU1JTg2JTg1JUU1JTg5JThEJUU1JUJFJTgwJUU1JUE0JTg0JUU2JTk2JUI5JUU4JUJGJTlCJUU4JUExJThDJUU2JTk0JUFGJUU0JUJCJTk4JUVGJUJDJThDJUU4JUIwJUEyJUU4JUIwJUEyJUU5JTg1JThEJUU1JTkwJTg4"))); System.out.println(new String(Base64.getDecoder().decode("JUU1JUIwJThBJUU2JTk1JUFDJUU3JTlBJTg0JUU2JTgyJUEzJUU4JTgwJTg1JUU2JTgyJUE4JUU1JUE1JUJEJUVGJUJDJThDJUU2JTgyJUE4JUU3JTlBJTg0JUU1JUE0JTg0JUU2JTk2JUI5JUU1JUI3JUIyJUU3JUJCJThGJUU1JTg3JUJBJUU1JTg1JUI3JUVGJUJDJThDJUU4JUFGJUI3JUU0JUJEJUEwJUU1JTlDJUE4JUU4JUE3JTg0JUU1JUFFJTlBJUU2JTk3JUI2JUU5JTk3JUI0JUU1JTg2JTg1JUU1JTg5JThEJUU1JUJFJTgwJUU1JUE0JTg0JUU2JTk2JUI5JUU4JUJGJTlCJUU4JUExJThDJUU2JTk0JUFGJUU0JUJCJTk4JUVGJUJDJThDJUU4JUIwJUEyJUU4JUIwJUEyJUU5JTg1JThEJUU1JTkwJTg4")));
} }
private void his(Map<String, String> receiveMessage) {
MessageSendResult messageSendResult = MessageApiHelper.templateMessageForCode02(receiveMessage);
retry(messageSendResult, receiveMessage);
}
} }

@ -1,6 +1,6 @@
package com.ynxbd.push.rabbit.send; package com.ynxbd.push.rabbit.send;
import com.alibaba.fastjson.JSON; import com.ynxbd.push.helper.MapHelper;
import org.springframework.amqp.rabbit.connection.CorrelationData; import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -24,10 +24,23 @@ public class RabbitSender {
message.put("count", "0"); message.put("count", "0");
send(message); send(message);
} }
public void send(Map<String, String> message) { public void send(Map<String, String> message) {
String uuid = UUID.randomUUID().toString(); String uuid = UUID.randomUUID().toString();
CorrelationData correlationData = new CorrelationData(uuid); CorrelationData correlationData = new CorrelationData(uuid);
message.put("message_id", uuid); message.put("message_id", uuid);
this.rabbitTemplate.convertAndSend("wxPushExchange", "wxPushRouting", message, correlationData); this.rabbitTemplate.convertAndSend("wxPushExchange", "wxPushRouting", message, correlationData);
} }
public void sendByTip(Map<String, Object> messageObj) {
Map<String, String> message = MapHelper.objMapToStrMap(messageObj);
String uuid = UUID.randomUUID().toString();
CorrelationData correlationData = new CorrelationData(uuid);
message.put("count", "0");
message.put("message_id", uuid);
// System.out.println("end=" + JSONObject.toJSONString(message));
this.rabbitTemplate.convertAndSend("wxPushExchange", "wxPushRouting", message, correlationData);
}
} }

@ -0,0 +1,281 @@
package com.ynxbd.push.service;
import com.alibaba.fastjson.JSONObject;
import com.ynxbd.push.entity.enums.HisApiEnum;
import com.ynxbd.push.entity.enums.MsgParamEnum;
import com.ynxbd.push.entity.response.ResponseResult;
import com.ynxbd.push.entity.type.MessageTypeEnum;
import com.ynxbd.push.helper.DesEncryptHelper;
import com.ynxbd.push.httpRequest.tencent.WeChatDataRequest;
import com.ynxbd.push.rabbit.send.RabbitSender;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import weixin.popular.bean.message.MessageSendResult;
import java.util.HashMap;
import java.util.Map;
@Slf4j
@Service
public class HisUniversalService {
@Autowired
private RabbitSender rabbitSender;
public MessageSendResult hisUniversal(Map<String, String> paramsMap) {
String callNo = paramsMap.get("callNo");
HisApiEnum hisApiEnum = HisApiEnum.toEnum(callNo);
if (hisApiEnum == null) {
return ResponseResult.CALL_NO_IS_NOT_FIND.toMessResult();
}
log.info("[{}]推送开始...", hisApiEnum.TITLE);
String templateId = WeChatDataRequest.getTemplateId(hisApiEnum.TITLE);
if (ObjectUtils.isEmpty(templateId)) {
return ResponseResult.TEMPLATE_ID_IS_NOT_FIND.toMessResult();
}
switch (hisApiEnum) {
case payment_end_04__001:
return payment_end_04__001(paramsMap, templateId, hisApiEnum.TITLE);
case payment_remind_04__001:
return payment_remind_04__001(paramsMap, templateId, hisApiEnum.TITLE);
case reg_success_04__001:
return reg_success_04__001(paramsMap, templateId, hisApiEnum.TITLE);
case report_notice_05__001:
return report_notice_05__001(paramsMap, templateId, hisApiEnum.TITLE);
case work_order_remind_02__001:
return work_order_remind_02__001(paramsMap, templateId, hisApiEnum.TITLE);
}
return ResponseResult.CALL_NO_IS_NOT_FIND.toMessResult();
}
/**
* 创建一个data模板
*
* @param paramsMap 入参map
* @param templateId 模板ID
*/
public Map<String, Object> createTemplate(Map<String, String> paramsMap, String templateId, String title) throws Exception {
String organizeName = paramsMap.get("organizeName");
if (ObjectUtils.isEmpty(organizeName)) {
throw new Exception("组织机构代码为空");
}
organizeName = DesEncryptHelper.deCode(organizeName);
if (organizeName.equals("error:null")) {
throw new Exception("组织机构代码为空 organizeName=" + organizeName);
}
Map<String, Object> tempData = new HashMap<>();
// 页面路径[入参url]
String url = paramsMap.get("url");
tempData.put(MsgParamEnum.URL.CODE, ObjectUtils.isEmpty(url) ? "" : url);
// tip
tempData.put(MsgParamEnum.TIP.CODE, MessageTypeEnum.COMMON.CODE);
// 模板ID
tempData.put(MsgParamEnum.TEMPLATE_ID.CODE, templateId);
tempData.put(MsgParamEnum.TITLE.CODE, title);
String patientId = paramsMap.get("patientId");
String doctorCode = paramsMap.get("doctorCode");
String cardNo = paramsMap.get("cardNo");
String openId = paramsMap.get("openId");
if (ObjectUtils.isEmpty(patientId) && ObjectUtils.isEmpty(doctorCode) && ObjectUtils.isEmpty(cardNo)) {
throw new Exception("查询信息的参数缺失");
}
if (!ObjectUtils.isEmpty(patientId)) {
tempData.put("patientId", patientId);
}
if (!ObjectUtils.isEmpty(doctorCode)) {
tempData.put("doctorCode", doctorCode);
}
if (!ObjectUtils.isEmpty(cardNo)) {
tempData.put("cardNo", cardNo);
}
return tempData;
}
/**
* 缴费完成通知就诊人缴费时间缴费金额治疗地点
*
* @param paramsMap 参数集
* @return MessageSendResult
*/
public MessageSendResult payment_end_04__001(Map<String, String> paramsMap, String templateId, String title) {
try {
Map<String, Object> tempData = createTemplate(paramsMap, templateId, title);
// 就诊人
MsgParamEnum.THING.put(paramsMap, tempData, "patientName", 1);
// 缴费时间
MsgParamEnum.TIME.put(paramsMap, tempData, "time", 4);
// 缴费金额
MsgParamEnum.AMOUNT.put(paramsMap, tempData, "money", 3);
// 治疗地点
MsgParamEnum.THING.put(paramsMap, tempData, "address", 17);
rabbitSender.sendByTip(tempData);
return ResponseResult.JOIN_QUEUE.toMessResult();
} catch (Exception e) {
log.error(e.getMessage());
return ResponseResult.PARAMETER_IS_NULL.toMessResult();
}
}
/**
* 缴费提醒患者姓名开单时间缴费项目金额
*
* @param paramsMap
* @param templateId
* @return
*/
private MessageSendResult payment_remind_04__001(Map<String, String> paramsMap, String templateId, String title) {
try {
Map<String, Object> tempData = createTemplate(paramsMap, templateId, title);
// 患者姓名
MsgParamEnum.THING.put(paramsMap, tempData, "patientName", 14);
// 开单时间
MsgParamEnum.TIME.put(paramsMap, tempData, "time", 17);
// 缴费项目
MsgParamEnum.THING.put(paramsMap, tempData, "projectName", 10);
// 金额
MsgParamEnum.AMOUNT.put(paramsMap, tempData, "money", 3);
rabbitSender.sendByTip(tempData);
return ResponseResult.JOIN_QUEUE.toMessResult();
} catch (Exception e) {
log.error(e.getMessage());
return ResponseResult.PARAMETER_IS_NULL.toMessResult();
}
}
/**
* 预约挂号成功通知就诊人就诊科室预约时间就诊地点
*
* @param paramsMap
* @param templateId
* @return
*/
private MessageSendResult reg_success_04__001(Map<String, String> paramsMap, String templateId, String title) {
try {
Map<String, Object> tempData = createTemplate(paramsMap, templateId, title);
// 就诊人
MsgParamEnum.THING.put(paramsMap, tempData, "patientName", 28);
// 就诊科室
MsgParamEnum.THING.put(paramsMap, tempData, "deptName", 22);
// 预约时间
MsgParamEnum.TIME.put(paramsMap, tempData, "time", 21);
// 就诊地点
MsgParamEnum.THING.put(paramsMap, tempData, "address", 6);
rabbitSender.sendByTip(tempData);
return ResponseResult.JOIN_QUEUE.toMessResult();
} catch (Exception e) {
log.error(e.getMessage());
return ResponseResult.PARAMETER_IS_NULL.toMessResult();
}
}
/**
* 检验检查报告通知就诊卡号就诊人单号检查时间项目
*
* @param paramsMap
* @param templateId
* @return
*/
private MessageSendResult report_notice_05__001(Map<String, String> paramsMap, String templateId, String title) {
try {
Map<String, Object> tempData = createTemplate(paramsMap, templateId, title);
// 就诊卡号
MsgParamEnum.CHARACTER_STRING.put(paramsMap, tempData, "cardNo", 12);
// 就诊人
MsgParamEnum.THING.put(paramsMap, tempData, "patientName", 3);
// 单号
MsgParamEnum.CHARACTER_STRING.put(paramsMap, tempData, "orderNo", 9);
// 检查时间
MsgParamEnum.TIME.put(paramsMap, tempData, "time", 14);
// 项目名称
MsgParamEnum.THING.put(paramsMap, tempData, "projectName", 5);
rabbitSender.sendByTip(tempData);
return ResponseResult.JOIN_QUEUE.toMessResult();
} catch (Exception e) {
log.error(e.getMessage());
return ResponseResult.PARAMETER_IS_NULL.toMessResult();
}
}
/**
* 工单处理提醒就诊卡号就诊人单号检查时间项目名称
*
* @param paramsMap
* @param templateId
* @return
*/
private MessageSendResult work_order_remind_02__001(Map<String, String> paramsMap, String templateId, String title) {
try {
Map<String, Object> tempData = createTemplate(paramsMap, templateId, title);
// 提交时间
MsgParamEnum.TIME.put(paramsMap, tempData, "time", 13);
// 工单名称
MsgParamEnum.THING.put(paramsMap, tempData, "projectName", 16);
rabbitSender.sendByTip(tempData);
return ResponseResult.JOIN_QUEUE.toMessResult();
} catch (Exception e) {
log.error(e.getMessage());
return ResponseResult.PARAMETER_IS_NULL.toMessResult();
}
}
public static void main(String[] args) {
Map<String, Object> map = new HashMap<>();
map.put("a", 1);
map.put("b", "2");
map.put("c", new HashMap<String, String>() {{
put("d", "1");
}});
log.info(JSONObject.toJSONString(map));
Map<String, String> map2 = new HashMap<>();
for (Map.Entry<String, Object> item : map.entrySet()) {
String key = item.getKey();
Object value = item.getValue();
if (value == null) {
map2.put(item.getKey(), null);
break;
}
if (value instanceof Map) {
map2.put(key, JSONObject.toJSONString(value));
} else {
map2.put(key, String.valueOf(value));
}
}
log.info(JSONObject.toJSONString(map2));
map = new HashMap<>();
for (Map.Entry<String, String> item : map2.entrySet()) {
String key = item.getKey();
String value = item.getValue();
if (value == null) {
map.put(item.getKey(), null);
break;
}
map.put(key, JSONObject.parse(value));
}
log.info(JSONObject.toJSONString(map));
}
}
Loading…
Cancel
Save