Browse Source

管理后台添加分享图显示

Menethil 7 years ago
parent
commit
e3bedf44fe

+ 14 - 8
litemall-admin/src/views/goods/list.vue

@@ -23,7 +23,7 @@
             </el-form-item>
             <el-form-item label="商品介绍">
               <span>{{ props.row.brief }}</span>
-            </el-form-item>   
+            </el-form-item>
             <el-form-item label="商品单位">
               <span>{{ props.row.unit }}</span>
             </el-form-item>
@@ -32,14 +32,14 @@
             </el-form-item>
             <el-form-item label="类目ID">
               <span>{{ props.row.categoryId }}</span>
-            </el-form-item>      
+            </el-form-item>
             <el-form-item label="品牌商ID">
               <span>{{ props.row.brandId }}</span>
             </el-form-item>
-          </el-form>          
+          </el-form>
         </template>
       </el-table-column>
-      
+
       <el-table-column align="center" label="商品编号" prop="goodsSn">
       </el-table-column>
 
@@ -52,6 +52,12 @@
         </template>
       </el-table-column>
 
+      <el-table-column align="center" property="iconUrl" label="分享图">
+        <template slot-scope="scope">
+          <img :src="scope.row.shareUrl" width="40"/>
+        </template>
+      </el-table-column>
+
       <el-table-column align="center" label="详情" prop="detail">
         <template slot-scope="scope">
           <el-dialog title="商品详情" :visible.sync="detailDialogVisible">
@@ -71,19 +77,19 @@
         <template slot-scope="scope">
           <el-tag :type="scope.row.isNew ? 'success' : 'error' ">{{scope.row.isNew ? '新品' : '非新品'}}</el-tag>
         </template>
-      </el-table-column> 
+      </el-table-column>
 
       <el-table-column align="center" label="是否热品" prop="isHot">
         <template slot-scope="scope">
           <el-tag :type="scope.row.isHot ? 'success' : 'error' ">{{scope.row.isHot ? '热品' : '非热品'}}</el-tag>
         </template>
-      </el-table-column> 
+      </el-table-column>
 
       <el-table-column align="center" label="是否在售" prop="isOnSale">
         <template slot-scope="scope">
           <el-tag :type="scope.row.isOnSale ? 'success' : 'error' ">{{scope.row.isOnSale ? '在售' : '未售'}}</el-tag>
         </template>
-      </el-table-column>             
+      </el-table-column>
 
       <el-table-column align="center" label="操作" width="200" class-name="small-padding fixed-width">
         <template slot-scope="scope">
@@ -211,4 +217,4 @@ export default {
     }
   }
 }
-</script>
+</script>

+ 1 - 1
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) {

+ 48 - 11
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<String, Object> cacheData;
+    public static final String INDEX = "index";
+    public static final String CATALOG = "catalog";
+    public static final String GOODS = "goods";
+
+    private static Map<String, Map<String, Object>> cacheDataList = new HashMap<>();
 
     /**
      * 缓存首页数据
      *
      * @param data
      */
-    public static void loadData(Map<String, Object> data) {
-        data.put("isCache", "true");
-        cacheData = data;
+    public static void loadData(String cacheKey, Map<String, Object> data) {
+        Map<String, Object> 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<String, Object> getCacheData() {
-        return cacheData;
+    public static Map<String, Object> 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<String, Object> 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<String, Object> cacheData = cacheDataList.get(cacheKey);
+        if (cacheData != null) {
+            cacheDataList.remove(cacheKey);
+        }
     }
 }

+ 10 - 0
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<LitemallCategory> 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);
     }
 

+ 2 - 2
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)) {

+ 6 - 10
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);
     }
 }