From 11c28e1061f1531a1105a4c33bbc62b1e8581870 Mon Sep 17 00:00:00 2001 From: 苗权威 <1160292058@qq.com> Date: Sat, 6 Jul 2019 19:29:04 +0800 Subject: [PATCH] change --- .idea/misc.xml | 1 + .idea/workspace.xml | 655 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- dingdong/src/main/java/ai/qiwu/dong/dingdong/common/Constants.java | 2 ++ dingdong/src/main/java/ai/qiwu/dong/dingdong/common/Holder.java | 1 + dingdong/src/main/java/ai/qiwu/dong/dingdong/common/SnowFlake.java | 9 --------- dingdong/src/main/java/ai/qiwu/dong/dingdong/controller/DingDongController.java | 11 +++-------- dingdong/src/main/java/ai/qiwu/dong/dingdong/service/ParseService.java | 59 +++++++++++++++++++++++++++++------------------------------ dingdong/src/main/java/ai/qiwu/dong/dingdong/service/ParseServiceCompromise.java | 185 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------------------- dingdong/src/main/resources/application.properties | 4 +++- dingdong/src/main/resources/logback.xml | 42 ------------------------------------------ jdwhale/src/main/java/ai/qiwu/mqw/jdwhale/controller/DingDongController.java | 6 +++--- jdwhale/src/main/java/ai/qiwu/mqw/jdwhale/service/ParseService.java | 11 +++++------ jdwhale/src/main/java/ai/qiwu/mqw/jdwhale/service/ParseServiceWithoutLRU.java | 9 +++++---- jdwhale/src/main/resources/application.properties | 4 +++- jdwhale/src/main/resources/logback.xml | 42 ------------------------------------------ spirit/src/main/resources/application.properties | 4 +++- spirit/src/main/resources/logback.xml | 42 ------------------------------------------ xiaoai/pom.xml | 15 +++++++++++++++ xiaoai/src/main/java/ai/qiwu/mi/xiaoai/XiaoaiApplication.java | 8 +++++++- xiaoai/src/main/java/ai/qiwu/mi/xiaoai/controller/XiaoAiController.java | 6 ++++++ xiaoai/src/main/java/ai/qiwu/mi/xiaoai/service/XiaoAiService.java | 40 +++++++++++++++------------------------- xiaoai/src/main/resources/application.properties | 4 +++- xiaodu/pom.xml | 7 ------- xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/common/Holder.java | 33 ++++++++++++++++++++++++++++----- xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/pojo/AudioUrlAndText.java | 21 ++++++++++++++++----- xiaodu/src/main/resources/application.properties | 9 +++------ xiaodu/src/main/resources/logback.xml | 42 ------------------------------------------ xiaoya/src/main/java/ai/qiwu/xiaoya/xiaoya/controller/XiaoYaController.java | 3 +-- xiaoya/src/main/java/ai/qiwu/xiaoya/xiaoya/service/ParseService.java | 6 +++--- xiaoya/src/main/resources/application.properties | 9 +++------ xiaoya/src/main/resources/logback.xml | 42 ------------------------------------------ 31 files changed, 614 insertions(+), 718 deletions(-) delete mode 100644 dingdong/src/main/java/ai/qiwu/dong/dingdong/common/SnowFlake.java delete mode 100644 dingdong/src/main/resources/logback.xml delete mode 100644 jdwhale/src/main/resources/logback.xml delete mode 100644 spirit/src/main/resources/logback.xml delete mode 100644 xiaodu/src/main/resources/logback.xml delete mode 100644 xiaoya/src/main/resources/logback.xml diff --git a/.idea/misc.xml b/.idea/misc.xml index 8b0269f..a4c70ab 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -6,6 +6,7 @@ + diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 4c2638e..2e93ce2 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,31 +2,37 @@ - - - - + + + - - - - - + + + + + + + + + + + + - - - - + + - - + + + + @@ -64,43 +70,41 @@ - - + + - - + + - + - - - - - - - + + - - + + - - + + + + + - + - - + + @@ -117,7 +121,11 @@ response + logger + + log + - + + + + + + + + + + + @@ -266,7 +249,7 @@ - + @@ -304,7 +287,7 @@ - + + + + @@ -487,15 +501,16 @@ - + - - + + @@ -575,432 +590,440 @@ - + - - + + + + + - - + + + + + + + + + - + - - + + + + + - - + + + + + + + + + - + - - + + + + + - - + + + + + + + + + - + - - + + - + - + + + + - + - - + + + + + - + - - + + - + - - + + - - + - + - - + + + + + - + - - + + + + + - + - - + + + + + - + - - + + + + + - + - - + + + + + - + - - + + - + - - + + + + + + - + - - + + - - + + - + - - + + - + - - + + - + - - + + - + - - - - - + + - + - - - - - + + - + - - - - - + + - + - - - - - + + - + - - - - - + + - + - - - - - + + - + - - - - - + + - + - - - - - + + - + - - - - - + + - + - - - - - + + - + - - - - - + + - + - - - - - + + - + - - - - - + + - + - - - - - + + - + - - + + - + + + + + + + + - + - + - + + + + + + + + + + + + + - + - - - - - + + - + - - - - - + + - + - - - - - + + - + - - - - - + + - + - - - - - + + - + - - + + - + - - - - - + + - + - - + + - + - - + + - + - - + + - + - - - - - - - + + - + - - + + diff --git a/dingdong/src/main/java/ai/qiwu/dong/dingdong/common/Constants.java b/dingdong/src/main/java/ai/qiwu/dong/dingdong/common/Constants.java index af710c1..946578c 100644 --- a/dingdong/src/main/java/ai/qiwu/dong/dingdong/common/Constants.java +++ b/dingdong/src/main/java/ai/qiwu/dong/dingdong/common/Constants.java @@ -22,6 +22,8 @@ public interface Constants { String DEV_SERVICE_RESP_PACK_ERROR = "DEV_SERVICE_RESP_PACK_ERROR"; String NOTICE_OPEN_PLATFORM_ERROR = "OPEN_PLATFORM_ERROR"; + Integer MAX_REPEAT = 3; + interface Intent { String XIAO_WU = "xiaowu"; String RECOMMEND = "recommend"; diff --git a/dingdong/src/main/java/ai/qiwu/dong/dingdong/common/Holder.java b/dingdong/src/main/java/ai/qiwu/dong/dingdong/common/Holder.java index 616c721..2654d0d 100644 --- a/dingdong/src/main/java/ai/qiwu/dong/dingdong/common/Holder.java +++ b/dingdong/src/main/java/ai/qiwu/dong/dingdong/common/Holder.java @@ -12,4 +12,5 @@ import lombok.Setter; public class Holder { private volatile String word; private volatile String lastAudioUrl; + private volatile int oneTimeMaxRepeat; } diff --git a/dingdong/src/main/java/ai/qiwu/dong/dingdong/common/SnowFlake.java b/dingdong/src/main/java/ai/qiwu/dong/dingdong/common/SnowFlake.java deleted file mode 100644 index c32e651..0000000 --- a/dingdong/src/main/java/ai/qiwu/dong/dingdong/common/SnowFlake.java +++ /dev/null @@ -1,9 +0,0 @@ -package ai.qiwu.dong.dingdong.common; - -/** - * @author 苗权威 - * @dateTime 19-6-27 下午8:26 - */ -public class SnowFlake { - -} diff --git a/dingdong/src/main/java/ai/qiwu/dong/dingdong/controller/DingDongController.java b/dingdong/src/main/java/ai/qiwu/dong/dingdong/controller/DingDongController.java index 31a7d95..824e660 100644 --- a/dingdong/src/main/java/ai/qiwu/dong/dingdong/controller/DingDongController.java +++ b/dingdong/src/main/java/ai/qiwu/dong/dingdong/controller/DingDongController.java @@ -4,6 +4,7 @@ import ai.qiwu.dong.dingdong.model.request.DingDongRequest; import ai.qiwu.dong.dingdong.model.response.DingDongResponse; import ai.qiwu.dong.dingdong.service.ParseService; import ai.qiwu.dong.dingdong.service.ParseServiceCompromise; +import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -14,10 +15,9 @@ import org.springframework.web.bind.annotation.*; * @dateTime 19-6-27 下午1:35 */ @RestController +@Slf4j public class DingDongController { - private static final Logger logger = LoggerFactory.getLogger(ParseService.class); - @Autowired private ParseServiceCompromise compromise; @@ -26,12 +26,7 @@ public class DingDongController { @RequestMapping("/ding") public @ResponseBody DingDongResponse dingdong(@RequestBody DingDongRequest request) { - logger.info("Request params : "+ request); + //log.info("Request params : "+ request); return compromise.getResponse(request); } - - @RequestMapping("/ding/callback") - public void dingdongCallback(@RequestParam String state) { - logger.info("Callback response : "+ state); - } } diff --git a/dingdong/src/main/java/ai/qiwu/dong/dingdong/service/ParseService.java b/dingdong/src/main/java/ai/qiwu/dong/dingdong/service/ParseService.java index 5c4b0f0..14245b8 100644 --- a/dingdong/src/main/java/ai/qiwu/dong/dingdong/service/ParseService.java +++ b/dingdong/src/main/java/ai/qiwu/dong/dingdong/service/ParseService.java @@ -9,6 +9,7 @@ import ai.qiwu.dong.dingdong.model.response.directive.Directive; import ai.qiwu.dong.dingdong.model.response.directive.DirectiveItem; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; @@ -29,15 +30,13 @@ import java.util.concurrent.ConcurrentHashMap; * @dateTime 19-6-27 下午1:13 */ @Service("parseService") +@Slf4j public class ParseService { - private static final Logger logger = LoggerFactory.getLogger(ParseService.class); - private static final ConcurrentHashMap REQUEST_TIMESTAMP_INTERVAL= new ConcurrentHashMap<>(); private static final ConcurrentHashMap SESSION_ID_WITH_REPEAT_COUNT= new ConcurrentHashMap<>(); - public DingDongResponse getResponse(DingDongRequest request) { String userId = null; User user = request.getUser(); @@ -59,14 +58,14 @@ public class ParseService { DingDongResponse noticeResponse = dealWithNoticeStatus(request); Integer removedRepeatCount = SESSION_ID_WITH_REPEAT_COUNT.remove(userId); if (removedRepeatCount != null) { - logger.info("删除之前的重复次数:"+removedRepeatCount); + log.info("删除之前的重复次数:"+removedRepeatCount); } return noticeResponse; }else if ("END".equals(request.getStatus())) { DingDongResponse endResponse = dealWithEndStatus(request); Integer removedRepeatCount = SESSION_ID_WITH_REPEAT_COUNT.remove(userId); if (removedRepeatCount != null) { - logger.info("删除之前的重复次数:"+removedRepeatCount); + log.info("删除之前的重复次数:"+removedRepeatCount); } return endResponse; } @@ -81,7 +80,7 @@ public class ParseService { Integer previousCount = SESSION_ID_WITH_REPEAT_COUNT.putIfAbsent(userId, 0); if (previousCount == null || previousCount < 2) { int currentCount = previousCount == null ? 1 : previousCount+1; - logger.info("两次请求过于短暂,可能是叮咚识别了自己的话,播放前一次的语音,重复次数: "+ currentCount); + log.info("两次请求过于短暂,可能是叮咚识别了自己的话,播放前一次的语音,重复次数: "+ currentCount); SESSION_ID_WITH_REPEAT_COUNT.put(userId, currentCount); if (lastResponseContent.getUrl() == null) { return buildErrorResponse(requestVersion, requestSequence, userId); @@ -91,23 +90,23 @@ public class ParseService { return response; } } - logger.info("重复次数超过两次,不再重复"); + log.info("重复次数超过两次,不再重复"); } // slots={focus=Story} // if (request.getSlots() == null || request.getSlots().size() == 1) { -// logger.info("收到了未在意图中的单字,可能是用户说的或是叮咚受到了自己播放的影响,处理方法:提示用户说的详细一些,这个单字是: "+userWord); +// log.info("收到了未在意图中的单字,可能是用户说的或是叮咚受到了自己播放的影响,处理方法:提示用户说的详细一些,这个单字是: "+userWord); // DingDongResponse uncatchSlot = buildErrorResponse(requestVersion, requestSequence, userId); // uncatchSlot.getDirective().getDirective_items().get(0).setContent("请说详细一些吧"); // SESSION_ID_WITH_REPEAT_COUNT.remove(userId); // return uncatchSlot; //// if (lastResponseContent != null && lastResponseContent.getUrl() != null) { -//// logger.info("未在意图中的单字情况:播放上次音频链接"); +//// log.info("未在意图中的单字情况:播放上次音频链接"); //// DingDongResponse response = buildResponse(requestVersion, requestSequence, userId); //// response.getDirective().getDirective_items().get(0).setContent(lastResponseContent.getUrl()); //// return response; //// }else { -//// logger.info("未在意图中的单字情况:由于没有音频链接缓存,所以读文字"); +//// log.info("未在意图中的单字情况:由于没有音频链接缓存,所以读文字"); //// DingDongResponse uncatchSlot = buildErrorResponse(requestVersion, requestSequence, userId); //// uncatchSlot.getDirective().getDirective_items().get(0).setContent("请说详细一些吧"); //// return uncatchSlot; @@ -117,16 +116,16 @@ public class ParseService { if (userWord == null) { Integer removedRepeatCount = SESSION_ID_WITH_REPEAT_COUNT.remove(userId); if (removedRepeatCount != null) { - logger.info("删除之前的重复次数:"+removedRepeatCount); + log.info("删除之前的重复次数:"+removedRepeatCount); } return buildErrorResponse(requestVersion, requestSequence, userId); } DingDongResponse response = requestQiWuInterface(userId, userWord, requestVersion, requestSequence); - logger.info("RESPONSE : "+response); + log.info("RESPONSE : "+response); Integer removedRepeatCount = SESSION_ID_WITH_REPEAT_COUNT.remove(userId); if (removedRepeatCount != null) { - logger.info("删除之前的重复次数:"+removedRepeatCount); + log.info("删除之前的重复次数:"+removedRepeatCount); } return response; } @@ -154,20 +153,20 @@ public class ParseService { HttpEntity responseBody = httpResponse.getEntity(); if (responseBody != null) { String responseContent = EntityUtils.toString(responseBody); - logger.info("齐悟接口返回: "+ responseContent); + log.info("齐悟接口返回: "+ responseContent); JSONObject responseJsonFormat = JSONObject.parseObject(responseContent); audioUrl = (String) responseJsonFormat.get("audio"); textContent = (String) responseJsonFormat.get("text"); } } catch (IOException e) { - logger.error("请求齐悟接口出错:"+e.toString()); + log.error("请求齐悟接口出错:"+e.toString()); return buildErrorResponse(version, sequence, userId); } finally { try { if (httpClient != null) httpClient.close(); if (httpResponse != null) httpResponse.close(); } catch (IOException e) { - logger.error("关闭与齐悟接口时出错:"+e.toString()); + log.error("关闭与齐悟接口时出错:"+e.toString()); } } return addUrlAndTextToResponse(audioUrl, textContent, version, sequence, userId); @@ -219,12 +218,12 @@ public class ParseService { private DingDongResponse dealWithNoticeStatus(DingDongRequest request) { String noticeType = request.getNotice_type(); switch (noticeType) { - case Constants.USER_INTPUT_NOREC: logger.info("status为NOTICE:用户输入的内容语义结果为拒识情况"); break; - case Constants.USER_NOREC_TIMES_OUT: logger.info("status为NOTICE:用户拒识次数超出最大值,默认最大值为2次");break; - case Constants.DEV_RESP_PACK_TOO_LONG: logger.info("status为NOTICE:开发者服务回包数据过长,长度最大为2Kb");break; - case Constants.DEV_SERVICE_VISIT_TIME_OUT: logger.info("status为NOTICE:开发者服务访问超时,默认超时时间为5秒");break; - case Constants.DEV_SERVICE_RESP_PACK_ERROR: logger.info("status为NOTICE:开发者服务回包数据错误");break; - case Constants.NOTICE_OPEN_PLATFORM_ERROR: logger.info("status为NOTICE:开放平台系统异常");break; + case Constants.USER_INTPUT_NOREC: log.info("status为NOTICE:用户输入的内容语义结果为拒识情况"); break; + case Constants.USER_NOREC_TIMES_OUT: log.info("status为NOTICE:用户拒识次数超出最大值,默认最大值为2次");break; + case Constants.DEV_RESP_PACK_TOO_LONG: log.info("status为NOTICE:开发者服务回包数据过长,长度最大为2Kb");break; + case Constants.DEV_SERVICE_VISIT_TIME_OUT: log.info("status为NOTICE:开发者服务访问超时,默认超时时间为5秒");break; + case Constants.DEV_SERVICE_RESP_PACK_ERROR: log.info("status为NOTICE:开发者服务回包数据错误");break; + case Constants.NOTICE_OPEN_PLATFORM_ERROR: log.info("status为NOTICE:开放平台系统异常");break; } DingDongResponse response = buildErrorResponse(request.getVersionid(), request.getSequence(), request.getUser().getUser_id()); response.getDirective().getDirective_items().get(0).setContent(""); @@ -235,18 +234,18 @@ public class ParseService { String endReason = request.getEnded_reason(); if (endReason != null && !endReason.isEmpty()) { switch (endReason) { - case Constants.USER_END : logger.info("用户主动结束"); break; - case Constants.SESSION_TIMEOUT: logger.info("会话超时平台结束"); break; - case Constants.SESSION_ALLTIMES_OUT: logger.info("会话总次数超出平台结束"); break; - case Constants.SESSION_CURTIMES_OUT: logger.info("会话当前次数超出平台结束"); break; - case Constants.OPEN_PLATFORM_ERROR: logger.info("开放平台处理异常"); break; - case Constants.SERVICE_INVOKER_TIMEOUT: logger.info("服务调用超时"); break; - case Constants.SERVICE_INVOKER_ERROR: logger.info("服务应答结果异常"); break; + case Constants.USER_END : log.info("用户主动结束"); break; + case Constants.SESSION_TIMEOUT: log.info("会话超时平台结束"); break; + case Constants.SESSION_ALLTIMES_OUT: log.info("会话总次数超出平台结束"); break; + case Constants.SESSION_CURTIMES_OUT: log.info("会话当前次数超出平台结束"); break; + case Constants.OPEN_PLATFORM_ERROR: log.info("开放平台处理异常"); break; + case Constants.SERVICE_INVOKER_TIMEOUT: log.info("服务调用超时"); break; + case Constants.SERVICE_INVOKER_ERROR: log.info("服务应答结果异常"); break; } } DingDongResponse response = buildErrorResponse(request.getVersionid(), request.getSequence(), request.getUser().getUser_id()); response.getDirective().getDirective_items().get(0).setContent("我们的作品库在不断扩充,欢迎下次再来玩"); - logger.info("退出前删除缓存,缓存删除结果:"+(REQUEST_TIMESTAMP_INTERVAL.remove(request.getUser().getUser_id()) != null)); + log.info("退出前删除缓存,缓存删除结果:"+(REQUEST_TIMESTAMP_INTERVAL.remove(request.getUser().getUser_id()) != null)); return response; } } diff --git a/dingdong/src/main/java/ai/qiwu/dong/dingdong/service/ParseServiceCompromise.java b/dingdong/src/main/java/ai/qiwu/dong/dingdong/service/ParseServiceCompromise.java index 5176c57..c7e3492 100644 --- a/dingdong/src/main/java/ai/qiwu/dong/dingdong/service/ParseServiceCompromise.java +++ b/dingdong/src/main/java/ai/qiwu/dong/dingdong/service/ParseServiceCompromise.java @@ -11,6 +11,7 @@ import ai.qiwu.dong.dingdong.model.response.directive.Directive; import ai.qiwu.dong.dingdong.model.response.directive.DirectiveItem; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; @@ -27,47 +28,47 @@ import java.util.*; import java.util.concurrent.ConcurrentHashMap; /** + * 由于叮咚在播放音频或tts过程中不会关麦,导致其将自身的声音识别为用户的话,以下尝试从几方面来解决这一问题: + * + * 我们规定除了“推荐作品”外,用户每句话前必须以“小wu”/“hui答”开始,或是每句话以“wan毕”结尾, + * 这样不符合的话就不会进入意图,但是该方案有个问题,叮咚在连续两次发生无法识别的情况下(不属于该技能意图的话), + * 会退出技能,为此我仍需在其文法编辑里加入通配符以匹配任意的话,在代码中我对这种通配意图做以下处理,缓存上一次该意图的话, + * 与本次的进行比较,若相同则认为是用户说的,若不通则认为是音箱误识的,当然对拒绝的处理采取重播上一次音频链接的方式, + * 为此我们需要缓存相关内容,对于缓存,由于无法保证END事件的发生,所以我们还需要一个定时删除的功能 * @author 苗权威 * @dateTime 19-6-29 上午9:37 */ @Service("compromise") +@Slf4j public class ParseServiceCompromise { - private final static Logger logger = LoggerFactory.getLogger(ParseServiceCompromise.class); - private final static ConcurrentHashMap USER_LAST_ALL_WORD_AudioUrl = new ConcurrentHashMap<>(); + /** + * 获取响应 + * @param request 请求信息 + * @return 响应信息 + */ public DingDongResponse getResponse(DingDongRequest request) { - String userId = null; - User user = request.getUser(); - if (user != null && user.getUser_id() != null) { - userId = request.getUser().getUser_id(); - }else { - if (request.getApplication_info() != null) { - userId = request.getApplication_info().getApplication_id(); - } - if (userId == null) { - //文档保证session字段一定不为空,将其id当作该种情况下的用户id - // 一次会话从开始到结束,sessionId不变,一次会话指的是从用户进入到我们的技能到其退出为止 - userId = request.getSession().getSession_id(); - } - } + String userId = getUserId(request); - String status = request.getStatus(); - if (!Status.INTENT.equals(status)) { - if (Status.LAUNCH.equals(status)) { - return dealLaunchIntent(request, userId); - } - else if (Status.NOTICE.equals(request.getStatus())) { - return dealWithNoticeStatus(request, userId); - } - else if (Status.END.equals(request.getStatus())) { - return dealWithEndStatus(request, userId); - } + //对不同状态进行处理,正常对话过程中为Intent,初次进入技能为Launch,结束为End, + // 异常状态信息平台会通过异步的形式发给我们,消息类型为Notice + switch (request.getStatus()) { + case Status.INTENT : return dealWithIntent(request, userId); + case Status.LAUNCH : return dealLaunchIntent(request, userId); + case Status.END : return dealWithEndStatus(request, userId); + case Status.NOTICE : return dealWithNoticeStatus(request, userId); + default : return buildErrorResponse(request, userId); } - return dealWithIntent(request, userId); } + /** + * 向终端接口发送请求获取响应 + * @param userId 用户id + * @param request 请求信息 + * @return 响应信息 + */ private DingDongResponse requestQiWuInterface(String userId, DingDongRequest request) { String audioUrl = ""; String textContent = "请说推荐作品"; @@ -91,33 +92,41 @@ public class ParseServiceCompromise { HttpEntity responseBody = httpResponse.getEntity(); if (responseBody != null) { String responseContent = EntityUtils.toString(responseBody); - logger.info("齐悟接口返回: "+ responseContent); + log.info("齐悟接口返回: "+ responseContent); JSONObject responseJsonFormat = JSONObject.parseObject(responseContent); audioUrl = (String) responseJsonFormat.get("audio"); textContent = (String) responseJsonFormat.get("text"); } } catch (IOException e) { - logger.error("请求齐悟接口出错:"+e.toString()); + log.error("请求齐悟接口出错:"+e.toString()); return buildErrorResponse(request, userId); } finally { try { if (httpClient != null) httpClient.close(); if (httpResponse != null) httpResponse.close(); } catch (IOException e) { - logger.error("关闭与齐悟接口时出错:"+e.toString()); + log.warn("关闭与齐悟接口时出错:"+e.toString()); } } return addUrlAndTextToResponse(audioUrl, textContent, request, userId); } + /** + * 处理意图内请求信息.按照我在文法编辑器里设置的,每个请求只会命中一个意图, + * 除了刚进入技能时说“打开技能名,推荐作品”,对于此我们另外处理 + * @param userId 用户id + * @param request 请求信息 + * @return 响应信息 + */ private DingDongResponse dealWithIntent(DingDongRequest request, String userId) { Map slots = request.getSlots(); if (slots == null) { - logger.info("slots为空,没有映射到任何意图"); + log.info("slots为空,没有映射到任何意图"); return buildErrorResponse(request, userId); } else if (slots.size() == 2) { String intentKey = null; + // focus默认包含,其值为我们的业务名 for (String key: slots.keySet() ) { if(!key.equals("focus")) { @@ -126,10 +135,10 @@ public class ParseServiceCompromise { } } if (intentKey == null || intentKey.isEmpty()) { - logger.info("意图个数为2,但是出现意料之外的情况,slots map : "+slots); + log.info("意图个数为2,但是出现意料之外的情况,slots map : "+slots); return buildErrorResponse(request, userId); } - + //分别处理“hui答“开始的意图;”小wu“开始的意图;”wan毕“结尾的意图;”推荐作品“意图;任意意图 switch (intentKey) { case Intent.END_BY_END : return parseWordInItsIntent(request, false, true, userId); case Intent.XIAO_WU : return parseWordInItsIntent(request, true, true, userId); @@ -137,23 +146,33 @@ public class ParseServiceCompromise { case Intent.RECOMMEND : return parseWordInItsIntent(request, true, false, userId); case Intent.ALL : return parseWordInItsIntent(request, false, false, userId); default: { - logger.info("没有匹配到任何已有意图,本次请求的意图名:"+intentKey); + log.info("没有匹配到任何已有意图,本次请求的意图名:"+intentKey); return buildErrorResponse(request, userId); } } } // {focus:story} else if (slots.size() <= 1) { - logger.info("slots不为null,但是没有映射到任何意图"); + log.info("slots不为null,但是没有映射到任何意图"); return buildErrorResponse(request, userId); - } else if (slots.size() == 3 && slots.containsKey(Intent.RECOMMEND)) { + } + // 对应"打开"技能名",推荐作品" + else if (slots.size() == 3 && slots.containsKey(Intent.RECOMMEND)) { return requestQiWuInterface(userId, request); } else { - logger.info("Intent请求slots大小>3,或是等于3但是没有recommend意图,预料之外"); + log.info("Intent请求slots大小>3,或是等于3但是没有recommend意图,预料之外"); return buildErrorResponse(request, userId); } } + /** + * font,needToCut皆为false则代表是匹配到任意意图的话 + * @param request 求信息 + * @param font 是否是限定开头的意图 + * @param needToCut 限定开头,结尾的意图语句需要裁剪 + * @param userId 用户id + * @return 响应信息 + */ private DingDongResponse parseWordInItsIntent(DingDongRequest request, boolean font, boolean needToCut, String userId) { String word = request.getInput_text(); Holder holder = USER_LAST_ALL_WORD_AudioUrl.get(userId); @@ -161,18 +180,18 @@ public class ParseServiceCompromise { if (needToCut) { if (font) { try { - logger.info("成功匹配到意图:"+word.substring(0,2)); + log.info("成功匹配到意图:"+word.substring(0,2)); } catch (Exception e) { - logger.info("日志本想打印出前置意图下用户所说的前两个字:小悟/回答,但是用户的话少于两个,这是不正常"); + log.info("日志本想打印出前置意图下用户所说的前两个字:小悟/回答,但是用户的话少于两个,这是不正常"); } if (word.length() > 2) { word = word.substring(2); } }else { try { - logger.info("成功匹配到意图:"+word.substring(word.length()-2)); + log.info("成功匹配到意图:"+word.substring(word.length()-2)); } catch (Exception e) { - logger.info("日志本想打印出后置意图下用户所说的最后两个字:完毕,但是用户的话少于两个,这是不正常的"); + log.info("日志本想打印出后置意图下用户所说的最后两个字:完毕,但是用户的话少于两个,这是不正常的"); } if (word.length() > 2) { word = word.substring(0, word.length()-2); @@ -181,28 +200,39 @@ public class ParseServiceCompromise { } // 处理ALL意图 else if (!font) { - if (holder != null && word.equals(holder.getWord())) { - logger.info("本次ALL意图的话语与上次相同,认定是用户说的话"); - } else { - if (holder == null) { - holder = new Holder(); - USER_LAST_ALL_WORD_AudioUrl.put(userId, holder); - } + if (holder == null) { + holder = new Holder(); + USER_LAST_ALL_WORD_AudioUrl.put(userId, holder); holder.setWord(word); + holder.setOneTimeMaxRepeat(1); + log.info("第一次匹配到任意意图,提醒用户再说一遍"); + return buildErrorResponse(request, userId); + } + else if (word.equals(holder.getWord())) { + log.info("本次ALL意图的话语与上次相同,认定是用户说的话"); + holder.setOneTimeMaxRepeat(0); + } + // 任意意图的匹配次数最多连续三次,第四次则不再拦截,默认为是用户的话 + else if (holder.getOneTimeMaxRepeat() > Constants.MAX_REPEAT) { + log.info("任意意图的次数超过三次,不再拦截,放过"); + holder.setOneTimeMaxRepeat(0); + } + else { + holder.setWord(word); + holder.setOneTimeMaxRepeat(holder.getOneTimeMaxRepeat()+1); DingDongResponse forbidResponse; if (holder.getLastAudioUrl() != null) { - logger.info("本次ALL意图的话语与上次不同,重复播放上次音频"); + log.info("本次ALL意图的话语与上次不同,重复播放上次音频"); forbidResponse = buildResponse(request, userId); forbidResponse.getDirective().getDirective_items().get(0).setContent(holder.getLastAudioUrl()); } else { - logger.info("本次ALL意图的话语与上次不同,提醒用户再说一遍"); + log.info("本次ALL意图的话语与上次不同,提醒用户再说一遍"); forbidResponse = buildErrorResponse(request, userId); } return forbidResponse; } - } - logger.info("此次解析得到的用户的话是:"+word); + log.info("此次解析得到的用户的话是:"+word); response = requestQiWuInterface(userId, request); String audioUrl = response.getDirective().getDirective_items().get(0).getContent(); @@ -258,15 +288,15 @@ public class ParseServiceCompromise { private DingDongResponse dealWithNoticeStatus(DingDongRequest request, String userId) { String noticeType = request.getNotice_type(); switch (noticeType) { - case Constants.USER_INTPUT_NOREC: logger.info("status为NOTICE:用户输入的内容语义结果为拒识情况"); break; - case Constants.USER_NOREC_TIMES_OUT: logger.info("status为NOTICE:用户拒识次数超出最大值,默认最大值为2次");break; - case Constants.DEV_RESP_PACK_TOO_LONG: logger.info("status为NOTICE:开发者服务回包数据过长,长度最大为2Kb");break; - case Constants.DEV_SERVICE_VISIT_TIME_OUT: logger.info("status为NOTICE:开发者服务访问超时,默认超时时间为5秒");break; - case Constants.DEV_SERVICE_RESP_PACK_ERROR: logger.info("status为NOTICE:开发者服务回包数据错误");break; - case Constants.NOTICE_OPEN_PLATFORM_ERROR: logger.info("status为NOTICE:开放平台系统异常");break; + case Constants.USER_INTPUT_NOREC: log.info("status为NOTICE:用户输入的内容语义结果为拒识情况"); break; + case Constants.USER_NOREC_TIMES_OUT: log.info("status为NOTICE:用户拒识次数超出最大值,默认最大值为2次");break; + case Constants.DEV_RESP_PACK_TOO_LONG: log.info("status为NOTICE:开发者服务回包数据过长,长度最大为2Kb");break; + case Constants.DEV_SERVICE_VISIT_TIME_OUT: log.info("status为NOTICE:开发者服务访问超时,默认超时时间为5秒");break; + case Constants.DEV_SERVICE_RESP_PACK_ERROR: log.info("status为NOTICE:开发者服务回包数据错误");break; + case Constants.NOTICE_OPEN_PLATFORM_ERROR: log.info("status为NOTICE:开放平台系统异常");break; } - if (USER_LAST_ALL_WORD_AudioUrl.remove(userId) != null) logger.info("非正常结束,平台发出NOTICE信息,在此处删除缓存成功"); + if (USER_LAST_ALL_WORD_AudioUrl.remove(userId) != null) log.info("非正常结束,平台发出NOTICE信息,在此处删除缓存成功"); return buildErrorResponse(request, userId); } @@ -274,19 +304,38 @@ public class ParseServiceCompromise { String endReason = request.getEnded_reason(); if (endReason != null && !endReason.isEmpty()) { switch (endReason) { - case Constants.USER_END : logger.info("用户主动结束"); break; - case Constants.SESSION_TIMEOUT: logger.info("会话超时平台结束"); break; - case Constants.SESSION_ALLTIMES_OUT: logger.info("会话总次数超出平台结束"); break; - case Constants.SESSION_CURTIMES_OUT: logger.info("会话当前次数超出平台结束"); break; - case Constants.OPEN_PLATFORM_ERROR: logger.info("开放平台处理异常"); break; - case Constants.SERVICE_INVOKER_TIMEOUT: logger.info("服务调用超时"); break; - case Constants.SERVICE_INVOKER_ERROR: logger.info("服务应答结果异常"); break; + case Constants.USER_END : log.info("用户主动结束"); break; + case Constants.SESSION_TIMEOUT: log.info("会话超时平台结束"); break; + case Constants.SESSION_ALLTIMES_OUT: log.info("会话总次数超出平台结束"); break; + case Constants.SESSION_CURTIMES_OUT: log.info("会话当前次数超出平台结束"); break; + case Constants.OPEN_PLATFORM_ERROR: log.info("开放平台处理异常"); break; + case Constants.SERVICE_INVOKER_TIMEOUT: log.info("服务调用超时"); break; + case Constants.SERVICE_INVOKER_ERROR: log.info("服务应答结果异常"); break; } } DingDongResponse response = buildErrorResponse(request, userId); response.getDirective().getDirective_items().get(0).setContent("我们的作品库在不断扩充,欢迎下次再来玩"); - if (USER_LAST_ALL_WORD_AudioUrl.remove(userId) != null) logger.info("平台发出END信息,代表技能退出,在此处删除缓存成功"); + if (USER_LAST_ALL_WORD_AudioUrl.remove(userId) != null) log.info("平台发出END信息,代表技能退出,在此处删除缓存成功"); return response; } + + private String getUserId(DingDongRequest request) { + String userId = null; + User user = request.getUser(); + if (user != null && user.getUser_id() != null) { + userId = request.getUser().getUser_id(); + }else { + if (request.getApplication_info() != null) { + userId = request.getApplication_info().getApplication_id(); + } + if (userId == null) { + //文档保证session字段一定不为空,将其id当作该种情况下的用户id + // 一次会话从开始到结束,sessionId不变,一次会话指的是从用户进入到我们的技能到其退出为止, + // 因为我们会将is_end设为false以维持住与用户的联系 + userId = request.getSession().getSession_id(); + } + } + return userId; + } } diff --git a/dingdong/src/main/resources/application.properties b/dingdong/src/main/resources/application.properties index 8b13789..5e8d8ba 100644 --- a/dingdong/src/main/resources/application.properties +++ b/dingdong/src/main/resources/application.properties @@ -1 +1,3 @@ - +logging.path=/usr/mqw/logs/dingdong +logging.level.root = info +spring.output.ansi.enabled=detect diff --git a/dingdong/src/main/resources/logback.xml b/dingdong/src/main/resources/logback.xml deleted file mode 100644 index bcd38ac..0000000 --- a/dingdong/src/main/resources/logback.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - %d %p (%file:%line\)- %m%n - - UTF-8 - - - - - - - - - - - - - /usr/mqw/logs/dingdong/ - - - /usr/mqw/logs/dingdong/base.log.%d.%i - - 64 MB - - - - - %d %p (%file:%line\)- %m%n - - UTF-8 - - - - - - \ No newline at end of file diff --git a/jdwhale/src/main/java/ai/qiwu/mqw/jdwhale/controller/DingDongController.java b/jdwhale/src/main/java/ai/qiwu/mqw/jdwhale/controller/DingDongController.java index 98d93ba..f3df7c7 100644 --- a/jdwhale/src/main/java/ai/qiwu/mqw/jdwhale/controller/DingDongController.java +++ b/jdwhale/src/main/java/ai/qiwu/mqw/jdwhale/controller/DingDongController.java @@ -3,6 +3,7 @@ package ai.qiwu.mqw.jdwhale.controller; import ai.qiwu.mqw.jdwhale.model.RequestModel.DingDongRequest; import ai.qiwu.mqw.jdwhale.model.ResponseModel.DingDongResponse; import ai.qiwu.mqw.jdwhale.service.ParseServiceWithoutLRU; +import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -16,16 +17,15 @@ import org.springframework.web.bind.annotation.RestController; * @dateTime 19-6-25 下午4:51 */ @RestController +@Slf4j public class DingDongController { - private static final Logger logger = LoggerFactory.getLogger(DingDongController.class); - @Autowired private ParseServiceWithoutLRU serviceWithoutLRU; @RequestMapping("/dingdong") public @ResponseBody DingDongResponse dingdong(@RequestBody DingDongRequest request) { - logger.info("Request params: "+request); + //log.info("Request params: "+request); return serviceWithoutLRU.getResponse(request); } } diff --git a/jdwhale/src/main/java/ai/qiwu/mqw/jdwhale/service/ParseService.java b/jdwhale/src/main/java/ai/qiwu/mqw/jdwhale/service/ParseService.java index 28b9894..db19164 100644 --- a/jdwhale/src/main/java/ai/qiwu/mqw/jdwhale/service/ParseService.java +++ b/jdwhale/src/main/java/ai/qiwu/mqw/jdwhale/service/ParseService.java @@ -11,6 +11,7 @@ import ai.qiwu.mqw.jdwhale.model.ResponseModel.response.OutputResponse; import ai.qiwu.mqw.jdwhale.model.ResponseModel.response.Reprompt; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; @@ -18,8 +19,6 @@ import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.util.EntityUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import java.io.IOException; @@ -33,8 +32,8 @@ import java.util.concurrent.ConcurrentHashMap; * @dateTime 19-6-25 下午5:13 */ @Service("service") +@Slf4j public class ParseService { - private static final Logger logger = LoggerFactory.getLogger(ParseService.class); private static final ConcurrentHashMap userResponseMap = new ConcurrentHashMap<>(); @@ -46,7 +45,7 @@ public class ParseService { case "LaunchRequest": return dealLaunchRequest(); case "IntentRequest": return dealIntentRequest(unknowRequest, userId); case "SessionEndedRequest": dealSessionEndedRequest(unknowRequest, userId); return null; - default: logger.info("ERROR DIRECTIVE"); return dealLaunchRequest(); + default: log.info("ERROR DIRECTIVE"); return dealLaunchRequest(); } } @@ -93,7 +92,7 @@ public class ParseService { private void dealSessionEndedRequest(TripleRequest request, String userId) { DingDongResponse response = userResponseMap.remove(userId); - logger.info("用户:"+userId+" 的缓存删除成功, " + response); + log.info("用户:"+userId+" 的缓存删除成功, " + response); } private void requestQiWuInterface(String userId, String userWord, DingDongResponse response) { @@ -119,7 +118,7 @@ public class ParseService { HttpEntity responseBody = httpResponse.getEntity(); if (responseBody != null) { String responseContent = EntityUtils.toString(responseBody); - logger.info("齐悟接口返回: "+ responseContent); + log.info("齐悟接口返回: "+ responseContent); JSONObject responseJsonFormat = JSONObject.parseObject(responseContent); audioUrl = (String) responseJsonFormat.get("audio"); textContent = (String) responseJsonFormat.get("text"); diff --git a/jdwhale/src/main/java/ai/qiwu/mqw/jdwhale/service/ParseServiceWithoutLRU.java b/jdwhale/src/main/java/ai/qiwu/mqw/jdwhale/service/ParseServiceWithoutLRU.java index f7c8a51..314581c 100644 --- a/jdwhale/src/main/java/ai/qiwu/mqw/jdwhale/service/ParseServiceWithoutLRU.java +++ b/jdwhale/src/main/java/ai/qiwu/mqw/jdwhale/service/ParseServiceWithoutLRU.java @@ -11,6 +11,7 @@ import ai.qiwu.mqw.jdwhale.model.ResponseModel.response.OutputResponse; import ai.qiwu.mqw.jdwhale.model.ResponseModel.response.Reprompt; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; @@ -32,8 +33,8 @@ import java.util.List; * @dateTime 19-6-26 下午4:09 */ @Service("serviceWithoutLRU") +@Slf4j public class ParseServiceWithoutLRU { - private static final Logger logger = LoggerFactory.getLogger(ParseService.class); public DingDongResponse getResponse(DingDongRequest request) { String userId = request.getSession().getUser().getUserId(); @@ -43,7 +44,7 @@ public class ParseServiceWithoutLRU { case "LaunchRequest": return dealLaunchRequest(); case "IntentRequest": return dealIntentRequest(unknowRequest, userId); case "SessionEndedRequest": dealSessionEndedRequest(userId); return null; - default: logger.info("ERROR DIRECTIVE"); return dealLaunchRequest(); + default: log.info("ERROR DIRECTIVE"); return dealLaunchRequest(); } } @@ -85,7 +86,7 @@ public class ParseServiceWithoutLRU { } private void dealSessionEndedRequest(String userId) { - logger.info("用户 "+userId+" 会话结束"); + log.info("用户 "+userId+" 会话结束"); } private void requestQiWuInterface(String userId, String userWord, DingDongResponse response) { @@ -111,7 +112,7 @@ public class ParseServiceWithoutLRU { HttpEntity responseBody = httpResponse.getEntity(); if (responseBody != null) { String responseContent = EntityUtils.toString(responseBody); - logger.info("齐悟接口返回: "+ responseContent); + log.info("齐悟接口返回: "+ responseContent); JSONObject responseJsonFormat = JSONObject.parseObject(responseContent); audioUrl = (String) responseJsonFormat.get("audio"); textContent = (String) responseJsonFormat.get("text"); diff --git a/jdwhale/src/main/resources/application.properties b/jdwhale/src/main/resources/application.properties index 8b13789..1e94248 100644 --- a/jdwhale/src/main/resources/application.properties +++ b/jdwhale/src/main/resources/application.properties @@ -1 +1,3 @@ - +logging.path=/usr/mqw/logs/jdwhale +logging.level.root = info +spring.output.ansi.enabled=detect diff --git a/jdwhale/src/main/resources/logback.xml b/jdwhale/src/main/resources/logback.xml deleted file mode 100644 index 88ab8d5..0000000 --- a/jdwhale/src/main/resources/logback.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - %d %p (%file:%line\)- %m%n - - UTF-8 - - - - - - - - - - - - - /usr/mqw/logs/jdWhale/ - - - /usr/mqw/logs/jdWhale/base.log.%d.%i - - 64 MB - - - - - %d %p (%file:%line\)- %m%n - - UTF-8 - - - - - - \ No newline at end of file diff --git a/spirit/src/main/resources/application.properties b/spirit/src/main/resources/application.properties index 8b13789..ea1fa38 100644 --- a/spirit/src/main/resources/application.properties +++ b/spirit/src/main/resources/application.properties @@ -1 +1,3 @@ - +logging.path=/usr/mqw/logs/spirit +logging.level.root = info +spring.output.ansi.enabled=detect diff --git a/spirit/src/main/resources/logback.xml b/spirit/src/main/resources/logback.xml deleted file mode 100644 index 93d69ef..0000000 --- a/spirit/src/main/resources/logback.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - %d %p (%file:%line\)- %m%n - - UTF-8 - - - - - - - - - - - - - /usr/mqw/logs/spirit/ - - - /usr/mqw/logs/spirit/base.log.%d.%i - - 64 MB - - - - - %d %p (%file:%line\)- %m%n - - UTF-8 - - - - - - \ No newline at end of file diff --git a/xiaoai/pom.xml b/xiaoai/pom.xml index 3db9550..af0ac41 100644 --- a/xiaoai/pom.xml +++ b/xiaoai/pom.xml @@ -11,6 +11,7 @@ ai.qiwu.mi xiaoai 0.0.1-SNAPSHOT + war xiaoai Demo project for Spring Boot @@ -22,6 +23,12 @@ org.springframework.boot spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-tomcat + + @@ -29,6 +36,13 @@ spring-boot-starter-test test + + + javax.servlet + javax.servlet-api + LATEST + provided + org.apache.httpcomponents @@ -50,6 +64,7 @@ + xiaoai org.springframework.boot diff --git a/xiaoai/src/main/java/ai/qiwu/mi/xiaoai/XiaoaiApplication.java b/xiaoai/src/main/java/ai/qiwu/mi/xiaoai/XiaoaiApplication.java index 9a4f025..d49df54 100644 --- a/xiaoai/src/main/java/ai/qiwu/mi/xiaoai/XiaoaiApplication.java +++ b/xiaoai/src/main/java/ai/qiwu/mi/xiaoai/XiaoaiApplication.java @@ -2,12 +2,18 @@ package ai.qiwu.mi.xiaoai; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; @SpringBootApplication -public class XiaoaiApplication { +public class XiaoaiApplication extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(XiaoaiApplication.class, args); } + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { + return builder.sources(XiaoaiApplication.class); + } } diff --git a/xiaoai/src/main/java/ai/qiwu/mi/xiaoai/controller/XiaoAiController.java b/xiaoai/src/main/java/ai/qiwu/mi/xiaoai/controller/XiaoAiController.java index e609e14..3305b73 100644 --- a/xiaoai/src/main/java/ai/qiwu/mi/xiaoai/controller/XiaoAiController.java +++ b/xiaoai/src/main/java/ai/qiwu/mi/xiaoai/controller/XiaoAiController.java @@ -3,6 +3,8 @@ package ai.qiwu.mi.xiaoai.controller; import ai.qiwu.mi.xiaoai.model.request.XiaoAiRequest; import ai.qiwu.mi.xiaoai.model.response.XiaoAiResponse; import ai.qiwu.mi.xiaoai.service.XiaoAiService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -21,6 +23,10 @@ public class XiaoAiController { @RequestMapping("/xiaoai") public @ResponseBody XiaoAiResponse xiaoai(@RequestBody XiaoAiRequest request) { + //log.info("请求:"+request); + //XiaoAiResponse response = xiaoAiService.getResponse(request); + //log.info("响应:"+response); + //return response; return xiaoAiService.getResponse(request); } } diff --git a/xiaoai/src/main/java/ai/qiwu/mi/xiaoai/service/XiaoAiService.java b/xiaoai/src/main/java/ai/qiwu/mi/xiaoai/service/XiaoAiService.java index a038d44..9104e93 100644 --- a/xiaoai/src/main/java/ai/qiwu/mi/xiaoai/service/XiaoAiService.java +++ b/xiaoai/src/main/java/ai/qiwu/mi/xiaoai/service/XiaoAiService.java @@ -13,6 +13,7 @@ import ai.qiwu.mi.xiaoai.model.response.innerResponse.directive.Directive; import ai.qiwu.mi.xiaoai.model.response.innerResponse.toSpeak.ToSpeak; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; @@ -35,10 +36,9 @@ import java.util.List; * @dateTime 19-7-5 下午8:52 */ @Service +@Slf4j public class XiaoAiService { - private static final Logger logger = LoggerFactory.getLogger(XiaoAiService.class); - public XiaoAiResponse getResponse(XiaoAiRequest request) { String userId = getUserId(request); int type = request.getRequest().getType(); @@ -71,20 +71,20 @@ public class XiaoAiService { HttpEntity responseBody = httpResponse.getEntity(); if (responseBody != null) { String responseContent = EntityUtils.toString(responseBody); - logger.info("齐悟接口返回: "+ responseContent); + //log.info("齐悟接口返回: "+ responseContent); JSONObject responseJsonFormat = JSONObject.parseObject(responseContent); audioUrl = (String) responseJsonFormat.get("audio"); textContent = (String) responseJsonFormat.get("text"); } } catch (IOException e) { - logger.info(ERROR_MSG.TERMINATE_IO_EXCEPTION); + log.info(ERROR_MSG.TERMINATE_IO_EXCEPTION); return buildTextResponse(ERROR_MSG.SORRY_REPEAT); } finally { try { if (httpClient != null) httpClient.close(); if (httpResponse != null) httpResponse.close(); } catch (IOException e) { - logger.info(ERROR_MSG.HTTP_CONNECTION_CLOSE_EXCEPTION); + log.info(ERROR_MSG.HTTP_CONNECTION_CLOSE_EXCEPTION); } } return buildAudioResponse(audioUrl); @@ -94,13 +94,19 @@ public class XiaoAiService { XiaoAiResponse response = new XiaoAiResponse(); response.setVersion("1.0"); response.setIs_session_end(false); + + Response responseInfo = new Response(); + // 这个字段很重要,他会在播放音频或是tts结束后,开麦收音,因为默认麦是关闭的, + // 若不主动打开则小爱在一次会话后退出技能。 + responseInfo.setOpen_mic(true); + response.setResponse(responseInfo); return response; } private XiaoAiResponse buildAudioResponse(String audioUrl) { XiaoAiResponse response = buildResponse(); + Response responseInfo = response.getResponse(); - Response responseInfo = new Response(); Directive directive = new Directive(); directive.setType("audio"); AudioItem audioItem = new AudioItem(); @@ -112,30 +118,19 @@ public class XiaoAiService { directives.add(directive); responseInfo.setDirectives(directives); - response.setResponse(responseInfo); return response; } private XiaoAiResponse buildTextResponse(String text) { XiaoAiResponse response = buildResponse(); + Response responseInfo = response.getResponse(); - Response responseInfo = new Response(); + responseInfo.setOpen_mic(true); ToSpeak toSpeak = new ToSpeak(); toSpeak.setType(0); toSpeak.setText(text); responseInfo.setTo_speak(toSpeak); - response.setResponse(responseInfo); - return response; - } - - private XiaoAiResponse buildOpenMicResponse() { - XiaoAiResponse response = buildResponse(); - - Response responseInfo = new Response(); - responseInfo.setOpen_mic(true); - - response.setResponse(responseInfo); return response; } @@ -145,14 +140,9 @@ public class XiaoAiService { private XiaoAiResponse dealWithIntentRequest(XiaoAiRequest request, String userId) { Boolean idle = request.getRequest().getNo_response(); - if (idle == null || idle) { + if (idle != null && idle) { return buildTextResponse(TTS.USER_IDLE); } - //String eventType = request.getRequest().getEvent_type(); - // 这里是否向小度一样需要在语音播放结束后主动开麦? -// if (eventType != null && eventType.equals(XiaoAiConstants.PLAYBACK_NEARLY_FINISHED)) { -// return buildOpenMicResponse(); -// } String userWord = request.getQuery(); if (userWord == null) { return buildTextResponse(ERROR_MSG.SORRY_REPEAT); diff --git a/xiaoai/src/main/resources/application.properties b/xiaoai/src/main/resources/application.properties index 8b13789..64456db 100644 --- a/xiaoai/src/main/resources/application.properties +++ b/xiaoai/src/main/resources/application.properties @@ -1 +1,3 @@ - +logging.path=/usr/mqw/logs/xiaoai +logging.level.root = info +spring.output.ansi.enabled=detect \ No newline at end of file diff --git a/xiaodu/pom.xml b/xiaodu/pom.xml index f547bad..fc2b74f 100644 --- a/xiaodu/pom.xml +++ b/xiaodu/pom.xml @@ -55,13 +55,6 @@ 1.2.58 compile - - - org.projectlombok - lombok - 1.18.8 - provided - diff --git a/xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/common/Holder.java b/xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/common/Holder.java index d92be32..c8a9ce4 100644 --- a/xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/common/Holder.java +++ b/xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/common/Holder.java @@ -1,19 +1,42 @@ package ai.qiwu.baidu.xiaodu.common; -import lombok.Getter; -import lombok.Setter; - import java.util.concurrent.locks.ReentrantLock; /** * @author 苗权威 * @dateTime 19-7-1 下午8:39 */ -@Getter -@Setter public class Holder { private volatile String timestamp; private volatile String lastAudioUrl; private final ReentrantLock FAIR_LOCK = new ReentrantLock(); private volatile int first; + + public String getTimestamp() { + return timestamp; + } + + public void setTimestamp(String timestamp) { + this.timestamp = timestamp; + } + + public String getLastAudioUrl() { + return lastAudioUrl; + } + + public void setLastAudioUrl(String lastAudioUrl) { + this.lastAudioUrl = lastAudioUrl; + } + + public ReentrantLock getFAIR_LOCK() { + return FAIR_LOCK; + } + + public int getFirst() { + return first; + } + + public void setFirst(int first) { + this.first = first; + } } diff --git a/xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/pojo/AudioUrlAndText.java b/xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/pojo/AudioUrlAndText.java index 3a3ed38..4953fd6 100644 --- a/xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/pojo/AudioUrlAndText.java +++ b/xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/pojo/AudioUrlAndText.java @@ -1,15 +1,26 @@ package ai.qiwu.baidu.xiaodu.pojo; -import lombok.Getter; -import lombok.Setter; - /** * @author 苗权威 * @dateTime 19-6-29 下午4:32 */ -@Getter -@Setter public class AudioUrlAndText { private String audioUrl; private String text; + + public String getAudioUrl() { + return audioUrl; + } + + public void setAudioUrl(String audioUrl) { + this.audioUrl = audioUrl; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } } diff --git a/xiaodu/src/main/resources/application.properties b/xiaodu/src/main/resources/application.properties index d71ec1c..96de9db 100644 --- a/xiaodu/src/main/resources/application.properties +++ b/xiaodu/src/main/resources/application.properties @@ -1,6 +1,3 @@ -log4j.appender.D = org.apache.log4j.DailyRollingFileAppender -log4j.appender.D.File = /usr/mqw/logs/xiaodu.log -log4j.appender.D.Append = true -log4j.appender.D.Threshold = DEBUG -log4j.appender.D.layout = org.apache.log4j.PatternLayout -log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n +logging.path=/usr/mqw/logs/jdwhale +logging.level.root = info +spring.output.ansi.enabled=detect \ No newline at end of file diff --git a/xiaodu/src/main/resources/logback.xml b/xiaodu/src/main/resources/logback.xml deleted file mode 100644 index 98cf148..0000000 --- a/xiaodu/src/main/resources/logback.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - %d %p (%file:%line\)- %m%n - - UTF-8 - - - - - - - - - - - - - /usr/mqw/logs/xiaodu/ - - - /usr/mqw/logs/xiaodu/base.log.%d.%i - - 64 MB - - - - - %d %p (%file:%line\)- %m%n - - UTF-8 - - - - - - \ No newline at end of file diff --git a/xiaoya/src/main/java/ai/qiwu/xiaoya/xiaoya/controller/XiaoYaController.java b/xiaoya/src/main/java/ai/qiwu/xiaoya/xiaoya/controller/XiaoYaController.java index 8b840be..8298119 100644 --- a/xiaoya/src/main/java/ai/qiwu/xiaoya/xiaoya/controller/XiaoYaController.java +++ b/xiaoya/src/main/java/ai/qiwu/xiaoya/xiaoya/controller/XiaoYaController.java @@ -17,14 +17,13 @@ import org.springframework.web.bind.annotation.RestController; */ @RestController public class XiaoYaController { - private static Logger logger = LoggerFactory.getLogger(XiaoYaController.class); @Autowired private ParseService service; @RequestMapping("/xiaoya") public @ResponseBody Response chat(@RequestBody RequestParams params) { - logger.info(params.toString()); + //log.info(params.toString()); return service.getResponse(params); } diff --git a/xiaoya/src/main/java/ai/qiwu/xiaoya/xiaoya/service/ParseService.java b/xiaoya/src/main/java/ai/qiwu/xiaoya/xiaoya/service/ParseService.java index 9cfceb6..e76954a 100644 --- a/xiaoya/src/main/java/ai/qiwu/xiaoya/xiaoya/service/ParseService.java +++ b/xiaoya/src/main/java/ai/qiwu/xiaoya/xiaoya/service/ParseService.java @@ -12,6 +12,7 @@ import ai.qiwu.xiaoya.xiaoya.model.ResponseModel.responsePart.directive.MetaData import ai.qiwu.xiaoya.xiaoya.model.ResponseModel.responsePart.directive.Stream; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; @@ -33,10 +34,9 @@ import java.util.List; * @dateTime 19-6-25 下午1:25 */ @Service("service") +@Slf4j public class ParseService { - private static Logger logger = LoggerFactory.getLogger(ParseService.class); - public Response getResponse(RequestParams params) { Response curResponse = buildResponse(); String userId = params.getContext().getSystem().getDevice().getIp(); @@ -69,7 +69,7 @@ public class ParseService { HttpEntity responseBody = httpResponse.getEntity(); if (responseBody != null) { String responseContent = EntityUtils.toString(responseBody); - logger.info("齐悟接口返回: "+ responseContent); + log.info("齐悟接口返回: "+ responseContent); JSONObject responseJsonFormat = JSONObject.parseObject(responseContent); audioUrl = (String) responseJsonFormat.get("audio"); textContent = (String) responseJsonFormat.get("text"); diff --git a/xiaoya/src/main/resources/application.properties b/xiaoya/src/main/resources/application.properties index 1c5cff4..96de9db 100644 --- a/xiaoya/src/main/resources/application.properties +++ b/xiaoya/src/main/resources/application.properties @@ -1,6 +1,3 @@ -log4j.appender.D = org.apache.log4j.DailyRollingFileAppender -log4j.appender.D.File = /usr/mqw/logs/xiaoyas.log -log4j.appender.D.Append = true -log4j.appender.D.Threshold = DEBUG -log4j.appender.D.layout = org.apache.log4j.PatternLayout -log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n +logging.path=/usr/mqw/logs/jdwhale +logging.level.root = info +spring.output.ansi.enabled=detect \ No newline at end of file diff --git a/xiaoya/src/main/resources/logback.xml b/xiaoya/src/main/resources/logback.xml deleted file mode 100644 index cc93d5b..0000000 --- a/xiaoya/src/main/resources/logback.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - %d %p (%file:%line\)- %m%n - - UTF-8 - - - - - - - - - - - - - /usr/mqw/logs/xiaoya/ - - - /usr/mqw/logs/xiaoya/base.log.%d.%i - - 64 MB - - - - - %d %p (%file:%line\)- %m%n - - UTF-8 - - - - - - \ No newline at end of file -- libgit2 0.27.1