|
|
|
@ -4,14 +4,17 @@ import cc.hiver.core.common.constant.ProductConstant; |
|
|
|
import cc.hiver.core.common.utils.SecurityUtil; |
|
|
|
import cc.hiver.core.common.utils.StringUtils; |
|
|
|
import cc.hiver.core.entity.User; |
|
|
|
import cc.hiver.mall.checkstock.pojo.CheckStockPageQuery; |
|
|
|
import cc.hiver.mall.checkstock.service.CheckStockService; |
|
|
|
import cc.hiver.mall.checkstock.vo.CheckStockAttributeVo; |
|
|
|
import cc.hiver.mall.checkstock.vo.CheckStockDetailVo; |
|
|
|
import cc.hiver.mall.checkstock.vo.CheckStockPageVo; |
|
|
|
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; |
|
|
|
import cc.hiver.mall.pojo.dto.SaleQueryDTO; |
|
|
|
import cc.hiver.mall.pojo.dto.*; |
|
|
|
import cc.hiver.mall.pojo.query.ProductPageQuery; |
|
|
|
import cc.hiver.mall.pojo.vo.*; |
|
|
|
import cc.hiver.mall.productpicture.entity.ProductPicture; |
|
|
|
@ -55,6 +58,9 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl |
|
|
|
@Autowired |
|
|
|
private SaleService saleService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private CheckStockService checkStockService; |
|
|
|
|
|
|
|
@Override |
|
|
|
public IPage<ProductPageVO> getShareList(ProductPageQuery productPageQuery) { |
|
|
|
if (StringUtils.isNotEmpty(productPageQuery.getEndDate())) { |
|
|
|
@ -117,6 +123,25 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl |
|
|
|
productPageVO.setBuyCount(buyCountMap.getOrDefault(productId, 0)); |
|
|
|
} |
|
|
|
} |
|
|
|
// 增加盘点信息
|
|
|
|
if (StringUtils.isNotEmpty(productPageQuery.getCheckStockId())) { |
|
|
|
final CheckStockPageQuery checkStockPageQuery = new CheckStockPageQuery(); |
|
|
|
checkStockPageQuery.setCheckStockId(productPageQuery.getCheckStockId()); |
|
|
|
checkStockPageQuery.setProductIdList(productIdList); |
|
|
|
checkStockPageQuery.setPageSize(200); |
|
|
|
final CheckStockPageVo checkStock = checkStockService.getCheckStock(checkStockPageQuery); |
|
|
|
final Page<CheckStockDetailVo> checkStockDetailVoList = checkStock.getCheckStockDetailVoList(); |
|
|
|
final Map<String, List<CheckStockAttributeVo>> checkStockAttributeVoMap = new HashMap<>(); |
|
|
|
for (CheckStockDetailVo record : checkStockDetailVoList.getRecords()) { |
|
|
|
checkStockAttributeVoMap.put(record.getProductId(), record.getCheckStockAttributeVos()); |
|
|
|
} |
|
|
|
for (ProductPageVO productPageVO : list) { |
|
|
|
final String productId = productPageVO.getId(); |
|
|
|
if (checkStockAttributeVoMap.containsKey(productId)) { |
|
|
|
productPageVO.setCheckStockAttributeVos(checkStockAttributeVoMap.get(productId)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
page.setRecords(list); |
|
|
|
return page; |
|
|
|
@ -475,7 +500,229 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// 20241110 新商品直接退货的也需要判断时是否需要新增商品
|
|
|
|
SaleReturnDTO saleReturnDTO = saleQueryDTO.getSaleReturnDTO(); |
|
|
|
if(saleReturnDTO != null){ |
|
|
|
List<ReturnSaleDetailDTO> returnSaleDetailList = saleReturnDTO.getReturnSaleDetailList(); |
|
|
|
for (ReturnSaleDetailDTO returnSaleDetailDTO : returnSaleDetailList) { |
|
|
|
// 需要新增的商品规格信息
|
|
|
|
final ProductCategoryVo productCategoryVo = new ProductCategoryVo(); |
|
|
|
productCategoryVo.setShopId("spfl"); |
|
|
|
// 需要新增的
|
|
|
|
final Map<String, List<String>> attributeValueMap = new HashMap<>(); |
|
|
|
|
|
|
|
// shopId从缓存中设置
|
|
|
|
// 判断是否新的商品,新的商品进行新增
|
|
|
|
final String productId = returnSaleDetailDTO.getProductId(); |
|
|
|
if (StringUtils.isEmpty(productId)) { |
|
|
|
// 货号或者商品名称都为空的时候不新增,其他时候新增商品
|
|
|
|
if (StringUtils.isEmpty(returnSaleDetailDTO.getProductSn()) && StringUtils.isEmpty(returnSaleDetailDTO.getProductName())) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
// 根据货号查询商品是否存在
|
|
|
|
final CopyOnWriteArrayList<Product> oldProductListBySn = getByProductSn(returnSaleDetailDTO.getProductSn(), shopId, ""); |
|
|
|
if (oldProductListBySn != null && !oldProductListBySn.isEmpty()) { |
|
|
|
// 旧商品,赋值商品id
|
|
|
|
returnSaleDetailDTO.setProductId(oldProductListBySn.get(0).getId()); |
|
|
|
} else { |
|
|
|
// 新增商品
|
|
|
|
final Product product = new Product(); |
|
|
|
product.setCreateBy(user.getId()); |
|
|
|
product.setCreateTime(new Date()); |
|
|
|
product.setProductName(returnSaleDetailDTO.getProductName()); |
|
|
|
product.setShopId(shopId); |
|
|
|
// 默认为已上架的
|
|
|
|
product.setDelFlag(ProductConstant.DEL_FLAG[1]); |
|
|
|
product.setCategoryId(returnSaleDetailDTO.getCategoryId()); |
|
|
|
product.setSupplierName(returnSaleDetailDTO.getSupplierName()); |
|
|
|
product.setProductSn(returnSaleDetailDTO.getProductSn()); |
|
|
|
// 零售价
|
|
|
|
product.setPrice(returnSaleDetailDTO.getPrice()); |
|
|
|
// 采购价
|
|
|
|
product.setPurchasePrice(returnSaleDetailDTO.getPurchasePrice()); |
|
|
|
// 批发价
|
|
|
|
product.setWholesalePrice(returnSaleDetailDTO.getWholesalePrice()); |
|
|
|
product.setProductPicture(returnSaleDetailDTO.getProductPicture()); |
|
|
|
product.setInStorageStatus(PurchaseConstant.IN_STORAGE_STATUS[1]); |
|
|
|
|
|
|
|
// 放到要查询的id中
|
|
|
|
// 填充前台传过来的数据
|
|
|
|
returnSaleDetailDTO.setProductId(product.getId()); |
|
|
|
if (returnSaleDetailDTO.getProductPictures() != null) { |
|
|
|
// 新增商品图片子图
|
|
|
|
for (ProductPicture productPicture : returnSaleDetailDTO.getProductPictures()) { |
|
|
|
productPicture.setProductId(product.getId()); |
|
|
|
} |
|
|
|
addProductPictureList.addAll(returnSaleDetailDTO.getProductPictures()); |
|
|
|
} |
|
|
|
|
|
|
|
// 将规格及规格下的规格值提取出来
|
|
|
|
final List<SaleDetailQueryDTO> stockLogList1 = returnSaleDetailDTO.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 + '"'); |
|
|
|
} else if ("尺码".equals(key)) { |
|
|
|
final String valueUpperCase = value.toUpperCase(); |
|
|
|
if (value.contains("码")) { |
|
|
|
value = valueUpperCase; |
|
|
|
} else { |
|
|
|
value = valueUpperCase + '码'; |
|
|
|
} |
|
|
|
sizeStr.append('"' + value + '"'); |
|
|
|
} 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()); |
|
|
|
} |
|
|
|
final CopyOnWriteArrayList<ProductAttributeOfAddVo> productAttributeOfAddVos = new CopyOnWriteArrayList<>(); |
|
|
|
for (Map.Entry<String, List<String>> stringListEntry : attributeValueMap.entrySet()) { |
|
|
|
final String key = stringListEntry.getKey(); |
|
|
|
final List<String> entryValue = stringListEntry.getValue(); |
|
|
|
final ProductAttributeOfAddVo productAttributeOfAddVo = new ProductAttributeOfAddVo(); |
|
|
|
productAttributeOfAddVo.setAttributeName(key); |
|
|
|
final CopyOnWriteArrayList<ProductAttributeValueVo> productAttributeValueVoList = new CopyOnWriteArrayList<>(); |
|
|
|
for (String s : entryValue) { |
|
|
|
final ProductAttributeValueVo productAttributeValueVo = new ProductAttributeValueVo(); |
|
|
|
productAttributeValueVo.setValue(s); |
|
|
|
productAttributeValueVoList.add(productAttributeValueVo); |
|
|
|
} |
|
|
|
productAttributeOfAddVo.setProductAttributeValueVoList(productAttributeValueVoList); |
|
|
|
productAttributeOfAddVos.add(productAttributeOfAddVo); |
|
|
|
} |
|
|
|
productCategoryVo.setProductAttributeOfAddVos(productAttributeOfAddVos); |
|
|
|
// 批量去新增,并拿到分类id,回填商品
|
|
|
|
// 维护该商品专属分类
|
|
|
|
final String s = productCategoryService.batchSaveCategoryAndAttribute(productCategoryVo); |
|
|
|
// 维护该店铺的专属分类
|
|
|
|
productCategoryService.batchSaveCategoryOfShop(productCategoryVo); |
|
|
|
product.setAttrId(s); |
|
|
|
addProductList.add(product); |
|
|
|
} |
|
|
|
} else { |
|
|
|
// 判断规格是否需要新增
|
|
|
|
final List<String> categoryIdList = new ArrayList<>(); |
|
|
|
categoryIdList.add(returnSaleDetailDTO.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 = returnSaleDetailDTO.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 (!sizeList.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); |
|
|
|
|