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