|
|
|
@ -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<ProductMapper, Product> impl |
|
|
|
@Autowired |
|
|
|
private ProductCategoryService productCategoryService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ProductAttributeValueService productAttributeValueService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private StockService stockService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private SaleService saleService; |
|
|
|
|
|
|
|
@Override |
|
|
|
public IPage<ProductPageVO> 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<ProductMapper, Product> impl |
|
|
|
final List<String> productIdList = new ArrayList<>(); |
|
|
|
for (ProductPageVO productPageVO : list) { |
|
|
|
productIdList.add(productPageVO.getId()); |
|
|
|
|
|
|
|
} |
|
|
|
if(!productIdList.isEmpty()){ |
|
|
|
|
|
|
|
if (!productIdList.isEmpty()) { |
|
|
|
// 获取子图
|
|
|
|
final List<ProductPicture> productPictureByProductIds = productPictureService.getProductPictureByProductIds(productIdList); |
|
|
|
final Map<String, List<ProductPicture>> productPictureMap = new HashMap<>(); |
|
|
|
@ -83,7 +90,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl |
|
|
|
} |
|
|
|
} |
|
|
|
// 获取商品均色均码的库存数
|
|
|
|
List<Stock> stockList = stockService.getDefaultStockCount(productIdList); |
|
|
|
final List<Stock> stockList = stockService.getDefaultStockCount(productIdList); |
|
|
|
// 处理为map, key为productId
|
|
|
|
final Map<String, Stock> stockMap = new HashMap<>(); |
|
|
|
for (Stock stock : stockList) { |
|
|
|
@ -93,10 +100,23 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> 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<BuyCountVo> buyCount = saleService.buyCount(productPageQuery.getCustomerId(), productIdList); |
|
|
|
// 封装为Map
|
|
|
|
final Map<String, Integer> 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<ProductMapper, Product> impl |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public CopyOnWriteArrayList<Product> getByProductSn(String productSn, String shopId) { |
|
|
|
return baseMapper.getByProductSn(productSn, shopId); |
|
|
|
public CopyOnWriteArrayList<Product> getByProductSn(String productSn, String shopId, String customerId) { |
|
|
|
final CopyOnWriteArrayList<Product> byProductSn = baseMapper.getByProductSn(productSn, shopId); |
|
|
|
// 如果客户id不为空,查询客户的购买次数
|
|
|
|
if (StringUtils.isNotEmpty(customerId)) { |
|
|
|
|
|
|
|
// 理论上来说一个货号在一个店铺中只会查询到一个商品信息
|
|
|
|
final List<String> productIdList = new ArrayList<>(); |
|
|
|
productIdList.add(byProductSn.get(0).getId()); |
|
|
|
final List<BuyCountVo> buyCount = saleService.buyCount(customerId, productIdList); |
|
|
|
// 封装为Map
|
|
|
|
final Map<String, Integer> 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<ProductMapper, Product> 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<String> productIdList = new ArrayList<>(); |
|
|
|
productIdList.add(byIdOrBrcode.getId()); |
|
|
|
final List<BuyCountVo> buyCount = saleService.buyCount(customerId, productIdList); |
|
|
|
// 封装为Map
|
|
|
|
final Map<String, Integer> 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<Product> getByBarcode(String barcode) { |
|
|
|
public List<Product> getByBarcode(String barcode, String customerId) { |
|
|
|
// shopId从缓存中设置
|
|
|
|
final String shopId = securityUtil.getShopId(); |
|
|
|
return baseMapper.getByBarcode(barcode, shopId); |
|
|
|
final List<Product> byBarcode = baseMapper.getByBarcode(barcode, shopId); |
|
|
|
// 如果客户id不为空,查询客户的购买次数
|
|
|
|
if (StringUtils.isNotEmpty(customerId)) { |
|
|
|
final List<String> productIdList = new ArrayList<>(); |
|
|
|
for (Product product : byBarcode) { |
|
|
|
productIdList.add(product.getId()); |
|
|
|
} |
|
|
|
final List<BuyCountVo> buyCount = saleService.buyCount(customerId, productIdList); |
|
|
|
// 封装为Map
|
|
|
|
final Map<String, Integer> 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<ProductMapper, Product> impl |
|
|
|
// 需要新增的商品
|
|
|
|
final List<Product> addProductList = new ArrayList<>(); |
|
|
|
final List<ProductPicture> addProductPictureList = new ArrayList<>(); |
|
|
|
|
|
|
|
// 需要新增的属性值集合
|
|
|
|
final List<ProductAttributeValue> productAttributeValues = new ArrayList<>(); |
|
|
|
for (SaleDetailDTO saleDetailDTO : saleDetailList) { |
|
|
|
// 需要新增的商品规格信息
|
|
|
|
final ProductCategoryVo productCategoryVo = new ProductCategoryVo(); |
|
|
|
@ -188,17 +257,17 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> 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<Product> oldProductListBySn = getByProductSn(saleDetailDTO.getProductSn(), shopId); |
|
|
|
final CopyOnWriteArrayList<Product> 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<ProductMapper, Product> 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<String, Object> stringObjectEntry : jsonObject.entrySet()) { |
|
|
|
final String key = stringObjectEntry.getKey(); |
|
|
|
@ -247,7 +316,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> 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<ProductMapper, Product> impl |
|
|
|
} else { |
|
|
|
value = valueUpperCase + '码'; |
|
|
|
} |
|
|
|
sizeStr.append('"' +value+ '"'); |
|
|
|
sizeStr.append('"' + value + '"'); |
|
|
|
} else { |
|
|
|
// 暂不支持其他规格
|
|
|
|
} |
|
|
|
@ -300,8 +369,103 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl |
|
|
|
product.setAttrId(s); |
|
|
|
addProductList.add(product); |
|
|
|
} |
|
|
|
} else { |
|
|
|
// 判断规格是否需要新增
|
|
|
|
final List<String> categoryIdList = new ArrayList<>(); |
|
|
|
categoryIdList.add(saleDetailDTO.getAttrId()); |
|
|
|
// 获取商品下的规格
|
|
|
|
final List<ProductCategoryVo> shopCategory = productCategoryService.getShopCategory(categoryIdList); |
|
|
|
final ProductCategoryVo oldProductCategoryVo = shopCategory.get(0); |
|
|
|
final List<ProductAttributeOfAddVo> productAttributeOfAddVos = oldProductCategoryVo.getProductAttributeOfAddVos(); |
|
|
|
final Map<String, ProductAttributeOfAddVo> productAttributeOfAddVoMap = new HashMap<>(); |
|
|
|
for (ProductAttributeOfAddVo productAttributeOfAddVo : productAttributeOfAddVos) { |
|
|
|
productAttributeOfAddVoMap.put(productAttributeOfAddVo.getAttributeName(), productAttributeOfAddVo); |
|
|
|
} |
|
|
|
//获取颜色及规格进行拼接
|
|
|
|
List<ProductAttributeValueVo> colorProductAttributeValueVoList = new ArrayList<>(); |
|
|
|
List<ProductAttributeValueVo> sizeProductAttributeValueVoList = new ArrayList<>(); |
|
|
|
if (productAttributeOfAddVoMap.containsKey("颜色")) { |
|
|
|
colorProductAttributeValueVoList = productAttributeOfAddVoMap.get("颜色").getProductAttributeValueVoList(); |
|
|
|
} |
|
|
|
// 将所有颜色放到一个集合中
|
|
|
|
final CopyOnWriteArrayList<String> colorList = new CopyOnWriteArrayList<>(); |
|
|
|
for (ProductAttributeValueVo productAttributeValueVo : colorProductAttributeValueVoList) { |
|
|
|
colorList.add(productAttributeValueVo.getValue()); |
|
|
|
} |
|
|
|
if (productAttributeOfAddVoMap.containsKey("尺码")) { |
|
|
|
sizeProductAttributeValueVoList = productAttributeOfAddVoMap.get("尺码").getProductAttributeValueVoList(); |
|
|
|
} |
|
|
|
// 将所有尺码放到一个集合中
|
|
|
|
final CopyOnWriteArrayList<String> sizeList = new CopyOnWriteArrayList<>(); |
|
|
|
for (ProductAttributeValueVo productAttributeValueVo : sizeProductAttributeValueVoList) { |
|
|
|
sizeList.add(productAttributeValueVo.getValue()); |
|
|
|
} |
|
|
|
// 判断是否需要新增规格
|
|
|
|
// 将规格及规格下的规格值提取出来
|
|
|
|
final List<SaleDetailQueryDTO> 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<String, Object> 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<String> strings = attributeValueMap.get(key); |
|
|
|
if (!strings.contains(value)) { |
|
|
|
strings.add(value); |
|
|
|
} |
|
|
|
} else { |
|
|
|
final List<String> 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<ProductMapper, Product> impl |
|
|
|
// 批量插入商品图片
|
|
|
|
productPictureService.batchSaveProductPicture(addProductPictureList); |
|
|
|
} |
|
|
|
//批量插入属性值
|
|
|
|
if (!productAttributeValues.isEmpty()) { |
|
|
|
productAttributeValueService.saveBatch(productAttributeValues, productAttributeValues.size()); |
|
|
|
} |
|
|
|
return saleQueryDTO; |
|
|
|
} |
|
|
|
|
|
|
|
|