自动化立体仓库 - WCS系统
999
zhangc
7 天以前 19adf22200dfe8e2bba439a2c1c640332f436835
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.zy.asrs.task;
 
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zy.asrs.entity.BasMap;
import com.zy.asrs.service.BasMapService;
import com.zy.common.utils.RedisUtil;
import com.zy.core.enums.RedisKeyType;
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;
import java.util.List;
 
@Component
@Slf4j
public class RealtimeBasMapScheduler {
 
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private BasMapService basMapService;
 
    /**
     * 每分钟从redis中更新地图数据到数据库中
     */
    @Scheduled(cron = "1 * * * * ? ")
    private void execute(){
        List<BasMap> basMaps = basMapService.selectList(new EntityWrapper<BasMap>().orderBy("lev", true));
        for (BasMap basMap : basMaps) {
            Integer lev = basMap.getLev();
            Object data = redisUtil.get(RedisKeyType.MAP.key + lev);
            if (data == null) {
                continue;
            }
 
            BasMap redisMap = JSON.parseObject(data.toString(), BasMap.class);
            basMap.setLastData(basMap.getData());
            basMap.setData(redisMap.getData());
            basMap.setUpdateTime(new Date());
            basMapService.updateById(basMap);//更新
        }
    }
 
}