From 698ae84adaf1b8d0e8dd61d7279863fe17c1e81d Mon Sep 17 00:00:00 2001
From: luodangjia <luodangjia>
Date: 星期四, 23 一月 2025 14:20:39 +0800
Subject: [PATCH] 1

---
 ruoyi-modules/ruoyi-company/src/main/java/com/ruoyi/company/controller/front/UserController.java |   40 ++++++++++++++++++++++++++++++++--------
 1 files changed, 32 insertions(+), 8 deletions(-)

diff --git a/ruoyi-modules/ruoyi-company/src/main/java/com/ruoyi/company/controller/front/UserController.java b/ruoyi-modules/ruoyi-company/src/main/java/com/ruoyi/company/controller/front/UserController.java
index 22df23c..4f998cf 100644
--- a/ruoyi-modules/ruoyi-company/src/main/java/com/ruoyi/company/controller/front/UserController.java
+++ b/ruoyi-modules/ruoyi-company/src/main/java/com/ruoyi/company/controller/front/UserController.java
@@ -9,6 +9,7 @@
 import com.ruoyi.common.redis.service.RedisService;
 import com.ruoyi.common.security.annotation.InnerAuth;
 import com.ruoyi.common.security.utils.SecurityUtils;
+import com.ruoyi.company.api.domain.Company;
 import com.ruoyi.company.api.domain.User;
 import com.ruoyi.company.api.domain.dto.MgtCompanyDTO;
 import com.ruoyi.company.api.model.RegisterUser;
@@ -35,7 +36,6 @@
     private final CompanyService companyService;
     private final RedisService redisService;
 
-
     @PostMapping("/register")
     public R register(@RequestBody MgtCompanyDTO mgtCompanyDTO) {
         companyService.saveCompany(mgtCompanyDTO);
@@ -47,8 +47,12 @@
     public R<UserDetail> getUserDetail() {
         AppUser appLoginUser = SecurityUtils.getAppLoginUser();
         User user = userService.getById(appLoginUser.getUserId());
+        Company company = companyService.getOne(new LambdaQueryWrapper<Company>()
+                .eq(Company::getUserId, user.getUserId()));
         UserDetail userDetail = new UserDetail();
         BeanUtils.copyProperties(user, userDetail);
+        BeanUtils.copyProperties(company, userDetail);
+        userDetail.setRegisterTime(user.getCreateTime());
         return R.ok(userDetail);
     }
 
@@ -80,7 +84,9 @@
     @PutMapping("/updateUserDetail")
     @Operation(summary = "编辑联系人信息",tags = {"企业端"})
     public R<Void> updateUserDetail(@RequestBody UserDetail userDetail) {
-        User user = userService.getById(userDetail.getUserId());
+        AppUser appLoginUser = SecurityUtils.getAppLoginUser();
+        userDetail.setUserId(appLoginUser.getUserId());
+        User user = userService.getById(appLoginUser.getUserId());
         BeanUtils.copyProperties(userDetail, user);
         userService.updateById(user);
         return R.ok();
@@ -97,18 +103,25 @@
         if (!user.getPhone().equals(updatePhone.getOldPhone())) {
             return R.fail("旧手机号错误");
         }
-        String verifyKey = CacheConstants.PHONE_CODE_KEY + StringUtils.nvl(user.getPhone(), "");
+        String verifyKey = CacheConstants.PHONE_CODE_KEY + StringUtils.nvl(updatePhone.getNewPhone(), "");
         String captcha = redisService.getCacheObject(verifyKey);
         if (captcha == null) {
+            throw new CaptchaException("验证码错误");
+        }
+        String[] split = captcha.split(":");
+
+        long l = Long.parseLong(split[1]);
+        long l1 = System.currentTimeMillis();
+        // 判断是否大于两分钟
+        if (l1 - l > 2 * 60 * 1000) {
             throw new CaptchaException("验证码已失效");
         }
-        redisService.deleteObject(verifyKey);
+        captcha = split[0];
         if (!updatePhone.getCode().equalsIgnoreCase(captcha)) {
             throw new CaptchaException("验证码错误");
         }
 
-        String password = SecurityUtils.encryptPassword(updatePhone.getPassword());
-        if (!user.getPassword().equals(password)) {
+        if (!SecurityUtils.matchesPassword(updatePhone.getPassword(), user.getPassword())) {
             return R.fail("密码错误");
         }
         user.setPhone(updatePhone.getNewPhone());
@@ -124,8 +137,7 @@
     public R<Void> updatePassword(@RequestBody UpdatePassword updatePassword) {
         AppUser appLoginUser = SecurityUtils.getAppLoginUser();
         User user = userService.getById(appLoginUser.getUserId());
-        String oldPassword = SecurityUtils.encryptPassword(updatePassword.getOldPassword());
-        if (!user.getPassword().equals(oldPassword)) {
+        if (!SecurityUtils.matchesPassword(updatePassword.getOldPassword(), user.getPassword())) {
             return R.fail("旧密码错误");
         }
         if (!updatePassword.getNewPassword().equals(updatePassword.getConfirmPassword())){
@@ -135,4 +147,16 @@
         userService.updateById(user);
         return R.ok();
     }
+
+    /**
+     * 通过公司名称和法人身份证号码查询用户信息
+     */
+    @GetMapping("/getUserByCompanyNameAndLegalId")
+    public R<User> getUserByCompanyNameAndLegalId(String companyName, String cardId) {
+        Company company = companyService.getOne(new LambdaQueryWrapper<Company>()
+                .eq(Company::getCompanyName, companyName)
+                .eq(Company::getIdCardNumber, cardId));
+        User user = userService.getById(company.getUserId());
+        return R.ok(user);
+    }
 }

--
Gitblit v1.7.1