From 62d85b2721cd41c5a61070c5808c1e33fbc31738 Mon Sep 17 00:00:00 2001
From: wangfukang <15630117759@163.com>
Date: Thu, 26 Sep 2024 21:12:42 +0800
Subject: [PATCH] =?UTF-8?q?=E5=BF=AB=E5=B0=8F=E7=8C=AA:=201.=E7=89=A9?=
=?UTF-8?q?=E6=B5=81=E7=9A=84=E6=A8=A1=E5=9E=8B=E4=BF=AE=E6=94=B9=EF=BC=9B?=
=?UTF-8?q?=202.=E6=94=BE=E5=BC=80=E5=BE=85=E5=85=A5=E5=BA=93=E4=BA=A4?=
=?UTF-8?q?=E6=98=93=E8=AE=B0=E5=BD=95=E6=8C=82=E9=92=A9=E9=99=90=E5=88=B6?=
=?UTF-8?q?=EF=BC=9B=203.app/productShare/save=20=E6=8E=A5=E5=8F=A3?=
=?UTF-8?q?=E4=BC=A0=E4=B8=80=E4=B8=AAscene=E5=8F=82=E6=95=B0=20=20?=
=?UTF-8?q?=E5=9C=A8share=E8=A1=A8=E5=AD=98=E4=B8=80=E4=B8=8B=EF=BC=8C?=
=?UTF-8?q?=E5=9C=A8getShareList=E7=9A=84=E6=97=B6=E5=80=99=E8=BF=94?=
=?UTF-8?q?=E5=9B=9E=EF=BC=88=E5=89=8D=E5=8F=B0=E4=BC=9A=E4=BC=A0=E5=8F=82?=
=?UTF-8?q?id=E7=9A=84=E6=97=B6=E5=80=99=EF=BC=89=EF=BC=9B=204.app/sale/bu?=
=?UTF-8?q?yAi=E9=9C=80=E8=A6=81=E8=BF=94=E5=9B=9EattrId=EF=BC=9B=205.?=
=?UTF-8?q?=E5=BF=AB=E5=B0=8F=E7=8C=AA:=20buyNew=E6=8E=A5=E5=8F=A3=20=20?=
=?UTF-8?q?=E6=97=A7=E5=95=86=E5=93=81=E7=9A=84=E6=96=B0=E8=A7=84=E6=A0=BC?=
=?UTF-8?q?=E6=B2=A1=E6=9C=89=E5=92=8CattrId=E7=9A=84=E5=88=86=E7=B1=BB?=
=?UTF-8?q?=E7=BB=91=E5=AE=9A=206.=E5=BF=AB=E5=B0=8F=E7=8C=AA:=20app/sale/?=
=?UTF-8?q?listPages=E8=BF=94=E5=9B=9E=E5=95=86=E5=93=81=E7=9A=84=20?=
=?UTF-8?q?=E5=88=86=E7=B1=BB=E4=BB=B7=E6=A0=BC=EF=BC=9B=E8=BF=98=E6=9C=89?=
=?UTF-8?q?getShopAll=EF=BC=9B=E8=BF=98=E6=9C=89app/sale/get/=E8=BF=98?=
=?UTF-8?q?=E6=9C=89app/purchase/getPurchaseAllData=208.=E5=BF=AB=E5=B0=8F?=
=?UTF-8?q?=E7=8C=AA:=20app/customerCategory/getCustomerCategoryListByShop?=
=?UTF-8?q?Id=20=20=E5=8A=A0=E4=B8=8A=E8=B4=9F=E5=BA=93=E5=AD=98=E6=95=B0?=
=?UTF-8?q?=209.=E5=BF=AB=E5=B0=8F=E7=8C=AA:=20app/sale/savePresale?=
=?UTF-8?q?=E6=8E=A5=E6=94=B6=E4=B8=80=E4=B8=8BcategoryId=EF=BC=88?=
=?UTF-8?q?=E5=AE=A2=E6=88=B7=E5=88=86=E7=B1=BB=EF=BC=89=E5=A6=82=E6=9E=9C?=
=?UTF-8?q?=E6=9C=89=E5=80=BC=E7=9A=84=E8=AF=9D=EF=BC=88=E5=89=8D=E5=8F=B0?=
=?UTF-8?q?=E4=B8=8D=E4=B8=80=E5=AE=9A=E4=BC=A0=E5=80=BC=EF=BC=89=EF=BC=8C?=
=?UTF-8?q?=E5=B9=B6=E4=BF=9D=E5=AD=98=E5=88=B0=E5=AE=A2=E6=88=B7=E8=A1=A8?=
=?UTF-8?q?=E9=87=8C=EF=BC=8Capp/debt/selectByUserId=E9=9C=80=E8=A6=81?=
=?UTF-8?q?=E8=BF=94=E5=9B=9EcategoryId=2010.=E5=BF=AB=E5=B0=8F=E7=8C=AA:?=
=?UTF-8?q?=20purchaseOcrPicture/callWithMessageOfPurchase=E5=92=8Capp/sal?=
=?UTF-8?q?e/buyAi=E7=A1=AE=E4=BF=9D=E6=8A=8AproductCount=E8=BF=94?=
=?UTF-8?q?=E5=9B=9E=E4=B8=80=E4=B8=AA=E6=95=B0=E5=AD=97=EF=BC=8C=E6=B2=A1?=
=?UTF-8?q?=E6=9C=89=E5=B0=B1=E8=BF=94=E5=9B=9E0=2011.=E5=BF=AB=E5=B0=8F?=
=?UTF-8?q?=E7=8C=AA:=20app/sale/buyAi=20purchaseOcrPicture/callWithMessag?=
=?UTF-8?q?eOfPurchase=20app/product/getByProductSn=20app/product/getShare?=
=?UTF-8?q?List=20app/product/getByBarcode=20app/product/getById=20app/sal?=
=?UTF-8?q?e/listPages=E8=BF=98=E6=9C=89=E9=A6=96=E9=A1=B5app/sale/getShop?=
=?UTF-8?q?All=E5=92=8Capp/sale/get/=EF=BC=88=E8=BF=99=E5=87=A0=E4=B8=AA?=
=?UTF-8?q?=E5=8F=AF=E8=83=BD=E5=92=8C=E4=B8=8A=E8=BE=B9=E9=80=BB=E8=BE=91?=
=?UTF-8?q?=E4=B8=8D=E4=B8=80=E6=A0=B7=EF=BC=8C=E6=98=AF=E5=B7=B2=E4=BF=9D?=
=?UTF-8?q?=E5=AD=98=E5=88=B0=E8=A1=A8=E9=87=8C=E7=9A=84saledetail?=
=?UTF-8?q?=E9=87=8C=E7=9A=84productId=E8=81=94=E6=9F=A5=EF=BC=89=20?=
=?UTF-8?q?=E8=BF=99=E5=87=A0=E4=B8=AA=E6=8E=A5=E5=8F=A3=20=20=E6=8E=A5?=
=?UTF-8?q?=E5=8F=A3=E5=8A=A0=E4=B8=80=E4=B8=AA=E5=8F=82=E6=95=B0=20=20?=
=?UTF-8?q?=E5=AE=A2=E6=88=B7id=EF=BC=8C=E5=A6=82=E6=9E=9C=E5=89=8D?=
=?UTF-8?q?=E5=8F=B0=E4=BC=A0=E5=80=BC=E4=BA=86=EF=BC=8C=E9=9C=80=E8=A6=81?=
=?UTF-8?q?=E8=81=94=E6=9F=A5=E8=AF=A5=E5=AE=A2=E6=88=B7=20=20=E4=BB=A5?=
=?UTF-8?q?=E4=B8=8A=E6=8E=A5=E5=8F=A3=E6=9F=A5=E8=AF=A2=E5=88=B0=E7=9A=84?=
=?UTF-8?q?=E5=95=86=E5=93=81=E7=9A=84=20=E8=B4=AD=E4=B9=B0=E6=AC=A1?=
=?UTF-8?q?=E6=95=B0=2012.=E5=85=A5=E5=BA=93=EF=BC=88=E5=88=86=E6=96=B0?=
=?UTF-8?q?=E5=95=86=E5=93=81=E5=92=8C=E6=97=A7=E5=95=86=E5=93=81=E6=9B=B4?=
=?UTF-8?q?=E6=96=B0=EF=BC=89=E3=80=81=E6=96=B0=E5=A2=9E=E5=95=86=E5=93=81?=
=?UTF-8?q?=E3=80=81=E7=BC=96=E8=BE=91=E6=A1=91=E5=93=81=E3=80=82=E5=88=A4?=
=?UTF-8?q?=E6=96=AD=E4=B8=80=E4=B8=8B=E5=89=8D=E5=8F=B0=E6=9C=89=E5=8F=AF?=
=?UTF-8?q?=E8=83=BD=E4=BC=A0=E5=80=BCnull=E5=AD=97=E7=AC=A6=E4=B8=B2?=
=?UTF-8?q?=E5=92=8C=20'[]',=E6=95=B0=E6=8D=AE=E5=BA=93=E4=BF=9D=E5=AD=98'?=
=?UTF-8?q?'.=EF=BC=88=E5=8E=86=E5=8F=B2=E6=95=B0=E6=8D=AE=E9=9C=80?=
=?UTF-8?q?=E8=A6=81=E5=A4=84=E7=90=86=EF=BC=89?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
hiver-admin/test-output/test-report.html | 18 +-
.../mall/controller/ProductController.java | 24 +-
.../hiver/mall/controller/SaleController.java | 39 +++-
.../cc/hiver/mall/dao/mapper/SaleMapper.java | 2 +
.../java/cc/hiver/mall/debt/entity/Debt.java | 12 +
.../debt/service/impl/DebtServiceImpl.java | 10 +-
.../java/cc/hiver/mall/entity/Product.java | 5 +
.../cc/hiver/mall/pojo/dto/SaleDetailDTO.java | 6 +
.../cc/hiver/mall/pojo/dto/SaleQueryDTO.java | 6 +
.../mall/pojo/query/ProductPageQuery.java | 3 +
.../cc/hiver/mall/pojo/vo/BuyCountVo.java | 16 ++
.../mall/pojo/vo/ProductCategoryVo2.java | 3 +
.../cc/hiver/mall/pojo/vo/ProductPageVO.java | 6 +
.../java/cc/hiver/mall/pojo/vo/SaleVO.java | 3 +
.../cc/hiver/mall/pojo/vo/ShopStockVo.java | 3 +
.../impl/PurchaseOcrPictureServiceImpl.java | 2 +-
.../mall/service/mybatis/ProductService.java | 6 +-
.../mall/service/mybatis/SaleService.java | 12 +-
.../SalesAndDetailsServiceImpl.java | 2 +
.../mybatis/ProductServiceImpl.java | 212 ++++++++++++++++--
.../serviceimpl/mybatis/SaleServiceImpl.java | 92 ++++++--
.../serviceimpl/mybatis/StockServiceImpl.java | 23 +-
.../java/cc/hiver/mall/utils/AliOcrUtil.java | 8 +-
.../mapper/ProductCategoryMapper.xml | 51 +++--
.../main/resources/mapper/ProductMapper.xml | 4 +-
.../src/main/resources/mapper/SaleMapper.xml | 19 ++
26 files changed, 486 insertions(+), 101 deletions(-)
create mode 100644 hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/BuyCountVo.java
diff --git a/hiver-admin/test-output/test-report.html b/hiver-admin/test-output/test-report.html
index 72fdae47..b2c8e635 100644
--- a/hiver-admin/test-output/test-report.html
+++ b/hiver-admin/test-output/test-report.html
@@ -5,7 +5,7 @@
-Hiver测试报告
+HiverԱ
@@ -35,7 +35,7 @@
Hiver
-九月 21, 2024 16:22:06
+ 23, 2024 22:26:15
@@ -84,7 +84,7 @@
passTest
-
16:22:06 下午 / 0.012 secs
+
22:26:16 / 0.015 secs
@@ -92,9 +92,9 @@
#test-id=1
passTest
-
09.21.2024 16:22:06
-
09.21.2024 16:22:06
-
0.012 secs
+
09.23.2024 22:26:16
+
09.23.2024 22:26:16
+
0.015 secs
@@ -104,7 +104,7 @@
| Pass |
- 16:22:06 |
+ 22:26:16 |
Test passed
|
@@ -128,13 +128,13 @@
Started
-
九月 21, 2024 16:22:06
+
23, 2024 22:26:15
Ended
-
九月 21, 2024 16:22:06
+
23, 2024 22:26:16
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/ProductController.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/ProductController.java
index c4b85b31..1f7ce840 100644
--- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/ProductController.java
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/ProductController.java
@@ -56,7 +56,7 @@ public class ProductController {
// 根据货号查询商品是否存在
// shopId从缓存中设置
final String shopId = securityUtil.getShopId();
- final CopyOnWriteArrayList
oldProductListBySn = productService.getByProductSn(productVo.getProductSn(), shopId);
+ final CopyOnWriteArrayList oldProductListBySn = productService.getByProductSn(productVo.getProductSn(), shopId,"");
if (oldProductListBySn != null && !oldProductListBySn.isEmpty()) {
return ResultUtil.error("您已有货号"+productVo.getProductSn()+"的商品,请更换货号");
}
@@ -77,6 +77,10 @@ public class ProductController {
product.setShopId(shopId);
// 新增的默认为已上架
product.setDelFlag(CommonConstant.DEL_FLAG_TRUE);
+ // 处理前台的错误传参
+ if("[]".equals(product.getCustomerCategoryRule()) || "null".equals(product.getCustomerCategoryRule())){
+ product.setCustomerCategoryRule("");
+ }
final boolean result = productService.save(product);
// 如果有子图,那么新增子图信息
final List productPictures = productVo.getProductPictures();
@@ -100,7 +104,7 @@ public class ProductController {
// 根据货号查询商品是否存在
// shopId从缓存中设置
final String shopId = securityUtil.getShopId();
- final CopyOnWriteArrayList oldProductListBySn = productService.getByProductSn(productVo.getProductSn(), shopId);
+ final CopyOnWriteArrayList oldProductListBySn = productService.getByProductSn(productVo.getProductSn(), shopId,"");
if (oldProductListBySn != null && !oldProductListBySn.isEmpty()) {
// 如果旧商品id不等于前台传递的商品id,则返回信息
if (!productVo.getId().equals(oldProductListBySn.get(0).getId())) {
@@ -123,6 +127,10 @@ public class ProductController {
} else {
return ResultUtil.error("添加分类信息失败");
}
+ // 处理前台的错误传参
+ if("[]".equals(product.getCustomerCategoryRule()) || "null".equals(product.getCustomerCategoryRule())){
+ product.setCustomerCategoryRule("");
+ }
final boolean result = productService.updateById(product);
// 如果有子图,那么新增子图信息
final List productPictures = productVo.getProductPictures();
@@ -326,8 +334,8 @@ public class ProductController {
@RequestMapping(value = "/getById/{id}", method = RequestMethod.POST)
@ApiOperation("根据id查询商品信息")
- public Result getById(@PathVariable String id) {
- final Product byId = productService.getByIdOrBrcode(id);
+ public Result getById(@PathVariable String id,String customerId) {
+ final Product byId = productService.getByIdOrBrcode(id, customerId);
if (byId != null) {
return new ResultUtil().setData(byId);
} else {
@@ -337,10 +345,10 @@ public class ProductController {
@RequestMapping(value = "/getByProductSn", method = RequestMethod.POST)
@ApiOperation("根据货号获取商品信息")
- public Result> getByProductSn(String productSn) {
+ public Result> getByProductSn(String productSn,String customerId) {
// shopId从缓存中设置
final String shopId = securityUtil.getShopId();
- final List byProductSn = productService.getByProductSn(productSn, shopId);
+ final List byProductSn = productService.getByProductSn(productSn, shopId,customerId);
if (byProductSn != null) {
return new ResultUtil>().setData(byProductSn);
} else {
@@ -350,8 +358,8 @@ public class ProductController {
@RequestMapping(value = "/getByBarcode", method = RequestMethod.POST)
@ApiOperation("根据条码获取商品信息")
- public Result> getByBarcode(String barcode) {
- final List byBarcode = productService.getByBarcode(barcode);
+ public Result> getByBarcode(String barcode, String customerId) {
+ final List byBarcode = productService.getByBarcode(barcode, customerId);
if (byBarcode != null) {
return new ResultUtil>().setData(byBarcode);
} else {
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/SaleController.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/SaleController.java
index 5c6ae24d..263de6aa 100644
--- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/SaleController.java
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/SaleController.java
@@ -480,7 +480,7 @@ public class SaleController {
@RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
@ApiOperation("获得订单详情")
- public Result get(@PathVariable String id) {
+ public Result get(@PathVariable String id, String customerId) {
final SaleNewVO saleNewVO = new SaleNewVO();
final Sale sale = saleService.getById(id);
saleNewVO.setSale(sale);
@@ -510,7 +510,7 @@ public class SaleController {
}
//
final Map productMap = new HashMap<>();
- if(list != null && !list.isEmpty()){
+ if (list != null && !list.isEmpty()) {
final List productList = productService.getProductList(list);
for (Product product : productList) {
productMap.putIfAbsent(product.getId(), product);
@@ -537,6 +537,7 @@ public class SaleController {
if (productMap.containsKey(productId)) {
final BigDecimal purchasePrice = productMap.get(productId).getPurchasePrice() == null ? BigDecimal.ZERO : productMap.get(productId).getPurchasePrice();
saleDetailDTO.setPurchasePrice(purchasePrice);
+ saleDetailDTO.setCustomerCategoryRule(productMap.get(productId).getCustomerCategoryRule());
} else {
saleDetailDTO.setPurchasePrice(saleDetail.getPurchasePrice());
}
@@ -560,10 +561,23 @@ public class SaleController {
saleDetailDTO.setStockLogList1(saleDetailQueryDTOS);
saleDetailDTOS.add(saleDetailDTO);
}
+ // 如果客户id不为空,查询客户的购买次数
+ if (StringUtils.isNotEmpty(customerId)) {
+ final List buyCount = saleService.buyCount(customerId, list);
+ // 封装为Map
+ final Map buyCountMap = new HashMap<>();
+ for (BuyCountVo buyCountVo : buyCount) {
+ buyCountMap.put(buyCountVo.getProductId(), buyCountVo.getBuyCount());
+ }
+ for (SaleDetailDTO saleDetailDTO : saleDetailDTOS) {
+ final String productId = saleDetailDTO.getProductId();
+ saleDetailDTO.setBuyCount(buyCountMap.getOrDefault(productId, 0));
+ }
+ }
saleNewVO.setSaleDetailDTOList(saleDetailDTOS);
//增加客户信息明细
- final String customerId = sale.getUserId();
- final Customer customer = customerService.getById(customerId);
+ final String addCustomerId = sale.getUserId();
+ final Customer customer = customerService.getById(addCustomerId);
saleNewVO.setCustomer(customer);
// 增加物流公司信息
final String transCompanyId = sale.getTransCompany();
@@ -1157,12 +1171,12 @@ public class SaleController {
@RequestMapping(value = "/buyAi", method = RequestMethod.POST)
@ApiOperation("同步步Ai开单")
- public Result buyAi(String aiMsg) {
+ public Result buyAi(String aiMsg, String customerId) {
if (StringUtils.isEmpty(aiMsg)) {
ResultUtil.error("指令不能为空!");
}
- final JSONObject jsonObject = saleService.buyAi(aiMsg);
+ final JSONObject jsonObject = saleService.buyAi(aiMsg, customerId);
return new ResultUtil().setData(jsonObject);
}
@@ -1332,4 +1346,17 @@ public class SaleController {
return ResultUtil.error("暂存失败!");
}
}
+
+ // 查询指定客户的购买次数
+ @RequestMapping(value = "/buyCount", method = RequestMethod.POST)
+ @ApiOperation("查询指定客户的购买次数")
+ public Result buyCount(String customerId, String productIds) {
+ if (StringUtils.isEmpty(customerId)) {
+ return ResultUtil.error("客户id不能为空");
+ }
+ // 将productIds使用,分隔,并封装为list
+ final List productIdList = Arrays.asList(productIds.split(","));
+ final List count = saleService.buyCount(customerId, productIdList);
+ return new ResultUtil>().setData(count);
+ }
}
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/SaleMapper.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/SaleMapper.java
index 6701c74c..ce6d7d3c 100644
--- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/SaleMapper.java
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/SaleMapper.java
@@ -140,4 +140,6 @@ public interface SaleMapper extends BaseMapper {
* @date 2024/8/18
*/
Page totalAmountDetailByProduct(Page page, @Param("salePageQuery") SalePageQuery salePageQuery);
+
+ List buyCount(@Param("customerId")String customerId, @Param("productIdList") List productIdList);
}
\ No newline at end of file
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/debt/entity/Debt.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/debt/entity/Debt.java
index b99c963d..1c860bb9 100644
--- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/debt/entity/Debt.java
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/debt/entity/Debt.java
@@ -1,11 +1,13 @@
package cc.hiver.mall.debt.entity;
import cc.hiver.core.base.HiverBaseEntity;
+import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
+import javax.persistence.Transient;
import java.math.BigDecimal;
@Data
@@ -35,4 +37,14 @@ public class Debt extends HiverBaseEntity {
@ApiModelProperty(value = "欠款方式:0:客户欠款;1:供应商欠款")
private String userType;
+ @Transient
+ @TableField(exist = false)
+ @ApiModelProperty(value = "客户分类id")
+ private String categoryId;
+
+ @Transient
+ @TableField(exist = false)
+ @ApiModelProperty(value = "客户分类名称")
+ private String categoryName;
+
}
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/debt/service/impl/DebtServiceImpl.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/debt/service/impl/DebtServiceImpl.java
index aa8ab64b..9bafd130 100644
--- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/debt/service/impl/DebtServiceImpl.java
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/debt/service/impl/DebtServiceImpl.java
@@ -290,7 +290,15 @@ public class DebtServiceImpl extends ServiceImpl implements De
@Override
public Debt selectByUserId(String shopId, String userId) {
- return debtMapper.selectByUserId(shopId, userId);
+ final Debt debt = debtMapper.selectByUserId(shopId, userId);
+ // 查询客户的分类id
+ if(debt != null){
+ // 获取客户信息
+ final Customer customer = customerService.getById(userId);
+ debt.setCategoryId(customer.getCategoryId());
+ debt.setCategoryName(customer.getCategoryName());
+ }
+ return debt == null ? new Debt() : debt;
}
@Override
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/entity/Product.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/entity/Product.java
index 956dac69..95727848 100644
--- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/entity/Product.java
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/entity/Product.java
@@ -123,4 +123,9 @@ public class Product implements Serializable {
@ApiModelProperty(value = "库存数量")
private Integer stockCount;
+ @Transient
+ @TableField(exist = false)
+ @ApiModelProperty(value = "客户购买数量")
+ private Integer buyCount;
+
}
\ No newline at end of file
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/dto/SaleDetailDTO.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/dto/SaleDetailDTO.java
index 4df0cad0..279b479e 100644
--- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/dto/SaleDetailDTO.java
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/dto/SaleDetailDTO.java
@@ -76,6 +76,12 @@ public class SaleDetailDTO implements Serializable {
@ApiModelProperty(value = "客户分类价格规则")
private String customerCategoryRule;
+ @ApiModelProperty(value = "商品专属分类id")
+ private String attrId;
+
+ @ApiModelProperty(value = "客户购买数量")
+ private Integer buyCount;
+
private static final long serialVersionUID = 1L;
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/dto/SaleQueryDTO.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/dto/SaleQueryDTO.java
index 7ca66e87..110a744b 100644
--- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/dto/SaleQueryDTO.java
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/dto/SaleQueryDTO.java
@@ -36,6 +36,12 @@ public class SaleQueryDTO implements Serializable {
@ApiModelProperty(value = "客户名称")
private String username;
+ @ApiModelProperty(value = "客户分类id")
+ private String categoryId;
+
+ @ApiModelProperty(value = "客户分类名称")
+ private String categoryName;
+
@ApiModelProperty(value = "挂单及分享单的id")
private String oldSaleId;
}
\ No newline at end of file
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/query/ProductPageQuery.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/query/ProductPageQuery.java
index 8939ed03..d512e0ab 100644
--- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/query/ProductPageQuery.java
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/query/ProductPageQuery.java
@@ -72,4 +72,7 @@ public class ProductPageQuery extends HiverBasePageQuery {
@ApiModelProperty("结束时间")
private String endDate;
+
+ @ApiModelProperty("客户id")
+ private String customerId;
}
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/BuyCountVo.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/BuyCountVo.java
new file mode 100644
index 00000000..168611bb
--- /dev/null
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/BuyCountVo.java
@@ -0,0 +1,16 @@
+package cc.hiver.mall.pojo.vo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+@ApiModel(value = "客户商品购买数量Vo")
+public class BuyCountVo {
+
+ @ApiModelProperty(value = "商品id")
+ private String productId;
+
+ @ApiModelProperty(value = "购买次数")
+ private Integer buyCount;
+}
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/ProductCategoryVo2.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/ProductCategoryVo2.java
index 6d26354b..4daf56bd 100644
--- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/ProductCategoryVo2.java
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/ProductCategoryVo2.java
@@ -23,5 +23,8 @@ public class ProductCategoryVo2 extends HiverBaseEntity {
@ApiModelProperty(value = "盘点数量")
private int stockCount;
+ @ApiModelProperty(value = "商品总负库存数(某一规格库存为正数的按0计算总数)")
+ private Integer minusStockCount;
+
private static final long serialVersionUID = 1L;
}
\ No newline at end of file
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/ProductPageVO.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/ProductPageVO.java
index 21d6a5aa..68f00c3c 100644
--- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/ProductPageVO.java
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/ProductPageVO.java
@@ -101,6 +101,9 @@ public class ProductPageVO {
@ApiModelProperty(value = "商品总库存(某一规格库存为负数的按0计算总数)")
private Integer stockCount;
+ @ApiModelProperty(value = "商品总负库存数(某一规格库存为正数的按0计算总数)")
+ private Integer minusStockCount;
+
@ApiModelProperty(value = "入库状态:0:待入库(未维护对应的采购价信息);1:已入库;新增商品时为已入库")
private Integer inStorageStatus;
@@ -117,4 +120,7 @@ public class ProductPageVO {
@ApiModelProperty(value = "客户价格规则")
private String customerCategoryRule;
+
+ @ApiModelProperty(value = "商品购买数量")
+ private Integer buyCount;
}
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/SaleVO.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/SaleVO.java
index 0dc4fbe8..b907d3d0 100644
--- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/SaleVO.java
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/SaleVO.java
@@ -77,4 +77,7 @@ public class SaleVO implements Serializable {
@ApiModelProperty(value = "删除标识")
String delFlag;
+
+ @ApiModelProperty(value = "客户id(如果传了这,需要查询客户的购买数量)")
+ private String customerId;
}
\ No newline at end of file
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/ShopStockVo.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/ShopStockVo.java
index d05e645d..d209a113 100644
--- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/ShopStockVo.java
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/ShopStockVo.java
@@ -26,6 +26,9 @@ public class ShopStockVo {
@ApiModelProperty(value = "库存数")
private Integer stockCount;
+ @ApiModelProperty(value = "负库存数")
+ private Integer minusStockCount;
+
@ApiModelProperty(value = "库存成本")
private BigDecimal stockCost;
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/purchaseocr/service/impl/PurchaseOcrPictureServiceImpl.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/purchaseocr/service/impl/PurchaseOcrPictureServiceImpl.java
index 958122ec..edfd5056 100644
--- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/purchaseocr/service/impl/PurchaseOcrPictureServiceImpl.java
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/purchaseocr/service/impl/PurchaseOcrPictureServiceImpl.java
@@ -241,7 +241,7 @@ public class PurchaseOcrPictureServiceImpl implements PurchaseOcrPictureService
final String attributeList = object.getString("attributeList");
final JSONArray attributeListJsonArray = JSON.parseArray(attributeList);
// 根据货号去查询商品,如果
- final List byProductSn = productService.getByProductSn(productSn, shopId);
+ final List byProductSn = productService.getByProductSn(productSn, shopId,"");
if (byProductSn != null && !byProductSn.isEmpty()) {
// 原则上一个店铺一个货号对应一个商品,这里如果查到了,直接拿第一个。
final Product product = byProductSn.get(0);
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/ProductService.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/ProductService.java
index 916370e1..ea282740 100644
--- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/ProductService.java
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/ProductService.java
@@ -30,13 +30,13 @@ public interface ProductService extends IService {
*/
List getProductListOfShop();
- CopyOnWriteArrayList getByProductSn(String productSn, String shopId);
+ CopyOnWriteArrayList getByProductSn(String productSn, String shopId,String customerId);
ProductLastBuyVo getByUserIdAndProductId(String userId, String productId);
- Product getByIdOrBrcode(String id);
+ Product getByIdOrBrcode(String id,String customerId);
- List getByBarcode(String barcode);
+ List getByBarcode(String barcode, String customerId);
/**
* 删除分类时,根据分类id删除商品信息
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/SaleService.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/SaleService.java
index 6439371a..7b04fef4 100644
--- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/SaleService.java
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/SaleService.java
@@ -57,7 +57,7 @@ public interface SaleService extends IService {
void buyAiSync(String aiMsg, String saleId);
- JSONObject buyAi(String aiMsg);
+ JSONObject buyAi(String aiMsg, String customerId);
void updateAiFlag(String id, Integer status);
@@ -148,4 +148,14 @@ public interface SaleService extends IService {
* @date 2024/8/18
*/
Page totalAmountDetailByProduct(SalePageQuery salePageQuery);
+
+ /**
+ * 获取客户购买次数
+ *
+ * @param customerId
+ * @return Integer
+ * @author 王富康
+ * @date 2024/9/26
+ */
+ List buyCount(String customerId, List productIdList);
}
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/SalesAndDetailsServiceImpl.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/SalesAndDetailsServiceImpl.java
index 0d75401c..389a00e9 100644
--- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/SalesAndDetailsServiceImpl.java
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/SalesAndDetailsServiceImpl.java
@@ -507,6 +507,8 @@ public class SalesAndDetailsServiceImpl implements SalesAndDetailsService {
customer.setCity(saleQueryDTO.getSale().getCity());
customer.setArea(saleQueryDTO.getSale().getArea());
customer.setShopId(saleQueryDTO.getSale().getShopId());
+ customer.setCategoryId(saleQueryDTO.getCategoryId());
+ customer.setCategoryName(saleQueryDTO.getCategoryName());
customerService.save(customer);
// 客户id拿新增的
customerId = customer.getId();
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/ProductServiceImpl.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/ProductServiceImpl.java
index 5201a210..6f64ecf2 100644
--- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/ProductServiceImpl.java
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/ProductServiceImpl.java
@@ -7,6 +7,7 @@ import cc.hiver.core.entity.User;
import cc.hiver.mall.common.constant.PurchaseConstant;
import cc.hiver.mall.dao.mapper.ProductMapper;
import cc.hiver.mall.entity.Product;
+import cc.hiver.mall.entity.ProductAttributeValue;
import cc.hiver.mall.entity.Stock;
import cc.hiver.mall.pojo.dto.SaleDetailDTO;
import cc.hiver.mall.pojo.dto.SaleDetailQueryDTO;
@@ -15,9 +16,7 @@ import cc.hiver.mall.pojo.query.ProductPageQuery;
import cc.hiver.mall.pojo.vo.*;
import cc.hiver.mall.productpicture.entity.ProductPicture;
import cc.hiver.mall.productpicture.service.ProductPictureService;
-import cc.hiver.mall.service.mybatis.ProductCategoryService;
-import cc.hiver.mall.service.mybatis.ProductService;
-import cc.hiver.mall.service.mybatis.StockService;
+import cc.hiver.mall.service.mybatis.*;
import cc.hiver.mall.utils.DateUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
@@ -47,12 +46,18 @@ public class ProductServiceImpl extends ServiceImpl impl
@Autowired
private ProductCategoryService productCategoryService;
+ @Autowired
+ private ProductAttributeValueService productAttributeValueService;
+
@Autowired
private StockService stockService;
+ @Autowired
+ private SaleService saleService;
+
@Override
public IPage getShareList(ProductPageQuery productPageQuery) {
- if(StringUtils.isNotEmpty(productPageQuery.getEndDate())){
+ if (StringUtils.isNotEmpty(productPageQuery.getEndDate())) {
// 加一天
productPageQuery.setEndDate(DateUtil.addDay(productPageQuery.getEndDate(), 1));
}
@@ -62,8 +67,10 @@ public class ProductServiceImpl extends ServiceImpl impl
final List productIdList = new ArrayList<>();
for (ProductPageVO productPageVO : list) {
productIdList.add(productPageVO.getId());
+
}
- if(!productIdList.isEmpty()){
+
+ if (!productIdList.isEmpty()) {
// 获取子图
final List productPictureByProductIds = productPictureService.getProductPictureByProductIds(productIdList);
final Map> productPictureMap = new HashMap<>();
@@ -83,7 +90,7 @@ public class ProductServiceImpl extends ServiceImpl impl
}
}
// 获取商品均色均码的库存数
- List stockList = stockService.getDefaultStockCount(productIdList);
+ final List stockList = stockService.getDefaultStockCount(productIdList);
// 处理为map, key为productId
final Map stockMap = new HashMap<>();
for (Stock stock : stockList) {
@@ -93,10 +100,23 @@ public class ProductServiceImpl extends ServiceImpl impl
final String productId = productPageVO.getId();
if (stockMap.containsKey(productId)) {
productPageVO.setDefaultStockCount(stockMap.get(productId).getStockCount());
- }else{
+ } else {
productPageVO.setDefaultStockCount(0);
}
}
+ // 如果客户id不为空,查询客户的购买次数
+ if (StringUtils.isNotEmpty(productPageQuery.getCustomerId())) {
+ final List buyCount = saleService.buyCount(productPageQuery.getCustomerId(), productIdList);
+ // 封装为Map
+ final Map buyCountMap = new HashMap<>();
+ for (BuyCountVo buyCountVo : buyCount) {
+ buyCountMap.put(buyCountVo.getProductId(), buyCountVo.getBuyCount());
+ }
+ for (ProductPageVO productPageVO : list) {
+ final String productId = productPageVO.getId();
+ productPageVO.setBuyCount(buyCountMap.getOrDefault(productId, 0));
+ }
+ }
}
page.setRecords(list);
return page;
@@ -132,8 +152,25 @@ public class ProductServiceImpl extends ServiceImpl impl
}
@Override
- public CopyOnWriteArrayList getByProductSn(String productSn, String shopId) {
- return baseMapper.getByProductSn(productSn, shopId);
+ public CopyOnWriteArrayList getByProductSn(String productSn, String shopId, String customerId) {
+ final CopyOnWriteArrayList byProductSn = baseMapper.getByProductSn(productSn, shopId);
+ // 如果客户id不为空,查询客户的购买次数
+ if (StringUtils.isNotEmpty(customerId)) {
+
+ // 理论上来说一个货号在一个店铺中只会查询到一个商品信息
+ final List productIdList = new ArrayList<>();
+ productIdList.add(byProductSn.get(0).getId());
+ final List buyCount = saleService.buyCount(customerId, productIdList);
+ // 封装为Map
+ final Map buyCountMap = new HashMap<>();
+ for (BuyCountVo buyCountVo : buyCount) {
+ buyCountMap.put(buyCountVo.getProductId(), buyCountVo.getBuyCount());
+ }
+ for (Product product : byProductSn) {
+ product.setBuyCount(buyCountMap.getOrDefault(product.getId(), 0));
+ }
+ }
+ return byProductSn;
}
@Override
@@ -142,15 +179,46 @@ public class ProductServiceImpl extends ServiceImpl impl
}
@Override
- public Product getByIdOrBrcode(String id) {
- return baseMapper.getByIdOrBrcode(id);
+ public Product getByIdOrBrcode(String id, String customerId) {
+ final Product byIdOrBrcode = baseMapper.getByIdOrBrcode(id);
+ // 如果客户id不为空,查询客户的购买次数
+ if (StringUtils.isNotEmpty(customerId)) {
+ final List productIdList = new ArrayList<>();
+ productIdList.add(byIdOrBrcode.getId());
+ final List buyCount = saleService.buyCount(customerId, productIdList);
+ // 封装为Map
+ final Map buyCountMap = new HashMap<>();
+ for (BuyCountVo buyCountVo : buyCount) {
+ buyCountMap.put(buyCountVo.getProductId(), buyCountVo.getBuyCount());
+ }
+ byIdOrBrcode.setBuyCount(buyCountMap.getOrDefault(byIdOrBrcode.getId(), 0));
+ }
+ return byIdOrBrcode;
}
@Override
- public List getByBarcode(String barcode) {
+ public List getByBarcode(String barcode, String customerId) {
// shopId从缓存中设置
final String shopId = securityUtil.getShopId();
- return baseMapper.getByBarcode(barcode, shopId);
+ final List byBarcode = baseMapper.getByBarcode(barcode, shopId);
+ // 如果客户id不为空,查询客户的购买次数
+ if (StringUtils.isNotEmpty(customerId)) {
+ final List productIdList = new ArrayList<>();
+ for (Product product : byBarcode) {
+ productIdList.add(product.getId());
+ }
+ final List buyCount = saleService.buyCount(customerId, productIdList);
+ // 封装为Map
+ final Map buyCountMap = new HashMap<>();
+ for (BuyCountVo buyCountVo : buyCount) {
+ buyCountMap.put(buyCountVo.getProductId(), buyCountVo.getBuyCount());
+ }
+ for (Product product : byBarcode) {
+ final String productId = product.getId();
+ product.setBuyCount(buyCountMap.getOrDefault(productId, 0));
+ }
+ }
+ return byBarcode;
}
/**
@@ -177,7 +245,8 @@ public class ProductServiceImpl extends ServiceImpl impl
// 需要新增的商品
final List addProductList = new ArrayList<>();
final List addProductPictureList = new ArrayList<>();
-
+ // 需要新增的属性值集合
+ final List productAttributeValues = new ArrayList<>();
for (SaleDetailDTO saleDetailDTO : saleDetailList) {
// 需要新增的商品规格信息
final ProductCategoryVo productCategoryVo = new ProductCategoryVo();
@@ -188,17 +257,17 @@ public class ProductServiceImpl extends ServiceImpl impl
// shopId从缓存中设置
// 判断是否新的商品,新的商品进行新增
final String productId = saleDetailDTO.getProductId();
- if (StringUtils.isEmpty(productId) ) {
+ if (StringUtils.isEmpty(productId)) {
// 货号或者商品名称都为空的时候不新增,其他时候新增商品
if (StringUtils.isEmpty(saleDetailDTO.getProductSn()) && StringUtils.isEmpty(saleDetailDTO.getProductName())) {
continue;
}
// 根据货号查询商品是否存在
- CopyOnWriteArrayList oldProductListBySn = getByProductSn(saleDetailDTO.getProductSn(), shopId);
+ final CopyOnWriteArrayList oldProductListBySn = getByProductSn(saleDetailDTO.getProductSn(), shopId, "");
if (oldProductListBySn != null && !oldProductListBySn.isEmpty()) {
// 旧商品,赋值商品id
saleDetailDTO.setProductId(oldProductListBySn.get(0).getId());
- }else{
+ } else {
// 新增商品
final Product product = new Product();
product.setCreateBy(user.getId());
@@ -235,9 +304,9 @@ public class ProductServiceImpl extends ServiceImpl impl
for (SaleDetailQueryDTO saleDetailQueryDTO : stockLogList1) {
final String attributeList = saleDetailQueryDTO.getAttributeList();
final StringBuilder newAttributeList = new StringBuilder();
- newAttributeList.append("{");
- StringBuilder colorStr = new StringBuilder("\"颜色\":");
- StringBuilder sizeStr = new StringBuilder("\"尺码\":");
+ newAttributeList.append('{');
+ final StringBuilder colorStr = new StringBuilder("\"颜色\":");
+ final StringBuilder sizeStr = new StringBuilder("\"尺码\":");
final JSONObject jsonObject = JSONUtil.parseObj(attributeList);
for (Map.Entry stringObjectEntry : jsonObject.entrySet()) {
final String key = stringObjectEntry.getKey();
@@ -247,7 +316,7 @@ public class ProductServiceImpl extends ServiceImpl impl
if (!value.contains("色")) {
value += '色';
}
- colorStr.append('"' +value+ '"');
+ colorStr.append('"' + value + '"');
} else if ("尺码".equals(key)) {
final String valueUpperCase = value.toUpperCase();
if (value.contains("码")) {
@@ -255,7 +324,7 @@ public class ProductServiceImpl extends ServiceImpl impl
} else {
value = valueUpperCase + '码';
}
- sizeStr.append('"' +value+ '"');
+ sizeStr.append('"' + value + '"');
} else {
// 暂不支持其他规格
}
@@ -300,8 +369,103 @@ public class ProductServiceImpl extends ServiceImpl impl
product.setAttrId(s);
addProductList.add(product);
}
+ } else {
+ // 判断规格是否需要新增
+ final List categoryIdList = new ArrayList<>();
+ categoryIdList.add(saleDetailDTO.getAttrId());
+ // 获取商品下的规格
+ final List shopCategory = productCategoryService.getShopCategory(categoryIdList);
+ final ProductCategoryVo oldProductCategoryVo = shopCategory.get(0);
+ final List productAttributeOfAddVos = oldProductCategoryVo.getProductAttributeOfAddVos();
+ final Map productAttributeOfAddVoMap = new HashMap<>();
+ for (ProductAttributeOfAddVo productAttributeOfAddVo : productAttributeOfAddVos) {
+ productAttributeOfAddVoMap.put(productAttributeOfAddVo.getAttributeName(), productAttributeOfAddVo);
+ }
+ //获取颜色及规格进行拼接
+ List colorProductAttributeValueVoList = new ArrayList<>();
+ List sizeProductAttributeValueVoList = new ArrayList<>();
+ if (productAttributeOfAddVoMap.containsKey("颜色")) {
+ colorProductAttributeValueVoList = productAttributeOfAddVoMap.get("颜色").getProductAttributeValueVoList();
+ }
+ // 将所有颜色放到一个集合中
+ final CopyOnWriteArrayList colorList = new CopyOnWriteArrayList<>();
+ for (ProductAttributeValueVo productAttributeValueVo : colorProductAttributeValueVoList) {
+ colorList.add(productAttributeValueVo.getValue());
+ }
+ if (productAttributeOfAddVoMap.containsKey("尺码")) {
+ sizeProductAttributeValueVoList = productAttributeOfAddVoMap.get("尺码").getProductAttributeValueVoList();
+ }
+ // 将所有尺码放到一个集合中
+ final CopyOnWriteArrayList sizeList = new CopyOnWriteArrayList<>();
+ for (ProductAttributeValueVo productAttributeValueVo : sizeProductAttributeValueVoList) {
+ sizeList.add(productAttributeValueVo.getValue());
+ }
+ // 判断是否需要新增规格
+ // 将规格及规格下的规格值提取出来
+ final List stockLogList1 = saleDetailDTO.getStockLogList1();
+ for (SaleDetailQueryDTO saleDetailQueryDTO : stockLogList1) {
+ final String attributeList = saleDetailQueryDTO.getAttributeList();
+ final StringBuilder newAttributeList = new StringBuilder();
+ newAttributeList.append('{');
+ final StringBuilder colorStr = new StringBuilder("\"颜色\":");
+ final StringBuilder sizeStr = new StringBuilder("\"尺码\":");
+ final JSONObject jsonObject = JSONUtil.parseObj(attributeList);
+ for (Map.Entry stringObjectEntry : jsonObject.entrySet()) {
+ final String key = stringObjectEntry.getKey();
+ String value = String.valueOf(stringObjectEntry.getValue());
+ // 根据规格id规格是颜色、还是尺码。
+ if ("颜色".equals(key)) {
+ if (!value.contains("色")) {
+ value += '色';
+ }
+ colorStr.append('"' + value + '"');
+ // 判断该商品是否已包含该颜色,不包含,则需要新增
+ if (!colorList.contains(value)) {
+ final ProductAttributeValue productAttributeValue = new ProductAttributeValue();
+ final String attributeId = productAttributeOfAddVoMap.get("颜色").getAttributeId();
+ productAttributeValue.setAttributeId(attributeId);
+ productAttributeValue.setValue(value);
+ productAttributeValues.add(productAttributeValue);
+ }
+ } else if ("尺码".equals(key)) {
+ final String valueUpperCase = value.toUpperCase();
+ if (value.contains("码")) {
+ value = valueUpperCase;
+ } else {
+ value = valueUpperCase + '码';
+ }
+ sizeStr.append('"' + value + '"');
+ // 判断该商品是否已包含该尺码,不包含,则需要新增
+ if (!colorList.contains(value)) {
+ final ProductAttributeValue productAttributeValue = new ProductAttributeValue();
+ final String attributeId = productAttributeOfAddVoMap.get("尺码").getAttributeId();
+ productAttributeValue.setAttributeId(attributeId);
+ productAttributeValue.setValue(value);
+ productAttributeValues.add(productAttributeValue);
+ }
+ } else {
+ // 暂不支持其他规格
+ }
+ if (attributeValueMap.containsKey(key)) {
+ final List strings = attributeValueMap.get(key);
+ if (!strings.contains(value)) {
+ strings.add(value);
+ }
+ } else {
+ final List valueList = new ArrayList<>();
+ valueList.add(value);
+ attributeValueMap.put(key, valueList);
+ }
+ }
+ newAttributeList.append(colorStr);
+ newAttributeList.append(',');
+ newAttributeList.append(sizeStr);
+ newAttributeList.append('}');
+ saleDetailQueryDTO.setAttributeList(newAttributeList.toString());
+ }
}
}
+
if (!addProductList.isEmpty()) {
// 批量插入商品
productMapper.batchSaveProduct(addProductList);
@@ -310,6 +474,10 @@ public class ProductServiceImpl extends ServiceImpl impl
// 批量插入商品图片
productPictureService.batchSaveProductPicture(addProductPictureList);
}
+ //批量插入属性值
+ if (!productAttributeValues.isEmpty()) {
+ productAttributeValueService.saveBatch(productAttributeValues, productAttributeValues.size());
+ }
return saleQueryDTO;
}
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/SaleServiceImpl.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/SaleServiceImpl.java
index f41545cc..84206150 100644
--- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/SaleServiceImpl.java
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/SaleServiceImpl.java
@@ -58,7 +58,7 @@ import java.util.regex.Pattern;
public class SaleServiceImpl extends ServiceImpl implements SaleService {
private static final Pattern productSn = Pattern.compile("货号");
- private static final Pattern COMPILE = Pattern.compile("\\D+");
+ private static final Pattern COMPILE = Pattern.compile("-?\\d+");
private static final Pattern SYYS = Pattern.compile("所有颜色", Pattern.LITERAL);
private static final Pattern SYCM = Pattern.compile("所有尺码", Pattern.LITERAL);
@Autowired
@@ -174,6 +174,7 @@ public class SaleServiceImpl extends ServiceImpl implements Sa
}
final Page saleList = saleMapper.queryPage(page, saleVO);
// 获取订单详情信息
+ List productIdList = new ArrayList<>();
for (Sale sale : saleList.getRecords()) {
final QueryWrapper querySaleDetailWrapper = new QueryWrapper<>();
querySaleDetailWrapper.select("product_id")
@@ -181,6 +182,7 @@ public class SaleServiceImpl extends ServiceImpl implements Sa
.groupBy("product_id");
final List list = saleDetailService.selectByCondition1(querySaleDetailWrapper);
if (!list.isEmpty()) {
+ productIdList.addAll(list);
final List saleDetailDTOS = new ArrayList<>();
final Map productMap = new HashMap<>();
// 获取商品信息
@@ -219,11 +221,13 @@ public class SaleServiceImpl extends ServiceImpl implements Sa
saleDetailDTO.setRealPrice(saleDetail.getRealPrice());
// 回填商品的的图片及货号
if (productMap.containsKey(productId)) {
- BigDecimal purchasePrice = productMap.get(productId).getPurchasePrice() == null ? BigDecimal.ZERO : productMap.get(productId).getPurchasePrice();
+ final BigDecimal purchasePrice = productMap.get(productId).getPurchasePrice() == null ? BigDecimal.ZERO : productMap.get(productId).getPurchasePrice();
saleDetailDTO.setPurchasePrice(purchasePrice);
saleDetailDTO.setProductPicture(productMap.get(productId).getProductPicture());
saleDetailDTO.setProductSn(productMap.get(productId).getProductSn());
- }else{
+ saleDetailDTO.setAttrId(productMap.get(productId).getAttrId());
+ saleDetailDTO.setCustomerCategoryRule(productMap.get(productId).getCustomerCategoryRule());
+ } else {
saleDetailDTO.setPurchasePrice(saleDetail.getPurchasePrice());
}
@@ -244,6 +248,21 @@ public class SaleServiceImpl extends ServiceImpl implements Sa
sale.setSaleDetailDTOList(saleDetailDTOS);
}
}
+ // 如果客户id不为空,查询客户的购买次数
+ if (StringUtils.isNotEmpty(saleVO.getCustomerId())) {
+ final List buyCount = saleService.buyCount(saleVO.getCustomerId(), productIdList);
+ // 封装为Map
+ final Map buyCountMap = new HashMap<>();
+ for (BuyCountVo buyCountVo : buyCount) {
+ buyCountMap.put(buyCountVo.getProductId(), buyCountVo.getBuyCount());
+ }
+ for (Sale saleListRecord : saleList.getRecords()) {
+ for (SaleDetailDTO saleDetailDTO : saleListRecord.getSaleDetailDTOList()) {
+ String productId = saleDetailDTO.getProductId();
+ saleDetailDTO.setBuyCount(buyCountMap.getOrDefault(productId, 0));
+ }
+ }
+ }
return saleList;
}
@@ -303,7 +322,7 @@ public class SaleServiceImpl extends ServiceImpl implements Sa
queryPWrapper.in("sale_id", saleIdList);
final List saleDetailList = saleDetailService.list(queryPWrapper);
// 获取商品id
- List productIdList = new ArrayList<>();
+ final List productIdList = new ArrayList<>();
for (SaleDetail saleDetail : saleDetailList) {
productIdList.add(saleDetail.getProductId());
}
@@ -327,11 +346,11 @@ public class SaleServiceImpl extends ServiceImpl implements Sa
saleDetailDTO.setPrice(saleDetail.getPrice());
saleDetailDTO.setWholesalePrice(saleDetail.getWholesalePrice());
// 取商品的采购价
- if(productMap.containsKey(saleDetail.getProductId())){
- Product product = productMap.get(saleDetail.getProductId());
- BigDecimal purchasePrice = product.getPurchasePrice() == null ? BigDecimal.ZERO : product.getPurchasePrice();
+ if (productMap.containsKey(saleDetail.getProductId())) {
+ final Product product = productMap.get(saleDetail.getProductId());
+ final BigDecimal purchasePrice = product.getPurchasePrice() == null ? BigDecimal.ZERO : product.getPurchasePrice();
saleDetailDTO.setPurchasePrice(purchasePrice);
- }else{
+ } else {
saleDetailDTO.setPurchasePrice(saleDetail.getPurchasePrice());
}
@@ -640,7 +659,7 @@ public class SaleServiceImpl extends ServiceImpl implements Sa
}
@Override
- public JSONObject buyAi(String aiMsg) {
+ public JSONObject buyAi(String aiMsg, String customerId) {
final JSONObject returnJsonObject = new JSONObject();
// 叉转X 文本纠错 使用正则表达式替换单个或多个连续的“叉”字符
aiMsg = replaceAllX(aiMsg);
@@ -652,13 +671,15 @@ public class SaleServiceImpl extends ServiceImpl implements Sa
final JSONObject jsonObject = AliOcrUtil.callWithMessage(aiMsg);
final String resultContent = jsonObject.get("resultContent").toString();
final JSONArray json = JSON.parseArray(resultContent);
+ // 旧商品的id集合
+ List oldProductIdList = new ArrayList<>();
for (int i = 0; i < json.size(); i++) {
final JSONObject object = json.getJSONObject(i);
String productSn = object.getString("productSn");
// 尝试从货号中提取正确的货号,因为货号可能包含颜色等信息
productSn = CommonUtil.getProductSn(productSn);
final String attributeList = object.getString("attributeList");
- String wholesalePriceStr = object.getString("wholesalePrice");
+ final String wholesalePriceStr = object.getString("wholesalePrice");
BigDecimal wholesalePrice = BigDecimal.ZERO;
// 使用正则表达式提取数字部分
final Pattern pattern = Pattern.compile("-?\\d+(\\.\\d+)?");
@@ -672,11 +693,12 @@ public class SaleServiceImpl extends ServiceImpl implements Sa
// 定义一个map,货号为key,purchaseDetail 为value
final Map purchaseDetailMap = new HashMap<>();
// 根据货号去查询商品,如果
- final List byProductSn = productService.getByProductSn(productSn, shopId);
+ final List byProductSn = productService.getByProductSn(productSn, shopId,"");
if (byProductSn != null && !byProductSn.isEmpty()) {
// 原则上一个店铺一个货号对应一个商品,这里如果查到了,直接拿第一个。
final Product product = byProductSn.get(0);
final String productId = product.getId();
+ oldProductIdList.add(productId);
// 查询商品所有的库存
final List stockList = stockService.getProductStock(productId);
final Map stockMap = new HashMap<>();
@@ -704,6 +726,7 @@ public class SaleServiceImpl extends ServiceImpl implements Sa
saleDetailDTO.setProductSn(product.getProductSn());
saleDetailDTO.setProductCount(0);
saleDetailDTO.setSupplierName(product.getSupplierName());
+ saleDetailDTO.setAttrId(product.getAttrId());
final List saleDetailQueryDTOS = new ArrayList<>();
// 获取商品分类及规格信息
@@ -741,7 +764,12 @@ public class SaleServiceImpl extends ServiceImpl implements Sa
String color = attributeListObject.getString("color").toUpperCase();
String size = attributeListObject.getString("size").toUpperCase();
final String productCount1 = attributeListObject.getString("productCount");
- final int productCount = Integer.parseInt(COMPILE.matcher(productCount1).replaceAll(""));
+ final Matcher countMatchered = COMPILE.matcher(productCount1);
+ String replaced = "";
+ if (countMatchered.find()) {
+ replaced = countMatchered.group();
+ }
+ final int productCount = Integer.parseInt(StringUtils.isEmpty(replaced) ? "0" : replaced);
// 20240330 只能新增颜色和尺码,颜色统一改为*色、尺码统一转大写,加‘码’;
// 根据规格id规格是颜色、还是尺码。
if (!color.contains("色")) {
@@ -823,7 +851,12 @@ public class SaleServiceImpl extends ServiceImpl implements Sa
String color = attributeListObject.getString("color").toUpperCase();
String size = attributeListObject.getString("size").toUpperCase();
final String productCount1 = attributeListObject.getString("productCount");
- final int productCount = Integer.parseInt(COMPILE.matcher(productCount1).replaceAll(""));
+ final Matcher countMatchered = COMPILE.matcher(productCount1);
+ String replaced = "";
+ if (countMatchered.find()) {
+ replaced = countMatchered.group();
+ }
+ final int productCount = Integer.parseInt(StringUtils.isEmpty(replaced) ? "0" : replaced);
// 20240330 只能新增颜色和尺码,颜色统一改为*色、尺码统一转大写,加‘码’;
// 根据规格id规格是颜色、还是尺码。
if (!color.contains("色")) {
@@ -847,11 +880,27 @@ public class SaleServiceImpl extends ServiceImpl implements Sa
}
}
+ // 如果客户id不为空,那么就查询商品的购买记录
+ if(StringUtils.isNotEmpty(customerId)){
+ // 获取客户的购买次数
+ final List buyCount = buyCount(customerId,oldProductIdList);
+ // 封装为Map
+ final Map buyCountMap = new HashMap<>();
+ for (BuyCountVo buyCountVo : buyCount) {
+ buyCountMap.put(buyCountVo.getProductId(), buyCountVo.getBuyCount());
+ }
+ // 回填数据
+ for (SaleDetailDTO saleDetailDTO : saleDetailDTOS) {
+ final String productId = saleDetailDTO.getProductId();
+ saleDetailDTO.setBuyCount(buyCountMap.getOrDefault(productId, 0));
+ }
+ }
} catch (NoApiKeyException e) {
throw new RuntimeException(e);
} catch (InputRequiredException e) {
throw new RuntimeException(e);
}
+
returnJsonObject.put("data", saleDetailDTOS);
returnJsonObject.put("aiNotRecognition", String.join(";", aiNotRecognitionList));
return returnJsonObject;
@@ -1222,7 +1271,7 @@ public class SaleServiceImpl extends ServiceImpl implements Sa
// shopId从缓存中设置
final String shopId = securityUtil.getShopId();
salePageQuery.setShopId(shopId);
- Page totalAmountDetailByCustomerVoPage = saleMapper.totalAmountDetailByCustomer(page, salePageQuery);
+ final Page totalAmountDetailByCustomerVoPage = saleMapper.totalAmountDetailByCustomer(page, salePageQuery);
return totalAmountDetailByCustomerVoPage;
}
@@ -1245,10 +1294,23 @@ public class SaleServiceImpl extends ServiceImpl implements Sa
// shopId从缓存中设置
final String shopId = securityUtil.getShopId();
salePageQuery.setShopId(shopId);
- Page totalAmountDetailByProductVoPage = saleMapper.totalAmountDetailByProduct(page, salePageQuery);
+ final Page totalAmountDetailByProductVoPage = saleMapper.totalAmountDetailByProduct(page, salePageQuery);
return totalAmountDetailByProductVoPage;
}
+ /**
+ * 获取客户购买次数
+ *
+ * @param customerId
+ * @return Integer
+ * @author 王富康
+ * @date 2024/9/26
+ */
+ @Override
+ public List buyCount(String customerId, List productIdList) {
+ return saleMapper.buyCount(customerId,productIdList);
+ }
+
/**
* 使用正则表达式替换输入字符串中连续的“叉”字符为相应数量的“X”字符。
*
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 ed6e9192..c288e506 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
@@ -501,7 +501,9 @@ public class StockServiceImpl extends ServiceImpl implements
// 设置商品的批发价和零售价
product.setPrice(purchaseDetail.getLsPrice());
product.setWholesalePrice(purchaseDetail.getWholesalePrice());
- product.setCustomerCategoryRule(purchaseDetail.getCustomerCategoryRule());
+ if(!"[]".equals(purchaseDetail.getCustomerCategoryRule()) && !"null".equals(purchaseDetail.getCustomerCategoryRule())){
+ product.setCustomerCategoryRule(purchaseDetail.getCustomerCategoryRule());
+ }
// 保存商品供应商信息
updateProductList.add(product);
@@ -608,6 +610,7 @@ public class StockServiceImpl extends ServiceImpl implements
int tailWarnCount = 0;
// 4. 库存数
int stockCount = 0;
+ int minusStockCount = 0;
// 5. 库存成本
BigDecimal stockCost = new BigDecimal(0);
for (Stock stock : stockList) {
@@ -629,6 +632,9 @@ public class StockServiceImpl extends ServiceImpl implements
}
// 计算库存数
stockCount += thisStockCount > 0 ? thisStockCount : 0;
+ // 计算负库存总数
+ minusStockCount += thisStockCount < 0 ? thisStockCount : 0;
+
// 计算达到库存预警的规格数量
if (tailWarn != null && tailWarn > thisStockCount) {
tailWarnCount++;
@@ -636,6 +642,7 @@ public class StockServiceImpl extends ServiceImpl implements
}
shopStockVo.setTailWarnCount(tailWarnCount);
shopStockVo.setStockCount(stockCount);
+ shopStockVo.setMinusStockCount(minusStockCount);
shopStockVo.setStockCost(stockCost);
return shopStockVo;
}
@@ -779,7 +786,7 @@ public class StockServiceImpl extends ServiceImpl implements
// 20240824 增加货号判断是否为旧商品
// 根据货号查询商品是否存在
- CopyOnWriteArrayList oldProductListBySn = productService.getByProductSn(purchaseDetail.getProductSn(), shopId);
+ CopyOnWriteArrayList oldProductListBySn = productService.getByProductSn(purchaseDetail.getProductSn(), shopId,"");
if (oldProductListBySn != null && !oldProductListBySn.isEmpty()) {
// 旧商品,赋值商品id
purchaseDetail.setProductId(oldProductListBySn.get(0).getId());
@@ -813,7 +820,9 @@ public class StockServiceImpl extends ServiceImpl implements
product.setPrintBarcode(purchaseDetail.getPrintBarcode());
product.setTailWarn(purchaseDetail.getTailWarn());
product.setInStorageStatus(PurchaseConstant.IN_STORAGE_STATUS[1]);
- product.setCustomerCategoryRule(purchaseDetail.getCustomerCategoryRule());
+ if(!"[]".equals(purchaseDetail.getCustomerCategoryRule()) && !"null".equals(purchaseDetail.getCustomerCategoryRule())){
+ product.setCustomerCategoryRule(purchaseDetail.getCustomerCategoryRule());
+ }
addProductList.add(product);
// 放到要查询的id中
productIdList.add(product.getId());
@@ -1001,7 +1010,9 @@ public class StockServiceImpl extends ServiceImpl implements
product.setProductPicture(purchaseDetail.getProductPicture());
// 更新商品的名称
product.setProductName(purchaseDetail.getProductName());
- product.setCustomerCategoryRule(purchaseDetail.getCustomerCategoryRule());
+ if(!"[]".equals(purchaseDetail.getCustomerCategoryRule()) && !"null".equals(purchaseDetail.getCustomerCategoryRule())){
+ product.setCustomerCategoryRule(purchaseDetail.getCustomerCategoryRule());
+ }
updateProductList.add(product);
// 先计算平均采购价、再更新库存数,否则会有问题。
@@ -1190,9 +1201,9 @@ public class StockServiceImpl extends ServiceImpl implements
productService.saveOrUpdateBatch(updateProductList);
// 更新供应商欠款信息及欠款记录
//如果没有采购价 并且是普通用户的话,不保存记录
-// if(CollectionUtil.isNotEmpty(purchaseVo.getPurchaseDetails()) && purchaseVo.getPurchaseDetails().get(0).getPurchasePrice() == null && !user.getType().equals(UserConstant.USER_TYPE_NORMAL)) {
+ if(CollectionUtil.isNotEmpty(purchaseVo.getPurchaseDetails()) && purchaseVo.getPurchaseDetails().get(0).getPurchasePrice() == null && !user.getType().equals(UserConstant.USER_TYPE_NORMAL)) {
debtService.purchaseToDebt(purchase);
-// }
+ }
return ResultUtil.success("添加成功");
} else {
return ResultUtil.error("添加入库单商品规格信息失败");
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 f6d9ee06..ba81f4cf 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
@@ -945,7 +945,7 @@ public class AliOcrUtil {
msgManager.add(userMsg);
stopWatch.start("开始回答");
final QwenParam param =
- QwenParam.builder().model("qwen2-72b-instruct").messages(msgManager.get())
+ QwenParam.builder().model("qwen-turbo-0919").messages(msgManager.get())
.resultFormat(QwenParam.ResultFormat.MESSAGE)
.seed(1234)
.temperature(0.85F)
@@ -997,7 +997,7 @@ public class AliOcrUtil {
// 尝试从货号中提取正确的货号,因为货号可能包含颜色等信息
productSn = CommonUtil.getProductSn(productSn);
// 根据货号去查询商品
- final CopyOnWriteArrayList byProductSn = productService.getByProductSn(productSn, shopId);
+ final CopyOnWriteArrayList byProductSn = productService.getByProductSn(productSn, shopId,"");
if (byProductSn != null && !byProductSn.isEmpty()) {
// 原则上一个店铺一个货号对应一个商品,这里如果查到了,直接拿第一个。
final Product product = byProductSn.get(0);
@@ -1224,7 +1224,7 @@ public class AliOcrUtil {
msgManager.add(userMsg);
stopWatch.start("开始回答");
final QwenParam param =
- QwenParam.builder().model("qwen2-72b-instruct").messages(msgManager.get())
+ QwenParam.builder().model("qwen-turbo-0919").messages(msgManager.get())
.resultFormat(QwenParam.ResultFormat.MESSAGE)
.build();
final GenerationResult result = gen.call(param);
@@ -1267,7 +1267,7 @@ public class AliOcrUtil {
msgManager.add(userMsg);
stopWatch.start("开始回答");
final QwenParam param =
- QwenParam.builder().model("qwen2-72b-instruct").messages(msgManager.get())
+ QwenParam.builder().model("qwen-turbo-0919").messages(msgManager.get())
.resultFormat(QwenParam.ResultFormat.MESSAGE)
.build();
final GenerationResult result = gen.call(param);
diff --git a/hiver-modules/hiver-mall/src/main/resources/mapper/ProductCategoryMapper.xml b/hiver-modules/hiver-mall/src/main/resources/mapper/ProductCategoryMapper.xml
index cd1f20cc..10618aee 100644
--- a/hiver-modules/hiver-mall/src/main/resources/mapper/ProductCategoryMapper.xml
+++ b/hiver-modules/hiver-mall/src/main/resources/mapper/ProductCategoryMapper.xml
@@ -285,7 +285,8 @@
+
+
\ No newline at end of file