|
|
|
@ -1,5 +1,6 @@
|
|
|
|
package com.op.sap.service.impl;
|
|
|
|
package com.op.sap.service.impl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
|
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
|
|
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
|
|
import com.op.common.core.constant.Constants;
|
|
|
|
import com.op.common.core.constant.Constants;
|
|
|
|
import com.op.common.core.domain.R;
|
|
|
|
import com.op.common.core.domain.R;
|
|
|
|
@ -21,6 +22,8 @@ import com.sap.conn.jco.*;
|
|
|
|
import org.apache.ibatis.session.ExecutorType;
|
|
|
|
import org.apache.ibatis.session.ExecutorType;
|
|
|
|
import org.apache.ibatis.session.SqlSession;
|
|
|
|
import org.apache.ibatis.session.SqlSession;
|
|
|
|
import org.apache.ibatis.session.SqlSessionFactory;
|
|
|
|
import org.apache.ibatis.session.SqlSessionFactory;
|
|
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
@ -45,6 +48,7 @@ public class SapBomServiceImpl implements SapBomService {
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private JCoDestination dest;
|
|
|
|
private JCoDestination dest;
|
|
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(SapBomServiceImpl.class);
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public R bomSync(SapBomQuery sapBomQuery) {
|
|
|
|
public R bomSync(SapBomQuery sapBomQuery) {
|
|
|
|
@ -124,15 +128,11 @@ public class SapBomServiceImpl implements SapBomService {
|
|
|
|
S_AEDAT.setValue(Constants.LOW, sapBomQuery.getAedat());
|
|
|
|
S_AEDAT.setValue(Constants.LOW, sapBomQuery.getAedat());
|
|
|
|
S_AEDAT.setValue("HIGH", END_DATE);
|
|
|
|
S_AEDAT.setValue("HIGH", END_DATE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // 获取调用 RFC 函数对象
|
|
|
|
// // 获取调用 RFC 函数对象
|
|
|
|
func.execute(dest);
|
|
|
|
func.execute(dest);
|
|
|
|
// // 获取 内表 - ZMES_PRO
|
|
|
|
// // 获取 内表 - ZMES_PRO
|
|
|
|
JCoTable maraTable = func.getTableParameterList().getTable("LT_BOM");
|
|
|
|
JCoTable maraTable = func.getTableParameterList().getTable("LT_BOM");
|
|
|
|
// JCoRecordMetaData metaData = maraTable.getRecordMetaData();
|
|
|
|
System.out.println(maraTable);
|
|
|
|
List<SapBom> sapBomList = new ArrayList<>();
|
|
|
|
List<SapBom> sapBomList = new ArrayList<>();
|
|
|
|
List<SapBomComponent> sapBomComponentList = new ArrayList<>();
|
|
|
|
List<SapBomComponent> sapBomComponentList = new ArrayList<>();
|
|
|
|
for (int i = 0; i < maraTable.getNumRows(); i++) {
|
|
|
|
for (int i = 0; i < maraTable.getNumRows(); i++) {
|
|
|
|
@ -193,10 +193,10 @@ public class SapBomServiceImpl implements SapBomService {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
SapBom sapBom = new SapBom();
|
|
|
|
SapBom sapBom = new SapBom();
|
|
|
|
sapBom.setFactoryCode(WERKS);
|
|
|
|
sapBom.setFactoryCode(WERKS);
|
|
|
|
sapBom.setProductionVersion(STLAL);
|
|
|
|
sapBom.setProductionVersion(VERID);
|
|
|
|
sapBom.setBomCode(STLNR);
|
|
|
|
sapBom.setBomCode(STLNR);
|
|
|
|
sapBom.setCumc(OJMBR);
|
|
|
|
sapBom.setCumc(OJMBR);
|
|
|
|
sapBom.setComponent(PMATNR);
|
|
|
|
// sapBom.setComponent(PMATNR);
|
|
|
|
sapBom.setOptionalBom(STLAL);
|
|
|
|
sapBom.setOptionalBom(STLAL);
|
|
|
|
sapBom.setPvvd(DateUtils.dateTime("yyyy-MM-dd", ADATU));
|
|
|
|
sapBom.setPvvd(DateUtils.dateTime("yyyy-MM-dd", ADATU));
|
|
|
|
sapBom.setPved(DateUtils.dateTime("yyyy-MM-dd", BDATU));
|
|
|
|
sapBom.setPved(DateUtils.dateTime("yyyy-MM-dd", BDATU));
|
|
|
|
@ -204,13 +204,15 @@ public class SapBomServiceImpl implements SapBomService {
|
|
|
|
sapBom.setBomCalculateUnit(MEINS);
|
|
|
|
sapBom.setBomCalculateUnit(MEINS);
|
|
|
|
sapBom.setBomBaseNumber(new BigDecimal(BMENG));
|
|
|
|
sapBom.setBomBaseNumber(new BigDecimal(BMENG));
|
|
|
|
sapBom.setBomBaseUnit(BMEIN);
|
|
|
|
sapBom.setBomBaseUnit(BMEIN);
|
|
|
|
sapBom.setComponentUnit(PMEINS);
|
|
|
|
// sapBom.setComponentUnit(PMEINS);
|
|
|
|
sapBom.setComponentProFlag(PBESKZ);
|
|
|
|
// sapBom.setComponentProFlag(PBESKZ);
|
|
|
|
// sapBom.setCurrentVersion("");
|
|
|
|
// sapBom.setCurrentVersion("");
|
|
|
|
sapBom.setCreateBy(ANNAM);
|
|
|
|
sapBom.setCreateBy(ANNAM);
|
|
|
|
sapBom.setCreateTime(DateUtils.dateTime("yyyy-MM-dd", ANDAT));
|
|
|
|
sapBom.setCreateTime(DateUtils.dateTime("yyyy-MM-dd", ANDAT));
|
|
|
|
sapBom.setUpdateBy(AENAM);
|
|
|
|
sapBom.setUpdateBy(AENAM);
|
|
|
|
sapBom.setUpdateTime(DateUtils.dateTime("yyyy-MM-dd", AEDAT));
|
|
|
|
sapBom.setUpdateTime(DateUtils.dateTime("yyyy-MM-dd", AEDAT));
|
|
|
|
|
|
|
|
sapBom.setAttr1(MATNR);
|
|
|
|
|
|
|
|
sapBom.setAttr2(MAKTX);
|
|
|
|
SapBomComponent sapBomComponent = new SapBomComponent();
|
|
|
|
SapBomComponent sapBomComponent = new SapBomComponent();
|
|
|
|
sapBomComponent.setId(IdUtils.simpleUUID().toString());
|
|
|
|
sapBomComponent.setId(IdUtils.simpleUUID().toString());
|
|
|
|
sapBomComponent.setBomCode(STLNR);
|
|
|
|
sapBomComponent.setBomCode(STLNR);
|
|
|
|
@ -226,82 +228,70 @@ public class SapBomServiceImpl implements SapBomService {
|
|
|
|
sapBomComponent.setLossRate(new BigDecimal(PAUSCH));
|
|
|
|
sapBomComponent.setLossRate(new BigDecimal(PAUSCH));
|
|
|
|
sapBomComponent.setLossAmount(new BigDecimal(PXHLCE));
|
|
|
|
sapBomComponent.setLossAmount(new BigDecimal(PXHLCE));
|
|
|
|
sapBomComponent.setCilosses(new BigDecimal(PMNGKO));
|
|
|
|
sapBomComponent.setCilosses(new BigDecimal(PMNGKO));
|
|
|
|
|
|
|
|
sapBomComponent.setComponentUnit(PMEINS);
|
|
|
|
sapBomComponent.setCreateBy(ANNAM);
|
|
|
|
sapBomComponent.setCreateBy(ANNAM);
|
|
|
|
|
|
|
|
sapBomComponent.setComponentProFlag(PBESKZ);
|
|
|
|
sapBomComponent.setCreateTime(DateUtils.getNowDate());
|
|
|
|
sapBomComponent.setCreateTime(DateUtils.getNowDate());
|
|
|
|
sapBomComponent.setUpdateBy(AENAM);
|
|
|
|
sapBomComponent.setUpdateBy(AENAM);
|
|
|
|
sapBomComponent.setUpdateTime(DateUtils.getNowDate());
|
|
|
|
sapBomComponent.setUpdateTime(DateUtils.getNowDate());
|
|
|
|
sapBomComponentList.add(sapBomComponent);
|
|
|
|
sapBomComponentList.add(sapBomComponent);
|
|
|
|
sapBomList.add(sapBom);
|
|
|
|
sapBomList.add(sapBom);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// createBOM(sapBomList,sapBomComponentList);
|
|
|
|
createBOM(sapBomList,sapBomComponentList);
|
|
|
|
return R.ok();
|
|
|
|
return R.ok();
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
return R.fail(e.getMessage());
|
|
|
|
return R.fail(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public SapBom getMaxRevisionBom(String STLNR) {
|
|
|
|
|
|
|
|
List<SapBom> list = sapBomMapper.selectBaseBomByBomCode(STLNR);
|
|
|
|
|
|
|
|
if (list == null || list.size() <= 0) {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return list.get(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void createBOM(List<SapBom> sapBomList, List<SapBomComponent> sapBomComponentList) {
|
|
|
|
public void createBOM(List<SapBom> sapBomList, List<SapBomComponent> sapBomComponentList) {
|
|
|
|
|
|
|
|
log.info("BOM同步开始---------");
|
|
|
|
List<SapBom> newBomList = sapBomList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(SapBom::getBomCode))), ArrayList::new));
|
|
|
|
List<SapBom> newBomList = sapBomList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(SapBom::getBomCode))), ArrayList::new));
|
|
|
|
DynamicDataSourceContextHolder.push("ds_1000");
|
|
|
|
DynamicDataSourceContextHolder.push("ds_1000");
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (newBomList.size() > 0) {
|
|
|
|
if (newBomList.size() > 0) {
|
|
|
|
|
|
|
|
|
|
|
|
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
|
|
|
|
|
|
|
|
for (SapBom sapBom : newBomList) {
|
|
|
|
for (SapBom sapBom : newBomList) {
|
|
|
|
List<SapBomComponent> sapBomComponents;
|
|
|
|
//更新BOM表数据
|
|
|
|
//查询Bom号是否存在
|
|
|
|
sapBomMapper.updateBaseBom(sapBom);
|
|
|
|
SapBom bomModel = this.getMaxRevisionBom(sapBom.getBomCode());
|
|
|
|
// List<SapBomComponent> sapBomComponents;
|
|
|
|
//存在且版本号大于现有版本
|
|
|
|
// //查询Bom是否存在
|
|
|
|
if (bomModel != null && sapBom.getOptionalBom() != null && Float.parseFloat(sapBom.getOptionalBom()) > Float.parseFloat(bomModel.getOptionalBom())) {
|
|
|
|
// SapBom bomModel = sapBomMapper.selectBaseBomByBomCode(sapBom.getBomCode());
|
|
|
|
//升级BOM
|
|
|
|
// //Bom存在则更新现有BOM
|
|
|
|
String bomBo = HandleEnum.BOM.getHandle(sapBom.getFactoryCode(), sapBom.getBomCode(), sapBom.getOptionalBom());
|
|
|
|
// if (bomModel != null ) {
|
|
|
|
sapBom.setBomBo(bomBo);
|
|
|
|
// sapBomMapper.updateBaseBom(sapBom);
|
|
|
|
|
|
|
|
// //删除base_bom_component表现有的数据
|
|
|
|
|
|
|
|
sapBomComponentMapper.deleteSapBomComponentByBomCode(sapBom.getBomCode());
|
|
|
|
|
|
|
|
// //执行插入
|
|
|
|
|
|
|
|
// sapBomComponentList.stream().forEach(components -> {
|
|
|
|
|
|
|
|
// sapBomComponentMapper.insertSapBomComponent(components);
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// } else if (bomModel == null) {
|
|
|
|
//插入BOM表
|
|
|
|
//插入BOM表
|
|
|
|
sapBomMapper.insertBaseBom(sapBom);
|
|
|
|
// sapBomMapper.insertBaseBom(sapBom);
|
|
|
|
//筛选组件清单
|
|
|
|
|
|
|
|
sapBomComponents = sapBomComponentList.stream().filter(sbc ->
|
|
|
|
|
|
|
|
sbc.getBomCode().equals(sapBom.getBomCode())).collect(Collectors.toList());
|
|
|
|
|
|
|
|
//执行插入
|
|
|
|
//执行插入
|
|
|
|
sapBomComponents.stream().forEach(components -> {
|
|
|
|
// for (SapBomComponent sapBomComponent : sapBomComponentList){
|
|
|
|
components.setBomBo(bomBo);
|
|
|
|
// sapBomComponentMapper.insertSapBomComponent(sapBomComponent);
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// for (SapBomComponent sapBomComponent : sapBomComponentList){
|
|
|
|
|
|
|
|
// sapBomComponentMapper.insertSapBomComponent(sapBomComponent);
|
|
|
|
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}finally {
|
|
|
|
//执行插入
|
|
|
|
|
|
|
|
for (SapBomComponent sapBomComponent : sapBomComponentList){
|
|
|
|
|
|
|
|
sapBomComponentMapper.insertSapBomComponent(sapBomComponent);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
log.info("BOM同步结束---------");
|
|
|
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
|
|
|
System.out.println(e.getMessage());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
finally {
|
|
|
|
DynamicDataSourceContextHolder.poll();
|
|
|
|
DynamicDataSourceContextHolder.poll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|