From 9faa74e1912022dc6e54c3e93426946876b5d83a Mon Sep 17 00:00:00 2001
From: yangys <y_ys79@sina.com>
Date: 星期五, 25 十月 2024 10:49:13 +0800
Subject: [PATCH] 修改redistemplate的hashkey serializer,更方便客户端查看redis的数据

---
 collect/src/main/java/com/qianwen/mdc/collect/cache/TimeSliceCache.java |   35 ++++++++++++++---------------------
 1 files changed, 14 insertions(+), 21 deletions(-)

diff --git a/collect/src/main/java/com/qianwen/mdc/collect/cache/TimeSliceCache.java b/collect/src/main/java/com/qianwen/mdc/collect/cache/TimeSliceCache.java
index 07e8edc..0f9a7fc 100644
--- a/collect/src/main/java/com/qianwen/mdc/collect/cache/TimeSliceCache.java
+++ b/collect/src/main/java/com/qianwen/mdc/collect/cache/TimeSliceCache.java
@@ -10,8 +10,6 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
-
-import com.qianwen.core.tool.utils.SpringUtil;
 import com.qianwen.mdc.collect.dto.CacheBuildDTO;
 import com.qianwen.mdc.collect.dto.CalendarShiftTimeSlicesDTO;
 import com.qianwen.mdc.collect.dto.TimestampToProductionTimeCacheDto;
@@ -19,47 +17,42 @@
 import com.qianwen.mdc.collect.utils.CommonUtil;
 import com.qianwen.mdc.collect.utils.redis.RedisUtil;
 
-/*
-
-import com.qianwen.posting.dto.CacheBuildDTO;
-import com.qianwen.posting.dto.CalendarShiftTimeSlicesDTO;
-import com.qianwen.posting.dto.TimestampToProductionTimeCacheDto;
-import com.qianwen.posting.service.ICalendarService;
-import com.qianwen.posting.utils.CommonUtil;
-*/
 @Component
 public class TimeSliceCache {
+	public static final String COLLECT_CALENDAR = "collect:calendar";
     public static final String CALENDAR = "calendar";
     public static final String CALENDARS_CODE = "calendar:code:";
     public static final String MINUTE_POINT = "minute-point:";
     private static final Logger log = LoggerFactory.getLogger(TimeSliceCache.class);
-    //private static final BladeRedis bladeRedis = (BladeRedis) SpringUtil.getBean(BladeRedis.class);
-    //private static final ICalendarService calendarService = (ICalendarService) SpringUtil.getBean(ICalendarService.class);
     @Autowired
     private RedisUtil redisUtil;
     @Autowired
     private CalendarService calendarService;
-    
+    //@Autowired
+    //private BladeRedis bladeRedis;
 
     public CalendarShiftTimeSlicesDTO getTimeSliceShift(String calendarCode, Date date) {
+    	
         int minutes = (DateTime.of(date).hour(true) * 60) + DateTime.of(date).minute();//鏃ユ湡杞寲涓哄垎閽熸暟锛屼綔涓篽ash key浠巖edis鍙栧垏鐗囨暟鎹暟鎹�
-        String redisKey = CommonUtil.getReallyCacheName("posting:calendar", CALENDARS_CODE.concat(calendarCode).concat(":").concat(MINUTE_POINT), DateTime.of(date).toDateStr());
-        //return (CalendarShiftTimeSlicesDTO) bladeRedis.hGet(redisKey, Integer.valueOf(minutes));
-    
-        return (CalendarShiftTimeSlicesDTO) redisUtil.hget(redisKey, minutes+"");
+        String redisKey = CommonUtil.getReallyCacheName(COLLECT_CALENDAR, CALENDARS_CODE.concat(calendarCode).concat(":").concat(MINUTE_POINT), DateTime.of(date).toDateStr());
+
+        return (CalendarShiftTimeSlicesDTO)redisUtil.getRedisTemplate().opsForHash().get(redisKey, Integer.valueOf(minutes));
+        
     }
 
     //鏋勫缓骞朵繚瀛樻椂闂村垏鐗囷紝淇濆瓨鍒皉edis
  
     public void build(CacheBuildDTO cacheBuildDTO) {
+    	
         String key = cacheBuildDTO.getTargetDate().format(DateTimeFormatter.ISO_LOCAL_DATE);
         List<TimestampToProductionTimeCacheDto> data = calendarService.buildProductionTimeCache(cacheBuildDTO);//鏌ヨ鐢熶骇鏃ュ巻锛屽苟璁$畻鍑烘椂闂村垏鐗�
         data.forEach(t -> {
-            String redisKey = CommonUtil.getReallyCacheName("posting:calendar", CALENDARS_CODE.concat(t.getCalendarCode()).concat(":").concat(MINUTE_POINT), key);
+            String redisKey = CommonUtil.getReallyCacheName(COLLECT_CALENDAR, CALENDARS_CODE.concat(t.getCalendarCode()).concat(":").concat(MINUTE_POINT), key);
             Map<Integer, CalendarShiftTimeSlicesDTO> timeSlicesDtoMap = t.getTimeSlicesDTOMap();
-            //bladeRedis.getRedisTemplate().opsForHash().putAll(redisKey, timeSlicesDtoMap);
-            //bladeRedis.expire(redisKey, 259200L);
-            redisUtil.hmset(redisKey, timeSlicesDtoMap, 259200L);
+            
+            //redisUtil.hmset(redisKey, timeSlicesDtoMap, 259200L);
+            redisUtil.getRedisTemplate().opsForHash().putAll(redisKey, timeSlicesDtoMap);
         });
+        
     }
 }

--
Gitblit v1.9.3