From 2ec5c14a87bce4cb6ccba7a1bd87708bcce055a9 Mon Sep 17 00:00:00 2001
From: zj <1772600164@qq.com>
Date: Fri, 21 Nov 2025 23:45:06 +0800
Subject: [PATCH] 1

---
 ruoyi-admin/src/main/java/com/ruoyi/im/service/impl/ImApiServcieImpl.java |   97 +++++++++++++++++++++++++++++++-----------------
 1 files changed, 62 insertions(+), 35 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/im/service/impl/ImApiServcieImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/im/service/impl/ImApiServcieImpl.java
index 8dc2ec6..92c09c3 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/im/service/impl/ImApiServcieImpl.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/im/service/impl/ImApiServcieImpl.java
@@ -23,6 +23,7 @@
 import com.ruoyi.im.service.NeteaseTeamService;
 import com.ruoyi.imenum.ErrorCodeEnum;
 import com.ruoyi.system.domain.GroupWelcomeConfig;
+import com.ruoyi.system.domain.InvitationBlacklist;
 import com.ruoyi.system.domain.NeteaseTeam;
 import com.ruoyi.system.domain.UserAccount;
 import com.ruoyi.im.service.ImApiServcie;
@@ -32,6 +33,7 @@
 import com.ruoyi.system.service.GroupWelcomeConfigService;
 import com.ruoyi.system.service.UserAccountService;
 import com.ruoyi.im.util.SymmetricCryptoUtil;
+import com.ruoyi.system.service.impl.InvitationBlacklistServiceImpl;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.http.HttpResponse;
@@ -77,6 +79,9 @@
     private JdbcTemplate jdbcTemplate;
     @Autowired
     private NeteaseTeamMapper neteaseTeamMapper;
+
+    @Autowired
+    InvitationBlacklistServiceImpl invitationBlacklistService;
 
     @Resource
     private final YunxinApiHttpClient yunxinClient;
@@ -125,6 +130,13 @@
             return Result.error("邀请码不能为空!");
         }
 
+        long count = invitationBlacklistService.count(new LambdaQueryWrapper<InvitationBlacklist>()
+                .eq(InvitationBlacklist::getInvitationCode, dto.getInvitationCode())
+        );
+        if(count > 0){
+            return Result.error("邀请码已被限制邀请!");
+        }
+
         String invitationCode = getInvitationCode();
         UserAccount user = new UserAccount();
         if(dto.getAccountType() == 0 && StringUtils.isNotEmpty(dto.getInvitationCode()) &&  !dto.getInvitationCode().equals("00000000")){
@@ -142,7 +154,7 @@
         userAccount.setCloudMessageAccount(dto.getAccount());
         userAccount.setPassword(SymmetricCryptoUtil.encryptPassword(dto.getPassword()));
         userAccount.setCreateTime(new Date());
-        userAccount.setNickname(dto.getNickname());
+        userAccount.setNickname(dto.getNikeName());
         userAccount.setCreateTime(new Date());
         userAccount.setUpdateTime(new Date());
         userAccount.setInvitationCode(invitationCode);
@@ -151,16 +163,21 @@
         if (!userAccountService.save(userAccount)) {
             throw new RuntimeException("保存用户账户失败");
         }
-
         try {
             // 注册云信账号(远程调用)
             Map<String, String> paramMap = new HashMap<>();
             paramMap.put("accid", dto.getAccount());
-            if(StringUtils.isNotEmpty(dto.getNickname())){
-                paramMap.put("name", dto.getNickname());
-            }
             paramMap.put("token", dto.getPassword());
 
+            if (StringUtils.isNotEmpty(dto.getNikeName())) {
+                Map<String, String> userInfoMap = new HashMap<>();
+                userInfoMap.put("name", dto.getNikeName());
+
+                // 使用 JSON 工具将 Map 转为 JSON 字符串
+                ObjectMapper objectMapper = new ObjectMapper();
+                String userInfoJson = objectMapper.writeValueAsString(userInfoMap);
+                paramMap.put("user_information", userInfoJson);
+            }
             YunxinApiResponse response = yunxinClient.executeV1Api(YUNXIN_CREATE_PATH, paramMap);
 
             // 处理云信响应
@@ -175,6 +192,15 @@
                 }
                 log.error("-----------注册账号异常:"+ErrorCodeEnum.getByCode(code).getComment()+"----im信息:"+ErrorCodeEnum.getByCode(code).getDesc());
                 throw new RuntimeException(errorMsg);
+            }
+            //修改昵称
+            UpdateUserBusinessDto userBusinessDto = new UpdateUserBusinessDto();
+            userBusinessDto.setName(dto.getNikeName());
+            updateUserAvatar(dto.getAccount(),userBusinessDto);
+
+            //默认添加邀请人为好友
+            if(ObjectUtil.isNotEmpty(user)){
+                addFriends(userAccount.getAccount(),user.getAccount());
             }
 
             // 注册成功后的其他操作
@@ -356,8 +382,6 @@
         return result;
     }
 
-
-
     /**
      * 生成校验和
      */
@@ -371,31 +395,33 @@
     @Override
     public AjaxResult updateUserAccount(UserAccountUpdateVo vo) {
         //更新用户名片
-        UpdateUserBusinessDto dto = new UpdateUserBusinessDto();
-        if(StringUtils.isNotEmpty(vo.getPhoneNumber())){
-            dto.setMobile(vo.getPhoneNumber());
-        }
-        if(StringUtils.isNotEmpty(vo.getNickname())){
-            dto.setName(vo.getNickname());
-        }
-        if(StringUtils.isNotEmpty(vo.getSignature())){
-            dto.setSign(vo.getSignature());
-        }
-        if(ObjectUtil.isNotEmpty(vo.getGender())){
-            dto.setGender(vo.getGender());
-        }
-        Map<String, Object> map = updateUserAvatar(vo.getAccountId(), dto);
+//        UpdateUserBusinessDto dto = new UpdateUserBusinessDto();
+//        if(StringUtils.isNotEmpty(vo.getPhoneNumber())){
+//            dto.setMobile(vo.getPhoneNumber());
+//        }
+//        if(StringUtils.isNotEmpty(vo.getNickname())){
+//            dto.setName(vo.getNickname());
+//        }
+//        if(StringUtils.isNotEmpty(vo.getSignature())){
+//            dto.setSign(vo.getSignature());
+//        }
+//        if(ObjectUtil.isNotEmpty(vo.getGender())){
+//            dto.setGender(vo.getGender());
+//        }
+//        Map<String, Object> map = updateUserAvatar(vo.getAccountId(), dto);
         //更新用户属性 状态 密码
-        if ((Boolean) map.get("success")) {
-            AjaxResult ajaxResult = updateAccountProperties(vo.getAccountId(), vo);
+//        if ((Boolean) map.get("success")) {
+            AjaxResult ajaxResult = updateAccountProperties(vo.getAccount(), vo);
             if(ajaxResult.isSuccess()){
-                UserAccount userAccount = userAccountService.getById(vo.getId());
+                UserAccount userAccount = userAccountService.getOne(new LambdaQueryWrapper<UserAccount>()
+                        .eq(UserAccount::getAccount,vo.getAccount())
+                );
                 if (StringUtils.isNotBlank(vo.getPhoneNumber())) {
                     userAccount.setPhoneNumber(vo.getPhoneNumber());
                 }
 
-                if (StringUtils.isNotBlank(vo.getAccountId())) {
-                    userAccount.setAccount(vo.getAccountId());
+                if (StringUtils.isNotBlank(vo.getAccount())) {
+                    userAccount.setAccount(vo.getAccount());
                 }
 
                 if (StringUtils.isNotBlank(vo.getNickname())) {
@@ -409,15 +435,17 @@
                 if (StringUtils.isNotBlank(vo.getSignature())) {
                     userAccount.setSignature(vo.getSignature());
                 }
+                userAccount.setGroupPermissions(vo.getGroupPermissions());
+                userAccount.setAddFriend(vo.getAddFriend());
                 userAccount.setStatus(vo.getStatus());
                 userAccount.setUpdateTime(new Date());
                 userAccountService.updateById(userAccount);
             }else{
                 return AjaxResult.error("更新用户属性失败!");
             }
-        } else {
-            return AjaxResult.error("更新用户名片失败!");
-        }
+//        } else {
+//            return AjaxResult.error("更新用户名片失败!");
+//        }
         return AjaxResult.success("更新成功!");
     }
 
@@ -453,6 +481,8 @@
             if(null != vo.getStatus() && vo.getStatus() == 1){
                 builder.setEnabled(false);
                 builder.setNeedKick(true);
+            }else if(null != vo.getStatus() && vo.getStatus() == 0){
+                builder.setEnabled(true);
             }else if(StringUtils.isNotEmpty(vo.getPassword())){
                 builder.setToken(vo.getPassword());
             }
@@ -468,17 +498,14 @@
             NeteaseResponse neteaseResponse = objectMapper.readValue(responseString, NeteaseResponse.class);
 
             if (neteaseResponse.isSuccess()) {
-                AjaxResult.success("账号属性更新成功");
+                return AjaxResult.success("账号属性更新成功");
             } else {
-                AjaxResult.error("账号属性更新失败");
+                return AjaxResult.error("账号属性更新失败");
             }
-
         } catch (Exception e) {
             e.printStackTrace();
-            AjaxResult.error("请求网易云信API失败");
+            return AjaxResult.error("请求网易云信API失败");
         }
-
-        return AjaxResult.success();
     }
 
 

--
Gitblit v1.9.3