| | |
| | | package com.ruoyi.web.controller.user; |
| | | |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.ruoyi.common.constant.HttpStatus; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | 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; |
| | | import com.ruoyi.system.service.UserAccountService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | @RestController |
| | | @RequestMapping("/im/user") |
| | | @Slf4j |
| | | public class UserController extends BaseController { |
| | | |
| | | @Autowired |
| | | UserAccountService userAccountService; |
| | | |
| | | @Autowired |
| | | private ImApiServcie imApiServcie; |
| | | |
| | | /** |
| | | * 获取用户列表 |
| | | * 获取会员列表 |
| | | */ |
| | | @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 条件 |
| | | if (ObjectUtil.isNotEmpty(vo.getKeywords())) { |
| | | queryWrapper.and(wrapper -> wrapper |
| | | .eq(UserAccount::getId, vo.getKeywords()) |
| | | .or() |
| | | .like(UserAccount::getPhoneNumber, vo.getKeywords()) |
| | | .or() |
| | | .like(UserAccount::getAccount, vo.getKeywords()) |
| | | .or() |
| | | .like(UserAccount::getNickname, vo.getKeywords()) |
| | | ); |
| | | } |
| | | |
| | | // 添加其他条件 |
| | | queryWrapper |
| | | .eq(ObjectUtil.isNotEmpty(vo.getAccountType()), UserAccount::getAccountType, vo.getAccountType()) |
| | | .eq(ObjectUtil.isNotEmpty(vo.getStatus()), UserAccount::getStatus, vo.getStatus()) |
| | | .between(ObjectUtil.isAllNotEmpty(vo.getStartTime(), vo.getEndTime()), |
| | | UserAccount::getCreateTime, vo.getStartTime(), vo.getEndTime()); |
| | | |
| | | // 默认按创建时间倒序 |
| | | queryWrapper.orderByDesc(UserAccount::getCreateTime); |
| | | startPage(); |
| | | List<UserAccount> list = userAccountService.list(new LambdaQueryWrapper<UserAccount>() |
| | | .eq(UserAccount::getId, vo.getId()) |
| | | .or() |
| | | .eq(UserAccount::getPhoneNumber, vo.getPhoneNumber()) |
| | | .or() |
| | | .eq(UserAccount::getAccount, vo.getAccount()) |
| | | .or() |
| | | .eq(UserAccount::getNickname, vo.getNickname()) |
| | | ); |
| | | return getDataTable(list); |
| | | List<UserAccount> list = userAccountService.list(queryWrapper); |
| | | |
| | | PageInfo<UserAccount> pageInfo = new PageInfo<>(list); |
| | | |
| | | List<UserAccountOut> toList = ConverterUtil.convertToList(list, UserAccountOut.class); |
| | | |
| | | TableDataInfo rspData = new TableDataInfo(); |
| | | rspData.setCode(HttpStatus.SUCCESS); |
| | | rspData.setMsg("查询成功"); |
| | | rspData.setRows(toList); |
| | | rspData.setTotal(pageInfo.getTotal()); |
| | | return rspData; |
| | | } |
| | | |
| | | /** |
| | | * 修改会员 |
| | | */ |
| | | // @PreAuthorize("@ss.hasPermi('im:user:updateUserAccount')") |
| | | @PostMapping("/updateUserAccount") |
| | | public AjaxResult updateUserAccount(UserAccountUpdateVo vo) { |
| | | |
| | | try { |
| | | UserAccount userAccount = userAccountService.getById(vo.getId()); |
| | | 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(); |
| | | logger.error("修改会员失败!"); |
| | | } |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | /** |
| | | * 创建会员 |
| | | */ |
| | | @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){ |
| | | e.printStackTrace(); |
| | | log.error("-----------批量注册报错------------"); |
| | | return Result.error("注册失败,请稍后再试!"); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |