|
|
@@ -9,8 +9,8 @@ import java.util.List;
|
|
|
import java.util.Random;
|
|
|
|
|
|
/**
|
|
|
- * 模拟商品数据服务(用于开发/测试环境)
|
|
|
- * 支持百货、服饰两类商品,自动分配商品名称、描述和图片
|
|
|
+ * 模拟商品数据服务(用于炮灰小程序)
|
|
|
+ * 支持百货、服饰两类商品,每个商品模板包含名称、描述、图片,确保图文匹配
|
|
|
*/
|
|
|
@Service
|
|
|
public class ProductServiceMock {
|
|
|
@@ -40,97 +40,77 @@ public class ProductServiceMock {
|
|
|
List<FsStoreProductListQueryVO> list = new ArrayList<>(limit);
|
|
|
Random random = new Random();
|
|
|
|
|
|
- // ----- 1. 分类商品名称(按类别) -----
|
|
|
- String[][] namesByCategory = {
|
|
|
- // 百货(category=1)
|
|
|
- {
|
|
|
- "不锈钢保温杯", "多功能收纳盒", "竹纤维毛巾", "无痕衣架(10个装)", "可折叠购物袋",
|
|
|
- "陶瓷马克杯", "保鲜碗三件套", "厨房计时器", "防滑地垫", "LED小夜灯",
|
|
|
- "指甲刀套装", "化妆棉(200片)", "牙刷架", "挂钩贴", "桌面垃圾桶"
|
|
|
- },
|
|
|
- // 服饰(category=2)
|
|
|
- {
|
|
|
- "纯棉短袖T恤", "宽松卫衣", "弹力牛仔裤", "运动休闲裤", "连帽开衫外套",
|
|
|
- "帆布鞋", "板鞋", "凉拖", "棒球帽", "帆布双肩包",
|
|
|
- "丝巾", "皮带", "袜子(5双装)", "内衣套装", "瑜伽裤"
|
|
|
- }
|
|
|
+ // ----- 定义商品模板(名称、描述、图片三者绑定) -----
|
|
|
+ // 百货模板(9个,与dailyImages一一对应)
|
|
|
+ ProductTemplate[] dailyTemplates = {
|
|
|
+ new ProductTemplate("不锈钢保温杯", "304不锈钢,长效保温",
|
|
|
+ "https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/%E4%BF%9D%E6%B8%A9%E6%9D%AF.jpg"),
|
|
|
+ new ProductTemplate("多功能收纳盒", "大容量,分类整理更轻松",
|
|
|
+ "https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/%E6%94%B6%E7%BA%B3%E7%9B%92.jpg"),
|
|
|
+ new ProductTemplate("竹纤维毛巾", "柔软吸水,亲肤耐用",
|
|
|
+ "https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/%E6%AF%9B%E5%B7%BE.jpg"),
|
|
|
+ new ProductTemplate("无痕衣架(10个装)", "防滑设计,坚固承重",
|
|
|
+ "https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/%E8%A1%A3%E6%9E%B6.jpg"),
|
|
|
+ new ProductTemplate("可折叠购物袋", "轻便折叠,环保材质",
|
|
|
+ "https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/%E6%8A%98%E5%8F%A0%E8%A2%8B.jpg"),
|
|
|
+ new ProductTemplate("陶瓷马克杯", "简约设计,手感细腻",
|
|
|
+ "https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/%E9%99%B6%E7%93%B7%E6%9D%AF.jpg"),
|
|
|
+ new ProductTemplate("厨房计时器", "精准定时,操作简单",
|
|
|
+ "https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/%E8%AE%A1%E6%97%B6%E5%99%A8.jpg"),
|
|
|
+ new ProductTemplate("LED小夜灯", "柔光不刺眼,节能省电",
|
|
|
+ "https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/%E5%B0%8F%E5%A4%9C%E7%81%AF.jpg"),
|
|
|
+ new ProductTemplate("防滑地垫", "吸水防滑,易清洗",
|
|
|
+ "https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/%E5%9C%B0%E5%9E%AB.jpg")
|
|
|
};
|
|
|
|
|
|
- // ----- 2. 分类商品描述(按类别) -----
|
|
|
- String[][] infoByCategory = {
|
|
|
- // 百货描述
|
|
|
- {
|
|
|
- "304不锈钢,长效保温", "大容量,分类整理更轻松", "柔软吸水,亲肤耐用",
|
|
|
- "防滑设计,坚固承重", "轻便折叠,环保材质",
|
|
|
- "简约设计,手感细腻", "密封保鲜,微波可用", "精准定时,操作简单",
|
|
|
- "吸水防滑,易清洗", "柔光不刺眼,节能省电",
|
|
|
- "锋利耐用,收纳方便", "柔软亲肤,不掉絮", "免钉安装,节省空间",
|
|
|
- "强力承重,不留痕", "精致小巧,实用美观"
|
|
|
- },
|
|
|
- // 服饰描述
|
|
|
- {
|
|
|
- "100%纯棉,透气舒适", "潮流宽松,百搭时尚", "高弹力,修身显瘦",
|
|
|
- "运动休闲,自在自如", "连帽设计,防风保暖",
|
|
|
- "经典帆布,轻便耐磨", "简约板鞋,日常百搭", "EVA材质,软底防滑",
|
|
|
- "可调节帽围,遮阳防晒", "大容量,轻便背负",
|
|
|
- "真丝质感,优雅点缀", "头层牛皮,质感出众", "精梳棉,吸汗透气",
|
|
|
- "舒适无痕,贴身呵护", "高弹力,适合瑜伽运动"
|
|
|
- }
|
|
|
+ // 服饰模板(9个,与clothingImages一一对应)
|
|
|
+ ProductTemplate[] clothingTemplates = {
|
|
|
+ new ProductTemplate("纯棉短袖T恤", "100%纯棉,透气舒适",
|
|
|
+ "https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/T%E6%81%A4.jpg"),
|
|
|
+ new ProductTemplate("宽松卫衣", "潮流宽松,百搭时尚",
|
|
|
+ "https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/%E5%8D%AB%E8%A1%A3.jpg"),
|
|
|
+ new ProductTemplate("弹力牛仔裤", "高弹力,修身显瘦",
|
|
|
+ "https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/%E7%89%9B%E4%BB%94%E8%A3%A4.jpg"),
|
|
|
+ new ProductTemplate("帆布鞋", "经典帆布,轻便耐磨",
|
|
|
+ "https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/%E5%B8%86%E5%B8%83%E9%9E%8B.jpg"),
|
|
|
+ new ProductTemplate("运动休闲裤", "运动休闲,自在自如",
|
|
|
+ "https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/%E4%BC%91%E9%97%B2%E8%A3%A4.jpg"),
|
|
|
+ new ProductTemplate("棒球帽", "可调节帽围,遮阳防晒",
|
|
|
+ "https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/%E6%A3%92%E7%90%83%E5%B8%BD.jpg"),
|
|
|
+ new ProductTemplate("帆布双肩包", "大容量,轻便背负",
|
|
|
+ "https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/%E5%8F%8C%E8%82%A9%E5%8C%85.jpg"),
|
|
|
+ new ProductTemplate("丝巾", "真丝质感,优雅点缀",
|
|
|
+ "https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/%E4%B8%9D%E5%B7%BE.jpg"),
|
|
|
+ new ProductTemplate("皮带", "头层牛皮,质感出众",
|
|
|
+ "https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/%E7%9A%AE%E5%B8%A6.jpg")
|
|
|
};
|
|
|
|
|
|
- // ----- 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;
|
|
|
+ // 根据 category 选择对应的模板数组
|
|
|
+ ProductTemplate[] templates = (category == 2) ? clothingTemplates : dailyTemplates;
|
|
|
|
|
|
// 通用单位
|
|
|
String[] unitNames = {"个", "件", "双", "条", "只", "套", "盒"};
|
|
|
|
|
|
- // ----- 4. 循环生成指定数量的商品 -----
|
|
|
+ // ----- 循环生成指定数量的商品 -----
|
|
|
for (int i = 0; i < limit; i++) {
|
|
|
FsStoreProductListQueryVO vo = new FsStoreProductListQueryVO();
|
|
|
|
|
|
+ // 从模板中按顺序循环取(保证图文匹配),也可改为随机取但模板本身已匹配
|
|
|
+ ProductTemplate template = templates[i % templates.length];
|
|
|
+
|
|
|
// ---- 基础ID ----
|
|
|
- vo.setProductId(400000L + i + 1 + category * 100000L); // 不同类别ID段不同
|
|
|
+ vo.setProductId(400000L + i + 1 + category * 100000L);
|
|
|
vo.setStoreId(500000L + random.nextInt(100));
|
|
|
|
|
|
- // ---- 图片(随机从对应图片池中选取) ----
|
|
|
- String randomImageUrl = images[random.nextInt(images.length)];
|
|
|
- vo.setImage(randomImageUrl);
|
|
|
+ // ---- 图片(直接从模板获取) ----
|
|
|
+ vo.setImage(template.imageUrl);
|
|
|
|
|
|
// ---- 商品名称(加前缀区分推荐/喜欢) ----
|
|
|
- String baseName = names[i % names.length];
|
|
|
String prefix = "推荐".equals(type) ? "🔥 " : "❤️ ";
|
|
|
- vo.setProductName(prefix + baseName);
|
|
|
+ vo.setProductName(prefix + template.name);
|
|
|
|
|
|
// ---- 商品描述 ----
|
|
|
- vo.setProductInfo(infos[i % infos.length]);
|
|
|
+ vo.setProductInfo(template.desc);
|
|
|
|
|
|
// ---- 分类ID(随机1~12) ----
|
|
|
vo.setCateId((long) (random.nextInt(12) + 1));
|
|
|
@@ -149,7 +129,7 @@ public class ProductServiceMock {
|
|
|
// ---- 单位 ----
|
|
|
vo.setUnitName(unitNames[random.nextInt(unitNames.length)]);
|
|
|
|
|
|
- // ---- ★ 非药品标志,所有药品字段置 null(与真实数据一致) ★ ----
|
|
|
+ // ---- ★ 非药品标志,所有药品字段置 null ★ ----
|
|
|
vo.setIsDrug("0");
|
|
|
vo.setDrugImage(null);
|
|
|
vo.setDrugRegCertNo(null);
|
|
|
@@ -167,10 +147,10 @@ public class ProductServiceMock {
|
|
|
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();
|
|
|
@@ -180,7 +160,7 @@ public class ProductServiceMock {
|
|
|
}
|
|
|
vo.setStoreIds(ids.toString());
|
|
|
|
|
|
- // ---- 是否赠品(约15%概率) ----
|
|
|
+ // ---- 是否赠品 ----
|
|
|
vo.setIsGift(random.nextInt(7) == 0 ? 1 : 0);
|
|
|
|
|
|
list.add(vo);
|
|
|
@@ -188,4 +168,17 @@ public class ProductServiceMock {
|
|
|
|
|
|
return list;
|
|
|
}
|
|
|
+
|
|
|
+ // ---------- 内部模板类 ----------
|
|
|
+ private static class ProductTemplate {
|
|
|
+ String name;
|
|
|
+ String desc;
|
|
|
+ String imageUrl;
|
|
|
+
|
|
|
+ ProductTemplate(String name, String desc, String imageUrl) {
|
|
|
+ this.name = name;
|
|
|
+ this.desc = desc;
|
|
|
+ this.imageUrl = imageUrl;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|