fix:优化操作与修复一些字段格式问题

This commit is contained in:
2026-09-23 19:32:24 +08:00
parent b5b62e84e6
commit 7991e0ff82
9 changed files with 408 additions and 46 deletions

View File

@@ -97,6 +97,14 @@ public class InboundPdaController {
inboundPdaService.usualInbound(usualInboundDto);
return ResponseData.build();
}
@PostMapping("/usualInboundList")
@Log("批量入平库")
@SaIgnore
public ResponseEntity usualInboundList(@RequestBody UsualInboundBatchDto batchDto) {
JSONObject result = inboundPdaService.usualInboundList(batchDto);
return ResponseData.build(result);
}
@PostMapping("/returnInbound")
@Log("退料入库")
@SaIgnore

View File

@@ -17,6 +17,14 @@ public interface InboundPdaService {
void usualInbound(UsualInboundDto usualInboundDto);
/**
* 批量入平库:对勾选的多张 SAP 物料凭证逐单执行平库入库。
*
* @param batchDto 勾选行列表 + 可选库区
* @return 执行结果汇总 {total, successCount, failCount, failList[]}
*/
JSONObject usualInboundList(UsualInboundBatchDto batchDto);
void submitGroupPlateInbound(GroupPlateInboundDto dto, Boolean subTask);
void submitManualInbound(ManualInboundDto dto);

View File

@@ -8,6 +8,7 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.nl.common.exception.BadRequestException;
@@ -15,6 +16,7 @@ import org.nl.common.utils.CodeUtil;
import org.nl.common.utils.IdUtil;
import org.nl.common.utils.MapOf;
import org.nl.common.utils.SecurityUtils;
import org.nl.config.SpringContextHolder;
import org.nl.wms.basedata_manage.enums.BaseDataEnum;
import org.nl.wms.basedata_manage.service.*;
import org.nl.wms.basedata_manage.service.dao.*;
@@ -27,6 +29,7 @@ import org.nl.wms.pm_manage.purchase.ListenerHandler.PurchaseListenerParams;
import org.nl.wms.pm_manage.purchase.service.PurchaseService;
import org.nl.wms.pm_manage.purchase.service.dao.Purchasedtl;
import org.nl.wms.pm_manage.sap.materialDocument.enums.MaterialDocumentBillType;
import org.nl.wms.pm_manage.sap.materialDocument.enums.MaterialDocumentIo;
import org.nl.wms.pm_manage.sap.materialDocument.enums.MaterialDocumentStatus;
import org.nl.wms.pm_manage.sap.materialDocument.service.dao.MaterialDocument;
import org.nl.wms.pm_manage.sap.materialDocument.service.dao.MaterialDocumentItem;
@@ -393,6 +396,78 @@ public class InboundPdaServiceImpl implements InboundPdaService {
groupPlateInboundDto.setVehicle_code(storagevehicleCode);
groupPlateInboundDto.setGroupPlateList(gpList);
this.submitGroupPlateInbound(groupPlateInboundDto, false);
// 入库成功后回写 SAP 物料凭证:累加已完成数量 + 单据标记完成
// 放在最后:前面任何一步抛异常都会回滚,状态保持 CREATED,可安全重试
markMaterialDocumentCompleted(usualInboundDto.getBill_id(), usualInboundDto.getDetailList());
}
/**
* 回写 SAP 物料凭证:按行累加已入库数量,并把单据状态置为已完成。
* <p>
* 仅在单据当前为 CREATED 时回写(条件更新,天然防并发重复回写)。
* 本方法在 {@link #usualInbound} 的事务内被调用,失败会随事务一起回滚,状态保持 CREATED。
*/
private void markMaterialDocumentCompleted(String billId, List<UsualInboundDto.UsualInboundDtlDto> detailList) {
if (StrUtil.isBlank(billId)) {
return;
}
MaterialDocument document = documentMapper.selectOne(new LambdaQueryWrapper<MaterialDocument>()
.eq(MaterialDocument::getMblnr, billId)
.eq(MaterialDocument::getBilltype, MaterialDocumentBillType.PURCHASE_IN.getCode())
.eq(MaterialDocument::getDeleted, 0)
.last("LIMIT 1"));
if (document == null) {
log.warn("平库入库:未找到物料凭证{},跳过已完成数量回写", billId);
return;
}
// 逐行累加已入库数量(按行号定位,行号为空则退回按物料编码定位)
List<MaterialDocumentItem> items = itemMapper.selectList(
new LambdaQueryWrapper<MaterialDocumentItem>()
.eq(MaterialDocumentItem::getDocument_id, document.getId())
.eq(MaterialDocumentItem::getDeleted, 0)
);
if (detailList != null) {
for (UsualInboundDto.UsualInboundDtlDto dtl : detailList) {
if (dtl == null || dtl.getQty() == null) {
continue;
}
MaterialDocumentItem target = matchDocumentItem(items, dtl);
if (target != null) {
BigDecimal current = target.getInstock_qty() == null ? BigDecimal.ZERO : target.getInstock_qty();
target.setInstock_qty(current.add(dtl.getQty()));
itemMapper.updateById(target);
}
}
}
// 完成状态由数据库条件更新,只有仍是 CREATED 才会生效
documentMapper.update(null, new LambdaUpdateWrapper<MaterialDocument>()
.set(MaterialDocument::getStatus, MaterialDocumentStatus.COMPLETED.getCode())
.eq(MaterialDocument::getId, document.getId())
.eq(MaterialDocument::getStatus, MaterialDocumentStatus.CREATED.getCode()));
}
/**
* 在物料凭证明细中定位本次入库对应的行:优先用行号(item_no → zeile),退回按物料编码。
*/
private MaterialDocumentItem matchDocumentItem(List<MaterialDocumentItem> items,
UsualInboundDto.UsualInboundDtlDto dtl) {
if (items == null || items.isEmpty()) {
return null;
}
if (StrUtil.isNotBlank(dtl.getItem_no())) {
for (MaterialDocumentItem item : items) {
if (item.getZeile() != null && dtl.getItem_no().equals(String.valueOf(item.getZeile()))) {
return item;
}
}
}
for (MaterialDocumentItem item : items) {
if (StrUtil.isNotBlank(dtl.getSku_code()) && dtl.getSku_code().equals(item.getMatnr())) {
return item;
}
}
return null;
}
/**
@@ -453,10 +528,132 @@ public class InboundPdaServiceImpl implements InboundPdaService {
.apply("UPPER(unit_name) = {0}", val.toUpperCase()).last("limit 1"));
}
@Override
public JSONObject usualInboundList(UsualInboundBatchDto batchDto) {
if (batchDto == null || batchDto.getList() == null || batchDto.getList().isEmpty()) {
throw new BadRequestException("批量入平库失败:未选择任何单据");
}
String sectCode = StrUtil.isNotBlank(batchDto.getSect_code())
? batchDto.getSect_code().trim() :"R001";
InboundPdaService self = SpringContextHolder.getBean(InboundPdaService.class);
List<JSONObject> failList = new ArrayList<>();
int successCount = 0;
int total = batchDto.getList().size();
for (UsualInboundBatchDto.Item row : batchDto.getList()) {
if (row == null) {
total--;
continue;
}
String billNo = StrUtil.blankToDefault(row.getMblnr(), String.valueOf(row.getId()));
MaterialDocument document = resolveBatchDocument(row);
String skipReason = checkBatchRow(document);
if (skipReason != null) {
failList.add(buildBatchResult(billNo, skipReason));
continue;
}
try {
self.usualInbound(buildUsualInboundDto(document, sectCode));
successCount++;
} catch (Exception e) {
failList.add(buildBatchResult(billNo, e.getMessage()));
}
}
JSONObject result = new JSONObject();
result.put("total", total);
result.put("successCount", successCount);
result.put("failCount", failList.size());
result.put("failList", failList);
result.put("sect_code", sectCode);
return result;
}
/**
* 按 id 优先、mblnr 兜底定位物料凭证主单,供校验与明细反查共用。
*/
private MaterialDocument resolveBatchDocument(UsualInboundBatchDto.Item row) {
if (row.getId() != null) {
MaterialDocument document = documentMapper.selectById(row.getId());
if (document != null) {
return document;
}
}
if (StrUtil.isNotBlank(row.getMblnr())) {
return documentMapper.selectOne(new LambdaQueryWrapper<MaterialDocument>()
.eq(MaterialDocument::getMblnr, row.getMblnr())
.eq(MaterialDocument::getBilltype, MaterialDocumentBillType.PURCHASE_IN.getCode())
.eq(MaterialDocument::getDeleted, 0)
.last("LIMIT 1"));
}
return null;
}
/**
* 批量前的单据校验:只处理「采购入库 + 已创建 + 入库方向」的单据,防止重复入库或入错方向。
*/
private String checkBatchRow(MaterialDocument document) {
if (document == null) {
return "未找到对应的采购入库单";
}
if (!MaterialDocumentBillType.PURCHASE_IN.getCode().equals(document.getBilltype())) {
return "非采购入库单据,不支持入平库";
}
if (!MaterialDocumentIo.IN.getCode().equals(document.getIo())) {
return "非入库方向的单据,不支持入平库";
}
if (!MaterialDocumentStatus.CREATED.getCode().equals(document.getStatus())) {
MaterialDocumentStatus status = null;
for (MaterialDocumentStatus value : MaterialDocumentStatus.values()) {
if (value.getCode().equals(document.getStatus())) {
status = value;
break;
}
}
return "单据状态为" + (status == null ? document.getStatus() : status.getName()) + ",已处理过,跳过";
}
return null;
}
/**
* 组装单个平库入库入参:明细由 material_document_item 反查,与 PDA 扫码入库口径一致。
*/
private UsualInboundDto buildUsualInboundDto(MaterialDocument document, String sectCode) {
List<MaterialDocumentItem> items = itemMapper.selectList(
new LambdaQueryWrapper<MaterialDocumentItem>()
.eq(MaterialDocumentItem::getDocument_id, document.getId())
.eq(MaterialDocumentItem::getDeleted, 0)
.orderByAsc(MaterialDocumentItem::getZeile)
);
if (items.isEmpty()) {
throw new BadRequestException("单据" + document.getMblnr() + "没有可入库的明细");
}
List<UsualInboundDto.UsualInboundDtlDto> detailList = new ArrayList<>();
for (MaterialDocumentItem item : items) {
UsualInboundDto.UsualInboundDtlDto dtl = new UsualInboundDto.UsualInboundDtlDto();
dtl.setOrder_no(StrUtil.blankToDefault(item.getEbeln(), document.getMblnr()));
dtl.setItem_no(item.getZeile() == null ? null : String.valueOf(item.getZeile()));
dtl.setSku_code(item.getMatnr());
dtl.setBatch_no(item.getCharg());
dtl.setQty(item.getMenge());
detailList.add(dtl);
}
UsualInboundDto dto = new UsualInboundDto();
dto.setBill_id(document.getMblnr());
dto.setSect_code(sectCode);
dto.setDetailList(detailList);
return dto;
}
private JSONObject buildBatchResult(String billNo, String reason) {
JSONObject json = new JSONObject();
json.put("mblnr", billNo);
json.put("reason", StrUtil.blankToDefault(reason, "未知原因"));
return json;
}
@Override
@Transactional
public void submitGroupPlateInbound(GroupPlateInboundDto groupPlateInboundDto, Boolean subTask) {
// 查询组盘明细
public void submitGroupPlateInbound(GroupPlateInboundDto groupPlateInboundDto, Boolean subTask) { // 查询组盘明细
List<GroupPlate> plateDaoList;
if (groupPlateInboundDto.getGroupPlateList().isEmpty()){
plateDaoList = iMdPbGroupplateService.list(

View File

@@ -3,6 +3,7 @@ package org.nl.wms.pm_manage.demand.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONArray;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@@ -109,8 +110,8 @@ public class PmDemandServiceImpl extends ServiceImpl<PmDemandMapper, PmDemand> i
demand.setCreate_time(param.getCreateTime());
demand.setPriority(param.getPriority());
demand.setStatus(param.getStatus());
demand.setSeq_no(param.getSeqNo());
demand.setWork_order(param.getWorkOrder());
demand.setSeq_no(StringUtils.isBlank(param.getSeqNo())?null:param.getSeqNo());
demand.setWork_order(StringUtils.isBlank(param.getWorkOrder())?param.getOrderCode():param.getWorkOrder());
demand.setSku_code(param.getSkuCode());
demand.setSku_name(param.getSkuName());
demand.setQty(param.getQty());
@@ -151,8 +152,8 @@ public class PmDemandServiceImpl extends ServiceImpl<PmDemandMapper, PmDemand> i
demand.setCreate_time(pmDemandParam.getCreateTime());
demand.setPriority(pmDemandParam.getPriority());
demand.setStatus(pmDemandParam.getStatus());
demand.setSeq_no(pmDemandParam.getSeqNo());
demand.setWork_order(pmDemandParam.getWorkOrder());
demand.setSeq_no(StringUtils.isBlank(pmDemandParam.getSeqNo())?null:pmDemandParam.getSeqNo());
demand.setWork_order(StringUtils.isBlank(pmDemandParam.getWorkOrder())?pmDemandParam.getOrderCode():pmDemandParam.getWorkOrder());
demand.setOrder_code(pmDemandParam.getOrderCode());
demand.setSku_code(pmDemandParam.getSkuCode());
demand.setSku_name(pmDemandParam.getSkuName());
@@ -217,6 +218,40 @@ public class PmDemandServiceImpl extends ServiceImpl<PmDemandMapper, PmDemand> i
}
/**
* 把逗号拼接的分配仓库写入值转成 json 列可接受的 JSON 数组文本。
* <p>
* pm_demand.inventory_dis 是 json 列,直接写 "6.011" 会因 JSON 语法非法报
* Invalid JSON text(见 PmDemandServiceImpl#allocateInventory)。
* 下游(SAP lgort、MES issueWarehouseNo)只接受单个仓库号,故取第一个有效值。
*/
private String buildInventoryDisJson(String inventoryDis) {
String first = resolveInventoryWarehouse(inventoryDis);
return JSON.toJSONString(Collections.singletonList(first));
}
/**
* 从 inventory_dis 列值中取出仓库号:兼容历史标量值("6.011")与新的 JSON 数组(["6.011"])。
*/
private String resolveInventoryWarehouse(String raw) {
if (StringUtils.isBlank(raw)) {
return "";
}
String text = raw.trim();
if (text.startsWith("[")) {
try {
List<String> values = JSON.parseArray(text, String.class);
if (!CollectionUtils.isEmpty(values) && StringUtils.isNotBlank(values.get(0))) {
return values.get(0);
}
} catch (Exception e) {
log.warn("解析inventory_dis失败: {}", raw);
}
}
// 逗号拼接的历史值只取第一个,保证下游拿到的是合法仓库号
return text.contains(",") ? text.split(",")[0].trim() : text;
}
@Override
public void allocateInventory(String id, String inventoryDis) {
PmDemand demand = this.getById(id);
@@ -226,7 +261,7 @@ public class PmDemandServiceImpl extends ServiceImpl<PmDemandMapper, PmDemand> i
if (Objects.equals(demand.getStatus(), DemandStatus.FINISH.getValue())){
throw new BadRequestException("单据已完成不允许分配");
}
demand.setInventory_dis(inventoryDis);
demand.setInventory_dis(buildInventoryDisJson(inventoryDis));
demand.setStatus(DemandStatus.DIS.getValue());
this.updateById(demand);
}
@@ -246,7 +281,7 @@ public class PmDemandServiceImpl extends ServiceImpl<PmDemandMapper, PmDemand> i
}
}
this.update(new LambdaUpdateWrapper<PmDemand>()
.set(PmDemand::getInventory_dis, inventoryDis)
.set(PmDemand::getInventory_dis, buildInventoryDisJson(inventoryDis))
.set(PmDemand::getStatus, DemandStatus.DIS.getValue())
.in(PmDemand::getId, ids));
}
@@ -354,7 +389,7 @@ public class PmDemandServiceImpl extends ServiceImpl<PmDemandMapper, PmDemand> i
}
Map<Boolean, List<PmDemandDto>> partitioned = pmDemandDtos.stream()
.collect(Collectors.partitioningBy(a -> ZD_STOR_SET
.contains(a.getInventoryDis())));
.contains(resolveInventoryWarehouse(a.getInventoryDis()))));
List<PmDemandDto> zdDemands = partitioned.get(true);
List<PmDemandDto> otherDemands = partitioned.get(false);
if (!CollectionUtils.isEmpty(otherDemands)) {
@@ -371,10 +406,15 @@ public class PmDemandServiceImpl extends ServiceImpl<PmDemandMapper, PmDemand> i
//判断是否存在其他工单的数据是则保存
for (String workOrder : groupByWorkOrder.keySet()) {
final List<PmDemandDto> demandDtos = groupByWorkOrder.get(workOrder);
final int orderCount = this.count(new LambdaQueryWrapper<PmDemand>()
// inventory_dis 是 json 列,不能用 SQL IN 直接比对;
// 先按工单取出未删除的分配仓库,解析后判断是否全部属于中鼎仓库
final List<PmDemand> orderDemands = this.list(new LambdaQueryWrapper<PmDemand>()
.eq(PmDemand::getWork_order, workOrder)
.in(PmDemand::getInventory_dis, ZD_STOR_SET)
.ne(PmDemand::getIs_deleted, 1));
.ne(PmDemand::getIs_deleted, 1)
.select(PmDemand::getInventory_dis));
final long orderCount = orderDemands.stream()
.filter(d -> ZD_STOR_SET.contains(resolveInventoryWarehouse(d.getInventory_dis())))
.count();
if (orderCount > demandDtos.size()){
throw new BadRequestException("工单"+workOrder+"下推中鼎失败,存在未勾选的单子");
}
@@ -427,7 +467,7 @@ public class PmDemandServiceImpl extends ServiceImpl<PmDemandMapper, PmDemand> i
PmDemandDto firstDemand = demands.get(0);
JSONObject billParam = new JSONObject();
billParam.put("stor_code", firstDemand.getInventoryDis());
billParam.put("stor_code", resolveInventoryWarehouse(firstDemand.getInventoryDis()));
billParam.put("biz_date", DateUtil.today());
billParam.put("bill_type", IOSEnum.BILL_TYPE.code("库存调拨"));
billParam.put("remark", "需求单下推生成");
@@ -496,7 +536,7 @@ public class PmDemandServiceImpl extends ServiceImpl<PmDemandMapper, PmDemand> i
entry.put("unitNo", "PCS"); // 序号
entry.put("qty", pmDemand.getQty()); // 数量
entry.put("materialNo", pmDemand.getSku_code()); // 来源单据标识
entry.put("issueWarehouseNo", pmDemand.getInventory_dis());
entry.put("issueWarehouseNo", resolveInventoryWarehouse(pmDemand.getInventory_dis()));
entry.put("receiptWarehouseNo", region.getPoint_type_explain());
entrys.add(entry);
}
@@ -527,14 +567,14 @@ public class PmDemandServiceImpl extends ServiceImpl<PmDemandMapper, PmDemand> i
final DemandInventryDto demandInventryDto = inventryDtoMap.get("6.002");
final DemandInventryDto pInventryDto = inventryDtoMap.get("6.011");
if (demandInventryDto !=null && demandInventryDto.getQty()!=null && demandInventryDto.getQty().compareTo(pmDemand.getQty())>=0){
pmDemand.setInventory_dis("6.002");
pmDemand.setInventory_dis(buildInventoryDisJson("6.002"));
pmDemand.setStatus(DemandStatus.DIS.getValue());
needAllcation.add(pmDemand);
}else if (pInventryDto !=null && pInventryDto.getQty()!=null && pInventryDto.getQty().compareTo(pmDemand.getQty())>=0){
pmDemand.setInventory_dis("6.011");
pmDemand.setInventory_dis(buildInventoryDisJson("6.011"));
pmDemand.setStatus(DemandStatus.DIS.getValue());
}else {
pmDemand.setInventory_dis("库存不足请手动分配");
pmDemand.setInventory_dis(buildInventoryDisJson("库存不足请手动分配"));
}
needAllcation.add(pmDemand);
}

View File

@@ -200,6 +200,28 @@ public class SapDealLLDBBillPmDeamndCallBack implements CallbackStrategy {
return items;
}
/**
* 取 SAP 库存地点(lgort):pm_demand.inventory_dis 是 json 列,值为 JSON 数组(["6.011"]),
* 不能直接塞给 SAP,需解析出仓库号;同时兼容历史标量值。
*/
private String resolveInventoryLgort(String inventoryDis) {
if (StringUtils.isBlank(inventoryDis)) {
return null;
}
String text = inventoryDis.trim();
if (text.startsWith("[")) {
try {
List<String> values = JSON.parseArray(text, String.class);
if (values != null && !values.isEmpty() && StringUtils.isNotBlank(values.get(0))) {
return values.get(0);
}
} catch (Exception e) {
log.warn("解析inventory_dis失败: {}", inventoryDis);
}
}
return text.contains(",") ? text.split(",")[0].trim() : text;
}
private MaterialTransferItem toTransferItem(IOStorInvDtl param, PmDemand demand, String umlgo,
IOStorInvDisDto dis) {
MaterialTransferItem item = new MaterialTransferItem();
@@ -219,7 +241,7 @@ public class SapDealLLDBBillPmDeamndCallBack implements CallbackStrategy {
param.getIostorinvdtl_id()));
item.setBwart(SapConstant.BWART_TRANSFER_311);
item.setLgort(StrUtil.blankToDefault(
demand.getInventory_dis(),
resolveInventoryLgort(demand.getInventory_dis()),
dis != null ? dis.getSect_code() : ""));
item.setMeins(StrUtil.blankToDefault(
dis != null ? dis.getQty_unit_name() : null,