From d77b86bfc9e63c7c035b0fd0188429dd800c206e Mon Sep 17 00:00:00 2001 From: Hai Liang Wang Date: Sat, 4 Jan 2020 13:24:44 +0800 Subject: [PATCH] https://github.com/chatopera/cosin/issues/266 add channel info for leavemsg --- .../cc/controller/apps/IMController.java | 22 +- .../apps/service/ChatServiceController.java | 16 +- .../java/com/chatopera/cc/model/LeaveMsg.java | 28 ++- .../repository/SNSAccountRepository.java | 3 +- .../com/chatopera/cc/proxy/LeaveMsgProxy.java | 53 +++++ .../apps/service/leavemsg/index.html | 203 ++++++++++-------- .../config/sql/cosinee-MySQL-slim.sql | 6 +- .../sql/upgrade/004.add_uk_leavemsg_snsid.sql | 32 +++ .../004.unique_uk_snsaccount_snsid.sql | 6 + 9 files changed, 258 insertions(+), 111 deletions(-) create mode 100644 contact-center/app/src/main/java/com/chatopera/cc/proxy/LeaveMsgProxy.java create mode 100644 contact-center/config/sql/upgrade/004.add_uk_leavemsg_snsid.sql create mode 100644 contact-center/config/sql/upgrade/004.unique_uk_snsaccount_snsid.sql 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 600fda18..0840551e 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 @@ -1023,20 +1023,22 @@ public class IMController extends Handler { return view; } - @RequestMapping("/leavemsg/save") @Menu(type = "admin", subtype = "user") public ModelAndView leavemsgsave(HttpServletRequest request, @Valid String appid, @Valid LeaveMsg msg) { if (StringUtils.isNotBlank(appid)) { - SNSAccount snsAccount = snsAccountRepository.findBySnsid(appid); - String orgi = snsAccount.getOrgi(); - CousultInvite invite = inviteRepository.findBySnsaccountidAndOrgi(appid, orgi); - List msgList = leaveMsgRes.findByOrgiAndUserid(invite.getOrgi(), msg.getUserid()); - // if(msg!=null && msgList.size() == 0){ - if (msg != null) { - msg.setOrgi(invite.getOrgi()); - leaveMsgRes.save(msg); - } + snsAccountRepository.findBySnsid(appid).ifPresent(p -> { + CousultInvite invite = inviteRepository.findBySnsaccountidAndOrgi(appid, MainContext.SYSTEM_ORGI); + // TODO 增加策略防止恶意刷消息 + // List msgList = leaveMsgRes.findByOrgiAndUserid(invite.getOrgi(), msg.getUserid()); + // if(msg!=null && msgList.size() == 0){ + if (msg != null) { + msg.setOrgi(invite.getOrgi()); + msg.setChannel(p); + msg.setSnsId(appid); + leaveMsgRes.save(msg); + } + }); } return request(super.createRequestPageTempletResponse("/apps/im/leavemsgsave")); } diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/apps/service/ChatServiceController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/apps/service/ChatServiceController.java index a58e7ebe..0c6e4cc9 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/apps/service/ChatServiceController.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/controller/apps/service/ChatServiceController.java @@ -27,10 +27,7 @@ import com.chatopera.cc.controller.Handler; import com.chatopera.cc.model.*; import com.chatopera.cc.peer.PeerSyncIM; import com.chatopera.cc.persistence.repository.*; -import com.chatopera.cc.proxy.AgentStatusProxy; -import com.chatopera.cc.proxy.AgentUserProxy; -import com.chatopera.cc.proxy.OnlineUserProxy; -import com.chatopera.cc.proxy.UserProxy; +import com.chatopera.cc.proxy.*; import com.chatopera.cc.socketio.message.Message; import com.chatopera.cc.util.IP; import com.chatopera.cc.util.IPTools; @@ -91,6 +88,9 @@ public class ChatServiceController extends Handler { @Autowired private LeaveMsgRepository leaveMsgRes; + @Autowired + private LeaveMsgProxy leaveMsgProxy; + @Autowired private OrganRepository organRes; @@ -543,10 +543,14 @@ public class ChatServiceController extends Handler { @RequestMapping("/leavemsg/index") @Menu(type = "service", subtype = "leavemsg", admin = true) public ModelAndView leavemsg(ModelMap map, HttpServletRequest request) { - Page leaveMsgList = leaveMsgRes.findByOrgi( + Page leaveMsgs = leaveMsgRes.findByOrgi( super.getOrgi(request), new PageRequest(super.getP(request), super.getPs(request), Direction.DESC, "createtime")); - map.put("leaveMsgList", leaveMsgList); + for (final LeaveMsg l : leaveMsgs) { + leaveMsgProxy.resolveChannelBySnsid(l); + } + + map.put("leaveMsgList", leaveMsgs); return request(super.createAppsTempletResponse("/apps/service/leavemsg/index")); } diff --git a/contact-center/app/src/main/java/com/chatopera/cc/model/LeaveMsg.java b/contact-center/app/src/main/java/com/chatopera/cc/model/LeaveMsg.java index d01ec52b..09cb0e2e 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/model/LeaveMsg.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/model/LeaveMsg.java @@ -31,19 +31,19 @@ public class LeaveMsg { private String orgi ; private Date createtime = new Date() ; private String creater ; - private String name ; private String mobile ; private String address ; private String email ; private String content ; - private String msgstatus ; private String qq ; - private String userid ; - - + private String snsId; + + @Transient + private SNSAccount channel; + @Id @Column(length = 32) @GeneratedValue(generator = "system-uuid") @@ -143,4 +143,22 @@ public class LeaveMsg { public void setUserid(String userid) { this.userid = userid; } + + @Column(name = "snsid") + public String getSnsId() { + return snsId; + } + + public void setSnsId(String snsId) { + this.snsId = snsId; + } + + @Transient + public SNSAccount getChannel() { + return channel; + } + + public void setChannel(SNSAccount channel) { + this.channel = channel; + } } diff --git a/contact-center/app/src/main/java/com/chatopera/cc/persistence/repository/SNSAccountRepository.java b/contact-center/app/src/main/java/com/chatopera/cc/persistence/repository/SNSAccountRepository.java index e3dce19e..4f9a4d7a 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/persistence/repository/SNSAccountRepository.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/persistence/repository/SNSAccountRepository.java @@ -34,7 +34,8 @@ public interface SNSAccountRepository boolean existsBySnsidAndSnstypeAndOrgi(String snsid, String snsType, String orgi); - SNSAccount findBySnsid(String snsid); + @Query(value = "SELECT * FROM `uk_snsaccount` WHERE snsid = ?1 LIMIT 1", nativeQuery = true) + Optional findBySnsid(String snsid); SNSAccount findBySnsidAndOrgi(String snsid, String orgi); diff --git a/contact-center/app/src/main/java/com/chatopera/cc/proxy/LeaveMsgProxy.java b/contact-center/app/src/main/java/com/chatopera/cc/proxy/LeaveMsgProxy.java new file mode 100644 index 00000000..776349e4 --- /dev/null +++ b/contact-center/app/src/main/java/com/chatopera/cc/proxy/LeaveMsgProxy.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2019-2020 Chatopera Inc, + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.chatopera.cc.proxy; + +import com.chatopera.cc.model.LeaveMsg; +import com.chatopera.cc.model.SNSAccount; +import com.chatopera.cc.persistence.repository.SNSAccountRepository; +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class LeaveMsgProxy { + private final static Logger logger = LoggerFactory.getLogger(LeaveMsgProxy.class); + + @Autowired + private SNSAccountRepository snsAccountRes; + + /** + * 根据snsId获得渠道信息 + * + * @param leaveMsg + * @return + */ + public boolean resolveChannelBySnsid(final LeaveMsg leaveMsg) { + if (StringUtils.isNotBlank(leaveMsg.getSnsId())) { + snsAccountRes.findBySnsid(leaveMsg.getSnsId()).ifPresent(p -> leaveMsg.setChannel(p)); + } else { + leaveMsg.setChannel(new SNSAccount()); + } + + if (leaveMsg.getChannel() != null && StringUtils.isNotBlank(leaveMsg.getChannel().getName())) { + return true; + } else { + return false; + } + } +} diff --git a/contact-center/app/src/main/resources/templates/apps/service/leavemsg/index.html b/contact-center/app/src/main/resources/templates/apps/service/leavemsg/index.html index c959e234..6409e46f 100644 --- a/contact-center/app/src/main/resources/templates/apps/service/leavemsg/index.html +++ b/contact-center/app/src/main/resources/templates/apps/service/leavemsg/index.html @@ -1,98 +1,127 @@
-
- <#include "/apps/service/include/left.html"> -
+
+ <#include "/apps/service/include/left.html"> +
-
-
-
-

- 访客留言<#if leaveMsgList??>(${leaveMsgList.totalElements}) -

- - - - - - - - - - - - - - - <#if leaveMsgList?? && leaveMsgList.content??> - <#list leaveMsgList.content as leaveMsg> - - - - - - - - - - - - <#else> - - - - - -
姓名电话邮件地址QQ内容留言时间操作
-

- - ${leaveMsg.name!''} - -

-

${leaveMsg.mobile!''}

${leaveMsg.email!''}

${leaveMsg.address!''}

${leaveMsg.qq!''}

${leaveMsg.content!''}

<#if leaveMsg.createtime??>${leaveMsg.createtime?string('yyyy-MM-dd HH:mm:ss')} - - 删除 - -
-
- -
当前没有在线坐席
-
-
+
+
+
+

+ 访客留言<#if leaveMsgList??>(${leaveMsgList.totalElements}) +

+ + + + + + + + + + + + + + + + + <#if leaveMsgList?? && leaveMsgList.content??> + <#list leaveMsgList.content as leaveMsg> + + + + + + + + + + + + + + <#else> + + + + + +
渠道名称姓名电话邮件地址QQ内容留言时间操作
+

+ + <#if leaveMsg.channel.snstype=="webim"> + 网站 + <#elseif leaveMsg.channel.snstype=="phone"> + 电话 + <#elseif leaveMsg.channel.snstype=="skype"> + Skype + <#else> + 未知 + + +

+
+

${leaveMsg.channel.name!''}

+
+

${leaveMsg.name!''}

+
+

${leaveMsg.mobile!''}

+
+

${leaveMsg.email!''}

+
+

${leaveMsg.address!''}

+
+

${leaveMsg.qq!''}

+
+

${leaveMsg.content!''}

+
+ <#if leaveMsg.createtime??>${leaveMsg.createtime?string('yyyy-MM-dd HH:mm:ss')} + + + + 删除 + +
+
+ +
当前没有在线坐席
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+ \ No newline at end of file diff --git a/contact-center/config/sql/cosinee-MySQL-slim.sql b/contact-center/config/sql/cosinee-MySQL-slim.sql index 300a3b08..33dedf21 100644 --- a/contact-center/config/sql/cosinee-MySQL-slim.sql +++ b/contact-center/config/sql/cosinee-MySQL-slim.sql @@ -2356,6 +2356,7 @@ CREATE TABLE `uk_leavemsg` ( `msgstatus` varchar(20) DEFAULT NULL COMMENT '消息状态', `contactsid` varchar(32) DEFAULT NULL COMMENT '匹配联系人ID', `userid` varchar(32) DEFAULT NULL COMMENT '用户ID', + `snsid` varchar(32) DEFAULT NULL COMMENT '渠道snsid', PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=COMPACT COMMENT='留言信息表'; @@ -3483,10 +3484,11 @@ CREATE TABLE `uk_snsaccount` ( `qrcode` varchar(100) DEFAULT NULL COMMENT '二维码', `refreshtoken` varchar(255) DEFAULT NULL COMMENT '刷新token', `verify` varchar(255) DEFAULT NULL COMMENT '验证代码', - `snsid` varchar(32) DEFAULT NULL COMMENT 'SNSID', + `snsid` varchar(32) NOT NULL COMMENT 'SNSID', `agent` tinyint(4) DEFAULT NULL COMMENT '坐席', PRIMARY KEY (`ID`) USING BTREE, - UNIQUE KEY `SQL121227155530370` (`ID`) USING BTREE + UNIQUE KEY `SQL121227155530370` (`ID`) USING BTREE, + UNIQUE KEY (`snsid`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=COMPACT COMMENT='渠道配置表'; -- ---------------------------- diff --git a/contact-center/config/sql/upgrade/004.add_uk_leavemsg_snsid.sql b/contact-center/config/sql/upgrade/004.add_uk_leavemsg_snsid.sql new file mode 100644 index 00000000..bb95861e --- /dev/null +++ b/contact-center/config/sql/upgrade/004.add_uk_leavemsg_snsid.sql @@ -0,0 +1,32 @@ +USE `cosinee`; +-- ----------------- +-- prepare variables +-- ----------------- + +SET @dbname = DATABASE ( ); +SET @tablename = "uk_leavemsg"; +SET @columnname = "snsid"; + +SET @preparedStatement = ( + SELECT + IF + ( + ( + SELECT + COUNT( * ) + FROM + INFORMATION_SCHEMA.COLUMNS + WHERE + ( table_name = @tablename ) + AND ( table_schema = @dbname ) + AND ( column_name = @columnname ) + ) > 0, + "SELECT 1", + CONCAT( "ALTER TABLE ", @tablename, " ADD ", @columnname, " varchar(32) DEFAULT NULL COMMENT '渠道snsid';" ) + ) +); +PREPARE alterIfNotExists +FROM + @preparedStatement; +EXECUTE alterIfNotExists; +DEALLOCATE PREPARE alterIfNotExists; \ No newline at end of file diff --git a/contact-center/config/sql/upgrade/004.unique_uk_snsaccount_snsid.sql b/contact-center/config/sql/upgrade/004.unique_uk_snsaccount_snsid.sql new file mode 100644 index 00000000..ed332bcb --- /dev/null +++ b/contact-center/config/sql/upgrade/004.unique_uk_snsaccount_snsid.sql @@ -0,0 +1,6 @@ +USE `cosinee`; +-- ----------------- +-- set snsid as unique +-- ----------------- + +ALTER TABLE `uk_snsaccount` ADD UNIQUE (`snsid`); \ No newline at end of file