|
@@ -1,15 +1,20 @@
|
1
|
1
|
package com.shigongli.task;
|
2
|
2
|
|
|
3
|
+import cn.binarywang.wx.miniapp.api.WxMaService;
|
|
4
|
+import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
|
|
5
|
+import com.shigongli.common.WxUtils;
|
|
6
|
+import com.shigongli.config.WeixinConfig;
|
3
|
7
|
import com.shigongli.entity.TaPerson;
|
4
|
8
|
import com.shigongli.service.ITaPersonService;
|
5
|
9
|
import lombok.extern.slf4j.Slf4j;
|
6
|
|
-import me.chanjar.weixin.common.util.DataUtils;
|
|
10
|
+import me.chanjar.weixin.common.error.WxErrorException;
|
7
|
11
|
import org.springframework.beans.factory.annotation.Autowired;
|
8
|
12
|
import org.springframework.scheduling.annotation.Scheduled;
|
9
|
13
|
import org.springframework.stereotype.Component;
|
10
|
14
|
|
11
|
15
|
import java.time.LocalDateTime;
|
12
|
16
|
import java.time.format.DateTimeFormatter;
|
|
17
|
+import java.util.ArrayList;
|
13
|
18
|
import java.util.List;
|
14
|
19
|
|
15
|
20
|
|
|
@@ -23,6 +28,12 @@ public class SendCheckOutMessage {
|
23
|
28
|
@Autowired
|
24
|
29
|
ITaPersonService iTaPersonService;
|
25
|
30
|
|
|
31
|
+ @Autowired
|
|
32
|
+ WeixinConfig weixinConfig;
|
|
33
|
+
|
|
34
|
+ @Autowired
|
|
35
|
+ WxUtils wxUtils;
|
|
36
|
+
|
26
|
37
|
@Scheduled(cron = "0 0 11 * * ?")
|
27
|
38
|
public void run() {
|
28
|
39
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
@@ -33,9 +44,50 @@ public class SendCheckOutMessage {
|
33
|
44
|
return;
|
34
|
45
|
}
|
35
|
46
|
|
|
47
|
+ // 找到消息模板
|
|
48
|
+ List<WeixinConfig.Ma.SubscribeMessage> subscribeMessages = weixinConfig.getMa().getSubscribeMessages();
|
|
49
|
+ WeixinConfig.Ma.SubscribeMessage subscribeMessage = null;
|
|
50
|
+ if (null == subscribeMessages || subscribeMessages.size() < 1) {
|
|
51
|
+ log.error("没有找到小程序消息提醒配置");
|
|
52
|
+ return;
|
|
53
|
+ }
|
|
54
|
+ for (WeixinConfig.Ma.SubscribeMessage message : subscribeMessages) {
|
|
55
|
+ if ("check-out".equals(message.getType())) {
|
|
56
|
+ subscribeMessage = message;
|
|
57
|
+ break;
|
|
58
|
+ }
|
|
59
|
+ }
|
|
60
|
+ if (null == subscribeMessage) {
|
|
61
|
+ log.error("没有找到退房提醒的消息配置");
|
|
62
|
+ return;
|
|
63
|
+ }
|
|
64
|
+
|
|
65
|
+ String remark = "请于12:00之前退房. 退房时请检查您的随身物品!";
|
|
66
|
+ WxMaService maService = wxUtils.getMaService();
|
|
67
|
+
|
36
|
68
|
// 每隔 1s 发送一条离店提醒
|
37
|
69
|
for (TaPerson taPerson : taPersonList) {
|
38
|
|
- // todo
|
|
70
|
+ List<WxMaSubscribeMessage.Data> dataList = new ArrayList<>();
|
|
71
|
+ dataList.add(new WxMaSubscribeMessage.Data("thing5", remark));
|
|
72
|
+ dataList.add(new WxMaSubscribeMessage.Data("time8", today));
|
|
73
|
+
|
|
74
|
+ WxMaSubscribeMessage wxMaSubscribeMessage = WxMaSubscribeMessage
|
|
75
|
+ .builder()
|
|
76
|
+ .templateId(subscribeMessage.getCode())
|
|
77
|
+ .toUser(taPerson.getOpenid())
|
|
78
|
+ .page(String.format("/pages/index/index?orderId=%s&houseId=%s", taPerson.getOrderId(), taPerson.getHouseId()))
|
|
79
|
+ .data(dataList)
|
|
80
|
+ .build();
|
|
81
|
+
|
|
82
|
+ try {
|
|
83
|
+ maService.getMsgService().sendSubscribeMsg(wxMaSubscribeMessage);
|
|
84
|
+ Thread.sleep(1000);
|
|
85
|
+ } catch (WxErrorException e) {
|
|
86
|
+ log.error("发送退房消息失败: {}", e.getMessage());
|
|
87
|
+ e.printStackTrace();
|
|
88
|
+ } catch (InterruptedException e) {
|
|
89
|
+ e.printStackTrace();
|
|
90
|
+ }
|
39
|
91
|
}
|
40
|
92
|
}
|
41
|
93
|
}
|