diff --git a/litemall-admin/src/views/goods/list.vue b/litemall-admin/src/views/goods/list.vue
index 39b01191..db751cbe 100644
--- a/litemall-admin/src/views/goods/list.vue
+++ b/litemall-admin/src/views/goods/list.vue
@@ -23,7 +23,7 @@
{{ props.row.brief }}
-
+
{{ props.row.unit }}
@@ -32,14 +32,14 @@
{{ props.row.categoryId }}
-
+
{{ props.row.brandId }}
-
+
-
+
@@ -52,6 +52,12 @@
+
+
+
+
+
+
@@ -71,19 +77,19 @@
{{scope.row.isNew ? '新品' : '非新品'}}
-
+
{{scope.row.isHot ? '热品' : '非热品'}}
-
+
{{scope.row.isOnSale ? '在售' : '未售'}}
-
+
@@ -211,4 +217,4 @@ export default {
}
}
}
-
\ No newline at end of file
+
diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGrouponRulesService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGrouponRulesService.java
index 72b2f4db..d0be94e2 100644
--- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGrouponRulesService.java
+++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGrouponRulesService.java
@@ -69,7 +69,7 @@ public class LitemallGrouponRulesService {
}
public void delete(Integer id) {
- mapper.deleteByPrimaryKey(id);
+ mapper.logicalDeleteByPrimaryKey(id);
}
public void update(LitemallGrouponRules grouponRules) {
diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/service/HomeCacheManager.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/service/HomeCacheManager.java
index 9aede087..5b491114 100644
--- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/service/HomeCacheManager.java
+++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/service/HomeCacheManager.java
@@ -1,25 +1,42 @@
package org.linlinjava.litemall.wx.service;
+import java.time.LocalDateTime;
+import java.util.HashMap;
import java.util.Map;
/**
- * 简单缓存首页的数据
+ * 简单缓存的数据
*/
public class HomeCacheManager {
- private static Map cacheData;
+ public static final String INDEX = "index";
+ public static final String CATALOG = "catalog";
+ public static final String GOODS = "goods";
+
+ private static Map> cacheDataList = new HashMap<>();
/**
* 缓存首页数据
*
* @param data
*/
- public static void loadData(Map data) {
- data.put("isCache", "true");
- cacheData = data;
+ public static void loadData(String cacheKey, Map data) {
+ Map cacheData = cacheDataList.get(cacheKey);
+ //有记录,则先丢弃
+ if (cacheData != null) {
+ cacheData.remove(cacheKey);
+ }
+
+ cacheData = new HashMap<>();
+ //深拷贝
+ cacheData.putAll(data);
+ cacheData.put("isCache", "true");
+ //设置缓存有效期为10分钟
+ cacheData.put("expireTime", LocalDateTime.now().plusMinutes(10));
+ cacheDataList.put(cacheKey, cacheData);
}
- public static Map getCacheData() {
- return cacheData;
+ public static Map getCacheData(String cacheKey) {
+ return cacheDataList.get(cacheKey);
}
/**
@@ -27,14 +44,34 @@ public class HomeCacheManager {
*
* @return
*/
- public static boolean hasData() {
- return cacheData != null;
+ public static boolean hasData(String cacheKey) {
+ Map cacheData = cacheDataList.get(cacheKey);
+ if (cacheData == null) {
+ return false;
+ } else {
+ LocalDateTime expire = (LocalDateTime) cacheData.get("expireTime");
+ if (expire.isBefore(LocalDateTime.now())) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+ }
+
+ /**
+ * 清除所有缓存
+ */
+ public static void clearAll() {
+ cacheDataList = new HashMap<>();
}
/**
* 清除缓存数据
*/
- public static void clear() {
- cacheData = null;
+ public static void clear(String cacheKey) {
+ Map cacheData = cacheDataList.get(cacheKey);
+ if (cacheData != null) {
+ cacheDataList.remove(cacheKey);
+ }
}
}
diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxCatalogController.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxCatalogController.java
index cdee6a5c..0af9bebe 100644
--- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxCatalogController.java
+++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxCatalogController.java
@@ -3,6 +3,7 @@ package org.linlinjava.litemall.wx.web;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.db.domain.LitemallCategory;
import org.linlinjava.litemall.db.service.LitemallCategoryService;
+import org.linlinjava.litemall.wx.service.HomeCacheManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
@@ -80,6 +81,12 @@ public class WxCatalogController {
*/
@GetMapping("all")
public Object queryAll() {
+ //优先从缓存中读取
+ if (HomeCacheManager.hasData(HomeCacheManager.CATALOG)) {
+ return ResponseUtil.ok(HomeCacheManager.getCacheData(HomeCacheManager.CATALOG));
+ }
+
+
// 所有一级分类目录
List l1CatList = categoryService.queryL1();
@@ -105,6 +112,9 @@ public class WxCatalogController {
data.put("allList", allList);
data.put("currentCategory", currentCategory);
data.put("currentSubCategory", currentSubCategory);
+
+ //缓存数据
+ HomeCacheManager.loadData(HomeCacheManager.CATALOG, data);
return ResponseUtil.ok(data);
}
diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxGoodsController.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxGoodsController.java
index ea33f70e..4d8792cd 100644
--- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxGoodsController.java
+++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxGoodsController.java
@@ -10,6 +10,7 @@ import org.linlinjava.litemall.core.validator.Sort;
import org.linlinjava.litemall.db.domain.*;
import org.linlinjava.litemall.db.service.*;
import org.linlinjava.litemall.wx.annotation.LoginUser;
+import org.linlinjava.litemall.wx.service.HomeCacheManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
@@ -156,7 +157,6 @@ public class WxGoodsController {
//商品分享图片地址
data.put("shareImage", info.getShareUrl());
-
return ResponseUtil.ok(data);
}
@@ -237,7 +237,7 @@ public class WxGoodsController {
@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer size,
@Sort(accepts = {"add_time", "retail_price"}) @RequestParam(defaultValue = "add_time") String sort,
- @Order @RequestParam(defaultValue = "desc") String order){
+ @Order @RequestParam(defaultValue = "desc") String order) {
//添加到搜索历史
if (userId != null && !StringUtils.isNullOrEmpty(keyword)) {
diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxHomeController.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxHomeController.java
index 4657cb67..f7e9e4e9 100644
--- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxHomeController.java
+++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxHomeController.java
@@ -36,18 +36,14 @@ public class WxHomeController {
@GetMapping("/cache")
- public Object cache(@NotNull Integer key) {
+ public Object cache(@NotNull String key) {
if (!key.equals("litemall_cache")) {
return ResponseUtil.fail();
}
// 清除缓存
- HomeCacheManager.clear();
- if (!HomeCacheManager.hasData()) {
- return ResponseUtil.ok();
- } else {
- return ResponseUtil.fail();
- }
+ HomeCacheManager.clearAll();
+ return ResponseUtil.ok("缓存已清除");
}
/**
@@ -73,8 +69,8 @@ public class WxHomeController {
@GetMapping("/index")
public Object index() {
//优先从缓存中读取
- if (HomeCacheManager.hasData()) {
- return ResponseUtil.ok(HomeCacheManager.getCacheData());
+ if (HomeCacheManager.hasData(HomeCacheManager.INDEX)) {
+ return ResponseUtil.ok(HomeCacheManager.getCacheData(HomeCacheManager.INDEX));
}
@@ -143,7 +139,7 @@ public class WxHomeController {
data.put("floorGoodsList", categoryList);
//缓存数据
- HomeCacheManager.loadData(data);
+ HomeCacheManager.loadData(HomeCacheManager.INDEX, data);
return ResponseUtil.ok(data);
}
}
\ No newline at end of file