summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshizhendong <[email protected]>2021-04-06 18:13:21 +0800
committershizhendong <[email protected]>2021-04-06 18:13:21 +0800
commit0e60bca561be03d173d93ec3b3b29e78232950f1 (patch)
treea50e4fd24938ef9d637fe494e1b0340e786a4803
parent26c921847c78954d9271c8010d37a68c5ed1034d (diff)
NEZ-531 dc,cabinet 接口修改
1、idc表改为 dc,idc 表暂不删除,新增 dc 表 2、dc 相关接口修改 3、系统内 idc 统一改为 dc
-rw-r--r--nz-admin/src/main/java/com/nis/modules/alert/entity/AlertMessageEntity.java8
-rw-r--r--nz-admin/src/main/java/com/nis/modules/alert/entity/AlertSilenceConf.java9
-rw-r--r--nz-admin/src/main/java/com/nis/modules/alert/service/impl/AlertMessageServiceImpl.java30
-rw-r--r--nz-admin/src/main/java/com/nis/modules/alert/service/impl/AlertSilenceServiceImpl.java34
-rw-r--r--nz-admin/src/main/java/com/nis/modules/asset/controller/AssetController.java4
-rw-r--r--nz-admin/src/main/java/com/nis/modules/asset/controller/CabinetController.java16
-rw-r--r--nz-admin/src/main/java/com/nis/modules/asset/controller/DcController.java207
-rw-r--r--nz-admin/src/main/java/com/nis/modules/asset/controller/IdcController.java18
-rw-r--r--nz-admin/src/main/java/com/nis/modules/asset/dao/AssetDao.java2
-rw-r--r--nz-admin/src/main/java/com/nis/modules/asset/dao/DcDao.java18
-rw-r--r--nz-admin/src/main/java/com/nis/modules/asset/entity/AssetAsset.java2
-rw-r--r--nz-admin/src/main/java/com/nis/modules/asset/entity/Cabinet.java20
-rw-r--r--nz-admin/src/main/java/com/nis/modules/asset/entity/Dc.java106
-rw-r--r--nz-admin/src/main/java/com/nis/modules/asset/entity/Idc.java2
-rw-r--r--nz-admin/src/main/java/com/nis/modules/asset/service/CabinetService.java41
-rw-r--r--nz-admin/src/main/java/com/nis/modules/asset/service/DcService.java51
-rw-r--r--nz-admin/src/main/java/com/nis/modules/asset/service/impl/AssetAssetServiceImpl.java88
-rw-r--r--nz-admin/src/main/java/com/nis/modules/asset/service/impl/AssetServiceImpl.java17
-rw-r--r--nz-admin/src/main/java/com/nis/modules/asset/service/impl/CabinetServiceImpl.java207
-rw-r--r--nz-admin/src/main/java/com/nis/modules/asset/service/impl/DcServiceImpl.java270
-rw-r--r--nz-admin/src/main/java/com/nis/modules/asset/service/impl/IdcServiceImpl.java28
-rw-r--r--nz-admin/src/main/java/com/nis/modules/asset/service/impl/IdcTrafficServiceImpl.java38
-rw-r--r--nz-admin/src/main/java/com/nis/modules/metric/controller/MetricsController.java18
-rw-r--r--nz-admin/src/main/java/com/nis/modules/metric/dto/NezhaMetrics.java554
-rw-r--r--nz-admin/src/main/java/com/nis/modules/overview/service/impl/OverviewServiceImpl.java40
-rw-r--r--nz-admin/src/main/java/com/nis/modules/panel/service/impl/ExpreTmplServiceImpl.java8
-rw-r--r--nz-admin/src/main/java/com/nis/modules/promserver/controller/PromserverController.java2
-rw-r--r--nz-admin/src/main/java/com/nis/modules/promserver/entity/Promserver.java6
-rw-r--r--nz-admin/src/main/java/com/nis/modules/promserver/service/impl/PromserverServiceImpl.java43
-rw-r--r--nz-admin/src/main/java/com/nis/modules/sys/service/impl/SysConfigServiceImpl.java2
-rw-r--r--nz-admin/src/main/resources/db/V2021.04.06__1.Insert dc table 2. idc_id was renamed to dc_id .sql35
-rw-r--r--nz-admin/src/main/resources/mapper/alert/AlertSilenceDao.xml4
-rw-r--r--nz-admin/src/main/resources/mapper/asset/AssetAccountDao.xml4
-rw-r--r--nz-admin/src/main/resources/mapper/asset/AssetAssetDao.xml8
-rw-r--r--nz-admin/src/main/resources/mapper/asset/AssetDao.xml6
-rw-r--r--nz-admin/src/main/resources/mapper/asset/CabinetDao.xml16
-rw-r--r--nz-admin/src/main/resources/mapper/asset/IdcDao.xml4
-rw-r--r--nz-admin/src/main/resources/mapper/endpoint/EndpointDao.xml2
-rw-r--r--nz-admin/src/main/resources/mapper/overview/OverviewDao.xml6
-rw-r--r--nz-common/src/main/java/com/nis/common/utils/RCode.java85
40 files changed, 1480 insertions, 579 deletions
diff --git a/nz-admin/src/main/java/com/nis/modules/alert/entity/AlertMessageEntity.java b/nz-admin/src/main/java/com/nis/modules/alert/entity/AlertMessageEntity.java
index 66686a15..0efd6ee6 100644
--- a/nz-admin/src/main/java/com/nis/modules/alert/entity/AlertMessageEntity.java
+++ b/nz-admin/src/main/java/com/nis/modules/alert/entity/AlertMessageEntity.java
@@ -4,7 +4,7 @@ import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.nis.modules.asset.entity.Asset;
-import com.nis.modules.asset.entity.Idc;
+import com.nis.modules.asset.entity.Dc;
import com.nis.modules.endpoint.entity.Endpoint;
import com.nis.modules.module.entity.Module;
import com.nis.modules.project.entity.Project;
@@ -89,7 +89,7 @@ public class AlertMessageEntity implements Serializable {
*/
private Integer assetId;
/**
- * 关联idc
+ * 关联dc
*/
private Integer dcId;
@@ -131,8 +131,8 @@ public class AlertMessageEntity implements Serializable {
private Endpoint endpoint;
/**
- * idc
+ * dc
*/
@TableField(exist = false)
- private Idc dc;
+ private Dc dc;
}
diff --git a/nz-admin/src/main/java/com/nis/modules/alert/entity/AlertSilenceConf.java b/nz-admin/src/main/java/com/nis/modules/alert/entity/AlertSilenceConf.java
index f6e6cee2..036e1965 100644
--- a/nz-admin/src/main/java/com/nis/modules/alert/entity/AlertSilenceConf.java
+++ b/nz-admin/src/main/java/com/nis/modules/alert/entity/AlertSilenceConf.java
@@ -1,18 +1,17 @@
package com.nis.modules.alert.entity;
-import java.util.Date;
-
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.nis.modules.asset.entity.Asset;
-import com.nis.modules.asset.entity.Idc;
+import com.nis.modules.asset.entity.Dc;
import com.nis.modules.endpoint.entity.Endpoint;
import com.nis.modules.module.entity.Module;
import com.nis.modules.project.entity.Project;
-
import lombok.Data;
+import java.util.Date;
+
@Data
@TableName("alert_silence_conf")
public class AlertSilenceConf {
@@ -39,7 +38,7 @@ public class AlertSilenceConf {
private String seq;
@TableField(exist = false)
- private Idc datacenter;
+ private Dc datacenter;
@TableField(exist = false)
private Project project;
diff --git a/nz-admin/src/main/java/com/nis/modules/alert/service/impl/AlertMessageServiceImpl.java b/nz-admin/src/main/java/com/nis/modules/alert/service/impl/AlertMessageServiceImpl.java
index feabb476..6bacbd11 100644
--- a/nz-admin/src/main/java/com/nis/modules/alert/service/impl/AlertMessageServiceImpl.java
+++ b/nz-admin/src/main/java/com/nis/modules/alert/service/impl/AlertMessageServiceImpl.java
@@ -19,9 +19,9 @@ import com.nis.modules.alert.entity.receive.AlertMessageReceiveDTO;
import com.nis.modules.alert.service.AlertMessageService;
import com.nis.modules.alert.service.AlertRuleService;
import com.nis.modules.asset.entity.Asset;
-import com.nis.modules.asset.entity.Idc;
+import com.nis.modules.asset.entity.Dc;
import com.nis.modules.asset.service.AssetService;
-import com.nis.modules.asset.service.IdcService;
+import com.nis.modules.asset.service.DcService;
import com.nis.modules.endpoint.dao.EndpointDao;
import com.nis.modules.endpoint.entity.Endpoint;
import com.nis.modules.endpoint.entity.EndpointState;
@@ -77,7 +77,7 @@ public class AlertMessageServiceImpl extends ServiceImpl<AlertMessageDao, AlertM
@Autowired
private EndpointService endpointService;
@Autowired
- private IdcService idcService;
+ private DcService dcService;
@Autowired
private RedisTemplate<String, Object> redisTemplate;
@Autowired
@@ -134,10 +134,10 @@ public class AlertMessageServiceImpl extends ServiceImpl<AlertMessageDao, AlertM
return;
}
- List<Idc> idcList = idcService.list();
- Map<Integer,Idc> idcMap = new HashMap<>();
- for (Idc dc:idcList) {
- idcMap.put(dc.getId(), dc);
+ List<Dc> dcList = dcService.list();
+ Map<Integer,Dc> dcMap = new HashMap<>();
+ for (Dc dc:dcList) {
+ dcMap.put(dc.getId(), dc);
}
List<Endpoint> endpointList = endpointService.list();
@@ -154,7 +154,7 @@ public class AlertMessageServiceImpl extends ServiceImpl<AlertMessageDao, AlertM
}
dcId = entity.getDcId();
if(dcId != null){
- entity.setDc(idcMap.get(dcId));
+ entity.setDc(dcMap.get(dcId));
}
}
}
@@ -357,7 +357,7 @@ public class AlertMessageServiceImpl extends ServiceImpl<AlertMessageDao, AlertM
}
}
- private AlertMessageReceiveDTO getReceiveLabels(AlertMessageReceiveDTO dto, Map<Integer, Endpoint> endpointMap, Map<Integer, Asset> assetIdAndEntityMap, Map<String, Asset> assetHostAndEntityMap, Map<String, Integer> projectNameAndIdMap, Map<String, Integer> idcNameAndIdMap, Map<Integer, Module> moduleIdAndEntityMap, Map<String, Module> moduleNameAndEntityMap) {
+ private AlertMessageReceiveDTO getReceiveLabels(AlertMessageReceiveDTO dto, Map<Integer, Endpoint> endpointMap, Map<Integer, Asset> assetIdAndEntityMap, Map<String, Asset> assetHostAndEntityMap, Map<String, Integer> projectNameAndIdMap, Map<String, Integer> dcNameAndIdMap, Map<Integer, Module> moduleIdAndEntityMap, Map<String, Module> moduleNameAndEntityMap) {
Map receiveLabels = dto.getLabels();
Map labelIds = new HashMap();
Integer assertId = null, moduleId = null, projectId = null, endpointId = null, dcId = null;
@@ -386,7 +386,7 @@ public class AlertMessageServiceImpl extends ServiceImpl<AlertMessageDao, AlertM
dcId = asset.getIdcId();
}
if (ToolUtil.isNotEmpty(receiveLabels.get("datacenter")) && ToolUtil.isEmpty(receiveLabels.get("asset"))) {
- dcId = idcNameAndIdMap.get(receiveLabels.get("datacenter").toString());
+ dcId = dcNameAndIdMap.get(receiveLabels.get("datacenter").toString());
}
}
labelIds.put("endpoint", endpointId);
@@ -541,7 +541,7 @@ public class AlertMessageServiceImpl extends ServiceImpl<AlertMessageDao, AlertM
r = sheet.createRow(++rowNum);
AlertRuleEntity alertRule = entity.getAlertRule();
String ruleName = alertRule == null ? "" : alertRule.getAlertName();
- Idc dc = entity.getDc();
+ Dc dc = entity.getDc();
String dcName = dc == null ? "" : dc.getName();
Project project = entity.getProject();
String projectName = project == null ? "" : project.getName();
@@ -618,8 +618,8 @@ public class AlertMessageServiceImpl extends ServiceImpl<AlertMessageDao, AlertM
List<Project> projectList = projectService.list();
Map<String, Integer> projectNameAndIdMap = projectList.stream().collect(Collectors.toMap(Project::getName, Project::getId));
- List<Idc> idcList = idcService.list();
- Map<String, Integer> idcNameAndIdMap = idcList.stream().collect(Collectors.toMap(Idc::getName, Idc::getId));
+ List<Dc> dcList = dcService.list();
+ Map<String, Integer> dcNameAndIdMap = dcList.stream().collect(Collectors.toMap(Dc::getName, Dc::getId));
AlertMessageEntity entity;
List<AlertMessageEntity> entities =new ArrayList<AlertMessageEntity>();
@@ -627,7 +627,7 @@ public class AlertMessageServiceImpl extends ServiceImpl<AlertMessageDao, AlertM
for (AlertMessageReceiveDTO dto : receiveData) {
try {
- getReceiveLabels(dto, endpointMap, assetIdAndEntityMap, assetHostAndEntityMap, projectNameAndIdMap, idcNameAndIdMap, moduleIdAndEntityMap, moduleNameAndEntityMap);
+ getReceiveLabels(dto, endpointMap, assetIdAndEntityMap, assetHostAndEntityMap, projectNameAndIdMap, dcNameAndIdMap, moduleIdAndEntityMap, moduleNameAndEntityMap);
entity = AlertMessageReceiveDTO.toAlertMessageEntity(dto, buildRuleId);
entities.add(entity);
@@ -639,4 +639,4 @@ public class AlertMessageServiceImpl extends ServiceImpl<AlertMessageDao, AlertM
// 存入缓存
opsForList.leftPush(Constant.ALERT_MESSAGE_RECV, JSON.toJSONString(entities));
}
-} \ No newline at end of file
+}
diff --git a/nz-admin/src/main/java/com/nis/modules/alert/service/impl/AlertSilenceServiceImpl.java b/nz-admin/src/main/java/com/nis/modules/alert/service/impl/AlertSilenceServiceImpl.java
index e961f0d7..12f3d283 100644
--- a/nz-admin/src/main/java/com/nis/modules/alert/service/impl/AlertSilenceServiceImpl.java
+++ b/nz-admin/src/main/java/com/nis/modules/alert/service/impl/AlertSilenceServiceImpl.java
@@ -1,19 +1,9 @@
package com.nis.modules.alert.service.impl;
-import java.text.ParseException;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.time.DateUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.log.Log;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nis.common.exception.NZException;
import com.nis.common.utils.DateUtil;
@@ -28,18 +18,24 @@ import com.nis.modules.alert.entity.AlertRuleEntity;
import com.nis.modules.alert.entity.AlertSilenceConf;
import com.nis.modules.alert.service.AlertSilenceService;
import com.nis.modules.asset.dao.AssetDao;
-import com.nis.modules.asset.dao.IdcDao;
+import com.nis.modules.asset.dao.DcDao;
import com.nis.modules.asset.entity.Asset;
-import com.nis.modules.asset.entity.Idc;
+import com.nis.modules.asset.entity.Dc;
import com.nis.modules.endpoint.dao.EndpointDao;
import com.nis.modules.endpoint.entity.Endpoint;
import com.nis.modules.module.dao.ModuleDao;
import com.nis.modules.module.entity.Module;
import com.nis.modules.project.dao.ProjectDao;
import com.nis.modules.project.entity.Project;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.time.DateUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
-import cn.hutool.core.util.ObjectUtil;
-import cn.hutool.log.Log;
+import java.text.ParseException;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
@Service("alertSilenceService")
public class AlertSilenceServiceImpl extends ServiceImpl<AlertSilenceDao,AlertSilenceConf> implements AlertSilenceService{
@@ -50,7 +46,7 @@ public class AlertSilenceServiceImpl extends ServiceImpl<AlertSilenceDao,AlertSi
private AlertSilenceDao alertSilenceDao;
@Autowired
- private IdcDao idcDao;
+ private DcDao dcDao;
@Autowired
private AssetDao assetDao;
@@ -176,8 +172,8 @@ public class AlertSilenceServiceImpl extends ServiceImpl<AlertSilenceDao,AlertSi
if(ObjectUtil.isNotEmpty(alertSilenceConf.getType())) {
switch(alertSilenceConf.getType()) {
case "datacenter":
- Idc idc = idcDao.selectById(alertSilenceConf.getLinkId());
- alertSilenceConf.setDatacenter(idc);
+ Dc dc = dcDao.selectById(alertSilenceConf.getLinkId());
+ alertSilenceConf.setDatacenter(dc);
break;
case "project":
Project project = projectDao.selectById(alertSilenceConf.getLinkId());
diff --git a/nz-admin/src/main/java/com/nis/modules/asset/controller/AssetController.java b/nz-admin/src/main/java/com/nis/modules/asset/controller/AssetController.java
index e7f4522f..1a8f6546 100644
--- a/nz-admin/src/main/java/com/nis/modules/asset/controller/AssetController.java
+++ b/nz-admin/src/main/java/com/nis/modules/asset/controller/AssetController.java
@@ -307,7 +307,7 @@ public class AssetController {
public R save(@RequestBody Asset asset) {
ValidateUtils.is(asset.getSn()).notNull(RCode.ASSET_SN_ISNULL).maxLength(64, RCode.ASSET_SN_TOO_LONG)
.and(asset.getModelId()).notNull(RCode.ASSET_MODELID_ISNULL)
- .and(asset.getIdcId()).notNull(RCode.IDC_IDCID_ISNULL)
+ .and(asset.getIdcId()).notNull(RCode.DC_ID_ISNULL)
.and(asset.getHost()).notNull(RCode.ASSET_HOST_ISNULL).ip(RCode.ASSET_HOST_FORMAT);
List<Account> accounts = asset.getAccounts();
@@ -361,7 +361,7 @@ public class AssetController {
ValidateUtils.is(asset.getId()).notNull(RCode.ASSET_ID_ISNULL)
.and(asset.getSn()).notNull(RCode.ASSET_SN_ISNULL).maxLength(64, RCode.ASSET_SN_TOO_LONG)
.and(asset.getModelId()).notNull(RCode.ASSET_MODELID_ISNULL)
- .and(asset.getIdcId()).notNull(RCode.IDC_IDCID_ISNULL)
+ .and(asset.getIdcId()).notNull(RCode.DC_ID_ISNULL)
.and(asset.getHost()).notNull(RCode.ASSET_HOST_ISNULL).ip(RCode.ASSET_HOST_FORMAT);
diff --git a/nz-admin/src/main/java/com/nis/modules/asset/controller/CabinetController.java b/nz-admin/src/main/java/com/nis/modules/asset/controller/CabinetController.java
index 26d99071..0d157439 100644
--- a/nz-admin/src/main/java/com/nis/modules/asset/controller/CabinetController.java
+++ b/nz-admin/src/main/java/com/nis/modules/asset/controller/CabinetController.java
@@ -49,8 +49,8 @@ public class CabinetController {
@SysLog(operation = OperationEnum.ADD,type = TypeEnum.CABINET)
@RequiresPermissions({"cabinet:save"})
public R save(@RequestBody Cabinet cabinet) {
- ValidateUtils.is(cabinet.getName()).notNull(RCode.IDC_CABINETNAME_ISNULL)
- .and(cabinet.getIdcId()).notNull(RCode.IDC_IDCID_ISNULL)
+ ValidateUtils.is(cabinet.getName()).notNull(RCode.DC_CABINETNAME_ISNULL)
+ .and(cabinet.getDcId()).notNull(RCode.DC_ID_ISNULL)
.and(cabinet.getY()).min(1, RCode.CABINET_Y_MINIMUM)
.and(cabinet.getX()).min(1, RCode.CABINET_X_MINIMUM);
@@ -68,9 +68,9 @@ public class CabinetController {
@SysLog(operation = OperationEnum.UPDATE,type = TypeEnum.CABINET)
@RequiresPermissions({"cabinet:update"})
public R update(@RequestBody Cabinet cabinet) {
- ValidateUtils.is(cabinet.getId()).notNull(RCode.IDC_CABINETID_ISNULL)
- .and(cabinet.getName()).notNull(RCode.IDC_CABINETNAME_ISNULL)
- .and(cabinet.getIdcId()).notNull(RCode.IDC_IDCID_ISNULL)
+ ValidateUtils.is(cabinet.getId()).notNull(RCode.DC_CABINETID_ISNULL)
+ .and(cabinet.getName()).notNull(RCode.DC_CABINETNAME_ISNULL)
+ .and(cabinet.getDcId()).notNull(RCode.DC_ID_ISNULL)
.and(cabinet.getY()).min(1, RCode.CABINET_Y_MINIMUM)
.and(cabinet.getX()).min(1, RCode.CABINET_X_MINIMUM);
@@ -88,7 +88,7 @@ public class CabinetController {
@SysLog(operation = OperationEnum.DELETE,type = TypeEnum.CABINET)
@RequiresPermissions({"cabinet:delete"})
public R delete(@RequestParam Integer ... ids) {
- ValidateUtils.is(ids).notNull(RCode.IDC_CABINETID_ISNULL);
+ ValidateUtils.is(ids).notNull(RCode.DC_CABINETID_ISNULL);
cabinetService.delete(ids);
return R.ok();
@@ -103,9 +103,9 @@ public class CabinetController {
@SysLog(operation = OperationEnum.QUERY, type = TypeEnum.CABINET)
@RequiresPermissions({"cabinet:u:info"})
public R getUInfo(Integer id) {
- ValidateUtils.is(id).notNull(RCode.IDC_CABINETID_ISNULL);
+ ValidateUtils.is(id).notNull(RCode.DC_CABINETID_ISNULL);
Map uInfo = cabinetService.getUInfo(id);
return R.ok(uInfo);
}
-} \ No newline at end of file
+}
diff --git a/nz-admin/src/main/java/com/nis/modules/asset/controller/DcController.java b/nz-admin/src/main/java/com/nis/modules/asset/controller/DcController.java
new file mode 100644
index 00000000..850209bc
--- /dev/null
+++ b/nz-admin/src/main/java/com/nis/modules/asset/controller/DcController.java
@@ -0,0 +1,207 @@
+package com.nis.modules.asset.controller;
+
+import com.nis.common.annotation.SysLog;
+import com.nis.common.smartvalidate.ValidateUtils;
+import com.nis.common.utils.*;
+import com.nis.modules.asset.entity.Cabinet;
+import com.nis.modules.asset.entity.Dc;
+import com.nis.modules.asset.service.CabinetService;
+import com.nis.modules.asset.service.DcService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.Map;
+
+
+/**
+ * 数据中心 controller
+ *
+ * @author shizhendong
+ * @date 2021-4-6
+ */
+@RestController
+@RequestMapping("/dc")
+public class DcController {
+
+ @Autowired
+ private DcService dcService;
+
+ @Autowired
+ private CabinetService cabinetService;
+
+ /**
+ * dc详情
+ * @param id
+ * @return
+ */
+ @GetMapping("/{id}")
+ @SysLog(operation = OperationEnum.QUERY,type = TypeEnum.DATACENTER)
+ public R queryDcDetails(@PathVariable("id") Integer id) {
+ return R.ok(dcService.queryDcDetails(id));
+ }
+
+ /**
+ * 数据中心请求列表
+ *
+ * @param params
+ * @return
+ */
+ @GetMapping
+ @SysLog(operation = OperationEnum.QUERY,type = TypeEnum.DATACENTER)
+ public R queryDcPage(@RequestParam Map<String, Object> params) {
+ PageUtils page = dcService.queryPage(params);
+ return R.ok(page);
+ }
+
+
+ /**
+ * 保存
+ *
+ * @param dc
+ * @return
+ */
+ @PostMapping
+ @SysLog(operation = OperationEnum.ADD, type = TypeEnum.DATACENTER)
+ public R saveDc(@RequestBody Dc dc) {
+ ValidateUtils.is(dc.getName()).notNull(RCode.DC_NAME_ISNULL)
+ .and(dc.getState()).notNull(RCode.DC_STATE_ISNULL)
+ .and(dc.getY()).min(1, RCode.DC_Y_MINIMUM)
+ .and(dc.getX()).min(1, RCode.DC_X_MINIMUM);
+
+ return R.ok().putData("id", dcService.saveDc(dc));
+ }
+
+ /**
+ * 修改
+ *
+ * @param dc
+ * @return
+ */
+ @PutMapping
+ @SysLog(operation = OperationEnum.UPDATE,type = TypeEnum.DATACENTER)
+ public R updateDc(@RequestBody Dc dc) {
+ ValidateUtils.is(dc.getId()).notNull(RCode.DC_ID_ISNULL)
+ .and(dc.getName()).notNull(RCode.DC_NAME_ISNULL)
+ .and(dc.getState()).notNull(RCode.DC_STATE_ISNULL)
+ .and(dc.getY()).min(1, RCode.DC_Y_MINIMUM)
+ .and(dc.getX()).min(1, RCode.DC_X_MINIMUM);
+
+ return R.ok().putData("id", dcService.updateDc(dc));
+ }
+
+
+ /**
+ * 删除
+ *
+ * @param ids
+ * @return
+ */
+ @DeleteMapping
+ @SysLog(operation = OperationEnum.DELETE,type = TypeEnum.DATACENTER)
+ public R deleteDcByIds(@RequestParam Integer ... ids) {
+ ValidateUtils.is(ids).notNull(RCode.DC_ID_ISNULL);
+
+ dcService.delete(ids);
+ return R.ok();
+ }
+
+
+ /**
+ * 机柜详情
+ *
+ * @param id
+ * @return
+ */
+ @GetMapping("/cabinet/{id}")
+ @SysLog(operation = OperationEnum.QUERY, type = TypeEnum.CABINET)
+ public R queryCabinetDetails(@PathVariable("id") Integer id) {
+ return R.ok(cabinetService.queryCabinetDetails(id));
+ }
+
+
+ /**
+ * 机柜请求列表
+ *
+ * @param params
+ * @return
+ */
+ @GetMapping("/cabinet")
+ @SysLog(operation = OperationEnum.QUERY, type = TypeEnum.CABINET)
+ public R queryCabinetPage(@RequestParam Map<String, Object> params) {
+ PageUtils page = cabinetService.queryCabinetPage(params);
+ return R.ok(page);
+ }
+
+
+ /**
+ * 保存
+ *
+ * @param cabinet
+ * @return
+ */
+ @PostMapping("/cabinet")
+ @SysLog(operation = OperationEnum.ADD, type = TypeEnum.CABINET)
+ public R saveCabinet(@RequestBody Cabinet cabinet) {
+ ValidateUtils.is(cabinet.getName()).notNull(RCode.DC_CABINETNAME_ISNULL)
+ .and(cabinet.getDcId()).notNull(RCode.DC_ID_ISNULL)
+ .and(cabinet.getY()).min(1, RCode.CABINET_Y_MINIMUM)
+ .and(cabinet.getX()).min(1, RCode.CABINET_X_MINIMUM);
+
+ return R.ok().putData("id", cabinetService.saveCabinet(cabinet));
+ }
+
+
+ /**
+ * 修改
+ *
+ * @param cabinet
+ * @return
+ */
+ @PutMapping("/cabinet")
+ @SysLog(operation = OperationEnum.UPDATE,type = TypeEnum.CABINET)
+ public R updateCabinet(@RequestBody Cabinet cabinet) {
+ ValidateUtils.is(cabinet.getId()).notNull(RCode.DC_CABINETID_ISNULL)
+ .and(cabinet.getName()).notNull(RCode.DC_CABINETNAME_ISNULL)
+ .and(cabinet.getDcId()).notNull(RCode.DC_ID_ISNULL)
+ .and(cabinet.getY()).min(1, RCode.CABINET_Y_MINIMUM)
+ .and(cabinet.getX()).min(1, RCode.CABINET_X_MINIMUM);
+
+ return R.ok().putData("id", cabinetService.updateCabinet(cabinet));
+ }
+
+
+
+ /**
+ * 删除
+ *
+ * @param ids
+ * @return
+ */
+ @DeleteMapping("/cabinet")
+ @SysLog(operation = OperationEnum.DELETE,type = TypeEnum.CABINET)
+ public R deleteCabinetByIds(@RequestParam Integer ... ids) {
+ ValidateUtils.is(ids).notNull(RCode.DC_CABINETID_ISNULL);
+
+ cabinetService.deleteByIds(ids);
+ return R.ok();
+ }
+
+
+
+ /**
+ * 机柜u位查询
+ * @param id
+ * @return
+ */
+ @GetMapping("/cabinet/u")
+ @SysLog(operation = OperationEnum.QUERY, type = TypeEnum.CABINET)
+ public R getCabinetUsizeDetails(Integer id) {
+ ValidateUtils.is(id).notNull(RCode.DC_CABINETID_ISNULL);
+
+ Map uInfo = cabinetService.getCabinetUsizeDetails(id);
+ return R.ok(uInfo);
+ }
+
+
+
+}
diff --git a/nz-admin/src/main/java/com/nis/modules/asset/controller/IdcController.java b/nz-admin/src/main/java/com/nis/modules/asset/controller/IdcController.java
index aacb2a7f..4e78f7bd 100644
--- a/nz-admin/src/main/java/com/nis/modules/asset/controller/IdcController.java
+++ b/nz-admin/src/main/java/com/nis/modules/asset/controller/IdcController.java
@@ -57,9 +57,9 @@ public class IdcController {
@SysLog(operation = OperationEnum.ADD,type = TypeEnum.DATACENTER)
@RequiresPermissions({"idc:save"})
public R save(@RequestBody Idc idc) {
- ValidateUtils.is(idc.getName()).notNull(RCode.IDC_IDCNAME_ISNULL)
- .and(idc.getY()).min(1, RCode.IDC_Y_MINIMUM)
- .and(idc.getX()).min(1, RCode.IDC_X_MINIMUM);
+ ValidateUtils.is(idc.getName()).notNull(RCode.DC_NAME_ISNULL)
+ .and(idc.getY()).min(1, RCode.DC_Y_MINIMUM)
+ .and(idc.getX()).min(1, RCode.DC_X_MINIMUM);
idcService.saveOrUpdateIdc(idc);
return R.ok();
@@ -75,10 +75,10 @@ public class IdcController {
@SysLog(operation = OperationEnum.UPDATE,type = TypeEnum.DATACENTER)
@RequiresPermissions({"idc:update"})
public R update(@RequestBody Idc idc) {
- ValidateUtils.is(idc.getId()).notNull(RCode.IDC_IDCID_ISNULL)
- .and(idc.getName()).notNull(RCode.IDC_IDCNAME_ISNULL)
- .and(idc.getY()).min(1, RCode.IDC_Y_MINIMUM)
- .and(idc.getX()).min(1, RCode.IDC_X_MINIMUM);
+ ValidateUtils.is(idc.getId()).notNull(RCode.DC_ID_ISNULL)
+ .and(idc.getName()).notNull(RCode.DC_NAME_ISNULL)
+ .and(idc.getY()).min(1, RCode.DC_Y_MINIMUM)
+ .and(idc.getX()).min(1, RCode.DC_X_MINIMUM);
idcService.saveOrUpdateIdc(idc);
return R.ok();
@@ -95,7 +95,7 @@ public class IdcController {
@SysLog(operation = OperationEnum.DELETE,type = TypeEnum.DATACENTER)
@RequiresPermissions({"idc:delete"})
public R delete(@RequestParam Integer ... ids) {
- ValidateUtils.is(ids).notNull(RCode.IDC_IDCID_ISNULL);
+ ValidateUtils.is(ids).notNull(RCode.DC_ID_ISNULL);
idcService.delete(ids);
return R.ok();
@@ -122,4 +122,4 @@ public class IdcController {
idcTrafficService.updateTraffic(idcId, setting);
return R.ok();
}
-} \ No newline at end of file
+}
diff --git a/nz-admin/src/main/java/com/nis/modules/asset/dao/AssetDao.java b/nz-admin/src/main/java/com/nis/modules/asset/dao/AssetDao.java
index 2e72a543..f0526e96 100644
--- a/nz-admin/src/main/java/com/nis/modules/asset/dao/AssetDao.java
+++ b/nz-admin/src/main/java/com/nis/modules/asset/dao/AssetDao.java
@@ -49,4 +49,4 @@ public interface AssetDao extends BaseMapper<Asset> {
// 只返回统计的列 id host state idc_id model_id
List<Asset> getAssetsStatColumn();
-} \ No newline at end of file
+}
diff --git a/nz-admin/src/main/java/com/nis/modules/asset/dao/DcDao.java b/nz-admin/src/main/java/com/nis/modules/asset/dao/DcDao.java
new file mode 100644
index 00000000..5c3783aa
--- /dev/null
+++ b/nz-admin/src/main/java/com/nis/modules/asset/dao/DcDao.java
@@ -0,0 +1,18 @@
+package com.nis.modules.asset.dao;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.nis.modules.asset.entity.Dc;
+import org.apache.ibatis.annotations.Mapper;
+import org.springframework.stereotype.Repository;
+
+/**
+ * 数据中心 dao
+ *
+ * @author shizhendong
+ * @date 2021-4-6
+ */
+@Mapper
+@Repository
+public interface DcDao extends BaseMapper<Dc> {
+
+}
diff --git a/nz-admin/src/main/java/com/nis/modules/asset/entity/AssetAsset.java b/nz-admin/src/main/java/com/nis/modules/asset/entity/AssetAsset.java
index 80996673..96c546aa 100644
--- a/nz-admin/src/main/java/com/nis/modules/asset/entity/AssetAsset.java
+++ b/nz-admin/src/main/java/com/nis/modules/asset/entity/AssetAsset.java
@@ -159,7 +159,7 @@ public class AssetAsset implements Serializable {
* 数据中心
*/
@TableField(exist = false)
- private Idc dc;
+ private Dc dc;
/**
* 创建人
diff --git a/nz-admin/src/main/java/com/nis/modules/asset/entity/Cabinet.java b/nz-admin/src/main/java/com/nis/modules/asset/entity/Cabinet.java
index 1a49bf1a..752ca719 100644
--- a/nz-admin/src/main/java/com/nis/modules/asset/entity/Cabinet.java
+++ b/nz-admin/src/main/java/com/nis/modules/asset/entity/Cabinet.java
@@ -35,7 +35,7 @@ public class Cabinet implements Serializable {
/**
* 数据中心id
*/
- private Integer idcId;
+ private Integer dcId;
/**
* u位容量
@@ -63,6 +63,24 @@ public class Cabinet implements Serializable {
private Integer y;
/**
+ * dc
+ */
+ @TableField(exist = false)
+ private Dc dc;
+
+ /**
+ * 资产计数
+ */
+ @TableField(exist = false)
+ private Integer assetNum;
+
+ /**
+ * alert计数
+ */
+ @TableField(exist = false)
+ private Integer alertNum;
+
+ /**
* 资产统计
*/
@TableField(exist = false)
diff --git a/nz-admin/src/main/java/com/nis/modules/asset/entity/Dc.java b/nz-admin/src/main/java/com/nis/modules/asset/entity/Dc.java
new file mode 100644
index 00000000..ae8c967e
--- /dev/null
+++ b/nz-admin/src/main/java/com/nis/modules/asset/entity/Dc.java
@@ -0,0 +1,106 @@
+package com.nis.modules.asset.entity;
+
+import com.baomidou.mybatisplus.annotation.FieldStrategy;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.nis.modules.sys.entity.SysUserEntity;
+import lombok.Data;
+
+import java.io.Serializable;
+
+
+/**
+ * 数据中心实体
+ *
+ * @author shizhendong
+ * @date 2021-04-06
+ */
+@Data
+@TableName("dc")
+public class Dc implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * 主键
+ */
+ @TableId
+ private Integer id;
+
+ /**
+ * 数据中心名称
+ */
+ private String name;
+
+ /**
+ * 数据中心位置
+ */
+ private String location;
+
+ /**
+ * 联系电话
+ */
+ private String tel;
+
+ /**
+ * 机房负责人
+ */
+ private Integer principal;
+
+ /**
+ * 用于撤销具体某次批量导入的uuid
+ */
+ private String seq;
+
+ /**
+ * 列
+ */
+ private Integer x;
+
+ /**
+ * 行
+ */
+ private Integer y;
+
+ /**
+ * 经度
+ */
+ @TableField(strategy = FieldStrategy.IGNORED)
+ private Double longitude;
+
+ /**
+ * 纬度
+ */
+ @TableField(strategy = FieldStrategy.IGNORED)
+ private Double latitude;
+
+ /**
+ * 状态
+ */
+ private String state;
+
+ /**
+ * 机房负责人
+ */
+ @TableField(exist = false)
+ private SysUserEntity adminUser;
+
+ /**
+ * 机柜计数
+ */
+ @TableField(exist = false)
+ private Integer cabinetNum;
+
+ /**
+ * 资产计数
+ */
+ @TableField(exist = false)
+ private Integer assetNum;
+
+ /**
+ * alert计数
+ */
+ @TableField(exist = false)
+ private Integer alertNum;
+
+}
diff --git a/nz-admin/src/main/java/com/nis/modules/asset/entity/Idc.java b/nz-admin/src/main/java/com/nis/modules/asset/entity/Idc.java
index 60aa2c0a..18cb59d9 100644
--- a/nz-admin/src/main/java/com/nis/modules/asset/entity/Idc.java
+++ b/nz-admin/src/main/java/com/nis/modules/asset/entity/Idc.java
@@ -97,4 +97,4 @@ public class Idc implements Serializable {
*/
@TableField(exist = false)
private Map alertStat;
-} \ No newline at end of file
+}
diff --git a/nz-admin/src/main/java/com/nis/modules/asset/service/CabinetService.java b/nz-admin/src/main/java/com/nis/modules/asset/service/CabinetService.java
index f981a599..de28bf8f 100644
--- a/nz-admin/src/main/java/com/nis/modules/asset/service/CabinetService.java
+++ b/nz-admin/src/main/java/com/nis/modules/asset/service/CabinetService.java
@@ -21,5 +21,46 @@ public interface CabinetService extends IService<Cabinet> {
void delete(Integer ... ids);
Map getUInfo(Integer id);
+
+ /**
+ * 详情
+ * @param id
+ * @return
+ */
+ Cabinet queryCabinetDetails(Integer id);
+
+ /**
+ * 分页列表
+ * @param params
+ * @return
+ */
+ PageUtils queryCabinetPage(Map<String, Object> params);
+
+ /**
+ * 保存
+ * @param cabinet
+ * @return
+ */
+ Integer saveCabinet(Cabinet cabinet);
+
+ /**
+ * 修改
+ * @param cabinet
+ * @return
+ */
+ Integer updateCabinet(Cabinet cabinet);
+
+ /**
+ * 删除
+ * @param ids
+ */
+ void deleteByIds(Integer... ids);
+
+ /**
+ * 机柜u位查询
+ * @param id
+ * @return
+ */
+ Map getCabinetUsizeDetails(Integer id);
}
diff --git a/nz-admin/src/main/java/com/nis/modules/asset/service/DcService.java b/nz-admin/src/main/java/com/nis/modules/asset/service/DcService.java
new file mode 100644
index 00000000..f24b6c72
--- /dev/null
+++ b/nz-admin/src/main/java/com/nis/modules/asset/service/DcService.java
@@ -0,0 +1,51 @@
+package com.nis.modules.asset.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.nis.common.utils.PageUtils;
+import com.nis.modules.asset.entity.Dc;
+
+import java.util.Map;
+
+/**
+ * 数据中心 service
+ *
+ * @author shizhendong
+ * @date 2021-4-6
+ */
+public interface DcService extends IService<Dc> {
+
+ /**
+ * 详情
+ * @param id
+ * @return
+ */
+ Dc queryDcDetails(Integer id);
+
+ /**
+ * 分页查询
+ * @param params
+ * @return
+ */
+ PageUtils queryPage(Map<String, Object> params);
+
+ /**
+ * 新增
+ * @param dc
+ * @return
+ */
+ Integer saveDc(Dc dc);
+
+ /**
+ * 修改
+ * @param dc
+ * @return
+ */
+ Integer updateDc(Dc dc);
+
+ /**
+ * 删除
+ * @param ids
+ */
+ void delete(Integer... ids);
+}
+
diff --git a/nz-admin/src/main/java/com/nis/modules/asset/service/impl/AssetAssetServiceImpl.java b/nz-admin/src/main/java/com/nis/modules/asset/service/impl/AssetAssetServiceImpl.java
index 8d79281e..9eb32e2a 100644
--- a/nz-admin/src/main/java/com/nis/modules/asset/service/impl/AssetAssetServiceImpl.java
+++ b/nz-admin/src/main/java/com/nis/modules/asset/service/impl/AssetAssetServiceImpl.java
@@ -74,7 +74,7 @@ public class AssetAssetServiceImpl extends ServiceImpl<AssetAssetDao, AssetAsset
private AssetFieldMetaDao assetFieldMetaDao;
@Autowired
- private IdcService idcService;
+ private DcService dcService;
@Autowired
private CabinetService cabinetService;
@@ -148,8 +148,8 @@ public class AssetAssetServiceImpl extends ServiceImpl<AssetAssetDao, AssetAsset
AssetModel model = modelService.getById(asset.getModelId());
asset.setModel(model);
- Idc idc = idcService.getById(asset.getDcId());
- asset.setDc(idc);
+ Dc dc = dcService.getById(asset.getDcId());
+ asset.setDc(dc);
if (asset.getCabinetId() != null) {
Cabinet cabinet = cabinetService.getById(asset.getCabinetId());
@@ -373,8 +373,8 @@ public class AssetAssetServiceImpl extends ServiceImpl<AssetAssetDao, AssetAsset
// 不是虚拟机进行 dc cabinet 校验,虚拟机直接集成 宿主机 dc cabinet 信息
if (typeConf.getVm().equals(0)) {
// dc
- Idc idc = idcService.getById(asset.getDcId());
- ValidateUtils.is(idc).notNull(RCode.ASSET_IDC_NOTFOUND);
+ Dc dc = dcService.getById(asset.getDcId());
+ ValidateUtils.is(dc).notNull(RCode.ASSET_DC_NOTFOUND);
// cab
if (ToolUtil.isNotEmpty(asset.getCabinetId())) {
@@ -382,8 +382,8 @@ public class AssetAssetServiceImpl extends ServiceImpl<AssetAssetDao, AssetAsset
ValidateUtils.is(cabinet).notNull(RCode.ASSET_CABINET_NOTFOUND);
// cabinet dc 不匹配
- if (!idc.getId().equals(cabinet.getIdcId())) {
- throw new NZException(RCode.IDC_NOTHAS_CABINET);
+ if (!dc.getId().equals(cabinet.getDcId())) {
+ throw new NZException(RCode.DC_NOTHAS_CABINET);
}
// 校验机柜可用位置
@@ -972,22 +972,22 @@ public class AssetAssetServiceImpl extends ServiceImpl<AssetAssetDao, AssetAsset
}
private List<Map> getDcStatByAsset(List<AssetAsset> assetList) {
- List<Idc> idcList = idcService.list();
+ List<Dc> dcList = dcService.list();
List<Cabinet> cabinetList = cabinetService.list();
Map<Integer, List<AssetAsset>> dcIdAndAssetListMap = assetList.stream().collect(Collectors.groupingBy(AssetAsset::getDcId));
Map<Integer, List<AssetAsset>> cabIdAndAssetListMap = assetList.stream().filter(assetAsset -> ToolUtil.isNotEmpty(assetAsset.getCabinetId())).collect(Collectors.groupingBy(AssetAsset::getCabinetId));
List<Map> dcStats = new ArrayList<>();
- for (Idc idc : idcList) {
- List<AssetAsset> dcAssetList = dcIdAndAssetListMap.get(idc.getId());
+ for (Dc dc : dcList) {
+ List<AssetAsset> dcAssetList = dcIdAndAssetListMap.get(dc.getId());
if (CollectionUtils.isEmpty(dcAssetList)) {
continue;
}
List<Map> dcBabyCab = new ArrayList();
for (Cabinet cabinet : cabinetList) {
List<AssetAsset> cabAssetList = cabIdAndAssetListMap.get(cabinet.getId());
- if (cabinet.getIdcId().equals(idc.getId()) && CollectionUtils.isNotEmpty(cabAssetList)) {
+ if (cabinet.getDcId().equals(dc.getId()) && CollectionUtils.isNotEmpty(cabAssetList)) {
Map cabStat = new HashMap(4);
cabStat.put("id", cabinet.getId());
cabStat.put("name", cabinet.getName());
@@ -996,8 +996,8 @@ public class AssetAssetServiceImpl extends ServiceImpl<AssetAssetDao, AssetAsset
}
}
Map statByDc = new HashMap(8);
- statByDc.put("id", idc.getId());
- statByDc.put("name", idc.getName());
+ statByDc.put("id", dc.getId());
+ statByDc.put("name", dc.getName());
statByDc.put("total", dcAssetList.size());
statByDc.put("children", dcBabyCab);
dcStats.add(statByDc);
@@ -1093,8 +1093,8 @@ public class AssetAssetServiceImpl extends ServiceImpl<AssetAssetDao, AssetAsset
// asset
this.remove(new QueryWrapper<AssetAsset>().lambda().eq(AssetAsset::getSeq, seq));
- // idc
- idcService.remove(new QueryWrapper<Idc>().lambda().eq(Idc::getSeq, seq));
+ // dc
+ dcService.remove(new QueryWrapper<Dc>().lambda().eq(Dc::getSeq, seq));
// cabinet
cabinetService.remove(new QueryWrapper<Cabinet>().lambda().eq(Cabinet::getSeq, seq));
@@ -1112,8 +1112,8 @@ public class AssetAssetServiceImpl extends ServiceImpl<AssetAssetDao, AssetAsset
List<String> assetSnList = assetList.stream().map(AssetAsset::getSn).collect(Collectors.toList());
List<String> assetIpList = assetList.stream().map(AssetAsset::getManageIp).collect(Collectors.toList());
- List<Idc> idcList = idcService.list();
- Map<String, Idc> idcNameAndEntityMap = idcList.stream().collect(Collectors.toMap(Idc::getName, Function.identity()));
+ List<Dc> dcList = dcService.list();
+ Map<String, Dc> dcNameAndEntityMap = dcList.stream().collect(Collectors.toMap(Dc::getName, Function.identity()));
List<Cabinet> cabinetList = cabinetDao.getCabinetWithAssetPositionInfo();
@@ -1289,9 +1289,9 @@ public class AssetAssetServiceImpl extends ServiceImpl<AssetAssetDao, AssetAsset
String dcName = ExcelUtils.getCellValue(row.getCell(6));
if (StringUtils.isEmpty(dcName)) {
saveFlag = false;
- this.addFailDetail(dataFromExcelRowNum, failDetails, headerInfos.get(6), RCode.IDC_IDCNAME_ISNULL.getMsg());
+ this.addFailDetail(dataFromExcelRowNum, failDetails, headerInfos.get(6), RCode.DC_NAME_ISNULL.getMsg());
} else {
- dcId = this.validateIdc(dcName, idcNameAndEntityMap, seqUUID, saveEntitys);
+ dcId = this.validateDc(dcName, dcNameAndEntityMap, seqUUID, saveEntitys);
}
// 虚拟机 vm info 校验 / 虚拟机必须选择宿主
@@ -1319,7 +1319,7 @@ public class AssetAssetServiceImpl extends ServiceImpl<AssetAssetDao, AssetAsset
Integer modelUsize = modelIdAndUsizeMap.get(modelId);
modelUsize = ToolUtil.isEmpty(modelUsize) ? 1 : modelUsize;
boolean posttionFlag = start != null && end != null;
- if (dcId != null) { // idc已存在,不需要添加
+ if (dcId != null) { // dc已存在,不需要添加
Cabinet cabinet = this.validateCabinet(cabinetName, dcId, cabinetList, seqUUID, saveEntitys, defaultCabinetUsize);
cabinetId = cabinet.getId();
boolean cabinetExitFlag = cabinet.getId() != null;
@@ -1342,7 +1342,7 @@ public class AssetAssetServiceImpl extends ServiceImpl<AssetAssetDao, AssetAsset
}
}
}
- } else { // idc不存在
+ } else { // dc不存在
this.saveEntityAddCabEntity(saveEntitys, cabinetName, defaultCabinetUsize, seqUUID);
if (posttionFlag) {
end = end + 1;
@@ -1406,7 +1406,7 @@ public class AssetAssetServiceImpl extends ServiceImpl<AssetAssetDao, AssetAsset
// 调用入库方法
Map updateMap = this.saveRowData(saveEntitys);
dataSourceTransactionManager.commit(transactionStatus);
- this.updateImportAssetRelatedInfo(updateMap, assetNameAndEntityMap, assetSnList, assetIpList, idcNameAndEntityMap, brandNameAndEntityMap, brandIdAndModelListMap, cabinetList);
+ this.updateImportAssetRelatedInfo(updateMap, assetNameAndEntityMap, assetSnList, assetIpList, dcNameAndEntityMap, brandNameAndEntityMap, brandIdAndModelListMap, cabinetList);
successNum++;
} catch (TransactionException e) {
dataSourceTransactionManager.rollback(transactionStatus);
@@ -1458,7 +1458,7 @@ public class AssetAssetServiceImpl extends ServiceImpl<AssetAssetDao, AssetAsset
boolean flag = false;
for (Cabinet entity : cabinetList) {
// 如果该机房下有该机柜
- if (StrUtil.equals(cabinetName, entity.getName()) && dcId.equals(entity.getIdcId())) {
+ if (StrUtil.equals(cabinetName, entity.getName()) && dcId.equals(entity.getDcId())) {
cabinet = entity;
flag = true;
break;
@@ -1467,7 +1467,7 @@ public class AssetAssetServiceImpl extends ServiceImpl<AssetAssetDao, AssetAsset
// 找不到机柜
if (!flag) {
cabinet.setName(cabinetName);
- cabinet.setIdcId(dcId);
+ cabinet.setDcId(dcId);
cabinet.setuSize(defaultCabinetUsize);
cabinet.setSeq(seqUUID);
saveEntitys.put("cabinet", cabinet);
@@ -1483,10 +1483,10 @@ public class AssetAssetServiceImpl extends ServiceImpl<AssetAssetDao, AssetAsset
}
}
- private void updateImportAssetRelatedInfo(Map updateMap, Map<String, AssetAsset> assetNameAndEntityMap, List<String> assetSnList, List<String> assetIpList, Map<String, Idc> idcNameAndEntityMap, Map<String, AssetBrand> brandNameAndEntityMap, Map<Integer, List<AssetModel>> brandIdAndModelListMap, List<Cabinet> cabinetList) {
- Idc updateIdc = (Idc) updateMap.get("idc");
+ private void updateImportAssetRelatedInfo(Map updateMap, Map<String, AssetAsset> assetNameAndEntityMap, List<String> assetSnList, List<String> assetIpList, Map<String, Dc> dcNameAndEntityMap, Map<String, AssetBrand> brandNameAndEntityMap, Map<Integer, List<AssetModel>> brandIdAndModelListMap, List<Cabinet> cabinetList) {
+ Dc updateIdc = (Dc) updateMap.get("dc");
if (updateIdc != null) {
- idcNameAndEntityMap.put(updateIdc.getName(), updateIdc);
+ dcNameAndEntityMap.put(updateIdc.getName(), updateIdc);
}
AssetBrand updateBrand = (AssetBrand) updateMap.get("brand");
@@ -1530,21 +1530,21 @@ public class AssetAssetServiceImpl extends ServiceImpl<AssetAssetDao, AssetAsset
public Map saveRowData(Map saveEntitys) {
Map updateMap = new HashMap();
// DC
- Idc idc = (Idc) saveEntitys.get("idc");
+ Dc dc = (Dc) saveEntitys.get("dc");
// Cabinet
Cabinet cabinet = (Cabinet) saveEntitys.get("cabinet");
- if (idc == null && cabinet != null) {
+ if (dc == null && cabinet != null) {
cabinetService.save(cabinet);
updateMap.put("cabinet", cabinet);
}
- if (idc != null) {
- idcService.save(idc);
+ if (dc != null) {
+ dcService.save(dc);
if (cabinet != null) {
- cabinet.setIdcId(idc.getId());
+ cabinet.setDcId(dc.getId());
cabinetService.save(cabinet);
updateMap.put("cabinet", cabinet);
}
- updateMap.put("idc", idc);
+ updateMap.put("dc", dc);
}
// brand
@@ -1576,8 +1576,8 @@ public class AssetAssetServiceImpl extends ServiceImpl<AssetAssetDao, AssetAsset
if (asset.getModelId() == null && model != null) {
asset.setModelId(model.getId());
}
- if (asset.getDcId() == null && idc != null) {
- asset.setDcId(idc.getId());
+ if (asset.getDcId() == null && dc != null) {
+ asset.setDcId(dc.getId());
}
if (asset.getCabinetId() == null && cabinet != null) {
asset.setCabinetId(cabinet.getId());
@@ -1616,16 +1616,16 @@ public class AssetAssetServiceImpl extends ServiceImpl<AssetAssetDao, AssetAsset
}
- private Integer validateIdc(String dcName, Map<String, Idc> idcNameAndEntityMap, String seqUUID, Map saveEntitys) {
- Idc idc = idcNameAndEntityMap.get(dcName);
- if (idc == null) {
- idc = new Idc();
- idc.setName(dcName);
- idc.setState(Constant.SWITCH_OPEN.toUpperCase());
- idc.setSeq(seqUUID);
- saveEntitys.put("idc", idc);
+ private Integer validateDc(String dcName, Map<String, Dc> dcNameAndEntityMap, String seqUUID, Map saveEntitys) {
+ Dc dc = dcNameAndEntityMap.get(dcName);
+ if (dc == null) {
+ dc = new Dc();
+ dc.setName(dcName);
+ dc.setState(Constant.SWITCH_OPEN.toUpperCase());
+ dc.setSeq(seqUUID);
+ saveEntitys.put("dc", dc);
}
- return idc.getId();
+ return dc.getId();
}
private List<String> getPortListByPattern(String portStr, Pattern portPattern) {
diff --git a/nz-admin/src/main/java/com/nis/modules/asset/service/impl/AssetServiceImpl.java b/nz-admin/src/main/java/com/nis/modules/asset/service/impl/AssetServiceImpl.java
index b7f86993..2495a19b 100644
--- a/nz-admin/src/main/java/com/nis/modules/asset/service/impl/AssetServiceImpl.java
+++ b/nz-admin/src/main/java/com/nis/modules/asset/service/impl/AssetServiceImpl.java
@@ -56,7 +56,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionDefinition;
-import org.springframework.transaction.TransactionException;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
@@ -428,7 +427,7 @@ public class AssetServiceImpl extends ServiceImpl<AssetDao, Asset> implements As
// 5. 数据中心校验
Idc idc = idcService.getById(asset.getIdcId());
- ValidateUtils.is(idc).notNull(RCode.ASSET_IDC_NOTFOUND);
+ ValidateUtils.is(idc).notNull(RCode.ASSET_DC_NOTFOUND);
// 6. 机柜及资产起始位置校验
Integer cabinetId = asset.getCabinetId();
@@ -437,9 +436,9 @@ public class AssetServiceImpl extends ServiceImpl<AssetDao, Asset> implements As
if (cabinetId != null) {
Cabinet cabinet = cabinetService.getById(cabinetId);
ValidateUtils.is(cabinet).notNull(RCode.ASSET_CABINET_NOTFOUND);
- if (!idc.getId().equals(cabinet.getIdcId())) {
+ if (!idc.getId().equals(cabinet.getDcId())) {
// 数据中心与机柜不符 当前数据中心没有含有所选机柜
- throw new NZException(RCode.IDC_NOTHAS_CABINET);
+ throw new NZException(RCode.DC_NOTHAS_CABINET);
}
// 选择了机柜再进行处理 usize 相关数据
if (start != null && end != null) {
@@ -918,7 +917,7 @@ public class AssetServiceImpl extends ServiceImpl<AssetDao, Asset> implements As
dcName = ExcelUtils.getCellValue(row.getCell(4));
if (StringUtils.isEmpty(dcName)) {
saveFlag = false;
- this.addFailDetail(dataFromExcelRowNum, failDetails, headerInfos.get(4), RCode.IDC_IDCNAME_ISNULL.getMsg());
+ this.addFailDetail(dataFromExcelRowNum, failDetails, headerInfos.get(4), RCode.DC_NAME_ISNULL.getMsg());
} else {
idcId = this.checkIdc(dcName, idcMap, seqUUID, saveEntitys);
// idcId 可能为null,入库之后返回
@@ -1439,7 +1438,7 @@ public class AssetServiceImpl extends ServiceImpl<AssetDao, Asset> implements As
if (idc != null) {
idcService.save(idc);
if (cabinet != null) {
- cabinet.setIdcId(idc.getId());
+ cabinet.setDcId(idc.getId());
cabinetService.save(cabinet);
updateMap.put("cabinet", cabinet);
}
@@ -2096,7 +2095,7 @@ public class AssetServiceImpl extends ServiceImpl<AssetDao, Asset> implements As
for (Cabinet entity : cabinetList) {
// 如果该机房下有该机柜
// if (cabinetName.equals(entity.getName()) && idcId.equals(entity.getIdcId())) {
- if (StrUtil.equals(cabinetName,entity.getName())&&idcId.equals(entity.getIdcId())) {
+ if (StrUtil.equals(cabinetName,entity.getName())&&idcId.equals(entity.getDcId())) {
cabinet = entity;
flag = true;
break;
@@ -2105,7 +2104,7 @@ public class AssetServiceImpl extends ServiceImpl<AssetDao, Asset> implements As
// 找不到机柜
if (!flag) {
cabinet.setName(cabinetName);
- cabinet.setIdcId(idcId);
+ cabinet.setDcId(idcId);
cabinet.setuSize(defaultCabinetUsize);
cabinet.setSeq(seqUUID);
saveEntitys.put("cabinet", cabinet);
@@ -2660,4 +2659,4 @@ public class AssetServiceImpl extends ServiceImpl<AssetDao, Asset> implements As
}
}
}
-} \ No newline at end of file
+}
diff --git a/nz-admin/src/main/java/com/nis/modules/asset/service/impl/CabinetServiceImpl.java b/nz-admin/src/main/java/com/nis/modules/asset/service/impl/CabinetServiceImpl.java
index 37b4fd1c..24d32d37 100644
--- a/nz-admin/src/main/java/com/nis/modules/asset/service/impl/CabinetServiceImpl.java
+++ b/nz-admin/src/main/java/com/nis/modules/asset/service/impl/CabinetServiceImpl.java
@@ -1,28 +1,34 @@
package com.nis.modules.asset.service.impl;
+import cn.hutool.log.Log;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nis.common.exception.NZException;
import com.nis.common.smartvalidate.ValidateUtils;
import com.nis.common.utils.*;
+import com.nis.modules.alert.dao.AlertMessageDao;
+import com.nis.modules.alert.entity.AlertMessageEntity;
import com.nis.modules.asset.dao.CabinetDao;
import com.nis.modules.asset.entity.Asset;
+import com.nis.modules.asset.entity.AssetAsset;
import com.nis.modules.asset.entity.Cabinet;
-import com.nis.modules.asset.entity.Idc;
+import com.nis.modules.asset.entity.Dc;
+import com.nis.modules.asset.service.AssetAssetService;
import com.nis.modules.asset.service.AssetService;
import com.nis.modules.asset.service.CabinetService;
-import com.nis.modules.asset.service.IdcService;
+import com.nis.modules.asset.service.DcService;
import com.nis.modules.overview.entity.AssetStat;
import com.nis.modules.overview.service.OverviewService;
import com.nis.modules.sys.entity.SysConfigEntity;
import com.nis.modules.sys.service.SysConfigService;
-import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
+import java.util.function.Function;
import java.util.stream.Collectors;
/**
@@ -32,11 +38,9 @@ import java.util.stream.Collectors;
* @date 2019-11-21
*/
@Service("cabinetService")
-@Slf4j
public class CabinetServiceImpl extends ServiceImpl<CabinetDao, Cabinet> implements CabinetService {
- @Autowired
- private IdcService idcService;
+ private static Log log = Log.get();
@Autowired
private AssetService assetService;
@@ -50,6 +54,15 @@ public class CabinetServiceImpl extends ServiceImpl<CabinetDao, Cabinet> impleme
@Autowired
private SysConfigService sysConfigService;
+ @Autowired
+ private DcService dcService;
+
+ @Autowired
+ private AssetAssetService assetAssetService;
+
+ @Autowired
+ private AlertMessageDao alertMessageDao;
+
@Override
public PageUtils queryPage(Map<String, Object> params) {
IPage<Cabinet> page = new Query<Cabinet>().getPage(params);
@@ -127,13 +140,13 @@ public class CabinetServiceImpl extends ServiceImpl<CabinetDao, Cabinet> impleme
*/
private void validateCabinetInfo(Cabinet cabinet) {
// 1. 校验机房是否存在
- Idc idc = idcService.getById(cabinet.getIdcId());
- if (idc == null) {
- throw new NZException(RCode.IDC_NOT_EXISTS);
+ Dc dc = dcService.getById(cabinet.getDcId());
+ if (dc == null) {
+ throw new NZException(RCode.DC_NOT_EXISTS);
}
// 2. 校验机柜名称唯一
- List<Cabinet> list = this.list(new QueryWrapper<Cabinet>().lambda().eq(Cabinet::getName, cabinet.getName()).eq(Cabinet::getIdcId, idc.getId()));
+ List<Cabinet> list = this.list(new QueryWrapper<Cabinet>().lambda().eq(Cabinet::getName, cabinet.getName()).eq(Cabinet::getDcId, dc.getId()));
boolean flag = false;
@@ -142,12 +155,12 @@ public class CabinetServiceImpl extends ServiceImpl<CabinetDao, Cabinet> impleme
}
if(!flag){
- throw new NZException(RCode.IDC_CABINETNAME_DUPLICATE);
+ throw new NZException(RCode.DC_CABINETNAME_DUPLICATE);
}
// 3.校验 usize 最小最大值
if(cabinet.getuSize() != null){
- ValidateUtils.is(cabinet.getuSize()).min(1, RCode.IDC_CABINETUSIZE_MINIMUM).max(Constant.CURRENT_CABINET_MAXU, RCode.IDC_CABINET_MAXU);
+ ValidateUtils.is(cabinet.getuSize()).min(1, RCode.DC_CABINETUSIZE_MINIMUM).max(Constant.CURRENT_CABINET_MAXU, RCode.DC_CABINET_MAXU);
}
// 4. 校验行列值
@@ -159,29 +172,29 @@ public class CabinetServiceImpl extends ServiceImpl<CabinetDao, Cabinet> impleme
* @param cabinet
*/
private void validateXY(Cabinet cabinet) {
- Idc idc = idcService.getById(cabinet.getIdcId());
+ Dc dc = dcService.getById(cabinet.getDcId());
Integer y = cabinet.getY();
Integer x = cabinet.getX();
if (y != null) {
- Integer idcY = idc.getY();
- if (idcY != null) {
- ValidateUtils.is(cabinet.getY()).max(idcY, RCode.CABINET_Y_INCORRECT);
+ Integer dcY = dc.getY();
+ if (dcY != null) {
+ ValidateUtils.is(cabinet.getY()).max(dcY, RCode.CABINET_Y_INCORRECT);
}
}
if (x != null) {
- Integer idcX = idc.getX();
- if (idcX != null) {
- ValidateUtils.is(cabinet.getX()).max(idcX, RCode.CABINET_X_INCORRECT);
+ Integer dcX = dc.getX();
+ if (dcX != null) {
+ ValidateUtils.is(cabinet.getX()).max(dcX, RCode.CABINET_X_INCORRECT);
}
}
// 当行列都不为空时 校验位置是否被占用 如果只单独填写了行或列的话 暂时不做具体位置校验
if (y != null && x != null) {
- Cabinet entity = this.getOne(new QueryWrapper<Cabinet>().lambda().eq(Cabinet::getIdcId, cabinet.getIdcId()).eq(Cabinet::getY, y).eq(Cabinet::getX, x));
+ Cabinet entity = this.getOne(new QueryWrapper<Cabinet>().lambda().eq(Cabinet::getDcId, cabinet.getDcId()).eq(Cabinet::getY, y).eq(Cabinet::getX, x));
if (entity != null) {
Integer id = cabinet.getId();
if (id == null) {
@@ -213,7 +226,7 @@ public class CabinetServiceImpl extends ServiceImpl<CabinetDao, Cabinet> impleme
// 1. 如果删除的机柜包含资产 不可删除
if (CollectionUtils.isNotEmpty(idList)) {
List<String> cabNames = this.listByIds(idList).stream().map(Cabinet::getName).collect(Collectors.toList());
- throw new NZException("These cabinets contain assets and cannot be deleted, cabinets info: " + cabNames.toString(), RCode.IDC_CABINET_ASSETS_EXISTS.getCode());
+ throw new NZException("These cabinets contain assets and cannot be deleted, cabinets info: " + cabNames.toString(), RCode.DC_CABINET_ASSETS_EXISTS.getCode());
}
// 2.删除
@@ -260,4 +273,154 @@ public class CabinetServiceImpl extends ServiceImpl<CabinetDao, Cabinet> impleme
resuleData.put("available", size - occupyList.size());
return resuleData;
}
-} \ No newline at end of file
+
+ @Override
+ public Cabinet queryCabinetDetails(Integer id) {
+ Cabinet cabinet = this.getById(id);
+ if (ToolUtil.isEmpty(cabinet)) {
+ throw new NZException(RCode.CABINET_NOT_EXISTS);
+ }
+
+ Dc dc = dcService.getById(cabinet.getDcId());
+ cabinet.setDc(dc);
+
+ List<AssetAsset> assetList = assetAssetService.list(new LambdaQueryWrapper<AssetAsset>().eq(AssetAsset::getCabinetId, cabinet.getId()));
+ cabinet.setAssetNum(assetList.size());
+ if(CollectionUtils.isNotEmpty(assetList)){
+ // 包含 asset 则统计 alert
+ List<Integer> cabinetAssetIdList = assetList.stream().map(AssetAsset::getId).collect(Collectors.toList());
+ List<AlertMessageEntity> alertList = alertMessageDao.getAlertsStatColumn();
+ long alertNum = alertList.stream().filter(alert -> cabinetAssetIdList.contains(alert.getAssetId())).count();
+ cabinet.setAlertNum((int) alertNum);
+ }else{
+ cabinet.setAlertNum(0);
+ }
+ return cabinet;
+ }
+
+ @Override
+ public PageUtils queryCabinetPage(Map<String, Object> params) {
+ IPage<Cabinet> page = this.page(new Query<Cabinet>().getPage(params), new LambdaQueryWrapper<Cabinet>()
+ .in(ToolUtil.isNotEmpty(params.get("ids")), Cabinet::getId, ToolUtil.isNotEmpty(params.get("ids")) ? Arrays.asList(params.get("ids").toString().split(",")) : null)
+ .like(ToolUtil.isNotEmpty(params.get("name")), Cabinet::getName, params.get("name"))
+ .in(ToolUtil.isNotEmpty(params.get("dcIds")), Cabinet::getDcId, ToolUtil.isNotEmpty(params.get("dcIds")) ? Arrays.asList(params.get("dcIds").toString().split(",")) : null));
+
+ List<Cabinet> cabinetList = page.getRecords();
+ if(CollectionUtils.isNotEmpty(cabinetList)){
+ // 处理返回结果
+ this.handleResuleList(cabinetList);
+ }
+ page.setRecords(cabinetList);
+ return new PageUtils(page);
+ }
+
+ private void handleResuleList(List<Cabinet> cabinetList) {
+ List<Dc> dcList = dcService.list();
+ Map<Integer, Dc> dcIdAndEntityMap = dcList.stream().collect(Collectors.toMap(Dc::getId, Function.identity()));
+
+ List<AssetAsset> assetList = assetAssetService.list();
+ assetList = assetList.stream().filter(asset -> asset.getCabinetId() != null).collect(Collectors.toList());
+
+ List<AlertMessageEntity> alertList = alertMessageDao.getAlertsStatColumn();
+ alertList = alertList.stream().filter(alertMessageEntity -> alertMessageEntity.getAssetId() != null).collect(Collectors.toList());
+
+ for (Cabinet cabinet : cabinetList) {
+ cabinet.setDc(dcIdAndEntityMap.get(cabinet.getDcId()));
+
+ List<Integer> cabinetAssetIdList = assetList.stream().filter(asset -> cabinet.getId().equals(asset.getCabinetId())).map(AssetAsset::getId).collect(Collectors.toList());
+ cabinet.setAssetNum(cabinetAssetIdList.size());
+
+ long alertNum = alertList.stream().filter(alert -> cabinetAssetIdList.contains(alert.getAssetId())).count();
+ cabinet.setAlertNum((int) alertNum);
+ }
+ }
+
+ @Override
+ public Integer saveCabinet(Cabinet cabinet) {
+ // 校验
+ this.validateCabinetInfo(cabinet);
+
+ // Usize 为空 则从配置表中取出 cabinet u位默认值
+ if (cabinet.getuSize() == null) {
+ SysConfigEntity configEntity = sysConfigService.getOne(new QueryWrapper<SysConfigEntity>().lambda().eq(SysConfigEntity::getParamKey, Constant.SYSCONFIG_KEY_DEFAULT_CABINETU).eq(SysConfigEntity::getStatus, 1));
+ cabinet.setuSize(Integer.valueOf(configEntity.getParamKey()));
+ }
+
+ // 保存
+ this.save(cabinet);
+ return cabinet.getId();
+ }
+
+ @Override
+ public Integer updateCabinet(Cabinet cabinet) {
+ // 校验
+ this.validateCabinetInfo(cabinet);
+
+ // 保存
+ this.updateById(cabinet);
+ return cabinet.getId();
+ }
+
+ @Override
+ public void deleteByIds(Integer... ids) {
+ List<AssetAsset> assets = assetAssetService.list();
+
+ // asset 使用的 cabinet
+ Set<Integer> assetUsedCabinetIds = assets.stream().filter(asset -> {
+ if (ToolUtil.isNotEmpty(asset.getCabinetId())) {
+ return true;
+ }
+ return false;
+ }).map(AssetAsset::getCabinetId).collect(Collectors.toSet());
+
+ List<Integer> idList = Arrays.stream(ids).collect(Collectors.toList());
+ idList.retainAll(assetUsedCabinetIds);
+ if (CollectionUtils.isNotEmpty(idList)) {
+ List<String> cabNames = this.listByIds(idList).stream().map(Cabinet::getName).collect(Collectors.toList());
+ throw new NZException("These cabinets contain assets and cannot be deleted, Details: " + cabNames.toString(), RCode.DC_CABINET_ASSETS_EXISTS.getCode());
+ }
+
+ // 删除
+ this.removeByIds(Arrays.asList(ids));
+ }
+
+ @Override
+ public Map getCabinetUsizeDetails(Integer id) {
+ // 获取当前机柜
+ Cabinet cabinet = this.getById(id);
+ if (cabinet == null) {
+ throw new NZException(RCode.ASSET_CABINET_NOTFOUND);
+ }
+
+ Map resuleData = new HashMap();
+ Integer size = cabinet.getuSize();
+ // 如果机柜没有大小 返回信息
+ if (size == null) {
+ resuleData.put("total", 0);
+ resuleData.put("available", 0);
+ resuleData.put("occupy", new ArrayList<>());
+ return resuleData;
+ }
+
+ resuleData.put("total", size);
+
+ // 查询当前机柜下资产
+ List<AssetAsset> assets = assetAssetService.list(new QueryWrapper<AssetAsset>().lambda().eq(AssetAsset::getCabinetId, cabinet.getId()));
+ assets = assets.stream().filter(asset -> asset.getCabinetStart() != null && asset.getCabinetEnd() != null).collect(Collectors.toList());
+
+ // 已经被占用位置
+ Set<Integer> occupyList = new TreeSet<>();
+ for (AssetAsset asset : assets) {
+ for (int i = asset.getCabinetStart(); i < asset.getCabinetEnd(); i++) {
+ occupyList.add(i);
+ }
+ }
+
+ // 对占用位置结果集排序
+ List<Integer> tempList = new ArrayList<>(occupyList);
+ Collections.sort(tempList);
+ resuleData.put("occupy", tempList);
+ resuleData.put("available", size - tempList.size());
+ return resuleData;
+ }
+}
diff --git a/nz-admin/src/main/java/com/nis/modules/asset/service/impl/DcServiceImpl.java b/nz-admin/src/main/java/com/nis/modules/asset/service/impl/DcServiceImpl.java
new file mode 100644
index 00000000..3ea8b7b4
--- /dev/null
+++ b/nz-admin/src/main/java/com/nis/modules/asset/service/impl/DcServiceImpl.java
@@ -0,0 +1,270 @@
+package com.nis.modules.asset.service.impl;
+
+import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.nis.common.exception.NZException;
+import com.nis.common.utils.*;
+import com.nis.modules.alert.dao.AlertMessageDao;
+import com.nis.modules.alert.entity.AlertMessageEntity;
+import com.nis.modules.asset.dao.AssetAssetDao;
+import com.nis.modules.asset.dao.CabinetDao;
+import com.nis.modules.asset.dao.DcDao;
+import com.nis.modules.asset.entity.AssetAsset;
+import com.nis.modules.asset.entity.Cabinet;
+import com.nis.modules.asset.entity.Dc;
+import com.nis.modules.asset.service.DcService;
+import com.nis.modules.promserver.dao.PromserverDao;
+import com.nis.modules.promserver.entity.Promserver;
+import com.nis.modules.sys.entity.SysUserEntity;
+import com.nis.modules.sys.service.SysUserService;
+import org.apache.commons.collections.CollectionUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+/**
+ * 数据中心 serviceImpl
+ * @author shizhendong
+ * @date 2021-4-6
+ */
+@Service
+public class DcServiceImpl extends ServiceImpl<DcDao, Dc> implements DcService {
+
+ @Autowired
+ private AssetAssetDao assetDao;
+
+ @Autowired
+ private CabinetDao cabinetDao;
+
+ @Autowired
+ private PromserverDao promserverDao;
+
+ @Autowired
+ private AlertMessageDao alertMessageDao;
+
+ @Autowired
+ private SysUserService sysUserService;
+
+
+ @Override
+ public Dc queryDcDetails(Integer id) {
+ Dc dc = this.getById(id);
+ if (ToolUtil.isEmpty(dc)) {
+ throw new NZException(RCode.DC_NOT_EXISTS);
+ }
+
+ if(ToolUtil.isNotEmpty(dc.getPrincipal())){
+ SysUserEntity principal = sysUserService.getById(dc.getPrincipal());
+ dc.setAdminUser(principal);
+ }
+
+ Integer cabinetNum = cabinetDao.selectCount(new LambdaQueryWrapper<Cabinet>().eq(Cabinet::getDcId, dc.getId()));
+ dc.setCabinetNum(cabinetNum);
+
+ Integer alertNum = alertMessageDao.selectCount(new LambdaQueryWrapper<AlertMessageEntity>().eq(AlertMessageEntity::getDcId, dc.getId()));
+ dc.setAlertNum(alertNum);
+
+ Integer assetNum = assetDao.selectCount(new LambdaQueryWrapper<AssetAsset>().eq(AssetAsset::getDcId, dc.getId()));
+ dc.setAssetNum(assetNum);
+
+ return dc;
+ }
+
+ @Override
+ public PageUtils queryPage(Map<String, Object> params) {
+
+ IPage<Dc> page = this.page(new Query<Dc>().getPage(params), new LambdaQueryWrapper<Dc>()
+ .in(ToolUtil.isNotEmpty(params.get("ids")), Dc::getId, ToolUtil.isNotEmpty(params.get("ids")) ? Arrays.asList(params.get("ids").toString().split(",")) : null)
+ .eq(ToolUtil.isNotEmpty(params.get("principal")), Dc::getPrincipal, params.get("principal"))
+ .eq(ToolUtil.isNotEmpty(params.get("state")), Dc::getState, params.get("state"))
+ .like(ToolUtil.isNotEmpty(params.get("name")), Dc::getName, params.get("name"))
+ .like(ToolUtil.isNotEmpty(params.get("location")), Dc::getLocation, params.get("location"))
+ .like(ToolUtil.isNotEmpty(params.get("tel")), Dc::getTel, params.get("tel")));
+
+ List<Dc> dcList = page.getRecords();
+ if(CollectionUtils.isNotEmpty(dcList)){
+ // 处理返回结果
+ this.handleResuleList(dcList);
+ }
+ page.setRecords(dcList);
+ return new PageUtils(page);
+ }
+
+ private void handleResuleList(List<Dc> dcList) {
+ List<SysUserEntity> userEntityList = sysUserService.list();
+ Map<Long, SysUserEntity> userIdAndEntityMap = userEntityList.stream().collect(Collectors.toMap(SysUserEntity::getUserId, Function.identity()));
+
+ List<Cabinet> cabinetList = cabinetDao.selectList(null);
+ List<AlertMessageEntity> alertMessageList = alertMessageDao.getAlertsStatColumn();
+ List<AssetAsset> assetList = assetDao.selectList(null);
+
+ for (Dc dc : dcList) {
+ if (ToolUtil.isNotEmpty(dc.getPrincipal())) {
+ dc.setAdminUser(userIdAndEntityMap.get(dc.getPrincipal().longValue()));
+ }
+
+ long cabinetNum = cabinetList.stream().filter(cabinet -> dc.getId().equals(cabinet.getDcId())).count();
+ dc.setCabinetNum((int) cabinetNum);
+
+ long alertCount = alertMessageList.stream().filter(alert -> dc.getId().equals(alert.getDcId())).count();
+ dc.setAlertNum((int) alertCount);
+
+ long assetCount = assetList.stream().filter(asset -> dc.getId().equals(asset.getDcId())).count();
+ dc.setAssetNum((int) assetCount);
+ }
+ }
+
+
+ /**
+ * 校验 dc 相关的信息
+ * @param dc
+ */
+ private void validateDcInfo(Dc dc) {
+ // 1. 校验机房负责人是否存在
+ if (dc.getPrincipal() != null) {
+ SysUserEntity principal = sysUserService.getById(dc.getPrincipal());
+ if (principal == null) {
+ throw new NZException(RCode.DC_PRINCIPAL_NOT_EXISTS);
+ }
+ }
+
+ // 2. 校验名称重复
+ List<Dc> list = this.list(new QueryWrapper<Dc>().lambda().eq(Dc::getName, dc.getName()));
+
+ boolean flag = false;
+ // 当只有一个结果并且这个结果是自身时,或没有结果时,说明名称不重复
+ if ((list == null || list.size() == 0) || (list != null && list.size() == 1 && list.get(0).getId().equals(dc.getId()))) {
+ flag = true;
+ }
+
+ if (!flag) {
+ throw new NZException(RCode.DC_NAME_DUPLICATE);
+ }
+
+ // 3.修改行列时校验行列值是否正确
+ if (dc.getId() != null) {
+ Integer y = dc.getY();
+ Integer x = dc.getX();
+
+ // 查询数据库中 机柜已占用机房最大行列作为修改的最小值
+ Map<String, Integer> cabinetMaxXY = cabinetDao.getCabinetMaxXY(dc.getId());
+ if (ToolUtil.isNotEmpty(cabinetMaxXY)) {
+ // 行 不为 null ,校验行
+ Integer maxY = cabinetMaxXY.get("y");
+ if (y != null && maxY != null) {
+ if (y < maxY) {
+ throw new NZException(RCode.DC_Y_ALREADYINUSE);
+ }
+ }
+ // 列 不为 null ,校验列
+ Integer maxX = cabinetMaxXY.get("x");
+ if (x != null && maxX != null) {
+ if (x < maxX) {
+ throw new NZException(RCode.DC_X_ALREADYINUSE);
+ }
+ }
+ }
+ }
+
+ // 4. 校验 State 是否合法
+ String state = dc.getState();
+ if (!StrUtil.equals(Constant.SWITCH_OPEN.toUpperCase(), state) && !StrUtil.equals(Constant.SWITCH_CLOSE.toUpperCase(), state)) {
+ throw new NZException(RCode.DC_STATE_ERROR);
+ }
+
+ // 5. 经纬度校验
+ Double longitude = dc.getLongitude();
+ if (longitude != null) {
+ if (longitude > 180 || longitude < -180) {
+ throw new NZException(RCode.DC_LONGITUDE_ERROR);
+ }
+ }
+
+ Double latitude = dc.getLatitude();
+ if (latitude != null) {
+ if (latitude > 90 || latitude < -90) {
+ throw new NZException(RCode.DC_LATITUDE_ERROR);
+ }
+ }
+ }
+
+ @Override
+ public Integer saveDc(Dc dc) {
+ // 校验 dc 相关信息
+ this.validateDcInfo(dc);
+
+ // 设置属性默认值
+ if (dc.getY() == null) {
+ dc.setY(1);
+ }
+
+ if (dc.getX() == null) {
+ dc.setX(1);
+ }
+
+ // 保存
+ this.save(dc);
+ return dc.getId();
+ }
+
+ @Override
+ public Integer updateDc(Dc dc) {
+ // 校验 dc 相关信息
+ this.validateDcInfo(dc);
+
+ // 保存
+ this.updateById(dc);
+ return dc.getId();
+ }
+
+ @Override
+ public void delete(Integer... ids) {
+ // 1. 校验是否包含 cabinet
+ List<Cabinet> cabinets = cabinetDao.selectList(null);
+ Set<Integer> cabinetUsedIdcIds = cabinets.stream().map(Cabinet::getDcId).collect(Collectors.toSet());
+
+ List<Integer> idList = Arrays.stream(ids).collect(Collectors.toList());
+ idList.retainAll(cabinetUsedIdcIds);
+ if (CollectionUtils.isNotEmpty(idList)) {
+ List<String> dcNames = this.listByIds(idList).stream().map(Dc::getName).collect(Collectors.toList());
+ throw new NZException("These dc contain cabinets and cannot be deleted, Details: " + dcNames.toString(), RCode.DC_CABINETS_EXISTS.getCode());
+ }
+
+ // 2. 校验是否包含 asset
+ List<AssetAsset> assets = assetDao.selectList(null);
+ Set<Integer> assetUsedIdcIds = assets.stream().map(AssetAsset::getDcId).collect(Collectors.toSet());
+
+ idList = Arrays.stream(ids).collect(Collectors.toList());
+ idList.retainAll(assetUsedIdcIds);
+ if (CollectionUtils.isNotEmpty(idList)) {
+ List<String> dcNames = this.listByIds(idList).stream().map(Dc::getName).collect(Collectors.toList());
+ throw new NZException("These dc contain assets and cannot be deleted, Details: " + dcNames.toString(), RCode.DC_ASSETS_EXISTS.getCode());
+ }
+
+ // 3. 校验是否包含 promeserver
+ List<Promserver> promservers = promserverDao.selectList(null);
+ Set<Integer> promserverUsedIdcIds = promservers.stream().map(Promserver::getDcId).collect(Collectors.toSet());
+
+ idList = Arrays.stream(ids).collect(Collectors.toList());
+ idList.retainAll(promserverUsedIdcIds);
+ if (CollectionUtils.isNotEmpty(idList)) {
+ List<String> dcNames = this.listByIds(idList).stream().map(Dc::getName).collect(Collectors.toList());
+ throw new NZException("These dc contain prometheus servers and cannot be deleted, Details: " + dcNames.toString(), RCode.DC_CABINETS_EXISTS.getCode());
+ }
+
+ // 4. 删除
+ this.removeByIds(Arrays.asList(ids));
+
+ // 5. 删除 alert
+ alertMessageDao.deleteByDCIds(Arrays.asList(ids));
+ }
+}
diff --git a/nz-admin/src/main/java/com/nis/modules/asset/service/impl/IdcServiceImpl.java b/nz-admin/src/main/java/com/nis/modules/asset/service/impl/IdcServiceImpl.java
index bb6e8772..bbf3f800 100644
--- a/nz-admin/src/main/java/com/nis/modules/asset/service/impl/IdcServiceImpl.java
+++ b/nz-admin/src/main/java/com/nis/modules/asset/service/impl/IdcServiceImpl.java
@@ -112,7 +112,7 @@ public class IdcServiceImpl extends ServiceImpl<IdcDao, Idc> implements IdcServi
if (idc.getPrincipal() != null) {
SysUserEntity principal = sysUserService.getById(idc.getPrincipal());
if (principal == null) {
- throw new NZException(RCode.IDC_PRINCIPAL_NOT_EXISTS);
+ throw new NZException(RCode.DC_PRINCIPAL_NOT_EXISTS);
}
}
@@ -126,7 +126,7 @@ public class IdcServiceImpl extends ServiceImpl<IdcDao, Idc> implements IdcServi
}
if (!flag) {
- throw new NZException(RCode.IDC_NAME_DUPLICATE);
+ throw new NZException(RCode.DC_NAME_DUPLICATE);
}
// 3.修改行列时校验行列值是否正确
@@ -141,14 +141,14 @@ public class IdcServiceImpl extends ServiceImpl<IdcDao, Idc> implements IdcServi
Integer maxY = cabinetMaxXY.get("y");
if (y != null && maxY != null) {
if (y < maxY) {
- throw new NZException(RCode.IDC_Y_ALREADYINUSE);
+ throw new NZException(RCode.DC_Y_ALREADYINUSE);
}
}
// 列 不为 null ,校验列
Integer maxX = cabinetMaxXY.get("x");
if (x != null && maxX != null) {
if (x < maxX) {
- throw new NZException(RCode.IDC_X_ALREADYINUSE);
+ throw new NZException(RCode.DC_X_ALREADYINUSE);
}
}
}
@@ -157,24 +157,24 @@ public class IdcServiceImpl extends ServiceImpl<IdcDao, Idc> implements IdcServi
// 4. 校验 State 是否合法
String state = idc.getState();
if (StringUtils.isEmpty(state)) {
- throw new NZException(RCode.IDC_STATE_ISNULL);
+ throw new NZException(RCode.DC_STATE_ISNULL);
}
if(!StrUtil.equals(Constant.SWITCH_OPEN.toUpperCase(),state) && !StrUtil.equals(Constant.SWITCH_CLOSE.toUpperCase(),state)) {
- throw new NZException(RCode.IDC_STATE_ERROR);
+ throw new NZException(RCode.DC_STATE_ERROR);
}
// 5. 经纬度校验
Double longitude = idc.getLongitude();
if (longitude != null) {
if (longitude > 180 || longitude < -180) {
- throw new NZException(RCode.IDC_LONGITUDE_ERROR);
+ throw new NZException(RCode.DC_LONGITUDE_ERROR);
}
}
Double latitude = idc.getLatitude();
if (latitude != null) {
if (latitude > 90 || latitude < -90) {
- throw new NZException(RCode.IDC_LATITUDE_ERROR);
+ throw new NZException(RCode.DC_LATITUDE_ERROR);
}
}
}
@@ -206,13 +206,13 @@ public class IdcServiceImpl extends ServiceImpl<IdcDao, Idc> implements IdcServi
public void delete(Integer... ids) {
// 1. 校验是否包含 cabinet
List<Cabinet> cabinets = cabinetDao.selectList(null);
- Set<Integer> cabinetUsedIdcIds = cabinets.stream().map(Cabinet::getIdcId).collect(Collectors.toSet());
+ Set<Integer> cabinetUsedIdcIds = cabinets.stream().map(Cabinet::getDcId).collect(Collectors.toSet());
List<Integer> idList = Arrays.stream(ids).collect(Collectors.toList());
idList.retainAll(cabinetUsedIdcIds);
if (CollectionUtils.isNotEmpty(idList)) {
List<String> idcNames = this.listByIds(idList).stream().map(Idc::getName).collect(Collectors.toList());
- throw new NZException("These idc contain cabinets and cannot be deleted, idcs info: " + idcNames.toString(), RCode.IDC_CABINETS_EXISTS.getCode());
+ throw new NZException("These idc contain cabinets and cannot be deleted, idcs info: " + idcNames.toString(), RCode.DC_CABINETS_EXISTS.getCode());
}
// 2. 校验是否包含 asset
@@ -223,18 +223,18 @@ public class IdcServiceImpl extends ServiceImpl<IdcDao, Idc> implements IdcServi
idList.retainAll(assetUsedIdcIds);
if (CollectionUtils.isNotEmpty(idList)) {
List<String> idcNames = this.listByIds(idList).stream().map(Idc::getName).collect(Collectors.toList());
- throw new NZException("These idc contain assets and cannot be deleted, idcs info: " + idcNames.toString(), RCode.IDC_ASSETS_EXISTS.getCode());
+ throw new NZException("These idc contain assets and cannot be deleted, idcs info: " + idcNames.toString(), RCode.DC_ASSETS_EXISTS.getCode());
}
// 3. 校验是否包含 promeserver
List<Promserver> promservers = promserverDao.selectList(null);
- Set<Integer> promserverUsedIdcIds = promservers.stream().map(Promserver::getIdcId).collect(Collectors.toSet());
+ Set<Integer> promserverUsedIdcIds = promservers.stream().map(Promserver::getDcId).collect(Collectors.toSet());
idList = Arrays.stream(ids).collect(Collectors.toList());
idList.retainAll(promserverUsedIdcIds);
if (CollectionUtils.isNotEmpty(idList)) {
List<String> idcNames = this.listByIds(idList).stream().map(Idc::getName).collect(Collectors.toList());
- throw new NZException("These idc contain prometheus servers and cannot be deleted, idcs info: " + idcNames.toString(), RCode.IDC_CABINETS_EXISTS.getCode());
+ throw new NZException("These idc contain prometheus servers and cannot be deleted, idcs info: " + idcNames.toString(), RCode.DC_CABINETS_EXISTS.getCode());
}
// 4. 删除
@@ -243,4 +243,4 @@ public class IdcServiceImpl extends ServiceImpl<IdcDao, Idc> implements IdcServi
// 5. 删除 alert
alertMessageDao.deleteByDCIds(Arrays.asList(ids));
}
-} \ No newline at end of file
+}
diff --git a/nz-admin/src/main/java/com/nis/modules/asset/service/impl/IdcTrafficServiceImpl.java b/nz-admin/src/main/java/com/nis/modules/asset/service/impl/IdcTrafficServiceImpl.java
index 4cd98c64..d88c18a5 100644
--- a/nz-admin/src/main/java/com/nis/modules/asset/service/impl/IdcTrafficServiceImpl.java
+++ b/nz-admin/src/main/java/com/nis/modules/asset/service/impl/IdcTrafficServiceImpl.java
@@ -8,9 +8,9 @@ import com.nis.common.exception.NZException;
import com.nis.common.smartvalidate.ValidateUtils;
import com.nis.common.utils.*;
import com.nis.modules.asset.dao.IdcTrafficDao;
-import com.nis.modules.asset.entity.Idc;
+import com.nis.modules.asset.entity.Dc;
import com.nis.modules.asset.entity.IdcTraffic;
-import com.nis.modules.asset.service.IdcService;
+import com.nis.modules.asset.service.DcService;
import com.nis.modules.asset.service.IdcTrafficService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -31,7 +31,7 @@ import java.util.Map;
public class IdcTrafficServiceImpl extends ServiceImpl<IdcTrafficDao, IdcTraffic> implements IdcTrafficService {
@Autowired
- private IdcService idcService;
+ private DcService dcService;
@Autowired
private IdcTrafficDao idcTrafficDao;
@@ -43,7 +43,7 @@ public class IdcTrafficServiceImpl extends ServiceImpl<IdcTrafficDao, IdcTraffic
// 校验 direction 是否在可选值内
String direction = (String) params.get("direction");
if (StringUtils.isNotEmpty(direction) && !Constant.TRAFFIC_DIRECTIONS.contains(direction)) {
- throw new NZException(RCode.IDC_TRAFFIC_DIRECTIONS_INVALIDE);
+ throw new NZException(RCode.DC_TRAFFIC_DIRECTIONS_INVALIDE);
}
List<IdcTraffic> traffics = idcTrafficDao.queryTrafficSetting(page, params);
@@ -61,12 +61,12 @@ public class IdcTrafficServiceImpl extends ServiceImpl<IdcTrafficDao, IdcTraffic
@Override
public void validateTrafficInfo(Integer idcId, List<IdcTraffic> setting) {
- ValidateUtils.is(idcId).notNull(RCode.IDC_IDCID_ISNULL)
- .and(setting).notNull(RCode.IDC_TRAFFIC_SETTING_ISNULL);
+ ValidateUtils.is(idcId).notNull(RCode.DC_ID_ISNULL)
+ .and(setting).notNull(RCode.DC_TRAFFIC_SETTING_ISNULL);
- Idc idc = idcService.getById(idcId);
- if (ToolUtil.isEmpty(idc)) {
- throw new NZException(RCode.IDC_NOT_EXISTS);
+ Dc dc = dcService.getById(idcId);
+ if (ToolUtil.isEmpty(dc)) {
+ throw new NZException(RCode.DC_NOT_EXISTS);
}
String host, direction;
@@ -77,20 +77,20 @@ public class IdcTrafficServiceImpl extends ServiceImpl<IdcTrafficDao, IdcTraffic
version = traffic.getVersion();
direction = traffic.getDirection();
- ValidateUtils.is(host).notNull(RCode.IDC_TRAFFIC_HOST_ISNULL)
- .and(port).notNull(RCode.IDC_TRAFFIC_PORT_ISNULL)
- .and(version).notNull(RCode.IDC_TRAFFIC_VERSION_ISNULL)
- .and(direction).notNull(RCode.IDC_TRAFFIC_DIRECTIONS_ISNULL)
- .and(traffic.getIfindex()).notNull(RCode.IDC_TRAFFIC_IFINDEX_ISNULL);
+ ValidateUtils.is(host).notNull(RCode.DC_TRAFFIC_HOST_ISNULL)
+ .and(port).notNull(RCode.DC_TRAFFIC_PORT_ISNULL)
+ .and(version).notNull(RCode.DC_TRAFFIC_VERSION_ISNULL)
+ .and(direction).notNull(RCode.DC_TRAFFIC_DIRECTIONS_ISNULL)
+ .and(traffic.getIfindex()).notNull(RCode.DC_TRAFFIC_IFINDEX_ISNULL);
// host
if (!CommonUtils.checkUrl(host)) {
- throw new NZException(RCode.IDC_TRAFFIC_HOST_FORMAT);
+ throw new NZException(RCode.DC_TRAFFIC_HOST_FORMAT);
}
// PORT
if (!CommonUtils.checkPort(port.toString())) {
- throw new NZException(RCode.IDC_TRAFFIC_PORT_INVALIDE);
+ throw new NZException(RCode.DC_TRAFFIC_PORT_INVALIDE);
}
// version
@@ -106,7 +106,7 @@ public class IdcTrafficServiceImpl extends ServiceImpl<IdcTrafficDao, IdcTraffic
String[] split = direction.split(",");
Arrays.asList(split).stream().forEach(s -> {
if (!Constant.TRAFFIC_DIRECTIONS.contains(s)) {
- throw new NZException(RCode.IDC_TRAFFIC_DIRECTIONS_INVALIDE);
+ throw new NZException(RCode.DC_TRAFFIC_DIRECTIONS_INVALIDE);
}
});
@@ -124,7 +124,7 @@ public class IdcTrafficServiceImpl extends ServiceImpl<IdcTrafficDao, IdcTraffic
if (ToolUtil.isNotEmpty(tags)) {
tags.keySet().stream().forEach(key -> {
if (!Constant.PROMETHEUS_LABELSKEY_PATTERN.matcher(key.toString()).matches()) {
- throw new NZException("tags's key " + key + " format is incorrect", RCode.IDC_TRAFFIC_TAGSKEY_FORMAT.getCode());
+ throw new NZException("tags's key " + key + " format is incorrect", RCode.DC_TRAFFIC_TAGSKEY_FORMAT.getCode());
}
});
}
@@ -151,4 +151,4 @@ public class IdcTrafficServiceImpl extends ServiceImpl<IdcTrafficDao, IdcTraffic
this.saveBatch(setting);
}
-} \ No newline at end of file
+}
diff --git a/nz-admin/src/main/java/com/nis/modules/metric/controller/MetricsController.java b/nz-admin/src/main/java/com/nis/modules/metric/controller/MetricsController.java
index 2bcd8547..7f380090 100644
--- a/nz-admin/src/main/java/com/nis/modules/metric/controller/MetricsController.java
+++ b/nz-admin/src/main/java/com/nis/modules/metric/controller/MetricsController.java
@@ -8,9 +8,9 @@ import com.nis.common.utils.TypeEnum;
import com.nis.modules.alert.entity.AlertMessageEntity;
import com.nis.modules.alert.service.AlertMessageService;
import com.nis.modules.asset.entity.Asset;
-import com.nis.modules.asset.entity.Idc;
+import com.nis.modules.asset.entity.Dc;
import com.nis.modules.asset.service.AssetService;
-import com.nis.modules.asset.service.IdcService;
+import com.nis.modules.asset.service.DcService;
import com.nis.modules.endpoint.service.EndpointService;
import com.nis.modules.metric.dto.NezhaMetrics;
import com.nis.modules.module.service.ModuleService;
@@ -51,7 +51,7 @@ public class MetricsController extends AbstractController {
private EndpointService endpointService;
@Autowired
- private IdcService idcService;
+ private DcService dcService;
@Autowired
private AssetService assetService;
@@ -89,7 +89,7 @@ public class MetricsController extends AbstractController {
// 3. endpoint总数
resultMap.put("endpoint", endpointService.count());
// 4. dc总数
- resultMap.put("dc", idcService.count());
+ resultMap.put("dc", dcService.count());
// 5. asset 在库总数
resultMap.put("asset", assetService.count(new QueryWrapper<Asset>().eq("state", 1)));
// 6. pending alert message 数量
@@ -111,12 +111,12 @@ public class MetricsController extends AbstractController {
perDc.put(name, "available");
}
- List<Idc> idcList = idcService.list();
+ List<Dc> idcList = dcService.list();
if (CollectionUtils.isNotEmpty(idcNames) && idcNames.size() < idcList.size()) {
- for (Idc idc : idcList) {
+ for (Dc dc : idcList) {
// 如果没有包含补充默认值 证明该dc下没有符合条件的per prometheus
- if (!idcNames.contains(idc.getName())) {
- perDc.put(idc.getName(), "unavailable");
+ if (!idcNames.contains(dc.getName())) {
+ perDc.put(dc.getName(), "unavailable");
}
}
}
@@ -125,4 +125,4 @@ public class MetricsController extends AbstractController {
resultMap.put("systemAlert", systemAlert);
return R.ok(resultMap);
}
-} \ No newline at end of file
+}
diff --git a/nz-admin/src/main/java/com/nis/modules/metric/dto/NezhaMetrics.java b/nz-admin/src/main/java/com/nis/modules/metric/dto/NezhaMetrics.java
index 5f7701d8..60b0c03c 100644
--- a/nz-admin/src/main/java/com/nis/modules/metric/dto/NezhaMetrics.java
+++ b/nz-admin/src/main/java/com/nis/modules/metric/dto/NezhaMetrics.java
@@ -1,277 +1,277 @@
-package com.nis.modules.metric.dto;
-
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.nis.common.utils.Constant;
-import com.nis.common.utils.ToolUtil;
-import com.nis.modules.alert.dao.AlertRuleDao;
-import com.nis.modules.alert.entity.AlertRuleEntity;
-import com.nis.modules.alert.service.AlertMessageService;
-import com.nis.modules.asset.dao.AssetPingDao;
-import com.nis.modules.asset.dao.IdcDao;
-import com.nis.modules.asset.entity.Asset;
-import com.nis.modules.asset.entity.AssetPing;
-import com.nis.modules.asset.entity.Idc;
-import com.nis.modules.asset.service.AssetService;
-import com.nis.modules.endpoint.service.EndpointService;
-import com.nis.modules.promserver.entity.Promserver;
-import com.nis.modules.promserver.service.PromserverService;
-import com.nis.modules.sys.dao.SysConfigDao;
-import com.nis.modules.sys.entity.SysConfigEntity;
-import io.micrometer.core.instrument.Gauge;
-import io.micrometer.core.instrument.Meter;
-import io.micrometer.core.instrument.MeterRegistry;
-import io.micrometer.core.instrument.binder.MeterBinder;
-import io.micrometer.core.instrument.search.Search;
-import org.apache.commons.collections.CollectionUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-@Component
-public class NezhaMetrics implements MeterBinder {
- public Map<String, Double> map;
- @Autowired
- private AlertMessageService alertMessageService;
- @Autowired
- private AssetService assetService;
- @Autowired
- private EndpointService endpointService;
-
- @Autowired
- private AlertRuleDao alertRuleDao;
-
- @Autowired
- private IdcDao idcDao;
-
- @Autowired
- private AssetPingDao assetPingDao;
-
- @Autowired
- private SysConfigDao sysConfigDao;
-
- @Autowired
- private PromserverService promserverService;
-
- NezhaMetrics() {
- map = new HashMap<>();
- }
-
- @Override
- public void bindTo(MeterRegistry meterRegistry) {
- if (map == null) {
- map = new HashMap<>();
- }
-
- /**
- * alert_nums指标
- */
- List<MetricsDto> alertNums = alertMessageService.queryAlertMessageStatisticsInfoByRule();
- Map<Integer, Double> ruleIdAndMessageTotalMap = alertNums.stream().collect(Collectors.toMap(MetricsDto::getId, MetricsDto::getTotal));
-
- // 先清空指标 再更新数据防止旧数据存在
- this.cleanMeterInRegistryByName(meterRegistry, "nz_alert_nums");
- List<AlertRuleEntity> rules = alertRuleDao.selectList(null);
-
- if (CollectionUtils.isNotEmpty(rules)) {
- AlertRuleEntity ruleEntity;
- Double total;
- for (int i = 0; i < rules.size(); i++) {
- ruleEntity = rules.get(i);
- total = ruleIdAndMessageTotalMap.get(ruleEntity.getId());
- map.put("alertNums" + i, ToolUtil.isEmpty(total) ? 0 : total);
-
- String key = "alertNums" + i;
- Gauge.builder("nz_alert_nums", map, x -> x.get(key))
- .tags("id", ruleEntity.getId() + "", "name", ruleEntity.getAlertName(), "severity", ruleEntity.getSeverity())
- .description("Alert message statistics info")
- .register(meterRegistry);
- }
- }
-
- /**
- * asset_nums指标
- */
- this.cleanMeterInRegistryByName(meterRegistry, "nz_asset_nums");
- List<MetricsDto> assetNums = assetService.queryAssetStatisticsByModel();
- if (ToolUtil.isNotEmpty(assetNums)) {
- MetricsDto metricsDto;
- for (int i = 0; i < assetNums.size(); i++) {
- metricsDto = assetNums.get(i);
- // 这里将统计值扔进map操作是避免弱引用 统计结果出现NaN
- map.put("assetNums" + i, metricsDto.getTotal());
- String key = "assetNums" + i;
- Gauge.builder("nz_asset_nums", map, x -> x.get(key))
- .tags("model", metricsDto.getName(), "type", metricsDto.getAssetType(), "vendor", metricsDto.getVendor(), "state", metricsDto.getState())
- .description("Asset statistics info")
- .register(meterRegistry);
- }
- } else {
- map.put("assetNums", 0.0);
- String key = "assetNums";
- Gauge.builder("nz_asset_nums", map, x -> x.get(key))
- .tags("model", "null", "type", "null", "vendor", "null")
- .description("Asset statistics info")
- .register(meterRegistry);
- }
-
-
- /**
- * endpoint_nums指标
- */
- this.cleanMeterInRegistryByName(meterRegistry, "nz_endpoint_nums");
- List<MetricsDto> endpointNums = endpointService.queryEndpointStatisticsInfoByModule();
- if (ToolUtil.isNotEmpty(endpointNums)) {
- for (int i = 0; i < endpointNums.size(); i++) {
- // 这里将统计值扔进map操作是避免弱引用 统计结果出现NaN
- map.put("endpointNums" + i, endpointNums.get(i).getTotal());
- String key = "endpointNums" + i;
- Gauge.builder("nz_endpoint_nums", map, x -> x.get(key))
- .tags("module", endpointNums.get(i).getName())
- .description("Endpoint statistics info")
- .register(meterRegistry);
- }
- } else {
- map.put("endpointNums", 0.0);
- String key = "endpointNums";
- Gauge.builder("nz_endpoint_nums", map, x -> x.get(key))
- .tags("module", "null")
- .description("Endpoint statistics info")
- .register(meterRegistry);
- }
-
-
- /**
- * asset ping 相关指标
- */
- this.cleanMeterInRegistryByName(meterRegistry, "nz_asset_ping");
- this.cleanMeterInRegistryByName(meterRegistry, "nz_asset_offline");
- this.cleanMeterInRegistryByName(meterRegistry, "nz_asset_online_nums");
-
- SysConfigEntity pingSwitchConfig = sysConfigDao.selectOne(new QueryWrapper<SysConfigEntity>().lambda().eq(SysConfigEntity::getParamKey, Constant.SYSCONFIG_KEY_ASSET_PING_SWITCH));
- // ping 开关为开启状态统计 nz_asset_ping 指标
- if (pingSwitchConfig != null && Constant.ASSET_PING_OPEN_SWITCH.equals(pingSwitchConfig.getParamValue())) {
- List<AssetPing> assetPings = assetPingDao.selectList(null);
- List<Asset> assetList = assetService.list();
- Map<String, Asset> assetHostAndAssetMap = new HashMap<>();
- for (Asset asset : assetList) {
- assetHostAndAssetMap.put(asset.getHost(), asset);
- }
-
- /**
- * asset_offline指标
- */
- List<AssetPing> offLineAssetPingList = assetPings.stream().filter(assetPing -> assetPing.getStatus().equals(0)).collect(Collectors.toList());
- if (CollectionUtils.isNotEmpty(offLineAssetPingList)) {
- String host;
- for (int i = 0; i < offLineAssetPingList.size(); i++) {
- host = offLineAssetPingList.get(i).getHost();
- map.put("nz_asset_offline" + i, 1d);
- String key = "nz_asset_offline" + i;
- Gauge.builder("nz_asset_offline", map, x -> x.get(key))
- .tags("host", host, "state", assetHostAndAssetMap.get(host).getState() + "")
- .description("Asset statistics info")
- .register(meterRegistry);
- }
- } else {
- map.put("assetOffline", 0.0);
- Gauge.builder("nz_asset_offline", map, x -> x.get("assetOffline"))
- .description("Asset offline statistics info")
- .register(meterRegistry);
- }
-
- /**
- * asset_online_nums指标
- */
- List<MetricsDto> assetOnlineNums = assetService.queryAssetStatisticsByModelOnLine();
- if (ToolUtil.isNotEmpty(assetOnlineNums)) {
- MetricsDto metricsDto;
- for (int i = 0; i < assetOnlineNums.size(); i++) {
- metricsDto = assetOnlineNums.get(i);
- map.put("assetOnlineNums" + i, metricsDto.getTotal());
- String key = "assetOnlineNums" + i;
- Gauge.builder("nz_asset_online_nums", map, x -> x.get(key))
- .tags("model", metricsDto.getName(), "type", metricsDto.getAssetType(), "vendor", metricsDto.getVendor())
- .description("Asset online statistics info")
- .register(meterRegistry);
- }
- } else {
- map.put("assetOnlineNums", 0.0);
- String key = "assetOnlineNums";
- Gauge.builder("nz_asset_online_nums", map, x -> x.get(key))
- .tags("model", "null", "type", "null", "vendor", "null")
- .description("Asset online statistics info")
- .register(meterRegistry);
- }
-
- /**
- * nz_asset_ping 指标
- */
- List<AssetPing> onLineAssetPingList = assetPings.stream().filter(assetPing -> assetPing.getStatus().equals(1)).collect(Collectors.toList());
- Map<String, Double> assetHostAndRttMap = onLineAssetPingList.stream().collect(Collectors.toMap(AssetPing::getHost, AssetPing::getRtt));
- if (ToolUtil.isNotEmpty(assetHostAndRttMap)) {
-
- List<Idc> idcList = idcDao.selectList(null);
- Map<Integer, String> idcIdAndNameMap = idcList.stream().collect(Collectors.toMap(Idc::getId, Idc::getName));
- String assetHost;
- Asset asset;
- int i = 0;
- for (Map.Entry<String, Double> entry : assetHostAndRttMap.entrySet()) {
- assetHost = entry.getKey();
- asset = assetHostAndAssetMap.get(assetHost);
- if (ToolUtil.isEmpty(asset)) continue;
- String key = "nz_asset_ping" + i++;
-
- map.put(key, entry.getValue());
- Gauge.builder("nz_asset_ping", map, x -> x.get(key))
- .tags("sn", asset.getSn(), "host", assetHost, "datacenter", idcIdAndNameMap.get(asset.getIdcId()))
- .description("Asset ping statistics info")
- .register(meterRegistry);
- }
- }
- }
-
-
- /**
- * nz_prometheus_status 指标
- */
- this.cleanMeterInRegistryByName(meterRegistry, "nz_prometheus_status");
- List<Promserver> promserverList = promserverService.list();
- if (CollectionUtils.isNotEmpty(promserverList)) {
- List<Idc> idcList = idcDao.selectList(null);
- Map<Integer, String> idcIdAndNameMap = idcList.stream().collect(Collectors.toMap(Idc::getId, Idc::getName));
-
- Promserver promserver;
- for (int i = 0; i < promserverList.size(); i++) {
- promserver = promserverList.get(i);
- String key = "nz_prometheus_status" + i;
- map.put(key, promserver.getStatus().doubleValue());
- Gauge.builder("nz_prometheus_status", map, x -> x.get(key))
- .tags("datacenter", idcIdAndNameMap.get(promserver.getIdcId()), "type", Constant.PromserverType.getPromserverType(promserver.getType()).getName(), "host", promserver.getHost(), "port", promserver.getPort() + "")
- .description("Prometheus status")
- .register(meterRegistry);
- }
- }
- }
-
- /**
- * 按照指标名称清除之前数据
- *
- * @param registry
- * @param meterName
- */
- private void cleanMeterInRegistryByName(MeterRegistry registry, String meterName) {
- while (true) {
- Search find = registry.find(meterName);
- Meter meter = find.meter();
- if (ToolUtil.isNotEmpty(meter)) {
- registry.remove(meter);
- } else {
- break;
- }
- }
- }
-}
+package com.nis.modules.metric.dto;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.nis.common.utils.Constant;
+import com.nis.common.utils.ToolUtil;
+import com.nis.modules.alert.dao.AlertRuleDao;
+import com.nis.modules.alert.entity.AlertRuleEntity;
+import com.nis.modules.alert.service.AlertMessageService;
+import com.nis.modules.asset.dao.AssetPingDao;
+import com.nis.modules.asset.dao.DcDao;
+import com.nis.modules.asset.entity.Asset;
+import com.nis.modules.asset.entity.AssetPing;
+import com.nis.modules.asset.entity.Dc;
+import com.nis.modules.asset.service.AssetService;
+import com.nis.modules.endpoint.service.EndpointService;
+import com.nis.modules.promserver.entity.Promserver;
+import com.nis.modules.promserver.service.PromserverService;
+import com.nis.modules.sys.dao.SysConfigDao;
+import com.nis.modules.sys.entity.SysConfigEntity;
+import io.micrometer.core.instrument.Gauge;
+import io.micrometer.core.instrument.Meter;
+import io.micrometer.core.instrument.MeterRegistry;
+import io.micrometer.core.instrument.binder.MeterBinder;
+import io.micrometer.core.instrument.search.Search;
+import org.apache.commons.collections.CollectionUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+@Component
+public class NezhaMetrics implements MeterBinder {
+ public Map<String, Double> map;
+ @Autowired
+ private AlertMessageService alertMessageService;
+ @Autowired
+ private AssetService assetService;
+ @Autowired
+ private EndpointService endpointService;
+
+ @Autowired
+ private AlertRuleDao alertRuleDao;
+
+ @Autowired
+ private DcDao dcDao;
+
+ @Autowired
+ private AssetPingDao assetPingDao;
+
+ @Autowired
+ private SysConfigDao sysConfigDao;
+
+ @Autowired
+ private PromserverService promserverService;
+
+ NezhaMetrics() {
+ map = new HashMap<>();
+ }
+
+ @Override
+ public void bindTo(MeterRegistry meterRegistry) {
+ if (map == null) {
+ map = new HashMap<>();
+ }
+
+ /**
+ * alert_nums指标
+ */
+ List<MetricsDto> alertNums = alertMessageService.queryAlertMessageStatisticsInfoByRule();
+ Map<Integer, Double> ruleIdAndMessageTotalMap = alertNums.stream().collect(Collectors.toMap(MetricsDto::getId, MetricsDto::getTotal));
+
+ // 先清空指标 再更新数据防止旧数据存在
+ this.cleanMeterInRegistryByName(meterRegistry, "nz_alert_nums");
+ List<AlertRuleEntity> rules = alertRuleDao.selectList(null);
+
+ if (CollectionUtils.isNotEmpty(rules)) {
+ AlertRuleEntity ruleEntity;
+ Double total;
+ for (int i = 0; i < rules.size(); i++) {
+ ruleEntity = rules.get(i);
+ total = ruleIdAndMessageTotalMap.get(ruleEntity.getId());
+ map.put("alertNums" + i, ToolUtil.isEmpty(total) ? 0 : total);
+
+ String key = "alertNums" + i;
+ Gauge.builder("nz_alert_nums", map, x -> x.get(key))
+ .tags("id", ruleEntity.getId() + "", "name", ruleEntity.getAlertName(), "severity", ruleEntity.getSeverity())
+ .description("Alert message statistics info")
+ .register(meterRegistry);
+ }
+ }
+
+ /**
+ * asset_nums指标
+ */
+ this.cleanMeterInRegistryByName(meterRegistry, "nz_asset_nums");
+ List<MetricsDto> assetNums = assetService.queryAssetStatisticsByModel();
+ if (ToolUtil.isNotEmpty(assetNums)) {
+ MetricsDto metricsDto;
+ for (int i = 0; i < assetNums.size(); i++) {
+ metricsDto = assetNums.get(i);
+ // 这里将统计值扔进map操作是避免弱引用 统计结果出现NaN
+ map.put("assetNums" + i, metricsDto.getTotal());
+ String key = "assetNums" + i;
+ Gauge.builder("nz_asset_nums", map, x -> x.get(key))
+ .tags("model", metricsDto.getName(), "type", metricsDto.getAssetType(), "vendor", metricsDto.getVendor(), "state", metricsDto.getState())
+ .description("Asset statistics info")
+ .register(meterRegistry);
+ }
+ } else {
+ map.put("assetNums", 0.0);
+ String key = "assetNums";
+ Gauge.builder("nz_asset_nums", map, x -> x.get(key))
+ .tags("model", "null", "type", "null", "vendor", "null")
+ .description("Asset statistics info")
+ .register(meterRegistry);
+ }
+
+
+ /**
+ * endpoint_nums指标
+ */
+ this.cleanMeterInRegistryByName(meterRegistry, "nz_endpoint_nums");
+ List<MetricsDto> endpointNums = endpointService.queryEndpointStatisticsInfoByModule();
+ if (ToolUtil.isNotEmpty(endpointNums)) {
+ for (int i = 0; i < endpointNums.size(); i++) {
+ // 这里将统计值扔进map操作是避免弱引用 统计结果出现NaN
+ map.put("endpointNums" + i, endpointNums.get(i).getTotal());
+ String key = "endpointNums" + i;
+ Gauge.builder("nz_endpoint_nums", map, x -> x.get(key))
+ .tags("module", endpointNums.get(i).getName())
+ .description("Endpoint statistics info")
+ .register(meterRegistry);
+ }
+ } else {
+ map.put("endpointNums", 0.0);
+ String key = "endpointNums";
+ Gauge.builder("nz_endpoint_nums", map, x -> x.get(key))
+ .tags("module", "null")
+ .description("Endpoint statistics info")
+ .register(meterRegistry);
+ }
+
+
+ /**
+ * asset ping 相关指标
+ */
+ this.cleanMeterInRegistryByName(meterRegistry, "nz_asset_ping");
+ this.cleanMeterInRegistryByName(meterRegistry, "nz_asset_offline");
+ this.cleanMeterInRegistryByName(meterRegistry, "nz_asset_online_nums");
+
+ SysConfigEntity pingSwitchConfig = sysConfigDao.selectOne(new QueryWrapper<SysConfigEntity>().lambda().eq(SysConfigEntity::getParamKey, Constant.SYSCONFIG_KEY_ASSET_PING_SWITCH));
+ // ping 开关为开启状态统计 nz_asset_ping 指标
+ if (pingSwitchConfig != null && Constant.ASSET_PING_OPEN_SWITCH.equals(pingSwitchConfig.getParamValue())) {
+ List<AssetPing> assetPings = assetPingDao.selectList(null);
+ List<Asset> assetList = assetService.list();
+ Map<String, Asset> assetHostAndAssetMap = new HashMap<>();
+ for (Asset asset : assetList) {
+ assetHostAndAssetMap.put(asset.getHost(), asset);
+ }
+
+ /**
+ * asset_offline指标
+ */
+ List<AssetPing> offLineAssetPingList = assetPings.stream().filter(assetPing -> assetPing.getStatus().equals(0)).collect(Collectors.toList());
+ if (CollectionUtils.isNotEmpty(offLineAssetPingList)) {
+ String host;
+ for (int i = 0; i < offLineAssetPingList.size(); i++) {
+ host = offLineAssetPingList.get(i).getHost();
+ map.put("nz_asset_offline" + i, 1d);
+ String key = "nz_asset_offline" + i;
+ Gauge.builder("nz_asset_offline", map, x -> x.get(key))
+ .tags("host", host, "state", assetHostAndAssetMap.get(host).getState() + "")
+ .description("Asset statistics info")
+ .register(meterRegistry);
+ }
+ } else {
+ map.put("assetOffline", 0.0);
+ Gauge.builder("nz_asset_offline", map, x -> x.get("assetOffline"))
+ .description("Asset offline statistics info")
+ .register(meterRegistry);
+ }
+
+ /**
+ * asset_online_nums指标
+ */
+ List<MetricsDto> assetOnlineNums = assetService.queryAssetStatisticsByModelOnLine();
+ if (ToolUtil.isNotEmpty(assetOnlineNums)) {
+ MetricsDto metricsDto;
+ for (int i = 0; i < assetOnlineNums.size(); i++) {
+ metricsDto = assetOnlineNums.get(i);
+ map.put("assetOnlineNums" + i, metricsDto.getTotal());
+ String key = "assetOnlineNums" + i;
+ Gauge.builder("nz_asset_online_nums", map, x -> x.get(key))
+ .tags("model", metricsDto.getName(), "type", metricsDto.getAssetType(), "vendor", metricsDto.getVendor())
+ .description("Asset online statistics info")
+ .register(meterRegistry);
+ }
+ } else {
+ map.put("assetOnlineNums", 0.0);
+ String key = "assetOnlineNums";
+ Gauge.builder("nz_asset_online_nums", map, x -> x.get(key))
+ .tags("model", "null", "type", "null", "vendor", "null")
+ .description("Asset online statistics info")
+ .register(meterRegistry);
+ }
+
+ /**
+ * nz_asset_ping 指标
+ */
+ List<AssetPing> onLineAssetPingList = assetPings.stream().filter(assetPing -> assetPing.getStatus().equals(1)).collect(Collectors.toList());
+ Map<String, Double> assetHostAndRttMap = onLineAssetPingList.stream().collect(Collectors.toMap(AssetPing::getHost, AssetPing::getRtt));
+ if (ToolUtil.isNotEmpty(assetHostAndRttMap)) {
+
+ List<Dc> dcList = dcDao.selectList(null);
+ Map<Integer, String> dcIdAndNameMap = dcList.stream().collect(Collectors.toMap(Dc::getId, Dc::getName));
+ String assetHost;
+ Asset asset;
+ int i = 0;
+ for (Map.Entry<String, Double> entry : assetHostAndRttMap.entrySet()) {
+ assetHost = entry.getKey();
+ asset = assetHostAndAssetMap.get(assetHost);
+ if (ToolUtil.isEmpty(asset)) continue;
+ String key = "nz_asset_ping" + i++;
+
+ map.put(key, entry.getValue());
+ Gauge.builder("nz_asset_ping", map, x -> x.get(key))
+ .tags("sn", asset.getSn(), "host", assetHost, "datacenter", dcIdAndNameMap.get(asset.getIdcId()) == null ? "" : dcIdAndNameMap.get(asset.getIdcId()))
+ .description("Asset ping statistics info")
+ .register(meterRegistry);
+ }
+ }
+ }
+
+
+ /**
+ * nz_prometheus_status 指标
+ */
+ this.cleanMeterInRegistryByName(meterRegistry, "nz_prometheus_status");
+ List<Promserver> promserverList = promserverService.list();
+ if (CollectionUtils.isNotEmpty(promserverList)) {
+ List<Dc> dcList = dcDao.selectList(null);
+ Map<Integer, String> idcIdAndNameMap = dcList.stream().collect(Collectors.toMap(Dc::getId, Dc::getName));
+
+ Promserver promserver;
+ for (int i = 0; i < promserverList.size(); i++) {
+ promserver = promserverList.get(i);
+ String key = "nz_prometheus_status" + i;
+ map.put(key, promserver.getStatus().doubleValue());
+ Gauge.builder("nz_prometheus_status", map, x -> x.get(key))
+ .tags("datacenter", idcIdAndNameMap.get(promserver.getDcId()) == null ? "" : idcIdAndNameMap.get(promserver.getDcId()), "type", Constant.PromserverType.getPromserverType(promserver.getType()).getName(), "host", promserver.getHost(), "port", promserver.getPort() + "")
+ .description("Prometheus status")
+ .register(meterRegistry);
+ }
+ }
+ }
+
+ /**
+ * 按照指标名称清除之前数据
+ *
+ * @param registry
+ * @param meterName
+ */
+ private void cleanMeterInRegistryByName(MeterRegistry registry, String meterName) {
+ while (true) {
+ Search find = registry.find(meterName);
+ Meter meter = find.meter();
+ if (ToolUtil.isNotEmpty(meter)) {
+ registry.remove(meter);
+ } else {
+ break;
+ }
+ }
+ }
+}
diff --git a/nz-admin/src/main/java/com/nis/modules/overview/service/impl/OverviewServiceImpl.java b/nz-admin/src/main/java/com/nis/modules/overview/service/impl/OverviewServiceImpl.java
index 2da2f974..55a0034a 100644
--- a/nz-admin/src/main/java/com/nis/modules/overview/service/impl/OverviewServiceImpl.java
+++ b/nz-admin/src/main/java/com/nis/modules/overview/service/impl/OverviewServiceImpl.java
@@ -77,7 +77,7 @@ public class OverviewServiceImpl implements OverviewService {
private AssetPingDao assetPingDao;
@Autowired
- private IdcDao idcDao;
+ private DcDao dcDao;
@Autowired
private ModelDao modelDao;
@@ -140,7 +140,7 @@ public class OverviewServiceImpl implements OverviewService {
assetPingList = assetPingDao.selectList(null);
}
- // 过滤掉没有 asset 的 idc
+ // 过滤掉没有 asset 的 dc
List<AssetStat> assetStatByDc = this.getAssetStatByDc(assetList, assetPingList, alertList);
assetStatByDc = assetStatByDc.stream().filter(assetStat -> ToolUtil.isNotEmpty(assetStat.getTotal()) && assetStat.getTotal() > 0).collect(Collectors.toList());
@@ -244,24 +244,24 @@ public class OverviewServiceImpl implements OverviewService {
@Override
public List<AssetStat> getAssetStatByDc(List<Asset> assetList, List<AssetPing> assetPingList, List<AlertMessageEntity> alertList) {
- List<Idc> idcList = idcDao.selectList(null);
- Map<Integer, List<Asset>> idcIdAndAssetListMap = assetList.stream().collect(Collectors.groupingBy(Asset::getIdcId));
+ List<Dc> dcList = dcDao.selectList(null);
+ Map<Integer, List<Asset>> dcIdAndAssetListMap = assetList.stream().collect(Collectors.groupingBy(Asset::getIdcId));
List<AlertMessageEntity> alertListByDc = alertList.stream().filter(alert -> ToolUtil.isNotEmpty(alert.getDcId())).collect(Collectors.toList());
List<AssetStat> dcStats = new ArrayList<>();
AssetStat assetStat;
List<Asset> tempAssets;
List<AssetPing> tempAssetPing;
List<AlertMessageEntity> tempAlertList;
- for (Idc idc : idcList) {
- tempAssets = idcIdAndAssetListMap.get(idc.getId());
+ for (Dc dc : dcList) {
+ tempAssets = dcIdAndAssetListMap.get(dc.getId());
tempAssets = CollectionUtils.isEmpty(tempAssets) ? Collections.emptyList() : tempAssets;
- tempAlertList = alertListByDc.stream().filter(alert -> idc.getId().equals(alert.getDcId())).collect(Collectors.toList());
+ tempAlertList = alertListByDc.stream().filter(alert -> dc.getId().equals(alert.getDcId())).collect(Collectors.toList());
tempAssetPing = this.getAssetPingByAsset(tempAssets, assetPingList);
assetStat = this.getAssetStat(tempAssets, tempAssetPing, tempAlertList);
- assetStat.setId(idc.getId());
- assetStat.setName(idc.getName());
+ assetStat.setId(dc.getId());
+ assetStat.setName(dc.getName());
dcStats.add(assetStat);
}
@@ -355,7 +355,7 @@ public class OverviewServiceImpl implements OverviewService {
List<EndpointStat> endpointInfoByDc = overviewDao.getEndpointInfoByDc();
// 补充 endpointTotal endpointUp endpointDown 信息
- Map<String, List<Integer>> idcNameWithEndpointIdsMap = this.getDcNameWithEndpointInfo();
+ Map<String, List<Integer>> dcNameWithEndpointIdsMap = this.getDcNameWithEndpointInfo();
// 根据 asset 停用状态 获取对应 endpoint ids
List<Integer> suspendedEndpointList = endpointDao.getSuspendedEndpointIdsByAssetState();
@@ -368,7 +368,7 @@ public class OverviewServiceImpl implements OverviewService {
Set<Integer> endpointUpIds = this.getUpStatusEndpointIds(suspendedEndpointList);
for (EndpointStat stat : endpointInfoByDc) {
- List<Integer> list = idcNameWithEndpointIdsMap.get(stat.getName());
+ List<Integer> list = dcNameWithEndpointIdsMap.get(stat.getName());
int endpointUp = 0;
int endpointSuspended = 0;
int total = list.size();
@@ -400,21 +400,21 @@ public class OverviewServiceImpl implements OverviewService {
}
private Map<String, List<Integer>> getDcNameWithEndpointInfo() {
- List<Idc> idcList = idcDao.selectList(null);
+ List<Dc> dcList = dcDao.selectList(null);
List<Asset> assetList = assetDao.getAssetsStatColumn();
List<Endpoint> endpointList = endpointService.list();
- Map<Integer, List<Asset>> idcIdAndAssetListMap = assetList.stream().collect(Collectors.groupingBy(Asset::getIdcId));
+ Map<Integer, List<Asset>> dcIdAndAssetListMap = assetList.stream().collect(Collectors.groupingBy(Asset::getIdcId));
Map<Integer, List<Endpoint>> assetIdAndEndpointListMap = endpointList.stream().collect(Collectors.groupingBy(Endpoint::getAssetId));
- Map<String, List<Integer>> idcNameWithEndpointIdsMap = new HashMap<>();
+ Map<String, List<Integer>> dcNameWithEndpointIdsMap = new HashMap<>();
List<Asset> tempAssets;
List<Endpoint> tempEndpoints;
List<Integer> endpointIdsByDc;
- for (Idc idc : idcList) {
- tempAssets = idcIdAndAssetListMap.get(idc.getId());
+ for (Dc dc : dcList) {
+ tempAssets = dcIdAndAssetListMap.get(dc.getId());
if (CollectionUtils.isEmpty(tempAssets)) {
- idcNameWithEndpointIdsMap.put(idc.getName(), Collections.emptyList());
+ dcNameWithEndpointIdsMap.put(dc.getName(), Collections.emptyList());
continue;
}
@@ -426,9 +426,9 @@ public class OverviewServiceImpl implements OverviewService {
endpointIdsByDc.addAll(tempEndpoints.stream().map(Endpoint::getId).collect(Collectors.toList()));
}
- idcNameWithEndpointIdsMap.put(idc.getName(), endpointIdsByDc);
+ dcNameWithEndpointIdsMap.put(dc.getName(), endpointIdsByDc);
}
- return idcNameWithEndpointIdsMap;
+ return dcNameWithEndpointIdsMap;
}
@Override
@@ -840,4 +840,4 @@ public class OverviewServiceImpl implements OverviewService {
}
return endPointIds;
}
-} \ No newline at end of file
+}
diff --git a/nz-admin/src/main/java/com/nis/modules/panel/service/impl/ExpreTmplServiceImpl.java b/nz-admin/src/main/java/com/nis/modules/panel/service/impl/ExpreTmplServiceImpl.java
index d5b73e53..16d2ec9a 100644
--- a/nz-admin/src/main/java/com/nis/modules/panel/service/impl/ExpreTmplServiceImpl.java
+++ b/nz-admin/src/main/java/com/nis/modules/panel/service/impl/ExpreTmplServiceImpl.java
@@ -12,9 +12,9 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nis.common.exception.NZException;
import com.nis.common.utils.*;
import com.nis.modules.asset.entity.Asset;
-import com.nis.modules.asset.entity.Idc;
+import com.nis.modules.asset.entity.Dc;
import com.nis.modules.asset.service.AssetService;
-import com.nis.modules.asset.service.IdcService;
+import com.nis.modules.asset.service.DcService;
import com.nis.modules.endpoint.entity.MonitorEndpoint;
import com.nis.modules.endpoint.service.MonitorEndpointService;
import com.nis.modules.module.entity.MonitorModule;
@@ -61,7 +61,7 @@ public class ExpreTmplServiceImpl extends ServiceImpl<ExpreTmplDao, ExpressionTm
private SysConfigService sysConfigService;
@Autowired
- private IdcService idcService;
+ private DcService dcService;
@Autowired
private AssetService assetService;
@@ -204,7 +204,7 @@ public class ExpreTmplServiceImpl extends ServiceImpl<ExpreTmplDao, ExpressionTm
Integer endpointId = var.startsWith("endpoint.") ? Integer.parseInt(varsVal.get(var).toString()) : null;
Asset asset = ToolUtil.isNotEmpty(assetId) ? assetService.getById(assetId) : null;
- Idc dc = ToolUtil.isNotEmpty(dcId) ? idcService.getById(dcId) : null;
+ Dc dc = ToolUtil.isNotEmpty(dcId) ? dcService.getById(dcId) : null;
MonitorProject project = ToolUtil.isNotEmpty(projectId) ? projectService.getById(projectId) : null;
MonitorModule module = ToolUtil.isNotEmpty(moduleId) ? moduleService.getById(moduleId) : null;
MonitorEndpoint endpoint = ToolUtil.isNotEmpty(endpointId) ? endpointService.getById(endpointId) : null;
diff --git a/nz-admin/src/main/java/com/nis/modules/promserver/controller/PromserverController.java b/nz-admin/src/main/java/com/nis/modules/promserver/controller/PromserverController.java
index e1b36a61..e74ac447 100644
--- a/nz-admin/src/main/java/com/nis/modules/promserver/controller/PromserverController.java
+++ b/nz-admin/src/main/java/com/nis/modules/promserver/controller/PromserverController.java
@@ -15,7 +15,7 @@ import java.util.HashMap;
import java.util.Map;
@RestController
-@RequestMapping("/promServer")
+@RequestMapping("/agent")
public class PromserverController extends AbstractController {
@Autowired
diff --git a/nz-admin/src/main/java/com/nis/modules/promserver/entity/Promserver.java b/nz-admin/src/main/java/com/nis/modules/promserver/entity/Promserver.java
index 3f608f65..c61b94d1 100644
--- a/nz-admin/src/main/java/com/nis/modules/promserver/entity/Promserver.java
+++ b/nz-admin/src/main/java/com/nis/modules/promserver/entity/Promserver.java
@@ -3,7 +3,7 @@ package com.nis.modules.promserver.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
-import com.nis.modules.asset.entity.Idc;
+import com.nis.modules.asset.entity.Dc;
import lombok.Data;
import javax.validation.constraints.NotBlank;
@@ -15,7 +15,7 @@ public class Promserver {
@TableId
private Integer id;
@NotBlank(message="参数名不能为空")
- private Integer idcId;
+ private Integer dcId;
@NotBlank(message="参数名不能为空")
private String host;
@NotBlank(message="参数名不能为空")
@@ -47,5 +47,5 @@ public class Promserver {
private String token;
@TableField(exist = false)
- private Idc dc;
+ private Dc dc;
}
diff --git a/nz-admin/src/main/java/com/nis/modules/promserver/service/impl/PromserverServiceImpl.java b/nz-admin/src/main/java/com/nis/modules/promserver/service/impl/PromserverServiceImpl.java
index 54645cdf..0c01a68f 100644
--- a/nz-admin/src/main/java/com/nis/modules/promserver/service/impl/PromserverServiceImpl.java
+++ b/nz-admin/src/main/java/com/nis/modules/promserver/service/impl/PromserverServiceImpl.java
@@ -7,8 +7,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nis.common.exception.NZException;
import com.nis.common.smartvalidate.ValidateUtils;
import com.nis.common.utils.*;
-import com.nis.modules.asset.entity.Idc;
-import com.nis.modules.asset.service.IdcService;
+import com.nis.modules.asset.entity.Dc;
+import com.nis.modules.asset.service.DcService;
import com.nis.modules.promserver.dao.PromserverDao;
import com.nis.modules.promserver.entity.Promserver;
import com.nis.modules.promserver.service.PromserverService;
@@ -29,27 +29,24 @@ import java.util.stream.Collectors;
public class PromserverServiceImpl extends ServiceImpl<PromserverDao, Promserver> implements PromserverService{
@Autowired
- private IdcService idcService;
+ private DcService dcService;
@Override
public PageUtils queryPage(Map<String, Object> params) {
- String id = (String)params.get("id");
- String idcId = (String)params.get("dcId");
String host = (String)params.get("host");
String type = (String)params.get("type");
String port = (String)params.get("port");
- String status = (String)params.get("status");
String token = (String) params.get("token");
IPage<Promserver> page = this.page(
- new Query<Promserver>().getPage(params),
- new QueryWrapper<Promserver>().lambda()
- .eq(StringUtils.isNotBlank(id),Promserver::getId, id)
- .like(StringUtils.isNotBlank(host),Promserver::getHost, host)
- .eq(StringUtils.isNotBlank(type), Promserver::getType,type)
- .eq(StringUtils.isNotBlank(idcId), Promserver::getIdcId,idcId)
- .eq(StringUtils.isNotBlank(port), Promserver::getPort,port)
- .eq(StringUtils.isNotBlank(status),Promserver::getStatus,status)
- .like(StringUtils.isNotEmpty(token), Promserver::getToken, token)
+ new Query<Promserver>().getPage(params),
+ new QueryWrapper<Promserver>().lambda()
+ .in(ToolUtil.isNotEmpty(params.get("ids")), Promserver::getId, ToolUtil.isNotEmpty(params.get("ids")) ? Arrays.asList(params.get("ids").toString().split(",")) : null)
+ .in(ToolUtil.isNotEmpty(params.get("dcIds")), Promserver::getDcId, ToolUtil.isNotEmpty(params.get("dcIds")) ? Arrays.asList(params.get("dcIds").toString().split(",")) : null)
+ .in(ToolUtil.isNotEmpty(params.get("statuss")), Promserver::getStatus, ToolUtil.isNotEmpty(params.get("statuss")) ? Arrays.asList(params.get("statuss").toString().split(",")) : null)
+ .like(StringUtils.isNotBlank(host), Promserver::getHost, host)
+ .eq(StringUtils.isNotBlank(type), Promserver::getType, type)
+ .eq(StringUtils.isNotBlank(port), Promserver::getPort, port)
+ .like(StringUtils.isNotEmpty(token), Promserver::getToken, token)
);
List<Promserver> promserverList = page.getRecords();
@@ -61,11 +58,11 @@ public class PromserverServiceImpl extends ServiceImpl<PromserverDao, Promserver
}
private List<Promserver> handleResultViewData(List<Promserver> promserverList) {
- List<Idc> idcList = idcService.list();
- Map<Integer, Idc> dcIdAndEntityMap = idcList.stream().collect(Collectors.toMap(Idc::getId, Function.identity()));
+ List<Dc> dcList = dcService.list();
+ Map<Integer, Dc> dcIdAndEntityMap = dcList.stream().collect(Collectors.toMap(Dc::getId, Function.identity()));
for (Promserver pojo : promserverList) {
- pojo.setDc(dcIdAndEntityMap.get(pojo.getIdcId()));
+ pojo.setDc(dcIdAndEntityMap.get(pojo.getDcId()));
}
return promserverList;
}
@@ -82,7 +79,7 @@ public class PromserverServiceImpl extends ServiceImpl<PromserverDao, Promserver
Integer type = promserverEntity.getType();
String host = promserverEntity.getHost();
Integer port = promserverEntity.getPort();
- ValidateUtils.is(promserverEntity.getIdcId()).notNull(RCode.PROMSERVER_IDCID_ISNULL)
+ ValidateUtils.is(promserverEntity.getDcId()).notNull(RCode.PROMSERVER_DCID_ISNULL)
.and(host).notNull(RCode.PROMSERVER_HOST_ISNULL)
.and(type).notNull(RCode.PROMSERVER_TYPE_ISNULL)
.and(port).notNull(RCode.PROMSERVER_PORT_ISNULL)
@@ -100,8 +97,8 @@ public class PromserverServiceImpl extends ServiceImpl<PromserverDao, Promserver
}
// dc 存在校验
- Idc dc = idcService.getById(promserverEntity.getIdcId());
- ValidateUtils.is(dc).notNull(RCode.IDC_NOT_EXISTS);
+ Dc dc = dcService.getById(promserverEntity.getDcId());
+ ValidateUtils.is(dc).notNull(RCode.DC_NOT_EXISTS);
// 校验 type 合法性
Constant.PromserverType[] values = Constant.PromserverType.values();
@@ -118,7 +115,7 @@ public class PromserverServiceImpl extends ServiceImpl<PromserverDao, Promserver
.eq(true, Promserver::getStatus, 1)
.eq(promId!=null, Promserver::getId, promId)
.eq(promId==null&&type!=null, Promserver::getType, type)
- .eq(promId==null&&idcId != null, Promserver::getIdcId, idcId));
+ .eq(promId==null&&idcId != null, Promserver::getDcId, idcId));
// 校验是否有可用 prometheus server
// ValidateUtils.is(list).notNull(RCode.PROMSERVER_HOST_ISNULL);
// Promserver server = list.get(RandomUtils.nextInt(0, list.size()));
@@ -161,7 +158,7 @@ public class PromserverServiceImpl extends ServiceImpl<PromserverDao, Promserver
Promserver promserver = this.getById(id);
ValidateUtils.is(promserver).notNull(RCode.PROMSERVER_NOTEXSITS);
- Idc dc = idcService.getById(promserver.getIdcId());
+ Dc dc = dcService.getById(promserver.getDcId());
promserver.setDc(dc);
return promserver;
}
diff --git a/nz-admin/src/main/java/com/nis/modules/sys/service/impl/SysConfigServiceImpl.java b/nz-admin/src/main/java/com/nis/modules/sys/service/impl/SysConfigServiceImpl.java
index c92f7127..4013ec20 100644
--- a/nz-admin/src/main/java/com/nis/modules/sys/service/impl/SysConfigServiceImpl.java
+++ b/nz-admin/src/main/java/com/nis/modules/sys/service/impl/SysConfigServiceImpl.java
@@ -526,7 +526,7 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigDao, SysConfigEnt
if (CommonUtils.toInt(defaultCabUIntValue) == null) {
throw new NZException(RCode.SYS_CONFIG_DEFAULTCABINETUSIZE_INVALIDE);
}
- ValidateUtils.is(defaultCabUIntValue).min(1, RCode.IDC_CABINETUSIZE_MINIMUM).max(Constant.CURRENT_CABINET_MAXU, RCode.IDC_CABINET_MAXU);
+ ValidateUtils.is(defaultCabUIntValue).min(1, RCode.DC_CABINETUSIZE_MINIMUM).max(Constant.CURRENT_CABINET_MAXU, RCode.DC_CABINET_MAXU);
Integer queryMaxSeriesIntValue = CommonUtils.toInt(queryMaxSeries);
if (queryMaxSeriesIntValue == null) {
diff --git a/nz-admin/src/main/resources/db/V2021.04.06__1.Insert dc table 2. idc_id was renamed to dc_id .sql b/nz-admin/src/main/resources/db/V2021.04.06__1.Insert dc table 2. idc_id was renamed to dc_id .sql
new file mode 100644
index 00000000..ef34210e
--- /dev/null
+++ b/nz-admin/src/main/resources/db/V2021.04.06__1.Insert dc table 2. idc_id was renamed to dc_id .sql
@@ -0,0 +1,35 @@
+/**
+ * 1. insert dc table
+ * 2. cabinet prom_server 表字段 idc_id 更名 为 dc_id
+ */
+SET NAMES utf8mb4;
+SET FOREIGN_KEY_CHECKS = 0;
+
+-- ----------------------------
+-- Table structure for asset_asset
+-- ----------------------------
+DROP TABLE IF EXISTS `dc`;
+CREATE TABLE `dc` (
+ `id` int(10) NOT NULL AUTO_INCREMENT COMMENT '主键自增',
+ `name` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '名称',
+ `location` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '位置',
+ `tel` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '联系电话',
+ `principal` int(10) NULL DEFAULT NULL COMMENT '机房负责人',
+ `seq` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '全局唯一,用于导入撤销',
+ `x` int(10) NULL DEFAULT NULL COMMENT '列',
+ `y` int(10) NULL DEFAULT NULL COMMENT '行',
+ `longitude` double(8, 5) NULL DEFAULT NULL COMMENT '经度 -180,180',
+ `latitude` double(8, 5) NULL DEFAULT NULL COMMENT '纬度 -90,90',
+ `state` varchar(8) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'ON' COMMENT '可选值:ON,OFF 默认:ON',
+ PRIMARY KEY (`id`) USING BTREE
+) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
+
+
+/**
+ * cabinet prom_server 表字段 idc_id 更名 为 dc_id
+ */
+ALTER TABLE `cabinet` CHANGE COLUMN `idc_id` `dc_id` int(11) NOT NULL COMMENT '数据中心id';
+ALTER TABLE `prom_server` CHANGE COLUMN `idc_id` `dc_id` int(11) NOT NULL COMMENT '数据中心id';
+
+
+SET FOREIGN_KEY_CHECKS = 1;
diff --git a/nz-admin/src/main/resources/mapper/alert/AlertSilenceDao.xml b/nz-admin/src/main/resources/mapper/alert/AlertSilenceDao.xml
index f2ccd969..1a7a18a2 100644
--- a/nz-admin/src/main/resources/mapper/alert/AlertSilenceDao.xml
+++ b/nz-admin/src/main/resources/mapper/alert/AlertSilenceDao.xml
@@ -63,7 +63,7 @@
left join project p on asic.link_id=p.id
left join module m on asic.link_id=m.id
left join asset aa on asic.link_id = aa.id
- left join idc i on asic.link_id=i.id
+ left join dc i on asic.link_id=i.id
where 1=1
<if test="params.id != null and params.id !='' ">
and asic.id = #{params.id}
@@ -107,4 +107,4 @@
UPDATE alert_silence_conf
SET state = ( CASE WHEN now() &lt; start_at THEN 1 WHEN ( now() &gt;= start_at AND now() &lt;= end_at ) THEN 2 ELSE 3 END);
</update>
-</mapper> \ No newline at end of file
+</mapper>
diff --git a/nz-admin/src/main/resources/mapper/asset/AssetAccountDao.xml b/nz-admin/src/main/resources/mapper/asset/AssetAccountDao.xml
index efe062c5..006dd37d 100644
--- a/nz-admin/src/main/resources/mapper/asset/AssetAccountDao.xml
+++ b/nz-admin/src/main/resources/mapper/asset/AssetAccountDao.xml
@@ -64,8 +64,8 @@
from asset_account aa left join sys_user su on aa.update_by = su.user_id
where 1=1 and aa.id =#{id}
</select>
-
-
+
+
<select id="selectAssetAccountsByAssetId" resultMap="assetAccount">
select aa.id,
aa.name,
diff --git a/nz-admin/src/main/resources/mapper/asset/AssetAssetDao.xml b/nz-admin/src/main/resources/mapper/asset/AssetAssetDao.xml
index d96594ad..f0bf9a86 100644
--- a/nz-admin/src/main/resources/mapper/asset/AssetAssetDao.xml
+++ b/nz-admin/src/main/resources/mapper/asset/AssetAssetDao.xml
@@ -18,7 +18,7 @@
<result property="createAt" column="create_at"/>
<result property="updateAt" column="update_at"/>
- <association property="dc" columnPrefix="d_" javaType="com.nis.modules.asset.entity.Idc">
+ <association property="dc" columnPrefix="d_" javaType="com.nis.modules.asset.entity.Dc">
<id property="id" column="id"/>
<result property="name" column="name"/>
</association>
@@ -71,8 +71,8 @@
brand.id AS b_id,
brand.NAME AS b_name,
- idc.id AS d_id,
- idc.NAME AS d_name,
+ dc.id AS d_id,
+ dc.NAME AS d_name,
cab.id AS c_id,
cab.NAME AS c_name,
@@ -85,7 +85,7 @@
LEFT JOIN asset_type_conf type ON asset.type_id = type.id
LEFT JOIN asset_brand brand ON asset.brand_id = brand.id
LEFT JOIN asset_model model ON asset.model_id = model.id
- LEFT JOIN idc idc ON asset.dc_id = idc.id
+ LEFT JOIN dc dc ON asset.dc_id = dc.id
LEFT JOIN cabinet cab ON asset.cabinet_id = cab.id
LEFT JOIN asset_ping assp ON asset.manage_ip = assp.host
diff --git a/nz-admin/src/main/resources/mapper/asset/AssetDao.xml b/nz-admin/src/main/resources/mapper/asset/AssetDao.xml
index 5e93194b..1898d207 100644
--- a/nz-admin/src/main/resources/mapper/asset/AssetDao.xml
+++ b/nz-admin/src/main/resources/mapper/asset/AssetDao.xml
@@ -31,7 +31,7 @@
<association property="cabinet" columnPrefix="cab_" javaType="com.nis.modules.asset.entity.Cabinet">
<result property="id" column="id"/>
<result property="name" column="name"/>
- <result property="idcId" column="idcId"/>
+ <result property="dcId" column="dcId"/>
<result property="uSize" column="uSize"/>
<result property="remark" column="remark"/>
</association>
@@ -95,7 +95,7 @@
/*机柜*/
cab.id AS cab_id,
cab.name AS cab_name,
- cab.idc_id AS cab_idcId,
+ cab.dc_id AS cab_dcId,
cab.u_size AS cab_uSize,
cab.remark AS cab_remark,
@@ -371,4 +371,4 @@
FROM
asset
</select>
-</mapper> \ No newline at end of file
+</mapper>
diff --git a/nz-admin/src/main/resources/mapper/asset/CabinetDao.xml b/nz-admin/src/main/resources/mapper/asset/CabinetDao.xml
index 432b6afb..9ded967d 100644
--- a/nz-admin/src/main/resources/mapper/asset/CabinetDao.xml
+++ b/nz-admin/src/main/resources/mapper/asset/CabinetDao.xml
@@ -7,7 +7,7 @@
<result property="id" column="id"/>
<result property="name" column="name"/>
<result property="uSize" column="u_size"/>
- <result property="idcId" column="idc_id"/>
+ <result property="dcId" column="dc_id"/>
<collection property="assetList" ofType="com.nis.modules.asset.entity.Asset" columnPrefix="as_">
<result column="id" property="id"/>
@@ -21,7 +21,7 @@
<result property="id" column="id"/>
<result property="name" column="name"/>
<result property="uSize" column="u_size"/>
- <result property="idcId" column="idc_id"/>
+ <result property="dcId" column="dc_id"/>
<collection property="assets" ofType="com.nis.modules.asset.entity.AssetAsset" columnPrefix="as_">
<result column="id" property="id"/>
@@ -35,7 +35,7 @@
SELECT
cab.id,
cab.name,
- cab.idc_id,
+ cab.dc_id,
cab.u_size,
cab.remark,
cab.x,
@@ -51,8 +51,8 @@
AND cab.name LIKE CONCAT('%', #{params.name}, '%')
</if>
- <if test="params.idcId != null and params.idcId != ''">
- AND cab.idc_id = #{params.idcId}
+ <if test="params.dcId != null and params.dcId != ''">
+ AND cab.dc_id = #{params.dcId}
</if>
<if test="params.uSize != null and params.uSize != ''">
@@ -80,12 +80,12 @@
FROM
cabinet cab
WHERE
- cab.idc_id = #{id}
+ cab.dc_id = #{id}
</select>
<select id="getCabinetWithAssets" resultMap="cabinetWithAssets">
SELECT
- cab.id,cab.name,cab.u_size,cab.idc_id,ass.id AS as_id,ass.cabinet_id AS as_cabinetId,ass.cabinet_start AS as_cabinetStart,ass.cabinet_end AS as_cabinetEnd
+ cab.id,cab.name,cab.u_size,cab.dc_id,ass.id AS as_id,ass.cabinet_id AS as_cabinetId,ass.cabinet_start AS as_cabinetStart,ass.cabinet_end AS as_cabinetEnd
FROM
cabinet cab
LEFT JOIN asset ass ON cab.id = ass.cabinet_id
@@ -93,7 +93,7 @@
<select id="getCabinetWithAssetPositionInfo" resultMap="cabinetWithAssetPosition">
SELECT
- cab.id,cab.name,cab.u_size,cab.idc_id,ass.id AS as_id,ass.cabinet_id AS as_cabinetId,ass.cabinet_start AS as_cabinetStart,ass.cabinet_end AS as_cabinetEnd
+ cab.id,cab.name,cab.u_size,cab.dc_id,ass.id AS as_id,ass.cabinet_id AS as_cabinetId,ass.cabinet_start AS as_cabinetStart,ass.cabinet_end AS as_cabinetEnd
FROM
cabinet cab
LEFT JOIN asset_asset ass ON cab.id = ass.cabinet_id
diff --git a/nz-admin/src/main/resources/mapper/asset/IdcDao.xml b/nz-admin/src/main/resources/mapper/asset/IdcDao.xml
index 598ff3df..9709f0c1 100644
--- a/nz-admin/src/main/resources/mapper/asset/IdcDao.xml
+++ b/nz-admin/src/main/resources/mapper/asset/IdcDao.xml
@@ -21,7 +21,7 @@
select i.*,
count(DISTINCT c.id) cabinetNum
from idc i
- left join cabinet c on i.id=c.idc_id
+ left join cabinet c on i.id=c.dc_id
<where>
<if test="params.id != null and params.id != ''">
@@ -51,4 +51,4 @@
group by i.id
</select>
-</mapper> \ No newline at end of file
+</mapper>
diff --git a/nz-admin/src/main/resources/mapper/endpoint/EndpointDao.xml b/nz-admin/src/main/resources/mapper/endpoint/EndpointDao.xml
index 610c41cd..88bdb2bc 100644
--- a/nz-admin/src/main/resources/mapper/endpoint/EndpointDao.xml
+++ b/nz-admin/src/main/resources/mapper/endpoint/EndpointDao.xml
@@ -163,4 +163,4 @@
WHERE
enabled = 0
</select>
-</mapper> \ No newline at end of file
+</mapper>
diff --git a/nz-admin/src/main/resources/mapper/overview/OverviewDao.xml b/nz-admin/src/main/resources/mapper/overview/OverviewDao.xml
index d5436b27..09a3b6cc 100644
--- a/nz-admin/src/main/resources/mapper/overview/OverviewDao.xml
+++ b/nz-admin/src/main/resources/mapper/overview/OverviewDao.xml
@@ -5,7 +5,7 @@
<select id="getIdcNameByPerPromeServer" resultType="java.lang.String">
SELECT idc.name AS dc FROM idc
- LEFT JOIN prom_server ps ON idc.id = ps.idc_id
+ LEFT JOIN prom_server ps ON idc.id = ps.dc_id
WHERE ps.type = 2 AND ps.status = 1
GROUP BY idc.id
</select>
@@ -19,9 +19,9 @@
COUNT( CASE WHEN ps.STATUS = '0' or ps.STATUS = '-2' THEN 0 END ) AS promDown
FROM
idc idc
- LEFT JOIN prom_server ps ON idc.id = ps.idc_id
+ LEFT JOIN prom_server ps ON idc.id = ps.dc_id
GROUP BY
idc.id
</select>
-</mapper> \ No newline at end of file
+</mapper>
diff --git a/nz-common/src/main/java/com/nis/common/utils/RCode.java b/nz-common/src/main/java/com/nis/common/utils/RCode.java
index 48e5b4da..bbb482cd 100644
--- a/nz-common/src/main/java/com/nis/common/utils/RCode.java
+++ b/nz-common/src/main/java/com/nis/common/utils/RCode.java
@@ -209,7 +209,7 @@ public enum RCode {
ASSET_MAINTENANCEID_ISNULL(311004, "Asset maintenance id can not be empty"),// 资产维修记录ID不能为空
ASSET_NOT_EXIST(316005, "Asset does not exist"), // 资产不存在
ASSET_MAINTENANCE_CONTENT_ISNULL(311006, "Asset maintenance content can not be empty"),// 资产维修记录内容不能为空
- ASSET_IDC_NOTFOUND(316007, "Asset idc not found"), // 数据中心未找到
+ ASSET_DC_NOTFOUND(316007, "Asset dc not found"), // 数据中心未找到
ASSET_CABINET_NOTFOUND(336008, "Asset cabinet not found"), // 机柜未找到
ASSET_HOST_DUPLICATE(312009, "Asset host duplicate"), // 资产主机地址重复
ASSET_SN_DUPLICATE(312010, "Asset serial number duplicate"), // 资产序列号重复
@@ -481,7 +481,7 @@ public enum RCode {
PROMSERVER_ID_ISNULL(521000, "PromServer id can not be empty"),
- PROMSERVER_IDCID_ISNULL(521001, "Idc id can not be empty"),
+ PROMSERVER_DCID_ISNULL(521001, "Dc id can not be empty"),
PROMSERVER_TYPE_ISNULL(521002, "PromServer type can not be empty"),
PROMSERVER_HOST_ISNULL(521003, "PromServer host can not be empty"),
PROMSERVER_PORT_ISNULL(521004, "PromServer port can not be empty"),
@@ -501,49 +501,50 @@ public enum RCode {
PROMSERVER_TOKEN_ISNULL(521018, "PromServer token info can not be empty"),
- IDC_IDCNAME_ISNULL(531000, "Idc name can not be empty"), // 数据中心name不能为空
- IDC_IDCID_ISNULL(531001, "Idc id can not be empty"), // 数据中心id不能为空
- IDC_IDCPHONE_FORMAT(533002, "Idc phone format error , format such as 18201436079"), // 数据中心电话格式错误
- IDC_PRINCIPAL_NOT_EXISTS(536003, "Idc principal does not exist"), // 数据中心负责人不存在
- IDC_NAME_DUPLICATE(532004, "Idc name duplicate"), // 数据中心名称重复
- IDC_CABINETS_EXISTS(533005, "These idc contain cabinets and cannot be deleted"), // 数据中心内含有机柜
- IDC_ASSETS_EXISTS(533006, "These idc contain assets and cannot be deleted"), // 数据中心内含有资产
- IDC_NOT_EXISTS(536007, "Idc does not exist"), // 数据中心不存在
- IDC_NOTHAS_CABINET(536008, "There is no this cabinet in the idc"), // 数据中心中没有该机柜
- IDC_ID_FORMAT(533009, "Id format error , type should be integer"), // ID类型错误
- IDC_CABINETNAME_ISNULL(531010, "Cabinet name can not be empty"), // 机柜名称不能为空
- IDC_CABINETID_ISNULL(531011, "Cabinet id can not be empty"), // 机柜id不能为空
- IDC_CABINETNAME_DUPLICATE(532012, "Cabinet name duplicate"), // 机柜名称重复
- IDC_CABINETUSIZE_MINIMUM(535013, "Cabinet u size is a minimum of 1"),// 机柜U位大小最小为1
- IDC_CABINET_ASSETS_EXISTS(533014, "These cabinets contain assets and cannot be deleted"),// 机柜中有资产
- IDC_CABINET_MAXU(535015, "The maximum U of current cabinet is 47"), // 当前机柜最大U为47
- IDC_Y_MINIMUM(535016,"Idc y is a minimum of 1"), // 数据中心行数最少为1
- IDC_X_MINIMUM(535017,"Idc x is a minimum of 1"), // 数据中心列数最少为1
- IDC_Y_ALREADYINUSE(535018,"Idc y is already in use"), // 数据中心行已经被使用
- IDC_X_ALREADYINUSE(535019,"Idc x is already in use"), // 数据中心列已经被使用
+ DC_NAME_ISNULL(531000, "Dc name can not be empty"), // 数据中心name不能为空
+ DC_ID_ISNULL(531001, "Dc id can not be empty"), // 数据中心id不能为空
+ DC_PHONE_FORMAT(533002, "Dc phone format error"),
+ DC_PRINCIPAL_NOT_EXISTS(536003, "Dc principal does not exist"), // 数据中心负责人不存在
+ DC_NAME_DUPLICATE(532004, "Dc name duplicate"), // 数据中心名称重复
+ DC_CABINETS_EXISTS(533005, "These Dc contain cabinets and cannot be deleted"), // 数据中心内含有机柜
+ DC_ASSETS_EXISTS(533006, "These Dc contain assets and cannot be deleted"), // 数据中心内含有资产
+ DC_NOT_EXISTS(536007, "Dc does not exist"), // 数据中心不存在
+ DC_NOTHAS_CABINET(536008, "There is no this cabinet in the dc"), // 数据中心中没有该机柜
+ DC_ID_FORMAT(533009, "Id format error , type should be integer"), // ID类型错误
+ DC_CABINETNAME_ISNULL(531010, "Cabinet name can not be empty"), // 机柜名称不能为空
+ DC_CABINETID_ISNULL(531011, "Cabinet id can not be empty"), // 机柜id不能为空
+ DC_CABINETNAME_DUPLICATE(532012, "Cabinet name duplicate"), // 机柜名称重复
+ DC_CABINETUSIZE_MINIMUM(535013, "Cabinet u size is a minimum of 1"),// 机柜U位大小最小为1
+ DC_CABINET_ASSETS_EXISTS(533014, "These cabinets contain assets and cannot be deleted"),// 机柜中有资产
+ DC_CABINET_MAXU(535015, "The maximum U of current cabinet is 47"), // 当前机柜最大U为47
+ DC_Y_MINIMUM(535016,"Dc y is a minimum of 1"), // 数据中心行数最少为1
+ DC_X_MINIMUM(535017,"Dc x is a minimum of 1"), // 数据中心列数最少为1
+ DC_Y_ALREADYINUSE(535018,"Dc y is already in use"), // 数据中心行已经被使用
+ DC_X_ALREADYINUSE(535019,"Dc x is already in use"), // 数据中心列已经被使用
CABINET_Y_MINIMUM(535020,"Cabinet y is a minimum of 1"), // 机柜所在行至少为1
CABINET_X_MINIMUM(535021,"Cabinet x is a minimum of 1"), // 机柜所在列至少为1
- CABINET_Y_INCORRECT(535022,"Cabinet y is not in this idc"), // 机柜所选行不在idc范围内
- CABINET_X_INCORRECT(535023,"Cabinet x is not in this idc"), // 机柜所选列不在idc范围内
+ CABINET_Y_INCORRECT(535022,"Cabinet y is not in this dc"), // 机柜所选行不在dc范围内
+ CABINET_X_INCORRECT(535023,"Cabinet x is not in this dc"), // 机柜所选列不在dc范围内
CABINET_POSITION_OCCUPIED(535024,"Cabinet position is occupied"), // 机柜所选位置已被占用
- IDC_PROMSERVER_EXISTS(533025, "There are promservers in the idc"),
- IDC_TRAFFIC_DIRECTIONS_INVALIDE(533026, "Idc traffic direction must be rx or tx"),
- IDC_TRAFFIC_SETTING_ISNULL(531027, "Idc traffic setting can not be empty"),
- IDC_TRAFFIC_DIRECTIONS_ISNULL(531028, "Idc traffic direction can not be empty"),
- IDC_TRAFFIC_IFINDEX_ISNULL(531029, "Idc traffic Ifindex can not be empty"),
- IDC_TRAFFIC_IFDESCR_ISNULL(531030, "Idc traffic ifdescr can not be empty"),
- IDC_NOT_INCLUDED_ASSET(533031,"Current asset is not included under the data center"),
- IDC_TRAFFIC_HOST_FORMAT(533032,"Idc traffic host must be in IP format"),
- IDC_TRAFFIC_HOST_ISNULL(531033,"Idc traffic host can not be empty"),
- IDC_TRAFFIC_PORT_ISNULL(531034,"Idc traffic port can not be empty"),
- IDC_TRAFFIC_VERSION_ISNULL(531035,"Idc traffic version can not be empty"),
- IDC_TRAFFIC_PORT_INVALIDE(535036,"Idc traffic port is invalide"),
- IDC_TRAFFIC_TAGSKEY_FORMAT(533037,"Idc traffic tags key format is incorrect"),
- IDC_PROMSERVERS_EXISTS(533038, "These idc contain prometheus servers and cannot be deleted"),
- IDC_STATE_ISNULL(531039, "Idc state can not be empty"),
- IDC_STATE_ERROR(534040, "Idc state must be ON or OFF"),
- IDC_LONGITUDE_ERROR(535041, "Idc longitude range is -180 to +180"),
- IDC_LATITUDE_ERROR(535042, "Idc latitude range is -90 to +90"),
+ DC_PROMSERVER_EXISTS(533025, "There are promservers in the dc"),
+ DC_TRAFFIC_DIRECTIONS_INVALIDE(533026, "Dc traffic direction must be rx or tx"),
+ DC_TRAFFIC_SETTING_ISNULL(531027, "Dc traffic setting can not be empty"),
+ DC_TRAFFIC_DIRECTIONS_ISNULL(531028, "Dc traffic direction can not be empty"),
+ DC_TRAFFIC_IFINDEX_ISNULL(531029, "Dc traffic Ifindex can not be empty"),
+ DC_TRAFFIC_IFDESCR_ISNULL(531030, "Dc traffic ifdescr can not be empty"),
+ DC_NOT_INCLUDED_ASSET(533031,"Current asset is not included under the data center"),
+ DC_TRAFFIC_HOST_FORMAT(533032,"Dc traffic host must be in IP format"),
+ DC_TRAFFIC_HOST_ISNULL(531033,"Dc traffic host can not be empty"),
+ DC_TRAFFIC_PORT_ISNULL(531034,"Dc traffic port can not be empty"),
+ DC_TRAFFIC_VERSION_ISNULL(531035,"Dc traffic version can not be empty"),
+ DC_TRAFFIC_PORT_INVALIDE(535036,"Dc traffic port is invalide"),
+ DC_TRAFFIC_TAGSKEY_FORMAT(533037,"Dc traffic tags key format is incorrect"),
+ DC_PROMSERVERS_EXISTS(533038, "These dc contain prometheus servers and cannot be deleted"),
+ DC_STATE_ISNULL(531039, "Dc state can not be empty"),
+ DC_STATE_ERROR(534040, "Dc state must be ON or OFF"),
+ DC_LONGITUDE_ERROR(535041, "Dc longitude range is -180 to +180"),
+ DC_LATITUDE_ERROR(535042, "Dc latitude range is -90 to +90"),
+ CABINET_NOT_EXISTS(536043, "Cabinet does not exist"),
SYS_I18N_DUPLICATE(542000, "duplicate error (code + lang)"), //国际化配置重复(code+lang)
SYS_I18N_NOSUCHLANG(543001, "no such lang"), //不合法的lang