diff --git a/pom.xml b/pom.xml
index 57102d84..d16eedee 100644
--- a/pom.xml
+++ b/pom.xml
@@ -34,6 +34,7 @@
0.9.1
1.18.4
3.0.3
+ 2.7.1
@@ -184,6 +185,12 @@
postdischarge-mobile
${xinelu.version}
+
+
+ org.simpleframework
+ simple-xml
+ ${simple-xml.version}
+
diff --git a/postdischarge-admin/src/main/resources/application.yml b/postdischarge-admin/src/main/resources/application.yml
index ad357f09..02e18e5d 100644
--- a/postdischarge-admin/src/main/resources/application.yml
+++ b/postdischarge-admin/src/main/resources/application.yml
@@ -182,3 +182,26 @@ xss:
excludes: /system/notice
# 匹配链接
urlPatterns: /system/*,/monitor/*,/tool/*
+
+# 微信小程序参数配置信息
+applet-chat-config:
+ # 微信小程序id,wxdec3416aa3d60cab
+ applet-id: wxdc32268eca6b78f9
+ # 微信小程序密钥,f58e19be0380c2ebc6e9e9684c0dacce
+ secret: 0d0e41432908750460aef2bf0aa871ae
+ # 微信小程序返回国家语言
+ lang: zh_CN
+ # 微信小程序授权类型
+ grant-type: authorization_code
+ # 微信小程序事件回调令牌
+ token: uI1NGHesp7ylIYVYQvp0TlcDmUTKCHj2
+ # 微信小程序事件回调消息加密密钥
+ encoding-aes-key: 5rbyhMBpdnxTEVT54zeHMNcXi3ccilQZ209QqGi89EW
+ # 优惠券领取模板id
+ coupon-receive-template-id: e1JRZaw1OfTz2b6X9DTqqaJtV4rXEt7uhwXoZLDb_eA
+ # 商品订单支付成功通知模板id
+ goods-order-template-id: -IxZeEkkXFhoSwGtBHbipKQ6kjEmkdTkswKeOypSsNQ
+ # 预约服务订单通知模板id
+ appoint-order-template-id: nUB9HRbqQXOVuTpkKBIHMgzWlNq6touzxf5QYBiMkbU
+ # 签到成功通知模板id
+ sign-template-id: S_c9bR4znSWpXg-6ACIMn7AkaR11dzo113XM8w4CKz0
diff --git a/postdischarge-common/src/main/java/com/xinelu/common/config/AppletChatConfig.java b/postdischarge-common/src/main/java/com/xinelu/common/config/AppletChatConfig.java
new file mode 100644
index 00000000..b2cd5dec
--- /dev/null
+++ b/postdischarge-common/src/main/java/com/xinelu/common/config/AppletChatConfig.java
@@ -0,0 +1,67 @@
+package com.xinelu.common.config;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+/**
+ * @Description 微信小程序参数配置类
+ * @Author 纪寒
+ * @Date 2024-03-19 15:52:38
+ * @Version 1.0
+ */
+@Data
+@Component
+@ConfigurationProperties(prefix = "applet-chat-config")
+public class AppletChatConfig {
+
+ /**
+ * 小程序id
+ */
+ private String appletId;
+
+ /**
+ * 小程序secret
+ */
+ private String secret;
+
+ /**
+ * 返回国家地区语言版本,zh_CN 简体,zh_TW 繁体,en 英语
+ */
+ private String lang;
+
+ /**
+ * 授权类型
+ */
+ private String grantType;
+
+ /**
+ * 微信小程序事件回调令牌
+ */
+ private String token;
+
+ /**
+ * 微信小程序事件回调消息加密密钥
+ */
+ private String encodingAesKey;
+
+ /**
+ * 优惠券领取模板id
+ */
+ private String couponReceiveTemplateId;
+
+ /**
+ * 商品订单支付成功通知模板id
+ */
+ private String goodsOrderTemplateId;
+
+ /**
+ * 预约服务订单通知模板id
+ */
+ private String appointOrderTemplateId;
+
+ /**
+ * 签到通知模板
+ */
+ private String signTemplateId;
+}
diff --git a/postdischarge-common/src/main/java/com/xinelu/common/enums/SubscribeMessageTypeEnum.java b/postdischarge-common/src/main/java/com/xinelu/common/enums/SubscribeMessageTypeEnum.java
new file mode 100644
index 00000000..a2ce93f0
--- /dev/null
+++ b/postdischarge-common/src/main/java/com/xinelu/common/enums/SubscribeMessageTypeEnum.java
@@ -0,0 +1,40 @@
+package com.xinelu.common.enums;
+
+import lombok.Getter;
+
+/**
+ * @Description 微信小程序订阅消息记录表 订阅消息类型枚举,
+ * @Date 2024-03-19 17:16:06
+ * @Author 纪寒
+ * @Version 1.0
+ */
+@Getter
+public enum SubscribeMessageTypeEnum {
+
+ /**
+ * 预约服务付款通知提醒
+ */
+ APPOINT_ORDER_MESSAGE_PUSH("APPOINT_ORDER_MESSAGE_PUSH"),
+
+ /**
+ * 优惠券领取提醒
+ */
+ COUPON_RECEIVE_MESSAGE_PUSH("COUPON_RECEIVE_MESSAGE_PUSH"),
+
+ /**
+ * 商品订单支付成功提醒
+ */
+ GOODS_ORDER_MESSAGE_PUSH("GOODS_ORDER_MESSAGE_PUSH"),
+
+ /**
+ * 签到积分通知提醒
+ */
+ SIGN_MESSAGE_PUSH("SIGN_MESSAGE_PUSH"),
+ ;
+
+ final private String info;
+
+ SubscribeMessageTypeEnum(String info) {
+ this.info = info;
+ }
+}
diff --git a/postdischarge-common/src/main/java/com/xinelu/common/utils/DateUtils.java b/postdischarge-common/src/main/java/com/xinelu/common/utils/DateUtils.java
index 7e8b39de..141a0bec 100644
--- a/postdischarge-common/src/main/java/com/xinelu/common/utils/DateUtils.java
+++ b/postdischarge-common/src/main/java/com/xinelu/common/utils/DateUtils.java
@@ -167,7 +167,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
* @param date LocalDate
* @param pattern 解析格式
* @return 日期字符串
- * @Author jihan
+ * @Author 纪寒
*/
public static String formatDateToString(LocalDate date, String pattern) {
if (Objects.isNull(date)) {
@@ -181,7 +181,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
*
* @param date 指定日期,如果为null,默认为当天
* @return 结束日期
- * @author jihan
+ * @author 纪寒
*/
public static LocalDateTime end(LocalDate date) {
return LocalDateTime.of(null == date ? LocalDate.now() : date, LocalTime.MAX);
@@ -193,7 +193,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
* @param beginTime 开始时间
* @param endTime 结束时间可以为null, 如果为null则表示now
* @return 分钟差值
- * @author jihan
+ * @author 纪寒
*/
public static long differenceMinutes(LocalDateTime beginTime, LocalDateTime endTime) {
if (null == beginTime) {
@@ -201,4 +201,15 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
}
return ChronoUnit.MINUTES.between(beginTime, null == endTime ? LocalDateTime.now() : endTime);
}
+
+ /**
+ * 时间戳转LocalDateTime
+ *
+ * @param timestamp 时间戳
+ * @return java.time.LocalDateTime
+ * @author 纪寒
+ */
+ public static LocalDateTime timestampToLocalDateTime(long timestamp) {
+ return LocalDateTime.ofEpochSecond(timestamp / 1000, 0, ZoneOffset.ofHours(8));
+ }
}
diff --git a/postdischarge-manage/src/main/java/com/xinelu/manage/domain/subscribemessagerecord/SubscribeMessageRecord.java b/postdischarge-manage/src/main/java/com/xinelu/manage/domain/subscribemessagerecord/SubscribeMessageRecord.java
index f0f00142..434714bc 100644
--- a/postdischarge-manage/src/main/java/com/xinelu/manage/domain/subscribemessagerecord/SubscribeMessageRecord.java
+++ b/postdischarge-manage/src/main/java/com/xinelu/manage/domain/subscribemessagerecord/SubscribeMessageRecord.java
@@ -87,7 +87,7 @@ public class SubscribeMessageRecord extends BaseEntity {
*/
@ApiModelProperty(value = "用于订阅消息次数")
@Excel(name = "用于订阅消息次数")
- private Long subscribeCount;
+ private Integer subscribeCount;
/**
* 订阅时间
diff --git a/postdischarge-manage/src/main/java/com/xinelu/manage/domain/subscribemessagesendrecord/SubscribeMessageSendRecord.java b/postdischarge-manage/src/main/java/com/xinelu/manage/domain/subscribemessagesendrecord/SubscribeMessageSendRecord.java
index 45aef908..074a0550 100644
--- a/postdischarge-manage/src/main/java/com/xinelu/manage/domain/subscribemessagesendrecord/SubscribeMessageSendRecord.java
+++ b/postdischarge-manage/src/main/java/com/xinelu/manage/domain/subscribemessagesendrecord/SubscribeMessageSendRecord.java
@@ -102,7 +102,7 @@ public class SubscribeMessageSendRecord extends BaseEntity {
*/
@ApiModelProperty(value = "推送结果状态码")
@Excel(name = "推送结果状态码", readConverterExp = "0=表示成功")
- private Long errorCode;
+ private Integer errorCode;
/**
* 推送结果状态码,success:成功
diff --git a/postdischarge-manage/src/main/java/com/xinelu/manage/mapper/patientinfo/PatientInfoMapper.java b/postdischarge-manage/src/main/java/com/xinelu/manage/mapper/patientinfo/PatientInfoMapper.java
index c9bcb296..9b1a290a 100644
--- a/postdischarge-manage/src/main/java/com/xinelu/manage/mapper/patientinfo/PatientInfoMapper.java
+++ b/postdischarge-manage/src/main/java/com/xinelu/manage/mapper/patientinfo/PatientInfoMapper.java
@@ -58,4 +58,12 @@ public interface PatientInfoMapper {
* @return 结果
*/
public int deletePatientInfoByIds(Long[] ids);
+
+ /**
+ * 根据openid查询被护理人信息
+ *
+ * @param openId 微信openId
+ * @return 被护理人基本信息
+ */
+ PatientInfo getPatientInfoByOpenId(String openId);
}
diff --git a/postdischarge-manage/src/main/java/com/xinelu/manage/mapper/subscribemessagerecord/SubscribeMessageRecordMapper.java b/postdischarge-manage/src/main/java/com/xinelu/manage/mapper/subscribemessagerecord/SubscribeMessageRecordMapper.java
index ae155e63..3d6b0bcf 100644
--- a/postdischarge-manage/src/main/java/com/xinelu/manage/mapper/subscribemessagerecord/SubscribeMessageRecordMapper.java
+++ b/postdischarge-manage/src/main/java/com/xinelu/manage/mapper/subscribemessagerecord/SubscribeMessageRecordMapper.java
@@ -1,6 +1,7 @@
package com.xinelu.manage.mapper.subscribemessagerecord;
import com.xinelu.manage.domain.subscribemessagerecord.SubscribeMessageRecord;
+import org.apache.ibatis.annotations.Param;
import java.util.List;
@@ -58,4 +59,23 @@ public interface SubscribeMessageRecordMapper {
* @return 结果
*/
int deleteSubscribeMessageRecordByIds(Long[] ids);
+
+ /**
+ * 批量新增微信小程序订阅消息记录
+ *
+ * @param subscribeMessageRecordList 新增微信小程序订阅消息记录
+ * @return int
+ **/
+ int insertSubscribeMessageRecordList(List subscribeMessageRecordList);
+
+ /**
+ * 根据会员openid与templateId修改微信小程序订阅消息记录
+ *
+ * @param openId 微信openid
+ * @param templateId 模板id
+ * @param subscribeStatus 订阅状态
+ * @param patientId 患者id
+ * @return int
+ **/
+ int updateSubscribeMessageTemplateId(@Param("openId") String openId, @Param("templateId") String templateId, @Param("subscribeStatus") String subscribeStatus, @Param("patientId") Long patientId);
}
diff --git a/postdischarge-manage/src/main/java/com/xinelu/manage/mapper/subscribemessagesendrecord/SubscribeMessageSendRecordMapper.java b/postdischarge-manage/src/main/java/com/xinelu/manage/mapper/subscribemessagesendrecord/SubscribeMessageSendRecordMapper.java
index 3784205d..7ceb8caa 100644
--- a/postdischarge-manage/src/main/java/com/xinelu/manage/mapper/subscribemessagesendrecord/SubscribeMessageSendRecordMapper.java
+++ b/postdischarge-manage/src/main/java/com/xinelu/manage/mapper/subscribemessagesendrecord/SubscribeMessageSendRecordMapper.java
@@ -58,4 +58,12 @@ public interface SubscribeMessageSendRecordMapper {
* @return 结果
*/
int deleteSubscribeMessageSendRecordByIds(Long[] ids);
+
+ /**
+ * 批量新增微信小程序订阅消息发送记录
+ *
+ * @param subscribeMessageSendRecordList 微信小程序订阅发送消息记录
+ * @return int
+ **/
+ int insertSubscribeMessageSendRecordList(List subscribeMessageSendRecordList);
}
diff --git a/postdischarge-manage/src/main/resources/mapper/manage/patientinfo/PatientInfoMapper.xml b/postdischarge-manage/src/main/resources/mapper/manage/patientinfo/PatientInfoMapper.xml
index 44a50ec8..f7481789 100644
--- a/postdischarge-manage/src/main/resources/mapper/manage/patientinfo/PatientInfoMapper.xml
+++ b/postdischarge-manage/src/main/resources/mapper/manage/patientinfo/PatientInfoMapper.xml
@@ -519,4 +519,33 @@
#{id}
+
+
\ No newline at end of file
diff --git a/postdischarge-manage/src/main/resources/mapper/manage/subscribemessagerecord/SubscribeMessageRecordMapper.xml b/postdischarge-manage/src/main/resources/mapper/manage/subscribemessagerecord/SubscribeMessageRecordMapper.xml
index 8072f8ea..c6ad81c4 100644
--- a/postdischarge-manage/src/main/resources/mapper/manage/subscribemessagerecord/SubscribeMessageRecordMapper.xml
+++ b/postdischarge-manage/src/main/resources/mapper/manage/subscribemessagerecord/SubscribeMessageRecordMapper.xml
@@ -193,4 +193,45 @@
#{id}
+
+
+ insert into subscribe_message_record(
+ patient_id,
+ unionid,
+ openid,
+ template_id,
+ message_type,
+ subscribe_count,
+ subscribe_time,
+ applet_id,
+ subscribe_status,
+ create_by,
+ create_time,
+ update_by,
+ update_time
+ ) values
+
+ (
+ #{subscribeMessageRecordList.patientId},
+ #{subscribeMessageRecordList.unionid},
+ #{subscribeMessageRecordList.openid},
+ #{subscribeMessageRecordList.templateId},
+ #{subscribeMessageRecordList.messageType},
+ #{subscribeMessageRecordList.subscribeCount},
+ #{subscribeMessageRecordList.subscribeTime},
+ #{subscribeMessageRecordList.appletId},
+ #{subscribeMessageRecordList.subscribeStatus},
+ #{subscribeMessageRecordList.createBy},
+ #{subscribeMessageRecordList.createTime},
+ #{subscribeMessageRecordList.updateBy},
+ #{subscribeMessageRecordList.updateTime}
+ )
+
+
+
+
+ update subscribe_message_record
+ set patient_id = #{patientId}, subscribe_status = #{subscribeStatus}, update_time = now()
+ where openid = #{openId} and template_id = #{templateId}
+
\ No newline at end of file
diff --git a/postdischarge-manage/src/main/resources/mapper/manage/subscribemessagesendrecord/SubscribeMessageSendRecordMapper.xml b/postdischarge-manage/src/main/resources/mapper/manage/subscribemessagesendrecord/SubscribeMessageSendRecordMapper.xml
index e7633f1e..cf4ac9e2 100644
--- a/postdischarge-manage/src/main/resources/mapper/manage/subscribemessagesendrecord/SubscribeMessageSendRecordMapper.xml
+++ b/postdischarge-manage/src/main/resources/mapper/manage/subscribemessagesendrecord/SubscribeMessageSendRecordMapper.xml
@@ -204,4 +204,31 @@
#{id}
+
+
+ insert into subscribe_message_send_record(
+ openid,
+ applet_id,
+ subscribe_time,
+ template_id,
+ msg_id,
+ message_type,
+ error_code,
+ error_status,
+ create_time
+ ) values
+
+ (
+ #{sendRecord.openid},
+ #{sendRecord.appletId},
+ #{sendRecord.subscribeTime},
+ #{sendRecord.templateId},
+ #{sendRecord.msgId},
+ #{sendRecord.messageType},
+ #{sendRecord.errorCode},
+ #{sendRecord.errorStatus},
+ #{sendRecord.createTime}
+ )
+
+
\ No newline at end of file
diff --git a/postdischarge-mobile/pom.xml b/postdischarge-mobile/pom.xml
index 8ede5002..0ac748c5 100644
--- a/postdischarge-mobile/pom.xml
+++ b/postdischarge-mobile/pom.xml
@@ -34,5 +34,10 @@
com.xinelu
postdischarge-manage
+
+
+ org.simpleframework
+ simple-xml
+
\ No newline at end of file
diff --git a/postdischarge-mobile/src/main/java/com/xinelu/mobile/mapper/MobileTestMapper.java b/postdischarge-mobile/src/main/java/com/xinelu/mobile/mapper/mobiletest/MobileTestMapper.java
similarity index 75%
rename from postdischarge-mobile/src/main/java/com/xinelu/mobile/mapper/MobileTestMapper.java
rename to postdischarge-mobile/src/main/java/com/xinelu/mobile/mapper/mobiletest/MobileTestMapper.java
index af0ed197..5307ed69 100644
--- a/postdischarge-mobile/src/main/java/com/xinelu/mobile/mapper/MobileTestMapper.java
+++ b/postdischarge-mobile/src/main/java/com/xinelu/mobile/mapper/mobiletest/MobileTestMapper.java
@@ -1,4 +1,4 @@
-package com.xinelu.mobile.mapper;
+package com.xinelu.mobile.mapper.mobiletest;
/**
* @Description 测试 Mapper
diff --git a/postdischarge-mobile/src/main/java/com/xinelu/mobile/service/wechatappletcallback/WeChatAppletCallBackService.java b/postdischarge-mobile/src/main/java/com/xinelu/mobile/service/wechatappletcallback/WeChatAppletCallBackService.java
new file mode 100644
index 00000000..f9f6b0cc
--- /dev/null
+++ b/postdischarge-mobile/src/main/java/com/xinelu/mobile/service/wechatappletcallback/WeChatAppletCallBackService.java
@@ -0,0 +1,19 @@
+package com.xinelu.mobile.service.wechatappletcallback;
+
+import com.xinelu.mobile.vo.wechatappletcallback.WeChatMessagePushVO;
+
+/**
+ * @Description 微信小程序事件回调业务层
+ * @Author 纪寒
+ * @Date 2024-03-15 15:45:50
+ * @Version 1.0
+ */
+public interface WeChatAppletCallBackService {
+
+ /**
+ * 微信小程序消息推送事件回调POST处理
+ *
+ * @param weChatMessagePushVO 请求参数
+ */
+ void handleWeChatAppletCallBack(WeChatMessagePushVO weChatMessagePushVO);
+}
diff --git a/postdischarge-mobile/src/main/java/com/xinelu/mobile/service/wechatappletcallback/impl/WeChatAppletCallBackServiceImpl.java b/postdischarge-mobile/src/main/java/com/xinelu/mobile/service/wechatappletcallback/impl/WeChatAppletCallBackServiceImpl.java
new file mode 100644
index 00000000..8823f23a
--- /dev/null
+++ b/postdischarge-mobile/src/main/java/com/xinelu/mobile/service/wechatappletcallback/impl/WeChatAppletCallBackServiceImpl.java
@@ -0,0 +1,278 @@
+package com.xinelu.mobile.service.wechatappletcallback.impl;
+
+import com.xinelu.common.config.AppletChatConfig;
+import com.xinelu.common.enums.SubscribeMessageTypeEnum;
+import com.xinelu.common.exception.ServiceException;
+import com.xinelu.common.utils.DateUtils;
+import com.xinelu.manage.domain.patientinfo.PatientInfo;
+import com.xinelu.manage.domain.subscribemessagerecord.SubscribeMessageRecord;
+import com.xinelu.manage.domain.subscribemessagesendrecord.SubscribeMessageSendRecord;
+import com.xinelu.manage.mapper.patientinfo.PatientInfoMapper;
+import com.xinelu.manage.mapper.subscribemessagerecord.SubscribeMessageRecordMapper;
+import com.xinelu.manage.mapper.subscribemessagesendrecord.SubscribeMessageSendRecordMapper;
+import com.xinelu.mobile.service.wechatappletcallback.WeChatAppletCallBackService;
+import com.xinelu.mobile.vo.wechatappletcallback.WeChatMessagePushVO;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.compress.utils.Lists;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+/**
+ * @Description 微信小程序事件回调业务层实现类
+ * @Author 纪寒
+ * @Date 2024-03-19 17:13:06
+ * @Version 1.0
+ */
+@Service
+@Slf4j
+public class WeChatAppletCallBackServiceImpl implements WeChatAppletCallBackService {
+
+ @Resource
+ private SubscribeMessageRecordMapper subscribeMessageRecordMapper;
+ @Resource
+ private AppletChatConfig appletChatConfig;
+ @Resource
+ private PatientInfoMapper patientInfoMapper;
+ @Resource
+ private SubscribeMessageSendRecordMapper subscribeMessageSendRecordMapper;
+ /**
+ * 微信消息推送变更事件标识
+ */
+ private static final String SUBSCRIBE_MSG_CHANGE_EVENT = "subscribe_msg_change_event";
+
+ /**
+ * 微信消息推送订阅事件标识
+ */
+ private static final String SUBSCRIBE_MSG_POPUP_EVENT = "subscribe_msg_popup_event";
+
+ /**
+ * 微信消息推送发送结果事件标识
+ */
+ private static final String SUBSCRIBE_MSG__SENT_EVENT = "subscribe_msg_sent_event";
+
+ /**
+ * 微信小程序消息推送事件回调POST处理
+ *
+ * @param weChatMessagePushVO 请求参数
+ */
+ @Transactional(rollbackFor = Exception.class)
+ @Override
+ public void handleWeChatAppletCallBack(WeChatMessagePushVO weChatMessagePushVO) {
+ if (weChatMessagePushVO.getEvent().equals(SUBSCRIBE_MSG_POPUP_EVENT)) {
+ //处理用户订阅授权事件
+ this.handleSubscribeMsgPopupEvent(weChatMessagePushVO);
+ }
+ if (weChatMessagePushVO.getEvent().equals(SUBSCRIBE_MSG_CHANGE_EVENT)) {
+ //处理订阅消息变更事件
+ this.handleSubscribeMsgChangeEvent(weChatMessagePushVO);
+ }
+ if (weChatMessagePushVO.getEvent().equals(SUBSCRIBE_MSG__SENT_EVENT)) {
+ //处理订阅消息发送结果事件
+ this.handleSubscribeMsgSentEvent(weChatMessagePushVO);
+ }
+ }
+
+ /**
+ * 处理用户订阅授权事件
+ *
+ * @param weChatMessagePushVO 参数信息
+ */
+ private void handleSubscribeMsgPopupEvent(WeChatMessagePushVO weChatMessagePushVO) {
+ //处理订阅消息授权事件
+ if (Objects.isNull(weChatMessagePushVO.getSubscribeMsgPopupEvent()) || CollectionUtils.isEmpty(weChatMessagePushVO.getSubscribeMsgPopupEvent().getSubscribeMsgPopupEventList())) {
+ return;
+ }
+ //查询用户信息表
+ PatientInfo patientInfo = patientInfoMapper.getPatientInfoByOpenId(StringUtils.isBlank(weChatMessagePushVO.getFromUserName()) ? "" : weChatMessagePushVO.getFromUserName());
+ //组装数据
+ List subscribeMessageRecordList = createSubscribeMessageRecordList(patientInfo, weChatMessagePushVO, SUBSCRIBE_MSG_POPUP_EVENT);
+ if (CollectionUtils.isEmpty(subscribeMessageRecordList)) {
+ return;
+ }
+ //根据openid查询数据库原有的订阅消息记录
+ SubscribeMessageRecord subscribeMessageRecord = new SubscribeMessageRecord();
+ subscribeMessageRecord.setOpenid(StringUtils.isBlank(weChatMessagePushVO.getFromUserName()) ? "" : weChatMessagePushVO.getFromUserName());
+ List existMessageRecordList = subscribeMessageRecordMapper.selectSubscribeMessageRecordList(subscribeMessageRecord);
+ List subtractSubscribeList = new ArrayList<>(CollectionUtils.subtract(subscribeMessageRecordList, existMessageRecordList));
+ if (CollectionUtils.isNotEmpty(subtractSubscribeList)) {
+ //新增订阅记录信息
+ int insertCount = subscribeMessageRecordMapper.insertSubscribeMessageRecordList(subtractSubscribeList);
+ if (insertCount <= 0) {
+ log.error("微信订阅消息回调,新增用户订阅消息记录失败,记录信息为:[{}]", subtractSubscribeList);
+ throw new ServiceException("微信订阅消息回调,新增用户订阅消息记录失败!");
+ }
+ }
+ List intersectionSubscribeList = new ArrayList<>(CollectionUtils.intersection(subscribeMessageRecordList, existMessageRecordList));
+ if (CollectionUtils.isNotEmpty(intersectionSubscribeList)) {
+ //修改订阅信息状态
+ for (SubscribeMessageRecord messageRecord : intersectionSubscribeList) {
+ Long patientId = null;
+ if (Objects.nonNull(patientInfo) && Objects.nonNull(patientInfo.getId())) {
+ patientId = patientInfo.getId();
+ }
+ String openId = StringUtils.isBlank(messageRecord.getOpenid()) ? "" : messageRecord.getOpenid();
+ String templateId = StringUtils.isBlank(messageRecord.getTemplateId()) ? "" : messageRecord.getTemplateId();
+ String subscribeStatus = StringUtils.isBlank(messageRecord.getSubscribeStatus()) ? "" : messageRecord.getSubscribeStatus();
+ subscribeMessageRecordMapper.updateSubscribeMessageTemplateId(openId, templateId, subscribeStatus, patientId);
+ }
+ }
+ }
+
+ /**
+ * 处理订阅消息变更事件
+ *
+ * @param weChatMessagePushVO 信息
+ */
+ private void handleSubscribeMsgChangeEvent(WeChatMessagePushVO weChatMessagePushVO) {
+ if (Objects.isNull(weChatMessagePushVO.getSubscribeMsgChangeEvent()) || CollectionUtils.isEmpty(weChatMessagePushVO.getSubscribeMsgChangeEvent().getSubscribeMsgPopupEventList())) {
+ return;
+ }
+ //查询用户信息表
+ PatientInfo patientInfo = patientInfoMapper.getPatientInfoByOpenId(StringUtils.isBlank(weChatMessagePushVO.getFromUserName()) ? "" : weChatMessagePushVO.getFromUserName());
+ //组装数据
+ List subscribeMessageRecordList = createSubscribeMessageRecordList(patientInfo, weChatMessagePushVO, SUBSCRIBE_MSG_CHANGE_EVENT);
+ if (CollectionUtils.isEmpty(subscribeMessageRecordList)) {
+ return;
+ }
+ //根据openid查询数据库原有的订阅消息记录
+ SubscribeMessageRecord subscribeMessageRecord = new SubscribeMessageRecord();
+ subscribeMessageRecord.setOpenid(StringUtils.isBlank(weChatMessagePushVO.getFromUserName()) ? "" : weChatMessagePushVO.getFromUserName());
+ List existMessageRecordList = subscribeMessageRecordMapper.selectSubscribeMessageRecordList(subscribeMessageRecord);
+ List intersectionSubscribeList = new ArrayList<>(CollectionUtils.intersection(subscribeMessageRecordList, existMessageRecordList));
+ if (CollectionUtils.isNotEmpty(intersectionSubscribeList)) {
+ //修改订阅信息状态
+ for (SubscribeMessageRecord messageRecord : intersectionSubscribeList) {
+ Long patientId = null;
+ if (Objects.nonNull(patientInfo) && Objects.nonNull(patientInfo.getId())) {
+ patientId = patientInfo.getId();
+ }
+ String openId = StringUtils.isBlank(messageRecord.getOpenid()) ? "" : messageRecord.getOpenid();
+ String templateId = StringUtils.isBlank(messageRecord.getTemplateId()) ? "" : messageRecord.getTemplateId();
+ String subscribeStatus = StringUtils.isBlank(messageRecord.getSubscribeStatus()) ? "" : messageRecord.getSubscribeStatus();
+ subscribeMessageRecordMapper.updateSubscribeMessageTemplateId(openId, templateId, subscribeStatus, patientId);
+ }
+ }
+ }
+
+ /**
+ * 处理订阅消息发送结果事件
+ *
+ * @param weChatMessagePushVO 信息
+ */
+ private void handleSubscribeMsgSentEvent(WeChatMessagePushVO weChatMessagePushVO) {
+ if (Objects.isNull(weChatMessagePushVO.getSubscribeMsgSentEvent()) || CollectionUtils.isEmpty(weChatMessagePushVO.getSubscribeMsgSentEvent().getSubscribeMsgSentEventList())) {
+ return;
+ }
+ //组装数据
+ List subscribeMessageSendRecordList = createSubscribeMessageSendRecordList(weChatMessagePushVO);
+ if (CollectionUtils.isNotEmpty(subscribeMessageSendRecordList)) {
+ int insertCount = subscribeMessageSendRecordMapper.insertSubscribeMessageSendRecordList(subscribeMessageSendRecordList);
+ if (insertCount <= 0) {
+ log.error("微信订阅消息回调,新增用户订阅消息发送记录失败,记录信息为:[{}]", subscribeMessageSendRecordList);
+ throw new ServiceException("微信订阅消息回调,新增用户订阅消息发送记录失败!");
+ }
+ }
+ }
+
+ /**
+ * 组装订阅消息数据
+ *
+ * @param patientInfo 会员用户信息
+ * @param weChatMessagePushVO 微信请求参数信息
+ * @param eventType 事件类型
+ * @return List
+ */
+ private List createSubscribeMessageRecordList(PatientInfo patientInfo, WeChatMessagePushVO weChatMessagePushVO, String eventType) {
+ List subscribeMessageRecordList = Lists.newArrayList();
+ if (SUBSCRIBE_MSG_POPUP_EVENT.equals(eventType)) {
+ subscribeMessageRecordList = weChatMessagePushVO.getSubscribeMsgPopupEvent().getSubscribeMsgPopupEventList().stream().filter(Objects::nonNull).map(item -> {
+ SubscribeMessageRecord subscribe = new SubscribeMessageRecord();
+ if (Objects.nonNull(patientInfo) && Objects.nonNull(patientInfo.getId())) {
+ subscribe.setPatientId(patientInfo.getId());
+ }
+ //此处模板通知需要根据实际情况进行修改
+ subscribe.setOpenid(StringUtils.isBlank(weChatMessagePushVO.getFromUserName()) ? "" : weChatMessagePushVO.getFromUserName());
+ subscribe.setAppletId(StringUtils.isBlank(weChatMessagePushVO.getToUserName()) ? "" : weChatMessagePushVO.getToUserName());
+ subscribe.setTemplateId(StringUtils.isBlank(item.getTemplateId()) ? "" : item.getTemplateId());
+ if (StringUtils.isNotBlank(item.getTemplateId()) && appletChatConfig.getCouponReceiveTemplateId().equals(item.getTemplateId())) {
+ subscribe.setMessageType(SubscribeMessageTypeEnum.COUPON_RECEIVE_MESSAGE_PUSH.getInfo());
+ }
+ if (StringUtils.isNotBlank(item.getTemplateId()) && appletChatConfig.getAppointOrderTemplateId().equals(item.getTemplateId())) {
+ subscribe.setMessageType(SubscribeMessageTypeEnum.APPOINT_ORDER_MESSAGE_PUSH.getInfo());
+ }
+ if (StringUtils.isNotBlank(item.getTemplateId()) && appletChatConfig.getGoodsOrderTemplateId().equals(item.getTemplateId())) {
+ subscribe.setMessageType(SubscribeMessageTypeEnum.GOODS_ORDER_MESSAGE_PUSH.getInfo());
+ }
+ if (StringUtils.isNotBlank(item.getTemplateId()) && appletChatConfig.getSignTemplateId().equals(item.getTemplateId())) {
+ subscribe.setMessageType(SubscribeMessageTypeEnum.SIGN_MESSAGE_PUSH.getInfo());
+ }
+ subscribe.setSubscribeCount(1);
+ subscribe.setSubscribeTime(StringUtils.isBlank(weChatMessagePushVO.getCreateTime()) ? null : DateUtils.timestampToLocalDateTime(Long.parseLong(weChatMessagePushVO.getCreateTime()) * 1000L));
+ subscribe.setCreateTime(LocalDateTime.now());
+ subscribe.setSubscribeStatus(StringUtils.isBlank(item.getSubscribeStatusString()) ? "" : item.getSubscribeStatusString());
+ return subscribe;
+ }).collect(Collectors.toList());
+ }
+ if (SUBSCRIBE_MSG_CHANGE_EVENT.equals(eventType)) {
+ subscribeMessageRecordList = weChatMessagePushVO.getSubscribeMsgChangeEvent().getSubscribeMsgPopupEventList().stream().filter(Objects::nonNull).map(item -> {
+ SubscribeMessageRecord subscribe = new SubscribeMessageRecord();
+ if (Objects.nonNull(patientInfo) && Objects.nonNull(patientInfo.getId())) {
+ subscribe.setPatientId(patientInfo.getId());
+ }
+ //此处模板通知需要根据实际情况进行修改
+ subscribe.setOpenid(StringUtils.isBlank(weChatMessagePushVO.getFromUserName()) ? "" : weChatMessagePushVO.getFromUserName());
+ subscribe.setAppletId(StringUtils.isBlank(weChatMessagePushVO.getToUserName()) ? "" : weChatMessagePushVO.getToUserName());
+ subscribe.setTemplateId(StringUtils.isBlank(item.getTemplateId()) ? "" : item.getTemplateId());
+ if (StringUtils.isNotBlank(item.getTemplateId()) && appletChatConfig.getCouponReceiveTemplateId().equals(item.getTemplateId())) {
+ subscribe.setMessageType(SubscribeMessageTypeEnum.COUPON_RECEIVE_MESSAGE_PUSH.getInfo());
+ }
+ if (StringUtils.isNotBlank(item.getTemplateId()) && appletChatConfig.getAppointOrderTemplateId().equals(item.getTemplateId())) {
+ subscribe.setMessageType(SubscribeMessageTypeEnum.APPOINT_ORDER_MESSAGE_PUSH.getInfo());
+ }
+ if (StringUtils.isNotBlank(item.getTemplateId()) && appletChatConfig.getGoodsOrderTemplateId().equals(item.getTemplateId())) {
+ subscribe.setMessageType(SubscribeMessageTypeEnum.GOODS_ORDER_MESSAGE_PUSH.getInfo());
+ }
+ if (StringUtils.isNotBlank(item.getTemplateId()) && appletChatConfig.getSignTemplateId().equals(item.getTemplateId())) {
+ subscribe.setMessageType(SubscribeMessageTypeEnum.SIGN_MESSAGE_PUSH.getInfo());
+ }
+ subscribe.setSubscribeCount(1);
+ subscribe.setSubscribeTime(StringUtils.isBlank(weChatMessagePushVO.getCreateTime()) ? null : DateUtils.timestampToLocalDateTime(Long.parseLong(weChatMessagePushVO.getCreateTime()) * 1000L));
+ subscribe.setCreateTime(LocalDateTime.now());
+ subscribe.setSubscribeStatus(StringUtils.isBlank(item.getSubscribeStatusString()) ? "" : item.getSubscribeStatusString());
+ return subscribe;
+ }).collect(Collectors.toList());
+ }
+ return subscribeMessageRecordList;
+ }
+
+ /**
+ * 组装订阅消息发送结果数据
+ *
+ * @param weChatMessagePushVO 微信请求参数信息
+ * @return List
+ */
+ private List createSubscribeMessageSendRecordList(WeChatMessagePushVO weChatMessagePushVO) {
+ return weChatMessagePushVO.getSubscribeMsgSentEvent().getSubscribeMsgSentEventList().stream().map(item -> {
+ SubscribeMessageSendRecord sendRecord = new SubscribeMessageSendRecord();
+ sendRecord.setOpenid(StringUtils.isBlank(weChatMessagePushVO.getFromUserName()) ? "" : weChatMessagePushVO.getFromUserName());
+ sendRecord.setAppletId(StringUtils.isBlank(weChatMessagePushVO.getToUserName()) ? "" : weChatMessagePushVO.getToUserName());
+ sendRecord.setTemplateId(StringUtils.isBlank(item.getTemplateId()) ? "" : item.getTemplateId());
+ sendRecord.setMessageType(StringUtils.isBlank(weChatMessagePushVO.getMsgType()) ? "" : weChatMessagePushVO.getMsgType());
+ sendRecord.setMsgId(StringUtils.isBlank(item.getMsgId()) ? "" : item.getMsgId());
+ sendRecord.setSubscribeTime(StringUtils.isBlank(weChatMessagePushVO.getCreateTime()) ? null : DateUtils.timestampToLocalDateTime(Long.parseLong(weChatMessagePushVO.getCreateTime()) * 1000L));
+ sendRecord.setCreateTime(LocalDateTime.now());
+ sendRecord.setErrorStatus(StringUtils.isBlank(item.getErrorStatus()) ? "" : item.getErrorStatus());
+ sendRecord.setErrorCode(StringUtils.isBlank(item.getErrorCode()) ? null : Integer.parseInt(item.getErrorCode()));
+ return sendRecord;
+ }).collect(Collectors.toList());
+ }
+}
diff --git a/postdischarge-mobile/src/main/java/com/xinelu/mobile/vo/wechatappletcallback/SubscribeMsgChangeEventVO.java b/postdischarge-mobile/src/main/java/com/xinelu/mobile/vo/wechatappletcallback/SubscribeMsgChangeEventVO.java
new file mode 100644
index 00000000..9da66f77
--- /dev/null
+++ b/postdischarge-mobile/src/main/java/com/xinelu/mobile/vo/wechatappletcallback/SubscribeMsgChangeEventVO.java
@@ -0,0 +1,25 @@
+package com.xinelu.mobile.vo.wechatappletcallback;
+
+import lombok.Data;
+import org.simpleframework.xml.ElementList;
+import org.simpleframework.xml.Root;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * @Description 当用户在手机端服务通知里消息卡片右上角“...”管理消息实体类
+ * @Author 纪寒
+ * @Date 2024-03-19 16:12:17
+ * @Version 1.0
+ */
+@Root(name = "SubscribeMsgChangeEvent", strict = false)
+@Data
+public class SubscribeMsgChangeEventVO implements Serializable {
+ private static final long serialVersionUID = -6682105837610124794L;
+ /**
+ * 信息集合
+ */
+ @ElementList(inline = true, required = false)
+ private List subscribeMsgPopupEventList;
+}
diff --git a/postdischarge-mobile/src/main/java/com/xinelu/mobile/vo/wechatappletcallback/SubscribeMsgPopupEventListVO.java b/postdischarge-mobile/src/main/java/com/xinelu/mobile/vo/wechatappletcallback/SubscribeMsgPopupEventListVO.java
new file mode 100644
index 00000000..0316246a
--- /dev/null
+++ b/postdischarge-mobile/src/main/java/com/xinelu/mobile/vo/wechatappletcallback/SubscribeMsgPopupEventListVO.java
@@ -0,0 +1,36 @@
+package com.xinelu.mobile.vo.wechatappletcallback;
+
+import lombok.Data;
+import org.simpleframework.xml.Element;
+import org.simpleframework.xml.Root;
+
+import java.io.Serializable;
+
+/**
+ * @Description 模板信息集合
+ * @Author 纪寒
+ * @Date 2024-03-19 16:10:28
+ * @Version 1.0
+ */
+@Root(name = "List", strict = false)
+@Data
+public class SubscribeMsgPopupEventListVO implements Serializable {
+ private static final long serialVersionUID = 548605591615555467L;
+ /**
+ * 模板id
+ */
+ @Element(name = "TemplateId", required = false)
+ private String templateId;
+
+ /**
+ * 订阅结果(accept接收;reject拒收)
+ */
+ @Element(name = "SubscribeStatusString", required = false)
+ private String subscribeStatusString;
+
+ /**
+ * 弹框场景,0代表在小程序页面内
+ */
+ @Element(name = "PopupScene", required = false)
+ private String popupScene;
+}
diff --git a/postdischarge-mobile/src/main/java/com/xinelu/mobile/vo/wechatappletcallback/SubscribeMsgPopupEventVO.java b/postdischarge-mobile/src/main/java/com/xinelu/mobile/vo/wechatappletcallback/SubscribeMsgPopupEventVO.java
new file mode 100644
index 00000000..9f552c5c
--- /dev/null
+++ b/postdischarge-mobile/src/main/java/com/xinelu/mobile/vo/wechatappletcallback/SubscribeMsgPopupEventVO.java
@@ -0,0 +1,25 @@
+package com.xinelu.mobile.vo.wechatappletcallback;
+
+import lombok.Data;
+import org.simpleframework.xml.ElementList;
+import org.simpleframework.xml.Root;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * @Description 当用户触发订阅消息弹框后信息实体类
+ * @Author 纪寒
+ * @Date 2024-03-19 16:09:23
+ * @Version 1.0
+ */
+@Root(name = "SubscribeMsgPopupEvent", strict = false)
+@Data
+public class SubscribeMsgPopupEventVO implements Serializable {
+ private static final long serialVersionUID = -6682105837610124794L;
+ /**
+ * 信息集合
+ */
+ @ElementList(inline = true, required = false)
+ private List subscribeMsgPopupEventList;
+}
diff --git a/postdischarge-mobile/src/main/java/com/xinelu/mobile/vo/wechatappletcallback/SubscribeMsgSentEventListVO.java b/postdischarge-mobile/src/main/java/com/xinelu/mobile/vo/wechatappletcallback/SubscribeMsgSentEventListVO.java
new file mode 100644
index 00000000..e85a4c28
--- /dev/null
+++ b/postdischarge-mobile/src/main/java/com/xinelu/mobile/vo/wechatappletcallback/SubscribeMsgSentEventListVO.java
@@ -0,0 +1,42 @@
+package com.xinelu.mobile.vo.wechatappletcallback;
+
+import lombok.Data;
+import org.simpleframework.xml.Element;
+import org.simpleframework.xml.Root;
+
+import java.io.Serializable;
+
+/**
+ * @Description 调用订阅消息接口发送消息给用户的最终结果信息集合实体类
+ * @Author 纪寒
+ * @Date 2024-03-19 16:13:39
+ * @Version 1.0
+ */
+@Root(name = "List", strict = false)
+@Data
+public class SubscribeMsgSentEventListVO implements Serializable {
+ private static final long serialVersionUID = 3771741965224817805L;
+ /**
+ * 模板id
+ */
+ @Element(name = "TemplateId", required = false)
+ private String templateId;
+
+ /**
+ * 消息id(调用接口时也会返回)
+ */
+ @Element(name = "MsgID", required = false)
+ private String msgId;
+
+ /**
+ * 推送结果状态码(0表示成功)
+ */
+ @Element(name = "ErrorCode", required = false)
+ private String errorCode;
+
+ /**
+ * 推送结果状态码对应的含义
+ */
+ @Element(name = "ErrorStatus", required = false)
+ private String errorStatus;
+}
diff --git a/postdischarge-mobile/src/main/java/com/xinelu/mobile/vo/wechatappletcallback/SubscribeMsgSentEventVO.java b/postdischarge-mobile/src/main/java/com/xinelu/mobile/vo/wechatappletcallback/SubscribeMsgSentEventVO.java
new file mode 100644
index 00000000..6fcc1f42
--- /dev/null
+++ b/postdischarge-mobile/src/main/java/com/xinelu/mobile/vo/wechatappletcallback/SubscribeMsgSentEventVO.java
@@ -0,0 +1,25 @@
+package com.xinelu.mobile.vo.wechatappletcallback;
+
+import lombok.Data;
+import org.simpleframework.xml.ElementList;
+import org.simpleframework.xml.Root;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * @Description 调用订阅消息接口发送消息给用户的最终结果实体类
+ * @Author 纪寒
+ * @Date 2024-03-19 16:13:23
+ * @Version 1.0
+ */
+@Root(name = "SubscribeMsgSentEvent", strict = false)
+@Data
+public class SubscribeMsgSentEventVO implements Serializable {
+ private static final long serialVersionUID = -6682105837610124794L;
+ /**
+ * 信息集合
+ */
+ @ElementList(inline = true, required = false)
+ private List subscribeMsgSentEventList;
+}
diff --git a/postdischarge-mobile/src/main/java/com/xinelu/mobile/vo/wechatappletcallback/WeChatMessagePushVO.java b/postdischarge-mobile/src/main/java/com/xinelu/mobile/vo/wechatappletcallback/WeChatMessagePushVO.java
new file mode 100644
index 00000000..df50dd6b
--- /dev/null
+++ b/postdischarge-mobile/src/main/java/com/xinelu/mobile/vo/wechatappletcallback/WeChatMessagePushVO.java
@@ -0,0 +1,66 @@
+package com.xinelu.mobile.vo.wechatappletcallback;
+
+import lombok.Data;
+import org.simpleframework.xml.Element;
+import org.simpleframework.xml.Root;
+
+import java.io.Serializable;
+
+/**
+ * @Description 微信小程序消息推送回调实体类
+ * @Author 纪寒
+ * @Date 2024-03-19 16:06:17
+ * @Version 1.0
+ */
+@Root(name = "xml", strict = false)
+@Data
+public class WeChatMessagePushVO implements Serializable {
+ private static final long serialVersionUID = 6233209958847696141L;
+ /**
+ * 小程序账号
+ */
+ @Element(name = "ToUserName", required = false)
+ private String toUserName;
+
+ /**
+ * 用户openid
+ */
+ @Element(name = "FromUserName", required = false)
+ private String fromUserName;
+
+ /**
+ * 时间戳
+ */
+ @Element(name = "CreateTime", required = false)
+ private String createTime;
+
+ /**
+ * 消息类型
+ */
+ @Element(name = "MsgType", required = false)
+ private String msgType;
+
+ /**
+ * 事件类型
+ */
+ @Element(name = "Event", required = false)
+ private String event;
+
+ /**
+ * 当用户触发订阅消息弹框后触发时间集合
+ */
+ @Element(name = "SubscribeMsgPopupEvent", required = false)
+ private SubscribeMsgPopupEventVO subscribeMsgPopupEvent;
+
+ /**
+ * 当用户在手机端服务通知里消息卡片右上角“...”管理消息时
+ */
+ @Element(name = "SubscribeMsgChangeEvent", required = false)
+ private SubscribeMsgChangeEventVO subscribeMsgChangeEvent;
+
+ /**
+ * 当用户在手机端服务通知里消息卡片右上角“...”管理消息时
+ */
+ @Element(name = "SubscribeMsgSentEvent", required = false)
+ private SubscribeMsgSentEventVO subscribeMsgSentEvent;
+}
diff --git a/postdischarge-mobile/src/main/resources/mapper.mobile/mobiletest/MobileTestMapper b/postdischarge-mobile/src/main/resources/mapper/mobile/mobiletest/MobileTestMapper
similarity index 70%
rename from postdischarge-mobile/src/main/resources/mapper.mobile/mobiletest/MobileTestMapper
rename to postdischarge-mobile/src/main/resources/mapper/mobile/mobiletest/MobileTestMapper
index ceb12892..3b8ea21e 100644
--- a/postdischarge-mobile/src/main/resources/mapper.mobile/mobiletest/MobileTestMapper
+++ b/postdischarge-mobile/src/main/resources/mapper/mobile/mobiletest/MobileTestMapper
@@ -2,5 +2,5 @@
-
+
\ No newline at end of file