From c6f9ff4c2de00ebc0f38c68f9964d90dbfe775f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=99=93=E8=BF=AA?= <2596750866@qq.com> Date: Fri, 22 Nov 2024 08:47:48 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=20=E7=94=9F=E4=BA=A7=E7=AE=A1=E7=90=86=20?= =?UTF-8?q?=E7=94=9F=E4=BA=A7=E5=85=A5=E5=BA=93=20=E5=8E=BB=E9=99=A4?= =?UTF-8?q?=E7=94=9F=E4=BA=A7=E5=85=A5=E5=BA=93service=E5=A7=94=E5=86=85?= =?UTF-8?q?=E6=9C=89=E5=85=B3=E6=96=B9=E6=B3=95=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/ErpInboundOrderServiceImpl.java | 246 +++++------------- 1 file changed, 72 insertions(+), 174 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/erp/service/impl/ErpInboundOrderServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/erp/service/impl/ErpInboundOrderServiceImpl.java index a90abb9a..d57d050e 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/erp/service/impl/ErpInboundOrderServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/erp/service/impl/ErpInboundOrderServiceImpl.java @@ -109,112 +109,10 @@ public class ErpInboundOrderServiceImpl implements IErpInboundOrderService /** * 生产订单新增委内加工入库单(先品质) - * - * @param erpInboundOrder 委内加工入库单 - * @return 结果 - */ + */ @Override - @Transactional(rollbackFor = Exception.class) - public int insertErpInboundOrder(ErpInboundOrder erpInboundOrder) - { - - QualityOrder qualityOrder = new QualityOrder(); - String loginName = ShiroUtils.getLoginName(); - erpInboundOrder.setCreateBy(loginName); - erpInboundOrder.setCreateTime(DateUtils.getNowDate()); - // 生成编号,年月日规则 - String qualityOrderCode = redisCache.generateBillNo("PZ"); - qualityOrder.setQualityOrderCode(qualityOrderCode); - //设置关联单号 - qualityOrder.setRelatedOrderCode(erpInboundOrder.getMakeNo()); - //设置为待品质 - qualityOrder.setQualityStatus("0"); - //设置为委内入库 - qualityOrder.setQualityStorageStatus("1"); - //设置订单类型 - qualityOrder.setQualityOrderType("1"); - qualityOrder.setCreateTime(new Date()); - qualityOrder.setCreateBy(loginName); - - - - // 获取所有makeorderBomId对应的SysMakeorderBom对象 - List sysMakeorderBoms = erpInboundOrder.getInboundDetails().stream() - .map(ErpInboundOrderDetail::getMakeorderBomId) - .map(this::getSysMakeorderBomById) - .collect(Collectors.toList()); - - // 筛选加工方式只有委内加工的数据 - List filterSysMakeorderBoms = sysMakeorderBoms.stream() - .filter(sysMakeorderBom -> "1".equals(sysMakeorderBom.getProcessMethod())) - .collect(Collectors.toList()); - - // 创建一个Set来存储filterSysMakeorderBoms中的所有物料号MaterialNo - Set materialNoSet = filterSysMakeorderBoms.stream() - .map(SysMakeorderBom::getMaterialNo) - .collect(Collectors.toSet()); - - // 使用materialNoSet来过滤erpInboundOrder.getInboundDetails() - List filteredErpInboundOrderDetails = erpInboundOrder.getInboundDetails().stream() - .filter(detail -> materialNoSet.contains(detail.getMaterialNo()) && detail.getCurrentNum() != null) - .collect(Collectors.toList()); - - - - // 首先,创建一个Map来收集每个物料号及其对应的加工费单价的列表 - Map> processFeesByMaterialNo = filteredErpInboundOrderDetails.stream() - .collect(Collectors.groupingBy( - ErpInboundOrderDetail::getMaterialNo, // 分组依据:物料号 - Collectors.mapping( - ErpInboundOrderDetail::getProcessFeeUnitPrice, // 映射:从每个细节中获取加工费单价 - Collectors.toList() // 收集:将映射结果收集到List中 - ) - )); - - // 然后,检查是否有任何物料号的加工费单价不一致 - boolean hasInconsistentFees = processFeesByMaterialNo.values().stream() - .anyMatch(prices -> prices.stream().distinct().count() > 1); - - // 如果发现加工费单价不一致,则抛出异常 - if (hasInconsistentFees) { - throw new BusinessException("请保持委内加工费单价一致"); - } - - - -// 计算本次委内完成数合计 - long addCurrentNum = filteredErpInboundOrderDetails.stream() - .mapToLong(ErpInboundOrderDetail::getCurrentNum) // 假设getCurrentNum()返回的是int或long类型 - .sum(); - - // 将long类型的addCurrentNum转换为BigDecimal类型 - BigDecimal bigAddCurrentNum = BigDecimal.valueOf(addCurrentNum); - - // 检查是否存在加工费单价为null的情况 - boolean hasMakeInTotalPriceNull = filteredErpInboundOrderDetails.stream() - .anyMatch(item -> item.getProcessFeeUnitPrice() == null); - - if (hasMakeInTotalPriceNull) { - throw new BusinessException("存在委内加工费为空,请检查!"); - } - - // 确保processFeeUnitPrice不为null,避免NullPointerException - BigDecimal processFeeUnitPrice = filteredErpInboundOrderDetails.get(0).getProcessFeeUnitPrice(); - if (processFeeUnitPrice == null) { - throw new BusinessException("加工费单价未找到,请检查!"); - } - - // 计算委内加工费总价 - BigDecimal makeInTotalPrice = bigAddCurrentNum.multiply(processFeeUnitPrice); - //加入到品质单中 - qualityOrder.setMakeInTotalPrice(makeInTotalPrice); - //添加委内加工品质单详情数据 - addQualityOrderDetail(erpInboundOrder, filteredErpInboundOrderDetails,qualityOrderCode,filterSysMakeorderBoms); - //添加委内加工品质单报告数据 - addQualityOrderReport(filteredErpInboundOrderDetails,qualityOrderCode,filterSysMakeorderBoms); - - //插入品质单 - return qualityOrderMapper.insertQualityOrder(qualityOrder); + public int insertErpInboundOrder(ErpInboundOrder erpInboundOrder) { + return erpInboundOrderMapper.insertErpInboundOrder(erpInboundOrder); } // 提取公共方法 @@ -223,39 +121,39 @@ public class ErpInboundOrderServiceImpl implements IErpInboundOrderService } //添加委内加工品质单报告数据 - private void addQualityOrderReport(List filteredErpInboundOrderDetails,String qualityOrderCode,List sysMakeorderBoms) { -// List inboundDetails = erpInboundOrder.getInboundDetails(); -// if (CollectionUtils.isEmpty(inboundDetails)) { -// throw new BusinessException("委内加工详情数据为空"); +// private void addQualityOrderReport(List filteredErpInboundOrderDetails,String qualityOrderCode,List sysMakeorderBoms) { +//// List inboundDetails = erpInboundOrder.getInboundDetails(); +//// if (CollectionUtils.isEmpty(inboundDetails)) { +//// throw new BusinessException("委内加工详情数据为空"); +//// } +// for (int i = 0; i < filteredErpInboundOrderDetails.size(); i++) { +// ErpInboundOrderDetail inboundDetail = filteredErpInboundOrderDetails.get(i); +// SysMakeorderBom sysMakeorderBom = sysMakeorderBoms.get(i); +// QualityOrderReport qualityOrderReport = new QualityOrderReport(); +// qualityOrderReport.setQualityOrderCode(qualityOrderCode); +// qualityOrderReport.setMaterialNo(sysMakeorderBom.getMaterialNo()); +// +// QualityOrderReport tempQualityOrderReport = qualityOrderReportMapper.selectMakeInOrderReportByNoAndCode(qualityOrderReport); +// if (tempQualityOrderReport != null){ +// qualityOrderReport.setQualityOrderReportId(tempQualityOrderReport.getQualityOrderReportId()); +// Long currentNum = inboundDetail.getCurrentNum(); +//// qualityOrderReport.setMakeInNum((int) (tempQualityOrderReport.getMakeInNum()+currentNum)); +// int updateQualityOrderReportResult = qualityOrderReportMapper.updateQualityOrderReportById(qualityOrderReport); +// if (updateQualityOrderReportResult <= 0){ +// throw new BusinessException("更新品质单报告数据失败"); +// } +// }else { +// qualityOrderReport.setMaterialName(sysMakeorderBom.getMaterialName()); +// //添加委内已完成数 +//// qualityOrderReport.setMakeInNum(Math.toIntExact(inboundDetail.getCurrentNum())); +// qualityOrderReport.setCreateBy(ShiroUtils.getLoginName()); +// qualityOrderReport.setCreateTime(new Date()); +// qualityOrderReportMapper.insertQualityOrderReport(qualityOrderReport); +// } +// +// // } - for (int i = 0; i < filteredErpInboundOrderDetails.size(); i++) { - ErpInboundOrderDetail inboundDetail = filteredErpInboundOrderDetails.get(i); - SysMakeorderBom sysMakeorderBom = sysMakeorderBoms.get(i); - QualityOrderReport qualityOrderReport = new QualityOrderReport(); - qualityOrderReport.setQualityOrderCode(qualityOrderCode); - qualityOrderReport.setMaterialNo(sysMakeorderBom.getMaterialNo()); - - QualityOrderReport tempQualityOrderReport = qualityOrderReportMapper.selectMakeInOrderReportByNoAndCode(qualityOrderReport); - if (tempQualityOrderReport != null){ - qualityOrderReport.setQualityOrderReportId(tempQualityOrderReport.getQualityOrderReportId()); - Long currentNum = inboundDetail.getCurrentNum(); - qualityOrderReport.setMakeInNum((int) (tempQualityOrderReport.getMakeInNum()+currentNum)); - int updateQualityOrderReportResult = qualityOrderReportMapper.updateQualityOrderReportById(qualityOrderReport); - if (updateQualityOrderReportResult <= 0){ - throw new BusinessException("更新品质单报告数据失败"); - } - }else { - qualityOrderReport.setMaterialName(sysMakeorderBom.getMaterialName()); - //添加委内已完成数 - qualityOrderReport.setMakeInNum(Math.toIntExact(inboundDetail.getCurrentNum())); - qualityOrderReport.setCreateBy(ShiroUtils.getLoginName()); - qualityOrderReport.setCreateTime(new Date()); - qualityOrderReportMapper.insertQualityOrderReport(qualityOrderReport); - } - - - } - } +// } //添加委内加工品质单详情数据 private void addQualityOrderDetail(ErpInboundOrder erpInboundOrder,List filteredErpInboundOrderDetails,String qualityOrderCode,List sysMakeorderBoms) { @@ -263,43 +161,43 @@ public class ErpInboundOrderServiceImpl implements IErpInboundOrderService // if (CollectionUtils.isEmpty(inboundDetails)) { // throw new BusinessException("委内加工详情数据为空"); // } - for (int i = 0; i < filteredErpInboundOrderDetails.size(); i++) { - ErpInboundOrderDetail inboundDetail = filteredErpInboundOrderDetails.get(i); - SysMakeorderBom sysMakeorderBom = sysMakeorderBoms.get(i); - - QualityOrderDetail qualityOrderDetail = new QualityOrderDetail(); - qualityOrderDetail.setMaterialNo(sysMakeorderBom.getMaterialNo()); - qualityOrderDetail.setQualityOrderCode(qualityOrderCode); - QualityOrderDetail tempQualityOrderDetail = qualityOrderDetailMapper.selectMakeInOrderDetailByCodeAndNo(qualityOrderDetail); - if (tempQualityOrderDetail != null){ - qualityOrderDetail.setQualityOrderDetailId(tempQualityOrderDetail.getQualityOrderDetailId()); - Long currentNum = inboundDetail.getCurrentNum(); - qualityOrderDetail.setMakeInNum((int) (tempQualityOrderDetail.getMakeInNum()+currentNum)); - int updateQualityOrderDetailResult = qualityOrderDetailMapper.updateQualityOrderDetail(qualityOrderDetail); - if (updateQualityOrderDetailResult <= 0){ - throw new BusinessException("更新品质单详情数据失败"); - } - }else { - qualityOrderDetail.setRelatedOrderCode(erpInboundOrder.getMakeNo()); - - qualityOrderDetail.setMaterialName(sysMakeorderBom.getMaterialName()); - qualityOrderDetail.setMaterialBrand(sysMakeorderBom.getBrand()); - qualityOrderDetail.setMaterialDescribe(sysMakeorderBom.getDescribe()); - qualityOrderDetail.setMaterialProcessMethod(sysMakeorderBom.getProcessMethod()); - qualityOrderDetail.setMaterialDeptType(sysMakeorderBom.getWarehouseDept()); - qualityOrderDetail.setMaterialPhotourl(sysMakeorderBom.getPhotoUrl()); - qualityOrderDetail.setMaterialUnit(sysMakeorderBom.getUnit()); - qualityOrderDetail.setMaterialType(sysMakeorderBom.getMaterialType()); - //添加委内已完成数 - qualityOrderDetail.setMakeInNum(Math.toIntExact(inboundDetail.getCurrentNum())); - //添加委内加工费单价 - qualityOrderDetail.setMakeInUnitPrice(inboundDetail.getProcessFeeUnitPrice()); - qualityOrderDetail.setCreateBy(ShiroUtils.getLoginName()); - qualityOrderDetail.setCreateTime(new Date()); - qualityOrderDetailMapper.insertQualityOrderDetail(qualityOrderDetail); - } - - } +// for (int i = 0; i < filteredErpInboundOrderDetails.size(); i++) { +// ErpInboundOrderDetail inboundDetail = filteredErpInboundOrderDetails.get(i); +// SysMakeorderBom sysMakeorderBom = sysMakeorderBoms.get(i); +// +// QualityOrderDetail qualityOrderDetail = new QualityOrderDetail(); +// qualityOrderDetail.setMaterialNo(sysMakeorderBom.getMaterialNo()); +// qualityOrderDetail.setQualityOrderCode(qualityOrderCode); +// QualityOrderDetail tempQualityOrderDetail = qualityOrderDetailMapper.selectMakeInOrderDetailByCodeAndNo(qualityOrderDetail); +// if (tempQualityOrderDetail != null){ +// qualityOrderDetail.setQualityOrderDetailId(tempQualityOrderDetail.getQualityOrderDetailId()); +// Long currentNum = inboundDetail.getCurrentNum(); +// qualityOrderDetail.setMakeInNum((int) (tempQualityOrderDetail.getMakeInNum()+currentNum)); +// int updateQualityOrderDetailResult = qualityOrderDetailMapper.updateQualityOrderDetail(qualityOrderDetail); +// if (updateQualityOrderDetailResult <= 0){ +// throw new BusinessException("更新品质单详情数据失败"); +// } +// }else { +// qualityOrderDetail.setRelatedOrderCode(erpInboundOrder.getMakeNo()); +// +// qualityOrderDetail.setMaterialName(sysMakeorderBom.getMaterialName()); +// qualityOrderDetail.setMaterialBrand(sysMakeorderBom.getBrand()); +// qualityOrderDetail.setMaterialDescribe(sysMakeorderBom.getDescribe()); +// qualityOrderDetail.setMaterialProcessMethod(sysMakeorderBom.getProcessMethod()); +// qualityOrderDetail.setMaterialDeptType(sysMakeorderBom.getWarehouseDept()); +// qualityOrderDetail.setMaterialPhotourl(sysMakeorderBom.getPhotoUrl()); +// qualityOrderDetail.setMaterialUnit(sysMakeorderBom.getUnit()); +// qualityOrderDetail.setMaterialType(sysMakeorderBom.getMaterialType()); +// //添加委内已完成数 +// qualityOrderDetail.setMakeInNum(Math.toIntExact(inboundDetail.getCurrentNum())); +// //添加委内加工费单价 +// qualityOrderDetail.setMakeInUnitPrice(inboundDetail.getProcessFeeUnitPrice()); +// qualityOrderDetail.setCreateBy(ShiroUtils.getLoginName()); +// qualityOrderDetail.setCreateTime(new Date()); +// qualityOrderDetailMapper.insertQualityOrderDetail(qualityOrderDetail); +// } +// +// } } /**