add:库存导出,修复收货组盘多单据扫码

This commit is contained in:
zhaoyf
2026-11-08 17:21:00 +08:00
parent 785677cf34
commit ef84d21fa4
3 changed files with 145 additions and 15 deletions

View File

@@ -82,7 +82,7 @@ PDA 扫码后调用以下接口收货:
| 接口 | 说明 |
|------|------|
| `GET /api/pda/inbound/getInfoByCode?code=` | **单次扫码只返回一条明细**:按标签行号取当前行,未识别到行号直接报错(不再返回整单明细);并校验标签物料与单据行一致。返回**剩余可入库数量**(单据数量 − 已入库数量),该行已收满直接报错 |
| `POST /api/pda/inbound/groupPlate` | 收货组盘:SAP 单据按单据号校验剩余数量,组盘记录 `ext_type` 落 `sap_material` / `sapOutboundDelivery` |
| `POST /api/pda/inbound/groupPlate` | 收货组盘:**一个托盘可混装多张单据**,按明细行上的 `order_no`(缺省回落表头 `bill_id`)逐行解析自己的单据后校验剩余数量,组盘记录 `ext_code`/`ext_type` 也按行落各自单据;同单据同行的多行明细按累计数量校验 |
| `POST /api/pda/inbound/usualInbound` | 平库直接入库:EAS 采购单走原逻辑,SAP 单据走新逻辑(按整行组盘 + 自动分配虚拟货位) |
入库明细完成时的回调策略(`callback_strategy`):

View File

@@ -27,7 +27,6 @@ import org.nl.wms.pm_manage.listener.PmManageEvent;
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.purchase.service.dao.Purchasemst;
import org.nl.wms.pm_manage.sap.materialDocument.enums.MaterialDocumentBillType;
import org.nl.wms.pm_manage.sap.materialDocument.enums.MaterialDocumentStatus;
import org.nl.wms.pm_manage.sap.materialDocument.service.dao.MaterialDocument;
@@ -235,17 +234,31 @@ public class InboundPdaServiceImpl implements InboundPdaService {
}
List<PdaGroupPlateDto.GroupPlateDtlDto> detailList = dto.getDetailList();
// SAP 单据(物料凭证/交货单)按单据号识别,EAS 采购单不返回内容
SapInboundDoc sapDoc = sapInboundDocResolver.resolve(dto.getBill_id());
Map<String, SapInboundDoc.SapInboundItem> sapItems = toSapItemMap(sapDoc);
detailList.forEach((item)->{
if (detailList == null || detailList.isEmpty()) {
throw new BadRequestException("组盘失败:组盘明细不能为空");
}
/*
* 一个托盘可能混装多张单据(例如两张单据都有行号 1),因此必须按「明细行上的单据号」逐行解析单据,
* 不能只按表头 bill_id 解析一张单据后让所有明细共用行项目索引,否则同号行项目会取到别的单据,
* 出现「超过单据剩余可入库数量」的误报。
*/
Map<String, SapInboundDoc> sapDocCache = new HashMap<>();
Map<String, Map<String, SapInboundDoc.SapInboundItem>> sapItemCache = new HashMap<>();
// 同一单据同一行号在本次提交中的累计组盘数量(同一条行项目可能被多次扫码放到同一托盘)
Map<String, BigDecimal> submittedQty = new HashMap<>();
for (PdaGroupPlateDto.GroupPlateDtlDto item : detailList) {
// 明细行上的单据号优先(PDA 扫码返回的 order_no 即单据号),缺失时回落到表头
String billNo = StrUtil.blankToDefault(StrUtil.trim(item.getOrder_no()), StrUtil.trim(dto.getBill_id()));
// SAP 单据(物料凭证/交货单)按单据号识别,EAS 采购单不返回内容
SapInboundDoc sapDoc = resolveSapDoc(sapDocCache, billNo);
if (sapDoc != null) {
checkSapItemQty(sapItems, item, sapDoc.getBillNo());
billNo = sapDoc.getBillNo();
checkSapItemQty(sapItemsOf(sapItemCache, sapDoc), item, billNo, submittedQty);
} else {
List<PurchaseMatInfoVo> purchaseMatInfoVos = purchaseService.selectPdaInMat(MapOf.of("orderNo", item.getOrder_no(),
List<PurchaseMatInfoVo> purchaseMatInfoVos = purchaseService.selectPdaInMat(MapOf.of("orderNo", billNo,
"itemNo", item.getItem_no()));
if (purchaseMatInfoVos.isEmpty()){
throw new BadRequestException("组盘失败:单据:"+item.getOrder_no()+"物料:"+item.getSku_code()+"不存在");
throw new BadRequestException("组盘失败:单据:"+billNo+"物料:"+item.getSku_code()+"不存在");
}
PurchaseMatInfoVo purchaseMatInfoVo = purchaseMatInfoVos.get(0);
if (item.getQty().add(purchaseMatInfoVo.getInstock_qty()).compareTo(purchaseMatInfoVo.getQty()) > 0){
@@ -264,7 +277,8 @@ public class InboundPdaServiceImpl implements InboundPdaService {
.qty_unit_name(unitDao.getUnit_name())
.qty(item.getQty())
.status(GROUP_PLATE_STATUS.code("组盘"))
.ext_code(sapDoc != null ? sapDoc.getBillNo() : dto.getBill_id())
// 组盘来源按行落库,保证多单据混装时每行都记录自己的单据号与单据类型
.ext_code(sapDoc != null ? sapDoc.getBillNo() : billNo)
.ext_type(sapDoc != null ? sapDoc.getSourceBillType() : SourceBillTypeEnum.PM_PURCHASE.getBillType())
.ext_dtl_code(item.getItem_no())
.create_id(SecurityUtils.getCurrentUserId())
@@ -273,7 +287,7 @@ public class InboundPdaServiceImpl implements InboundPdaService {
.build();
iMdPbGroupplateService.save(groupDao);
});
}
JSONObject result = new JSONObject();
result.put("success", true);
result.put("message", "组盘提交成功");
@@ -469,6 +483,32 @@ public class InboundPdaServiceImpl implements InboundPdaService {
return result;
}
/**
* 按单据号解析 SAP 单据,同一单据号只解析一次(一个托盘可能混装多张单据)。
* <p>解析不到(EAS 单据)时也缓存 null,避免同一次提交里重复查库。
*/
private SapInboundDoc resolveSapDoc(Map<String, SapInboundDoc> cache, String billNo) {
if (StrUtil.isBlank(billNo)) {
return null;
}
String key = billNo.trim();
if (cache.containsKey(key)) {
return cache.get(key);
}
SapInboundDoc document = sapInboundDocResolver.resolve(key);
cache.put(key, document);
return document;
}
/**
* 取某张单据的行项目索引(按单据号缓存),不同单据的行项目互不干扰
*/
private Map<String, SapInboundDoc.SapInboundItem> sapItemsOf(
Map<String, Map<String, SapInboundDoc.SapInboundItem>> cache, SapInboundDoc document) {
String key = document.getBillNo() == null ? "" : document.getBillNo();
return cache.computeIfAbsent(key, k -> toSapItemMap(document));
}
/**
* 校验收货数量不超过 SAP 单据剩余可入库数量(平库入库)
*/
@@ -479,14 +519,27 @@ public class InboundPdaServiceImpl implements InboundPdaService {
/**
* 校验收货数量不超过 SAP 单据剩余可入库数量(收货组盘)
* <p>
* sapItems 必须是<b>该行所属单据</b>的行项目索引:一个托盘可能混装多张单据,不同单据可能存在相同行号,
* 不能共用同一份行项目索引,否则会取到别的单据的行项目。
*
* @param submittedQty 同一单据同一行号在本次提交中的累计数量,非空时按累计值校验
*/
private void checkSapItemQty(Map<String, SapInboundDoc.SapInboundItem> sapItems,
PdaGroupPlateDto.GroupPlateDtlDto item, String billNo) {
checkSapItemQtyInternal(sapItems, item.getItem_no(), item.getSku_code(), item.getQty(), billNo);
PdaGroupPlateDto.GroupPlateDtlDto item, String billNo,
Map<String, BigDecimal> submittedQty) {
checkSapItemQtyInternal(sapItems, item.getItem_no(), item.getSku_code(), item.getQty(), billNo,
submittedQty);
}
private void checkSapItemQtyInternal(Map<String, SapInboundDoc.SapInboundItem> sapItems,
String itemNoValue, String skuCode, BigDecimal qty, String billNo) {
checkSapItemQtyInternal(sapItems, itemNoValue, skuCode, qty, billNo, null);
}
private void checkSapItemQtyInternal(Map<String, SapInboundDoc.SapInboundItem> sapItems,
String itemNoValue, String skuCode, BigDecimal qty, String billNo,
Map<String, BigDecimal> submittedQty) {
if (qty == null || qty.signum() <= 0) {
throw new BadRequestException("入库失败:物料" + skuCode + "的入库数量必须大于0");
}
@@ -498,9 +551,17 @@ public class InboundPdaServiceImpl implements InboundPdaService {
if (sapItem == null) {
throw new BadRequestException("入库失败:单据" + billNo + "中不存在行项目" + itemNoValue);
}
if (qty.compareTo(sapItem.remainQty()) > 0) {
BigDecimal checkQty = qty;
if (submittedQty != null) {
// 同一条行项目可能在本次组盘中出现多行(同一标签多次扫码),累计后再校验
String rowKey = billNo + "#"
+ (sapItem.getItemNo() == null ? itemNo : sapItem.getItemNo().trim());
checkQty = submittedQty.getOrDefault(rowKey, BigDecimal.ZERO).add(qty);
submittedQty.put(rowKey, checkQty);
}
if (checkQty.compareTo(sapItem.remainQty()) > 0) {
throw new BadRequestException("入库失败:物料" + skuCode + "入库数量"
+ qty.stripTrailingZeros().toPlainString() + "超过单据剩余可入库数量"
+ checkQty.stripTrailingZeros().toPlainString() + "超过单据剩余可入库数量"
+ sapItem.remainQty().stripTrailingZeros().toPlainString());
}
}

View File

@@ -57,6 +57,18 @@
</div>
<!--如果想在工具栏加入更多按钮,可以使用插槽方式, slot = 'left' or 'right'-->
<crudOperation :permission="permission">
<el-button
slot="right"
class="filter-item"
type="primary"
plain
icon="el-icon-download"
size="mini"
:loading="exporting"
@click="exportAll"
>
导出
</el-button>
<el-button
slot="right"
class="filter-item"
@@ -188,6 +200,17 @@ import { download } from '@/api/data'
import { downloadFile } from '@/utils'
import request from '@/utils/request'
import QRCode from 'qrcode'
import { exportRowsToExcel } from '@/utils/export-excel'
// 导出列:仓库、库区、仓位、物料编码、物料名称、总数
const EXPORT_COLUMNS = [
{ label: '仓库', prop: 'stor_name', width: 18 },
{ label: '库区', prop: 'sect_name', width: 18 },
{ label: '仓位', prop: 'struct_code', width: 18 },
{ label: '物料编码', prop: 'material_code', width: 20 },
{ label: '物料名称', prop: 'material_name', width: 30 },
{ label: '总数', prop: 'qty', width: 14 }
]
export default {
name: 'Structivt',
@@ -215,6 +238,7 @@ export default {
syncDialogVisible: false,
syncWarehouseCode: '',
syncLoading: false,
exporting: false,
printDialogVisible: false,
printPreviewVisible: false,
printRow: {},
@@ -266,6 +290,51 @@ export default {
})
}
},
exportAll() {
this.exporting = true
this.fetchExportRows().then(rows => {
if (!rows.length) {
this.$message.info('当前筛选条件下没有可导出的数据')
return
}
const total = exportRowsToExcel({
columns: EXPORT_COLUMNS,
rows,
sheetName: '库存明细',
fileName: '库存明细'
})
this.$message.success('导出成功,共 ' + total + ' 条数据')
}).catch(() => {
this.$message.error('导出失败,请重试')
}).finally(() => {
this.exporting = false
})
},
// 按当前筛选条件分页拉取全部数据
fetchExportRows() {
const params = { ...this.crud.getQueryParams() }
delete params.page
delete params.size
delete params.sort
const pageSize = 5000
const rows = []
const loadPage = page => {
return request({
url: 'api/structivt',
method: 'get',
params: { ...params, page, size: pageSize }
}).then(res => {
const list = (res && res.data) || []
rows.push(...list)
const total = Number((res && res.totalElements) || 0)
if (!list.length || rows.length >= total) {
return rows
}
return loadPage(page + 1)
})
}
return loadPage(0)
},
openSyncDialog() {
this.syncWarehouseCode = ''
this.syncDialogVisible = true