Przeglądaj źródła

Merge remote-tracking branch 'origin/master' into master

zlisen 4 lat temu
rodzic
commit
022bedf776

+ 0
- 2
debug.log Wyświetl plik

@@ -1,2 +0,0 @@
1
-[0104/224528.192:ERROR:directory_reader_win.cc(43)] FindFirstFile: The system cannot find the path specified. (0x3)
2
-[0104/225418.866:ERROR:directory_reader_win.cc(43)] FindFirstFile: The system cannot find the path specified. (0x3)

+ 1
- 1
pom.xml Wyświetl plik

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

+ 2
- 0
src/main/java/com/shigongli/SpringApplication.java Wyświetl plik

@@ -2,9 +2,11 @@ package com.shigongli;
2 2
 
3 3
 import org.springframework.boot.autoconfigure.SpringBootApplication;
4 4
 import org.springframework.scheduling.annotation.EnableAsync;
5
+import org.springframework.scheduling.annotation.EnableScheduling;
5 6
 import org.springframework.transaction.annotation.EnableTransactionManagement;
6 7
 
7 8
 @EnableAsync
9
+@EnableScheduling
8 10
 @EnableTransactionManagement
9 11
 @SpringBootApplication
10 12
 public class SpringApplication {

+ 15
- 2
src/main/java/com/shigongli/config/WeixinConfig.java Wyświetl plik

@@ -1,20 +1,24 @@
1 1
 package com.shigongli.config;
2 2
 
3 3
 import lombok.Data;
4
+import lombok.NoArgsConstructor;
4 5
 import org.springframework.boot.context.properties.ConfigurationProperties;
5 6
 import org.springframework.boot.context.properties.NestedConfigurationProperty;
6 7
 import org.springframework.stereotype.Component;
7 8
 
9
+import java.util.ArrayList;
10
+import java.util.List;
11
+
8 12
 @Data
9 13
 @Component
10 14
 @ConfigurationProperties(prefix = "weixin")
11 15
 public class WeixinConfig {
12 16
 
13 17
     @NestedConfigurationProperty
14
-    private Ma ma = new Ma();
18
+    private Ma ma;
15 19
 
16 20
     @NestedConfigurationProperty
17
-    private Mp mp = new Mp();
21
+    private Mp mp;
18 22
 
19 23
     @Data
20 24
     public static class Ma {
@@ -23,6 +27,15 @@ public class WeixinConfig {
23 27
         private String token;
24 28
         private String aesKey;
25 29
         private String msgDataFormat;
30
+
31
+        @NestedConfigurationProperty
32
+        private List<SubscribeMessage> subscribeMessages;
33
+
34
+        @Data
35
+        public static class SubscribeMessage {
36
+            private String type;
37
+            private String code;
38
+        }
26 39
     }
27 40
 
28 41
     @Data

+ 12
- 4
src/main/java/com/shigongli/controller/TaHousePersonController.java Wyświetl plik

@@ -7,10 +7,9 @@ import com.shigongli.common.BaseController;
7 7
 import com.shigongli.common.ResponseBean;
8 8
 import com.shigongli.common.StringUtils;
9 9
 import com.shigongli.constants.StatusConstant;
10
-import com.shigongli.entity.TaHouseOrder;
11
-import com.shigongli.entity.TaHouseSetting;
12
-import com.shigongli.entity.TaPerson;
10
+import com.shigongli.entity.*;
13 11
 import com.shigongli.service.ITaHouseOrderService;
12
+import com.shigongli.service.ITaHouseService;
14 13
 import com.shigongli.service.ITaHouseSettingService;
15 14
 import com.shigongli.vo.HousePersonParams;
16 15
 import io.swagger.annotations.Api;
@@ -25,7 +24,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
25 24
 import org.springframework.web.bind.annotation.RequestMethod;
26 25
 import org.springframework.web.bind.annotation.RequestParam;
27 26
 import com.shigongli.service.ITaHousePersonService;
28
-import com.shigongli.entity.TaHousePerson;
29 27
 import org.springframework.web.bind.annotation.RestController;
30 28
 
31 29
 import javax.servlet.http.HttpServletRequest;
@@ -57,6 +55,9 @@ public class TaHousePersonController extends BaseController {
57 55
     @Autowired
58 56
     ITaHouseSettingService iTaHouseSettingService;
59 57
 
58
+    @Autowired
59
+    ITaHouseService iTaHouseService;
60
+
60 61
 
61 62
     /**
62 63
      * 分页查询列表
@@ -102,6 +103,12 @@ public class TaHousePersonController extends BaseController {
102 103
             return ResponseBean.error("请设置入住人员信息", ResponseBean.ERROR_MISSING_PARAMS);
103 104
         }
104 105
 
106
+        // 房源
107
+        TaHouse taHouse = iTaHouseService.getById(housePersonParams.getHouseId());
108
+        if (null == taHouse || StatusConstant.DELETE.equals(taHouse.getStatus())) {
109
+            return ResponseBean.error("当前房源状态异常", ResponseBean.ERROR_UNAVAILABLE);
110
+        }
111
+
105 112
         // 订单
106 113
         TaHouseOrder taHouseOrder = iTaHouseOrderService.getById(housePersonParams.getOrderId());
107 114
         if (null == taHouseOrder) {
@@ -142,6 +149,7 @@ public class TaHousePersonController extends BaseController {
142 149
         }
143 150
 
144 151
         if (iTaHousePersonService.saveBatch(taHousePersonList)){
152
+            iTaHousePersonService.sendMessageToManager(taHouse, taHouseSetting.getStartDate());
145 153
             return ResponseBean.success(taHousePersonList);
146 154
         }else {
147 155
             return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);

+ 3
- 0
src/main/java/com/shigongli/entity/TaShopKeeper.java Wyświetl plik

@@ -52,4 +52,7 @@ public class TaShopKeeper implements Serializable {
52 52
 
53 53
     @TableField(exist = false)
54 54
     private TaShop taShop;
55
+
56
+    @TableField(exist = false)
57
+    private String openid;
55 58
 }

+ 4
- 0
src/main/java/com/shigongli/mapper/TaPersonMapper.java Wyświetl plik

@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5 5
 import org.apache.ibatis.annotations.Mapper;
6 6
 import org.apache.ibatis.annotations.Param;
7 7
 
8
+import java.util.List;
9
+
8 10
 /**
9 11
  * <p>
10 12
  * 人员表 Mapper 接口
@@ -17,4 +19,6 @@ import org.apache.ibatis.annotations.Param;
17 19
 public interface TaPersonMapper extends BaseMapper<TaPerson> {
18 20
 
19 21
     TaPerson getByOpenId(@Param("openid") String openid);
22
+
23
+    List<TaPerson> getCheckoutListBy(@Param("dateStr") String dateStr);
20 24
 }

+ 4
- 0
src/main/java/com/shigongli/mapper/TaShopKeeperMapper.java Wyświetl plik

@@ -3,6 +3,9 @@ package com.shigongli.mapper;
3 3
 import com.shigongli.entity.TaShopKeeper;
4 4
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5 5
 import org.apache.ibatis.annotations.Mapper;
6
+import org.apache.ibatis.annotations.Param;
7
+
8
+import java.util.List;
6 9
 
7 10
 /**
8 11
  * <p>
@@ -15,4 +18,5 @@ import org.apache.ibatis.annotations.Mapper;
15 18
 @Mapper
16 19
 public interface TaShopKeeperMapper extends BaseMapper<TaShopKeeper> {
17 20
 
21
+    List<TaShopKeeper> getByHouse(@Param("houseId") String houseId);
18 22
 }

+ 2
- 0
src/main/java/com/shigongli/service/ITaHousePersonService.java Wyświetl plik

@@ -1,5 +1,6 @@
1 1
 package com.shigongli.service;
2 2
 
3
+import com.shigongli.entity.TaHouse;
3 4
 import com.shigongli.entity.TaHousePerson;
4 5
 import com.baomidou.mybatisplus.extension.service.IService;
5 6
 
@@ -13,4 +14,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
13 14
  */
14 15
 public interface ITaHousePersonService extends IService<TaHousePerson> {
15 16
 
17
+    void sendMessageToManager(TaHouse taHouse, String dateStr);
16 18
 }

+ 4
- 0
src/main/java/com/shigongli/service/ITaPersonService.java Wyświetl plik

@@ -4,6 +4,8 @@ import com.shigongli.entity.TaPerson;
4 4
 import com.baomidou.mybatisplus.extension.service.IService;
5 5
 import com.shigongli.entity.TaShopKeeper;
6 6
 
7
+import java.util.List;
8
+
7 9
 /**
8 10
  * <p>
9 11
  * 人员表 服务类
@@ -17,4 +19,6 @@ public interface ITaPersonService extends IService<TaPerson> {
17 19
     TaPerson getByOpenId(String openid);
18 20
 
19 21
     TaPerson getByPhone(String phone);
22
+
23
+    List<TaPerson> getCheckoutListBy(String date);
20 24
 }

+ 2
- 0
src/main/java/com/shigongli/service/ITaShopKeeperService.java Wyświetl plik

@@ -23,4 +23,6 @@ public interface ITaShopKeeperService extends IService<TaShopKeeper> {
23 23
     List<TaShopKeeper> getByPerson(String personId);
24 24
 
25 25
     TaShopKeeper getByPhone(String phone, String shopId);
26
+
27
+    List<TaShopKeeper> getByHouse(String houseId);
26 28
 }

+ 79
- 0
src/main/java/com/shigongli/service/impl/TaHousePersonServiceImpl.java Wyświetl plik

@@ -1,11 +1,27 @@
1 1
 package com.shigongli.service.impl;
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;
7
+import com.shigongli.entity.TaHouse;
3 8
 import com.shigongli.entity.TaHousePerson;
9
+import com.shigongli.entity.TaShopKeeper;
4 10
 import com.shigongli.mapper.TaHousePersonMapper;
5 11
 import com.shigongli.service.ITaHousePersonService;
6 12
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
13
+import com.shigongli.service.ITaShopKeeperService;
14
+import lombok.extern.slf4j.Slf4j;
15
+import me.chanjar.weixin.mp.api.WxMpService;
16
+import me.chanjar.weixin.mp.bean.subscribe.WxMpSubscribeMessage;
17
+import org.checkerframework.checker.units.qual.A;
18
+import org.springframework.beans.factory.annotation.Autowired;
19
+import org.springframework.scheduling.annotation.Async;
7 20
 import org.springframework.stereotype.Service;
8 21
 
22
+import java.util.ArrayList;
23
+import java.util.List;
24
+
9 25
 /**
10 26
  * <p>
11 27
  * 住房人 服务实现类
@@ -14,7 +30,70 @@ import org.springframework.stereotype.Service;
14 30
  * @author yansen
15 31
  * @since 2020-12-11
16 32
  */
33
+@Slf4j
17 34
 @Service
18 35
 public class TaHousePersonServiceImpl extends ServiceImpl<TaHousePersonMapper, TaHousePerson> implements ITaHousePersonService {
36
+    @Autowired
37
+    ITaShopKeeperService iTaShopKeeperService;
38
+
39
+    @Autowired
40
+    WxUtils wxUtils;
41
+
42
+    @Autowired
43
+    WeixinConfig weixinConfig;
44
+
45
+    @Async
46
+    @Override
47
+    public void sendMessageToManager(TaHouse taHouse, String dateStr) {
48
+        try {
49
+            String houseId = taHouse.getHouseId();
50
+            List<TaShopKeeper> taShopKeeperList = iTaShopKeeperService.getByHouse(houseId);
51
+            if (null == taShopKeeperList || taShopKeeperList.size() < 1) {
52
+                log.error("没有找到房源【{}】对应的店主", houseId);
53
+                return;
54
+            }
55
+
56
+            // 先暂时发送一个店主
57
+            TaShopKeeper taShopKeeper = taShopKeeperList.get(0);
58
+
59
+            // 找到消息模板
60
+            List<WeixinConfig.Ma.SubscribeMessage> subscribeMessages = weixinConfig.getMa().getSubscribeMessages();
61
+            WeixinConfig.Ma.SubscribeMessage subscribeMessage = null;
62
+            if (null == subscribeMessages || subscribeMessages.size() < 1) {
63
+                log.error("没有找到小程序消息提醒配置");
64
+                return;
65
+            }
66
+            for (WeixinConfig.Ma.SubscribeMessage message : subscribeMessages) {
67
+                if ("settled-in".equals(message.getType())) {
68
+                    subscribeMessage = message;
69
+                    break;
70
+                }
71
+            }
72
+            if (null == subscribeMessage) {
73
+                log.error("没有找到入店提醒的消息配置");
74
+                return;
75
+            }
76
+
77
+            // 发送内容
78
+            List<WxMaSubscribeMessage.Data> dataList = new ArrayList<>();
79
+            dataList.add(new WxMaSubscribeMessage.Data("thing6", taHouse.getTitle().substring(0, 10)));
80
+            dataList.add(new WxMaSubscribeMessage.Data("date2", dateStr));
81
+
82
+            //
83
+            WxMaService maService = wxUtils.getMaService();
84
+            WxMaSubscribeMessage wxMaSubscribeMessage = WxMaSubscribeMessage
85
+                    .builder()
86
+                    .templateId(subscribeMessage.getCode())
87
+                    .toUser(taShopKeeper.getOpenid())
88
+                    .page(String.format("/pages/house/household/index?houseId=%s", houseId))
89
+                    .data(dataList)
90
+                    .build();
91
+
92
+            maService.getMsgService().sendSubscribeMsg(wxMaSubscribeMessage);
19 93
 
94
+        } catch (Exception e) {
95
+            log.error("发送订阅消息给店主失败: {}", e.getMessage());
96
+            e.printStackTrace();
97
+        }
98
+    }
20 99
 }

+ 7
- 0
src/main/java/com/shigongli/service/impl/TaPersonServiceImpl.java Wyświetl plik

@@ -11,6 +11,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
11 11
 import org.springframework.beans.factory.annotation.Autowired;
12 12
 import org.springframework.stereotype.Service;
13 13
 
14
+import java.util.List;
15
+
14 16
 /**
15 17
  * <p>
16 18
  * 人员表 服务实现类
@@ -42,4 +44,9 @@ public class TaPersonServiceImpl extends ServiceImpl<TaPersonMapper, TaPerson> i
42 44
 
43 45
         return getOne(queryWrapper);
44 46
     }
47
+
48
+    @Override
49
+    public List<TaPerson> getCheckoutListBy(String date) {
50
+        return taPersonMapper.getCheckoutListBy(date);
51
+    }
45 52
 }

+ 8
- 0
src/main/java/com/shigongli/service/impl/TaShopKeeperServiceImpl.java Wyświetl plik

@@ -29,6 +29,9 @@ public class TaShopKeeperServiceImpl extends ServiceImpl<TaShopKeeperMapper, TaS
29 29
     @Autowired
30 30
     ITaShopService iTaShopService;
31 31
 
32
+    @Autowired
33
+    TaShopKeeperMapper taShopKeeperMapper;
34
+
32 35
     @Override
33 36
     public void bindPerson(TaPerson taPerson) {
34 37
         List<TaShopKeeper> shopKeeperList = getByPhone(taPerson.getPhone());
@@ -82,4 +85,9 @@ public class TaShopKeeperServiceImpl extends ServiceImpl<TaShopKeeperMapper, TaS
82 85
 
83 86
         return getOne(queryWrapper);
84 87
     }
88
+
89
+    @Override
90
+    public List<TaShopKeeper> getByHouse(String houseId) {
91
+        return taShopKeeperMapper.getByHouse(houseId);
92
+    }
85 93
 }

+ 41
- 0
src/main/java/com/shigongli/task/SendCheckOutMessage.java Wyświetl plik

@@ -0,0 +1,41 @@
1
+package com.shigongli.task;
2
+
3
+import com.shigongli.entity.TaPerson;
4
+import com.shigongli.service.ITaPersonService;
5
+import lombok.extern.slf4j.Slf4j;
6
+import me.chanjar.weixin.common.util.DataUtils;
7
+import org.springframework.beans.factory.annotation.Autowired;
8
+import org.springframework.scheduling.annotation.Scheduled;
9
+import org.springframework.stereotype.Component;
10
+
11
+import java.time.LocalDateTime;
12
+import java.time.format.DateTimeFormatter;
13
+import java.util.List;
14
+
15
+
16
+/**
17
+ * 发送离店提醒
18
+ */
19
+@Slf4j
20
+@Component
21
+public class SendCheckOutMessage {
22
+
23
+    @Autowired
24
+    ITaPersonService iTaPersonService;
25
+
26
+    @Scheduled(cron = "0 0 11 * * ?")
27
+    public void run() {
28
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
29
+        String today = LocalDateTime.now().format(formatter);
30
+
31
+        List<TaPerson> taPersonList = iTaPersonService.getCheckoutListBy(today);
32
+        if (null == taPersonList) {
33
+            return;
34
+        }
35
+
36
+        // 每隔 1s 发送一条离店提醒
37
+        for (TaPerson taPerson : taPersonList) {
38
+            // todo
39
+        }
40
+    }
41
+}

+ 6
- 0
src/main/resources/application.yml Wyświetl plik

@@ -45,6 +45,12 @@ weixin:
45 45
     token:
46 46
     aesKey:
47 47
     msgDataFormat: JSON
48
+    subscribe-messages:
49
+      - type: settled-in
50
+        code: rMg5CzypZSniRGHoZ7SBdqv_kmf7fPfTJMZ1k1SgobY
51
+      - type: check-out
52
+        code:
53
+
48 54
   # 公众号
49 55
   mp:
50 56
     appid: wx74db171e5f6524ad

+ 13
- 0
src/main/resources/mapper/TaPersonMapper.xml Wyświetl plik

@@ -5,4 +5,17 @@
5 5
     <select id="getByOpenId" resultType="com.shigongli.entity.TaPerson">
6 6
         select * from ta_person where openid = #{openid}
7 7
     </select>
8
+    <select id="getCheckoutListBy" resultType="com.shigongli.entity.TaPerson">
9
+        SELECT DISTINCT
10
+            m.*
11
+        FROM
12
+            ta_house_setting t
13
+            INNER JOIN ta_house_order s ON t.setting_id = s.setting_id
14
+            INNER JOIN ta_person m ON m.person_id = s.person_id
15
+        WHERE
16
+            t.end_date = #{dateStr}
17
+            AND t.`status` = 1
18
+            AND s.`status` = 1
19
+            AND m.`status` = 1
20
+    </select>
8 21
 </mapper>

+ 11
- 0
src/main/resources/mapper/TaShopKeeperMapper.xml Wyświetl plik

@@ -2,4 +2,15 @@
2 2
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3 3
 <mapper namespace="com.shigongli.mapper.TaShopKeeperMapper">
4 4
 
5
+    <select id="getByHouse" resultType="com.shigongli.entity.TaShopKeeper">
6
+        SELECT DISTINCT
7
+            t.*,
8
+            s.openid
9
+        FROM
10
+            ta_shop_keeper t
11
+            INNER JOIN ta_house m ON m.shop_id = t.shop_id
12
+            INNER JOIN ta_person s ON s.person_id = t.person_id
13
+        WHERE
14
+            m.house_id = #{houseId}
15
+    </select>
5 16
 </mapper>