1
zj
2025-08-23 a441a1665bc8dd78b70cc842ad9777ff0ec6daee
ruoyi-admin/src/main/java/com/ruoyi/web/controller/user/UserController.java
@@ -9,7 +9,10 @@
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.im.comm.Result;
import com.ruoyi.im.dto.RegisterDto;
import com.ruoyi.im.out.UserAccountOut;
import com.ruoyi.im.service.ImApiServcie;
import com.ruoyi.im.util.ConverterUtil;
import com.ruoyi.im.util.PhoneNumberValidatorUtil;
import com.ruoyi.system.domain.UserAccount;
import com.ruoyi.system.domain.vo.UserAccountUpdateVo;
import com.ruoyi.system.domain.vo.UserAccountVo;
@@ -40,11 +43,12 @@
    /**
     * 获取会员列表
     */
    @PreAuthorize("@ss.hasPermi('im:user:list')")
//    @PreAuthorize("@ss.hasPermi('im:user:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserAccountVo vo)
    {
        // 创建查询条件包装器
        LambdaQueryWrapper<UserAccount> queryWrapper = new LambdaQueryWrapper<>();
        // 只有当 keyword 不为空时才添加 OR 条件
@@ -69,14 +73,16 @@
        // 默认按创建时间倒序
        queryWrapper.orderByDesc(UserAccount::getCreateTime);
        startPage();
        List<UserAccount> list = userAccountService.list(queryWrapper);
        return getDataTable(list);
        List<UserAccountOut> toList = ConverterUtil.convertToList(list, UserAccountOut.class);
        return getDataTable(toList);
    }
    /**
     * 修改会员
     */
    @PreAuthorize("@ss.hasPermi('im:user:updateUserAccount')")
//    @PreAuthorize("@ss.hasPermi('im:user:updateUserAccount')")
    @PostMapping("/updateUserAccount")
    public AjaxResult updateUserAccount(UserAccountUpdateVo vo) {
@@ -85,6 +91,11 @@
            if(ObjectUtil.isEmpty(userAccount)){
                return AjaxResult.error("会员不存在!");
            }
            PhoneNumberValidatorUtil.ValidationResult result = PhoneNumberValidatorUtil.validatePhoneNumber(vo.getPhoneNumber());
            if(!result.isValid()){
                return AjaxResult.error("手机号格式不正确!");
            }
            vo.setAccountId(userAccount.getCloudMessageAccount());
            return imApiServcie.updateUserAccount(vo);
        }catch (Exception e){
            e.printStackTrace();
@@ -94,14 +105,34 @@
    }
    /**
     * 批量注册
     * 创建会员
     */
    @PostMapping("/batchRegister")
    public Result batchRegister(@Validated RegisterDto dto){
        try {
            if(null == dto.getType()){
                return Result.error("类型不能为空");
            }else if(dto.getType() == 2){
                if(StringUtils.isEmpty(dto.getAccount())){
                    return Result.error("账号不能为空");
                }
                if(StringUtils.isEmpty(dto.getPassword())){
                    return Result.error("密码不能为空");
                }
                if(StringUtils.isEmpty(dto.getNickname())){
                    return Result.error("昵称不能为空");
                }
            }else if (dto.getType() == 1){
                if(dto.getNumber() <= 0){
                    return Result.error("数量不能为空");
                }else if(dto.getNumber() > 100){
                    return Result.error("批量注册最多一次100");
                }
            }
            return imApiServcie.batchRegister(dto);
        }catch (Exception e){
            log.error("批量注册报错:",e);
            e.printStackTrace();
            log.error("-----------批量注册报错------------");
            return Result.error("注册失败,请稍后再试!");
        }
    }