SAP模块同步生产订单接口

highway
Yangwl 1 year ago
parent 49e1a80e02
commit 39e071022d

@ -0,0 +1,100 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.op</groupId>
<artifactId>op-modules</artifactId>
<version>0.0.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>op-modules-sap</artifactId>
<description>
op-modules-sap系统模块
</description>
<dependencies>
<!-- SpringCloud Alibaba Nacos -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- SpringCloud Alibaba Nacos Config -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!-- SpringCloud Alibaba Sentinel -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<!-- SpringBoot Actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- Swagger UI -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger.fox.version}</version>
</dependency>
<!-- Mysql Connector -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- OP Common DataSource -->
<dependency>
<groupId>com.op</groupId>
<artifactId>op-common-datasource</artifactId>
</dependency>
<!-- OP Common DataScope -->
<dependency>
<groupId>com.op</groupId>
<artifactId>op-common-datascope</artifactId>
</dependency>
<!-- OP Common Log -->
<dependency>
<groupId>com.op</groupId>
<artifactId>op-common-log</artifactId>
</dependency>
<!-- OP Common Swagger -->
<dependency>
<groupId>com.op</groupId>
<artifactId>op-common-swagger</artifactId>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,23 @@
package com.op.mes;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import com.op.common.security.annotation.EnableCustomConfig;
import com.op.common.security.annotation.EnableRyFeignClients;
import com.op.common.swagger.annotation.EnableCustomSwagger2;
/**
*
*
* @author OP
*/
@EnableCustomConfig
@EnableCustomSwagger2
@EnableRyFeignClients
@SpringBootApplication
public class SapApplication {
public static void main(String[] args) {
SpringApplication.run(SapApplication.class, args);
System.err.println("Sap服务启动成功");
}
}

@ -0,0 +1,80 @@
package com.op.mes.util;
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 java.io.File;
import java.io.FileOutputStream;
import java.util.Properties;
public class SAPConnUtils {
private static final String ABAP_AS_POOLED = "ABAP_AS_WITH_POOL";
/**
* SAP
* @param name ABAP
* @param suffix
* @param properties
*/
private static void createDataFile(String name, String suffix, Properties properties){
File cfg = new File(name+"."+suffix);
if(cfg.exists()){
cfg.deleteOnExit();
}
try{
FileOutputStream fos = new FileOutputStream(cfg, false);
properties.store(fos, "for tests only !");
fos.close();
}catch (Exception e){
System.out.println("Create Data file fault, error msg: " + e.toString());
throw new RuntimeException("Unable to create the destination file " + cfg.getName(), e);
}
}
/**
* SAP
*/
private static void initProperties(SapConn sapConn) {
Properties connectProperties = new Properties();
// SAP服务器
connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, sapConn.getJCO_ASHOST());
// SAP系统编号
connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, sapConn.getJCO_SYSNR());
// SAP集团
connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, sapConn.getJCO_CLIENT());
// SAP用户名
connectProperties.setProperty(DestinationDataProvider.JCO_USER, sapConn.getJCO_USER());
// SAP密码
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, sapConn.getJCO_PASSWD());
// SAP登录语言
connectProperties.setProperty(DestinationDataProvider.JCO_LANG, sapConn.getJCO_LANG());
// 最大连接数
connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, sapConn.getJCO_POOL_CAPACITY());
// 最大连接线程
connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, sapConn.getJCO_PEAK_LIMIT());
// SAP ROUTER
connectProperties.setProperty(DestinationDataProvider.JCO_SAPROUTER, sapConn.getJCO_SAPROUTER());
createDataFile(ABAP_AS_POOLED, "jcoDestination", connectProperties);
}
/**
* SAP
* @return SAP
*/
public static JCoDestination connect(SapConn sapConn){
System.out.println("正在连接至SAP...");
JCoDestination destination = null;
initProperties(sapConn);
try {
destination = JCoDestinationManager.getDestination(ABAP_AS_POOLED);
destination.ping();
System.out.println("已成功建立sap的连接");
} catch (JCoException e) {
System.out.println("Connect SAP fault, error msg: " + e.toString());
}
return destination;
}
}

@ -0,0 +1,125 @@
package com.op.mes.util;
public class SapConn {
// SAP服务器
private String JCO_ASHOST;
// SAP系统编号
private String JCO_SYSNR;
// SAP集团
private String JCO_CLIENT;
// SAP用户名
private String JCO_USER;
// SAP密码
private String JCO_PASSWD;
// SAP登录语言
private String JCO_LANG;
// 最大连接数
private String JCO_POOL_CAPACITY;
// 最大连接线程
private String JCO_PEAK_LIMIT;
// SAP ROUTER
private String JCO_SAPROUTER;
public SapConn(String JCO_ASHOST, String JCO_SYSNR, String JCO_CLIENT, String JCO_USER,
String JCO_PASSWD, String JCO_LANG, String JCO_POOL_CAPACITY, String JCO_PEAK_LIMIT,
String JCO_SAPROUTER) {
this.JCO_ASHOST = JCO_ASHOST;
this.JCO_SYSNR = JCO_SYSNR;
this.JCO_CLIENT = JCO_CLIENT;
this.JCO_USER = JCO_USER;
this.JCO_PASSWD = JCO_PASSWD;
this.JCO_LANG = JCO_LANG;
this.JCO_POOL_CAPACITY = JCO_POOL_CAPACITY;
this.JCO_PEAK_LIMIT = JCO_PEAK_LIMIT;
this.JCO_SAPROUTER = JCO_SAPROUTER;
}
public SapConn() {}
public String getJCO_ASHOST() {
return JCO_ASHOST;
}
public void setJCO_ASHOST(String JCO_ASHOST) {
this.JCO_ASHOST = JCO_ASHOST;
}
public String getJCO_SYSNR() {
return JCO_SYSNR;
}
public void setJCO_SYSNR(String JCO_SYSNR) {
this.JCO_SYSNR = JCO_SYSNR;
}
public String getJCO_CLIENT() {
return JCO_CLIENT;
}
public void setJCO_CLIENT(String JCO_CLIENT) {
this.JCO_CLIENT = JCO_CLIENT;
}
public String getJCO_USER() {
return JCO_USER;
}
public void setJCO_USER(String JCO_USER) {
this.JCO_USER = JCO_USER;
}
public String getJCO_PASSWD() {
return JCO_PASSWD;
}
public void setJCO_PASSWD(String JCO_PASSWD) {
this.JCO_PASSWD = JCO_PASSWD;
}
public String getJCO_LANG() {
return JCO_LANG;
}
public void setJCO_LANG(String JCO_LANG) {
this.JCO_LANG = JCO_LANG;
}
public String getJCO_POOL_CAPACITY() {
return JCO_POOL_CAPACITY;
}
public void setJCO_POOL_CAPACITY(String JCO_POOL_CAPACITY) {
this.JCO_POOL_CAPACITY = JCO_POOL_CAPACITY;
}
public String getJCO_PEAK_LIMIT() {
return JCO_PEAK_LIMIT;
}
public void setJCO_PEAK_LIMIT(String JCO_PEAK_LIMIT) {
this.JCO_PEAK_LIMIT = JCO_PEAK_LIMIT;
}
public String getJCO_SAPROUTER() {
return JCO_SAPROUTER;
}
public void setJCO_SAPROUTER(String JCO_SAPROUTER) {
this.JCO_SAPROUTER = JCO_SAPROUTER;
}
@Override
public String toString() {
return "SapConn{" +
"JCO_ASHOST='" + JCO_ASHOST + '\'' +
", JCO_SYSNR='" + JCO_SYSNR + '\'' +
", JCO_CLIENT='" + JCO_CLIENT + '\'' +
", JCO_USER='" + JCO_USER + '\'' +
", JCO_PASSWD='" + JCO_PASSWD + '\'' +
", JCO_LANG='" + JCO_LANG + '\'' +
", JCO_POOL_CAPACITY='" + JCO_POOL_CAPACITY + '\'' +
", JCO_PEAK_LIMIT='" + JCO_PEAK_LIMIT + '\'' +
", JCO_SAPROUTER='" + JCO_SAPROUTER + '\'' +
'}';
}
}

@ -0,0 +1,106 @@
package com.op.mes.util;
import com.sap.conn.jco.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Configuration
public class SapConnConfig {
static List<Map<String, Object>> returnList = new ArrayList<Map<String, Object>>();
static JCoFunction function;
@Value("${sap.ashost}")
public String ashost;
@Value("${sap.sysnr}")
public String sysnr;
@Value("${sap.client}")
public String client;
@Value("${sap.user}")
public String user;
@Value("${sap.passwd}")
public String passwd;
@Value("${sap.lang}")
public String lang;
@Value("${sap.pool_capacity}")
public String pool_capacity;
@Value("${sap.peak_limit}")
public String peak_limit;
@Value("${sap.saprouter}")
public String saprouter;
@Bean
public void SapConn() {
SapConn con = new SapConn(
ashost,
sysnr,
client,
user,
passwd,
lang,
pool_capacity,
peak_limit,
saprouter
);
// 连接
JCoDestination jCoDestination = SAPConnUtils.connect(con);
RfcTest(jCoDestination);
}
public static List<Map<String, Object>> RfcTest(JCoDestination jCoDestination){
try {
// 获取调用 RFC 函数对象
JCoFunction func = jCoDestination.getRepository().getFunction("ZPPR_MES_PRO_TO");
// 配置传入参数
JCoParameterList importParameterList = func.getImportParameterList();
//importParameterList.setValue("S_AUFNR",001002125255 );
// 调用并获取返回值
func.execute(jCoDestination);
// 获取 内表 - ZMES_PRO
JCoTable maraTable = func.getTableParameterList().getTable("ZMES_PRO");
JCoRecordMetaData metaData = maraTable.getRecordMetaData();
System.out.println("###"+metaData.toString());
// 循环输出 Table 数据
for (int i = 0; i < maraTable.getNumRows(); i++) {
maraTable.setRow(i);
String AUFNR = maraTable.getString("AUFNR");
String AUART = maraTable.getString("AUART");
String MAUFNR = maraTable.getString("MAUFNR");
String PLNBEZ = maraTable.getString("PLNBEZ");
String MAKTX = maraTable.getString("MAKTX");
String PWERK = maraTable.getString("PWERK");
String GAMNG = maraTable.getString("GAMNG");
String GMEIN = maraTable.getString("GMEIN");
String PLNNR = maraTable.getString("PLNNR");
String GSTRP = maraTable.getString("GSTRP");
String GLTRP = maraTable.getString("GLTRP");
String ERNAM = maraTable.getString("ERNAM");
String ERDAT = maraTable.getString("ERDAT");
String STTXT = maraTable.getString("STTXT");
// System.out.println("物料编号:" + matnr + " - 创建日期:" + esdra + " - 创建人:" + ernam + " - 物料组:" + matkl + " - 单位:" + meins);
System.out.println("订单号:" +AUFNR+" - 订单类型:" + AUART+ " - 上级订单编号:" + MAUFNR+ " - 物料号:" + PLNBEZ+ " - 物料描述(短文本):" + MAKTX
+ " - 订单的计划工厂:" + PWERK+ " - 订单数量总计:" + GAMNG+ " - 基本计量单位:" + GMEIN+ " - 任务清单组码:" + PLNNR+ " - 基本开始日期:" + GSTRP
+ " - 基本完成日期:" + GLTRP+ " - 输入者:" + ERNAM+ " - 创建日期:" + ERDAT+ " - 系统状态:" + STTXT);
}
} catch (Exception e) {
e.printStackTrace();
}
return returnList;
}
}

@ -0,0 +1,10 @@
Spring Boot Version: ${spring-boot.version}
Spring Application Name: ${spring.application.name}
____ _____ _____ _____
/ __ \| __ \ / ____| /\ | __ \
| | | | |__) |____| (___ / \ | |__) |
| | | | ___/______\___ \ / /\ \ | ___/
| |__| | | ____) / ____ \| |
\____/|_| |_____/_/ \_\_|

@ -0,0 +1,31 @@
# Tomcat
server:
port: 9205
# Spring
spring:
application:
# 应用名称
name: op-sap
profiles:
# 环境配置
active: dev
cloud:
nacos:
discovery:
namespace: haiwei-test
group: ywl
# 服务注册地址
server-addr: 140.249.53.142:8848
config:
namespace: haiwei-test
group: ywl
#命名空间
#group: local
# 配置中心地址
server-addr: 140.249.53.142:8848
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<!-- 日志存放路径 -->
<property name="log.path" value="logs/op-system" />
<!-- 日志输出格式 -->
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n" />
<!-- 控制台输出 -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
</appender>
<!-- 系统日志输出 -->
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/info.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>INFO</level>
<!-- 匹配时的操作:接收(记录) -->
<onMatch>ACCEPT</onMatch>
<!-- 不匹配时的操作:拒绝(不记录) -->
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/error.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>ERROR</level>
<!-- 匹配时的操作:接收(记录) -->
<onMatch>ACCEPT</onMatch>
<!-- 不匹配时的操作:拒绝(不记录) -->
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- 系统模块日志级别控制 -->
<logger name="com.op" level="info" />
<!-- Spring日志级别控制 -->
<logger name="org.springframework" level="warn" />
<root level="info">
<appender-ref ref="console" />
</root>
<!--系统操作日志-->
<root level="info">
<appender-ref ref="file_info" />
<appender-ref ref="file_error" />
</root>
</configuration>

@ -15,6 +15,7 @@
<module>op-file</module>
<module>op-mes</module>
<module>op-wms</module>
<module>op-sap</module>
</modules>
<artifactId>op-modules</artifactId>

Loading…
Cancel
Save