SAP订单同步接口增加工厂参数、修改MES连接SAP工具类。删除多余文件。

highway
Yangwl 1 year ago
parent d6e558f422
commit 63d00b8a45

@ -6,6 +6,15 @@ public class SapShopOrderQuery {
private String aufnr; private String aufnr;
private String matnr; private String matnr;
private String erdat; private String erdat;
private String werk;
public String getWerk() {
return werk;
}
public void setWerk(String werk) {
this.werk = werk;
}
public String getAufnr() { public String getAufnr() {
return aufnr; return aufnr;

@ -18,6 +18,14 @@ import com.op.common.swagger.annotation.EnableCustomSwagger2;
public class SapApplication { public class SapApplication {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(SapApplication.class, args); SpringApplication.run(SapApplication.class, args);
System.err.println("Sap服务启动成功"); System.err.println("Sap服务启动成功\n" +
" ███████ ███████ ████████ ██ ███████\n" +
" ██░░░░░██ ░██░░░░██ ██░░░░░░ ████ ░██░░░░██\n" +
" ██ ░░██░██ ░██ ░██ ██░░██ ░██ ░██\n" +
"░██ ░██░███████ █████░█████████ ██ ░░██ ░███████\n" +
"░██ ░██░██░░░░ ░░░░░ ░░░░░░░░██ ██████████░██░░░░\n" +
"░░██ ██ ░██ ░██░██░░░░░░██░██\n" +
" ░░███████ ░██ ████████ ░██ ░██░██\n" +
" ░░░░░░░ ░░ ░░░░░░░░ ░░ ░░ ░░");
} }
} }

@ -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,5 +1,6 @@
package com.op.sap.service.impl; package com.op.sap.service.impl;
import com.op.common.core.constant.Constants;
import com.op.common.core.domain.R; import com.op.common.core.domain.R;
import com.op.common.core.utils.DateUtils; import com.op.common.core.utils.DateUtils;
import com.op.common.core.utils.StringUtils; import com.op.common.core.utils.StringUtils;
@ -38,30 +39,42 @@ public class SapOrderServiceImpl implements SapOrderService {
throw new RuntimeException("Function does not exist in SAP"); throw new RuntimeException("Function does not exist in SAP");
} }
JCoParameterList jCoParameterList= func.getTableParameterList();
JCoParameterList js= func.getExportParameterList();
System.out.println(js);
System.out.println(jCoParameterList);
// 配置传入参数 // 配置传入参数
// S_AUFNR订单号 S_MATNR物料号 S_ERDAT(创建日期) 例如20230923 // S_WERKS(工厂) S_AUFNR订单号 S_MATNR物料号 S_ERDAT(创建日期) 例如20230923
if (!StringUtils.isNull(sapShopOrderQuery.getWerk())){
JCoTable S_WERKS = func.getTableParameterList().getTable("S_WERKS");
S_WERKS.appendRow();
S_WERKS.setValue(Constants.SIGN, "I");
S_WERKS.setValue(Constants.OPTION, "EQ");
S_WERKS.setValue(Constants.LOW, sapShopOrderQuery.getWerk());
}
if (!StringUtils.isNull(sapShopOrderQuery.getAufnr())){ if (!StringUtils.isNull(sapShopOrderQuery.getAufnr())){
JCoTable S_AUFNR = func.getTableParameterList().getTable("S_AUFNR"); JCoTable S_AUFNR = func.getTableParameterList().getTable("S_AUFNR");
S_AUFNR.appendRow(); S_AUFNR.appendRow();
S_AUFNR.setValue("SIGN", "I"); S_AUFNR.setValue(Constants.SIGN, "I");
S_AUFNR.setValue("OPTION", "EQ"); S_AUFNR.setValue(Constants.OPTION, "EQ");
S_AUFNR.setValue("LOW", sapShopOrderQuery.getAufnr()); S_AUFNR.setValue(Constants.LOW, sapShopOrderQuery.getAufnr());
} }
if (!StringUtils.isNull(sapShopOrderQuery.getMatnr())){ if (!StringUtils.isNull(sapShopOrderQuery.getMatnr())){
JCoTable S_MATNR = func.getTableParameterList().getTable("S_MATNR"); JCoTable S_MATNR = func.getTableParameterList().getTable("S_MATNR");
S_MATNR.appendRow(); S_MATNR.appendRow();
S_MATNR.setValue("SIGN", "I"); S_MATNR.setValue(Constants.SIGN, "I");
S_MATNR.setValue("OPTION", "EQ"); S_MATNR.setValue(Constants.OPTION, "EQ");
S_MATNR.setValue("LOW",sapShopOrderQuery.getMatnr()); S_MATNR.setValue(Constants.LOW,sapShopOrderQuery.getMatnr());
} }
if (!StringUtils.isNull(sapShopOrderQuery.getErdat())){ if (!StringUtils.isNull(sapShopOrderQuery.getErdat())){
JCoTable S_ERDAT = func.getTableParameterList().getTable("S_ERDAT"); JCoTable S_ERDAT = func.getTableParameterList().getTable("S_ERDAT");
S_ERDAT.appendRow(); S_ERDAT.appendRow();
S_ERDAT.setValue("SIGN", "I"); S_ERDAT.setValue(Constants.SIGN, "I");
S_ERDAT.setValue("OPTION", "BT"); S_ERDAT.setValue(Constants.OPTION, "BT");
S_ERDAT.setValue("LOW", sapShopOrderQuery.getErdat()); S_ERDAT.setValue(Constants.LOW, sapShopOrderQuery.getErdat());
S_ERDAT.setValue("HIGH", END_DATE); S_ERDAT.setValue(Constants.HIGH, END_DATE);
} }

@ -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,87 +1,12 @@
package com.op.sap.util; package com.op.sap.util;
import com.op.sap.domain.SapConn;
import com.sap.conn.jco.JCoDestination; import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoDestinationManager; import com.sap.conn.jco.JCoDestinationManager;
import com.sap.conn.jco.JCoException; import com.sap.conn.jco.JCoException;
import com.sap.conn.jco.ext.DestinationDataProvider;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import java.io.File;
import java.io.FileOutputStream;
import java.util.Properties;
public class SAPConnUtils { public class SAPConnUtils {
//
// @Value("${sap.sysnr}")
// public static String sysnr;
//
// @Value("${sap.client}")
// public static String client;
//
// @Value("${sap.user}")
// public static String user;
//
// @Value("${sap.passwd}")
// public static String passwd;
//
// @Value("${sap.lang}")
// public static String lang;
//
// @Value("${sap.pool_capacity}")
// public static String pool_capacity;
//
// @Value("${sap.peak_limit}")
// public static String peak_limit;
//
// @Value("${sap.saprouter}")
// public static String saprouter;
private static final String ABAP_AS_POOLED = "ABAP_AS_WITH_POOL"; private static final String ABAP_AS_POOLED = "ABAP_AS_WITH_POOL";
static {
Properties connectProperties = new Properties();
connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "192.168.0.54");
connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, "00");
connectProperties.setProperty(DestinationDataProvider.JCO_USER, "MES");
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "123456");
connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "800");
connectProperties.setProperty(DestinationDataProvider.JCO_LANG, "zh");
connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT,"20");
connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY,"true");
connectProperties.setProperty(DestinationDataProvider.JCO_SAPROUTER,"");
createDataFile(ABAP_AS_POOLED,"jcoDestination",connectProperties);
}
/**
* SAP
* @param name
* ABAP
* @param suffix
*
* @param properties
*
*/
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());
}
}
public static JCoDestination connect() { public static JCoDestination connect() {
JCoDestination destination = null; JCoDestination destination = null;
try { try {

@ -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…
Cancel
Save