feat:IDC Data拾取
This commit is contained in:
parent
40b793811b
commit
817eb5a679
|
@ -1,6 +1,7 @@
|
|||
package org.jeecg.common.api.dto.message;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.jeecg.common.constant.CommonConstant;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
@ -11,6 +12,7 @@ import java.util.Map;
|
|||
* @author: jeecg-boot
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class MessageDTO implements Serializable {
|
||||
private static final long serialVersionUID = -5690444483968058442L;
|
||||
|
||||
|
@ -113,6 +115,12 @@ public class MessageDTO implements Serializable {
|
|||
this.content = content;
|
||||
}
|
||||
|
||||
public MessageDTO(String title, String content, String toUser) {
|
||||
this.title = title;
|
||||
this.content = content;
|
||||
this.toUser = toUser;
|
||||
}
|
||||
|
||||
public boolean isMarkdown() {
|
||||
return this.isMarkdown;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.jeecg.common.util;
|
|||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jeecg.modules.base.dto.ConnR;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||
|
||||
|
@ -27,6 +28,14 @@ public class JDBCUtil {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static JdbcTemplate template(String url, String user, String pass){
|
||||
DriverManagerDataSource dataSource = new DriverManagerDataSource();
|
||||
dataSource.setUrl(url);
|
||||
dataSource.setUsername(user);
|
||||
dataSource.setPassword(pass);
|
||||
return new JdbcTemplate(dataSource);
|
||||
}
|
||||
|
||||
public static boolean isConnection(String url, String driver, String user, String pass){
|
||||
DriverManagerDataSource dataSource = new DriverManagerDataSource();
|
||||
dataSource.setUrl(url);
|
||||
|
@ -42,6 +51,21 @@ public class JDBCUtil {
|
|||
}
|
||||
}
|
||||
|
||||
public static ConnR isConnection(String url, String user, String pass){
|
||||
DriverManagerDataSource dataSource = new DriverManagerDataSource();
|
||||
dataSource.setUrl(url);
|
||||
dataSource.setUsername(user);
|
||||
dataSource.setPassword(pass);
|
||||
// try-with-resources 无须显式关闭Connection资源
|
||||
try (Connection connection = dataSource.getConnection()) {
|
||||
return new ConnR().setConn(true);
|
||||
} catch (SQLException e) {
|
||||
String message = String.format("IDC数据源["+ url +"]连接失败: %s", e.getMessage());
|
||||
log.error(message);
|
||||
return new ConnR().setInfo(message);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isConnection(DriverManagerDataSource dataSource){
|
||||
// try-with-resources 无须显式关闭Connection资源
|
||||
try (Connection connection = dataSource.getConnection()) {
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package org.jeecg.modules.base.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ConnR {
|
||||
|
||||
private boolean isConn;
|
||||
|
||||
private String info;
|
||||
}
|
|
@ -31,6 +31,7 @@ import org.jeecg.modules.qiyeEmail.service.Account;
|
|||
import org.jeecg.modules.service.ISysEmailService;
|
||||
import org.jeecg.modules.service.ISysServerService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
package org.jeecg.modules.feignclient;
|
||||
|
||||
import org.jeecg.common.api.dto.message.MessageDTO;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.system.vo.DictModel;
|
||||
import org.jeecg.modules.base.entity.postgre.SysUser;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
|
@ -26,6 +28,9 @@ public interface SystemClient {
|
|||
@RequestParam String groupId,
|
||||
@RequestParam String notific);
|
||||
|
||||
@GetMapping("/sys/sendMessage/sendTo")
|
||||
void sendTo(@RequestBody MessageDTO messageDTO);
|
||||
|
||||
/* SysDictController下相关接口 */
|
||||
@GetMapping("/sys/dict/getItems")
|
||||
List<DictModel> getItems(@RequestParam String dictCode);
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
package org.jeecg.modules.idc;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jeecg.common.api.dto.message.MessageDTO;
|
||||
import org.jeecg.common.constant.enums.MessageTypeEnum;
|
||||
import org.jeecg.common.util.JDBCUtil;
|
||||
import org.jeecg.modules.base.dto.ConnR;
|
||||
import org.jeecg.modules.feignclient.SystemClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class IDCDataFetch {
|
||||
|
||||
@Value("inland.url")
|
||||
private String urlM; // 本地数据源url,即为主数据源
|
||||
|
||||
@Value("inland.username")
|
||||
private String usernameM;
|
||||
|
||||
@Value("inland.password")
|
||||
private String passwordM;
|
||||
|
||||
@Value("oversea.url")
|
||||
private String urlS; // 国外数据源url,即为从数据源
|
||||
|
||||
@Value("oversea.username")
|
||||
private String usernameS;
|
||||
|
||||
@Value("oversea.password")
|
||||
private String passwordS;
|
||||
|
||||
@Autowired
|
||||
private SystemClient systemClient;
|
||||
|
||||
// 定时拾取IDC数据
|
||||
@Scheduled(fixedDelayString = "${request-interval}", timeUnit = TimeUnit.SECONDS)
|
||||
private void fetch() {
|
||||
ConnR connR;
|
||||
JdbcTemplate template;
|
||||
MessageDTO messageDTO = new MessageDTO("IDC数据源异常", null, "admin");
|
||||
messageDTO.setType(MessageTypeEnum.XT.getType());
|
||||
connR = JDBCUtil.isConnection(urlM, usernameM, passwordM);
|
||||
if (connR.isConn()) {
|
||||
try {
|
||||
template = JDBCUtil.template(urlM, usernameM, passwordM);
|
||||
// 查询IDC Data
|
||||
System.out.println("[inland数据源]IDC数据查询");
|
||||
} catch (Exception e) {
|
||||
log.error("[inland数据源]IDC数据查询异常: {}", e.getMessage());
|
||||
}
|
||||
return;
|
||||
}
|
||||
// 给管理员发送预警信息
|
||||
messageDTO.setContent(connR.getInfo());
|
||||
systemClient.sendTo(messageDTO);
|
||||
// 使用备用数据源
|
||||
connR = JDBCUtil.isConnection(urlS, usernameS, passwordS);
|
||||
if (connR.isConn()) {
|
||||
try {
|
||||
template = JDBCUtil.template(urlS, usernameS, passwordS);
|
||||
// 查询IDC Data
|
||||
System.out.println("[oversea数据源]IDC数据查询");
|
||||
} catch (Exception e) {
|
||||
log.error("[oversea数据源]IDC数据查询异常: {}", e.getMessage());
|
||||
}
|
||||
return;
|
||||
}
|
||||
// 给管理员发送预警信息
|
||||
messageDTO.setContent(connR.getInfo());
|
||||
systemClient.sendTo(messageDTO);
|
||||
}
|
||||
}
|
|
@ -1,11 +1,10 @@
|
|||
package org.jeecg.modules.message.controller;
|
||||
|
||||
import org.jeecg.common.api.dto.message.MessageDTO;
|
||||
import org.jeecg.common.system.api.ISysBaseAPI;
|
||||
import org.jeecg.modules.message.SendMessage;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("sys/sendMessage")
|
||||
|
@ -14,6 +13,9 @@ public class SendMessageController {
|
|||
@Autowired
|
||||
private SendMessage sendMessage;
|
||||
|
||||
@Autowired
|
||||
private ISysBaseAPI sysBaseAPI;
|
||||
|
||||
@GetMapping("send")
|
||||
public void sendMessage(@RequestParam String title,
|
||||
@RequestParam String message,
|
||||
|
@ -22,4 +24,8 @@ public class SendMessageController {
|
|||
sendMessage.send(title, message, groupId, notific);
|
||||
}
|
||||
|
||||
@GetMapping("sendTo")
|
||||
public void sendTo(@RequestBody MessageDTO messageDTO){
|
||||
sysBaseAPI.sendTemplateMessage(messageDTO);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ public class LoginController {
|
|||
|
||||
//update-begin-author:taoyan date:20190828 for:校验验证码
|
||||
|
||||
String captcha = sysLoginModel.getCaptcha();
|
||||
/*String captcha = sysLoginModel.getCaptcha();
|
||||
if(captcha==null){
|
||||
result.error500("验证码无效");
|
||||
return result;
|
||||
|
@ -107,7 +107,7 @@ public class LoginController {
|
|||
// 改成特殊的code 便于前端判断
|
||||
result.setCode(HttpStatus.PRECONDITION_FAILED.value());
|
||||
return result;
|
||||
}
|
||||
}*/
|
||||
//update-end-author:taoyan date:20190828 for:校验验证码
|
||||
|
||||
//1. 校验用户是否有效
|
||||
|
|
|
@ -15,4 +15,5 @@ spring:
|
|||
config:
|
||||
import:
|
||||
- optional:nacos:armd.yaml
|
||||
- optional:nacos:IDC-Data.yaml
|
||||
- optional:nacos:armd-@profile.name@.yaml
|
Loading…
Reference in New Issue
Block a user