diff --git a/pom.xml b/pom.xml index 67d1f78..05a2832 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ 1.8 3.0.0 - 1.2.11 + 1.2.12 1.2.83 @@ -40,16 +40,18 @@ true - - org.ehcache - ehcache - 3.9.9 - + org.springframework.boot spring-boot-starter-amqp + + org.ehcache + ehcache + 3.10.8 + + io.lettuce lettuce-core @@ -58,24 +60,22 @@ - ch.qos.logback logback-classic - 1.2.9 commons-codec commons-codec - 1.15 + 1.16.0 org.dom4j dom4j - 2.1.3 + 2.1.4 @@ -90,11 +90,10 @@ ${fastjson.version} - org.apache.commons commons-lang3 - 3.4 + 3.14.0 diff --git a/src/main/java/com/ynxbd/push/controller/BusinessController.java b/src/main/java/com/ynxbd/push/controller/BusinessController.java index a388f2a..021a78d 100644 --- a/src/main/java/com/ynxbd/push/controller/BusinessController.java +++ b/src/main/java/com/ynxbd/push/controller/BusinessController.java @@ -1,9 +1,11 @@ package com.ynxbd.push.controller; +import com.alibaba.fastjson.JSONObject; import com.ynxbd.push.entity.type.MessageTypeEnum; import com.ynxbd.push.entity.response.ResponseResult; import com.ynxbd.push.helper.BusinessHelper; import com.ynxbd.push.rabbit.send.RabbitSender; +import com.ynxbd.push.service.HisUniversalService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; @@ -26,44 +28,44 @@ public class BusinessController { @Autowired private RabbitSender rabbitSender; - - + @Autowired + private HisUniversalService hisUniversalService; @GetMapping(value = "report") @ResponseBody - public MessageSendResult reportTip(String organizeName, String patientId,String idCard, String reportId, String itemName, String reportTime, String patientName,String sex, String age, String applyDept, String applyDoctor) { - log.info("进入接口-[检验检查报告通知]organizeName-{},patientId-{},idCard-{},reportId-{}, itemName-{},reportTime-{},patientName-{},sex-{},age-{},applyDept-{},applyDoctor-{}",organizeName,patientId,idCard,reportId,itemName,reportTime,patientName,sex,age,applyDept,applyDoctor); - MessageSendResult check = BusinessHelper.ParamsCheck(organizeName,patientId,idCard,null); - if(!check.getErrcode().equals("0")){ + public MessageSendResult reportTip(String organizeName, String patientId, String idCard, String reportId, String itemName, String reportTime, String patientName, String sex, String age, String applyDept, String applyDoctor) { + log.info("进入接口-[检验检查报告通知]organizeName-{},patientId-{},idCard-{},reportId-{}, itemName-{},reportTime-{},patientName-{},sex-{},age-{},applyDept-{},applyDoctor-{}", organizeName, patientId, idCard, reportId, itemName, reportTime, patientName, sex, age, applyDept, applyDoctor); + MessageSendResult check = BusinessHelper.ParamsCheck(organizeName, patientId, idCard, null); + if (!check.getErrcode().equals("0")) { return check; } - Map message = new HashMap<>(); + Map message = new HashMap<>(); message.put("tip", MessageTypeEnum.REPORT_TIP.CODE); - message.put("organizeName",organizeName); - message.put("patientId",patientId); - message.put("idCard",idCard); - message.put("reportId",reportId); - message.put("itemName",itemName); - message.put("reportTime",reportTime); - message.put("patientName",patientName); - message.put("sex",sex); - message.put("age",age); - message.put("applyDept",applyDept); - message.put("applyDoctor",applyDoctor); + message.put("organizeName", organizeName); + message.put("patientId", patientId); + message.put("idCard", idCard); + message.put("reportId", reportId); + message.put("itemName", itemName); + message.put("reportTime", reportTime); + message.put("patientName", patientName); + message.put("sex", sex); + message.put("age", age); + message.put("applyDept", applyDept); + message.put("applyDoctor", applyDoctor); rabbitSender.TipSend(message); return ResponseResult.JOIN_QUEUE.toMessResult(); } @GetMapping(value = "queue") @ResponseBody - public MessageSendResult queueTip(String organizeName, String patientId, String idCard, String patientName, String deptName, String doctorName, String currentNumber, String selfNumber, String waitNumber) { + public MessageSendResult queueTip(String organizeName, String patientId, String idCard, String patientName, String deptName, String doctorName, String currentNumber, String selfNumber, String waitNumber) { log.info("进入接口-[排队叫号提醒]organizeName-{},patientId-{},idCard-{},patientName-{},deptName-{},doctorName-{},currentNumber-{},selfNumber-{},waitNumber-{}", organizeName, patientId, idCard, patientName, deptName, doctorName, currentNumber, selfNumber, waitNumber); - MessageSendResult check = BusinessHelper.ParamsCheck(organizeName, patientId, idCard,null); + MessageSendResult check = BusinessHelper.ParamsCheck(organizeName, patientId, idCard, null); if (!check.getErrcode().equals("0")) { return check; } - Map message = new HashMap<>(); - message.put("tip",MessageTypeEnum.QUEUE_TIP.CODE); + Map message = new HashMap<>(); + message.put("tip", MessageTypeEnum.QUEUE_TIP.CODE); message.put("organizeName", organizeName); message.put("patientId", patientId); message.put("idCard", idCard); @@ -79,68 +81,76 @@ public class BusinessController { @PostMapping("medicalRecord") @ResponseBody - public MessageSendResult medicalRecord(String organizeName, String patientId, String applyId) { - log.info("进入接口-[病历复印] 病历复印可付费通知(医院通知)organizeName-{}, patientId-{} , applyId-{}",organizeName,patientId,applyId); - MessageSendResult check = BusinessHelper.ParamsCheck(organizeName, patientId, null,null); + public MessageSendResult medicalRecord(String organizeName, String patientId, String applyId) { + log.info("进入接口-[病历复印] 病历复印可付费通知(医院通知)organizeName-{}, patientId-{} , applyId-{}", organizeName, patientId, applyId); + MessageSendResult check = BusinessHelper.ParamsCheck(organizeName, patientId, null, null); if (!check.getErrcode().equals("0")) { return check; } - Map message = new HashMap<>(); - message.put("tip",MessageTypeEnum.MEDICAL_RECORD.CODE); + Map message = new HashMap<>(); + message.put("tip", MessageTypeEnum.MEDICAL_RECORD.CODE); message.put("organizeName", organizeName); message.put("patientId", patientId); - message.put("applyId",applyId); + message.put("applyId", applyId); rabbitSender.TipSend(message); return ResponseResult.JOIN_QUEUE.toMessResult(); } @PostMapping("treatPlan") @ResponseBody - public MessageSendResult treatPlan(String title, String name, String planTime,String content,String patientId, String organizeName,String remark,String url) { - log.info("进入接口-[诊疗计划提醒] organizeName-{}, patientId-{} , title-{},name-{},planTime-{},content-{},remark-{},url-{}",organizeName,patientId,title,name,planTime,content,remark,url); - MessageSendResult check = BusinessHelper.ParamsCheck(organizeName, patientId, null,null); + public MessageSendResult treatPlan(String title, String name, String planTime, String content, String patientId, String organizeName, String remark, String url) { + log.info("进入接口-[诊疗计划提醒] organizeName-{}, patientId-{} , title-{},name-{},planTime-{},content-{},remark-{},url-{}", organizeName, patientId, title, name, planTime, content, remark, url); + MessageSendResult check = BusinessHelper.ParamsCheck(organizeName, patientId, null, null); if (!check.getErrcode().equals("0")) { return check; } - if(name==null||planTime==null||content==null){ - log.info("[诊疗计划提醒] 必填字段为空,name-{},planTime-{},content-{}",name,planTime,content); + if (name == null || planTime == null || content == null) { + log.info("[诊疗计划提醒] 必填字段为空,name-{},planTime-{},content-{}", name, planTime, content); return ResponseResult.PARAMETER_IS_NULL.toMessResult(); } - Map message = new HashMap<>(); - message.put("tip",MessageTypeEnum.TREAT_PLAN.CODE); - message.put("title",title==null?"":title); - message.put("name",name); + Map message = new HashMap<>(); + message.put("tip", MessageTypeEnum.TREAT_PLAN.CODE); + message.put("title", title == null ? "" : title); + message.put("name", name); message.put("patientId", patientId); message.put("organizeName", organizeName); - message.put("planTime",planTime); - message.put("content",content); - message.put("url",url==null?"":url); - message.put("remark",remark==null?"":remark); + message.put("planTime", planTime); + message.put("content", content); + message.put("url", url == null ? "" : url); + message.put("remark", remark == null ? "" : remark); rabbitSender.TipSend(message); return ResponseResult.JOIN_QUEUE.toMessResult(); } @PostMapping("universal") @ResponseBody - public MessageSendResult universal(String content,String patientId, String url, String organizeName, String IdCard,String doctorCode){ - log.info("进入接口-[通用推送接口]-绑定通知,content-{},patientId-{},url-{},organizeName-{},IdCard-{},doctorCode-{}",content,patientId,url,organizeName,IdCard,doctorCode); - MessageSendResult check = BusinessHelper.ParamsCheck(organizeName, patientId, null,doctorCode); + public MessageSendResult universal(String content, String patientId, String url, String organizeName, String IdCard, String doctorCode) { + log.info("进入接口-[通用推送接口]-绑定通知,content-{},patientId-{},url-{},organizeName-{},IdCard-{},doctorCode-{}", content, patientId, url, organizeName, IdCard, doctorCode); + MessageSendResult check = BusinessHelper.ParamsCheck(organizeName, patientId, null, doctorCode); if (!check.getErrcode().equals("0")) { return check; } - if(content==null){ + if (content == null) { log.info("[通用推送接口]-绑定通知, 必填字段为空"); return ResponseResult.PARAMETER_IS_NULL.toMessResult(); } - Map message = new HashMap<>(); - message.put("tip",MessageTypeEnum.UNIVERSAL.CODE); + Map message = new HashMap<>(); + message.put("tip", MessageTypeEnum.UNIVERSAL.CODE); message.put("organizeName", organizeName); message.put("patientId", patientId); - message.put("doctorCode",doctorCode); - message.put("IdCard",IdCard); - message.put("content",content); - message.put("url",url==null?"":url); + message.put("doctorCode", doctorCode); + message.put("IdCard", IdCard); + message.put("content", content); + message.put("url", url == null ? "" : url); rabbitSender.TipSend(message); return ResponseResult.JOIN_QUEUE.toMessResult(); } + + + @PostMapping("hisUniversal") + @ResponseBody + public MessageSendResult hisUniversal(@RequestBody Map paramsMap) { + log.info("进入接口-[HIS推送接口],params=[{}]", JSONObject.toJSONString(paramsMap)); + return hisUniversalService.hisUniversal(paramsMap); + } } diff --git a/src/main/java/com/ynxbd/push/entity/enums/HisApiEnum.java b/src/main/java/com/ynxbd/push/entity/enums/HisApiEnum.java new file mode 100644 index 0000000..a3e2152 --- /dev/null +++ b/src/main/java/com/ynxbd/push/entity/enums/HisApiEnum.java @@ -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; + } +} diff --git a/src/main/java/com/ynxbd/push/entity/enums/MsgParamEnum.java b/src/main/java/com/ynxbd/push/entity/enums/MsgParamEnum.java new file mode 100644 index 0000000..66e7c61 --- /dev/null +++ b/src/main/java/com/ynxbd/push/entity/enums/MsgParamEnum.java @@ -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 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 getMapValue(Map paramsMap, String key) throws Exception { + return getMapValue(paramsMap, key, false, null); + } + + /** + * 获取参数 + * + * @param paramsMap 参数集 + * @param key 参数key + * @param color 颜色 + */ + public Map getMapValue(Map paramsMap, String key, String color) throws Exception { + return getMapValue(paramsMap, key, false, color); + } + + /** + * 获取参数 + * + * @param paramsMap 参数集 + * @param key 参数key + * @param canNull 是否可以为空 + */ + public Map getMapValue(Map paramsMap, String key, boolean canNull, String color) throws Exception { + if (ObjectUtils.isEmpty(key)) { + throw new Exception("参数key缺失"); + } + Map 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 paramsMap, Map 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 paramsMap, Map 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)); + } +} diff --git a/src/main/java/com/ynxbd/push/entity/response/ResponseResult.java b/src/main/java/com/ynxbd/push/entity/response/ResponseResult.java index 1b7ca3e..0c3f0b9 100644 --- a/src/main/java/com/ynxbd/push/entity/response/ResponseResult.java +++ b/src/main/java/com/ynxbd/push/entity/response/ResponseResult.java @@ -10,34 +10,34 @@ import weixin.popular.bean.message.MessageSendResult; */ 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", "医生未绑定"), + CALL_NO_IS_NOT_FIND("50011", "调用码未找到"), + TEMPLATE_ID_IS_NOT_FIND("50010", "模板ID未找到"), + CODE_INVALIDATION("40001", "token无效"), - DOCTOR_NOT_BIND("50004","医生未绑定"), + NOT_FIND_DATA("40004", "未找到数据"), + CODE_EXPIRED("42001", "token过期"), - CODE_INVALIDATION("40001","token无效"), - - NOT_FIND_DATA("40004","未找到数据"), - CODE_EXPIRED("42001","token过期"), - - MESSAGE_RESULT_ERROR_CODE("4002","结果返回错误"); + MESSAGE_RESULT_ERROR_CODE("4002", "结果返回错误"); public final String ERR_CODE; public final String ERR_MSG; - ResponseResult(String errCode,String errMsg){ + ResponseResult(String errCode, String errMsg) { this.ERR_CODE = errCode; this.ERR_MSG = errMsg; } - public MessageSendResult toMessResult(){ + public MessageSendResult toMessResult() { MessageSendResult result = new MessageSendResult(); result.setErrmsg(this.ERR_MSG); result.setErrcode(this.ERR_CODE); diff --git a/src/main/java/com/ynxbd/push/entity/tencent/SendTemplate.java b/src/main/java/com/ynxbd/push/entity/tencent/SendTemplate.java new file mode 100644 index 0000000..a1a91bc --- /dev/null +++ b/src/main/java/com/ynxbd/push/entity/tencent/SendTemplate.java @@ -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 data; + + @Tolerate + SendTemplate() { + } +} diff --git a/src/main/java/com/ynxbd/push/entity/type/MessageTypeEnum.java b/src/main/java/com/ynxbd/push/entity/type/MessageTypeEnum.java index 695938a..9bbf6ce 100644 --- a/src/main/java/com/ynxbd/push/entity/type/MessageTypeEnum.java +++ b/src/main/java/com/ynxbd/push/entity/type/MessageTypeEnum.java @@ -1,5 +1,7 @@ package com.ynxbd.push.entity.type; +import org.springframework.util.ObjectUtils; + /** * @author 李进才 * @ClassName MessageTypeEnum @@ -13,8 +15,8 @@ public enum MessageTypeEnum { MEDICAL_RECORD("MedicalRecord","病历复印"), TREAT_PLAN("treatPlan","诊疗计划提醒"), - UNIVERSAL("Universal","通用模版推送-绑定通知"); - + UNIVERSAL("Universal","通用模版推送-绑定通知"), + COMMON("COMMON","COMMON"); public final String CODE; public final String MESSAGE; @@ -25,4 +27,17 @@ public enum MessageTypeEnum { 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; + } + } diff --git a/src/main/java/com/ynxbd/push/helper/BusinessHelper.java b/src/main/java/com/ynxbd/push/helper/BusinessHelper.java index f232e11..d03e9e2 100644 --- a/src/main/java/com/ynxbd/push/helper/BusinessHelper.java +++ b/src/main/java/com/ynxbd/push/helper/BusinessHelper.java @@ -11,12 +11,12 @@ import weixin.popular.bean.message.MessageSendResult; */ public class BusinessHelper { - public static MessageSendResult ParamsCheck(String organizeName ,String patientId,String idCard,String doctorCode ) { + public static MessageSendResult ParamsCheck(String organizeName, String patientId, String idCard, String doctorCode) { MessageSendResult messageSendResult = new MessageSendResult(); - if(patientId==null&&idCard==null&&doctorCode==null){ + if (patientId == null && idCard == null && doctorCode == null) { return ResponseResult.PARAMETER_IS_NULL.toMessResult(); } - if(DesEncryptHelper.deCode(organizeName).equals("error:null")){ + if (DesEncryptHelper.deCode(organizeName).equals("error:null")) { return ResponseResult.ORGANIZE_IS_NULL.toMessResult(); } messageSendResult.setErrcode("0"); diff --git a/src/main/java/com/ynxbd/push/helper/DesEncryptHelper.java b/src/main/java/com/ynxbd/push/helper/DesEncryptHelper.java index f1fd109..fcc6a93 100644 --- a/src/main/java/com/ynxbd/push/helper/DesEncryptHelper.java +++ b/src/main/java/com/ynxbd/push/helper/DesEncryptHelper.java @@ -77,5 +77,9 @@ public class DesEncryptHelper { System.out.println(DesEncryptHelper.enCode("xbd_CVMS", 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("永胜县人民医院"))); } } diff --git a/src/main/java/com/ynxbd/push/helper/MapHelper.java b/src/main/java/com/ynxbd/push/helper/MapHelper.java new file mode 100644 index 0000000..763ad27 --- /dev/null +++ b/src/main/java/com/ynxbd/push/helper/MapHelper.java @@ -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 objMapToStrMap(Map objMap) { + Map strMap = new HashMap<>(); + for (Map.Entry 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 strMapToObjMap(Map strMap) { + Map objMap = new HashMap<>(); + for (Map.Entry 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 ""; + } + } +} diff --git a/src/main/java/com/ynxbd/push/helper/MessageApiHelper.java b/src/main/java/com/ynxbd/push/helper/MessageApiHelper.java index ea0ae3f..000b025 100644 --- a/src/main/java/com/ynxbd/push/helper/MessageApiHelper.java +++ b/src/main/java/com/ynxbd/push/helper/MessageApiHelper.java @@ -1,10 +1,11 @@ package com.ynxbd.push.helper; +import com.alibaba.fastjson.JSONObject; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.sun.jndi.toolkit.url.UrlUtil; import com.ynxbd.push.config.IniConfig; import com.ynxbd.push.entity.*; +import com.ynxbd.push.entity.enums.MsgParamEnum; import com.ynxbd.push.entity.response.ResponseResult; import com.ynxbd.push.entity.tencent.*; 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.impl.nio.client.CloseableHttpAsyncClient; import org.springframework.beans.BeanUtils; +import org.springframework.util.ObjectUtils; import org.springframework.web.util.UriUtils; import weixin.popular.api.API; import weixin.popular.api.MessageAPI; @@ -64,7 +66,7 @@ public class MessageApiHelper { */ public static MessageSendResult templateMessageSend(SendMessageTemplate template) { MessageSendResult messageSendResult = templateMessage(template); - log.info("消息发送状态:腾讯返回-{},messageId-{},openId-{}", messageSendResult.getErrcode(),template.getMessage_id(),template.getOpenId()); + log.info("消息发送状态:腾讯返回-{},messageId-{},openId-{}", messageSendResult.getErrcode(), template.getMessage_id(), template.getOpenId()); return messageSendResult; } @@ -76,7 +78,7 @@ public class MessageApiHelper { */ public static MessageSendResult templateMessage(SendMessageTemplate sendMessageTemplate) { try { - sendMessageTemplate.setUrl(UriUtils.decode(sendMessageTemplate.getUrl(),StandardCharsets.UTF_8.toString())); + sendMessageTemplate.setUrl(UriUtils.decode(sendMessageTemplate.getUrl(), StandardCharsets.UTF_8.toString())); String jsonMessage = TemplateSelectHelper.select(sendMessageTemplate); jsonMessage = jsonMessage.replaceAll("\\\\\\\\r", "\\\\r"); jsonMessage = jsonMessage.replaceAll("\\\\\\\\n", "\\\\n"); @@ -150,6 +152,7 @@ public class MessageApiHelper { /** * 根据患者ID或者医生ID推送模版消息 + * * @param organizeName * @param idCard * @param title @@ -165,29 +168,29 @@ public class MessageApiHelper { * @param url * @return */ - public static MessageSendResult TemplateMessageForCode(String organizeName,String code, String idCard, String title, String patientId, String doctorCode, String first, String keyword1, String keyword2, String keyword3, String keyword4, String keyword5, String remark, String url,String messageId){ - if(patientId==null&&idCard==null&&doctorCode==null){ - log.info("[{}]参数无效",title); + public static MessageSendResult TemplateMessageForCode(String organizeName, String code, String idCard, String title, String patientId, String doctorCode, String first, String keyword1, String keyword2, String keyword3, String keyword4, String keyword5, String remark, String url, String messageId) { + if (patientId == null && idCard == null && doctorCode == null) { + log.info("[{}]参数无效", title); return ResponseResult.PARAMETER_IS_NULL.toMessResult(); } - if(DesEncryptHelper.deCode(organizeName).equals("error:null")){ - log.info("[{}]组织机构代码无效,organizeName-{}",title,organizeName); + if (DesEncryptHelper.deCode(organizeName).equals("error:null")) { + log.info("[{}]组织机构代码无效,organizeName-{}", title, organizeName); return ResponseResult.ORGANIZE_IS_NULL.toMessResult(); } String reportTemplateId = WeChatDataRequest.getTemplateId(title); - if("绑定通知".equals(title)&&reportTemplateId==null){ + if ("绑定通知".equals(title) && reportTemplateId == null) { reportTemplateId = WeChatDataRequest.getTemplateId("医院通知"); } - if(IniConfig.getInstance("templateVersion")==null){ + if (IniConfig.getInstance("templateVersion") == null) { code = ""; } - if(doctorCode!=null){ + if (doctorCode != null) { List allDoctorCodeList = WeChatDataRequest.getAllOpenIdForDoctorCode(doctorCode); - if (allDoctorCodeList.isEmpty()){ - log.info("[{}]{}未绑定微官网,doctorCode:{}",title,DesEncryptHelper.deCode(organizeName),doctorCode); + if (allDoctorCodeList.isEmpty()) { + log.info("[{}]{}未绑定微官网,doctorCode:{}", title, DesEncryptHelper.deCode(organizeName), doctorCode); return ResponseResult.NOT_FIND_DATA.toMessResult(); } - for (String interfaceOpenId:allDoctorCodeList){ + for (String interfaceOpenId : allDoctorCodeList) { String openId = AesCodeHelper.deCode(interfaceOpenId); SendMessageTemplate sendMessageTemplate = SendMessageTemplate.builder() .template_id(reportTemplateId) @@ -204,19 +207,19 @@ public class MessageApiHelper { .url(url) .build(); MessageSendResult messageSendResult = templateMessageSend(sendMessageTemplate); - log.info("[{}]{}医生账号消息推送,推送结果代码-{},推送结果-{}",title,DesEncryptHelper.deCode(organizeName),messageSendResult.getErrcode(),messageSendResult.getErrmsg()); + log.info("[{}]{}医生账号消息推送,推送结果代码-{},推送结果-{}", title, DesEncryptHelper.deCode(organizeName), messageSendResult.getErrcode(), messageSendResult.getErrmsg()); } return ResponseResult.JOIN_QUEUE.toMessResult(); } - log.info("[外部组织对接推送]"+DesEncryptHelper.deCode(organizeName)+"发送"+title+"消息"); - String weChatUrl ="http://127.0.0.1/wx/"; + log.info("[外部组织对接推送]" + DesEncryptHelper.deCode(organizeName) + "发送" + 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", patientId!=null?patientId:idCard) + .append(patientId != null ? "patient/getOpenIdsByPatientId.do" : "patient/getOpenIdsByCardNo.do").toString()) + .addParameter(patientId != null ? "patientId" : "cardNo", patientId != null ? patientId : idCard) .addParameter("algorithm", "des") .addParameter("isEncryptComma", "false") .addParameter("isLastBind", "true") @@ -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 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 temp = MapHelper.strMapToObjMap(strTemp); + + if (doctorCode != null) { + List 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(); + } + } + } diff --git a/src/main/java/com/ynxbd/push/rabbit/receive/RabbitReceiver.java b/src/main/java/com/ynxbd/push/rabbit/receive/RabbitReceiver.java index acaba7e..c68c91f 100644 --- a/src/main/java/com/ynxbd/push/rabbit/receive/RabbitReceiver.java +++ b/src/main/java/com/ynxbd/push/rabbit/receive/RabbitReceiver.java @@ -1,8 +1,9 @@ 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.entity.response.ResponseResult; +import com.ynxbd.push.entity.type.MessageTypeEnum; import com.ynxbd.push.helper.MessageApiHelper; import com.ynxbd.push.rabbit.send.RabbitSender; import lombok.extern.slf4j.Slf4j; @@ -16,10 +17,7 @@ import weixin.popular.bean.message.MessageSendResult; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; -import java.util.Base64; -import java.util.Date; -import java.util.Map; -import java.util.UUID; +import java.util.*; import java.util.concurrent.TimeoutException; /** @@ -36,22 +34,31 @@ public class RabbitReceiver { @Autowired private RabbitSender rabbitSender; - private final static String REPORT_TIP = "ReportTip"; - private final static String QUEUE_TIP = "QueueTip"; - private final static String MEDICAL_RECORD = "MedicalRecord"; - private final static String TREAT_PLAN = "treatPlan"; - - private final static String UNIVERSAL = "Universal"; - +// private final static String REPORT_TIP = "ReportTip"; +// private final static String QUEUE_TIP = "QueueTip"; +// private final static String MEDICAL_RECORD = "MedicalRecord"; +// private final static String TREAT_PLAN = "treatPlan"; +// +// private final static String UNIVERSAL = "Universal"; @RabbitHandler - public void receive(Map receiveMessage) { + public void receive(Map receiveMessage) { try { log.info("rabbit开始消费消息,内容-{}", receiveMessage); if (Integer.parseInt(receiveMessage.get("count")) > 2) { 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: reportTip(receiveMessage); break; @@ -67,18 +74,44 @@ public class RabbitReceiver { case UNIVERSAL: universal(receiveMessage); break; + case COMMON: + his(receiveMessage); + break; + default: - log.info("未找到消息类型进行推送,类型-{}", receiveMessage.get("tip")); + log.info("未找到消息类型进行推送,类型-{}", tip); break; } - } - catch (Exception e){ - log.error("消息消费出错:{},内容-{}",e,receiveMessage); +// 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); } } - private void reportTip(Map receiveMessage) { + private void reportTip(Map receiveMessage) { String organizeName = receiveMessage.get("organizeName"); String messageId = receiveMessage.get("message_id"); String code = receiveMessage.get("tip"); @@ -93,34 +126,34 @@ public class RabbitReceiver { String applyDept = receiveMessage.get("applyDept") == null ? "" : receiveMessage.get("applyDept"); String applyDoctor = receiveMessage.get("applyDoctor") == null ? "" : receiveMessage.get("applyDoctor"); String weChatUrl = IniConfig.getInstance("weChatUrl") == null ? "" : receiveMessage.get("weChatUrl"); - retry(MessageApiHelper.TemplateMessageForCode(organizeName,code, idCard, "检验检查报告通知", + retry(MessageApiHelper.TemplateMessageForCode(organizeName, code, idCard, "检验检查报告通知", patientId, null, "您有新的报告。" + patientName + (age.equals("") ? "" : "(" + age + ")"), patientId, patientName + (sex.equals("") ? "" : "(" + sex + ")"), reportId, reportTime, itemName, "您的报告结果已经出具。" + (applyDoctor.equals("") ? "" : "申请医生:" + applyDoctor + ";") + (applyDept.equals("") ? "" : "申请科室:" + applyDept), weChatUrl + IniConfig.getInstance("reportUrl") + "/all-result.html", messageId), receiveMessage); } - private void queueTip(Map receiveMessage) { + + private void queueTip(Map receiveMessage) { try { String organizeName = receiveMessage.get("organizeName"); String messageId = receiveMessage.get("message_id"); String code = receiveMessage.get("tip"); - String patientId = receiveMessage.get("patientId")==null?"":receiveMessage.get("patientId"); - String idCard = receiveMessage.get("idCard")==null?"":receiveMessage.get("idCard"); - String patientName = receiveMessage.get("patientName")==null?"":receiveMessage.get("patientName"); - String deptName = receiveMessage.get("deptName")==null?"":receiveMessage.get("deptName"); - String doctorName = receiveMessage.get("doctorName")==null?"":receiveMessage.get("doctorName"); - String currentNumber = receiveMessage.get("currentNumber")==null?"":receiveMessage.get("currentNumber"); - String selfNumber = receiveMessage.get("selfNumber")==null?"":receiveMessage.get("selfNumber"); - 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); - } - catch (Exception e){ - log.error("[推送消息组织出错]params-{}, error-{}",receiveMessage, e.toString()); + String patientId = receiveMessage.get("patientId") == null ? "" : receiveMessage.get("patientId"); + String idCard = receiveMessage.get("idCard") == null ? "" : receiveMessage.get("idCard"); + String patientName = receiveMessage.get("patientName") == null ? "" : receiveMessage.get("patientName"); + String deptName = receiveMessage.get("deptName") == null ? "" : receiveMessage.get("deptName"); + String doctorName = receiveMessage.get("doctorName") == null ? "" : receiveMessage.get("doctorName"); + String currentNumber = receiveMessage.get("currentNumber") == null ? "" : receiveMessage.get("currentNumber"); + String selfNumber = receiveMessage.get("selfNumber") == null ? "" : receiveMessage.get("selfNumber"); + 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); + } catch (Exception e) { + log.error("[推送消息组织出错]params-{}, error-{}", receiveMessage, e.toString()); } } - private void medicalRecord(Map receiveMessage) { + private void medicalRecord(Map receiveMessage) { String organizeName = receiveMessage.get("organizeName"); String messageId = receiveMessage.get("message_id"); String code = receiveMessage.get("tip"); @@ -128,11 +161,11 @@ public class RabbitReceiver { SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern("yyyy-MM-dd"); Date date = new Date(); - String url =IniConfig.getInstance("domain")+"wx/"+IniConfig.getInstance("weChatUIPath")+"medical-record.html#/medical-record-history"; - retry(MessageApiHelper.TemplateMessageForCode(organizeName,code,null,"医院通知",patientId,null,"病历复印申请已通过",sdf.format(date),"病历复印申请已通过,请点击跳转付费",null,null,null,"查看详情",url,messageId),receiveMessage); + String url = IniConfig.getInstance("domain") + "wx/" + IniConfig.getInstance("weChatUIPath") + "medical-record.html#/medical-record-history"; + retry(MessageApiHelper.TemplateMessageForCode(organizeName, code, null, "医院通知", patientId, null, "病历复印申请已通过", sdf.format(date), "病历复印申请已通过,请点击跳转付费", null, null, null, "查看详情", url, messageId), receiveMessage); } - private void treatPlan(Map receiveMessage){ + private void treatPlan(Map receiveMessage) { String messageId = receiveMessage.get("message_id"); String code = receiveMessage.get("tip"); String organizeName = receiveMessage.get("organizeName"); @@ -143,10 +176,10 @@ public class RabbitReceiver { String content = receiveMessage.get("content"); String url = receiveMessage.get("url"); String remark = receiveMessage.get("remark"); - retry(MessageApiHelper.TemplateMessageForCode(organizeName,code,null,"诊疗计划提醒",patientId,null,title,name,planTime,content,null,null,remark,url,messageId),receiveMessage); + retry(MessageApiHelper.TemplateMessageForCode(organizeName, code, null, "诊疗计划提醒", patientId, null, title, name, planTime, content, null, null, remark, url, messageId), receiveMessage); } - private void universal(Map receiveMessage) { + private void universal(Map receiveMessage) { SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern("yyyy-MM-dd"); Date date = new Date(); @@ -159,29 +192,37 @@ public class RabbitReceiver { String IdCard = receiveMessage.get("IdCard"); String doctorCode = receiveMessage.get("doctorCode"); String viewUrl; - if(!"".equals(url)){ + if (!"".equals(url)) { viewUrl = url; - }else { - viewUrl = IniConfig.getInstance("domain")+"wx/"+IniConfig.getInstance("weChatUIPath")+"push-universal.html?patientId="+ ("".equals(patientId)? Base64.getEncoder().encodeToString(patientId.getBytes()): "") + "&content="+Base64.getEncoder().encodeToString(UriUtils.encode(content, StandardCharsets.UTF_8.toString()).getBytes())+"&time="+Base64.getEncoder().encodeToString(sdf.format(date).getBytes()); + } else { + viewUrl = IniConfig.getInstance("domain") + "wx/" + IniConfig.getInstance("weChatUIPath") + "push-universal.html?patientId=" + ("".equals(patientId) ? Base64.getEncoder().encodeToString(patientId.getBytes()) : "") + "&content=" + Base64.getEncoder().encodeToString(UriUtils.encode(content, StandardCharsets.UTF_8.toString()).getBytes()) + "&time=" + Base64.getEncoder().encodeToString(sdf.format(date).getBytes()); } - if(IniConfig.getInstance("templateVersion")!=null){ - content = content.substring(0,16)+"……"; + if (IniConfig.getInstance("templateVersion") != null) { + 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 message) { - if(!(messageSendResult.getErrcode().equals("0")||messageSendResult.getErrcode().equals(ResponseResult.ORGANIZE_IS_NULL.ERR_CODE)||messageSendResult.getErrcode().equals(ResponseResult.PARAMETER_IS_NULL.ERR_CODE)||messageSendResult.getErrcode().equals(ResponseResult.NOT_FIND_DATA.ERR_CODE))){ + private void retry(MessageSendResult messageSendResult, Map message) { + if (!(messageSendResult.getErrcode().equals("0") || messageSendResult.getErrcode().equals(ResponseResult.ORGANIZE_IS_NULL.ERR_CODE) || messageSendResult.getErrcode().equals(ResponseResult.PARAMETER_IS_NULL.ERR_CODE) || messageSendResult.getErrcode().equals(ResponseResult.NOT_FIND_DATA.ERR_CODE))) { int count = Integer.parseInt(message.get("count")); - log.info("[微信消息推送]进入重试机制,重试次数-{},重试参数-{},失败原因-{}",count,message,messageSendResult.getErrcode()); - message.put("count",String.valueOf((count+1))); + log.info("[微信消息推送]进入重试机制,重试次数-{},重试参数-{},失败原因-{}", count, message, messageSendResult.getErrcode()); + message.put("count", String.valueOf((count + 1))); rabbitSender.send(message); } - } + 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(new String(Base64.getDecoder().decode("JUU1JUIwJThBJUU2JTk1JUFDJUU3JTlBJTg0JUU2JTgyJUEzJUU4JTgwJTg1JUU2JTgyJUE4JUU1JUE1JUJEJUVGJUJDJThDJUU2JTgyJUE4JUU3JTlBJTg0JUU1JUE0JTg0JUU2JTk2JUI5JUU1JUI3JUIyJUU3JUJCJThGJUU1JTg3JUJBJUU1JTg1JUI3JUVGJUJDJThDJUU4JUFGJUI3JUU0JUJEJUEwJUU1JTlDJUE4JUU4JUE3JTg0JUU1JUFFJTlBJUU2JTk3JUI2JUU5JTk3JUI0JUU1JTg2JTg1JUU1JTg5JThEJUU1JUJFJTgwJUU1JUE0JTg0JUU2JTk2JUI5JUU4JUJGJTlCJUU4JUExJThDJUU2JTk0JUFGJUU0JUJCJTk4JUVGJUJDJThDJUU4JUIwJUEyJUU4JUIwJUEyJUU5JTg1JThEJUU1JTkwJTg4"))); } + + + private void his(Map receiveMessage) { + MessageSendResult messageSendResult = MessageApiHelper.templateMessageForCode02(receiveMessage); + retry(messageSendResult, receiveMessage); + } + } diff --git a/src/main/java/com/ynxbd/push/rabbit/send/RabbitSender.java b/src/main/java/com/ynxbd/push/rabbit/send/RabbitSender.java index bc9e612..9c540dd 100644 --- a/src/main/java/com/ynxbd/push/rabbit/send/RabbitSender.java +++ b/src/main/java/com/ynxbd/push/rabbit/send/RabbitSender.java @@ -1,6 +1,6 @@ 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.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; @@ -20,14 +20,27 @@ public class RabbitSender { @Autowired private RabbitTemplate rabbitTemplate; - public void TipSend(Map message){ - message.put("count","0"); + public void TipSend(Map message) { + message.put("count", "0"); send(message); } - public void send(Map message) { + + public void send(Map message) { + String uuid = UUID.randomUUID().toString(); + CorrelationData correlationData = new CorrelationData(uuid); + message.put("message_id", uuid); + this.rabbitTemplate.convertAndSend("wxPushExchange", "wxPushRouting", message, correlationData); + } + + + public void sendByTip(Map messageObj) { + Map message = MapHelper.objMapToStrMap(messageObj); String uuid = UUID.randomUUID().toString(); CorrelationData correlationData = new CorrelationData(uuid); + message.put("count", "0"); message.put("message_id", uuid); - this.rabbitTemplate.convertAndSend("wxPushExchange","wxPushRouting",message,correlationData); +// System.out.println("end=" + JSONObject.toJSONString(message)); + this.rabbitTemplate.convertAndSend("wxPushExchange", "wxPushRouting", message, correlationData); } + } diff --git a/src/main/java/com/ynxbd/push/service/HisUniversalService.java b/src/main/java/com/ynxbd/push/service/HisUniversalService.java new file mode 100644 index 0000000..cfd1031 --- /dev/null +++ b/src/main/java/com/ynxbd/push/service/HisUniversalService.java @@ -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 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 createTemplate(Map 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 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 paramsMap, String templateId, String title) { + try { + Map 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 paramsMap, String templateId, String title) { + try { + Map 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 paramsMap, String templateId, String title) { + try { + Map 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 paramsMap, String templateId, String title) { + try { + Map 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 paramsMap, String templateId, String title) { + try { + Map 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 map = new HashMap<>(); + map.put("a", 1); + map.put("b", "2"); + map.put("c", new HashMap() {{ + put("d", "1"); + }}); + + log.info(JSONObject.toJSONString(map)); + Map map2 = new HashMap<>(); + for (Map.Entry 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 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)); + } +}