rev:sap推送改切计划根据仓库生成多个单据

This commit is contained in:
2024-07-03 16:01:24 +08:00
parent 2bf7146c87
commit 1f9ea990ec

View File

@@ -18,6 +18,9 @@ import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
@@ -128,14 +131,20 @@ public class SapToLmsServiceImpl implements SapToLmsService {
public JSONObject getReCutInfo(JSONObject json) { public JSONObject getReCutInfo(JSONObject json) {
log.info("getReCutInfo的输入参数为------------------------" + json.toString()); log.info("getReCutInfo的输入参数为------------------------" + json.toString());
JSONObject jsonMst = new JSONObject();
JSONObject result = new JSONObject(); JSONObject result = new JSONObject();
String msg = "改切出库单据推送成功!"; String msg = "改切出库单据推送成功!";
try { try {
JSONArray dtl_ja = json.getJSONArray("ITEM"); // 需要插入分切计划的集合
String LGORT = dtl_ja.getJSONObject(0).getString("LGORT"); List<JSONObject> needInsetIos = new ArrayList<>();
// 子卷集合
List<JSONObject> dtl_ja = json.getJSONArray("ITEM").toJavaList(JSONObject.class);
// 根据仓库进行分类:一个仓库生成一个单据
Map<String, List<JSONObject>> storList = dtl_ja.stream()
.collect(Collectors.groupingBy(row -> row.getString("LGORT")));
for(String LGORT: storList.keySet()) {
// 查询仓库是否存在
JSONObject stor_jo = WQLObject.getWQLObject("ST_IVT_BSRealStorAttr").query("ext_id = '" + LGORT + "'").uniqueResult(0); JSONObject stor_jo = WQLObject.getWQLObject("ST_IVT_BSRealStorAttr").query("ext_id = '" + LGORT + "'").uniqueResult(0);
if (ObjectUtil.isEmpty(stor_jo)) { if (ObjectUtil.isEmpty(stor_jo)) {
result.put("RTYPE", "E"); result.put("RTYPE", "E");
@@ -145,13 +154,15 @@ public class SapToLmsServiceImpl implements SapToLmsService {
return result; return result;
} }
// 组织主表信息
JSONObject jsonMst = new JSONObject();
jsonMst.put("stor_id", stor_jo.getString("stor_id")); jsonMst.put("stor_id", stor_jo.getString("stor_id"));
jsonMst.put("stor_code", stor_jo.getString("stor_code")); jsonMst.put("stor_code", stor_jo.getString("stor_code"));
jsonMst.put("stor_name", stor_jo.getString("stor_name")); jsonMst.put("stor_name", stor_jo.getString("stor_name"));
// 组织明细信息
JSONArray dtls = new JSONArray(); JSONArray dtls = new JSONArray();
for (int i = 0; i < dtl_ja.size(); i++) { for (JSONObject jo : storList.get(LGORT)) {
JSONObject jo = dtl_ja.getJSONObject(i);
String sap_pcsn = jo.getString("CHARG"); String sap_pcsn = jo.getString("CHARG");
if (StrUtil.isEmpty("sap_pcsn")) { if (StrUtil.isEmpty("sap_pcsn")) {
throw new BadRequestException("请求参数SAP批次不能为空!"); throw new BadRequestException("请求参数SAP批次不能为空!");
@@ -191,10 +202,17 @@ public class SapToLmsServiceImpl implements SapToLmsService {
if (!dtls.isEmpty()) { if (!dtls.isEmpty()) {
jsonMst.put("tableData", dtls); jsonMst.put("tableData", dtls);
recutPlanService.insertDtl(jsonMst); needInsetIos.add(jsonMst);
} else { } else {
throw new BadRequestException("推送失败SAP推送的子卷明细不符合出库状态"); throw new BadRequestException("推送失败SAP推送的子卷明细不符合出库状态");
} }
}
// 生成单据
for(JSONObject jsonIos : needInsetIos) {
recutPlanService.insertDtl(jsonIos);
}
} catch (Exception exception) { } catch (Exception exception) {
result.put("TYPE", "E"); result.put("TYPE", "E");
result.put("MESSAGE", "推送失败!" + exception.getMessage()); result.put("MESSAGE", "推送失败!" + exception.getMessage());