|
@@ -2,6 +2,8 @@ package cn.iocoder.yudao.module.pms.sap;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.ObjUtil;
|
|
|
+import cn.iocoder.yudao.module.pms.sap.service.IotSapService;
|
|
|
+import cn.iocoder.yudao.module.pms.sap.vo.IotSapMaterialVO;
|
|
|
import cn.iocoder.yudao.module.system.api.saporg.SapOrgApi;
|
|
|
import cn.iocoder.yudao.module.system.api.saporg.dto.SapOrgRespDTO;
|
|
|
import com.sap.conn.jco.*;
|
|
@@ -13,6 +15,7 @@ import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -25,6 +28,8 @@ public class SapController {
|
|
|
private SapConnector sapConnector;
|
|
|
@Autowired
|
|
|
private SapOrgApi sapOrgApi;
|
|
|
+ @Autowired
|
|
|
+ private IotSapService iotSapService;
|
|
|
|
|
|
@GetMapping("/callSapStock")
|
|
|
@Operation(summary = "同步sap 库存接口")
|
|
@@ -181,9 +186,19 @@ public class SapController {
|
|
|
});
|
|
|
}
|
|
|
if (otItabTable != null && otItabTable.getNumRows() > 0) {
|
|
|
+ List<IotSapMaterialVO> sapMaterials = new ArrayList<>();
|
|
|
for (int i = 0; i < otItabTable.getNumRows(); i++) {
|
|
|
otItabTable.setRow(i);
|
|
|
- System.out.println(String.format("行号 %d: 物料编码=%s, 物料描述=%s, 物料类型=%s, 物料类型描述=%s, 物料组=%s, 物料组描述=%s, 集团级的DF=%s\n",
|
|
|
+ IotSapMaterialVO tempMaterial = new IotSapMaterialVO();
|
|
|
+ tempMaterial.setMATNR(otItabTable.getString("MATNR"));
|
|
|
+ tempMaterial.setMAKTX(otItabTable.getString("MAKTX"));
|
|
|
+ tempMaterial.setMTART(otItabTable.getString("MTART"));
|
|
|
+ tempMaterial.setMTBEZ(otItabTable.getString("MTBEZ"));
|
|
|
+ tempMaterial.setMATKL(otItabTable.getString("MATKL"));
|
|
|
+ tempMaterial.setWGBEZ(otItabTable.getString("WGBEZ"));
|
|
|
+ tempMaterial.setLVORM(otItabTable.getString("LVORM"));
|
|
|
+ sapMaterials.add(tempMaterial);
|
|
|
+ /* System.out.println(String.format("行号 %d: 物料编码=%s, 物料描述=%s, 物料类型=%s, 物料类型描述=%s, 物料组=%s, 物料组描述=%s, 集团级的DF=%s\n",
|
|
|
i,
|
|
|
otItabTable.getString("MATNR"), // 物料编码
|
|
|
otItabTable.getString("MAKTX"), // 物料描述
|
|
@@ -192,8 +207,9 @@ public class SapController {
|
|
|
otItabTable.getString("MATKL"), // 物料组
|
|
|
otItabTable.getString("WGBEZ"), // 物料组描述
|
|
|
otItabTable.getString("LVORM") // 集团级的DF
|
|
|
- ));
|
|
|
+ )); */
|
|
|
}
|
|
|
+ iotSapService.processMaterials(sapMaterials);
|
|
|
}
|
|
|
return "Material Info: " + output.getString("OT_ITAB");
|
|
|
} catch (JCoException e) {
|
|
@@ -201,8 +217,64 @@ public class SapController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @GetMapping("/callSapMaterialMasterDatas")
|
|
|
+ @Operation(summary = "同步sap 物料主数据接口")
|
|
|
+ public String callSapMaterialMasterDatas() {
|
|
|
+ //
|
|
|
+ try {
|
|
|
+ JCoDestination destination = sapConnector.getDestination();
|
|
|
+ JCoFunction function = destination.getRepository().getFunction("BAPI_MATERIAL_GETLIST");
|
|
|
+
|
|
|
+ // 设置输入参数
|
|
|
+ /* JCoParameterList input = function.getImportParameterList();
|
|
|
+ input.setValue("IV_LAEDA", ""); // 上次更改的日期
|
|
|
+ input.setValue("IV_MATNR", ""); // 物料编号
|
|
|
+ input.setValue("IV_MAKTX", ""); // 物料描述 */
|
|
|
+
|
|
|
+ // JCoTable materialRange = function.getTableParameterList().getTable("MATNR_RANGE");
|
|
|
+ function.getImportParameterList().setValue("MATERIAL_TYPE", "ALL");
|
|
|
+ // 执行 RFC 调用
|
|
|
+ function.execute(destination);
|
|
|
+
|
|
|
+ // JCoParameterList returnParams = function.getExportParameterList();
|
|
|
+ // String returnType = returnParams.getString("RETURN_TYPE");
|
|
|
+ // String returnMessage = returnParams.getString("RETURN_MESSAGE");
|
|
|
+
|
|
|
+ /* if ("E".equals(returnType) || "A".equals(returnType)) {
|
|
|
+ throw new RuntimeException("SAP调用错误: " + returnMessage);
|
|
|
+ } */
|
|
|
+ List<SapMaterial> materialList = new ArrayList<>();
|
|
|
+ // 处理返回的物料列表
|
|
|
+ JCoTable materialTable = function.getTableParameterList().getTable("RETURN");
|
|
|
+ for (int i = 0; i < materialTable.getNumRows(); i++) {
|
|
|
+ materialTable.setRow(i);
|
|
|
+
|
|
|
+ SapMaterial material = new SapMaterial();
|
|
|
+ material.setMaterialNumber(materialTable.getString("MATERIAL"));
|
|
|
+ material.setMaterialDescription(materialTable.getString("MATL_DESC"));
|
|
|
+ material.setMaterialType(materialTable.getString("MATL_TYPE"));
|
|
|
+ material.setPlant(materialTable.getString("PLANT"));
|
|
|
+ material.setBaseUnit(materialTable.getString("BASE_UOM"));
|
|
|
+ material.setIndustrySector(materialTable.getString("INDUSTRY"));
|
|
|
+
|
|
|
+ materialList.add(material);
|
|
|
+ System.out.println("物料编码:" + material.getMaterialNumber());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 释放资源
|
|
|
+ function.getTableParameterList().getTable("MATLIST").clear();
|
|
|
+
|
|
|
+ // 获取输出参数
|
|
|
+ JCoParameterList output = function.getTableParameterList();
|
|
|
+
|
|
|
+ return "Material Info: " + output.getString("OT_ITAB");
|
|
|
+ } catch (JCoException e) {
|
|
|
+ return "Error calling SAP Material Master Data: " + e.getMessage();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
- * 查询所有SAP工厂
|
|
|
+ * 查询所有 SAP 工厂
|
|
|
*/
|
|
|
private List<String> factoryCodes(){
|
|
|
List<SapOrgRespDTO> sapOrgs = sapOrgApi.getSapOrgByType(1);
|
|
@@ -214,4 +286,75 @@ public class SapController {
|
|
|
.collect(Collectors.toList());
|
|
|
return CollUtil.isEmpty(factoryCodes) ? CollUtil.empty(String.class) : factoryCodes;
|
|
|
}
|
|
|
+
|
|
|
+ // 物料数据模型类
|
|
|
+ public static class SapMaterial {
|
|
|
+ private String materialNumber;
|
|
|
+ private String materialDescription;
|
|
|
+ private String materialType;
|
|
|
+ private String plant;
|
|
|
+ private String baseUnit;
|
|
|
+ private String industrySector;
|
|
|
+
|
|
|
+ // Getters and Setters
|
|
|
+ public String getMaterialNumber() {
|
|
|
+ return materialNumber;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setMaterialNumber(String materialNumber) {
|
|
|
+ this.materialNumber = materialNumber;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getMaterialDescription() {
|
|
|
+ return materialDescription;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setMaterialDescription(String materialDescription) {
|
|
|
+ this.materialDescription = materialDescription;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getMaterialType() {
|
|
|
+ return materialType;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setMaterialType(String materialType) {
|
|
|
+ this.materialType = materialType;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getPlant() {
|
|
|
+ return plant;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setPlant(String plant) {
|
|
|
+ this.plant = plant;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getBaseUnit() {
|
|
|
+ return baseUnit;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setBaseUnit(String baseUnit) {
|
|
|
+ this.baseUnit = baseUnit;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getIndustrySector() {
|
|
|
+ return industrySector;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setIndustrySector(String industrySector) {
|
|
|
+ this.industrySector = industrySector;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String toString() {
|
|
|
+ return "SapMaterial{" +
|
|
|
+ "materialNumber='" + materialNumber + '\'' +
|
|
|
+ ", materialDescription='" + materialDescription + '\'' +
|
|
|
+ ", materialType='" + materialType + '\'' +
|
|
|
+ ", plant='" + plant + '\'' +
|
|
|
+ ", baseUnit='" + baseUnit + '\'' +
|
|
|
+ ", industrySector='" + industrySector + '\'' +
|
|
|
+ '}';
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|