mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-14 13:42:07 +08:00
bug修改-权限获取
This commit is contained in:
+2
-2
@@ -62,8 +62,8 @@ public class PlateController {
|
|||||||
@DeleteMapping("/delete")
|
@DeleteMapping("/delete")
|
||||||
@Operation(summary = "删除板材信息")
|
@Operation(summary = "删除板材信息")
|
||||||
@Parameters({
|
@Parameters({
|
||||||
@Parameter(name = "id", description = "编号", required = true),
|
@Parameter(name = "id", description = "编号", required = true, example = "1024"),
|
||||||
@Parameter(name = "organId", description = "板材所属组织ID")
|
@Parameter(name = "organId", description = "板材所属组织ID", example = "1024")
|
||||||
})
|
})
|
||||||
// @PreAuthorize("@ss.hasPermission('manage:plate:delete')")
|
// @PreAuthorize("@ss.hasPermission('manage:plate:delete')")
|
||||||
@PreAuthorize("@ss.hasAnyPermissions('manage:plate:delete','base:plate:delete')")
|
@PreAuthorize("@ss.hasAnyPermissions('manage:plate:delete','base:plate:delete')")
|
||||||
|
|||||||
+2
-1
@@ -1,12 +1,13 @@
|
|||||||
package com.cf.imes.module.manage.framework.rpc.config;
|
package com.cf.imes.module.manage.framework.rpc.config;
|
||||||
|
|
||||||
import com.cf.imes.module.system.api.organ.OrganApi;
|
import com.cf.imes.module.system.api.organ.OrganApi;
|
||||||
|
import com.cf.imes.module.system.api.permission.PermissionApi;
|
||||||
import com.cf.imes.module.system.api.process.ProcessApi;
|
import com.cf.imes.module.system.api.process.ProcessApi;
|
||||||
import com.cf.imes.module.system.api.user.AdminUserApi;
|
import com.cf.imes.module.system.api.user.AdminUserApi;
|
||||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@EnableFeignClients(clients = {AdminUserApi.class, OrganApi.class, ProcessApi.class})
|
@EnableFeignClients(clients = {AdminUserApi.class, OrganApi.class, ProcessApi.class, PermissionApi.class})
|
||||||
public class RpcConfiguration {
|
public class RpcConfiguration {
|
||||||
}
|
}
|
||||||
|
|||||||
+43
-14
@@ -10,6 +10,7 @@ import com.cf.imes.module.manage.controller.admin.plate.vo.plate.PlateImportResp
|
|||||||
import com.cf.imes.module.manage.controller.admin.plate.vo.plate.PlatePageReqVO;
|
import com.cf.imes.module.manage.controller.admin.plate.vo.plate.PlatePageReqVO;
|
||||||
import com.cf.imes.module.manage.controller.admin.plate.vo.plate.PlateSaveReqVO;
|
import com.cf.imes.module.manage.controller.admin.plate.vo.plate.PlateSaveReqVO;
|
||||||
import com.cf.imes.module.system.api.organ.OrganApi;
|
import com.cf.imes.module.system.api.organ.OrganApi;
|
||||||
|
import com.cf.imes.module.system.api.permission.PermissionApi;
|
||||||
import com.cf.imes.module.system.enums.ErrorCodeConstants;
|
import com.cf.imes.module.system.enums.ErrorCodeConstants;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
@@ -26,6 +27,7 @@ import com.cf.imes.module.manage.dal.mysql.plate.PlateMapper;
|
|||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
|
import static com.cf.imes.framework.security.core.util.SecurityFrameworkUtils.getLoginUser;
|
||||||
import static com.cf.imes.module.system.enums.ErrorCodeConstants.PLATE_NOT_EXISTS;
|
import static com.cf.imes.module.system.enums.ErrorCodeConstants.PLATE_NOT_EXISTS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -43,22 +45,29 @@ public class PlateServiceImpl implements PlateService {
|
|||||||
@Resource
|
@Resource
|
||||||
private OrganApi organApi;
|
private OrganApi organApi;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private PermissionApi permissionApi;
|
||||||
|
|
||||||
|
private final static String BASE_PLATE_IMPORT_PERMISSION = "base:plate:import"; // 导入板材
|
||||||
|
private final static String BASE_PLATE_DELETE_PERMISSION = "base:plate:delete"; // 删除板材信息
|
||||||
|
private final static String BASE_PLATE_CREATE_PERMISSION = "base:plate:create"; // 创建板材信息
|
||||||
|
private final static String BASE_PLATE_UPDATE_PERMISSION = "base:plate:update"; // 更新板材信息
|
||||||
|
private final static String BASE_PLATE_QUERY_PERMISSION = "base:plate:query"; // 获得板材信息
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@OrganIgnore
|
@OrganIgnore
|
||||||
public Long createPlate(PlateSaveReqVO createReqVO) {
|
public Long createPlate(PlateSaveReqVO createReqVO) {
|
||||||
PlateDO plate = BeanUtils.toBean(createReqVO, PlateDO.class);
|
PlateDO plate = BeanUtils.toBean(createReqVO, PlateDO.class);
|
||||||
if (createReqVO.getOrganId() != null && createReqVO.getOrganId() != 0 ){
|
if (permissionApi.hasRoles(getLoginUser().getId(), BASE_PLATE_CREATE_PERMISSION).getData()){
|
||||||
validateOrganExists(createReqVO.getOrganId());
|
if (plate.getOrganId() != null && plate.getOrganId() != 0 ){
|
||||||
validateGoodExists(createReqVO.getGoodsId(), createReqVO.getOrganId());
|
validateOrganExists(plate.getOrganId());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
plate.setOrganId(OrganContextHolder.getOrganId());
|
plate.setOrganId(OrganContextHolder.getOrganId());
|
||||||
}
|
}
|
||||||
// 判断板材是否存在
|
// 判断板材是否存在
|
||||||
PlateDO existPlate = plateMapper.selectByGoodID(createReqVO.getGoodsId(), plate.getOrganId());
|
validateGoodExists(plate.getGoodsId(),plate.getOrganId());
|
||||||
|
|
||||||
if (existPlate != null){
|
|
||||||
throw exception(ErrorCodeConstants.PLATE_EXISTS);
|
|
||||||
}
|
|
||||||
plateMapper.insert(plate);// 组织id未传输
|
plateMapper.insert(plate);// 组织id未传输
|
||||||
// 返回
|
// 返回
|
||||||
return plate.getId();
|
return plate.getId();
|
||||||
@@ -69,10 +78,13 @@ public class PlateServiceImpl implements PlateService {
|
|||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void updatePlate(PlateSaveReqVO updateReqVO) {
|
public void updatePlate(PlateSaveReqVO updateReqVO) {
|
||||||
// 更新 判断是否有组织id
|
// 更新 判断是否有组织id
|
||||||
if (updateReqVO.getOrganId() == null || updateReqVO.getOrganId() == 0){
|
if (permissionApi.hasRoles(getLoginUser().getId(), BASE_PLATE_UPDATE_PERMISSION).getData()){
|
||||||
|
if (updateReqVO.getOrganId() != null && updateReqVO.getOrganId() != 0 ){
|
||||||
|
validateOrganExists(updateReqVO.getOrganId());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
updateReqVO.setOrganId(OrganContextHolder.getOrganId());
|
updateReqVO.setOrganId(OrganContextHolder.getOrganId());
|
||||||
}
|
}
|
||||||
validateOrganExists(updateReqVO.getOrganId());
|
|
||||||
|
|
||||||
// 校验存在
|
// 校验存在
|
||||||
validatePlateExists(updateReqVO.getId(), updateReqVO.getOrganId());
|
validatePlateExists(updateReqVO.getId(), updateReqVO.getOrganId());
|
||||||
@@ -84,10 +96,13 @@ public class PlateServiceImpl implements PlateService {
|
|||||||
@OrganIgnore
|
@OrganIgnore
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void deletePlate(Long id,Long organId) {
|
public void deletePlate(Long id,Long organId) {
|
||||||
if (organId == null || organId == 0){
|
if (permissionApi.hasRoles(getLoginUser().getId(), BASE_PLATE_DELETE_PERMISSION).getData()){
|
||||||
|
if (organId != null && organId != 0 ){
|
||||||
|
validateOrganExists(organId);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
organId = OrganContextHolder.getOrganId();
|
organId = OrganContextHolder.getOrganId();
|
||||||
}
|
}
|
||||||
validateOrganExists(organId);
|
|
||||||
|
|
||||||
// 校验存在
|
// 校验存在
|
||||||
validatePlateExists(id,organId);
|
validatePlateExists(id,organId);
|
||||||
@@ -115,6 +130,13 @@ public class PlateServiceImpl implements PlateService {
|
|||||||
@Override
|
@Override
|
||||||
@OrganIgnore
|
@OrganIgnore
|
||||||
public PageResult<PlateDO> getPlatePage(PlatePageReqVO pageReqVO) {
|
public PageResult<PlateDO> getPlatePage(PlatePageReqVO pageReqVO) {
|
||||||
|
if (permissionApi.hasRoles(getLoginUser().getId(), BASE_PLATE_QUERY_PERMISSION).getData()){
|
||||||
|
if (pageReqVO.getOrganId() != null && pageReqVO.getOrganId() != 0 ){
|
||||||
|
validateOrganExists(pageReqVO.getOrganId());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
pageReqVO.setOrganId(OrganContextHolder.getOrganId());
|
||||||
|
}
|
||||||
if (pageReqVO.getOrganId() == null || pageReqVO.getOrganId() == 0){
|
if (pageReqVO.getOrganId() == null || pageReqVO.getOrganId() == 0){
|
||||||
pageReqVO.setOrganId(OrganContextHolder.getOrganId());
|
pageReqVO.setOrganId(OrganContextHolder.getOrganId());
|
||||||
}
|
}
|
||||||
@@ -130,25 +152,32 @@ public class PlateServiceImpl implements PlateService {
|
|||||||
// if (CollUtil.isEmpty(importPlates)) {
|
// if (CollUtil.isEmpty(importPlates)) {
|
||||||
// throw ServiceExceptionUtil.exception(ErrorCodeConstants.PLATE_IMPORT_LIST_IS_EMPTY);
|
// throw ServiceExceptionUtil.exception(ErrorCodeConstants.PLATE_IMPORT_LIST_IS_EMPTY);
|
||||||
// }
|
// }
|
||||||
|
if (permissionApi.hasRoles(getLoginUser().getId(), BASE_PLATE_IMPORT_PERMISSION).getData()){
|
||||||
|
if (organId != null && organId != 0 ){
|
||||||
validateOrganExists(organId);
|
validateOrganExists(organId);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
organId = OrganContextHolder.getOrganId();
|
||||||
|
}
|
||||||
PlateImportRespVO respVO = PlateImportRespVO.builder().createPlateNames(new ArrayList<>())
|
PlateImportRespVO respVO = PlateImportRespVO.builder().createPlateNames(new ArrayList<>())
|
||||||
.updatePlateNames(new ArrayList<>()).failurePlateNames(new LinkedHashMap<>()).build();
|
.updatePlateNames(new ArrayList<>()).failurePlateNames(new LinkedHashMap<>()).build();
|
||||||
// 批量插入集合
|
// 批量插入集合
|
||||||
List<PlateDO> insertList = new ArrayList<>();
|
List<PlateDO> insertList = new ArrayList<>();
|
||||||
// 批量更新集合
|
// 批量更新集合
|
||||||
List<PlateDO> updateList = new ArrayList<>();
|
List<PlateDO> updateList = new ArrayList<>();
|
||||||
|
Long finalOrganId = organId;
|
||||||
importPlates.forEach(importPlate -> {
|
importPlates.forEach(importPlate -> {
|
||||||
// 判断如果不存在,在进行插入
|
// 判断如果不存在,在进行插入
|
||||||
PlateDO existPlate = plateMapper.selectByGoodID(importPlate.getGoodsId(), organId);
|
PlateDO existPlate = plateMapper.selectByGoodID(importPlate.getGoodsId(), finalOrganId);
|
||||||
if (existPlate == null) {
|
if (existPlate == null) {
|
||||||
respVO.getCreatePlateNames().add(importPlate.getGoodsName());
|
respVO.getCreatePlateNames().add(importPlate.getGoodsName());
|
||||||
insertList.add(BeanUtils.toBean(importPlate, PlateDO.class).setOrganId(organId).setTexture(Boolean.valueOf(importPlate.getTexture())));
|
insertList.add(BeanUtils.toBean(importPlate, PlateDO.class).setOrganId(finalOrganId).setTexture(Boolean.valueOf(importPlate.getTexture())));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 判断是否允许更新
|
// 判断是否允许更新
|
||||||
if (!isUpdateSupport) {
|
if (!isUpdateSupport) {
|
||||||
respVO.getFailurePlateNames().put(importPlate.getGoodsName(), ErrorCodeConstants.PLATE_EXISTS.getMsg());
|
respVO.getFailurePlateNames().put(importPlate.getGoodsName(), ErrorCodeConstants.PLATE_EXISTS.getMsg());
|
||||||
PlateDO plateDO = BeanUtils.toBean(importPlate, PlateDO.class).setOrganId(organId).setId(existPlate.getId()).setTexture(Boolean.valueOf(importPlate.getTexture()));
|
PlateDO plateDO = BeanUtils.toBean(importPlate, PlateDO.class).setOrganId(finalOrganId).setId(existPlate.getId()).setTexture(Boolean.valueOf(importPlate.getTexture()));
|
||||||
updateList.add(plateDO);
|
updateList.add(plateDO);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
+13
@@ -48,4 +48,17 @@ public interface PermissionApi {
|
|||||||
@Parameter(name = "userId", description = "用户编号", example = "2", required = true)
|
@Parameter(name = "userId", description = "用户编号", example = "2", required = true)
|
||||||
CommonResult<DeptDataPermissionRespDTO> getDeptDataPermission(@RequestParam("userId") Long userId);
|
CommonResult<DeptDataPermissionRespDTO> getDeptDataPermission(@RequestParam("userId") Long userId);
|
||||||
|
|
||||||
|
@GetMapping(PREFIX + "/user-role-id-list-by-user-id")
|
||||||
|
@Operation(summary = "获得拥有多个角色的用户编号集合")
|
||||||
|
@Parameter(name = "roleIds", description = "角色编号集合", example = "1,2", required = true)
|
||||||
|
CommonResult<Set<String>> getUserRoleIdListByUserIds(@RequestParam("userId") Long userId);
|
||||||
|
|
||||||
|
@GetMapping(PREFIX + "/has-roles")
|
||||||
|
@Operation(summary = "判断用户是否拥有权限标识")
|
||||||
|
@Parameters({
|
||||||
|
@Parameter(name = "userId", description = "用户编号", example = "1", required = true),
|
||||||
|
@Parameter(name = "permission", description = "权限标识", example = "2", required = true)
|
||||||
|
})
|
||||||
|
CommonResult<Boolean> hasRoles(@RequestParam("userId") Long userId,
|
||||||
|
@RequestParam("permission") String permission);
|
||||||
}
|
}
|
||||||
|
|||||||
+11
@@ -40,4 +40,15 @@ public class PermissionApiImpl implements PermissionApi {
|
|||||||
return success(deptDataPermission);
|
return success(deptDataPermission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommonResult<Set<String>> getUserRoleIdListByUserIds(Long userId) {
|
||||||
|
return success(permissionService.getUserPermissions(userId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommonResult<Boolean> hasRoles(Long userId, String permission) {
|
||||||
|
Set<String> permissions = permissionService.getUserPermissions(userId);
|
||||||
|
return success(permissions.contains(permission));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+10
@@ -171,4 +171,14 @@ public interface PermissionService {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
Set<Long> getListRoleUsers(Long roleId, Long organId);
|
Set<Long> getListRoleUsers(Long roleId, Long organId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户权限标识
|
||||||
|
*/
|
||||||
|
Set<String> getUserPermissions(Long userId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断用户是否拥有相对应的权限
|
||||||
|
*/
|
||||||
|
Boolean hasPermission(Long userId, String permission);
|
||||||
}
|
}
|
||||||
|
|||||||
+30
@@ -18,6 +18,7 @@ import com.cf.imes.module.system.api.permission.dto.DeptDataPermissionRespDTO;
|
|||||||
import com.cf.imes.module.system.constants.permission.InternalRoleConstants;
|
import com.cf.imes.module.system.constants.permission.InternalRoleConstants;
|
||||||
import com.cf.imes.module.system.controller.admin.permission.vo.permission.PermissionAssignRoleUserReqVO;
|
import com.cf.imes.module.system.controller.admin.permission.vo.permission.PermissionAssignRoleUserReqVO;
|
||||||
import com.cf.imes.module.system.controller.admin.permission.vo.permission.PermissionAssignUserRoleReqVO;
|
import com.cf.imes.module.system.controller.admin.permission.vo.permission.PermissionAssignUserRoleReqVO;
|
||||||
|
import com.cf.imes.module.system.convert.auth.AuthConvert;
|
||||||
import com.cf.imes.module.system.dal.dataobject.permission.MenuDO;
|
import com.cf.imes.module.system.dal.dataobject.permission.MenuDO;
|
||||||
import com.cf.imes.module.system.dal.dataobject.permission.RoleDO;
|
import com.cf.imes.module.system.dal.dataobject.permission.RoleDO;
|
||||||
import com.cf.imes.module.system.dal.dataobject.permission.RoleMenuDO;
|
import com.cf.imes.module.system.dal.dataobject.permission.RoleMenuDO;
|
||||||
@@ -53,8 +54,10 @@ import java.util.function.Supplier;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
|
import static com.cf.imes.framework.common.pojo.CommonResult.success;
|
||||||
import static com.cf.imes.framework.common.util.collection.CollectionUtils.convertSet;
|
import static com.cf.imes.framework.common.util.collection.CollectionUtils.convertSet;
|
||||||
import static com.cf.imes.framework.common.util.json.JsonUtils.toJsonString;
|
import static com.cf.imes.framework.common.util.json.JsonUtils.toJsonString;
|
||||||
|
import static com.cf.imes.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||||
import static com.cf.imes.module.system.enums.ErrorCodeConstants.ROLE_ME_ERROR;
|
import static com.cf.imes.module.system.enums.ErrorCodeConstants.ROLE_ME_ERROR;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -596,4 +599,31 @@ public class PermissionServiceImpl implements PermissionService {
|
|||||||
return SpringUtil.getBean(getClass());
|
return SpringUtil.getBean(getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户权限标识
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Set<String> getUserPermissions(Long userId) {
|
||||||
|
// 1.2 获得角色列表
|
||||||
|
Set<Long> roleIds = getUserRoleIdListByUserId(getLoginUserId());
|
||||||
|
if (CollUtil.isEmpty(roleIds)) {
|
||||||
|
return Collections.emptySet();
|
||||||
|
}
|
||||||
|
List<RoleDO> roles = roleService.getRoleList1(roleIds);
|
||||||
|
roles.removeIf(role -> !CommonStatusEnum.ENABLE.getStatus().equals(role.getStatus())); // 移除禁用的角色
|
||||||
|
|
||||||
|
// 1.3 获得菜单列表
|
||||||
|
Set<Long> menuIds = getRoleMenuListByRoleId2(convertSet(roles, RoleDO::getId));
|
||||||
|
List<MenuDO> menuList = menuService.getMenuList1(menuIds);
|
||||||
|
menuList.removeIf(menu -> !CommonStatusEnum.ENABLE.getStatus().equals(menu.getStatus())); // 移除禁用的菜单
|
||||||
|
|
||||||
|
return convertSet(menuList, MenuDO::getPermission);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean hasPermission(Long userId, String permission) {
|
||||||
|
Set<String> permissions = getUserPermissions(userId);
|
||||||
|
return permissions.contains(permission);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user