更换git仓库后的提交
This commit is contained in:
33
cn-user/.gitignore
vendored
Normal file
33
cn-user/.gitignore
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
HELP.md
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
45
cn-user/pom.xml
Normal file
45
cn-user/pom.xml
Normal file
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.njcn.product</groupId>
|
||||
<artifactId>CN_Product</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>cn-user</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<name>cn-user</name>
|
||||
<description>cn-user</description>
|
||||
|
||||
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>njcn-common</artifactId>
|
||||
<version>0.0.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>mybatis-plus</artifactId>
|
||||
<version>0.0.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>spingboot2.3.12</artifactId>
|
||||
<version>2.3.12</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,146 @@
|
||||
//package com.njcn.product.cnuser.user.controller;
|
||||
//
|
||||
//import cn.hutool.core.date.DateUnit;
|
||||
//import cn.hutool.core.util.ObjectUtil;
|
||||
//import cn.hutool.core.util.StrUtil;
|
||||
//import com.alibaba.fastjson.JSON;
|
||||
//import com.njcn.common.bean.CustomCacheUtil;
|
||||
//import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
//import com.njcn.common.pojo.constant.OperateType;
|
||||
//import com.njcn.common.pojo.constant.SecurityConstants;
|
||||
//import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
//import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
//import com.njcn.common.pojo.exception.BusinessException;
|
||||
//import com.njcn.common.pojo.response.HttpResult;
|
||||
//import com.njcn.common.utils.JwtUtil;
|
||||
//import com.njcn.common.utils.LogUtil;
|
||||
//import com.njcn.common.utils.RSAUtil;
|
||||
//import com.njcn.product.cnuser.user.pojo.constant.UserValidMessage;
|
||||
//import com.njcn.product.cnuser.user.pojo.param.SysUserParam;
|
||||
//import com.njcn.product.cnuser.user.pojo.po.SysUser;
|
||||
//import com.njcn.product.cnuser.user.pojo.po.Token;
|
||||
//import com.njcn.product.cnuser.user.service.ISysUserService;
|
||||
//import com.njcn.product.cnuser.user.pojo.enums.UserResponseEnum;
|
||||
//
|
||||
//import com.njcn.web.controller.BaseController;
|
||||
//import com.njcn.web.utils.HttpResultUtil;
|
||||
//import com.njcn.web.utils.RequestUtil;
|
||||
//import io.swagger.annotations.Api;
|
||||
//import io.swagger.annotations.ApiOperation;
|
||||
//import lombok.RequiredArgsConstructor;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.springframework.web.bind.annotation.*;
|
||||
//
|
||||
//import javax.servlet.http.HttpServletRequest;
|
||||
//import java.security.KeyPair;
|
||||
//import java.util.Base64;
|
||||
//import java.util.HashMap;
|
||||
//import java.util.Map;
|
||||
//
|
||||
//
|
||||
//@Slf4j
|
||||
//@RestController
|
||||
//@Api(tags = "登录/注销")
|
||||
//@RequestMapping("/admin")
|
||||
//@RequiredArgsConstructor
|
||||
//public class AuthController extends BaseController {
|
||||
//
|
||||
// private final ISysUserService sysUserService;
|
||||
// private final CustomCacheUtil customCacheUtil;
|
||||
// private KeyPair keyPair;
|
||||
//
|
||||
//
|
||||
// @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.AUTHENTICATE)
|
||||
// @PostMapping("/login")
|
||||
// @ApiOperation("登录")
|
||||
// public HttpResult<Object> login(@RequestBody SysUserParam.LoginParam param, HttpServletRequest request) {
|
||||
// String methodDescribe = getMethodDescribe("login");
|
||||
// LogUtil.njcnDebug(log, "{},登录参数为:{}", methodDescribe, param);
|
||||
// byte[] decode = Base64.getDecoder().decode(param.getUsername());
|
||||
// String username = new String(decode);
|
||||
// String password = null;
|
||||
//
|
||||
// try {
|
||||
// password = RSAUtil.decrypt(param.getPassword(), keyPair.getPrivate());
|
||||
// } catch (Exception e) {
|
||||
// throw new BusinessException(UserResponseEnum.RSA_DECRYT_ERROR);
|
||||
// }
|
||||
// // 因不确定是否能登陆成功先将登陆名保存到request,一遍记录谁执行了登录操作
|
||||
// request.setAttribute(SecurityConstants.AUTHENTICATE_USERNAME, username);
|
||||
// SysUser user = sysUserService.getUserByLoginNameAndPassword(username, password);
|
||||
// if (ObjectUtil.isNull(user)) {
|
||||
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, UserValidMessage.LOGIN_FAILED);
|
||||
// } else {
|
||||
// String accessToken = JwtUtil.getAccessToken(user.getId(),username);
|
||||
// String refreshToken = JwtUtil.getRefreshToken(accessToken);
|
||||
// Token token = new Token();
|
||||
// token.setAccessToken(accessToken);
|
||||
// token.setRefreshToken(refreshToken);
|
||||
//
|
||||
// Map<String, Object> map = new HashMap<>();
|
||||
// map.put("name", user.getName());
|
||||
// map.put("id", user.getId());
|
||||
// map.put("loginName",user.getLoginName());
|
||||
//
|
||||
// token.setUserInfo(map);
|
||||
//
|
||||
// customCacheUtil.putWithExpireTime(accessToken, JSON.toJSONString(user), DateUnit.DAY.getMillis() * Integer.MAX_VALUE);
|
||||
// sysUserService.updateLoginTime(user.getId());
|
||||
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, token, methodDescribe);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @OperateInfo(info = LogEnum.SYSTEM_SERIOUS, operateType = OperateType.LOGOUT)
|
||||
// @ApiOperation("注销登录")
|
||||
// @PostMapping("/logout")
|
||||
// public HttpResult<Object> logout() {
|
||||
// String methodDescribe = getMethodDescribe("logout");
|
||||
// LogUtil.njcnDebug(log, "{},注销登录", methodDescribe);
|
||||
// String accessToken = RequestUtil.getAccessToken();
|
||||
// if (StrUtil.isNotBlank(accessToken)) {
|
||||
// customCacheUtil.remove(accessToken);
|
||||
//
|
||||
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
// }
|
||||
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
||||
// }
|
||||
//
|
||||
// @OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
// @ApiOperation("刷新accessToken")
|
||||
// @GetMapping("/refreshToken")
|
||||
// public HttpResult<Object> refreshToken(HttpServletRequest request) {
|
||||
// String methodDescribe = getMethodDescribe("refreshToken");
|
||||
// LogUtil.njcnDebug(log, "{},刷新token", methodDescribe);
|
||||
// String accessToken = RequestUtil.getAccessToken();
|
||||
//
|
||||
// Token token = new Token();
|
||||
// if (StrUtil.isNotBlank(accessToken)) {
|
||||
// Map<String, Object> map = JwtUtil.parseToken(accessToken);
|
||||
// String userId = (String) map.get(SecurityConstants.USER_ID);
|
||||
// SysUser user = sysUserService.getById(userId);
|
||||
// String accessTokenNew = JwtUtil.getAccessToken(userId, user.getLoginName());
|
||||
// request.setAttribute(SecurityConstants.AUTHENTICATE_USERNAME, user.getLoginName());
|
||||
//// String refreshTokenNew = JwtUtil.getRefreshToken(accessTokenNew);
|
||||
//
|
||||
// token.setAccessToken(accessTokenNew);
|
||||
// token.setRefreshToken(accessToken);
|
||||
//
|
||||
// customCacheUtil.putWithExpireTime(accessTokenNew, JSON.toJSONString(user), DateUnit.DAY.getMillis() * Integer.MAX_VALUE);
|
||||
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, token, methodDescribe);
|
||||
// } else {
|
||||
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
// @ApiOperation("获取RSA公钥")
|
||||
// @GetMapping("/getPublicKey")
|
||||
// public HttpResult<String> publicKey(@RequestParam("username") String username, HttpServletRequest request) throws Exception {
|
||||
// String methodDescribe = getMethodDescribe("publicKey");
|
||||
// LogUtil.njcnDebug(log, "{},获取RSA公钥", methodDescribe);
|
||||
// // 因不确定是否能登陆成功先将登陆名保存到request,一遍记录谁执行了登录操作
|
||||
// request.setAttribute(SecurityConstants.AUTHENTICATE_USERNAME, username);
|
||||
// keyPair = RSAUtil.generateKeyPair();
|
||||
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, RSAUtil.publicKeyToString(keyPair.getPublic()), methodDescribe);
|
||||
// }
|
||||
//}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.njcn.product.cnuser.user.controller;
|
||||
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.constant.OperateType;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.LogUtil;
|
||||
import com.njcn.product.cnuser.user.pojo.vo.DeptAllTreeVO;
|
||||
import com.njcn.product.cnuser.user.service.IDeptService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import com.njcn.web.utils.HttpResultUtil;
|
||||
import io.swagger.annotations.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 前端控制器(部门信息)
|
||||
* </p>
|
||||
*
|
||||
* @author hongawen
|
||||
* @since 2021-12-13
|
||||
*/
|
||||
@Validated
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/dept")
|
||||
@Api(tags = "部门管理")
|
||||
@AllArgsConstructor
|
||||
public class DeptController extends BaseController {
|
||||
|
||||
private final IDeptService deptService;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 根据登录用户获取部门树
|
||||
*/
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
@GetMapping("/loginDeptTree")
|
||||
@ApiOperation("根据登录用户获取部门树")
|
||||
public HttpResult<Object> loginDeptTree(@RequestParam("deptIndex")String deptIndex) {
|
||||
String methodDescribe = getMethodDescribe("loginDeptTree");
|
||||
List<DeptAllTreeVO> result = deptService.loginDeptTree(deptIndex);
|
||||
if (!result.isEmpty()) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
} else {
|
||||
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.NO_DATA, null, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
package com.njcn.product.cnuser.user.controller;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.constant.OperateType;
|
||||
import com.njcn.common.pojo.constant.SecurityConstants;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.JwtUtil;
|
||||
import com.njcn.common.utils.LogUtil;
|
||||
import com.njcn.product.cnuser.user.pojo.param.SysFunctionParam;
|
||||
import com.njcn.product.cnuser.user.pojo.param.SysRoleParam;
|
||||
import com.njcn.product.cnuser.user.pojo.po.SysFunction;
|
||||
import com.njcn.product.cnuser.user.pojo.vo.MenuVO;
|
||||
import com.njcn.product.cnuser.user.service.ISysFunctionService;
|
||||
import com.njcn.product.cnuser.user.service.ISysRoleFunctionService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import com.njcn.web.utils.HttpResultUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.logging.log4j.util.Strings;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-11-15
|
||||
*/
|
||||
@Slf4j
|
||||
@Api(tags = "菜单(资源)管理")
|
||||
@RestController
|
||||
@RequestMapping("/sysFunction")
|
||||
@RequiredArgsConstructor
|
||||
public class SysFunctionController extends BaseController {
|
||||
private final ISysFunctionService sysFunctionService;
|
||||
private final ISysRoleFunctionService sysRoleFunctionService;
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
@GetMapping("/getTree")
|
||||
@ApiOperation("按照名称模糊查询菜单树")
|
||||
@ApiImplicitParam(name = "keyword", value = "查询参数", required = true)
|
||||
public HttpResult<List<SysFunction>> getFunctionTreeByKeyword(@RequestParam @Validated String keyword) {
|
||||
String methodDescribe = getMethodDescribe("getFunctionTreeByKeyword");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, keyword);
|
||||
List<SysFunction> result = sysFunctionService.getFunctionTreeByKeyword(keyword);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
@GetMapping("/functionTreeNoButton")
|
||||
@ApiOperation("菜单树-不包括按钮")
|
||||
public HttpResult<List<SysFunction>> getFunctionTreeNoButton() {
|
||||
String methodDescribe = getMethodDescribe("getFunctionTreeNoButton");
|
||||
List<SysFunction> list = sysFunctionService.getFunctionTree(false);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD)
|
||||
@PostMapping("/add")
|
||||
@ApiOperation("新增菜单")
|
||||
@ApiImplicitParam(name = "functionParam", value = "菜单数据", required = true)
|
||||
public HttpResult<Boolean> add(@RequestBody @Validated SysFunctionParam functionParam) {
|
||||
String methodDescribe = getMethodDescribe("add");
|
||||
LogUtil.njcnDebug(log, "{},菜单数据为:{}", methodDescribe, functionParam);
|
||||
boolean result = sysFunctionService.addFunction(functionParam);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.UPDATE)
|
||||
@PostMapping("/update")
|
||||
@ApiOperation("修改菜单")
|
||||
@ApiImplicitParam(name = "functionParam", value = "菜单数据", required = true)
|
||||
public HttpResult<Boolean> update(@RequestBody @Validated SysFunctionParam.UpdateParam functionParam) {
|
||||
String methodDescribe = getMethodDescribe("update");
|
||||
LogUtil.njcnDebug(log, "{},更新的菜单信息为:{}", methodDescribe, functionParam);
|
||||
boolean result = sysFunctionService.updateFunction(functionParam);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.DELETE)
|
||||
@PostMapping("/delete")
|
||||
@ApiOperation("删除菜单")
|
||||
@ApiImplicitParam(name = "id", value = "菜单id", required = true)
|
||||
public HttpResult<Boolean> delete(@RequestParam String id) {
|
||||
String methodDescribe = getMethodDescribe("delete");
|
||||
LogUtil.njcnDebug(log, "{},删除的菜单id为:{}", methodDescribe, id);
|
||||
boolean result = sysFunctionService.deleteFunction(id);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
@GetMapping("/getMenu")
|
||||
@ApiOperation("获取菜单")
|
||||
public HttpResult<List<MenuVO>> getMenu(HttpServletRequest request) {
|
||||
String methodDescribe = getMethodDescribe("getMenu");
|
||||
String tokenStr = request.getHeader(SecurityConstants.AUTHORIZATION_KEY);
|
||||
if (StrUtil.isNotBlank(tokenStr)) {
|
||||
tokenStr = tokenStr.replace(SecurityConstants.AUTHORIZATION_PREFIX, Strings.EMPTY);
|
||||
String userId = (String) (JwtUtil.parseToken(tokenStr).get("userId"));
|
||||
List<MenuVO> list = sysFunctionService.getMenuByUserId(userId);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
|
||||
}
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
@GetMapping("/getButton")
|
||||
@ApiOperation("获取按钮")
|
||||
public HttpResult<Map<String, List<String>>> getButton(HttpServletRequest request) {
|
||||
String methodDescribe = getMethodDescribe("getButton");
|
||||
String tokenStr = request.getHeader(SecurityConstants.AUTHORIZATION_KEY);
|
||||
if (StrUtil.isNotBlank(tokenStr)) {
|
||||
tokenStr = tokenStr.replace(SecurityConstants.AUTHORIZATION_PREFIX, Strings.EMPTY);
|
||||
String userId = (String) JwtUtil.parseToken(tokenStr).get("userId");
|
||||
Map<String, List<String>> map = sysFunctionService.getButtonByUserId(userId);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, map, methodDescribe);
|
||||
}
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
@PostMapping("/getFunctionsByRoleId")
|
||||
@ApiOperation("获取角色id绑定的菜单(资源)")
|
||||
@ApiImplicitParam(name = "id", value = "角色id", required = true)
|
||||
public HttpResult<List<SysFunction>> getFunctionsByRoleId(@RequestParam @Validated String id) {
|
||||
String methodDescribe = getMethodDescribe("getFunctionsByRoleId");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, id);
|
||||
List<SysFunction> sysFunctions = sysRoleFunctionService.listFunctionByRoleId(id);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, sysFunctions, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(operateType = OperateType.UPDATE, info = LogEnum.SYSTEM_MEDIUM)
|
||||
@PostMapping("/assignFunctionByRoleId")
|
||||
@ApiOperation("角色分配菜单")
|
||||
@ApiImplicitParam(name = "roleFunctionComponent", value = "角色信息", required = true)
|
||||
public HttpResult<Boolean> assignFunctionByRoleId(@RequestBody @Validated SysRoleParam.RoleBindFunction param) {
|
||||
String methodDescribe = getMethodDescribe("assignFunctionByRoleId");
|
||||
LogUtil.njcnDebug(log, "{},传入的角色id和资源id集合为:{}", methodDescribe, param);
|
||||
boolean result = sysRoleFunctionService.updateRoleFunction(param.getRoleId(), param.getFunctionIds());
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
package com.njcn.product.cnuser.user.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.constant.OperateType;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.LogUtil;
|
||||
import com.njcn.product.cnuser.user.pojo.param.SysRoleParam;
|
||||
import com.njcn.product.cnuser.user.pojo.po.SysRole;
|
||||
import com.njcn.product.cnuser.user.service.ISysRoleService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import com.njcn.web.utils.HttpResultUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-11-11
|
||||
*/
|
||||
@Slf4j
|
||||
@Api(tags = "角色管理")
|
||||
@RestController
|
||||
@RequestMapping("/sysRole")
|
||||
@RequiredArgsConstructor
|
||||
public class SysRoleController extends BaseController {
|
||||
private final ISysRoleService sysRoleService;
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
@PostMapping("/list")
|
||||
@ApiOperation("分页查询角色")
|
||||
@ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
|
||||
public HttpResult<Page<SysRole>> list(@RequestBody @Validated SysRoleParam.QueryParam queryParam) {
|
||||
String methodDescribe = getMethodDescribe("list");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, queryParam);
|
||||
Page<SysRole> result = sysRoleService.listRole(queryParam);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD)
|
||||
@PostMapping("/add")
|
||||
@ApiOperation("新增角色信息")
|
||||
@ApiImplicitParam(name = "roleParam", value = "角色信息", required = true)
|
||||
public HttpResult<Boolean> add(@RequestBody @Validated SysRoleParam sysRoleParam) {
|
||||
String methodDescribe = getMethodDescribe("add");
|
||||
LogUtil.njcnDebug(log, "{},角色信息数据为:{}", methodDescribe, sysRoleParam);
|
||||
boolean result = sysRoleService.addRole(sysRoleParam);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.UPDATE)
|
||||
@PostMapping("/update")
|
||||
@ApiOperation("修改角色信息")
|
||||
@ApiImplicitParam(name = "updateParam", value = "角色信息", required = true)
|
||||
public HttpResult<Boolean> update(@RequestBody @Validated SysRoleParam.UpdateParam updateParam) {
|
||||
String methodDescribe = getMethodDescribe("update");
|
||||
LogUtil.njcnDebug(log, "{},角色信息数据为:{}", methodDescribe, updateParam);
|
||||
boolean result = sysRoleService.updateRole(updateParam);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.DELETE)
|
||||
@PostMapping("/delete")
|
||||
@ApiOperation("删除角色信息")
|
||||
@ApiImplicitParam(name = "ids", value = "角色id集合", required = true)
|
||||
public HttpResult<Boolean> delete(@RequestBody List<String> ids) {
|
||||
String methodDescribe = getMethodDescribe("delete");
|
||||
LogUtil.njcnDebug(log, "{},角色信息数据为:{}", methodDescribe, ids);
|
||||
boolean result = sysRoleService.deleteRole(ids);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
@GetMapping("/simpleList")
|
||||
@ApiOperation("查询所有角色作为下拉框")
|
||||
public HttpResult<List<SysRole>> simpleList() {
|
||||
String methodDescribe = getMethodDescribe("simpleList");
|
||||
List<SysRole> result = sysRoleService.simpleList();
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
package com.njcn.product.cnuser.user.controller;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.constant.OperateType;
|
||||
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.LogUtil;
|
||||
import com.njcn.product.cnuser.user.pojo.param.SysUserParam;
|
||||
import com.njcn.product.cnuser.user.pojo.po.SysUser;
|
||||
import com.njcn.product.cnuser.user.service.ISysUserService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import com.njcn.web.utils.HttpResultUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @since 2024-11-08
|
||||
*/
|
||||
@Slf4j
|
||||
@Api(tags = "用户管理")
|
||||
@RestController
|
||||
@RequestMapping("/sysUser")
|
||||
@RequiredArgsConstructor
|
||||
public class SysUserController extends BaseController {
|
||||
|
||||
private final ISysUserService sysUserService;
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
@PostMapping("/list")
|
||||
@ApiOperation("分页查询用户列表")
|
||||
@ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
|
||||
public HttpResult<Page<SysUser>> list(@RequestBody @Validated SysUserParam.SysUserQueryParam queryParam) {
|
||||
String methodDescribe = getMethodDescribe("list");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, queryParam);
|
||||
Page<SysUser> result = sysUserService.listUser(queryParam);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD)
|
||||
@PostMapping("/add")
|
||||
@ApiOperation("新增用户")
|
||||
@ApiImplicitParam(name = "addUserParam", value = "新增用户", required = true)
|
||||
public HttpResult<Boolean> add(@RequestBody @Validated SysUserParam.SysUserAddParam addUserParam) {
|
||||
String methodDescribe = getMethodDescribe("add");
|
||||
LogUtil.njcnDebug(log, "{},用户数据为:{}", methodDescribe, addUserParam);
|
||||
boolean result = sysUserService.addUser(addUserParam);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.UPDATE)
|
||||
@PostMapping("/update")
|
||||
@ApiOperation("修改用户")
|
||||
@ApiImplicitParam(name = "updateUserParam", value = "修改用户", required = true)
|
||||
public HttpResult<Boolean> update(@RequestBody @Validated SysUserParam.SysUserUpdateParam updateUserParam) {
|
||||
String methodDescribe = getMethodDescribe("update");
|
||||
LogUtil.njcnDebug(log, "{},用户数据为:{}", methodDescribe, updateUserParam);
|
||||
boolean result = sysUserService.updateUser(updateUserParam);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.DELETE)
|
||||
@PostMapping("/delete")
|
||||
@ApiOperation("批量删除用户")
|
||||
@ApiImplicitParam(name = "ids", value = "用户id", required = true)
|
||||
public HttpResult<Boolean> delete(@RequestBody List<String> ids) {
|
||||
String methodDescribe = getMethodDescribe("delete");
|
||||
LogUtil.njcnDebug(log, "{},用户id为:{}", methodDescribe, String.join(StrUtil.COMMA, ids));
|
||||
boolean result = sysUserService.deleteUser(ids);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.UPDATE)
|
||||
@PostMapping("/updatePassword")
|
||||
@ApiOperation("修改密码")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "用户id", required = true),
|
||||
@ApiImplicitParam(name = "oldPassword", value = "旧密码", required = true),
|
||||
@ApiImplicitParam(name = "newPassword", value = "新密码", required = true)
|
||||
})
|
||||
public HttpResult<Boolean> updatePassword(@RequestBody @Validated SysUserParam.SysUserUpdatePasswordParam param) {
|
||||
String methodDescribe = getMethodDescribe("updatePassword");
|
||||
LogUtil.njcnDebug(log, "{},用户id:{},用户旧密码:{},新密码:{}", methodDescribe, param.getId(), param.getOldPassword(), param.getNewPassword());
|
||||
boolean result = sysUserService.updatePassword(param);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
@GetMapping("/getAll")
|
||||
@ApiOperation("获取所有用户")
|
||||
public HttpResult<List<SysUser>> getAll() {
|
||||
String methodDescribe = getMethodDescribe("getAll");
|
||||
LogUtil.njcnDebug(log, "{},查询所有用户", methodDescribe);
|
||||
List<SysUser> result = sysUserService.lambdaQuery().eq(SysUser::getState, DataStateEnum.ENABLE.getCode()).list();
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.njcn.product.cnuser.user.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
import com.njcn.product.cnuser.user.pojo.dto.DeptDTO;
|
||||
import com.njcn.product.cnuser.user.pojo.po.Dept;
|
||||
import com.njcn.product.cnuser.user.pojo.vo.DeptAllTreeVO;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author hongawen
|
||||
* @since 2021-12-13
|
||||
*/
|
||||
public interface DeptMapper extends BaseMapper<Dept> {
|
||||
|
||||
/**
|
||||
* 根据条件获取后代部门索引
|
||||
* @param id 部门id
|
||||
* @param type 指定部门类型
|
||||
* @return 后代部门索引
|
||||
*/
|
||||
List<DeptDTO> getDeptDescendantIndexes(@Param("id")String id, @Param("type")List<Integer> type);
|
||||
|
||||
/**
|
||||
*
|
||||
* @return 部门树
|
||||
*/
|
||||
List<DeptAllTreeVO> getAllDeptTree(@Param("id")String id, @Param("type")List<Integer> type);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.njcn.product.cnuser.user.mapper;
|
||||
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.njcn.product.cnuser.user.pojo.po.SysFunction;
|
||||
import com.njcn.product.cnuser.user.pojo.vo.MenuVO;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-11-12
|
||||
*/
|
||||
public interface SysFunctionMapper extends MPJBaseMapper<SysFunction> {
|
||||
|
||||
/**
|
||||
* 根据用户id获取菜单列表
|
||||
* @param userId 用户id
|
||||
* @return 菜单列表
|
||||
*/
|
||||
List<MenuVO> getMenuByUserId(String userId);
|
||||
|
||||
/*
|
||||
* 根据用户id获取按钮列表
|
||||
* @param userId 用户id
|
||||
* @return 按钮列表
|
||||
*/
|
||||
List<SysFunction> getButtonByUserId(String userId);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.njcn.product.cnuser.user.mapper;
|
||||
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.njcn.product.cnuser.user.pojo.po.SysFunction;
|
||||
import com.njcn.product.cnuser.user.pojo.po.SysRoleFunction;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-11-12
|
||||
*/
|
||||
public interface SysRoleFunctionMapper extends MPJBaseMapper<SysRoleFunction> {
|
||||
|
||||
/**
|
||||
* 根据角色id获取角色拥有的菜单(资源)列表
|
||||
*
|
||||
* @param roleId 角色id
|
||||
* @return 角色拥有的菜单(资源)列表
|
||||
*/
|
||||
List<SysFunction> getFunctionListByRoleId(@Param("roleId") String roleId);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.njcn.product.cnuser.user.mapper;
|
||||
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.njcn.product.cnuser.user.pojo.po.SysRole;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-11-11
|
||||
*/
|
||||
public interface SysRoleMapper extends MPJBaseMapper<SysRole> {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.njcn.product.cnuser.user.mapper;
|
||||
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.njcn.product.cnuser.user.pojo.po.SysUser;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @since 2024-11-08
|
||||
*/
|
||||
public interface SysUserMapper extends MPJBaseMapper<SysUser> {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.njcn.product.cnuser.user.mapper;
|
||||
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.njcn.product.cnuser.user.pojo.po.SysRole;
|
||||
import com.njcn.product.cnuser.user.pojo.po.SysUserRole;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-11-12
|
||||
*/
|
||||
public interface SysUserRoleMapper extends MPJBaseMapper<SysUserRole> {
|
||||
/**
|
||||
* 根据用户id获取角色详情
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @return 角色结果集
|
||||
*/
|
||||
List<SysRole> getRoleListByUserId(String userId);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.njcn.product.cnuser.user.mapper.SysFunctionMapper">
|
||||
|
||||
|
||||
<select id="getMenuByUserId" resultType="com.njcn.product.cnuser.user.pojo.vo.MenuVO">
|
||||
SELECT distinct a.id as id,
|
||||
a.path as path,
|
||||
a.name as name,
|
||||
a.code as code,
|
||||
a.component as component,
|
||||
a.icon as icon,
|
||||
a.pId as pId,
|
||||
a.sort as sort
|
||||
FROM sys_function a
|
||||
inner join sys_role_function b on a.id = b.Function_Id
|
||||
inner join sys_user_role c on b.Role_Id = c.Role_Id
|
||||
WHERE c.user_Id = #{userId}
|
||||
AND a.type in (0)
|
||||
</select>
|
||||
|
||||
<select id="getButtonByUserId" resultType="com.njcn.product.cnuser.user.pojo.po.SysFunction">
|
||||
select distinct a.*
|
||||
from sys_function a
|
||||
inner join sys_role_function b on a.id = b.Function_Id
|
||||
inner join sys_user_role c on b.Role_Id = c.Role_Id
|
||||
where c.user_Id = #{userId}
|
||||
and a.type in (1)
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.njcn.product.cnuser.user.mapper.SysRoleFunctionMapper">
|
||||
|
||||
<select id="getFunctionListByRoleId" resultType="com.njcn.product.cnuser.user.pojo.po.SysFunction">
|
||||
select b.*
|
||||
from sys_role_function a
|
||||
inner join sys_function b on a.Function_Id = b.id
|
||||
where a.Role_Id = #{roleId} and b.type in (0, 1)
|
||||
and b.state = 1 order by b.sort,b.Update_Time desc
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.njcn.product.cnuser.user.mapper.SysRoleMapper">
|
||||
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.njcn.product.cnuser.user.mapper.SysUserMapper">
|
||||
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.njcn.product.cnuser.user.mapper.SysUserRoleMapper">
|
||||
|
||||
|
||||
<select id="getRoleListByUserId" resultType="com.njcn.product.cnuser.user.pojo.po.SysRole">
|
||||
select b.*
|
||||
from sys_user_role a
|
||||
inner join sys_role b on a.Role_Id = b.id
|
||||
where a.User_Id = #{userId}
|
||||
and b.state = 1
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.njcn.product.cnuser.user.pojo.constant;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024/11/12
|
||||
*/
|
||||
public interface FunctionConst {
|
||||
/**
|
||||
* 资源类型:0-菜单
|
||||
*/
|
||||
int TYPE_MENU =0;
|
||||
|
||||
/**
|
||||
* 资源类型:1-按钮
|
||||
*/
|
||||
int TYPE_BUTTON =1;
|
||||
|
||||
/**
|
||||
* 资源类型:2-公共资源
|
||||
*/
|
||||
int TYPE_PUBLIC =2;
|
||||
|
||||
/**
|
||||
* 资源类型:3-服务间调用资源
|
||||
*/
|
||||
int TYPE_SERVICE_INVOKE_FUNCTION =3;
|
||||
|
||||
/**
|
||||
* 顶级父节点ID
|
||||
*/
|
||||
String FATHER_PID = "0";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.njcn.product.cnuser.user.pojo.constant;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024/11/11
|
||||
*/
|
||||
public interface RoleConst {
|
||||
/**
|
||||
* 角色类型:0-超级管理员
|
||||
*/
|
||||
int TYPE_SUPER_ADMINISTRATOR = 0;
|
||||
|
||||
/**
|
||||
* 角色类型:1-管理员
|
||||
*/
|
||||
int TYPE_ADMINISTRATOR = 1;
|
||||
|
||||
/**
|
||||
* 角色类型:2-用户
|
||||
*/
|
||||
int TYPE_USER = 2;
|
||||
|
||||
/**
|
||||
* 角色类型:3-APP角色
|
||||
*/
|
||||
int TYPE_APP = 3;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.njcn.product.cnuser.user.pojo.constant;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024/11/11
|
||||
*/
|
||||
public interface UserConst {
|
||||
Integer STATE_DELETE = 0;
|
||||
Integer STATE_ENABLE = 1;
|
||||
Integer STATE_LOCKED = 2;
|
||||
Integer STATE_WAITING_FOR_APPROVAL = 3;
|
||||
Integer STATE_SLEEPING = 4;
|
||||
Integer STATE_PASSWORD_EXPIRED = 5;
|
||||
|
||||
String SUPER_ADMIN = "root";
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.njcn.product.cnuser.user.pojo.constant;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024/11/8
|
||||
*/
|
||||
public interface UserValidMessage {
|
||||
|
||||
String ID_NOT_BLANK = "id不能为空,请检查id参数";
|
||||
|
||||
String ID_FORMAT_ERROR = "id格式错误,请检查id参数";
|
||||
|
||||
String DEPT_ID_FORMAT_ERROR = "部门id格式错误,请检查deptId参数";
|
||||
|
||||
String NAME_NOT_BLANK = "名称不能为空,请检查name参数";
|
||||
|
||||
String NAME_FORMAT_ERROR = "名称格式错误,请检查name参数";
|
||||
|
||||
String CODE_NOT_BLANK = "编码不能为空,请检查code参数";
|
||||
|
||||
String LOGIN_NAME_NOT_BLANK = "登录名不能为空,请检查loginName参数";
|
||||
|
||||
String LOGIN_NAME_FORMAT_ERROR = "登录名格式错误,需以字母开头,长度为3-16位的字母或数字";
|
||||
|
||||
String PASSWORD_NOT_BLANK = "密码不能为空,请检查password参数";
|
||||
|
||||
String PASSWORD_FORMAT_ERROR = "密码格式错误,需要包含特殊字符字母数字8-16位";
|
||||
|
||||
String PHONE_FORMAT_ERROR = "电话号码格式错误,请检查phone参数";
|
||||
|
||||
String EMAIL_FORMAT_ERROR = "邮箱格式错误,请检查email参数";
|
||||
|
||||
String OLD_PASSWORD_NOT_BLANK = "旧密码不能为空,请检查oldPassword参数";
|
||||
|
||||
String NEW_PASSWORD_NOT_BLANK = "新密码不能为空,请检查newPassword参数";
|
||||
|
||||
String PID_NOT_BLANK = "父节点id不能为空,请检查pid参数";
|
||||
|
||||
String SORT_NOT_NULL = "排序不能为空,请检查sort参数";
|
||||
|
||||
String TYPE_NOT_BLANK = "类型不能为空,请检查type参数";
|
||||
|
||||
String PARAM_FORMAT_ERROR = "参数值非法";
|
||||
|
||||
String LOGIN_FAILED = "登录失败,用户名或密码错误";
|
||||
|
||||
String FUNCTION_NAME_FORMAT_ERROR = "菜单名称格式错误,只能包含字母、数字、中文、下划线、中划线、空格,长度为1-32个字符";
|
||||
String FUNCTION_CODE_FORMAT_ERROR = "菜单编码格式错误,只能包含字母、数字、下划线、中划线、空格,长度为1-32个字符";
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.njcn.product.cnuser.user.pojo.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2022年02月11日 14:08
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class DeptDTO implements Serializable {
|
||||
|
||||
private String id;
|
||||
|
||||
private String pid;
|
||||
|
||||
private String pids;
|
||||
|
||||
private String name;
|
||||
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 专项分析类型区分
|
||||
*/
|
||||
private Integer specialType;
|
||||
|
||||
private String area;
|
||||
|
||||
private String remark;
|
||||
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 部门类型 0-非自定义;1-web自定义;2-App自定义;3-web测试
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.njcn.product.cnuser.user.pojo.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2021年05月08日 15:12
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class UserDTO {
|
||||
|
||||
private String userIndex;
|
||||
|
||||
private String username;
|
||||
|
||||
private String nickname;
|
||||
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 角色集合
|
||||
*/
|
||||
private List<String> roleName;
|
||||
|
||||
/**
|
||||
* sm4加密秘钥
|
||||
*/
|
||||
private String secretKey;
|
||||
|
||||
/**
|
||||
* sm4中间过程校验
|
||||
*/
|
||||
private String standBy;
|
||||
|
||||
private String deptIndex;
|
||||
|
||||
private Integer type;
|
||||
|
||||
private String headSculpture;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.njcn.product.cnuser.user.pojo.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024/11/9
|
||||
*/
|
||||
@Getter
|
||||
public enum UserResponseEnum {
|
||||
LOGIN_NAME_REPEAT("A010001", "登录名重复,请检查loginName参数"),
|
||||
REGISTER_PHONE_FAIL("A010002", "该号码已被注册"),
|
||||
USER_NAME_REPEAT("A010003", "用户名重复,请检查name参数"),
|
||||
REGISTER_EMAIL_FAIL("A010004", "该邮箱已被注册"),
|
||||
NAME_OR_CODE_REPEAT("A010005", "名称或编码已存在"),
|
||||
EXISTS_SAME_MENU_CHILDREN("A010006", "该层级下已存在相同名称或相同编码或相同路径或相同组件地址的菜单"),
|
||||
EXISTS_CHILDREN_NOT_UPDATE("A010008", "该菜单下存在子节点,无法将菜单修改为按钮"),
|
||||
EXISTS_CHILDREN_NOT_DELETE("A010007", "该节点下存在子节点,无法删除"),
|
||||
SUPER_ADMINSTRATOR_ROLE_CANNOT_UPDATE("A010009", "禁止修改超级管理员角色"),
|
||||
SUPER_ADMINSTRATOR_ROLE_CANNOT_DELETE("A010009", "禁止删除超级管理员角色"),
|
||||
SUPER_ADMIN_CANNOT_DELETE("A010010", "禁止删除超级管理员用户"),
|
||||
COMPONENT_NOT_BLANK("A010011", "组件地址不能为空"),
|
||||
FUNCTION_PATH_FORMAT_ERROR("A010012", "菜单路由地址格式错误,只能包含字母、数字、下划线、中划线、空格、斜线、反斜线,长度为1-32个字符"),
|
||||
FUNCTION_COMPONENT_FORMAT_ERROR("A010013","菜单组件地址格式错误,只能包含字母、数字、下划线、中划线、空格、斜线、反斜线,长度为1-32个字符" ),
|
||||
SUPER_ADMIN_REPEAT("A010013","超级管理员已存在,请勿重复添加" ),
|
||||
RSA_DECRYT_ERROR("A010014","RSA解密失败" ),
|
||||
PASSWORD_SAME("A010015", "新密码不能与旧密码相同"),
|
||||
OLD_PASSWORD_ERROR("A010016", "旧密码错误"), ;
|
||||
|
||||
private String code;
|
||||
private String message;
|
||||
|
||||
UserResponseEnum(String code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.njcn.product.cnuser.user.pojo.param;
|
||||
|
||||
import com.njcn.common.pojo.constant.PatternRegex;
|
||||
import com.njcn.product.cnuser.user.pojo.constant.UserValidMessage;
|
||||
import com.njcn.web.pojo.param.BaseParam;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.hibernate.validator.constraints.Range;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024/11/12
|
||||
*/
|
||||
@Data
|
||||
public class SysFunctionParam {
|
||||
@ApiModelProperty("父节点")
|
||||
@NotBlank(message = UserValidMessage.PID_NOT_BLANK)
|
||||
private String pid;
|
||||
|
||||
@ApiModelProperty("名称")
|
||||
@NotBlank(message = UserValidMessage.NAME_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.FUNCTION_NAME_REGEX, message = UserValidMessage.FUNCTION_NAME_FORMAT_ERROR)
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty("编码")
|
||||
@NotBlank(message = UserValidMessage.CODE_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.FUNCTION_CODE_REGEX, message = UserValidMessage.FUNCTION_CODE_FORMAT_ERROR)
|
||||
private String code;
|
||||
|
||||
@ApiModelProperty("路径")
|
||||
private String path;
|
||||
|
||||
@ApiModelProperty("组件地址")
|
||||
private String component;
|
||||
|
||||
@ApiModelProperty("图标")
|
||||
private String icon;
|
||||
|
||||
@ApiModelProperty("排序")
|
||||
@NotNull(message = UserValidMessage.SORT_NOT_NULL)
|
||||
@Range(min = 0, max = 999, message = UserValidMessage.PARAM_FORMAT_ERROR)
|
||||
private Integer sort;
|
||||
|
||||
@ApiModelProperty("资源类型")
|
||||
@NotNull(message = UserValidMessage.TYPE_NOT_BLANK)
|
||||
@Range(min = 0, max = 3, message = UserValidMessage.PARAM_FORMAT_ERROR)
|
||||
private Integer type;
|
||||
|
||||
@ApiModelProperty("描述")
|
||||
private String remark;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class QueryParam extends BaseParam {
|
||||
@ApiModelProperty("名称")
|
||||
@Pattern(regexp = PatternRegex.FUNCTION_NAME_REGEX, message = UserValidMessage.FUNCTION_NAME_FORMAT_ERROR)
|
||||
private String name;
|
||||
}
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class UpdateParam extends SysFunctionParam {
|
||||
|
||||
@ApiModelProperty("id")
|
||||
@NotBlank(message = UserValidMessage.ID_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = UserValidMessage.ID_FORMAT_ERROR)
|
||||
private String id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.njcn.product.cnuser.user.pojo.param;
|
||||
|
||||
import com.njcn.common.pojo.constant.PatternRegex;
|
||||
import com.njcn.product.cnuser.user.pojo.constant.UserValidMessage;
|
||||
import com.njcn.web.pojo.param.BaseParam;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.hibernate.validator.constraints.Range;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024/11/11
|
||||
*/
|
||||
@Data
|
||||
public class SysRoleParam {
|
||||
|
||||
|
||||
@ApiModelProperty("名称")
|
||||
@NotBlank(message = UserValidMessage.NAME_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.DEPT_NAME_REGEX, message = UserValidMessage.NAME_FORMAT_ERROR)
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty("编码")
|
||||
@NotNull(message = UserValidMessage.CODE_NOT_BLANK)
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 角色类型 0:超级管理员;1:管理员;2:普通用户
|
||||
*/
|
||||
@ApiModelProperty("类型")
|
||||
@Range(min = 0, max = 2, message = UserValidMessage.PARAM_FORMAT_ERROR)
|
||||
private Integer type;
|
||||
|
||||
@ApiModelProperty("描述")
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 更新操作实体
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class UpdateParam extends SysRoleParam {
|
||||
|
||||
@ApiModelProperty("id")
|
||||
@NotBlank(message = UserValidMessage.ID_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = UserValidMessage.ID_FORMAT_ERROR)
|
||||
private String id;
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class QueryParam extends BaseParam {
|
||||
@ApiModelProperty("名称")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty("编码")
|
||||
private String code;
|
||||
|
||||
@ApiModelProperty("类型")
|
||||
private Integer type;
|
||||
}
|
||||
|
||||
/**
|
||||
* 角色绑定菜单(资源)参数
|
||||
*/
|
||||
@Data
|
||||
public static class RoleBindFunction {
|
||||
@ApiModelProperty("角色id")
|
||||
@NotBlank(message = UserValidMessage.ID_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = UserValidMessage.ID_FORMAT_ERROR)
|
||||
private String roleId;
|
||||
|
||||
@ApiModelProperty("菜单ids")
|
||||
private List<String> functionIds;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package com.njcn.product.cnuser.user.pojo.param;
|
||||
|
||||
import com.njcn.common.pojo.constant.PatternRegex;
|
||||
import com.njcn.product.cnuser.user.pojo.constant.UserValidMessage;
|
||||
import com.njcn.web.pojo.param.BaseParam;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024/11/8
|
||||
*/
|
||||
@Data
|
||||
public class SysUserParam {
|
||||
|
||||
@ApiModelProperty("用户名(别名)")
|
||||
@NotBlank(message = UserValidMessage.NAME_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.USERNAME_REGEX, message = UserValidMessage.NAME_FORMAT_ERROR)
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty("部门Id")
|
||||
private String deptId;
|
||||
|
||||
@ApiModelProperty("电话号码")
|
||||
@Pattern(regexp = PatternRegex.PHONE_REGEX_OR_NULL, message = UserValidMessage.PHONE_FORMAT_ERROR)
|
||||
private String phone;
|
||||
|
||||
@ApiModelProperty("邮箱")
|
||||
@Pattern(regexp = PatternRegex.EMAIL_REGEX_OR_NULL, message = UserValidMessage.EMAIL_FORMAT_ERROR)
|
||||
private String email;
|
||||
|
||||
@ApiModelProperty("角色ids")
|
||||
private List<String> roleIds;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class SysUserAddParam extends SysUserParam {
|
||||
|
||||
@ApiModelProperty("登录名")
|
||||
@NotBlank(message = UserValidMessage.LOGIN_NAME_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.LOGIN_NAME_REGEX, message = UserValidMessage.LOGIN_NAME_FORMAT_ERROR)
|
||||
private String loginName;
|
||||
|
||||
@ApiModelProperty("密码")
|
||||
@NotBlank(message = UserValidMessage.PASSWORD_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.PASSWORD_REGEX, message = UserValidMessage.PASSWORD_FORMAT_ERROR)
|
||||
private String password;
|
||||
}
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class SysUserUpdateParam extends SysUserParam {
|
||||
|
||||
@ApiModelProperty("用户表Id")
|
||||
@NotBlank(message = UserValidMessage.ID_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = UserValidMessage.ID_FORMAT_ERROR)
|
||||
private String id;
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class SysUserUpdatePasswordParam {
|
||||
@ApiModelProperty("用户Id")
|
||||
@NotBlank(message = UserValidMessage.ID_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = UserValidMessage.ID_FORMAT_ERROR)
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty("旧密码")
|
||||
@NotBlank(message = UserValidMessage.OLD_PASSWORD_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.PASSWORD_REGEX, message = UserValidMessage.PASSWORD_FORMAT_ERROR)
|
||||
private String oldPassword;
|
||||
|
||||
@ApiModelProperty("新密码")
|
||||
@NotBlank(message = UserValidMessage.NEW_PASSWORD_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.PASSWORD_REGEX, message = UserValidMessage.PASSWORD_FORMAT_ERROR)
|
||||
private String newPassword;
|
||||
}
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class SysUserQueryParam extends BaseParam {
|
||||
@ApiModelProperty("用户名(别名)")
|
||||
private String name;
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class LoginParam {
|
||||
@ApiModelProperty("登录名")
|
||||
@NotBlank(message = UserValidMessage.LOGIN_NAME_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.LOGIN_NAME_REGEX, message = UserValidMessage.LOGIN_NAME_FORMAT_ERROR)
|
||||
private String username;
|
||||
|
||||
@ApiModelProperty("密码")
|
||||
@NotBlank(message = UserValidMessage.PASSWORD_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.PASSWORD_REGEX, message = UserValidMessage.PASSWORD_FORMAT_ERROR)
|
||||
private String password;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.njcn.product.cnuser.user.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.njcn.db.mybatisplus.bo.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author hongawen
|
||||
* @since 2021-12-13
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("sys_dept")
|
||||
public class Dept extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 部门表Id
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 父节点Id(0为根节点)
|
||||
*/
|
||||
private String pid;
|
||||
|
||||
/**
|
||||
* 上层所有节点Id
|
||||
*/
|
||||
private String pids;
|
||||
|
||||
/**
|
||||
* 部门名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 部门编号
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 专项分析类型区分
|
||||
*/
|
||||
private Integer specialType;
|
||||
|
||||
/**
|
||||
* (sys_Area)行政区域Id,自定义部门无需填写部门
|
||||
*/
|
||||
private String area;
|
||||
|
||||
/**
|
||||
* 部门类型 0-非自定义;1-web自定义;2-App自定义;3-web测试
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 部门描述
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 部门状态 0-删除;1-正常;默认正常
|
||||
*/
|
||||
private Integer state;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.njcn.product.cnuser.user.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.njcn.db.mybatisplus.bo.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-11-15
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("sys_function")
|
||||
public class SysFunction extends BaseEntity implements Serializable {
|
||||
private static final long serialVersionUID = -30909841321495323L;
|
||||
|
||||
/**
|
||||
* 资源表Id
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 节点(0为根节点)
|
||||
*/
|
||||
private String pid;
|
||||
|
||||
/**
|
||||
* 上层所有节点
|
||||
*/
|
||||
private String pids;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 编码
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 路径
|
||||
*/
|
||||
private String path;
|
||||
|
||||
/**
|
||||
* 组件地址
|
||||
*/
|
||||
private String component;
|
||||
|
||||
/**
|
||||
* 图标(没有图标默认为:“Null”)
|
||||
*/
|
||||
private String icon;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 资源类型:0-菜单、1-按钮、2-公共资源、3-服务间调用资源
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 权限资源描述
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 权限资源状态:0-删除 1-正常
|
||||
*/
|
||||
private Integer state;
|
||||
|
||||
/**
|
||||
* 子节点
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private List<SysFunction> children;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.njcn.product.cnuser.user.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.njcn.db.mybatisplus.bo.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-11-11
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("sys_role")
|
||||
public class SysRole extends BaseEntity implements Serializable {
|
||||
private static final long serialVersionUID = 183697621480953314L;
|
||||
|
||||
/**
|
||||
* 角色表Id
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 角色名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 编码,有需要用做匹配时候用(关联字典表id)
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 类型:0-超级管理员;1-管理员角色;2-普通角色,默认普通角色
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 状态:0-删除;1-正常;默认正常
|
||||
*/
|
||||
private Integer state;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.njcn.product.cnuser.user.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-11-15
|
||||
*/
|
||||
@Data
|
||||
@TableName("sys_role_function")
|
||||
public class SysRoleFunction implements Serializable {
|
||||
private static final long serialVersionUID = -32044506851166587L;
|
||||
/**
|
||||
* 角色表Id
|
||||
*/
|
||||
private String roleId;
|
||||
|
||||
/**
|
||||
* 资源表Id
|
||||
*/
|
||||
private String functionId;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
package com.njcn.product.cnuser.user.pojo.po;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||
import com.njcn.db.mybatisplus.bo.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @since 2024-11-08
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("sys_user")
|
||||
public class SysUser extends BaseEntity implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -54771740356521149L;
|
||||
|
||||
/**
|
||||
* 用户表Id
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 用户名(别名)
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 登录名
|
||||
*/
|
||||
private String loginName;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 部门Id
|
||||
*/
|
||||
private String deptId;
|
||||
|
||||
/**
|
||||
* 电话号码
|
||||
*/
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 最后一次登录时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
|
||||
@JsonSerialize(using = LocalDateTimeSerializer.class)
|
||||
private LocalDateTime loginTime;
|
||||
|
||||
/**
|
||||
* 密码错误次数
|
||||
*/
|
||||
private Integer loginErrorTimes;
|
||||
|
||||
/**
|
||||
* 用户密码错误锁定时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
|
||||
@JsonSerialize(using = LocalDateTimeSerializer.class)
|
||||
private LocalDateTime lockTime;
|
||||
|
||||
/**
|
||||
* 用户状态 0-删除;1-正常;2-锁定;3-待审核;4-休眠;5-密码过期
|
||||
*/
|
||||
private Integer state;
|
||||
|
||||
@TableField(exist = false)
|
||||
private List<String> roleIds;
|
||||
|
||||
@TableField(exist = false)
|
||||
private List<String> roleNames;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.njcn.product.cnuser.user.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-11-12
|
||||
*/
|
||||
@Data
|
||||
@TableName("sys_user_role")
|
||||
public class SysUserRole implements Serializable {
|
||||
private static final long serialVersionUID = 725290952766199948L;
|
||||
/**
|
||||
* 用户Id
|
||||
*/
|
||||
private String userId;
|
||||
|
||||
/**
|
||||
* 角色Id
|
||||
*/
|
||||
private String roleId;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.njcn.product.cnuser.user.pojo.po;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
public class Token {
|
||||
|
||||
private String accessToken;
|
||||
|
||||
private String refreshToken;
|
||||
|
||||
private Map<String, Object> userInfo;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.njcn.product.cnuser.user.pojo.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author denghuajun
|
||||
* @version 1.0.0
|
||||
* @date 2022年04月15日 11:28
|
||||
*/
|
||||
@Data
|
||||
public class DeptAllTreeVO {
|
||||
|
||||
@ApiModelProperty("id")
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty("名称")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty("父节点id")
|
||||
private String pid;
|
||||
|
||||
@ApiModelProperty("父节点集合")
|
||||
private String pids;
|
||||
|
||||
private Integer sort;
|
||||
|
||||
@ApiModelProperty("子节点详细信息")
|
||||
private List<DeptAllTreeVO> children;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.njcn.product.cnuser.user.pojo.vo;
|
||||
|
||||
import com.njcn.product.cnuser.user.pojo.po.SysFunction;
|
||||
import com.njcn.product.cnuser.user.pojo.vo.MetaVO;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class MenuVO extends SysFunction {
|
||||
|
||||
private String redirect;
|
||||
|
||||
private MetaVO meta;
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.njcn.product.cnuser.user.pojo.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class MetaVO {
|
||||
|
||||
/**
|
||||
* 菜单和面包屑对应的图标
|
||||
*/
|
||||
private String icon;
|
||||
|
||||
/**
|
||||
* 路由标题 (用作 document.title || 菜单的名称)
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 路由外链时填写的访问地址
|
||||
*/
|
||||
@JsonProperty("isLink")
|
||||
private String isLink;
|
||||
|
||||
/**
|
||||
* 是否在菜单中隐藏 (通常列表详情页需要隐藏)
|
||||
*/
|
||||
@JsonProperty("isHide")
|
||||
private boolean isHide;
|
||||
|
||||
/**
|
||||
* 菜单是否全屏 (示例:数据大屏页面)
|
||||
*/
|
||||
@JsonProperty("isFull")
|
||||
private boolean isFull;
|
||||
|
||||
/**
|
||||
* 菜单是否固定在标签页中 (首页通常是固定项)
|
||||
*/
|
||||
@JsonProperty("isAffix")
|
||||
private boolean isAffix;
|
||||
|
||||
/**
|
||||
* 当前路由是否缓存
|
||||
*/
|
||||
@JsonProperty("isKeepAlive")
|
||||
private boolean isKeepAlive;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.njcn.product.cnuser.user.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.product.cnuser.user.pojo.po.Dept;
|
||||
import com.njcn.product.cnuser.user.pojo.vo.DeptAllTreeVO;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author hongawen
|
||||
* @since 2021-12-13
|
||||
*/
|
||||
public interface IDeptService extends IService<Dept> {
|
||||
|
||||
|
||||
/**
|
||||
* 根据登录用户获取区域树
|
||||
* @return 结果
|
||||
*/
|
||||
List<DeptAllTreeVO> loginDeptTree(String deptIndex);
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.njcn.product.cnuser.user.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.product.cnuser.user.pojo.param.SysFunctionParam;
|
||||
import com.njcn.product.cnuser.user.pojo.po.SysFunction;
|
||||
import com.njcn.product.cnuser.user.pojo.vo.MenuVO;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-11-12
|
||||
*/
|
||||
public interface ISysFunctionService extends IService<SysFunction> {
|
||||
|
||||
/**
|
||||
* 根据关键字模糊查询菜单(资源)树
|
||||
*
|
||||
* @param keyword 关键字
|
||||
* @return 菜单(资源)树
|
||||
*/
|
||||
List<SysFunction> getFunctionTreeByKeyword(String keyword);
|
||||
|
||||
/**
|
||||
* 添加菜单(资源)
|
||||
*
|
||||
* @param functionParam 资源参数
|
||||
* @return 是否添加成功
|
||||
*/
|
||||
boolean addFunction(SysFunctionParam functionParam);
|
||||
|
||||
/**
|
||||
* 修改菜单(资源)
|
||||
*
|
||||
* @param functionParam 资源参数
|
||||
* @return 是否更新成功
|
||||
*/
|
||||
boolean updateFunction(SysFunctionParam.UpdateParam functionParam);
|
||||
|
||||
/**
|
||||
* 删除菜单(资源)
|
||||
*
|
||||
* @param id 资源id
|
||||
*/
|
||||
boolean deleteFunction(String id);
|
||||
|
||||
/**
|
||||
* 获取树形结构的菜单(资源
|
||||
*
|
||||
* @param isContainButton 是否包含按钮
|
||||
* @return 树形结构的资源
|
||||
*/
|
||||
List<SysFunction> getFunctionTree(boolean isContainButton);
|
||||
|
||||
/**
|
||||
* 根据用户id获取菜单
|
||||
*
|
||||
* @return 路由菜单
|
||||
*/
|
||||
List<MenuVO> getMenuByUserId(String userId);
|
||||
|
||||
/**
|
||||
* 根据用户id获取按钮
|
||||
* @param userId 用户id
|
||||
* @return 按钮
|
||||
*/
|
||||
Map<String, List<String>> getButtonByUserId(String userId);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.njcn.product.cnuser.user.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.product.cnuser.user.pojo.po.SysFunction;
|
||||
import com.njcn.product.cnuser.user.pojo.po.SysRoleFunction;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-11-12
|
||||
*/
|
||||
public interface ISysRoleFunctionService extends IService<SysRoleFunction> {
|
||||
|
||||
/**
|
||||
* 获取角色id绑定的菜单(资源)
|
||||
*
|
||||
* @param roleId 角色id
|
||||
* @return 菜单(资源)列表
|
||||
*/
|
||||
List<SysFunction> listFunctionByRoleId(String roleId);
|
||||
|
||||
/**
|
||||
* 更新角色菜单(资源)关联数据
|
||||
*
|
||||
* @param roleId 角色id
|
||||
* @param functionIds 菜单(资源)ids
|
||||
* @return 成功返回true,失败返回false
|
||||
*/
|
||||
boolean updateRoleFunction(String roleId, List<String> functionIds);
|
||||
|
||||
/**
|
||||
* 根据角色ids删除角色资源关联数据
|
||||
*
|
||||
* @param roleIds
|
||||
* @return 成功返回true,失败返回false
|
||||
*/
|
||||
boolean deleteRoleFunctionByRoleIds(List<String> roleIds);
|
||||
|
||||
/**
|
||||
* 根据菜单(资源)ids删除角色资源关联数据
|
||||
*
|
||||
* @param functionIds 菜单(资源)ids
|
||||
* @return 成功返回true,失败返回false
|
||||
*/
|
||||
boolean deleteRoleFunctionByFunctionIds(List<String> functionIds);
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.njcn.product.cnuser.user.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.product.cnuser.user.pojo.param.SysRoleParam;
|
||||
import com.njcn.product.cnuser.user.pojo.po.SysRole;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-11-11
|
||||
*/
|
||||
public interface ISysRoleService extends IService<SysRole> {
|
||||
|
||||
/**
|
||||
* 分页查询角色列表
|
||||
*
|
||||
* @param queryParam 查询参数
|
||||
*/
|
||||
Page<SysRole> listRole(SysRoleParam.QueryParam queryParam);
|
||||
|
||||
/**
|
||||
* 新增角色
|
||||
*
|
||||
* @param sysRoleParam 角色参数
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean addRole(SysRoleParam sysRoleParam);
|
||||
|
||||
/**
|
||||
* 更新角色
|
||||
*
|
||||
* @param updateParam 更新参数
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean updateRole(SysRoleParam.UpdateParam updateParam);
|
||||
|
||||
/**
|
||||
* 删除角色
|
||||
*
|
||||
* @param ids 角色id列表
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean deleteRole(List<String> ids);
|
||||
|
||||
/**
|
||||
* 查询所有角色作为下拉框
|
||||
*
|
||||
* @return 角色列表
|
||||
*/
|
||||
List<SysRole> simpleList();
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.njcn.product.cnuser.user.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.product.cnuser.user.pojo.po.SysRole;
|
||||
import com.njcn.product.cnuser.user.pojo.po.SysUserRole;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-11-12
|
||||
*/
|
||||
public interface ISysUserRoleService extends IService<SysUserRole> {
|
||||
|
||||
/**
|
||||
* 根据用户id获取角色
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @return 角色信息
|
||||
*/
|
||||
List<SysRole> listRoleByUserId(String userId);
|
||||
|
||||
/**
|
||||
* 新增用户角色关联数据
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @param roleIds 角色id
|
||||
* @return 成功返回true,失败返回false
|
||||
*/
|
||||
boolean addUserRole(String userId, List<String> roleIds);
|
||||
|
||||
/**
|
||||
* 修改用户角色关联数据
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @param roleIds 角色id
|
||||
* @return 成功返回true,失败返回false
|
||||
*/
|
||||
boolean updateUserRole(String userId, List<String> roleIds);
|
||||
|
||||
/**
|
||||
* 根据用户id删除用户角色关联数据
|
||||
*
|
||||
* @param userIds 用户ids
|
||||
* @return 成功返回true,失败返回false
|
||||
*/
|
||||
boolean deleteUserRoleByUserIds(List<String> userIds);
|
||||
|
||||
/**
|
||||
* 根据角色id删除用户角色关联数据
|
||||
*
|
||||
* @param roleIds 角色ids
|
||||
* @return 成功返回true,失败返回false
|
||||
*/
|
||||
boolean deleteUserRoleByRoleIds(List<String> roleIds);
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package com.njcn.product.cnuser.user.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.product.cnuser.user.pojo.param.SysUserParam;
|
||||
import com.njcn.product.cnuser.user.pojo.po.SysUser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @since 2024-11-08
|
||||
*/
|
||||
public interface ISysUserService extends IService<SysUser> {
|
||||
|
||||
/**
|
||||
* 分页查询用户列表
|
||||
*
|
||||
* @param queryParam 分页查询参数
|
||||
* @return 分页查询结果
|
||||
*/
|
||||
Page<SysUser> listUser(SysUserParam.SysUserQueryParam queryParam);
|
||||
|
||||
/**
|
||||
* 根据登录名查询用户
|
||||
*
|
||||
* @param loginName
|
||||
* @return 用户对象,如果没有查询到则返回null
|
||||
*/
|
||||
SysUser getUserByLoginName(String loginName);
|
||||
|
||||
/**
|
||||
* 根据手机号查询用户
|
||||
*
|
||||
* @param phone 手机号
|
||||
* @param isExcludeSelf 是否排除自己
|
||||
* @param id 排除自己时需要传入自己的ID
|
||||
* @return 用户对象,如果没有查询到则返回null
|
||||
*/
|
||||
SysUser getUserByPhone(String phone, boolean isExcludeSelf, String id);
|
||||
|
||||
/**
|
||||
* 根据用户名(别名)查询用户
|
||||
*
|
||||
* @param name 用户名(别名)
|
||||
* @param isExcludeSelf 是否排除自己
|
||||
* @param id 排除自己时需要传入自己的ID
|
||||
* @return 用户对象,如果没有查询到则返回null
|
||||
*/
|
||||
SysUser getUserByName(String name, boolean isExcludeSelf, String id);
|
||||
|
||||
/**
|
||||
* 根据邮箱查询用户
|
||||
* @param email 邮箱
|
||||
* @param isExcludeSelf 是否排除自己
|
||||
* @param id 排除自己时需要传入自己的ID
|
||||
* @return 用户对象,如果没有查询到则返回null
|
||||
*/
|
||||
SysUser getUserByEmail(String email, boolean isExcludeSelf, String id);
|
||||
|
||||
/**
|
||||
* 新增用户
|
||||
*
|
||||
* @param addUserParam 新增用户参数
|
||||
* @return 结果,true表示新增成功,false表示新增失败
|
||||
*/
|
||||
boolean addUser(SysUserParam.SysUserAddParam addUserParam);
|
||||
|
||||
/**
|
||||
* 更新用户
|
||||
*
|
||||
* @param updateUserParam 更新用户参数
|
||||
* @return 结果,true表示更新成功,false表示更新失败
|
||||
*/
|
||||
boolean updateUser(SysUserParam.SysUserUpdateParam updateUserParam);
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
* @return 结果,true表示修改成功,false表示修改失败
|
||||
*/
|
||||
boolean updatePassword(SysUserParam.SysUserUpdatePasswordParam param);
|
||||
|
||||
/**
|
||||
* 批量删除用户
|
||||
*
|
||||
* @param ids 用户ID列表
|
||||
* @return 结果,true表示删除成功,false表示删除失败
|
||||
*/
|
||||
boolean deleteUser(List<String> ids);
|
||||
|
||||
/**
|
||||
* 根据登录名和密码查询用户
|
||||
*
|
||||
* @param loginName 登录名
|
||||
* @param password 密码
|
||||
* @return 用户对象,如果没有查询到则返回null
|
||||
*/
|
||||
SysUser getUserByLoginNameAndPassword(String loginName, String password);
|
||||
|
||||
/**
|
||||
* 更新用户登录时间为当前时间
|
||||
*
|
||||
* @param userId
|
||||
*/
|
||||
boolean updateLoginTime(String userId);
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.njcn.product.cnuser.user.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.core.lang.tree.TreeNode;
|
||||
import cn.hutool.core.lang.tree.TreeUtil;
|
||||
import cn.hutool.core.text.StrPool;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
|
||||
import com.njcn.product.cnuser.user.mapper.DeptMapper;
|
||||
import com.njcn.product.cnuser.user.pojo.po.Dept;
|
||||
import com.njcn.product.cnuser.user.pojo.vo.DeptAllTreeVO;
|
||||
import com.njcn.product.cnuser.user.service.IDeptService;
|
||||
import com.njcn.web.factory.PageFactory;
|
||||
import com.njcn.web.utils.RequestUtil;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author hongawen
|
||||
* @since 2021-12-13
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements IDeptService {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public List<DeptAllTreeVO> loginDeptTree(String deptIndex) {
|
||||
List<DeptAllTreeVO> deptList = this.baseMapper.getAllDeptTree(deptIndex, Stream.of(0).collect(Collectors.toList()));
|
||||
return deptList.stream()
|
||||
.filter(deptVO -> deptVO.getId().equals(deptIndex))
|
||||
.peek(deptFirst -> deptFirst.setChildren(getChildrens(deptFirst, deptList)))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归查找所有部门的下级部门
|
||||
*/
|
||||
private List<DeptAllTreeVO> getChildrens(DeptAllTreeVO deptFirst, List<DeptAllTreeVO> allDept) {
|
||||
return allDept.stream().filter(dept -> dept.getPid().equals(deptFirst.getId()))
|
||||
.peek(deptVo -> {
|
||||
deptVo.setChildren(getChildrens(deptVo, allDept));
|
||||
}).sorted(Comparator.comparing(DeptAllTreeVO::getSort)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,234 @@
|
||||
package com.njcn.product.cnuser.user.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.common.pojo.constant.PatternRegex;
|
||||
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.product.cnuser.user.pojo.constant.FunctionConst;
|
||||
import com.njcn.product.cnuser.user.pojo.enums.UserResponseEnum;
|
||||
import com.njcn.product.cnuser.user.mapper.SysFunctionMapper;
|
||||
import com.njcn.product.cnuser.user.pojo.param.SysFunctionParam;
|
||||
import com.njcn.product.cnuser.user.pojo.po.SysFunction;
|
||||
import com.njcn.product.cnuser.user.pojo.vo.MenuVO;
|
||||
import com.njcn.product.cnuser.user.pojo.vo.MetaVO;
|
||||
import com.njcn.product.cnuser.user.service.ISysFunctionService;
|
||||
import com.njcn.product.cnuser.user.service.ISysRoleFunctionService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-11-12
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SysFunctionServiceImpl extends ServiceImpl<SysFunctionMapper, SysFunction> implements ISysFunctionService {
|
||||
|
||||
private final ISysRoleFunctionService sysRoleFunctionService;
|
||||
|
||||
@Override
|
||||
public List<SysFunction> getFunctionTreeByKeyword(String keyword) {
|
||||
List<SysFunction> functionTree = this.getFunctionTree(true);
|
||||
filterTreeByName(functionTree, keyword);
|
||||
return functionTree;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean addFunction(SysFunctionParam functionParam) {
|
||||
functionParam.setName(functionParam.getName().trim());
|
||||
functionParam.setPath(functionParam.getPath().trim());
|
||||
functionParam.setComponent(functionParam.getComponent().trim());
|
||||
checkFunctionParam(functionParam, false);
|
||||
SysFunction function = new SysFunction();
|
||||
BeanUtil.copyProperties(functionParam, function);
|
||||
function.setState(DataStateEnum.ENABLE.getCode());
|
||||
if (Objects.equals(functionParam.getPid(), FunctionConst.FATHER_PID)) {
|
||||
function.setPids(FunctionConst.FATHER_PID);
|
||||
} else {
|
||||
SysFunction fatherFunction = this.lambdaQuery().eq(SysFunction::getId, functionParam.getPid()).one();
|
||||
if (Objects.equals(fatherFunction.getPid(), FunctionConst.FATHER_PID)) {
|
||||
function.setPids(functionParam.getPid());
|
||||
} else {
|
||||
String pidS = fatherFunction.getPids();
|
||||
function.setPids(pidS + "," + functionParam.getPid());
|
||||
}
|
||||
}
|
||||
return this.save(function);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean updateFunction(SysFunctionParam.UpdateParam param) {
|
||||
param.setName(param.getName().trim());
|
||||
boolean result = false;
|
||||
param.setPath(param.getPath().trim());
|
||||
param.setComponent(param.getComponent().trim());
|
||||
checkFunctionParam(param, true);
|
||||
SysFunction oldFunction = this.lambdaQuery().eq(SysFunction::getId, param.getId()).eq(SysFunction::getState, DataStateEnum.ENABLE.getCode()).one();
|
||||
List<SysFunction> childrenList = this.lambdaQuery().eq(SysFunction::getPid, param.getId()).eq(SysFunction::getState, DataStateEnum.ENABLE.getCode()).list();
|
||||
if (oldFunction.getType().equals(FunctionConst.TYPE_MENU) && param.getType().equals(FunctionConst.TYPE_BUTTON) && !CollectionUtils.isEmpty(childrenList)) {
|
||||
throw new BusinessException(UserResponseEnum.EXISTS_CHILDREN_NOT_UPDATE);
|
||||
} else {
|
||||
SysFunction function = new SysFunction();
|
||||
BeanUtil.copyProperties(param, function);
|
||||
result = this.updateById(function);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean deleteFunction(String id) {
|
||||
boolean result1 = false;
|
||||
sysRoleFunctionService.deleteRoleFunctionByFunctionIds(Collections.singletonList(id));
|
||||
List<SysFunction> childrenList = this.lambdaQuery().eq(SysFunction::getState, DataStateEnum.ENABLE.getCode()).eq(SysFunction::getPid, id).list();
|
||||
if (CollectionUtils.isEmpty(childrenList)) {
|
||||
result1 = this.lambdaUpdate().set(SysFunction::getState, DataStateEnum.DELETED.getCode()).in(SysFunction::getId, id).update();
|
||||
} else {
|
||||
throw new BusinessException(UserResponseEnum.EXISTS_CHILDREN_NOT_DELETE);
|
||||
}
|
||||
return result1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysFunction> getFunctionTree(boolean isContainButton) {
|
||||
LambdaQueryWrapper<SysFunction> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SysFunction::getState, DataStateEnum.ENABLE.getCode());
|
||||
if (isContainButton) {
|
||||
wrapper.in(SysFunction::getType, FunctionConst.TYPE_MENU, FunctionConst.TYPE_BUTTON);
|
||||
} else {
|
||||
wrapper.in(SysFunction::getType, FunctionConst.TYPE_MENU);
|
||||
}
|
||||
List<SysFunction> allFunctions = this.list(wrapper);
|
||||
return allFunctions.stream().filter(fun -> Objects.equals(FunctionConst.FATHER_PID, fun.getPid())).peek(funS -> funS.setChildren(getChildrenList(funS, allFunctions))).sorted(Comparator.comparingInt(SysFunction::getSort)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MenuVO> getMenuByUserId(String userId) {
|
||||
List<MenuVO> menu = this.baseMapper.getMenuByUserId(userId);
|
||||
menu.stream().forEach(m -> {
|
||||
MetaVO meta = new MetaVO();
|
||||
meta.setIcon(m.getIcon());
|
||||
meta.setTitle(m.getName());
|
||||
meta.setIsLink("");
|
||||
meta.setHide(false);
|
||||
meta.setFull(false);
|
||||
meta.setAffix(false);
|
||||
if("home".equals(m.getCode())){
|
||||
meta.setAffix(true);
|
||||
}
|
||||
meta.setKeepAlive(true);
|
||||
m.setMeta(meta);
|
||||
m.setName(m.getCode());
|
||||
});
|
||||
return menu.stream().filter(fun -> Objects.equals(FunctionConst.FATHER_PID, fun.getPid())).peek(funS -> {
|
||||
List<SysFunction> childrenList = getChildrenList(funS, menu);
|
||||
if (ObjectUtil.isNull(childrenList) || childrenList.size() == 0) {
|
||||
funS.setRedirect(null);
|
||||
} else {
|
||||
funS.setRedirect(funS.getComponent());
|
||||
funS.setComponent(null);
|
||||
}
|
||||
funS.setChildren(childrenList);
|
||||
}).sorted(Comparator.comparingInt(MenuVO::getSort)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, List<String>> getButtonByUserId(String userId) {
|
||||
List<SysFunction> sysFunctions = this.baseMapper.getButtonByUserId(userId);
|
||||
|
||||
Map<String, List<String>> buttonMap = new HashMap<>();
|
||||
sysFunctions.stream().collect(Collectors.groupingBy(SysFunction::getPid)).forEach((k, v) -> {
|
||||
SysFunction fatherFunction = this.getById(k);
|
||||
if (ObjectUtil.isNotNull(fatherFunction)) {
|
||||
buttonMap.put(fatherFunction.getCode(), v.stream().map(SysFunction::getCode).collect(Collectors.toList()));
|
||||
}
|
||||
});
|
||||
return buttonMap;
|
||||
}
|
||||
|
||||
private <T extends SysFunction> List<SysFunction> getChildrenList(T currMenu, List<? extends SysFunction> categories) {
|
||||
return categories.stream().filter(o -> Objects.equals(o.getPid(), currMenu.getId())).peek(o -> o.setChildren(getChildrenList(o, categories))).sorted(Comparator.comparingInt(SysFunction::getSort)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验参数,
|
||||
* 1.检查是否存在相同名称的菜单
|
||||
* 名称 && 路径做唯一判断
|
||||
*/
|
||||
private void checkFunctionParam(SysFunctionParam functionParam, boolean isExcludeSelf) {
|
||||
if (functionParam.getType().equals(FunctionConst.TYPE_MENU)) {
|
||||
if (StrUtil.isBlank(functionParam.getComponent())) {
|
||||
throw new BusinessException(UserResponseEnum.COMPONENT_NOT_BLANK);
|
||||
}
|
||||
if (StrUtil.isBlank(functionParam.getPath()) || !Pattern.matches(PatternRegex.FUNCTION_PATH_REGEX, functionParam.getPath())) {
|
||||
throw new BusinessException(UserResponseEnum.FUNCTION_PATH_FORMAT_ERROR);
|
||||
}
|
||||
if(StrUtil.isBlank(functionParam.getComponent()) || !Pattern.matches(PatternRegex.FUNCTION_COMPONENT_REGEX, functionParam.getComponent())){
|
||||
throw new BusinessException(UserResponseEnum.FUNCTION_COMPONENT_FORMAT_ERROR);
|
||||
}
|
||||
}
|
||||
LambdaQueryWrapper<SysFunction> functionLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
// 同一个pid下,名称、编码、路径、组件地址不能重复
|
||||
functionLambdaQueryWrapper
|
||||
.eq(SysFunction::getPid, functionParam.getPid())
|
||||
.eq(SysFunction::getState, DataStateEnum.ENABLE.getCode())
|
||||
.and(obj -> obj.eq(SysFunction::getName, functionParam.getName()).or()
|
||||
.eq(SysFunction::getCode, functionParam.getCode()).or()
|
||||
.eq(StrUtil.isNotBlank(functionParam.getPath()), SysFunction::getPath, functionParam.getPath()).or()
|
||||
.eq(StrUtil.isNotBlank(functionParam.getComponent()), SysFunction::getComponent, functionParam.getComponent())
|
||||
);
|
||||
//更新的时候,需排除当前记录
|
||||
if (isExcludeSelf) {
|
||||
if (functionParam instanceof SysFunctionParam.UpdateParam) {
|
||||
functionLambdaQueryWrapper.ne(SysFunction::getId, ((SysFunctionParam.UpdateParam) functionParam).getId());
|
||||
}
|
||||
}
|
||||
int countByAccount = this.count(functionLambdaQueryWrapper);
|
||||
//大于等于1个则表示重复
|
||||
if (countByAccount >= 1) {
|
||||
throw new BusinessException(UserResponseEnum.EXISTS_SAME_MENU_CHILDREN);
|
||||
}
|
||||
}
|
||||
|
||||
private List<SysFunction> filterTreeByName(List<SysFunction> tree, String keyword) {
|
||||
if (CollectionUtils.isEmpty(tree) || !StrUtil.isNotBlank(keyword)) {
|
||||
return tree;
|
||||
}
|
||||
filter(tree, keyword);
|
||||
return tree;
|
||||
}
|
||||
|
||||
private void filter(List<SysFunction> list, String keyword) {
|
||||
for (int i = list.size() - 1; i >= 0; i--) {
|
||||
SysFunction function = list.get(i);
|
||||
List<SysFunction> children = function.getChildren();
|
||||
if (!function.getName().contains(keyword)) {
|
||||
if (!CollectionUtils.isEmpty(children)) {
|
||||
filter(children, keyword);
|
||||
}
|
||||
if (CollectionUtils.isEmpty(function.getChildren())) {
|
||||
list.remove(i);
|
||||
}
|
||||
}
|
||||
// else {
|
||||
// if (!CollectionUtils.isEmpty(children)) {
|
||||
// filter(children, keyword);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.njcn.product.cnuser.user.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.product.cnuser.user.mapper.SysRoleFunctionMapper;
|
||||
import com.njcn.product.cnuser.user.pojo.po.SysFunction;
|
||||
import com.njcn.product.cnuser.user.pojo.po.SysRoleFunction;
|
||||
import com.njcn.product.cnuser.user.service.ISysRoleFunctionService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-11-12
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SysRoleFunctionServiceImpl extends ServiceImpl<SysRoleFunctionMapper, SysRoleFunction> implements ISysRoleFunctionService {
|
||||
|
||||
@Override
|
||||
public List<SysFunction> listFunctionByRoleId(String roleId) {
|
||||
return this.baseMapper.getFunctionListByRoleId(roleId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean updateRoleFunction(String roleId, List<String> functionIds) {
|
||||
//删除原有关系
|
||||
this.deleteRoleFunctionByRoleIds(Collections.singletonList(roleId));
|
||||
//新增关系
|
||||
List<SysRoleFunction> roleFunctions = new ArrayList<>();
|
||||
functionIds.forEach(functionId -> {
|
||||
SysRoleFunction roleFunction = new SysRoleFunction();
|
||||
roleFunction.setRoleId(roleId);
|
||||
roleFunction.setFunctionId(functionId);
|
||||
roleFunctions.add(roleFunction);
|
||||
});
|
||||
if (CollectionUtil.isEmpty(roleFunctions)) {
|
||||
return true;
|
||||
} else {
|
||||
return this.saveBatch(roleFunctions);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean deleteRoleFunctionByRoleIds(List<String> roleIds) {
|
||||
LambdaQueryWrapper<SysRoleFunction> lambdaQuery = new LambdaQueryWrapper<>();
|
||||
lambdaQuery.in(SysRoleFunction::getRoleId, roleIds);
|
||||
return this.remove(lambdaQuery);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean deleteRoleFunctionByFunctionIds(List<String> functionIds) {
|
||||
LambdaQueryWrapper<SysRoleFunction> lambdaQuery = new LambdaQueryWrapper<>();
|
||||
lambdaQuery.in(SysRoleFunction::getFunctionId, functionIds);
|
||||
return this.remove(lambdaQuery);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
package com.njcn.product.cnuser.user.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.product.cnuser.user.mapper.SysRoleMapper;
|
||||
import com.njcn.product.cnuser.user.pojo.constant.RoleConst;
|
||||
import com.njcn.product.cnuser.user.pojo.enums.UserResponseEnum;
|
||||
import com.njcn.product.cnuser.user.pojo.param.SysRoleParam;
|
||||
import com.njcn.product.cnuser.user.pojo.po.SysRole;
|
||||
import com.njcn.product.cnuser.user.service.ISysRoleFunctionService;
|
||||
import com.njcn.product.cnuser.user.service.ISysRoleService;
|
||||
import com.njcn.product.cnuser.user.service.ISysUserRoleService;
|
||||
import com.njcn.web.factory.PageFactory;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-11-11
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements ISysRoleService {
|
||||
|
||||
private final ISysUserRoleService sysUserRoleService;
|
||||
private final ISysRoleFunctionService sysRoleFunctionService;
|
||||
|
||||
@Override
|
||||
public Page<SysRole> listRole(SysRoleParam.QueryParam queryParam) {
|
||||
QueryWrapper<SysRole> queryWrapper = new QueryWrapper<>();
|
||||
if (ObjectUtil.isNotNull(queryParam)) {
|
||||
queryWrapper.like(StrUtil.isNotBlank(queryParam.getName()), "sys_role.name", queryParam.getName()).eq(StrUtil.isNotBlank(queryParam.getCode()), "sys_role.code", queryParam.getCode()).eq(ObjectUtil.isNotNull(queryParam.getType()), "sys_role.type", queryParam.getType());
|
||||
}
|
||||
// if (queryParam.getType().equals(0)) {
|
||||
// queryWrapper.in("sys_role.type", queryParam.getType(), 1);
|
||||
// } else if (queryParam.getType().equals(1)) {
|
||||
// queryWrapper.eq("sys_role.type", 2);
|
||||
// }
|
||||
queryWrapper.eq("sys_role.state", DataStateEnum.ENABLE.getCode()).orderByDesc("sys_role.Update_Time");
|
||||
return this.baseMapper.selectPage(new Page<>(PageFactory.getPageNum(queryParam), PageFactory.getPageSize(queryParam)), queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean addRole(SysRoleParam sysRoleParam) {
|
||||
sysRoleParam.setName(sysRoleParam.getName().trim());
|
||||
checkRepeat(sysRoleParam, false);
|
||||
SysRole role = new SysRole();
|
||||
BeanUtil.copyProperties(sysRoleParam, role);
|
||||
//默认为正常状态
|
||||
role.setState(DataStateEnum.ENABLE.getCode());
|
||||
return this.save(role);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean updateRole(SysRoleParam.UpdateParam updateParam) {
|
||||
updateParam.setName(updateParam.getName().trim());
|
||||
checkRepeat(updateParam, true);
|
||||
//不能修改超级管理员角色
|
||||
Integer count = this.lambdaQuery()
|
||||
.in(SysRole::getType, RoleConst.TYPE_SUPER_ADMINISTRATOR)
|
||||
.eq(SysRole::getId, updateParam.getId()).eq(SysRole::getState, DataStateEnum.ENABLE.getCode()).count();
|
||||
if (count > 0) {
|
||||
throw new BusinessException(UserResponseEnum.SUPER_ADMINSTRATOR_ROLE_CANNOT_UPDATE);
|
||||
}
|
||||
SysRole role = new SysRole();
|
||||
BeanUtil.copyProperties(updateParam, role);
|
||||
return this.updateById(role);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean deleteRole(List<String> ids) {
|
||||
//不能删除超级管理员角色
|
||||
Integer count = this.lambdaQuery()
|
||||
.in(SysRole::getType, RoleConst.TYPE_SUPER_ADMINISTRATOR)
|
||||
.in(SysRole::getId, ids).eq(SysRole::getState, DataStateEnum.ENABLE.getCode()).count();
|
||||
if (count > 0) {
|
||||
throw new BusinessException(UserResponseEnum.SUPER_ADMINSTRATOR_ROLE_CANNOT_DELETE);
|
||||
}
|
||||
// 删除角色和用户的绑定
|
||||
sysUserRoleService.deleteUserRoleByRoleIds(ids);
|
||||
//删除角色和资源的绑定
|
||||
sysRoleFunctionService.deleteRoleFunctionByRoleIds(ids);
|
||||
return this.lambdaUpdate().set(SysRole::getState, DataStateEnum.DELETED.getCode()).in(SysRole::getId, ids).update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysRole> simpleList() {
|
||||
LambdaQueryWrapper<SysRole> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.select(SysRole::getId, SysRole::getName).eq(SysRole::getState, DataStateEnum.ENABLE.getCode());
|
||||
return this.baseMapper.selectList(lambdaQueryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验参数,检查是否存在相同名称或编码的角色
|
||||
*/
|
||||
private void checkRepeat(SysRoleParam roleParam, boolean isExcludeSelf) {
|
||||
LambdaQueryWrapper<SysRole> roleLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
roleLambdaQueryWrapper
|
||||
.eq(SysRole::getState, DataStateEnum.ENABLE.getCode())
|
||||
.and(w -> w.eq(SysRole::getName, roleParam.getName()).or().eq(SysRole::getCode, roleParam.getCode()));
|
||||
//更新的时候,需排除当前记录
|
||||
if (isExcludeSelf) {
|
||||
if (roleParam instanceof SysRoleParam.UpdateParam) {
|
||||
roleLambdaQueryWrapper.ne(SysRole::getId, ((SysRoleParam.UpdateParam) roleParam).getId());
|
||||
}
|
||||
}
|
||||
int countByAccount = this.count(roleLambdaQueryWrapper);
|
||||
//大于等于1个则表示重复
|
||||
if (countByAccount >= 1) {
|
||||
throw new BusinessException(UserResponseEnum.NAME_OR_CODE_REPEAT);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.njcn.product.cnuser.user.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.product.cnuser.user.mapper.SysUserRoleMapper;
|
||||
import com.njcn.product.cnuser.user.pojo.po.SysRole;
|
||||
import com.njcn.product.cnuser.user.pojo.po.SysUserRole;
|
||||
import com.njcn.product.cnuser.user.service.ISysUserRoleService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-11-12
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUserRole> implements ISysUserRoleService {
|
||||
|
||||
@Override
|
||||
public List<SysRole> listRoleByUserId(String userId) {
|
||||
return this.baseMapper.getRoleListByUserId(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean addUserRole(String userId, List<String> roleIds) {
|
||||
List<SysUserRole> userRoles = new ArrayList<>();
|
||||
if (!CollectionUtil.isEmpty(roleIds)) {
|
||||
roleIds.forEach(id -> {
|
||||
SysUserRole userRole = new SysUserRole();
|
||||
userRole.setUserId(userId);
|
||||
userRole.setRoleId(id);
|
||||
userRoles.add(userRole);
|
||||
});
|
||||
}
|
||||
return this.saveBatch(userRoles);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean updateUserRole(String userId, List<String> roleIds) {
|
||||
//删除原有关系
|
||||
this.deleteUserRoleByUserIds(Collections.singletonList(userId));
|
||||
//新增关系
|
||||
List<SysUserRole> userROles = new ArrayList<>();
|
||||
roleIds.forEach(role -> {
|
||||
SysUserRole userRole = new SysUserRole();
|
||||
userRole.setUserId(userId);
|
||||
userRole.setRoleId(role);
|
||||
userROles.add(userRole);
|
||||
});
|
||||
return this.saveBatch(userROles);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean deleteUserRoleByUserIds(List<String> userIds) {
|
||||
LambdaQueryWrapper<SysUserRole> lambdaQuery = new LambdaQueryWrapper<>();
|
||||
lambdaQuery.in(SysUserRole::getUserId, userIds);
|
||||
return this.remove(lambdaQuery);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean deleteUserRoleByRoleIds(List<String> roleIds) {
|
||||
LambdaQueryWrapper<SysUserRole> lambdaQuery = new LambdaQueryWrapper<>();
|
||||
lambdaQuery.in(SysUserRole::getRoleId, roleIds);
|
||||
return this.remove(lambdaQuery);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,212 @@
|
||||
package com.njcn.product.cnuser.user.service.impl;
|
||||
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.utils.sm.Sm4Utils;
|
||||
import com.njcn.db.mybatisplus.constant.DbConstant;
|
||||
import com.njcn.product.cnuser.user.pojo.constant.RoleConst;
|
||||
import com.njcn.product.cnuser.user.pojo.constant.UserConst;
|
||||
import com.njcn.product.cnuser.user.pojo.enums.UserResponseEnum;
|
||||
import com.njcn.product.cnuser.user.mapper.SysUserMapper;
|
||||
import com.njcn.product.cnuser.user.pojo.po.SysRole;
|
||||
import com.njcn.product.cnuser.user.pojo.po.SysUser;
|
||||
import com.njcn.product.cnuser.user.service.ISysUserRoleService;
|
||||
import com.njcn.product.cnuser.user.pojo.param.SysUserParam;
|
||||
import com.njcn.product.cnuser.user.service.ISysUserService;
|
||||
import com.njcn.web.factory.PageFactory;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-11-08
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService {
|
||||
|
||||
private final ISysUserRoleService sysUserRoleService;
|
||||
|
||||
@Override
|
||||
public Page<SysUser> listUser(SysUserParam.SysUserQueryParam queryParam) {
|
||||
QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
|
||||
if (ObjectUtil.isNotNull(queryParam)) {
|
||||
queryWrapper.like(StrUtil.isNotBlank(queryParam.getName()), "sys_user.name", queryParam.getName())
|
||||
.between(ObjectUtil.isAllNotEmpty(queryParam.getSearchBeginTime(), queryParam.getSearchEndTime()), "sys_user.Login_Time", queryParam.getSearchBeginTime(), queryParam.getSearchEndTime());
|
||||
//排序
|
||||
if (ObjectUtil.isAllNotEmpty(queryParam.getSortBy(), queryParam.getOrderBy())) {
|
||||
queryWrapper.orderBy(true, queryParam.getOrderBy().equals(DbConstant.ASC), StrUtil.toUnderlineCase(queryParam.getSortBy()));
|
||||
} else {
|
||||
queryWrapper.orderByDesc("sys_user.update_time");
|
||||
}
|
||||
} else {
|
||||
queryWrapper.orderByDesc("sys_user.update_time");
|
||||
}
|
||||
queryWrapper.ne("sys_user.state", UserConst.STATE_DELETE);
|
||||
Page<SysUser> page = this.baseMapper.selectPage(new Page<>(PageFactory.getPageNum(queryParam), PageFactory.getPageSize(queryParam)), queryWrapper);
|
||||
page.getRecords().forEach(sysUser -> {
|
||||
List<SysRole> sysRoles = sysUserRoleService.listRoleByUserId(sysUser.getId());
|
||||
sysUser.setRoleIds(sysRoles.stream().map(SysRole::getId).collect(Collectors.toList()));
|
||||
sysUser.setRoleNames(sysRoles.stream().map(SysRole::getName).collect(Collectors.toList()));
|
||||
});
|
||||
return page;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUser getUserByLoginName(String loginName) {
|
||||
return this.lambdaQuery().ne(SysUser::getState, UserConst.STATE_DELETE).eq(SysUser::getLoginName, loginName).one();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUser getUserByPhone(String phone, boolean isExcludeSelf, String id) {
|
||||
LambdaQueryWrapper<SysUser> lambdaQuery = new LambdaQueryWrapper<>();
|
||||
lambdaQuery.eq(SysUser::getPhone, phone).ne(SysUser::getState, UserConst.STATE_DELETE);
|
||||
if (isExcludeSelf) {
|
||||
lambdaQuery.ne(SysUser::getId, id);
|
||||
}
|
||||
return this.baseMapper.selectOne(lambdaQuery);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUser getUserByName(String name, boolean isExcludeSelf, String id) {
|
||||
LambdaQueryWrapper<SysUser> lambdaQuery = new LambdaQueryWrapper<>();
|
||||
lambdaQuery.eq(SysUser::getName, name).ne(SysUser::getState, UserConst.STATE_DELETE);
|
||||
if (isExcludeSelf) {
|
||||
lambdaQuery.ne(SysUser::getId, id);
|
||||
}
|
||||
return this.baseMapper.selectOne(lambdaQuery);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUser getUserByEmail(String email, boolean isExcludeSelf, String id) {
|
||||
LambdaQueryWrapper<SysUser> lambdaQuery = new LambdaQueryWrapper<>();
|
||||
lambdaQuery.eq(SysUser::getEmail, email).ne(SysUser::getState, UserConst.STATE_DELETE);
|
||||
if (isExcludeSelf) {
|
||||
lambdaQuery.ne(SysUser::getId, id);
|
||||
}
|
||||
return this.baseMapper.selectOne(lambdaQuery);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean addUser(SysUserParam.SysUserAddParam addUserParam) {
|
||||
addUserParam.setName(addUserParam.getName().trim());
|
||||
addUserParam.setLoginName(addUserParam.getLoginName().trim());
|
||||
if (UserConst.SUPER_ADMIN.equals(addUserParam.getLoginName())) {
|
||||
throw new BusinessException(UserResponseEnum.SUPER_ADMIN_REPEAT);
|
||||
}
|
||||
if (!Objects.isNull(getUserByLoginName(addUserParam.getLoginName()))) {
|
||||
throw new BusinessException(UserResponseEnum.LOGIN_NAME_REPEAT);
|
||||
}
|
||||
checkRepeat(addUserParam, false, null);
|
||||
SysUser sysUser = new SysUser();
|
||||
BeanUtils.copyProperties(addUserParam, sysUser);
|
||||
String secretkey = Sm4Utils.globalSecretKey;
|
||||
Sm4Utils sm4 = new Sm4Utils(secretkey);
|
||||
sysUser.setPassword(sm4.encryptData_ECB(sysUser.getPassword()));
|
||||
sysUser.setLoginTime(LocalDateTimeUtil.now());
|
||||
sysUser.setLoginErrorTimes(0);
|
||||
sysUser.setState(UserConst.STATE_ENABLE);
|
||||
boolean result = this.save(sysUser);
|
||||
sysUserRoleService.addUserRole(sysUser.getId(), addUserParam.getRoleIds());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean updateUser(SysUserParam.SysUserUpdateParam updateUserParam) {
|
||||
updateUserParam.setName(updateUserParam.getName().trim());
|
||||
checkRepeat(updateUserParam, true, updateUserParam.getId());
|
||||
SysUser sysUser = new SysUser();
|
||||
BeanUtils.copyProperties(updateUserParam, sysUser);
|
||||
sysUserRoleService.updateUserRole(sysUser.getId(), updateUserParam.getRoleIds());
|
||||
return this.updateById(sysUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean updatePassword(SysUserParam.SysUserUpdatePasswordParam param) {
|
||||
if (param.getOldPassword().equals(param.getNewPassword())) {
|
||||
throw new BusinessException(UserResponseEnum.PASSWORD_SAME);
|
||||
}
|
||||
SysUser user = lambdaQuery().ne(SysUser::getState, UserConst.STATE_DELETE).eq(SysUser::getId, param.getId()).one();
|
||||
if (ObjectUtil.isNotNull(user)) {
|
||||
String secretkey = Sm4Utils.globalSecretKey;
|
||||
Sm4Utils sm4 = new Sm4Utils(secretkey);
|
||||
if (sm4.encryptData_ECB(param.getOldPassword()).equals(user.getPassword())) {
|
||||
user.setPassword(sm4.encryptData_ECB(param.getNewPassword()));
|
||||
return this.updateById(user);
|
||||
}else {
|
||||
throw new BusinessException(UserResponseEnum.OLD_PASSWORD_ERROR);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean deleteUser(List<String> ids) {
|
||||
for (String id : ids) {
|
||||
List<SysRole> sysRoles = sysUserRoleService.listRoleByUserId(id);
|
||||
for (SysRole sysRole : sysRoles) {
|
||||
if (sysRole.getType().equals(RoleConst.TYPE_SUPER_ADMINISTRATOR)) {
|
||||
throw new BusinessException(UserResponseEnum.SUPER_ADMIN_CANNOT_DELETE); // 超级管理员角色不能删除
|
||||
}
|
||||
}
|
||||
}
|
||||
// 删除用户角色关联数据
|
||||
sysUserRoleService.deleteUserRoleByUserIds(ids);
|
||||
return this.lambdaUpdate()
|
||||
.set(SysUser::getState, UserConst.STATE_DELETE)
|
||||
.in(SysUser::getId, ids)
|
||||
.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUser getUserByLoginNameAndPassword(String loginName, String password) {
|
||||
String secretkey = Sm4Utils.globalSecretKey;
|
||||
Sm4Utils sm4 = new Sm4Utils(secretkey);
|
||||
return this.lambdaQuery().ne(SysUser::getState, UserConst.STATE_DELETE)
|
||||
.eq(SysUser::getLoginName, loginName)
|
||||
.eq(SysUser::getPassword, sm4.encryptData_ECB(password)).one();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateLoginTime(String userId) {
|
||||
return this.lambdaUpdate().eq(SysUser::getId, userId).set(SysUser::getLoginTime, LocalDateTimeUtil.now()).update();
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验重复
|
||||
*
|
||||
* @param sysUserParam 检查对象
|
||||
* @param isExcludeSelf 是否排除自己
|
||||
* @param id 排除自己id
|
||||
*/
|
||||
private void checkRepeat(SysUserParam sysUserParam, boolean isExcludeSelf, String id) {
|
||||
if (!Objects.isNull(getUserByName(sysUserParam.getName(), isExcludeSelf, id))) {
|
||||
throw new BusinessException(UserResponseEnum.USER_NAME_REPEAT);
|
||||
}
|
||||
if (StringUtils.isNotBlank(sysUserParam.getPhone()) && !Objects.isNull(getUserByPhone(sysUserParam.getPhone(), isExcludeSelf, id))) {
|
||||
throw new BusinessException(UserResponseEnum.REGISTER_PHONE_FAIL);
|
||||
}
|
||||
if (StringUtils.isNotBlank(sysUserParam.getEmail()) && !Objects.isNull(getUserByEmail(sysUserParam.getEmail(), isExcludeSelf, id))) {
|
||||
throw new BusinessException(UserResponseEnum.REGISTER_EMAIL_FAIL);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user