scada服务数据源
parent
c7c00e0d72
commit
77742e3c2f
@ -0,0 +1,74 @@
|
|||||||
|
package com.op.scada.config;
|
||||||
|
|
||||||
|
|
||||||
|
import com.sap.conn.jco.ext.DestinationDataProvider;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class DestinationManager {
|
||||||
|
@Value("${sap.ashost}")
|
||||||
|
private String ashost;
|
||||||
|
|
||||||
|
@Value("${sap.sysnr}")
|
||||||
|
private String sysnr;
|
||||||
|
|
||||||
|
@Value("${sap.client}")
|
||||||
|
private String client;
|
||||||
|
|
||||||
|
@Value("${sap.user}")
|
||||||
|
private String user;
|
||||||
|
|
||||||
|
@Value("${sap.passwd}")
|
||||||
|
private String passwd;
|
||||||
|
|
||||||
|
@Value("${sap.lang}")
|
||||||
|
private String lang;
|
||||||
|
|
||||||
|
@Value("${sap.pool_capacity}")
|
||||||
|
private String pool_capacity;
|
||||||
|
|
||||||
|
@Value("${sap.peak_limit}")
|
||||||
|
private String peak_limit;
|
||||||
|
|
||||||
|
@Value("${sap.saprouter}")
|
||||||
|
private String saprouter;
|
||||||
|
|
||||||
|
private static final String ABAP_AS_POOLED = "ABAP_AS_WITH_POOL";
|
||||||
|
@Bean
|
||||||
|
public void CreateABAP(){
|
||||||
|
|
||||||
|
Properties connectProperties = new Properties();
|
||||||
|
connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, ashost);
|
||||||
|
connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, sysnr);
|
||||||
|
connectProperties.setProperty(DestinationDataProvider.JCO_USER, user);
|
||||||
|
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, passwd);
|
||||||
|
connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, client);
|
||||||
|
connectProperties.setProperty(DestinationDataProvider.JCO_LANG, lang);
|
||||||
|
connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT,peak_limit);
|
||||||
|
connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY,pool_capacity);
|
||||||
|
connectProperties.setProperty(DestinationDataProvider.JCO_SAPROUTER,saprouter);
|
||||||
|
createDataFile(ABAP_AS_POOLED,"jcoDestination",connectProperties);
|
||||||
|
}
|
||||||
|
private static void createDataFile(String name, String suffix, Properties properties) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
File cfg = new File(name + "." + suffix);
|
||||||
|
if (cfg.exists()) {
|
||||||
|
cfg.deleteOnExit();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
FileOutputStream fos = new FileOutputStream(cfg,false);
|
||||||
|
properties.store(fos, "for test only!");
|
||||||
|
} catch (Exception e) {
|
||||||
|
// TODO: handle exception
|
||||||
|
// System.out.println("Create Data file fault,error msg:" + e.toString());
|
||||||
|
throw new RuntimeException("无法创建目标文件" + cfg.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
package com.op.scada.config;
|
||||||
|
|
||||||
|
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty;
|
||||||
|
import com.op.common.core.domain.R;
|
||||||
|
import com.op.common.datasource.creator.DynamicDatasourceCreator;
|
||||||
|
import com.op.system.api.RemoteUserService;
|
||||||
|
import com.op.system.api.domain.SysUser;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化动态数据源
|
||||||
|
*
|
||||||
|
* @ClassName: DynamicDatasource
|
||||||
|
* @Description: TODO
|
||||||
|
* @author shichangzhou
|
||||||
|
* @date 2023年4月19日 下午1:01:30
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class DynamicDatasource {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private DynamicDatasourceCreator dynamicDatasourceCreator;
|
||||||
|
@Autowired
|
||||||
|
private RemoteUserService remoteUserService;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void init() {
|
||||||
|
// 加载sf-cloud库的sys_datasource
|
||||||
|
SysUser sysUser = new SysUser();
|
||||||
|
sysUser.setUserId(1L);
|
||||||
|
R<List<Map<String, String>>> dateSources0 = remoteUserService.getPoolNameList(sysUser);
|
||||||
|
List<Map<String, String>> dateSources = dateSources0.getData();
|
||||||
|
for (Map<String, String> dateSource : dateSources) {
|
||||||
|
DataSourceProperty sdp = new DataSourceProperty();
|
||||||
|
sdp.setUrl(dateSource.get("url"));
|
||||||
|
sdp.setUsername(dateSource.get("userName"));
|
||||||
|
sdp.setPassword(dateSource.get("password"));
|
||||||
|
sdp.setDriverClassName(dateSource.get("driveClassName"));
|
||||||
|
sdp.setPoolName(dateSource.get("poolName"));// 这是数据源的key
|
||||||
|
sdp.setLazy(false);
|
||||||
|
dynamicDatasourceCreator.createDynamicDataSource(sdp);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue