SAP订单同步接口增加工厂参数、修改MES连接SAP工具类。删除多余文件。
parent
d6e558f422
commit
63d00b8a45
@ -1,49 +0,0 @@
|
|||||||
package com.op.sap.config;
|
|
||||||
|
|
||||||
import com.sap.conn.jco.ext.DataProviderException;
|
|
||||||
import com.sap.conn.jco.ext.DestinationDataEventListener;
|
|
||||||
import com.sap.conn.jco.ext.DestinationDataProvider;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
public class DestinationDataProviderImpl implements DestinationDataProvider {
|
|
||||||
/**
|
|
||||||
* DestinationDataProvider is of type interface.
|
|
||||||
* We define DestinationDataProviderImpl class to implements this interface
|
|
||||||
* so that we can define the SAP connection parameters more flexibly,
|
|
||||||
* not just in xxx.jcodestionation file.
|
|
||||||
*
|
|
||||||
* The point is that we override getDestinationProperties() method.
|
|
||||||
* Afterwards, instance of DestinationDataProvider should be registered
|
|
||||||
* using Environment.registerDestinationDataProvider() method to take effect
|
|
||||||
*/
|
|
||||||
|
|
||||||
private Map provider = new HashMap();
|
|
||||||
@Override
|
|
||||||
public Properties getDestinationProperties(String destName) throws DataProviderException {
|
|
||||||
if (destName == null){
|
|
||||||
throw new NullPointerException("Destination name is empty.");
|
|
||||||
}
|
|
||||||
if (provider.size() == 0){
|
|
||||||
throw new IllegalStateException("Data provider is empty.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return (Properties) provider.get(destName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean supportsEvents() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setDestinationDataEventListener(DestinationDataEventListener destinationDataEventListener) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addDestinationProps(String destName, Properties props){
|
|
||||||
provider.put(destName, props);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,73 +1,74 @@
|
|||||||
package com.op.sap.config;
|
package com.op.sap.config;
|
||||||
|
|
||||||
import com.sap.conn.jco.JCoDestination;
|
|
||||||
import com.sap.conn.jco.JCoDestinationManager;
|
|
||||||
import com.sap.conn.jco.JCoException;
|
|
||||||
import com.sap.conn.jco.ext.DestinationDataProvider;
|
import com.sap.conn.jco.ext.DestinationDataProvider;
|
||||||
import com.sap.conn.jco.ext.Environment;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
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;
|
import java.util.Properties;
|
||||||
|
|
||||||
public class DestinationManager {
|
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class DestinationManager {
|
||||||
@Value("${sap.ashost}")
|
@Value("${sap.ashost}")
|
||||||
public static String ashost;
|
private String ashost;
|
||||||
|
|
||||||
@Value("${sap.sysnr}")
|
@Value("${sap.sysnr}")
|
||||||
public static String sysnr;
|
private String sysnr;
|
||||||
|
|
||||||
@Value("${sap.client}")
|
@Value("${sap.client}")
|
||||||
public static String client;
|
private String client;
|
||||||
|
|
||||||
@Value("${sap.user}")
|
@Value("${sap.user}")
|
||||||
public static String user;
|
private String user;
|
||||||
|
|
||||||
@Value("${sap.passwd}")
|
@Value("${sap.passwd}")
|
||||||
public static String passwd;
|
private String passwd;
|
||||||
|
|
||||||
@Value("${sap.lang}")
|
@Value("${sap.lang}")
|
||||||
public static String lang;
|
private String lang;
|
||||||
|
|
||||||
@Value("${sap.pool_capacity}")
|
@Value("${sap.pool_capacity}")
|
||||||
public static String pool_capacity;
|
private String pool_capacity;
|
||||||
|
|
||||||
@Value("${sap.peak_limit}")
|
@Value("${sap.peak_limit}")
|
||||||
public static String peak_limit;
|
private String peak_limit;
|
||||||
|
|
||||||
@Value("${sap.saprouter}")
|
@Value("${sap.saprouter}")
|
||||||
public static String saprouter;
|
private String saprouter;
|
||||||
|
|
||||||
private static Properties setProperties(String destName)
|
private static final String ABAP_AS_POOLED = "ABAP_AS_WITH_POOL";
|
||||||
{
|
@Bean
|
||||||
// SAP connection parameters and other properties
|
public void CreateABAP(){
|
||||||
Properties props = new Properties();
|
|
||||||
|
Properties connectProperties = new Properties();
|
||||||
if (destName == "SAP_AS") {
|
connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, ashost);
|
||||||
props.setProperty(DestinationDataProvider.JCO_ASHOST, ashost);
|
connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, sysnr);
|
||||||
props.setProperty(DestinationDataProvider.JCO_SYSNR, sysnr);
|
connectProperties.setProperty(DestinationDataProvider.JCO_USER, user);
|
||||||
props.setProperty(DestinationDataProvider.JCO_USER, user);
|
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, passwd);
|
||||||
props.setProperty(DestinationDataProvider.JCO_PASSWD, passwd);
|
connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, client);
|
||||||
props.setProperty(DestinationDataProvider.JCO_CLIENT, client);
|
connectProperties.setProperty(DestinationDataProvider.JCO_LANG, lang);
|
||||||
props.setProperty(DestinationDataProvider.JCO_LANG, lang);
|
connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT,peak_limit);
|
||||||
props.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT,peak_limit);
|
connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY,pool_capacity);
|
||||||
props.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY,pool_capacity);
|
connectProperties.setProperty(DestinationDataProvider.JCO_SAPROUTER,saprouter);
|
||||||
props.setProperty(DestinationDataProvider.JCO_SAPROUTER,saprouter);
|
createDataFile(ABAP_AS_POOLED,"jcoDestination",connectProperties);
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return props;
|
|
||||||
}
|
}
|
||||||
|
private static void createDataFile(String name, String suffix, Properties properties) {
|
||||||
public static JCoDestination getDestination (String destName) throws JCoException {
|
// TODO Auto-generated method stub
|
||||||
Properties props = setProperties(destName);
|
File cfg = new File(name + "." + suffix);
|
||||||
|
if (cfg.exists()) {
|
||||||
DestinationDataProviderImpl providerImpl = new DestinationDataProviderImpl();
|
cfg.deleteOnExit();
|
||||||
providerImpl.addDestinationProps(destName, props);
|
}
|
||||||
|
try {
|
||||||
Environment.registerDestinationDataProvider(providerImpl);
|
FileOutputStream fos = new FileOutputStream(cfg,false);
|
||||||
|
properties.store(fos, "for test only!");
|
||||||
JCoDestination dest = JCoDestinationManager.getDestination(destName);
|
} catch (Exception e) {
|
||||||
return dest;
|
// TODO: handle exception
|
||||||
|
// System.out.println("Create Data file fault,error msg:" + e.toString());
|
||||||
|
throw new RuntimeException("无法创建目标文件" + cfg.getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
package com.op.sap.util;
|
|
||||||
|
|
||||||
import com.sap.conn.jco.JCoField;
|
|
||||||
import com.sap.conn.jco.JCoRecordMetaData;
|
|
||||||
import com.sap.conn.jco.JCoTable;
|
|
||||||
|
|
||||||
public class JCoUtils {
|
|
||||||
public static void printJCoTable(JCoTable jcoTable)
|
|
||||||
{
|
|
||||||
// header
|
|
||||||
|
|
||||||
// JCoRecordMeataData is the meta data of either a structure or a table.
|
|
||||||
// Each element describes a field of the structure or table.
|
|
||||||
JCoRecordMetaData tableMeta = jcoTable.getRecordMetaData();
|
|
||||||
for(int i = 0; i < tableMeta.getFieldCount(); i++){
|
|
||||||
System.out.print(String.format("%s\t", tableMeta.getName(i)));
|
|
||||||
}
|
|
||||||
System.out.println(); // new line
|
|
||||||
|
|
||||||
// line items
|
|
||||||
|
|
||||||
for(int i = 0; i < jcoTable.getNumRows(); i++){
|
|
||||||
// Sets the row pointer to the specified position(beginning from zero)
|
|
||||||
jcoTable.setRow(i);
|
|
||||||
|
|
||||||
// Each line is of type JCoStructure
|
|
||||||
for(JCoField fld : jcoTable){
|
|
||||||
System.out.print(String.format("%s\t", fld.getValue()));
|
|
||||||
}
|
|
||||||
System.out.println();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,10 +1,11 @@
|
|||||||
Spring Boot Version: ${spring-boot.version}
|
Spring Boot Version: ${spring-boot.version}
|
||||||
Spring Application Name: ${spring.application.name}
|
Spring Application Name: ${spring.application.name}
|
||||||
_
|
|
||||||
| |
|
███████ ███████ ████████ ██ ███████
|
||||||
___ _ __ ______ ___ _ _ ___| |_ ___ _ __ ___
|
██░░░░░██ ░██░░░░██ ██░░░░░░ ████ ░██░░░░██
|
||||||
/ _ \| '_ \______/ __| | | / __| __/ _ \ '_ ` _ \
|
██ ░░██░██ ░██ ░██ ██░░██ ░██ ░██
|
||||||
| (_) | |_) | \__ \ |_| \__ \ || __/ | | | | |
|
░██ ░██░███████ █████░█████████ ██ ░░██ ░███████
|
||||||
\___/| .__/ |___/\__, |___/\__\___|_| |_| |_|
|
░██ ░██░██░░░░ ░░░░░ ░░░░░░░░██ ██████████░██░░░░
|
||||||
| | __/ |
|
░░██ ██ ░██ ░██░██░░░░░░██░██
|
||||||
|_| |___/
|
░░███████ ░██ ████████ ░██ ░██░██
|
||||||
|
░░░░░░░ ░░ ░░░░░░░░ ░░ ░░ ░░
|
||||||
|
Loading…
Reference in New Issue