zhoutg 6 years ago
parent
commit
3bac438616

+ 5 - 5
user-service/src/main/java/com/diagbot/exception/ServiceErrorCode.java

@@ -8,17 +8,17 @@ package com.diagbot.exception;
  * @time: 2018/9/10 11:11
  */
 public enum ServiceErrorCode implements ErrorCode {
-    USER_NOT_FOUND("10020000","用户不存在"),
-    USER_PASSWORD_ERROR("10020001","密码错误"),
-    GET_TOKEN_FAIL("10020002","获取token失败"),
-    TOKEN_IS_NOT_MATCH_USER("10020003","请使用自己的token进行接口请求"),
+    USER_NOT_FOUND("10020000","该手机号暂未注册!"),
+    USER_PASSWORD_ERROR("10020001","手机号或密码不正确!"),
+    GET_TOKEN_FAIL("10020002","获取token失败"),
+    TOKEN_IS_NOT_MATCH_USER("10020003","请使用自己的token进行接口请求"),
 
     SMS_SEND_ERROR("10020004", "短信发送错误!"),
     USER_BIND_ERROR("10020005", "用户手机号已经绑定无需再次验证!"),
     USER_UN_BIND_ERROR("10020006", "用户手机号未绑定无需解绑!"),
     VERIFYCODE_ERROR("10020007", "图片验证码生成错误!"),
     USER_EXIST("10020008", "该手机已注册!"),
-    EMAIL_IS_NULL("10020009","请输入邮箱");
+    EMAIL_IS_NULL("10020009","请输入邮箱");
 
     private String code;
     private String msg;

+ 5 - 3
user-service/src/main/java/com/diagbot/facade/UserFacade.java

@@ -31,6 +31,8 @@ import java.util.Date;
 @Component
 public class UserFacade extends UserServiceImpl {
 
+    private static final String CACHE_NAME = "UserInfo";
+
     @Autowired
     AuthServiceClient authServiceClient;
     @Autowired
@@ -55,8 +57,8 @@ public class UserFacade extends UserServiceImpl {
         return  user;
     }
 
-    @Cacheable(value = "UserName", key = "'username:'+#p0")
-    public User getUserInfo(String username){
+    //@Cacheable(value = "UserName", key = "'username:'+#p0")
+    public User  getUserInfo(String username){
         return this.findByName(username);
     }
 
@@ -81,7 +83,7 @@ public class UserFacade extends UserServiceImpl {
         return RespDTO.onSuc(loginDTO);
     }
 
-    private static final String CACHE_NAME = "UserInfo";
+
 
     //缓存演示
     @CachePut(value = CACHE_NAME, key = "'user:'+#p0['id']")

+ 47 - 0
user-service/src/main/java/com/diagbot/facade/VerFacade.java

@@ -123,6 +123,53 @@ public class VerFacade {
         return smsVerService.createSmsVerification(swsVerInfo);
     }
 
+
+
+    /**
+     * 忘记密码获取短信验证码
+     * @param smsVerCreatVO 获取短信验证码输入参数
+     * @return 获取短信验证码是否成功
+     */
+    public Boolean getSmsWithResetPassword(SmsVerCreatVO smsVerCreatVO){
+        //参数验证
+        if (null == smsVerCreatVO){
+            throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
+                    "短信验证码创建信息不能为空!");
+        }
+        if (StringUtil.isBlank(smsVerCreatVO.getMobile())){
+            throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
+                    "用户电话不能为空!");
+        }
+        if (!RegexValidateUtil.checkMobileNumber(smsVerCreatVO.getMobile())){
+            throw new CommonException(CommonErrorCode.PARAM_IS_ERROR,
+                    "请输入正确的手机号!");
+        }
+        User bean = userFacade.getUserInfo(smsVerCreatVO.getMobile());
+        if (bean == null){
+            throw new CommonException(CommonErrorCode.PARAM_IS_ERROR, "手机号未注册!");
+        }
+
+        //验证是否超过三分钟
+        SwsVerInfo swsVerInfoCheck = smsVerService.getSmsVerification(smsVerCreatVO.getMobile());
+        if (null != swsVerInfoCheck){
+            if (DateUtil.after(DateUtil.addMinutes(swsVerInfoCheck.getCreateTime(), 3),
+                    DateUtil.now())){
+                throw new CommonException(ServiceErrorCode.SMS_SEND_ERROR,
+                        "同一用户三分钟之内不能重复发送验证短信,请三分钟之后再次发送!");
+            }
+        }
+
+        //发送短信
+        String smsTemplateCode = "SMS_143861902";
+        String code = smsVerService.smsSend(smsVerCreatVO.getMobile(), smsTemplateCode);
+
+        //创建用户短信验证信息,缓存到redis
+        SwsVerInfo swsVerInfo = new SwsVerInfo();
+        swsVerInfo.setMobile(smsVerCreatVO.getMobile());
+        swsVerInfo.setCode(code);
+        return smsVerService.createSmsVerification(swsVerInfo);
+    }
+
     /**
      * 验证短信码
      * @param smsVerVerVO 短信验证码验证输入信息

+ 2 - 7
user-service/src/main/java/com/diagbot/vo/ImgVerVerVO.java

@@ -3,10 +3,6 @@ package com.diagbot.vo;
 import lombok.Getter;
 import lombok.Setter;
 
-import javax.validation.constraints.NotBlank;
-import javax.validation.constraints.NotNull;
-import java.util.Date;
-
 /**
  * @Description: 图片验证码验证输入信息
  * @author: gaodm
@@ -14,11 +10,10 @@ import java.util.Date;
  */
 @Getter
 @Setter
-public class ImgVerVerVO {
+public class
+ImgVerVerVO {
     //图片验证码唯一标志
-    @NotBlank(message = "图片验证码唯一标志不能为空!")
     private String imgId;
     //验证码
-    @NotBlank(message = "验证码不能为空!")
     private String code;
 }

+ 2 - 0
user-service/src/main/java/com/diagbot/vo/UserSaveVO.java

@@ -20,11 +20,13 @@ public class UserSaveVO {
     private Date gmtModified;
     private String creator;
     private String modifier;
+    @NotBlank(message = "请输入密码!")
     private String password;
     @NotBlank(message = "请输入手机号!")
     private String username;
     @NotBlank(message = "请输入机构名称!")
     private String organization;
+    @NotBlank(message = "请输入联系人姓名!")
     private String linkman;
     @NotBlank(message = "请输入邮箱!")
     private String email; //邮箱

+ 9 - 9
user-service/src/main/java/com/diagbot/web/UserController.java

@@ -10,12 +10,12 @@ import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
+import springfox.documentation.annotations.ApiIgnore;
 
 import java.util.Map;
 
@@ -31,7 +31,7 @@ public class UserController {
     @Autowired
     private UserFacade userFacade;
 
-    @ApiOperation(value = "注册", notes = "username和password为必选项")
+    @ApiOperation(value = "注册", notes = "username|password|organization|email|linkman|imgId|code为必填项")
     @PostMapping("/registry")
     @SysLogger("registry")
     @Transactional
@@ -40,19 +40,18 @@ public class UserController {
         return RespDTO.onSuc(user);
     }
 
-    @ApiOperation(value = "登录", notes = "usernamepassword为必选项")
+    @ApiOperation(value = "登录", notes = "username|password为必选项")
     @PostMapping("/login")
     @SysLogger("login")
-    public RespDTO login(@RequestParam String username , @RequestParam String password){
-        //参数判读省略
-      return   userFacade.login(username,password);
+    public RespDTO login(@RequestParam String username, @RequestParam String password){
+        return  userFacade.login(username, password);
     }
 
     @ApiOperation(value = "根据用户名获取用户", notes = "根据用户名获取用户")
-    @PostMapping("/{username}")
-    @SysLogger("getUserInfo")
+    @PostMapping("/getByUsername")
+    @SysLogger("getByUsername")
 //    @PreAuthorize("hasAnyAuthority('ROLE_USER')")
-    public RespDTO getUserInfo(@PathVariable("username") String username){
+    public RespDTO getUserInfo(@RequestParam String username){
         //参数判读省略
         User user=  userFacade.getUserInfo(username);
         return RespDTO.onSuc(user);
@@ -128,6 +127,7 @@ public class UserController {
     @GetMapping("/getUser")
     @SysLogger("getUser")
     @Transactional
+    @ApiIgnore
     public RespDTO getUser(Long id){
         return RespDTO.onSuc(userFacade.getById(id));
     }

+ 20 - 7
user-service/src/main/java/com/diagbot/web/VerController.java

@@ -47,23 +47,23 @@ public class VerController {
     @PostMapping("/verifyImgVerification")
     @SysLogger("verifyImgVerification")
     public RespDTO verImgVerification(@RequestBody @Valid ImgVerVerVO imgVerVerVO){
-        return   RespDTO.onSuc(verFacade.verifyImgVerification(imgVerVerVO));
+        return  RespDTO.onSuc(verFacade.verifyImgVerification(imgVerVerVO));
     }
 
     /**
-     * 获取短信验证码
+     * 注册获取短信验证码
      * @param smsVerCreatVO 获取短信验证码输入参数
      * @return 获取短信验证码是否成功
      */
-    @ApiOperation(value = "获取短信验证码", notes = "图片验证码唯一标志后,图形验证码,用户号码不能为空")
-    @PostMapping("/getSmsVerification")
-    @SysLogger("getSmsVerification")
-    public RespDTO getSmsVerification(@RequestBody @Valid SmsVerCreatVO smsVerCreatVO){
+    @ApiOperation(value = "注册获取短信验证码", notes = "图片验证码唯一标志后,图形验证码,用户号码不能为空")
+    @PostMapping("/getSmsWithRegister")
+    @SysLogger("getSmsWithRegister")
+    public RespDTO getSmsWithRegister(@RequestBody @Valid SmsVerCreatVO smsVerCreatVO){
         return   RespDTO.onSuc(verFacade.getSmsVerification(smsVerCreatVO));
     }
 
     /**
-     * 验证短信码并且注册为新的用户
+     * 验证注册短信码并且注册为新的用户
      * @param smsVerVerVO 短信验证码验证输入信息
      * @return 用户信息是否注册到数据库
      */
@@ -73,4 +73,17 @@ public class VerController {
     public RespDTO verifySmsVerification(@RequestBody SmsVerVerVO smsVerVerVO){
         return RespDTO.onSuc(verFacade.verifySmsVerification(smsVerVerVO));
     }
+
+
+    /**
+     * 忘记密码获取短信验证码
+     * @param smsVerCreatVO 获取短信验证码输入参数
+     * @return 获取短信验证码是否成功
+     */
+    @ApiOperation(value = "忘记密码获取短信验证码", notes = "用户号码不能为空")
+    @PostMapping("/getSmsWithResetPassword")
+    @SysLogger("getSmsWithResetPassword")
+    public RespDTO getSmsWithResetPassword(@RequestBody @Valid SmsVerCreatVO smsVerCreatVO){
+        return   RespDTO.onSuc(verFacade.getSmsWithResetPassword(smsVerCreatVO));
+    }
 }

+ 3 - 0
user-service/src/main/resources/mapper/UserMapper.xml

@@ -12,6 +12,9 @@
         <result column="modifier" property="modifier" />
         <result column="password" property="password" />
         <result column="username" property="username" />
+        <result column="linkman" property="linkman" />
+        <result column="organization" property="organization" />
+        <result column="email" property="email" />
     </resultMap>
 
     <select id="findByName" resultMap="BaseResultMap" parameterType="java.lang.String">