|
|
|
@ -3,22 +3,33 @@ package com.op.sap.service.impl;
|
|
|
|
|
import com.op.common.core.domain.R;
|
|
|
|
|
import com.op.common.core.utils.DateUtils;
|
|
|
|
|
import com.op.common.core.utils.StringUtils;
|
|
|
|
|
import com.op.sap.domain.vo.SapSupplierQuery;
|
|
|
|
|
import com.op.sap.domain.vo.SapWorkCenterQuery;
|
|
|
|
|
import com.op.sap.mapper.SapBomMapper;
|
|
|
|
|
import com.op.sap.service.SapWorkCenterService;
|
|
|
|
|
import com.op.sap.util.SAPConnUtils;
|
|
|
|
|
import com.op.system.api.domain.sap.SapCustom;
|
|
|
|
|
import com.op.system.api.domain.sap.SapSupplier;
|
|
|
|
|
import com.op.system.api.domain.sap.SapWorkCenter;
|
|
|
|
|
import com.sap.conn.jco.*;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
public class SapWorkCenterServiceImpl implements SapWorkCenterService {
|
|
|
|
|
private static final String END_DATE="99991231";
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private SapBomMapper sapBomMapper;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public R sapWorkCenterSync() {
|
|
|
|
|
public R sapWorkCenterSync(SapWorkCenterQuery sapWorkCenterQuery) {
|
|
|
|
|
try {
|
|
|
|
|
// 获取调用 RFC 函数对象
|
|
|
|
|
//获取连接
|
|
|
|
@ -28,12 +39,38 @@ public class SapWorkCenterServiceImpl implements SapWorkCenterService {
|
|
|
|
|
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");
|
|
|
|
|
/*
|
|
|
|
|
S_WERKS 工厂
|
|
|
|
|
S_ARBPL 工作中心
|
|
|
|
|
S_AEDAT 修改日期 例如:20230923
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (!StringUtils.isNull(sapWorkCenterQuery.getWerks())){
|
|
|
|
|
JCoTable S_WERKS = func.getTableParameterList().getTable("S_WERKS");
|
|
|
|
|
S_WERKS.appendRow();
|
|
|
|
|
S_WERKS.setValue("SIGN", "I");
|
|
|
|
|
S_WERKS.setValue("OPTION", "EQ");
|
|
|
|
|
S_WERKS.setValue("LOW", sapWorkCenterQuery.getWerks());
|
|
|
|
|
}
|
|
|
|
|
if (!StringUtils.isNull(sapWorkCenterQuery.getArbpl())){
|
|
|
|
|
JCoTable S_ARBPL = func.getTableParameterList().getTable("S_ARBPL");
|
|
|
|
|
S_ARBPL.appendRow();
|
|
|
|
|
S_ARBPL.setValue("SIGN", "I");
|
|
|
|
|
S_ARBPL.setValue("OPTION", "EQ");
|
|
|
|
|
S_ARBPL.setValue("LOW", sapWorkCenterQuery.getArbpl());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!StringUtils.isNull(sapWorkCenterQuery.getAedat())){
|
|
|
|
|
JCoTable S_AEDAT = func.getTableParameterList().getTable("S_AEDAT");
|
|
|
|
|
S_AEDAT.appendRow();
|
|
|
|
|
S_AEDAT.setValue("SIGN", "I");
|
|
|
|
|
S_AEDAT.setValue("OPTION", "BT");
|
|
|
|
|
S_AEDAT.setValue("LOW", sapWorkCenterQuery.getAedat());
|
|
|
|
|
S_AEDAT.setValue("HIGH", END_DATE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func.execute(dest);//执行调用函数
|
|
|
|
|
// 获取 内表 - ZMES_PRO
|
|
|
|
|
JCoTable maraTable = func.getTableParameterList().getTable("LT_ARBPL");
|
|
|
|
@ -69,7 +106,7 @@ public class SapWorkCenterServiceImpl implements SapWorkCenterService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public R sapSupplierSync(SapSupplier sapSupplier) {
|
|
|
|
|
public R sapSupplierSync(SapSupplierQuery sapSupplierQuery) {
|
|
|
|
|
try {
|
|
|
|
|
// 获取调用 RFC 函数对象
|
|
|
|
|
//获取连接
|
|
|
|
@ -83,35 +120,32 @@ public class SapWorkCenterServiceImpl implements SapWorkCenterService {
|
|
|
|
|
/* 输入表
|
|
|
|
|
S_BUKRS 工厂 1000/1001/1002
|
|
|
|
|
S_LIFNR 供应商
|
|
|
|
|
S_ERDAT 记录创建日期
|
|
|
|
|
S_ERDAT 记录创建日期 20230807
|
|
|
|
|
*/
|
|
|
|
|
if (!StringUtils.isNull(sapSupplier.getBukrs())){
|
|
|
|
|
if (!StringUtils.isNull(sapSupplierQuery.getBukrs())){
|
|
|
|
|
JCoTable S_BUKRS = func.getTableParameterList().getTable("S_BUKRS");
|
|
|
|
|
S_BUKRS.appendRow();
|
|
|
|
|
S_BUKRS.setValue("SIGN", "I");
|
|
|
|
|
S_BUKRS.setValue("OPTION", "EQ");
|
|
|
|
|
S_BUKRS.setValue("LOW", sapSupplier.getBukrs());
|
|
|
|
|
S_BUKRS.setValue("LOW", sapSupplierQuery.getBukrs());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!StringUtils.isNull(sapSupplier.getLifnr())){
|
|
|
|
|
if (!StringUtils.isNull(sapSupplierQuery.getLifnr())){
|
|
|
|
|
JCoTable S_LIFNR = func.getTableParameterList().getTable("S_LIFNR");
|
|
|
|
|
S_LIFNR.appendRow();
|
|
|
|
|
S_LIFNR.setValue("SIGN", "I");
|
|
|
|
|
S_LIFNR.setValue("OPTION", "EQ");
|
|
|
|
|
S_LIFNR.setValue("LOW", sapSupplier.getLifnr());
|
|
|
|
|
S_LIFNR.setValue("LOW", sapSupplierQuery.getLifnr());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///日期参数示例
|
|
|
|
|
|
|
|
|
|
if (!StringUtils.isNull(sapSupplier.getErdat())){
|
|
|
|
|
if (!StringUtils.isNull(sapSupplierQuery.getErdat())){
|
|
|
|
|
JCoTable S_ERDAT = func.getTableParameterList().getTable("S_ERDAT");
|
|
|
|
|
S_ERDAT.appendRow();
|
|
|
|
|
S_ERDAT.setValue("SIGN", "I");
|
|
|
|
|
S_ERDAT.setValue("OPTION", "EQ");
|
|
|
|
|
S_ERDAT.setValue("LOW", sapSupplier.getErdat() );
|
|
|
|
|
S_ERDAT.setValue("OPTION", "BT");
|
|
|
|
|
S_ERDAT.setValue("LOW", sapSupplierQuery.getErdat());
|
|
|
|
|
S_ERDAT.setValue("HIGH", END_DATE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func.execute(dest);//执行调用函数
|
|
|
|
|
// 获取 内表 - ZMES_PRO
|
|
|
|
|
JCoTable maraTable = func.getTableParameterList().getTable("LT_LIFNR");
|
|
|
|
@ -164,7 +198,6 @@ public class SapWorkCenterServiceImpl implements SapWorkCenterService {
|
|
|
|
|
S_KUNNR 客户
|
|
|
|
|
S_ERDAT 记录创建日期
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (!StringUtils.isNull(sapCustom.getBukrs())){
|
|
|
|
|
JCoTable S_BUKRS = func.getTableParameterList().getTable("S_BUKRS");
|
|
|
|
|
S_BUKRS.appendRow();
|
|
|
|
@ -173,19 +206,21 @@ public class SapWorkCenterServiceImpl implements SapWorkCenterService {
|
|
|
|
|
S_BUKRS.setValue("LOW", sapCustom.getBukrs());
|
|
|
|
|
}
|
|
|
|
|
if (!StringUtils.isNull(sapCustom.getKunnr())){
|
|
|
|
|
|
|
|
|
|
JCoTable S_KUNNR = func.getTableParameterList().getTable("S_KUNNR");
|
|
|
|
|
S_KUNNR.appendRow();
|
|
|
|
|
S_KUNNR.setValue("SIGN", "I");
|
|
|
|
|
S_KUNNR.setValue("OPTION", "EQ");
|
|
|
|
|
S_KUNNR.setValue("LOW", sapCustom.getKunnr());
|
|
|
|
|
}
|
|
|
|
|
///日期参数示例 20230921
|
|
|
|
|
if (!StringUtils.isNull(sapCustom.getErdat())){
|
|
|
|
|
///日期参数示例 20230921
|
|
|
|
|
JCoTable S_ERDAT = func.getTableParameterList().getTable("S_ERDAT");
|
|
|
|
|
S_ERDAT.appendRow();
|
|
|
|
|
S_ERDAT.setValue("SIGN", "I");
|
|
|
|
|
S_ERDAT.setValue("OPTION", "EQ");
|
|
|
|
|
S_ERDAT.setValue("OPTION", "BT");
|
|
|
|
|
S_ERDAT.setValue("LOW", sapCustom.getErdat() );
|
|
|
|
|
S_ERDAT.setValue("HIGH", END_DATE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func.execute(dest);//执行调用函数
|
|
|
|
@ -222,4 +257,37 @@ public class SapWorkCenterServiceImpl implements SapWorkCenterService {
|
|
|
|
|
return R.fail(e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**sys_factory**/
|
|
|
|
|
@Override
|
|
|
|
|
public void syncWorkCenter(List<SapWorkCenter> dtos) {
|
|
|
|
|
//sap返回的工作中心编码
|
|
|
|
|
List<String> codes = dtos.stream().map(SapWorkCenter::getArbpl).collect(Collectors.toList());
|
|
|
|
|
//sap返回的工作中心编码-本地已存在
|
|
|
|
|
List<String> exsitCodes = sapBomMapper.getExsitCodes(codes);
|
|
|
|
|
//sap返回的工作中心编码-本地不存在// 差集 (list2 - list1)
|
|
|
|
|
List<String> noExsitCodes = codes.stream().filter(item -> !exsitCodes.contains(item)).collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
List<SapWorkCenter> updates = new ArrayList<>();
|
|
|
|
|
for(String exsitCode:exsitCodes){
|
|
|
|
|
updates = dtos.stream().filter(dto -> dto.getArbpl().equals(exsitCode)).collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
if(CollectionUtils.isEmpty(updates)){
|
|
|
|
|
int m = sapBomMapper.updateFactoryBatchs(updates);
|
|
|
|
|
System.out.println("工作中心更新成功条数:"+m);
|
|
|
|
|
}
|
|
|
|
|
List<SapWorkCenter> adds = new ArrayList<>();
|
|
|
|
|
for(String noExsitCode:noExsitCodes){
|
|
|
|
|
adds = dtos.stream().filter(dto -> dto.getArbpl().equals(noExsitCode)).collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
if(CollectionUtils.isEmpty(adds)){
|
|
|
|
|
//工厂parentId
|
|
|
|
|
String parentId = sapBomMapper.getParentId(adds.get(0).getWeeks());
|
|
|
|
|
adds.stream().forEach(e->{
|
|
|
|
|
e.setParentId(parentId);
|
|
|
|
|
});
|
|
|
|
|
int n = sapBomMapper.addFactoryBatchs(adds);
|
|
|
|
|
System.out.println("工作中心新增成功条数:"+ n);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|