package com.qiwu.chatbotbackend.entity; import java.io.IOException; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.concurrent.ExecutionException; import com.qiwu.chatbotbackend.GameEnvironment.GameEnv; import com.qiwu.chatbotbackend.processing.ChatCacheController; import org.springframework.beans.factory.DisposableBean; import javax.annotation.PreDestroy; public class ChatCache implements DisposableBean { private String chatKey = "不知道"; private Map infoPoint = null; private GameEnv gameEnv = null; private boolean reloading = false; public boolean isReloading() { return reloading; } public void setReloading(boolean reloading) { this.reloading = reloading; } public String getChatKey() { return chatKey; } public void setChatKey(String chatKey) { this.chatKey = chatKey; } public Map getInfoPoint() { return infoPoint; } public void setInfoPoint(Map infoPoint) { this.infoPoint = infoPoint; } public GameEnv getGameEnv() { return gameEnv; } public void setGameEnv(GameEnv gameEnv) { this.gameEnv = gameEnv; } public ChatCache(String chatKey, GameEnv gameEnv, Map infoPoint){ this.chatKey = chatKey; this.gameEnv = gameEnv; this.infoPoint = infoPoint; } @Override public void destroy() throws IOException { //System.out.println("销毁:" + chatKey); //ChatCacheController.saveChatCache(chatKey, this); } public ChatCache(UserInfo userInfo) throws Exception { try { gameEnv = new GameEnv(userInfo.botAccount); }catch (Exception e){ System.out.println("游戏平台初始化失败"); } String k; infoPoint = new HashMap(); Iterator iit = userInfo.varInitialMap.keySet().iterator(); while (iit.hasNext()) { k = iit.next(); infoPoint.put(k, userInfo.varInitialMap.get(k)); } infoPoint.put("lastUpdateTime", String.valueOf(System.currentTimeMillis())); } }