Commit 292f3813 sunke

工位缓存

1 个父辈 c5cef2b0
...@@ -18,6 +18,7 @@ import org.springframework.data.mongodb.core.query.Criteria; ...@@ -18,6 +18,7 @@ import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -27,14 +28,14 @@ import java.util.concurrent.ConcurrentHashMap; ...@@ -27,14 +28,14 @@ import java.util.concurrent.ConcurrentHashMap;
@Slf4j @Slf4j
public class StationCacheUtil { public class StationCacheUtil {
@Autowired private static DataCache dataCache;
private DataCache dataCache;
/** /**
* 工位缓存信息 * 工位缓存信息
*/ */
private static Map<String, Station> stationMap = new ConcurrentHashMap<>(); private static Map<String, Station> stationMap = new ConcurrentHashMap<>();
@PostConstruct
public void init() { public void init() {
log.info("开始工位缓存信息"); log.info("开始工位缓存信息");
for (int i = 1; i < 5; i++) { for (int i = 1; i < 5; i++) {
...@@ -49,18 +50,41 @@ public class StationCacheUtil { ...@@ -49,18 +50,41 @@ public class StationCacheUtil {
} }
} }
private synchronized void updateStation(Station station){ private static synchronized void updateStation(Station station){
stationMap.put(station.getName(),station); stationMap.put(station.getName(),station);
dataCache.updateCache(station.getName(), station); dataCache.updateCache(station.getName(), station);
} }
/** /**
* 更新工位当前的RFID信息
* @param stationName 工位名称
* @param rfid 料箱RFID信息
*/
public static void updateCurrentRfid(String stationName, String rfid){
if(rfid == null){
rfid = "";
}
Station station = getStation(stationName);
if(station != null){
station.setCurrentRfid(rfid);
updateStation(station);
}
}
/**
* 获取工位信息 * 获取工位信息
* @param stationName 工位名称 * @param stationName 工位名称
* @return * @return
*/ */
public Station getStation(String stationName){ public static Station getStation(String stationName){
return stationMap.get(stationName); return stationMap.get(stationName);
} }
@Autowired
public void setDataCache(DataCache dataCache) {
StationCacheUtil.dataCache = dataCache;
}
} }
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!