diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/controller/SysSalesOrderController.java b/ruoyi-admin/src/main/java/com/ruoyi/system/controller/SysSalesOrderController.java index 70b4adb4..3e11d0bd 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/controller/SysSalesOrderController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/controller/SysSalesOrderController.java @@ -556,9 +556,11 @@ public class SysSalesOrderController extends BaseController public String deliverGoods(@RequestParam List salesOrderIds, ModelMap mmap) { List salesOrders = sysSalesOrderService.selectBatchSalesOrderById(salesOrderIds); + List salesOrderIdList = salesOrders.stream().map(sysSalesOrder -> sysSalesOrder.getSalesOrderId()).collect(Collectors.toList()); SysSalesOrder sysSalesOrder = salesOrders.get(0); mmap.put("salesOrders", salesOrders); mmap.put("sysSalesOrder", sysSalesOrder); + mmap.put("salesOrderIdList", salesOrderIdList); return prefix + "/salesDeliverGoods"; } @@ -582,8 +584,9 @@ public class SysSalesOrderController extends BaseController @RequestMapping("/salesDeliverGoodsDetailList") public TableDataInfo storageMakeDetailList(SysSalesOrder sysSalesOrder){ startPage(); - String salesOrderCode = sysSalesOrder.getSalesOrderCode(); - List list = sysSalesOrderChildService.selectOrderChildListBySalesOrderCode(salesOrderCode); + List salesOrderIdList = sysSalesOrder.getSalesOrderIdList(); + List list = sysSalesOrderChildService.selectSalesDeliverGoodsDetailList(salesOrderIdList); + //List list = sysSalesOrderChildService.selectOrderChildListBySalesOrderCode(salesOrderCode); return getDataTable(list) ; } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/domain/SysSalesOrder.java b/ruoyi-admin/src/main/java/com/ruoyi/system/domain/SysSalesOrder.java index 82b8d3c4..03043a8b 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/domain/SysSalesOrder.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/domain/SysSalesOrder.java @@ -202,6 +202,10 @@ public class SysSalesOrder extends BaseEntity { private List selectAftersalesNoticeVOList; + //用于出货的销售订单id集合 + + private List salesOrderIdList; + //销售子表物料号 private String materialCode; @@ -778,6 +782,15 @@ public class SysSalesOrder extends BaseEntity { this.materialName = materialName; } + + public List getSalesOrderIdList() { + return salesOrderIdList; + } + + public void setSalesOrderIdList(List salesOrderIdList) { + this.salesOrderIdList = salesOrderIdList; + } + @Override public String toString() { return Objects.toStringHelper(this) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/domain/SysSalesOrderChild.java b/ruoyi-admin/src/main/java/com/ruoyi/system/domain/SysSalesOrderChild.java index 511c3d22..e733c2e0 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/domain/SysSalesOrderChild.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/domain/SysSalesOrderChild.java @@ -1,11 +1,13 @@ package com.ruoyi.system.domain; +import com.fasterxml.jackson.annotation.JsonFormat; import com.google.common.base.Objects; import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.annotation.FieldCompare; import com.ruoyi.common.core.domain.BaseEntity; import java.math.BigDecimal; +import java.util.Date; /** * 销售订单对象 sys_sales_order @@ -138,7 +140,8 @@ public class SysSalesOrderChild extends BaseEntity { private Double materialRmbSum; @Excel(name = "计划交付时间") - private String deliveryTime; + @JsonFormat(pattern = "yyyy-MM-dd") + private Date deliveryTime; @Excel(name = "质保天数") private String expiryDay; /*业务人员*/ @@ -427,11 +430,11 @@ public class SysSalesOrderChild extends BaseEntity { this.materialRmbSum = materialRmbSum; } - public String getDeliveryTime() { + public Date getDeliveryTime() { return deliveryTime; } - public void setDeliveryTime(String deliveryTime) { + public void setDeliveryTime(Date deliveryTime) { this.deliveryTime = deliveryTime; } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/domain/Vo/ExportSalesOrderChildVo.java b/ruoyi-admin/src/main/java/com/ruoyi/system/domain/Vo/ExportSalesOrderChildVo.java index c0033332..14d96bcc 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/domain/Vo/ExportSalesOrderChildVo.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/domain/Vo/ExportSalesOrderChildVo.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import java.math.BigDecimal; +import java.util.Date; /** * 导出销售订单子表模板类 @@ -64,6 +65,6 @@ public class ExportSalesOrderChildVo { /** 计划交付时间 */ @JsonFormat(pattern = "yyyy-MM-dd") - private String deliveryTime; + private Date deliveryTime; } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/mapper/SysSalesOrderChildMapper.java b/ruoyi-admin/src/main/java/com/ruoyi/system/mapper/SysSalesOrderChildMapper.java index 67bb853f..5e549a29 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/mapper/SysSalesOrderChildMapper.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/mapper/SysSalesOrderChildMapper.java @@ -57,4 +57,9 @@ public interface SysSalesOrderChildMapper { * 检查销售订单子表是否引用了物料 * */ int checkMaterialIsReferencedBySalesOrderChild(String materialNo); + + /** + * 通过销售订单号批量查询销售订单子表 + * */ + List selectBatchOrderChildListBySalesOrderCode(List salesOrderCodeList); } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/service/ISysSalesOrderChildService.java b/ruoyi-admin/src/main/java/com/ruoyi/system/service/ISysSalesOrderChildService.java index 49fcebe3..03138843 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/service/ISysSalesOrderChildService.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/service/ISysSalesOrderChildService.java @@ -36,4 +36,9 @@ public interface ISysSalesOrderChildService { * @return */ Integer deleteSysSalesOrderChildByQuoteId(String salesOrderCode); + + /** + * 销售出货物料列表展示 + */ + List selectSalesDeliverGoodsDetailList(List salesOrderIdList); } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/service/ISysSalesShippingInformService.java b/ruoyi-admin/src/main/java/com/ruoyi/system/service/ISysSalesShippingInformService.java index 75e213db..85263a59 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/service/ISysSalesShippingInformService.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/service/ISysSalesShippingInformService.java @@ -81,7 +81,7 @@ public interface ISysSalesShippingInformService /** * 通过销售发起出货生成销售出货通知单列表 * */ - int generateShippingInformBySalesOrder(SysSalesOrder sysSalesOrder, String outOrderCode); + int generateShippingInformBySalesOrder(SysSalesOrder sysSalesOrder, String outOrderCode,List salesOrderIdList); /** diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysSalesOrderChildServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysSalesOrderChildServiceImpl.java index 6dcb85f5..f92a9f74 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysSalesOrderChildServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysSalesOrderChildServiceImpl.java @@ -1,29 +1,41 @@ package com.ruoyi.system.service.impl; +import com.ruoyi.system.domain.SysSalesOrder; import com.ruoyi.system.domain.SysSalesOrderChild; import com.ruoyi.system.mapper.SysSalesOrderChildMapper; import com.ruoyi.system.service.ISysSalesOrderChildService; +import com.ruoyi.system.service.ISysSalesOrderService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; @Service public class SysSalesOrderChildServiceImpl implements ISysSalesOrderChildService { @Autowired private SysSalesOrderChildMapper sysCustomerQuoteChildMapper; + + @Autowired + private ISysSalesOrderService sysSalesOrderService; + + @Override - public List selectSysSalesOrderChildList (SysSalesOrderChild sysCustomerQuoteChild) { + public List selectSysSalesOrderChildList(SysSalesOrderChild sysCustomerQuoteChild) { List sysSalesOrderChildren = sysCustomerQuoteChildMapper.selectSysSalesOrderChildList(sysCustomerQuoteChild); return sysSalesOrderChildren; } + @Override - public List selectSysSalesOrderChildListAll (SysSalesOrderChild sysCustomerQuoteChild) { + public List selectSysSalesOrderChildListAll(SysSalesOrderChild sysCustomerQuoteChild) { return sysCustomerQuoteChildMapper.selectSysSalesOrderChildListAll(sysCustomerQuoteChild); } + @Override public int insertSysSalesOrderChild(SysSalesOrderChild sysCustomerQuoteChild) { return sysCustomerQuoteChildMapper.insertSysSalesOrderChild(sysCustomerQuoteChild); @@ -56,7 +68,7 @@ public class SysSalesOrderChildServiceImpl implements ISysSalesOrderChildService @Override public SysSalesOrderChild selectOneByQuoteIdAndMaterialCode(String quoteId, String materialCode) { - return sysCustomerQuoteChildMapper.selectOneByQuoteIdAndMaterialCode(quoteId,materialCode); + return sysCustomerQuoteChildMapper.selectOneByQuoteIdAndMaterialCode(quoteId, materialCode); } /* @@ -72,4 +84,50 @@ public class SysSalesOrderChildServiceImpl implements ISysSalesOrderChildService public Integer deleteSysSalesOrderChildByQuoteId(String salesOrderCode) { return sysCustomerQuoteChildMapper.deleteSysSalesOrderChildByQuoteId(salesOrderCode); } + + /** + * 销售出货物料列表展示 + */ + @Override + public List selectSalesDeliverGoodsDetailList(List salesOrderIdList) { + List sysSalesOrders = sysSalesOrderService.selectBatchSalesOrderById(salesOrderIdList); + List salesOrderCodeList = sysSalesOrders.stream() + .map(SysSalesOrder::getSalesOrderCode) + .collect(Collectors.toList()); + + List list = sysCustomerQuoteChildMapper.selectBatchOrderChildListBySalesOrderCode(salesOrderCodeList); + + // 合并相同物料料号的数据 + Map mergedMap = list.stream() + .collect(Collectors.toMap( + SysSalesOrderChild::getMaterialCode, + item -> item, + (existingItem, newItem) -> { + existingItem.setMaterialNum( + (existingItem.getMaterialNum() != null ? existingItem.getMaterialNum() : 0) + + (newItem.getMaterialNum() != null ? newItem.getMaterialNum() : 0) + ); + existingItem.setFinishNum( + (existingItem.getFinishNum() != null ? existingItem.getFinishNum() : 0) + + (newItem.getFinishNum() != null ? newItem.getFinishNum() : 0) + ); + existingItem.setHasApplyShippingNum( + (existingItem.getHasApplyShippingNum() != null ? existingItem.getHasApplyShippingNum() : 0) + + (newItem.getHasApplyShippingNum() != null ? newItem.getHasApplyShippingNum() : 0) + ); + existingItem.setOutBoundQuantity( + (existingItem.getOutBoundQuantity() != null ? existingItem.getOutBoundQuantity() : 0) + + (newItem.getOutBoundQuantity() != null ? newItem.getOutBoundQuantity() : 0) + ); + return existingItem; + } + )); + + // 将合并后的数据转换为列表 + List mergedList = new ArrayList<>(mergedMap.values()); + + return mergedList; + } } + + diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysSalesOrderServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysSalesOrderServiceImpl.java index ae74a4c0..e09653eb 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysSalesOrderServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysSalesOrderServiceImpl.java @@ -305,6 +305,11 @@ public class SysSalesOrderServiceImpl implements ISysSalesOrderService if (s == 0){ return 0; } + List sysSalesOrderChildList = sysSalesOrder.getSysSalesOrderChildList(); + + // 校验子表数据 + checkSysSalesOrderChildList(sysSalesOrderChildList); + for (int i = 0; i < s ;i++) { SysSalesOrderChild sysSalesOrderChild = sysSalesOrder.getSysSalesOrderChildList().get(i); sysSalesOrderChild.setQuoteId(sysSalesOrder.getSalesOrderCode()); @@ -315,6 +320,31 @@ public class SysSalesOrderServiceImpl implements ISysSalesOrderService } + //自定义校验 + private void checkSysSalesOrderChildList(List sysSalesOrderChildList) { + // 检查物料数量是否为空 + boolean anyMaterialNum = sysSalesOrderChildList.stream() + .anyMatch(sysSalesOrderChild -> sysSalesOrderChild.getMaterialNum() == null); + if (anyMaterialNum) { + throw new BusinessException("物料数量不能为空"); + } + + // 检查计划交付时间是否为空 + boolean anyDeliveryTime = sysSalesOrderChildList.stream() + .anyMatch(sysSalesOrderChild -> sysSalesOrderChild.getDeliveryTime() == null); + if (anyDeliveryTime) { + throw new BusinessException("计划交付时间不能为空"); + } + + // 检查质保天数是否为空 + boolean anyExpiryDay = sysSalesOrderChildList.stream() + .anyMatch(sysSalesOrderChild -> sysSalesOrderChild.getExpiryDay() == null); + if (anyExpiryDay) { + throw new BusinessException("质保天数不能为空"); + } + } + + /** * 修改销售订单 * @@ -493,22 +523,62 @@ public class SysSalesOrderServiceImpl implements ISysSalesOrderService List sysSalesOrderChildList = sysSalesOrder.getSysSalesOrderChildList(); + //过滤掉申请出货数为0的数据,也就是本次不发起出货 + sysSalesOrderChildList = sysSalesOrderChildList.stream().filter(sysSalesOrderChild -> sysSalesOrderChild.getApplyShippingNum() != 0 ).collect(Collectors.toList()); + + List salesOrderIdList = sysSalesOrder.getSalesOrderIdList(); + + List sysSalesOrders = sysSalesOrderMapper.selectBatchSalesOrderById(salesOrderIdList); + List collectSalesOrderCode = sysSalesOrders.stream().map(SysSalesOrder::getSalesOrderCode).collect(Collectors.toList()); + List oldSalesOrderChildList = salesOrderChildMapper.selectBatchOrderChildListBySalesOrderCode(collectSalesOrderCode); + //如果子表中有申请出货数为空的数据,不能提交保存 boolean applyShippingNumHasNull = sysSalesOrderChildList.stream().anyMatch(sysSalesOrderChild -> sysSalesOrderChild.getApplyShippingNum() == null); if (applyShippingNumHasNull){ throw new BusinessException("申请出货数不能为空,请检查"); } + // 将旧数据按物料编号分组 + Map> oldDataGroupedByMaterialCode = oldSalesOrderChildList.stream() + .collect(Collectors.groupingBy(SysSalesOrderChild::getMaterialCode)); + + // 当前时间 + Date now = new Date(); + for (SysSalesOrderChild sysSalesOrderChild : sysSalesOrderChildList) { + String materialCode = sysSalesOrderChild.getMaterialCode(); + Integer applyShippingNum = sysSalesOrderChild.getApplyShippingNum(); + + // 获取旧数据中相同物料编号的数据 + List oldChildren = oldDataGroupedByMaterialCode.get(materialCode); + + if (oldChildren != null && !oldChildren.isEmpty()) { + // 按照 deliveryTime 接近当前时间排序 + oldChildren.sort(Comparator.comparing(oldChild -> Math.abs(now.getTime() - oldChild.getDeliveryTime().getTime()))); - sysSalesOrderChild.setUpdateTime(new Date()); - sysSalesOrderChild.setUpdateBy(loginName); - sysSalesOrderChild.setQuoteId(sysSalesOrder.getSalesOrderCode()); - sysSalesOrderChild.setHasApplyShippingNum(sysSalesOrderChild.getApplyShippingNum()); - int updateSysSalesOrderChildResult = salesOrderChildMapper.updateSysSalesOrderChildByCodeAndQuoteId(sysSalesOrderChild); - if (updateSysSalesOrderChildResult <= 0){ - throw new BusinessException("更新销售订单子表数据失败"); + for (SysSalesOrderChild oldChild : oldChildren) { + Integer hasApplyShippingNum = oldChild.getHasApplyShippingNum(); + if (hasApplyShippingNum == null) { + hasApplyShippingNum = 0; // 确保 hasApplyShippingNum 不为 null + } + + // 计算新的已申请出货数 + hasApplyShippingNum += applyShippingNum; + oldChild.setHasApplyShippingNum(hasApplyShippingNum); + oldChild.setUpdateTime(new Date()); + oldChild.setUpdateBy(loginName); + oldChild.setQuoteId(sysSalesOrder.getSalesOrderCode()); + + // 更新数据库 + int updateSysSalesOrderChildResult = salesOrderChildMapper.updateSysSalesOrderChild(oldChild); + if (updateSysSalesOrderChildResult <= 0) { + throw new BusinessException("更新销售订单子表数据失败"); + } + + // 更新完成后,跳出循环 + break; + } } } @@ -516,10 +586,10 @@ public class SysSalesOrderServiceImpl implements ISysSalesOrderService //两个表生成同一个出库单号 String outOrderCode = redisCache.generateBillNo("CK"); //通过销售发起出货生成仓库出库单 - int insertWarehouseOutOrderResult = warehouseOutOrderService.generateWarehouseOutOrderBySalesOrder(sysSalesOrder,outOrderCode); + int insertWarehouseOutOrderResult = warehouseOutOrderService.generateWarehouseOutOrderBySalesOrder(sysSalesOrder,outOrderCode,salesOrderIdList); //通过销售发起出货生成销售出货通知单列表 - int insertShippingInformResult = sysSalesShippingInformService.generateShippingInformBySalesOrder(sysSalesOrder,outOrderCode); + int insertShippingInformResult = sysSalesShippingInformService.generateShippingInformBySalesOrder(sysSalesOrder,outOrderCode,salesOrderIdList); return sysSalesOrderMapper.updateSysSalesOrderBySalesOrderCode(sysSalesOrder); } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysSalesShippingInformServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysSalesShippingInformServiceImpl.java index da6a3128..bded2fda 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysSalesShippingInformServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysSalesShippingInformServiceImpl.java @@ -6,6 +6,7 @@ import java.net.URLEncoder; import java.text.SimpleDateFormat; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; import com.alibaba.excel.EasyExcel; import com.alibaba.excel.ExcelWriter; @@ -185,48 +186,74 @@ public class SysSalesShippingInformServiceImpl implements ISysSalesShippingInfor * 通过销售发起出货生成销售出货通知单列表 * */ @Override - public int generateShippingInformBySalesOrder(SysSalesOrder sysSalesOrder,String outOrderCode) { + public int generateShippingInformBySalesOrder(SysSalesOrder sysSalesOrder,String outOrderCode,List salesOrderIdList) { String loginName = ShiroUtils.getLoginName(); SysSalesShippingInform sysSalesShippingInform = new SysSalesShippingInform(); - String salesOrderCode = sysSalesOrder.getSalesOrderCode(); - if (StringUtils.isEmpty(salesOrderCode)){ - log.warn("销售订单编号为空:{}",salesOrderCode); - } +// String salesOrderCode = sysSalesOrder.getSalesOrderCode(); +// if (StringUtils.isEmpty(salesOrderCode)){ +// log.warn("销售订单编号为空:{}",salesOrderCode); +// } //从数据库查询的数据 - SysSalesOrderVo sysSalesOrderVo = sysSalesOrderMapper.selectSysSalesOrderBySalesOrderCode(salesOrderCode); +// SysSalesOrderVo sysSalesOrderVo = sysSalesOrderMapper.selectSysSalesOrderBySalesOrderCode(salesOrderCode); + + List sysSalesOrders = sysSalesOrderMapper.selectBatchSalesOrderById(salesOrderIdList); + + + + String salesOrderCodes = getSalesOrderCodes(sysSalesOrders); sysSalesShippingInform.setOutOrderCode(outOrderCode); //出库状态为 待仓库准备物料 sysSalesShippingInform.setWarehouseOutStatus("0"); - sysSalesShippingInform.setSalesOrderCode(salesOrderCode); - //订单类型设置为 销售订单 - sysSalesShippingInform.setWarehouseOrderType("0"); + sysSalesShippingInform.setSalesOrderCode(salesOrderCodes); //出库类型设置为 销售出库 sysSalesShippingInform.setWarehouseOutType("0"); - sysSalesShippingInform.setCustomerId(sysSalesOrderVo.getEnterpriseCode()); - sysSalesShippingInform.setCustomerName(sysSalesOrderVo.getEnterpriseName()); - sysSalesShippingInform.setDeliveryCondition(sysSalesOrderVo.getDeliveryConditions()); + sysSalesShippingInform.setCustomerId(sysSalesOrder.getEnterpriseCode()); + sysSalesShippingInform.setCustomerName(sysSalesOrder.getEnterpriseName()); + sysSalesShippingInform.setDeliveryCondition(sysSalesOrder.getDeliveryConditions()); sysSalesShippingInform.setCreateTime(new Date()); sysSalesShippingInform.setCreateBy(loginName); - sysSalesShippingInform.setAllPriceExcludingTaxDollar(BigDecimal.valueOf(sysSalesOrderVo.getNoUsdSum())); - sysSalesShippingInform.setAllPriceExcludingTaxRmb(BigDecimal.valueOf(sysSalesOrderVo.getNoRmbSum())); - sysSalesShippingInform.setAllPriceIncludesTax(BigDecimal.valueOf(sysSalesOrderVo.getRmbTaxSum())); - //更新物料合计 - sysSalesShippingInform.setMaterialSum(Math.toIntExact(sysSalesOrderVo.getMaterialSum())); - //更新数量合计 - sysSalesShippingInform.setEnterpriseSum(Math.toIntExact(sysSalesOrderVo.getEnterpriseSum())); - - sysSalesShippingInform.setCustomerContact(sysSalesOrderVo.getCustomerDelivery()); - sysSalesShippingInform.setContactNumber(sysSalesOrderVo.getDeliveryPhone()); - sysSalesShippingInform.setCustomerContactAddress(sysSalesOrderVo.getDeliveryAddress()); + sysSalesShippingInform.setBusinessMembers(loginName); + // 计算所有订单的合计金额(美元) + double totalNoUsdSum = sysSalesOrders.stream() + .filter(Objects::nonNull).mapToDouble(SysSalesOrder::getNoUsdSum).sum(); + + // 计算所有订单的合计金额(人民币) + double totalNoRmbSum = sysSalesOrders.stream() + .filter(Objects::nonNull).mapToDouble(SysSalesOrder::getNoRmbSum).sum(); + + // 计算所有订单的含税合计金额(人民币) + double totalRmbTaxSum = sysSalesOrders.stream() + .filter(Objects::nonNull).mapToDouble(SysSalesOrder::getRmbTaxSum).sum(); + + // 计算所有订单的物料合计 + long totalMaterialSum = sysSalesOrders.stream() + .mapToLong(order -> order.getMaterialSum() != null ? order.getMaterialSum() : 0L) + .sum(); + + // 计算所有订单的数量合计 + long totalEnterpriseSum = sysSalesOrders.stream() + .mapToLong(order -> order.getEnterpriseSum() != null ? order.getEnterpriseSum() : 0L) + .sum(); + + // 设置到sysSalesShippingInform对象中 + sysSalesShippingInform.setAllPriceExcludingTaxDollar(BigDecimal.valueOf(totalNoUsdSum)); + sysSalesShippingInform.setAllPriceExcludingTaxRmb(BigDecimal.valueOf(totalNoRmbSum)); + sysSalesShippingInform.setAllPriceIncludesTax(BigDecimal.valueOf(totalRmbTaxSum)); + sysSalesShippingInform.setMaterialSum(Math.toIntExact(totalMaterialSum)); + sysSalesShippingInform.setEnterpriseSum(Math.toIntExact(totalEnterpriseSum)); + + sysSalesShippingInform.setCustomerContact(sysSalesOrder.getCustomerDelivery()); + sysSalesShippingInform.setContactNumber(sysSalesOrder.getDeliveryPhone()); + sysSalesShippingInform.setCustomerContactAddress(sysSalesOrder.getDeliveryAddress()); sysSalesShippingInform.setCustomerContactBillto(sysSalesOrder.getCustomerDeliveryBillto()); sysSalesShippingInform.setContactNumberBillto(sysSalesOrder.getDeliveryPhoneBillto()); sysSalesShippingInform.setContactAddressBillto(sysSalesOrder.getDeliveryAddressBillto()); - //更新销售出库详情数据 + //更新销售出货通知详情数据 List sysSalesOrderChildList = sysSalesOrder.getSysSalesOrderChildList(); for (SysSalesOrderChild sysSalesOrderChild : sysSalesOrderChildList) { SysSalesShippingInformDetail sysSalesShippingInformDetail = new SysSalesShippingInformDetail(); @@ -240,7 +267,15 @@ public class SysSalesShippingInformServiceImpl implements ISysSalesShippingInfor sysSalesShippingInformDetail.setMaterialProcessMethod(sysSalesOrderChild.getProcessMethod()); sysSalesShippingInformDetail.setMakeNum(sysSalesOrderChild.getMaterialNum()); sysSalesShippingInformDetail.setHasOutOrderNum(sysSalesOrderChild.getOutBoundQuantity()); - sysSalesShippingInformDetail.setThisShippingNum(sysSalesOrderChild.getApplyShippingNum()); + //申请出货数 <= 订单数量 + //申请出货数 + Integer applyShippingNum = sysSalesOrderChild.getApplyShippingNum(); + if (applyShippingNum <= sysSalesOrderChild.getMaterialNum()){ + sysSalesShippingInformDetail.setThisShippingNum(applyShippingNum); + }else { + throw new BusinessException("申请出货数不能大于订单数量"); + } + sysSalesShippingInformDetail.setCreateBy(loginName); sysSalesShippingInformDetail.setCreateTime(new Date()); shippingInformDetailMapper.insertSysSalesShippingInformDetail(sysSalesShippingInformDetail); @@ -249,6 +284,24 @@ public class SysSalesShippingInformServiceImpl implements ISysSalesShippingInfor return sysSalesShippingInformMapper.insertSysSalesShippingInform(sysSalesShippingInform); } + + + + //处理多个销售订单发货的单号拼接问题 + private static String getSalesOrderCodes(List sysSalesOrders) { + if (sysSalesOrders == null || sysSalesOrders.isEmpty()) { + return ""; + } + + // 使用Java 8 Stream API收集所有salesOrderCode + String result = sysSalesOrders.stream() + .map(SysSalesOrder::getSalesOrderCode) + .collect(Collectors.joining(",")); + + return result; + } + + /** * 修改保存确认发货 */ diff --git a/ruoyi-admin/src/main/java/com/ruoyi/warehouse/service/IWarehouseOutOrderService.java b/ruoyi-admin/src/main/java/com/ruoyi/warehouse/service/IWarehouseOutOrderService.java index e06517d5..3ea74599 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/warehouse/service/IWarehouseOutOrderService.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/warehouse/service/IWarehouseOutOrderService.java @@ -108,7 +108,7 @@ public interface IWarehouseOutOrderService /** * 通过销售发起出货生成仓库出库单 * */ - int generateWarehouseOutOrderBySalesOrder(SysSalesOrder sysSalesOrder, String outOrderCode); + int generateWarehouseOutOrderBySalesOrder(SysSalesOrder sysSalesOrder, String outOrderCode, List salesOrderIdList); /** * 开发修改单领料审核通过后生产出库单 diff --git a/ruoyi-admin/src/main/java/com/ruoyi/warehouse/service/impl/WarehouseOutOrderServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/warehouse/service/impl/WarehouseOutOrderServiceImpl.java index f87a45a1..0083cfae 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/warehouse/service/impl/WarehouseOutOrderServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/warehouse/service/impl/WarehouseOutOrderServiceImpl.java @@ -742,63 +742,89 @@ public class WarehouseOutOrderServiceImpl implements IWarehouseOutOrderService * 通过销售发起出货生成仓库出库单 * */ @Override - public int generateWarehouseOutOrderBySalesOrder(SysSalesOrder sysSalesOrder,String outOrderCode) { + public int generateWarehouseOutOrderBySalesOrder(SysSalesOrder sysSalesOrder,String outOrderCode,List salesOrderIdList) { - String salesOrderCode = sysSalesOrder.getSalesOrderCode(); - if (StringUtils.isEmpty(salesOrderCode)){ - log.warn("销售订单编号为空:{}",salesOrderCode); - } - //从数据库查询的数据 - SysSalesOrderVo sysSalesOrderVo = sysSalesOrderMapper.selectSysSalesOrderBySalesOrderCode(salesOrderCode); +// String salesOrderCode = sysSalesOrder.getSalesOrderCode(); +// if (StringUtils.isEmpty(salesOrderCode)){ +// log.warn("销售订单编号为空:{}",salesOrderCode); +// } +// //从数据库查询的数据 +// SysSalesOrderVo sysSalesOrderVo = sysSalesOrderMapper.selectSysSalesOrderBySalesOrderCode(salesOrderCode); - WarehouseOutOrder warehouseOutOrder = new WarehouseOutOrder(); - warehouseOutOrder.setOutOrderCode(outOrderCode); - //添加生产单号 - SysMakeOrder makeOrder = sysMakeOrderMapper.selectMakeOrderBySaleNo(salesOrderCode); - if (makeOrder == null){ - log.warn("生产订单编号为空:{}",makeOrder.getMakeNo()); - } + String loginName = ShiroUtils.getLoginName(); + List sysSalesOrders = sysSalesOrderMapper.selectBatchSalesOrderById(salesOrderIdList); - warehouseOutOrder.setDeliveryName(sysSalesOrderVo.getCustomerDelivery()); - warehouseOutOrder.setDeliveryNumber(sysSalesOrderVo.getDeliveryPhone()); - warehouseOutOrder.setDeliveryAddress(sysSalesOrderVo.getDeliveryAddress()); + String salesOrderCodes = getSalesOrderCodes(sysSalesOrders); + + WarehouseOutOrder warehouseOutOrder = new WarehouseOutOrder(); + warehouseOutOrder.setOutOrderCode(outOrderCode); + warehouseOutOrder.setDeliveryName(sysSalesOrder.getCustomerDelivery()); + warehouseOutOrder.setDeliveryNumber(sysSalesOrder.getDeliveryPhone()); + warehouseOutOrder.setDeliveryAddress(sysSalesOrder.getDeliveryAddress()); - warehouseOutOrder.setMakeNo(makeOrder.getMakeNo()); //出库状态为 待仓库准备物料 warehouseOutOrder.setWarehouseOutStatus("0"); - warehouseOutOrder.setRelatedOrderCode(salesOrderCode); - warehouseOutOrder.setSalesOrderCode(salesOrderCode); + warehouseOutOrder.setRelatedOrderCode(salesOrderCodes); +// warehouseOutOrder.setSalesOrderCode(salesOrderCode); //订单类型设置为 销售订单 warehouseOutOrder.setWarehouseOrderType("0"); //出库类型设置为 销售出库 warehouseOutOrder.setWarehouseOutType("0"); + + // 计算所有订单的物料合计 + long totalMaterialSum = sysSalesOrders.stream() + .mapToLong(order -> order.getMaterialSum() != null ? order.getMaterialSum() : 0L) + .sum(); + + // 计算所有订单的企业合计 + long totalEnterpriseSum = sysSalesOrders.stream() + .mapToLong(order -> order.getEnterpriseSum() != null ? order.getEnterpriseSum() : 0L) + .sum(); + + //物料合计 - warehouseOutOrder.setMaterialSum(Math.toIntExact(sysSalesOrderVo.getMaterialSum())); + warehouseOutOrder.setMaterialSum(Math.toIntExact(totalMaterialSum)); //数量合计 - warehouseOutOrder.setEnterpriseSum(Math.toIntExact(sysSalesOrderVo.getEnterpriseSum())); + warehouseOutOrder.setEnterpriseSum(Math.toIntExact(totalEnterpriseSum)); - warehouseOutOrder.setBusinessName(sysSalesOrderVo.getBusinessMembers()); - warehouseOutOrder.setCustomerId(sysSalesOrderVo.getEnterpriseCode()); - warehouseOutOrder.setCustomerName(sysSalesOrderVo.getEnterpriseName()); - warehouseOutOrder.setApplyName(sysSalesOrderVo.getApplyUser()); - warehouseOutOrder.setDeliveryCondition(sysSalesOrderVo.getDeliveryConditions()); + warehouseOutOrder.setBusinessName(loginName); + warehouseOutOrder.setCustomerId(sysSalesOrder.getEnterpriseCode()); + warehouseOutOrder.setCustomerName(sysSalesOrder.getEnterpriseName()); + warehouseOutOrder.setApplyName(sysSalesOrder.getApplyUser()); + warehouseOutOrder.setDeliveryCondition(sysSalesOrder.getDeliveryConditions()); warehouseOutOrder.setCreateTime(new Date()); warehouseOutOrder.setCreateBy(ShiroUtils.getLoginName()); //新增出库单明细 - CreateOutOrderDetailBySalesOrderChildList(sysSalesOrder, salesOrderCode, sysSalesOrderVo, outOrderCode); + CreateOutOrderDetailBySalesOrderChildList(sysSalesOrder,outOrderCode); return warehouseOutOrderMapper.insertWarehouseOutOrder(warehouseOutOrder); } + + //处理多个销售订单发货的单号拼接问题 + private static String getSalesOrderCodes(List sysSalesOrders) { + if (sysSalesOrders == null || sysSalesOrders.isEmpty()) { + return ""; + } + + // 使用Java 8 Stream API收集所有salesOrderCode + String result = sysSalesOrders.stream() + .map(SysSalesOrder::getSalesOrderCode) + .collect(Collectors.joining(",")); + + return result; + } + + //新增出库单明细 - private void CreateOutOrderDetailBySalesOrderChildList(SysSalesOrder sysSalesOrder, String salesOrderCode, SysSalesOrderVo sysSalesOrderVo, String outOrderCode) { + private void CreateOutOrderDetailBySalesOrderChildList(SysSalesOrder sysSalesOrder,String outOrderCode) { List sysSalesOrderChildList = sysSalesOrder.getSysSalesOrderChildList(); for (SysSalesOrderChild sysSalesOrderChild : sysSalesOrderChildList) { WarehouseOutOrderDetail warehouseOutOrderDetail = new WarehouseOutOrderDetail(); warehouseOutOrderDetail.setOutOrderCode(outOrderCode); - warehouseOutOrderDetail.setRelatedOrderCode(salesOrderCode); + warehouseOutOrderDetail.setRelatedOrderCode(sysSalesOrderChild.getQuoteId()); warehouseOutOrderDetail.setMaterialNo(sysSalesOrderChild.getMaterialCode()); warehouseOutOrderDetail.setMaterialName(sysSalesOrderChild.getMaterialName()); warehouseOutOrderDetail.setMaterialType(sysSalesOrderChild.getMaterialType()); @@ -808,9 +834,9 @@ public class WarehouseOutOrderServiceImpl implements IWarehouseOutOrderService warehouseOutOrderDetail.setMaterialProcessMethod(sysSalesOrderChild.getProcessMethod()); warehouseOutOrderDetail.setMakeNum(sysSalesOrderChild.getMaterialNum()); warehouseOutOrderDetail.setApplyOutOrderSum(sysSalesOrderChild.getApplyShippingNum()); - warehouseOutOrderDetail.setCustomerId(sysSalesOrderVo.getEnterpriseCode()); - warehouseOutOrderDetail.setCustomerName(sysSalesOrderVo.getEnterpriseName()); - warehouseOutOrderDetail.setDeliveryCondition(sysSalesOrderVo.getDeliveryConditions()); + warehouseOutOrderDetail.setCustomerId(sysSalesOrder.getEnterpriseCode()); + warehouseOutOrderDetail.setCustomerName(sysSalesOrder.getEnterpriseName()); + warehouseOutOrderDetail.setDeliveryCondition(sysSalesOrder.getDeliveryConditions()); warehouseOutOrderDetail.setCreateTime(new Date()); warehouseOutOrderDetail.setCreateBy(ShiroUtils.getLoginName()); int insertOutOrderDetailResult = outOrderDetailMapper.insertWarehouseOutOrderDetail(warehouseOutOrderDetail); diff --git a/ruoyi-admin/src/main/resources/mapper/system/SysSalesOrderChildMapper.xml b/ruoyi-admin/src/main/resources/mapper/system/SysSalesOrderChildMapper.xml index 8abd7010..92dc2cb7 100644 --- a/ruoyi-admin/src/main/resources/mapper/system/SysSalesOrderChildMapper.xml +++ b/ruoyi-admin/src/main/resources/mapper/system/SysSalesOrderChildMapper.xml @@ -127,6 +127,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select count(1) from sys_sales_order_child where materialCode = #{materialCode} + + insert into sys_sales_order_child diff --git a/ruoyi-admin/src/main/resources/templates/system/salesOrder/add.html b/ruoyi-admin/src/main/resources/templates/system/salesOrder/add.html index 9125e8c1..c1caec02 100644 --- a/ruoyi-admin/src/main/resources/templates/system/salesOrder/add.html +++ b/ruoyi-admin/src/main/resources/templates/system/salesOrder/add.html @@ -447,12 +447,20 @@ { title: '物料的含税单价(美元)',field: 'materialUsd',align: 'center',}, { title: '物料的含税总价(美元)',field: 'materialUsdSum', align: 'center',}, { title: '物料的不含税总价(美元)',field: 'materialNoUsdSum',align: 'center',}, - { title: '计划交付时间',field: 'deliveryTime',align: 'center',editable: {type: 'date',title: '计划交付时间',} }, + { title: '计划交付时间',field: 'deliveryTime',align: 'center', + editable: {type: 'date',title: '计划交付时间', + validate: function(value) { + if (!$.trim(value)) { + return '计划交付时间不能为空'; + } + }, + } + }, {title: '质保天数',align: 'center',field: 'expiryDay', editable: { type: 'text',emptyText: "天数",enabled:true,title: '质保天数', validate: function (value) { //字段验证 - if (!$.trim(value)) {return '不能为空';} + if (!$.trim(value)) {return '质保天数不能为空';} } }, format: function (value, row, index) { return value + "天数";} diff --git a/ruoyi-admin/src/main/resources/templates/system/salesOrder/salesDeliverGoods.html b/ruoyi-admin/src/main/resources/templates/system/salesOrder/salesDeliverGoods.html index cd86f05b..9c973cfd 100644 --- a/ruoyi-admin/src/main/resources/templates/system/salesOrder/salesDeliverGoods.html +++ b/ruoyi-admin/src/main/resources/templates/system/salesOrder/salesDeliverGoods.html @@ -30,8 +30,8 @@
-
- +
+
@@ -119,6 +119,8 @@ var sysSalesOrder = [[${sysSalesOrder}]]; + var salesOrderIdList = [[${salesOrderIdList}]]; + var prefix = ctx + "system/salesOrder"; $("#form-salesDeliverGoods-edit").validate({ focusCleanup: true @@ -139,6 +141,7 @@ // 根据实际字段名调整 return { "id":item.id, + "quoteId": item.quoteId, "materialCode": item.materialCode, "materialName": item.materialName, "materialType": item.materialType, @@ -158,6 +161,7 @@ const combinedData = Object.assign({}, salesOrderData, { sysSalesOrderChildList: materialDataList, + salesOrderIdList: salesOrderIdList }); // 合并表单数据和表格数据 console.log(combinedData) @@ -313,6 +317,11 @@ field: 'id', visible: false }, + { + title: '销售订单号', + field: 'quoteId', + visible: false + }, { title: '料号', field: 'materialCode', @@ -371,7 +380,23 @@ { title: '申请出货数', field: 'applyShippingNum', - editable:true, + editable: { + validate: function(value) { + if ($.trim(value) === '') { + return '申请出货数不能为空'; + } + if (isNaN(value)) { + return '申请出货数不能为空'; + } + if (value < 0) { + return '申请出货数不能为空'; + } + //不能为小数 + if (value % 1 !== 0) { + return '申请出货数不能为空'; + } + }, + }, formatter: function (value, row) { // 检查 row 是否存在 if (!row) { @@ -399,7 +424,7 @@ function queryParams(params) { var curParams = { // 传递参数查询参数 - salesOrderCode: sysSalesOrder.salesOrderCode + salesOrderIdList: salesOrderIdList }; return curParams; }