张延森 6 years ago
parent
commit
66e4db3235

+ 1
- 1
pom.xml View File

10
 	</parent>
10
 	</parent>
11
 	<groupId>com.huiju.welcome</groupId>
11
 	<groupId>com.huiju.welcome</groupId>
12
 	<artifactId>mainbiz</artifactId>
12
 	<artifactId>mainbiz</artifactId>
13
-	<version>v4.0.0</version>
13
+	<version>v4.0.1</version>
14
 	<name>mainbiz</name>
14
 	<name>mainbiz</name>
15
 	<description>com.huiju.welcome main service</description>
15
 	<description>com.huiju.welcome main service</description>
16
 
16
 

+ 29
- 0
src/main/java/com.huiju.welcome/config/SMSProperties.java View File

1
+package com.huiju.welcome.config;
2
+
3
+
4
+import lombok.Data;
5
+import org.springframework.boot.context.properties.ConfigurationProperties;
6
+
7
+@Data
8
+@ConfigurationProperties(prefix = "sms")
9
+public class SMSProperties {
10
+    String url;
11
+    String method;
12
+    String contentType;
13
+    Captcha captcha;
14
+
15
+    @Data
16
+    public static class Template {
17
+        String code;
18
+        String tel;
19
+        String[] params;
20
+    }
21
+
22
+    @Data
23
+    public static class Captcha {
24
+        String code;
25
+        Integer expire;
26
+        Integer size;
27
+        String sign;
28
+    }
29
+}

+ 21
- 7
src/main/java/com.huiju.welcome/controller/TaGoodsOrdersController.java View File

6
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
7
 import com.huiju.welcome.common.base.BaseController;
7
 import com.huiju.welcome.common.base.BaseController;
8
 import com.huiju.welcome.common.base.ResponseBean;
8
 import com.huiju.welcome.common.base.ResponseBean;
9
-import com.huiju.welcome.model.SysUser;
10
-import com.huiju.welcome.model.TaGoodsOrders;
11
-import com.huiju.welcome.model.TaGoodsOrdersDetail;
12
-import com.huiju.welcome.model.TdGoodsType;
13
-import com.huiju.welcome.service.ISysUserService;
14
-import com.huiju.welcome.service.ITaGoodsOrdersDetailService;
15
-import com.huiju.welcome.service.ITaGoodsOrdersService;
9
+import com.huiju.welcome.model.*;
10
+import com.huiju.welcome.service.*;
16
 import com.huiju.welcome.utils.JWTUtils;
11
 import com.huiju.welcome.utils.JWTUtils;
17
 import com.huiju.welcome.utils.StatusUtils;
12
 import com.huiju.welcome.utils.StatusUtils;
18
 import com.huiju.welcome.utils.StringUtils;
13
 import com.huiju.welcome.utils.StringUtils;
19
 import io.swagger.annotations.ApiImplicitParams;
14
 import io.swagger.annotations.ApiImplicitParams;
20
 import io.swagger.annotations.ApiOperation;
15
 import io.swagger.annotations.ApiOperation;
21
 import io.swagger.models.auth.In;
16
 import io.swagger.models.auth.In;
17
+import org.apache.http.HttpStatus;
22
 import org.slf4j.Logger;
18
 import org.slf4j.Logger;
23
 import org.slf4j.LoggerFactory;
19
 import org.slf4j.LoggerFactory;
24
 import org.springframework.beans.factory.annotation.Autowired;
20
 import org.springframework.beans.factory.annotation.Autowired;
49
     public ITaGoodsOrdersDetailService iTaGoodsOrdersDetailService;
45
     public ITaGoodsOrdersDetailService iTaGoodsOrdersDetailService;
50
     @Autowired
46
     @Autowired
51
     public ISysUserService iSysUserService;
47
     public ISysUserService iSysUserService;
48
+    @Autowired
49
+    public ITaMainUsherRecordService iTaMainUsherRecordService;
50
+    @Autowired
51
+    public ITaCustomerService iTaCustomerService;
52
 
52
 
53
 
53
 
54
     /**
54
     /**
70
             Integer recId = iTaGoodsOrdersService.getRecIdByCustomerIdCurrentDate(taGoodsOrders.getCustomerId());
70
             Integer recId = iTaGoodsOrdersService.getRecIdByCustomerIdCurrentDate(taGoodsOrders.getCustomerId());
71
             if(recId != null){
71
             if(recId != null){
72
                 taGoodsOrders.setRecId(recId);
72
                 taGoodsOrders.setRecId(recId);
73
+            } else {
74
+                //
75
+                TaCustomer cust = iTaCustomerService.getById(taGoodsOrders.getCustomerId());
76
+                if (cust != null) {
77
+                    boolean ok = iTaMainUsherRecordService.newRecordByConsultant(cust, null);
78
+
79
+                    if (!ok) {
80
+                        return ResponseBean.error("更新客户到访失败", HttpStatus.SC_INTERNAL_SERVER_ERROR);
81
+                    }
82
+                    recId = iTaGoodsOrdersService.getRecIdByCustomerIdCurrentDate(taGoodsOrders.getCustomerId());
83
+                    taGoodsOrders.setRecId(recId);
84
+                } else {
85
+                    return ResponseBean.error("关联客户信息失败", HttpStatus.SC_INTERNAL_SERVER_ERROR);
86
+                }
73
             }
87
             }
74
             Boolean flag = iTaGoodsOrdersService.save(taGoodsOrders);
88
             Boolean flag = iTaGoodsOrdersService.save(taGoodsOrders);
75
 
89
 

+ 19
- 0
src/main/java/com.huiju.welcome/controller/TaTransactionRecordController.java View File

1
 package com.huiju.welcome.controller;
1
 package com.huiju.welcome.controller;
2
 
2
 
3
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
3
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
4
 import com.baomidou.mybatisplus.core.metadata.IPage;
5
 import com.baomidou.mybatisplus.core.metadata.IPage;
5
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
 import com.huiju.welcome.common.base.BaseController;
7
 import com.huiju.welcome.common.base.BaseController;
7
 import com.huiju.welcome.common.base.ResponseBean;
8
 import com.huiju.welcome.common.base.ResponseBean;
9
+import com.huiju.welcome.model.TaCustomer;
8
 import com.huiju.welcome.model.TaTransactionRecord;
10
 import com.huiju.welcome.model.TaTransactionRecord;
11
+import com.huiju.welcome.service.ITaCustomerService;
9
 import com.huiju.welcome.service.ITaTransactionRecordService;
12
 import com.huiju.welcome.service.ITaTransactionRecordService;
13
+import com.huiju.welcome.utils.StatusUtils;
10
 import org.slf4j.Logger;
14
 import org.slf4j.Logger;
11
 import org.slf4j.LoggerFactory;
15
 import org.slf4j.LoggerFactory;
12
 import org.springframework.beans.factory.annotation.Autowired;
16
 import org.springframework.beans.factory.annotation.Autowired;
35
     @Autowired
39
     @Autowired
36
     public ITaTransactionRecordService iTaTransactionRecordService;
40
     public ITaTransactionRecordService iTaTransactionRecordService;
37
 
41
 
42
+    @Autowired
43
+    public ITaCustomerService iTaCustomerService;
44
+
38
 
45
 
39
     /**
46
     /**
40
      * 分页查询列表
47
      * 分页查询列表
70
     public ResponseBean taTransactionRecordAdd(@RequestBody TaTransactionRecord taTransactionRecord){
77
     public ResponseBean taTransactionRecordAdd(@RequestBody TaTransactionRecord taTransactionRecord){
71
         ResponseBean responseBean = new ResponseBean();
78
         ResponseBean responseBean = new ResponseBean();
72
         try {
79
         try {
80
+            // 反更新客户表
81
+            UpdateWrapper<TaCustomer> wrapper = new UpdateWrapper<>();
82
+            wrapper.eq("customer_id", taTransactionRecord.getCustomerId());
83
+            wrapper.set("status", StatusUtils.BizDone);
84
+            iTaCustomerService.update(new TaCustomer(), wrapper);
85
+
73
             if (iTaTransactionRecordService.save(taTransactionRecord)){
86
             if (iTaTransactionRecordService.save(taTransactionRecord)){
74
                 responseBean.addSuccess(taTransactionRecord);
87
                 responseBean.addSuccess(taTransactionRecord);
75
             }else {
88
             }else {
114
                                         @RequestBody TaTransactionRecord taTransactionRecord){
127
                                         @RequestBody TaTransactionRecord taTransactionRecord){
115
         ResponseBean responseBean = new ResponseBean();
128
         ResponseBean responseBean = new ResponseBean();
116
         try {
129
         try {
130
+            // 反更新客户表
131
+            UpdateWrapper<TaCustomer> wrapper = new UpdateWrapper<>();
132
+            wrapper.eq("customer_id", taTransactionRecord.getCustomerId());
133
+            wrapper.set("status", StatusUtils.BizDone);
134
+            iTaCustomerService.update(new TaCustomer(), wrapper);
135
+
117
             taTransactionRecord.setRecordId(id);
136
             taTransactionRecord.setRecordId(id);
118
             if (iTaTransactionRecordService.updateById(taTransactionRecord)){
137
             if (iTaTransactionRecordService.updateById(taTransactionRecord)){
119
                 responseBean.addSuccess(taTransactionRecord);
138
                 responseBean.addSuccess(taTransactionRecord);

+ 21
- 8
src/main/java/com.huiju.welcome/controller/TaWechatUserController.java View File

12
 import com.huiju.welcome.service.ISysUserService;
12
 import com.huiju.welcome.service.ISysUserService;
13
 import com.huiju.welcome.service.ITaPersonService;
13
 import com.huiju.welcome.service.ITaPersonService;
14
 import com.huiju.welcome.service.ITaWechatUserService;
14
 import com.huiju.welcome.service.ITaWechatUserService;
15
-import com.huiju.welcome.utils.CommConstant;
16
-import com.huiju.welcome.utils.JWTUtils;
17
-import com.huiju.welcome.utils.MiniApp;
18
-import com.huiju.welcome.utils.StatusUtils;
15
+import com.huiju.welcome.utils.*;
19
 import org.apache.http.HttpStatus;
16
 import org.apache.http.HttpStatus;
20
 import org.slf4j.Logger;
17
 import org.slf4j.Logger;
21
 import org.slf4j.LoggerFactory;
18
 import org.slf4j.LoggerFactory;
22
 import org.springframework.beans.factory.annotation.Autowired;
19
 import org.springframework.beans.factory.annotation.Autowired;
20
+import org.springframework.beans.factory.annotation.Value;
23
 import org.springframework.boot.context.properties.EnableConfigurationProperties;
21
 import org.springframework.boot.context.properties.EnableConfigurationProperties;
24
 import org.springframework.web.bind.annotation.*;
22
 import org.springframework.web.bind.annotation.*;
25
 
23
 
54
     @Autowired
52
     @Autowired
55
     private ISysUserService iSysUserService;
53
     private ISysUserService iSysUserService;
56
 
54
 
55
+    @Autowired
56
+    private SMSUtils smsUtils;
57
+
57
     @GetMapping("/login")
58
     @GetMapping("/login")
58
     public ResponseBean login(@RequestParam String code) {
59
     public ResponseBean login(@RequestParam String code) {
59
         ResponseBean resp = miniApp.getOpenid(code);
60
         ResponseBean resp = miniApp.getOpenid(code);
103
         return ResponseBean.success(map);
104
         return ResponseBean.success(map);
104
     }
105
     }
105
 
106
 
107
+    @PostMapping("/captcha")
108
+    public ResponseBean sendCaptcha(@RequestParam String tel) {
109
+        boolean success = smsUtils.sendCaptcha(tel);
110
+        if (success) {
111
+            return ResponseBean.success("发送验证码成功");
112
+        } else {
113
+            return ResponseBean.error("验证码发送失败, 请重试", HttpStatus.SC_INTERNAL_SERVER_ERROR);
114
+        }
115
+    }
116
+
106
     @PostMapping("/bind")
117
     @PostMapping("/bind")
107
     public ResponseBean bind(@RequestBody String paramStr, HttpServletRequest request) {
118
     public ResponseBean bind(@RequestBody String paramStr, HttpServletRequest request) {
108
         String userId = JWTUtils.getSubject(request);
119
         String userId = JWTUtils.getSubject(request);
128
             return ResponseBean.error("绑定参数为空或者非法", HttpStatus.SC_BAD_REQUEST);
139
             return ResponseBean.error("绑定参数为空或者非法", HttpStatus.SC_BAD_REQUEST);
129
         }
140
         }
130
 
141
 
131
-        // todo
132
-        // 先简单验证
133
-        if (!"1234".equals(captcha)) {
134
-            return ResponseBean.error("绑定参数为空或者非法", HttpStatus.SC_BAD_REQUEST);
142
+        // 校验短信验证码, 当前年度为万能码
143
+        LocalDateTime now = LocalDateTime.now();
144
+        if (!String.valueOf(now.getYear()).equals(captcha)) {
145
+            if (!smsUtils.checkCaptcha(phone, captcha)) {
146
+                return ResponseBean.error("验证码不正确或已过期", HttpStatus.SC_BAD_REQUEST);
147
+            }
135
         }
148
         }
136
 
149
 
137
         SysUser sysUser = iSysUserService.getByPhone(phone);
150
         SysUser sysUser = iSysUserService.getByPhone(phone);

+ 3
- 7
src/main/java/com.huiju.welcome/service/impl/TaCarRecordServiceImpl.java View File

7
 import com.huiju.welcome.mapper.TaCarRecordMapper;
7
 import com.huiju.welcome.mapper.TaCarRecordMapper;
8
 import com.huiju.welcome.model.*;
8
 import com.huiju.welcome.model.*;
9
 import com.huiju.welcome.service.*;
9
 import com.huiju.welcome.service.*;
10
-import com.huiju.welcome.utils.AliFaceUtils;
11
-import com.huiju.welcome.utils.CommConstant;
12
-import com.huiju.welcome.utils.StatusUtils;
13
-import com.huiju.welcome.utils.TencentFaceUtils;
10
+import com.huiju.welcome.utils.*;
14
 import com.tencentcloudapi.common.exception.TencentCloudSDKException;
11
 import com.tencentcloudapi.common.exception.TencentCloudSDKException;
15
 import com.tencentcloudapi.iai.v20180301.models.Candidate;
12
 import com.tencentcloudapi.iai.v20180301.models.Candidate;
16
 import org.slf4j.Logger;
13
 import org.slf4j.Logger;
226
     @Override
223
     @Override
227
     public List<TaCarRecord> getTimeline() {
224
     public List<TaCarRecord> getTimeline() {
228
         LocalDateTime now = LocalDateTime.now();
225
         LocalDateTime now = LocalDateTime.now();
226
+        String dayBegin = DateUtils.localDatetime2day(now) + " 00:00:00";
229
 
227
 
230
-        // 四小时内
231
-        LocalDateTime fourHour = now.minusHours(4);
232
         QueryWrapper<TaCarRecord> query = new QueryWrapper<>();
228
         QueryWrapper<TaCarRecord> query = new QueryWrapper<>();
233
-        query.ge("create_date", fourHour);
229
+        query.ge("create_date", dayBegin);
234
         query.groupBy("plate_number");
230
         query.groupBy("plate_number");
235
         query.orderByDesc("create_date");
231
         query.orderByDesc("create_date");
236
         List<TaCarRecord> result = taCarRecordMapper.selectList(query);
232
         List<TaCarRecord> result = taCarRecordMapper.selectList(query);

+ 11
- 11
src/main/java/com.huiju.welcome/service/impl/TaCustomerServiceImpl.java View File

315
         List<SysDict> dictList = iSysDictService.list();
315
         List<SysDict> dictList = iSysDictService.list();
316
         dictList.stream().forEach(e -> {
316
         dictList.stream().forEach(e -> {
317
             //对比数据重新赛值
317
             //对比数据重新赛值
318
-            if (e.getId().equals(taCustomer.getNowArea())){
318
+            if (null != taCustomer.getNowArea() && e.getId().equals(taCustomer.getNowArea())){
319
                 taCustomer.setNowAreaLable(e.getLabel());
319
                 taCustomer.setNowAreaLable(e.getLabel());
320
             }
320
             }
321
-            if (e.getId().equals(taCustomer.getFamilyWork())){
321
+            if (null != taCustomer.getFamilyWork() && e.getId().equals(taCustomer.getFamilyWork())){
322
                 taCustomer.setFamilyWorkLable(e.getLabel());
322
                 taCustomer.setFamilyWorkLable(e.getLabel());
323
             }
323
             }
324
-            if (e.getId().equals(Integer.valueOf(taCustomer.getFamilyIndustry()))){
324
+            if (null != taCustomer.getFamilyIndustry() && e.getId().equals(Integer.valueOf(taCustomer.getFamilyIndustry()))){
325
                 taCustomer.setFamilyIndustryLable(e.getLabel());
325
                 taCustomer.setFamilyIndustryLable(e.getLabel());
326
             }
326
             }
327
-            if (e.getId().equals(Integer.valueOf(taCustomer.getFamilyDuty()))){
327
+            if (null != taCustomer.getFamilyDuty() && e.getId().equals(Integer.valueOf(taCustomer.getFamilyDuty()))){
328
                 taCustomer.setFamilyDutyLable(e.getLabel());
328
                 taCustomer.setFamilyDutyLable(e.getLabel());
329
             }
329
             }
330
-            if (e.getId().equals(taCustomer.getHousePurchasing())){
330
+            if (null != taCustomer.getHousePurchasing() && e.getId().equals(taCustomer.getHousePurchasing())){
331
                 taCustomer.setHousePurchasingLable(e.getLabel());
331
                 taCustomer.setHousePurchasingLable(e.getLabel());
332
             }
332
             }
333
-            if (e.getId().equals(taCustomer.getHouseProperty())){
333
+            if (null != taCustomer.getHouseProperty() && e.getId().equals(taCustomer.getHouseProperty())){
334
                 taCustomer.setHousePropertyLable(e.getLabel());
334
                 taCustomer.setHousePropertyLable(e.getLabel());
335
             }
335
             }
336
-            if (e.getId().equals(taCustomer.getHouseLivingArea())){
336
+            if (null != taCustomer.getHouseLivingArea() && e.getId().equals(taCustomer.getHouseLivingArea())){
337
                 taCustomer.setHouseLivingAreaLable(e.getLabel());
337
                 taCustomer.setHouseLivingAreaLable(e.getLabel());
338
             }
338
             }
339
-            if (e.getId().equals(taCustomer.getHouseType())){
339
+            if (null != taCustomer.getHouseType() && e.getId().equals(taCustomer.getHouseType())){
340
                 taCustomer.setHouseTypeLable(e.getLabel());
340
                 taCustomer.setHouseTypeLable(e.getLabel());
341
             }
341
             }
342
-            if (e.getId().equals(taCustomer.getFamilyStructure())){
342
+            if (null != taCustomer.getFamilyStructure() && e.getId().equals(taCustomer.getFamilyStructure())){
343
                 taCustomer.setFamilyStructureLable(e.getLabel());
343
                 taCustomer.setFamilyStructureLable(e.getLabel());
344
             }
344
             }
345
-            if (e.getId().equals(taCustomer.getCustomerAge())){
345
+            if (null != taCustomer.getCustomerAge() && e.getId().equals(taCustomer.getCustomerAge())){
346
                 taCustomer.setCustomerAgeLable(e.getLabel());
346
                 taCustomer.setCustomerAgeLable(e.getLabel());
347
             }
347
             }
348
-            if (e.getId().equals(Integer.valueOf(taCustomer.getFavorLevel()))){
348
+            if (null != taCustomer.getFavorLevel() && e.getId().equals(Integer.valueOf(taCustomer.getFavorLevel()))){
349
                 taCustomer.setFavorLevelLable(e.getLabel());
349
                 taCustomer.setFavorLevelLable(e.getLabel());
350
             }
350
             }
351
         });
351
         });

+ 12
- 8
src/main/java/com.huiju.welcome/service/impl/TaMainUsherRecordServiceImpl.java View File

465
                 return false;
465
                 return false;
466
             }
466
             }
467
         } else {
467
         } else {
468
+            TaMainUsherRecord origin = taMainUsherRecordMapper.selectById(taMainUsherRecord.getRecId());
468
             String remark = taMainUsherRecord.getRemark();
469
             String remark = taMainUsherRecord.getRemark();
469
         
470
         
470
             if (null == remark) {
471
             if (null == remark) {
471
-                remark = taCustomer.getRemark();
472
+                remark = origin.getRemark();
473
+            }
474
+            else if (!StringUtils.isEmpty(origin.getRemark()) && !remark.equals(origin.getRemark())) {
475
+                remark += "\n\n---" + DateUtils.cutSecond(LocalDateTime.now())+ "---" + "\n" + origin.getRemark();
472
             }
476
             }
473
-            //else if (!StringUtils.isEmpty(taCustomer.getRemark())) {
474
-            //    remark += "\n\n---" + DateUtils.cutSecond(LocalDateTime.now())+ "---" + "\n" + taCustomer.getRemark();
475
-            //}
476
             taMainUsherRecord.setRemark(remark);
477
             taMainUsherRecord.setRemark(remark);
477
         
478
         
478
             int row = taMainUsherRecordMapper.updateById(taMainUsherRecord);
479
             int row = taMainUsherRecordMapper.updateById(taMainUsherRecord);
485
 	        queryWrapper.eq("rec_id",taMainUsherRecord.getRecId());
486
 	        queryWrapper.eq("rec_id",taMainUsherRecord.getRecId());
486
 	        taFollowupRecordMapper.delete(queryWrapper);
487
 	        taFollowupRecordMapper.delete(queryWrapper);
487
         }
488
         }
488
-	    for (TaFollowupRecord follow : taFollowupRecordList) {
489
-		    follow.setRecId(taMainUsherRecord.getRecId());
490
-		    taFollowupRecordMapper.insert(follow);
491
-	    }
489
+
490
+        if (null != taFollowupRecordList) {
491
+            for (TaFollowupRecord follow : taFollowupRecordList) {
492
+                follow.setRecId(taMainUsherRecord.getRecId());
493
+                taFollowupRecordMapper.insert(follow);
494
+            }
495
+        }
492
     
496
     
493
         return true;
497
         return true;
494
     }
498
     }

+ 3
- 3
src/main/java/com.huiju.welcome/service/impl/TaVisitingLogServiceImpl.java View File

14
 import com.huiju.welcome.service.ITaDeviceService;
14
 import com.huiju.welcome.service.ITaDeviceService;
15
 import com.huiju.welcome.service.ITaPersonService;
15
 import com.huiju.welcome.service.ITaPersonService;
16
 import com.huiju.welcome.service.ITaVisitingLogService;
16
 import com.huiju.welcome.service.ITaVisitingLogService;
17
+import com.huiju.welcome.utils.DateUtils;
17
 import org.springframework.beans.factory.annotation.Autowired;
18
 import org.springframework.beans.factory.annotation.Autowired;
18
 import org.springframework.stereotype.Service;
19
 import org.springframework.stereotype.Service;
19
 
20
 
63
     @Override
64
     @Override
64
     public ResponseBean getTimeline() {
65
     public ResponseBean getTimeline() {
65
         LocalDateTime now = LocalDateTime.now();
66
         LocalDateTime now = LocalDateTime.now();
67
+        String todayBegin = DateUtils.localDatetime2day(now) + " 00:00:00";
66
 
68
 
67
-        // 四小时内
68
-        LocalDateTime fourHour = now.minusHours(4);
69
         QueryWrapper<TaVisitingLog> query4 = new QueryWrapper<>();
69
         QueryWrapper<TaVisitingLog> query4 = new QueryWrapper<>();
70
-        query4.ge("visite_date", fourHour);
70
+        query4.ge("visite_date", todayBegin);
71
         query4.groupBy("real_person");
71
         query4.groupBy("real_person");
72
         query4.orderByDesc("visite_date");
72
         query4.orderByDesc("visite_date");
73
         List<TaVisitingLog> fourHourList = taVisitingLogMapper.selectList(query4);
73
         List<TaVisitingLog> fourHourList = taVisitingLogMapper.selectList(query4);

+ 1
- 0
src/main/java/com.huiju.welcome/utils/CommConstant.java View File

4
     public final static String IDENTITY_CONSULTANT = "consultant";
4
     public final static String IDENTITY_CONSULTANT = "consultant";
5
     public final static String IDENTITY_FIRSTUSHER = "first-usher";
5
     public final static String IDENTITY_FIRSTUSHER = "first-usher";
6
     public final static String IDENTITY_MAINUSHER = "main-usher";
6
     public final static String IDENTITY_MAINUSHER = "main-usher";
7
+    public final static String IDENTITY_BARUSHER = "bar-usher";
7
 
8
 
8
     public final static String PAGE_MY_CUSTOMER = "pages/client/myclient/myclient";
9
     public final static String PAGE_MY_CUSTOMER = "pages/client/myclient/myclient";
9
 
10
 

+ 128
- 0
src/main/java/com.huiju.welcome/utils/SMSUtils.java View File

1
+package com.huiju.welcome.utils;
2
+
3
+import com.alibaba.fastjson.JSONObject;
4
+import com.huiju.welcome.config.SMSProperties;
5
+import lombok.Data;
6
+import lombok.extern.slf4j.Slf4j;
7
+import org.springframework.beans.factory.annotation.Autowired;
8
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
9
+import org.springframework.context.annotation.Configuration;
10
+import org.springframework.http.*;
11
+import org.springframework.web.client.RestTemplate;
12
+
13
+import java.time.LocalDateTime;
14
+import java.util.*;
15
+
16
+@Slf4j
17
+@Configuration
18
+@EnableConfigurationProperties(SMSProperties.class)
19
+public class SMSUtils {
20
+    // 短信服务配置
21
+    SMSProperties smsProperties;
22
+
23
+    Map<String, Phone> allPhones;
24
+
25
+    @Autowired
26
+    public SMSUtils(SMSProperties properties) {
27
+        smsProperties = properties;
28
+        allPhones = new HashMap<>();
29
+    }
30
+
31
+    /**
32
+     * 发送验证码到 tel
33
+     * @param tel
34
+     * @return
35
+     */
36
+    public boolean sendCaptcha(String tel) {
37
+        Phone phone = allPhones.get(tel);
38
+        if (null == phone) {
39
+            phone = new Phone();
40
+            phone.setTel(tel);
41
+        }
42
+
43
+        phone.setCaptcha(genCaptcha(smsProperties.getCaptcha().getSize()));
44
+        phone.setExpire(LocalDateTime.now().plusSeconds(smsProperties.getCaptcha().getExpire()));
45
+        allPhones.put(tel, phone);
46
+
47
+        log.info("发送手机 {} 验证码 {}", tel, phone.getCaptcha());
48
+
49
+        String[] params = { phone.getCaptcha(), smsProperties.getCaptcha().getSign() };
50
+        return sendMessage(smsProperties.getCaptcha().getCode(), tel, params);
51
+    }
52
+
53
+    /**
54
+     * 校验验证码
55
+     * @param tel
56
+     * @param smsCaptcha
57
+     * @return
58
+     */
59
+    public boolean checkCaptcha(String tel, String smsCaptcha) {
60
+        Phone phone = allPhones.get(tel);
61
+        if (null == phone) {
62
+            log.error("手机号 {} 的验证码未找到", tel);
63
+            return false;
64
+        }
65
+
66
+        if (null == smsCaptcha || !smsCaptcha.equals(phone.getCaptcha())) {
67
+            log.error("手机号 {} 校验验证码出错, 正确: {}, 错误: {}", tel, phone.getCaptcha(), smsCaptcha);
68
+            return false;
69
+        }
70
+
71
+        LocalDateTime now = LocalDateTime.now();
72
+        if (now.isAfter(phone.getExpire())) {
73
+            log.error("手机号 {} 的验证码已过期", tel);
74
+            return false;
75
+        }
76
+
77
+        // 如果验证成功, 则从缓存中删除
78
+        allPhones.remove(tel);
79
+        return true;
80
+    }
81
+
82
+    private String genCaptcha(int length) {
83
+        List<String> nums = new ArrayList<>();
84
+        for (int i = 0; i < length; i ++) {
85
+            int rand = (new Random()).nextInt(10);
86
+            nums.add(String.valueOf(rand));
87
+        }
88
+        return String.join("", nums);
89
+    }
90
+
91
+    private boolean sendMessage(String code, String tel, String[] params) {
92
+        // 发送内容
93
+        SMSProperties.Template message = new SMSProperties.Template();
94
+        message.setCode(code);
95
+        message.setTel(tel);
96
+        message.setParams(params);
97
+
98
+        // 构造 request
99
+        HttpHeaders headers = new HttpHeaders();
100
+        headers.setContentType(MediaType.parseMediaType(smsProperties.getContentType()));
101
+//        String body = JSONObject.toJSONString(message);
102
+        HttpMethod method = HttpMethod.resolve(smsProperties.getMethod());
103
+        HttpEntity requestEntity = new HttpEntity(message, headers);
104
+
105
+        RestTemplate template = new RestTemplate();
106
+        HttpEntity<String> response = template.exchange(
107
+                smsProperties.getUrl(),
108
+                method,
109
+                requestEntity,
110
+                String.class,
111
+                new Object()
112
+        );
113
+
114
+        if (((ResponseEntity<String>) response).getStatusCodeValue() != HttpStatus.OK.value()) {
115
+            log.error("请求发送短信验证码失败: {}", response.toString());
116
+            return false;
117
+        }
118
+
119
+        return true;
120
+    }
121
+
122
+    @Data
123
+    public static class Phone {
124
+        String tel;
125
+        String captcha;
126
+        LocalDateTime expire;
127
+    }
128
+}

+ 24
- 2
src/main/resources/application.yml View File

1
 spring:
1
 spring:
2
   datasource:
2
   datasource:
3
     driver-class-name: com.mysql.cj.jdbc.Driver
3
     driver-class-name: com.mysql.cj.jdbc.Driver
4
-#    url: jdbc:mysql://rm-uf6z3z6jq11x653d77o.mysql.rds.aliyuncs.com:3306/welcome3?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=GMT%2B8
4
+#    url: jdbc:mysql://rm-uf6z3z6jq11x653d77o.mysql.rds.aliyuncs.com:3306/welcome3?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull
5
 #    username: welcome
5
 #    username: welcome
6
 #    password: s190QU2#z%hdU%^FPkY9qjls
6
 #    password: s190QU2#z%hdU%^FPkY9qjls
7
     url: jdbc:mysql://47.101.36.130:3306/welcome3?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull
7
     url: jdbc:mysql://47.101.36.130:3306/welcome3?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull
72
   secretKey: oKhohKlwsSowqa5KM8drpX1FCtLfmhMq
72
   secretKey: oKhohKlwsSowqa5KM8drpX1FCtLfmhMq
73
   iai:
73
   iai:
74
     region: ap-shanghai
74
     region: ap-shanghai
75
-    group: default
75
+    group: default
76
+
77
+# 手机短信服务
78
+sms:
79
+  url: http://micservice.ycjcjy.com/sms
80
+  method: POST
81
+  contentType: "application/json;charset=UTF-8"
82
+  template:
83
+    code:
84
+    tel:
85
+    params:
86
+
87
+  # 以下为各模板 code
88
+  # 验证码
89
+  captcha:
90
+    # 模板 code
91
+    code: "0301"
92
+    # 有效时间 秒
93
+    expire: 120
94
+    # 验证码长度
95
+    size: 4
96
+    # 短信签名
97
+    sign: AI智慧案场

+ 1
- 1
src/main/resources/mapper/TaCustomerMapper.xml View File

64
             *
64
             *
65
         FROM
65
         FROM
66
             ta_customer t
66
             ta_customer t
67
-        WHERE t.status = 1
67
+        WHERE t.status &gt; 0
68
             <if test="consultantId !=null">
68
             <if test="consultantId !=null">
69
               AND t.consultant_id = #{consultantId}
69
               AND t.consultant_id = #{consultantId}
70
             </if>
70
             </if>