Commit 3c0c6f8a by hxw

游戏重新生成时删除所有存档、填表项目接到中控bot、在文本中删除拼音标注

parent 7648340e
...@@ -548,36 +548,26 @@ public class SqlHelper { ...@@ -548,36 +548,26 @@ public class SqlHelper {
return archiveInfo; return archiveInfo;
} }
// public boolean insertCategoryByBotId(int botId, String categoryName) {
// String sql = "insert into chatbot_config (botId, categoryId, configData, configName) VALUES (?, ?, ?, ?)"; public boolean deleteArchiveByBotAccount(String botAccount) {
// int id = 0; String sql = "delete from game_archive where user_key like ?";
// boolean b = true; boolean b;
// int bNum = 0;
// try { try {
// PreparedStatement ps = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); PreparedStatement ps = conn.prepareStatement(sql);
// ps.setString(1, String.valueOf(botId)); ps.setString(1, "%" + botAccount);
// ps.setString(2, "0"); b = ps.execute();
// ps.setString(4, jConfig.getConfigName());
// ps.close();
// System.out.println(ps.toString());
// return b;
// bNum = ps.executeUpdate();
// ResultSet rs = ps.getGeneratedKeys(); } catch (SQLException e) {
// if(rs.next()){ System.out.println("删除游戏存档失败");
// id = rs.getInt(1); e.printStackTrace();
// idList.add(id); return false;
// } }
// ps.close(); }
// rs.close();
// conn.commit();
//
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// return b;
//
// }
......
...@@ -44,7 +44,7 @@ public class ListeningConstructor extends ElementConstructor{ ...@@ -44,7 +44,7 @@ public class ListeningConstructor extends ElementConstructor{
for(int i = 0; i < size;i++){ for(int i = 0; i < size;i++){
plotNode = null; plotNode = null;
autoJump = false; autoJump = false;
priority = "1"; priority = "2";
feature = "match"; feature = "match";
config = listeningActions.getJSONObject(i); config = listeningActions.getJSONObject(i);
curPremiseList = JSONArray.parseArray(config.getJSONArray("curPremise").toJSONString(), String.class); curPremiseList = JSONArray.parseArray(config.getJSONArray("curPremise").toJSONString(), String.class);
...@@ -78,10 +78,11 @@ public class ListeningConstructor extends ElementConstructor{ ...@@ -78,10 +78,11 @@ public class ListeningConstructor extends ElementConstructor{
} }
if(plotNode.getString("priority") != null) if(config.getString("priority") != null)
priority = plotNode.getString("priority"); priority = config.getString("priority");
updateKnowledge.put(nextPlotId + "_from", ""); updateKnowledge.put(nextLocation + "_activate_by", "");
updateKnowledge.put(nextLocation + "_activate_ready", "0");
updateKnowledge.put("site", nextLocation); updateKnowledge.put("site", nextLocation);
...@@ -92,10 +93,12 @@ public class ListeningConstructor extends ElementConstructor{ ...@@ -92,10 +93,12 @@ public class ListeningConstructor extends ElementConstructor{
nextGameStep = String.format(GAME_STEP_FORMAT, botAccount,nextPlotId); nextGameStep = String.format(GAME_STEP_FORMAT, botAccount,nextPlotId);
updateKnowledge.put(lastTaskCondition, nextCondition); updateKnowledge.put(lastTaskCondition, nextCondition);
updateKnowledge.put(lastTaskReply, reply); updateKnowledge.put(lastTaskReply, reply);
updateKnowledge.put(nextPlotId, "1"); //下一步设为1 updateKnowledge.put(nextPlotId, "1"); //下一步设为1
updateKnowledge.put(nTaskLineName, nextGameStep); updateKnowledge.put(nTaskLineName, nextGameStep);
updateKnowledge.put("game_step", nextGameStep);
}else{ }else{
feature = "match,return-0"; feature = "match,return-0";
} }
......
...@@ -78,6 +78,7 @@ public class PlotConstructor2 extends ElementConstructor { ...@@ -78,6 +78,7 @@ public class PlotConstructor2 extends ElementConstructor {
BFSGenerate4(plotIndex.get(start), userinfo, jsonObject); BFSGenerate4(plotIndex.get(start), userinfo, jsonObject);
varInitialMap.put(start, "1"); varInitialMap.put(start, "1");
ListeningConstructor.cc(botAccount, jsonObject, plotIndex, configTermList);
} else { } else {
...@@ -87,7 +88,7 @@ public class PlotConstructor2 extends ElementConstructor { ...@@ -87,7 +88,7 @@ public class PlotConstructor2 extends ElementConstructor {
return; return;
} }
ListeningConstructor.cc(botAccount, jsonObject, plotIndex, configTermList);
...@@ -434,7 +435,8 @@ public class PlotConstructor2 extends ElementConstructor { ...@@ -434,7 +435,8 @@ public class PlotConstructor2 extends ElementConstructor {
//下一部剧情在不同地点时,为了防止到达下个地点的剧情重复执行,需要加一个标志表示下一步剧情是否已经发生过 //下一部剧情在不同地点时,为了防止到达下个地点的剧情重复执行,需要加一个标志表示下一步剧情是否已经发生过
appendKnowledge(extraUK, nextId + "_from", id); appendKnowledge(extraUK, nextLocation + "_activate_by", id);
appendKnowledge(extraUK, nextLocation + "_activate_ready", "1");
...@@ -863,27 +865,13 @@ public class PlotConstructor2 extends ElementConstructor { ...@@ -863,27 +865,13 @@ public class PlotConstructor2 extends ElementConstructor {
StringBuffer curPremise = new StringBuffer(); StringBuffer curPremise = new StringBuffer();
appendPremise(curPremise, "yaobuyao", "match", "Include", nextLocation); appendPremise(curPremise, "yaobuyao", "match", "Include", nextLocation);
appendPremise(hisPremise, nextId + "_from", "match", "Include", plotId); appendPremise(hisPremise, nextLocation + "_activate_by", "match", "Include", plotId);
appendPremise(hisPremise, nextLocation + "_activate_ready", "match", "Include", "1");
appendPremise(hisPremise, "isNeighbour:yaobuyao", "match", "Include", "1+3+4"); appendPremise(hisPremise, "isNeighbour:yaobuyao", "match", "Include", "1+3+4");
// appendPremise(hisPremise, plotId, "match", "Include", "2"); //剧情已完成且未前往
// appendPremise(hisPremise, "from_" + plotId, "match", "Include", "0");
// appendPremise(hisPremise, "to_" + nextId, "match", "Include", "0");
// if(autoJump) {
// feature = "match,activate:after"
// appendKnowledge(extraUK, "plot_jump_text", "str+" + reply);
//
// arriveActivatePlot2(jsonObject, id, nextId, gameStep, "plot_" + nextId + "_*", nextUnknownText, arriveUK.toString(), "match,activate:after");
// }else {
// feature = "match";
// arriveActivatePlot2(jsonObject, id, nextId, reply, gameStep, nextGameStep, nextLocation, nextCondition, nextUnknownText, arriveUK.toString(), "match");
// }
JSONObject updateKnowledge = new JSONObject(); JSONObject updateKnowledge = new JSONObject();
JSONArray curPremiseList = new JSONArray(); JSONArray curPremiseList = new JSONArray();
curPremiseList.add(curPremise.toString()); curPremiseList.add(curPremise.toString());
...@@ -897,6 +885,7 @@ public class PlotConstructor2 extends ElementConstructor { ...@@ -897,6 +885,7 @@ public class PlotConstructor2 extends ElementConstructor {
listeningConfig.put("hisPremise", hisPremiseList); listeningConfig.put("hisPremise", hisPremiseList);
listeningConfig.put("updateKnowledge", updateKnowledge); listeningConfig.put("updateKnowledge", updateKnowledge);
listeningConfig.put("nextPlotId", nextId); listeningConfig.put("nextPlotId", nextId);
listeningConfig.put("priority", "1");
if(gameElements.getJSONArray("listeningActions") == null) if(gameElements.getJSONArray("listeningActions") == null)
gameElements.put("listeningActions", new JSONArray()); gameElements.put("listeningActions", new JSONArray());
......
...@@ -791,7 +791,7 @@ public class ActionMatcher { ...@@ -791,7 +791,7 @@ public class ActionMatcher {
/** /**
* 在新平台添加debug_mode这个关键字, 后台会将存储的变量值返回给页面以作调试 * 如果接收到的表单中包含debug_mode这个参数, 后台会将存储的变量值返回给前段,用于调试
* *
* @param ans 最终返回的数据 * @param ans 最终返回的数据
* @param context * @param context
......
...@@ -21,7 +21,7 @@ public class ChatCacheController { ...@@ -21,7 +21,7 @@ public class ChatCacheController {
public static long TIME_OUT = 300000; public static long TIME_OUT = 300000;
private static String CHAT_CACHE_DIR = "ChatCache/"; public static String CHAT_CACHE_DIR = "ChatCache/";
private static String ARCHIVE_NAME = "%s-%s-%s"; private static String ARCHIVE_NAME = "%s-%s-%s";
private static String ENV_PATH = CHAT_CACHE_DIR + "%s-%s-%s-env.data"; private static String ENV_PATH = CHAT_CACHE_DIR + "%s-%s-%s-env.data";
...@@ -89,7 +89,7 @@ public class ChatCacheController { ...@@ -89,7 +89,7 @@ public class ChatCacheController {
public static synchronized boolean saveChatCache(ChatCache chatCache, SqlHelper helper) throws IOException { public static synchronized boolean saveChatCache(ChatCache chatCache, SqlHelper helper) throws IOException {
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss"); DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss");
String nowTime = now .format(format); String nowTime = now .format(format), userId, botAccount, keyElem[];
Boolean opFlag, destroy = false; Boolean opFlag, destroy = false;
System.out.println("游戏存档中"); System.out.println("游戏存档中");
...@@ -196,6 +196,7 @@ public class ChatCacheController { ...@@ -196,6 +196,7 @@ public class ChatCacheController {
Map<String, ChatCache> chatCacheMap = (Map<String, ChatCache>) context.getAttribute("chatCache"); Map<String, ChatCache> chatCacheMap = (Map<String, ChatCache>) context.getAttribute("chatCache");
try { try {
helper = new SqlHelper();
Iterator<String> it = chatCacheMap.keySet().iterator(); Iterator<String> it = chatCacheMap.keySet().iterator();
while (it.hasNext()) { while (it.hasNext()) {
...@@ -211,7 +212,7 @@ public class ChatCacheController { ...@@ -211,7 +212,7 @@ public class ChatCacheController {
chatCache = chatCacheMap.get(sessionKey); chatCache = chatCacheMap.get(sessionKey);
if(chatCache != null && !chatCache.getRandKey().equals(chatCache.getUserKey()) && chatCache.isGameStart()) { if(chatCache != null && !chatCache.getRandKey().equals(chatCache.getUserKey()) && chatCache.isGameStart()) {
saveChatCache(chatCache, null); saveChatCache(chatCache, helper);
} }
System.out.println("移除" + sessionKey); System.out.println("移除" + sessionKey);
it.remove(); it.remove();
...@@ -219,6 +220,8 @@ public class ChatCacheController { ...@@ -219,6 +220,8 @@ public class ChatCacheController {
} }
}catch (Exception e){ }catch (Exception e){
e.printStackTrace(); e.printStackTrace();
}finally {
helper.destroy();
} }
context.setAttribute("chatCache", chatCacheMap); context.setAttribute("chatCache", chatCacheMap);
} }
...@@ -236,53 +239,45 @@ public class ChatCacheController { ...@@ -236,53 +239,45 @@ public class ChatCacheController {
} }
public static synchronized boolean findChatCache(String userKey, ServletContext context, String botAccount) throws Exception { public static synchronized boolean findChatCache(String userKey, ServletContext context) throws Exception {
ChatCache chatCache = null;
GameEnv gameEnv = null;
ArchiveInfo archiveInfo = null; ArchiveInfo archiveInfo = null;
Map<String ,String> infoPoint = null; Map<String, ChatCache> chatCacheMap = null;
ChatCache chatCache = null;
String fileDir = System.getProperty("user.dir") + "/ChatCache"; String fileDir = System.getProperty("user.dir") + "/ChatCache";
String line, pair[]; Boolean findFlag = false;
SqlHelper helper; SqlHelper helper;
Map<String, String> infoPoints = new HashMap<String, String>(); Map<String, String> infoPoints = new HashMap<String, String>();
try { try {
helper = new SqlHelper();
archiveInfo = helper.queryUserLastGameArchive(userKey);
helper.destroy();
} catch(Exception e){ if (context.getAttribute("chatCache") == null) {
e.printStackTrace(); chatCacheMap = new HashMap<String, ChatCache>();
return false; if (chatCacheMap.containsKey(userKey)) {
chatCache = chatCacheMap.get(userKey);
findFlag = !(chatCache.getUserKey().endsWith(chatCache.getRandKey())); //userKey和randKey不同表示存在用户id,如果相同则没有登录只是试玩
} }
return archiveInfo != null;
} }
System.out.println("findFlag" + findFlag);
if (!findFlag) {
helper = new SqlHelper();
archiveInfo = helper.queryUserLastGameArchive(userKey);
helper.destroy();
findFlag = (archiveInfo != null);
}
public static synchronized boolean deleteUnuseChatCache(String chatKey, ServletContext context) throws Exception {
try {
System.out.println("移除----------------------------");
HashMap<String, ChatCache> chatCacheHashMap = (HashMap<String, ChatCache>)context.getAttribute("chatCache");
chatCacheHashMap.remove(chatKey);
} catch(Exception e){ } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return false; return false;
} }
return true; return findFlag;
} }
} }
...@@ -189,7 +189,7 @@ public class FormsPoster { ...@@ -189,7 +189,7 @@ public class FormsPoster {
* @param URL * @param URL
* @throws UnsupportedEncodingException * @throws UnsupportedEncodingException
*/ */
public void postGameQA(Map<String ,String> curInfoPoint, Map<String ,String> historyInfoPoint, Solution ans,GameEnv gameEnv, WorldController worldController, String URL, UserInfo userInfo) throws UnsupportedEncodingException { public void postGameQA1(String gameStep, Map<String ,String> curInfoPoint, Map<String ,String> historyInfoPoint, Solution ans,GameEnv gameEnv, WorldController worldController, String URL, UserInfo userInfo) throws UnsupportedEncodingException {
String key, keyName; String key, keyName;
Iterator<String> k_iter = null; Iterator<String> k_iter = null;
List<BasicNameValuePair> pairList = new ArrayList<BasicNameValuePair>(); List<BasicNameValuePair> pairList = new ArrayList<BasicNameValuePair>();
...@@ -198,7 +198,7 @@ public class FormsPoster { ...@@ -198,7 +198,7 @@ public class FormsPoster {
if (historyInfoPoint.get("qa_threshold") != null) if (historyInfoPoint.get("qa_threshold") != null)
threshold = historyInfoPoint.get("qa_threshold"); threshold = historyInfoPoint.get("qa_threshold");
pairList.add(new BasicNameValuePair("game_step", historyInfoPoint.get("game_step"))); pairList.add(new BasicNameValuePair("game_step", gameStep));
pairList.add(new BasicNameValuePair("query_text", curInfoPoint.get("query_text"))); pairList.add(new BasicNameValuePair("query_text", curInfoPoint.get("query_text")));
pairList.add(new BasicNameValuePair("qa_threshold", threshold)); pairList.add(new BasicNameValuePair("qa_threshold", threshold));
...@@ -251,4 +251,13 @@ public class FormsPoster { ...@@ -251,4 +251,13 @@ public class FormsPoster {
} }
} }
} public void postGameQA(Map<String ,String> curInfoPoint, Map<String ,String> historyInfoPoint, Solution ans,GameEnv gameEnv, WorldController worldController, String URL, UserInfo userInfo) throws UnsupportedEncodingException {
postGameQA1(historyInfoPoint.get("game_step"), curInfoPoint, historyInfoPoint,ans, gameEnv, worldController, URL, userInfo);
if(historyInfoPoint.get("common_answer").equals("") || historyInfoPoint.get("common_answer").equals("no answer")){
postGameQA1(curInfoPoint.get("bot_name"), curInfoPoint, historyInfoPoint, ans, gameEnv, worldController, URL, userInfo);
}
}
}
...@@ -38,8 +38,6 @@ public class ContextDestroyListener implements ServletContextListener { ...@@ -38,8 +38,6 @@ public class ContextDestroyListener implements ServletContextListener {
chatKey = cacheIter.next(); chatKey = cacheIter.next();
cache = chatCacheMap.get(chatKey); cache = chatCacheMap.get(chatKey);
//当用户id和随机对话id不同时,表示用户为登录状态,用户登录且开始游戏,则可以存档 //当用户id和随机对话id不同时,表示用户为登录状态,用户登录且开始游戏,则可以存档
if (cache != null && !cache.getRandKey().equals(cache.getUserKey()) && cache.isGameStart()) { if (cache != null && !cache.getRandKey().equals(cache.getUserKey()) && cache.isGameStart()) {
System.out.println(String.format("saving %s", chatKey)); System.out.println(String.format("saving %s", chatKey));
......
...@@ -24,7 +24,8 @@ public class FindCacheServlet extends HttpServlet { ...@@ -24,7 +24,8 @@ public class FindCacheServlet extends HttpServlet {
Boolean exist = false; Boolean exist = false;
try { try {
exist = ChatCacheController.findChatCache(userKey, context, botAccount);
exist = ChatCacheController.findChatCache(userKey, context);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
......
...@@ -7,6 +7,7 @@ import com.qiwu.chatbotbackend.entity.UserInfo; ...@@ -7,6 +7,7 @@ import com.qiwu.chatbotbackend.entity.UserInfo;
import com.qiwu.chatbotbackend.gameDesign.*; import com.qiwu.chatbotbackend.gameDesign.*;
import com.qiwu.chatbotbackend.processing.MyFunc; import com.qiwu.chatbotbackend.processing.MyFunc;
import com.qiwu.chatbotbackend.processing.UserInfoController; import com.qiwu.chatbotbackend.processing.UserInfoController;
import com.qiwu.chatbotbackend.task.utils.FileFinder;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import javax.servlet.ServletException; import javax.servlet.ServletException;
...@@ -20,6 +21,8 @@ import java.time.LocalDateTime; ...@@ -20,6 +21,8 @@ import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import static com.qiwu.chatbotbackend.processing.ChatCacheController.CHAT_CACHE_DIR;
@WebServlet(name = "GameDesignServlet", urlPatterns = {"/gameDesign"}) @WebServlet(name = "GameDesignServlet", urlPatterns = {"/gameDesign"})
public class GameDesignServlet extends HttpServlet { public class GameDesignServlet extends HttpServlet {
...@@ -103,7 +106,7 @@ public class GameDesignServlet extends HttpServlet { ...@@ -103,7 +106,7 @@ public class GameDesignServlet extends HttpServlet {
//清空之前生成的配置条目 //清空之前生成的配置条目
try { try {
flag = botInit(botId, userinfo, helper); flag = botInit(botId, botAccount, userinfo, helper);
} catch (SQLException e) { } catch (SQLException e) {
System.out.println("清空旧数据失败"); System.out.println("清空旧数据失败");
e.printStackTrace(); e.printStackTrace();
...@@ -122,7 +125,7 @@ public class GameDesignServlet extends HttpServlet { ...@@ -122,7 +125,7 @@ public class GameDesignServlet extends HttpServlet {
ldt = LocalDateTime.now(); ldt = LocalDateTime.now();
now = ldt.format(dtf); now = ldt.format(dtf);
timeUsedDetect.append("\n,预处理之后:").append(now); timeUsedDetect.append("\n,预处理之后:").append(now);
String moduleList[] = {"map", "goods", "globalVariable", "npc", "plots", "listeningActions"}; String moduleList[] = {"map", "goods", "globalVariable", "npc", "plots"};
for(String moduleName: moduleList){ for(String moduleName: moduleList){
switch (moduleName) { switch (moduleName) {
...@@ -153,10 +156,6 @@ public class GameDesignServlet extends HttpServlet { ...@@ -153,10 +156,6 @@ public class GameDesignServlet extends HttpServlet {
constructor = new CharacterConstructor(helper, botId, botAccount, keywordMap, exceptRelation, POS); constructor = new CharacterConstructor(helper, botId, botAccount, keywordMap, exceptRelation, POS);
constructor.construct(gameElements, userinfo); constructor.construct(gameElements, userinfo);
break; break;
case "listeningActions":
moduleName2 = "生成处于监听的action";
constructor = new ListeningConstructor(helper, botId, botAccount, keywordMap, exceptRelation, POS);
constructor.construct(gameElements, userinfo);
default: default:
continue; continue;
...@@ -218,6 +217,10 @@ public class GameDesignServlet extends HttpServlet { ...@@ -218,6 +217,10 @@ public class GameDesignServlet extends HttpServlet {
} }
} }
if(returnStatus == 1){
deleteOldArchive(helper, botAccount);
}
helper.destroy(); helper.destroy();
...@@ -259,11 +262,12 @@ public class GameDesignServlet extends HttpServlet { ...@@ -259,11 +262,12 @@ public class GameDesignServlet extends HttpServlet {
out.flush(); out.flush();
} }
public boolean botInit(int botId, UserInfo userInfo, SqlHelper helper) throws SQLException, IOException { public boolean botInit(int botId, String botAccount, UserInfo userInfo, SqlHelper helper) throws SQLException, IOException {
boolean deleteConfigFlag = helper.deleteConfigByBotId(botId); boolean deleteConfigFlag = helper.deleteConfigByBotId(botId);
boolean deleteVariableFlag = helper.deleteVariableByBotId(botId); boolean deleteVariableFlag = helper.deleteVariableByBotId(botId);
boolean deleteCategoryFlag = helper.deleteCategoryByBotId(botId); boolean deleteCategoryFlag = helper.deleteCategoryByBotId(botId);
boolean batchInsertCategoryFlag = helper.batchInsertCategoryByBotId(botId, categoryMap); boolean batchInsertCategoryFlag = helper.batchInsertCategoryByBotId(botId, categoryMap);
boolean deleteArchiveFlag = deleteOldArchive(helper, botAccount);
return deleteConfigFlag && deleteVariableFlag; return deleteConfigFlag && deleteVariableFlag;
...@@ -293,8 +297,6 @@ public class GameDesignServlet extends HttpServlet { ...@@ -293,8 +297,6 @@ public class GameDesignServlet extends HttpServlet {
actionPostData.put("POS", POS.toString() + POS2); actionPostData.put("POS", POS.toString() + POS2);
//System.out.println(actionPostData.toJSONString());
userInfo.extraInfo.put("activeAction", startCondition); userInfo.extraInfo.put("activeAction", startCondition);
try { try {
returnMessage = MyFunc.postJSON(POST_URL, actionPostData, (String)gameElements.get("auth")); returnMessage = MyFunc.postJSON(POST_URL, actionPostData, (String)gameElements.get("auth"));
...@@ -340,6 +342,14 @@ public class GameDesignServlet extends HttpServlet { ...@@ -340,6 +342,14 @@ public class GameDesignServlet extends HttpServlet {
} }
} }
public Boolean deleteOldArchive(SqlHelper helper, String botAccount){
Boolean sqlDeleteFlag = helper.deleteArchiveByBotAccount(botAccount);
Boolean fileDeleteFlag = FileFinder.deleteGameArchive(CHAT_CACHE_DIR, botAccount);
return sqlDeleteFlag && fileDeleteFlag;
}
} }
...@@ -60,12 +60,6 @@ public class GetAnswerServlet extends HttpServlet { ...@@ -60,12 +60,6 @@ public class GetAnswerServlet extends HttpServlet {
receiveParamters.put("userKey", new String[]{userKey}); receiveParamters.put("userKey", new String[]{userKey});
receiveParamters.put("randKey", new String[]{randKey}); receiveParamters.put("randKey", new String[]{randKey});
// if(!receiveParamters.get("chat_key")[0].startsWith("@"))
// chatKey = receiveParamters.get("chat_key")[0].split("@")[0];
// else
// chatKey = receiveParamters.get("chat_key")[0];
// receiveParamters.get("chat_key")[0] = chatKey;
LogWriter logWriter = new LogWriter(LOG_PATH, chatKey); LogWriter logWriter = new LogWriter(LOG_PATH, chatKey);
...@@ -90,7 +84,6 @@ public class GetAnswerServlet extends HttpServlet { ...@@ -90,7 +84,6 @@ public class GetAnswerServlet extends HttpServlet {
ChatCache chatCache = null; ChatCache chatCache = null;
Boolean loadCacheStatus = Boolean.valueOf(false); Boolean loadCacheStatus = Boolean.valueOf(false);
try { try {
//chatCache = ChatCacheController.getChatCache2(userKey, randKey, context, userinfo, receiveParamters, loadCacheStatus);
chatCache = ChatCacheController.getChatCache(userKey, randKey, context, userinfo, receiveParamters, loadCacheStatus); chatCache = ChatCacheController.getChatCache(userKey, randKey, context, userinfo, receiveParamters, loadCacheStatus);
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
......
package com.qiwu.chatbotbackend.task.utils; package com.qiwu.chatbotbackend.task.utils;
import com.alibaba.fastjson.JSONObject;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Queue; import java.util.regex.Matcher;
import java.util.regex.Pattern;
/** /**
* 实现一个支持通配符的基于广度优先算法的文件查找器 * 实现一个支持通配符的基于广度优先算法的文件查找器
...@@ -18,7 +16,6 @@ public class FileFinder { ...@@ -18,7 +16,6 @@ public class FileFinder {
* 查找文件。 * 查找文件。
* @param baseDirName 待查找的目录 * @param baseDirName 待查找的目录
* @param targetFileName 目标文件名,支持通配符形式 * @param targetFileName 目标文件名,支持通配符形式
* @param count 期望结果数目,如果畏0,则表示查找全部。
* @return 满足查询条件的文件名列表 * @return 满足查询条件的文件名列表
*/ */
public static List findFiles(String baseDirName, String targetFileName) { public static List findFiles(String baseDirName, String targetFileName) {
...@@ -88,4 +85,37 @@ public class FileFinder { ...@@ -88,4 +85,37 @@ public class FileFinder {
return (strIndex == strLength); return (strIndex == strLength);
} }
public static boolean deleteGameArchive(String baseDirName, String botAccount){
String tempName;
String regEx = ".*@@@" + botAccount + "@@@@.*";
List fileList = new ArrayList();
Pattern pattern = Pattern.compile(regEx);
Matcher matcher = null;
//判断目录是否存在
File baseDir = new File(baseDirName);
if (!baseDir.exists() || !baseDir.isDirectory()){
System.out.println("文件查找失败:" + baseDirName + "不是一个目录!");
return false;
}
File[] files = baseDir.listFiles();
for (int i = 0; i < files.length; i++) {
//如果是目录则放进队列
if (files[i].isDirectory()) {
continue;
} else {
//如果是文件则根据文件名与目标文件名进行匹配
tempName = files[i].getName();
matcher = pattern.matcher(tempName);
if (matcher.find()) {
//匹配成功,将文件名添加到结果集
files[i].delete();
}
}
}
return true;
}
} }
...@@ -293,6 +293,8 @@ public class GameBotUtil extends BasicBotUtil{ ...@@ -293,6 +293,8 @@ public class GameBotUtil extends BasicBotUtil{
}else{ }else{
System.out.println("没有识别到" + LOAD_BY_SITE_CONDITION); System.out.println("没有识别到" + LOAD_BY_SITE_CONDITION);
} }
} else if(ansAction.featureMap.containsKey("sendArchiveList")){
} }
} catch (SQLException e) { } catch (SQLException e) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment