Commit e3bedf44 authored by Menethil's avatar Menethil
Browse files

管理后台添加分享图显示

parent 0b1435e0
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
</el-form-item> </el-form-item>
<el-form-item label="商品介绍"> <el-form-item label="商品介绍">
<span>{{ props.row.brief }}</span> <span>{{ props.row.brief }}</span>
</el-form-item> </el-form-item>
<el-form-item label="商品单位"> <el-form-item label="商品单位">
<span>{{ props.row.unit }}</span> <span>{{ props.row.unit }}</span>
</el-form-item> </el-form-item>
...@@ -32,14 +32,14 @@ ...@@ -32,14 +32,14 @@
</el-form-item> </el-form-item>
<el-form-item label="类目ID"> <el-form-item label="类目ID">
<span>{{ props.row.categoryId }}</span> <span>{{ props.row.categoryId }}</span>
</el-form-item> </el-form-item>
<el-form-item label="品牌商ID"> <el-form-item label="品牌商ID">
<span>{{ props.row.brandId }}</span> <span>{{ props.row.brandId }}</span>
</el-form-item> </el-form-item>
</el-form> </el-form>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column align="center" label="商品编号" prop="goodsSn"> <el-table-column align="center" label="商品编号" prop="goodsSn">
</el-table-column> </el-table-column>
...@@ -52,6 +52,12 @@ ...@@ -52,6 +52,12 @@
</template> </template>
</el-table-column> </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"> <el-table-column align="center" label="详情" prop="detail">
<template slot-scope="scope"> <template slot-scope="scope">
<el-dialog title="商品详情" :visible.sync="detailDialogVisible"> <el-dialog title="商品详情" :visible.sync="detailDialogVisible">
...@@ -71,19 +77,19 @@ ...@@ -71,19 +77,19 @@
<template slot-scope="scope"> <template slot-scope="scope">
<el-tag :type="scope.row.isNew ? 'success' : 'error' ">{{scope.row.isNew ? '新品' : '非新品'}}</el-tag> <el-tag :type="scope.row.isNew ? 'success' : 'error' ">{{scope.row.isNew ? '新品' : '非新品'}}</el-tag>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column align="center" label="是否热品" prop="isHot"> <el-table-column align="center" label="是否热品" prop="isHot">
<template slot-scope="scope"> <template slot-scope="scope">
<el-tag :type="scope.row.isHot ? 'success' : 'error' ">{{scope.row.isHot ? '热品' : '非热品'}}</el-tag> <el-tag :type="scope.row.isHot ? 'success' : 'error' ">{{scope.row.isHot ? '热品' : '非热品'}}</el-tag>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column align="center" label="是否在售" prop="isOnSale"> <el-table-column align="center" label="是否在售" prop="isOnSale">
<template slot-scope="scope"> <template slot-scope="scope">
<el-tag :type="scope.row.isOnSale ? 'success' : 'error' ">{{scope.row.isOnSale ? '在售' : '未售'}}</el-tag> <el-tag :type="scope.row.isOnSale ? 'success' : 'error' ">{{scope.row.isOnSale ? '在售' : '未售'}}</el-tag>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column align="center" label="操作" width="200" class-name="small-padding fixed-width"> <el-table-column align="center" label="操作" width="200" class-name="small-padding fixed-width">
<template slot-scope="scope"> <template slot-scope="scope">
...@@ -211,4 +217,4 @@ export default { ...@@ -211,4 +217,4 @@ export default {
} }
} }
} }
</script> </script>
\ No newline at end of file
...@@ -69,7 +69,7 @@ public class LitemallGrouponRulesService { ...@@ -69,7 +69,7 @@ public class LitemallGrouponRulesService {
} }
public void delete(Integer id) { public void delete(Integer id) {
mapper.deleteByPrimaryKey(id); mapper.logicalDeleteByPrimaryKey(id);
} }
public void update(LitemallGrouponRules grouponRules) { public void update(LitemallGrouponRules grouponRules) {
......
package org.linlinjava.litemall.wx.service; package org.linlinjava.litemall.wx.service;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
* 简单缓存首页的数据 * 简单缓存的数据
*/ */
public class HomeCacheManager { 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 * @param data
*/ */
public static void loadData(Map<String, Object> data) { public static void loadData(String cacheKey, Map<String, Object> data) {
data.put("isCache", "true"); Map<String, Object> cacheData = cacheDataList.get(cacheKey);
cacheData = data; //有记录,则先丢弃
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() { public static Map<String, Object> getCacheData(String cacheKey) {
return cacheData; return cacheDataList.get(cacheKey);
} }
/** /**
...@@ -27,14 +44,34 @@ public class HomeCacheManager { ...@@ -27,14 +44,34 @@ public class HomeCacheManager {
* *
* @return * @return
*/ */
public static boolean hasData() { public static boolean hasData(String cacheKey) {
return cacheData != null; 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() { public static void clear(String cacheKey) {
cacheData = null; Map<String, Object> cacheData = cacheDataList.get(cacheKey);
if (cacheData != null) {
cacheDataList.remove(cacheKey);
}
} }
} }
...@@ -3,6 +3,7 @@ package org.linlinjava.litemall.wx.web; ...@@ -3,6 +3,7 @@ package org.linlinjava.litemall.wx.web;
import org.linlinjava.litemall.core.util.ResponseUtil; import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.db.domain.LitemallCategory; import org.linlinjava.litemall.db.domain.LitemallCategory;
import org.linlinjava.litemall.db.service.LitemallCategoryService; import org.linlinjava.litemall.db.service.LitemallCategoryService;
import org.linlinjava.litemall.wx.service.HomeCacheManager;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
...@@ -80,6 +81,12 @@ public class WxCatalogController { ...@@ -80,6 +81,12 @@ public class WxCatalogController {
*/ */
@GetMapping("all") @GetMapping("all")
public Object queryAll() { public Object queryAll() {
//优先从缓存中读取
if (HomeCacheManager.hasData(HomeCacheManager.CATALOG)) {
return ResponseUtil.ok(HomeCacheManager.getCacheData(HomeCacheManager.CATALOG));
}
// 所有一级分类目录 // 所有一级分类目录
List<LitemallCategory> l1CatList = categoryService.queryL1(); List<LitemallCategory> l1CatList = categoryService.queryL1();
...@@ -105,6 +112,9 @@ public class WxCatalogController { ...@@ -105,6 +112,9 @@ public class WxCatalogController {
data.put("allList", allList); data.put("allList", allList);
data.put("currentCategory", currentCategory); data.put("currentCategory", currentCategory);
data.put("currentSubCategory", currentSubCategory); data.put("currentSubCategory", currentSubCategory);
//缓存数据
HomeCacheManager.loadData(HomeCacheManager.CATALOG, data);
return ResponseUtil.ok(data); return ResponseUtil.ok(data);
} }
......
...@@ -10,6 +10,7 @@ import org.linlinjava.litemall.core.validator.Sort; ...@@ -10,6 +10,7 @@ import org.linlinjava.litemall.core.validator.Sort;
import org.linlinjava.litemall.db.domain.*; import org.linlinjava.litemall.db.domain.*;
import org.linlinjava.litemall.db.service.*; import org.linlinjava.litemall.db.service.*;
import org.linlinjava.litemall.wx.annotation.LoginUser; import org.linlinjava.litemall.wx.annotation.LoginUser;
import org.linlinjava.litemall.wx.service.HomeCacheManager;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
...@@ -156,7 +157,6 @@ public class WxGoodsController { ...@@ -156,7 +157,6 @@ public class WxGoodsController {
//商品分享图片地址 //商品分享图片地址
data.put("shareImage", info.getShareUrl()); data.put("shareImage", info.getShareUrl());
return ResponseUtil.ok(data); return ResponseUtil.ok(data);
} }
...@@ -237,7 +237,7 @@ public class WxGoodsController { ...@@ -237,7 +237,7 @@ public class WxGoodsController {
@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer size, @RequestParam(defaultValue = "10") Integer size,
@Sort(accepts = {"add_time", "retail_price"}) @RequestParam(defaultValue = "add_time") String sort, @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)) { if (userId != null && !StringUtils.isNullOrEmpty(keyword)) {
......
...@@ -36,18 +36,14 @@ public class WxHomeController { ...@@ -36,18 +36,14 @@ public class WxHomeController {
@GetMapping("/cache") @GetMapping("/cache")
public Object cache(@NotNull Integer key) { public Object cache(@NotNull String key) {
if (!key.equals("litemall_cache")) { if (!key.equals("litemall_cache")) {
return ResponseUtil.fail(); return ResponseUtil.fail();
} }
// 清除缓存 // 清除缓存
HomeCacheManager.clear(); HomeCacheManager.clearAll();
if (!HomeCacheManager.hasData()) { return ResponseUtil.ok("缓存已清除");
return ResponseUtil.ok();
} else {
return ResponseUtil.fail();
}
} }
/** /**
...@@ -73,8 +69,8 @@ public class WxHomeController { ...@@ -73,8 +69,8 @@ public class WxHomeController {
@GetMapping("/index") @GetMapping("/index")
public Object index() { public Object index() {
//优先从缓存中读取 //优先从缓存中读取
if (HomeCacheManager.hasData()) { if (HomeCacheManager.hasData(HomeCacheManager.INDEX)) {
return ResponseUtil.ok(HomeCacheManager.getCacheData()); return ResponseUtil.ok(HomeCacheManager.getCacheData(HomeCacheManager.INDEX));
} }
...@@ -143,7 +139,7 @@ public class WxHomeController { ...@@ -143,7 +139,7 @@ public class WxHomeController {
data.put("floorGoodsList", categoryList); data.put("floorGoodsList", categoryList);
//缓存数据 //缓存数据
HomeCacheManager.loadData(data); HomeCacheManager.loadData(HomeCacheManager.INDEX, data);
return ResponseUtil.ok(data); return ResponseUtil.ok(data);
} }
} }
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment