From 5159b07c9d45c8bc9cbd21a8acc1805789779a0a Mon Sep 17 00:00:00 2001 From: liuxiaoxu <1793812695@qq.com> Date: Fri, 27 Sep 2024 09:04:48 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=20=E9=94=80=E5=94=AE=E7=AE=A1=E7=90=86=20?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AE=A2=E6=88=B7=E6=8A=A5=E4=BB=B7=E6=89=B9?= =?UTF-8?q?=E9=87=8F=E6=8F=92=E5=85=A5=E7=89=A9=E6=96=99=E7=9A=84=E5=89=8D?= =?UTF-8?q?=E7=AB=AFjs=E6=96=B9=E6=B3=95=EF=BC=9A=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=A6=82=E4=B8=8B=EF=BC=9A=201=EF=BC=9A=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E4=B8=A4=E4=B8=AASet=EF=BC=9A=E4=B8=80=E4=B8=AA=E7=94=A8?= =?UTF-8?q?=E4=BA=8E=E5=AD=98=E5=82=A8=E7=8E=B0=E6=9C=89=E7=9A=84=E7=89=A9?= =?UTF-8?q?=E6=96=99=E5=8F=B7=EF=BC=8C=E5=8F=A6=E4=B8=80=E4=B8=AA=E7=94=A8?= =?UTF-8?q?=E4=BA=8E=E5=AD=98=E5=82=A8=E5=8D=B3=E5=B0=86=E6=8F=92=E5=85=A5?= =?UTF-8?q?=E7=9A=84=E7=89=A9=E6=96=99=E5=8F=B7=E3=80=82=202=EF=BC=9A?= =?UTF-8?q?=E5=9C=A8=E5=8F=91=E8=B5=B7=E6=9F=A5=E8=AF=A2=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E4=B9=8B=E5=89=8D=E6=A3=80=E6=9F=A5=EF=BC=9A=E7=A1=AE=E4=BF=9D?= =?UTF-8?q?=E7=89=A9=E6=96=99=E5=8F=B7=E6=97=A2=E4=B8=8D=E5=9C=A8=E7=8E=B0?= =?UTF-8?q?=E6=9C=89=E6=95=B0=E6=8D=AE=E4=B8=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E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SysCustomerQuoteController.java | 8 ++ .../templates/system/customerQuote/add.html | 97 ++++++------------- 2 files changed, 39 insertions(+), 66 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/controller/SysCustomerQuoteController.java b/ruoyi-admin/src/main/java/com/ruoyi/system/controller/SysCustomerQuoteController.java index 49eb1ebf..5c08d0ca 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/controller/SysCustomerQuoteController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/controller/SysCustomerQuoteController.java @@ -35,6 +35,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import java.io.IOException; +import java.math.BigDecimal; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -467,6 +468,13 @@ public class SysCustomerQuoteController extends BaseController sysCustomerQuoteHistory.setCustomerCode(customerCode); List sysCustomerQuoteHistories = quoteHistoryService.selectSysCustomerQuoteHistoryList(sysCustomerQuoteHistory); List filterCustomerQuoteHistories = sysCustomerQuoteHistories.stream().filter(item -> item.getIsLatest().equals("1")).collect(Collectors.toList()); + if (filterCustomerQuoteHistories.size() == 0) + { + SysCustomerQuoteHistory temp = new SysCustomerQuoteHistory(); + temp.setMaterialRmb(BigDecimal.ZERO); + temp.setMaterialUsd(BigDecimal.ZERO); + return AjaxResult.success(temp); + } return AjaxResult.success(filterCustomerQuoteHistories.get(0)); } diff --git a/ruoyi-admin/src/main/resources/templates/system/customerQuote/add.html b/ruoyi-admin/src/main/resources/templates/system/customerQuote/add.html index 334d3d6b..fdce477f 100644 --- a/ruoyi-admin/src/main/resources/templates/system/customerQuote/add.html +++ b/ruoyi-admin/src/main/resources/templates/system/customerQuote/add.html @@ -653,28 +653,28 @@ } var existingData = $("#bootstrap-sub-table-quoteChild").bootstrapTable('getData'); - var promises = []; + var materialCodesSet = new Set(); // 使用Set来存储物料号 - // 存储要插入的新行 - var newRows = []; + // 存储所有现有的物料号 + existingData.forEach(function (row) { + materialCodesSet.add(row.materialCode); + }); - // 遍历选中的每一行物料信息 - for (var i = 0; i < selectedRows.length; i++) { - var rowData = selectedRows[i]; + // 存储所有即将插入的物料号 + var newMaterialCodesSet = new Set(); + var promises = selectedRows.map(rowData => { // 检查是否已经存在相同的物料 - var isDuplicate = false; - for (var j = 0; j < existingData.length; j++) { - if (existingData[j].materialCode === rowData.materialNo) { - isDuplicate = true; - break; - } + if (materialCodesSet.has(rowData.materialNo) || newMaterialCodesSet.has(rowData.materialNo)) { + $.modal.alertError("不能选择已添加过的相同料号:" + rowData.materialNo); + return Promise.reject("Duplicate material number: " + rowData.materialNo); } - if (!isDuplicate) { - // 如果不存在,则准备插入新行,并发起查询请求 - promises.push(queryRecentQuotation(rowData.materialNo).then(function (quotationData) { - // 将查询结果赋值给 newRows 中的相应字段 + // 标记即将插入的物料号 + newMaterialCodesSet.add(rowData.materialNo); + + return queryRecentQuotation(rowData.materialNo) + .then(function (quotationData) { return { materialId: rowData.id, materialCode: rowData.materialNo, @@ -705,58 +705,23 @@ updateTime: "", remark: "", }; - }).catch(function (error) { - // 返回一个默认对象以保证数据结构一致 - return { - materialId: rowData.id, - materialCode: rowData.materialNo, - materialName: rowData.materialName, - materialType: rowData.materialType, - describe: rowData.describe, - brand: rowData.brand, - unit: rowData.unit, - processMethod: rowData.processMethod, - photoUrl: rowData.photoUrl, - countTax: '', - usdTax: '', - materialNum: "", - materialSole: "", - recentQuotationRMB: '', - recentQuotationUSD: '', - materialRmb: "", - materialNoRmb: "", - materialNoUsd: "", - materialUsd: "", - materialUsdSum: "", - materialNoUsdSum: "", - materialNoRmbSum: "", - materialRmbSum: "", - createBy: "", - createTime: "", - updateBy: "", - updateTime: "", - remark: "", - }; - })); - } else { - $.modal.alertError("不能选择已添加过的相同料号"); - } - } + }); + }); - // 使用Promise.all等待所有查询完成 - Promise.all(promises).then(function (rows) { - newRows = rows.filter(row => !!row); // 清除可能的null或undefined - if (newRows.length > 0) { + // 使用Promise.all等待所有查询完成,并将结果直接存入 newRows + Promise.all(promises) + .then(function (newRows) { // 批量插入新行 - for (var k = 0; k < newRows.length; k++) { - $("#bootstrap-sub-table-quoteChild").bootstrapTable('insertRow', { index: 1, row: newRows[k] }); - } - } - layer.close(index); - }).catch(function (error) { - console.error('Some requests failed:', error); - layer.close(index); - }); + newRows.forEach(function (row) { + $("#bootstrap-sub-table-quoteChild").bootstrapTable('insertRow', { index: 1, row: row }); + }); + + layer.close(index); + }) + .catch(function (error) { + console.error('Some requests failed:', error); + layer.close(index); + }); } // 查找最新的报价数据