소스 검색

Merge branch 'master' of ssh://192.168.8.213:10022/miaxis/zzjs

Althars123 4 년 전
부모
커밋
ae81b696eb

+ 0 - 35
zzjs-common/src/main/java/com/miaxis/common/enums/HomePageDataType.java

@@ -1,35 +0,0 @@
-package com.miaxis.common.enums;
-
-/**
- * @author wwl
- * @version 1.0
- * @date 2021/4/27 15:18
- */
-public enum HomePageDataType {
-
-    CAROUSElCHART(1, "carouselChart", "轮播图"),
-    COUPON(2, "coupon", "优惠劵"),
-    MENU(3, "menu", "首页菜单");
-
-    private final Integer code;
-    private final String dataType;//文件类型
-    private final String info;
-
-    HomePageDataType(Integer code, String dataType, String info)
-    {
-        this.code = code;
-        this.dataType = dataType;
-        this.info = info;
-    }
-
-    public Integer getCode() {
-        return code;
-    }
-
-    public String getDataType() {
-        return dataType;
-    }
-
-    public String getInfo() {
-        return info;
-    }}

+ 44 - 85
zzjs-service/src/main/java/com/miaxis/carousel/service/impl/HomePageDataInfoServiceImpl.java

@@ -9,11 +9,12 @@ import com.miaxis.carousel.service.IHomePageDataInfoService;
 import com.miaxis.carousel.vo.HomePageDataInfoVo;
 import com.miaxis.common.constant.Constants;
 import com.miaxis.common.core.domain.Response;
-import com.miaxis.common.enums.HomePageDataType;
+import com.miaxis.common.core.domain.entity.SysDictData;
 import com.miaxis.common.exception.CustomException;
 import com.miaxis.common.utils.bean.BeanUtils;
 import com.miaxis.file.domain.FileInfo;
 import com.miaxis.file.service.IFileInfoService;
+import com.miaxis.system.mapper.SysDictDataMapper;
 import lombok.RequiredArgsConstructor;
 import lombok.SneakyThrows;
 import org.springframework.data.redis.core.RedisTemplate;
@@ -39,6 +40,8 @@ public class HomePageDataInfoServiceImpl extends ServiceImpl<HomePageDataInfoMap
 
     private final IFileInfoService fileInfoService;
 
+    private final SysDictDataMapper dictDataMapper;
+
     /**
      * 查询首页数据列表
      *
@@ -119,18 +122,19 @@ public class HomePageDataInfoServiceImpl extends ServiceImpl<HomePageDataInfoMap
     @Transactional(rollbackFor = Exception.class)
     public Response removeCarouselByIds(Long[] ids) {
 
+        //首页字典类型
+        List<SysDictData> sysDictData = dictDataMapper.selectDictDataByType("wx_menu_type");
+        //删除数据
         for (Long id : ids) {
             this.update(new UpdateWrapper<HomePageDataInfo>().set("status","1").eq("id",id));
-
-            //判断类型 删除缓存
-            if (redisTemplate.hasKey(Constants.HOME_PAGE_DATA_KEY  + HomePageDataType.CAROUSElCHART.getDataType()+":"+id)){
-                redisTemplate.delete(Constants.HOME_PAGE_DATA_KEY  + HomePageDataType.CAROUSElCHART.getDataType() + ":" + id);
-            }
-            if (redisTemplate.hasKey(Constants.HOME_PAGE_DATA_KEY  + HomePageDataType.COUPON.getDataType()+":"+id)){
-                redisTemplate.delete(Constants.HOME_PAGE_DATA_KEY  + HomePageDataType.COUPON.getDataType() + ":" + id);
-            }
-            if (redisTemplate.hasKey(Constants.HOME_PAGE_DATA_KEY  + HomePageDataType.MENU.getDataType()+":"+id)){
-                redisTemplate.delete(Constants.HOME_PAGE_DATA_KEY  + HomePageDataType.MENU.getDataType() + ":" + id);
+        }
+        //根据字典类型 更新缓存
+        for (SysDictData dictData : sysDictData) {
+            for (Long id : ids) {
+                //判断类型 删除缓存
+                if (redisTemplate.hasKey(Constants.HOME_PAGE_DATA_KEY  + dictData.getDictValue()+":"+id)){
+                    redisTemplate.delete(Constants.HOME_PAGE_DATA_KEY  + dictData.getDictValue() + ":" + id);
+                }
             }
         }
         return Response.success();
@@ -144,76 +148,33 @@ public class HomePageDataInfoServiceImpl extends ServiceImpl<HomePageDataInfoMap
      */
     @Override
     public Response getHomePageDataList() {
-
         Map<String, List<HomePageDataInfoVo>> map = new HashMap<>();
 
-        List<HomePageDataInfoVo> carouselChartInfoVos = new ArrayList<>(); //轮播图list
-        List<HomePageDataInfoVo> couponInfos = new ArrayList<>(); //优惠劵list
-        List<HomePageDataInfoVo> menuInfos = new ArrayList<>(); //首页菜单list
-
-        //-------------------从缓存获取轮播图-------------------
-        Set carouselChartkeys = redisTemplate.keys(Constants.HOME_PAGE_DATA_KEY + HomePageDataType.CAROUSElCHART.getDataType()+":*");
-        if (!carouselChartkeys.isEmpty()){
-            for (Object key : carouselChartkeys) {
-                String jsonStr = (String) redisTemplate.opsForValue().get(key);
-                HomePageDataInfoVo homePageDataInfoVo = JSONObject.parseObject(jsonStr).toJavaObject(HomePageDataInfoVo.class);
-                carouselChartInfoVos.add(homePageDataInfoVo);
-            }
-        }else {
-            //数据库获取(此处可不做查询!)
-            HomePageDataInfo homePageDataInfo = new HomePageDataInfo();
-            homePageDataInfo.setDataType(HomePageDataType.CAROUSElCHART.getDataType());
-            homePageDataInfo.setStatus("0");//启用状态
-            carouselChartInfoVos = homePageDataInfoMapper.selectHomePageDataInfoList(homePageDataInfo);
-        }
-        //排序
-        List<HomePageDataInfoVo> chartInfoVos = carouselChartInfoVos.stream()
-                .sorted(Comparator.comparing(HomePageDataInfoVo::getWeight).reversed())
-                .collect(Collectors.toList());
-
-        //-------------------从缓存获取优惠劵-------------------
-        Set couponKeys = redisTemplate.keys(Constants.HOME_PAGE_DATA_KEY + HomePageDataType.COUPON.getDataType()+":*");
-        if (!couponKeys.isEmpty()){
-            for (Object key : couponKeys) {
-                String jsonStr = (String) redisTemplate.opsForValue().get(key);
-                HomePageDataInfoVo homePageDataInfoVo = JSONObject.parseObject(jsonStr).toJavaObject(HomePageDataInfoVo.class);
-                couponInfos.add(homePageDataInfoVo);
+        //首页字典类型
+        List<SysDictData> sysDictData = dictDataMapper.selectDictDataByType("wx_menu_type");
+        for (SysDictData dictData : sysDictData) {
+            List<HomePageDataInfoVo> newInfos = new ArrayList<>();
+            Set carouselChartkeys = redisTemplate.keys(Constants.HOME_PAGE_DATA_KEY + dictData.getDictValue()+":*");
+            if (!carouselChartkeys.isEmpty()){
+                for (Object key : carouselChartkeys) {
+                    String jsonStr = (String) redisTemplate.opsForValue().get(key);
+                    HomePageDataInfoVo homePageDataInfoVo = JSONObject.parseObject(jsonStr).toJavaObject(HomePageDataInfoVo.class);
+                    newInfos.add(homePageDataInfoVo);
+                }
+            }else {
+                //数据库获取(此处可不做查询!)
+                HomePageDataInfo homePageDataInfo = new HomePageDataInfo();
+                homePageDataInfo.setDataType(dictData.getDictValue());
+                homePageDataInfo.setStatus("0");//启用状态
+                newInfos = homePageDataInfoMapper.selectHomePageDataInfoList(homePageDataInfo);
             }
-        }else {
-            //数据库获取(此处可不做查询!)
-            HomePageDataInfo homePageDataInfo = new HomePageDataInfo();
-            homePageDataInfo.setDataType(HomePageDataType.COUPON.getDataType());
-            homePageDataInfo.setStatus("0");//启用状态
-            couponInfos = homePageDataInfoMapper.selectHomePageDataInfoList(homePageDataInfo);
-        }
-        //排序
-        List<HomePageDataInfoVo> couponInfoVos = couponInfos.stream()
-                .sorted(Comparator.comparing(HomePageDataInfoVo::getWeight).reversed())
-                .collect(Collectors.toList());
+            //排序
+            List<HomePageDataInfoVo> infoVos = newInfos.stream()
+                    .sorted(Comparator.comparing(HomePageDataInfoVo::getWeight).reversed())
+                    .collect(Collectors.toList());
 
-        //----------------从缓存获取首页菜单-------------------
-        Set menuKeys = redisTemplate.keys(Constants.HOME_PAGE_DATA_KEY + HomePageDataType.MENU.getDataType()+":*");
-        if (!menuKeys.isEmpty()){
-            for (Object key : menuKeys) {
-                String jsonStr = (String) redisTemplate.opsForValue().get(key);
-                HomePageDataInfoVo homePageDataInfoVo = JSONObject.parseObject(jsonStr).toJavaObject(HomePageDataInfoVo.class);
-                menuInfos.add(homePageDataInfoVo);
-            }
-        }else {
-            //数据库获取(此处可不做查询!)
-            HomePageDataInfo homePageDataInfo = new HomePageDataInfo();
-            homePageDataInfo.setDataType(HomePageDataType.MENU.getDataType());
-            homePageDataInfo.setStatus("0");//启用状态
-            menuInfos = homePageDataInfoMapper.selectHomePageDataInfoList(homePageDataInfo);
+            map.put(dictData.getDictValue(),infoVos);
         }
-        //排序
-        List<HomePageDataInfoVo> menuInfoVos = menuInfos.stream()
-                .sorted(Comparator.comparing(HomePageDataInfoVo::getWeight).reversed())
-                .collect(Collectors.toList());
-
-        map.put(HomePageDataType.CAROUSElCHART.getDataType(),chartInfoVos);
-        map.put(HomePageDataType.COUPON.getDataType(),couponInfoVos);
-        map.put(HomePageDataType.MENU.getDataType(),menuInfoVos);
 
         return Response.success(map);
     }
@@ -248,15 +209,13 @@ public class HomePageDataInfoServiceImpl extends ServiceImpl<HomePageDataInfoMap
         JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(homePageDataInfo));
         jsonObject.put("fileUrl",fileInfo.getFileUrl());
 
-        //判断类型 删除缓存
-        if (redisTemplate.hasKey(Constants.HOME_PAGE_DATA_KEY  + HomePageDataType.CAROUSElCHART.getDataType()+":"+homePageDataInfo.getId())){
-            redisTemplate.delete(Constants.HOME_PAGE_DATA_KEY  + HomePageDataType.CAROUSElCHART.getDataType() + ":" + homePageDataInfo.getId());
-        }
-        if (redisTemplate.hasKey(Constants.HOME_PAGE_DATA_KEY  + HomePageDataType.COUPON.getDataType()+":"+homePageDataInfo.getId())){
-            redisTemplate.delete(Constants.HOME_PAGE_DATA_KEY  + HomePageDataType.COUPON.getDataType() + ":" + homePageDataInfo.getId());
-        }
-        if (redisTemplate.hasKey(Constants.HOME_PAGE_DATA_KEY  + HomePageDataType.MENU.getDataType()+":"+homePageDataInfo.getId())){
-            redisTemplate.delete(Constants.HOME_PAGE_DATA_KEY  + HomePageDataType.MENU.getDataType() + ":" + homePageDataInfo.getId());
+        //首页字典类型
+        List<SysDictData> sysDictData = dictDataMapper.selectDictDataByType("wx_menu_type");
+        //根据字典类型 删除缓存
+        for (SysDictData dictData : sysDictData) {
+            if (redisTemplate.hasKey(Constants.HOME_PAGE_DATA_KEY  + dictData.getDictValue()+":"+homePageDataInfo.getId())){
+                redisTemplate.delete(Constants.HOME_PAGE_DATA_KEY  + dictData.getDictValue() + ":" + homePageDataInfo.getId());
+            }
         }
 
         //同时更新缓存(根据type拼接)