|
|
package com.aurora.controller;
|
|
|
|
|
|
import com.aurora.annotation.OptLog;
|
|
|
import com.aurora.model.dto.PageResultDTO;
|
|
|
import com.aurora.model.dto.UserInfoDTO;
|
|
|
import com.aurora.model.dto.UserOnlineDTO;
|
|
|
import com.aurora.service.UserInfoService;
|
|
|
import com.aurora.model.vo.*;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.validation.Valid;
|
|
|
|
|
|
import static com.aurora.constant.OptTypeConstant.DELETE;
|
|
|
import static com.aurora.constant.OptTypeConstant.UPDATE;
|
|
|
|
|
|
@Api(tags = "用户信息模块")
|
|
|
@RestController
|
|
|
public class UserInfoController {
|
|
|
|
|
|
@Autowired
|
|
|
private UserInfoService userInfoService;//调用用户信息相关的业务方法
|
|
|
|
|
|
@OptLog(optType = UPDATE)
|
|
|
@ApiOperation("更新用户信息")//用户自主更新个人基本信息
|
|
|
@PutMapping("/users/info")
|
|
|
public ResultVO<?> updateUserInfo(@Valid @RequestBody UserInfoVO userInfoVO) {
|
|
|
userInfoService.updateUserInfo(userInfoVO);
|
|
|
return ResultVO.ok();
|
|
|
}
|
|
|
|
|
|
@OptLog(optType = UPDATE)
|
|
|
@ApiOperation("更新用户头像")
|
|
|
@ApiImplicitParam(name = "file", value = "用户头像", required = true, dataType = "MultipartFile")
|
|
|
@PostMapping("/users/avatar")
|
|
|
public ResultVO<String> updateUserAvatar(MultipartFile file) {
|
|
|
//MultipartFile file:接受用户上传的头像文件,返回更新后头像的存储路径(字符串格式)
|
|
|
return ResultVO.ok(userInfoService.updateUserAvatar(file));
|
|
|
}
|
|
|
|
|
|
@OptLog(optType = UPDATE)
|
|
|
@ApiOperation("绑定用户邮箱")//用户绑定个人邮箱(通常需要验证码验证)
|
|
|
@PutMapping("/users/email")
|
|
|
public ResultVO<?> saveUserEmail(@Valid @RequestBody EmailVO emailVO) {
|
|
|
//EmailVO emailVO:封装邮箱绑定的参数,包含邮箱地址、验证码等绑定信息,且会被@Valid校验
|
|
|
userInfoService.saveUserEmail(emailVO);
|
|
|
return ResultVO.ok();
|
|
|
}
|
|
|
|
|
|
@OptLog(optType = UPDATE)
|
|
|
@ApiOperation("修改用户的订阅状态")//用户自主修改订阅相关状态(比如订阅网站通知、内容推送等)
|
|
|
@PutMapping("/users/subscribe")
|
|
|
public ResultVO<?> updateUserSubscribe(@RequestBody SubscribeVO subscribeVO) {
|
|
|
userInfoService.updateUserSubscribe(subscribeVO);
|
|
|
return ResultVO.ok();
|
|
|
}
|
|
|
|
|
|
@OptLog(optType = UPDATE)
|
|
|
@ApiOperation(value = "修改用户角色")//后台管理员修改用户的角色(比如普通用户改为编辑)
|
|
|
@PutMapping("/admin/users/role")
|
|
|
public ResultVO<?> updateUserRole(@Valid @RequestBody UserRoleVO userRoleVO) {
|
|
|
userInfoService.updateUserRole(userRoleVO);
|
|
|
return ResultVO.ok();
|
|
|
}
|
|
|
|
|
|
@OptLog(optType = UPDATE)
|
|
|
@ApiOperation(value = "修改用户禁用状态")//后台管理员禁用/解禁用户账号
|
|
|
@PutMapping("/admin/users/disable")
|
|
|
public ResultVO<?> updateUserDisable(@Valid @RequestBody UserDisableVO userDisableVO) {
|
|
|
userInfoService.updateUserDisable(userDisableVO);
|
|
|
return ResultVO.ok();
|
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "查看在线用户")//后台管理员查看当前在线的用户列表
|
|
|
@GetMapping("/admin/users/online")
|
|
|
public ResultVO<PageResultDTO<UserOnlineDTO>> listOnlineUsers(ConditionVO conditionVO) {
|
|
|
return ResultVO.ok(userInfoService.listOnlineUsers(conditionVO));
|
|
|
}
|
|
|
|
|
|
@OptLog(optType = DELETE)//记录用户下线的日志
|
|
|
@ApiOperation(value = "下线用户")//后台管理员强制让指定在线用户下线(清除在线状态)
|
|
|
@DeleteMapping("/admin/users/{userInfoId}/online")
|
|
|
public ResultVO<?> removeOnlineUser(@PathVariable("userInfoId") Integer userInfoId) {
|
|
|
userInfoService.removeOnlineUser(userInfoId);
|
|
|
return ResultVO.ok();
|
|
|
}
|
|
|
|
|
|
@ApiOperation("根据id获取用户信息")//获取指定ID用户的个人信息(用于前端查看他人信息或后台查看用户详情)
|
|
|
@GetMapping("/users/info/{userInfoId}")
|
|
|
public ResultVO<UserInfoDTO> getUserInfoById(@PathVariable("userInfoId") Integer userInfoId) {
|
|
|
return ResultVO.ok(userInfoService.getUserInfoById(userInfoId));
|
|
|
}
|
|
|
|
|
|
}
|