2021与蓝度共同重构项目,服务端
fix
zhanzhiqin
2022-06-02 b64d778d7ea64b2c6517b4ec34646be50a930151
ximon-admin/src/main/java/com/sandu/ximon/admin/service/AdminService.java
@@ -166,23 +166,50 @@
        return updateById(admin);
    }
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteAdmin(Long adminId) {
        boolean flag = false;
        Admin admin = getById(adminId);
        if (admin == null) {
            throw new BusinessException("找不到管理员");
        }
        List<Role> roles = roleService.listByAdminId(admin.getId());
        if (CollectionUtil.isEmpty(roles)) {
            throw new BusinessException("当前用户没有角色");
        }
        List<Integer> levels = roles.stream().map(Role::getLevel).collect(Collectors.toList());
        int min = Collections.min(levels);
        int maxLevel = roleService.assertLevels(min);
        if (!RoleLevelStatus.SUPER.getCode().equals(maxLevel)) {
        if (!AdministratorEnums.ADMIN.getCode().equals(SecurityUtils.getUserDetails().getAdministratorType())) {
            throw new BusinessException("只有超级管理员才能删除用户");
        }
        return removeById(adminId);
        //管理员角色关系表
        AdminRoleRelationService adminRoleRelationService = SpringContextHolder.getBean(AdminRoleRelationService.class);
        //有用户必定有用户与角色的关系数据
        AdminRoleRelation one = adminRoleRelationService.getOne(Wrappers.lambdaQuery(AdminRoleRelation.class).eq(AdminRoleRelation::getAdminId, admin.getId()));
        Role role = SpringContextHolder.getBean(RoleService.class).getOne(Wrappers.lambdaQuery(Role.class).eq(Role::getId, one.getRoleId()));
        if (role == null) {
            throw new BusinessException("数据异常!");
        }
        if (role.getLevel().equals(RoleLevelStatus.SUPER.getCode())) {
            throw new BusinessException("超级管理员无法删除");
        } else {
            //删用户
            if (removeById(adminId)) {
                //删角色关系表信息
                flag = adminRoleRelationService.removeById(one);
                //删除失败回滚数据
                if (!flag) {
                    throw new BusinessException("删除管理员用户失败!");
                }
            }
        }
        /**
         * 删除管理员 日志记录开始
         */
        String content = "删除管理员:" + admin.getUsername() + "用户id:" + admin;
        StoreOperationRecordsUtils.storeOperationData(null, null, "删除管理员", content);
        /**
         * 删除管理员 日志记录结束
         */
        return flag;
    }
    /**
@@ -235,7 +262,9 @@
        //排序方式
        String orderBy = orderByResult + " " + orderBySeq;
        PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize(), orderBy);
        if (baseConditionVO != null) {
            PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize(), orderBy);
        }
        return adminMapper.listAdmin(keyword);
    }