|
|
@@ -0,0 +1,191 @@
|
|
|
+package com.fs.hisStore.service.impl;
|
|
|
+
|
|
|
+import com.fs.hisStore.vo.FsStoreProductListQueryVO;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Random;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 模拟商品数据服务(用于开发/测试环境)
|
|
|
+ * 支持百货、服饰两类商品,自动分配商品名称、描述和图片
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class ProductServiceMock {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 模拟推荐商品列表
|
|
|
+ * @param limit 返回条数
|
|
|
+ * @param category 商品类别:1-百货,2-服饰
|
|
|
+ * @return 商品列表
|
|
|
+ */
|
|
|
+ public List<FsStoreProductListQueryVO> selectFsStoreProductTuiQuery(int limit, int category) {
|
|
|
+ return generateMockList(limit, category, "推荐");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 模拟喜欢商品列表
|
|
|
+ * @param limit 返回条数
|
|
|
+ * @param category 商品类别:1-百货,2-服饰
|
|
|
+ * @return 商品列表
|
|
|
+ */
|
|
|
+ public List<FsStoreProductListQueryVO> selectFsStoreProductGoodQuery(int limit, int category) {
|
|
|
+ return generateMockList(limit, category, "喜欢");
|
|
|
+ }
|
|
|
+
|
|
|
+ // ================== 私有核心生成方法 ==================
|
|
|
+ private List<FsStoreProductListQueryVO> generateMockList(int limit, int category, String type) {
|
|
|
+ List<FsStoreProductListQueryVO> list = new ArrayList<>(limit);
|
|
|
+ Random random = new Random();
|
|
|
+
|
|
|
+ // ----- 1. 分类商品名称(按类别) -----
|
|
|
+ String[][] namesByCategory = {
|
|
|
+ // 百货(category=1)
|
|
|
+ {
|
|
|
+ "不锈钢保温杯", "多功能收纳盒", "竹纤维毛巾", "无痕衣架(10个装)", "可折叠购物袋",
|
|
|
+ "陶瓷马克杯", "保鲜碗三件套", "厨房计时器", "防滑地垫", "LED小夜灯",
|
|
|
+ "指甲刀套装", "化妆棉(200片)", "牙刷架", "挂钩贴", "桌面垃圾桶"
|
|
|
+ },
|
|
|
+ // 服饰(category=2)
|
|
|
+ {
|
|
|
+ "纯棉短袖T恤", "宽松卫衣", "弹力牛仔裤", "运动休闲裤", "连帽开衫外套",
|
|
|
+ "帆布鞋", "板鞋", "凉拖", "棒球帽", "帆布双肩包",
|
|
|
+ "丝巾", "皮带", "袜子(5双装)", "内衣套装", "瑜伽裤"
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ // ----- 2. 分类商品描述(按类别) -----
|
|
|
+ String[][] infoByCategory = {
|
|
|
+ // 百货描述
|
|
|
+ {
|
|
|
+ "304不锈钢,长效保温", "大容量,分类整理更轻松", "柔软吸水,亲肤耐用",
|
|
|
+ "防滑设计,坚固承重", "轻便折叠,环保材质",
|
|
|
+ "简约设计,手感细腻", "密封保鲜,微波可用", "精准定时,操作简单",
|
|
|
+ "吸水防滑,易清洗", "柔光不刺眼,节能省电",
|
|
|
+ "锋利耐用,收纳方便", "柔软亲肤,不掉絮", "免钉安装,节省空间",
|
|
|
+ "强力承重,不留痕", "精致小巧,实用美观"
|
|
|
+ },
|
|
|
+ // 服饰描述
|
|
|
+ {
|
|
|
+ "100%纯棉,透气舒适", "潮流宽松,百搭时尚", "高弹力,修身显瘦",
|
|
|
+ "运动休闲,自在自如", "连帽设计,防风保暖",
|
|
|
+ "经典帆布,轻便耐磨", "简约板鞋,日常百搭", "EVA材质,软底防滑",
|
|
|
+ "可调节帽围,遮阳防晒", "大容量,轻便背负",
|
|
|
+ "真丝质感,优雅点缀", "头层牛皮,质感出众", "精梳棉,吸汗透气",
|
|
|
+ "舒适无痕,贴身呵护", "高弹力,适合瑜伽运动"
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ // ----- 3. 分类商品图片(按类别)★ 请替换为你的真实图片链接 ★ -----
|
|
|
+ String[] dailyImages = {
|
|
|
+ "https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/%E6%94%B6%E7%BA%B3%E7%9B%92.jpg", // 收纳盒
|
|
|
+ "https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/%E4%BF%9D%E6%B8%A9%E6%9D%AF.jpg", // 保温杯
|
|
|
+ "https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/%E6%AF%9B%E5%B7%BE.jpg", // 毛巾
|
|
|
+ "https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/%E8%A1%A3%E6%9E%B6.jpg", // 衣架
|
|
|
+ "https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/%E6%8A%98%E5%8F%A0%E8%A2%8B.jpg", // 折叠袋
|
|
|
+ "https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/%E9%99%B6%E7%93%B7%E6%9D%AF.jpg", // 陶瓷杯
|
|
|
+ "https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/%E8%AE%A1%E6%97%B6%E5%99%A8.jpg", // 计时器
|
|
|
+ "https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/%E5%B0%8F%E5%A4%9C%E7%81%AF.jpg", // 小夜灯
|
|
|
+ "https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/%E5%9C%B0%E5%9E%AB.jpg" // 地垫
|
|
|
+ };
|
|
|
+
|
|
|
+ String[] clothingImages = {
|
|
|
+ "https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/T%E6%81%A4.jpg", // T恤
|
|
|
+ "https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/%E5%8D%AB%E8%A1%A3.jpg", // 卫衣
|
|
|
+ "https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/%E7%89%9B%E4%BB%94%E8%A3%A4.jpg", // 牛仔裤
|
|
|
+ "https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/%E5%B8%86%E5%B8%83%E9%9E%8B.jpg",// 帆布鞋
|
|
|
+ "https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/%E4%BC%91%E9%97%B2%E8%A3%A4.jpg",// 休闲裤
|
|
|
+ "https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/%E6%A3%92%E7%90%83%E5%B8%BD.jpg",// 棒球帽
|
|
|
+ "https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/%E5%8F%8C%E8%82%A9%E5%8C%85.jpg", // 双肩包
|
|
|
+ "https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/%E4%B8%9D%E5%B7%BE.jpg", // 丝巾
|
|
|
+ "https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/%E7%9A%AE%E5%B8%A6.jpg" // 皮带
|
|
|
+ };
|
|
|
+
|
|
|
+ // 根据 category 选择对应的数据池
|
|
|
+ int idx = (category == 2) ? 1 : 0;
|
|
|
+ String[] names = namesByCategory[idx];
|
|
|
+ String[] infos = infoByCategory[idx];
|
|
|
+ String[] images = (category == 2) ? clothingImages : dailyImages;
|
|
|
+
|
|
|
+ // 通用单位
|
|
|
+ String[] unitNames = {"个", "件", "双", "条", "只", "套", "盒"};
|
|
|
+
|
|
|
+ // ----- 4. 循环生成指定数量的商品 -----
|
|
|
+ for (int i = 0; i < limit; i++) {
|
|
|
+ FsStoreProductListQueryVO vo = new FsStoreProductListQueryVO();
|
|
|
+
|
|
|
+ // ---- 基础ID ----
|
|
|
+ vo.setProductId(400000L + i + 1 + category * 100000L); // 不同类别ID段不同
|
|
|
+ vo.setStoreId(500000L + random.nextInt(100));
|
|
|
+
|
|
|
+ // ---- 图片(随机从对应图片池中选取) ----
|
|
|
+ String randomImageUrl = images[random.nextInt(images.length)];
|
|
|
+ vo.setImage(randomImageUrl);
|
|
|
+
|
|
|
+ // ---- 商品名称(加前缀区分推荐/喜欢) ----
|
|
|
+ String baseName = names[i % names.length];
|
|
|
+ String prefix = "推荐".equals(type) ? "🔥 " : "❤️ ";
|
|
|
+ vo.setProductName(prefix + baseName);
|
|
|
+
|
|
|
+ // ---- 商品描述 ----
|
|
|
+ vo.setProductInfo(infos[i % infos.length]);
|
|
|
+
|
|
|
+ // ---- 分类ID(随机1~12) ----
|
|
|
+ vo.setCateId((long) (random.nextInt(12) + 1));
|
|
|
+
|
|
|
+ // ---- 价格(百货5~150,服饰20~300) ----
|
|
|
+ double minPrice = (category == 2) ? 20 : 5;
|
|
|
+ double maxPrice = (category == 2) ? 300 : 150;
|
|
|
+ double priceVal = minPrice + random.nextDouble() * (maxPrice - minPrice);
|
|
|
+ vo.setPrice(BigDecimal.valueOf(priceVal).setScale(2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ double otPriceVal = priceVal * (0.8 + random.nextDouble() * 0.5);
|
|
|
+ vo.setOtPrice(BigDecimal.valueOf(otPriceVal).setScale(2, BigDecimal.ROUND_HALF_UP));
|
|
|
+
|
|
|
+ // ---- 销量(0~9999) ----
|
|
|
+ vo.setSales(random.nextInt(10000));
|
|
|
+
|
|
|
+ // ---- 单位 ----
|
|
|
+ vo.setUnitName(unitNames[random.nextInt(unitNames.length)]);
|
|
|
+
|
|
|
+ // ---- ★ 非药品标志,所有药品字段置 null(与真实数据一致) ★ ----
|
|
|
+ vo.setIsDrug("0");
|
|
|
+ vo.setDrugImage(null);
|
|
|
+ vo.setDrugRegCertNo(null);
|
|
|
+ vo.setCommonName(null);
|
|
|
+ vo.setDosageForm(null);
|
|
|
+ vo.setUnitPrice(null);
|
|
|
+ vo.setBatchNumber(null);
|
|
|
+ vo.setMah(null);
|
|
|
+ vo.setMahAddress(null);
|
|
|
+ vo.setManufacturer(null);
|
|
|
+ vo.setManufacturerAddress(null);
|
|
|
+ vo.setIndications(null);
|
|
|
+ vo.setDosage(null);
|
|
|
+ vo.setAdverseReactions(null);
|
|
|
+ vo.setContraindications(null);
|
|
|
+ vo.setPrecautions(null);
|
|
|
+
|
|
|
+ // ---- 审核状态(固定为"1") ----
|
|
|
+ vo.setIsAudit("1");
|
|
|
+
|
|
|
+ // ---- 店铺信息(随机1~5个店铺) ----
|
|
|
+ int storeCount = random.nextInt(5) + 1;
|
|
|
+ vo.setStoreCount(storeCount);
|
|
|
+ StringBuilder ids = new StringBuilder();
|
|
|
+ for (int j = 0; j < storeCount; j++) {
|
|
|
+ if (j > 0) ids.append(",");
|
|
|
+ ids.append(500000L + random.nextInt(100));
|
|
|
+ }
|
|
|
+ vo.setStoreIds(ids.toString());
|
|
|
+
|
|
|
+ // ---- 是否赠品(约15%概率) ----
|
|
|
+ vo.setIsGift(random.nextInt(7) == 0 ? 1 : 0);
|
|
|
+
|
|
|
+ list.add(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+}
|