自动化立体仓库 - WMS系统
cl
2026-03-24 2c33a9a2967206d6167335ca178a0bce3351426c
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package com.zy.asrs.service.impl;
 
import com.zy.asrs.mapper.ReportQueryMapper;
import com.zy.asrs.service.MonitorLocMapCacheService;
import com.zy.common.utils.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.HashSet;
import java.util.List;
import java.util.Set;
 
@Slf4j
@Service
public class MonitorLocMapCacheServiceImpl implements MonitorLocMapCacheService {
 
    /** 与 WCS MonitorReportServiceImpl 写入键一致 */
    private static final String LOC_MAP_CACHE_KEY_PREFIX = "monitor:loc:map:row:";
 
    private static final String[] LOC_MAP_CACHE_PATTERNS = {
            "monitor:loc:map:*",
            "*monitor:loc:map:*",
    };
 
    @Autowired(required = false)
    private RedisUtil redisUtil;
    @Autowired(required = false)
    private ReportQueryMapper reportQueryMapper;
 
    @Override
    public void clearQuietly() {
        if (redisUtil == null) {
            return;
        }
        try {
            Set<String> toDelete = new HashSet<>();
            for (String pattern : LOC_MAP_CACHE_PATTERNS) {
                Set<?> keys = redisUtil.keys(pattern);
                if (keys == null || keys.isEmpty()) {
                    continue;
                }
                for (Object key : keys) {
                    if (key != null) {
                        toDelete.add(String.valueOf(key));
                    }
                }
            }
            toDelete.add(LOC_MAP_CACHE_KEY_PREFIX + "1");
            if (reportQueryMapper != null) {
                List<Integer> rows = reportQueryMapper.getViewLocRowTotal();
                if (rows != null) {
                    for (Integer row : rows) {
                        if (row != null) {
                            toDelete.add(LOC_MAP_CACHE_KEY_PREFIX + row);
                        }
                    }
                }
            }
            if (toDelete.isEmpty()) {
                return;
            }
            redisUtil.del(toDelete.toArray(new String[0]));
        } catch (Exception e) {
            log.warn("清理库位热力图缓存失败,继续业务", e);
        }
    }
}