|
|
@ -58,7 +58,7 @@ import java.util.regex.Pattern; |
|
|
public class SaleServiceImpl extends ServiceImpl<SaleMapper, Sale> implements SaleService { |
|
|
public class SaleServiceImpl extends ServiceImpl<SaleMapper, Sale> implements SaleService { |
|
|
|
|
|
|
|
|
private static final Pattern productSn = Pattern.compile("货号"); |
|
|
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 SYYS = Pattern.compile("所有颜色", Pattern.LITERAL); |
|
|
private static final Pattern SYCM = Pattern.compile("所有尺码", Pattern.LITERAL); |
|
|
private static final Pattern SYCM = Pattern.compile("所有尺码", Pattern.LITERAL); |
|
|
@Autowired |
|
|
@Autowired |
|
|
@ -174,6 +174,7 @@ public class SaleServiceImpl extends ServiceImpl<SaleMapper, Sale> implements Sa |
|
|
} |
|
|
} |
|
|
final Page<Sale> saleList = saleMapper.queryPage(page, saleVO); |
|
|
final Page<Sale> saleList = saleMapper.queryPage(page, saleVO); |
|
|
// 获取订单详情信息
|
|
|
// 获取订单详情信息
|
|
|
|
|
|
List<String> productIdList = new ArrayList<>(); |
|
|
for (Sale sale : saleList.getRecords()) { |
|
|
for (Sale sale : saleList.getRecords()) { |
|
|
final QueryWrapper<SaleDetail> querySaleDetailWrapper = new QueryWrapper<>(); |
|
|
final QueryWrapper<SaleDetail> querySaleDetailWrapper = new QueryWrapper<>(); |
|
|
querySaleDetailWrapper.select("product_id") |
|
|
querySaleDetailWrapper.select("product_id") |
|
|
@ -181,6 +182,7 @@ public class SaleServiceImpl extends ServiceImpl<SaleMapper, Sale> implements Sa |
|
|
.groupBy("product_id"); |
|
|
.groupBy("product_id"); |
|
|
final List<String> list = saleDetailService.selectByCondition1(querySaleDetailWrapper); |
|
|
final List<String> list = saleDetailService.selectByCondition1(querySaleDetailWrapper); |
|
|
if (!list.isEmpty()) { |
|
|
if (!list.isEmpty()) { |
|
|
|
|
|
productIdList.addAll(list); |
|
|
final List<SaleDetailDTO> saleDetailDTOS = new ArrayList<>(); |
|
|
final List<SaleDetailDTO> saleDetailDTOS = new ArrayList<>(); |
|
|
final Map<String, Product> productMap = new HashMap<>(); |
|
|
final Map<String, Product> productMap = new HashMap<>(); |
|
|
// 获取商品信息
|
|
|
// 获取商品信息
|
|
|
@ -219,10 +221,12 @@ public class SaleServiceImpl extends ServiceImpl<SaleMapper, Sale> implements Sa |
|
|
saleDetailDTO.setRealPrice(saleDetail.getRealPrice()); |
|
|
saleDetailDTO.setRealPrice(saleDetail.getRealPrice()); |
|
|
// 回填商品的的图片及货号
|
|
|
// 回填商品的的图片及货号
|
|
|
if (productMap.containsKey(productId)) { |
|
|
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.setPurchasePrice(purchasePrice); |
|
|
saleDetailDTO.setProductPicture(productMap.get(productId).getProductPicture()); |
|
|
saleDetailDTO.setProductPicture(productMap.get(productId).getProductPicture()); |
|
|
saleDetailDTO.setProductSn(productMap.get(productId).getProductSn()); |
|
|
saleDetailDTO.setProductSn(productMap.get(productId).getProductSn()); |
|
|
|
|
|
saleDetailDTO.setAttrId(productMap.get(productId).getAttrId()); |
|
|
|
|
|
saleDetailDTO.setCustomerCategoryRule(productMap.get(productId).getCustomerCategoryRule()); |
|
|
} else { |
|
|
} else { |
|
|
saleDetailDTO.setPurchasePrice(saleDetail.getPurchasePrice()); |
|
|
saleDetailDTO.setPurchasePrice(saleDetail.getPurchasePrice()); |
|
|
} |
|
|
} |
|
|
@ -244,6 +248,21 @@ public class SaleServiceImpl extends ServiceImpl<SaleMapper, Sale> implements Sa |
|
|
sale.setSaleDetailDTOList(saleDetailDTOS); |
|
|
sale.setSaleDetailDTOList(saleDetailDTOS); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
// 如果客户id不为空,查询客户的购买次数
|
|
|
|
|
|
if (StringUtils.isNotEmpty(saleVO.getCustomerId())) { |
|
|
|
|
|
final List<BuyCountVo> buyCount = saleService.buyCount(saleVO.getCustomerId(), productIdList); |
|
|
|
|
|
// 封装为Map
|
|
|
|
|
|
final Map<String, Integer> 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; |
|
|
return saleList; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -303,7 +322,7 @@ public class SaleServiceImpl extends ServiceImpl<SaleMapper, Sale> implements Sa |
|
|
queryPWrapper.in("sale_id", saleIdList); |
|
|
queryPWrapper.in("sale_id", saleIdList); |
|
|
final List<SaleDetail> saleDetailList = saleDetailService.list(queryPWrapper); |
|
|
final List<SaleDetail> saleDetailList = saleDetailService.list(queryPWrapper); |
|
|
// 获取商品id
|
|
|
// 获取商品id
|
|
|
List<String> productIdList = new ArrayList<>(); |
|
|
final List<String> productIdList = new ArrayList<>(); |
|
|
for (SaleDetail saleDetail : saleDetailList) { |
|
|
for (SaleDetail saleDetail : saleDetailList) { |
|
|
productIdList.add(saleDetail.getProductId()); |
|
|
productIdList.add(saleDetail.getProductId()); |
|
|
} |
|
|
} |
|
|
@ -328,8 +347,8 @@ public class SaleServiceImpl extends ServiceImpl<SaleMapper, Sale> implements Sa |
|
|
saleDetailDTO.setWholesalePrice(saleDetail.getWholesalePrice()); |
|
|
saleDetailDTO.setWholesalePrice(saleDetail.getWholesalePrice()); |
|
|
// 取商品的采购价
|
|
|
// 取商品的采购价
|
|
|
if (productMap.containsKey(saleDetail.getProductId())) { |
|
|
if (productMap.containsKey(saleDetail.getProductId())) { |
|
|
Product product = productMap.get(saleDetail.getProductId()); |
|
|
final Product product = productMap.get(saleDetail.getProductId()); |
|
|
BigDecimal purchasePrice = product.getPurchasePrice() == null ? BigDecimal.ZERO : product.getPurchasePrice(); |
|
|
final BigDecimal purchasePrice = product.getPurchasePrice() == null ? BigDecimal.ZERO : product.getPurchasePrice(); |
|
|
saleDetailDTO.setPurchasePrice(purchasePrice); |
|
|
saleDetailDTO.setPurchasePrice(purchasePrice); |
|
|
} else { |
|
|
} else { |
|
|
saleDetailDTO.setPurchasePrice(saleDetail.getPurchasePrice()); |
|
|
saleDetailDTO.setPurchasePrice(saleDetail.getPurchasePrice()); |
|
|
@ -640,7 +659,7 @@ public class SaleServiceImpl extends ServiceImpl<SaleMapper, Sale> implements Sa |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public JSONObject buyAi(String aiMsg) { |
|
|
public JSONObject buyAi(String aiMsg, String customerId) { |
|
|
final JSONObject returnJsonObject = new JSONObject(); |
|
|
final JSONObject returnJsonObject = new JSONObject(); |
|
|
// 叉转X 文本纠错 使用正则表达式替换单个或多个连续的“叉”字符
|
|
|
// 叉转X 文本纠错 使用正则表达式替换单个或多个连续的“叉”字符
|
|
|
aiMsg = replaceAllX(aiMsg); |
|
|
aiMsg = replaceAllX(aiMsg); |
|
|
@ -652,13 +671,15 @@ public class SaleServiceImpl extends ServiceImpl<SaleMapper, Sale> implements Sa |
|
|
final JSONObject jsonObject = AliOcrUtil.callWithMessage(aiMsg); |
|
|
final JSONObject jsonObject = AliOcrUtil.callWithMessage(aiMsg); |
|
|
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"); |
|
|
// 尝试从货号中提取正确的货号,因为货号可能包含颜色等信息
|
|
|
// 尝试从货号中提取正确的货号,因为货号可能包含颜色等信息
|
|
|
productSn = CommonUtil.getProductSn(productSn); |
|
|
productSn = CommonUtil.getProductSn(productSn); |
|
|
final String attributeList = object.getString("attributeList"); |
|
|
final String attributeList = object.getString("attributeList"); |
|
|
String wholesalePriceStr = object.getString("wholesalePrice"); |
|
|
final String wholesalePriceStr = object.getString("wholesalePrice"); |
|
|
BigDecimal wholesalePrice = BigDecimal.ZERO; |
|
|
BigDecimal wholesalePrice = BigDecimal.ZERO; |
|
|
// 使用正则表达式提取数字部分
|
|
|
// 使用正则表达式提取数字部分
|
|
|
final Pattern pattern = Pattern.compile("-?\\d+(\\.\\d+)?"); |
|
|
final Pattern pattern = Pattern.compile("-?\\d+(\\.\\d+)?"); |
|
|
@ -672,11 +693,12 @@ public class SaleServiceImpl extends ServiceImpl<SaleMapper, Sale> implements Sa |
|
|
// 定义一个map,货号为key,purchaseDetail 为value
|
|
|
// 定义一个map,货号为key,purchaseDetail 为value
|
|
|
final Map<String, PurchaseDetail> purchaseDetailMap = new HashMap<>(); |
|
|
final Map<String, PurchaseDetail> purchaseDetailMap = new HashMap<>(); |
|
|
// 根据货号去查询商品,如果
|
|
|
// 根据货号去查询商品,如果
|
|
|
final List<Product> byProductSn = productService.getByProductSn(productSn, shopId); |
|
|
final List<Product> byProductSn = productService.getByProductSn(productSn, shopId,""); |
|
|
if (byProductSn != null && !byProductSn.isEmpty()) { |
|
|
if (byProductSn != null && !byProductSn.isEmpty()) { |
|
|
// 原则上一个店铺一个货号对应一个商品,这里如果查到了,直接拿第一个。
|
|
|
// 原则上一个店铺一个货号对应一个商品,这里如果查到了,直接拿第一个。
|
|
|
final Product product = byProductSn.get(0); |
|
|
final Product product = byProductSn.get(0); |
|
|
final String productId = product.getId(); |
|
|
final 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<>(); |
|
|
@ -704,6 +726,7 @@ public class SaleServiceImpl extends ServiceImpl<SaleMapper, Sale> implements Sa |
|
|
saleDetailDTO.setProductSn(product.getProductSn()); |
|
|
saleDetailDTO.setProductSn(product.getProductSn()); |
|
|
saleDetailDTO.setProductCount(0); |
|
|
saleDetailDTO.setProductCount(0); |
|
|
saleDetailDTO.setSupplierName(product.getSupplierName()); |
|
|
saleDetailDTO.setSupplierName(product.getSupplierName()); |
|
|
|
|
|
saleDetailDTO.setAttrId(product.getAttrId()); |
|
|
final List<SaleDetailQueryDTO> saleDetailQueryDTOS = new ArrayList<>(); |
|
|
final List<SaleDetailQueryDTO> saleDetailQueryDTOS = new ArrayList<>(); |
|
|
|
|
|
|
|
|
// 获取商品分类及规格信息
|
|
|
// 获取商品分类及规格信息
|
|
|
@ -741,7 +764,12 @@ public class SaleServiceImpl extends ServiceImpl<SaleMapper, Sale> implements Sa |
|
|
String color = attributeListObject.getString("color").toUpperCase(); |
|
|
String color = attributeListObject.getString("color").toUpperCase(); |
|
|
String size = attributeListObject.getString("size").toUpperCase(); |
|
|
String size = attributeListObject.getString("size").toUpperCase(); |
|
|
final String productCount1 = attributeListObject.getString("productCount"); |
|
|
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 只能新增颜色和尺码,颜色统一改为*色、尺码统一转大写,加‘码’;
|
|
|
// 20240330 只能新增颜色和尺码,颜色统一改为*色、尺码统一转大写,加‘码’;
|
|
|
// 根据规格id规格是颜色、还是尺码。
|
|
|
// 根据规格id规格是颜色、还是尺码。
|
|
|
if (!color.contains("色")) { |
|
|
if (!color.contains("色")) { |
|
|
@ -823,7 +851,12 @@ public class SaleServiceImpl extends ServiceImpl<SaleMapper, Sale> implements Sa |
|
|
String color = attributeListObject.getString("color").toUpperCase(); |
|
|
String color = attributeListObject.getString("color").toUpperCase(); |
|
|
String size = attributeListObject.getString("size").toUpperCase(); |
|
|
String size = attributeListObject.getString("size").toUpperCase(); |
|
|
final String productCount1 = attributeListObject.getString("productCount"); |
|
|
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 只能新增颜色和尺码,颜色统一改为*色、尺码统一转大写,加‘码’;
|
|
|
// 20240330 只能新增颜色和尺码,颜色统一改为*色、尺码统一转大写,加‘码’;
|
|
|
// 根据规格id规格是颜色、还是尺码。
|
|
|
// 根据规格id规格是颜色、还是尺码。
|
|
|
if (!color.contains("色")) { |
|
|
if (!color.contains("色")) { |
|
|
@ -847,11 +880,27 @@ public class SaleServiceImpl extends ServiceImpl<SaleMapper, Sale> implements Sa |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
// 如果客户id不为空,那么就查询商品的购买记录
|
|
|
|
|
|
if(StringUtils.isNotEmpty(customerId)){ |
|
|
|
|
|
// 获取客户的购买次数
|
|
|
|
|
|
final List<BuyCountVo> buyCount = buyCount(customerId,oldProductIdList); |
|
|
|
|
|
// 封装为Map
|
|
|
|
|
|
final Map<String, Integer> 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) { |
|
|
} catch (NoApiKeyException e) { |
|
|
throw new RuntimeException(e); |
|
|
throw new RuntimeException(e); |
|
|
} catch (InputRequiredException e) { |
|
|
} catch (InputRequiredException e) { |
|
|
throw new RuntimeException(e); |
|
|
throw new RuntimeException(e); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
returnJsonObject.put("data", saleDetailDTOS); |
|
|
returnJsonObject.put("data", saleDetailDTOS); |
|
|
returnJsonObject.put("aiNotRecognition", String.join(";", aiNotRecognitionList)); |
|
|
returnJsonObject.put("aiNotRecognition", String.join(";", aiNotRecognitionList)); |
|
|
return returnJsonObject; |
|
|
return returnJsonObject; |
|
|
@ -1222,7 +1271,7 @@ public class SaleServiceImpl extends ServiceImpl<SaleMapper, Sale> implements Sa |
|
|
// shopId从缓存中设置
|
|
|
// shopId从缓存中设置
|
|
|
final String shopId = securityUtil.getShopId(); |
|
|
final String shopId = securityUtil.getShopId(); |
|
|
salePageQuery.setShopId(shopId); |
|
|
salePageQuery.setShopId(shopId); |
|
|
Page<TotalAmountDetailByCustomerVo> totalAmountDetailByCustomerVoPage = saleMapper.totalAmountDetailByCustomer(page, salePageQuery); |
|
|
final Page<TotalAmountDetailByCustomerVo> totalAmountDetailByCustomerVoPage = saleMapper.totalAmountDetailByCustomer(page, salePageQuery); |
|
|
return totalAmountDetailByCustomerVoPage; |
|
|
return totalAmountDetailByCustomerVoPage; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -1245,10 +1294,23 @@ public class SaleServiceImpl extends ServiceImpl<SaleMapper, Sale> implements Sa |
|
|
// shopId从缓存中设置
|
|
|
// shopId从缓存中设置
|
|
|
final String shopId = securityUtil.getShopId(); |
|
|
final String shopId = securityUtil.getShopId(); |
|
|
salePageQuery.setShopId(shopId); |
|
|
salePageQuery.setShopId(shopId); |
|
|
Page<TotalAmountDetailByProductVo> totalAmountDetailByProductVoPage = saleMapper.totalAmountDetailByProduct(page, salePageQuery); |
|
|
final Page<TotalAmountDetailByProductVo> totalAmountDetailByProductVoPage = saleMapper.totalAmountDetailByProduct(page, salePageQuery); |
|
|
return totalAmountDetailByProductVoPage; |
|
|
return totalAmountDetailByProductVoPage; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 获取客户购买次数 |
|
|
|
|
|
* |
|
|
|
|
|
* @param customerId |
|
|
|
|
|
* @return Integer |
|
|
|
|
|
* @author 王富康 |
|
|
|
|
|
* @date 2024/9/26 |
|
|
|
|
|
*/ |
|
|
|
|
|
@Override |
|
|
|
|
|
public List<BuyCountVo> buyCount(String customerId, List<String> productIdList) { |
|
|
|
|
|
return saleMapper.buyCount(customerId,productIdList); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 使用正则表达式替换输入字符串中连续的“叉”字符为相应数量的“X”字符。 |
|
|
* 使用正则表达式替换输入字符串中连续的“叉”字符为相应数量的“X”字符。 |
|
|
* |
|
|
* |
|
|
|