浏览代码

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

zlisen 4 年前
父节点
当前提交
022bedf776

+ 0
- 2
debug.log 查看文件

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 查看文件

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

+ 2
- 0
src/main/java/com/shigongli/SpringApplication.java 查看文件

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

+ 15
- 2
src/main/java/com/shigongli/config/WeixinConfig.java 查看文件

1
 package com.shigongli.config;
1
 package com.shigongli.config;
2
 
2
 
3
 import lombok.Data;
3
 import lombok.Data;
4
+import lombok.NoArgsConstructor;
4
 import org.springframework.boot.context.properties.ConfigurationProperties;
5
 import org.springframework.boot.context.properties.ConfigurationProperties;
5
 import org.springframework.boot.context.properties.NestedConfigurationProperty;
6
 import org.springframework.boot.context.properties.NestedConfigurationProperty;
6
 import org.springframework.stereotype.Component;
7
 import org.springframework.stereotype.Component;
7
 
8
 
9
+import java.util.ArrayList;
10
+import java.util.List;
11
+
8
 @Data
12
 @Data
9
 @Component
13
 @Component
10
 @ConfigurationProperties(prefix = "weixin")
14
 @ConfigurationProperties(prefix = "weixin")
11
 public class WeixinConfig {
15
 public class WeixinConfig {
12
 
16
 
13
     @NestedConfigurationProperty
17
     @NestedConfigurationProperty
14
-    private Ma ma = new Ma();
18
+    private Ma ma;
15
 
19
 
16
     @NestedConfigurationProperty
20
     @NestedConfigurationProperty
17
-    private Mp mp = new Mp();
21
+    private Mp mp;
18
 
22
 
19
     @Data
23
     @Data
20
     public static class Ma {
24
     public static class Ma {
23
         private String token;
27
         private String token;
24
         private String aesKey;
28
         private String aesKey;
25
         private String msgDataFormat;
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
     @Data
41
     @Data

+ 12
- 4
src/main/java/com/shigongli/controller/TaHousePersonController.java 查看文件

7
 import com.shigongli.common.ResponseBean;
7
 import com.shigongli.common.ResponseBean;
8
 import com.shigongli.common.StringUtils;
8
 import com.shigongli.common.StringUtils;
9
 import com.shigongli.constants.StatusConstant;
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
 import com.shigongli.service.ITaHouseOrderService;
11
 import com.shigongli.service.ITaHouseOrderService;
12
+import com.shigongli.service.ITaHouseService;
14
 import com.shigongli.service.ITaHouseSettingService;
13
 import com.shigongli.service.ITaHouseSettingService;
15
 import com.shigongli.vo.HousePersonParams;
14
 import com.shigongli.vo.HousePersonParams;
16
 import io.swagger.annotations.Api;
15
 import io.swagger.annotations.Api;
25
 import org.springframework.web.bind.annotation.RequestMethod;
24
 import org.springframework.web.bind.annotation.RequestMethod;
26
 import org.springframework.web.bind.annotation.RequestParam;
25
 import org.springframework.web.bind.annotation.RequestParam;
27
 import com.shigongli.service.ITaHousePersonService;
26
 import com.shigongli.service.ITaHousePersonService;
28
-import com.shigongli.entity.TaHousePerson;
29
 import org.springframework.web.bind.annotation.RestController;
27
 import org.springframework.web.bind.annotation.RestController;
30
 
28
 
31
 import javax.servlet.http.HttpServletRequest;
29
 import javax.servlet.http.HttpServletRequest;
57
     @Autowired
55
     @Autowired
58
     ITaHouseSettingService iTaHouseSettingService;
56
     ITaHouseSettingService iTaHouseSettingService;
59
 
57
 
58
+    @Autowired
59
+    ITaHouseService iTaHouseService;
60
+
60
 
61
 
61
     /**
62
     /**
62
      * 分页查询列表
63
      * 分页查询列表
102
             return ResponseBean.error("请设置入住人员信息", ResponseBean.ERROR_MISSING_PARAMS);
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
         TaHouseOrder taHouseOrder = iTaHouseOrderService.getById(housePersonParams.getOrderId());
113
         TaHouseOrder taHouseOrder = iTaHouseOrderService.getById(housePersonParams.getOrderId());
107
         if (null == taHouseOrder) {
114
         if (null == taHouseOrder) {
142
         }
149
         }
143
 
150
 
144
         if (iTaHousePersonService.saveBatch(taHousePersonList)){
151
         if (iTaHousePersonService.saveBatch(taHousePersonList)){
152
+            iTaHousePersonService.sendMessageToManager(taHouse, taHouseSetting.getStartDate());
145
             return ResponseBean.success(taHousePersonList);
153
             return ResponseBean.success(taHousePersonList);
146
         }else {
154
         }else {
147
             return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
155
             return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);

+ 3
- 0
src/main/java/com/shigongli/entity/TaShopKeeper.java 查看文件

52
 
52
 
53
     @TableField(exist = false)
53
     @TableField(exist = false)
54
     private TaShop taShop;
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 查看文件

5
 import org.apache.ibatis.annotations.Mapper;
5
 import org.apache.ibatis.annotations.Mapper;
6
 import org.apache.ibatis.annotations.Param;
6
 import org.apache.ibatis.annotations.Param;
7
 
7
 
8
+import java.util.List;
9
+
8
 /**
10
 /**
9
  * <p>
11
  * <p>
10
  * 人员表 Mapper 接口
12
  * 人员表 Mapper 接口
17
 public interface TaPersonMapper extends BaseMapper<TaPerson> {
19
 public interface TaPersonMapper extends BaseMapper<TaPerson> {
18
 
20
 
19
     TaPerson getByOpenId(@Param("openid") String openid);
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 查看文件

3
 import com.shigongli.entity.TaShopKeeper;
3
 import com.shigongli.entity.TaShopKeeper;
4
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5
 import org.apache.ibatis.annotations.Mapper;
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
  * <p>
11
  * <p>
15
 @Mapper
18
 @Mapper
16
 public interface TaShopKeeperMapper extends BaseMapper<TaShopKeeper> {
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 查看文件

1
 package com.shigongli.service;
1
 package com.shigongli.service;
2
 
2
 
3
+import com.shigongli.entity.TaHouse;
3
 import com.shigongli.entity.TaHousePerson;
4
 import com.shigongli.entity.TaHousePerson;
4
 import com.baomidou.mybatisplus.extension.service.IService;
5
 import com.baomidou.mybatisplus.extension.service.IService;
5
 
6
 
13
  */
14
  */
14
 public interface ITaHousePersonService extends IService<TaHousePerson> {
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 查看文件

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

+ 2
- 0
src/main/java/com/shigongli/service/ITaShopKeeperService.java 查看文件

23
     List<TaShopKeeper> getByPerson(String personId);
23
     List<TaShopKeeper> getByPerson(String personId);
24
 
24
 
25
     TaShopKeeper getByPhone(String phone, String shopId);
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 查看文件

1
 package com.shigongli.service.impl;
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
 import com.shigongli.entity.TaHousePerson;
8
 import com.shigongli.entity.TaHousePerson;
9
+import com.shigongli.entity.TaShopKeeper;
4
 import com.shigongli.mapper.TaHousePersonMapper;
10
 import com.shigongli.mapper.TaHousePersonMapper;
5
 import com.shigongli.service.ITaHousePersonService;
11
 import com.shigongli.service.ITaHousePersonService;
6
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
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
 import org.springframework.stereotype.Service;
20
 import org.springframework.stereotype.Service;
8
 
21
 
22
+import java.util.ArrayList;
23
+import java.util.List;
24
+
9
 /**
25
 /**
10
  * <p>
26
  * <p>
11
  * 住房人 服务实现类
27
  * 住房人 服务实现类
14
  * @author yansen
30
  * @author yansen
15
  * @since 2020-12-11
31
  * @since 2020-12-11
16
  */
32
  */
33
+@Slf4j
17
 @Service
34
 @Service
18
 public class TaHousePersonServiceImpl extends ServiceImpl<TaHousePersonMapper, TaHousePerson> implements ITaHousePersonService {
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 查看文件

11
 import org.springframework.beans.factory.annotation.Autowired;
11
 import org.springframework.beans.factory.annotation.Autowired;
12
 import org.springframework.stereotype.Service;
12
 import org.springframework.stereotype.Service;
13
 
13
 
14
+import java.util.List;
15
+
14
 /**
16
 /**
15
  * <p>
17
  * <p>
16
  * 人员表 服务实现类
18
  * 人员表 服务实现类
42
 
44
 
43
         return getOne(queryWrapper);
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 查看文件

29
     @Autowired
29
     @Autowired
30
     ITaShopService iTaShopService;
30
     ITaShopService iTaShopService;
31
 
31
 
32
+    @Autowired
33
+    TaShopKeeperMapper taShopKeeperMapper;
34
+
32
     @Override
35
     @Override
33
     public void bindPerson(TaPerson taPerson) {
36
     public void bindPerson(TaPerson taPerson) {
34
         List<TaShopKeeper> shopKeeperList = getByPhone(taPerson.getPhone());
37
         List<TaShopKeeper> shopKeeperList = getByPhone(taPerson.getPhone());
82
 
85
 
83
         return getOne(queryWrapper);
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 查看文件

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 查看文件

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

+ 13
- 0
src/main/resources/mapper/TaPersonMapper.xml 查看文件

5
     <select id="getByOpenId" resultType="com.shigongli.entity.TaPerson">
5
     <select id="getByOpenId" resultType="com.shigongli.entity.TaPerson">
6
         select * from ta_person where openid = #{openid}
6
         select * from ta_person where openid = #{openid}
7
     </select>
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
 </mapper>
21
 </mapper>

+ 11
- 0
src/main/resources/mapper/TaShopKeeperMapper.xml 查看文件

2
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
2
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
 <mapper namespace="com.shigongli.mapper.TaShopKeeperMapper">
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
 </mapper>
16
 </mapper>