diff --git a/device/pom.xml b/device/pom.xml index c57833d4..1d045f75 100644 --- a/device/pom.xml +++ b/device/pom.xml @@ -28,6 +28,12 @@ spingboot2.3.12 2.3.12 + + com.njcn.gather + system + 1.0.0 + compile + diff --git a/device/src/main/java/com/njcn/gather/device/device/controller/PqDevController.java b/device/src/main/java/com/njcn/gather/device/device/controller/PqDevController.java index c4cb72e5..a915b49e 100644 --- a/device/src/main/java/com/njcn/gather/device/device/controller/PqDevController.java +++ b/device/src/main/java/com/njcn/gather/device/device/controller/PqDevController.java @@ -75,7 +75,7 @@ public class PqDevController extends BaseController { } @OperateInfo(operateType = OperateType.UPDATE) - @PutMapping("/update") + @PostMapping("/update") @ApiOperation("修改被检设备") @ApiImplicitParam(name = "updateParam", value = "被检设备", required = true) public HttpResult update(@RequestBody @Validated PqDevParam.UpdateParam updateParam) { @@ -90,7 +90,7 @@ public class PqDevController extends BaseController { } @OperateInfo(operateType = OperateType.DELETE) - @DeleteMapping("/delete") + @PostMapping("/delete") @ApiOperation("删除被检设备") @ApiImplicitParam(name = "ids", value = "被检设备id", required = true) public HttpResult delete(@RequestBody List ids) { @@ -159,7 +159,7 @@ public class PqDevController extends BaseController { } @OperateInfo(info = LogEnum.BUSINESS_COMMON) - @PostMapping("/listBoundByPlanId") + @GetMapping("/listBoundByPlanId") @ApiOperation("根据计划id查询出所有已绑定的设备") @ApiImplicitParam(name = "planId", value = "计划id", required = true) public HttpResult> listBoundByPlanId(@RequestParam("planId") String planId) { 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 91012fd3..c243d302 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 @@ -7,6 +7,7 @@ import com.njcn.web.pojo.param.BaseParam; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; +import org.hibernate.validator.constraints.Range; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; @@ -76,6 +77,7 @@ public class PqDevParam { private String ip; @ApiModelProperty(value = "端口号", required = true) + @Range(min = 1, max = 65535, message = DeviceValidMessage.PORT_RANGE_ERROR) @NotNull(message = DeviceValidMessage.PORT_NOT_NULL) private Integer port; 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 0c59b8b2..c9f571d3 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 @@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.njcn.common.pojo.enums.common.DataStateEnum; +import com.njcn.common.pojo.exception.BusinessException; import com.njcn.db.mybatisplus.constant.DbConstant; import com.njcn.gather.device.device.mapper.PqDevMapper; import com.njcn.gather.device.device.pojo.param.PqDevParam; @@ -14,6 +15,9 @@ import com.njcn.gather.device.device.pojo.po.PqDev; import com.njcn.gather.device.device.pojo.vo.PqDevExcel; import com.njcn.gather.device.device.service.IPqDevService; import com.njcn.gather.device.device.util.DeviceUtil; +import com.njcn.gather.device.pojo.enums.DeviceResponseEnum; +import com.njcn.gather.system.dictionary.pojo.po.DictData; +import com.njcn.gather.system.dictionary.service.IDictDataService; import com.njcn.web.factory.PageFactory; import com.njcn.web.utils.ExcelUtil; import lombok.RequiredArgsConstructor; @@ -34,6 +38,8 @@ import java.util.stream.Collectors; @RequiredArgsConstructor public class PqDevServiceImpl extends ServiceImpl implements IPqDevService { + private final IDictDataService dictDataService; + @Override public Page listPqDevs(PqDevParam.QueryParam queryParam) { QueryWrapper queryWrapper = new QueryWrapper<>(); @@ -50,18 +56,29 @@ public class PqDevServiceImpl extends ServiceImpl implements queryWrapper.orderBy(true, false, "pq_dev.Create_Time"); } queryWrapper.eq("pq_dev.state", DataStateEnum.ENABLE.getCode()); - return this.page(new Page<>(PageFactory.getPageNum(queryParam), PageFactory.getPageSize(queryParam)), queryWrapper); + Page page = this.page(new Page<>(PageFactory.getPageNum(queryParam), PageFactory.getPageSize(queryParam)), queryWrapper); + page.getRecords().forEach(p -> { + if (ObjectUtil.isNotNull(p.getSeries())) { + p.setSeries(DeviceUtil.decoderString(1, p.getSeries())); + } + if (ObjectUtil.isNotNull(p.getDevKey())) { + p.setDevKey(DeviceUtil.decoderString(1, p.getDevKey())); + } + }); + return page; } @Override public boolean addPqDev(PqDevParam pqDevParam) { PqDev pqDev = new PqDev(); BeanUtil.copyProperties(pqDevParam, pqDev); - if (Objects.nonNull(pqDev.getSeries())) { - pqDev.setSeries(DeviceUtil.encodeString(1, pqDev.getSeries())); - } - if (Objects.nonNull(pqDev.getDevKey())) { - pqDev.setDevKey(DeviceUtil.encodeString(1, pqDev.getDevKey())); + if (pqDevParam.getEncryptionFlag() == 1) { + if (StrUtil.isNotBlank(pqDevParam.getSeries()) && StrUtil.isNotBlank(pqDevParam.getDevKey())) { + pqDev.setSeries(DeviceUtil.encodeString(1, pqDev.getSeries())); + pqDev.setDevKey(DeviceUtil.encodeString(1, pqDev.getDevKey())); + } else { + throw new BusinessException(DeviceResponseEnum.SERIES_AND_DEVKEY_NOT_BLANK); + } } //todo 比对式设备处理 pqDev.setState(DataStateEnum.ENABLE.getCode()); @@ -124,6 +141,7 @@ public class PqDevServiceImpl extends ServiceImpl implements } queryWrapper.eq("pq_dev.state", DataStateEnum.ENABLE.getCode()); List pqDevs = this.list(queryWrapper); + this.visualize(pqDevs); List pqDevExcels = BeanUtil.copyToList(pqDevs, PqDevExcel.ExportData.class); ExcelUtil.exportExcel("被检设备导出数据.xlsx", "被检设备", PqDevExcel.ExportData.class, pqDevExcels); } @@ -155,4 +173,24 @@ public class PqDevServiceImpl extends ServiceImpl implements return result1 && result2; } + + //可视化,各种id回显字典值,解码等操作 + private void visualize(List sourceList) { + sourceList.forEach(pqDev -> { + //todo + + if (ObjectUtil.isNotNull(pqDev.getDevType())) { + DictData dictData = dictDataService.getDicDataById(pqDev.getDevType()); + if(ObjectUtil.isNotNull(dictData)){ + pqDev.setDevType(dictData.getName()); + } + } + if (Objects.nonNull(pqDev.getSeries())) { + pqDev.setSeries(DeviceUtil.decoderString(1, pqDev.getSeries())); + } + if (Objects.nonNull(pqDev.getDevKey())) { + pqDev.setDevKey(DeviceUtil.decoderString(1, pqDev.getDevKey())); + } + }); + } } 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 fe3e8d73..1efbcf7d 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 @@ -10,6 +10,8 @@ public interface DeviceValidMessage { String ID_FORMAT_ERROR = "id格式错误,请检查id参数"; + String PORT_RANGE_ERROR = "端口号范围错误,请检查port参数"; + String NAME_NOT_BLANK = "名称不能为空,请检查name参数"; String NAME_FORMAT_ERROR = "名称格式错误,请检查name参数"; diff --git a/device/src/main/java/com/njcn/gather/device/pojo/enums/DeviceResponseEnum.java b/device/src/main/java/com/njcn/gather/device/pojo/enums/DeviceResponseEnum.java index 524387c1..cc9b50bd 100644 --- a/device/src/main/java/com/njcn/gather/device/pojo/enums/DeviceResponseEnum.java +++ b/device/src/main/java/com/njcn/gather/device/pojo/enums/DeviceResponseEnum.java @@ -6,7 +6,8 @@ import lombok.Getter; public enum DeviceResponseEnum { //NAME_REPEAT("A001001", "名称重复"), - IMPORT_DATA_FAIL("A001002", "导入数据失败"); + IMPORT_DATA_FAIL("A001002", "导入数据失败"), + SERIES_AND_DEVKEY_NOT_BLANK("A001003", "加密设备的序列号和设备密钥不能为空"); private final String code; diff --git a/system/src/main/java/com/njcn/gather/system/dictionary/controller/DictDataController.java b/system/src/main/java/com/njcn/gather/system/dictionary/controller/DictDataController.java index a1288f35..a492e856 100644 --- a/system/src/main/java/com/njcn/gather/system/dictionary/controller/DictDataController.java +++ b/system/src/main/java/com/njcn/gather/system/dictionary/controller/DictDataController.java @@ -79,7 +79,7 @@ public class DictDataController extends BaseController { * 修改字典数据 */ @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.UPDATE) - @PutMapping("/update") + @PostMapping("/update") @ApiOperation("修改字典数据") @ApiImplicitParam(name = "updateParam", value = "字典数据", required = true) public HttpResult update(@RequestBody @Validated DictDataParam.UpdateParam updateParam) { diff --git a/system/src/main/java/com/njcn/gather/system/dictionary/controller/DictPqController.java b/system/src/main/java/com/njcn/gather/system/dictionary/controller/DictPqController.java index 2f58aeba..6586c8c2 100644 --- a/system/src/main/java/com/njcn/gather/system/dictionary/controller/DictPqController.java +++ b/system/src/main/java/com/njcn/gather/system/dictionary/controller/DictPqController.java @@ -62,7 +62,7 @@ public class DictPqController extends BaseController { } @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.UPDATE) - @PutMapping("/update") + @PostMapping("/update") @ApiOperation("更新电能质量指标字典") @ApiImplicitParam(name = "updateParam", value = "更新参数", required = true) public HttpResult update(@RequestBody @Validated DictPqParam.UpdateParam updateParam) { @@ -70,7 +70,7 @@ public class DictPqController extends BaseController { LogUtil.njcnDebug(log, "{},更新数据为:{}", methodDescribe, updateParam); boolean result = dictPqService.updateDictPq(updateParam); if (result) { - return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); } else { return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe); } diff --git a/system/src/main/java/com/njcn/gather/system/dictionary/controller/DictTreeController.java b/system/src/main/java/com/njcn/gather/system/dictionary/controller/DictTreeController.java index 6e204071..efeb4846 100644 --- a/system/src/main/java/com/njcn/gather/system/dictionary/controller/DictTreeController.java +++ b/system/src/main/java/com/njcn/gather/system/dictionary/controller/DictTreeController.java @@ -63,7 +63,7 @@ public class DictTreeController extends BaseController { * @param dicParam 修改参数 */ @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.UPDATE) - @PutMapping("/update") + @PostMapping("/update") @ApiOperation("修改") @ApiImplicitParam(name = "dicParam", value = "数据", required = true) public HttpResult update(@RequestBody @Validated DictTreeParam.UpdateParam dicParam) { diff --git a/system/src/main/java/com/njcn/gather/system/dictionary/controller/DictTypeController.java b/system/src/main/java/com/njcn/gather/system/dictionary/controller/DictTypeController.java index a7269dbb..ab5f0923 100644 --- a/system/src/main/java/com/njcn/gather/system/dictionary/controller/DictTypeController.java +++ b/system/src/main/java/com/njcn/gather/system/dictionary/controller/DictTypeController.java @@ -77,7 +77,7 @@ public class DictTypeController extends BaseController { } @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.UPDATE) - @PutMapping("/update") + @PostMapping("/update") @ApiOperation("修改字典类型") @ApiImplicitParam(name = "updateParam", value = "字典类型数据", required = true) public HttpResult update(@RequestBody @Validated DictTypeParam.UpdateParam updateParam) { diff --git a/system/src/main/java/com/njcn/gather/system/dictionary/service/impl/DictDataServiceImpl.java b/system/src/main/java/com/njcn/gather/system/dictionary/service/impl/DictDataServiceImpl.java index 54bc758d..44c3b884 100644 --- a/system/src/main/java/com/njcn/gather/system/dictionary/service/impl/DictDataServiceImpl.java +++ b/system/src/main/java/com/njcn/gather/system/dictionary/service/impl/DictDataServiceImpl.java @@ -94,7 +94,7 @@ public class DictDataServiceImpl extends ServiceImpl i @Override public DictData getDicDataById(String dicIndex) { - return this.baseMapper.selectById(dicIndex); + return this.lambdaQuery().eq(DictData::getId, dicIndex).eq(DictData::getState, DataStateEnum.ENABLE.getCode()).one(); } @@ -109,11 +109,13 @@ public class DictDataServiceImpl extends ServiceImpl i @Override public List dictDataCache() { MPJLambdaWrapper dictTypeWrapper = new MPJLambdaWrapper() + .eq(DictData::getState, DataStateEnum.ENABLE.getCode()) .selectAll(DictData.class) .selectAs(DictType::getId, DictDataCache::getTypeId) .selectAs(DictType::getName, DictDataCache::getTypeName) .selectAs(DictType::getCode, DictDataCache::getTypeCode) - .leftJoin(DictType.class, DictType::getId, DictData::getTypeId); + .leftJoin(DictType.class, DictType::getId, DictData::getTypeId) + .eq(DictType::getState, DataStateEnum.ENABLE.getCode()); List allDictData = this.getBaseMapper().selectJoinList(DictDataCache.class, dictTypeWrapper); Map> dictDataCacheMap = allDictData.stream() @@ -166,10 +168,9 @@ public class DictDataServiceImpl extends ServiceImpl i */ private void checkDicDataName(DictDataParam dictDataParam, boolean isExcludeSelf) { LambdaQueryWrapper dictDataLambdaQueryWrapper = new LambdaQueryWrapper<>(); - dictDataLambdaQueryWrapper - .eq(DictData::getName, dictDataParam.getName()) - .eq(DictData::getTypeId, dictDataParam.getTypeId()) - .eq(DictData::getState, DataStateEnum.ENABLE.getCode()); + dictDataLambdaQueryWrapper.eq(DictData::getTypeId, dictDataParam.getTypeId()) + .eq(DictData::getState, DataStateEnum.ENABLE.getCode()) + .and(w -> w.eq(DictData::getName, dictDataParam.getName()).or().eq(DictData::getCode, dictDataParam.getCode())); //更新的时候,需排除当前记录 if (isExcludeSelf) { if (dictDataParam instanceof DictDataParam.UpdateParam) { @@ -179,7 +180,7 @@ public class DictDataServiceImpl extends ServiceImpl i int countByAccount = this.count(dictDataLambdaQueryWrapper); //大于等于1个则表示重复 if (countByAccount >= 1) { - throw new BusinessException(SystemResponseEnum.DICT_DATA_NAME_REPEAT); + throw new BusinessException(SystemResponseEnum.DICT_DATA_REPEAT); } } } diff --git a/system/src/main/java/com/njcn/gather/system/dictionary/service/impl/DictTypeServiceImpl.java b/system/src/main/java/com/njcn/gather/system/dictionary/service/impl/DictTypeServiceImpl.java index e4612e65..3bf5bcb9 100644 --- a/system/src/main/java/com/njcn/gather/system/dictionary/service/impl/DictTypeServiceImpl.java +++ b/system/src/main/java/com/njcn/gather/system/dictionary/service/impl/DictTypeServiceImpl.java @@ -103,9 +103,8 @@ public class DictTypeServiceImpl extends ServiceImpl i */ private void checkDicTypeName(DictTypeParam dictTypeParam, boolean isExcludeSelf) { LambdaQueryWrapper dictTypeLambdaQueryWrapper = new LambdaQueryWrapper<>(); - dictTypeLambdaQueryWrapper - .eq(DictType::getName, dictTypeParam.getName()) - .eq(DictType::getState, DataStateEnum.ENABLE.getCode()); + dictTypeLambdaQueryWrapper.eq(DictType::getState, DataStateEnum.ENABLE.getCode()) + .and(w -> w.eq(DictType::getCode, dictTypeParam.getCode()).or().eq(DictType::getName, dictTypeParam.getName())); //更新的时候,需排除当前记录 if (isExcludeSelf) { if (dictTypeParam instanceof DictTypeParam.UpdateParam) { @@ -115,7 +114,7 @@ public class DictTypeServiceImpl extends ServiceImpl i int countByAccount = this.count(dictTypeLambdaQueryWrapper); //大于等于1个则表示重复 if (countByAccount >= 1) { - throw new BusinessException(SystemResponseEnum.DICT_TYPE_NAME_REPEAT); + throw new BusinessException(SystemResponseEnum.DICT_TYPE_REPEAT); } } } diff --git a/system/src/main/java/com/njcn/gather/system/pojo/enums/SystemResponseEnum.java b/system/src/main/java/com/njcn/gather/system/pojo/enums/SystemResponseEnum.java index f0cbbaf1..3d91747c 100644 --- a/system/src/main/java/com/njcn/gather/system/pojo/enums/SystemResponseEnum.java +++ b/system/src/main/java/com/njcn/gather/system/pojo/enums/SystemResponseEnum.java @@ -15,8 +15,8 @@ public enum SystemResponseEnum { * A00350 ~ A00449 */ SYSTEM_COMMON_ERROR("A00350","系统模块异常"), - DICT_TYPE_NAME_REPEAT("A00351", "字典类型名称重复"), - DICT_DATA_NAME_REPEAT("A00352", "字典数据名称重复"), + DICT_TYPE_REPEAT("A00351", "字典类型名称或编码重复"), + DICT_DATA_REPEAT("A00352", "字典数据名称或编码重复"), AREA_CODE_REPEAT("A00353","行政区域编码重复"), LOAD_TYPE_EMPTY("A00354","用能负荷数据为空"), LINE_MARK_EMPTY("A00355","字典监测点评分等级数据为空"), 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 188a1872..8b372e22 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 @@ -14,7 +14,9 @@ public enum UserResponseEnum { REGISTER_EMAIL_FAIL("A010004", "该邮箱已被注册"), NAME_OR_CODE_REPEAT("A010005", "名称或编码已存在"), EXISTS_SAME_MENU_CHILDREN("A010006", "当前菜单下已存在相同的子菜单"), - EXISTS_CHILDREN("A010007", "该节点下存在子节点,请先无法删除"); + EXISTS_CHILDREN_NOT_UPDATE("A010008", "该菜单下存在子节点,无法将菜单修改为按钮"), + EXISTS_CHILDREN_NOT_DELETE("A010007", "该节点下存在子节点,无法删除"), + ADMINSTRATOR_ROLE_CANNOT_DELETE("A010009", "超级管理员及管理员角色禁止删除"),; 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 index 98ed302b..a9471805 100644 --- 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 @@ -37,6 +37,17 @@ public class SysFunctionController extends BaseController { private final ISysFunctionService sysFunctionService; private final ISysRoleFunctionService sysRoleFunctionService; + @OperateInfo(info = LogEnum.SYSTEM_COMMON) + @PostMapping("/list") + @ApiOperation("分页查询菜单树") + @ApiImplicitParam(name = "queryParam", value = "查询参数", required = true) + public HttpResult> list(@RequestBody @Validated SysFunctionParam.QueryParam queryParam) { + String methodDescribe = getMethodDescribe("list"); + LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, queryParam); + List result = sysFunctionService.listFunction(queryParam); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); + } + @OperateInfo(info = LogEnum.SYSTEM_COMMON) @GetMapping("/functionTree") @ApiOperation("菜单树") @@ -71,7 +82,7 @@ public class SysFunctionController extends BaseController { } @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.UPDATE) - @PutMapping("/update") + @PostMapping("/update") @ApiOperation("修改菜单") @ApiImplicitParam(name = "functionParam", value = "菜单数据", required = true) public HttpResult update(@RequestBody @Validated SysFunctionParam.UpdateParam functionParam) { @@ -133,11 +144,11 @@ public class SysFunctionController extends BaseController { // } @OperateInfo(operateType = OperateType.UPDATE, info = LogEnum.SYSTEM_MEDIUM) - @PutMapping("/assignFunctionByRoleId") + @PostMapping("/assignFunctionByRoleId") @ApiOperation("角色分配菜单") @ApiImplicitParam(name = "roleFunctionComponent", value = "角色信息", required = true) - public HttpResult assignFunctionByRoleIndexes(@RequestBody @Validated SysRoleParam.RoleBindFunction param) { - String methodDescribe = getMethodDescribe("assignFunctionByRoleIndexes"); + public HttpResult assignFunctionByRoleId(@RequestBody @Validated SysRoleParam.RoleBindFunction param) { + String methodDescribe = getMethodDescribe("assignFunctionByRoleId"); LogUtil.njcnDebug(log, "{},传入的角色id和资源id集合为:{}", methodDescribe, param); boolean result = sysRoleFunctionService.updateRoleFunction(param.getRoleId(), param.getFunctionIds()); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, 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 bca9cc7b..81751b5d 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 @@ -65,7 +65,7 @@ public class SysRoleController extends BaseController { } @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.UPDATE) - @PutMapping("/update") + @PostMapping("/update") @ApiOperation("修改角色信息") @ApiImplicitParam(name = "updateParam", value = "角色信息", required = true) public HttpResult update(@RequestBody @Validated SysRoleParam.UpdateParam updateParam) { 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 2af01c6e..5785f66d 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 @@ -89,7 +89,7 @@ public class SysUserController extends BaseController { } @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.UPDATE) - @PutMapping("/update") + @PostMapping("/update") @ApiOperation("修改用户") @ApiImplicitParam(name = "updateUserParam", value = "修改用户", required = true) public HttpResult update(@RequestBody @Validated SysUserParam.SysUserUpdateParam updateUserParam) { @@ -123,7 +123,7 @@ public class SysUserController extends BaseController { } @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.UPDATE) - @PutMapping("/updatePassword") + @PostMapping("/updatePassword") @ApiOperation("修改密码") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "用户id", required = true), 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 index 1e9d48c2..43dd6b77 100644 --- 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 @@ -6,8 +6,8 @@ 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 + where a.Role_Id = #{roleId} and b.type in (0, 1) + and b.state = 1 order by b.sort,b.Update_Time desc 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 index 45061534..9a4ac2bb 100644 --- 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 @@ -2,6 +2,7 @@ package com.njcn.gather.user.user.pojo.param; import com.njcn.common.pojo.constant.PatternRegex; import com.njcn.gather.user.pojo.constant.UserValidMessage; +import com.njcn.web.pojo.param.BaseParam; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; @@ -55,6 +56,18 @@ public class SysFunctionParam { @ApiModelProperty("描述") private String remark; + @Data + @EqualsAndHashCode(callSuper = true) + public static class QueryParam extends BaseParam { + @ApiModelProperty("名称") + @Pattern(regexp = PatternRegex.FUNCTION_NAME, message = UserValidMessage.NAME_FORMAT_ERROR) + private String name; + + @ApiModelProperty("资源类型") + @Range(min = 0, max = 3, message = UserValidMessage.PARAM_FORMAT_ERROR) + private Integer type; + } + @Data @EqualsAndHashCode(callSuper = true) public static class UpdateParam extends SysFunctionParam { 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 index fd191418..fe67c463 100644 --- 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 @@ -2,7 +2,6 @@ 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; @@ -13,6 +12,14 @@ import java.util.List; */ public interface ISysFunctionService extends IService { + /** + * 获取菜单(资源)列表 + * + * @param queryParam 查询参数 + * @return 菜单列表 + */ + List listFunction(SysFunctionParam.QueryParam queryParam); + /** * 添加菜单(资源) * 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 a5a1a894..a820340f 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,7 +3,6 @@ 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; @@ -45,29 +44,6 @@ public interface ISysRoleService extends IService { */ boolean deleteRole(List ids); - /** - * 查询所有角色列表 - * - * @return 角色列表 - */ - //List listAllRole(); - - /** - * 根据权限类型type获取角色列表 - * - * @param type 角色类型 - * @return 角色列表 - */ - //List listRoleByType(Integer type); - - /** - * 根据用户id获取角色 - * - * @param userId 用户id - * @return 角色列表 - */ - //List listRoleByUserId(String userId); - /** * 查询所有角色作为下拉框 * @@ -80,7 +56,5 @@ 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/impl/SysFunctionServiceImpl.java b/user/src/main/java/com/njcn/gather/user/user/service/impl/SysFunctionServiceImpl.java index f87adbbe..7d428b58 100644 --- 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 @@ -1,6 +1,8 @@ package com.njcn.gather.user.user.service.impl; import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.njcn.common.pojo.enums.common.DataStateEnum; @@ -34,6 +36,20 @@ public class SysFunctionServiceImpl extends ServiceImpl listFunction(SysFunctionParam.QueryParam queryParam) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + if (ObjectUtil.isNotNull(queryParam)) { + wrapper.like(StrUtil.isNotBlank(queryParam.getName()), SysFunction::getName, queryParam.getName()).eq(ObjectUtil.isNotNull(queryParam.getType()), SysFunction::getType, queryParam.getType()); + } + wrapper.eq(SysFunction::getState, DataStateEnum.ENABLE.getCode()); + 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 boolean addFunction(SysFunctionParam functionParam) { checkFunctionParam(functionParam, false); @@ -60,10 +76,17 @@ public class SysFunctionServiceImpl extends ServiceImpl childrenList = this.lambdaQuery().eq(SysFunction::getPid, param.getId()).eq(SysFunction::getState, DataStateEnum.ENABLE.getCode()).list(); + if (oldFunction.getType().equals(FunctionConst.TYPE_MENU) && param.getType().equals(FunctionConst.TYPE_BUTTON) && !CollectionUtils.isEmpty(childrenList)) { + throw new BusinessException(UserResponseEnum.EXISTS_CHILDREN_NOT_UPDATE); + } else { + SysFunction function = new SysFunction(); + BeanUtil.copyProperties(param, function); + result = this.updateById(function); + } // if (result) { // refreshRolesFunctionsCache(); // } @@ -81,7 +104,7 @@ public class SysFunctionServiceImpl extends ServiceImpl impl public Page listRole(SysRoleParam.QueryParam queryParam) { QueryWrapper queryWrapper = new QueryWrapper<>(); if (ObjectUtil.isNotNull(queryParam)) { - queryWrapper.like(StrUtil.isNotBlank(queryParam.getName()), "sys_role.name", queryParam.getName()) - .eq(StrUtil.isNotBlank(queryParam.getCode()), "sys_role.code", queryParam.getCode()) - .eq(ObjectUtil.isNotNull(queryParam.getType()), "sys_role.type", queryParam.getType()); + queryWrapper.like(StrUtil.isNotBlank(queryParam.getName()), "sys_role.name", queryParam.getName()).eq(StrUtil.isNotBlank(queryParam.getCode()), "sys_role.code", queryParam.getCode()).eq(ObjectUtil.isNotNull(queryParam.getType()), "sys_role.type", queryParam.getType()); } // if (queryParam.getType().equals(0)) { // queryWrapper.in("sys_role.type", queryParam.getType(), 1); // } else if (queryParam.getType().equals(1)) { // queryWrapper.eq("sys_role.type", 2); // } - queryWrapper.eq("sys_role.state", DataStateEnum.ENABLE.getCode()); + queryWrapper.eq("sys_role.state", DataStateEnum.ENABLE.getCode()).orderByDesc("sys_role.Update_Time"); return this.baseMapper.selectPage(new Page<>(PageFactory.getPageNum(queryParam), PageFactory.getPageSize(queryParam)), queryWrapper); } @@ -72,37 +71,24 @@ public class SysRoleServiceImpl extends ServiceImpl impl @Override public boolean deleteRole(List ids) { + //超级管理员、管理员角色不能删除 + Integer count = this.lambdaQuery() + .in(SysRole::getType, RoleConst.TYPE_SUPER_ADMINISTRATOR, RoleConst.TYPE_ADMINISTRATOR) + .in(SysRole::getId, ids).eq(SysRole::getState, DataStateEnum.ENABLE.getCode()).count(); + if (count > 0) { + throw new BusinessException(UserResponseEnum.ADMINSTRATOR_ROLE_CANNOT_DELETE); + } // 删除角色和用户的绑定 sysUserRoleService.deleteUserRoleByRoleIds(ids); //删除角色和资源的绑定 sysRoleFunctionService.deleteRoleFunctionByRoleIds(ids); - return this.lambdaUpdate() - .set(SysRole::getState, DataStateEnum.DELETED.getCode()) - .in(SysRole::getId, ids).update(); + 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 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 simpleList() { LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); -// lambdaQueryWrapper.select(SysRole::getId, SysRole::getName).eq(SysRole::getState, DataStateEnum.ENABLE.getCode()).eq(SysRole::getType, RoleConst.TYPE_USER); - lambdaQueryWrapper.select(SysRole::getId, SysRole::getName).eq(SysRole::getState, DataStateEnum.ENABLE.getCode()); + lambdaQueryWrapper.select(SysRole::getId, SysRole::getName).ne(SysRole::getType, RoleConst.TYPE_SUPER_ADMINISTRATOR).eq(SysRole::getState, DataStateEnum.ENABLE.getCode()); return this.baseMapper.selectList(lambdaQueryWrapper); } @@ -126,9 +112,8 @@ public class SysRoleServiceImpl extends ServiceImpl impl private void checkRepeat(SysRoleParam roleParam, boolean isExcludeSelf) { LambdaQueryWrapper roleLambdaQueryWrapper = new LambdaQueryWrapper<>(); roleLambdaQueryWrapper - .eq(SysRole::getName, roleParam.getName()) - .eq(SysRole::getCode, roleParam.getCode()) - .eq(SysRole::getState, DataStateEnum.ENABLE.getCode()); + .eq(SysRole::getState, DataStateEnum.ENABLE.getCode()) + .and(w -> w.eq(SysRole::getName, roleParam.getName()).or().eq(SysRole::getCode, roleParam.getCode())); //更新的时候,需排除当前记录 if (isExcludeSelf) { if (roleParam instanceof SysRoleParam.UpdateParam) {