package com.ynxbd.wx.config; import com.ynxbd.common.bean.Patient; import com.ynxbd.common.bean.enums.MerchantEnum; import com.ynxbd.common.bean.pay.Recipe; import com.ynxbd.common.bean.pay.Register; import com.ynxbd.common.dao.PatientDao; import com.ynxbd.common.helper.ProperHelper; import com.ynxbd.common.helper.http.OkHttpHelper; import com.ynxbd.wx.utils.DesEncryptHelper; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ObjectUtils; import java.util.List; @Slf4j public class MessagePushConfig { private MessagePushConfig() { } // 挂号导航是否开启功能===================================== public static final boolean REG_NAVIGATE_IS_ENABLE; // 挂号导航请求链接 public static final String REG_NAVIGATE_URL; // 挂号成功推送是否开启功能================================== public static final boolean REG_IS_ENABLE; // 挂号请求链接 public static final String REG_URL; // 是否开启功能============================================ public static final boolean REG_CANCEL_IS_ENABLE; // 消息推送链接 public static final String REG_CANCEL_URL; // 是否开启功能============================================ public static final boolean RECIPE_IS_ENABLE; /** * 消息推送主链接 */ public static final String HOST_URL; // 消息推送链接 public static final String RECIPE_URL; static { ProperHelper config = new ProperHelper().read("message-push.properties"); REG_NAVIGATE_IS_ENABLE = config.getBoolean("msg.reg.navigate.is_enable", false); REG_NAVIGATE_URL = config.getString("msg.reg.navigate.url"); // REG_IS_ENABLE = config.getBoolean("msg.reg.is_enable", false); REG_URL = config.getString("msg.reg.url"); // REG_CANCEL_IS_ENABLE = config.getBoolean("msg.reg.cancel.is_enable", false); REG_CANCEL_URL = config.getString("msg.reg.cancel.url"); HOST_URL = config.getString("msg.host.url"); // RECIPE_IS_ENABLE = config.getBoolean("msg.recipe.is_enable", false); RECIPE_URL = config.getString("msg.recipe.url"); if (REG_CANCEL_URL == null) { log.error("【消息推送】配置文件message-push.properties读取失败"); } } /** * 挂号导航推送 * * @param reg 挂号信息 */ public static void regNavigatePush(MerchantEnum merchantEnum, Register reg) { try { if (!merchantEnum.equals(MerchantEnum.WX) || !REG_NAVIGATE_IS_ENABLE || ObjectUtils.isEmpty(REG_NAVIGATE_URL)) { return; } String openid = reg.getOpenid(); String patientId = reg.getPatientId(); String regDate = reg.getRegDate(); // 挂号日期 String begTime = reg.getBegTime(); // 开始时间 String endTime = reg.getEndTime(); // 结束时间 String doctName = reg.getDoctName(); String deptName = reg.getDeptName(); String deptCode = reg.getDeptCode(); if (openid == null || patientId == null) { log.warn("[推送]挂号导航通知失败,参数缺失~openid={}, patientId={}", openid, patientId); return; } Patient patient = new PatientDao().selectByOpenidAndPatientId(openid, patientId); if (patient == null) { log.warn("[推送]挂号导航通知失败,患者信息不存在~"); return; } log.info("[挂号导航]开始推送 openid={}, patientId={}", openid, patientId); String time = (ObjectUtils.isEmpty(begTime) || ObjectUtils.isEmpty(endTime)) ? "" : (" " + begTime + "-" + endTime); OkHttpHelper.getAsync(REG_NAVIGATE_URL, params -> { params.put("patientName", patient.getName() + " ID:" + patientId); params.put("content", "就诊时间:" + regDate + time); params.put("deptName", deptName); params.put("deptCode", deptCode); params.put("openId", DesEncryptHelper.enCode(openid)); }); } catch (Exception e) { log.warn("[推送]挂号导航通知失败 {}", e.getMessage()); } } /** * 挂号推送 */ public static void regPush(MerchantEnum merchantEnum, Register reg) { try { if (!merchantEnum.equals(MerchantEnum.WX) || !REG_IS_ENABLE || reg == null || ObjectUtils.isEmpty(REG_URL)) { return; } log.info("[推送]挂号通知..."); String openid = reg.getOpenid(); String patientId = reg.getPatientId(); String regDate = reg.getRegDate(); // 挂号日期 String begTime = reg.getBegTime(); // 开始时间 String endTime = reg.getEndTime(); // 结束时间 String doctName = reg.getDoctName(); String deptName = reg.getDeptName(); String deptCode = reg.getDeptCode(); String tradeNo = reg.getTradeNo(); if (openid == null || patientId == null) { log.warn("[推送]挂号通知失败,参数缺失~openid={}, patientId={}", openid, patientId); return; } Patient patient = new PatientDao().selectByOpenidAndPatientId(openid, patientId); if (patient == null) { log.warn("[推送]挂号通知失败,患者信息不存在"); return; } String time = (ObjectUtils.isEmpty(begTime) || ObjectUtils.isEmpty(endTime)) ? "" : (" " + begTime + "-" + endTime); OkHttpHelper.getAsync(REG_URL, params -> { params.put("openId", DesEncryptHelper.enCode(openid)); params.put("patientName", patient.getName() + " ID:" + patientId); params.put("deptName", deptName); params.put("doctor", doctName + "(" + regDate + time + ")"); // 医生姓名 params.put("sex", patient.getSex()); // 医生姓名 params.put("seq", ""); // HIS交易流水号 }); } catch (Exception e) { log.warn("[推送]挂号通知 {}", e.getMessage()); } } /** * 取消预约推送 */ public static void regCancelPush(MerchantEnum merchantEnum, Register reg) { try { if (!merchantEnum.equals(MerchantEnum.WX) || !REG_CANCEL_IS_ENABLE || reg == null || ObjectUtils.isEmpty(REG_CANCEL_URL)) { return; } log.info("[推送]取消预约..."); String openid = reg.getOpenid(); String patientId = reg.getPatientId(); String regDate = reg.getRegDate(); // 挂号日期 String begTime = reg.getBegTime(); // 开始时间 String endTime = reg.getEndTime(); // 结束时间 String doctName = reg.getDoctName(); String deptName = reg.getDeptName(); String deptCode = reg.getDeptCode(); String tradeNo = reg.getTradeNo(); if (openid == null || patientId == null) { log.warn("[推送]取消预约通知失败,参数缺失~openid={}, patientId={}", openid, patientId); return; } Patient patient = new PatientDao().selectByOpenidAndPatientId(openid, patientId); if (patient == null) { log.info("[推送]取消预约通知失败,患者信息不存在~"); return; } String time = (ObjectUtils.isEmpty(begTime) || ObjectUtils.isEmpty(endTime)) ? "" : (" " + begTime + "-" + endTime); OkHttpHelper.getAsync(REG_CANCEL_URL, params -> { params.put("openId", DesEncryptHelper.enCode(openid)); params.put("patientName", patient.getName() + " ID:" + patientId); params.put("deptName", deptName); params.put("treatTime", regDate + time); // 就诊时间 params.put("seq", ""); params.put("doctor", doctName); // 医生姓名 params.put("sex", patient.getSex()); // 性别 }); } catch (Exception e) { log.warn("[推送]取消预约通知失败 {}", e.getMessage()); } } /** * 缴费成功推送 */ public static void recipePush(List recipeList, String treatNum, String patientId, String openid, String tip) { try { if (!RECIPE_IS_ENABLE || ObjectUtils.isEmpty(RECIPE_URL)) { return; } if (ObjectUtils.isEmpty(treatNum) || ObjectUtils.isEmpty(patientId) || ObjectUtils.isEmpty(openid)) { return; } StringBuilder sb = new StringBuilder(); Recipe recipe; for (int i = 0; i < recipeList.size(); i++) { recipe = recipeList.get(i); if (recipe != null) { sb.append(recipe.getRecipeId()); if ((i + 1) != recipeList.size()) { sb.append("、"); } } } Patient patient = new PatientDao().selectByOpenidAndPatientId(openid, patientId); if (patient == null) { return; } OkHttpHelper.getAsync(RECIPE_URL, params -> { params.put("openId", DesEncryptHelper.enCode(openid)); params.put("patientName", patient.getName() + " ID:" + patientId); params.put("content", tip); params.put("treatNum", treatNum); params.put("recipeIds", sb.toString()); }); } catch (Exception e) { log.warn("[推送]缴费信息通知失败 {}", e.getMessage()); } } }