feat:IDC Data拾取
This commit is contained in:
parent
06def98569
commit
977447bd07
|
@ -46,7 +46,7 @@ public class JDBCUtil {
|
||||||
try (Connection connection = dataSource.getConnection()) {
|
try (Connection connection = dataSource.getConnection()) {
|
||||||
return true;
|
return true;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
log.error("JDBCUtil.isConnection():数据源["+ url +"]连接失败: {}", e.getMessage());
|
log.error("数据源["+ url +"]连接失败: {}", e.getMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,8 +60,7 @@ public class JDBCUtil {
|
||||||
try (Connection connection = dataSource.getConnection()) {
|
try (Connection connection = dataSource.getConnection()) {
|
||||||
return new ConnR().setConn(true);
|
return new ConnR().setConn(true);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String message = String.format("IDC数据源["+ url +"]连接失败: %s", e.getMessage());
|
String message = String.format("[xxx数据源]连接失败: %s", e.getMessage());
|
||||||
log.error(message);
|
|
||||||
return new ConnR().setInfo(message);
|
return new ConnR().setInfo(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,7 +72,7 @@ public class JDBCUtil {
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String url = "--";
|
String url = "--";
|
||||||
if (ObjectUtil.isNotNull(dataSource)) url = dataSource.getUrl();
|
if (ObjectUtil.isNotNull(dataSource)) url = dataSource.getUrl();
|
||||||
log.error("JDBCUtil.isConnection():数据源["+ url +"]连接失败: {}", e.getMessage());
|
log.error("数据源["+ url +"]连接失败: {}", e.getMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,10 +6,7 @@ import org.jeecg.common.system.vo.DictModel;
|
||||||
import org.jeecg.modules.base.entity.postgre.SysUser;
|
import org.jeecg.modules.base.entity.postgre.SysUser;
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -28,7 +25,7 @@ public interface SystemClient {
|
||||||
@RequestParam String groupId,
|
@RequestParam String groupId,
|
||||||
@RequestParam String notific);
|
@RequestParam String notific);
|
||||||
|
|
||||||
@GetMapping("/sys/sendMessage/sendTo")
|
@PostMapping("/sys/sendMessage/sendTo")
|
||||||
void sendTo(@RequestBody MessageDTO messageDTO);
|
void sendTo(@RequestBody MessageDTO messageDTO);
|
||||||
|
|
||||||
/* SysDictController下相关接口 */
|
/* SysDictController下相关接口 */
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package org.jeecg.modules.idc;
|
package org.jeecg.modules.idc;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.jeecg.common.api.dto.message.MessageDTO;
|
import org.jeecg.common.api.dto.message.MessageDTO;
|
||||||
|
import org.jeecg.common.config.mqtoken.UserTokenContext;
|
||||||
import org.jeecg.common.constant.enums.MessageTypeEnum;
|
import org.jeecg.common.constant.enums.MessageTypeEnum;
|
||||||
import org.jeecg.common.util.JDBCUtil;
|
import org.jeecg.common.util.JDBCUtil;
|
||||||
import org.jeecg.modules.base.dto.ConnR;
|
import org.jeecg.modules.base.dto.ConnR;
|
||||||
|
@ -17,26 +19,28 @@ import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static org.jeecg.common.util.TokenUtils.getTempToken;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class IDCDataFetch {
|
public class IDCDataFetch {
|
||||||
|
|
||||||
@Value("inland.url")
|
@Value("${inland.url}")
|
||||||
private String urlM; // 本地数据源url,即为主数据源
|
private String urlM; // 本地数据源url,即为主数据源
|
||||||
|
|
||||||
@Value("inland.username")
|
@Value("${inland.username}")
|
||||||
private String usernameM;
|
private String usernameM;
|
||||||
|
|
||||||
@Value("inland.password")
|
@Value("${inland.password}")
|
||||||
private String passwordM;
|
private String passwordM;
|
||||||
|
|
||||||
@Value("oversea.url")
|
@Value("${oversea.url}")
|
||||||
private String urlS; // 国外数据源url,即为从数据源
|
private String urlS; // 国外数据源url,即为从数据源
|
||||||
|
|
||||||
@Value("oversea.username")
|
@Value("${oversea.username}")
|
||||||
private String usernameS;
|
private String usernameS;
|
||||||
|
|
||||||
@Value("oversea.password")
|
@Value("${oversea.password}")
|
||||||
private String passwordS;
|
private String passwordS;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -44,39 +48,51 @@ public class IDCDataFetch {
|
||||||
|
|
||||||
// 定时拾取IDC数据
|
// 定时拾取IDC数据
|
||||||
@Scheduled(fixedDelayString = "${request-interval}", timeUnit = TimeUnit.SECONDS)
|
@Scheduled(fixedDelayString = "${request-interval}", timeUnit = TimeUnit.SECONDS)
|
||||||
private void fetch() {
|
public void fetch() {
|
||||||
ConnR connR;
|
|
||||||
JdbcTemplate template;
|
JdbcTemplate template;
|
||||||
MessageDTO messageDTO = new MessageDTO("IDC数据源异常", null, "admin");
|
MessageDTO messageDTO = new MessageDTO("IDC数据源异常", null, "admin");
|
||||||
messageDTO.setType(MessageTypeEnum.XT.getType());
|
messageDTO.setType(MessageTypeEnum.XT.getType());
|
||||||
connR = JDBCUtil.isConnection(urlM, usernameM, passwordM);
|
ConnR connR = JDBCUtil.isConnection(urlM, usernameM, passwordM);
|
||||||
if (connR.isConn()) {
|
if (connR.isConn()) {
|
||||||
try {
|
try {
|
||||||
template = JDBCUtil.template(urlM, usernameM, passwordM);
|
template = JDBCUtil.template(urlM, usernameM, passwordM);
|
||||||
// 查询IDC Data
|
// 查询IDC Data
|
||||||
System.out.println("[inland数据源]IDC数据查询");
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("[inland数据源]IDC数据查询异常: {}", e.getMessage());
|
log.error("[inland数据源]IDC数据处理异常: {}", e.getMessage());
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
UserTokenContext.setToken(getTempToken());
|
||||||
|
// 对发送警告消息时可能出现的异常进行捕获(503) 防止影响后续代码执行
|
||||||
|
try {
|
||||||
// 给管理员发送预警信息
|
// 给管理员发送预警信息
|
||||||
messageDTO.setContent(connR.getInfo());
|
String message = StrUtil.replace(connR.getInfo(), "xxx", "inland");
|
||||||
|
messageDTO.setContent(message);
|
||||||
systemClient.sendTo(messageDTO);
|
systemClient.sendTo(messageDTO);
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error("发送inland数据源异常信息失败: {}", e.getMessage());
|
||||||
|
}
|
||||||
// 使用备用数据源
|
// 使用备用数据源
|
||||||
connR = JDBCUtil.isConnection(urlS, usernameS, passwordS);
|
connR = JDBCUtil.isConnection(urlS, usernameS, passwordS);
|
||||||
if (connR.isConn()) {
|
if (connR.isConn()) {
|
||||||
try {
|
try {
|
||||||
template = JDBCUtil.template(urlS, usernameS, passwordS);
|
template = JDBCUtil.template(urlS, usernameS, passwordS);
|
||||||
// 查询IDC Data
|
// 查询IDC Data
|
||||||
System.out.println("[oversea数据源]IDC数据查询");
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("[oversea数据源]IDC数据查询异常: {}", e.getMessage());
|
log.error("[oversea数据源]IDC数据处理异常: {}", e.getMessage());
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
// 给管理员发送预警信息
|
// 给管理员发送预警信息
|
||||||
messageDTO.setContent(connR.getInfo());
|
String message = StrUtil.replace(connR.getInfo(), "xxx", "oversea");
|
||||||
|
messageDTO.setContent(message);
|
||||||
systemClient.sendTo(messageDTO);
|
systemClient.sendTo(messageDTO);
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error("发送oversea数据源异常信息失败: {}", e.getMessage());
|
||||||
|
}
|
||||||
|
UserTokenContext.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ public class SendMessageController {
|
||||||
sendMessage.send(title, message, groupId, notific);
|
sendMessage.send(title, message, groupId, notific);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("sendTo")
|
@PostMapping("sendTo")
|
||||||
public void sendTo(@RequestBody MessageDTO messageDTO){
|
public void sendTo(@RequestBody MessageDTO messageDTO){
|
||||||
sysBaseAPI.sendTemplateMessage(messageDTO);
|
sysBaseAPI.sendTemplateMessage(messageDTO);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user