bug修改-权限获取

This commit is contained in:
lym
2024-07-26 11:18:37 +08:00
parent d7d45accf2
commit f6e72c35b7
7 changed files with 113 additions and 19 deletions
@@ -62,8 +62,8 @@ public class PlateController {
@DeleteMapping("/delete")
@Operation(summary = "删除板材信息")
@Parameters({
@Parameter(name = "id", description = "编号", required = true),
@Parameter(name = "organId", description = "板材所属组织ID")
@Parameter(name = "id", description = "编号", required = true, example = "1024"),
@Parameter(name = "organId", description = "板材所属组织ID", example = "1024")
})
// @PreAuthorize("@ss.hasPermission('manage:plate:delete')")
@PreAuthorize("@ss.hasAnyPermissions('manage:plate:delete','base:plate:delete')")
@@ -1,12 +1,13 @@
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.permission.PermissionApi;
import com.cf.imes.module.system.api.process.ProcessApi;
import com.cf.imes.module.system.api.user.AdminUserApi;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Configuration;
@Configuration(proxyBeanMethods = false)
@EnableFeignClients(clients = {AdminUserApi.class, OrganApi.class, ProcessApi.class})
@EnableFeignClients(clients = {AdminUserApi.class, OrganApi.class, ProcessApi.class, PermissionApi.class})
public class RpcConfiguration {
}
@@ -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.PlateSaveReqVO;
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 org.springframework.stereotype.Service;
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 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;
/**
@@ -43,22 +45,29 @@ public class PlateServiceImpl implements PlateService {
@Resource
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
@OrganIgnore
public Long createPlate(PlateSaveReqVO createReqVO) {
PlateDO plate = BeanUtils.toBean(createReqVO, PlateDO.class);
if (createReqVO.getOrganId() != null && createReqVO.getOrganId() != 0 ){
validateOrganExists(createReqVO.getOrganId());
validateGoodExists(createReqVO.getGoodsId(), createReqVO.getOrganId());
}else {
if (permissionApi.hasRoles(getLoginUser().getId(), BASE_PLATE_CREATE_PERMISSION).getData()){
if (plate.getOrganId() != null && plate.getOrganId() != 0 ){
validateOrganExists(plate.getOrganId());
}
} else {
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未传输
// 返回
return plate.getId();
@@ -69,10 +78,13 @@ public class PlateServiceImpl implements PlateService {
@Transactional(rollbackFor = Exception.class)
public void updatePlate(PlateSaveReqVO updateReqVO) {
// 更新 判断是否有组织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());
}
validateOrganExists(updateReqVO.getOrganId());
// 校验存在
validatePlateExists(updateReqVO.getId(), updateReqVO.getOrganId());
@@ -84,10 +96,13 @@ public class PlateServiceImpl implements PlateService {
@OrganIgnore
@Transactional(rollbackFor = Exception.class)
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();
}
validateOrganExists(organId);
// 校验存在
validatePlateExists(id,organId);
@@ -115,6 +130,13 @@ public class PlateServiceImpl implements PlateService {
@Override
@OrganIgnore
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){
pageReqVO.setOrganId(OrganContextHolder.getOrganId());
}
@@ -130,25 +152,32 @@ public class PlateServiceImpl implements PlateService {
// if (CollUtil.isEmpty(importPlates)) {
// throw ServiceExceptionUtil.exception(ErrorCodeConstants.PLATE_IMPORT_LIST_IS_EMPTY);
// }
validateOrganExists(organId);
if (permissionApi.hasRoles(getLoginUser().getId(), BASE_PLATE_IMPORT_PERMISSION).getData()){
if (organId != null && organId != 0 ){
validateOrganExists(organId);
}
} else {
organId = OrganContextHolder.getOrganId();
}
PlateImportRespVO respVO = PlateImportRespVO.builder().createPlateNames(new ArrayList<>())
.updatePlateNames(new ArrayList<>()).failurePlateNames(new LinkedHashMap<>()).build();
// 批量插入集合
List<PlateDO> insertList = new ArrayList<>();
// 批量更新集合
List<PlateDO> updateList = new ArrayList<>();
Long finalOrganId = organId;
importPlates.forEach(importPlate -> {
// 判断如果不存在,在进行插入
PlateDO existPlate = plateMapper.selectByGoodID(importPlate.getGoodsId(), organId);
PlateDO existPlate = plateMapper.selectByGoodID(importPlate.getGoodsId(), finalOrganId);
if (existPlate == null) {
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;
}
// 判断是否允许更新
if (!isUpdateSupport) {
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);
}
});