fix : 修改数据同步逻辑
This commit is contained in:
@@ -5,10 +5,13 @@ import com.nis.entity.AlertMessageActiveEntity;
|
||||
import com.nis.entity.AlertMessageEntity;
|
||||
import com.nis.entity.AlertRuleEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
|
||||
@Mapper
|
||||
public interface AlertRuleDao extends BaseMapper<AlertRuleEntity> {
|
||||
|
||||
List<AlertRuleEntity> selectAllDatas();
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ import com.nis.entity.Dc;
|
||||
import com.nis.entity.Idc;
|
||||
import com.nis.entity.Module;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@@ -21,4 +23,5 @@ import org.springframework.stereotype.Repository;
|
||||
@Repository
|
||||
public interface ModuleDao extends BaseMapper<Module> {
|
||||
|
||||
List<Module> selectSnmpDatas();
|
||||
}
|
||||
|
||||
30
src/main/java/com/nis/dao/SysConfigDao.java
Normal file
30
src/main/java/com/nis/dao/SysConfigDao.java
Normal file
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
|
||||
*
|
||||
|
||||
*
|
||||
|
||||
*/
|
||||
|
||||
package com.nis.dao;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nis.entity.SysConfigEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
/**
|
||||
* 系统配置信息
|
||||
*
|
||||
|
||||
*/
|
||||
@Mapper
|
||||
public interface SysConfigDao extends BaseMapper<SysConfigEntity> {
|
||||
|
||||
List<SysConfigEntity> selectSysConfigEntitys();
|
||||
}
|
||||
@@ -10,10 +10,15 @@ package com.nis.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nis.entity.SysDictEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
|
||||
@Mapper
|
||||
public interface SysDictDao extends BaseMapper<SysDictEntity> {
|
||||
|
||||
List<SysDictEntity> selectDatas(@Param("type") String type);
|
||||
}
|
||||
|
||||
20
src/main/java/com/nis/dao/SysUserDao.java
Normal file
20
src/main/java/com/nis/dao/SysUserDao.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package com.nis.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nis.entity.Account;
|
||||
import com.nis.entity.Asset;
|
||||
import com.nis.entity.SysUserEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface SysUserDao extends BaseMapper<SysUserEntity> {
|
||||
|
||||
List<SysUserEntity> selectOldUsers();
|
||||
|
||||
List<SysUserEntity> selectNewUsers();
|
||||
}
|
||||
@@ -118,6 +118,6 @@ public class AlertMessageActiveEntity implements Serializable {
|
||||
@TableField(exist = false)
|
||||
private Dc dc;
|
||||
|
||||
|
||||
@TableField(exist = false)
|
||||
private String severity;
|
||||
}
|
||||
|
||||
@@ -117,6 +117,6 @@ public class AlertMessageHistoryEntity implements Serializable {
|
||||
@TableField(exist = false)
|
||||
private Dc dc;
|
||||
|
||||
|
||||
@TableField(exist = false)
|
||||
private String severity;
|
||||
}
|
||||
|
||||
@@ -76,6 +76,7 @@ public class AlertRuleEntity implements Serializable {
|
||||
*/
|
||||
private String seq;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String severity;
|
||||
|
||||
private Integer method;
|
||||
|
||||
83
src/main/java/com/nis/entity/SysUserEntity.java
Normal file
83
src/main/java/com/nis/entity/SysUserEntity.java
Normal file
@@ -0,0 +1,83 @@
|
||||
package com.nis.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 系统用户
|
||||
*/
|
||||
@Data
|
||||
@TableName("sys_user")
|
||||
public class SysUserEntity implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
@TableField(exist=false)
|
||||
private Long id;
|
||||
|
||||
@TableField(exist=false)
|
||||
private Long userId;
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String username;
|
||||
|
||||
|
||||
private String password;
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
@TableField(exist=false)
|
||||
private String pin;
|
||||
|
||||
/**
|
||||
* 盐
|
||||
*/
|
||||
private String salt;
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 状态 0:禁用 1:正常
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 语言
|
||||
*/
|
||||
private String lang;
|
||||
@TableField(exist=false)
|
||||
private String mobile;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(exist=false)
|
||||
private Date createAt;
|
||||
@TableField(exist=false)
|
||||
private Integer createBy;
|
||||
@TableField(exist=false)
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 来源
|
||||
*/
|
||||
private String source;
|
||||
|
||||
@TableField(exist=false)
|
||||
private String lastLoginIp;
|
||||
@TableField(exist=false)
|
||||
private Date lastLoginTime;
|
||||
|
||||
private Date createTime;
|
||||
}
|
||||
@@ -37,7 +37,7 @@ public class BeforeHandler implements CommandLineRunner {
|
||||
log.info("backup database successful");
|
||||
|
||||
// 删除触发器
|
||||
sqlHandler.dropTriggers();
|
||||
/*sqlHandler.dropTriggers();
|
||||
log.info("drop all trigger successful");
|
||||
|
||||
// 修改表结构
|
||||
@@ -45,7 +45,7 @@ public class BeforeHandler implements CommandLineRunner {
|
||||
log.info("alter table successful");
|
||||
|
||||
// 新增表
|
||||
sqlHandler.batchAddTable();
|
||||
sqlHandler.batchAddTable();*/
|
||||
|
||||
log.info("all sql execute successful , before handler close");
|
||||
|
||||
|
||||
@@ -1,12 +1,32 @@
|
||||
package com.nis.handler;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.jdbc.datasource.init.ScriptException;
|
||||
import org.springframework.jdbc.datasource.init.ScriptUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
|
||||
import com.nis.dao.SqlDao;
|
||||
import com.nis.entity.SysConfigEntity;
|
||||
import com.nis.entity.SysUserEntity;
|
||||
import com.nis.service.AlertMessageService;
|
||||
import com.nis.service.AssetAssetService;
|
||||
import com.nis.service.AssetBrandService;
|
||||
@@ -14,8 +34,12 @@ import com.nis.service.AssetModelService;
|
||||
import com.nis.service.ChartService;
|
||||
import com.nis.service.DcService;
|
||||
import com.nis.service.EndpointService;
|
||||
import com.nis.service.SysConfigService;
|
||||
import com.nis.service.SysUserService;
|
||||
import com.nis.util.Constant;
|
||||
import com.nis.util.ToolUtil;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.log.Log;
|
||||
|
||||
@@ -53,6 +77,15 @@ public class SqlHandler {
|
||||
@Autowired
|
||||
private ChartService chartService;
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
@Autowired
|
||||
private SysUserService sysUserService;
|
||||
|
||||
@Autowired
|
||||
private SysConfigService sysConfigService;
|
||||
|
||||
public void removeData() {
|
||||
String assetPing = "delete from asset_ping";
|
||||
sqlDao.execute(assetPing);
|
||||
@@ -140,7 +173,8 @@ public class SqlHandler {
|
||||
|
||||
String sysMenu = "ALTER TABLE `sys_menu` \r\n"
|
||||
+ "ADD COLUMN `description` varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL,\r\n"
|
||||
+ "ADD COLUMN `icon` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT 'nz-icon nz-alert-add';";
|
||||
+ "ADD COLUMN `icon` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT 'nz-icon nz-alert-add',"
|
||||
+ "ADD COLUMN `required` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '必要权限,如编辑按钮需要 勾选查看权限 填写内容为 sys_menu.id,多个逗号分隔 1,2';";
|
||||
sqlDao.execute(sysMenu);
|
||||
|
||||
String alertRule = "ALTER TABLE `alert_rule` \r\n"
|
||||
@@ -198,11 +232,11 @@ public class SqlHandler {
|
||||
+ " `id` int(10) NOT NULL AUTO_INCREMENT,\r\n"
|
||||
+ " `message_id` int(10) NOT NULL COMMENT '关联 alert_message.id',\r\n"
|
||||
+ " `user_id` int(10) NOT NULL COMMENT '关联 sys_user.id',\r\n"
|
||||
+ " `method` varchar(128) NOT NULL COMMENT '通知方式 VARCHARemail 或 NOTIFICATION_SCRIPT.name',\r\n"
|
||||
+ " `message_state` char(1) NOT NULL COMMENT '消息状态1: active2: expired',\r\n"
|
||||
+ " `state` char(1) NOT NULL COMMENT '通知状态0:失败1:成功',\r\n"
|
||||
+ " `error_msg` varchar(1024) NOT NULL DEFAULT '' COMMENT '发送错误信息',\r\n"
|
||||
+ " `time` datetime NOT NULL COMMENT '发送时间',\r\n"
|
||||
+ " `method_id` int(10) NOT NULL COMMENT '通知方式id 关联ALERT_NOTIFICATION_METHOD.id',\r\n"
|
||||
+ " PRIMARY KEY (`id`) USING BTREE\r\n"
|
||||
+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;";
|
||||
|
||||
@@ -672,9 +706,18 @@ public class SqlHandler {
|
||||
* asset_type_conf
|
||||
* monitor_event_log
|
||||
* sys_timezone
|
||||
* @throws IOException
|
||||
* @throws SQLException
|
||||
* @throws ScriptException
|
||||
*/
|
||||
public void initData() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
public void initData() throws ScriptException, SQLException {
|
||||
Resource classPathResource = new ClassPathResource("db/init.sql");
|
||||
ScriptUtils.executeSqlScript(dataSource.getConnection(), classPathResource);
|
||||
// asset_brand表数据单独处理
|
||||
assetBrandService.handler();
|
||||
// asset_model表数据处理 前提先处理好brand表数据信息
|
||||
assetModelService.handler();
|
||||
/*StringBuilder sb = new StringBuilder();
|
||||
sb.append("INSERT INTO `asset_field_group`(`id`, `name`, `remark`, `build_in`, `seq`) VALUES (1, 'default', 'Default meta group', '1', '');");
|
||||
sb.append("INSERT INTO `alert_severity_conf`(`id`, `name`, `color`, `weight`, `remark`) VALUES (1, 'P1', '#f2866e', 1, '高级告警');");
|
||||
sb.append("INSERT INTO `alert_severity_conf`(`id`, `name`, `color`, `weight`, `remark`) VALUES (2, 'P2', '#f89984', 2, '中级告警');");
|
||||
@@ -971,16 +1014,15 @@ public class SqlHandler {
|
||||
+ "INSERT INTO `sys_config`(`param_key`, `param_value`, `status`, `remark`) VALUES ('terminal_telnet_pin_tip', 'assword:', 1, '默认:assword:');\r\n"
|
||||
+ "INSERT INTO `sys_config`(`param_key`, `param_value`, `status`, `remark`) VALUES ('terminal_telnet_user_tip', 'ogin:', 1, '默认:ogin:');\r\n"
|
||||
+ "INSERT INTO `sys_config`(`param_key`, `param_value`, `status`, `remark`) VALUES ('terminal_timeout', '30', 1, '默认:30,单位:minute');\r\n"
|
||||
+ "INSERT INTO `sys_config`(`param_key`, `param_value`, `status`, `remark`) VALUES ('snmp_trap_listen_port', '160', 1, 'snmp trap接收端口');\r\n"
|
||||
+ "update sys_config set param_key =\"default_scrape_interval\" where param_key=\"scrape_interval\";\r\n"
|
||||
+ "update sys_config set param_key =\"default_scrape_timeout\" where param_key=\"scrape_timeout\";\r\n"
|
||||
+ "update sys_config set param_value =\"Asia/Almaty\" where param_key=\"timezone\";\r\n"
|
||||
);
|
||||
// 修改sys_user表数据 初始化name字段内容
|
||||
sb.append("update sys_user set name = username;");
|
||||
sqlDao.execute(sb.toString());
|
||||
// asset_brand表数据单独处理
|
||||
assetBrandService.handler();
|
||||
// asset_model表数据处理 前提先处理好brand表数据信息
|
||||
assetModelService.handler();
|
||||
*/
|
||||
}
|
||||
|
||||
public void transferData() {
|
||||
@@ -998,5 +1040,61 @@ public class SqlHandler {
|
||||
// 图表相关数据同步
|
||||
chartService.handler();
|
||||
|
||||
// 将原来数据库的数据数据还原
|
||||
this.dataRestore();
|
||||
}
|
||||
|
||||
public void dataRestore() {
|
||||
StringBuilder sb =new StringBuilder();
|
||||
// sys_user表数据还原
|
||||
List<SysUserEntity> users = sysUserService.queryNewUsers();
|
||||
List<SysUserEntity> oldUsers = sysUserService.queryOldUsers();
|
||||
Map<Long, SysUserEntity> userIdAndEntity = users.stream().collect(Collectors.toMap(SysUserEntity::getId, Function.identity()));
|
||||
for(SysUserEntity user : oldUsers) {
|
||||
SysUserEntity sysUserEntity = userIdAndEntity.get(user.getUserId());
|
||||
if(ToolUtil.isNotEmpty(sysUserEntity)) {
|
||||
sb.append("update sys_user set id='"+user.getUserId()+"',username='"+user.getUsername()+"',pin='"
|
||||
+user.getPassword()+"',salt='"+user.getSalt()+"',email='"+user.getEmail()+"',status='"
|
||||
+user.getStatus()+"',lang='"+user.getLang()
|
||||
+"',source='"+user.getSource()+"',name='"+user.getUsername()+"';");
|
||||
}else {
|
||||
sb.append("insert into sys_user (id,username,pin,salt,email,status,"
|
||||
+ "lang,source,name) values('"+user.getUserId()+"','"+user.getUsername()+"','"+user.getPassword()
|
||||
+"','"+user.getSalt()+"','"+user.getEmail()+"','"+user.getStatus()
|
||||
+"','"+user.getLang()+"','"+user.getSource()+"','"+user.getUsername()+"');");
|
||||
}
|
||||
}
|
||||
//
|
||||
sqlDao.execute(sb.toString());
|
||||
|
||||
// sys_config表数据
|
||||
List<SysConfigEntity> newDatas = sysConfigService.list();
|
||||
List<SysConfigEntity> oldDatas = sysConfigService.querySysConfigEntitys();
|
||||
Map<String, String> oldDataMap = oldDatas.stream().collect(Collectors.toMap(SysConfigEntity::getParamKey, SysConfigEntity::getParamValue));
|
||||
for(SysConfigEntity data : newDatas) {
|
||||
if(data.getParamKey().equals("default_scrape_interval")) {
|
||||
data.setParamValue(oldDataMap.get("scrape_interval"));
|
||||
}else if(data.getParamKey().equals("default_scrape_timeout")) {
|
||||
data.setParamValue(oldDataMap.get("scrape_timeout"));
|
||||
}else if(data.getParamKey().equals("timezone")) {
|
||||
data.setParamValue("Asia/Shanghai");
|
||||
}else {
|
||||
String value = oldDataMap.get(data.getParamKey());
|
||||
if(value!=null) {
|
||||
data.setParamValue(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
sysConfigService.updateBatchById(newDatas);
|
||||
|
||||
// prom_server snmp_mib link project_topo表数据同步
|
||||
StringBuilder restoreData = new StringBuilder();
|
||||
restoreData.append("INSERT INTO prom_server (id, dc_id, `host`, `port`, type, `status`, check_time,token ) SELECT id, idc_id,`host`,`port`,type,`status`,check_time,\"\" FROM prom_server_copy;\r\n"
|
||||
+ " INSERT INTO project_topo (id, project_id, topo,update_at,update_by) SELECT id, project_id, topo,update_at,update_by from project_topo_copy;\r\n"
|
||||
+ " INSERT INTO project_topo_icon (id,name,bytes,type,unit) select id,name,bytes,type,-1 from project_topo_icon_copy where id > 4;\r\n"
|
||||
+ " INSERT INTO snmp_mib (id,name,file_name,content,models,remark,update_by,update_at,tree) select id,name,file_name,content,models,remark,update_by,update_at,tree from snmp_mib_copy;\r\n"
|
||||
+ " INSERT INTO link (id,name,create_by,url,build_in,weight) select id,name,create_by,url,build_in,0 from link_copy;"
|
||||
+ " INSERT INTO cabinet (id,name,dc_id,u_size,remark,seq,x,y) select id,name,idc_id,u_size,remark,seq,x,y from cabinet_copy;");
|
||||
sqlDao.execute(restoreData.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,5 +11,6 @@ import com.nis.entity.AlertRuleEntity;
|
||||
|
||||
public interface AlertRuleService extends IService<AlertRuleEntity> {
|
||||
|
||||
List<AlertRuleEntity> queryAllDatas();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.nis.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.nis.entity.Dc;
|
||||
import com.nis.entity.Idc;
|
||||
@@ -8,4 +10,5 @@ import com.nis.entity.Module;
|
||||
|
||||
public interface ModuleService extends IService<Module> {
|
||||
|
||||
List<Module> querySnmpDatas();
|
||||
}
|
||||
26
src/main/java/com/nis/service/SysConfigService.java
Normal file
26
src/main/java/com/nis/service/SysConfigService.java
Normal file
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
|
||||
*
|
||||
|
||||
*
|
||||
|
||||
*/
|
||||
|
||||
package com.nis.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.nis.entity.SysConfigEntity;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 系统配置信息
|
||||
*
|
||||
|
||||
*/
|
||||
public interface SysConfigService extends IService<SysConfigEntity> {
|
||||
|
||||
List<SysConfigEntity> querySysConfigEntitys();
|
||||
}
|
||||
@@ -21,5 +21,6 @@ import java.util.Map;
|
||||
*/
|
||||
public interface SysDictService extends IService<SysDictEntity> {
|
||||
|
||||
List<SysDictEntity> queryDatas(String type);
|
||||
}
|
||||
|
||||
|
||||
28
src/main/java/com/nis/service/SysUserService.java
Normal file
28
src/main/java/com/nis/service/SysUserService.java
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
|
||||
*
|
||||
|
||||
*
|
||||
|
||||
*/
|
||||
|
||||
package com.nis.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.nis.entity.SysUserEntity;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* 系统用户
|
||||
*
|
||||
|
||||
*/
|
||||
public interface SysUserService extends IService<SysUserEntity> {
|
||||
|
||||
List<SysUserEntity> queryOldUsers();
|
||||
|
||||
List<SysUserEntity> queryNewUsers();
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.nis.service.impl;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.nis.dao.AlertMessageDao;
|
||||
import com.nis.entity.AlertMessageActiveEntity;
|
||||
@@ -22,8 +23,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
||||
|
||||
|
||||
@Service("alertMessageService")
|
||||
public class AlertMessageServiceImpl extends ServiceImpl<AlertMessageDao, AlertMessageEntity> implements AlertMessageService {
|
||||
|
||||
@@ -40,7 +39,7 @@ public class AlertMessageServiceImpl extends ServiceImpl<AlertMessageDao, AlertM
|
||||
public void handler() {
|
||||
|
||||
// alert rule数据修改
|
||||
List<AlertRuleEntity> rules = alertRuleService.list();
|
||||
List<AlertRuleEntity> rules = alertRuleService.queryAllDatas();
|
||||
for(AlertRuleEntity rule : rules) {
|
||||
if(rule.getSeverity().equals("P1")) {
|
||||
rule.setSeverityId(1);
|
||||
@@ -51,8 +50,10 @@ public class AlertMessageServiceImpl extends ServiceImpl<AlertMessageDao, AlertM
|
||||
}
|
||||
rule.setMethod(1);
|
||||
}
|
||||
|
||||
alertRuleService.remove(new QueryWrapper<AlertRuleEntity>());
|
||||
if(ToolUtil.isNotEmpty(rules)) {
|
||||
alertRuleService.updateBatchById(rules);
|
||||
alertRuleService.saveBatch(rules);
|
||||
}
|
||||
|
||||
List<AlertMessageEntity> messages = this.list();
|
||||
@@ -74,6 +75,7 @@ public class AlertMessageServiceImpl extends ServiceImpl<AlertMessageDao, AlertM
|
||||
activeMessages.add(activeMessage);
|
||||
}else {
|
||||
AlertMessageHistoryEntity historyMessage = new AlertMessageHistoryEntity();
|
||||
message.setState(3);
|
||||
BeanUtil.copyProperties(message, historyMessage);
|
||||
historyMessages.add(historyMessage);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ import com.nis.service.AlertMessageHistoryService;
|
||||
import com.nis.service.AlertMessageService;
|
||||
import com.nis.service.AlertRuleService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -21,6 +23,11 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
public class AlertRuleServiceImpl extends ServiceImpl<AlertRuleDao, AlertRuleEntity> implements AlertRuleService {
|
||||
|
||||
@Override
|
||||
public List<AlertRuleEntity> queryAllDatas() {
|
||||
return this.baseMapper.selectAllDatas();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ public class AssetAssetServiceImpl extends ServiceImpl<AssetAssetDao, AssetAsset
|
||||
// 查询model关联资产类型信息
|
||||
List<Model> models = modelService.list();
|
||||
Map<Integer, Integer> modelAndType = models.stream().collect(Collectors.toMap(Model::getId, Model::getTypeCode));
|
||||
List<SysDictEntity> sysDicts = sysDictService.list(new QueryWrapper<SysDictEntity>().lambda().eq(SysDictEntity::getType, "assetType"));
|
||||
List<SysDictEntity> sysDicts = sysDictService.queryDatas("assetType");
|
||||
Map<Integer, String> dictAndType = sysDicts.stream().collect(Collectors.toMap(SysDictEntity::getCode, SysDictEntity::getValue));
|
||||
Map<Integer,String> modelIdAndTypeName = new HashMap<Integer,String>();
|
||||
for(Integer key : modelAndType.keySet()) {
|
||||
|
||||
@@ -37,7 +37,7 @@ public class AssetBrandServiceImpl extends ServiceImpl<AssetBrandDao, AssetBrand
|
||||
}
|
||||
|
||||
public void initData() {
|
||||
List<SysDictEntity> brands = sysDictService.list(new QueryWrapper<SysDictEntity>().lambda().eq(SysDictEntity::getType, "vendor"));
|
||||
List<SysDictEntity> brands = sysDictService.queryDatas("vendor");
|
||||
|
||||
List<AssetBrand> assetBrands = new ArrayList<AssetBrand>();
|
||||
for(SysDictEntity brand : brands) {
|
||||
|
||||
@@ -29,6 +29,7 @@ public class DcServiceImpl extends ServiceImpl<DcDao, Dc> implements DcService {
|
||||
|
||||
for(Idc idc : idcs) {
|
||||
Dc dc = new Dc();
|
||||
dc.setId(idc.getId());
|
||||
dc.setName(idc.getName());
|
||||
dc.setLocation(idc.getLocation());
|
||||
dc.setTel(idc.getTel());
|
||||
|
||||
@@ -76,6 +76,9 @@ public class EndpointServiceImpl extends ServiceImpl<EndpointDao, Endpoint> impl
|
||||
BeanUtil.copyProperties(project, monitorProject);
|
||||
monitorProjects.add(monitorProject);
|
||||
}
|
||||
|
||||
// 先清空表
|
||||
monitorProjectService.remove(new QueryWrapper<MonitorProject>());
|
||||
if(ToolUtil.isNotEmpty(monitorProjects)) {
|
||||
monitorProjectService.saveBatch(monitorProjects);
|
||||
}
|
||||
@@ -83,7 +86,7 @@ public class EndpointServiceImpl extends ServiceImpl<EndpointDao, Endpoint> impl
|
||||
|
||||
// 同步module数据 首先需要将module中snmp类型的新增凭证
|
||||
List<SnmpCredential> snmpCredentials = new ArrayList<SnmpCredential>();
|
||||
List<Module> snmpModules = moduleService.list(new QueryWrapper<Module>().eq("type", "snmp"));
|
||||
List<Module> snmpModules = moduleService.querySnmpDatas();
|
||||
Map<Integer,SnmpCredential> moduleIdAndSnmpcredentialMap = new HashMap<Integer,SnmpCredential>();
|
||||
for(Module snmpModule : snmpModules) {
|
||||
String snmpParam = snmpModule.getSnmpParam();
|
||||
@@ -157,7 +160,7 @@ public class EndpointServiceImpl extends ServiceImpl<EndpointDao, Endpoint> impl
|
||||
MonitorModule monitorModule = new MonitorModule();
|
||||
monitorModule.setName(module.getName());
|
||||
monitorModule.setId(module.getId());
|
||||
monitorModule.setProjectId(module.getId());
|
||||
monitorModule.setProjectId(module.getProjectId());
|
||||
monitorModule.setRemark(module.getRemark());
|
||||
monitorModule.setSeq(module.getSeq());
|
||||
monitorModule.setBuildIn(module.getBuildIn());
|
||||
|
||||
@@ -12,9 +12,16 @@ import com.nis.service.DcService;
|
||||
import com.nis.service.IdcService;
|
||||
import com.nis.service.ModuleService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class ModuleServiceImpl extends ServiceImpl<ModuleDao, Module> implements ModuleService {
|
||||
|
||||
@Override
|
||||
public List<Module> querySnmpDatas() {
|
||||
return this.baseMapper.selectSnmpDatas();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
32
src/main/java/com/nis/service/impl/SysConfigServiceImpl.java
Normal file
32
src/main/java/com/nis/service/impl/SysConfigServiceImpl.java
Normal file
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
|
||||
*
|
||||
|
||||
*
|
||||
|
||||
*/
|
||||
|
||||
package com.nis.service.impl;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.nis.dao.SysConfigDao;
|
||||
import com.nis.entity.SysConfigEntity;
|
||||
import com.nis.service.SysConfigService;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
@Service("sysConfigService")
|
||||
public class SysConfigServiceImpl extends ServiceImpl<SysConfigDao, SysConfigEntity> implements SysConfigService {
|
||||
|
||||
@Override
|
||||
public List<SysConfigEntity> querySysConfigEntitys() {
|
||||
return this.baseMapper.selectSysConfigEntitys();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -26,4 +26,9 @@ import java.util.stream.Collectors;
|
||||
@Service("sysDictService")
|
||||
public class SysDictServiceImpl extends ServiceImpl<SysDictDao, SysDictEntity> implements SysDictService {
|
||||
|
||||
@Override
|
||||
public List<SysDictEntity> queryDatas(String type) {
|
||||
return this.baseMapper.selectDatas(type);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
25
src/main/java/com/nis/service/impl/SysUserServiceImpl.java
Normal file
25
src/main/java/com/nis/service/impl/SysUserServiceImpl.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package com.nis.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.nis.dao.SysUserDao;
|
||||
import com.nis.entity.SysUserEntity;
|
||||
import com.nis.service.SysUserService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service("sysUserService")
|
||||
public class SysUserServiceImpl extends ServiceImpl<SysUserDao, SysUserEntity> implements SysUserService {
|
||||
|
||||
@Override
|
||||
public List<SysUserEntity> queryOldUsers() {
|
||||
return this.baseMapper.selectOldUsers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysUserEntity> queryNewUsers() {
|
||||
return this.baseMapper.selectNewUsers();
|
||||
}
|
||||
|
||||
}
|
||||
27
src/main/resources/mapper/AlertRuleDao.xml
Normal file
27
src/main/resources/mapper/AlertRuleDao.xml
Normal file
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.nis.dao.AlertRuleDao">
|
||||
|
||||
<resultMap type="com.nis.entity.AlertRuleEntity" id="alertRuleMap">
|
||||
<result property="id" column="id"/>
|
||||
<result property="name" column="alert_name"/>
|
||||
<result property="expr" column="expr"/>
|
||||
<result property="operator" column="operator"/>
|
||||
<result property="threshold" column="threshold"/>
|
||||
<result property="unit" column="unit"/>
|
||||
<result property="method" column="method"/>
|
||||
<result property="last" column="last"/>
|
||||
<result property="severityId" column="severity_id"/>
|
||||
<result property="summary" column="summary"/>
|
||||
<result property="description" column="description"/>
|
||||
<result property="receiver" column="receiver"/>
|
||||
<result property="buildIn" column="buildIn"/>
|
||||
<result property="severity" column="severity"/>
|
||||
|
||||
</resultMap>
|
||||
|
||||
<select id="selectAllDatas" resultMap="alertRuleMap">
|
||||
select * from alert_rule_copy
|
||||
</select>
|
||||
</mapper>
|
||||
9
src/main/resources/mapper/ModuleDao.xml
Normal file
9
src/main/resources/mapper/ModuleDao.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.nis.dao.ModuleDao">
|
||||
|
||||
<select id="selectSnmpDatas" resultType="com.nis.entity.Module">
|
||||
select * from module_copy where type="snmp"
|
||||
</select>
|
||||
</mapper>
|
||||
9
src/main/resources/mapper/SysConfigDao.xml
Normal file
9
src/main/resources/mapper/SysConfigDao.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nis.dao.SysConfigDao">
|
||||
|
||||
<select id="selectSysConfigEntitys" resultType="com.nis.entity.SysConfigEntity">
|
||||
select * from sys_config_copy
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
9
src/main/resources/mapper/SysDictDao.xml
Normal file
9
src/main/resources/mapper/SysDictDao.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.nis.dao.SysDictDao">
|
||||
|
||||
<select id="selectDatas" resultType="com.nis.entity.SysDictEntity">
|
||||
select * from sys_dict_copy where type = #{type}
|
||||
</select>
|
||||
</mapper>
|
||||
36
src/main/resources/mapper/SysUserDao.xml
Normal file
36
src/main/resources/mapper/SysUserDao.xml
Normal file
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.nis.dao.SysUserDao">
|
||||
<resultMap type="com.nis.entity.SysUserEntity" id="oldUserMap">
|
||||
<result property="userId" column="user_id"/>
|
||||
<result property="username" column="username"/>
|
||||
<result property="password" column="password"/>
|
||||
<result property="salt" column="salt"/>
|
||||
<result property="email" column="email"/>
|
||||
<result property="status" column="status"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
<result property="lang" column="lang"/>
|
||||
<result property="source" column="source"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap type="com.nis.entity.SysUserEntity" id="newUserMap">
|
||||
<result property="id" column="id"/>
|
||||
<result property="username" column="username"/>
|
||||
<result property="pin" column="pin"/>
|
||||
<result property="salt" column="salt"/>
|
||||
<result property="email" column="email"/>
|
||||
<result property="status" column="status"/>
|
||||
<result property="lang" column="lang"/>
|
||||
<result property="source" column="source"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="selectOldUsers" resultMap="oldUserMap">
|
||||
select * from sys_user_copy
|
||||
</select>
|
||||
|
||||
<select id="selectNewUsers" resultMap="newUserMap">
|
||||
select * from sys_user
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user