From 6abacc646ec446060d9b6d5475bdb09abe9f17fa Mon Sep 17 00:00:00 2001 From: Hai Liang Wang Date: Thu, 12 Dec 2019 14:40:29 +0800 Subject: [PATCH] enhance tag api, fix chatbot agent transfer bug, fix chatbot tab, etc. --- .../cc/controller/apps/IMController.java | 38 ++++++++++++++----- .../persistence/impl/TagDataExchangeImpl.java | 32 ++++++++++++++++ .../impl/UserDataExchangeImpl.java | 30 +++++++-------- .../resources/templates/apps/entim/chat.html | 4 ++ .../resources/templates/apps/im/index.html | 2 +- .../config/sql/cosinee-MySQL-slim.sql | 1 + .../chatbot/classes/ChatbotEventHandler.java | 2 +- 7 files changed, 82 insertions(+), 27 deletions(-) create mode 100644 contact-center/app/src/main/java/com/chatopera/cc/persistence/impl/TagDataExchangeImpl.java diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/apps/IMController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/apps/IMController.java index 3a277fe5..e56b6eff 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/apps/IMController.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/controller/apps/IMController.java @@ -831,40 +831,58 @@ public class IMController extends Handler { } map.addAttribute("username", nickname); + boolean isChatbotAgentFirst = false; + boolean isEnableExchangeAgentType = false; + Chatbot bot = null; // 是否使用机器人客服 - Chatbot bot = null; - if (MainContext.hasModule(Constants.CSKEFU_MODULE_CHATBOT) && - StringUtils.isNotBlank(invite.getAiid()) && - invite.isAi() && - ((bot = chatbotRes.findOne(invite.getAiid())) != null) && - ((StringUtils.equals( - ai, "true")) || (invite.isAifirst() && ai == null))) { //启用 AI , 并且 AI优先 接待 + if (invite.isAi() && MainContext.hasModule(Constants.CSKEFU_MODULE_CHATBOT)) { + // 查找机器人 + bot = chatbotRes.findOne(invite.getAiid()); + if (bot != null) { + // 判断是否接受访客切换坐席类型 + isEnableExchangeAgentType = !StringUtils.equals( + bot.getWorkmode(), Constants.CHATBOT_CHATBOT_ONLY); + // 判断是否机器人客服优先 + if (((StringUtils.equals( + ai, "true")) || (invite.isAifirst() && ai == null))) { + isChatbotAgentFirst = true; + } + } + } + + map.addAttribute( + "exchange", isEnableExchangeAgentType); + + if (isChatbotAgentFirst) { + // 机器人坐席 HashMap chatbotConfig = new HashMap(); chatbotConfig.put("botname", invite.getAiname()); chatbotConfig.put("botid", invite.getAiid()); chatbotConfig.put("botwelcome", invite.getAimsg()); chatbotConfig.put("botfirst", Boolean.toString(invite.isAifirst())); chatbotConfig.put("isai", Boolean.toString(invite.isAi())); - map.addAttribute( - "exchange", !StringUtils.equals(bot.getWorkmode(), Constants.CHATBOT_CHATBOT_ONLY)); + if (chatbotConfig != null) { map.addAttribute("chatbotConfig", chatbotConfig); } view = request(super.createRequestPageTempletResponse("/apps/im/chatbot/index")); - if (MobileDevice.isMobile(request.getHeader("User-Agent")) || StringUtils.isNotBlank(mobile)) { + if (MobileDevice.isMobile(request.getHeader("User-Agent")) || StringUtils.isNotBlank( + mobile)) { view = request(super.createRequestPageTempletResponse( "/apps/im/chatbot/mobile")); // 智能机器人 移动端 } } else { + // 维持人工坐席的设定,检查是否进入留言 if (!isLeavemsg && (MobileDevice.isMobile( request.getHeader("User-Agent")) || StringUtils.isNotBlank(mobile))) { view = request( super.createRequestPageTempletResponse("/apps/im/mobile")); // WebIM移动端。再次点选技能组? } } + map.addAttribute( "chatMessageList", chatMessageRes.findByUsessionAndOrgi(userid, orgi, new PageRequest(0, 20, Direction.DESC, diff --git a/contact-center/app/src/main/java/com/chatopera/cc/persistence/impl/TagDataExchangeImpl.java b/contact-center/app/src/main/java/com/chatopera/cc/persistence/impl/TagDataExchangeImpl.java new file mode 100644 index 00000000..f6ef9676 --- /dev/null +++ b/contact-center/app/src/main/java/com/chatopera/cc/persistence/impl/TagDataExchangeImpl.java @@ -0,0 +1,32 @@ +package com.chatopera.cc.persistence.impl; + +import com.chatopera.cc.model.Tag; +import com.chatopera.cc.model.User; +import com.chatopera.cc.persistence.interfaces.DataExchangeInterface; +import com.chatopera.cc.persistence.repository.TagRepository; +import com.chatopera.cc.persistence.repository.UserRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.io.Serializable; +import java.util.List; + +@Service("tagdata") +public class TagDataExchangeImpl implements DataExchangeInterface { + @Autowired + private TagRepository tagRes; + + public String getDataByIdAndOrgi(String id, String orgi) { + Tag tag = tagRes.findByOrgiAndId(orgi, id); + return tag != null ? tag.getTag() : id; + } + + @Override + public List getListDataByIdAndOrgi(String id, String creater, String orgi) { + return null; + } + + public void process(Object data, String orgi) { + + } +} diff --git a/contact-center/app/src/main/java/com/chatopera/cc/persistence/impl/UserDataExchangeImpl.java b/contact-center/app/src/main/java/com/chatopera/cc/persistence/impl/UserDataExchangeImpl.java index 7fb235b8..f960eb9c 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/persistence/impl/UserDataExchangeImpl.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/persistence/impl/UserDataExchangeImpl.java @@ -27,20 +27,20 @@ import java.util.List; @Service("userdata") public class UserDataExchangeImpl implements DataExchangeInterface { - @Autowired - private UserRepository userRes ; - - public String getDataByIdAndOrgi(String id, String orgi){ - User user = userRes.findById(id); - return user!=null ? user.getUsername() : id; - } + @Autowired + private UserRepository userRes; - @Override - public List getListDataByIdAndOrgi(String id , String creater, String orgi) { - return null ; - } - - public void process(Object data , String orgi) { - - } + public String getDataByIdAndOrgi(String id, String orgi) { + User user = userRes.findById(id); + return user != null ? user.getUsername() : id; + } + + @Override + public List getListDataByIdAndOrgi(String id, String creater, String orgi) { + return null; + } + + public void process(Object data, String orgi) { + + } } diff --git a/contact-center/app/src/main/resources/templates/apps/entim/chat.html b/contact-center/app/src/main/resources/templates/apps/entim/chat.html index 799f22f3..51905f41 100644 --- a/contact-center/app/src/main/resources/templates/apps/entim/chat.html +++ b/contact-center/app/src/main/resources/templates/apps/entim/chat.html @@ -242,6 +242,10 @@ var hostname = location.hostname ; var socket = io.connect(location.protocol+"//"+top.hostname+":"+top.port+"/im/ent?userid=${user.id!''!''}&orgi=${user.orgi!''}&contextid=${contextid!''}",{transports: ['websocket'], upgrade: false}); socket.on('message', function(data) { + if(data.contextid != "${entimuser.id!''}"){ + return; + } + console.log('message', data); data.createtime = formatDate(data.createtime); var chat=document.getElementsByClassName('chatting-left').innerText; diff --git a/contact-center/app/src/main/resources/templates/apps/im/index.html b/contact-center/app/src/main/resources/templates/apps/im/index.html index 6e1be90d..e600d0c7 100644 --- a/contact-center/app/src/main/resources/templates/apps/im/index.html +++ b/contact-center/app/src/main/resources/templates/apps/im/index.html @@ -362,7 +362,7 @@
    <#if models?seq_contains("chatbot") && inviteData.ai && aiid??> - <#if !exchange?? || exchange == "true"> + <#if exchange == "true">
  • 智能客服
  • 人工坐席
  • diff --git a/contact-center/config/sql/cosinee-MySQL-slim.sql b/contact-center/config/sql/cosinee-MySQL-slim.sql index e383c7a2..2ffcc25e 100644 --- a/contact-center/config/sql/cosinee-MySQL-slim.sql +++ b/contact-center/config/sql/cosinee-MySQL-slim.sql @@ -7710,6 +7710,7 @@ INSERT INTO `uk_sysdic` VALUES ('ff8080816de316aa016de31d0e130016', '企业聊 INSERT INTO `uk_sysdic` VALUES ('ff8080816de316aa016de3201ffb001c', '创建群组', 'pub', 'A14_A01', 'cskefu', 'layui-icon', 'ff8080816de316aa016de31d0e130016', '', NULL, '', '', NULL, '4028cac3614cd2f901614cf8be1f0324', '2019-10-19 16:26:36', NULL, 1, 0, '402888815d2fe37f015d2fe75cc80002', 0, 0, NULL, NULL, NULL, NULL, NULL); INSERT INTO `uk_sysdic` VALUES ('4028c1236170e237016170e4d95a03c6', '类似问题', 'pub', 'topicmore', 'cskefu', 'layui-icon', '402888815e097729015e0999f26e0002', '', NULL, '', '', NULL, '4028cac3614cd2f901614cf8be1f0324', '2018-02-07 23:31:41', NULL, 1, 0, '402888815e097729015e0999f26e0002', 0, 0, NULL, NULL, NULL, NULL, NULL); INSERT INTO `uk_sysdic` VALUES ('4028c1236173b85b016173bde0fd0333', '用户接口', 'pub', 'userdata', 'cskefu', 'layui-icon', '402888815e097729015e0999f26e0002', '', NULL, '', '', NULL, '4028cac3614cd2f901614cf8be1f0324', '2018-02-08 12:47:59', NULL, 1, 0, '402888815e097729015e0999f26e0002', 0, 0, NULL, NULL, NULL, NULL, NULL); +INSERT INTO `uk_sysdic` VALUES ('4028826a6eeed0f3016eeed9eee7001c', '标签接口', 'pub', 'tagdata', 'cskefu', 'layui-icon', '402888815e097729015e0999f26e0002', '', NULL, '', '', NULL, '4028cac3614cd2f901614cf8be1f0324', '2019-12-10 16:08:10', NULL, 1, 0, '402888815e097729015e0999f26e0002', 0, 0, NULL, NULL, NULL, NULL, NULL); INSERT INTO `uk_sysdic` VALUES ('4028c1236173b85b016173be114e0335', '部门接口', 'pub', 'organdata', 'cskefu', 'layui-icon', '402888815e097729015e0999f26e0002', '', NULL, '', '', NULL, '4028cac3614cd2f901614cf8be1f0324', '2018-02-08 12:48:11', NULL, 1, 0, '402888815e097729015e0999f26e0002', 0, 0, NULL, NULL, NULL, NULL, NULL); INSERT INTO `uk_sysdic` VALUES ('4028cba3613c9d2d01613cb0dbf8062d', '全部联系人', 'pub', 'A02_A01_A02_B01', NULL, 'auth', '402881ef612b1f5b01612cc87273054a', NULL, NULL, '', NULL, NULL, '297e8c7b455798280145579c73e501c1', '2018-01-28 20:14:39', NULL, 0, 0, '402888815d2fe37f015d2fe75cc80002', 0, 0, 'javascript:;', 'webim', '4', NULL, 'top'); INSERT INTO `uk_sysdic` VALUES ('4028cba3613c9d2d01613cb15cce062e', '今日新增', 'pub', 'A02_A01_A02_B02', NULL, 'auth', '402881ef612b1f5b01612cc87273054a', NULL, NULL, '', NULL, NULL, '297e8c7b455798280145579c73e501c1', '2018-01-28 20:15:12', NULL, 0, 0, '402888815d2fe37f015d2fe75cc80002', 0, 0, 'javascript:;', 'webim', '4', NULL, 'top'); diff --git a/public/plugins/chatbot/classes/ChatbotEventHandler.java b/public/plugins/chatbot/classes/ChatbotEventHandler.java index 93a37c67..ad3b8cb4 100644 --- a/public/plugins/chatbot/classes/ChatbotEventHandler.java +++ b/public/plugins/chatbot/classes/ChatbotEventHandler.java @@ -241,7 +241,7 @@ public class ChatbotEventHandler { MainContext.getCache().deleteAgentUserByUserIdAndOrgi(p, orgi); MainContext.getCache().deleteOnlineUserByIdAndOrgi(user, orgi); - p.setStatus(MainContext.OnlineUserStatusEnum.OFFLINE.toString()); + p.setStatus(MainContext.AgentUserStatusEnum.END.toString()); onlineUser.setStatus(MainContext.OnlineUserStatusEnum.OFFLINE.toString()); getAgentUserRes().save(p);