xiaochan 1 anno fa
parent
commit
234b420489

+ 14 - 0
src/main/java/thyyxxk/webserver/controller/LoginController.java

@@ -9,6 +9,7 @@ import thyyxxk.webserver.entity.dictionary.CodeName;
 import thyyxxk.webserver.entity.login.UserInfo;
 import thyyxxk.webserver.service.LoginService;
 
+import javax.print.DocFlavor;
 import java.util.List;
 import java.util.Map;
 
@@ -48,4 +49,17 @@ public class LoginController {
     }
 
 
+    @GetMapping("/sendAVerificationCode")
+    @PassToken
+    public ResultVo<String> sendAVerificationCode(@RequestParam("codeRs") String codeRs) {
+        return service.sendAVerificationCode(codeRs);
+    }
+
+    @GetMapping("/checkVerificationCode")
+    @PassToken
+    public ResultVo<String> checkVerificationCode(@RequestParam("codeRs") String codeRs,
+                                                  @RequestParam("verificationCode") String verificationCode) {
+        return service.checkVerificationCode(codeRs, verificationCode);
+    }
+
 }

+ 16 - 5
src/main/java/thyyxxk/webserver/dao/his/LoginDao.java

@@ -13,7 +13,7 @@ public interface LoginDao {
     @Select("select a.code, rtrim(b.name) name, a.password, a.code_rs, " +
             "b.dept_code as dept_code," +
             "rtrim(b.yb_code) as yb_code," +
-            "emp_tit_code, input_err_frequency , next_input_times " +
+            "emp_tit_code " +
             "from dj_user_base a " +
             "         left join a_employee_mi b on (a.code = b.code)  " +
             "where a.code_rs=#{codeRs} and a.del_flag=0")
@@ -91,14 +91,25 @@ public interface LoginDao {
             "  and isnull(a.del_flag, '0') = '0'")
     UserInfo getUserInfoByCode(String code);
 
-    @Select("select top 1 input_err_frequency from dj_user_base where code_rs = '${codeRs}'")
-    Integer selectInputErrFrequency(String codeRs);
 
     @Select("select frequency from t_questionnaire_frequency where code='login_over_limit_waiting' ")
     Integer selectLockTime();
 
-    @Update("update dj_user_base set  input_err_frequency = ${times} , next_input_times = #{date} where code_rs = '${codeRs}' ")
-    void addInputErrFrequency(String codeRs, Integer times, Date date);
+    @Update("update dj_user_base set " +
+            "   verification_code = #{verificationCode}, " +
+            "   verification_time = #{verificationTime} " +
+            "       where code_rs = #{codeRs}")
+    void updateVerificationCodeByCodeRs(String codeRs, String verificationCode, Date verificationTime);
 
 
+    @Select("select count(1) from dj_user_base " +
+            "where code_rs = #{codeRs} " +
+            "   and verification_time >= getdate() " +
+            "   and verification_code = #{verificationCode} ")
+    int checkVerificationCode(String codeRs, String verificationCode);
+
+    @Update("update dj_user_base set password = 'e10adc3949ba59abbe56e057f20f883e' ,verification_code = null , verification_time = null" +
+            " where code_rs = #{codeRs}")
+    int updatePasswordByCodeRs(String codeRs);
+
 }

+ 1 - 2
src/main/java/thyyxxk/webserver/entity/login/UserInfo.java

@@ -151,8 +151,7 @@ public class UserInfo {
     private String partTimeDeptName;
     private Map<String, String> partTimeDeptMap;
 
-    private Integer inputErrFrequency;
-    private Date nextInputTimes;
+    private String verificationCode;
 
     /**
      * 当前科室的人可以在会诊完成几天后,可以去到患者的医嘱录入界面

+ 22 - 1
src/main/java/thyyxxk/webserver/service/LoginService.java

@@ -14,6 +14,7 @@ import thyyxxk.webserver.entity.dictionary.CodeName;
 import thyyxxk.webserver.entity.login.UserInfo;
 import thyyxxk.webserver.entity.login.VueMenu;
 import thyyxxk.webserver.service.externalhttp.CorpWxSrvc;
+import thyyxxk.webserver.service.outpatient.wxapi.SendWxInfoService;
 import thyyxxk.webserver.service.redislike.RedisLikeService;
 import thyyxxk.webserver.utils.*;
 
@@ -31,16 +32,18 @@ public class LoginService {
     private final RedisLikeService redisLikeService;
     private final CorpWxSrvc srvc;
     private final PublicServer publicServer;
+    private final SendWxInfoService sendWxInfoService;
 
     @Autowired
     public LoginService(LoginDao dao, TokenService tokenService,
                         RedisLikeService redisLikeService,
-                        CorpWxSrvc srvc, PublicServer publicServer) {
+                        CorpWxSrvc srvc, PublicServer publicServer, SendWxInfoService sendWxInfoService) {
         this.dao = dao;
         this.tokenService = tokenService;
         this.redisLikeService = redisLikeService;
         this.srvc = srvc;
         this.publicServer = publicServer;
+        this.sendWxInfoService = sendWxInfoService;
     }
 
     public ResultVo<UserInfo> login(UserInfo userInfo) {
@@ -81,6 +84,24 @@ public class LoginService {
         return ResultVoUtil.success(tempUserInfo);
     }
 
+    public ResultVo<String> sendAVerificationCode(String codeRs) {
+        SendWxInfoService.Verification v = sendWxInfoService.sendResetPassword(codeRs);
+        if (v.getVerificationCode() != null) {
+            dao.updateVerificationCodeByCodeRs(codeRs, v.getVerificationCode(), DateUtil.offsetHour(new Date(), 30));
+            return ResultVoUtil.success("验证码已发送。");
+        }
+        return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR, v.getError());
+    }
+
+    public ResultVo<String> checkVerificationCode(String codeRs, String verificationCode) {
+        int count = dao.checkVerificationCode(codeRs, verificationCode);
+        if (count > 0) {
+            dao.updatePasswordByCodeRs(codeRs);
+            return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "密码已重置,默认密码为123456");
+        }
+        return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "验证码过期或者验证码错误。");
+    }
+
     public ResultVo<JSONObject> simpleLogin(String code) {
         UserInfo us = dao.getUserInfoByCode(code);
         if (us == null) {

+ 56 - 2
src/main/java/thyyxxk/webserver/service/outpatient/wxapi/SendWxInfoService.java

@@ -1,8 +1,11 @@
 package thyyxxk.webserver.service.outpatient.wxapi;
 
+import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
+import org.jetbrains.annotations.NotNull;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.web.client.RestTemplate;
@@ -11,6 +14,9 @@ import thyyxxk.webserver.utils.SnowFlakeId;
 import thyyxxk.webserver.utils.TokenUtil;
 import thyyxxk.webserver.utils.WeComUtil;
 
+import javax.annotation.PostConstruct;
+import java.util.concurrent.ThreadLocalRandom;
+
 @Service
 @Slf4j
 public class SendWxInfoService {
@@ -28,7 +34,7 @@ public class SendWxInfoService {
     }
 
     public JSONObject sendCorpWxMsg(String touser, String content) {
-        String requestUrl= SEND_MSG_URL.replace("ACCESS_TOKEN", tokenService.getWeComSendMsgToken());
+        String requestUrl = SEND_MSG_URL.replace("ACCESS_TOKEN", tokenService.getWeComSendMsgToken());
         JSONObject msgObj = new JSONObject();
         msgObj.put("content", content);
         JSONObject param = new JSONObject();
@@ -46,8 +52,56 @@ public class SendWxInfoService {
         return result;
     }
 
+    public static @NotNull String generateRandomNumber(int length) {
+        StringBuilder sb = new StringBuilder(length);
+        ThreadLocalRandom random = ThreadLocalRandom.current();
+        for (int i = 0; i < length; i++) {
+            sb.append(random.nextInt(0, 10));  // 生成0到9之间的随机数字
+        }
+        return sb.toString();
+    }
+
+    public static @NotNull String generateRandomNumber() {
+        return generateRandomNumber(6);
+    }
+
+    @Data
+    public static class Verification {
+        private String verificationCode;
+        private String error;
+    }
+
+    public Verification sendResetPassword(String touser) {
+        String requestUrl = SEND_MSG_URL.replace("ACCESS_TOKEN", tokenService.getWeComSendMsgToken());
+        String verificationCode = generateRandomNumber();
+        JSONObject msgObj = new JSONObject() {{
+            put("content", StrUtil.format("重置密码\n您的验证码为:【{}】\n30分钟有效", verificationCode));
+        }};
+        JSONObject param = new JSONObject() {{
+            put("touser", touser);
+            put("msgtype", "text");
+            put("agentid", AGENT_ID);
+            put("safe", 0);
+            put("text", msgObj);
+        }};
+
+        RestTemplate restTemplate = new RestTemplate();
+        String response = restTemplate.postForObject(requestUrl, param, String.class);
+        JSONObject result = JSONObject.parseObject(response);
+        log.info("推送企业信息消息:\n内容:{}\n结果:{}", param, result);
+        Integer errcode = result.getInteger("errcode");
+        int a = null == errcode ? -1 : errcode;
+
+        Verification v = new Verification();
+        v.setVerificationCode(a == 0 ? verificationCode : null);
+        v.setError(result.getString("errmsg"));
+        return v;
+
+    }
+
+
     public int sendCriticalValue(String touser, String content) {
-        String requestUrl= SEND_MSG_URL.replace("ACCESS_TOKEN", tokenService.getWeComSendMsgToken());
+        String requestUrl = SEND_MSG_URL.replace("ACCESS_TOKEN", tokenService.getWeComSendMsgToken());
         JSONObject msgObj = new JSONObject();
         msgObj.put("content", content);
         JSONObject param = new JSONObject();