refactor(system): 优化角色服务的事务处理和集合操作

This commit is contained in:
2026-01-07 18:40:22 +08:00
parent 6364b0f577
commit 394d1409e1
3 changed files with 6 additions and 10 deletions
@@ -5,11 +5,13 @@ import cn.odboy.system.dal.dataobject.SystemRoleTb;
import io.swagger.annotations.ApiModelProperty;
import java.util.List;
import java.util.Set;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
@EqualsAndHashCode(callSuper = true)
public class SystemMenuVo extends SystemMenuTb {
@ApiModelProperty(value = "菜单角色")
@@ -123,6 +123,7 @@ public class SystemRoleService {
*
* @param args /
*/
@Transactional(rollbackFor = Exception.class)
public void updateBindMenuById(SystemRoleVo args) {
SystemRoleTb role = systemRoleMapper.selectById(args.getId());
checkRoleLevels(role.getLevel());
@@ -142,7 +143,7 @@ public class SystemRoleService {
*/
@Transactional(rollbackFor = Exception.class)
public void deleteRoleByIds(Set<Long> ids) {
List<Integer> roleLevels = systemRoleMapper.selectByIds(ids).stream().map(SystemRoleTb::getLevel).distinct().collect(Collectors.toList());
List<Integer> roleLevels = systemRoleMapper.selectByIds(ids).stream().map(SystemRoleTb::getLevel).distinct().toList();
for (Integer roleLevel : roleLevels) {
checkRoleLevels(roleLevel);
}
@@ -270,7 +271,7 @@ public class SystemRoleService {
*/
private int checkRoleLevels(Integer level) {
List<Integer> levels = systemUserRoleService.queryRoleByUsersId(KitSecurityHelper.getCurrentUserId()).stream()
.map(SystemRoleTb::getLevel).collect(Collectors.toList());
.map(SystemRoleTb::getLevel).toList();
int min = Collections.min(levels);
if (level != null) {
if (level < min) {
@@ -282,14 +283,6 @@ public class SystemRoleService {
public void exportRoleXlsx(HttpServletResponse response, SystemQueryRoleArgs args) {
List<SystemRoleVo> systemRoleVos = this.queryRoleByArgs(args);
// KitXlsxExportUtil.exportFile(response, "角色数据", systemRoleVos, SystemRoleExportRowVo.class, (dataObject) -> {
// SystemRoleExportRowVo rowVo = new SystemRoleExportRowVo();
// rowVo.setName(dataObject.getName());
// rowVo.setLevel(dataObject.getLevel());
// rowVo.setDescription(dataObject.getDescription());
// rowVo.setCreateTime(dataObject.getCreateTime());
// return CollUtil.newArrayList(rowVo);
// });
List<SystemRoleExportRowVo> rowVos = new ArrayList<>();
for (SystemRoleVo dataObject : systemRoleVos) {
SystemRoleExportRowVo rowVo = new SystemRoleExportRowVo();
@@ -123,6 +123,7 @@ public class SystemRoleService {
*
* @param args /
*/
@Transactional(rollbackFor = Exception.class)
public void updateBindMenuById(SystemRoleVo args) {
SystemRoleTb role = systemRoleMapper.selectById(args.getId());
checkRoleLevels(role.getLevel());