This commit is contained in:
六如
2024-10-21 14:15:03 +08:00
parent c84a05b522
commit 89304e8004
15 changed files with 41 additions and 94 deletions

View File

@@ -32,7 +32,7 @@ public class ExceptionHandlerController {
log.error("报错code:{}, msg:{}", errorCode.getCode(), errorCode.getMsg(), e);
return Result.err(errorCode.getCode(), errorCode.getMsg());
}
if (e instanceof BizException || e instanceof IllegalArgumentException) {
if (e instanceof BizException) {
RuntimeException bizException = (RuntimeException) e;
return Result.err(bizException.getMessage());
}

View File

@@ -2,7 +2,6 @@ package com.gitee.sop.adminbackend.controller.isv;
import com.gitee.sop.adminbackend.common.resp.Result;
import com.gitee.sop.adminbackend.controller.isv.req.IsvGroupSettingParam;
import com.gitee.sop.adminbackend.dao.entity.PermGroup;
import com.gitee.sop.adminbackend.service.isv.PermIsvGroupService;
import com.gitee.sop.adminbackend.service.isv.dto.IsvGroupSettingDTO;
import com.gitee.sop.adminbackend.util.CopyUtil;
@@ -32,9 +31,9 @@ public class PermIsvGroupController {
* @param isvId isvId
* @return 返回影响行数
*/
@GetMapping("listIsvCode")
public Result<List<String>> listIsvGroup(Long isvId) {
List<String> permGroups = permIsvGroupService.listIsvGroup(isvId);
@GetMapping("listIsvGroupId")
public Result<List<Long>> listIsvGroupId(Long isvId) {
List<Long> permGroups = permIsvGroupService.listIsvGroupId(isvId);
return Result.ok(permGroups);
}

View File

@@ -14,6 +14,6 @@ public class IsvGroupSettingParam {
@NotNull
private Long isvId;
private List<String> groupCodeList;
private List<Long> groupIds;
}

View File

@@ -1,7 +1,5 @@
package com.gitee.sop.adminbackend.controller.isv.req;
import java.time.LocalDateTime;
import com.gitee.fastmybatis.core.query.Operator;
import com.gitee.fastmybatis.core.query.annotation.Condition;
import com.gitee.fastmybatis.core.query.param.PageParam;
@@ -17,12 +15,6 @@ import lombok.EqualsAndHashCode;
@Data
public class PermGroupParam extends PageParam {
/**
* 分组代码
*/
@Condition(operator = Operator.like)
private String groupCode;
/**
* 分组描述
*/

View File

@@ -25,12 +25,7 @@ public class PermGroup {
private Long id;
/**
* 分组代码
*/
private String groupCode;
/**
* 角色描述
* 分组名称
*/
private String groupName;

View File

@@ -25,9 +25,9 @@ public class PermGroupPermission {
private Long id;
/**
* 分组表code
* 组id
*/
private String groupCode;
private Long groupId;
/**
* api_info.id

View File

@@ -27,9 +27,9 @@ public class PermIsvGroup {
private Long isvId;
/**
* 组code
* 组id
*/
private String groupCode;
private Long groupId;
private LocalDateTime addTime;

View File

@@ -120,30 +120,6 @@ public class IsvInfoService implements LambdaService<IsvInfo, IsvInfoMapper> {
}
private void saveIsvRole(IsvInfo isvInfo, List<String> roleCodeList) {
Long isvId = isvInfo.getId();
permIsvGroupService.deleteByColumn(PermIsvGroup::getIsvId, isvId);
List<PermIsvGroup> tobeSaveList = roleCodeList.stream()
.map(groupCode -> {
PermIsvGroup rec = new PermIsvGroup();
rec.setIsvId(isvId);
rec.setGroupCode(groupCode);
return rec;
})
.collect(Collectors.toList());
permIsvGroupService.saveBatch(tobeSaveList);
// TODO:同步到网关
// try {
// routePermissionService.sendIsvRolePermissionMsg(isvInfo.getAppKey(), roleCodeList);
// } catch (Exception e) {
// log.error("同步角色失败isvInfo:{}, roleCodeList:{}", isvInfo, roleCodeList);
// throw new BizException("同步角色失败,请查看网关日志");
// }
}
private IsvKeysGenDTO createIsvKeys(RSATool.KeyFormat keyFormat) throws Exception {
IsvKeysGenDTO isvKeysGenDTO = new IsvKeysGenDTO();

View File

@@ -28,10 +28,10 @@ public class PermGroupService implements LambdaService<PermGroup, PermGroupMappe
});
}
public Map<String, String> getCodeNameMap(Collection<String> codeList) {
public Map<Long, String> getCodeNameMap(Collection<Long> groupIdList) {
return this.query()
.in(PermGroup::getGroupCode, codeList)
.map(PermGroup::getGroupCode, PermGroup::getGroupName);
.in(PermGroup::getId, groupIdList)
.map(PermGroup::getId, PermGroup::getGroupName);
}

View File

@@ -45,40 +45,43 @@ public class PermIsvGroupService implements LambdaService<PermIsvGroup, PermIsvG
if (list.isEmpty()) {
return new HashMap<>();
}
Set<String> codes = list.stream().map(PermIsvGroup::getGroupCode).collect(Collectors.toSet());
Map<String, String> groupCodeMap = permGroupService.getCodeNameMap(codes);
Set<Long> groupIds = list.stream().map(PermIsvGroup::getGroupId).collect(Collectors.toSet());
Map<Long, String> groupCodeMap = permGroupService.getCodeNameMap(groupIds);
return this.query()
.in(PermIsvGroup::getIsvId, isvIds)
.group(PermIsvGroup::getIsvId,
permIsvGroup -> groupCodeMap.getOrDefault(permIsvGroup.getGroupCode(), ""));
permIsvGroup -> groupCodeMap.getOrDefault(permIsvGroup.getGroupId(), ""));
}
@Transactional(rollbackFor = Exception.class)
public int updateIsvGroup(IsvGroupSettingDTO isvGroupSettingDTO) {
// 先删除所有
int i = this.deleteByColumn(PermIsvGroup::getIsvId, isvGroupSettingDTO.getIsvId());
List<String> groupCodeList = isvGroupSettingDTO.getGroupCodeList();
if (CollectionUtils.isEmpty(groupCodeList)) {
List<Long> groupIds = isvGroupSettingDTO.getGroupIds();
if (CollectionUtils.isEmpty(groupIds)) {
return i;
}
List<PermIsvGroup> saveList = groupCodeList
List<PermIsvGroup> saveList = groupIds
.stream()
.map(groupCode -> {
.map(groupId -> {
PermIsvGroup permIsvGroup = new PermIsvGroup();
permIsvGroup.setIsvId(isvGroupSettingDTO.getIsvId());
permIsvGroup.setGroupCode(groupCode);
permIsvGroup.setGroupId(groupId);
return permIsvGroup;
}).collect(Collectors.toList());
return this.saveBatch(saveList);
int cnt = this.saveBatch(saveList);
// TODO:同步到网关
return cnt;
}
public List<String> listIsvGroup(Long isvId) {
public List<Long> listIsvGroupId(Long isvId) {
List<PermIsvGroup> list = this.list(PermIsvGroup::getIsvId, isvId);
if (list.isEmpty()) {
return new ArrayList<>(0);
}
return list.stream().map(PermIsvGroup::getGroupCode).distinct().collect(Collectors.toList());
return list.stream().map(PermIsvGroup::getGroupId).distinct().collect(Collectors.toList());
}

View File

@@ -15,7 +15,6 @@ public class IsvGroupSettingDTO {
@NotNull
private Long isvId;
@NotEmpty
private List<String> groupCodeList;
private List<Long> groupIds;
}