注释获取IDC数据库相关代码

This commit is contained in:
duwenyuan 2026-05-12 15:13:33 +08:00
parent ce6d2a28ec
commit 4f30f693e4

View File

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