diff --git a/op-modules/op-sap/src/main/java/com/op/sap.rar b/op-modules/op-sap/src/main/java/com/op/sap.rar new file mode 100644 index 00000000..ff9aae69 Binary files /dev/null and b/op-modules/op-sap/src/main/java/com/op/sap.rar differ diff --git a/op-modules/op-sap/src/main/java/com/op/sap/controller/SapController.java b/op-modules/op-sap/src/main/java/com/op/sap/controller/SapController.java index 5ac5b038..62579b68 100644 --- a/op-modules/op-sap/src/main/java/com/op/sap/controller/SapController.java +++ b/op-modules/op-sap/src/main/java/com/op/sap/controller/SapController.java @@ -2,14 +2,10 @@ package com.op.sap.controller; import com.op.common.core.domain.R; import com.op.common.core.web.controller.BaseController; -import com.op.common.core.web.domain.AjaxResult; import com.op.common.log.annotation.Log; import com.op.common.log.enums.BusinessType; -import com.op.sap.service.SapBomService; +import com.op.sap.service.*; -import com.op.sap.service.SapMaterialPreparationService; -import com.op.sap.service.SapOrderService; -import com.op.sap.service.SapRouterService; import com.op.system.api.domain.sap.SapCreateOrder; import com.op.system.api.domain.sap.SapMaterialPreparation; import com.op.system.api.domain.sap.SapRFW; @@ -35,6 +31,12 @@ public class SapController extends BaseController { @Autowired private SapRouterService sapRouterService; + @Autowired + private SapItemSyncService sapItemSyncService; + + @Autowired + private SapWorkCenterService sapWorkCenterService; + /** * 订单同步接口 * @return @@ -49,17 +51,18 @@ public class SapController extends BaseController { * 物料同步接口 * @return */ -// @PostMapping("/itemSync") -// public List itemSync(){ -// return sapService.itemSync(); -// } + @PostMapping("/itemSync") + @Log(title = "同步SAP物料清单", businessType = BusinessType.SAP) + public R itemSync(){ + return sapItemSyncService.itemSync(); + } /** * 物料清单同步接口 * @return */ @PostMapping("/bomSync") - @Log(title = "同步SAP物料清单", businessType = BusinessType.SAP) + @Log(title = "同步SAP物料组件清单", businessType = BusinessType.SAP) public R bomSync(){ return sapBomService.bomSync(); } @@ -99,6 +102,11 @@ public class SapController extends BaseController { return sapOrderService.sapCloseOrder(shopOrder); } + /** + * 报工 + * @param sapRFW + * @return + */ @PostMapping("/sapRFWOrder") @Log(title = "生产订单报工接口", businessType = BusinessType.SAP) public R sapRFWOrder(@RequestBody SapRFW sapRFW){ @@ -106,9 +114,42 @@ public class SapController extends BaseController { } + /** + * 工艺路线同步 + * @return + */ @PostMapping("/sapRouterSync") + @Log(title = "工艺路线同步接口", businessType = BusinessType.SAP) public R sapRouerSync() { return sapRouterService.sapRouterSync(); } + /** + * 工作中心 + */ + @PostMapping("/sapWorkCenterSync") + @Log(title = "工作中心接口", businessType = BusinessType.SAP) + public R sapWorkCenterSync(){ + return sapWorkCenterService.sapWorkCenterSync(); + } + /** + *供应商主数据接口 + */ + @PostMapping("/sapSupplierSync") + @Log(title = "供应商主数据", businessType = BusinessType.SAP) + public R sapSupplierSync(){ + return sapWorkCenterService.sapSupplierSync(); + } + + /** + * 客户主数据接口 + * @return + */ + + @PostMapping("/sapCustomSync") + @Log(title = "客户主数据", businessType = BusinessType.SAP) + public R sapCustomSync(){ + return sapWorkCenterService.sapCustomSync(); + } + } diff --git a/op-modules/op-sap/src/main/java/com/op/sap/domain/SapMaterialPreparation.java b/op-modules/op-sap/src/main/java/com/op/sap/domain/SapMaterialPreparation.java new file mode 100644 index 00000000..2981cdd7 --- /dev/null +++ b/op-modules/op-sap/src/main/java/com/op/sap/domain/SapMaterialPreparation.java @@ -0,0 +1,125 @@ +package com.op.sap.domain; + + +public class SapMaterialPreparation { + //订单号 + private String AUFNR; + //预留/相关需求的项目编号 + private String RSPOS; + //物料号 + private String MATNR; + //物料描述(短文本) + private String MAKTX; + //工厂 + private String WERKS; + //库存地点 + private String LGORT; + //组件的需求日期 + private String BDTER; + //需求量 + private String BDMNG; + //欠料数量 + private String ZQLSL; + //基本计量单位 + private String MEINS; + //标识:反冲 + private String RGEKZ; + //直接采购标识 + private String DBSKZ; + + public String getAUFNR() { + return AUFNR; + } + + public void setAUFNR(String AUFNR) { + this.AUFNR = AUFNR; + } + + public String getRSPOS() { + return RSPOS; + } + + public void setRSPOS(String RSPOS) { + this.RSPOS = RSPOS; + } + + public String getMATNR() { + return MATNR; + } + + public void setMATNR(String MATNR) { + this.MATNR = MATNR; + } + + public String getMAKTX() { + return MAKTX; + } + + public void setMAKTX(String MAKTX) { + this.MAKTX = MAKTX; + } + + public String getWERKS() { + return WERKS; + } + + public void setWERKS(String WERKS) { + this.WERKS = WERKS; + } + + public String getLGORT() { + return LGORT; + } + + public void setLGORT(String LGORT) { + this.LGORT = LGORT; + } + + public String getBDTER() { + return BDTER; + } + + public void setBDTER(String BDTER) { + this.BDTER = BDTER; + } + + public String getBDMNG() { + return BDMNG; + } + + public void setBDMNG(String BDMNG) { + this.BDMNG = BDMNG; + } + + public String getZQLSL() { + return ZQLSL; + } + + public void setZQLSL(String ZQLSL) { + this.ZQLSL = ZQLSL; + } + + public String getMEINS() { + return MEINS; + } + + public void setMEINS(String MEINS) { + this.MEINS = MEINS; + } + + public String getRGEKZ() { + return RGEKZ; + } + + public void setRGEKZ(String RGEKZ) { + this.RGEKZ = RGEKZ; + } + + public String getDBSKZ() { + return DBSKZ; + } + + public void setDBSKZ(String DBSKZ) { + this.DBSKZ = DBSKZ; + } +} diff --git a/op-modules/op-sap/src/main/java/com/op/sap/mapper/SapBomMapper.java b/op-modules/op-sap/src/main/java/com/op/sap/mapper/SapBomMapper.java index 725a9ee9..95e1a4e6 100644 --- a/op-modules/op-sap/src/main/java/com/op/sap/mapper/SapBomMapper.java +++ b/op-modules/op-sap/src/main/java/com/op/sap/mapper/SapBomMapper.java @@ -4,16 +4,20 @@ import com.op.system.api.domain.sap.SapBom; import com.op.system.api.domain.sap.SapBomComponent; import org.apache.ibatis.annotations.Mapper; +import java.util.List; + @Mapper public interface SapBomMapper { /** * 新增BOM物料管理 * - * @param sapBom BOM物料管理 - * @return 结果 */ + List selectBaseBomByBomCode(String bomCode); + public int insertBaseBom(SapBom sapBom); + void insertBaseBomBatch(List sapBomList); + public int insertBasetBomComponent(SapBomComponent sapBomComponent); } diff --git a/op-modules/op-sap/src/main/java/com/op/sap/service/SapBomService.java b/op-modules/op-sap/src/main/java/com/op/sap/service/SapBomService.java index ff1c1cbe..8de4fe3f 100644 --- a/op-modules/op-sap/src/main/java/com/op/sap/service/SapBomService.java +++ b/op-modules/op-sap/src/main/java/com/op/sap/service/SapBomService.java @@ -2,7 +2,10 @@ package com.op.sap.service; import com.op.common.core.domain.R; import com.op.common.core.web.domain.AjaxResult; +import com.op.system.api.domain.sap.SapBom; public interface SapBomService { public R bomSync(); + + SapBom getMaxRevisionBom(String STLNR); } diff --git a/op-modules/op-sap/src/main/java/com/op/sap/service/SapItemSyncService.java b/op-modules/op-sap/src/main/java/com/op/sap/service/SapItemSyncService.java new file mode 100644 index 00000000..1260ae77 --- /dev/null +++ b/op-modules/op-sap/src/main/java/com/op/sap/service/SapItemSyncService.java @@ -0,0 +1,17 @@ +package com.op.sap.service; + +import com.op.common.core.domain.R; + +import java.util.List; + +/** + * 杨万里 2023年8月 + */ +public interface SapItemSyncService { + + /** + * 物料同步 + * @return + */ + R itemSync(); +} diff --git a/op-modules/op-sap/src/main/java/com/op/sap/service/SapOrderService.java b/op-modules/op-sap/src/main/java/com/op/sap/service/SapOrderService.java index bcb7437a..f5dfa4be 100644 --- a/op-modules/op-sap/src/main/java/com/op/sap/service/SapOrderService.java +++ b/op-modules/op-sap/src/main/java/com/op/sap/service/SapOrderService.java @@ -8,12 +8,38 @@ import com.op.system.api.model.SapProOrder; import java.util.List; +/** + * 杨万里 2023年8月 + */ public interface SapOrderService { + /** + * 订单同步 + * @param sapProOrder + * @return + */ R> shopOrderSync(SapProOrder sapProOrder); + + /** + * 订单创建 + * @param sapCreateOrderList + * @return + */ R> SapCreateOrder(List sapCreateOrderList); + /** + * 订单关闭 + * @param shopOrder + * @return + */ + R sapCloseOrder(String shopOrder); + /** + * 订单报工 + * @param sapRFW + * @return + */ + R sapRFWOrder(SapRFW sapRFW); } diff --git a/op-modules/op-sap/src/main/java/com/op/sap/service/SapWorkCenterService.java b/op-modules/op-sap/src/main/java/com/op/sap/service/SapWorkCenterService.java new file mode 100644 index 00000000..db9a72fd --- /dev/null +++ b/op-modules/op-sap/src/main/java/com/op/sap/service/SapWorkCenterService.java @@ -0,0 +1,12 @@ +package com.op.sap.service; + +import com.op.common.core.domain.R; + +public interface SapWorkCenterService { + + R sapWorkCenterSync(); + + R sapSupplierSync(); + + R sapCustomSync(); +} diff --git a/op-modules/op-sap/src/main/java/com/op/sap/service/impl/SapBomServiceImpl.java b/op-modules/op-sap/src/main/java/com/op/sap/service/impl/SapBomServiceImpl.java index 6aca333e..9cfd7cb6 100644 --- a/op-modules/op-sap/src/main/java/com/op/sap/service/impl/SapBomServiceImpl.java +++ b/op-modules/op-sap/src/main/java/com/op/sap/service/impl/SapBomServiceImpl.java @@ -4,7 +4,11 @@ import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder; import com.op.common.core.constant.Constants; import com.op.common.core.domain.R; import com.op.common.core.exception.ServiceException; +import com.op.common.core.utils.DateUtils; +import com.op.common.core.utils.StringUtils; +import com.op.common.core.utils.uuid.IdUtils; import com.op.common.core.web.domain.AjaxResult; +import com.op.sap.util.HandleEnum; import com.op.system.api.domain.sap.SapBom; import com.op.system.api.domain.sap.SapBomComponent; import com.op.sap.mapper.SapBomComponentMapper; @@ -13,14 +17,15 @@ import com.op.sap.service.SapBomService; import com.op.sap.util.SAPConnUtils; import com.sap.conn.jco.*; +import org.apache.ibatis.session.ExecutorType; +import org.apache.ibatis.session.SqlSession; +import org.apache.ibatis.session.SqlSessionFactory; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.TreeSet; +import java.util.*; import java.util.stream.Collectors; @Service @@ -32,6 +37,9 @@ public class SapBomServiceImpl implements SapBomService { @Autowired private SapBomComponentMapper sapBomComponentMapper; + @Autowired + private SqlSessionFactory sqlSessionFactory; + @Override public R bomSync() { @@ -52,10 +60,10 @@ public class SapBomServiceImpl implements SapBomService { // jCoTable.setValue(Constants.LOW, "00012222"); JCoTable jCoTables = func.getTableParameterList().getTable("S_MATNR"); - jCoTables.appendRow(); - jCoTables.setValue(Constants.SIGN, "I"); - jCoTables.setValue(Constants.OPTION, "EQ"); - jCoTables.setValue(Constants.LOW, "000000010101000115"); +// jCoTables.appendRow(); +// jCoTables.setValue(Constants.SIGN, "I"); +// jCoTables.setValue(Constants.OPTION, "EQ"); +// jCoTables.setValue(Constants.LOW, "000000010101000115"); JCoTable S_WERKS_jCoTables = func.getTableParameterList().getTable("S_WERKS"); S_WERKS_jCoTables.appendRow(); @@ -68,15 +76,14 @@ public class SapBomServiceImpl implements SapBomService { JCoTable maraTable = func.getTableParameterList().getTable("LT_BOM"); JCoRecordMetaData metaData = maraTable.getRecordMetaData(); System.out.println("###" + metaData.toString()); - SapBom sapBom = new SapBom(); - SapBomComponent sapBomComponent=new SapBomComponent(); - DynamicDataSourceContextHolder.push("op_xiaolan"); + + + List sapBomList=new ArrayList<>(); + List sapBomComponentList=new ArrayList<>(); + for (int i = 0; i < maraTable.getNumRows(); i++) { maraTable.setRow(i); String STLNR = maraTable.getString("STLNR"); - if (STLNR == null || STLNR.equals("")){ - throw new ServiceException("组件清单码为空"); - } String MATNR = maraTable.getString("MATNR"); String MAKTX = maraTable.getString("MAKTX"); String WERKS = maraTable.getString("WERKS"); @@ -107,40 +114,59 @@ public class SapBomServiceImpl implements SapBomService { String BEIKZ = maraTable.getString("BEIKZ"); String BEIKZ_NM = maraTable.getString("BEIKZ_NM"); String SANKA = maraTable.getString("SANKA"); - System.out.println("物料编码:" + MATNR + - " - 物料名称:" + MAKTX + " - 工厂:" + WERKS + - " - 生产版本:" + VERID + " - BOM单号:" + STLNR - + " - 可选BOM:" + STLAL + " - 创建日期:" + ANDAT + " - 创建者:" + ANNAM + - " - 修改日期:" + AEDAT + " - 修改者:" + AENAM - + " - 生产版本有效期:" + ADATU + " - 生产版本截止日期:" + BDATU + " - BOM计算数量:" + LOSGR + - " - BOM计算单位:" + MEINS + - " - BOM基本数量:" + BMENG + " - BOM基本单位:" + BMEIN + " - BOM层次:" + STUFE + " - 项目编号:" + WEGXX - + " - 组件编码:" + PMATNR + " - 组件名称:" + PMAKTX + " - 组件上层物料名称:" + OJTXB - + " - 标准用量:" + PMENGE + " - 损耗率:" + PAUSCH + " - 损耗额:" + PXHLCE + " - 含损耗用量:" + PMNGKO - + " - 组件数量单位:" + PMEINS + " - 组件采购标志:" + PBESKZ + " - 物料供应标识:" + BEIKZ + " - 物料供应标识:" + BEIKZ_NM - + " - 成本核算标识相关:" + SANKA); -// sapBom.setFactoryCode(WERKS); -// sapBom.setProductionVersion(VERID); -// sapBom.setBomCode(STLNR); -// sapBom.setOptionalBom(STLAL); -// sapBom.setPvvd(DateUtils.dateTime("yyyy-MM-dd", ADATU)); -// sapBom.setPved(DateUtils.dateTime("yyyy-MM-dd", BDATU)); -// sapBom.setBomCalculateNumber(new BigDecimal(LOSGR)); -// sapBom.setBomCalculateUnit(MEINS); -// sapBom.setBomBaseNumber(new BigDecimal(BMENG)); -// sapBom.setBomBaseUnit(BMEIN); -// sapBom.setComponentUnit(PMEINS); -// sapBom.setComponentProFlag(PBESKZ); -// sapBom.setCreateBy(ANNAM); -// // sapBom.setCreateTime(DateUtils.dateTime("yyyy-MM-dd", ANDAT)); -// sapBom.setUpdateBy(AENAM); -// // sapBom.setUpdateTime(DateUtils.dateTime("yyyy-MM-dd", AEDAT)); + String OJMBR = maraTable.getString("OJMBR"); + + if (!StringUtils.isEmpty(STLAL)){ + System.out.println("物料编码:" + MATNR + + " - 物料名称:" + MAKTX + " - 工厂:" + WERKS + + " - 生产版本:" + VERID + " - BOM单号:" + STLNR + + " - 可选BOM:" + STLAL + " - 创建日期:" + ANDAT + " - 创建者:" + ANNAM + + " - 修改日期:" + AEDAT + " - 修改者:" + AENAM + + " - 生产版本有效期:" + ADATU + " - 生产版本截止日期:" + BDATU + " - BOM计算数量:" + LOSGR + + " - BOM计算单位:" + MEINS + + " - BOM基本数量:" + BMENG + " - BOM基本单位:" + BMEIN + " - BOM层次:" + STUFE + " - 项目编号:" + WEGXX + + " - 组件编码:" + PMATNR + " - 组件名称:" + PMAKTX + " - 组件上层物料编码:" + OJMBR+" - 组件上层物料名称:" + OJTXB + + " - 标准用量:" + PMENGE + " - 损耗率:" + PAUSCH + " - 损耗额:" + PXHLCE + " - 含损耗用量:" + PMNGKO + + " - 组件数量单位:" + PMEINS + " - 组件采购标志:" + PBESKZ + " - 物料供应标识:" + BEIKZ + " - 物料供应标识:" + BEIKZ_NM + + " - 成本核算标识相关:" + SANKA); + } + + + + //插入BOM表 + //BomBO + /** + * 查询是否有此BOM清单 + */ + SapBom sapBom = new SapBom(); + sapBom.setFactoryCode(WERKS); + sapBom.setProductionVersion(STLAL); + sapBom.setBomCode(STLNR); + sapBom.setCumc(OJMBR); + sapBom.setComponent(PMATNR); + sapBom.setOptionalBom(STLAL); + sapBom.setPvvd(DateUtils.dateTime("yyyy-MM-dd", ADATU)); + sapBom.setPved(DateUtils.dateTime("yyyy-MM-dd", BDATU)); + sapBom.setBomCalculateNumber(new BigDecimal(LOSGR)); + sapBom.setBomCalculateUnit(MEINS); + sapBom.setBomBaseNumber(new BigDecimal(BMENG)); + sapBom.setBomBaseUnit(BMEIN); + sapBom.setComponentUnit(PMEINS); + sapBom.setComponentProFlag(PBESKZ); + // sapBom.setCurrentVersion(""); + sapBom.setCreateBy(ANNAM); + sapBom.setCreateTime(DateUtils.dateTime("yyyy-MM-dd", ANDAT)); + sapBom.setUpdateBy(AENAM); + sapBom.setUpdateTime(DateUtils.dateTime("yyyy-MM-dd", AEDAT)); + + SapBomComponent sapBomComponent=new SapBomComponent(); sapBomComponent.setBomCode(STLNR); - sapBomComponent.setSite(WERKS); + sapBomComponent.setSite("1000"); sapBomComponent.setMsi(BEIKZ); sapBomComponent.setSanka(SANKA); sapBomComponent.setProductCode(MATNR); - sapBomComponent.setCumc(OJTXB); + sapBomComponent.setCumc(OJMBR); + sapBomComponent.setComponent(PMATNR); sapBomComponent.setBomHierarchy(STUFE); sapBomComponent.setProjectNo(WEGXX); sapBomComponent.setStandardDosage(new BigDecimal(PMENGE)); @@ -148,13 +174,13 @@ public class SapBomServiceImpl implements SapBomService { sapBomComponent.setLossAmount(new BigDecimal(PXHLCE)); sapBomComponent.setCilosses(new BigDecimal(PMNGKO)); sapBomComponent.setCreateBy(ANNAM); - // sapBomComponent.setCreateTime(DateUtils.dateTime("yyyy-MM-dd", ANDAT)); + sapBomComponent.setCreateTime(DateUtils.dateTime("yyyy-MM-dd", ANDAT)); sapBomComponent.setUpdateBy(AENAM); - // sapBomComponent.setUpdateTime(DateUtils.dateTime("yyyy-MM-dd", AEDAT)); - // sapBomList.add(sapBom); - // sapBomComponentMapper.insertSapBomComponent(sapBomComponent); + sapBomComponent.setUpdateTime(DateUtils.dateTime("yyyy-MM-dd", AEDAT)); + sapBomComponentList.add(sapBomComponent); + sapBomList.add(sapBom); } - // inserBaseBom(sapBomList); + createBOM(sapBomList,sapBomComponentList); return R.ok(); } catch (Exception e) { return R.fail(e.getMessage()); @@ -162,10 +188,65 @@ public class SapBomServiceImpl implements SapBomService { } } - public void inserBaseBom(List sapBomList){ - sapBomList = sapBomList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(SapBom::getBomCode))), ArrayList::new)); - for (SapBom sapBom:sapBomList) { - sapBomMapper.insertBaseBom(sapBom); + @Override + public SapBom getMaxRevisionBom(String STLNR) { + List list = sapBomMapper.selectBaseBomByBomCode(STLNR); + if (list == null || list.size() <= 0) { + return null; + } + + return list.get(0); + } + + public void createBOM(List sapBomList,List sapBomComponentList){ + List newBomList = sapBomList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(SapBom::getBomCode))), ArrayList::new)); + if (newBomList.size()>0){ + DynamicDataSourceContextHolder.push("ds_1000"); + SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH,false); + for (SapBom sapBom:newBomList) { + List sapBomComponents; + //查询Bom号是否存在 + SapBom bomModel = this.getMaxRevisionBom(sapBom.getBomCode()); + //存在且版本号大于现有版本 + if (bomModel!=null&&sapBom.getOptionalBom()!=null&&Float.parseFloat(sapBom.getOptionalBom())>Float.parseFloat(bomModel.getOptionalBom())) + { + //升级BOM + String bomBo = HandleEnum.BOM.getHandle(sapBom.getFactoryCode(),sapBom.getBomCode(),sapBom.getOptionalBom()); + sapBom.setBomBo(bomBo); + //插入BOM表 + sapBomMapper.insertBaseBom(sapBom); + //筛选组件清单 + sapBomComponents = sapBomComponentList.stream().filter(sbc-> + sbc.getBomCode().equals(sapBom.getBomCode())).collect(Collectors.toList()); + //执行插入 + + sapBomComponents.stream().forEach(components -> { + components.setBomBo(bomBo); + sapBomComponentMapper.insertSapBomComponent(components); + }); + + } + else if (bomModel==null&&sapBom.getOptionalBom()!=null){ + //插入初始BOM + String bomBo = HandleEnum.BOM.getHandle(sapBom.getFactoryCode(),sapBom.getBomCode(),sapBom.getOptionalBom()); + sapBom.setBomBo(bomBo); + //插入BOM表 + sapBomMapper.insertBaseBom(sapBom); + //筛选组件清单 + sapBomComponents = sapBomComponentList.stream().filter(sbc-> + sbc.getBomCode().equals(sapBom.getBomCode())).collect(Collectors.toList()); + //执行插入 + sapBomComponents.stream().forEach(components -> { + components.setBomBo(bomBo); + sapBomComponentMapper.insertSapBomComponent(components); + }); + + } + sqlSession.commit(); + sqlSession.clearCache(); + + } + } } diff --git a/op-modules/op-sap/src/main/java/com/op/sap/service/impl/SapItemSyncImpl.java b/op-modules/op-sap/src/main/java/com/op/sap/service/impl/SapItemSyncImpl.java new file mode 100644 index 00000000..10f7206d --- /dev/null +++ b/op-modules/op-sap/src/main/java/com/op/sap/service/impl/SapItemSyncImpl.java @@ -0,0 +1,130 @@ +package com.op.sap.service.impl; + +import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder; +import com.op.common.core.constant.Constants; +import com.op.common.core.domain.R; +import com.op.sap.mapper.SapBaseProductMapper; +import com.op.sap.service.SapItemSyncService; +import com.op.sap.util.SAPConnUtils; +import com.op.system.api.domain.sap.SapBaseProduct; +import com.sap.conn.jco.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; + +@Service +public class SapItemSyncImpl implements SapItemSyncService { + @Autowired + private SapBaseProductMapper sapBaseProductMapper; + @Override + public R itemSync() { + try { + // 获取调用 RFC 函数对象 + //获取连接 + JCoDestination dest = SAPConnUtils.connect(); + JCoRepository repository = dest.getRepository(); + JCoFunction func = repository.getFunction("ZMMR_MES_MAT_GET"); + if (func == null) { + throw new RuntimeException("Function does not exist in SAP"); + } + + JCoTable jCoTables = func.getTableParameterList().getTable("S_MATNR"); + System.out.println(jCoTables); +// jCoTables.appendRow(); +// jCoTables.setValue(Constants.SIGN, "I"); +// jCoTables.setValue(Constants.OPTION, "EQ"); +// jCoTables.setValue(Constants.LOW, "000000010101000115"); + // 获取调用 RFC 函数对象 + func.execute(dest); + // 获取 内表 - ZMES_PRO + JCoTable maraTable = func.getTableParameterList().getTable("LT_MARA"); + JCoRecordMetaData metaData = maraTable.getRecordMetaData(); + System.out.println("###" + metaData.toString()); + DynamicDataSourceContextHolder.push("ds_1000"); + for (int i = 0; i < maraTable.getNumRows(); i++) { + SapBaseProduct baseProduct = new SapBaseProduct(); + 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"); + BigDecimal BRGEW = maraTable.getBigDecimal("BRGEW"); + BigDecimal NTGEW = maraTable.getBigDecimal("NTGEW"); + BigDecimal VOLUM = maraTable.getBigDecimal("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"); + // String SANKA = maraTable.getString("SANKA"); + System.out.println( + "物料号:" + MATNR+ + "物料描述(短文本):" + MAKTX+ + "国际文件号(EAN/UPC):" + EAN11+ + "物料类型:" + MTART+ + "物料类型描述:" + MTBEZ+ + "物料组:" + MATKL+ + "物料组描述:" + WGBEZ+ + "毛重:" + BRGEW+ + "净重:" + NTGEW+ + "体积:" + VOLUM+ + "体积单位:" + VOLEH+ + "基本计量单位:" + MEINS+ + "帐面库存单位的可选计量单位 :" + MEINH+ + "基本计量单位转换分子:" + UMREZ+ + "转换为基本计量单位的分母:" + UMREN+ + "在客户级标记要删除的物料:" + LVORM+ + "数量:" + MENGE+ + "总货架寿命 :" + MHDHB+ + "产品组:" + SPART+ + "产品组描述:" + SPART_NM+ + "物料组1:" + MVGR1+ + "物料组1描述:" + MVGR1_NM+ + "物料组2:" + MVGR2+ + "物料组2描述:" + MVGR2_NM+ + " 物料组3:" + MVGR3+ + " 物料组描述 :" + MVGR3_NM); + //查询物料存不存在 + baseProduct.setProductCode(MATNR); + SapBaseProduct sapBaseProduct=sapBaseProductMapper.selectBaseProductByProductCode(baseProduct); + if (sapBaseProduct==null){ + sapBaseProduct.setProductCode(MATNR); + sapBaseProduct.setProductDescZh(MAKTX); +// baseProduct.setProductean11(EAN11); + sapBaseProduct.setProductGroup(MATKL); + sapBaseProduct.setProductGroupName(WGBEZ); + sapBaseProduct.setGrossWeight(BRGEW); + sapBaseProduct.setNetWeight(NTGEW); + sapBaseProduct.setVolume(VOLUM); + sapBaseProduct.setDelFlag("0"); + // sapBaseProductMapper.insertBaseProduct(sapBaseProduct); + } + + + } + return R.ok(); + + }catch (Exception e){ + return R.fail(e.getMessage()); + } + } +} diff --git a/op-modules/op-sap/src/main/java/com/op/sap/service/impl/SapWorkCenterServiceImpl.java b/op-modules/op-sap/src/main/java/com/op/sap/service/impl/SapWorkCenterServiceImpl.java new file mode 100644 index 00000000..f47253d6 --- /dev/null +++ b/op-modules/op-sap/src/main/java/com/op/sap/service/impl/SapWorkCenterServiceImpl.java @@ -0,0 +1,169 @@ +package com.op.sap.service.impl; + +import com.op.common.core.domain.R; +import com.op.common.core.utils.DateUtils; +import com.op.sap.service.SapWorkCenterService; +import com.op.sap.util.SAPConnUtils; +import com.op.system.api.domain.sap.SapWorkCenter; +import com.sap.conn.jco.*; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +@Service +public class SapWorkCenterServiceImpl implements SapWorkCenterService { + + @Override + public R sapWorkCenterSync() { + try { + // 获取调用 RFC 函数对象 + //获取连接 + JCoDestination dest = SAPConnUtils.connect(); + JCoRepository repository = dest.getRepository(); + JCoFunction func = repository.getFunction("ZMES_GET_ARBPL"); + if (func == null) { + throw new RuntimeException("Function does not exist in SAP"); + } + // 配置传入参数 + JCoTable jCoTable = func.getTableParameterList().getTable("S_WERKS"); +// jCoTable.appendRow(); +// jCoTable.setValue("SIGN", "I"); +// jCoTable.setValue("OPTION", "EQ"); +// jCoTable.setValue("LOW", "1000"); + func.execute(dest);//执行调用函数 + // 获取 内表 - ZMES_PRO + JCoTable maraTable = func.getTableParameterList().getTable("LT_ARBPL"); + JCoRecordMetaData metaData = maraTable.getRecordMetaData(); + System.out.println("###" + metaData.toString()); + List sapWorkCenterList=new ArrayList<>(); + for (int i = 0; i sapWorkCenterList=new ArrayList<>(); + for (int i = 0; i sapWorkCenterList=new ArrayList<>(); + for (int i = 0; i = parts.length) { + return null; + } else { + return parts[position]; + } + } + + public String getPrefix() { + return prefix; + } +} diff --git a/op-modules/op-sap/src/main/resources/bootstrap.yml b/op-modules/op-sap/src/main/resources/bootstrap.yml index 14dae316..6981aeea 100644 --- a/op-modules/op-sap/src/main/resources/bootstrap.yml +++ b/op-modules/op-sap/src/main/resources/bootstrap.yml @@ -14,12 +14,12 @@ spring: nacos: discovery: namespace: lanju-op - group: zxl + group: ywl # 服务注册地址 server-addr: 140.249.53.142:8848 config: namespace: lanju-op - group: zxl + group: ywl #命名空间 #group: local # 配置中心地址 diff --git a/op-modules/op-sap/src/main/resources/mapper/sap/SapBomComponentMapper.xml b/op-modules/op-sap/src/main/resources/mapper/sap/SapBomComponentMapper.xml index 0465b9e6..85282fa3 100644 --- a/op-modules/op-sap/src/main/resources/mapper/sap/SapBomComponentMapper.xml +++ b/op-modules/op-sap/src/main/resources/mapper/sap/SapBomComponentMapper.xml @@ -68,6 +68,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" insert into base_bom_component id, + bom_bo, bom_code, site, product_code, @@ -94,6 +95,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{id}, + #{bomBo}, #{bomCode}, #{site}, #{productCode}, diff --git a/op-modules/op-sap/src/main/resources/mapper/sap/SapBomMapper.xml b/op-modules/op-sap/src/main/resources/mapper/sap/SapBomMapper.xml index d1cdb9e2..34b049ec 100644 --- a/op-modules/op-sap/src/main/resources/mapper/sap/SapBomMapper.xml +++ b/op-modules/op-sap/src/main/resources/mapper/sap/SapBomMapper.xml @@ -60,14 +60,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - - where factory_code = #{factoryCode} + where bom_code = #{bomCode} + order by production_version desc insert into base_bom + bom_bo, factory_code, production_version, bom_code, @@ -94,6 +96,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" current_version, + #{bomBo}, #{factoryCode}, #{productionVersion}, #{bomCode}, @@ -120,6 +123,64 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{currentVersion}, + + insert into base_bom + + bom_bo, + factory_code, + production_version, + bom_code, + optional_bom, + optional_bom_text, + pvvd, + pved, + bom_calculate_number, + bom_calculate_unit, + bom_base_number, + bom_base_unit, + component_unit, + component_pro_flag, + msi, + sanka, + attr1, + attr2, + attr3, + create_by, + create_time, + update_by, + update_time, + remark, + current_version, + + VALUES + + #{bomBo}, + #{factoryCode}, + #{productionVersion}, + #{bomCode}, + #{optionalBom}, + #{optionalBomText}, + #{pvvd}, + #{pved}, + #{bomCalculateNumber}, + #{bomCalculateUnit}, + #{bomBaseNumber}, + #{bomBaseUnit}, + #{componentUnit}, + #{componentProFlag}, + #{msi}, + #{sanka}, + #{attr1}, + #{attr2}, + #{attr3}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + #{remark}, + #{currentVersion}, + + update base_bom