注释获取IDC数据库相关代码
This commit is contained in:
parent
ce6d2a28ec
commit
4f30f693e4
|
|
@ -26,79 +26,79 @@ import static org.jeecg.modules.base.enums.Template.IDC_DATASOURCE_STATUS;
|
||||||
@RefreshScope
|
@RefreshScope
|
||||||
public class TemplateManager {
|
public class TemplateManager {
|
||||||
|
|
||||||
@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
|
||||||
private SystemClient systemClient;
|
// private SystemClient systemClient;
|
||||||
|
//
|
||||||
private final String TEMPLATEKEY = "template";
|
// private final String TEMPLATEKEY = "template";
|
||||||
|
//
|
||||||
private final ConcurrentMap<String, JdbcTemplate> templateMap = new ConcurrentHashMap<>();
|
// private final ConcurrentMap<String, JdbcTemplate> templateMap = new ConcurrentHashMap<>();
|
||||||
|
//
|
||||||
private void setTemplate(JdbcTemplate template){
|
// private void setTemplate(JdbcTemplate template){
|
||||||
templateMap.put(TEMPLATEKEY, template);
|
// templateMap.put(TEMPLATEKEY, template);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public JdbcTemplate getTemplate(){
|
// public JdbcTemplate getTemplate(){
|
||||||
return templateMap.get(TEMPLATEKEY);
|
// return templateMap.get(TEMPLATEKEY);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/*
|
// /*
|
||||||
* 定时检查inland/oversea数据源的的连接状态
|
// * 定时检查inland/oversea数据源的的连接状态
|
||||||
* */
|
// * */
|
||||||
// @Scheduled(fixedDelay = 10, timeUnit = TimeUnit.SECONDS)
|
// // @Scheduled(fixedDelay = 10, timeUnit = TimeUnit.SECONDS)
|
||||||
private void checkTemplate(){
|
// private void checkTemplate(){
|
||||||
try {
|
// try {
|
||||||
MessageDTO messageDTO = new MessageDTO(null, IDC_DATASOURCE_STATUS.getCode(), "admin");
|
// MessageDTO messageDTO = new MessageDTO(null, IDC_DATASOURCE_STATUS.getCode(), "admin");
|
||||||
messageDTO.setType(MessageTypeEnum.XT.getType());
|
// messageDTO.setType(MessageTypeEnum.XT.getType());
|
||||||
ConnR connR = JDBCUtil.isConnection(urlM, usernameM, passwordM);
|
// ConnR connR = JDBCUtil.isConnection(urlM, usernameM, passwordM);
|
||||||
// 如果inland数据源不可用 尝试oversea数据源
|
// // 如果inland数据源不可用 尝试oversea数据源
|
||||||
JdbcTemplate template;
|
// JdbcTemplate template;
|
||||||
if (connR.isConn()){
|
// if (connR.isConn()){
|
||||||
template = JDBCUtil.template(urlM, usernameM, passwordM);
|
// template = JDBCUtil.template(urlM, usernameM, passwordM);
|
||||||
this.setTemplate(template);
|
// this.setTemplate(template);
|
||||||
} else {
|
// } else {
|
||||||
String info = "发送%s数据源异常信息失败: {}";
|
// String info = "发送%s数据源异常信息失败: {}";
|
||||||
// 为当前线程设置临时Token 避免OpenFeign调用其它服务接口时401
|
// // 为当前线程设置临时Token 避免OpenFeign调用其它服务接口时401
|
||||||
UserTokenContext.setToken(TokenUtils.getTempToken());
|
// UserTokenContext.setToken(TokenUtils.getTempToken());
|
||||||
// 给admin发送数据源异常消息
|
// // 给admin发送数据源异常消息
|
||||||
Map<String, Object> data = DataTool.getInstance()
|
// Map<String, Object> data = DataTool.getInstance()
|
||||||
.put("inland").put(connR.getInfo()).get();
|
// .put("inland").put(connR.getInfo()).get();
|
||||||
messageDTO.setData(data);
|
// messageDTO.setData(data);
|
||||||
try { systemClient.sendTo(messageDTO); }
|
// try { systemClient.sendTo(messageDTO); }
|
||||||
catch(Exception e) {log.error(String.format(info, "inland") , e.getMessage());}
|
// catch(Exception e) {log.error(String.format(info, "inland") , e.getMessage());}
|
||||||
connR = JDBCUtil.isConnection(urlS, usernameS, passwordS);
|
// connR = JDBCUtil.isConnection(urlS, usernameS, passwordS);
|
||||||
if (connR.isConn()){
|
// if (connR.isConn()){
|
||||||
template = JDBCUtil.template(urlS, usernameS, passwordS);
|
// template = JDBCUtil.template(urlS, usernameS, passwordS);
|
||||||
this.setTemplate(template);
|
// this.setTemplate(template);
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
// 给admin发送数据源异常消息
|
// // 给admin发送数据源异常消息
|
||||||
data = DataTool.getInstance().put("oversea").put(connR.getInfo()).get();
|
// data = DataTool.getInstance().put("oversea").put(connR.getInfo()).get();
|
||||||
messageDTO.setData(data);
|
// messageDTO.setData(data);
|
||||||
try { systemClient.sendTo(messageDTO); }
|
// try { systemClient.sendTo(messageDTO); }
|
||||||
catch(Exception e) {log.error(String.format(info, "oversea") , e.getMessage());}
|
// catch(Exception e) {log.error(String.format(info, "oversea") , e.getMessage());}
|
||||||
}
|
// }
|
||||||
}catch (Exception e){
|
// }catch (Exception e){
|
||||||
log.error("定时检查inland/oversea数据源状态异常: {}", e.getMessage());
|
// log.error("定时检查inland/oversea数据源状态异常: {}", e.getMessage());
|
||||||
}finally {
|
// }finally {
|
||||||
UserTokenContext.remove();
|
// UserTokenContext.remove();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user