角色关联资源
This commit is contained in:
@@ -81,7 +81,7 @@ public class PqDevParam {
|
||||
|
||||
@ApiModelProperty(value = "装置是否为加密版本", required = true)
|
||||
@NotNull(message = DeviceValidMessage.ENCRYPTION_NOT_NULL)
|
||||
private Integer encryption;
|
||||
private Integer encryptionFlag;
|
||||
|
||||
@ApiModelProperty("装置识别码(3ds加密)")
|
||||
private String series;
|
||||
@@ -93,7 +93,7 @@ public class PqDevParam {
|
||||
private String sampleId;
|
||||
|
||||
@ApiModelProperty(value = "送样日期")
|
||||
@DateTimeStrValid(message = DeviceValidMessage.ARRIVE_DATE_TIME_FORMAT_ERROR)
|
||||
@DateTimeStrValid(message = DeviceValidMessage.ARRIVE_DATE_FORMAT_ERROR)
|
||||
private String arrivedDate;
|
||||
|
||||
@ApiModelProperty("所属地市名称")
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.njcn.gather.device.device.pojo.vo;
|
||||
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
import com.njcn.common.pojo.constant.PatternRegex;
|
||||
import com.njcn.gather.device.pojo.constant.DeviceValidMessage;
|
||||
import com.njcn.web.pojo.annotation.DateTimeStrValid;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
@@ -51,7 +52,7 @@ public class PqDevExcel implements Serializable {
|
||||
|
||||
@Excel(name = "生产日期(yyyy-MM-dd)", width = 25, format = "yyyy-MM-dd")
|
||||
@NotNull(message = DeviceValidMessage.CREATEDATETIME_NOT_NULL)
|
||||
//@DateTimeStrValid(format = "yyyy-MM-dd", message = DeviceValidMessage.CREATEDATETIME_FORMAT_ERROR)
|
||||
// @DateTimeStrValid(message = DeviceValidMessage.CREATEDATETIME_FORMAT_ERROR)
|
||||
private LocalDate createDate;
|
||||
|
||||
@Excel(name = "出厂编号", width = 40)
|
||||
@@ -79,7 +80,7 @@ public class PqDevExcel implements Serializable {
|
||||
@NotNull(message = DeviceValidMessage.PORT_NOT_NULL)
|
||||
private Integer port;
|
||||
|
||||
@Excel(name = "是否为加密版本(1:是/0:否)", width = 20)
|
||||
@Excel(name = "是否为加密版本(1:是/0:否)", width = 20, replace = {"是_1", "否_0"})
|
||||
@NotNull(message = DeviceValidMessage.ENCRYPTION_NOT_NULL)
|
||||
private Integer encryption;
|
||||
|
||||
@@ -93,7 +94,7 @@ public class PqDevExcel implements Serializable {
|
||||
private String sampleId;
|
||||
|
||||
@Excel(name = "送样日期(yyyy-MM-dd)", width = 25, format = "yyyy-MM-dd")
|
||||
//@DateTimeStrValid(format = "yyyy-MM-dd", message = DeviceValidMessage.ARRIVEDATETIME_FORMAT_ERROR)
|
||||
// @DateTimeStrValid(message = DeviceValidMessage.ARRIVE_DATE_FORMAT_ERROR)
|
||||
private LocalDate arrivedDate;
|
||||
|
||||
@Excel(name = "所属地市名称", width = 20)
|
||||
@@ -108,13 +109,13 @@ public class PqDevExcel implements Serializable {
|
||||
@Excel(name = "检测状态", width = 15)
|
||||
private Integer checkState;
|
||||
|
||||
@Excel(name = "检测结果(1:合格/0:不合格)", width = 15)
|
||||
@Excel(name = "检测结果(1:合格/0:不合格)", width = 15, replace = {"合格_1", "不合格_0"})
|
||||
private Integer checkResult;
|
||||
|
||||
@Excel(name = "报告状态(1:生成/0:未生成)", width = 15)
|
||||
@Excel(name = "报告状态(1:生成/0:未生成)", width = 15, replace = {"生成_1", "未生成_0"})
|
||||
private Integer reportState;
|
||||
|
||||
@Excel(name = "归档状态(1:归档/0:未归档)", width = 15)
|
||||
@Excel(name = "归档状态(1:归档/0:未归档)", width = 15, replace = {"归档_1", "未归档_0"})
|
||||
private Integer documentState;
|
||||
|
||||
@Excel(name = "报告路径", width = 20)
|
||||
|
||||
@@ -40,7 +40,7 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
||||
if (ObjectUtil.isNotNull(queryParam)) {
|
||||
queryWrapper.like(StrUtil.isNotBlank(queryParam.getName()), "pq_dev.name", queryParam.getName())
|
||||
.eq(StrUtil.isNotBlank(queryParam.getDevType()), "pq_dev.dev_type", queryParam.getDevType())
|
||||
.between(ObjectUtil.isAllNotEmpty(queryParam.getSearchBeginTime(), queryParam.getSearchEndTime()), "pq_dev.CreateDate", queryParam.getSearchBeginTime(), queryParam.getSearchEndTime());
|
||||
.between(ObjectUtil.isAllNotEmpty(queryParam.getSearchBeginTime(), queryParam.getSearchEndTime()), "pq_dev.Create_Date", queryParam.getSearchBeginTime(), queryParam.getSearchEndTime());
|
||||
//排序
|
||||
if (ObjectUtil.isAllNotEmpty(queryParam.getSortBy(), queryParam.getOrderBy())) {
|
||||
queryWrapper.orderBy(true, queryParam.getOrderBy().equals(DbConstant.ASC), StrUtil.toUnderlineCase(queryParam.getSortBy()));
|
||||
@@ -118,7 +118,7 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
||||
if (ObjectUtil.isNotNull(queryParam)) {
|
||||
queryWrapper.like(StrUtil.isNotBlank(queryParam.getName()), "pq_dev.name", queryParam.getName())
|
||||
.eq(StrUtil.isNotBlank(queryParam.getDevType()), "pq_dev.dev_type", queryParam.getDevType())
|
||||
.between(ObjectUtil.isAllNotEmpty(queryParam.getSearchBeginTime(), queryParam.getSearchEndTime()), "pq_dev.CreateDate", queryParam.getSearchBeginTime(), queryParam.getSearchEndTime());
|
||||
.between(ObjectUtil.isAllNotEmpty(queryParam.getSearchBeginTime(), queryParam.getSearchEndTime()), "pq_dev.Create_Date", queryParam.getSearchBeginTime(), queryParam.getSearchEndTime());
|
||||
//排序
|
||||
if (ObjectUtil.isAllNotEmpty(queryParam.getSortBy(), queryParam.getOrderBy())) {
|
||||
queryWrapper.orderBy(true, queryParam.getOrderBy().equals(DbConstant.ASC), StrUtil.toUnderlineCase(queryParam.getSortBy()));
|
||||
|
||||
@@ -52,5 +52,5 @@ public interface DeviceValidMessage {
|
||||
|
||||
String PQ_DEV_IDS_NOT_NULL="设备ID集合不能为null,请检查pqDevIds参数";
|
||||
|
||||
String ARRIVE_DATE_TIME_FORMAT_ERROR = "送样日期格式错误,请检查arrivedDateTime参数";
|
||||
String ARRIVE_DATE_FORMAT_ERROR = "送样日期格式错误,请检查arrivedDateTime参数";
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class DictDataExcel implements Serializable {
|
||||
/**
|
||||
* 事件等级:0-普通;1-中等;2-严重(默认为0)
|
||||
*/
|
||||
@Excel(name = "事件等级", width = 15, replace = {"0", "普通", "1", "中等", "2", "严重"})
|
||||
@Excel(name = "事件等级", width = 15, replace = {"普通_0", "中等_1", "严重_2"})
|
||||
private Integer level;
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.njcn.gather.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";
|
||||
|
||||
}
|
||||
@@ -5,8 +5,8 @@ package com.njcn.gather.user.pojo.constant;
|
||||
* @data 2024/11/11
|
||||
*/
|
||||
public interface UserState {
|
||||
Integer DELETED = 0;
|
||||
Integer ENABLED = 1;
|
||||
Integer DELETE = 0;
|
||||
Integer ENABLE = 1;
|
||||
Integer LOCKED = 2;
|
||||
Integer WAITING_FOR_APPROVAL = 3;
|
||||
Integer SLEEPING = 4;
|
||||
|
||||
@@ -40,6 +40,8 @@ public interface UserValidMessage {
|
||||
|
||||
String PATH_NOT_BLANK = "路径不能为空,请检查path参数";
|
||||
|
||||
String COMPONENT_NOT_BLANK = "组件地址不能为空,请检查component参数";
|
||||
|
||||
String PATH_FORMAT_ERROR = "路径格式错误,请检查path参数";
|
||||
|
||||
String TYPE_NOT_BLANK = "类型不能为空,请检查type参数";
|
||||
|
||||
@@ -12,7 +12,9 @@ public enum UserResponseEnum {
|
||||
REGISTER_PHONE_FAIL("A010002", "该号码已被注册"),
|
||||
USER_NAME_REPEAT("A010003", "用户名重复,请检查name参数"),
|
||||
REGISTER_EMAIL_FAIL("A010004", "该邮箱已被注册"),
|
||||
ROLE_NAME_REPEAT("A010005", "角色名称重复");
|
||||
NAME_OR_CODE_REPEAT("A010005", "名称或编码已存在"),
|
||||
EXISTS_SAME_MENU_CHILDREN("A010006", "当前菜单下已存在相同的子菜单"),
|
||||
EXISTS_CHILDREN("A010007", "该节点下存在子节点,请先无法删除");
|
||||
|
||||
private String code;
|
||||
private String message;
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
package com.njcn.gather.user.user.controller;
|
||||
|
||||
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.gather.user.user.pojo.param.SysFunctionParam;
|
||||
import com.njcn.gather.user.user.pojo.param.SysRoleParam;
|
||||
import com.njcn.gather.user.user.pojo.po.SysFunction;
|
||||
import com.njcn.gather.user.user.service.ISysFunctionService;
|
||||
import com.njcn.gather.user.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.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @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("/functionTree")
|
||||
@ApiOperation("菜单树")
|
||||
public HttpResult<List<SysFunction>> getFunctionTree() {
|
||||
String methodDescribe = getMethodDescribe("getFunctionTree");
|
||||
List<SysFunction> list = sysFunctionService.getFunctionTree(true);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
@GetMapping("/functionTreeNoButton")
|
||||
@ApiOperation("菜单树-不包括按钮")
|
||||
public HttpResult<List<SysFunction>> getFunctionTreeNoButton() {
|
||||
String methodDescribe = getMethodDescribe("getFunctionTree");
|
||||
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)
|
||||
@PutMapping("/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("/getFunctionById")
|
||||
// @ApiOperation("菜单详情")
|
||||
// @ApiImplicitParam(name = "id", value = "菜单id", required = true)
|
||||
// public HttpResult<SysFunction> getFunctionById(String id) {
|
||||
// String methodDescribe = getMethodDescribe("getFunctionById");
|
||||
// LogUtil.njcnDebug(log, "{},菜单id为:{}", methodDescribe, id);
|
||||
// SysFunction function = sysFunctionService.getFunctionById(id);
|
||||
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, function, methodDescribe);
|
||||
// }
|
||||
|
||||
// @OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
// @GetMapping("/getButtonById")
|
||||
// @ApiOperation("获取按钮")
|
||||
// @ApiImplicitParam(name = "id", value = "菜单id", required = true)
|
||||
// public HttpResult<List<SysFunction>> getButtonById(String id) {
|
||||
// String methodDescribe = getMethodDescribe("getButtonById");
|
||||
// LogUtil.njcnDebug(log, "{},菜单id为:{}", methodDescribe, id);
|
||||
// List<SysFunction> list = sysFunctionService.getButtonsById(id);
|
||||
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
|
||||
// }
|
||||
|
||||
|
||||
// @OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
// @GetMapping("/getRouteMenu")
|
||||
// @ApiOperation("路由菜单")
|
||||
// public HttpResult<List<SysFunction>> getRouteMenu() {
|
||||
// String methodDescribe = getMethodDescribe("getRouteMenu");
|
||||
// List<SysFunction> list = sysFunctionService.getRouteMenu();
|
||||
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
|
||||
// }
|
||||
|
||||
@OperateInfo(operateType = OperateType.UPDATE, info = LogEnum.SYSTEM_MEDIUM)
|
||||
@PutMapping("/assignFunctionByRoleId")
|
||||
@ApiOperation("角色分配菜单")
|
||||
@ApiImplicitParam(name = "roleFunctionComponent", value = "角色信息", required = true)
|
||||
public HttpResult<Boolean> assignFunctionByRoleIndexes(@RequestBody @Validated SysRoleParam.RoleBindFunction param) {
|
||||
String methodDescribe = getMethodDescribe("assignFunctionByRoleIndexes");
|
||||
LogUtil.njcnDebug(log, "{},传入的角色id和资源id集合为:{}", methodDescribe, param);
|
||||
boolean result = sysRoleFunctionService.updateRoleFunction(param.getRoleId(), param.getFunctionIds());
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
// @OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
// @GetMapping("/userFunctionTree")
|
||||
// @ApiOperation("用户菜单树")
|
||||
// public HttpResult<List<SysFunction>> getUserFunctionTree() {
|
||||
// String methodDescribe = getMethodDescribe("getUserFunctionTree");
|
||||
// List<SysFunction> list = sysFunctionService.getUserFunctionTree();
|
||||
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
package com.njcn.gather.user.user.controller;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.njcn.gather.user.user.pojo.param.SysRoleParam;
|
||||
import com.njcn.gather.user.user.pojo.po.SysRole;
|
||||
import com.njcn.web.utils.HttpResultUtil;
|
||||
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.gather.user.user.pojo.param.SysRoleParam;
|
||||
import com.njcn.gather.user.user.pojo.po.SysFunction;
|
||||
import com.njcn.gather.user.user.pojo.po.SysRole;
|
||||
import com.njcn.gather.user.user.service.ISysRoleFunctionService;
|
||||
import com.njcn.gather.user.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;
|
||||
@@ -36,10 +36,11 @@ import java.util.List;
|
||||
@RequiredArgsConstructor
|
||||
public class SysRoleController extends BaseController {
|
||||
private final ISysRoleService sysRoleService;
|
||||
private final ISysRoleFunctionService sysRoleFunctionService;
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
@PostMapping("/list")
|
||||
@ApiOperation("查询角色信息")
|
||||
@ApiOperation("分页查询角色")
|
||||
@ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
|
||||
public HttpResult<Page<SysRole>> list(@RequestBody @Validated SysRoleParam.QueryParam queryParam) {
|
||||
String methodDescribe = getMethodDescribe("list");
|
||||
@@ -93,53 +94,47 @@ public class SysRoleController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
@PostMapping("/listRoleByIds")
|
||||
@ApiOperation("根据角色id集合查询角色信息")
|
||||
@ApiImplicitParam(name = "ids", value = "角色id集合", required = true)
|
||||
public HttpResult<List<SysRole>> listRoleByIds(@RequestBody List<String> ids) {
|
||||
String methodDescribe = getMethodDescribe("listRoleByIds");
|
||||
List<SysRole> users = sysRoleService.list((new LambdaQueryWrapper<SysRole>().in(CollUtil.isNotEmpty(ids), SysRole::getId, ids)));
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, users, methodDescribe);
|
||||
}
|
||||
// @OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
// @PostMapping("/listRoleByIds")
|
||||
// @ApiOperation("根据角色id集合查询角色信息")
|
||||
// @ApiImplicitParam(name = "ids", value = "角色id集合", required = true)
|
||||
// public HttpResult<List<SysRole>> listRoleByIds(@RequestBody List<String> ids) {
|
||||
// String methodDescribe = getMethodDescribe("listRoleByIds");
|
||||
// List<SysRole> roles = sysRoleService.list((new LambdaQueryWrapper<SysRole>().in(CollUtil.isNotEmpty(ids), SysRole::getId, ids)));
|
||||
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, roles, methodDescribe);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 根据角色id查询相关联的资源和组件
|
||||
*/
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
@PostMapping("/selectFunctionComponent")
|
||||
@ApiOperation("根据角色id查询相关联的资源和组件")
|
||||
@ApiImplicitParam(name = "ids", value = "角色索引", required = true)
|
||||
public HttpResult<Object> selectFunctionComponent(@RequestBody List<String> ids) {
|
||||
String methodDescribe = getMethodDescribe("selectFunctionComponent");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, ids);
|
||||
boolean result = sysRoleService.selectRelevance(ids);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.DELETE_PID_EXIST, null, methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.DELETE_PID_UNEXIST, null, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
@PostMapping("/listRoleByType")
|
||||
@ApiOperation("根据权限类型查询相关角色")
|
||||
@ApiImplicitParam(name = "type", value = "权限类型", required = true)
|
||||
public HttpResult<List<SysRole>> listRoleByType(@RequestParam("type") Integer type) {
|
||||
String methodDescribe = getMethodDescribe("listRoleByType");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, type);
|
||||
List<SysRole> result = sysRoleService.listRoleByType(type);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
@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(info = LogEnum.SYSTEM_COMMON)
|
||||
@GetMapping("/listAllRole")
|
||||
@ApiOperation("查询所有角色")
|
||||
public HttpResult<List<SysRole>> listAllRole() {
|
||||
String methodDescribe = getMethodDescribe("listAllRole");
|
||||
List<SysRole> result = sysRoleService.listAllRole();
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
// @OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
// @PostMapping("/listRoleByType")
|
||||
// @ApiOperation("根据权限类型查询相关角色")
|
||||
// @ApiImplicitParam(name = "type", value = "权限类型", required = true)
|
||||
// public HttpResult<List<SysRole>> listRoleByType(@RequestParam("type") Integer type) {
|
||||
// String methodDescribe = getMethodDescribe("listRoleByType");
|
||||
// LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, type);
|
||||
// List<SysRole> result = sysRoleService.listRoleByType(type);
|
||||
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
// }
|
||||
|
||||
// @OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
// @GetMapping("/listAllRole")
|
||||
// @ApiOperation("查询所有角色")
|
||||
// public HttpResult<List<SysRole>> listAllRole() {
|
||||
// String methodDescribe = getMethodDescribe("listAllRole");
|
||||
// List<SysRole> result = sysRoleService.listAllRole();
|
||||
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
// }
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
@GetMapping("/simpleList")
|
||||
|
||||
@@ -4,7 +4,6 @@ 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.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;
|
||||
@@ -22,9 +21,7 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -91,23 +88,6 @@ public class SysUserController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
//更新redis数据
|
||||
//sysUserService.userRoleList();
|
||||
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)
|
||||
@PutMapping("/update")
|
||||
@ApiOperation("修改用户")
|
||||
@@ -125,6 +105,23 @@ public class SysUserController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
//更新redis数据
|
||||
//sysUserService.userRoleList();
|
||||
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)
|
||||
@PutMapping("/updatePassword")
|
||||
@ApiOperation("修改密码")
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.njcn.gather.user.user.mapper;
|
||||
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.njcn.gather.user.user.pojo.po.SysFunction;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-11-12
|
||||
*/
|
||||
public interface SysFunctionMapper extends MPJBaseMapper<SysFunction> {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.njcn.gather.user.user.mapper;
|
||||
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.njcn.gather.user.user.pojo.po.SysFunction;
|
||||
import com.njcn.gather.user.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,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.gather.user.user.mapper.SysFunctionMapper">
|
||||
|
||||
|
||||
</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.gather.user.user.mapper.SysRoleFunctionMapper">
|
||||
|
||||
<select id="getFunctionListByRoleId" resultType="com.njcn.gather.user.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 (1)
|
||||
and b.state = 1
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
<select id="getRoleListByUserId" resultType="com.njcn.gather.user.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}
|
||||
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,67 @@
|
||||
package com.njcn.gather.user.user.pojo.param;
|
||||
|
||||
import com.njcn.common.pojo.constant.PatternRegex;
|
||||
import com.njcn.gather.user.pojo.constant.UserValidMessage;
|
||||
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, message = UserValidMessage.NAME_FORMAT_ERROR)
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty("编码")
|
||||
@NotBlank(message = UserValidMessage.CODE_NOT_BLANK)
|
||||
private String code;
|
||||
|
||||
@ApiModelProperty("路径")
|
||||
@NotBlank(message = UserValidMessage.PATH_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.FUNCTION_URL, message = UserValidMessage.PATH_FORMAT_ERROR)
|
||||
private String path;
|
||||
|
||||
@ApiModelProperty("组件地址")
|
||||
@NotBlank(message = UserValidMessage.COMPONENT_NOT_BLANK)
|
||||
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 UpdateParam extends SysFunctionParam {
|
||||
|
||||
@ApiModelProperty("id")
|
||||
@NotBlank(message = UserValidMessage.ID_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = UserValidMessage.ID_FORMAT_ERROR)
|
||||
private String id;
|
||||
}
|
||||
}
|
||||
@@ -26,18 +26,18 @@ public class SysRoleParam {
|
||||
@Pattern(regexp = PatternRegex.DEPT_NAME_REGEX, message = UserValidMessage.NAME_FORMAT_ERROR)
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty("角色代码")
|
||||
@ApiModelProperty("编码")
|
||||
@NotNull(message = UserValidMessage.CODE_NOT_BLANK)
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 角色类型 0:超级管理员;1:管理员;2:普通用户
|
||||
*/
|
||||
@ApiModelProperty("角色类型")
|
||||
@ApiModelProperty("类型")
|
||||
@Range(min = 0, max = 2, message = UserValidMessage.PARAM_FORMAT_ERROR)
|
||||
private Integer type;
|
||||
|
||||
@ApiModelProperty("角色描述")
|
||||
@ApiModelProperty("描述")
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
@@ -60,17 +60,24 @@ public class SysRoleParam {
|
||||
@ApiModelProperty("名称")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty("角色编码")
|
||||
@ApiModelProperty("编码")
|
||||
private String code;
|
||||
|
||||
@ApiModelProperty("角色类型")
|
||||
@ApiModelProperty("类型")
|
||||
private Integer type;
|
||||
}
|
||||
|
||||
/**
|
||||
* 角色绑定菜单(资源)参数
|
||||
*/
|
||||
@Data
|
||||
public static class RoleFunctionParam {
|
||||
public static class RoleBindFunction {
|
||||
@ApiModelProperty("角色id")
|
||||
@NotNull(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,88 @@
|
||||
package com.njcn.gather.user.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;
|
||||
}
|
||||
|
||||
@@ -28,22 +28,22 @@ public class SysRole extends BaseEntity implements Serializable {
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 角色代码,有需要用做匹配时候用(关联字典表id)
|
||||
* 编码,有需要用做匹配时候用(关联字典表id)
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 0-超级管理员;1-管理员角色;2-普通角色,默认普通角色
|
||||
* 类型:0-超级管理员;1-管理员角色;2-普通角色,默认普通角色
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 角色描述
|
||||
* 描述
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 角色状态0-删除;1-正常;默认正常
|
||||
* 状态:0-删除;1-正常;默认正常
|
||||
*/
|
||||
private Integer state;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.njcn.gather.user.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-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,76 @@
|
||||
package com.njcn.gather.user.user.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.gather.user.user.pojo.param.SysFunctionParam;
|
||||
import com.njcn.gather.user.user.pojo.param.SysRoleParam;
|
||||
import com.njcn.gather.user.user.pojo.po.SysFunction;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-11-12
|
||||
*/
|
||||
public interface ISysFunctionService extends IService<SysFunction> {
|
||||
|
||||
/**
|
||||
* 添加菜单(资源)
|
||||
*
|
||||
* @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获取菜单(资源)
|
||||
*
|
||||
* @param id 资源id
|
||||
* @return 资源
|
||||
*/
|
||||
//SysFunction getFunctionById(String id);
|
||||
|
||||
/**
|
||||
* 根据菜单(资源)id获取按钮
|
||||
*
|
||||
* @param id 菜单id
|
||||
* @return 菜单下面所有按钮
|
||||
*/
|
||||
//List<SysFunction> getButtonsById(String id);
|
||||
|
||||
/**
|
||||
* 获取路由菜单
|
||||
*
|
||||
* @return 路由菜单
|
||||
*/
|
||||
List<SysFunction> getRouteMenu();
|
||||
|
||||
/**
|
||||
* 获取用户拥有的资源树
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
//List<SysFunction> getUserFunctionTree();
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.njcn.gather.user.user.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.gather.user.user.pojo.po.SysFunction;
|
||||
import com.njcn.gather.user.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 addRoleFunction(String roleId, List<String> functionIds);
|
||||
|
||||
/**
|
||||
* 更新角色菜单(资源)关联数据
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.njcn.gather.user.user.service;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.gather.user.user.pojo.param.SysRoleParam;
|
||||
import com.njcn.gather.user.user.pojo.po.SysFunction;
|
||||
import com.njcn.gather.user.user.pojo.po.SysRole;
|
||||
|
||||
import java.util.List;
|
||||
@@ -49,7 +50,7 @@ public interface ISysRoleService extends IService<SysRole> {
|
||||
*
|
||||
* @return 角色列表
|
||||
*/
|
||||
List<SysRole> listAllRole();
|
||||
//List<SysRole> listAllRole();
|
||||
|
||||
/**
|
||||
* 根据权限类型type获取角色列表
|
||||
@@ -57,7 +58,7 @@ public interface ISysRoleService extends IService<SysRole> {
|
||||
* @param type 角色类型
|
||||
* @return 角色列表
|
||||
*/
|
||||
List<SysRole> listRoleByType(Integer type);
|
||||
//List<SysRole> listRoleByType(Integer type);
|
||||
|
||||
/**
|
||||
* 根据用户id获取角色
|
||||
@@ -65,7 +66,7 @@ public interface ISysRoleService extends IService<SysRole> {
|
||||
* @param userId 用户id
|
||||
* @return 角色列表
|
||||
*/
|
||||
List<SysRole> listRoleByUserId(String userId);
|
||||
//List<SysRole> listRoleByUserId(String userId);
|
||||
|
||||
/**
|
||||
* 查询所有角色作为下拉框
|
||||
@@ -79,5 +80,7 @@ public interface ISysRoleService extends IService<SysRole> {
|
||||
*
|
||||
* @param ids 角色id
|
||||
*/
|
||||
boolean selectRelevance(List<String> ids);
|
||||
// boolean selectRelevance(List<String> ids);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -11,37 +11,46 @@ import java.util.List;
|
||||
* @date 2024-11-12
|
||||
*/
|
||||
public interface ISysUserRoleService extends IService<SysUserRole> {
|
||||
/**
|
||||
* 根据用户id获取 用户--角色关系数据
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 关系数据
|
||||
*/
|
||||
List<SysUserRole> listUserRoleByUserId(String userId);
|
||||
|
||||
/**
|
||||
* 新增用户和角色的关系
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @param roleIds 角色id
|
||||
* @return boolean
|
||||
*/
|
||||
boolean addUserRole(String userId, List<String> roleIds);
|
||||
|
||||
/**
|
||||
* 修改用户和角色的关系
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @param roleIds 角色id
|
||||
* @return boolean
|
||||
*/
|
||||
boolean updateUserRole(String userId, List<String> roleIds);
|
||||
|
||||
/**
|
||||
* 根据用户id获取角色详情
|
||||
* 根据用户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,180 @@
|
||||
package com.njcn.gather.user.user.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
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.gather.user.pojo.constant.FunctionConst;
|
||||
import com.njcn.gather.user.pojo.enums.UserResponseEnum;
|
||||
import com.njcn.gather.user.user.mapper.SysFunctionMapper;
|
||||
import com.njcn.gather.user.user.pojo.param.SysFunctionParam;
|
||||
import com.njcn.gather.user.user.pojo.po.SysFunction;
|
||||
import com.njcn.gather.user.user.service.ISysFunctionService;
|
||||
import com.njcn.gather.user.user.service.ISysRoleFunctionService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
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 boolean addFunction(SysFunctionParam functionParam) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
boolean result = this.save(function);
|
||||
//if (result) {
|
||||
//refreshRolesFunctionsCache();
|
||||
//}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateFunction(SysFunctionParam.UpdateParam param) {
|
||||
checkFunctionParam(param, true);
|
||||
SysFunction function = new SysFunction();
|
||||
BeanUtil.copyProperties(param, function);
|
||||
boolean result = this.updateById(function);
|
||||
// if (result) {
|
||||
// refreshRolesFunctionsCache();
|
||||
// }
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
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();
|
||||
// if (result) {
|
||||
// refreshRolesFunctionsCache();
|
||||
// }
|
||||
} else {
|
||||
throw new BusinessException(UserResponseEnum.EXISTS_CHILDREN);
|
||||
}
|
||||
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 SysFunction getFunctionById(String id) {
|
||||
// return this.lambdaQuery().eq(SysFunction::getId, id).one();
|
||||
// }
|
||||
|
||||
// @Override
|
||||
// public List<SysFunction> getButtonsById(String id) {
|
||||
// List<Integer> typeList = Arrays.asList(FunctionConst.TYPE_MENU, FunctionConst.TYPE_BUTTON);
|
||||
// return this.lambdaQuery()
|
||||
// .eq(SysFunction::getPid, id)
|
||||
// .in(SysFunction::getType, typeList)
|
||||
// .eq(SysFunction::getState, DataStateEnum.ENABLE.getCode())
|
||||
// .orderByAsc(SysFunction::getSort).list();
|
||||
// }
|
||||
|
||||
@Override
|
||||
public List<SysFunction> getRouteMenu() {
|
||||
// List<SysFunction> result = new ArrayList<>();
|
||||
// List<String> functionIds;
|
||||
// if (Objects.equals(RequestUtil.getUsername(), UserType.SUPER_ADMIN)) {
|
||||
// //查询所有菜单
|
||||
// functionIds = this.lambdaQuery().eq(SysFunction::getState, DataStateEnum.ENABLE.getCode()).list().stream().map(SysFunction::getId).distinct().collect(Collectors.toList());
|
||||
// } else {
|
||||
// List<String> roleIdList = sysUserRoleService.listRoleByUserId(RequestUtil.getUserIndex()).stream().map(SysUserRole::getRoleId).distinct().collect(Collectors.toList());
|
||||
// functionIds = sysRoleFunctionService.listRoleFunctionByRoleIds(roleIdList).stream().map(SysRoleFunction::getFunctionId).distinct().collect(Collectors.toList());
|
||||
// }
|
||||
// if (CollectionUtils.isEmpty(functionIds)) {
|
||||
// return result;
|
||||
// }
|
||||
// List<SysFunction> functionList = this.lambdaQuery().eq(SysFunction::getState, DataStateEnum.ENABLE.getCode())
|
||||
// .in(SysFunction::getId, functionIds)
|
||||
// .in(SysFunction::getType, FunctionConst.TYPE_MENU, FunctionConst.TYPE_BUTTON).list();
|
||||
// result = functionList.stream()
|
||||
// .filter(fun -> Objects.equals(FunctionConst.FATHER_PID, fun.getPid().trim()))
|
||||
// .peek(funS -> funS.setChildren(getChildrenList(funS, functionList)))
|
||||
// .sorted(Comparator.comparingInt(SysFunction::getSort))
|
||||
// .collect(Collectors.toList());
|
||||
// //组装驾驶舱
|
||||
// setDriverChildren(result);
|
||||
// 处理tab页
|
||||
// setTab(result);
|
||||
// return result;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public List<SysFunction> getUserFunctionTree() {
|
||||
// return Collections.emptyList();
|
||||
// }
|
||||
|
||||
/**
|
||||
* 根据当前分类找出子类,递归找出子类的子类
|
||||
*/
|
||||
private List<SysFunction> getChildrenList(SysFunction currMenu, List<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) {
|
||||
LambdaQueryWrapper<SysFunction> functionLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
// 同一个pid下,名称、编码、路径、组件地址不能重复
|
||||
functionLambdaQueryWrapper.eq(SysFunction::getName, functionParam.getName()).eq(SysFunction::getCode, functionParam.getCode()).eq(SysFunction::getPath, functionParam.getPath()).eq(SysFunction::getComponent, functionParam.getComponent()).eq(SysFunction::getPid, functionParam.getPid()).eq(SysFunction::getState, DataStateEnum.ENABLE.getCode());
|
||||
//更新的时候,需排除当前记录
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.njcn.gather.user.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.gather.user.user.mapper.SysRoleFunctionMapper;
|
||||
import com.njcn.gather.user.user.pojo.po.SysFunction;
|
||||
import com.njcn.gather.user.user.pojo.po.SysRoleFunction;
|
||||
import com.njcn.gather.user.user.service.ISysRoleFunctionService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
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
|
||||
public boolean addRoleFunction(String roleId, List<String> functionIds) {
|
||||
List<SysRoleFunction> roleFunctions = new ArrayList<>();
|
||||
if (!CollectionUtil.isEmpty(functionIds)) {
|
||||
functionIds.forEach(functionId -> {
|
||||
SysRoleFunction roleFunction = new SysRoleFunction();
|
||||
roleFunction.setRoleId(roleId);
|
||||
roleFunction.setFunctionId(functionId);
|
||||
roleFunctions.add(roleFunction);
|
||||
});
|
||||
}
|
||||
return this.saveBatch(roleFunctions);
|
||||
}
|
||||
|
||||
@Override
|
||||
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);
|
||||
});
|
||||
return this.saveBatch(roleFunctions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteRoleFunctionByRoleIds(List<String> roleIds) {
|
||||
LambdaQueryWrapper<SysRoleFunction> lambdaQuery = new LambdaQueryWrapper<>();
|
||||
lambdaQuery.in(SysRoleFunction::getRoleId, roleIds);
|
||||
return this.remove(lambdaQuery);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteRoleFunctionByFunctionIds(List<String> functionIds) {
|
||||
LambdaQueryWrapper<SysRoleFunction> lambdaQuery = new LambdaQueryWrapper<>();
|
||||
lambdaQuery.in(SysRoleFunction::getFunctionId, functionIds);
|
||||
return this.remove(lambdaQuery);
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import com.njcn.gather.user.pojo.enums.UserResponseEnum;
|
||||
import com.njcn.gather.user.user.mapper.SysRoleMapper;
|
||||
import com.njcn.gather.user.user.pojo.param.SysRoleParam;
|
||||
import com.njcn.gather.user.user.pojo.po.SysRole;
|
||||
import com.njcn.gather.user.user.service.ISysRoleFunctionService;
|
||||
import com.njcn.gather.user.user.service.ISysRoleService;
|
||||
import com.njcn.gather.user.user.service.ISysUserRoleService;
|
||||
import com.njcn.web.factory.PageFactory;
|
||||
@@ -32,14 +33,15 @@ import java.util.List;
|
||||
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.eq(StrUtil.isNotBlank(queryParam.getName()), "sys_role.name", queryParam.getName());
|
||||
queryWrapper.eq(StrUtil.isNotBlank(queryParam.getCode()), "sys_role.code", queryParam.getCode());
|
||||
queryWrapper.eq(ObjectUtil.isNotNull(queryParam.getType()), "sys_role.type", queryParam.getType());
|
||||
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);
|
||||
@@ -52,7 +54,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
||||
|
||||
@Override
|
||||
public boolean addRole(SysRoleParam sysRoleParam) {
|
||||
checkCode(sysRoleParam, false);
|
||||
checkRepeat(sysRoleParam, false);
|
||||
SysRole role = new SysRole();
|
||||
BeanUtil.copyProperties(sysRoleParam, role);
|
||||
//默认为正常状态
|
||||
@@ -62,7 +64,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
||||
|
||||
@Override
|
||||
public boolean updateRole(SysRoleParam.UpdateParam updateParam) {
|
||||
checkCode(updateParam, true);
|
||||
checkRepeat(updateParam, true);
|
||||
SysRole role = new SysRole();
|
||||
BeanUtil.copyProperties(updateParam, role);
|
||||
return this.updateById(role);
|
||||
@@ -70,33 +72,31 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
||||
|
||||
@Override
|
||||
public boolean deleteRole(List<String> ids) {
|
||||
//todo
|
||||
|
||||
// 删除角色和用户的绑定
|
||||
//this.baseMapper.deleteUserRole(ids);
|
||||
// 删除角色和资源的绑定
|
||||
//this.baseMapper.deleteFunctionRole(ids);
|
||||
// 删除角色和组件的绑定
|
||||
//this.baseMapper.deleteComponentRole(ids);
|
||||
return this.lambdaUpdate().set(SysRole::getState, DataStateEnum.DELETED.getCode()).in(SysRole::getId, ids).update();
|
||||
sysUserRoleService.deleteUserRoleByRoleIds(ids);
|
||||
//删除角色和资源的绑定
|
||||
sysRoleFunctionService.deleteRoleFunctionByRoleIds(ids);
|
||||
return this.lambdaUpdate()
|
||||
.set(SysRole::getState, DataStateEnum.DELETED.getCode())
|
||||
.in(SysRole::getId, ids).update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysRole> listAllRole() {
|
||||
QueryWrapper<SysRole> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.ne("sys_role.state", DataStateEnum.DELETED.getCode());
|
||||
return this.baseMapper.selectList(queryWrapper);
|
||||
}
|
||||
// @Override
|
||||
// public List<SysRole> listAllRole() {
|
||||
// QueryWrapper<SysRole> queryWrapper = new QueryWrapper<>();
|
||||
// queryWrapper.ne("sys_role.state", DataStateEnum.DELETED.getCode());
|
||||
// return this.baseMapper.selectList(queryWrapper);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public List<SysRole> listRoleByType(Integer type) {
|
||||
return this.lambdaQuery().eq(SysRole::getType, type).eq(SysRole::getState, DataStateEnum.ENABLE.getCode()).list();
|
||||
}
|
||||
// @Override
|
||||
// public List<SysRole> listRoleByType(Integer type) {
|
||||
// return this.lambdaQuery().eq(SysRole::getType, type).eq(SysRole::getState, DataStateEnum.ENABLE.getCode()).list();
|
||||
// }
|
||||
|
||||
@Override
|
||||
public List<SysRole> listRoleByUserId(String userId) {
|
||||
return sysUserRoleService.listRoleByUserId(userId);
|
||||
}
|
||||
// @Override
|
||||
// public List<SysRole> listRoleByUserId(String userId) {
|
||||
// return sysUserRoleService.listRoleByUserId(userId);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public List<SysRole> simpleList() {
|
||||
@@ -106,26 +106,29 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
||||
return this.baseMapper.selectList(lambdaQueryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean selectRelevance(List<String> ids) {
|
||||
// 判断角色是否和用户绑定
|
||||
//List<UserRole> userRoleList = this.userRoleMapper.selectUserRole(ids);
|
||||
// 判断角色是否和资源绑定
|
||||
//List<RoleFunction> roleFunctionList = this.roleFunctionMapper.selectRoleFunction(ids);
|
||||
// 判断角色是否和组件绑定
|
||||
//List<RoleComponent> roleComponentList = this.roleComponentMapper.selectRoleComponet(ids);
|
||||
//if (!userRoleList.isEmpty() || !roleComponentList.isEmpty() || !roleFunctionList.isEmpty()) {
|
||||
// return true;
|
||||
//}
|
||||
return false;
|
||||
}
|
||||
// @Override
|
||||
// public boolean selectRelevance(List<String> ids) {
|
||||
// // 判断角色是否和用户绑定
|
||||
// List<UserRole> userRoleList = this.userRoleMapper.selectUserRole(ids);
|
||||
// // 判断角色是否和资源绑定
|
||||
// List<RoleFunction> roleFunctionList = this.roleFunctionMapper.selectRoleFunction(ids);
|
||||
// // 判断角色是否和组件绑定
|
||||
// List<RoleComponent> roleComponentList = this.roleComponentMapper.selectRoleComponet(ids);
|
||||
// if (!userRoleList.isEmpty() || !roleComponentList.isEmpty() || !roleFunctionList.isEmpty()) {
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 校验参数,检查是否存在相同编码的角色
|
||||
* 校验参数,检查是否存在相同名称或编码的角色
|
||||
*/
|
||||
private void checkCode(SysRoleParam roleParam, boolean isExcludeSelf) {
|
||||
private void checkRepeat(SysRoleParam roleParam, boolean isExcludeSelf) {
|
||||
LambdaQueryWrapper<SysRole> roleLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
roleLambdaQueryWrapper.eq(SysRole::getName, roleParam.getName()).eq(SysRole::getState, DataStateEnum.ENABLE.getCode());
|
||||
roleLambdaQueryWrapper
|
||||
.eq(SysRole::getName, roleParam.getName())
|
||||
.eq(SysRole::getCode, roleParam.getCode())
|
||||
.eq(SysRole::getState, DataStateEnum.ENABLE.getCode());
|
||||
//更新的时候,需排除当前记录
|
||||
if (isExcludeSelf) {
|
||||
if (roleParam instanceof SysRoleParam.UpdateParam) {
|
||||
@@ -135,7 +138,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
||||
int countByAccount = this.count(roleLambdaQueryWrapper);
|
||||
//大于等于1个则表示重复
|
||||
if (countByAccount >= 1) {
|
||||
throw new BusinessException(UserResponseEnum.ROLE_NAME_REPEAT);
|
||||
throw new BusinessException(UserResponseEnum.NAME_OR_CODE_REPEAT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.njcn.gather.user.user.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.gather.user.user.mapper.SysUserRoleMapper;
|
||||
import com.njcn.gather.user.user.pojo.po.SysRole;
|
||||
@@ -11,10 +10,10 @@ import com.njcn.gather.user.user.service.ISysUserRoleService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
@@ -25,49 +24,51 @@ import java.util.stream.Collectors;
|
||||
@RequiredArgsConstructor
|
||||
public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUserRole> implements ISysUserRoleService {
|
||||
|
||||
private final SysUserRoleMapper sysUserRoleMapper;
|
||||
|
||||
@Override
|
||||
public List<SysUserRole> listUserRoleByUserId(String userId) {
|
||||
return this.lambdaQuery().eq(SysUserRole::getUserId, userId).list();
|
||||
public List<SysRole> listRoleByUserId(String userId) {
|
||||
return this.baseMapper.getRoleListByUserId(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addUserRole(String userId, List<String> roleIds) {
|
||||
boolean result = false;
|
||||
List<SysUserRole> userRoles = new ArrayList<>();
|
||||
if (!CollectionUtil.isEmpty(roleIds)) {
|
||||
roleIds.forEach(id -> {
|
||||
SysUserRole userRole = new SysUserRole();
|
||||
userRole.setUserId(userId);
|
||||
roleIds.forEach(id -> {
|
||||
userRole.setRoleId(id);
|
||||
this.save(userRole);
|
||||
userRoles.add(userRole);
|
||||
});
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
return this.saveBatch(userRoles);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateUserRole(String userId, List<String> roleIds) {
|
||||
//删除原有关系
|
||||
List<String> userRoleList = this.lambdaQuery().eq(SysUserRole::getUserId, userId).list().stream().map(SysUserRole::getRoleId).collect(Collectors.toList());
|
||||
LambdaQueryWrapper<SysUserRole> lambdaQuery = Wrappers.lambdaQuery();
|
||||
if (!CollectionUtils.isEmpty(userRoleList)) {
|
||||
lambdaQuery.eq(SysUserRole::getUserId, userId).in(SysUserRole::getRoleId, userRoleList);
|
||||
sysUserRoleMapper.delete(lambdaQuery);
|
||||
}
|
||||
this.deleteUserRoleByUserIds(Collections.singletonList(userId));
|
||||
//新增关系
|
||||
List<SysUserRole> userROles = new ArrayList<>();
|
||||
roleIds.forEach(role -> {
|
||||
SysUserRole userRole = new SysUserRole();
|
||||
userRole.setUserId(userId);
|
||||
userRole.setRoleId(role);
|
||||
this.save(userRole);
|
||||
userROles.add(userRole);
|
||||
});
|
||||
return true;
|
||||
return this.saveBatch(userROles);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysRole> listRoleByUserId(String userId) {
|
||||
return this.baseMapper.getRoleListByUserId(userId);
|
||||
public boolean deleteUserRoleByUserIds(List<String> userIds) {
|
||||
LambdaQueryWrapper<SysUserRole> lambdaQuery = new LambdaQueryWrapper<>();
|
||||
lambdaQuery.in(SysUserRole::getUserId, userIds);
|
||||
return this.remove(lambdaQuery);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteUserRoleByRoleIds(List<String> roleIds) {
|
||||
LambdaQueryWrapper<SysUserRole> lambdaQuery = new LambdaQueryWrapper<>();
|
||||
lambdaQuery.in(SysUserRole::getRoleId, roleIds);
|
||||
return this.remove(lambdaQuery);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ 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.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
@@ -26,7 +25,6 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@@ -58,7 +56,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
} else {
|
||||
queryWrapper.orderByDesc("sys_user.update_time");
|
||||
}
|
||||
queryWrapper.ne("sys_user.state", UserState.DELETED);
|
||||
queryWrapper.ne("sys_user.state", UserState.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());
|
||||
@@ -71,20 +69,20 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
@Override
|
||||
public List<SysUser> listUserByDeptId(String deptId) {
|
||||
if (StrUtil.isNotBlank(deptId)) {
|
||||
return this.lambdaQuery().ne(SysUser::getState, UserState.DELETED).eq(SysUser::getDeptId, deptId).orderByAsc(SysUser::getCreateTime).list();
|
||||
return this.lambdaQuery().ne(SysUser::getState, UserState.DELETE).eq(SysUser::getDeptId, deptId).orderByAsc(SysUser::getCreateTime).list();
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUser getUserByLoginName(String loginName) {
|
||||
return this.lambdaQuery().ne(SysUser::getState, UserState.DELETED).eq(SysUser::getLoginName, loginName).one();
|
||||
return this.lambdaQuery().ne(SysUser::getState, UserState.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, UserState.DELETED);
|
||||
lambdaQuery.eq(SysUser::getPhone, phone).ne(SysUser::getState, UserState.DELETE);
|
||||
if (isExcludeSelf) {
|
||||
lambdaQuery.ne(SysUser::getId, id);
|
||||
}
|
||||
@@ -94,7 +92,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
@Override
|
||||
public SysUser getUserByName(String name, boolean isExcludeSelf, String id) {
|
||||
LambdaQueryWrapper<SysUser> lambdaQuery = new LambdaQueryWrapper<>();
|
||||
lambdaQuery.eq(SysUser::getName, name).ne(SysUser::getState, UserState.DELETED);
|
||||
lambdaQuery.eq(SysUser::getName, name).ne(SysUser::getState, UserState.DELETE);
|
||||
if (isExcludeSelf) {
|
||||
lambdaQuery.ne(SysUser::getId, id);
|
||||
}
|
||||
@@ -104,7 +102,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
@Override
|
||||
public SysUser getUserByEmail(String email, boolean isExcludeSelf, String id) {
|
||||
LambdaQueryWrapper<SysUser> lambdaQuery = new LambdaQueryWrapper<>();
|
||||
lambdaQuery.eq(SysUser::getEmail, email).ne(SysUser::getState, UserState.DELETED);
|
||||
lambdaQuery.eq(SysUser::getEmail, email).ne(SysUser::getState, UserState.DELETE);
|
||||
if (isExcludeSelf) {
|
||||
lambdaQuery.ne(SysUser::getId, id);
|
||||
}
|
||||
@@ -125,10 +123,10 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
// todo 别忘记移除登录时间
|
||||
sysUser.setLoginTime(LocalDateTimeUtil.now());
|
||||
sysUser.setLoginErrorTimes(0);
|
||||
sysUser.setState(UserState.ENABLED);
|
||||
boolean result1 = this.save(sysUser);
|
||||
boolean result2 = sysUserRoleService.addUserRole(sysUser.getId(), addUserParam.getRoleIds());
|
||||
return result1 && result2;
|
||||
sysUser.setState(UserState.ENABLE);
|
||||
boolean result = this.save(sysUser);
|
||||
sysUserRoleService.addUserRole(sysUser.getId(), addUserParam.getRoleIds());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -136,14 +134,13 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
checkRepeat(updateUserParam, true, updateUserParam.getId());
|
||||
SysUser sysUser = new SysUser();
|
||||
BeanUtils.copyProperties(updateUserParam, sysUser);
|
||||
boolean result1 = this.updateById(sysUser);
|
||||
boolean result2 = sysUserRoleService.updateUserRole(sysUser.getId(), updateUserParam.getRoleIds());
|
||||
return result1 && result2;
|
||||
sysUserRoleService.updateUserRole(sysUser.getId(), updateUserParam.getRoleIds());
|
||||
return this.updateById(sysUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean oldPwdConfirm(String userId, String oldPassword) {
|
||||
SysUser user = lambdaQuery().ne(SysUser::getState, UserState.DELETED).eq(SysUser::getId, userId).one();
|
||||
SysUser user = lambdaQuery().ne(SysUser::getState, UserState.DELETE).eq(SysUser::getId, userId).one();
|
||||
if (ObjectUtil.isNotNull(user)) {
|
||||
String secretkey = Sm4Utils.globalSecretKey;
|
||||
Sm4Utils sm4 = new Sm4Utils(secretkey);
|
||||
@@ -156,7 +153,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
|
||||
@Override
|
||||
public boolean updatePassword(String userId, String newPassword) {
|
||||
SysUser user = lambdaQuery().ne(SysUser::getState, UserState.DELETED).eq(SysUser::getId, userId).one();
|
||||
SysUser user = lambdaQuery().ne(SysUser::getState, UserState.DELETE).eq(SysUser::getId, userId).one();
|
||||
if (ObjectUtil.isNotNull(user)) {
|
||||
String secretkey = Sm4Utils.globalSecretKey;
|
||||
Sm4Utils sm4 = new Sm4Utils(secretkey);
|
||||
@@ -168,8 +165,10 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
|
||||
@Override
|
||||
public boolean deleteUser(List<String> ids) {
|
||||
// 删除用户角色关联数据
|
||||
sysUserRoleService.deleteUserRoleByUserIds(ids);
|
||||
return this.lambdaUpdate()
|
||||
.set(SysUser::getState, UserState.DELETED)
|
||||
.set(SysUser::getState, UserState.DELETE)
|
||||
.in(SysUser::getId, ids)
|
||||
.update();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user