张延森 4 anni fa
parent
commit
0238aab2c0

+ 1
- 1
pom.xml Vedi File

@@ -10,7 +10,7 @@
10 10
 	</parent>
11 11
 	<groupId>com.shigongli</groupId>
12 12
 	<artifactId>shigongli</artifactId>
13
-	<version>0.0.4</version>
13
+	<version>0.0.5</version>
14 14
 	<name>shigongli</name>
15 15
 	<description>ShiGongli Service</description>
16 16
 

+ 7
- 0
src/main/java/com/shigongli/controller/LoginController.java Vedi File

@@ -3,6 +3,7 @@ package com.shigongli.controller;
3 3
 import cn.binarywang.wx.miniapp.api.WxMaService;
4 4
 import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
5 5
 import com.shigongli.common.*;
6
+import com.shigongli.config.WeixinConfig;
6 7
 import com.shigongli.constants.StatusConstant;
7 8
 import com.shigongli.entity.SysUser;
8 9
 import com.shigongli.entity.TaPerson;
@@ -42,6 +43,9 @@ public class LoginController extends BaseController {
42 43
     @Autowired
43 44
     WxUtils wxUtils;
44 45
 
46
+    @Autowired
47
+    WeixinConfig weixinConfig;
48
+
45 49
     /**
46 50
      * 公众号登录
47 51
      * @param code
@@ -135,6 +139,9 @@ public class LoginController extends BaseController {
135 139
         String jws = JWTUtils.encode(claims);
136 140
         taPerson.setToken(jws);
137 141
 
142
+        // 消息模板
143
+        taPerson.setSubscribeMessageList(weixinConfig.getMa().getSubscribeMessages());
144
+
138 145
         return ResponseBean.success(taPerson);
139 146
     }
140 147
 }

+ 10
- 0
src/main/java/com/shigongli/entity/TaPerson.java Vedi File

@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.annotation.TableId;
8 8
 import java.io.Serializable;
9 9
 import java.util.List;
10 10
 
11
+import com.shigongli.config.WeixinConfig;
11 12
 import io.swagger.annotations.ApiModel;
12 13
 import io.swagger.annotations.ApiModelProperty;
13 14
 import lombok.Data;
@@ -63,4 +64,13 @@ public class TaPerson implements Serializable {
63 64
 
64 65
     @TableField(exist = false)
65 66
     private List<TaShopKeeper> shopKeeperList;
67
+
68
+    @TableField(exist = false)
69
+    private List<WeixinConfig.Ma.SubscribeMessage> subscribeMessageList;
70
+
71
+    @TableField(exist = false)
72
+    private String orderId;
73
+
74
+    @TableField(exist = false)
75
+    private String houseId;
66 76
 }

+ 54
- 2
src/main/java/com/shigongli/task/SendCheckOutMessage.java Vedi File

@@ -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
 }

+ 1
- 1
src/main/resources/application.yml Vedi File

@@ -49,7 +49,7 @@ weixin:
49 49
       - type: settled-in
50 50
         code: rMg5CzypZSniRGHoZ7SBdqv_kmf7fPfTJMZ1k1SgobY
51 51
       - type: check-out
52
-        code:
52
+        code: OtpD30Kb9qbNBJ2-IVnhu5g1hHnuNvCvdVuFh4e6mPU
53 53
 
54 54
   # 公众号
55 55
   mp:

+ 3
- 1
src/main/resources/mapper/TaPersonMapper.xml Vedi File

@@ -7,7 +7,9 @@
7 7
     </select>
8 8
     <select id="getCheckoutListBy" resultType="com.shigongli.entity.TaPerson">
9 9
         SELECT DISTINCT
10
-            m.*
10
+            m.*,
11
+            max(s.order_id) as order_id,
12
+            max(t.house_id) as house_id
11 13
         FROM
12 14
             ta_house_setting t
13 15
             INNER JOIN ta_house_order s ON t.setting_id = s.setting_id