|
|
@ -1,41 +1,55 @@ |
|
|
package cc.hiver.mall.purchaseocr.service.impl; |
|
|
package cc.hiver.mall.purchaseocr.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import cc.hiver.core.common.utils.CommonUtil; |
|
|
import cc.hiver.core.common.utils.SecurityUtil; |
|
|
import cc.hiver.core.common.utils.SecurityUtil; |
|
|
import cc.hiver.core.entity.User; |
|
|
import cc.hiver.core.entity.User; |
|
|
import cc.hiver.mall.common.constant.PurchaseConstant; |
|
|
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.Purchase; |
|
|
import cc.hiver.mall.entity.*; |
|
|
import cc.hiver.mall.entity.Shop; |
|
|
import cc.hiver.mall.pojo.vo.ProductAttributeOfAddVo; |
|
|
|
|
|
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; |
|
|
import cc.hiver.mall.purchaseocr.vo.PurchaseOciPictureAddVo; |
|
|
import cc.hiver.mall.purchaseocr.vo.PurchaseOciPictureAddVo; |
|
|
import cc.hiver.mall.purchaseocr.vo.PurchaseOcrCountVo; |
|
|
import cc.hiver.mall.purchaseocr.vo.PurchaseOcrCountVo; |
|
|
import cc.hiver.mall.purchaseocr.vo.PurchaseOcrExample; |
|
|
import cc.hiver.mall.purchaseocr.vo.PurchaseOcrExample; |
|
|
|
|
|
import cc.hiver.mall.saleaimsg.entity.SaleAiMsg; |
|
|
import cc.hiver.mall.service.ShopService; |
|
|
import cc.hiver.mall.service.ShopService; |
|
|
import cc.hiver.mall.service.mybatis.ProductService; |
|
|
import cc.hiver.mall.service.mybatis.*; |
|
|
import cc.hiver.mall.service.mybatis.PurchaseDetailService; |
|
|
|
|
|
import cc.hiver.mall.service.mybatis.PurchaseService; |
|
|
|
|
|
import cc.hiver.mall.utils.AliOcrUtil; |
|
|
import cc.hiver.mall.utils.AliOcrUtil; |
|
|
|
|
|
import cn.hutool.core.date.StopWatch; |
|
|
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationResult; |
|
|
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationResult; |
|
|
import com.alibaba.dashscope.exception.InputRequiredException; |
|
|
import com.alibaba.dashscope.exception.InputRequiredException; |
|
|
import com.alibaba.dashscope.exception.NoApiKeyException; |
|
|
import com.alibaba.dashscope.exception.NoApiKeyException; |
|
|
import com.alibaba.dashscope.exception.UploadFileException; |
|
|
import com.alibaba.dashscope.exception.UploadFileException; |
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
import java.util.Date; |
|
|
import java.math.BigDecimal; |
|
|
import java.util.List; |
|
|
import java.util.*; |
|
|
import java.util.concurrent.CopyOnWriteArrayList; |
|
|
import java.util.concurrent.CopyOnWriteArrayList; |
|
|
|
|
|
import java.util.regex.Matcher; |
|
|
|
|
|
import java.util.regex.Pattern; |
|
|
|
|
|
|
|
|
@Slf4j |
|
|
@Slf4j |
|
|
@Service |
|
|
@Service |
|
|
public class PurchaseOcrPictureServiceImpl implements PurchaseOcrPictureService { |
|
|
public class PurchaseOcrPictureServiceImpl implements PurchaseOcrPictureService { |
|
|
|
|
|
|
|
|
|
|
|
private static final Pattern productSn = Pattern.compile("货号"); |
|
|
|
|
|
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 |
|
|
@Autowired |
|
|
private PurchaseOcrPictureMapper purchaseOcrPictureMapper; |
|
|
private PurchaseOcrPictureMapper purchaseOcrPictureMapper; |
|
|
|
|
|
|
|
|
@ -60,6 +74,12 @@ public class PurchaseOcrPictureServiceImpl implements PurchaseOcrPictureService |
|
|
@Autowired |
|
|
@Autowired |
|
|
private ThreadPoolConfiguration threadPoolConfiguration; |
|
|
private ThreadPoolConfiguration threadPoolConfiguration; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private StockService stockService; |
|
|
|
|
|
@Autowired |
|
|
|
|
|
private ProductCategoryService productCategoryService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public JSONObject batchSave(PurchaseOciPictureAddVo purchaseOciPictureAddVo) { |
|
|
public JSONObject batchSave(PurchaseOciPictureAddVo purchaseOciPictureAddVo) { |
|
|
final JSONObject jsonObject = new JSONObject(); |
|
|
final JSONObject jsonObject = new JSONObject(); |
|
|
@ -116,10 +136,10 @@ public class PurchaseOcrPictureServiceImpl implements PurchaseOcrPictureService |
|
|
// 异步处理ocr识别
|
|
|
// 异步处理ocr识别
|
|
|
try { |
|
|
try { |
|
|
// 获取参数示例
|
|
|
// 获取参数示例
|
|
|
PurchaseOcrExample purchaseOcrExample = purchaseOciPictureAddVo.getPurchaseOcrExample(); |
|
|
final PurchaseOcrExample purchaseOcrExample = purchaseOciPictureAddVo.getPurchaseOcrExample(); |
|
|
AiPurchaseThread timerThread; |
|
|
AiPurchaseThread timerThread; |
|
|
for (PurchaseOcrPicture purchaseOcrPicture : purchaseOcrPictureAddList) { |
|
|
for (PurchaseOcrPicture purchaseOcrPicture : purchaseOcrPictureAddList) { |
|
|
timerThread = new AiPurchaseThread(purchaseId, purchaseOcrPicture,purchaseOcrExample, purchaseOcrPictureService, productService, purchaseDetailService, purchaseService); |
|
|
timerThread = new AiPurchaseThread(purchaseId, purchaseOcrPicture, purchaseOcrExample, purchaseOcrPictureService, productService, purchaseDetailService, purchaseService, productCategoryService); |
|
|
// 这里可以使用线程池,也可以使用CompletionService处理,运行任务需要是callable的,需要最终结果。
|
|
|
// 这里可以使用线程池,也可以使用CompletionService处理,运行任务需要是callable的,需要最终结果。
|
|
|
threadPoolConfiguration.threadPoolTaskExecutor().execute(timerThread); |
|
|
threadPoolConfiguration.threadPoolTaskExecutor().execute(timerThread); |
|
|
} |
|
|
} |
|
|
@ -160,4 +180,287 @@ public class PurchaseOcrPictureServiceImpl implements PurchaseOcrPictureService |
|
|
final String shopId = securityUtil.getShopId(); |
|
|
final String shopId = securityUtil.getShopId(); |
|
|
return purchaseOcrPictureMapper.getOcrCount(shopId); |
|
|
return purchaseOcrPictureMapper.getOcrCount(shopId); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public JSONObject callWithMessageOfPurchase(String questionMsg) throws NoApiKeyException, InputRequiredException { |
|
|
|
|
|
|
|
|
|
|
|
final JSONObject returnJsonObject = new JSONObject(); |
|
|
|
|
|
final StopWatch stopWatch = new StopWatch("Ai入库计时:"); |
|
|
|
|
|
// 叉转X 文本纠错 使用正则表达式替换单个或多个连续的“叉”字符
|
|
|
|
|
|
questionMsg = replaceAllX(questionMsg); |
|
|
|
|
|
// 解析语句,根据“货号”分割换行一下,一个一个执行
|
|
|
|
|
|
final String[] split = productSn.split(questionMsg); |
|
|
|
|
|
final List<SaleAiMsg> saleAiMsgs = new ArrayList<>(); |
|
|
|
|
|
for (String s : split) { |
|
|
|
|
|
if (cc.hiver.core.common.utils.StringUtils.isNotEmpty(s)) { |
|
|
|
|
|
final String oneAiMsg = "货号:" + s; |
|
|
|
|
|
// 封装需要新增的ai开单记录表
|
|
|
|
|
|
final SaleAiMsg saleAiMsg = new SaleAiMsg(); |
|
|
|
|
|
saleAiMsg.setAiMsg(oneAiMsg); |
|
|
|
|
|
saleAiMsgs.add(saleAiMsg); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
final PurchaseVo purchaseVo = new PurchaseVo(); |
|
|
|
|
|
// 定义一个map,货号为key,purchaseDetail 为value
|
|
|
|
|
|
final Map<String, PurchaseDetail> purchaseDetailMap = new HashMap<>(); |
|
|
|
|
|
// shopId从缓存中设置
|
|
|
|
|
|
final String shopId = securityUtil.getShopId(); |
|
|
|
|
|
// 进行识别
|
|
|
|
|
|
for (SaleAiMsg saleAiMsg : saleAiMsgs) { |
|
|
|
|
|
stopWatch.start("Ai入库计时:" + saleAiMsg); |
|
|
|
|
|
try { |
|
|
|
|
|
final JSONObject jsonObject = AliOcrUtil.callWithMessageOfPurchase(saleAiMsg.getAiMsg()); |
|
|
|
|
|
final String resultContent = jsonObject.get("resultContent").toString(); |
|
|
|
|
|
final JSONArray json = JSON.parseArray(resultContent); |
|
|
|
|
|
|
|
|
|
|
|
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 productName = object.getString("productName"); |
|
|
|
|
|
final String priceStr = object.getString("price"); |
|
|
|
|
|
BigDecimal price = BigDecimal.valueOf(0); |
|
|
|
|
|
// 使用正则表达式提取数字部分
|
|
|
|
|
|
final Pattern pattern = Pattern.compile("-?\\d+(\\.\\d+)?"); |
|
|
|
|
|
final Matcher matcher = pattern.matcher(priceStr); |
|
|
|
|
|
if (matcher.find()) { |
|
|
|
|
|
// 获取匹配到的数字字符串并转换为BigDecimal
|
|
|
|
|
|
final String numericPart = matcher.group(); |
|
|
|
|
|
price = new BigDecimal(numericPart); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
final String attributeList = object.getString("attributeList"); |
|
|
|
|
|
final JSONArray attributeListJsonArray = JSON.parseArray(attributeList); |
|
|
|
|
|
// 根据货号去查询商品,如果
|
|
|
|
|
|
final List<Product> byProductSn = productService.getByProductSn(productSn, shopId); |
|
|
|
|
|
if (byProductSn != null && !byProductSn.isEmpty()) { |
|
|
|
|
|
// 原则上一个店铺一个货号对应一个商品,这里如果查到了,直接拿第一个。
|
|
|
|
|
|
final Product product = byProductSn.get(0); |
|
|
|
|
|
final String productId = product.getId(); |
|
|
|
|
|
// 查询商品所有的库存
|
|
|
|
|
|
final List<Stock> stockList = stockService.getProductStock(productId); |
|
|
|
|
|
final Map<String, Integer> stockMap = new HashMap<>(); |
|
|
|
|
|
for (Stock stock : stockList) { |
|
|
|
|
|
stockMap.put(stock.getAttributeList(), stock.getStockCount()); |
|
|
|
|
|
} |
|
|
|
|
|
final String categoryId = product.getCategoryId(); |
|
|
|
|
|
final PurchaseDetail purchaseDetail = new PurchaseDetail(); |
|
|
|
|
|
purchaseDetail.setProductId(productId); |
|
|
|
|
|
purchaseDetail.setProductName(product.getProductName()); |
|
|
|
|
|
purchaseDetail.setShopId(product.getShopId()); |
|
|
|
|
|
purchaseDetail.setCategoryId(categoryId); |
|
|
|
|
|
purchaseDetail.setPrice(product.getPrice()); |
|
|
|
|
|
purchaseDetail.setPurchasePrice(price); |
|
|
|
|
|
purchaseDetail.setWholesalePrice(product.getWholesalePrice()); |
|
|
|
|
|
purchaseDetail.setProductPicture(product.getProductPicture()); |
|
|
|
|
|
purchaseDetail.setProductSn(product.getProductSn()); |
|
|
|
|
|
purchaseDetail.setProductCount(0); |
|
|
|
|
|
purchaseDetail.setSupplierName(product.getSupplierName()); |
|
|
|
|
|
final List<StockLog> stockLogList = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
// 获取商品分类及规格信息
|
|
|
|
|
|
final List<String> categoryIdList = new ArrayList<>(); |
|
|
|
|
|
categoryIdList.add(categoryId); |
|
|
|
|
|
final List<ProductCategoryVo> shopCategory = productCategoryService.getShopCategory(categoryIdList); |
|
|
|
|
|
final ProductCategoryVo productCategoryVo = shopCategory.get(0); |
|
|
|
|
|
final List<ProductAttributeOfAddVo> productAttributeOfAddVos = productCategoryVo.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()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (int j = 0; j < attributeListJsonArray.size(); j++) { |
|
|
|
|
|
final JSONObject attributeListObject = attributeListJsonArray.getJSONObject(j); |
|
|
|
|
|
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("")); |
|
|
|
|
|
// 20240330 只能新增颜色和尺码,颜色统一改为*色、尺码统一转大写,加‘码’;
|
|
|
|
|
|
// 根据规格id规格是颜色、还是尺码。
|
|
|
|
|
|
if (!color.contains("色")) { |
|
|
|
|
|
color += '色'; |
|
|
|
|
|
} |
|
|
|
|
|
if (!size.contains("码")) { |
|
|
|
|
|
size += '码'; |
|
|
|
|
|
} |
|
|
|
|
|
size = size.toUpperCase(); |
|
|
|
|
|
|
|
|
|
|
|
if ("SYYS色".equals(color) && "SYCM码".equals(size)) { |
|
|
|
|
|
for (ProductAttributeValueVo productAttributeValueVo : colorProductAttributeValueVoList) { |
|
|
|
|
|
for (ProductAttributeValueVo attributeValueVo : sizeProductAttributeValueVoList) { |
|
|
|
|
|
final StockLog stockLog = new StockLog(); |
|
|
|
|
|
final String attribute = "{\"颜色\":\"" + productAttributeValueVo.getValue() + "\",\"尺码\":\"" + attributeValueVo.getValue() + "\"}"; |
|
|
|
|
|
stockLog.setAttributeList(attribute); |
|
|
|
|
|
stockLog.setProductCount(productCount); |
|
|
|
|
|
purchaseDetail.setProductCount(purchaseDetail.getProductCount() + productCount); |
|
|
|
|
|
stockLogList.add(stockLog); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
continue; |
|
|
|
|
|
// 所有颜色,所有尺码
|
|
|
|
|
|
} |
|
|
|
|
|
if ("SYYS色".equals(color)) { |
|
|
|
|
|
// 所有颜色,固定尺码
|
|
|
|
|
|
for (ProductAttributeValueVo productAttributeValueVo : colorProductAttributeValueVoList) { |
|
|
|
|
|
final StockLog stockLog = new StockLog(); |
|
|
|
|
|
final String attribute = "{\"颜色\":\"" + productAttributeValueVo.getValue() + "\",\"尺码\":\"" + size + "\"}"; |
|
|
|
|
|
stockLog.setAttributeList(attribute); |
|
|
|
|
|
stockLog.setProductCount(productCount); |
|
|
|
|
|
purchaseDetail.setProductCount(purchaseDetail.getProductCount() + productCount); |
|
|
|
|
|
stockLogList.add(stockLog); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
if ("SYCM码".equals(size)) { |
|
|
|
|
|
// 所有尺码,固定颜色
|
|
|
|
|
|
for (ProductAttributeValueVo attributeValueVo : sizeProductAttributeValueVoList) { |
|
|
|
|
|
final StockLog stockLog = new StockLog(); |
|
|
|
|
|
final String attribute = "{\"颜色\":\"" + color + "\",\"尺码\":\"" + attributeValueVo.getValue() + "\"}"; |
|
|
|
|
|
stockLog.setAttributeList(attribute); |
|
|
|
|
|
stockLog.setProductCount(productCount); |
|
|
|
|
|
purchaseDetail.setProductCount(purchaseDetail.getProductCount() + productCount); |
|
|
|
|
|
stockLogList.add(stockLog); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
// 不包含所有按照获取的拼接
|
|
|
|
|
|
final StockLog stockLog = new StockLog(); |
|
|
|
|
|
final String attribute = "{\"颜色\":\"" + color + "\",\"尺码\":\"" + size + "\"}"; |
|
|
|
|
|
stockLog.setAttributeList(attribute); |
|
|
|
|
|
stockLog.setProductCount(productCount); |
|
|
|
|
|
purchaseDetail.setProductCount(purchaseDetail.getProductCount() + productCount); |
|
|
|
|
|
stockLogList.add(stockLog); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
// 判断是否存在改货号,如果不存在,新增,存在,则追加stockLogList
|
|
|
|
|
|
if (purchaseDetailMap.containsKey(productSn)) { |
|
|
|
|
|
final PurchaseDetail addPurchaseDetail = purchaseDetailMap.get(productSn); |
|
|
|
|
|
addPurchaseDetail.getStockLogList1().addAll(stockLogList); |
|
|
|
|
|
} else { |
|
|
|
|
|
purchaseDetail.setStockLogList1(stockLogList); |
|
|
|
|
|
purchaseDetailMap.put(productSn, purchaseDetail); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
// 没查到,封装数据,货号为id
|
|
|
|
|
|
final PurchaseDetail purchaseDetail = new PurchaseDetail(); |
|
|
|
|
|
purchaseDetail.setId(StringUtils.isEmpty(productSn) ? productName : productSn); |
|
|
|
|
|
purchaseDetail.setProductName(productName); |
|
|
|
|
|
purchaseDetail.setProductSn(productSn); |
|
|
|
|
|
purchaseDetail.setPurchasePrice(price); |
|
|
|
|
|
purchaseDetail.setProductCount(0); |
|
|
|
|
|
// 获取默认分类
|
|
|
|
|
|
final ProductCategoryVo defaultCategory = productCategoryService.getDefaultCategory(shopId); |
|
|
|
|
|
if (defaultCategory != null) { |
|
|
|
|
|
purchaseDetail.setCategoryId(defaultCategory.getCategoryId()); |
|
|
|
|
|
purchaseDetail.setCategoryName(defaultCategory.getCategoryName()); |
|
|
|
|
|
} |
|
|
|
|
|
final List<StockLog> stockLogList = new ArrayList<>(); |
|
|
|
|
|
for (int j = 0; j < attributeListJsonArray.size(); j++) { |
|
|
|
|
|
final JSONObject attributeListObject = attributeListJsonArray.getJSONObject(j); |
|
|
|
|
|
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("")); |
|
|
|
|
|
// 20240330 只能新增颜色和尺码,颜色统一改为*色、尺码统一转大写,加‘码’;
|
|
|
|
|
|
// 根据规格id规格是颜色、还是尺码。
|
|
|
|
|
|
if (!color.contains("色")) { |
|
|
|
|
|
color += '色'; |
|
|
|
|
|
} |
|
|
|
|
|
if (!size.contains("码")) { |
|
|
|
|
|
size += '码'; |
|
|
|
|
|
} |
|
|
|
|
|
size = size.toUpperCase(); |
|
|
|
|
|
// 不包含所有按照获取的拼接
|
|
|
|
|
|
final StockLog stockLog = new StockLog(); |
|
|
|
|
|
final String attribute = "{\"颜色\":\"" + color + "\",\"尺码\":\"" + size + "\"}"; |
|
|
|
|
|
stockLog.setAttributeList(attribute); |
|
|
|
|
|
stockLog.setProductCount(productCount); |
|
|
|
|
|
purchaseDetail.setProductCount(purchaseDetail.getProductCount() + productCount); |
|
|
|
|
|
stockLogList.add(stockLog); |
|
|
|
|
|
} |
|
|
|
|
|
// 判断是否存在改货号,如果不存在,新增,存在,则追加stockLogList
|
|
|
|
|
|
if (purchaseDetailMap.containsKey(productSn)) { |
|
|
|
|
|
final PurchaseDetail addPurchaseDetail = purchaseDetailMap.get(productSn); |
|
|
|
|
|
addPurchaseDetail.getStockLogList1().addAll(stockLogList); |
|
|
|
|
|
} else { |
|
|
|
|
|
purchaseDetail.setStockLogList1(stockLogList); |
|
|
|
|
|
purchaseDetailMap.put(productSn, purchaseDetail); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} catch (NoApiKeyException e) { |
|
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
|
} catch (InputRequiredException e) { |
|
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
|
} |
|
|
|
|
|
stopWatch.stop(); |
|
|
|
|
|
} |
|
|
|
|
|
log.info(stopWatch.prettyPrint()); |
|
|
|
|
|
final List<PurchaseDetail> purchaseDetails = new ArrayList<>(); |
|
|
|
|
|
for (Map.Entry<String, PurchaseDetail> stringPurchaseDetailEntry : purchaseDetailMap.entrySet()) { |
|
|
|
|
|
purchaseDetails.add(stringPurchaseDetailEntry.getValue()); |
|
|
|
|
|
} |
|
|
|
|
|
purchaseVo.setPurchaseDetails(purchaseDetails); |
|
|
|
|
|
returnJsonObject.put("data", purchaseVo); |
|
|
|
|
|
return returnJsonObject; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 使用正则表达式替换输入字符串中连续的“叉”字符为相应数量的“X”字符。 |
|
|
|
|
|
* |
|
|
|
|
|
* @param input 待替换的字符串 |
|
|
|
|
|
* @return 替换后的字符串 |
|
|
|
|
|
*/ |
|
|
|
|
|
private static String replaceAllX(String input) { |
|
|
|
|
|
// 定义正则表达式
|
|
|
|
|
|
final Pattern pattern = Pattern.compile("(叉+)"); |
|
|
|
|
|
// 创建匹配器
|
|
|
|
|
|
final Matcher matcher = pattern.matcher(input); |
|
|
|
|
|
|
|
|
|
|
|
// 用于构建替换后的结果字符串
|
|
|
|
|
|
final StringBuffer sb = new StringBuffer(); |
|
|
|
|
|
while (matcher.find()) { |
|
|
|
|
|
// 获取匹配到的“叉”字符数
|
|
|
|
|
|
final int count = matcher.group(1).length(); |
|
|
|
|
|
// 创建一个字符数组,用于存放“X”字符
|
|
|
|
|
|
final char[] xs = new char[count]; |
|
|
|
|
|
// 填充数组
|
|
|
|
|
|
Arrays.fill(xs, 'X'); |
|
|
|
|
|
// 将字符数组转换为字符串
|
|
|
|
|
|
final String replacement = new String(xs); |
|
|
|
|
|
// 将替换后的字符串添加到结果缓冲区
|
|
|
|
|
|
matcher.appendReplacement(sb, replacement); |
|
|
|
|
|
} |
|
|
|
|
|
// 添加剩余未匹配部分到结果缓冲区
|
|
|
|
|
|
matcher.appendTail(sb); |
|
|
|
|
|
// 对【所有】进行特殊处理
|
|
|
|
|
|
String returnStr = sb.toString(); |
|
|
|
|
|
returnStr = SYYS.matcher(returnStr).replaceAll(",SYYS色"); |
|
|
|
|
|
returnStr = SYCM.matcher(returnStr).replaceAll(",SYCM码"); |
|
|
|
|
|
// 返回最终替换后的字符串
|
|
|
|
|
|
return returnStr; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|