diff --git a/mall-common/src/main/java/com/suisung/mall/common/modules/product/ShopProductBase.java b/mall-common/src/main/java/com/suisung/mall/common/modules/product/ShopProductBase.java index eae240fb..6e34ba2a 100644 --- a/mall-common/src/main/java/com/suisung/mall/common/modules/product/ShopProductBase.java +++ b/mall-common/src/main/java/com/suisung/mall/common/modules/product/ShopProductBase.java @@ -39,6 +39,9 @@ public class ShopProductBase implements Serializable { @ApiModelProperty(value = "产品名称(in=>2,100)") private String product_name; + @ApiModelProperty(value = "商品货号") + private String product_number; + @ApiModelProperty(value = "商品卖点:商品广告词") private String product_tips; diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/components/BaiduAi.java b/mall-shop/src/main/java/com/suisung/mall/shop/components/BaiduAi.java index 6b87aa1a..130cb28f 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/components/BaiduAi.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/components/BaiduAi.java @@ -12,6 +12,8 @@ import com.suisung.mall.common.utils.HttpServletUtils; import com.suisung.mall.common.utils.I18nUtil; import com.suisung.mall.shop.config.BaiduConfig; import okhttp3.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.IOException; import java.io.UnsupportedEncodingException; @@ -22,9 +24,10 @@ import java.util.Map; public class BaiduAi { static final OkHttpClient HTTP_CLIENT = new OkHttpClient().newBuilder().build(); + private static final Logger log = LoggerFactory.getLogger(BaiduAi.class); - public static void main(String[] args) throws IOException { + public static void main(String[] args) { String url = "https://lancerdt.oss-accelerate.aliyuncs.com/mall/images/media/store/10002/20240123d3c27007baf740c9bdc429f850259501.jpg"; BaiduAiBriefDTO brief = new BaiduAiBriefDTO(); @@ -64,7 +67,7 @@ public class BaiduAi { } - public static String addProductImg(String url, BaiduAiBriefDTO brief) throws IOException { + public static String addProductImg(String url, BaiduAiBriefDTO brief) { Map map = new HashMap<>(); map.put("url", url); map.put("brief", JSON.toJSONString(brief)); @@ -73,39 +76,38 @@ public class BaiduAi { try { par = HttpServletUtils.generateParams(map, "utf-8"); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); - RequestBody body = RequestBody.create(mediaType, par); - Request request = new Request.Builder() - .url("https://aip.baidubce.com/rest/2.0/image-classify/v1/realtime_search/product/add?access_token=" + BaiduConfig.getAccessToken()) - .method("POST", body) - .addHeader("Content-Type", "application/x-www-form-urlencoded") - .addHeader("Accept", "application/json") - .build(); - Response response = HTTP_CLIENT.newCall(request).execute(); + MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); + RequestBody body = RequestBody.create(mediaType, par); + Request request = new Request.Builder() + .url("https://aip.baidubce.com/rest/2.0/image-classify/v1/realtime_search/product/add?access_token=" + BaiduConfig.getAccessToken()) + .method("POST", body) + .addHeader("Content-Type", "application/x-www-form-urlencoded") + .addHeader("Accept", "application/json") + .build(); + Response response = HTTP_CLIENT.newCall(request).execute(); - String resultStr = response.body().string(); - System.out.println(resultStr); + String resultStr = response.body().string(); + System.out.println(resultStr); - JSONObject jsonObject = JSONUtil.parseObj(resultStr); - Integer errCode = Convert.toInt(jsonObject.get("error_code")); - String errMessage = Convert.toStr(jsonObject.get("error_msg")); - String contSign = Convert.toStr(jsonObject.get("cont_sign")); + JSONObject jsonObject = JSONUtil.parseObj(resultStr); + Integer errCode = Convert.toInt(jsonObject.get("error_code")); +// String errMessage = Convert.toStr(jsonObject.get("error_msg")); + String contSign = Convert.toStr(jsonObject.get("cont_sign")); - if (CheckUtil.isEmpty(errCode)) { + if (CheckUtil.isNotEmpty(errCode)) { + return ""; + } - } else { + return contSign; + } catch (Exception e) { + log.error("Baidu Ai 添加图片异常", e.getMessage()); return ""; } - - return contSign; } - public static String editProductImg(String url, BaiduAiBriefDTO brief) throws IOException { + public static String editProductImg(String url, BaiduAiBriefDTO brief) { Map map = new HashMap<>(); map.put("url", url); map.put("brief", JSON.toJSONString(brief)); @@ -114,40 +116,41 @@ public class BaiduAi { try { par = HttpServletUtils.generateParams(map, "utf-8"); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); - RequestBody body = RequestBody.create(mediaType, par); - Request request = new Request.Builder() - .url("https://aip.baidubce.com/rest/2.0/image-classify/v1/realtime_search/product/update?access_token=" + BaiduConfig.getAccessToken()) - .method("POST", body) - .addHeader("Content-Type", "application/x-www-form-urlencoded") - .addHeader("Accept", "application/json") - .build(); - Response response = HTTP_CLIENT.newCall(request).execute(); + MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); + RequestBody body = RequestBody.create(mediaType, par); + Request request = new Request.Builder() + .url("https://aip.baidubce.com/rest/2.0/image-classify/v1/realtime_search/product/update?access_token=" + BaiduConfig.getAccessToken()) + .method("POST", body) + .addHeader("Content-Type", "application/x-www-form-urlencoded") + .addHeader("Accept", "application/json") + .build(); + Response response = HTTP_CLIENT.newCall(request).execute(); - String resultStr = response.body().string(); - System.out.println(resultStr); + String resultStr = response.body().string(); + System.out.println(resultStr); - JSONObject jsonObject = JSONUtil.parseObj(resultStr); + JSONObject jsonObject = JSONUtil.parseObj(resultStr); - Integer errCode = Convert.toInt(jsonObject.get("error_code")); - String errMessage = Convert.toStr(jsonObject.get("error_msg")); - String contSign = Convert.toStr(jsonObject.get("cont_sign")); + Integer errCode = Convert.toInt(jsonObject.get("error_code")); + String errMessage = Convert.toStr(jsonObject.get("error_msg")); + String contSign = Convert.toStr(jsonObject.get("cont_sign")); - if (CheckUtil.isEmpty(errCode)) { + if (CheckUtil.isEmpty(errCode)) { - } else { + } else { + return ""; + } + + return contSign; + } catch (Exception e) { + log.error("Baidu Ai 编辑图片异常", e.getMessage()); return ""; } - - return contSign; } - public static String removeProductImg(String url, String cont_sign) throws IOException { + public static String removeProductImg(String url, String cont_sign) { Map map = new HashMap<>(); if (CheckUtil.isNotEmpty(url)) { @@ -162,38 +165,37 @@ public class BaiduAi { try { par = HttpServletUtils.generateParams(map, "utf-8"); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); - RequestBody body = RequestBody.create(mediaType, par); - Request request = new Request.Builder() - .url("https://aip.baidubce.com/rest/2.0/image-classify/v1/realtime_search/product/delete?access_token=" + BaiduConfig.getAccessToken()) - .method("POST", body) - .addHeader("Content-Type", "application/x-www-form-urlencoded") - .addHeader("Accept", "application/json") - .build(); - Response response = HTTP_CLIENT.newCall(request).execute(); + MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); + RequestBody body = RequestBody.create(mediaType, par); + Request request = new Request.Builder() + .url("https://aip.baidubce.com/rest/2.0/image-classify/v1/realtime_search/product/delete?access_token=" + BaiduConfig.getAccessToken()) + .method("POST", body) + .addHeader("Content-Type", "application/x-www-form-urlencoded") + .addHeader("Accept", "application/json") + .build(); + Response response = HTTP_CLIENT.newCall(request).execute(); - String resultStr = response.body().string(); - System.out.println(resultStr); + String resultStr = response.body().string(); +// System.out.println(resultStr); - JSONObject jsonObject = JSONUtil.parseObj(resultStr); - Integer errCode = Convert.toInt(jsonObject.get("error_code")); - String errMessage = Convert.toStr(jsonObject.get("error_msg")); - String contSign = Convert.toStr(jsonObject.get("cont_sign")); + JSONObject jsonObject = JSONUtil.parseObj(resultStr); + Integer errCode = Convert.toInt(jsonObject.get("error_code")); + String errMessage = Convert.toStr(jsonObject.get("error_msg")); + String contSign = Convert.toStr(jsonObject.get("cont_sign")); - if (CheckUtil.isEmpty(errCode)) { + if (CheckUtil.isNotEmpty(errCode)) { + return ""; + } - } else { + return contSign; + } catch (Exception e) { + log.error("Baidu Ai 删除图片异常", e.getMessage()); return ""; } - - return contSign; } - public static List searchProductImg(String url, Integer pn, Integer rn) throws IOException { + public static List searchProductImg(String url, Integer pn, Integer rn) { Map map = new HashMap<>(); map.put("url", url); @@ -209,45 +211,47 @@ public class BaiduAi { try { par = HttpServletUtils.generateParams(map, "utf-8"); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); - RequestBody body = RequestBody.create(mediaType, par); - Request request = new Request.Builder() - .url("https://aip.baidubce.com/rest/2.0/image-classify/v1/realtime_search/product/search?access_token=" + BaiduConfig.getAccessToken()) - .method("POST", body) - .addHeader("Content-Type", "application/x-www-form-urlencoded") - .addHeader("Accept", "application/json") - .build(); - Response response = HTTP_CLIENT.newCall(request).execute(); - String resultStr = response.body().string(); - System.out.println(resultStr); + MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); + RequestBody body = RequestBody.create(mediaType, par); + Request request = new Request.Builder() + .url("https://aip.baidubce.com/rest/2.0/image-classify/v1/realtime_search/product/search?access_token=" + BaiduConfig.getAccessToken()) + .method("POST", body) + .addHeader("Content-Type", "application/x-www-form-urlencoded") + .addHeader("Accept", "application/json") + .build(); + Response response = HTTP_CLIENT.newCall(request).execute(); - JSONObject jsonObject = JSONUtil.parseObj(resultStr); + String resultStr = response.body().string(); + System.out.println(resultStr); - Integer errCode = Convert.toInt(jsonObject.get("error_code")); - String errMessage = Convert.toStr(jsonObject.get("error_msg")); - String contSign = Convert.toStr(jsonObject.get("cont_sign")); + JSONObject jsonObject = JSONUtil.parseObj(resultStr); - Integer result_num = Convert.toInt(jsonObject.get("result_num")); + Integer errCode = Convert.toInt(jsonObject.get("error_code")); + String errMessage = Convert.toStr(jsonObject.get("error_msg")); + String contSign = Convert.toStr(jsonObject.get("cont_sign")); - List items = new ArrayList<>(); + Integer result_num = Convert.toInt(jsonObject.get("result_num")); - if (CheckUtil.isNotEmpty(result_num)) { - JSONArray resData = (JSONArray) jsonObject.get("result"); + List items = new ArrayList<>(); - if (resData == null) { - throw new ApiException(I18nUtil._("返回结果为空!")); + if (CheckUtil.isNotEmpty(result_num)) { + JSONArray resData = (JSONArray) jsonObject.get("result"); + if (resData == null) { + log.error(I18nUtil._("Baidu Ai 搜索图片,返回结果为空!")); + return null; + } + + items = JSONUtil.toList(resData, Map.class); + } else { + return items; } - items = JSONUtil.toList(resData, Map.class); - } else { return items; + } catch (Exception e) { + log.error("Baidu Ai 搜索图片异常", e.getMessage()); + return null; } - - return items; } } \ No newline at end of file diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/product/service/ShopProductBaseService.java b/mall-shop/src/main/java/com/suisung/mall/shop/product/service/ShopProductBaseService.java index be315bb4..cfb7ccae 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/product/service/ShopProductBaseService.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/product/service/ShopProductBaseService.java @@ -259,6 +259,14 @@ public interface ShopProductBaseService extends IBaseService { */ Map getProductBasicInfo(Long product_id, Integer store_id); + /** + * 根据店铺Id和商品货号,获取商品Id + * @param store_id + * @param product_number + * @return + */ + Long getProductIdByStoreAndProductNumber(Integer store_id, String product_number); + @Transactional boolean updateProductSubsite(Integer store_id); diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/product/service/impl/ShopProductBaseServiceImpl.java b/mall-shop/src/main/java/com/suisung/mall/shop/product/service/impl/ShopProductBaseServiceImpl.java index 350c91f4..bbb50220 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/product/service/impl/ShopProductBaseServiceImpl.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/product/service/impl/ShopProductBaseServiceImpl.java @@ -67,6 +67,7 @@ import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.util.Pair; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.context.request.RequestContextHolder; @@ -98,149 +99,102 @@ import static io.seata.common.util.LambdaUtils.distinctByKey; @Transactional @Service public class ShopProductBaseServiceImpl extends BaseServiceImpl implements ShopProductBaseService { + private final Logger logger = LoggerFactory.getLogger(ShopProductBaseServiceImpl.class); @Autowired private ShopBaseProductCategoryService shopBaseProductCategoryService; - @Autowired private ShopProductMetaService shopProductMetaService; - @Autowired private ShopProductPreSaleService shopProductPreSaleService; - @Autowired private ShopProductBaseService shopProductBaseService; - @Autowired private ShopStoreAnalyticsService shopStoreAnalyticsService; - @Autowired private ShopProductAnalyticsService shopProductAnalyticsService; - @Autowired private ShopProductDetailService shopProductDetailService; - @Autowired private ShopProductInfoService shopProductInfoService; - @Autowired private ShopProductValidPeriodService shopProductValidPeriodService; - @Autowired private ShopProductItemService shopProductItemService; - @Autowired private AccountBaseConfigService accountBaseConfigService; - @Autowired private ShopBaseCurrencyService shopBaseCurrencyService; - @Autowired private ShopUserCartService shopUserCartService; - @Autowired private ShopStoreTransportTypeService transportTypeService; - @Autowired private ShopBaseProductCategoryService productCategoryService; - @Autowired private ShopProductIndexService shopProductIndexService; - @Autowired private ShopProductImageService shopProductImageService; - @Autowired private ShopStoreBaseService shopStoreBaseService; - @Autowired private ShopBaseProductSpecService baseProductSpecService; - @Autowired private ShopBaseStoreGradeService baseStoreGradeService; - @Autowired private ShopProductAssistIndexService assistIndexService; - @Autowired private ShopProductDataService shopProductDataService; - @Autowired private ShopProductItemSeqService shopProductItemSeqService; - @Autowired private ShopProductValidPeriodService validPeriodService; - @Autowired private ShopUserSearchHistoryService shopUserSearchHistoryService; - @Autowired private ShopBaseStateCodeService shopBaseStateCodeService; - @Autowired private ShopProductBaseMapper shopProductBaseMapper; - @Autowired private ShopStoreActivityBaseService shopStoreActivityBaseService; - @Autowired private ShopStoreActivityItemService shopStoreActivityItemService; - @Autowired private ShopActivityGroupbookingService shopActivityGroupbookingService; - @Autowired private ShopBaseProductTypeService shopBaseProductTypeService; - @Autowired private ShopNumberSeqService shopNumberSeqService; - @Autowired private EduService eduService; - @Autowired private ShopBaseDistrictService shopBaseDistrictService; - @Autowired private ShopBaseContractTypeService shopBaseContractTypeService; - @Autowired private ShopBaseMarketCategoryService shopBaseMarketCategoryService; - @Autowired private MessageService messageService; - @Autowired private ShopOrderItemService shopOrderItemService; - @Autowired private SearchService searchService; - @Autowired private ShopChainItemService shopChainItemService; - @Autowired private ShopUserProductBrowseService shopUserProductBrowseService; - @Autowired private ShopUserProductBuyService shopUserProductBuyService; - @Autowired private ShopUserFavoritesItemService shopUserFavoritesItemService; - @Autowired private MqMessageService mqMessageService; - @Autowired private ThreadPoolExecutor executor; - @Autowired private ShopBaseLangMetaService shopBaseLangMetaService; - @Resource private SxSyncGoodsService sxSyncGoodsService; - private final Logger logger = LoggerFactory.getLogger(ShopProductBaseServiceImpl.class); - @Override public boolean trySaveProduct(String productObj, String productItems) { @@ -690,7 +644,7 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl shopProductItemList, List shopProductImageList, ShopProductValidPeriod shopProductValidPeriod, List shopProductAssistIndexList) { + Pair pair = saveProduct(shopProductBase, shopProductIndex, shopProductData, shopProductDetail, shopProductInfo, shopProductItemList, shopProductImageList, shopProductValidPeriod, shopProductAssistIndexList); + if (!pair.getFirst()) { + throw new ApiException(pair.getSecond()); + } + + return true; + } + + /** + * 保存一个商品所有信息,不会抛出异常 + * + * @param shopProductBase 商品基础表信息 + * @param shopProductIndex 商品索引表信息 + * @param shopProductData 商品数据表信息 + * @param shopProductDetail 商品详情表信息 + * @param shopProductInfo 商品信息表信息 + * @param shopProductItemList 商品SKU信息 + * @param shopProductImageList 商品图片信息 + * @param shopProductValidPeriod 虚拟商品信息 + * @param shopProductAssistIndexList 辅助信息表 + * @return + */ + public Pair saveProduct(ShopProductBase shopProductBase, ShopProductIndex shopProductIndex, ShopProductData shopProductData, ShopProductDetail shopProductDetail, ShopProductInfo shopProductInfo, List shopProductItemList, List shopProductImageList, ShopProductValidPeriod shopProductValidPeriod, List shopProductAssistIndexList) { Integer store_id = shopProductBase.getStore_id(); ShopStoreBase storeBase = null; if (store_id == null) { - return false; - } else { - storeBase = shopStoreBaseService.get(store_id); - Integer store_type = storeBase.getStore_type(); - // 判断是否为供应商店铺 - if (store_type == 2) { - shopProductIndex.setProduct_fx_enable(1); // 供应商是否允许批发市场分销 - shopProductIndex.setProduct_dist_enable(0); // 三级分销逻辑 + return Pair.of(false, I18nUtil._("缺少店铺ID!")); + } + + storeBase = shopStoreBaseService.get(store_id); + Integer store_type = storeBase.getStore_type(); + // 判断是否为供应商店铺 + if (store_type == 2) { + shopProductIndex.setProduct_fx_enable(1); // 供应商是否允许批发市场分销 + shopProductIndex.setProduct_dist_enable(0); // 三级分销逻辑 + } + + // TODO 判断违禁词 + + // 商品是否需要审核 + boolean verify_type = accountBaseConfigService.getConfig("product_verify_flag", false); + Long productId = shopProductBase.getProduct_id(); + + // add 2025-01-08 + if (productId == null) { + // 根据店铺id和商品货号获取商品id + productId = getProductIdByStoreAndProductNumber(store_id, shopProductBase.getProduct_number()); + if (productId != null && productId > 0) { + shopProductBase.setProduct_id(productId); } } - // todo 判断违禁词 - - // 是否需要审核 - boolean verify_type = accountBaseConfigService.getConfig("product_verify_flag", false); - Long product_id = shopProductBase.getProduct_id(); - boolean isUpdate = false; String product_image_old = ""; - if (product_id == null && storeBase != null) { - product_id = shopNumberSeqService.createNextNo("product_id"); - - if (null == product_id) { - throw new ApiException(I18nUtil._("生成商品编号异常!")); + if (productId == null && storeBase != null) { + // 生成商品ID:product_id + productId = shopNumberSeqService.createNextNo("product_id"); + if (null == productId) { + return Pair.of(false, I18nUtil._("生成商品编号异常!")); } else { - shopProductBase.setProduct_id(product_id); + shopProductBase.setProduct_id(productId); } // begin 新增,判断发布商品数量是否超限 @@ -740,26 +726,23 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl indexQueryWrapper = new QueryWrapper<>(); indexQueryWrapper.eq("store_id", store_id); + // 当前的商品数量 long product_num = shopProductIndexService.count(indexQueryWrapper); if (product_num >= store_grade_product_limit) { - throw new ApiException(I18nUtil._("发布产品数超过店铺当前等级可允许发布商品数!")); + return Pair.of(false, I18nUtil._("发布产品数超过店铺当前等级可允许发布商品数!")); } } } else { - //for baiduAi - ShopProductBase productBaseOld = shopProductBaseService.get(product_id); - + //for baiduAi 以图搜图 + ShopProductBase productBaseOld = shopProductBaseService.get(productId); if (productBaseOld != null) { product_image_old = productBaseOld.getProduct_image(); isUpdate = true; @@ -775,6 +758,7 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl assistItemList = new ArrayList<>(); if (CollUtil.isNotEmpty(shopProductAssistIndexList)) { @@ -835,7 +819,7 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl spec_item_ids = new ArrayList<>(); List item_names = new ArrayList<>(); - Long item_id = null; + Long item_id; for (Object josn_item_spec : array_item_spec) { cn.hutool.json.JSONObject item = (cn.hutool.json.JSONObject) ((cn.hutool.json.JSONObject) josn_item_spec).get("item"); @@ -1016,13 +996,13 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl del_baidu_image_row = new ArrayList<>(); - //List add_baidu_image_row = new ArrayList<>(); - //product_image String contSign = ""; String product_image_new = shopProductBase.getProduct_image(); @@ -1137,16 +1121,10 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl mqMessageVos = Collections.singletonList(new MqMessageVo(MqConstant.SHOP_EXCHANGE, MqConstant.SHOP_UPDATEDISTPRODUCT_ROUTING_KEY, product_id)); + List mqMessageVos = Collections.singletonList(new MqMessageVo(MqConstant.SHOP_EXCHANGE, MqConstant.SHOP_UPDATEDISTPRODUCT_ROUTING_KEY, productId)); mqMessageService.sendBatchMqMsg(mqMessageVos); } - return true; + return Pair.of(true, I18nUtil._("保存处理成功!")); } /** @@ -1520,22 +1494,22 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl product_contsign_map = BaiduAi.searchProductImg(productSearchDTO.getProduct_img_url(), productSearchDTO.getPage() - 1, productSearchDTO.getRows()); - //List contsigns = product_contsign_map.stream().map(s -> Convert.toStr(s.get("cont_sign"))).distinct().collect(Collectors.toList()); - List contsigns = new ArrayList<>(); + List product_contsign_map = BaiduAi.searchProductImg(productSearchDTO.getProduct_img_url(), productSearchDTO.getPage() - 1, productSearchDTO.getRows()); - for (Map row : product_contsign_map) { - BigDecimal score = Convert.toBigDecimal(row.get("score")); - if (score.compareTo(BigDecimal.valueOf(0.8)) > 0) { - contsigns.add(Convert.toStr(row.get("cont_sign"))); - } + //List contsigns = product_contsign_map.stream().map(s -> Convert.toStr(s.get("cont_sign"))).distinct().collect(Collectors.toList()); + List contsigns = new ArrayList<>(); + + for (Map row : product_contsign_map) { + BigDecimal score = Convert.toBigDecimal(row.get("score")); + if (score.compareTo(BigDecimal.valueOf(0.8)) > 0) { + contsigns.add(Convert.toStr(row.get("cont_sign"))); } + } - if (CollUtil.isNotEmpty(contsigns)) { - column_row.in("product_contsign", contsigns); - } + if (CollUtil.isNotEmpty(contsigns)) { + column_row.in("product_contsign", contsigns); + } /* //todo 修正排序 @@ -1543,9 +1517,7 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("store_id", store_id); + queryWrapper.eq("product_number", product_number); + queryWrapper.select("product_id"); + ShopProductBase record = getOne(queryWrapper); + if (record == null || record.getProduct_id() == null) { + return null; + } + + return record.getProduct_id(); + } + @Override @Transactional public boolean updateProductSubsite(Integer store_id) { @@ -5109,6 +5106,7 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl goodsList = sxSyncGoodsService.pageByStoreId(storeId, CommonConstant.Disable2, i, pageSize).getRecords(); @@ -5116,7 +5114,7 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl(), new ShopProductValidPeriod(), new ArrayList()); + Pair pair = saveProduct(shopProductBase, shopProductIndex, shopProductData, shopProductDetail, shopProductInfo, shopProductItemList, new ArrayList(), new ShopProductValidPeriod(), new ArrayList()); + if (!pair.getFirst()) { + logger.error(pair.getSecond()); + continue; + } + + successCnt += 1; } } - return true; + return successCnt > 0; }