|
|
|
package com.water.watersys.controller;
|
|
|
|
|
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
|
import com.water.watersys.components.Result;
|
|
|
|
import com.water.watersys.model.dto.ChangePassword;
|
|
|
|
import com.water.watersys.model.dto.ChangeUserInfo;
|
|
|
|
import com.water.watersys.model.vo.UserOv;
|
|
|
|
import com.water.watersys.service.UserSysService;
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
import jakarta.annotation.Resource;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@CrossOrigin
|
|
|
|
@Tag(name = "用户", description = "用户")
|
|
|
|
public class UserController {
|
|
|
|
@Resource
|
|
|
|
private UserSysService userSysService;
|
|
|
|
|
|
|
|
static Logger logger= LoggerFactory.getLogger(UserController.class);
|
|
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "获取用户信息", description = "获取用户信息")
|
|
|
|
@GetMapping("/user")
|
|
|
|
public Result<UserOv> user() {
|
|
|
|
Object loginId = StpUtil.getLoginId();
|
|
|
|
UserOv userOv = userSysService.getUser((String) loginId);
|
|
|
|
logger.info("用户信息获取={}", userOv);
|
|
|
|
if (userOv != null) {
|
|
|
|
return Result.success(userOv);
|
|
|
|
}else {
|
|
|
|
return Result.notFoundFail();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Operation(summary = "修改用户密码", description = "修改用户密码")
|
|
|
|
@PutMapping("/changePassword")
|
|
|
|
public Result<String> changePassword(@RequestBody ChangePassword changePassword) {
|
|
|
|
String loginId = (String) StpUtil.getLoginId();
|
|
|
|
Integer id = userSysService.changePassword(changePassword,loginId);
|
|
|
|
logger.info("修改密码={}", id);
|
|
|
|
if (id != 0) {
|
|
|
|
return Result.success();
|
|
|
|
}else {
|
|
|
|
return Result.createFail("密码验证失败");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Operation(summary = "修改用户状态", description = "修改用户状态")
|
|
|
|
@PutMapping("/changeUserStatus")
|
|
|
|
public Result<String> changeUserStatus(Integer status) {
|
|
|
|
String loginId = (String) StpUtil.getLoginId();
|
|
|
|
Integer id = userSysService.changeUserStatus(status,loginId);
|
|
|
|
if (id != 0) {
|
|
|
|
return Result.success();
|
|
|
|
}else {
|
|
|
|
return Result.createFail();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Operation(summary = "修改用户信息", description = "修改用户信息")
|
|
|
|
@PutMapping("/changeUserInfo")
|
|
|
|
public Result<String> changeUserInfo(ChangeUserInfo changeUserInfo) {
|
|
|
|
String loginId = (String) StpUtil.getLoginId();
|
|
|
|
Integer id = userSysService.changeUserInfo(changeUserInfo,loginId);
|
|
|
|
if (id != 0) {
|
|
|
|
return Result.success();
|
|
|
|
}else {
|
|
|
|
return Result.createFail();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|