diff --git a/ruoyi-admin/src/main/java/com/ruoyi/purchase/controller/PurchaseOrderController.java b/ruoyi-admin/src/main/java/com/ruoyi/purchase/controller/PurchaseOrderController.java index 85c66db2..cdbefe30 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/purchase/controller/PurchaseOrderController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/purchase/controller/PurchaseOrderController.java @@ -13,10 +13,13 @@ import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.page.TableDataInfo; +import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.purchase.domain.PurchaseMaterial; import com.ruoyi.purchase.domain.PurchaseOrder; +import com.ruoyi.purchase.domain.PurchaseOrderChild; +import com.ruoyi.purchase.domain.PurchaseQuoteChild; import com.ruoyi.purchase.domain.exportDto.PurchaseMaterialDto; import com.ruoyi.purchase.domain.exportDto.PurchaseOrderDto; import com.ruoyi.purchase.service.IPurchaseMaterialService; @@ -32,6 +35,7 @@ import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.math.BigDecimal; import java.util.*; import static com.ruoyi.common.config.datasource.DynamicDataSourceContextHolder.log; @@ -53,6 +57,9 @@ public class PurchaseOrderController extends BaseController @Autowired private IPurchaseMaterialService purchaseMaterialService; + @Autowired + private RedisCache redisCache; + @RequiresPermissions("purchase:purchaseOrder:view") @GetMapping() public String purchaseOrder() @@ -103,8 +110,40 @@ public class PurchaseOrderController extends BaseController @Log(title = "采购订单", businessType = BusinessType.INSERT) @PostMapping("/add") @ResponseBody - public AjaxResult addSave(PurchaseOrder purchaseOrder) - { + public AjaxResult addSave(@RequestBody PurchaseOrder purchaseOrder) throws Exception{ + //获取采购订单子表中的供应商,核算供应商数量和采购物料合计以及采购数量合计,采购不含税报价合计,采购含税报价合计 + List purchaseMaterials = purchaseOrder.getPurchaseOrderChildList(); + purchaseOrder.setPurchaseOrderCode(redisCache.generateBillNo("CG")); + BigDecimal materialNoRmb = BigDecimal.valueOf(0.0); + BigDecimal materialRmb = BigDecimal.valueOf(0.0); + BigDecimal materialNoRmbSum = BigDecimal.valueOf(0.0); + BigDecimal materialRmbSum = BigDecimal.valueOf(0.0); + BigDecimal materialSum = BigDecimal.valueOf(0.0); + Long materialNum = 0L; + Long supplierNum = 0L; + for (PurchaseOrderChild purchaseOrderChild : purchaseMaterials) { + purchaseOrderChild.setPurchaseOrderCode(purchaseOrder.getPurchaseOrderCode()); + for (PurchaseQuoteChild purchaseSupplierQuote : purchaseOrderChild.getPurchaseQuoteChildList()){ + BigDecimal suplierMaterialNoRmb = purchaseSupplierQuote.getMaterialNoRmb(); + BigDecimal suplierMaterialRmb = purchaseSupplierQuote.getMaterialRmb(); + Long suplierMaterialNum = purchaseSupplierQuote.getMaterialNum(); + BigDecimal suplierMaterialNoRmbSum = suplierMaterialNoRmb.multiply(BigDecimal.valueOf(suplierMaterialNum)); + BigDecimal suplierMaterialRmbSum = suplierMaterialRmb.multiply(BigDecimal.valueOf(suplierMaterialNum)); + materialNum = materialNum + suplierMaterialNum; + materialNoRmb = materialNoRmb.add(purchaseSupplierQuote.getMaterialNoRmb()); + materialRmb = materialRmb.add(purchaseSupplierQuote.getMaterialRmb()); + materialRmbSum = materialRmbSum.add(suplierMaterialRmbSum); + materialNoRmbSum = materialNoRmbSum.add(suplierMaterialNoRmbSum); + purchaseSupplierQuote.setPurchaseQuoteCode(purchaseOrder.getPurchaseOrderCode()); + if (purchaseSupplierQuote.getSupplierCode() != null){ + supplierNum ++; + } + } + purchaseOrderChild.setMaterialNormb(materialNoRmb); + purchaseOrderChild.setMaterialRmb(materialRmb); + purchaseOrderChild.setMaterialNum(materialNum); + } + purchaseOrder.setSupplierNum(Math.toIntExact(supplierNum)); return toAjax(purchaseOrderService.insertPurchaseOrder(purchaseOrder)); } 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 4ba47ae1..3ec562d4 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 @@ -2,6 +2,7 @@ package com.ruoyi.purchase.controller; import java.util.Arrays; import java.util.List; +import java.util.Set; import com.ruoyi.common.core.text.Convert; import com.ruoyi.purchase.domain.PurchasePlan; @@ -114,22 +115,21 @@ public class PurchasePlanController extends BaseController @GetMapping("/addPurchaseOrder/{purchasePlanCodes}") public String purChaseOrder(@PathVariable("purchasePlanCodes") String purchasePlanCodes,ModelMap mmap){ //purchasePlanCodes去除重复数据,purchasePlanCodeArray作为数组类型去除 - String purchasePlanCode = purchasePlanCodes; + + // 直接使用String的split方法分割字符串,然后转为Stream去重,最后再拼接回字符串 String[] purchasePlanCodeArray = purchasePlanCodes.split(","); - purchasePlanCodes = Arrays.toString(Arrays.stream(purchasePlanCodeArray).distinct().toArray()); + String uniquePurchasePlanCodes = String.join(",", Arrays.stream(purchasePlanCodeArray).distinct().toArray(String[]::new)); //查询相关采购计划数据 - List purchasePlanList = purchasePlanService.selectPurchasePlanByPlanCode(purchasePlanCode); + List purchasePlanList = purchasePlanService.selectPurchasePlanByPlanCode(uniquePurchasePlanCodes); //根据采购计划编号查询对应的采购报价数据 - List purchasePlanChildList = purchasePlanChildService.getPurchasePlanChildByPlanCodes(purchasePlanCode); + List purchasePlanChildList = purchasePlanChildService.getPurchasePlanChildByPlanCodes(uniquePurchasePlanCodes); + //再根据采购计划编号分组查询对应的采购报价数据分组 for(PurchasePlanChild purchasePlanChild : purchasePlanChildList){ - List purchaseQuoteChildList = purchasePlanChild.getPurchaseQuoteChildList(); + purchasePlanChild.setPurchaseSupplierList(purchasePlanChild.parseSupplierMaterialCombinations(purchasePlanChild.getSupplierCodes())); } - //再根据采购计划编号分组查询对应的采购报价数据分组 - - purchasePlanCodes = purchasePlanCodes.replace("[","").replace("]",""); //查询物料报价中供应商 mmap.put("purchasePlanList", purchasePlanList); - mmap.put("purchasePlanCodes", purchasePlanCodes); + mmap.put("purchasePlanCodes", uniquePurchasePlanCodes); mmap.put("purchasePlanChildList", purchasePlanChildList); return prefix + "/addPurchaseOrder"; } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/purchase/domain/PurchaseOrder.java b/ruoyi-admin/src/main/java/com/ruoyi/purchase/domain/PurchaseOrder.java index 393abf2f..1ec203d4 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/purchase/domain/PurchaseOrder.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/purchase/domain/PurchaseOrder.java @@ -5,6 +5,8 @@ import org.apache.commons.lang3.builder.ToStringStyle; import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.core.domain.BaseEntity; +import java.util.List; + /** * 采购订单对象 purchase_order * @@ -177,6 +179,16 @@ public class PurchaseOrder extends BaseEntity /** 备用二 */ private String standbyTwo; + private List purchaseOrderChildList; + + public List getPurchaseOrderChildList() { + return purchaseOrderChildList; + } + + public void setPurchaseOrderChildList(List purchaseOrderChildList) { + this.purchaseOrderChildList = purchaseOrderChildList; + } + public Long getPurchaseOrderId() { return purchaseOrderId; } 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 d6c0bcf3..0f3012a5 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 @@ -1,6 +1,8 @@ package com.ruoyi.purchase.domain; import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.apache.commons.lang3.builder.ToStringBuilder; @@ -17,6 +19,7 @@ import com.ruoyi.common.core.domain.BaseEntity; public class PurchasePlanChild extends BaseEntity { private static final long serialVersionUID = 1L; + public List parseSupplierMaterialCombinations; /** 采购计划物料清单索引 */ private Long purchasePlanChildId; @@ -83,10 +86,30 @@ public class PurchasePlanChild extends BaseEntity /** 删除标志 */ private String delFlag; + /** 关联供应商编号 */ + private String supplierCodes; + /** 关联采购报价单编号 */ + private String correlationCodes; - private List purchaseQuoteChildList; + private List purchaseSupplierList; - public void setPurchasePlanChildId(Long purchasePlanChildId) + public String getSupplierCodes() { + return supplierCodes; + } + + public void setSupplierCodes(String supplierCodes) { + this.supplierCodes = supplierCodes; + } + + public String getCorrelationCodes() { + return correlationCodes; + } + + public void setCorrelationCodes(String correlationCodes) { + this.correlationCodes = correlationCodes; + } + + public void setPurchasePlanChildId(Long purchasePlanChildId) { this.purchasePlanChildId = purchasePlanChildId; } @@ -233,12 +256,12 @@ public class PurchasePlanChild extends BaseEntity this.supplierName = supplierName; } - public List getPurchaseQuoteChildList() { - return purchaseQuoteChildList; + public List getPurchaseSupplierList() { + return purchaseSupplierList; } - public void setPurchaseQuoteChildList(List purchaseQuoteChildList) { - this.purchaseQuoteChildList = purchaseQuoteChildList; + public void setPurchaseSupplierList(List purchaseSupplierList) { + this.purchaseSupplierList = purchaseSupplierList; } public String getUseStatus() @@ -264,6 +287,31 @@ public class PurchasePlanChild extends BaseEntity return delFlag; } + public List parseSupplierMaterialCombinations(String combinations) { + if (combinations == null || combinations.isEmpty()) { + return Collections.emptyList(); + } + //materialCode|purchaseQuoteCode|supplierCode|supplierName|materialName|materialNoRmb|materialRmb + /* 1. 料号 | 2. 供应商报价编号 | 3. 供应商编号 | 4.供应商名称 | 5. 物料名称 | 6. 物料含税单价(RMB) | 7. 物料不含税单价(RMB) */ + 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]); + purchaseQuoteChild.setSupplierCode(split1[2]); + purchaseQuoteChild.setSupplierName(split1[3]); + purchaseQuoteChild.setMaterialName(split1[4]); + purchaseQuoteChild.setMaterialNoRmb(BigDecimal.valueOf(Float.parseFloat(split1[5]))); + purchaseQuoteChild.setMaterialRmb(BigDecimal.valueOf(Float.parseFloat(split1[6]))); + purchaseSupplierList.add(purchaseQuoteChild); + } + return purchaseSupplierList; + } @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/purchase/service/impl/PurchaseOrderServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/purchase/service/impl/PurchaseOrderServiceImpl.java index 57adf4c4..dbdf08e3 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/purchase/service/impl/PurchaseOrderServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/purchase/service/impl/PurchaseOrderServiceImpl.java @@ -59,6 +59,8 @@ public class PurchaseOrderServiceImpl implements IPurchaseOrderService @Override public int insertPurchaseOrder(PurchaseOrder purchaseOrder) { + //根据上传的物料信息做采购订单子项 + // return purchaseOrderMapper.insertPurchaseOrder(purchaseOrder); } diff --git a/ruoyi-admin/src/main/resources/mapper/purchase/PurchasePlanChildMapper.xml b/ruoyi-admin/src/main/resources/mapper/purchase/PurchasePlanChildMapper.xml index 29c4e5cc..7e798987 100644 --- a/ruoyi-admin/src/main/resources/mapper/purchase/PurchasePlanChildMapper.xml +++ b/ruoyi-admin/src/main/resources/mapper/purchase/PurchasePlanChildMapper.xml @@ -19,6 +19,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + @@ -164,31 +166,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" \ No newline at end of file diff --git a/ruoyi-admin/src/main/resources/templates/purchase/purchasePlan/purchasePlan.html b/ruoyi-admin/src/main/resources/templates/purchase/purchasePlan/purchasePlan.html index 073ea231..13fcbaeb 100644 --- a/ruoyi-admin/src/main/resources/templates/purchase/purchasePlan/purchasePlan.html +++ b/ruoyi-admin/src/main/resources/templates/purchase/purchasePlan/purchasePlan.html @@ -171,14 +171,13 @@ //·拼接采购计划单号 for(var i=0;i