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); + }); } // 查找最新的报价数据