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);
|
}
|
}
|
}
|