Browse Source

fix: APP登录、注册、添加就诊人验证短信验证码拆成一个单独的接口

matianxiang 3 months ago
parent
commit
5424370573

+ 7 - 0
eitc-patient-app/src/main/java/com/eitc/patient/controller/AppLoginController.java

@@ -94,6 +94,13 @@ public class AppLoginController extends BaseController {
94 94
         return appUserService.sendCaptchaCode(phoneNumber);
95 95
     }
96 96
 
97
+    @PostMapping("/checkCaptchaCode")
98
+    @ApiOperation("验证短信验证码")
99
+    public AjaxResult checkCaptchaCode(String phoneNumber, String captchaCode) {
100
+        appUserService.checkCaptchaCode(phoneNumber, captchaCode);
101
+        return success();
102
+    }
103
+
97 104
     /**
98 105
      * 退出登录
99 106
      *

+ 2 - 2
eitc-patient-base/src/main/java/com/eitc/patient/domain/NoticeManage.java

@@ -37,13 +37,13 @@ public class NoticeManage extends EitcBaseEntity {
37 37
 
38 38
     @TableField(value = "notice_start_time")
39 39
     @ApiModelProperty(value = "公告开始时间", name = "noticeStartTime")
40
-    @JsonFormat(pattern = "yyyy-MM-dd HH:mm")
40
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
41 41
     @NotNull(message = "公告开始时间不能为空")
42 42
     private Date noticeStartTime;
43 43
 
44 44
     @TableField(value = "notice_end_time")
45 45
     @ApiModelProperty(value = "公告结束时间", name = "noticeEndTime")
46
-    @JsonFormat(pattern = "yyyy-MM-dd HH:mm")
46
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
47 47
     @NotNull(message = "公告结束时间不能为空")
48 48
     private Date noticeEndTime;
49 49
 

+ 7 - 2
eitc-patient-base/src/main/java/com/eitc/patient/mapper/AppUserMapper.java

@@ -15,8 +15,13 @@ import org.apache.ibatis.annotations.Update;
15 15
 @Mapper
16 16
 public interface AppUserMapper extends BaseMapper<AppUser> {
17 17
 
18
-
19
-
18
+    /**
19
+     * 回复删除数据
20
+     *
21
+     * @param id id
22
+     * @author mtx
23
+     * @date: 2024/6/13 10:33
24
+     */
20 25
     int updateRevert(@Param("id") String id);
21 26
 
22 27
 }

+ 8 - 0
eitc-patient-base/src/main/java/com/eitc/patient/service/IAppUserService.java

@@ -107,6 +107,14 @@ public interface IAppUserService extends IService<AppUser> {
107 107
     AjaxResult synchronizeData(AppUser beforeAppUser);
108 108
 
109 109
     /**
110
+     * 验证短信验证码时候正确
111
+     *
112
+     * @param phoneNumber 手机号
113
+     * @param captchaCode 录入的验证码
114
+     */
115
+    void checkCaptchaCode(String phoneNumber, String captchaCode);
116
+
117
+    /**
110 118
      * 退出登录
111 119
      */
112 120
     void logout();

+ 16 - 36
eitc-patient-base/src/main/java/com/eitc/patient/service/impl/AppUserServiceImpl.java

@@ -10,7 +10,6 @@ import com.eitc.common.core.redis.RedisCache;
10 10
 import com.eitc.common.utils.JWTUtil;
11 11
 import com.eitc.common.utils.PatientBaseUtil;
12 12
 import com.eitc.common.utils.SecurityUtils;
13
-import com.eitc.system.utils.SendSmsUtil;
14 13
 import com.eitc.patient.constant.PatientConstant;
15 14
 import com.eitc.patient.domain.AppUser;
16 15
 import com.eitc.patient.domain.AppUserPatients;
@@ -158,11 +157,6 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
158 157
                 throw new RuntimeException("用户不存在或密码错误");
159 158
             }
160 159
         } else if (String.valueOf(AppUserLoginTypeEnum.CAPTCHA.getCode()).equals(loginType)) {
161
-            // 手机验证码登录
162
-            String captchaCode = map.get("captchaCode");
163
-            if (checkCaptchaCode(phoneNumber, captchaCode)) {
164
-                throw new RuntimeException("验证码错误");
165
-            }
166 160
             AppUser user = getAppUserByPhoneNumber(phoneNumber);
167 161
             if (Objects.isNull(user)) {
168 162
                 throw new RuntimeException(phoneNumber + "用户不存在");
@@ -204,11 +198,6 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
204 198
                 throw new RuntimeException(phoneNumber + "用户不存在或密码错误");
205 199
             }
206 200
         } else if (String.valueOf(AppUserLoginTypeEnum.CAPTCHA.getCode()).equals(loginType)) {
207
-            // 手机验证码登录
208
-            String captchaCode = map.get("captchaCode");
209
-            if (checkCaptchaCode(phoneNumber, captchaCode)) {
210
-                throw new RuntimeException("验证码错误");
211
-            }
212 201
             SysUser sysUser = getPCUserByPhoneNumber(phoneNumber);
213 202
             if (Objects.isNull(sysUser)) {
214 203
                 throw new RuntimeException(phoneNumber + "用户不存在");
@@ -237,8 +226,6 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
237 226
         //生成JWt的令牌
238 227
         String token = JWTUtil.getToken(payload, secretKey);
239 228
         payload.put("token", token);
240
-        // 删除验证码
241
-        delCaptchaCode(appUser.getPhoneNumber());
242 229
         return payload;
243 230
     }
244 231
 
@@ -253,13 +240,10 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
253 240
         Map<String, String> payload = new HashMap<>();
254 241
         payload.put("id", userId);
255 242
         payload.put("phoneNumber", user.getPhonenumber());
256
-
257 243
         String secretKey = PatientBaseUtil.getSecretKey(userId);
258 244
         //生成JWt的令牌
259 245
         String token = JWTUtil.getToken(payload, secretKey);
260 246
         payload.put("token", token);
261
-        // 删除验证码
262
-        delCaptchaCode(user.getPhonenumber());
263 247
         return payload;
264 248
     }
265 249
 
@@ -325,9 +309,6 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
325 309
         if (Objects.isNull(appUser)) {
326 310
             return AjaxResult.error("用户不存在");
327 311
         }
328
-        if (checkCaptchaCode(phoneNumber, captchaCode)) {
329
-            return AjaxResult.error("验证码错误");
330
-        }
331 312
         if (!password.equals(confirmPassword)) {
332 313
             return AjaxResult.error("两次密码不一致");
333 314
         }
@@ -337,8 +318,6 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
337 318
                 .eq(AppUser::getId, appUser.getId())
338 319
                 .set(AppUser::getPassword, SecurityUtils.encryptPassword(password)));
339 320
 
340
-        // 删除验证码
341
-        delCaptchaCode(phoneNumber);
342 321
         return AjaxResult.success();
343 322
     }
344 323
 
@@ -366,9 +345,6 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
366 345
         if (StringUtils.isEmpty(captchaCode)) {
367 346
             return AjaxResult.error("验证码不能为空");
368 347
         }
369
-        if (checkCaptchaCode(phoneNumber, captchaCode)) {
370
-            return AjaxResult.error("验证码错误");
371
-        }
372 348
         // 注册过的手机号不允许绑定
373 349
         if (appUserService.count(Wrappers.<AppUser>lambdaQuery().eq(AppUser::getPhoneNumber, phoneNumber)) > 0) {
374 350
             return AjaxResult.error("您所设置的手机号已绑定");
@@ -390,8 +366,6 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
390 366
                 .eq(AppUser::getId, JWTUtil.getAppUserId())
391 367
                 .set(AppUser::getPhoneNumber, phoneNumber));
392 368
 
393
-        // 删除验证码
394
-        delCaptchaCode(phoneNumber);
395 369
         return AjaxResult.success();
396 370
     }
397 371
 
@@ -583,16 +557,10 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
583 557
     @Override
584 558
     public boolean register(Map<String, String> map) {
585 559
         String phoneNumber = map.get("phoneNumber");
586
-        if (checkCaptchaCode(phoneNumber, map.get("captchaCode"))) {
587
-            throw new IllegalArgumentException("验证码错误");
588
-        }
589 560
         if (Objects.nonNull(getAppUserByPhoneNumber(phoneNumber))) {
590 561
             throw new IllegalArgumentException("手机号已注册");
591 562
         }
592 563
 
593
-        // 删除验证码
594
-        delCaptchaCode(phoneNumber);
595
-
596 564
         // 添加用户
597 565
         AppUser appUser = new AppUser();
598 566
         appUser.setPhoneNumber(phoneNumber);
@@ -673,15 +641,27 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
673 641
      *
674 642
      * @param phoneNumber 手机号
675 643
      * @param captchaCode 录入的验证码
676
-     * @return 是否相同 已经取反
677 644
      */
678
-    public boolean checkCaptchaCode(String phoneNumber, String captchaCode) {
645
+    @Override
646
+    public void checkCaptchaCode(String phoneNumber, String captchaCode) {
647
+        if (StringUtils.isEmpty(phoneNumber)) {
648
+            throw new IllegalArgumentException("手机号不能为空");
649
+        }
650
+        if (StringUtils.isEmpty(captchaCode)) {
651
+            throw new IllegalArgumentException("验证码不能为空");
652
+        }
653
+
679 654
         String key = PatientConstant.ERM_APP_CAPTCHA_CODE + phoneNumber;
680 655
         if (redisCache.hasKey(key)) {
681 656
             int code = redisCache.getCacheObject(key);
682
-            return !String.valueOf(code).equals(captchaCode);
657
+            boolean b = String.valueOf(code).equals(captchaCode);
658
+            if (b) {
659
+                // 删除验证码
660
+                delCaptchaCode(phoneNumber);
661
+                return;
662
+            }
683 663
         }
684
-        return true;
664
+        throw new IllegalArgumentException("验证码错误");
685 665
     }
686 666
 
687 667
     /**

+ 3 - 2
eitc-patient-pc/src/main/java/com/eitc/patient/controller/NoticeManageController.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
5 5
 import com.eitc.common.annotation.Log;
6 6
 import com.eitc.common.core.controller.BaseController;
7 7
 import com.eitc.common.core.domain.AjaxResult;
8
+import com.eitc.common.core.page.TableDataInfo;
8 9
 import com.eitc.common.enums.BusinessType;
9 10
 import com.eitc.common.utils.StringUtils;
10 11
 import com.eitc.patient.domain.NoticeManage;
@@ -44,14 +45,14 @@ public class NoticeManageController extends BaseController {
44 45
      */
45 46
     @GetMapping("/list")
46 47
     @ApiOperation("查询公告管理")
47
-    public AjaxResult list(NoticeManage noticeManage) {
48
+    public TableDataInfo list(NoticeManage noticeManage) {
48 49
         startPage();
49 50
         LambdaQueryWrapper<NoticeManage> wrapper = Wrappers.<NoticeManage>lambdaQuery().orderByDesc(NoticeManage::getCreateDate)
50 51
                 .like(StringUtils.isNotBlank(noticeManage.getNoticeTitle()), NoticeManage::getNoticeTitle, noticeManage.getNoticeTitle())
51 52
                 .like(Objects.nonNull(noticeManage.getPublishStatus()), NoticeManage::getPublishStatus, noticeManage.getPublishStatus())
52 53
                 .like(Objects.nonNull(noticeManage.getDisplayStatus()), NoticeManage::getDisplayStatus, noticeManage.getDisplayStatus());
53 54
         List<NoticeManage> list = noticeManageService.list(wrapper);
54
-        return success(list);
55
+        return getDataTable(list);
55 56
     }
56 57
 
57 58
     /**