|
|
|
@ -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<SapBom> sapBomList=new ArrayList<>();
|
|
|
|
|
List<SapBomComponent> 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<SapBom> 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<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){
|
|
|
|
|
List<SapBom> 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<SapBomComponent> 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();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|