|
|
@ -8,16 +8,16 @@ import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.nl.common.utils.CodeUtil; |
|
|
|
import org.nl.common.utils.SecurityUtils; |
|
|
|
import org.nl.modules.common.exception.BadRequestException; |
|
|
|
import org.nl.modules.wql.core.bean.WQLObject; |
|
|
|
import org.nl.wms.ext.sap.service.SapToLmsService; |
|
|
|
import org.nl.wms.st.instor.service.RecutPlanService; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
@Service |
|
|
@ -160,6 +160,184 @@ public class SapToLmsServiceImpl implements SapToLmsService { |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 转单指令在MES平台查看后,更新信息,发送LMS(是否拆包、更新后的入库日期、是否更换外包装箱标签),LMS重打子卷标签、包装箱外标签 |
|
|
|
* |
|
|
|
* @param param |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public JSONObject inventoryTransferInfoSync(JSONObject param) { |
|
|
|
/** |
|
|
|
* { |
|
|
|
* "SaleOrderItem": "销售订单号-行号", |
|
|
|
* "CustomerName": "客户编码", |
|
|
|
* "DemandDate": "销售订单行交货日期", |
|
|
|
* "item": [ |
|
|
|
* { |
|
|
|
* "SaleOrderItem": "销售订单号-行号", |
|
|
|
* "PackageBoxSN": "包装箱号", |
|
|
|
* "isRePrintPackageBoxLabel": "是否需要重打外包装标签", |
|
|
|
* "isUnPackBox": "是否需要拆包重打子卷标签", |
|
|
|
* "UpdatedDateOfProduction": "更改后的制造完成日期" |
|
|
|
* }, |
|
|
|
* { |
|
|
|
* "SaleOrderItem": "销售订单号-行号", |
|
|
|
* "PackageBoxSN": "包装箱号", |
|
|
|
* "isRePrintPackageBoxLabel": "是否需要重打外包装标签", |
|
|
|
* "isUnPackBox": "是否需要拆包重打子卷标签", |
|
|
|
* "UpdatedDateOfProduction": "更改后的制造完成日期" |
|
|
|
* } |
|
|
|
* ] |
|
|
|
* } |
|
|
|
*/ |
|
|
|
log.info("inventoryTransferInfoSync接口输入参数为:-------------------" + param.toString()); |
|
|
|
JSONObject result = new JSONObject(); |
|
|
|
|
|
|
|
try { |
|
|
|
JSONArray rows = param.getJSONArray("details"); |
|
|
|
String SaleOrderItem = param.getString("SaleOrderItem"); |
|
|
|
String CustomerName = param.getString("CustomerName"); |
|
|
|
String DemandDate = param.getString("DemandDate"); |
|
|
|
|
|
|
|
if (ObjectUtil.isEmpty(rows) || rows.size() == 0) { |
|
|
|
throw new BadRequestException("item长度不能为0!"); |
|
|
|
} |
|
|
|
|
|
|
|
// 定义set集合储存仓库
|
|
|
|
HashSet<String> storSet = new HashSet<>(); |
|
|
|
|
|
|
|
for (int i = 0; i < rows.size(); i++) { |
|
|
|
JSONObject json = rows.getJSONObject(i); |
|
|
|
String PackageBoxSN = json.getString("PackageBoxSN"); |
|
|
|
|
|
|
|
// 查询此木箱在哪个仓库
|
|
|
|
JSONObject jsonBox = WQLObject.getWQLObject("st_ivt_structattr") |
|
|
|
.query("storagevehicle_code = '" + PackageBoxSN + "' and is_delete = '0' and is_used = '1' and lock_type = '1'").uniqueResult(0); |
|
|
|
|
|
|
|
if (ObjectUtil.isEmpty(jsonBox)) { |
|
|
|
throw new BadRequestException("此木箱不在库内:" + PackageBoxSN); |
|
|
|
} |
|
|
|
storSet.add(jsonBox.getString("stor_code")); |
|
|
|
} |
|
|
|
|
|
|
|
// 根据仓库生成多个库存变更单据
|
|
|
|
for (String stor_code : storSet) { |
|
|
|
double total_qty = 0; |
|
|
|
double detail_count = 0; |
|
|
|
String changeinv_id = IdUtil.getSnowflake(1, 1).nextId() + ""; |
|
|
|
|
|
|
|
JSONObject jsonStor = WQLObject.getWQLObject("st_ivt_bsrealstorattr").query("stor_code = '" + stor_code + "'").uniqueResult(0); |
|
|
|
if (ObjectUtil.isEmpty(jsonStor)) { |
|
|
|
throw new BadRequestException("仓库不存在:" + stor_code); |
|
|
|
} |
|
|
|
|
|
|
|
JSONArray rowsDtl = new JSONArray(); |
|
|
|
|
|
|
|
for (int i = 0; i < rows.size(); i++) { |
|
|
|
JSONObject row = rows.getJSONObject(i); |
|
|
|
String PackageBoxSN = row.getString("PackageBoxSN"); |
|
|
|
|
|
|
|
JSONObject jsonBox = WQLObject.getWQLObject("st_ivt_structattr") |
|
|
|
.query("storagevehicle_code = '" + PackageBoxSN + "' and is_delete = '0' and is_used = '1' and lock_type = '1'").uniqueResult(0); |
|
|
|
|
|
|
|
if (StrUtil.equals(jsonBox.getString("stor_code"), stor_code)) { |
|
|
|
rowsDtl.add(row); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 插入库存变更主表明细表
|
|
|
|
for (int i = 0; i < rowsDtl.size(); i++) { |
|
|
|
JSONObject row = rowsDtl.getJSONObject(i); |
|
|
|
String PackageBoxSN = row.getString("PackageBoxSN"); |
|
|
|
String isRePrintPackageBoxLabel = row.getString("isRePrintPackageBoxLabel"); |
|
|
|
String isUnPackBox = row.getString("isUnPackBox"); |
|
|
|
String UpdatedDateOfProduction = row.getString("UpdatedDateOfProduction"); |
|
|
|
//查询该木箱内子卷数量
|
|
|
|
JSONArray container_rows = WQLObject.getWQLObject("pdm_bi_subpackagerelation").query("package_box_sn = '" + PackageBoxSN + "'").getResultJSONArray(0); |
|
|
|
for (int j = 0; j < container_rows.size(); j++) { |
|
|
|
JSONObject container_row = container_rows.getJSONObject(j); |
|
|
|
JSONObject change_jo = new JSONObject(); |
|
|
|
change_jo.put("changeinvdtl_id", IdUtil.getSnowflake(1, 1).nextId() + ""); |
|
|
|
change_jo.put("changeinv_id", changeinv_id); |
|
|
|
change_jo.put("seq_no", detail_count + 1); |
|
|
|
JSONObject mater_jo = WQLObject.getWQLObject("md_me_materialbase").query("material_code = '" + container_row.getString("product_name") + "'").uniqueResult(0); |
|
|
|
if (ObjectUtil.isEmpty(mater_jo)) { |
|
|
|
throw new BadRequestException("物料不存在:" + container_row.getString("product_name")); |
|
|
|
} |
|
|
|
change_jo.put("material_id", mater_jo.getString("material_id")); |
|
|
|
change_jo.put("pcsn", container_row.getString("container_name")); |
|
|
|
change_jo.put("package_box_sn", container_row.getString("package_box_sn")); |
|
|
|
change_jo.put("mfg_order_name", SaleOrderItem); |
|
|
|
change_jo.put("demand_date", DemandDate); |
|
|
|
change_jo.put("customer_name", CustomerName); |
|
|
|
//查询对应的客户
|
|
|
|
JSONObject customer_jo = WQLObject.getWQLObject("md_cs_customerbase").query("cust_code = '" + CustomerName + "'").uniqueResult(0); |
|
|
|
if (ObjectUtil.isEmpty(customer_jo)) { |
|
|
|
throw new BadRequestException("客户不存在:" + CustomerName); |
|
|
|
} |
|
|
|
change_jo.put("customer_description", customer_jo.getString("cust_name")); |
|
|
|
change_jo.put("isRePrintPackageBoxLabel", isRePrintPackageBoxLabel); |
|
|
|
change_jo.put("isUnPackBox", isUnPackBox); |
|
|
|
change_jo.put("UpdatedDateOfProduction", UpdatedDateOfProduction); |
|
|
|
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")); |
|
|
|
} |
|
|
|
change_jo.put("qty_unit_id", mater_jo.getString("base_unit_id")); |
|
|
|
change_jo.put("qty_unit_name", unit.getString("unit_name")); |
|
|
|
change_jo.put("qty", container_row.getString("net_weight")); |
|
|
|
WQLObject.getWQLObject("ST_IVT_StructIvtChangeDtl").insert(change_jo); |
|
|
|
total_qty += container_row.getDoubleValue("net_weight"); |
|
|
|
detail_count += 1; |
|
|
|
} |
|
|
|
} |
|
|
|
String currentUserId = SecurityUtils.getCurrentUserId(); |
|
|
|
String nickName = SecurityUtils.getCurrentNickName(); |
|
|
|
String now = DateUtil.now(); |
|
|
|
|
|
|
|
JSONObject mst_jo = new JSONObject(); |
|
|
|
mst_jo.put("changeinv_id", changeinv_id); |
|
|
|
mst_jo.put("bill_code", CodeUtil.getNewCode("CHANGE_CODE")); |
|
|
|
mst_jo.put("buss_type", "2001"); |
|
|
|
mst_jo.put("bill_type", "2001"); |
|
|
|
mst_jo.put("biz_date", DateUtil.today()); |
|
|
|
mst_jo.put("stor_id", jsonStor.getString("stor_id")); |
|
|
|
mst_jo.put("stor_code", jsonStor.getString("stor_code")); |
|
|
|
mst_jo.put("stor_name", jsonStor.getString("stor_name")); |
|
|
|
mst_jo.put("total_qty", total_qty); |
|
|
|
mst_jo.put("detail_count", detail_count); |
|
|
|
mst_jo.put("bill_status", "10"); |
|
|
|
mst_jo.put("create_mode", "03"); |
|
|
|
mst_jo.put("input_optid", currentUserId + ""); |
|
|
|
mst_jo.put("input_optname", nickName); |
|
|
|
mst_jo.put("input_time", now); |
|
|
|
mst_jo.put("update_optid", currentUserId + ""); |
|
|
|
mst_jo.put("update_optname", nickName); |
|
|
|
mst_jo.put("update_time", now); |
|
|
|
mst_jo.put("is_delete", "0"); |
|
|
|
mst_jo.put("is_upload", "0"); |
|
|
|
Long deptId = SecurityUtils.getDeptId(); |
|
|
|
mst_jo.put("sysdeptid", deptId + ""); |
|
|
|
mst_jo.put("syscompanyid", deptId + ""); |
|
|
|
WQLObject.getWQLObject("ST_IVT_StructIvtChange").insert(mst_jo); |
|
|
|
} |
|
|
|
result.put("RTYPE", "S"); |
|
|
|
result.put("RTMSG", "操作成功!"); |
|
|
|
result.put("RTOAL", 1); |
|
|
|
result.put("RTDAT", null); |
|
|
|
} catch (Exception e) { |
|
|
|
result.put("RTYPE", "E"); |
|
|
|
result.put("RTMSG", "操作失败!," + e.getMessage()); |
|
|
|
result.put("RTOAL", 0); |
|
|
|
result.put("RTDAT", null); |
|
|
|
} |
|
|
|
// }
|
|
|
|
log.info("inventoryTransferInfoSync接口输出参数为:-------------------" + result.toString()); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public JSONObject getMaterialInfo(JSONObject jo) { |
|
|
|
JSONArray rows = jo.getJSONArray("DATAS"); |
|
|
|