From 8bc05cca1e4385b079b675e7249649b680e1eb94 Mon Sep 17 00:00:00 2001 From: zhangsiqi <2825463979@qq.com> Date: Fri, 28 Jun 2024 08:37:40 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=87=E8=B4=AD=E8=AE=A1=E5=88=92=E7=94=9F?= =?UTF-8?q?=E6=88=90=E9=87=87=E8=B4=AD=E8=AE=A2=E5=8D=95=EF=BC=9A=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E7=89=A9=E6=96=99=E6=96=99=E5=8F=B7=E9=87=87=E8=B4=AD?= =?UTF-8?q?=E6=8A=A5=E4=BB=B7=EF=BC=8C=E5=B9=B6=E6=94=BE=E5=85=A5=E9=87=87?= =?UTF-8?q?=E8=B4=AD=E8=AE=A1=E5=88=92=E7=9A=84=E7=89=A9=E6=96=99=E7=9A=84?= =?UTF-8?q?=E4=BE=9B=E5=BA=94=E5=95=86=E5=88=97=E8=A1=A8=E4=B8=AD=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=E4=B8=BA=E5=89=8D=E7=AB=AF=E5=8A=A8=E6=80=81=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/PurchasePlanController.java | 19 +- .../purchase/domain/PurchasePlanChild.java | 22 +- .../service/impl/PurchasePlanServiceImpl.java | 2 + .../purchase/PurchasePlanChildMapper.xml | 79 ++++-- .../purchaseOrder/addPurchaseStorage.html | 238 ++++++---------- .../purchasePlan/addPurchaseOrder.html | 259 ++++++++++++------ 6 files changed, 346 insertions(+), 273 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/purchase/controller/PurchasePlanController.java b/ruoyi-admin/src/main/java/com/ruoyi/purchase/controller/PurchasePlanController.java index 3ec562d4..eab8ca9b 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/purchase/controller/PurchasePlanController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/purchase/controller/PurchasePlanController.java @@ -1,8 +1,7 @@ package com.ruoyi.purchase.controller; -import java.util.Arrays; -import java.util.List; -import java.util.Set; +import java.util.*; +import java.util.stream.Collectors; import com.ruoyi.common.core.text.Convert; import com.ruoyi.purchase.domain.PurchasePlan; @@ -27,6 +26,8 @@ import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.common.core.page.TableDataInfo; +import static com.alibaba.druid.sql.ast.TDDLHint.Type.Function; + /** * 采购计划单Controller * @@ -113,7 +114,7 @@ public class PurchasePlanController extends BaseController return prefix + "/edit"; } @GetMapping("/addPurchaseOrder/{purchasePlanCodes}") - public String purChaseOrder(@PathVariable("purchasePlanCodes") String purchasePlanCodes,ModelMap mmap){ + public String addPurchaseOrder(@PathVariable("purchasePlanCodes") String purchasePlanCodes,ModelMap mmap){ //purchasePlanCodes去除重复数据,purchasePlanCodeArray作为数组类型去除 // 直接使用String的split方法分割字符串,然后转为Stream去重,最后再拼接回字符串 @@ -123,11 +124,15 @@ public class PurchasePlanController extends BaseController List purchasePlanList = purchasePlanService.selectPurchasePlanByPlanCode(uniquePurchasePlanCodes); //根据采购计划编号查询对应的采购报价数据 List purchasePlanChildList = purchasePlanChildService.getPurchasePlanChildByPlanCodes(uniquePurchasePlanCodes); - //再根据采购计划编号分组查询对应的采购报价数据分组 + for(PurchasePlanChild purchasePlanChild : purchasePlanChildList){ - purchasePlanChild.setPurchaseSupplierList(purchasePlanChild.parseSupplierMaterialCombinations(purchasePlanChild.getSupplierCodes())); + String materialCode = purchasePlanChild.getMaterialCode(); + List purchaseQuoteChildList = purchaseQuoteChildService.selectQuoteChildByMaterialCode(materialCode); + purchasePlanChild.setPurchaseSupplierList(purchaseQuoteChildList); } - //查询物料报价中供应商 + //再根据采购计划编号分组查询对应的采购报价数据分组 + //用stream流处理相同供应商\物料\ + //将供应商信息解析成List mmap.put("purchasePlanList", purchasePlanList); mmap.put("purchasePlanCodes", uniquePurchasePlanCodes); mmap.put("purchasePlanChildList", purchasePlanChildList); diff --git a/ruoyi-admin/src/main/java/com/ruoyi/purchase/domain/PurchasePlanChild.java b/ruoyi-admin/src/main/java/com/ruoyi/purchase/domain/PurchasePlanChild.java index 0f3012a5..88b0e3e5 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/purchase/domain/PurchasePlanChild.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/purchase/domain/PurchasePlanChild.java @@ -91,6 +91,7 @@ public class PurchasePlanChild extends BaseEntity /** 关联采购报价单编号 */ private String correlationCodes; + private String planCodes; private List purchaseSupplierList; public String getSupplierCodes() { @@ -264,6 +265,14 @@ public class PurchasePlanChild extends BaseEntity this.purchaseSupplierList = purchaseSupplierList; } + public String getPlanCodes() { + return planCodes; + } + + public void setPlanCodes(String planCodes) { + this.planCodes = planCodes; + } + public String getUseStatus() { return useStatus; @@ -282,7 +291,9 @@ public class PurchasePlanChild extends BaseEntity this.delFlag = delFlag; } - public String getDelFlag() + + + public String getDelFlag() { return delFlag; } @@ -291,15 +302,12 @@ public class PurchasePlanChild extends BaseEntity if (combinations == null || combinations.isEmpty()) { return Collections.emptyList(); } - //materialCode|purchaseQuoteCode|supplierCode|supplierName|materialName|materialNoRmb|materialRmb - /* 1. 料号 | 2. 供应商报价编号 | 3. 供应商编号 | 4.供应商名称 | 5. 物料名称 | 6. 物料含税单价(RMB) | 7. 物料不含税单价(RMB) */ + //materialCode|purchaseQuoteCode|supplierCode|supplierName|materialName|materialNoRmb|materialRmb|purchasePlanCode|correlationCode + /* 1. 料号 | 2. 供应商报价编号 | 3. 供应商编号 | 4.供应商名称 | 5. 物料名称 | 6. 物料含税单价(RMB) | 7. 物料不含税单价(RMB) | 8关联采购计划单号 | 9关联相关订单号 */ List purchaseSupplierList = new ArrayList<>(); String[] split = combinations.split(","); for (int i = 0; i < split.length; i++) { String[] split1 = split[i].split("\\|"); - if (split1.length != 7) { - continue; - } PurchaseQuoteChild purchaseQuoteChild = new PurchaseQuoteChild(); purchaseQuoteChild.setMaterialCode(split1[0]); purchaseQuoteChild.setPurchaseQuoteCode(split1[1]); @@ -308,6 +316,8 @@ public class PurchasePlanChild extends BaseEntity purchaseQuoteChild.setMaterialName(split1[4]); purchaseQuoteChild.setMaterialNoRmb(BigDecimal.valueOf(Float.parseFloat(split1[5]))); purchaseQuoteChild.setMaterialRmb(BigDecimal.valueOf(Float.parseFloat(split1[6]))); + purchaseQuoteChild.setPurchasePlanCode(split1[7]); + purchaseQuoteChild.setCorrelationCode(split1[8]); purchaseSupplierList.add(purchaseQuoteChild); } return purchaseSupplierList; diff --git a/ruoyi-admin/src/main/java/com/ruoyi/purchase/service/impl/PurchasePlanServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/purchase/service/impl/PurchasePlanServiceImpl.java index 06210031..a77c7148 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/purchase/service/impl/PurchasePlanServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/purchase/service/impl/PurchasePlanServiceImpl.java @@ -20,6 +20,7 @@ import org.springframework.stereotype.Service; import com.ruoyi.purchase.mapper.PurchasePlanMapper; import com.ruoyi.purchase.service.IPurchasePlanService; import com.ruoyi.common.core.text.Convert; +import org.springframework.transaction.annotation.Transactional; /** * 采购计划单Service业务层处理 @@ -88,6 +89,7 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService * @return 结果 */ @Override + @Transactional(rollbackFor = Exception.class) public int updatePurchasePlan(PurchasePlan purchasePlan) { String loginName = ShiroUtils.getLoginName(); diff --git a/ruoyi-admin/src/main/resources/mapper/purchase/PurchasePlanChildMapper.xml b/ruoyi-admin/src/main/resources/mapper/purchase/PurchasePlanChildMapper.xml index 7e798987..dae7afc9 100644 --- a/ruoyi-admin/src/main/resources/mapper/purchase/PurchasePlanChildMapper.xml +++ b/ruoyi-admin/src/main/resources/mapper/purchase/PurchasePlanChildMapper.xml @@ -20,7 +20,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - + + @@ -31,6 +32,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + select purchase_plan_child_id, purchase_plan_code, material_id, material_code, material_name, material_type, process_method, brand, @@ -165,25 +167,60 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" update purchase_plan_child set del_flag = '0' where purchase_plan_child_id = #{purchasePlanChildId} \ No newline at end of file diff --git a/ruoyi-admin/src/main/resources/templates/purchase/purchaseOrder/addPurchaseStorage.html b/ruoyi-admin/src/main/resources/templates/purchase/purchaseOrder/addPurchaseStorage.html index 85306ef0..68383709 100644 --- a/ruoyi-admin/src/main/resources/templates/purchase/purchaseOrder/addPurchaseStorage.html +++ b/ruoyi-admin/src/main/resources/templates/purchase/purchaseOrder/addPurchaseStorage.html @@ -3,13 +3,7 @@ - +
@@ -52,174 +46,57 @@ \ No newline at end of file diff --git a/ruoyi-admin/src/main/resources/templates/purchase/purchasePlan/addPurchaseOrder.html b/ruoyi-admin/src/main/resources/templates/purchase/purchasePlan/addPurchaseOrder.html index 635433bc..9f81d8d0 100644 --- a/ruoyi-admin/src/main/resources/templates/purchase/purchasePlan/addPurchaseOrder.html +++ b/ruoyi-admin/src/main/resources/templates/purchase/purchasePlan/addPurchaseOrder.html @@ -9,7 +9,7 @@
- +
@@ -19,33 +19,33 @@

公司地址:

- +
- +
- +
- +
- +
- +
- +
- +
- +
- +
@@ -89,6 +89,7 @@ $("#form-plan-purchaseOrder-add").validate({focusCleanup: true}); var purchasePlanChildList = [[${purchasePlanChildList}]]; var purchasePlanList = [[${purchasePlanList}]]; + var purchasePlanCodes = [[${purchasePlanCodes}]]; var formId = "form-plan-purchaseOrder-add"; //根据物料物料数量添加物料分类表,自动生成类似的表单对象 //初始根据采购计划单,涉及到物料做分类表 @@ -101,6 +102,7 @@ //获取 // 假设qualityOrderCode已经定义或者可以通过某种方式获取到 $(function() { + $("#purchasePlanCodes").val(purchasePlanCodes); // 初始化表格 // 假设purchasePlanChildList已定义并包含了需要处理的数据 purchasePlanChildList.forEach(function (material, index) { @@ -109,57 +111,21 @@ tableIdList.push(tableId); // 创建物料信息的容器 var $tableWrapper = $('
'); + // 将整个物料信息容器添加到页面 + $('#material').append($tableWrapper); // 添加关联销售订单号信息 var $headerDiv = $('
' + '
' + - '
' + + '

' + '物料 ' + index + ': ' + '关联订单号: ' + '' + material.correlationCodes + '' + - '

' + + '' + '
' + - '' + '
' + + '
' + '
' + '' + '' + ''); $tableWrapper.append($headerDiv); - // 创建表格的容器 - // 循环处理每个供应商的信息 - material.purchaseSupplierList.forEach(function (supplier, supplierIndex) { - var $supplierInfo = $('
'); // 卡片样式容器,用于包裹每个供应商的信息 - // 构建供应商信息头部 - var $headerContent = - $('
' + '供应商 ' + supplierIndex + ': ' + '' + - '

' + '' + supplier.supplierCode + '' + '-' + '' + supplier.supplierName + '' + '-最新不含税采购价: ' + '' + supplier.materialNoRmb + '' + ' RMB ' + ' 最新含税采购价: ' + '' + supplier.materialRmb + ' RMB

' + - '
' + - '
' + - '' + - '
' + - '' + - '
' + - '
' + - '
' + - '' + - '
' + - '
' + - '' + - '' + - '
' + - '
' + - '
' + - '
' + - '
'); - $supplierInfo.append($headerContent); - // 构建供应商信息下的输入表单 - $supplierForm = $('
'); - // 实际采购数输入框 - // 其他表单项可以根据需要类似添加 - $supplierInfo.append($supplierForm); - $tableWrapper.append($supplierInfo); - }); - tableSetup($supplierForm, tableId); - // 将整个物料信息容器添加到页面 - $('#material').append($tableWrapper); var materialObj = { purchasePlanCode: material.purchasePlanCode, materialCode: material.materialCode, @@ -173,14 +139,97 @@ materialNum: material.materialNum, }; var materialData = [materialObj]; // Bootstrap Table需要一个数组作为数据源 - materialList.push(materialObj); + materialList.push(material); tables(materialTable, materialData); + // 创建表格的容器 + //如果物料下的供应商为空,则不需要添加供应商信息,并在容器中添加一个提示信息:暂无供应商信息,请先添加供应商信息。 + const uniqueSuppliers = []; + if (material.purchaseSupplierList.size == 0) { + var $noSupplierDiv = $('
暂无供应商信息,请先添加供应商信息。
'); + $tableWrapper.append($noSupplierDiv); + }else{ + material.purchaseSupplierList.forEach(supplier => { + const key = `${supplier.supplierCode}_${supplier.materialCode}`; + if (!uniqueSuppliers.map(s => `${s.supplierCode}_${s.materialCode}`).includes(key)) { + uniqueSuppliers.push(supplier); + } + }); + // 循环处理每个供应商的信息 + uniqueSuppliers.forEach(function (supplier, supplierIndex) { + //如果供应商相同,则不需要再次添加供应商信息 + $supplierInfo = $('
'); + // 卡片样式容器,用于包裹每个供应商的信息 + // 构建供应商信息头部 + var $headerContent = + $('
' + + '
' + + '
'+ + '

供应商 ' + supplierIndex + ':' + '

' + + '' + supplier.supplierCode + '' + '-' + + '' + supplier.supplierName + '' + + '-最新不含税采购价: ' + + '' + supplier.materialNoRmb + + ''+ ' RMB 最新含税采购价: ' + + '' + supplier.materialRmb + ' RMB ' + + '' + + '' + + '' + + '
' + + '
' + + '
' + + '
' + + '' + + '
' + + '' + + '
' + + '
' + + '
' + + '' + + '
' + + '
' + + '' + + '' + + '
' + + '
' + + '
' + + '
'); + $tableWrapper.append($supplierInfo); + $supplierInfo.append($headerContent); + // 构建供应商信息下的输入表单 + $supplierForm = $('
'); + // 实际采购数输入框 + // 其他表单项可以根据需要类似添加 + $supplierInfo.append($supplierForm); + }); + tableSetup($supplierInfo, tableId); + } }); // 给实际采购数的输入框绑定事件处理器 - $('.supplierMaterialNum').off('keyup').on('keyup', function() { - var tableId = $(this).closest('.table-materialCode').attr('id'); + $('.supplierMaterialNum').off('keyup').on('keyup', function(event,element) { + console.log(event); + console.log(element); + var tableId = $(element).closest('.table-materialCode').attr('id'); + if (event.keyCode === 13) { + // 获取当前供应商的采购数量 + var purchaseNum = parseFloat($(event).val()) || 0; + // 获取当前供应商的采购价格 + var noRmbPrice = parseFloat($(event).closest('.supplier-card').find('.supplierMaterialNoRmb').text().trim()); + var rmbPrice = parseFloat($(event).closest('.supplier-card').find('.supplierMaterialRmb').text().trim()); + // 更新供应商采购总价 + $(event).closest('.supplier-card').find('.supplierPurchaseTotal').text(purchaseNum * noRmbPrice); + if (rmbPrice) { + $(event).closest('.supplier-card').find('.supplierPurchaseTotalRmb').text(purchaseNum * rmbPrice); + } + if (purchaseNum > 0) { + // 如果采购数量大于0,则显示供应商采购总价 + $(event).closest('.supplier-card').find('.supplierPurchaseTotal').removeClass('hidden'); + $(event).closest('.supplier-card').find('.supplierPurchaseTotalRmb').removeClass('hidden'); + } else { + // 否则隐藏供应商采购总价 + $(event).closest('.supplier-card').find('.supplierPurchaseTotal').addClass('hidden'); + $(event).closest('.supplier-card').find('.supplierPurchaseTotalRmb').addClass('hidden');} + } recalculateTotals(tableId); // 重新计算当前物料的合计 - calculateGlobalTotals(); // 然后重新计算整个订单的合计 }); }); // 新增函数:重新计算某物料的采购数量合计、不含税采购总价和含税采购总价 @@ -225,27 +274,27 @@ } function tableSetup(element, tableId) { var $totalSection = $( - '
' + - '
' + - '
' + - '' + - '
' + - '' + - '
' + - '
' + - '
' + - '' + - '
' + - '' + - '
' + - '
' + - '
' + - '' + - '
' + - '' + - '
' + - '
' + - '
'+ + '
' + + '
' + + '
' + + '' + + '
' + + '' + + '
' + + '
' + + '
' + + '' + + '
' + + '' + + '
' + + '
' + + '
' + + '' + + '
' + + '' + + '
' + + '
' + + '
'+ '
'); element.append($totalSection); } @@ -292,13 +341,14 @@ function submitHandler() { if ($.validate.form()) { var purchaseOrder = { - supplierNum: 0, - materialNum: 0, - materialNoRmbSum: 0, - materialRmbSum: 0, - purchaseOrderChildList: [] + supplierNum: 0,materialNum: 0,materialNoRmbSum: 0,materialRmbSum: 0, + stockNo: $("#stockNo").val(), + stockName: $("#stockName").val(), + stockAddress: $("#stockAddress").val(), + stockContact: $("#stockContact").val(), + stockPhone: $("#stockPhone").val(), + purchaseOrderChildList: [], }; - // 遍历每个物料容器 $('.table-materialCode').each(function(index, tableElement) { var tableId = tableIdList[index]; @@ -306,7 +356,6 @@ if (typeof materialObj === 'undefined') return; $('#' + 'material-' + tableId).find('.supplier-card').each(function(supplierIndex, supplierCard) { var materialData = { - purchasePlanCode: materialObj.purchasePlanCode, materialCode: materialObj.materialCode, materialName: materialObj.materialName, materialType: materialObj.materialType, @@ -319,9 +368,12 @@ materialNoRmb: parseFloat($(supplierCard).find('.supplierMaterialNoRmb').text().trim()), materialRmb: parseFloat($(supplierCard).find('.supplierMaterialRmb').text().trim()), materialNum: parseInt($(supplierCard).find('.supplierMaterialNum').val(), 10) || 0, - deliveryTime: $(supplierCard).find('.supplierDeliveryTime').val() + deliveryTime: $(supplierCard).find('.supplierDeliveryTime').val(), + purchasePlanCode:$(supplierCard).find('.supplierPurchasePlanCode').text().trim(), + correlationCode:$(supplierCard).find('.supplierCorrelationCode').text().trim(), + purchaseQuoteCode: $(supplierCard).find('.supplierPurchaseQuoteCode').text().trim(), }; - purchaseOrder.purchaseQuoteChildList.push(materialData); + purchaseOrder.purchaseOrderChildList.push(materialData); }); }); @@ -340,7 +392,7 @@ // 发送数据到后端API $.ajax({ type: "POST", - url: prefix + "/add", + url: prefix + "/addPurchaseOrder", data: JSON.stringify(purchaseOrder), contentType: "application/json; charset=utf-8", dataType: "json", @@ -360,6 +412,39 @@ // 如果需要在页面加载时初始化合计或重新绑定事件处理器,这部分应放在更合适的位置,不在此函数内 } } + //获取仓库相关信息 + function getWarehouseInfo() { + $("#inputWarehouseID").select2({ + theme: "bootstrap", + allowClear: true, + placeholder: "请选择供应商", + ajax: { + url: ctx + "stock/stockInfo/list", + type: "post", + dataType: "json", + delay: 250, + processResults: function (res, params) { + var resultList = res.rows; + var options = []; + for (let i in resultList) { + var option = resultList[i]; + option.id = resultList[i]["StockNo"]; + option.text = resultList[i]["StockNo"]; + option.title = resultList[i]["StockName"]; + options.push(option); + } + return {results: options,} + }, + escapeMarkup: function (markup) {return markup;}, + } + }) + $("#inputWarehouseID").on("select2:select", function (e) { + var data = e.params.data; + $("#inputWarehouseName").val(data.StockName); + $("#inputReceiver").val(data.stockmanager); + $("#inputAddressDetails").val(data.stockAddr); + }); +} \ No newline at end of file