From d00810baf1e277263521910fd6bc1945e5245ebf Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Mon, 8 Apr 2024 17:02:53 +0800 Subject: [PATCH] =?UTF-8?q?TASK:=E6=90=AD=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mixi/schedule/ReCollocationSchedule.java | 2 +- .../java/com/mixi/service/PythonService.java | 3 +- .../com/mixi/service/TProductService.java | 56 ++++++++++++------- 3 files changed, 39 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/mixi/schedule/ReCollocationSchedule.java b/src/main/java/com/mixi/schedule/ReCollocationSchedule.java index 7d621a1..edefe7a 100644 --- a/src/main/java/com/mixi/schedule/ReCollocationSchedule.java +++ b/src/main/java/com/mixi/schedule/ReCollocationSchedule.java @@ -21,7 +21,7 @@ public class ReCollocationSchedule { * @author yl * @since 2023-04-13 */ -// @Scheduled(cron = "0 0 1 * * ?") + @Scheduled(cron = "0 0 1 * * ?") // @Scheduled(cron = "0 0/2 * * * ?") public void websocketHeartBeatTask() { log.info("定时任务-商品重新搭配开始---------"); diff --git a/src/main/java/com/mixi/service/PythonService.java b/src/main/java/com/mixi/service/PythonService.java index 16c81d8..2b9eca8 100644 --- a/src/main/java/com/mixi/service/PythonService.java +++ b/src/main/java/com/mixi/service/PythonService.java @@ -43,7 +43,7 @@ public class PythonService { * @param ids * @return */ - public JSONObject attributeRecognition(List pictureUrls,List ids) { + public JSONObject attributeRecognition(List pictureUrls,List ids, List category) { //限流校验 AccessLimitUtils.validate("attributeRecognition", 20); OkHttpClient client = new OkHttpClient().newBuilder() @@ -58,6 +58,7 @@ public class PythonService { content.put("upload_img_path", pictureUrls); //识别图片id数组 content.put("upload_img_id", ids); + content.put("upload_img_category", category); RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(content)); Request request = new Request.Builder() .url(accessPythonIp + ":9993/api/attribute") diff --git a/src/main/java/com/mixi/service/TProductService.java b/src/main/java/com/mixi/service/TProductService.java index 3ce3713..97250e8 100644 --- a/src/main/java/com/mixi/service/TProductService.java +++ b/src/main/java/com/mixi/service/TProductService.java @@ -1071,7 +1071,8 @@ public class TProductService extends ServiceImpl { //计算python商品属性,性能慢 一次一件 JSONObject productIdInnerToMap = pythonService.attributeRecognition( Collections.singletonList(tProduct.getPictureUrl()), - Collections.singletonList(tProduct.getId().toString())); + Collections.singletonList(tProduct.getId().toString()), + Collections.singletonList(tProduct.getPictureUrl().split("/")[2] + "/" + tProduct.getPictureUrl().split("/")[3])); //保存商品属性 tProductAttributeService.saveBatch(resolveProductAttributeNew(productIdInnerToMap, product.getTimeZone())); // resolveProductIdToMap(productIdToMap, productIdInnerToMap); @@ -1860,29 +1861,44 @@ public class TProductService extends ServiceImpl { List> questList = Lists.partition(page.getRecords(), 10); questList.forEach(list -> { //校验规则 - List validateList = validateGenerateProductAssortment(list, null, dataBase, tProductIdToAttributeItemNewMap); - if (CollectionUtils.isEmpty(validateList)) { - return; - } +// List validateList = validateGenerateProductAssortment(list, null, dataBase, tProductIdToAttributeItemNewMap); +// if (CollectionUtils.isEmpty(validateList)) { +// return; +// } + List validateList = list; try { - Map dataBaseMap = dataBase.stream().collect(Collectors.toMap(p -> p.getId().toString(), - p2 -> GenerateCollocationDataBaseDTO.builder() - .category(tProductIdToAttributeItemNewMap.get(p2.getId())) - .path(p2.getPictureUrl()).build(), (v1, v2) -> v2)); - //推荐搭配 - List collocationOutResult = pythonService.generateCollocation( - validateList.stream() - .map(product1 -> - GenerateCollocationQueryDTO.builder() - .item_category(tProductIdToAttributeItemNewMap.get(product1.getId())) - .path(product1.getPictureUrl()) - .item_id(product1.getId().toString()).build()) - .collect(Collectors.toList()), dataBaseMap - ); + QueryWrapper qw = new QueryWrapper<>(); + List db = tProductMapper.selectList(qw); + List query = new ArrayList<>(); + List database = new ArrayList<>(); + for (TProduct tProduct : validateList) { + GenerateCollocationQueryNewDTO vo = new GenerateCollocationQueryNewDTO(); +// vo.setItem_name(tProduct.getPictureName().split("_")[0]); + vo.setItem_name(tProduct.getPictureName()); + vo.setImage_path(tProduct.getPictureUrl()); + String[] split = tProduct.getPictureUrl().split("/"); + vo.setSemantic_category(split[2] + "/" + split[3]); + query.add(vo); + } + for (TProduct tProduct : db) { + GenerateCollocationQueryNewDTO vo = new GenerateCollocationQueryNewDTO(); +// vo.setItem_name(tProduct.getPictureName().split("_")[0]); + vo.setItem_name(tProduct.getPictureName()); + vo.setImage_path(tProduct.getPictureUrl()); + String[] split = tProduct.getPictureUrl().split("/"); + vo.setSemantic_category(split[2] + "/" + split[3]); + database.add(vo); + } + List collocationOutResult = pythonService.generateCollocationNew(query, database); //保存搭配数据 + List collect = validateList.stream().map(TProduct::getId).collect(Collectors.toList()); + for (Long l : collect) { + tProductAssortmentService.deleteByProductId(String.valueOf(l)); + } tProductAssortmentService.saveBatch( - resolveProductAssortment(collocationOutResult, dataBaseMap, "Asia/Shanghai")); + resolveProductAssortmentNew(collocationOutResult, "Asia/Shanghai")); //更新商品的搭配状态为已搭配 + System.out.println(collocationOutResult); validateList.stream().forEach(pro -> pro.setCollocationState(1)); this.updateBatchById(validateList); } catch (Exception e) {