From 67068fb9f71814ad46f1863fe88f77a85d1a5303 Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Thu, 8 May 2025 17:59:34 +0800 Subject: [PATCH] TASK:mixi; --- .../com/mixi/service/TProductService.java | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/mixi/service/TProductService.java b/src/main/java/com/mixi/service/TProductService.java index 4d43a27..a1488ff 100644 --- a/src/main/java/com/mixi/service/TProductService.java +++ b/src/main/java/com/mixi/service/TProductService.java @@ -787,13 +787,13 @@ public class TProductService extends ServiceImpl { if (originalFilename == null) { throw new BusinessException("file name is null."); } - String itemNameColorCode = originalFilename.substring(0, originalFilename.lastIndexOf('.')); + String fileName = originalFilename.substring(0, originalFilename.lastIndexOf('.')); // 根据itemName查询mi-tu商品信息 // 根据最后一个"_"分割itemNameColorCode - int lastUnderscoreIndex = itemNameColorCode.lastIndexOf("_"); +// int lastUnderscoreIndex = itemNameColorCode.lastIndexOf("_"); // String itemName = itemNameColorCode.substring(0, lastUnderscoreIndex); - String colorCode = itemNameColorCode.substring(lastUnderscoreIndex + 1); +// String colorCode = itemNameColorCode.substring(lastUnderscoreIndex + 1); // List miTuProductList = getMiTuProductList(itemName, colorCode); int total = 0; // for (MiTuProduct miTuProduct : miTuProductList) { @@ -806,17 +806,19 @@ public class TProductService extends ServiceImpl { String minioFullPath = minioUtil.upload(MI_TU_BUCKET_NAME, minioPath, file); TProduct saveProduct = new TProduct(); saveProduct.setAccountId(accountId); - saveProduct.setPrice(BigDecimal.valueOf(1000.0d)); + Random random = new Random(); + double randomDouble = 500 + (1500 - 500) * random.nextDouble(); + saveProduct.setPrice(BigDecimal.valueOf(randomDouble)); saveProduct.setOnSaleState(1); //上传中 saveProduct.setUploadState(0); saveProduct.setPictureUrl(minioFullPath); - saveProduct.setPictureName(itemNameColorCode); + saveProduct.setPictureName(fileName); saveProduct.setMd5(md5); //按时区计算 saveProduct.setCreateDate(DateUtil.getByTimeZone(timeZone)); - saveProduct.setColor(colorCode); +// saveProduct.setColor(colorCode); // 根据当前已有店铺查询商品店铺库存 // List miTuProductStock = new ArrayList<>(); // List storeList = storeService.list(); @@ -832,7 +834,9 @@ public class TProductService extends ServiceImpl { // for (MiTuProductStock tuProductStock : miTuProductStock) { // total = total + tuProductStock.getNum(); // } - saveProduct.setTotal(10); +// Random random = new Random(); + int randomNumber = random.nextInt(16) + 5; + saveProduct.setTotal(randomNumber); tProductMapper.insert(saveProduct); // List productStockList = new ArrayList<>(); // HashMap> map = new HashMap<>(); @@ -1230,8 +1234,9 @@ public class TProductService extends ServiceImpl { // 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]); + String attributeItem = getProductAttributeItem(tProduct.getId()); +// String[] split = tProduct.getPictureUrl().split("/"); + vo.setSemantic_category(attributeItem); query.add(vo); } for (TProduct tProduct : db) { @@ -1239,8 +1244,9 @@ public class TProductService extends ServiceImpl { // 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]); + String attributeItem = getProductAttributeItem(tProduct.getId()); +// String[] split = tProduct.getPictureUrl().split("/"); + vo.setSemantic_category(attributeItem); database.add(vo); } List collocationOutResult = pythonService.generateCollocationNew(query, database); @@ -1277,6 +1283,16 @@ public class TProductService extends ServiceImpl { return result; } + private String getProductAttributeItem(Long id) { + QueryWrapper qw = new QueryWrapper<>(); + qw.lambda().eq(TProductAttribute::getProductId, id); + List list = tProductAttributeService.list(qw); + if (CollectionUtils.isEmpty(list)) { + return null; + } + return list.get(0).getAttributeItem(); + } + private Collection resolveProductAssortmentNew(List collocationOutResult, String timeZone) { log.info("获取python推荐搭配总数据是###{}", JSON.toJSONString(collocationOutResult)); List result = Lists.newArrayList();