181 lines
5.9 KiB
Java
181 lines
5.9 KiB
Java
package com.stdproject.controller;
|
||
|
||
import cn.hutool.core.util.ObjUtil;
|
||
import cn.hutool.core.util.StrUtil;
|
||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||
import com.stdproject.config.ResponseResult;
|
||
import com.stdproject.entity.User;
|
||
import com.stdproject.service.IUserService;
|
||
import io.micrometer.common.util.StringUtils;
|
||
import jakarta.annotation.Resource;
|
||
import org.springframework.web.bind.annotation.*;
|
||
|
||
import java.util.Map;
|
||
|
||
|
||
/**
|
||
* <p>
|
||
* 用户 前端控制器
|
||
* </p>
|
||
*
|
||
* @author lilin
|
||
* @since 2025-05-08
|
||
*/
|
||
@RestController
|
||
@RequestMapping("/user")
|
||
public class UserController {
|
||
|
||
@Resource
|
||
private IUserService userService;
|
||
|
||
/***********************************
|
||
* 用途说明:新增系统用户
|
||
* 参数说明
|
||
* user 用户对象
|
||
* roleids 角色ID
|
||
* 返回值说明: 是否新增成功
|
||
***********************************/
|
||
@PostMapping("/addUser")
|
||
@ResponseBody
|
||
public ResponseResult addUser(@RequestBody User user, String roleids) {
|
||
Map reslut = userService.addUser(user, roleids);
|
||
return ResponseResult.successData(reslut);
|
||
}
|
||
|
||
/***********************************
|
||
* 用途说明:修改用户信息
|
||
* 参数说明
|
||
* user 用户对象
|
||
* roleids 角色ID
|
||
* 返回值说明: 是否新增成功
|
||
***********************************/
|
||
@PostMapping("/updateUser")
|
||
@ResponseBody
|
||
public ResponseResult updateUser(@RequestBody User user, String roleids) {
|
||
if (StringUtils.isEmpty(user.getId())) {
|
||
return ResponseResult.error("没有用户ID");
|
||
}
|
||
Map reslut = userService.updateById(user, roleids);
|
||
return ResponseResult.successData(reslut);
|
||
}
|
||
|
||
/***********************************
|
||
* 用途说明:查询用户信息
|
||
* 参数说明
|
||
* orgid 所属组织ID
|
||
* nickname 用户昵称
|
||
* page 分页条件
|
||
* 返回值说明: 用户信息集合
|
||
***********************************/
|
||
@GetMapping("/queryUsers")
|
||
@ResponseBody
|
||
public ResponseResult queryUsers(String orgid,String appId, String nickname, Page<User> page) {
|
||
Page<Map<String, Object>> mapPage = userService.queryUsers(orgid, appId, nickname, page);
|
||
return ResponseResult.successData(mapPage);
|
||
}
|
||
|
||
/***********************************
|
||
* 用途说明:根据ID删除用户
|
||
* 参数说明
|
||
*id 用户id
|
||
* 返回值说明: 判断是否删除成功
|
||
************************************/
|
||
@PostMapping("/deleteUserById")
|
||
@ResponseBody
|
||
public ResponseResult deleteUserById(String id) {
|
||
if (id == null || id.trim().isEmpty()) {
|
||
return ResponseResult.error("用户ID不能为空");
|
||
}
|
||
boolean result = userService.deleteUserById(id);
|
||
if (!result) {
|
||
return ResponseResult.error("删除用户失败,可能用户不存在");
|
||
}
|
||
return ResponseResult.success();
|
||
}
|
||
|
||
/***********************************
|
||
* 用途说明:根据ID批量删除用户
|
||
* 参数说明
|
||
*ids 用户id集合
|
||
* 返回值说明: 判断是否删除成功
|
||
************************************/
|
||
@PostMapping("/deleteUserByIds")
|
||
@ResponseBody
|
||
public ResponseResult deleteUserByIds(String ids) {
|
||
if (StringUtils.isBlank(ids)) {
|
||
return ResponseResult.error("参数为空");
|
||
}
|
||
boolean ok = userService.deleteUserByIds(ids);
|
||
if (ok) {
|
||
return ResponseResult.success();
|
||
} else {
|
||
return ResponseResult.error();
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/***********************************
|
||
* 用途说明:设置账号状态(管理员)
|
||
* 参数说明
|
||
*id 用户id
|
||
* status 设置状态
|
||
* 返回值说明: 判断是否设置成功
|
||
************************************/
|
||
@PostMapping("/setStatus")
|
||
@ResponseBody
|
||
public ResponseResult setStatus(@RequestParam String id,@RequestParam String status) {
|
||
if (StringUtils.isEmpty(id)) {
|
||
return ResponseResult.error("用户ID为空");
|
||
}
|
||
if (StringUtils.isEmpty(status)) {
|
||
return ResponseResult.error("设置状态为空");
|
||
}
|
||
boolean ok = userService.setStatus(id, status);
|
||
if (ok) {
|
||
return ResponseResult.success();
|
||
} else {
|
||
return ResponseResult.error();
|
||
}
|
||
}
|
||
|
||
/***********************************
|
||
* 用途说明:重置用户密码(管理员)
|
||
* 参数说明
|
||
*id 重置密码的 用户id
|
||
* 返回值说明: 判断是否重置成功
|
||
************************************/
|
||
@PostMapping("/resetPassword")
|
||
@ResponseBody
|
||
public ResponseResult resetPassword(String id) throws Exception {
|
||
if (StrUtil.isBlank(id)) {
|
||
ResponseResult.error("参数为空");
|
||
}
|
||
boolean ok = userService.resetPassword(id);
|
||
if (ok) {
|
||
return ResponseResult.success();
|
||
} else {
|
||
return ResponseResult.error();
|
||
}
|
||
}
|
||
@PostMapping("/login")
|
||
@ResponseBody
|
||
public ResponseResult login(String appid,String username, String password) {
|
||
if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) {
|
||
return ResponseResult.error("用户名称或者密码不能为空!");
|
||
}
|
||
// 根据用户名查询用户
|
||
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
|
||
User user = userService.getOne(queryWrapper.eq("app_id",appid).eq("username", username));
|
||
if (ObjUtil.isEmpty( user)) {
|
||
return ResponseResult.error(String.format("%s您输入的用户账号不存在!", username));
|
||
}
|
||
if(password.equals(user.getPassword())){
|
||
return ResponseResult.successData(user);
|
||
}else{
|
||
return ResponseResult.error("您输入的密码错误!");
|
||
}
|
||
}
|
||
}
|