From 0a62da90aa4e9dc393cb61caa8577b587bae923c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=8E=8B=E5=AF=8C=E5=BA=B7?= <15630117759@163.com>
Date: Sun, 4 Aug 2024 17:01:27 +0800
Subject: [PATCH] =?UTF-8?q?AI=E5=9B=BE=E7=89=87=E5=85=A5=E5=BA=93=E7=9C=9F?=
=?UTF-8?q?=E5=88=A0=E9=99=A4=E8=AF=A6=E6=83=85=E5=92=8Cstocklog;?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
撤销采购单,不删除商品,只回退库存数。
---
hiver-admin/test-output/test-report.html | 14 ++---
.../mall/dao/mapper/PurchaseDetailMapper.java | 2 +
.../hiver/mall/dao/mapper/StockLogMapper.java | 2 +
.../cc/hiver/mall/entity/PurchaseDetail.java | 4 ++
.../cc/hiver/mall/pojo/vo/PurchaseOcrVo.java | 3 ++
.../mybatis/PurchaseDetailService.java | 2 +
.../mall/service/mybatis/StockLogService.java | 2 +
.../mybatis/PurchaseDetailServiceImpl.java | 5 ++
.../mybatis/PurchaseServiceImpl.java | 54 ++-----------------
.../mybatis/StockLogServiceImpl.java | 5 ++
.../serviceimpl/mybatis/StockServiceImpl.java | 6 +--
.../java/cc/hiver/mall/utils/AliOcrUtil.java | 2 +
.../resources/mapper/PurchaseDetailMapper.xml | 38 ++++++++++---
.../main/resources/mapper/StockLogMapper.xml | 9 +++-
14 files changed, 79 insertions(+), 69 deletions(-)
diff --git a/hiver-admin/test-output/test-report.html b/hiver-admin/test-output/test-report.html
index 8e73f001..f779fe9d 100644
--- a/hiver-admin/test-output/test-report.html
+++ b/hiver-admin/test-output/test-report.html
@@ -35,7 +35,7 @@
Hiver
-���� 04, 2024 12:12:02
+���� 04, 2024 16:50:15
@@ -84,7 +84,7 @@
passTest
-
12:12:02 ���� / 0.016 secs
+
16:50:16 ���� / 0.016 secs
@@ -92,8 +92,8 @@
#test-id=1
passTest
-
08.04.2024 12:12:02
-
08.04.2024 12:12:02
+
08.04.2024 16:50:16
+
08.04.2024 16:50:16
0.016 secs
@@ -104,7 +104,7 @@
| Pass |
- 12:12:02 |
+ 16:50:16 |
Test passed
|
@@ -128,13 +128,13 @@
Started
-
���� 04, 2024 12:12:02
+
���� 04, 2024 16:50:15
Ended
-
���� 04, 2024 12:12:02
+
���� 04, 2024 16:50:16
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/PurchaseDetailMapper.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/PurchaseDetailMapper.java
index f6a85a52..6d0b3b83 100644
--- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/PurchaseDetailMapper.java
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/PurchaseDetailMapper.java
@@ -54,4 +54,6 @@ public interface PurchaseDetailMapper extends BaseMapper
{
* @return List
*/
List getPurchaseDetailListByProductIds(@Param("productIdList") List productIdList,@Param("id") String id);
+
+ void realDeleteByPurchaseId(@Param("purchaseId") String purchaseId);
}
\ No newline at end of file
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/StockLogMapper.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/StockLogMapper.java
index e91c764a..af52e705 100644
--- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/StockLogMapper.java
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/StockLogMapper.java
@@ -45,4 +45,6 @@ public interface StockLogMapper extends BaseMapper {
List getPurchaseDetails(@Param("purchaseIdList") List purchaseIdList);
List getByProductIds(@Param("purchaseId") String purchaseId,@Param("productIdList") List productIdList);
+
+ void realDeleteByPurchaseId(@Param("purchaseId") String purchaseId);
}
\ No newline at end of file
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/entity/PurchaseDetail.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/entity/PurchaseDetail.java
index e974bf6f..5d16139c 100644
--- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/entity/PurchaseDetail.java
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/entity/PurchaseDetail.java
@@ -98,6 +98,10 @@ public class PurchaseDetail extends HiverBaseEntity {
@ApiModelProperty(value = "识别图片id")
private String ocrPicturePath;
+
+ @ApiModelProperty(value = "排序")
+ private Integer sort;
+
@Transient
@TableField(exist = false)
@ApiModelProperty(value = "入库商品规格明细表")
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/PurchaseOcrVo.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/PurchaseOcrVo.java
index 11b76a67..f130493a 100644
--- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/PurchaseOcrVo.java
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/PurchaseOcrVo.java
@@ -21,6 +21,9 @@ public class PurchaseOcrVo {
@ApiModelProperty(value = "数量")
private Integer productCount;
+ @ApiModelProperty(value = "排序")
+ private Integer sort;
+
@ApiModelProperty(value = "单位")
private CopyOnWriteArrayList attributeList;
}
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/PurchaseDetailService.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/PurchaseDetailService.java
index 2ed062da..8fcabc44 100644
--- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/PurchaseDetailService.java
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/PurchaseDetailService.java
@@ -21,6 +21,8 @@ public interface PurchaseDetailService extends IService {
void deleteByPurchaseId(String purchaseId);
+ void realDeleteByPurchaseId(String purchaseId);
+
List getPurchaseDetails(List purchaseIdList);
/**
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/StockLogService.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/StockLogService.java
index d903a5fb..c6eb9390 100644
--- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/StockLogService.java
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/StockLogService.java
@@ -25,4 +25,6 @@ public interface StockLogService extends IService {
* @return List
*/
List getByProductIds(String purchaseId, String productIds);
+
+ void realDeleteByPurchaseId(String purchaseId);
}
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/PurchaseDetailServiceImpl.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/PurchaseDetailServiceImpl.java
index bd63197f..ac6cc886 100644
--- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/PurchaseDetailServiceImpl.java
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/PurchaseDetailServiceImpl.java
@@ -82,6 +82,11 @@ public class PurchaseDetailServiceImpl extends ServiceImpl getPurchaseDetails(List purchaseIdList) {
return purchaseDetailMapper.getPurchaseDetails(purchaseIdList);
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/PurchaseServiceImpl.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/PurchaseServiceImpl.java
index 1c615b2e..3d98cd95 100644
--- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/PurchaseServiceImpl.java
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/PurchaseServiceImpl.java
@@ -436,7 +436,7 @@ public class PurchaseServiceImpl extends ServiceImpl i
stockLogMap.put(mapKey, stockLogs);
}
}
- final Map> purchaseDetailMap = new HashMap<>();
+ final LinkedHashMap> purchaseDetailMap = new LinkedHashMap<>();
for (PurchaseDetail purchaseDetail : purchaseDetails) {
// 这里对purchaseDetail做个合并处理,优先根据商品id分组,如果商品id为空,那就就根据商品货号分组,如果商品货号为空,则根据商品名称分组,
// 重复的直接覆盖即可
@@ -651,7 +651,7 @@ public class PurchaseServiceImpl extends ServiceImpl i
for (PurchaseDetail purchaseDetail : byPurchaseIdList) {
productIdList.add(purchaseDetail.getProductId());
}
- // 查询该商品除当前入库单的其他的入库记录
+ // 查询该商品除当前入库单的其他的入库记录,用于计算平均采购价
final List purductPurchaseList = purchaseDetailService.getPurchaseDetailListByProductIds(productIdList, id);
// 封装为商品id为key,List为value 的map
final Map> purductPurchaseMap = new HashMap<>();
@@ -665,59 +665,15 @@ public class PurchaseServiceImpl extends ServiceImpl i
purductPurchaseMap.put(productId, purchaseDetails);
}
}
- // 查询该商品的销售记录
- final List purductSaleList = saleDetailService.getSaleDetailListByProductIds(productIdList);
- // 封装为商品id为key,List为value 的map
- final Map> purductSaleMap = new HashMap<>();
- for (SaleDetail saleDetail : purductSaleList) {
- final String productId = saleDetail.getProductId();
- if (purductSaleMap.containsKey(productId)) {
- purductSaleMap.get(productId).add(saleDetail);
- } else {
- final List saleDetails = new ArrayList<>();
- saleDetails.add(saleDetail);
- purductSaleMap.put(productId, saleDetails);
- }
- }
- //
- final StringJoiner needDeleteProductId = new StringJoiner(",");
- final StringJoiner needDeleteStockProductId = new StringJoiner(",");
- final StringJoiner needReduceStockProductId = new StringJoiner(",");
-
- for (PurchaseDetail purchaseDetail : byPurchaseIdList) {
- final String productId = purchaseDetail.getProductId();
- if (!purductPurchaseMap.containsKey(productId) && !purductSaleMap.containsKey(productId)) {
- // 可以删除商品的相关信息
- needDeleteProductId.add(productId);
- // 库存删除
- needDeleteStockProductId.add(productId);
- } else {
- // 商品保留,库存扣减
- needReduceStockProductId.add(productId);
- }
+ final List stockLogList = stockLogService.getByPurchaseId(id);
+ // 根据入库记录减掉库存数
+ stockService.batchReduceStockByLog(stockLogList);
- }
- // 执行删除商品
- if (StringUtils.isNotEmpty(needDeleteProductId.toString())) {
- productService.batchDeleteProduct(needDeleteProductId.toString());
- }
- // 执行删除库存
- if (StringUtils.isNotEmpty(needReduceStockProductId.toString())) {
- stockService.batchDeleteStockByProductIds(needDeleteStockProductId.toString());
- }
- // 执行扣减库存
- if (StringUtils.isNotEmpty(needReduceStockProductId.toString())) {
- // 获取当前入库单各商品的规格及数量信息
- final List stockLogList = stockLogService.getByProductIds(id, needReduceStockProductId.toString());
- // 根据入库记录减掉库存数
- stockService.batchReduceStockByLog(stockLogList);
- }
// 4. 根据采购单id删除库存记录
stockLogService.deleteByPurchaseId(id);
// 5. 计算平均采购价
// 获取该商品的历次入库记录,排除掉本次入库记录 入库的价格*入库数量/入库总数量
- final Map productPurchasePriceMap = new HashMap<>();
final List productList = new ArrayList<>();
for (Map.Entry> stringListEntry : purductPurchaseMap.entrySet()) {
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/StockLogServiceImpl.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/StockLogServiceImpl.java
index 3ccab6fe..b81fed99 100644
--- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/StockLogServiceImpl.java
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/StockLogServiceImpl.java
@@ -57,4 +57,9 @@ public class StockLogServiceImpl extends ServiceImpl i
return stockLogMapper.getByProductIds(purchaseId, productIdList);
}
+ @Override
+ public void realDeleteByPurchaseId(String purchaseId) {
+ stockLogMapper.realDeleteByPurchaseId(purchaseId);
+ }
+
}
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/StockServiceImpl.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/StockServiceImpl.java
index 860c67a0..7d2b0e59 100644
--- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/StockServiceImpl.java
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/StockServiceImpl.java
@@ -736,9 +736,9 @@ public class StockServiceImpl extends ServiceImpl implements
insertFlag = false;
}
- // 先根据入库单id 删除详情及库存履历表信息
- purchaseDetailService.deleteByPurchaseId(purchaseId);
- stockLogService.deleteByPurchaseId(purchaseId);
+ // 先根据入库单id 删除详情及库存履历表信息(真删除)
+ purchaseDetailService.realDeleteByPurchaseId(purchaseId);
+ stockLogService.realDeleteByPurchaseId(purchaseId);
// 获取前台入库商品信息
final List purchaseDetails = purchaseVo.getPurchaseDetails();
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/utils/AliOcrUtil.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/utils/AliOcrUtil.java
index 68cf0efd..b23b6d2c 100644
--- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/utils/AliOcrUtil.java
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/utils/AliOcrUtil.java
@@ -654,6 +654,7 @@ public class AliOcrUtil {
}
purchaseOcrVo.setAttributeList(attributeList);
+ purchaseOcrVo.setSort(i);
purchaseOcrVos.add(purchaseOcrVo);
// 处理当前识别的货号及名称,现在需要特殊处理的 是货号:去掉“/”,或者是“/"在货号或者名称中间的,需要分隔为货号及名称
@@ -809,6 +810,7 @@ public class AliOcrUtil {
}
stockLogList.add(stockLog);
purchaseDetail.setStockLogList1(stockLogList);
+ purchaseDetail.setSort(purchaseOcrVo.getSort());
// 如果货号为空,那么就拿商品名称作为key
purchaseDetailMap.put(StringUtils.isEmpty(productSn) ? productName : productSn, purchaseDetail);
}
diff --git a/hiver-modules/hiver-mall/src/main/resources/mapper/PurchaseDetailMapper.xml b/hiver-modules/hiver-mall/src/main/resources/mapper/PurchaseDetailMapper.xml
index d4119787..3454961b 100644
--- a/hiver-modules/hiver-mall/src/main/resources/mapper/PurchaseDetailMapper.xml
+++ b/hiver-modules/hiver-mall/src/main/resources/mapper/PurchaseDetailMapper.xml
@@ -30,6 +30,7 @@
+
@@ -93,7 +94,7 @@
id, create_by, create_time, del_flag, update_by, update_time, purchase_id, product_id,
product_name, unit, shop_id, category_id, attribute_list, supplier_id,supplier_name, product_sn,
barcode, price, purchase_price, wholesale_price, product_picture, product_video,
- product_intro, sales_week, tail_warn, print_barcode, product_count,ocr_picture_path
+ product_intro, sales_week, tail_warn, print_barcode, product_count,ocr_picture_path,sort