refactor(system): 优化角色服务的事务处理和集合操作
This commit is contained in:
+2
@@ -5,11 +5,13 @@ import cn.odboy.system.dal.dataobject.SystemRoleTb;
|
|||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
public class SystemMenuVo extends SystemMenuTb {
|
public class SystemMenuVo extends SystemMenuTb {
|
||||||
|
|
||||||
@ApiModelProperty(value = "菜单角色")
|
@ApiModelProperty(value = "菜单角色")
|
||||||
|
|||||||
+3
-10
@@ -123,6 +123,7 @@ public class SystemRoleService {
|
|||||||
*
|
*
|
||||||
* @param args /
|
* @param args /
|
||||||
*/
|
*/
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void updateBindMenuById(SystemRoleVo args) {
|
public void updateBindMenuById(SystemRoleVo args) {
|
||||||
SystemRoleTb role = systemRoleMapper.selectById(args.getId());
|
SystemRoleTb role = systemRoleMapper.selectById(args.getId());
|
||||||
checkRoleLevels(role.getLevel());
|
checkRoleLevels(role.getLevel());
|
||||||
@@ -142,7 +143,7 @@ public class SystemRoleService {
|
|||||||
*/
|
*/
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void deleteRoleByIds(Set<Long> ids) {
|
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) {
|
for (Integer roleLevel : roleLevels) {
|
||||||
checkRoleLevels(roleLevel);
|
checkRoleLevels(roleLevel);
|
||||||
}
|
}
|
||||||
@@ -270,7 +271,7 @@ public class SystemRoleService {
|
|||||||
*/
|
*/
|
||||||
private int checkRoleLevels(Integer level) {
|
private int checkRoleLevels(Integer level) {
|
||||||
List<Integer> levels = systemUserRoleService.queryRoleByUsersId(KitSecurityHelper.getCurrentUserId()).stream()
|
List<Integer> levels = systemUserRoleService.queryRoleByUsersId(KitSecurityHelper.getCurrentUserId()).stream()
|
||||||
.map(SystemRoleTb::getLevel).collect(Collectors.toList());
|
.map(SystemRoleTb::getLevel).toList();
|
||||||
int min = Collections.min(levels);
|
int min = Collections.min(levels);
|
||||||
if (level != null) {
|
if (level != null) {
|
||||||
if (level < min) {
|
if (level < min) {
|
||||||
@@ -282,14 +283,6 @@ public class SystemRoleService {
|
|||||||
|
|
||||||
public void exportRoleXlsx(HttpServletResponse response, SystemQueryRoleArgs args) {
|
public void exportRoleXlsx(HttpServletResponse response, SystemQueryRoleArgs args) {
|
||||||
List<SystemRoleVo> systemRoleVos = this.queryRoleByArgs(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<>();
|
List<SystemRoleExportRowVo> rowVos = new ArrayList<>();
|
||||||
for (SystemRoleVo dataObject : systemRoleVos) {
|
for (SystemRoleVo dataObject : systemRoleVos) {
|
||||||
SystemRoleExportRowVo rowVo = new SystemRoleExportRowVo();
|
SystemRoleExportRowVo rowVo = new SystemRoleExportRowVo();
|
||||||
|
|||||||
+1
@@ -123,6 +123,7 @@ public class SystemRoleService {
|
|||||||
*
|
*
|
||||||
* @param args /
|
* @param args /
|
||||||
*/
|
*/
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void updateBindMenuById(SystemRoleVo args) {
|
public void updateBindMenuById(SystemRoleVo args) {
|
||||||
SystemRoleTb role = systemRoleMapper.selectById(args.getId());
|
SystemRoleTb role = systemRoleMapper.selectById(args.getId());
|
||||||
checkRoleLevels(role.getLevel());
|
checkRoleLevels(role.getLevel());
|
||||||
|
|||||||
Reference in New Issue
Block a user