|
@@ -119,50 +119,54 @@ public class ClusterService {
|
|
|
|
|
|
@SneakyThrows
|
|
|
public int getLicenseNum() {
|
|
|
- //1 获取当前用户信息
|
|
|
- String roleCode = AuthUtil.getCurrentUserRoleCode();
|
|
|
- String userType = AuthUtil.getCurrentUseType();
|
|
|
- String userId = AuthUtil.getCurrentUserId();
|
|
|
- log.info("当前用户信息为:roleCode - " + roleCode + ",userType - " + userType + ",userId - " + userId);
|
|
|
+ try {
|
|
|
+ //1 获取当前用户信息
|
|
|
+ String roleCode = AuthUtil.getCurrentUserRoleCode();
|
|
|
+ String userType = AuthUtil.getCurrentUseType();
|
|
|
+ String userId = AuthUtil.getCurrentUserId();
|
|
|
+ log.info("当前用户信息为:roleCode - " + roleCode + ",userType - " + userType + ",userId - " + userId);
|
|
|
+
|
|
|
+ //2 获取当前用户使用的集群账户 id
|
|
|
+ if (DictConstants.ROLE_CODE_ADMIN.equals(roleCode) || DictConstants.ROLE_CODE_SYSADMIN.equals(roleCode)) { // 管理
|
|
|
+ return -1;
|
|
|
+ } else if (DictConstants.ROLE_CODE_UESR.equals(roleCode)) { //普通
|
|
|
+ ClusterParam clusterParam = new ClusterParam();
|
|
|
+ clusterParam.setCreateUserId(userId);
|
|
|
+ Integer licenseTotal = clusterMapper.getSimulationLicenseNum(userId); // 拥有节点
|
|
|
+ if (DictConstants.USER_TYPE_EXCLUSIVE.equals(userType)) { // 普通独占
|
|
|
+ if (licenseTotal == null || licenseTotal == 0) {
|
|
|
+ return 0;
|
|
|
+ } else {
|
|
|
+ Integer licenseAssigned = clusterMapper.getAssignedSimLicenseNum(clusterParam); // 已分配节点
|
|
|
+ return licenseTotal - licenseAssigned;
|
|
|
+ }
|
|
|
+ } else if (DictConstants.USER_TYPE_PUBLIC.equals(userType)) {
|
|
|
+ return licenseTotal;
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("普通用户占用类型获取失败。");
|
|
|
+ }
|
|
|
|
|
|
- //2 获取当前用户使用的集群账户 id
|
|
|
- if (DictConstants.ROLE_CODE_ADMIN.equals(roleCode) || DictConstants.ROLE_CODE_SYSADMIN.equals(roleCode)) { // 管理
|
|
|
- return -1;
|
|
|
- } else if (DictConstants.ROLE_CODE_UESR.equals(roleCode)) { //普通
|
|
|
- ClusterParam clusterParam = new ClusterParam();
|
|
|
- clusterParam.setCreateUserId(userId);
|
|
|
- Integer licenseTotal = clusterMapper.getSimulationLicenseNum(userId); // 拥有节点
|
|
|
- if (DictConstants.USER_TYPE_EXCLUSIVE.equals(userType)) { // 普通独占
|
|
|
- if (licenseTotal == null || licenseTotal == 0) {
|
|
|
- return 0;
|
|
|
+ } else if (DictConstants.ROLE_CODE_SUBUESR.equals(roleCode)) {
|
|
|
+ int licenseTotal;
|
|
|
+ if (DictConstants.USER_TYPE_EXCLUSIVE.equals(userType)) {
|
|
|
+ ClusterParam clusterParam = new ClusterParam();
|
|
|
+ clusterParam.setCreateUserId(userId);
|
|
|
+ licenseTotal = clusterMapper.getSimulationLicenseNum(userId); // 拥有节点
|
|
|
+ } else if (DictConstants.USER_TYPE_PUBLIC.equals(userType)) {
|
|
|
+ //查询父账户
|
|
|
+ userId = AuthUtil.getCreateUserId();
|
|
|
+ ClusterParam clusterParam = new ClusterParam();
|
|
|
+ clusterParam.setCreateUserId(userId);
|
|
|
+ licenseTotal = clusterMapper.getSimulationLicenseNum(userId); // 拥有节点
|
|
|
} else {
|
|
|
- Integer licenseAssigned = clusterMapper.getAssignedSimLicenseNum(clusterParam); // 已分配节点
|
|
|
- return licenseTotal - licenseAssigned;
|
|
|
+ throw new RuntimeException("普通用户子账户占用类型获取失败。");
|
|
|
}
|
|
|
- } else if (DictConstants.USER_TYPE_PUBLIC.equals(userType)) {
|
|
|
return licenseTotal;
|
|
|
} else {
|
|
|
- throw new RuntimeException("普通用户占用类型获取失败。");
|
|
|
- }
|
|
|
-
|
|
|
- } else if (DictConstants.ROLE_CODE_SUBUESR.equals(roleCode)) {
|
|
|
- int licenseTotal;
|
|
|
- if (DictConstants.USER_TYPE_EXCLUSIVE.equals(userType)) {
|
|
|
- ClusterParam clusterParam = new ClusterParam();
|
|
|
- clusterParam.setCreateUserId(userId);
|
|
|
- licenseTotal = clusterMapper.getSimulationLicenseNum(userId); // 拥有节点
|
|
|
- } else if (DictConstants.USER_TYPE_PUBLIC.equals(userType)) {
|
|
|
- //查询父账户
|
|
|
- userId = AuthUtil.getCreateUserId();
|
|
|
- ClusterParam clusterParam = new ClusterParam();
|
|
|
- clusterParam.setCreateUserId(userId);
|
|
|
- licenseTotal = clusterMapper.getSimulationLicenseNum(userId); // 拥有节点
|
|
|
- } else {
|
|
|
- throw new RuntimeException("普通用户子账户占用类型获取失败。");
|
|
|
+ throw new RuntimeException("用户类型获取失败。");
|
|
|
}
|
|
|
- return licenseTotal;
|
|
|
- } else {
|
|
|
- throw new RuntimeException("用户类型获取失败。");
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException("此用户暂未分配集群");
|
|
|
}
|
|
|
}
|
|
|
|