From 068ebcfcabb9e4ea74bcddaafab1e66232e7fc8a Mon Sep 17 00:00:00 2001 From: zhangherong <571457620@qq.com> Date: 星期二, 29 七月 2025 18:24:30 +0800 Subject: [PATCH] art: SAP-同步生产订单接口测试 --- src/main/java/org/jeecg/modules/sap/controller/SAPTestController.java | 10 ++ src/main/java/org/jeecg/modules/sap/FunctionConst.java | 16 ++++ src/main/java/org/jeecg/modules/sap/dto/ProductionOrderDTO.java | 55 +++++++++++++ src/main/java/org/jeecg/modules/sap/service/ProductionOrderSync.java | 8 ++ src/main/java/org/jeecg/modules/sap/service/impl/ProductionOrderSyncImpl.java | 115 ++++++++++++++++++++++++++++ 5 files changed, 204 insertions(+), 0 deletions(-) diff --git a/src/main/java/org/jeecg/modules/sap/FunctionConst.java b/src/main/java/org/jeecg/modules/sap/FunctionConst.java new file mode 100644 index 0000000..3126ff1 --- /dev/null +++ b/src/main/java/org/jeecg/modules/sap/FunctionConst.java @@ -0,0 +1,16 @@ +package org.jeecg.modules.sap; + +public class FunctionConst { + //1.鐢熶骇璁㈠崟鍚屾鎺ュ彛 + public static String ZPPF_033_1 = "ZPPF_033_1"; + //2.璁㈠崟BOM鍚屾鎺ュ彛 + public static String ZPPF_033_3 = "ZPPF_033_3"; + //3.浜у搧宸ュ簭鍚屾鎺ュ彛 + public static String ZPPF_033_2 = "ZPPF_033_2"; + //4.鐢熶骇璁㈠崟宸ュ簭鎶ュ伐鎺ュ彛銆佺敓浜ц鍗曞叆搴撱�佷笉鍚堟牸鍝佸鐞� + public static String ZMES_PRODORDCONF_CREATE_TT2301 = "ZMES_PRODORDCONF_CREATE_TT2301"; + //5.鐢熶骇璁㈠崟鎶曟枡鎺ュ彛 + public static String ZMES_GOODSMVT_CREATE_2301 = "ZMES_GOODSMVT_CREATE_2301"; + //6.鐢熶骇璁㈠崟鍏抽棴鎺ュ彛 + public static String ZPPF_019 = "ZPPF_019"; +} diff --git a/src/main/java/org/jeecg/modules/sap/controller/SAPTestController.java b/src/main/java/org/jeecg/modules/sap/controller/SAPTestController.java index d563780..c51bd9c 100644 --- a/src/main/java/org/jeecg/modules/sap/controller/SAPTestController.java +++ b/src/main/java/org/jeecg/modules/sap/controller/SAPTestController.java @@ -4,6 +4,7 @@ import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.jeecg.common.api.vo.Result; +import org.jeecg.modules.sap.service.ProductionOrderSync; import org.jeecg.modules.sap.service.SAPService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -17,6 +18,8 @@ public class SAPTestController { @Autowired private SAPService sapService; + @Autowired + private ProductionOrderSync productionOrderSync; @ApiOperation(value = "SAP闆嗘垚娴嬭瘯-娴嬭瘯鎺ュ彛", notes = "SAP闆嗘垚娴嬭瘯-娴嬭瘯鎺ュ彛") @GetMapping("/test") @@ -24,4 +27,11 @@ String test = sapService.test(); return Result.ok(test); } + + @ApiOperation(value = "SAP闆嗘垚娴嬭瘯-娴嬭瘯鎺ュ彛", notes = "SAP闆嗘垚娴嬭瘯-娴嬭瘯鎺ュ彛") + @GetMapping("/syncProductionOrder") + public Result<?> syncProductionOrder() { + productionOrderSync.syncProductionOrder(); + return Result.ok(); + } } diff --git a/src/main/java/org/jeecg/modules/sap/dto/ProductionOrderDTO.java b/src/main/java/org/jeecg/modules/sap/dto/ProductionOrderDTO.java new file mode 100644 index 0000000..baef85c --- /dev/null +++ b/src/main/java/org/jeecg/modules/sap/dto/ProductionOrderDTO.java @@ -0,0 +1,55 @@ +package org.jeecg.modules.sap.dto; + +import lombok.Data; + +@Data +public class ProductionOrderDTO { + /** 閿�鍞鍗曡椤� */ + private String KDPOS; + /** 鎵瑰彿 */ + private String CHARG; + /** 鐗╂枡鎻忚堪锛堢煭鏂囨湰锛� */ + private String MAKTX; + /** 鐗╂枡鍙� */ + private String MATNR; + /** 閿�鍞鍗曞彿 */ + private String KDAUF; + /** 璁㈠崟鍙� */ + private String AUFNR; + /** 璁㈠崟绫诲瀷 */ + private String DAUAT; + /** 璁㈠崟鏁伴噺鎬昏 */ + private String GAMNG; + /** 鍩烘湰璁¢噺鍗曚綅 */ + private String GMEIN; + /** 璁㈠崟浼樺厛绾� */ + private String APRIO; + /** 璁㈠崟涓伐搴忕殑宸ヨ壓璺嚎鍙� */ + private String AUFPL; + /** 鐗╂枡鍗� */ + private String STLNR; + /** 宸ュ巶 */ + private String DWERK; + /** 鍚嶇О */ + private String NAME1; + /** 鐢熶骇绠$悊鍛� */ + private String FEVOR; + /** 鐢熶骇璋冨害鍛樻弿杩� */ + private String TXT; + /** 淇敼鏂囨。涓殑涓汉璐熻矗鐨勭敤鎴峰悕 */ + private String USNAM; + /** 鍒涘缓淇敼鏂囨。鐨勬暟鎹� */ + private String UDATE; + /** 涓婃鏇存敼鐨勬棩鏈� */ + private String LAEDA; + /** 鏃堕棿宸叉洿鏀� */ + private String TIMES; + /** 瀵硅薄鐨勫崟涓姸鎬� (鐭璮orm) */ + private String TXT04; + /** 瀵硅薄鐘舵�� */ + private String TXT30; + /** 璁㈠崟寮�濮嬫棩鏈� */ + private String GSTRP; + /** 鍩烘湰瀹屾垚鏃ユ湡 */ + private String GLTRP; +} diff --git a/src/main/java/org/jeecg/modules/sap/service/ProductionOrderSync.java b/src/main/java/org/jeecg/modules/sap/service/ProductionOrderSync.java new file mode 100644 index 0000000..8373a02 --- /dev/null +++ b/src/main/java/org/jeecg/modules/sap/service/ProductionOrderSync.java @@ -0,0 +1,8 @@ +package org.jeecg.modules.sap.service; + +public interface ProductionOrderSync { + /** + * 鍚屾鐢熸垚璁㈠崟 + */ + void syncProductionOrder(); +} diff --git a/src/main/java/org/jeecg/modules/sap/service/impl/ProductionOrderSyncImpl.java b/src/main/java/org/jeecg/modules/sap/service/impl/ProductionOrderSyncImpl.java new file mode 100644 index 0000000..ed2c10b --- /dev/null +++ b/src/main/java/org/jeecg/modules/sap/service/impl/ProductionOrderSyncImpl.java @@ -0,0 +1,115 @@ +package org.jeecg.modules.sap.service.impl; + +import com.sap.conn.jco.*; +import lombok.extern.slf4j.Slf4j; +import org.jeecg.config.sap.SapRfcConnectionManager; +import org.jeecg.modules.sap.FunctionConst; +import org.jeecg.modules.sap.dto.ProductionOrderDTO; +import org.jeecg.modules.sap.service.ProductionOrderSync; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +/** + * 鐢熸垚璁㈠崟鍚屾鏈嶅姟 + */ +@Service +@Slf4j +public class ProductionOrderSyncImpl implements ProductionOrderSync { + //鏂扮伀鐐伐鍘傜紪鐮� + private static final String factoryCode = "2301"; + //鏍囧噯鐢熶骇璁㈠崟 + private static final String orderTypeCode1 = "Z001"; + //杩斿伐璁㈠崟 鏆傛椂涓嶇敤 + private static final String orderTypeCode2 = "Z002"; + //鍏垎鍘傝皟搴﹀憳 +// private static final String productionManager = "012"; + private static final String productionManager = "010"; + //鐢熶骇璁㈠崟鐘舵�� CRTD 鏂板缓锛孯EL 涓嬭揪锛孴ECO 鍏抽棴 瀹為檯涓婏紝鍙湁REL鐘舵�佺殑宸ュ崟鎵嶅彲浠ヨ繘琛屾搷浣� + private static final String orderStatus = "REL"; + + @Autowired + private SapRfcConnectionManager connectionManager; + + + @Override + public void syncProductionOrder() { + JCoDestination destination = connectionManager.getDestination(); + try { + JCoRepository repository = destination.getRepository(); + JCoFunction function = repository.getFunction(FunctionConst.ZPPF_033_1); + if (function == null) { + throw new RuntimeException("RFC 鍑芥暟 ZPPF_033_1 鏈壘鍒帮紒"); + } + // 璁剧疆杈撳叆鍙傛暟 + //璁㈠崟鍙锋煡璇㈡潯浠� +// JCoTable AUFNRTable = function.getTableParameterList().getTable("ZTAB_AUFNR"); + //璁㈠崟绫诲瀷 鏍囧噯鐢熶骇璁㈠崟 + JCoTable AUARTTable = function.getTableParameterList().getTable("ZTAB_AUART"); + AUARTTable.appendRow(); + AUARTTable.setValue("AUART", orderTypeCode1); + //鍏垎鍘傝皟搴� + JCoTable FEVORTable = function.getTableParameterList().getTable("ZTAB_FEVOR"); + FEVORTable.appendRow(); + FEVORTable.setValue("FEVOR", productionManager); + //鏂扮伀鐐� + JCoTable WERKSTable = function.getTableParameterList().getTable("ZTAB_WERKS"); + WERKSTable.appendRow(); + WERKSTable.setValue("WERKS", factoryCode); + //璁㈠崟鐘舵�� + JCoTable TXT04Table = function.getTableParameterList().getTable("ZTAB_TXT04"); + TXT04Table.appendRow(); + TXT04Table.setValue("TXT04", orderStatus); + // 鎵ц璋冪敤 + function.execute(destination); + //鑾峰彇杩斿洖缁撴灉 + String zmess = function.getExportParameterList().getValue("ZMESS").toString(); + String ztype = function.getExportParameterList().getValue("ZTYPE").toString();//S 鏍囪瘑 鎴愬姛 + if(!"S".equals(ztype)){ + log.error("鑾峰彇璁㈠崟淇℃伅澶辫触锛孼TYPE={}, ZMESS={}", ztype, zmess); + return; + } + // 鑾峰彇杈撳嚭鍙傛暟 + JCoTable outputTable = function.getTableParameterList().getTable("ZTAB_OUT"); + int numRows = outputTable.getNumRows(); + List<ProductionOrderDTO> resultList = new ArrayList<>(); + ProductionOrderDTO dto; + for (int i = 0; i < numRows; i++) { + outputTable.setRow(i); + dto = new ProductionOrderDTO(); + dto.setKDPOS(outputTable.getString("KDPOS")); + dto.setCHARG(outputTable.getString("CHARG")); + dto.setMAKTX(outputTable.getString("MAKTX")); + dto.setMATNR(outputTable.getString("MATNR")); + dto.setKDAUF(outputTable.getString("KDAUF")); + dto.setAUFNR(outputTable.getString("AUFNR")); + dto.setDAUAT(outputTable.getString("DAUAT")); + dto.setGAMNG(outputTable.getString("GAMNG")); + dto.setGMEIN(outputTable.getString("GMEIN")); + dto.setAPRIO(outputTable.getString("APRIO")); + dto.setAUFPL(outputTable.getString("AUFPL")); + dto.setSTLNR(outputTable.getString("STLNR")); + dto.setDWERK(outputTable.getString("DWERK")); + dto.setNAME1(outputTable.getString("NAME1")); + dto.setFEVOR(outputTable.getString("FEVOR")); + dto.setTXT(outputTable.getString("TXT")); + dto.setUSNAM(outputTable.getString("USNAM")); + dto.setUDATE(outputTable.getString("UDATE")); + dto.setLAEDA(outputTable.getString("LAEDA")); + dto.setTIMES(outputTable.getString("TIMES")); + dto.setTXT04(outputTable.getString("TXT04")); + dto.setTXT30(outputTable.getString("TXT30")); + dto.setGSTRP(outputTable.getString("GSTRP")); + dto.setGLTRP(outputTable.getString("GLTRP")); + + //娣诲姞缁撴灉闆� + resultList.add(dto); + log.info(dto.toString()); + } + } catch (JCoException e) { + log.error(e.getMessage(), e); + } + } +} -- Gitblit v1.9.3