|
@@ -1,47 +1,46 @@
|
|
|
package com.fs.hisStore.service.impl;
|
|
package com.fs.hisStore.service.impl;
|
|
|
|
|
|
|
|
import com.fs.hisStore.vo.FsStoreProductListQueryVO;
|
|
import com.fs.hisStore.vo.FsStoreProductListQueryVO;
|
|
|
|
|
+import com.fs.hisStore.vo.FsStoreProductQueryVO;
|
|
|
|
|
+import com.fs.hisStore.domain.FsStoreProductAttrScrm;
|
|
|
|
|
+import com.fs.hisStore.domain.FsStoreProductAttrValueScrm;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-import java.util.Random;
|
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 模拟商品数据服务(用于炮灰小程序)
|
|
* 模拟商品数据服务(用于炮灰小程序)
|
|
|
* 支持百货、服饰两类商品,每个商品模板包含名称、描述、图片,确保图文匹配
|
|
* 支持百货、服饰两类商品,每个商品模板包含名称、描述、图片,确保图文匹配
|
|
|
|
|
+ * 并预生成固定ID的商品缓存,支持按ID查询详情
|
|
|
*/
|
|
*/
|
|
|
@Service
|
|
@Service
|
|
|
public class ProductServiceMock {
|
|
public class ProductServiceMock {
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 模拟推荐商品列表
|
|
|
|
|
- * @param limit 返回条数
|
|
|
|
|
- * @param category 商品类别:1-百货,2-服饰
|
|
|
|
|
- * @return 商品列表
|
|
|
|
|
- */
|
|
|
|
|
- public List<FsStoreProductListQueryVO> selectFsStoreProductTuiQuery(int limit, int category) {
|
|
|
|
|
- return generateMockList(limit, category, "推荐");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 存储所有模拟商品详情(按ID)
|
|
|
|
|
+ private final Map<Long, FsStoreProductQueryVO> productDetailCache = new ConcurrentHashMap<>();
|
|
|
|
|
+ // 存储百货和服饰的商品ID列表(用于列表查询)
|
|
|
|
|
+ private final List<Long> dailyProductIds = new ArrayList<>();
|
|
|
|
|
+ private final List<Long> clothingProductIds = new ArrayList<>();
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 模拟喜欢商品列表
|
|
|
|
|
- * @param limit 返回条数
|
|
|
|
|
- * @param category 商品类别:1-百货,2-服饰
|
|
|
|
|
- * @return 商品列表
|
|
|
|
|
- */
|
|
|
|
|
- public List<FsStoreProductListQueryVO> selectFsStoreProductGoodQuery(int limit, int category) {
|
|
|
|
|
- return generateMockList(limit, category, "喜欢");
|
|
|
|
|
|
|
+ // 商品模板(名称、描述、图片)
|
|
|
|
|
+ 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;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // ================== 私有核心生成方法 ==================
|
|
|
|
|
- private List<FsStoreProductListQueryVO> generateMockList(int limit, int category, String type) {
|
|
|
|
|
- List<FsStoreProductListQueryVO> list = new ArrayList<>(limit);
|
|
|
|
|
- Random random = new Random();
|
|
|
|
|
-
|
|
|
|
|
- // ----- 定义商品模板(名称、描述、图片三者绑定) -----
|
|
|
|
|
- // 百货模板(9个,与dailyImages一一对应)
|
|
|
|
|
|
|
+ // 预生成所有商品,初始化缓存
|
|
|
|
|
+ @PostConstruct
|
|
|
|
|
+ private void init() {
|
|
|
|
|
+ // ----- 百货模板(9个) -----
|
|
|
ProductTemplate[] dailyTemplates = {
|
|
ProductTemplate[] dailyTemplates = {
|
|
|
new ProductTemplate("不锈钢保温杯", "304不锈钢,长效保温",
|
|
new ProductTemplate("不锈钢保温杯", "304不锈钢,长效保温",
|
|
|
"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/%E4%BF%9D%E6%B8%A9%E6%9D%AF.jpg"),
|
|
@@ -63,7 +62,7 @@ public class ProductServiceMock {
|
|
|
"https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/%E5%9C%B0%E5%9E%AB.jpg")
|
|
"https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/%E5%9C%B0%E5%9E%AB.jpg")
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- // 服饰模板(9个,与clothingImages一一对应)
|
|
|
|
|
|
|
+ // ----- 服饰模板(9个) -----
|
|
|
ProductTemplate[] clothingTemplates = {
|
|
ProductTemplate[] clothingTemplates = {
|
|
|
new ProductTemplate("纯棉短袖T恤", "100%纯棉,透气舒适",
|
|
new ProductTemplate("纯棉短袖T恤", "100%纯棉,透气舒适",
|
|
|
"https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/T%E6%81%A4.jpg"),
|
|
"https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/T%E6%81%A4.jpg"),
|
|
@@ -85,100 +84,150 @@ public class ProductServiceMock {
|
|
|
"https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/%E7%9A%AE%E5%B8%A6.jpg")
|
|
"https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/app/casualtiesType/%E7%9A%AE%E5%B8%A6.jpg")
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- // 根据 category 选择对应的模板数组
|
|
|
|
|
- ProductTemplate[] templates = (category == 2) ? clothingTemplates : dailyTemplates;
|
|
|
|
|
|
|
+ // 生成百货商品,ID从 800001 开始
|
|
|
|
|
+ long baseId = 800001L;
|
|
|
|
|
+ for (int i = 0; i < dailyTemplates.length; i++) {
|
|
|
|
|
+ ProductTemplate t = dailyTemplates[i];
|
|
|
|
|
+ Long productId = baseId + i;
|
|
|
|
|
+ FsStoreProductQueryVO vo = buildProductDetail(productId, t, 1); // category=1 百货
|
|
|
|
|
+ productDetailCache.put(productId, vo);
|
|
|
|
|
+ dailyProductIds.add(productId);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // 通用单位
|
|
|
|
|
- String[] unitNames = {"个", "件", "双", "条", "只", "套", "盒"};
|
|
|
|
|
|
|
+ // 生成服饰商品,ID从 900001 开始
|
|
|
|
|
+ baseId = 900001L;
|
|
|
|
|
+ for (int i = 0; i < clothingTemplates.length; i++) {
|
|
|
|
|
+ ProductTemplate t = clothingTemplates[i];
|
|
|
|
|
+ Long productId = baseId + i;
|
|
|
|
|
+ FsStoreProductQueryVO vo = buildProductDetail(productId, t, 2); // category=2 服饰
|
|
|
|
|
+ productDetailCache.put(productId, vo);
|
|
|
|
|
+ clothingProductIds.add(productId);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // ----- 循环生成指定数量的商品 -----
|
|
|
|
|
- for (int i = 0; i < limit; i++) {
|
|
|
|
|
- FsStoreProductListQueryVO vo = new FsStoreProductListQueryVO();
|
|
|
|
|
|
|
+ // 构建商品详情对象(FsStoreProductQueryVO)
|
|
|
|
|
+ private FsStoreProductQueryVO buildProductDetail(Long productId, ProductTemplate template, int category) {
|
|
|
|
|
+ FsStoreProductQueryVO vo = new FsStoreProductQueryVO();
|
|
|
|
|
+ vo.setProductId(productId);
|
|
|
|
|
+ vo.setStoreId("500000"); // 固定店铺ID(可模拟)
|
|
|
|
|
+ vo.setImage(template.imageUrl);
|
|
|
|
|
+ vo.setSliderImage(template.imageUrl);
|
|
|
|
|
+ vo.setProductName(template.name);
|
|
|
|
|
+ vo.setProductInfo(template.desc);
|
|
|
|
|
+ vo.setCateId((long) (category == 1 ? 1 : 2)); // 模拟分类
|
|
|
|
|
+ // 价格随机生成,但与之前保持一致范围
|
|
|
|
|
+ double minPrice = (category == 2) ? 20 : 5;
|
|
|
|
|
+ double maxPrice = (category == 2) ? 300 : 150;
|
|
|
|
|
+ double priceVal = minPrice + new Random().nextDouble() * (maxPrice - minPrice);
|
|
|
|
|
+ vo.setPrice(BigDecimal.valueOf(priceVal).setScale(2, BigDecimal.ROUND_HALF_UP));
|
|
|
|
|
+ double otPriceVal = priceVal * (0.8 + new Random().nextDouble() * 0.5);
|
|
|
|
|
+ vo.setOtPrice(BigDecimal.valueOf(otPriceVal).setScale(2, BigDecimal.ROUND_HALF_UP));
|
|
|
|
|
+ vo.setSales((long) new Random().nextInt(10000));
|
|
|
|
|
+ vo.setUnitName(new String[]{"个","件","双","条","只","套","盒"}[new Random().nextInt(7)]);
|
|
|
|
|
+ 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);
|
|
|
|
|
+ vo.setIsAudit("1");
|
|
|
|
|
+ return vo;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // 从模板中按顺序循环取(保证图文匹配),也可改为随机取但模板本身已匹配
|
|
|
|
|
- ProductTemplate template = templates[i % templates.length];
|
|
|
|
|
-
|
|
|
|
|
- // ---- 基础ID ----
|
|
|
|
|
- vo.setProductId(400000L + i + 1 + category * 100000L);
|
|
|
|
|
- vo.setStoreId(500000L + random.nextInt(100));
|
|
|
|
|
-
|
|
|
|
|
- // ---- 图片(直接从模板获取) ----
|
|
|
|
|
- vo.setImage(template.imageUrl);
|
|
|
|
|
-
|
|
|
|
|
- // ---- 商品名称(加前缀区分推荐/喜欢) ----
|
|
|
|
|
- String prefix = "推荐".equals(type) ? "🔥 " : "❤️ ";
|
|
|
|
|
- vo.setProductName(prefix + template.name);
|
|
|
|
|
-
|
|
|
|
|
- // ---- 商品描述 ----
|
|
|
|
|
- vo.setProductInfo(template.desc);
|
|
|
|
|
-
|
|
|
|
|
- // ---- 分类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);
|
|
|
|
|
-
|
|
|
|
|
- // ---- 审核状态 ----
|
|
|
|
|
- vo.setIsAudit("1");
|
|
|
|
|
-
|
|
|
|
|
- // ---- 店铺信息 ----
|
|
|
|
|
- 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());
|
|
|
|
|
-
|
|
|
|
|
- // ---- 是否赠品 ----
|
|
|
|
|
- vo.setIsGift(random.nextInt(7) == 0 ? 1 : 0);
|
|
|
|
|
-
|
|
|
|
|
- list.add(vo);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // ----- 对外接口 -----
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 模拟推荐商品列表(从缓存取)
|
|
|
|
|
+ * @param limit 返回条数
|
|
|
|
|
+ * @param category 商品类别:1-百货,2-服饰
|
|
|
|
|
+ * @return 商品列表(FsStoreProductListQueryVO)
|
|
|
|
|
+ */
|
|
|
|
|
+ public List<FsStoreProductListQueryVO> selectFsStoreProductTuiQuery(int limit, int category) {
|
|
|
|
|
+ return generateMockList(limit, category, "推荐");
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- return list;
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 模拟喜欢商品列表
|
|
|
|
|
+ */
|
|
|
|
|
+ public List<FsStoreProductListQueryVO> selectFsStoreProductGoodQuery(int limit, int category) {
|
|
|
|
|
+ return generateMockList(limit, category, "喜欢");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // ---------- 内部模板类 ----------
|
|
|
|
|
- private static class ProductTemplate {
|
|
|
|
|
- String name;
|
|
|
|
|
- String desc;
|
|
|
|
|
- String imageUrl;
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 根据商品ID查询详情(返回完整VO,含属性等信息)
|
|
|
|
|
+ * @param productId 商品ID
|
|
|
|
|
+ * @return FsStoreProductQueryVO 或 null
|
|
|
|
|
+ */
|
|
|
|
|
+ public FsStoreProductQueryVO getProductDetailById(Long productId) {
|
|
|
|
|
+ return productDetailCache.get(productId);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- ProductTemplate(String name, String desc, String imageUrl) {
|
|
|
|
|
- this.name = name;
|
|
|
|
|
- this.desc = desc;
|
|
|
|
|
- this.imageUrl = imageUrl;
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 模拟获取商品属性列表(返回空列表,因为模拟数据无规格)
|
|
|
|
|
+ */
|
|
|
|
|
+ public List<FsStoreProductAttrScrm> getProductAttrList(Long productId) {
|
|
|
|
|
+ return new ArrayList<>();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 模拟获取商品属性值列表(返回空列表)
|
|
|
|
|
+ */
|
|
|
|
|
+ public List<FsStoreProductAttrValueScrm> getProductAttrValueList(Long productId) {
|
|
|
|
|
+ return new ArrayList<>();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // ---------- 私有方法:生成列表VO ----------
|
|
|
|
|
+ private List<FsStoreProductListQueryVO> generateMockList(int limit, int category, String type) {
|
|
|
|
|
+ List<Long> ids = (category == 2) ? clothingProductIds : dailyProductIds;
|
|
|
|
|
+ if (ids.isEmpty()) {
|
|
|
|
|
+ return new ArrayList<>();
|
|
|
|
|
+ }
|
|
|
|
|
+ // 取前limit个(若不足则循环取)
|
|
|
|
|
+ List<FsStoreProductListQueryVO> result = new ArrayList<>();
|
|
|
|
|
+ for (int i = 0; i < limit; i++) {
|
|
|
|
|
+ Long id = ids.get(i % ids.size());
|
|
|
|
|
+ FsStoreProductQueryVO detail = productDetailCache.get(id);
|
|
|
|
|
+ if (detail == null) continue;
|
|
|
|
|
+ // 转换为FsStoreProductListQueryVO(可复用字段)
|
|
|
|
|
+ FsStoreProductListQueryVO vo = new FsStoreProductListQueryVO();
|
|
|
|
|
+ vo.setProductId(detail.getProductId());
|
|
|
|
|
+ vo.setImage(detail.getImage());
|
|
|
|
|
+ vo.setProductName(( "推荐".equals(type) ? "🔥 " : "❤️ " ) + detail.getProductName());
|
|
|
|
|
+ vo.setProductInfo(detail.getProductInfo());
|
|
|
|
|
+ vo.setCateId(detail.getCateId());
|
|
|
|
|
+ vo.setPrice(detail.getPrice());
|
|
|
|
|
+ vo.setOtPrice(detail.getOtPrice());
|
|
|
|
|
+ vo.setUnitName(detail.getUnitName());
|
|
|
|
|
+ vo.setIsDrug(detail.getIsDrug());
|
|
|
|
|
+ vo.setDrugImage(detail.getDrugImage());
|
|
|
|
|
+ vo.setDrugRegCertNo(detail.getDrugRegCertNo());
|
|
|
|
|
+ vo.setCommonName(detail.getCommonName());
|
|
|
|
|
+ vo.setDosageForm(detail.getDosageForm());
|
|
|
|
|
+ vo.setUnitPrice(detail.getUnitPrice());
|
|
|
|
|
+ vo.setBatchNumber(detail.getBatchNumber());
|
|
|
|
|
+ vo.setMah(detail.getMah());
|
|
|
|
|
+ vo.setMahAddress(detail.getMahAddress());
|
|
|
|
|
+ vo.setManufacturer(detail.getManufacturer());
|
|
|
|
|
+ vo.setManufacturerAddress(detail.getManufacturerAddress());
|
|
|
|
|
+ vo.setIndications(detail.getIndications());
|
|
|
|
|
+ vo.setDosage(detail.getDosage());
|
|
|
|
|
+ vo.setAdverseReactions(detail.getAdverseReactions());
|
|
|
|
|
+ vo.setContraindications(detail.getContraindications());
|
|
|
|
|
+ vo.setPrecautions(detail.getPrecautions());
|
|
|
|
|
+ vo.setIsAudit(detail.getIsAudit());
|
|
|
|
|
+ vo.setStoreId(Long.parseLong(detail.getStoreId()));
|
|
|
|
|
+ result.add(vo);
|
|
|
}
|
|
}
|
|
|
|
|
+ return result;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|