Browse Source

企业密码重置

marxjaw 3 months ago
parent
commit
8b5cee0032

+ 1 - 0
yt-common/src/main/java/com/ytpm/general/RepMessage.java

@@ -14,6 +14,7 @@ public class RepMessage {
     public static final String LOGOUT_SUCCESS = "已退出登录";
     public static final String LOGIN_SUCCESS = "登录成功";
     public static final String LOCK_USER_SUCCESS = "用户锁定成功";
+    public static final String RESET_SUCCESS = "重置成功";
 
     public static final String NOT_LOGIN= "当前用户未登录";
     public static final String USER_NAME_EMPTY = "用户名不能为空";

+ 9 - 0
yt-middle/middle-platform/src/main/java/com/ytpm/middle/controller/AgentController.java

@@ -65,4 +65,13 @@ public class AgentController {
     public Result<String> enabled(@RequestParam(name = "creditCode")String creditCode,  @ApiIgnore @AuthenticationPrincipal AgentUserInfo userInfo){
         return agentService.enabled(creditCode,userInfo.getUserId());
     }
+
+    /**
+     * 重置密码
+     */
+    @ApiOperation("重置密码")
+    @GetMapping("/resetPwd")
+    public Result<String> resetPwd(@RequestParam(name = "creditCode")String creditCode){
+        return agentService.resetPwd(creditCode);
+    }
 }

+ 6 - 0
yt-middle/middle-platform/src/main/java/com/ytpm/middle/dao/AgentMapper.java

@@ -3,6 +3,7 @@ package com.ytpm.middle.dao;
 import com.ytpm.middle.param.AgentBaseInfoParam;
 import com.ytpm.middle.view.AgentBaseInfoListVO;
 import com.ytpm.oauth.model.YtPlatformUser;
+import org.apache.ibatis.annotations.Param;
 import org.mapstruct.Mapper;
 
 import java.util.List;
@@ -18,4 +19,9 @@ public interface AgentMapper {
      * 新增用户
      */
     void addOneUser(YtPlatformUser user);
+
+    /**
+     * 重置密码
+     */
+    void resetPwd(@Param("userId") String userId, @Param("encrypt") String encrypt);
 }

+ 4 - 0
yt-middle/middle-platform/src/main/java/com/ytpm/middle/service/AgentService.java

@@ -24,4 +24,8 @@ public interface AgentService {
      * 启用或禁用
      */
     Result<String> enabled(String creditCode, String userId);
+    /**
+     * 重置密码
+     */
+    Result<String> resetPwd(String creditCode);
 }

+ 15 - 0
yt-middle/middle-platform/src/main/java/com/ytpm/middle/service/impl/AgentServiceImpl.java

@@ -91,6 +91,20 @@ public class AgentServiceImpl implements AgentService {
         enterpriseMapper.updateById(enterprise);
         return Result.resultOk(RepMessage.MODIFY_SUCCESS);
     }
+    /**
+     * 重置密码
+     */
+    @Override
+    public Result<String> resetPwd(String creditCode) {
+        YtMiddleEnterprise old = enterpriseMapper.getByCode(creditCode);
+        if(Objects.isNull(old)) {
+            return Result.resultOk(RepMessage.OBJECT_NOT_EXIST);
+        }
+        String generatedPassword = RandomPasswordGenerator.generatePassword(8);
+        agentMapper.resetPwd(old.getUserId(),new BCryptPasswordEncoder().encode(generatedPassword));
+        //TODO 短信通知企业负责人重置后的密码
+        return Result.resultOk(RepMessage.RESET_SUCCESS);
+    }
 
     /**
      * 企业信息新增操作
@@ -123,5 +137,6 @@ public class AgentServiceImpl implements AgentService {
         user.setChannelId(accountId);
         user.setLoginDays(1);
         agentMapper.addOneUser(user);
+        //TODO 短信通知企业负责人 账号密码,邀请其登录代理商管理系统
     }
 }

+ 5 - 0
yt-middle/middle-platform/src/main/resources/mapper/AgentMapper.xml

@@ -47,6 +47,11 @@
          #{transferAmount}
         );
     </insert>
+    <update id="resetPwd">
+        update yt_platform_user
+        set encrypt_pwd = #{encrypt}
+        where user_id = #{userId}
+    </update>
 
     <select id="getBaseInfoList" resultType="com.ytpm.middle.view.AgentBaseInfoListVO">
         select