|
|
|
|
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.healthcard.HCPreConsultHelper;
|
|
|
|
|
import com.ynxbd.common.helper.common.DateHelper;
|
|
|
|
|
import com.ynxbd.common.helper.common.XmlConfigHelper;
|
|
|
|
|
import com.ynxbd.common.helper.http.OkHttpHelper;
|
|
|
|
|
import com.ynxbd.wx.utils.DesEncryptHelper;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import okhttp3.FormBody;
|
|
|
|
|
import okhttp3.RequestBody;
|
|
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class MessagePushConfig {
|
|
|
|
|
private MessagePushConfig() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static final String ORGANIZENAME = "4B80803106B38A5F";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 消息推送链接
|
|
|
|
|
*/
|
|
|
|
|
public static final String HOST_URL;
|
|
|
|
|
|
|
|
|
|
// [挂号]导航推送 https://map.ipsmap.com?id=opBdKy87Gs&appKey=fnAs1mE5HP&poi=科室编码
|
|
|
|
|
public static final boolean REG_NAVIGATE_IS_ENABLE;
|
|
|
|
|
public static final String REG_NAVIGATE_API;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// [挂号]缴费通知
|
|
|
|
|
public static final boolean REG_PAID_IS_ENABLE;
|
|
|
|
|
public static final String REG_PAID_API;
|
|
|
|
|
|
|
|
|
|
// [挂号]取消预约
|
|
|
|
|
public static final boolean REG_CANCEL_IS_ENABLE;
|
|
|
|
|
public static final String REG_CANCEL_API;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// [挂号]预问诊reg_pre_consult
|
|
|
|
|
public static final boolean REG_PRE_CONSULT_IS_ENABLE;
|
|
|
|
|
public static final String REG_PRE_CONSULT_API;
|
|
|
|
|
|
|
|
|
|
// [处方]缴费通知
|
|
|
|
|
public static final boolean RX_PAID_IS_ENABLE;
|
|
|
|
|
public static final String RX_PAID_API;
|
|
|
|
|
|
|
|
|
|
// 产科建档
|
|
|
|
|
public static final boolean OBS_DOCUMENT_IS_ENABLE;
|
|
|
|
|
public static final String OBS_DOCUMENT_API;
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
|
XmlConfigHelper config = new XmlConfigHelper().read("wx-msg-push.xml");
|
|
|
|
|
|
|
|
|
|
HOST_URL = config.getString("host_url", "");
|
|
|
|
|
if (ObjectUtils.isEmpty(HOST_URL)) {
|
|
|
|
|
log.error("【消息推送】配置文件wx-msg-push.xml读取失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// [挂号]导航推送
|
|
|
|
|
XmlConfigHelper regNavigateConfig = config.getConfigNode("reg_navigate");
|
|
|
|
|
REG_NAVIGATE_IS_ENABLE = regNavigateConfig.getBoolean("is_enable", false);
|
|
|
|
|
REG_NAVIGATE_API = HOST_URL + regNavigateConfig.getString("api");
|
|
|
|
|
|
|
|
|
|
// [挂号]缴费通知
|
|
|
|
|
XmlConfigHelper regPaidConfig = config.getConfigNode("reg_paid");
|
|
|
|
|
REG_PAID_IS_ENABLE = regPaidConfig.getBoolean("is_enable", false);
|
|
|
|
|
REG_PAID_API = HOST_URL + regPaidConfig.getString("api");
|
|
|
|
|
|
|
|
|
|
// [挂号]取消预约
|
|
|
|
|
XmlConfigHelper regCancelConfig = config.getConfigNode("reg_cancel");
|
|
|
|
|
REG_CANCEL_IS_ENABLE = regCancelConfig.getBoolean("is_enable", false);
|
|
|
|
|
REG_CANCEL_API = HOST_URL + regCancelConfig.getString("api");
|
|
|
|
|
|
|
|
|
|
// [挂号]预问诊
|
|
|
|
|
XmlConfigHelper regAIConfig = config.getConfigNode("reg_pre_consult");
|
|
|
|
|
REG_PRE_CONSULT_IS_ENABLE = regAIConfig.getBoolean("is_enable", false);
|
|
|
|
|
REG_PRE_CONSULT_API = HOST_URL + regAIConfig.getString("api");
|
|
|
|
|
|
|
|
|
|
// [处方]缴费通知
|
|
|
|
|
XmlConfigHelper rxPaidConfig = config.getConfigNode("rx_paid");
|
|
|
|
|
RX_PAID_IS_ENABLE = rxPaidConfig.getBoolean("is_enable", false);
|
|
|
|
|
RX_PAID_API = HOST_URL + rxPaidConfig.getString("api");
|
|
|
|
|
|
|
|
|
|
// 产科建档
|
|
|
|
|
XmlConfigHelper obsDocumentConfig = config.getConfigNode("obs_document");
|
|
|
|
|
OBS_DOCUMENT_IS_ENABLE = obsDocumentConfig.getBoolean("is_enable", false);
|
|
|
|
|
OBS_DOCUMENT_API = HOST_URL + obsDocumentConfig.getString("api");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 挂号导航推送
|
|
|
|
|
*
|
|
|
|
|
* @param reg 挂号信息
|
|
|
|
|
*/
|
|
|
|
|
public static void regNavigatePush(MerchantEnum merchantEnum, Register reg) {
|
|
|
|
|
try {
|
|
|
|
|
if (!merchantEnum.equals(MerchantEnum.WX) || !REG_NAVIGATE_IS_ENABLE || ObjectUtils.isEmpty(REG_NAVIGATE_API)) {
|
|
|
|
|
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 (ObjectUtils.isEmpty(openid) || ObjectUtils.isEmpty(patientId)) {
|
|
|
|
|
log.warn("[推送]挂号导航通知失败,参数缺失 openid={}, patientId={}", openid, patientId);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Patient patient = new PatientDao().selectByOpenIdAndEPId(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_API, 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_PAID_IS_ENABLE || reg == null || ObjectUtils.isEmpty(REG_PAID_API)) {
|
|
|
|
|
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().selectByOpenIdAndEPId(openid, patientId);
|
|
|
|
|
if (patient == null) {
|
|
|
|
|
log.warn("[推送]挂号通知失败,患者信息不存在");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String time = (ObjectUtils.isEmpty(begTime) || ObjectUtils.isEmpty(endTime)) ? "" : (" " + begTime + "-" + endTime);
|
|
|
|
|
|
|
|
|
|
OkHttpHelper.getAsync(REG_PAID_API, 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());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 通用推送消息接口
|
|
|
|
|
*
|
|
|
|
|
* @param tip 所属部分
|
|
|
|
|
* @param patientId 患者id
|
|
|
|
|
* @param content 推送内容
|
|
|
|
|
* @param url 链接地址
|
|
|
|
|
*/
|
|
|
|
|
public static void businessPush(String tip, String patientId, String content, String url) {
|
|
|
|
|
if (patientId == null) {
|
|
|
|
|
log.info("[{}]通用推送错误,patientId为空", tip);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
log.info("[{}]通用推送开始,patientId-{},content-{},url-{}", tip, patientId, content, url);
|
|
|
|
|
RequestBody requestBody = new FormBody.Builder()
|
|
|
|
|
.add("patientId", patientId)
|
|
|
|
|
.add("content", content)
|
|
|
|
|
.add("url", url)
|
|
|
|
|
.add("organizeName", ORGANIZENAME)
|
|
|
|
|
.build();
|
|
|
|
|
OkHttpHelper.post(REG_PRE_CONSULT_API, requestBody);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 挂号完成-发起预问诊通知
|
|
|
|
|
*/
|
|
|
|
|
public static void regEndPreConsult(MerchantEnum merchantEnum, Register order) {
|
|
|
|
|
if (!merchantEnum.equals(MerchantEnum.WX)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
pushPreConsult(order, "为了帮助医生更全面地了解您的身体情况,请花2分钟时间填写病情信息,以便医生提前了解病症,为您提供更好的诊疗服务。");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 预问诊完成通知
|
|
|
|
|
*/
|
|
|
|
|
public static void preConsultReportNotify(Register order) {
|
|
|
|
|
pushPreConsult(order, "您好,您的预问诊报告可以查看啦");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 预问诊推送
|
|
|
|
|
*/
|
|
|
|
|
public static void pushPreConsult(Register order, String content) {
|
|
|
|
|
try {
|
|
|
|
|
if (order == null || !REG_PRE_CONSULT_IS_ENABLE || ObjectUtils.isEmpty(REG_PRE_CONSULT_API)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
log.info("[推送]预问诊通知...");
|
|
|
|
|
String openId = order.getOpenid();
|
|
|
|
|
String patientName = order.getPatientId();
|
|
|
|
|
String outTradeNo = order.getOutTradeNo();
|
|
|
|
|
|
|
|
|
|
if (ObjectUtils.isEmpty(openId) || ObjectUtils.isEmpty(patientName) || ObjectUtils.isEmpty(outTradeNo)) {
|
|
|
|
|
log.warn("[推送]预问诊完成通知-失败:参数缺失 openId={}, patientName={}, outTradeNo={}", openId, patientName, outTradeNo);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
String url = HCPreConsultHelper.getH5Online(outTradeNo);
|
|
|
|
|
if (ObjectUtils.isEmpty(url)) {
|
|
|
|
|
log.warn("[推送]预问诊完成通知-失败:链接为空[outTradeNo:{}]", outTradeNo);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RequestBody requestBody = new FormBody.Builder()
|
|
|
|
|
.add("openId", DesEncryptHelper.enCode(openId))
|
|
|
|
|
.add("patientName", patientName)
|
|
|
|
|
.add("date", DateHelper.getCurDate())
|
|
|
|
|
.add("content", content)
|
|
|
|
|
.add("url", url)
|
|
|
|
|
.add("organizeName", "355E376621BFA6B8")
|
|
|
|
|
.build();
|
|
|
|
|
OkHttpHelper.post(REG_PRE_CONSULT_API, requestBody);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("[推送]预问诊完成通知-异常-{}", e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 红河州医院产科建党推送
|
|
|
|
|
*
|
|
|
|
|
* @param merchantEnum
|
|
|
|
|
* @param reg
|
|
|
|
|
*/
|
|
|
|
|
public static void regObsDocument(MerchantEnum merchantEnum, Register reg) {
|
|
|
|
|
try {
|
|
|
|
|
if (!merchantEnum.equals(MerchantEnum.WX)
|
|
|
|
|
|| reg == null || ObjectUtils.isEmpty(OBS_DOCUMENT_API)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.info("[推送]产科建档推送通知...");
|
|
|
|
|
String patientId = reg.getPatientId();
|
|
|
|
|
if (patientId == null) {
|
|
|
|
|
log.warn("[推送]产科建档推送通知失败,参数缺失~ patientId= null");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RequestBody requestBody = new FormBody.Builder()
|
|
|
|
|
.add("patientId", patientId)
|
|
|
|
|
.add("content", "[孕产建档提示]尊敬的孕妈妈您好!为了向您提供更好的服务,请点击下方链接完成孕产建档,若您已建档请忽略!")
|
|
|
|
|
.add("url", "https://zhck.hhzyy.com:10082/wxapp/")
|
|
|
|
|
.add("organizeName", ORGANIZENAME)
|
|
|
|
|
.add("buttonName", "进入产科建档系统")
|
|
|
|
|
.build();
|
|
|
|
|
OkHttpHelper.post(OBS_DOCUMENT_API, requestBody);
|
|
|
|
|
} 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_API)) {
|
|
|
|
|
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().selectByOpenIdAndEPId(openid, patientId);
|
|
|
|
|
if (patient == null) {
|
|
|
|
|
log.info("[推送]取消预约通知失败,患者信息不存在~");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String time = (ObjectUtils.isEmpty(begTime) || ObjectUtils.isEmpty(endTime)) ? "" : (" " + begTime + "-" + endTime);
|
|
|
|
|
|
|
|
|
|
OkHttpHelper.getAsync(REG_CANCEL_API, 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 rxPush(List<Recipe> recipeList, String treatNum, String patientId, String openid, String tip) {
|
|
|
|
|
try {
|
|
|
|
|
if (!RX_PAID_IS_ENABLE || ObjectUtils.isEmpty(RX_PAID_API)) {
|
|
|
|
|
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().selectByOpenIdAndEPId(openid, patientId);
|
|
|
|
|
if (patient == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OkHttpHelper.getAsync(RX_PAID_API, 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());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|