feat(inventory-delivery): 优化多采购单发货与SN查询
- 多采购单发货按页签隔离仓库、价格、税率和采购明细上下文 - 发货SN查询优先按明细SN过滤,历史数据缺明细时按出库单兜底 - 撤回后SN出库单号清空场景避免误查同仓历史SN - 入库金额计算过滤空价格,避免空指针并保证含税/不含税汇总稳定 - 采购单查询增加ID排序,保证分页/列表顺序稳定 - 应用环境配置切换为devcp_1.0.0
parent
7835efa964
commit
c88e6ce5be
|
|
@ -174,7 +174,7 @@ export default {
|
|||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
deliveryId: null,
|
||||
// 不按状态/出库单过滤:撤回后的SN已还原为入库状态且outer_code被清空
|
||||
// 主口径按发货明细SN过滤;仅历史数据缺发货明细时,才退回出库单号+库存状态
|
||||
inventoryStatus: null,
|
||||
outerCode: null,
|
||||
warehouseId: null,
|
||||
|
|
@ -218,10 +218,21 @@ export default {
|
|||
}
|
||||
getDelivery(this.deliveryId).then(response => {
|
||||
this.form = response.data || {}
|
||||
// SN码列表查询参数(与发货单详情一致:不传 outer_code)
|
||||
// SN码列表查询参数(与发货单详情一致):优先按发货明细SN过滤
|
||||
this.snQueryParams.deliveryId = this.deliveryId
|
||||
// 每次打开重置出库单口径,避免上一条发货单的兜底条件残留
|
||||
this.snQueryParams.outerCode = null
|
||||
this.snQueryParams.inventoryStatus = null
|
||||
this.snQueryParams.warehouseId = this.form.warehouseId
|
||||
this.snQueryParams.productSnList = this.form.productSnList
|
||||
const productSnList = this.form.productSnList || []
|
||||
this.snQueryParams.productSnList = productSnList
|
||||
// 历史数据未写 oms_inventory_delivery_detail 时只剩仓库过滤,
|
||||
// 会把整个虚拟仓(同仓库历史出库单)的SN都查出来,此处退回出库单口径兜底;
|
||||
// 已撤回(状态2)的SN出库单号已清空,无法按出库单口径收窄,维持原行为
|
||||
if (productSnList.length === 0 && String(this.form.deliveryStatus) !== '2' && this.form.outerCode) {
|
||||
this.snQueryParams.outerCode = this.form.outerCode
|
||||
this.snQueryParams.inventoryStatus = '1'
|
||||
}
|
||||
this.getSnList()
|
||||
const businessKey = this.form.outerCode || this.outerCode
|
||||
this.loadFlows(businessKey)
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ export default {
|
|||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
deliveryId: null,
|
||||
// 不按状态/出库单过滤:撤回后的SN已还原为入库状态且outer_code被清空
|
||||
// 主口径按发货明细SN过滤;仅历史数据缺发货明细时,才退回出库单号+库存状态
|
||||
inventoryStatus: null,
|
||||
outerCode: null,
|
||||
warehouseId: null,
|
||||
|
|
@ -153,10 +153,20 @@ export default {
|
|||
};
|
||||
getDelivery(id).then(response => {
|
||||
this.detail = response.data;
|
||||
// Update snQueryParams with data from the detail response
|
||||
// 注意:不传 outer_code,撤回后SN的outer_code已被清空,该过滤条件会查不到数据
|
||||
// 优先用发货明细的SN精确过滤:撤回后SN的outer_code已清空、状态已还原,只有SN过滤始终准确
|
||||
// 每次加载先重置兜底条件,避免上一条发货单的查询条件残留
|
||||
this.snQueryParams.outerCode = null;
|
||||
this.snQueryParams.inventoryStatus = null;
|
||||
this.snQueryParams.warehouseId = response.data.warehouseId;
|
||||
this.snQueryParams.productSnList = response.data.productSnList;
|
||||
const productSnList = response.data.productSnList || [];
|
||||
this.snQueryParams.productSnList = productSnList;
|
||||
// 历史数据未写 oms_inventory_delivery_detail 时只剩仓库过滤,
|
||||
// 会把整个虚拟仓(同仓库历史出库单)的SN都查出来,此处退回出库单口径兜底;
|
||||
// 已撤回(状态2)的SN出库单号已清空,无法按出库单口径收窄,维持原行为
|
||||
if (productSnList.length === 0 && String(response.data.deliveryStatus) !== '2' && response.data.outerCode) {
|
||||
this.snQueryParams.outerCode = response.data.outerCode;
|
||||
this.snQueryParams.inventoryStatus = '1';
|
||||
}
|
||||
// Fetch the first page of SN list
|
||||
this.getSnList();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@
|
|||
<el-row>
|
||||
<el-col :span="6" v-if="isImported">
|
||||
<el-form-item label="税率" prop="taxRate">
|
||||
<el-input v-model="taxRate" placeholder="请输入税率"/>
|
||||
<el-input v-model="taxRate" placeholder="请输入税率" @input="handleTaxRateChange"/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
|
@ -159,6 +159,10 @@ export default {
|
|||
isImportedTabs: {},
|
||||
// 各采购单页签是否为“指定发货”:{ [purchaseNo]: true }
|
||||
assignTabs: {},
|
||||
// 各采购单页签导入时使用的税率:{ [purchaseNo]: 0.13 },多采购单发货时税率按各自采购单取值
|
||||
tabTaxRateMap: {},
|
||||
// 各采购单页签的导入上下文:仓库、价格、税率、采购明细不能跨页签共用
|
||||
tabContextMap: {},
|
||||
// 切换页签恢复勾选期间忽略 selection-change
|
||||
suppressSelectionChange: false,
|
||||
// 请求序号,避免快速切换页签时旧响应覆盖新页签
|
||||
|
|
@ -265,9 +269,11 @@ export default {
|
|||
productMatchBindList(orderCode, productCode, { pageNum: 1, pageSize: 100 }).then(response => {
|
||||
this.purchaseOrderList = response.rows || [];
|
||||
const filtered = this.filteredPurchaseOrderList;
|
||||
this.initTabContextMap(filtered);
|
||||
if (filtered.length > 0) {
|
||||
this.activePurchaseNo = filtered[0].purchaseNo;
|
||||
this.queryParams.purchaseNo = this.activePurchaseNo;
|
||||
this.applyTabContext(this.activePurchaseNo);
|
||||
} else {
|
||||
this.activePurchaseNo = '';
|
||||
this.queryParams.purchaseNo = undefined;
|
||||
|
|
@ -348,6 +354,61 @@ export default {
|
|||
pageSize: this.queryParams.pageSize
|
||||
});
|
||||
},
|
||||
// 初始化各采购单页签的上下文,页签接口没有仓库/明细时先保留空值,后续选择采购单时补齐
|
||||
initTabContextMap(purchaseList) {
|
||||
const contextMap = {};
|
||||
(purchaseList || []).forEach(purchase => {
|
||||
const context = {
|
||||
purchaseNo: purchase.purchaseNo,
|
||||
warehouseId: purchase.warehouseId != null ? purchase.warehouseId : null,
|
||||
warehouseName: purchase.warehouseName || '',
|
||||
price: purchase.price != null ? purchase.price : null,
|
||||
taxRate: purchase.taxRate != null ? purchase.taxRate : 0.13,
|
||||
itemId: purchase.itemId != null ? purchase.itemId : null
|
||||
};
|
||||
contextMap[purchase.purchaseNo] = context;
|
||||
this.$set(this.tabTaxRateMap, purchase.purchaseNo, context.taxRate);
|
||||
});
|
||||
this.tabContextMap = contextMap;
|
||||
},
|
||||
// 保存当前页签的仓库、价格、税率和采购明细,切换页签后不能复用其他采购单的值
|
||||
saveTabContext(purchaseNo) {
|
||||
if (!purchaseNo) return;
|
||||
this.mergeTabContext(purchaseNo, {
|
||||
warehouseId: this.warehouseId,
|
||||
warehouseName: this.warehouseName,
|
||||
price: this.price,
|
||||
taxRate: this.taxRate,
|
||||
itemId: this.form.itemId
|
||||
});
|
||||
},
|
||||
// 合并页签上下文,空值不覆盖已有值(采购绑定列表通常不返回仓库、税率和明细ID)
|
||||
mergeTabContext(purchaseNo, context) {
|
||||
if (!purchaseNo || !context) return this.tabContextMap[purchaseNo] || {};
|
||||
const merged = { ...(this.tabContextMap[purchaseNo] || {}), purchaseNo };
|
||||
if (context.warehouseId != null) merged.warehouseId = context.warehouseId;
|
||||
if (context.warehouseName) merged.warehouseName = context.warehouseName;
|
||||
if (context.price != null) merged.price = context.price;
|
||||
if (context.taxRate != null) merged.taxRate = context.taxRate;
|
||||
if (context.itemId != null) merged.itemId = context.itemId;
|
||||
this.$set(this.tabContextMap, purchaseNo, merged);
|
||||
if (merged.taxRate != null) {
|
||||
this.$set(this.tabTaxRateMap, purchaseNo, merged.taxRate);
|
||||
}
|
||||
return merged;
|
||||
},
|
||||
// 把指定采购单页签的上下文恢复到表单,切换页签时同步清掉上一个采购单的明细ID
|
||||
applyTabContext(purchaseNo) {
|
||||
const context = this.tabContextMap[purchaseNo] || {};
|
||||
this.warehouseId = context.warehouseId != null ? context.warehouseId : null;
|
||||
this.warehouseName = context.warehouseName || '';
|
||||
this.price = context.price != null ? context.price : null;
|
||||
this.taxRate = context.taxRate != null
|
||||
? context.taxRate
|
||||
: (this.tabTaxRateMap[purchaseNo] != null ? this.tabTaxRateMap[purchaseNo] : 0.13);
|
||||
this.form.purchaseNo = purchaseNo;
|
||||
this.form.itemId = context.itemId != null ? context.itemId : undefined;
|
||||
},
|
||||
handleTabClick(tab) {
|
||||
const newTab = tab.name;
|
||||
const prevTab = this.lastActivePurchaseNo;
|
||||
|
|
@ -355,15 +416,19 @@ export default {
|
|||
if (prevTab === newTab) {
|
||||
this.activePurchaseNo = newTab;
|
||||
this.queryParams.purchaseNo = newTab;
|
||||
this.form.purchaseNo = newTab;
|
||||
return;
|
||||
}
|
||||
// 切换前先保存上一个页签的勾选
|
||||
this.saveCurrentTab(prevTab);
|
||||
this.saveTabContext(prevTab);
|
||||
this.lastActivePurchaseNo = newTab;
|
||||
this.activePurchaseNo = newTab;
|
||||
this.queryParams.purchaseNo = newTab;
|
||||
this.queryParams.pageNum = 1;
|
||||
this.queryParams.pageSize = this.defaultPageSize;
|
||||
// 恢复目标页签自己的仓库、价格、税率和明细ID
|
||||
this.applyTabContext(newTab);
|
||||
const cached = this.tabDataMap[newTab];
|
||||
if (cached) {
|
||||
this.applyTabData(newTab, cached.rows, cached.total, cached.pageNum, cached.pageSize, false);
|
||||
|
|
@ -403,7 +468,9 @@ export default {
|
|||
if (!this.isImportedTabs[purchaseNo] || this.assignTabs[purchaseNo]) return;
|
||||
const rows = this.selectedSnMap[purchaseNo] || {};
|
||||
Object.keys(rows).forEach(productSn => {
|
||||
list.push(rows[productSn]);
|
||||
const row = rows[productSn];
|
||||
// 一个出库单可以选多个采购单,SN 必须带上所属页签的采购单号,后端按采购单分组校验
|
||||
list.push({ ...row, purchaseNo });
|
||||
});
|
||||
});
|
||||
return list;
|
||||
|
|
@ -417,12 +484,28 @@ export default {
|
|||
Object.keys(rows).forEach(productSn => {
|
||||
list.push({
|
||||
productSn,
|
||||
licenseKey: rows[productSn].licenseKey
|
||||
licenseKey: rows[productSn].licenseKey,
|
||||
// 指定发货的SN已入库,库存表不返回采购单号,必须按所属页签带上,
|
||||
// 否则后端无法区分多个采购单,会整批按最后一个采购单校验
|
||||
purchaseNo
|
||||
});
|
||||
});
|
||||
});
|
||||
return list;
|
||||
},
|
||||
// 跨页签重复SN校验:selectedSnList 只按页签汇总行数,同一SN出现在两个采购单页签时会重复计数,
|
||||
// 后端按SN去重后实际数量不足,必须提交前拦截
|
||||
getDuplicateSnList() {
|
||||
const snCountMap = {};
|
||||
Object.keys(this.selectedSnMap).forEach(purchaseNo => {
|
||||
const rows = this.selectedSnMap[purchaseNo] || {};
|
||||
Object.keys(rows).forEach(productSn => {
|
||||
if (!productSn) return;
|
||||
snCountMap[productSn] = (snCountMap[productSn] || 0) + 1;
|
||||
});
|
||||
});
|
||||
return Object.keys(snCountMap).filter(productSn => snCountMap[productSn] > 1);
|
||||
},
|
||||
handleDownloadTemplate() {
|
||||
exportDownloadTemplateData({
|
||||
productCode: this.queryParams.productCode,
|
||||
|
|
@ -461,13 +544,17 @@ export default {
|
|||
return;
|
||||
}
|
||||
|
||||
// 设置采购单信息
|
||||
this.warehouseId = currentPurchase.warehouseId;
|
||||
this.warehouseName = currentPurchase.warehouseName;
|
||||
this.price = currentPurchase.price;
|
||||
this.taxRate = currentPurchase.taxRate;
|
||||
this.form.purchaseNo = currentPurchase.purchaseNo;
|
||||
this.form.itemId = currentPurchase.itemId;
|
||||
// 页签数据来自采购绑定列表,只保证采购单号;仓库、税率、明细ID可能为空,
|
||||
// 不能用 undefined 覆盖已有值,否则导入数据会丢失仓库/价格
|
||||
this.saveTabContext(this.activePurchaseNo);
|
||||
this.mergeTabContext(this.activePurchaseNo, {
|
||||
warehouseId: currentPurchase.warehouseId,
|
||||
warehouseName: currentPurchase.warehouseName,
|
||||
price: currentPurchase.price,
|
||||
taxRate: currentPurchase.taxRate,
|
||||
itemId: currentPurchase.itemId
|
||||
});
|
||||
this.applyTabContext(this.activePurchaseNo);
|
||||
|
||||
// 直接触发文件选择
|
||||
this.isAssignMode = true;
|
||||
|
|
@ -485,12 +572,15 @@ export default {
|
|||
}
|
||||
}
|
||||
|
||||
this.warehouseId = order.warehouseId;
|
||||
this.warehouseName = order.warehouseName;
|
||||
this.price = order.price;
|
||||
this.taxRate = order.taxRate;
|
||||
this.form.purchaseNo = order.purchaseNo;
|
||||
this.form.itemId = order.itemId;
|
||||
this.saveTabContext(this.activePurchaseNo);
|
||||
this.mergeTabContext(order.purchaseNo, {
|
||||
warehouseId: order.warehouseId,
|
||||
warehouseName: order.warehouseName,
|
||||
price: order.price,
|
||||
taxRate: order.taxRate,
|
||||
itemId: order.itemId
|
||||
});
|
||||
this.applyTabContext(order.purchaseNo);
|
||||
if (this.isAssignMode) {
|
||||
this.handleAssign();
|
||||
} else {
|
||||
|
|
@ -503,36 +593,99 @@ export default {
|
|||
handleAssign() {
|
||||
this.$refs.assignUploadInput.click();
|
||||
},
|
||||
// 采购单页签的剩余应发数量:配额数量 - 已备货数量
|
||||
getPurchaseRemainQuantity(purchaseNo) {
|
||||
const purchase = this.filteredPurchaseOrderList.find(item => item.purchaseNo === purchaseNo);
|
||||
if (purchase) {
|
||||
const remain = Number(purchase.phNum || 0) - Number(purchase.bhNum || 0);
|
||||
return remain > 0 ? remain : 0;
|
||||
}
|
||||
// 采购单不在当前绑定页签中(如通过弹窗选择了其他采购单)时,沿用整单剩余量
|
||||
const remainQuantity = this.getRemainQuantity();
|
||||
return Number.isNaN(remainQuantity) ? this.defaultPageSize : remainQuantity;
|
||||
},
|
||||
// 文件选择时固定本次导入/指定发货的上下文,避免请求返回前切换页签导致数据落到其他采购单
|
||||
buildFileContext() {
|
||||
const purchaseNo = this.form.purchaseNo || this.activePurchaseNo;
|
||||
const context = this.tabContextMap[purchaseNo] || {};
|
||||
const isActive = purchaseNo === this.activePurchaseNo;
|
||||
return {
|
||||
purchaseNo,
|
||||
// 本次文件属于哪个页签,异步返回时用户可能已切换页签
|
||||
sourceTab: this.activePurchaseNo,
|
||||
// 导入接口要求文件行数等于该采购单页签的剩余应发数量,
|
||||
// 多采购单时不能用整单剩余量,否则 20 台的页签会被要求导入 44 行
|
||||
quantity: this.getPurchaseRemainQuantity(purchaseNo),
|
||||
taxRate: context.taxRate != null ? context.taxRate
|
||||
: (isActive && this.taxRate != null ? this.taxRate : 0.13),
|
||||
warehouseId: context.warehouseId != null ? context.warehouseId
|
||||
: (isActive && this.warehouseId != null ? this.warehouseId : this.queryParams.warehouseId),
|
||||
warehouseName: context.warehouseName || (isActive ? this.warehouseName : ''),
|
||||
price: context.price != null ? context.price : (isActive ? this.price : null),
|
||||
itemId: context.itemId != null ? context.itemId : (isActive ? this.form.itemId : undefined)
|
||||
};
|
||||
},
|
||||
onFileChange(event) {
|
||||
const file = event.target.files[0];
|
||||
if (!file) return;
|
||||
|
||||
const context = this.buildFileContext();
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
formData.append('productCode', this.productData.productCode);
|
||||
formData.append('quantity', this.queryParams.pageSize);
|
||||
formData.append('quantity', context.quantity);
|
||||
formData.append('orderType', this.productData.orderType);
|
||||
|
||||
importSnData(formData).then(response => {
|
||||
this.$message.success('导入成功');
|
||||
const rows = response.data.productSnDataList || [];
|
||||
if (this.warehouseName) {
|
||||
rows.forEach(item => {
|
||||
item.warehouseName = this.warehouseName;
|
||||
item.warehouseId = this.warehouseId;
|
||||
item.innerPrice = this.price;
|
||||
});
|
||||
const purchaseNo = context.purchaseNo || this.activePurchaseNo;
|
||||
this.mergeTabContext(purchaseNo, context);
|
||||
rows.forEach(item => {
|
||||
if (context.warehouseId != null) {
|
||||
item.warehouseId = context.warehouseId;
|
||||
}
|
||||
if (context.warehouseName) {
|
||||
item.warehouseName = context.warehouseName;
|
||||
}
|
||||
if (context.price != null) {
|
||||
item.innerPrice = context.price;
|
||||
}
|
||||
if (context.purchaseNo) {
|
||||
item.purchaseNo = context.purchaseNo;
|
||||
}
|
||||
});
|
||||
// 导入弹窗可能选择了其他采购单,数据必须落到刚选择的采购单页签
|
||||
// 上传/解析期间用户手动切换了页签时,只缓存结果,不抢回当前视图
|
||||
const userSwitchedTab = this.activePurchaseNo !== context.sourceTab;
|
||||
if (purchaseNo !== this.activePurchaseNo && !userSwitchedTab) {
|
||||
this.saveCurrentTab(context.sourceTab);
|
||||
this.activePurchaseNo = purchaseNo;
|
||||
this.lastActivePurchaseNo = purchaseNo;
|
||||
this.queryParams.purchaseNo = purchaseNo;
|
||||
this.applyTabContext(purchaseNo);
|
||||
}
|
||||
const purchaseNo = this.activePurchaseNo;
|
||||
this.$set(this.isImportedTabs, purchaseNo, true);
|
||||
this.$set(this.assignTabs, purchaseNo, false);
|
||||
this.$set(this.tabTaxRateMap, purchaseNo, context.taxRate);
|
||||
this.$set(this.tabDataMap, purchaseNo, {
|
||||
rows,
|
||||
total: rows.length,
|
||||
pageNum: 1,
|
||||
pageSize: rows.length
|
||||
});
|
||||
this.applyTabData(purchaseNo, rows, rows.length, 1, rows.length, true);
|
||||
if (this.activePurchaseNo === purchaseNo) {
|
||||
this.form.purchaseNo = purchaseNo;
|
||||
this.taxRate = context.taxRate;
|
||||
this.applyTabData(purchaseNo, rows, rows.length, 1, rows.length, true);
|
||||
} else {
|
||||
// 当前显示的是其他页签:只更新该采购单的已选缓存,切回时再恢复勾选
|
||||
const selected = rows.reduce((map, row) => {
|
||||
map[row.productSn] = row;
|
||||
return map;
|
||||
}, {});
|
||||
this.$set(this.selectedSnMap, purchaseNo, selected);
|
||||
}
|
||||
}).catch(() => {
|
||||
this.$message.error('导入失败');
|
||||
});
|
||||
|
|
@ -542,46 +695,77 @@ export default {
|
|||
const file = event.target.files[0];
|
||||
if (!file) return;
|
||||
|
||||
const context = this.buildFileContext();
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
formData.append('productCode', this.productData.productCode);
|
||||
formData.append('orderType', this.productData.orderType);
|
||||
formData.append('purchaseNo', this.form.purchaseNo);
|
||||
formData.append('purchaseNo', context.purchaseNo);
|
||||
|
||||
assignDeliverySnData(formData).then(response => {
|
||||
this.$message.success('指定发货导入成功');
|
||||
const rows = response.data.productSnDataList || [];
|
||||
if (this.warehouseName) {
|
||||
rows.forEach(item => {
|
||||
item.warehouseName = this.warehouseName;
|
||||
item.warehouseId = this.warehouseId;
|
||||
item.innerPrice = this.price;
|
||||
});
|
||||
}
|
||||
const purchaseNo = context.purchaseNo || this.activePurchaseNo;
|
||||
this.mergeTabContext(purchaseNo, context);
|
||||
rows.forEach(item => {
|
||||
if (context.warehouseId != null) {
|
||||
item.warehouseId = context.warehouseId;
|
||||
}
|
||||
if (context.warehouseName) {
|
||||
item.warehouseName = context.warehouseName;
|
||||
}
|
||||
if (context.price != null) {
|
||||
item.innerPrice = context.price;
|
||||
}
|
||||
if (context.purchaseNo) {
|
||||
item.purchaseNo = context.purchaseNo;
|
||||
}
|
||||
});
|
||||
|
||||
// 指定发货可能选中了其他采购单,需先保存当前页签再切换
|
||||
const purchaseNo = this.form.purchaseNo || this.activePurchaseNo;
|
||||
if (purchaseNo !== this.activePurchaseNo) {
|
||||
this.saveCurrentTab(this.lastActivePurchaseNo);
|
||||
// 上传/解析期间用户手动切换了页签时,只缓存结果,不抢回当前视图
|
||||
const userSwitchedTab = this.activePurchaseNo !== context.sourceTab;
|
||||
if (purchaseNo !== this.activePurchaseNo && !userSwitchedTab) {
|
||||
this.saveCurrentTab(context.sourceTab);
|
||||
this.activePurchaseNo = purchaseNo;
|
||||
this.lastActivePurchaseNo = purchaseNo;
|
||||
this.queryParams.purchaseNo = purchaseNo;
|
||||
this.applyTabContext(purchaseNo);
|
||||
}
|
||||
|
||||
this.$set(this.isImportedTabs, purchaseNo, true);
|
||||
this.$set(this.assignTabs, purchaseNo, true);
|
||||
this.$set(this.tabTaxRateMap, purchaseNo, context.taxRate);
|
||||
this.$set(this.tabDataMap, purchaseNo, {
|
||||
rows,
|
||||
total: rows.length,
|
||||
pageNum: 1,
|
||||
pageSize: rows.length
|
||||
});
|
||||
this.applyTabData(purchaseNo, rows, rows.length, 1, rows.length, true);
|
||||
if (this.activePurchaseNo === purchaseNo) {
|
||||
this.form.purchaseNo = purchaseNo;
|
||||
this.taxRate = context.taxRate;
|
||||
this.applyTabData(purchaseNo, rows, rows.length, 1, rows.length, true);
|
||||
} else {
|
||||
// 当前显示的是其他页签:只更新该采购单的已选缓存,切回时再恢复勾选
|
||||
const selected = rows.reduce((map, row) => {
|
||||
map[row.productSn] = row;
|
||||
return map;
|
||||
}, {});
|
||||
this.$set(this.selectedSnMap, purchaseNo, selected);
|
||||
}
|
||||
}).catch(() => {
|
||||
this.$message.error('指定发货导入失败');
|
||||
});
|
||||
this.$refs.assignUploadInput.value = ''; // Reset file input
|
||||
},
|
||||
// 税率输入框只显示当前页签的税率,修改后同步到当前页签,提交时按页签取值
|
||||
handleTaxRateChange(value) {
|
||||
if (this.isImportedTabs[this.activePurchaseNo]) {
|
||||
this.$set(this.tabTaxRateMap, this.activePurchaseNo, value);
|
||||
this.mergeTabContext(this.activePurchaseNo, { taxRate: value });
|
||||
}
|
||||
},
|
||||
submitForm() {
|
||||
this.$refs.form.validate(valid => {
|
||||
if (valid) {
|
||||
|
|
@ -598,12 +782,21 @@ export default {
|
|||
return;
|
||||
}
|
||||
|
||||
const duplicateSnList = this.getDuplicateSnList();
|
||||
if (duplicateSnList.length > 0) {
|
||||
this.$message.error(`SN码${duplicateSnList.join('、')}在多个采购单页签中重复,请检查后重试`);
|
||||
return;
|
||||
}
|
||||
|
||||
// 导入页签的行需要带上税率
|
||||
Object.keys(this.isImportedTabs).forEach(purchaseNo => {
|
||||
if (!this.isImportedTabs[purchaseNo]) return;
|
||||
const rows = this.selectedSnMap[purchaseNo] || {};
|
||||
// 一个出库单选多个采购单时,各页签税率可能不同,不能统一取最后操作的采购单税率
|
||||
const taxRate = this.tabTaxRateMap[purchaseNo] != null ? this.tabTaxRateMap[purchaseNo] : this.taxRate;
|
||||
Object.keys(rows).forEach(productSn => {
|
||||
rows[productSn].taxRate = this.taxRate;
|
||||
rows[productSn].taxRate = taxRate;
|
||||
rows[productSn].purchaseNo = purchaseNo;
|
||||
});
|
||||
});
|
||||
const data = {
|
||||
|
|
@ -646,6 +839,8 @@ export default {
|
|||
this.tabDataMap = {};
|
||||
this.isImportedTabs = {};
|
||||
this.assignTabs = {};
|
||||
this.tabTaxRateMap = {};
|
||||
this.tabContextMap = {};
|
||||
this.suppressSelectionChange = false;
|
||||
this.lastActivePurchaseNo = '';
|
||||
this.loadedTab = '';
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import com.ruoyi.common.utils.StringUtils;
|
|||
import com.ruoyi.sip.domain.*;
|
||||
import com.ruoyi.sip.dto.ApiDataQueryDto;
|
||||
import com.ruoyi.sip.dto.inventory.InventoryDeliveryDetailExcelDto;
|
||||
import com.ruoyi.sip.dto.inventory.OmsPurchaseOrderItemDto;
|
||||
import com.ruoyi.sip.flowable.domain.Todo;
|
||||
import com.ruoyi.sip.flowable.mapper.TodoMapper;
|
||||
import com.ruoyi.sip.flowable.service.TodoCommonTemplate;
|
||||
|
|
@ -23,6 +24,7 @@ import com.ruoyi.sip.flowable.service.TodoService;
|
|||
import com.ruoyi.sip.mapper.InventoryInfoMapper;
|
||||
import com.ruoyi.sip.mapper.InventoryOuterDetailMapper;
|
||||
import com.ruoyi.sip.mapper.InventoryOuterMapper;
|
||||
import com.ruoyi.sip.mapper.OmsInventoryInnerMapper;
|
||||
import com.ruoyi.sip.mapper.OmsPurchaseOrderMapMapper;
|
||||
import com.ruoyi.sip.service.*;
|
||||
import com.ruoyi.sip.vo.DeliveryApproveVo;
|
||||
|
|
@ -98,6 +100,8 @@ public class InventoryDeliveryServiceImpl implements IInventoryDeliveryService,
|
|||
private OmsPurchaseOrderMapMapper omsPurchaseOrderMapMapper;
|
||||
@Resource
|
||||
private InventoryInfoMapper inventoryInfoMapper;
|
||||
@Resource
|
||||
private OmsInventoryInnerMapper omsInventoryInnerMapper;
|
||||
@Autowired
|
||||
private TodoService todoService;
|
||||
@Autowired
|
||||
|
|
@ -150,6 +154,8 @@ public class InventoryDeliveryServiceImpl implements IInventoryDeliveryService,
|
|||
|
||||
//仅维保订单:发货SN直接沿用关联项目已发货的SN,不校验采购绑定、不回写SN库存信息
|
||||
boolean maintenanceOnly = false;
|
||||
// 本次发货SN与采购单的归属关系,导入回写入库单时复用,避免再次查库
|
||||
Map<String, String> snPurchaseMap = Collections.emptyMap();
|
||||
if (StringUtils.isNotEmpty(inventoryDelivery.getOrderCode())) {
|
||||
ProjectOrderInfo orderInfo = projectOrderInfoService.selectProjectOrderInfoByOrderCode(inventoryDelivery.getOrderCode());
|
||||
if (orderInfo == null) {
|
||||
|
|
@ -161,66 +167,11 @@ public class InventoryDeliveryServiceImpl implements IInventoryDeliveryService,
|
|||
|
||||
if (maintenanceOnly) {
|
||||
validateMaintenanceDeliverySn(inventoryDelivery.getOrderCode(), inventoryDelivery.getProductCode(), productSnList);
|
||||
} else if (StringUtils.isNotEmpty(inventoryDelivery.getPurchaseNo())) {
|
||||
int newSnCount = CollUtil.isEmpty(productSnList) ? productSnDataList.size() : productSnList.size();
|
||||
OmsPurchaseOrder purchaseOrder = omsPurchaseOrderService.selectOmsPurchaseOrderByNo(inventoryDelivery.getPurchaseNo());
|
||||
if (purchaseOrder == null) {
|
||||
throw new ServiceException("采购单信息不存在");
|
||||
}
|
||||
OmsPurchaseOrderMap purchaseOrderMap = omsPurchaseOrderMapMapper.selectByOrderIdAndPurchaseId(orderInfo.getId(), purchaseOrder.getId(), inventoryDelivery.getProductCode());
|
||||
if (purchaseOrderMap == null || purchaseOrderMap.getBindNum() == null || purchaseOrderMap.getBindNum() <= 0) {
|
||||
throw new ServiceException("当前订单与采购单未建立绑定关系或绑定数量为0");
|
||||
}
|
||||
int totalBindNum = purchaseOrderMap.getBindNum();
|
||||
int alreadyBindNum = inventoryInfoMapper.countByOrderCodeAndPurchaseNo(inventoryDelivery.getOrderCode(), inventoryDelivery.getPurchaseNo(), inventoryDelivery.getProductCode());
|
||||
int remainingNum = totalBindNum - alreadyBindNum;
|
||||
if (newSnCount > remainingNum) {
|
||||
throw new ServiceException(String.format("新增SN码数量(%d)超过剩余可新增数量(%d),总绑定数(%d),已绑定数(%d)", newSnCount, remainingNum, totalBindNum, alreadyBindNum));
|
||||
}
|
||||
} else if (CollUtil.isNotEmpty(productSnList)) {
|
||||
List<InventoryInfo> inventoryInfoList = inventoryInfoMapper.listByProductSnList(productSnList);
|
||||
if (CollUtil.isEmpty(inventoryInfoList)) {
|
||||
throw new ServiceException("未找到SN码对应的库存信息");
|
||||
}
|
||||
Map<String, List<InventoryInfo>> innerCodeMap = inventoryInfoList.stream()
|
||||
.filter(info -> StringUtils.isNotEmpty(info.getInnerCode()))
|
||||
.collect(Collectors.groupingBy(InventoryInfo::getInnerCode));
|
||||
|
||||
Map<String, Long> purchaseNoCountMap = new HashMap<>();
|
||||
for (Map.Entry<String, List<InventoryInfo>> entry : innerCodeMap.entrySet()) {
|
||||
String innerCode = entry.getKey();
|
||||
OmsInventoryInner queryInner = new OmsInventoryInner();
|
||||
queryInner.setInnerCode(innerCode);
|
||||
List<OmsInventoryInner> innerList = omsInventoryInnerService.selectOmsInventoryInnerList(queryInner);
|
||||
if (CollUtil.isNotEmpty(innerList) && StringUtils.isNotEmpty(innerList.get(0).getPurchaseNo())) {
|
||||
String purchaseNo = innerList.get(0).getPurchaseNo();
|
||||
purchaseNoCountMap.put(purchaseNo, purchaseNoCountMap.getOrDefault(purchaseNo, 0L) + entry.getValue().size());
|
||||
}
|
||||
}
|
||||
|
||||
for (Map.Entry<String, Long> entry : purchaseNoCountMap.entrySet()) {
|
||||
String purchaseNo = entry.getKey();
|
||||
long newSnCount = entry.getValue();
|
||||
|
||||
OmsPurchaseOrder purchaseOrder = omsPurchaseOrderService.selectOmsPurchaseOrderByNo(purchaseNo);
|
||||
if (purchaseOrder == null) {
|
||||
throw new ServiceException(String.format("采购单[%s]信息不存在", purchaseNo));
|
||||
}
|
||||
|
||||
OmsPurchaseOrderMap purchaseOrderMap = omsPurchaseOrderMapMapper.selectByOrderIdAndPurchaseId(orderInfo.getId(), purchaseOrder.getId(), inventoryDelivery.getProductCode());
|
||||
if (purchaseOrderMap == null || purchaseOrderMap.getBindNum() == null || purchaseOrderMap.getBindNum() <= 0) {
|
||||
throw new ServiceException(String.format("订单与采购单[%s]未建立绑定关系或绑定数量为0", purchaseNo));
|
||||
}
|
||||
|
||||
int totalBindNum = purchaseOrderMap.getBindNum();
|
||||
int alreadyBindNum = inventoryInfoMapper.countByOrderCodeAndPurchaseNo(inventoryDelivery.getOrderCode(), purchaseNo, inventoryDelivery.getProductCode());
|
||||
int remainingNum = totalBindNum - alreadyBindNum;
|
||||
|
||||
if (newSnCount > remainingNum) {
|
||||
throw new ServiceException(String.format("采购单[%s]新增SN码数量(%d)超过剩余可新增数量(%d),总绑定数(%d),已绑定数(%d)",
|
||||
purchaseNo, newSnCount, remainingNum, totalBindNum, alreadyBindNum));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 一个出库单可以选多个采购单发货(前端每个采购单一个页签,分别导入或指定发货),
|
||||
// 提交时只有一个 purchaseNo,必须按每个SN实际归属的采购单分组校验绑定余量,
|
||||
// 否则多采购单一起发货会整批按最后操作的采购单校验,必然提示超出剩余可新增数量
|
||||
snPurchaseMap = validatePurchaseBindQuota(inventoryDelivery, orderInfo, productSnList, productSnDataList, assignSnDataList);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -327,9 +278,11 @@ public class InventoryDeliveryServiceImpl implements IInventoryDeliveryService,
|
|||
inventoryInfoService.saveBatch(inventoryInfoList);
|
||||
}
|
||||
} else if (CollUtil.isNotEmpty(productSnDataList)) {
|
||||
Long warehouseId = productSnDataList.get(0).getWarehouseId();
|
||||
if (warehouseId!=null && !warehouseId.equals(inventoryDelivery.getWarehouseId())){
|
||||
throw new ServiceException("发货数据仓库与出库单仓库不一致,请确认后重试");
|
||||
for (InventoryInfo inventoryInfo : productSnDataList) {
|
||||
Long warehouseId = inventoryInfo.getWarehouseId();
|
||||
if (warehouseId != null && !warehouseId.equals(inventoryDelivery.getWarehouseId())) {
|
||||
throw new ServiceException("发货数据仓库与出库单仓库不一致,请确认后重试");
|
||||
}
|
||||
}
|
||||
for (InventoryInfo inventoryInfo : productSnDataList) {
|
||||
inventoryInfo.setInventoryStatus(InventoryInfo.InventoryStatusEnum.OUTER.getCode());
|
||||
|
|
@ -343,7 +296,43 @@ public class InventoryDeliveryServiceImpl implements IInventoryDeliveryService,
|
|||
detail.setProductSn(inventoryInfo.getProductSn());
|
||||
detailList.add(detail);
|
||||
}
|
||||
omsInventoryInnerService.importByOuter(productSnDataList, inventoryDelivery.getProductCode(), inventoryDelivery.getPurchaseNo(), inventoryDelivery.getItemId());
|
||||
// 一个出库单可以同时导入多个采购单的SN:按SN归属的采购单分组回写入库单,
|
||||
// 否则整批会挂到最后操作的采购单上,入库单、应付单归属和采购单入库数量都会错
|
||||
Map<String, List<InventoryInfo>> importGroupMap = new LinkedHashMap<>();
|
||||
for (InventoryInfo inventoryInfo : productSnDataList) {
|
||||
String groupPurchaseNo = snPurchaseMap.get(inventoryInfo.getProductSn());
|
||||
if (StringUtils.isEmpty(groupPurchaseNo)) {
|
||||
groupPurchaseNo = inventoryInfo.getPurchaseNo();
|
||||
}
|
||||
if (StringUtils.isEmpty(groupPurchaseNo)) {
|
||||
groupPurchaseNo = inventoryDelivery.getPurchaseNo();
|
||||
}
|
||||
if (StringUtils.isEmpty(groupPurchaseNo)) {
|
||||
throw new ServiceException(String.format("SN码[%s]未找到所属采购单,无法生成入库单", inventoryInfo.getProductSn()));
|
||||
}
|
||||
// 已按SN逐条校验过采购配额时,归属必须来自校验结果,
|
||||
// 不允许再回落到行级或整单采购单,否则会把其他采购单的SN挂到同一张入库单上
|
||||
if (CollUtil.isNotEmpty(snPurchaseMap) && !groupPurchaseNo.equals(snPurchaseMap.get(inventoryInfo.getProductSn()))) {
|
||||
throw new ServiceException(String.format("SN码[%s]未确定所属采购单,无法生成入库单", inventoryInfo.getProductSn()));
|
||||
}
|
||||
importGroupMap.computeIfAbsent(groupPurchaseNo, key -> new ArrayList<>()).add(inventoryInfo);
|
||||
}
|
||||
for (Map.Entry<String, List<InventoryInfo>> entry : importGroupMap.entrySet()) {
|
||||
String groupPurchaseNo = entry.getKey();
|
||||
Long preferredItemId = Objects.equals(groupPurchaseNo, inventoryDelivery.getPurchaseNo())
|
||||
? inventoryDelivery.getItemId() : null;
|
||||
Map<Long, Integer> itemAllocations = allocatePurchaseItemQuantities(groupPurchaseNo,
|
||||
inventoryDelivery.getProductCode(), entry.getValue().size(), preferredItemId);
|
||||
int offset = 0;
|
||||
for (Map.Entry<Long, Integer> allocation : itemAllocations.entrySet()) {
|
||||
int allocationSize = allocation.getValue();
|
||||
List<InventoryInfo> itemSnList = new ArrayList<>(
|
||||
entry.getValue().subList(offset, offset + allocationSize));
|
||||
omsInventoryInnerService.importByOuter(itemSnList, inventoryDelivery.getProductCode(),
|
||||
groupPurchaseNo, allocation.getKey());
|
||||
offset += allocationSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 指定发货/导入与手工勾选混用时,避免手工勾选的SN被静默丢弃
|
||||
if ((CollUtil.isNotEmpty(productSnDataList) || CollUtil.isNotEmpty(assignSnDataList)) && CollUtil.isNotEmpty(productSnList)) {
|
||||
|
|
@ -1656,4 +1645,262 @@ public class InventoryDeliveryServiceImpl implements IInventoryDeliveryService,
|
|||
throw new ServiceException("仅维保订单只能发关联项目已发货的SN,请重新选择发货清单");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 按SN实际归属的采购单分组校验采购单绑定余量。
|
||||
*
|
||||
* @param inventoryDelivery 发货信息
|
||||
* @param orderInfo 订单信息
|
||||
* @param productSnList 页面勾选的SN
|
||||
* @param productSnDataList 导入清单的SN(尚未入库)
|
||||
* @param assignSnDataList 指定发货清单的SN(已入库未发货,发货时才绑定订单,同样占用配货数量)
|
||||
* @return 本次发货SN与采购单号的关系,供导入回写入库单时复用
|
||||
*/
|
||||
private Map<String, String> validatePurchaseBindQuota(InventoryDelivery inventoryDelivery, ProjectOrderInfo orderInfo,
|
||||
List<String> productSnList, List<InventoryInfo> productSnDataList,
|
||||
List<InventoryInfo> assignSnDataList) {
|
||||
Set<String> allSnSet = new LinkedHashSet<>();
|
||||
if (CollUtil.isNotEmpty(productSnList)) {
|
||||
allSnSet.addAll(productSnList);
|
||||
}
|
||||
// 与原有行为保持一致:纯手工勾选SN时,SN必须已存在于库存
|
||||
if (CollUtil.isNotEmpty(productSnList) && CollUtil.isEmpty(productSnDataList) && CollUtil.isEmpty(assignSnDataList)
|
||||
&& CollUtil.isEmpty(inventoryInfoMapper.listByProductSnList(productSnList))) {
|
||||
throw new ServiceException("未找到SN码对应的库存信息");
|
||||
}
|
||||
if (CollUtil.isNotEmpty(productSnDataList)) {
|
||||
productSnDataList.stream().map(InventoryInfo::getProductSn).filter(StringUtils::isNotEmpty).forEach(allSnSet::add);
|
||||
}
|
||||
if (CollUtil.isNotEmpty(assignSnDataList)) {
|
||||
assignSnDataList.stream().map(InventoryInfo::getProductSn).filter(StringUtils::isNotEmpty).forEach(allSnSet::add);
|
||||
}
|
||||
Map<String, String> snPurchaseMap = resolveSnPurchaseNoMap(allSnSet, productSnDataList, assignSnDataList,
|
||||
inventoryDelivery.getPurchaseNo());
|
||||
// 完全没有采购单线索(历史库存未关联入库单、整单也没有采购单号)时不做采购配额校验,
|
||||
// 保持原有行为,避免影响与采购单无关的发货场景
|
||||
if (snPurchaseMap.isEmpty()) {
|
||||
return snPurchaseMap;
|
||||
}
|
||||
// 分组校验前必须保证每个SN都能确定采购单,否则未解析的SN会漏校验,
|
||||
// 等到导入阶段才按整单采购单兜底,仍会把多采购单的SN挂到同一张入库单上
|
||||
if (snPurchaseMap.size() != allSnSet.size()) {
|
||||
throw new ServiceException("存在SN码未确定所属采购单,请重新选择发货清单");
|
||||
}
|
||||
|
||||
Map<String, List<String>> purchaseSnMap = new LinkedHashMap<>();
|
||||
snPurchaseMap.forEach((productSn, purchaseNo) ->
|
||||
purchaseSnMap.computeIfAbsent(purchaseNo, key -> new ArrayList<>()).add(productSn));
|
||||
|
||||
for (Map.Entry<String, List<String>> entry : purchaseSnMap.entrySet()) {
|
||||
String purchaseNo = entry.getKey();
|
||||
int newSnCount = entry.getValue().size();
|
||||
OmsPurchaseOrder purchaseOrder = omsPurchaseOrderService.selectOmsPurchaseOrderByNo(purchaseNo);
|
||||
if (purchaseOrder == null) {
|
||||
throw new ServiceException(String.format("采购单[%s]信息不存在", purchaseNo));
|
||||
}
|
||||
OmsPurchaseOrderMap purchaseOrderMap = omsPurchaseOrderMapMapper.selectByOrderIdAndPurchaseId(orderInfo.getId(), purchaseOrder.getId(), inventoryDelivery.getProductCode());
|
||||
if (purchaseOrderMap == null || purchaseOrderMap.getBindNum() == null || purchaseOrderMap.getBindNum() <= 0) {
|
||||
throw new ServiceException(String.format("当前订单与采购单[%s]未建立绑定关系或绑定数量为0", purchaseNo));
|
||||
}
|
||||
int totalBindNum = purchaseOrderMap.getBindNum();
|
||||
int alreadyBindNum = inventoryInfoMapper.countByOrderCodeAndPurchaseNo(inventoryDelivery.getOrderCode(), purchaseNo, inventoryDelivery.getProductCode());
|
||||
int remainingNum = totalBindNum - alreadyBindNum;
|
||||
if (newSnCount > remainingNum) {
|
||||
throw new ServiceException(String.format("采购单[%s]新增SN码数量(%d)超过剩余可新增数量(%d),总绑定数(%d),已绑定数(%d)",
|
||||
purchaseNo, newSnCount, remainingNum, totalBindNum, alreadyBindNum));
|
||||
}
|
||||
}
|
||||
return snPurchaseMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析每个SN归属的采购单。
|
||||
*
|
||||
* <p>前端按采购单页签提交的SN优先,已入库SN再用库存入库单的实际采购单做一致性校验;
|
||||
* 前端未声明时使用库存实际归属;两者都取不到时,只有在能确定本次只涉及一个采购单的
|
||||
* 情况下才回落到本次提交的采购单号,多采购单场景直接报错,避免整批SN被归到同一采购单。</p>
|
||||
*
|
||||
* @param snSet 本次发货涉及的SN
|
||||
* @param productSnDataList 导入清单
|
||||
* @param assignSnDataList 指定发货清单
|
||||
* @param defaultPurchaseNo 本次提交的采购单号
|
||||
* @return SN与采购单号的关系,每个SN都有值
|
||||
*/
|
||||
private Map<String, String> resolveSnPurchaseNoMap(Set<String> snSet, List<InventoryInfo> productSnDataList,
|
||||
List<InventoryInfo> assignSnDataList, String defaultPurchaseNo) {
|
||||
Map<String, String> snPurchaseMap = new LinkedHashMap<>();
|
||||
if (CollUtil.isEmpty(snSet)) {
|
||||
return snPurchaseMap;
|
||||
}
|
||||
Map<String, String> declaredPurchaseMap = new LinkedHashMap<>();
|
||||
collectSnPurchaseNo(snSet, productSnDataList, declaredPurchaseMap);
|
||||
collectSnPurchaseNo(snSet, assignSnDataList, declaredPurchaseMap);
|
||||
Map<String, String> inventoryPurchaseMap = loadInventoryPurchaseNoMap(snSet);
|
||||
Set<String> knownPurchaseNoSet = new LinkedHashSet<>(declaredPurchaseMap.values());
|
||||
knownPurchaseNoSet.addAll(inventoryPurchaseMap.values());
|
||||
// 没有任何采购单线索时(历史库存未关联采购单、纯手工发货),保持原有行为不做采购配额校验
|
||||
if (knownPurchaseNoSet.isEmpty() && StringUtils.isEmpty(defaultPurchaseNo)) {
|
||||
return snPurchaseMap;
|
||||
}
|
||||
// 只有已知采购单为空或仅等于本次提交的采购单时,才能认为缺失归属的SN也属于该采购单;
|
||||
// 多采购单一起发货时提交的 purchaseNo 只是最后操作的页签,不能作为整批兜底
|
||||
boolean canUseDefaultPurchaseNo = StringUtils.isNotEmpty(defaultPurchaseNo)
|
||||
&& (knownPurchaseNoSet.isEmpty()
|
||||
|| (knownPurchaseNoSet.size() == 1 && knownPurchaseNoSet.contains(defaultPurchaseNo)));
|
||||
for (String productSn : snSet) {
|
||||
String declaredPurchaseNo = declaredPurchaseMap.get(productSn);
|
||||
String inventoryPurchaseNo = inventoryPurchaseMap.get(productSn);
|
||||
if (StringUtils.isNotEmpty(declaredPurchaseNo)) {
|
||||
if (StringUtils.isNotEmpty(inventoryPurchaseNo) && !inventoryPurchaseNo.equals(declaredPurchaseNo)) {
|
||||
throw new ServiceException(String.format("SN码[%s]所属采购单为[%s],与页签选择的采购单[%s]不一致,请确认后重试",
|
||||
productSn, inventoryPurchaseNo, declaredPurchaseNo));
|
||||
}
|
||||
snPurchaseMap.put(productSn, declaredPurchaseNo);
|
||||
} else if (StringUtils.isNotEmpty(inventoryPurchaseNo)) {
|
||||
snPurchaseMap.put(productSn, inventoryPurchaseNo);
|
||||
} else if (canUseDefaultPurchaseNo) {
|
||||
snPurchaseMap.put(productSn, defaultPurchaseNo);
|
||||
} else {
|
||||
throw new ServiceException(String.format("SN码[%s]未携带采购单号,无法确定所属采购单,请重新选择发货清单", productSn));
|
||||
}
|
||||
}
|
||||
return snPurchaseMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询已入库SN的实际采购单归属。
|
||||
*
|
||||
* @param snSet 本次发货涉及的SN
|
||||
* @return SN与库存入库单采购单号的关系,未入库或入库单无采购单号的SN不在结果中
|
||||
*/
|
||||
private Map<String, String> loadInventoryPurchaseNoMap(Set<String> snSet) {
|
||||
Map<String, String> snPurchaseMap = new HashMap<>();
|
||||
if (CollUtil.isEmpty(snSet)) {
|
||||
return snPurchaseMap;
|
||||
}
|
||||
List<InventoryInfo> inventoryInfoList = inventoryInfoMapper.listByProductSnList(new ArrayList<>(snSet));
|
||||
if (CollUtil.isEmpty(inventoryInfoList)) {
|
||||
return snPurchaseMap;
|
||||
}
|
||||
List<String> innerCodeList = inventoryInfoList.stream().map(InventoryInfo::getInnerCode)
|
||||
.filter(StringUtils::isNotEmpty).distinct().collect(Collectors.toList());
|
||||
Map<String, String> innerPurchaseMap = new HashMap<>();
|
||||
if (CollUtil.isNotEmpty(innerCodeList)) {
|
||||
for (OmsInventoryInner inner : omsInventoryInnerMapper.selectOmsInventoryInnerByInnerCodeList(innerCodeList)) {
|
||||
if (StringUtils.isNotEmpty(inner.getInnerCode()) && StringUtils.isNotEmpty(inner.getPurchaseNo())) {
|
||||
innerPurchaseMap.put(inner.getInnerCode(), inner.getPurchaseNo());
|
||||
}
|
||||
}
|
||||
}
|
||||
for (InventoryInfo info : inventoryInfoList) {
|
||||
String purchaseNo = innerPurchaseMap.get(info.getInnerCode());
|
||||
if (StringUtils.isEmpty(info.getProductSn()) || StringUtils.isEmpty(purchaseNo)) {
|
||||
continue;
|
||||
}
|
||||
String existingPurchaseNo = snPurchaseMap.get(info.getProductSn());
|
||||
if (StringUtils.isNotEmpty(existingPurchaseNo) && !existingPurchaseNo.equals(purchaseNo)) {
|
||||
throw new ServiceException(String.format("SN码[%s]在库存中同时归属采购单[%s]和[%s],请确认后重试",
|
||||
info.getProductSn(), existingPurchaseNo, purchaseNo));
|
||||
}
|
||||
snPurchaseMap.put(info.getProductSn(), purchaseNo);
|
||||
}
|
||||
return snPurchaseMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 收集前端清单中明确携带的SN采购单归属。
|
||||
*
|
||||
* @param snSet 本次发货涉及的SN
|
||||
* @param snDataList 导入或指定发货清单
|
||||
* @param snPurchaseMap SN与采购单号的关系
|
||||
*/
|
||||
private void collectSnPurchaseNo(Set<String> snSet, List<InventoryInfo> snDataList, Map<String, String> snPurchaseMap) {
|
||||
if (CollUtil.isEmpty(snDataList)) {
|
||||
return;
|
||||
}
|
||||
for (InventoryInfo info : snDataList) {
|
||||
String productSn = info.getProductSn();
|
||||
if (StringUtils.isEmpty(productSn) || StringUtils.isEmpty(info.getPurchaseNo()) || !snSet.contains(productSn)) {
|
||||
continue;
|
||||
}
|
||||
String existingPurchaseNo = snPurchaseMap.get(productSn);
|
||||
if (StringUtils.isNotEmpty(existingPurchaseNo) && !existingPurchaseNo.equals(info.getPurchaseNo())) {
|
||||
throw new ServiceException(String.format("SN码[%s]同时归属采购单[%s]和[%s],请确认后重试",
|
||||
productSn, existingPurchaseNo, info.getPurchaseNo()));
|
||||
}
|
||||
snPurchaseMap.put(productSn, info.getPurchaseNo());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 按采购明细剩余可入库数量拆分本次入库量。
|
||||
*
|
||||
* <p>同一采购单同一产品可能存在多条明细,单条明细剩余不足但合计足够时,
|
||||
* 需要拆成多张入库单分别回写对应明细,不能只取一条明细。
|
||||
* 优先使用前端带入的明细,再按明细顺序补足。</p>
|
||||
*
|
||||
* @param purchaseNo 采购单号
|
||||
* @param productCode 产品编码
|
||||
* @param groupSize 本次该采购单需要入库的SN数量
|
||||
* @param preferredItemId 前端指定的采购明细ID,可为空
|
||||
* @return 采购明细ID与本次入库数量的关系,按拆分顺序排列
|
||||
*/
|
||||
private Map<Long, Integer> allocatePurchaseItemQuantities(String purchaseNo, String productCode, int groupSize,
|
||||
Long preferredItemId) {
|
||||
OmsPurchaseOrderItemDto itemQuery = new OmsPurchaseOrderItemDto();
|
||||
itemQuery.setPurchaseNo(purchaseNo);
|
||||
itemQuery.setProductCode(productCode);
|
||||
List<OmsPurchaseOrderItemDto> itemList = omsPurchaseOrderService.listItem(itemQuery);
|
||||
if (CollUtil.isEmpty(itemList)) {
|
||||
throw new ServiceException(String.format("采购单[%s]未找到产品[%s]的采购明细", purchaseNo, productCode));
|
||||
}
|
||||
List<OmsPurchaseOrderItemDto> candidates = new ArrayList<>();
|
||||
if (preferredItemId != null) {
|
||||
for (OmsPurchaseOrderItemDto item : itemList) {
|
||||
if (preferredItemId.equals(item.getItemId())) {
|
||||
if (getRemainingInnerQuantity(item) > 0) {
|
||||
candidates.add(item);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (OmsPurchaseOrderItemDto item : itemList) {
|
||||
if (item.getItemId() == null || item.getItemId().equals(preferredItemId)
|
||||
|| getRemainingInnerQuantity(item) <= 0) {
|
||||
continue;
|
||||
}
|
||||
candidates.add(item);
|
||||
}
|
||||
|
||||
Map<Long, Integer> allocationMap = new LinkedHashMap<>();
|
||||
int remaining = groupSize;
|
||||
for (OmsPurchaseOrderItemDto item : candidates) {
|
||||
if (remaining <= 0) {
|
||||
break;
|
||||
}
|
||||
int take = Math.min(remaining, getRemainingInnerQuantity(item));
|
||||
if (take > 0) {
|
||||
allocationMap.put(item.getItemId(), take);
|
||||
remaining -= take;
|
||||
}
|
||||
}
|
||||
if (remaining > 0) {
|
||||
throw new ServiceException(String.format("采购单[%s]产品[%s]剩余可入库数量不足,本次需入库%d",
|
||||
purchaseNo, productCode, groupSize));
|
||||
}
|
||||
return allocationMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 采购明细剩余可入库数量。
|
||||
*
|
||||
* @param item 采购明细
|
||||
* @return 剩余可入库数量
|
||||
*/
|
||||
private int getRemainingInnerQuantity(OmsPurchaseOrderItemDto item) {
|
||||
int quantity = item.getQuantity() == null ? 0 : item.getQuantity().intValue();
|
||||
int innerQuantity = item.getInnerQuantity() == null ? 0 : item.getInnerQuantity().intValue();
|
||||
return quantity - innerQuantity;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -225,7 +225,10 @@ public class OmsInventoryInnerServiceImpl implements IOmsInventoryInnerService {
|
|||
|
||||
}
|
||||
BigDecimal finalTaxRate = taxRate == null ? new BigDecimal(defaultTax) : taxRate;
|
||||
BigDecimal withoutTax = inventoryInfoList.stream().reduce(BigDecimal.ZERO, (a, b) -> a.add(b.getInnerPrice().divide(BigDecimal.ONE.add(finalTaxRate), 2, RoundingMode.HALF_UP)), BigDecimal::add);
|
||||
BigDecimal withoutTax = inventoryInfoList.stream()
|
||||
.map(InventoryInfo::getInnerPrice)
|
||||
.filter(Objects::nonNull)
|
||||
.reduce(BigDecimal.ZERO, (a, b) -> a.add(b.divide(BigDecimal.ONE.add(finalTaxRate), 2, RoundingMode.HALF_UP)), BigDecimal::add);
|
||||
payableBill.setTotalPriceWithoutTax(withoutTax);
|
||||
payableBill.setTaxRate(finalTaxRate);
|
||||
payableBill.setTaxAmount(totalPriceWithTax.subtract(payableBill.getTotalPriceWithoutTax()));
|
||||
|
|
@ -322,7 +325,8 @@ public class OmsInventoryInnerServiceImpl implements IOmsInventoryInnerService {
|
|||
omsInventoryInner.setProductCode(productCode);
|
||||
omsInventoryInner.setProductType(productInfos.get(0).getType());
|
||||
omsInventoryInner.setPurchaseNo(purchaseNo);
|
||||
omsInventoryInner.setTotalAmount(inventoryInfoList.stream().map(InventoryInfo::getInnerPrice).reduce(BigDecimal.ZERO, BigDecimal::add));
|
||||
omsInventoryInner.setTotalAmount(inventoryInfoList.stream().map(InventoryInfo::getInnerPrice)
|
||||
.filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
||||
omsInventoryInner.setTaxRate(inventoryInfoList.get(0).getTaxRate());
|
||||
// omsInventoryInner.setTaxTotal(inventoryInfoList.stream().map(item->
|
||||
// item.getInnerPrice().divide(BigDecimal.ONE.add(item.getTaxRate()),2, RoundingMode.HALF_UP)
|
||||
|
|
|
|||
|
|
@ -246,7 +246,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<foreach item="item" collection="authVendorCodeList" separator="," open="(" close=")">#{item}</foreach>
|
||||
</if>
|
||||
</where>
|
||||
order by t2.create_time desc
|
||||
order by t2.create_time desc, t1.id asc
|
||||
|
||||
</select>
|
||||
<select id="listPurchaseStock" resultType="com.ruoyi.sip.dto.inventory.OmsPurchaseOrderItemDto">
|
||||
|
|
|
|||
Loading…
Reference in New Issue