refactor(integration): 优化库存记录的 SAP 批次号获取和更新逻辑
- 新增 getSapBatchNo 方法,从 SAP系统获取物料批次号 - 修改 callErpMaterial 和 callErpLot 方法,使用新的批次号获取逻辑 - 优化库存记录的批量更新逻辑,提高处理效率 - 增加错误处理和异常抛出,提高系统稳定性
This commit is contained in:
parent
2724f5ff80
commit
22f57ebd41
@ -2,9 +2,12 @@ package com.foreverwin.iep.integration.feign;
|
||||
|
||||
import com.foreverwin.mom.common.core.util.R;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @program: mom-wms-biz
|
||||
* @description: 获取SAP批次号
|
||||
@ -17,4 +20,7 @@ public interface RemoteGetSapBatchNoService {
|
||||
@PostMapping("/shopOrderStatisticTransCallErp/api/getSapBatchNo")
|
||||
R<String> getSapBatchNo(@RequestBody String erpItem);
|
||||
|
||||
@PostMapping("/shopOrderStatisticTransCallErp/api/getSapBatchNo/{num}")
|
||||
List<R> getSapBatchNo(@RequestBody String erpItem, @PathVariable int num);
|
||||
|
||||
}
|
||||
@ -232,7 +232,9 @@ public class CopyShopOrderStatisticTransController {
|
||||
@PostMapping("/callErpMaterial")
|
||||
public R callErpMaterial() {
|
||||
R<List<InventoryRecord>> byType = inventoryRecordMapper.getByType("1","0");
|
||||
Vector<InventoryRecord> update = new Vector<>();
|
||||
List<InventoryRecord> inventoryRecords = byType.getData();
|
||||
|
||||
// if (inventoryRecords.size() == 0){
|
||||
// return R.failed("没有需要同步的库存数据");
|
||||
// }
|
||||
@ -259,7 +261,10 @@ public class CopyShopOrderStatisticTransController {
|
||||
jsonObject.put("MATKL", ""); // 物料组
|
||||
jsonObject.put("WERKS", site); // 工厂
|
||||
jsonObject.put("LGORT", consumptionTransaction.getErpInventory()); // 存储地点
|
||||
jsonObject.put("CHARG", consumptionTransaction.getSapBatchNo()); // 批次号
|
||||
String sapBatchNo = registerDocumentService.getSapBatchNo(consumptionTransaction.getWorkshopNumber());
|
||||
|
||||
|
||||
jsonObject.put("CHARG", sapBatchNo); // 批次号
|
||||
jsonObject.put("BWART", "261"); // 移动类型
|
||||
jsonObject.put("SOBKZ", ""); // 特殊库存标识
|
||||
jsonObject.put("AUFNR", consumptionTransaction.getShopOrder()); // 订单号
|
||||
@ -281,6 +286,7 @@ public class CopyShopOrderStatisticTransController {
|
||||
jsonObject.put("UMCHA", ""); // 收货/发货批量
|
||||
jsonObject.put("RSNUM", consumptionTransaction.getReservedNo()); // 预留/相关需求的编号
|
||||
jsonObject.put("RSPOS", consumptionTransaction.getReservedLine()); // 预留 / 相关需求的项目编号
|
||||
update.add(targetObj);
|
||||
itemList.add(jsonObject);
|
||||
newList.add(targetObj);
|
||||
}
|
||||
@ -317,11 +323,10 @@ public class CopyShopOrderStatisticTransController {
|
||||
if ("E".equals(invokeResponse.getResult())) {
|
||||
return R.failed("SAP错误:"+invokeResponse.getMessageContent());
|
||||
} else {
|
||||
for (InventoryRecord targetObj : srcList) {
|
||||
for (InventoryRecord targetObj : update) {
|
||||
targetObj.setIsSap("1");
|
||||
R r = inventoryRecordMapper.apiUpdateById(targetObj);
|
||||
r.getMsg();
|
||||
}
|
||||
inventoryRecordMapper.batchUpdate(update);
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
@ -383,6 +388,7 @@ public class CopyShopOrderStatisticTransController {
|
||||
@SysLog("生产管理报工平台-批次完工入库报工")
|
||||
@PostMapping("/callErpLot")
|
||||
public R callErpLot() {
|
||||
Vector<InventoryRecord> update = new Vector<>();
|
||||
R<List<InventoryRecord>> byType = inventoryRecordMapper.getByType("0","0");
|
||||
List<InventoryRecord> inventoryRecords = byType.getData();
|
||||
// if (inventoryRecords.size() == 0){
|
||||
@ -411,7 +417,9 @@ public class CopyShopOrderStatisticTransController {
|
||||
jsonObject.put("MATKL", ""); // 物料组
|
||||
jsonObject.put("WERKS", site); // 工厂
|
||||
jsonObject.put("LGORT", completeTransaction.getErpInventory()); // 存储地点
|
||||
jsonObject.put("CHARG", completeTransaction.getSapBatchNo()); // 批次号
|
||||
String sapBatchNo = registerDocumentService.getSapBatchNo(completeTransaction.getWorkshopNumber());
|
||||
completeTransaction.setSapBatchNo(sapBatchNo);
|
||||
jsonObject.put("CHARG", sapBatchNo); // 批次号
|
||||
jsonObject.put("BWART", "101"); // 移动类型
|
||||
jsonObject.put("SOBKZ", ""); // 特殊库存标识
|
||||
jsonObject.put("AUFNR", completeTransaction.getShopOrder()); // 订单号
|
||||
@ -440,6 +448,7 @@ public class CopyShopOrderStatisticTransController {
|
||||
jsonObject.put("Z_JH", completeTransaction.getBarcode()); // 卷号
|
||||
jsonObject.put("Z_CVN", completeTransaction.getExternalLot()); // 客户卷号
|
||||
jsonObject.put("Z_GRADE", completeTransaction.getGrade()); // 等级
|
||||
update.add(completeTransaction);
|
||||
itemList.add(jsonObject);
|
||||
newList.add(targetObj);
|
||||
}
|
||||
@ -466,21 +475,22 @@ public class CopyShopOrderStatisticTransController {
|
||||
TenantContextHolder.setTenantId(site);
|
||||
invokeResponse = goodMvtCreateService.call(invokeRequest);
|
||||
// 处理ERP返回的报文
|
||||
invokeResponse = updateLotComplete(invokeResponse.getObjectResponse(), srcList, invokeResponse);
|
||||
invokeResponse = updateLotComplete(invokeResponse.getObjectResponse(), update, invokeResponse);
|
||||
} catch (Exception e) {
|
||||
// 不用回滚,将错误抛出
|
||||
invokeResponse.setResult("E");
|
||||
invokeResponse.setMessageContent(e.getMessage());
|
||||
|
||||
}
|
||||
}
|
||||
if ("E".equals(invokeResponse.getResult())) {
|
||||
|
||||
return R.failed("SAP错误:"+invokeResponse.getMessageContent());
|
||||
} else {
|
||||
for (InventoryRecord targetObj : srcList) {
|
||||
for (InventoryRecord targetObj : update) {
|
||||
targetObj.setIsSap("1");
|
||||
R r = inventoryRecordMapper.apiUpdateById(targetObj);
|
||||
r.getMsg();
|
||||
}
|
||||
inventoryRecordMapper.batchUpdate(update);
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
@ -507,9 +517,9 @@ public class CopyShopOrderStatisticTransController {
|
||||
targetObj.setDateCreate(LocalDateTime.now());
|
||||
targetObj.setSyncMessageRemark(msgid);
|
||||
targetObj.setIsSap("2");
|
||||
R r = inventoryRecordMapper.apiUpdateById(targetObj);
|
||||
r.getMsg();
|
||||
}
|
||||
R r = inventoryRecordMapper.batchUpdate(srcList);
|
||||
r.getMsg();
|
||||
invokeResponse.setResult(result);
|
||||
invokeResponse.setMessageContent(message);
|
||||
return invokeResponse;
|
||||
@ -598,4 +608,5 @@ public class CopyShopOrderStatisticTransController {
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -10,6 +10,8 @@ public interface RegisterDocumentService {
|
||||
|
||||
InvokeResponse createDocumentAndCallErp(List<DocumentDetailed> zwDocumentDetailList);
|
||||
|
||||
List<String> getSapBatchNo(String erpItem, int num);
|
||||
|
||||
void cancelDocumentNo(Document document);
|
||||
|
||||
String getSapBatchNo(String erpItem);
|
||||
|
||||
@ -257,6 +257,40 @@ public class RegisterDocumentServiceImpl implements RegisterDocumentService {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSapBatchNo(String erpItem, int num) {
|
||||
String site = TenantContextHolder.getTenantId();
|
||||
InvokeResponse invokeResponse = new InvokeResponse();
|
||||
InvokeRequest invokeRequest = new InvokeRequest();
|
||||
Map<String, Integer> itemMap = new HashMap<>();
|
||||
itemMap.put(erpItem, num);
|
||||
List<String> chargList = new ArrayList<>();
|
||||
|
||||
try {
|
||||
invokeResponse = assembleInvokeRequest(site, itemMap, invokeRequest);
|
||||
if ("E".equals(invokeResponse.getResult())) {
|
||||
throw BusinessException.build("获取物料的sap批次失败");
|
||||
} else {
|
||||
String jsonContent = invokeResponse.getMessageContent();
|
||||
List<Map> list = JSONArray.parseArray(jsonContent, Map.class);
|
||||
|
||||
for (Map<String, Object> item : list) {
|
||||
String charg = (String) item.get("CHARG");
|
||||
if (charg != null) {
|
||||
chargList.add(charg);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw BusinessException.build(e.getMessage());
|
||||
}
|
||||
|
||||
return chargList;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public InvokeResponse assembleInvokeRequest(String site, Map<String, Integer> items, InvokeRequest invokeRequest) {
|
||||
InvokeResponse invokeResponse = new InvokeResponse(invokeRequest);
|
||||
if (items.size() > 0) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user