| package com.zy.asrs.task; | 
|   | 
| import com.alibaba.fastjson.JSON; | 
| import com.zy.asrs.entity.BasMap; | 
| import com.zy.asrs.service.BasMapService; | 
| import com.zy.common.utils.RedisUtil; | 
| import lombok.extern.slf4j.Slf4j; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.scheduling.annotation.Scheduled; | 
| import org.springframework.stereotype.Component; | 
|   | 
| import java.util.Date; | 
|   | 
| @Component | 
| @Slf4j | 
| public class RealtimeBasMapScheduler { | 
|   | 
|     @Autowired | 
|     private RedisUtil redisUtil; | 
|     @Autowired | 
|     private BasMapService basMapService; | 
|   | 
|     /** | 
|      * 每分钟从redis中更新地图数据到数据库中 | 
|      */ | 
|     @Scheduled(cron = "1 * * * * ? ") | 
|     private void execute(){ | 
|         for (int i = 1; i <= 4; i++) {//总共四层楼 | 
|             Object data = redisUtil.get("realtimeBasMap_" + i); | 
|             if (data == null) { | 
|                 continue; | 
|             } | 
|   | 
|             BasMap redisMap = JSON.parseObject(data.toString(), BasMap.class); | 
|   | 
|             BasMap basMap = basMapService.selectLatestMap(i); | 
|             if (basMap == null) { | 
|                 continue; | 
|             } | 
|   | 
|             basMap.setLastData(basMap.getData()); | 
|             basMap.setData(redisMap.getData()); | 
|             basMap.setUpdateTime(new Date()); | 
|   | 
|             basMapService.updateById(basMap);//更新 | 
|         } | 
|     } | 
|   | 
| } |