SAP模块提交订单同步操作

highway
Yangwl 2 years ago
parent 6b0292d505
commit 7aefee6af8

@ -17,12 +17,14 @@ import java.util.List;
* @author OP
*/
@FeignClient(contextId = "remotePlanService", value = ServiceNameConstants.PLAN_SERVICE, fallbackFactory = RemotePlanFallbackFactory.class)
public interface RemotePlanService {
@PostMapping("/order/sapAddOrder")
public R<Boolean> sapAddOrder(@RequestBody SapProOrder sapProOrder);
/**
* SAP
* @param proOrderList
* @return
*/
@PostMapping("/order/shopOrderSync")
public R<Boolean> shopOrderSync(List<SapProOrder> proOrderList);
}

@ -0,0 +1,14 @@
package com.op.system.api;
import com.op.common.core.domain.R;
import com.op.system.api.model.SapProOrder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.List;
public interface RemoteSapService {
@PostMapping("/sap/shopOrderSync")
public R<List<SapProOrder>> shopOrderSync();
}

@ -25,10 +25,9 @@ public class RemotePlanFallbackFactory implements FallbackFactory<RemotePlanServ
log.error("Plan服务调用失败:{}", throwable.getMessage());
return new RemotePlanService() {
@Override
public R<Boolean> sapAddOrder(SapProOrder sapProOrder) {
return R.fail("新增SAP订单失败:" + throwable.getMessage());
public R<Boolean> shopOrderSync(List<SapProOrder> proOrderList) {
return R.fail("PLAN服务新增SAP订单失败:" + throwable.getMessage());
}
};
}
}

@ -0,0 +1,24 @@
package com.op.system.api.factory;
import com.op.common.core.domain.R;
import com.op.system.api.RemoteSapService;
import com.op.system.api.model.SapProOrder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import java.util.List;
public class RemoteSapFallbackFactory implements FallbackFactory<RemoteSapService> {
private static final Logger log = LoggerFactory.getLogger(RemoteSapFallbackFactory.class);
@Override
public RemoteSapService create(Throwable throwable) {
log.error("SAP服务调用失败:{}", throwable.getMessage());
return new RemoteSapService() {
@Override
public R<List<SapProOrder>> shopOrderSync() {
return R.fail("SAP服务获取SAP订单失败:" + throwable.getMessage());
}
};
}
}

@ -4,3 +4,4 @@ com.op.system.api.factory.RemoteFileFallbackFactory
com.op.system.api.factory.RemoteMesFallbackFactory
com.op.system.api.factory.RemotePlanFallbackFactory
com.op.system.api.factory.RemoteTechnologyFallbackFactory
com.op.system.api.factory.RemoteSapFallbackFactory

@ -2,7 +2,7 @@ package com.op.common.log.enums;
/**
*
*
*
* @author OP
*/
public enum BusinessType {
@ -55,4 +55,9 @@ public enum BusinessType {
*
*/
CLEAN,
/**
* SAP
*/
SAP,
}

@ -1,246 +0,0 @@
package com.op.job.task;
import com.op.common.core.utils.uuid.IdUtils;
import com.op.job.domain.SapConn;
import com.op.job.util.SAPConnUtils;
import com.op.system.api.RemoteMesService;
import com.op.system.api.RemoteUserService;
import com.op.system.api.model.SapProOrder;
import com.sap.conn.jco.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Component("sapTask")
public class SapTask {
static List<Map<String, Object>> returnList = new ArrayList<Map<String, Object>>();
@Autowired
private RemoteMesService remoteMesService;
@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;
public void sapSyncTask() {
System.out.println("执行SAP订单同步方法");
// 连接
SapConn con = new SapConn(
ashost,
sysnr,
client,
user,
passwd,
lang,
pool_capacity,
peak_limit,
saprouter
);
JCoDestination jCoDestination = SAPConnUtils.connect(con);
//获取SAP订单数据
RfcTest(jCoDestination);
}
public void maraSyncTask(){
}
public static void main(String[] args) throws JCoException {
System.out.println("执行BOM同步方法");
// 连接
SapConn con = new SapConn(
"192.168.0.53",
"00",
"800",
"MES",
"123456",
"zh",
"true",
"20",
""
);
JCoDestination jCoDestination = SAPConnUtils.connect(con);
//获取BOM数据
//获取调用 RFC 函数对象
JCoFunction func = jCoDestination.getRepository().getFunction("ZPPR_MES_BOM");
// 配置传入参数
JCoParameterList importParameterList = func.getImportParameterList();
// importParameterList.setValue("S_WERKS","1000");
// 调用并获取返回值
func.execute(jCoDestination);
// 获取 内表 - ZMES_PRO
JCoTable bomTable = func.getTableParameterList().getTable("LT_BOM");
JCoRecordMetaData metaData = bomTable.getRecordMetaData();
System.out.println("###"+metaData.toString());
System.out.println("###"+bomTable.getNumRows());
for (int i = 0; i < bomTable.getNumRows(); i++) {
bomTable.setRow(i);
String MATNR = bomTable.getString("MATNR");
String MAKTX = bomTable.getString("MAKTX");
String WERKS = bomTable.getString("WERKS");
String VERID = bomTable.getString("VERID");
String STLNR = bomTable.getString("STLNR");
System.out.println("物料编码:" +MATNR+" - 物料名称:" + MAKTX+" - 工厂:" + WERKS+" - 生产版本:" + VERID+" - BOM单号" + STLNR);
}
}
// public static void main(String[] arg) throws JCoException {
// System.out.println("执行同步方法");
// // 连接
// SapConn con = new SapConn(
// "192.168.0.53",
// "00",
// "800",
// "MES",
// "123456",
// "zh",
// "true",
// "20",
// ""
// );
// JCoDestination jCoDestination = SAPConnUtils.connect(con);
// //获取SAP订单数据
// // 获取调用 RFC 函数对象
// JCoFunction func = jCoDestination.getRepository().getFunction("ZMMR_MES_MAT_GET");
//
// // 配置传入参数
// JCoParameterList importParameterList = func.getImportParameterList();
// importParameterList.setValue("S_MATNR","000000000000000019" );
//
// // 调用并获取返回值
// func.execute(jCoDestination);
// // 获取 内表 - ZMES_PRO
// JCoTable bomTable = func.getTableParameterList().getTable("LT_MARA");
// JCoRecordMetaData metaData = bomTable.getRecordMetaData();
// System.out.println("###"+metaData.toString());
// System.out.println("###"+bomTable.getNumRows());
// for (int i = 0; i < bomTable.getNumRows(); i++) {
// String MATNR = bomTable.getString("MATNR");
// String MAKTX = bomTable.getString("MAKTX");
//// String WERKS = bomTable.getString("WERKS");
//// String VERID = bomTable.getString("VERID");
//// String STLNR = bomTable.getString("STLNR");
// System.out.println("物料号:" +MATNR+" - 物料描述:" + MAKTX);
// }
// }
public 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());
SapProOrder proOrder=new SapProOrder();
List<SapProOrder> proOrderList=new ArrayList<>();
// 循环输出 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("订单号:" +AUFNR+" - 订单类型:" + AUART+ " - 上级订单编号:" + MAUFNR+ " - 物料号:" + PLNBEZ+ " - 物料描述(短文本):" + MAKTX
+ " - 订单的计划工厂:" + PWERK+ " - 订单数量总计:" + GAMNG+ " - 基本计量单位:" + GMEIN+ " - 任务清单组码:" + PLNNR+ " - 基本开始日期:" + GSTRP
+ " - 基本完成日期:" + GLTRP+ " - 输入者:" + ERNAM+ " - 创建日期:" + ERDAT+ " - 系统状态:" + STTXT);
proOrder.setId(IdUtils.fastSimpleUUID());
proOrder.setPlanFactoryCode(PWERK);
proOrder.setOrderCode(AUFNR);
proOrder.setOrderType(AUART);
proOrder.setProdCode(PLNBEZ);
proOrder.setProdDesc(MAKTX);
proOrder.setQuantity(Long.parseLong(GAMNG.substring(0,GAMNG.indexOf("."))));
proOrder.setUnit(GMEIN);
proOrder.setWorkerOrder(PLNNR);
proOrder.setPlanProDate(dateparse(GSTRP));
proOrder.setPlanComplete(dateparse(GLTRP));
proOrder.setParentOrder(MAUFNR);
proOrder.setCreateBy(ERNAM);
proOrder.setCreateTime(dateparse(ERDAT));
proOrder.setUpdateBy(ERNAM);
proOrder.setUpdateTime(dateparse(ERDAT));
proOrder.setStatus("0");
// proOrderList.add(proOrder);
// System.out.println("物料编号:" + matnr + " - 创建日期:" + esdra + " - 创建人:" + ernam + " - 物料组:" + matkl + " - 单位:" + meins);
remoteMesService.sapAddOrder(proOrder);
}
} catch (Exception e) {
e.printStackTrace();
}
return returnList;
}
private static Date dateparse(String date) throws ParseException {
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
Date sfdate = sf.parse(date);
return sfdate;
}
}

@ -130,25 +130,21 @@ public class ProOrderController extends BaseController {
public AjaxResult add(@RequestBody ProOrder proOrder) {
return toAjax(proOrderService.insertProOrder(proOrder));
}
/**
*
* SAP
* @param proOrderList
* @return
*/
@Log(title = "批量保存SAP生产订单", businessType = BusinessType.INSERT)
@PostMapping("/sapAddOrder")
public R<Boolean> sapAddOrder(@RequestBody ProOrder proOrder) {
try {
if (proOrder!=null){
proOrderService.insertSapProOrder(proOrder);
}
}catch (Exception e){
return R.fail(e.getMessage());
}
return R.ok();
@Log(title = "同步SAP订单", businessType = BusinessType.INSERT)
@PostMapping("/shopOrderSync")
public void shopOrderSync(List<ProOrder> proOrderList) {
proOrderService.shopOrderSync(proOrderList);
}
/**
*
*/

@ -47,12 +47,6 @@ public interface IProOrderService {
*/
public int insertProOrder(ProOrder proOrder);
/**
* SAP
* @param proOrder
* @return
*/
public int insertSapProOrder(ProOrder proOrder);
/**
*
@ -108,4 +102,12 @@ public interface IProOrderService {
* @return
*/
public AjaxResult getOrderList(String id);
/**
* SAP
* @param proOrderList
*/
void shopOrderSync(List<ProOrder> proOrderList);
}

@ -2,11 +2,15 @@ package com.op.plan.service.impl;
import java.util.*;
import com.alibaba.csp.sentinel.util.StringUtil;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import com.op.common.core.context.SecurityContextHolder;
import com.op.common.core.exception.CheckedException;
import com.op.common.core.utils.DateUtils;
import com.op.common.core.utils.uuid.IdUtils;
import com.op.common.core.web.domain.AjaxResult;
import com.op.common.log.enums.BusinessType;
import com.op.plan.domain.*;
import com.op.plan.domain.dto.ProOrderDTO;
import com.op.plan.domain.dto.SplitOrderDTO;
@ -194,6 +198,21 @@ public class ProOrderServiceImpl implements IProOrderService {
return success(proOrder);
}
@Override
public void shopOrderSync(List<ProOrder> proOrderList) {
for (ProOrder proOrder:proOrderList) {
String shopOrder = proOrder.getOrderCode();
if (StringUtil.isBlank(shopOrder)) {
throw new CheckedException("订单号不能为空!");
}
if (StringUtil.isBlank(proOrder.getStatus())) {
throw new CheckedException("订单号不能为空!");
}
}
}
/**
*
*
@ -277,10 +296,7 @@ public class ProOrderServiceImpl implements IProOrderService {
return proOrderMapper.insertProOrder(proOrder);
}
@Override
public int insertSapProOrder(ProOrder proOrder) {
return 0;
}
/**
*
@ -470,4 +486,6 @@ public class ProOrderServiceImpl implements IProOrderService {
return 1;
}
}
}

@ -1,5 +1,46 @@
package com.op.sap.controller;
import com.op.common.core.domain.R;
import com.op.common.log.annotation.Log;
import com.op.common.log.enums.BusinessType;
import com.op.sap.service.SapService;
import com.op.system.api.model.SapProOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/sap")
public class SapController {
@Autowired
private SapService sapService;
/**
* SAP
* @return
*/
@PostMapping("/shopOrderSync")
@Log(title = "同步SAP订单", businessType = BusinessType.SAP)
public List<SapProOrder> shopOrderSync(){
return sapService.shopOrderSync();
}
/**
*
* @return
*/
@PostMapping("saveItem")
public R<Boolean> saveItem(){
return sapService.sapItem();
}
@PostMapping("saveBom")
public R<Boolean> saveBom(){
return sapService.sapBom();
}
}

@ -0,0 +1,125 @@
package com.op.sap.domain;
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,19 @@
package com.op.sap.service;
import com.op.common.core.domain.R;
import com.op.system.api.model.SapProOrder;
import java.util.List;
public interface SapService {
R<Boolean> sapItem();
R<Boolean> sapBom();
List<SapProOrder> shopOrderSync();
}

@ -0,0 +1,284 @@
package com.op.sap.service.impl;
import com.op.common.core.domain.R;
import com.op.common.core.utils.DateUtils;
import com.op.common.core.utils.http.HttpUtils;
import com.op.common.core.utils.uuid.IdUtils;
import com.op.sap.domain.SapConn;
import com.op.sap.service.SapService;
import com.op.sap.util.SAPConnUtils;
import com.op.system.api.RemoteMesService;
import com.op.system.api.RemotePlanService;
import com.op.system.api.model.SapProOrder;
import com.sap.conn.jco.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class SapServiceImpl implements SapService {
@Autowired
private RemotePlanService remotePlanService;
@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;
@Override
public List<SapProOrder> shopOrderSync() {
// 连接
SapConn con = new SapConn(
ashost,
sysnr,
client,
user,
passwd,
lang,
pool_capacity,
peak_limit,
saprouter
);
JCoDestination jCoDestination = SAPConnUtils.connect(con);
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());
SapProOrder proOrder=new SapProOrder();
List<SapProOrder> proOrderList=new ArrayList<>();
// 循环输出 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("订单号:" +AUFNR+" - 订单类型:" + AUART+ " - 上级订单编号:" + MAUFNR+ " - 物料号:" + PLNBEZ+ " - 物料描述(短文本):" + MAKTX
+ " - 订单的计划工厂:" + PWERK+ " - 订单数量总计:" + GAMNG+ " - 基本计量单位:" + GMEIN+ " - 任务清单组码:" + PLNNR+ " - 基本开始日期:" + GSTRP
+ " - 基本完成日期:" + GLTRP+ " - 输入者:" + ERNAM+ " - 创建日期:" + ERDAT+ " - 系统状态:" + STTXT);
proOrder.setId(IdUtils.fastSimpleUUID());
proOrder.setPlanFactoryCode(PWERK);
proOrder.setOrderCode(AUFNR);
proOrder.setOrderType(AUART);
proOrder.setProdCode(PLNBEZ);
proOrder.setProdDesc(MAKTX);
proOrder.setQuantity(Long.parseLong(GAMNG.substring(0,GAMNG.indexOf("."))));
proOrder.setUnit(GMEIN);
proOrder.setWorkerOrder(PLNNR);
proOrder.setPlanProDate(DateUtils.dateTime("yyyy-MM-dd",GSTRP));
proOrder.setPlanComplete(DateUtils.dateTime("yyyy-MM-dd",GLTRP));
proOrder.setParentOrder(MAUFNR);
proOrder.setCreateBy(ERNAM);
proOrder.setCreateTime(DateUtils.dateTime("yyyy-MM-dd",ERDAT));
proOrder.setUpdateBy(ERNAM);
proOrder.setUpdateTime(DateUtils.dateTime("yyyy-MM-dd",ERDAT));
proOrder.setStatus("0");
proOrderList.add(proOrder);
// remotePlanService.sapAddOrder(proOrder);
// remoteMesService.sapAddOrder(proOrder);
}
return proOrderList;
} catch (Exception e) {
return null;
}
}
@Override
public R<Boolean> sapItem() {
// 连接
SapConn con = new SapConn(
ashost,
sysnr,
client,
user,
passwd,
lang,
pool_capacity,
peak_limit,
saprouter
);
JCoDestination jCoDestination = SAPConnUtils.connect(con);
try {
// 获取调用 RFC 函数对象
JCoFunction func = jCoDestination.getRepository().getFunction("ZMMR_MES_MAT_GET");
// 配置传入参数
JCoParameterList importParameterList = func.getImportParameterList();
//importParameterList.setValue("S_AUFNR",001002125255 );
// 调用并获取返回值
func.execute(jCoDestination);
// 获取 内表 - ZMES_PRO
JCoTable maraTable = func.getTableParameterList().getTable("LT_MARA");
JCoRecordMetaData metaData = maraTable.getRecordMetaData();
System.out.println("###"+metaData.toString());
SapProOrder proOrder=new SapProOrder();
List<SapProOrder> proOrderList=new ArrayList<>();
// 循环输出 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");
}
} catch (Exception e) {
return R.fail(e.getMessage());
}
return R.ok();
}
@Override
public R<Boolean> sapBom() {
SapConn con = new SapConn(
ashost,
sysnr,
client,
user,
passwd,
lang,
pool_capacity,
peak_limit,
saprouter
);
JCoDestination jCoDestination = SAPConnUtils.connect(con);
try {
// 获取调用 RFC 函数对象
JCoFunction func = jCoDestination.getRepository().getFunction("ZMMR_MES_MAT_GET");
// 配置传入参数
JCoParameterList importParameterList = func.getImportParameterList();
//importParameterList.setValue("S_AUFNR",001002125255 );
// 调用并获取返回值
func.execute(jCoDestination);
// 获取 内表 - ZMES_PRO
JCoTable maraTable = func.getTableParameterList().getTable("LT_MARA");
JCoRecordMetaData metaData = maraTable.getRecordMetaData();
System.out.println("###"+metaData.toString());
SapProOrder proOrder=new SapProOrder();
List<SapProOrder> proOrderList=new ArrayList<>();
// 循环输出 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");
}
} catch (Exception e) {
return R.fail(e.getMessage());
}
return R.ok();
}
public static void main(String[] args) throws JCoException {
// 连接
SapConn con = new SapConn(
"192.168.0.53",
"00",
"800",
"MES",
"123456",
"zh",
"true",
"20",
""
);
JCoDestination jCoDestination = SAPConnUtils.connect(con);
// 获取调用 RFC 函数对象
JCoFunction func = jCoDestination.getRepository().getFunction("ZMMR_MES_MAT_GET");
// 配置传入参数
JCoParameterList importParameterList = func.getImportParameterList();
// importParameterList.setValue("S_ERDAT","2019-11-07" );
// 调用并获取返回值
func.execute(jCoDestination);
// 获取 内表 - ZMES_PRO
JCoTable maraTable = func.getTableParameterList().getTable("LT_MARA");
JCoRecordMetaData metaData = maraTable.getRecordMetaData();
System.out.println("###" + metaData.toString());
SapProOrder proOrder = new SapProOrder();
List<SapProOrder> proOrderList = new ArrayList<>();
// 循环输出 Table 数据
for (int i = 0; i < maraTable.getNumRows(); i++) {
maraTable.setRow(i);
String MATNR = maraTable.getString("MATNR");
String MAKTX = maraTable.getString("MAKTX");
String EAN11 = maraTable.getString("EAN11");
String MTART = maraTable.getString("MTART");
String MTBEZ = maraTable.getString("MTBEZ");
String MATKL = maraTable.getString("MATKL");
String WGBEZ = maraTable.getString("WGBEZ");
String BRGEW = maraTable.getString("BRGEW");
String NTGEW = maraTable.getString("NTGEW");
String VOLUM = maraTable.getString("VOLUM");
String VOLEH = maraTable.getString("VOLEH");
String MEINS = maraTable.getString("MEINS");
String MEINH = maraTable.getString("MEINH");
String UMREZ = maraTable.getString("UMREZ");
String UMREN = maraTable.getString("UMREN");
String LVORM = maraTable.getString("LVORM");
String MENGE = maraTable.getString("MENGE");
String MHDHB = maraTable.getString("MHDHB");
String SPART = maraTable.getString("SPART");
String SPART_NM = maraTable.getString("SPART_NM");
String MVGR1 = maraTable.getString("MVGR1");
String MVGR1_NM = maraTable.getString("MVGR1_NM");
String MVGR2 = maraTable.getString("MVGR2");
String MVGR2_NM = maraTable.getString("MVGR2_NM");
String MVGR3 = maraTable.getString("MVGR3");
String MVGR3_NM = maraTable.getString("MVGR3_NM");
String MVGR4 = maraTable.getString("MVGR4");
String MVGR4_NM = maraTable.getString("MVGR4_NM");
String MVGR5 = maraTable.getString("MVGR5");
String MVGR5_NM = maraTable.getString("MVGR5_NM");
System.out.println("物料号:" + MATNR + " - 物料描述:" + MAKTX + " - 国际文件号(EAN/UPC)" + EAN11 + " - 物料类型:" + MTART );
}
}
}

@ -0,0 +1,85 @@
package com.op.sap.util;
import com.op.sap.domain.SapConn;
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;
}
}
Loading…
Cancel
Save