trigger: verify valid_volumes after runner restart
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
package com.freedom.admin.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.freedom.admin.common.Result;
|
||||
import com.freedom.admin.entity.TSysDept;
|
||||
import com.freedom.admin.service.TSysDeptService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.security.PermitAll;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author zhangjiaxun
|
||||
* @date 2021/2/8 15:39
|
||||
* @description 系统-部门表
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys-dept")
|
||||
@Log4j2
|
||||
public class TSysDeptController {
|
||||
|
||||
@Autowired
|
||||
private TSysDeptService tSysDeptService;
|
||||
|
||||
/**
|
||||
* 列表查询
|
||||
*
|
||||
* @return Result
|
||||
*/
|
||||
@RequestMapping("/findPageList")
|
||||
@PermitAll
|
||||
public Result<TSysDept> findPageList(@Param("pageNum") long pageNum,
|
||||
@Param("pageSize") long pageSize,
|
||||
TSysDept tSysDept){
|
||||
QueryWrapper<TSysDept> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("del_flag",0);
|
||||
queryWrapper.eq(tSysDept.getParentId() != null,"parent_id",tSysDept.getParentId());
|
||||
queryWrapper.like(StringUtils.isNotBlank(tSysDept.getDeptName()),"dept_name", tSysDept.getDeptName());
|
||||
Page<TSysDept> page = tSysDeptService.page(new Page<>(pageNum,pageSize), queryWrapper);
|
||||
return Result.ok().setData(page);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取部门Tree数据
|
||||
*
|
||||
* @return Result
|
||||
*/
|
||||
@RequestMapping("/getTreeList")
|
||||
@PermitAll
|
||||
public Result<TSysDept> getTreeList() {
|
||||
List<Map<String, Object>> treeList = tSysDeptService.getTreeList();
|
||||
return Result.ok().setData(treeList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取部门TreeSelect数据
|
||||
*
|
||||
* @return Result
|
||||
*/
|
||||
@RequestMapping("/getTreeSelectList")
|
||||
@PermitAll
|
||||
public Result<TSysDept> getTreeSelectList() {
|
||||
List<Map<String, Object>> treeSelectListList = tSysDeptService.getTreeSelectList();
|
||||
return Result.ok().setData(treeSelectListList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @param tSysDept
|
||||
* @return Result
|
||||
*/
|
||||
@RequestMapping("/add")
|
||||
@PermitAll
|
||||
public Result<TSysDept> add(TSysDept tSysDept) {
|
||||
boolean save = tSysDeptService.save(tSysDept);
|
||||
return Result.ok().setData(save);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新
|
||||
*
|
||||
* @param tSysDept
|
||||
* @return Result
|
||||
*/
|
||||
@RequestMapping("/update")
|
||||
@PermitAll
|
||||
public Result<TSysDept> update(TSysDept tSysDept) {
|
||||
log.info("先查询出父级部门,将要更新的子级部门level+1");
|
||||
if (tSysDept.getParentId() != null){
|
||||
Long parentId = 0L;
|
||||
if (parentId.equals(tSysDept.getParentId())){
|
||||
tSysDept.setLevel(1);
|
||||
}else {
|
||||
QueryWrapper<TSysDept> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("id",tSysDept.getParentId());
|
||||
TSysDept parentDept = tSysDeptService.getOne(queryWrapper);
|
||||
if (parentDept == null){
|
||||
return Result.error().message("父级部门不存在");
|
||||
}
|
||||
tSysDept.setLevel(parentDept.getLevel() + 1);
|
||||
}
|
||||
}
|
||||
boolean update = tSysDeptService.updateById(tSysDept);
|
||||
return Result.ok().setData(update);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除部门(逻辑删除)
|
||||
*
|
||||
* @param tSysDept
|
||||
* @return Result
|
||||
*/
|
||||
@RequestMapping("/delete")
|
||||
@PermitAll
|
||||
public Result<TSysDept> delete(TSysDept tSysDept) {
|
||||
if (tSysDept.getId() == null){
|
||||
return Result.error().message("部门ID不能为空");
|
||||
}
|
||||
TSysDept dept = new TSysDept();
|
||||
dept.setId(tSysDept.getId());
|
||||
dept.setDelFlag(true);
|
||||
boolean update = tSysDeptService.updateById(dept);
|
||||
return Result.ok().setData(update);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
package com.freedom.admin.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.freedom.admin.base.BaseController;
|
||||
import com.freedom.admin.common.Result;
|
||||
import com.freedom.admin.entity.TSysDept;
|
||||
import com.freedom.admin.entity.TSysPermission;
|
||||
import com.freedom.admin.service.TSysPermissionService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.security.PermitAll;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author zhangjiaxun
|
||||
* @date 2021/2/4 11:00
|
||||
* @description 控制层-系统权限
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys-permission")
|
||||
@Log4j2
|
||||
public class TSysPermissionController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
TSysPermissionService tSysPermissionService;
|
||||
|
||||
/**
|
||||
* 登录成功时,获取登录用户权限数据
|
||||
*
|
||||
* @return Result
|
||||
* */
|
||||
@RequestMapping("/getPermissionList")
|
||||
@PreAuthorize("permitAll()")
|
||||
public Result<Map<String,Object>> getPermissionList(){
|
||||
List<Map<String, Object>> permissionList = tSysPermissionService.getPermissionListByUserId(getUser().getId());
|
||||
return Result.ok().setData(permissionList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取权限tree数据
|
||||
*
|
||||
* @return Result
|
||||
*/
|
||||
@RequestMapping("/getTreeList")
|
||||
@PreAuthorize("permitAll()")
|
||||
public Result<Map<String,Object>> getTreeList(){
|
||||
List<Map<String, Object>> treeList = tSysPermissionService.getTreeList();
|
||||
return Result.ok().setData(treeList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取权限TreeSelect数据
|
||||
*
|
||||
* @return Result
|
||||
*/
|
||||
@RequestMapping("/getTreeSelectList")
|
||||
@PermitAll
|
||||
public Result<TSysDept> getTreeSelectList() {
|
||||
List<Map<String, Object>> treeSelectListList = tSysPermissionService.getTreeSelectList();
|
||||
return Result.ok().setData(treeSelectListList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜单权限页面-获取菜单列表数据
|
||||
*
|
||||
* @return Result
|
||||
*/
|
||||
@RequestMapping("/findPageList")
|
||||
@PreAuthorize("permitAll()")
|
||||
public Result findPageList(@Param("pageNum") long pageNum,
|
||||
@Param("pageSize") long pageSize,
|
||||
TSysPermission tSysPermission){
|
||||
QueryWrapper<TSysPermission> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("del_flag",0);
|
||||
queryWrapper.eq(tSysPermission.getParentId() != null,"parent_id", tSysPermission.getParentId());
|
||||
queryWrapper.like(StringUtils.isNotBlank(tSysPermission.getPermissionName()),"permission_name", tSysPermission.getPermissionName());
|
||||
Page<TSysPermission> page = tSysPermissionService.page(new Page<>(pageNum,pageSize), queryWrapper);
|
||||
return Result.ok().setData(page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜单权限页面-获取菜单树
|
||||
*
|
||||
* @return Result
|
||||
*/
|
||||
@RequestMapping("/getTreeListByRoleId")
|
||||
@PreAuthorize("permitAll()")
|
||||
public Result getTreeListByRoleId(@Param("roleId") Long roleId){
|
||||
List<Map<String, Object>> treeList = tSysPermissionService.getTreeListByRoleId(roleId);
|
||||
log.info("treeList:{}",treeList);
|
||||
return Result.ok().setData(treeList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @param tSysPermission
|
||||
* @return Result
|
||||
*/
|
||||
@RequestMapping("/add")
|
||||
@PermitAll
|
||||
public Result<TSysDept> add(TSysPermission tSysPermission) {
|
||||
boolean save = tSysPermissionService.save(tSysPermission);
|
||||
return Result.ok().setData(save);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新
|
||||
*
|
||||
* @param tSysPermission
|
||||
* @return Result
|
||||
*/
|
||||
@RequestMapping("/update")
|
||||
@PermitAll
|
||||
public Result<TSysPermission> update(TSysPermission tSysPermission) {
|
||||
log.info("先查询出父级权限,将要更新的子级部门level+1");
|
||||
if (tSysPermission.getParentId() != null){
|
||||
Long parentId = 0L;
|
||||
if (parentId.equals(tSysPermission.getParentId())){
|
||||
tSysPermission.setLevel(1);
|
||||
}else {
|
||||
QueryWrapper<TSysPermission> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("id",tSysPermission.getParentId());
|
||||
TSysPermission parentPermission = tSysPermissionService.getOne(queryWrapper);
|
||||
if (parentPermission == null){
|
||||
return Result.error().message("父级菜单不存在");
|
||||
}
|
||||
tSysPermission.setLevel(parentPermission.getLevel() + 1);
|
||||
}
|
||||
}
|
||||
boolean update = tSysPermissionService.updateById(tSysPermission);
|
||||
return Result.ok().setData(update);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除菜单权限(前端 /delete 与 /remove 兼容)
|
||||
*
|
||||
* @param tSysPermission
|
||||
* @return Result
|
||||
*/
|
||||
@RequestMapping("/delete")
|
||||
@PermitAll
|
||||
public Result<TSysPermission> delete(TSysPermission tSysPermission) {
|
||||
try {
|
||||
boolean remove = tSysPermissionService.removeByPermissionId(tSysPermission.getId());
|
||||
return Result.ok().setData(remove);
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除页面
|
||||
*
|
||||
* @param tSysPermission
|
||||
* @return Result
|
||||
*/
|
||||
@RequestMapping("/remove")
|
||||
@PermitAll
|
||||
public Result<TSysPermission> remove(TSysPermission tSysPermission) {
|
||||
log.info("先查询出父级权限,将要更新的子级部门level+1");
|
||||
try {
|
||||
boolean remove = tSysPermissionService.removeByPermissionId(tSysPermission.getId());
|
||||
return Result.ok().setData(remove);
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
package com.freedom.admin.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.freedom.admin.base.BaseController;
|
||||
import com.freedom.admin.common.Result;
|
||||
import com.freedom.admin.config.MyException;
|
||||
import com.freedom.admin.entity.TSysRole;
|
||||
import com.freedom.admin.entity.TSysRolePermission;
|
||||
import com.freedom.admin.entity.TSysUser;
|
||||
import com.freedom.admin.service.TSysRolePermissionService;
|
||||
import com.freedom.admin.service.TSysRoleService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.security.PermitAll;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author zhangjiaxun
|
||||
* @date 2021/2/8 15:39
|
||||
* @description
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys-role")
|
||||
public class TSysRoleController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private TSysRoleService tSysRoleService;
|
||||
|
||||
@Autowired
|
||||
private TSysRolePermissionService tSysRolePermissionService;
|
||||
|
||||
/**
|
||||
* 获取角色数据列表
|
||||
*
|
||||
* @return Result
|
||||
* */
|
||||
@RequestMapping("/findPageList")
|
||||
@PermitAll
|
||||
public Result<TSysRole> findPageList(@Param("pageNum") long pageNum,
|
||||
@Param("pageSize") long pageSize,
|
||||
TSysRole tSysRole){
|
||||
QueryWrapper<TSysRole> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("del_flag",0);
|
||||
queryWrapper.eq(StringUtils.isNotBlank(tSysRole.getRoleName()),"role_name", tSysRole.getRoleName());
|
||||
Page<TSysRole> page = tSysRoleService.page(new Page<>(pageNum,pageSize), queryWrapper);
|
||||
return Result.ok().setData(page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @param tSysRole
|
||||
* @return Result
|
||||
*/
|
||||
@RequestMapping("/add")
|
||||
@PermitAll
|
||||
public Result<TSysRole> add(TSysRole tSysRole) {
|
||||
boolean save = tSysRoleService.save(tSysRole);
|
||||
return Result.ok().setData(save);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新
|
||||
*
|
||||
* @param tSysRole
|
||||
* @return Result
|
||||
*/
|
||||
@RequestMapping("/update")
|
||||
@PermitAll
|
||||
public Result<TSysRole> update(TSysRole tSysRole) {
|
||||
boolean update = tSysRoleService.updateById(tSysRole);
|
||||
return Result.ok().setData(update);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取角色下拉列表数据
|
||||
*
|
||||
* @return Result
|
||||
*/
|
||||
@RequestMapping("/getRoleSelectList")
|
||||
public Result<Map<String, String>> getRoleSelectList() {
|
||||
List<Map<String, String>> roleSelectList = tSysRoleService.getRoleSelectList();
|
||||
return Result.ok().setData(roleSelectList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加角色权限
|
||||
* */
|
||||
@RequestMapping("/addRolePermission")
|
||||
@PermitAll
|
||||
public Result<TSysUser> addRolePermission(Long roleId, String rolePermissionStr){
|
||||
try {
|
||||
boolean save = tSysRolePermissionService.save(roleId, rolePermissionStr, getUsername());
|
||||
return Result.ok().setData(save);
|
||||
} catch (MyException e) {
|
||||
return Result.error().code(e.getCode()).message(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除角色(逻辑删除 + 清理角色权限关联)
|
||||
* */
|
||||
@RequestMapping("/delete")
|
||||
@PermitAll
|
||||
public Result delete(TSysRole tSysRole){
|
||||
try {
|
||||
if (tSysRole.getId() == null) {
|
||||
return Result.error().message("角色ID不能为空");
|
||||
}
|
||||
// 删除角色权限关联
|
||||
QueryWrapper<TSysRolePermission> rolePermissionWrapper = new QueryWrapper<>();
|
||||
rolePermissionWrapper.eq("role_id", tSysRole.getId());
|
||||
tSysRolePermissionService.remove(rolePermissionWrapper);
|
||||
// 逻辑删除角色
|
||||
TSysRole role = new TSysRole();
|
||||
role.setId(tSysRole.getId());
|
||||
role.setDelFlag(true);
|
||||
boolean update = tSysRoleService.updateById(role);
|
||||
if (!update) {
|
||||
return Result.error().message("删除角色失败");
|
||||
}
|
||||
return Result.ok();
|
||||
} catch (Exception e) {
|
||||
return Result.error().message("删除角色失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
package com.freedom.admin.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.freedom.admin.base.BaseController;
|
||||
import com.freedom.admin.common.Result;
|
||||
import com.freedom.admin.config.MyException;
|
||||
import com.freedom.admin.entity.TSysUser;
|
||||
import com.freedom.admin.entity.TSysUserRole;
|
||||
import com.freedom.admin.mapper.TSysUserRoleMapper;
|
||||
import com.freedom.admin.service.TSysUserService;
|
||||
import com.freedom.admin.service.UserService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.security.PermitAll;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zhangjiaxun
|
||||
* @date 2021/2/2 13:41
|
||||
* @description 控制层-用户表
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("sys-user")
|
||||
@Log4j2
|
||||
public class TSysUserController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private TSysUserService tSysUserService;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private TSysUserRoleMapper tSysUserRoleMapper;
|
||||
|
||||
/**
|
||||
* 用户注册
|
||||
*
|
||||
* @param sysUser 用户信息
|
||||
* @return Result 响应结果
|
||||
* */
|
||||
@RequestMapping("register")
|
||||
@PermitAll
|
||||
public Result<TSysUser> register(TSysUser sysUser){
|
||||
try {
|
||||
QueryWrapper<TSysUser> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("del_flag",0);
|
||||
queryWrapper.eq("username", sysUser.getUsername());
|
||||
long count = tSysUserService.count(queryWrapper);
|
||||
if (count > 0){
|
||||
return Result.error().message("账号已存在!");
|
||||
}
|
||||
boolean register = tSysUserService.register(sysUser);
|
||||
return Result.ok().setData(register);
|
||||
} catch (MyException e) {
|
||||
return Result.error().code(e.getCode()).message(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
* */
|
||||
@RequestMapping("getUserInfo")
|
||||
@PreAuthorize("hasAnyAuthority('user:getUserInfo')")
|
||||
public Result<TSysUser> getUserInfo(){
|
||||
TSysUser user = getUser();
|
||||
return Result.ok().setData(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录用户个人中心信息
|
||||
* */
|
||||
@RequestMapping("getPersonalInfo")
|
||||
@PermitAll
|
||||
public Result<TSysUser> getPersonalInfo(){
|
||||
TSysUser user = getUser();
|
||||
if (user == null) {
|
||||
return Result.error().message("用户未登录");
|
||||
}
|
||||
user.setPassword(null);
|
||||
return Result.ok().setData(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
* */
|
||||
@RequestMapping("updatePassword")
|
||||
@PermitAll
|
||||
public Result updatePassword(TSysUser tSysUser, String oldPassword, String newPassword){
|
||||
try {
|
||||
if (StringUtils.isBlank(oldPassword) || StringUtils.isBlank(newPassword)) {
|
||||
return Result.error().message("旧密码和新密码不能为空");
|
||||
}
|
||||
QueryWrapper<TSysUser> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("del_flag",0);
|
||||
queryWrapper.eq("id", tSysUser.getId());
|
||||
TSysUser user = tSysUserService.getOne(queryWrapper);
|
||||
if (user == null) {
|
||||
return Result.error().message("用户不存在");
|
||||
}
|
||||
BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
|
||||
if (!bCryptPasswordEncoder.matches(oldPassword, user.getPassword())) {
|
||||
return Result.error().code(419).message("旧密码不正确");
|
||||
}
|
||||
user.setPassword(bCryptPasswordEncoder.encode(newPassword));
|
||||
user.setEncodeType("BCrypt");
|
||||
tSysUserService.updateById(user);
|
||||
return Result.ok();
|
||||
} catch (Exception e) {
|
||||
return Result.error().message("修改密码失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置密码
|
||||
* */
|
||||
@RequestMapping("resetPassword")
|
||||
@PermitAll
|
||||
public Result resetPassword(TSysUser tSysUser){
|
||||
try {
|
||||
TSysUser user = new TSysUser();
|
||||
user.setId(tSysUser.getId());
|
||||
BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
|
||||
user.setPassword(bCryptPasswordEncoder.encode("123456"));
|
||||
user.setEncodeType("BCrypt");
|
||||
tSysUserService.updateById(user);
|
||||
return Result.ok().message("密码已重置为 123456");
|
||||
} catch (Exception e) {
|
||||
return Result.error().message("重置密码失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户数据列表
|
||||
* */
|
||||
@RequestMapping("findPageList")
|
||||
@PermitAll
|
||||
public Result<TSysUser> findPageList(@Param("pageNum") long pageNum,
|
||||
@Param("pageSize") long pageSize,
|
||||
TSysUser tSysUser){
|
||||
QueryWrapper<TSysUser> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("del_flag",0);
|
||||
queryWrapper.eq(StringUtils.isNotBlank(tSysUser.getUsername()),"username", tSysUser.getUsername());
|
||||
Page<TSysUser> page = tSysUserService.page(new Page<>(pageNum,pageSize), queryWrapper);
|
||||
// 填充每个用户的角色ID,用于编辑回显
|
||||
if (page.getRecords() != null) {
|
||||
for (TSysUser user : page.getRecords()) {
|
||||
QueryWrapper<TSysUserRole> roleWrapper = new QueryWrapper<>();
|
||||
roleWrapper.eq("user_id", user.getId());
|
||||
List<TSysUserRole> userRoleList = tSysUserRoleMapper.selectList(roleWrapper);
|
||||
if (userRoleList != null && !userRoleList.isEmpty()) {
|
||||
List<String> roleIdList = new ArrayList<>();
|
||||
for (TSysUserRole ur : userRoleList) {
|
||||
roleIdList.add(String.valueOf(ur.getRoleId()));
|
||||
}
|
||||
user.setRoleIds(String.join(",", roleIdList));
|
||||
}
|
||||
}
|
||||
}
|
||||
return Result.ok().setData(page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户列表数据
|
||||
* */
|
||||
@RequestMapping("add")
|
||||
@PermitAll
|
||||
public Result<TSysUser> add(TSysUser tSysUser,String userRoleStr){
|
||||
try {
|
||||
QueryWrapper<TSysUser> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("del_flag",0);
|
||||
queryWrapper.eq("username", tSysUser.getUsername());
|
||||
long count = tSysUserService.count(queryWrapper);
|
||||
if (count > 0){
|
||||
return Result.error().message("账号已存在!");
|
||||
}
|
||||
boolean save = tSysUserService.save(tSysUser, userRoleStr, getUsername());
|
||||
return Result.ok().setData(save);
|
||||
} catch (MyException e) {
|
||||
return Result.error().code(e.getCode()).message(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@RequestMapping("update")
|
||||
@PermitAll
|
||||
public Result update(TSysUser tSysUser,String userRoleStr){
|
||||
try {
|
||||
tSysUserService.updateById(tSysUser);
|
||||
// 更新用户角色关联
|
||||
if (StringUtils.isNotBlank(userRoleStr)) {
|
||||
QueryWrapper<TSysUserRole> delWrapper = new QueryWrapper<>();
|
||||
delWrapper.eq("user_id", tSysUser.getId());
|
||||
tSysUserRoleMapper.delete(delWrapper);
|
||||
List<TSysUserRole> roleList = com.alibaba.fastjson.JSONArray.parseArray(userRoleStr, TSysUserRole.class);
|
||||
if (roleList != null && !roleList.isEmpty()) {
|
||||
for (TSysUserRole ur : roleList) {
|
||||
ur.setUserId(tSysUser.getId());
|
||||
ur.setCreateBy(getUsername());
|
||||
ur.setCreateTime(new java.util.Date());
|
||||
tSysUserRoleMapper.insert(ur);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@RequestMapping("remove")
|
||||
@PermitAll
|
||||
public Result remove(TSysUser tSysUser){
|
||||
try {
|
||||
tSysUserService.removeById(tSysUser.getId());
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user