diff --git a/device/src/main/java/com/njcn/gather/device/device/pojo/param/PqDevParam.java b/device/src/main/java/com/njcn/gather/device/device/pojo/param/PqDevParam.java index 16f17dff..91012fd3 100644 --- a/device/src/main/java/com/njcn/gather/device/device/pojo/param/PqDevParam.java +++ b/device/src/main/java/com/njcn/gather/device/device/pojo/param/PqDevParam.java @@ -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("所属地市名称") diff --git a/device/src/main/java/com/njcn/gather/device/device/pojo/vo/PqDevExcel.java b/device/src/main/java/com/njcn/gather/device/device/pojo/vo/PqDevExcel.java index 3445668e..f1da8c7b 100644 --- a/device/src/main/java/com/njcn/gather/device/device/pojo/vo/PqDevExcel.java +++ b/device/src/main/java/com/njcn/gather/device/device/pojo/vo/PqDevExcel.java @@ -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) diff --git a/device/src/main/java/com/njcn/gather/device/device/service/impl/PqDevServiceImpl.java b/device/src/main/java/com/njcn/gather/device/device/service/impl/PqDevServiceImpl.java index a61735d9..7c6e342d 100644 --- a/device/src/main/java/com/njcn/gather/device/device/service/impl/PqDevServiceImpl.java +++ b/device/src/main/java/com/njcn/gather/device/device/service/impl/PqDevServiceImpl.java @@ -40,7 +40,7 @@ public class PqDevServiceImpl extends ServiceImpl 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 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())); diff --git a/device/src/main/java/com/njcn/gather/device/pojo/constant/DeviceValidMessage.java b/device/src/main/java/com/njcn/gather/device/pojo/constant/DeviceValidMessage.java index 344d3fae..fe3e8d73 100644 --- a/device/src/main/java/com/njcn/gather/device/pojo/constant/DeviceValidMessage.java +++ b/device/src/main/java/com/njcn/gather/device/pojo/constant/DeviceValidMessage.java @@ -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参数"; } diff --git a/system/src/main/java/com/njcn/gather/system/dictionary/pojo/vo/DictDataExcel.java b/system/src/main/java/com/njcn/gather/system/dictionary/pojo/vo/DictDataExcel.java index 49a803b4..a7ec85ce 100644 --- a/system/src/main/java/com/njcn/gather/system/dictionary/pojo/vo/DictDataExcel.java +++ b/system/src/main/java/com/njcn/gather/system/dictionary/pojo/vo/DictDataExcel.java @@ -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; /** diff --git a/user/src/main/java/com/njcn/gather/user/pojo/constant/FunctionConst.java b/user/src/main/java/com/njcn/gather/user/pojo/constant/FunctionConst.java new file mode 100644 index 00000000..f8311f7a --- /dev/null +++ b/user/src/main/java/com/njcn/gather/user/pojo/constant/FunctionConst.java @@ -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"; + +} diff --git a/user/src/main/java/com/njcn/gather/user/pojo/constant/UserState.java b/user/src/main/java/com/njcn/gather/user/pojo/constant/UserState.java index 384ad180..995bdc7f 100644 --- a/user/src/main/java/com/njcn/gather/user/pojo/constant/UserState.java +++ b/user/src/main/java/com/njcn/gather/user/pojo/constant/UserState.java @@ -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; diff --git a/user/src/main/java/com/njcn/gather/user/pojo/constant/UserValidMessage.java b/user/src/main/java/com/njcn/gather/user/pojo/constant/UserValidMessage.java index 11e9c403..076a8848 100644 --- a/user/src/main/java/com/njcn/gather/user/pojo/constant/UserValidMessage.java +++ b/user/src/main/java/com/njcn/gather/user/pojo/constant/UserValidMessage.java @@ -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参数"; diff --git a/user/src/main/java/com/njcn/gather/user/pojo/enums/UserResponseEnum.java b/user/src/main/java/com/njcn/gather/user/pojo/enums/UserResponseEnum.java index 6a440f18..188a1872 100644 --- a/user/src/main/java/com/njcn/gather/user/pojo/enums/UserResponseEnum.java +++ b/user/src/main/java/com/njcn/gather/user/pojo/enums/UserResponseEnum.java @@ -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; diff --git a/user/src/main/java/com/njcn/gather/user/user/controller/SysFunctionController.java b/user/src/main/java/com/njcn/gather/user/user/controller/SysFunctionController.java new file mode 100644 index 00000000..98ed302b --- /dev/null +++ b/user/src/main/java/com/njcn/gather/user/user/controller/SysFunctionController.java @@ -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> getFunctionTree() { + String methodDescribe = getMethodDescribe("getFunctionTree"); + List list = sysFunctionService.getFunctionTree(true); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe); + } + + @OperateInfo(info = LogEnum.SYSTEM_COMMON) + @GetMapping("/functionTreeNoButton") + @ApiOperation("菜单树-不包括按钮") + public HttpResult> getFunctionTreeNoButton() { + String methodDescribe = getMethodDescribe("getFunctionTree"); + List 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 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 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 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 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> getButtonById(String id) { +// String methodDescribe = getMethodDescribe("getButtonById"); +// LogUtil.njcnDebug(log, "{},菜单id为:{}", methodDescribe, id); +// List list = sysFunctionService.getButtonsById(id); +// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe); +// } + + +// @OperateInfo(info = LogEnum.SYSTEM_COMMON) +// @GetMapping("/getRouteMenu") +// @ApiOperation("路由菜单") +// public HttpResult> getRouteMenu() { +// String methodDescribe = getMethodDescribe("getRouteMenu"); +// List 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 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> getUserFunctionTree() { +// String methodDescribe = getMethodDescribe("getUserFunctionTree"); +// List list = sysFunctionService.getUserFunctionTree(); +// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe); +// } +} + diff --git a/user/src/main/java/com/njcn/gather/user/user/controller/SysRoleController.java b/user/src/main/java/com/njcn/gather/user/user/controller/SysRoleController.java index ba73b9ce..bca9cc7b 100644 --- a/user/src/main/java/com/njcn/gather/user/user/controller/SysRoleController.java +++ b/user/src/main/java/com/njcn/gather/user/user/controller/SysRoleController.java @@ -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> 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> listRoleByIds(@RequestBody List ids) { - String methodDescribe = getMethodDescribe("listRoleByIds"); - List users = sysRoleService.list((new LambdaQueryWrapper().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> listRoleByIds(@RequestBody List ids) { +// String methodDescribe = getMethodDescribe("listRoleByIds"); +// List roles = sysRoleService.list((new LambdaQueryWrapper().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 selectFunctionComponent(@RequestBody List 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> listRoleByType(@RequestParam("type") Integer type) { - String methodDescribe = getMethodDescribe("listRoleByType"); - LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, type); - List result = sysRoleService.listRoleByType(type); - return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); + @PostMapping("/getFunctionsByRoleId") + @ApiOperation("获取角色id绑定的菜单(资源)") + @ApiImplicitParam(name = "id", value = "角色id", required = true) + public HttpResult> getFunctionsByRoleId(@RequestParam @Validated String id) { + String methodDescribe = getMethodDescribe("getFunctionsByRoleId"); + LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, id); + List sysFunctions = sysRoleFunctionService.listFunctionByRoleId(id); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, sysFunctions, methodDescribe); } - @OperateInfo(info = LogEnum.SYSTEM_COMMON) - @GetMapping("/listAllRole") - @ApiOperation("查询所有角色") - public HttpResult> listAllRole() { - String methodDescribe = getMethodDescribe("listAllRole"); - List 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> listRoleByType(@RequestParam("type") Integer type) { +// String methodDescribe = getMethodDescribe("listRoleByType"); +// LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, type); +// List result = sysRoleService.listRoleByType(type); +// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); +// } + +// @OperateInfo(info = LogEnum.SYSTEM_COMMON) +// @GetMapping("/listAllRole") +// @ApiOperation("查询所有角色") +// public HttpResult> listAllRole() { +// String methodDescribe = getMethodDescribe("listAllRole"); +// List result = sysRoleService.listAllRole(); +// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); +// } @OperateInfo(info = LogEnum.SYSTEM_COMMON) @GetMapping("/simpleList") diff --git a/user/src/main/java/com/njcn/gather/user/user/controller/SysUserController.java b/user/src/main/java/com/njcn/gather/user/user/controller/SysUserController.java index 67929acb..2af01c6e 100644 --- a/user/src/main/java/com/njcn/gather/user/user/controller/SysUserController.java +++ b/user/src/main/java/com/njcn/gather/user/user/controller/SysUserController.java @@ -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 delete(@RequestBody List 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 delete(@RequestBody List 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("修改密码") diff --git a/user/src/main/java/com/njcn/gather/user/user/mapper/SysFunctionMapper.java b/user/src/main/java/com/njcn/gather/user/user/mapper/SysFunctionMapper.java new file mode 100644 index 00000000..5e07e4a4 --- /dev/null +++ b/user/src/main/java/com/njcn/gather/user/user/mapper/SysFunctionMapper.java @@ -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 { + +} + diff --git a/user/src/main/java/com/njcn/gather/user/user/mapper/SysRoleFunctionMapper.java b/user/src/main/java/com/njcn/gather/user/user/mapper/SysRoleFunctionMapper.java new file mode 100644 index 00000000..07111bd8 --- /dev/null +++ b/user/src/main/java/com/njcn/gather/user/user/mapper/SysRoleFunctionMapper.java @@ -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 { + + /** + * 根据角色id获取角色拥有的菜单(资源)列表 + * + * @param roleId 角色id + * @return 角色拥有的菜单(资源)列表 + */ + List getFunctionListByRoleId(@Param("roleId") String roleId); +} + diff --git a/user/src/main/java/com/njcn/gather/user/user/mapper/mapping/SysFunctionMapper.xml b/user/src/main/java/com/njcn/gather/user/user/mapper/mapping/SysFunctionMapper.xml new file mode 100644 index 00000000..c07b9a72 --- /dev/null +++ b/user/src/main/java/com/njcn/gather/user/user/mapper/mapping/SysFunctionMapper.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/user/src/main/java/com/njcn/gather/user/user/mapper/mapping/SysRoleFunctionMapper.xml b/user/src/main/java/com/njcn/gather/user/user/mapper/mapping/SysRoleFunctionMapper.xml new file mode 100644 index 00000000..1e9d48c2 --- /dev/null +++ b/user/src/main/java/com/njcn/gather/user/user/mapper/mapping/SysRoleFunctionMapper.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/user/src/main/java/com/njcn/gather/user/user/mapper/mapping/SysUserRoleMapper.xml b/user/src/main/java/com/njcn/gather/user/user/mapper/mapping/SysUserRoleMapper.xml index c9a183b2..3cb25f69 100644 --- a/user/src/main/java/com/njcn/gather/user/user/mapper/mapping/SysUserRoleMapper.xml +++ b/user/src/main/java/com/njcn/gather/user/user/mapper/mapping/SysUserRoleMapper.xml @@ -6,8 +6,8 @@ diff --git a/user/src/main/java/com/njcn/gather/user/user/pojo/param/SysFunctionParam.java b/user/src/main/java/com/njcn/gather/user/user/pojo/param/SysFunctionParam.java new file mode 100644 index 00000000..45061534 --- /dev/null +++ b/user/src/main/java/com/njcn/gather/user/user/pojo/param/SysFunctionParam.java @@ -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; + } +} diff --git a/user/src/main/java/com/njcn/gather/user/user/pojo/param/SysRoleParam.java b/user/src/main/java/com/njcn/gather/user/user/pojo/param/SysRoleParam.java index e5ad836e..566b0afa 100644 --- a/user/src/main/java/com/njcn/gather/user/user/pojo/param/SysRoleParam.java +++ b/user/src/main/java/com/njcn/gather/user/user/pojo/param/SysRoleParam.java @@ -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 functionIds; } } diff --git a/user/src/main/java/com/njcn/gather/user/user/pojo/po/SysFunction.java b/user/src/main/java/com/njcn/gather/user/user/pojo/po/SysFunction.java new file mode 100644 index 00000000..149ecf4b --- /dev/null +++ b/user/src/main/java/com/njcn/gather/user/user/pojo/po/SysFunction.java @@ -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 children; +} + diff --git a/user/src/main/java/com/njcn/gather/user/user/pojo/po/SysRole.java b/user/src/main/java/com/njcn/gather/user/user/pojo/po/SysRole.java index 643b1f5a..bf8838ed 100644 --- a/user/src/main/java/com/njcn/gather/user/user/pojo/po/SysRole.java +++ b/user/src/main/java/com/njcn/gather/user/user/pojo/po/SysRole.java @@ -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; } diff --git a/user/src/main/java/com/njcn/gather/user/user/pojo/po/SysRoleFunction.java b/user/src/main/java/com/njcn/gather/user/user/pojo/po/SysRoleFunction.java new file mode 100644 index 00000000..9f67a2c8 --- /dev/null +++ b/user/src/main/java/com/njcn/gather/user/user/pojo/po/SysRoleFunction.java @@ -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; + +} + diff --git a/user/src/main/java/com/njcn/gather/user/user/service/ISysFunctionService.java b/user/src/main/java/com/njcn/gather/user/user/service/ISysFunctionService.java new file mode 100644 index 00000000..fd191418 --- /dev/null +++ b/user/src/main/java/com/njcn/gather/user/user/service/ISysFunctionService.java @@ -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 { + + /** + * 添加菜单(资源) + * + * @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 getFunctionTree(boolean isContainButton); + + /** + * 根据id获取菜单(资源) + * + * @param id 资源id + * @return 资源 + */ + //SysFunction getFunctionById(String id); + + /** + * 根据菜单(资源)id获取按钮 + * + * @param id 菜单id + * @return 菜单下面所有按钮 + */ + //List getButtonsById(String id); + + /** + * 获取路由菜单 + * + * @return 路由菜单 + */ + List getRouteMenu(); + + /** + * 获取用户拥有的资源树 + * + * @return + */ + //List getUserFunctionTree(); +} diff --git a/user/src/main/java/com/njcn/gather/user/user/service/ISysRoleFunctionService.java b/user/src/main/java/com/njcn/gather/user/user/service/ISysRoleFunctionService.java new file mode 100644 index 00000000..de83d2b0 --- /dev/null +++ b/user/src/main/java/com/njcn/gather/user/user/service/ISysRoleFunctionService.java @@ -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 { + + /** + * 获取角色id绑定的菜单(资源) + * + * @param roleId 角色id + * @return 菜单(资源)列表 + */ + List listFunctionByRoleId(String roleId); + + /** + * 新增角色菜单(资源)关联数据 + * + * @param roleId 角色id + * @param functionIds 菜单(资源)ids + * @return 成功返回true,失败返回false + */ + boolean addRoleFunction(String roleId, List functionIds); + + /** + * 更新角色菜单(资源)关联数据 + * + * @param roleId 角色id + * @param functionIds 菜单(资源)ids + * @return 成功返回true,失败返回false + */ + boolean updateRoleFunction(String roleId, List functionIds); + + /** + * 根据角色ids删除角色资源关联数据 + * + * @param roleIds + * @return 成功返回true,失败返回false + */ + boolean deleteRoleFunctionByRoleIds(List roleIds); + + /** + * 根据菜单(资源)ids删除角色资源关联数据 + * + * @param functionIds 菜单(资源)ids + * @return 成功返回true,失败返回false + */ + boolean deleteRoleFunctionByFunctionIds(List functionIds); +} diff --git a/user/src/main/java/com/njcn/gather/user/user/service/ISysRoleService.java b/user/src/main/java/com/njcn/gather/user/user/service/ISysRoleService.java index 8bbb8116..a5a1a894 100644 --- a/user/src/main/java/com/njcn/gather/user/user/service/ISysRoleService.java +++ b/user/src/main/java/com/njcn/gather/user/user/service/ISysRoleService.java @@ -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 { * * @return 角色列表 */ - List listAllRole(); + //List listAllRole(); /** * 根据权限类型type获取角色列表 @@ -57,7 +58,7 @@ public interface ISysRoleService extends IService { * @param type 角色类型 * @return 角色列表 */ - List listRoleByType(Integer type); + //List listRoleByType(Integer type); /** * 根据用户id获取角色 @@ -65,7 +66,7 @@ public interface ISysRoleService extends IService { * @param userId 用户id * @return 角色列表 */ - List listRoleByUserId(String userId); + //List listRoleByUserId(String userId); /** * 查询所有角色作为下拉框 @@ -79,5 +80,7 @@ public interface ISysRoleService extends IService { * * @param ids 角色id */ - boolean selectRelevance(List ids); + // boolean selectRelevance(List ids); + + } diff --git a/user/src/main/java/com/njcn/gather/user/user/service/ISysUserRoleService.java b/user/src/main/java/com/njcn/gather/user/user/service/ISysUserRoleService.java index d7e458f7..6a9c64a7 100644 --- a/user/src/main/java/com/njcn/gather/user/user/service/ISysUserRoleService.java +++ b/user/src/main/java/com/njcn/gather/user/user/service/ISysUserRoleService.java @@ -11,37 +11,46 @@ import java.util.List; * @date 2024-11-12 */ public interface ISysUserRoleService extends IService { - /** - * 根据用户id获取 用户--角色关系数据 - * - * @param userId 用户ID - * @return 关系数据 - */ - List listUserRoleByUserId(String userId); /** - * 新增用户和角色的关系 - * - * @param userId 用户id - * @param roleIds 角色id - * @return boolean - */ - boolean addUserRole(String userId, List roleIds); - - /** - * 修改用户和角色的关系 - * - * @param userId 用户id - * @param roleIds 角色id - * @return boolean - */ - boolean updateUserRole(String userId, List roleIds); - - /** - * 根据用户id获取角色详情 + * 根据用户id获取角色 * * @param userId 用户id * @return 角色信息 */ List listRoleByUserId(String userId); + + /** + * 新增用户角色关联数据 + * + * @param userId 用户id + * @param roleIds 角色id + * @return 成功返回true,失败返回false + */ + boolean addUserRole(String userId, List roleIds); + + /** + * 修改用户角色关联数据 + * + * @param userId 用户id + * @param roleIds 角色id + * @return 成功返回true,失败返回false + */ + boolean updateUserRole(String userId, List roleIds); + + /** + * 根据用户id删除用户角色关联数据 + * + * @param userIds 用户ids + * @return 成功返回true,失败返回false + */ + boolean deleteUserRoleByUserIds(List userIds); + + /** + * 根据角色id删除用户角色关联数据 + * + * @param roleIds 角色ids + * @return 成功返回true,失败返回false + */ + boolean deleteUserRoleByRoleIds(List roleIds); } diff --git a/user/src/main/java/com/njcn/gather/user/user/service/impl/SysFunctionServiceImpl.java b/user/src/main/java/com/njcn/gather/user/user/service/impl/SysFunctionServiceImpl.java new file mode 100644 index 00000000..f87adbbe --- /dev/null +++ b/user/src/main/java/com/njcn/gather/user/user/service/impl/SysFunctionServiceImpl.java @@ -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 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 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 getFunctionTree(boolean isContainButton) { + LambdaQueryWrapper 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 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 getButtonsById(String id) { +// List 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 getRouteMenu() { +// List result = new ArrayList<>(); +// List 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 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 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 getUserFunctionTree() { +// return Collections.emptyList(); +// } + + /** + * 根据当前分类找出子类,递归找出子类的子类 + */ + private List getChildrenList(SysFunction currMenu, List 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 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); + } + } +} diff --git a/user/src/main/java/com/njcn/gather/user/user/service/impl/SysRoleFunctionServiceImpl.java b/user/src/main/java/com/njcn/gather/user/user/service/impl/SysRoleFunctionServiceImpl.java new file mode 100644 index 00000000..8b71b971 --- /dev/null +++ b/user/src/main/java/com/njcn/gather/user/user/service/impl/SysRoleFunctionServiceImpl.java @@ -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 implements ISysRoleFunctionService { + + @Override + public List listFunctionByRoleId(String roleId) { + return this.baseMapper.getFunctionListByRoleId(roleId); + } + + @Override + public boolean addRoleFunction(String roleId, List functionIds) { + List 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 functionIds) { + //删除原有关系 + this.deleteRoleFunctionByRoleIds(Collections.singletonList(roleId)); + //新增关系 + List 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 roleIds) { + LambdaQueryWrapper lambdaQuery = new LambdaQueryWrapper<>(); + lambdaQuery.in(SysRoleFunction::getRoleId, roleIds); + return this.remove(lambdaQuery); + } + + @Override + public boolean deleteRoleFunctionByFunctionIds(List functionIds) { + LambdaQueryWrapper lambdaQuery = new LambdaQueryWrapper<>(); + lambdaQuery.in(SysRoleFunction::getFunctionId, functionIds); + return this.remove(lambdaQuery); + } +} diff --git a/user/src/main/java/com/njcn/gather/user/user/service/impl/SysRoleServiceImpl.java b/user/src/main/java/com/njcn/gather/user/user/service/impl/SysRoleServiceImpl.java index 28e6a616..1771103a 100644 --- a/user/src/main/java/com/njcn/gather/user/user/service/impl/SysRoleServiceImpl.java +++ b/user/src/main/java/com/njcn/gather/user/user/service/impl/SysRoleServiceImpl.java @@ -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 implements ISysRoleService { private final ISysUserRoleService sysUserRoleService; + private final ISysRoleFunctionService sysRoleFunctionService; @Override public Page listRole(SysRoleParam.QueryParam queryParam) { QueryWrapper 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 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 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 impl @Override public boolean deleteRole(List 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 listAllRole() { - QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.ne("sys_role.state", DataStateEnum.DELETED.getCode()); - return this.baseMapper.selectList(queryWrapper); - } +// @Override +// public List listAllRole() { +// QueryWrapper queryWrapper = new QueryWrapper<>(); +// queryWrapper.ne("sys_role.state", DataStateEnum.DELETED.getCode()); +// return this.baseMapper.selectList(queryWrapper); +// } - @Override - public List listRoleByType(Integer type) { - return this.lambdaQuery().eq(SysRole::getType, type).eq(SysRole::getState, DataStateEnum.ENABLE.getCode()).list(); - } +// @Override +// public List listRoleByType(Integer type) { +// return this.lambdaQuery().eq(SysRole::getType, type).eq(SysRole::getState, DataStateEnum.ENABLE.getCode()).list(); +// } - @Override - public List listRoleByUserId(String userId) { - return sysUserRoleService.listRoleByUserId(userId); - } + // @Override +// public List listRoleByUserId(String userId) { +// return sysUserRoleService.listRoleByUserId(userId); +// } @Override public List simpleList() { @@ -106,26 +106,29 @@ public class SysRoleServiceImpl extends ServiceImpl impl return this.baseMapper.selectList(lambdaQueryWrapper); } - @Override - public boolean selectRelevance(List ids) { - // 判断角色是否和用户绑定 - //List userRoleList = this.userRoleMapper.selectUserRole(ids); - // 判断角色是否和资源绑定 - //List roleFunctionList = this.roleFunctionMapper.selectRoleFunction(ids); - // 判断角色是否和组件绑定 - //List roleComponentList = this.roleComponentMapper.selectRoleComponet(ids); - //if (!userRoleList.isEmpty() || !roleComponentList.isEmpty() || !roleFunctionList.isEmpty()) { - // return true; - //} - return false; - } +// @Override +// public boolean selectRelevance(List ids) { +// // 判断角色是否和用户绑定 +// List userRoleList = this.userRoleMapper.selectUserRole(ids); +// // 判断角色是否和资源绑定 +// List roleFunctionList = this.roleFunctionMapper.selectRoleFunction(ids); +// // 判断角色是否和组件绑定 +// List 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 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 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); } } } diff --git a/user/src/main/java/com/njcn/gather/user/user/service/impl/SysUserRoleServiceImpl.java b/user/src/main/java/com/njcn/gather/user/user/service/impl/SysUserRoleServiceImpl.java index 6900a59a..7251a608 100644 --- a/user/src/main/java/com/njcn/gather/user/user/service/impl/SysUserRoleServiceImpl.java +++ b/user/src/main/java/com/njcn/gather/user/user/service/impl/SysUserRoleServiceImpl.java @@ -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 implements ISysUserRoleService { - private final SysUserRoleMapper sysUserRoleMapper; - @Override - public List listUserRoleByUserId(String userId) { - return this.lambdaQuery().eq(SysUserRole::getUserId, userId).list(); + public List listRoleByUserId(String userId) { + return this.baseMapper.getRoleListByUserId(userId); } @Override public boolean addUserRole(String userId, List roleIds) { - boolean result = false; + List userRoles = new ArrayList<>(); if (!CollectionUtil.isEmpty(roleIds)) { - SysUserRole userRole = new SysUserRole(); - userRole.setUserId(userId); roleIds.forEach(id -> { + SysUserRole userRole = new SysUserRole(); + userRole.setUserId(userId); userRole.setRoleId(id); - this.save(userRole); + userRoles.add(userRole); }); - result = true; } - return result; + return this.saveBatch(userRoles); } @Override public boolean updateUserRole(String userId, List roleIds) { //删除原有关系 - List userRoleList = this.lambdaQuery().eq(SysUserRole::getUserId, userId).list().stream().map(SysUserRole::getRoleId).collect(Collectors.toList()); - LambdaQueryWrapper 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 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 listRoleByUserId(String userId) { - return this.baseMapper.getRoleListByUserId(userId); + public boolean deleteUserRoleByUserIds(List userIds) { + LambdaQueryWrapper lambdaQuery = new LambdaQueryWrapper<>(); + lambdaQuery.in(SysUserRole::getUserId, userIds); + return this.remove(lambdaQuery); + } + + @Override + public boolean deleteUserRoleByRoleIds(List roleIds) { + LambdaQueryWrapper lambdaQuery = new LambdaQueryWrapper<>(); + lambdaQuery.in(SysUserRole::getRoleId, roleIds); + return this.remove(lambdaQuery); } } diff --git a/user/src/main/java/com/njcn/gather/user/user/service/impl/SysUserServiceImpl.java b/user/src/main/java/com/njcn/gather/user/user/service/impl/SysUserServiceImpl.java index 40152ef4..a6fe161d 100644 --- a/user/src/main/java/com/njcn/gather/user/user/service/impl/SysUserServiceImpl.java +++ b/user/src/main/java/com/njcn/gather/user/user/service/impl/SysUserServiceImpl.java @@ -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 impl } else { queryWrapper.orderByDesc("sys_user.update_time"); } - queryWrapper.ne("sys_user.state", UserState.DELETED); + queryWrapper.ne("sys_user.state", UserState.DELETE); Page page = this.baseMapper.selectPage(new Page<>(PageFactory.getPageNum(queryParam), PageFactory.getPageSize(queryParam)), queryWrapper); page.getRecords().forEach(sysUser -> { List sysRoles = sysUserRoleService.listRoleByUserId(sysUser.getId()); @@ -71,20 +69,20 @@ public class SysUserServiceImpl extends ServiceImpl impl @Override public List 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 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 impl @Override public SysUser getUserByName(String name, boolean isExcludeSelf, String id) { LambdaQueryWrapper 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 impl @Override public SysUser getUserByEmail(String email, boolean isExcludeSelf, String id) { LambdaQueryWrapper 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 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 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 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 impl @Override public boolean deleteUser(List ids) { + // 删除用户角色关联数据 + sysUserRoleService.deleteUserRoleByUserIds(ids); return this.lambdaUpdate() - .set(SysUser::getState, UserState.DELETED) + .set(SysUser::getState, UserState.DELETE) .in(SysUser::getId, ids) .update(); }