| | |
| | | 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; |
| | |
| | | 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();//日期转化为分钟数,作为hash key从redis取切片数据数据 |
| | | 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)); |
| | | |
| | | } |
| | | |
| | | //构建并保存时间切片,保存到redis |
| | | |
| | | 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); |
| | | }); |
| | | |
| | | } |
| | | } |