rev:sap推送改切计划根据仓库生成多个单据
This commit is contained in:
@@ -18,6 +18,9 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@@ -128,73 +131,88 @@ public class SapToLmsServiceImpl implements SapToLmsService {
|
||||
public JSONObject getReCutInfo(JSONObject json) {
|
||||
log.info("getReCutInfo的输入参数为:------------------------" + json.toString());
|
||||
|
||||
JSONObject jsonMst = new JSONObject();
|
||||
|
||||
JSONObject result = new JSONObject();
|
||||
|
||||
String msg = "改切出库单据推送成功!";
|
||||
|
||||
try {
|
||||
JSONArray dtl_ja = json.getJSONArray("ITEM");
|
||||
String LGORT = dtl_ja.getJSONObject(0).getString("LGORT");
|
||||
JSONObject stor_jo = WQLObject.getWQLObject("ST_IVT_BSRealStorAttr").query("ext_id = '" + LGORT + "'").uniqueResult(0);
|
||||
if (ObjectUtil.isEmpty(stor_jo)) {
|
||||
result.put("RTYPE", "E");
|
||||
result.put("RTMSG", "操作失败!" + "未查询到外部标识为:" + LGORT + "对应的仓库!");
|
||||
result.put("RTOAL", 1);
|
||||
result.put("RTDAT", null);
|
||||
return result;
|
||||
}
|
||||
// 需要插入分切计划的集合
|
||||
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")));
|
||||
|
||||
jsonMst.put("stor_id", stor_jo.getString("stor_id"));
|
||||
jsonMst.put("stor_code", stor_jo.getString("stor_code"));
|
||||
jsonMst.put("stor_name", stor_jo.getString("stor_name"));
|
||||
for(String LGORT: storList.keySet()) {
|
||||
// 查询仓库是否存在
|
||||
JSONObject stor_jo = WQLObject.getWQLObject("ST_IVT_BSRealStorAttr").query("ext_id = '" + LGORT + "'").uniqueResult(0);
|
||||
if (ObjectUtil.isEmpty(stor_jo)) {
|
||||
result.put("RTYPE", "E");
|
||||
result.put("RTMSG", "操作失败!" + "未查询到外部标识为:" + LGORT + "对应的仓库!");
|
||||
result.put("RTOAL", 1);
|
||||
result.put("RTDAT", null);
|
||||
return result;
|
||||
}
|
||||
|
||||
JSONArray dtls = new JSONArray();
|
||||
for (int i = 0; i < dtl_ja.size(); i++) {
|
||||
JSONObject jo = dtl_ja.getJSONObject(i);
|
||||
String sap_pcsn = jo.getString("CHARG");
|
||||
if (StrUtil.isEmpty("sap_pcsn")) {
|
||||
throw new BadRequestException("请求参数SAP批次不能为空!");
|
||||
}
|
||||
JSONObject sub_jo = WQLObject.getWQLObject("PDM_BI_SubPackageRelation").query("sap_pcsn = '" + sap_pcsn + "'").uniqueResult(0);
|
||||
if (ObjectUtil.isEmpty(sub_jo)) {
|
||||
throw new BadRequestException("LMS中不存在SAP批次为【" + sap_pcsn + "】的包装关系");
|
||||
}
|
||||
String container_name = sub_jo.getString("container_name");
|
||||
JSONObject struct_ivt = WQLObject.getWQLObject("st_ivt_structivt").query("pcsn = '" + container_name + "'").uniqueResult(0);
|
||||
if (ObjectUtil.isEmpty(struct_ivt)) {
|
||||
throw new BadRequestException("SAP批次为【" + sap_pcsn + "】的成品卷不存在或已经出库!");
|
||||
} else {
|
||||
if (struct_ivt.getDoubleValue("frozen_qty") > 0) {
|
||||
msg = "SAP批次为【" + sap_pcsn + "】的成品卷已经被分配或出库中";
|
||||
// 组织主表信息
|
||||
JSONObject jsonMst = new JSONObject();
|
||||
jsonMst.put("stor_id", stor_jo.getString("stor_id"));
|
||||
jsonMst.put("stor_code", stor_jo.getString("stor_code"));
|
||||
jsonMst.put("stor_name", stor_jo.getString("stor_name"));
|
||||
|
||||
// 组织明细信息
|
||||
JSONArray dtls = new JSONArray();
|
||||
for (JSONObject jo : storList.get(LGORT)) {
|
||||
String sap_pcsn = jo.getString("CHARG");
|
||||
if (StrUtil.isEmpty("sap_pcsn")) {
|
||||
throw new BadRequestException("请求参数SAP批次不能为空!");
|
||||
}
|
||||
JSONObject sub_jo = WQLObject.getWQLObject("PDM_BI_SubPackageRelation").query("sap_pcsn = '" + sap_pcsn + "'").uniqueResult(0);
|
||||
if (ObjectUtil.isEmpty(sub_jo)) {
|
||||
throw new BadRequestException("LMS中不存在SAP批次为【" + sap_pcsn + "】的包装关系");
|
||||
}
|
||||
String container_name = sub_jo.getString("container_name");
|
||||
JSONObject struct_ivt = WQLObject.getWQLObject("st_ivt_structivt").query("pcsn = '" + container_name + "'").uniqueResult(0);
|
||||
if (ObjectUtil.isEmpty(struct_ivt)) {
|
||||
throw new BadRequestException("SAP批次为【" + sap_pcsn + "】的成品卷不存在或已经出库!");
|
||||
} else {
|
||||
JSONObject dtl = new JSONObject();
|
||||
//查询该物料
|
||||
JSONObject mater_jo = WQLObject.getWQLObject("md_me_materialbase").query("material_code = '" + sub_jo.getString("product_name") + "'").uniqueResult(0);
|
||||
if (ObjectUtil.isEmpty(mater_jo)) {
|
||||
throw new BadRequestException("未查询到物料:" + sub_jo.getString("product_name") + ",信息!");
|
||||
if (struct_ivt.getDoubleValue("frozen_qty") > 0) {
|
||||
msg = "SAP批次为【" + sap_pcsn + "】的成品卷已经被分配或出库中";
|
||||
} else {
|
||||
JSONObject dtl = new JSONObject();
|
||||
//查询该物料
|
||||
JSONObject mater_jo = WQLObject.getWQLObject("md_me_materialbase").query("material_code = '" + sub_jo.getString("product_name") + "'").uniqueResult(0);
|
||||
if (ObjectUtil.isEmpty(mater_jo)) {
|
||||
throw new BadRequestException("未查询到物料:" + sub_jo.getString("product_name") + ",信息!");
|
||||
}
|
||||
dtl.put("material_id", mater_jo.getString("material_id"));
|
||||
dtl.put("sap_pcsn", sap_pcsn);
|
||||
JSONObject unit = WQLObject.getWQLObject("md_pb_measureunit").query("measure_unit_id = '" + mater_jo.getString("base_unit_id") + "'").uniqueResult(0);
|
||||
if (ObjectUtil.isEmpty(unit)) {
|
||||
throw new BadRequestException("未查询到物料计量单位:" + mater_jo.getString("base_unit_id") + ",信息!");
|
||||
}
|
||||
dtl.put("qty_unit_id", unit.getString("measure_unit_id"));
|
||||
dtl.put("qty_unit_name", unit.getString("unit_name"));
|
||||
dtl.put("package_box_sn", sub_jo.getString("package_box_sn"));
|
||||
dtl.put("qty", sub_jo.getString("net_weight"));
|
||||
dtls.add(dtl);
|
||||
}
|
||||
dtl.put("material_id", mater_jo.getString("material_id"));
|
||||
dtl.put("sap_pcsn", sap_pcsn);
|
||||
JSONObject unit = WQLObject.getWQLObject("md_pb_measureunit").query("measure_unit_id = '" + mater_jo.getString("base_unit_id") + "'").uniqueResult(0);
|
||||
if (ObjectUtil.isEmpty(unit)) {
|
||||
throw new BadRequestException("未查询到物料计量单位:" + mater_jo.getString("base_unit_id") + ",信息!");
|
||||
}
|
||||
dtl.put("qty_unit_id", unit.getString("measure_unit_id"));
|
||||
dtl.put("qty_unit_name", unit.getString("unit_name"));
|
||||
dtl.put("package_box_sn", sub_jo.getString("package_box_sn"));
|
||||
dtl.put("qty", sub_jo.getString("net_weight"));
|
||||
dtls.add(dtl);
|
||||
}
|
||||
}
|
||||
|
||||
if (!dtls.isEmpty()) {
|
||||
jsonMst.put("tableData", dtls);
|
||||
needInsetIos.add(jsonMst);
|
||||
} else {
|
||||
throw new BadRequestException("推送失败!SAP推送的子卷明细不符合出库状态!");
|
||||
}
|
||||
}
|
||||
|
||||
if (!dtls.isEmpty()) {
|
||||
jsonMst.put("tableData", dtls);
|
||||
recutPlanService.insertDtl(jsonMst);
|
||||
} else {
|
||||
throw new BadRequestException("推送失败!SAP推送的子卷明细不符合出库状态!");
|
||||
// 生成单据
|
||||
for(JSONObject jsonIos : needInsetIos) {
|
||||
recutPlanService.insertDtl(jsonIos);
|
||||
}
|
||||
|
||||
} catch (Exception exception) {
|
||||
result.put("TYPE", "E");
|
||||
result.put("MESSAGE", "推送失败!" + exception.getMessage());
|
||||
|
||||
Reference in New Issue
Block a user