|
|
@ -7,10 +7,7 @@ import cc.hiver.mall.common.constant.PurchaseConstant; |
|
|
import cc.hiver.mall.config.thread.AiPurchaseThread; |
|
|
import cc.hiver.mall.config.thread.AiPurchaseThread; |
|
|
import cc.hiver.mall.config.thread.ThreadPoolConfiguration; |
|
|
import cc.hiver.mall.config.thread.ThreadPoolConfiguration; |
|
|
import cc.hiver.mall.entity.*; |
|
|
import cc.hiver.mall.entity.*; |
|
|
import cc.hiver.mall.pojo.vo.ProductAttributeOfAddVo; |
|
|
import cc.hiver.mall.pojo.vo.*; |
|
|
import cc.hiver.mall.pojo.vo.ProductAttributeValueVo; |
|
|
|
|
|
import cc.hiver.mall.pojo.vo.ProductCategoryVo; |
|
|
|
|
|
import cc.hiver.mall.pojo.vo.PurchaseVo; |
|
|
|
|
|
import cc.hiver.mall.purchaseocr.entity.PurchaseOcrPicture; |
|
|
import cc.hiver.mall.purchaseocr.entity.PurchaseOcrPicture; |
|
|
import cc.hiver.mall.purchaseocr.mapper.PurchaseOcrPictureMapper; |
|
|
import cc.hiver.mall.purchaseocr.mapper.PurchaseOcrPictureMapper; |
|
|
import cc.hiver.mall.purchaseocr.service.PurchaseOcrPictureService; |
|
|
import cc.hiver.mall.purchaseocr.service.PurchaseOcrPictureService; |
|
|
@ -77,6 +74,9 @@ public class PurchaseOcrPictureServiceImpl implements PurchaseOcrPictureService |
|
|
@Autowired |
|
|
@Autowired |
|
|
private ProductCategoryService productCategoryService; |
|
|
private ProductCategoryService productCategoryService; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private SaleService saleService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public JSONObject batchSave(PurchaseOciPictureAddVo purchaseOciPictureAddVo) { |
|
|
public JSONObject batchSave(PurchaseOciPictureAddVo purchaseOciPictureAddVo) { |
|
|
@ -180,7 +180,7 @@ public class PurchaseOcrPictureServiceImpl implements PurchaseOcrPictureService |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public JSONObject callWithMessageOfPurchase(String questionMsg) throws NoApiKeyException, InputRequiredException { |
|
|
public JSONObject callWithMessageOfPurchase(String questionMsg, String customerId, String singleProductId) throws NoApiKeyException, InputRequiredException { |
|
|
|
|
|
|
|
|
final JSONObject returnJsonObject = new JSONObject(); |
|
|
final JSONObject returnJsonObject = new JSONObject(); |
|
|
final StopWatch stopWatch = new StopWatch("Ai入库计时:"); |
|
|
final StopWatch stopWatch = new StopWatch("Ai入库计时:"); |
|
|
@ -210,7 +210,8 @@ public class PurchaseOcrPictureServiceImpl implements PurchaseOcrPictureService |
|
|
final JSONObject jsonObject = AliOcrUtil.callWithMessageOfPurchase(saleAiMsg.getAiMsg()); |
|
|
final JSONObject jsonObject = AliOcrUtil.callWithMessageOfPurchase(saleAiMsg.getAiMsg()); |
|
|
final String resultContent = jsonObject.get("resultContent").toString(); |
|
|
final String resultContent = jsonObject.get("resultContent").toString(); |
|
|
final JSONArray json = JSON.parseArray(resultContent); |
|
|
final JSONArray json = JSON.parseArray(resultContent); |
|
|
|
|
|
// 旧商品的id集合
|
|
|
|
|
|
List<String> oldProductIdList = new ArrayList<>(); |
|
|
for (int i = 0; i < json.size(); i++) { |
|
|
for (int i = 0; i < json.size(); i++) { |
|
|
final JSONObject object = json.getJSONObject(i); |
|
|
final JSONObject object = json.getJSONObject(i); |
|
|
String productSn = object.getString("productSn"); |
|
|
String productSn = object.getString("productSn"); |
|
|
@ -242,10 +243,18 @@ public class PurchaseOcrPictureServiceImpl implements PurchaseOcrPictureService |
|
|
final JSONArray attributeListJsonArray = JSON.parseArray(attributeList); |
|
|
final JSONArray attributeListJsonArray = JSON.parseArray(attributeList); |
|
|
// 根据货号去查询商品,如果
|
|
|
// 根据货号去查询商品,如果
|
|
|
final List<Product> byProductSn = productService.getByProductSn(productSn, shopId,""); |
|
|
final List<Product> byProductSn = productService.getByProductSn(productSn, shopId,""); |
|
|
if (byProductSn != null && !byProductSn.isEmpty()) { |
|
|
if (StringUtils.isNotEmpty(singleProductId) || (byProductSn != null && !byProductSn.isEmpty())) { |
|
|
// 原则上一个店铺一个货号对应一个商品,这里如果查到了,直接拿第一个。
|
|
|
// 原则上一个店铺一个货号对应一个商品,这里如果查到了,直接拿第一个。
|
|
|
final Product product = byProductSn.get(0); |
|
|
Product product = new Product(); |
|
|
final String productId = product.getId(); |
|
|
if(!byProductSn.isEmpty()){ |
|
|
|
|
|
product = byProductSn.get(0); |
|
|
|
|
|
} |
|
|
|
|
|
if(StringUtils.isNotEmpty(singleProductId)){ |
|
|
|
|
|
// 20240928 app/sale/buyAi接口加个参数productId,如果传值了,查规格库存数的时候就查这款商品的
|
|
|
|
|
|
product = productService.getById(singleProductId); |
|
|
|
|
|
} |
|
|
|
|
|
String productId = product.getId(); |
|
|
|
|
|
oldProductIdList.add(productId); |
|
|
// 查询商品所有的库存
|
|
|
// 查询商品所有的库存
|
|
|
final List<Stock> stockList = stockService.getProductStock(productId); |
|
|
final List<Stock> stockList = stockService.getProductStock(productId); |
|
|
final Map<String, Integer> stockMap = new HashMap<>(); |
|
|
final Map<String, Integer> stockMap = new HashMap<>(); |
|
|
@ -385,6 +394,19 @@ public class PurchaseOcrPictureServiceImpl implements PurchaseOcrPictureService |
|
|
stockLogList.add(stockLog); |
|
|
stockLogList.add(stockLog); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
// 如果客户id不为空,那么就查询商品的购买记录
|
|
|
|
|
|
if(StringUtils.isNotEmpty(customerId)){ |
|
|
|
|
|
// 获取客户的购买次数
|
|
|
|
|
|
final List<BuyCountVo> buyCount = saleService.buyCount(customerId,oldProductIdList); |
|
|
|
|
|
// 封装为Map
|
|
|
|
|
|
final Map<String, Integer> buyCountMap = new HashMap<>(); |
|
|
|
|
|
for (BuyCountVo buyCountVo : buyCount) { |
|
|
|
|
|
buyCountMap.put(buyCountVo.getProductId(), buyCountVo.getBuyCount()); |
|
|
|
|
|
} |
|
|
|
|
|
// 回填数据
|
|
|
|
|
|
final String thisProductId = purchaseDetail.getProductId(); |
|
|
|
|
|
purchaseDetail.setBuyCount(buyCountMap.getOrDefault(thisProductId, 0)); |
|
|
|
|
|
} |
|
|
// 判断是否存在改货号,如果不存在,新增,存在,则追加stockLogList
|
|
|
// 判断是否存在改货号,如果不存在,新增,存在,则追加stockLogList
|
|
|
if (purchaseDetailMap.containsKey(productSn)) { |
|
|
if (purchaseDetailMap.containsKey(productSn)) { |
|
|
final PurchaseDetail addPurchaseDetail = purchaseDetailMap.get(productSn); |
|
|
final PurchaseDetail addPurchaseDetail = purchaseDetailMap.get(productSn); |
|
|
@ -450,6 +472,7 @@ public class PurchaseOcrPictureServiceImpl implements PurchaseOcrPictureService |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} catch (NoApiKeyException e) { |
|
|
} catch (NoApiKeyException e) { |
|
|
throw new RuntimeException(e); |
|
|
throw new RuntimeException(e); |
|
|
} catch (InputRequiredException e) { |
|
|
} catch (InputRequiredException e) { |
|
|
|