diff --git a/.gitignore b/.gitignore index 11b7236c..8c077982 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,5 @@ backups/ .env build.gradle .vscode/ +nohup.out private diff --git a/LICENSE b/LICENSE index 982420b0..a8a29d25 100644 --- a/LICENSE +++ b/LICENSE @@ -1,13 +1,6 @@ -Copyright 2018-2020 Chatopera Inc. . All rights reserved. +Copyright (2018-2020) Chatopera Inc. . All rights reserved. This software and related documentation are provided under a license agreement containing restrictions on use and disclosure and are protected by intellectual property laws. - -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 - Except as expressly permitted in your license agreement or allowed by law, you may not use, copy, reproduce, translate, broadcast, modify, license, transmit, distribute, exhibit, perform, publish, or display any part, in any form, or by any means. Reverse engineering, disassembly, diff --git a/README.md b/README.md index 0c90a954..f69fc380 100644 --- a/README.md +++ b/README.md @@ -122,9 +122,9 @@ The collaboration is efficient, very professional. The software is steady with h 寻找开发者合作智能客服项目,社区共建,携手共赢! -* 组织或个人,在春松客服主页展示为认证开发者 -* 春松客服官方推荐项目机会 -* 专访并通过官方渠道曝光 +- 组织或个人,在春松客服主页展示为认证开发者 +- 春松客服官方推荐项目机会 +- 专访并通过官方渠道曝光 填写申请:[https://www.wjx.top/jq/93397428.aspx](https://www.wjx.top/jq/93397428.aspx) @@ -135,8 +135,6 @@ The collaboration is efficient, very professional. The software is steady with h

- -
展开查看更多产品截图

@@ -185,7 +183,6 @@ The collaboration is efficient, very professional. The software is steady with h 参考部署[开源社区版本文档](https://docs.chatopera.com/products/cskefu/deploy.html)。 - ## 鸣谢 [FreeSWITCH 中国社区](http://www.freeswitch.org.cn/) @@ -201,8 +198,6 @@ Copyright (2018-2020) 北 [co-banner-image]: https://static-public.chatopera.com/assets/images/42383104-da925942-8168-11e8-8195-868d5fcec170.png [co-url]: https://www.chatopera.com - - ## Chatopera 云服务 [https://bot.chatopera.com/](https://bot.chatopera.com/) @@ -263,7 +258,6 @@ Chatopera 机器人平台包括知识库、多轮对话、意图识别和语音

-

立即使用
diff --git a/contact-center/.dockerignore b/contact-center/.dockerignore index b669156a..58f6b874 100644 --- a/contact-center/.dockerignore +++ b/contact-center/.dockerignore @@ -1,6 +1,8 @@ app/target !app/target/*.war.original !app/target/*.war +!app/target/*.jar.original +!app/target/*.jar logs/ tmp/ data/ diff --git a/contact-center/Dockerfile b/contact-center/Dockerfile index fe4493d0..2094f8ae 100644 --- a/contact-center/Dockerfile +++ b/contact-center/Dockerfile @@ -38,7 +38,7 @@ RUN /bin/bash -c "mkdir -p /{data,logs}" # build WAR RUN mkdir -p /opt/chatopera -COPY ./app/target/contact-center-*.war /opt/chatopera/contact-center.war +COPY ./app/target/contact-center.war /opt/chatopera/contact-center.war COPY ./assets/mysql.setup.db.sh /opt/chatopera COPY ./assets/mysql.upgrade.db.sh /opt/chatopera COPY ./assets/utils.sh /opt/chatopera diff --git a/contact-center/admin/build.sh b/contact-center/admin/build.sh index c3c14f15..7677df04 100755 --- a/contact-center/admin/build.sh +++ b/contact-center/admin/build.sh @@ -29,4 +29,11 @@ docker build --build-arg VCS_REF=$PACKAGE_VERSION \ --build-arg APPLICATION_BUILD_DATESTR=$TIMESTAMP \ --build-arg APPLICATION_CUSTOMER_ENTITY=$APPLICATION_CUSTOMER_ENTITY \ --no-cache \ - --force-rm=true --tag $registryName/$imagename:$PACKAGE_VERSION . \ No newline at end of file + --force-rm=true --tag $registryName/$imagename:$PACKAGE_VERSION . + +if [ $? -eq 0 ]; then + docker tag $registryName/$imagename:$PACKAGE_VERSION $registryName/$imagename:develop +else + echo "Build contact-center failure." + exit 1 +fi \ No newline at end of file diff --git a/contact-center/admin/deploy.sh b/contact-center/admin/deploy.sh new file mode 100755 index 00000000..80709fac --- /dev/null +++ b/contact-center/admin/deploy.sh @@ -0,0 +1,50 @@ +#! /bin/bash +########################################### +# +########################################### + +# constants +baseDir=$(cd `dirname "$0"`;pwd) +REPO_ID_SNP=chatopera-snapshots +REPO_URL_SNP=https://nexus.chatopera.com/repository/maven-snapshots/ +REPO_ID_REL=chatopera-releases +REPO_URL_REL=https://nexus.chatopera.com/repository/maven-releases/ + +# functions + +# main +[ -z "${BASH_SOURCE[0]}" -o "${BASH_SOURCE[0]}" = "$0" ] || return +cd $baseDir/../app +mvn clean jar:jar +PACKAGE_VERSION=$(grep --max-count=1 '' pom.xml | awk -F '>' '{ print $2 }' | awk -F '<' '{ print $1 }') +if [[ $PACKAGE_VERSION == *SNAPSHOT ]]; then + echo "Deploy as snapshot package ..." + mvn deploy:deploy-file \ + -Dmaven.test.skip=true \ + -Dfile=./target/contact-center.jar \ + -DgroupId=com.chatopera.cc \ + -DartifactId=cc-core \ + -Dversion=$PACKAGE_VERSION \ + -Dpackaging=jar \ + -DgeneratePom=true \ + -DrepositoryId=$REPO_ID_SNP \ + -Durl=$REPO_URL_SNP + if [ ! $? -eq 0 ]; then + exit 1 + fi +else + echo "Deploy as release package ..." + mvn deploy:deploy-file \ + -Dmaven.test.skip=true \ + -Dfile=./target/contact-center.jar \ + -DgroupId=com.chatopera.cc \ + -DartifactId=cc-core \ + -Dversion=$PACKAGE_VERSION \ + -Dpackaging=jar \ + -DgeneratePom=true \ + -DrepositoryId=$REPO_ID_REL \ + -Durl=$REPO_URL_REL + if [ ! $? -eq 0 ]; then + exit 1 + fi +fi diff --git a/contact-center/admin/dev.sh b/contact-center/admin/dev.sh deleted file mode 100755 index 3276f289..00000000 --- a/contact-center/admin/dev.sh +++ /dev/null @@ -1,30 +0,0 @@ -#! /bin/bash -########################################### -# -########################################### - -# constants -baseDir=$(cd `dirname "$0"`;pwd) - -if [ -f $baseDir/localrc ]; then - echo "Load localrc for environment variables ..." - set -x - source $baseDir/localrc -else - echo $baseDir/localrc "not exist." - echo "First, copy and modify the rc template." - echo "cp " $baseDir/localrc.sample $baseDir/localrc - exit 1 -fi - - -# functions -function start(){ - cd $baseDir/../app - mvn spring-boot:run -} - - -# main -[ -z "${BASH_SOURCE[0]}" -o "${BASH_SOURCE[0]}" = "$0" ] || return -start diff --git a/contact-center/admin/install-plugins.sh b/contact-center/admin/install-plugins.sh new file mode 100755 index 00000000..16f867d0 --- /dev/null +++ b/contact-center/admin/install-plugins.sh @@ -0,0 +1,47 @@ +#! /bin/bash +########################################### +# +########################################### + +# constants +baseDir=$(cd `dirname "$0"`;pwd) +SCRIPT_PATH=$0 +ts=`date +"%Y-%m-%d_%H-%M-%S"` +buildDir=/tmp/cc-build-$ts +# functions +function print_usage(){ + echo "Install contact-center plugin: $SCRIPT_PATH contact-center_jar_path plugin_path output_path" +} + +# main +[ -z "${BASH_SOURCE[0]}" -o "${BASH_SOURCE[0]}" = "$0" ] || return +if [ "$#" -ne 4 ]; then + CONTACT_CENTER=$1 + CC_PLUGIN=$2 + OUTPUT_PATH=$3 + if [ ! -f $1 ]; then + echo "contact center jar file not exist." + print_usage + exit 1 + fi + + if [ ! -f $2 ]; then + echo "cc plugin jar file not exist." + print_usage + exit 2 + fi + + # create jar + rm -rf $buildDir + mkdir $buildDir + unzip $CONTACT_CENTER -d $buildDir + cp $CC_PLUGIN $buildDir/BOOT-INF/lib + cd $buildDir + jar -cvfM0 $3 . + echo "Created new jar file as" $OUTPUT_PATH "successfully." + echo "Build done, delete buildDir" $buildDir "in 3 seconds ..." + sleep 3 + rm -rf $buildDir +else + print_usage +fi diff --git a/contact-center/admin/localrc.sample b/contact-center/admin/localrc.sample deleted file mode 100644 index d6af77f7..00000000 --- a/contact-center/admin/localrc.sample +++ /dev/null @@ -1,19 +0,0 @@ -export SERVER_PORT=8035 -export SERVER_LOG_PATH=$baseDir/../logs -# Log Level: INFO, DEBUG, ERROR, STDOUT -export SERVER_LOG_LEVEL=INFO -export WEB_UPLOAD_PATH=$baseDir/../data -export SPRING_FREEMARKER_CACHE=false -export SPRING_DATA_ELASTICSEARCH_PROPERTIES_PATH_DATA=$baseDir/../data -export UK_IM_SERVER_PORT=8036 -export UK_IM_SERVER_HOST=localhost -export UK_IM_SERVER_THREADS=10 -export SPRING_DATASOURCE_TYPE=com.alibaba.druid.pool.DruidDataSource -export SPRING_DATASOURCE_DRIVER_CLASS_NAME=com.mysql.jdbc.Driver -export SPRING_DATASOURCE_URL=jdbc:mysql://localhost:8889/ukefu-test?useUnicode=true&characterEncoding=UTF-8 -export SPRING_DATASOURCE_USERNAME=root -export SPRING_DATASOURCE_PASSWORD=root -export MANAGEMENT_SECURITY_ENABLED=false -export SPRING_REDIS_DATABASE=2 -export SPRING_REDIS_HOST=redis -export SPRING_REDIS_PORT=6379 diff --git a/contact-center/admin/package.sh b/contact-center/admin/package.sh index 288dafad..4cf5cfbe 100755 --- a/contact-center/admin/package.sh +++ b/contact-center/admin/package.sh @@ -10,7 +10,9 @@ baseDir=$(cd `dirname "$0"`;pwd) # main [ -z "${BASH_SOURCE[0]}" -o "${BASH_SOURCE[0]}" = "$0" ] || return cd $baseDir/../app -mvn clean package +mvn -DskipTests clean package +# take too long time with dev002 for uploading artifact, skip this operation +# $baseDir/deploy.app.sh if [ ! $? -eq 0 ]; then exit 1 diff --git a/contact-center/admin/push.sh b/contact-center/admin/push.sh index 269bfd36..94844209 100755 --- a/contact-center/admin/push.sh +++ b/contact-center/admin/push.sh @@ -5,12 +5,17 @@ # constants baseDir=$(cd `dirname "$0"`;pwd) +appHome=$baseDir/.. registryName=dockerhub.qingcloud.com imagename=chatopera/contact-center -PACKAGE_VERSION=w4l # functions # main [ -z "${BASH_SOURCE[0]}" -o "${BASH_SOURCE[0]}" = "$0" ] || return -docker push $registryName/$imagename:$PACKAGE_VERSION \ No newline at end of file +# build +cd $appHome +PACKAGE_VERSION=`git rev-parse --short HEAD` + +docker push $registryName/$imagename:$PACKAGE_VERSION +docker push $registryName/$imagename:develop \ No newline at end of file diff --git a/contact-center/admin/gen-eclipse.sh b/contact-center/admin/root.sh similarity index 85% rename from contact-center/admin/gen-eclipse.sh rename to contact-center/admin/root.sh index 819fcd07..ef281848 100755 --- a/contact-center/admin/gen-eclipse.sh +++ b/contact-center/admin/root.sh @@ -9,5 +9,5 @@ baseDir=$(cd `dirname "$0"`;pwd) # main [ -z "${BASH_SOURCE[0]}" -o "${BASH_SOURCE[0]}" = "$0" ] || return -cd $baseDir/../app -mvn eclipse:eclipse +cd $baseDir/../root +mvn deploy diff --git a/contact-center/admin/uninstall.sh b/contact-center/admin/uninstall.sh new file mode 100755 index 00000000..cb2e7ccd --- /dev/null +++ b/contact-center/admin/uninstall.sh @@ -0,0 +1,12 @@ +#! /bin/bash +########################################### +# +########################################### + +# constants +baseDir=$(cd `dirname "$0"`;pwd) +# functions + +# main +[ -z "${BASH_SOURCE[0]}" -o "${BASH_SOURCE[0]}" = "$0" ] || return +rm -rf ~/.m2/repository/com/chatopera/cc diff --git a/contact-center/app/.gitignore b/contact-center/app/.gitignore index d85c7295..c673875b 100644 --- a/contact-center/app/.gitignore +++ b/contact-center/app/.gitignore @@ -1,9 +1,6 @@ # dev profile src/main/resources/application-dev.properties -# ignore plugins source code -src/main/java/com/chatopera/cc/plugins/ - # ignore channel views within plugins src/main/resources/templates/admin/channel/* !src/main/resources/templates/admin/channel/im @@ -11,3 +8,5 @@ src/main/resources/templates/admin/channel/* # ignore app views within plugins src/main/resources/templates/apps/callout src/main/resources/templates/apps/chatbot +src/main/resources/templates/apps/callcenter +logs/ diff --git a/contact-center/app/pom.xml b/contact-center/app/pom.xml index 02ff7672..5d48d555 100644 --- a/contact-center/app/pom.xml +++ b/contact-center/app/pom.xml @@ -3,382 +3,31 @@ 4.0.0 com.chatopera.cc contact-center - 5.1.0 war - cskefu + cc-core 春松客服:多渠道智能客服系统 - org.springframework.boot - spring-boot-starter-parent - 1.5.10.RELEASE + com.chatopera.cc + cc-root + 6.0.0-SNAPSHOT + + - - UTF-8 - 1.8 - - - - org.springframework.boot - spring-boot-starter - - - org.springframework.boot - spring-boot-starter-test - test - - - - org.springframework.boot - spring-boot-starter-web - - - - org.apache.activemq - activemq-pool - 5.14.3 - - - - org.springframework.boot - spring-boot-starter-activemq - - - - org.springframework.boot - spring-boot-starter-freemarker - - - org.springframework.boot - spring-boot-starter-tomcat - provided - - - org.freemarker - freemarker - 2.3.29 - - - mysql - mysql-connector-java - 5.1.21 - - - net.java.dev.jna - jna - 4.1.0 - - - javax.activation - activation - 1.1.1 - - - javax.mail - javax.mail-api - 1.5.1 - - - com.sun.mail - javax.mail - 1.6.0 - - - org.springframework.boot - spring-boot-starter-cache - - - org.springframework.session - spring-session-data-redis - - - org.springframework.boot - spring-boot-starter-data-jpa - - - org.springframework.boot - spring-boot-starter-security - - - org.springframework.boot - spring-boot-starter-aop - - - org.springframework.boot - spring-boot-starter-data-elasticsearch - - - org.springframework.data - spring-data-elasticsearch - - - org.springframework.boot - spring-boot-starter-data-redis - 1.5.13.RELEASE - - - org.jasypt - jasypt - 1.9.2 - - - org - jaudiotagger - 2.0.1 - - - lt.jave - jave - 1.0.2 - - - commons-codec - commons-codec - 1.10 - - - commons-lang - commons-lang - 2.6 - - - org.springframework.boot - spring-boot-starter-thymeleaf - - - org.springframework.boot - spring-boot-starter-actuator - - - - - org.springframework.boot - spring-boot-starter-hateoas - - - - - io.micrometer - micrometer-registry-prometheus - 1.1.1 - - - io.micrometer - micrometer-spring-legacy - 1.1.1 - - - commons-beanutils - commons-beanutils - 1.8.0 - - - com.corundumstudio.socketio - netty-socketio - 1.7.12 - - - commons-io - commons-io - 2.4 - - - org.springframework - spring-context-support - - - org.quartz-scheduler - quartz - 2.3.0 - - - com.fasterxml.jackson.dataformat - jackson-dataformat-xml - - - - - org.aspectj - aspectjrt - 1.9.4 - - - org.aspectj - aspectjweaver - 1.9.4 - - - - - com.alibaba - druid - 1.0.27 - - - org.lionsoul - ip2region - 1.7.2 - - - com.lmax - disruptor - 3.3.6 - - - org.apache.poi - poi - 3.15 - - - org.apache.poi - poi-ooxml - 3.15 - - - com.alibaba - fastjson - 1.2.47 - - - com.github.binarywang - weixin-java-mp - 2.6.0 - - - - com.google.code.gson - gson - 2.8.1 - - - - org.jsoup - jsoup - 1.10.2 - - - - commons-dbutils - commons-dbutils - 1.6 - - - - joda-time - joda-time - 2.9.9 - - - - de.odysseus.juel - juel-impl - 2.2.7 - - - - com.fasterxml.jackson.core - jackson-core - 2.8.8 - - - - cglib - cglib - 3.2.5 - - - commons-dbcp - commons-dbcp - 1.3 - provided - - - com.oracle - ojdbc6 - 12.1.0.1-atlassian-hosted - - - com.belerweb - pinyin4j - 2.5.0 - - - commons-collections - commons-collections - 3.2.2 - - - org.olap4j - olap4j - 1.2.0 - - - mondrian - mondrian - 3.7.0 - - - - io.minio - minio - 5.0.0 - - - - com.googlecode.aviator - aviator - 3.3.0 - - - - com.aliyun - aliyun-java-sdk-core - 3.3.1 - - - com.aliyun - aliyun-java-sdk-dysmsapi - 1.0.0 - - - org.apache.httpcomponents - httpclient - 4.3.6 - - - org.apache.httpcomponents - httpasyncclient - 4.0.2 - - - org.apache.httpcomponents - httpmime - 4.3.6 - - - org.json - json - 20140107 - - - com.mashape.unirest - unirest-java - 1.4.9 - - - com.chatopera.compose4j - compose4j - 1.0.0 - - - com.chatopera.bot - sdk - 3.1.0 - - - + contact-center + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + org.apache.maven.plugins maven-resources-plugin @@ -436,7 +85,6 @@ - maven-compiler-plugin @@ -463,7 +111,6 @@ 2.1.1 - compile @@ -471,7 +118,7 @@ chatopera Chatopera Inc. - https://nexus.chatopera.com/repository/maven-public + https://nexus.chatopera.com/repository/maven-public/ true diff --git a/contact-center/app/src/main/java/com/chatopera/cc/Application.java b/contact-center/app/src/main/java/com/chatopera/cc/Application.java index a19994dc..cb950880 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/Application.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/Application.java @@ -22,6 +22,8 @@ import com.chatopera.cc.basic.plugins.PluginRegistry; import com.chatopera.cc.config.AppCtxRefreshEventListener; import com.chatopera.cc.util.SystemEnvHelper; import com.chatopera.cc.util.mobile.MobileNumberUtils; +import org.apache.commons.lang.StringEscapeUtils; +import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; @@ -36,8 +38,6 @@ import org.springframework.boot.web.servlet.MultipartConfigFactory; import org.springframework.context.annotation.Bean; import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; -import org.springframework.jms.annotation.EnableJms; -import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.transaction.annotation.EnableTransactionManagement; import javax.servlet.MultipartConfigElement; @@ -65,41 +65,46 @@ public class Application { */ static { // CRM模块 - MainContext.enableModule(Constants.CSKEFU_MODULE_CONTACTS); + if (StringUtils.equalsIgnoreCase(SystemEnvHelper.parseFromApplicationProps("cskefu.modules.contacts"), "true")) { + MainContext.enableModule(Constants.CSKEFU_MODULE_CONTACTS); + } // 会话监控模块 Customer Chats Audit - MainContext.enableModule(Constants.CSKEFU_MODULE_CCA); + if (StringUtils.equalsIgnoreCase(SystemEnvHelper.parseFromApplicationProps("cskefu.modules.cca"), "true")) { + MainContext.enableModule(Constants.CSKEFU_MODULE_CCA); + } // 企业聊天模块 - MainContext.enableModule(Constants.CSKEFU_MODULE_ENTIM); - - /** - * 插件组 - */ - // 外呼模块 - if (SystemEnvHelper.isClassExistByFullName( - PluginRegistry.PLUGIN_ENTRY_CALLOUT)) { - MainContext.enableModule(Constants.CSKEFU_MODULE_CALLOUT); + if (StringUtils.equalsIgnoreCase(SystemEnvHelper.parseFromApplicationProps("cskefu.modules.entim"), "true")) { + MainContext.enableModule(Constants.CSKEFU_MODULE_ENTIM); } - // skype模块 - if (SystemEnvHelper.isClassExistByFullName( - PluginRegistry.PLUGIN_ENTRY_SKYPE)) { - MainContext.enableModule(Constants.CSKEFU_MODULE_SKYPE); + // 数据报表 + if (StringUtils.equalsIgnoreCase(SystemEnvHelper.parseFromApplicationProps("cskefu.modules.report"), "true")) { + MainContext.enableModule(Constants.CSKEFU_MODULE_REPORT); } - // 聊天机器人模块 - if (SystemEnvHelper.isClassExistByFullName(PluginRegistry.PLUGIN_ENTRY_CHATBOT)) { - MainContext.enableModule(Constants.CSKEFU_MODULE_CHATBOT); - } + } /** * Init local resources */ - protected static void init() { + protected static void serve(final String[] args) { try { MobileNumberUtils.init(); + /************************ + * 该APP中加载多个配置文件 + * http://roufid.com/load-multiple-configuration-files-different-directories-spring-boot/ + ************************/ + SpringApplication app = new SpringApplicationBuilder(Application.class) + .properties("spring.config.name:application,git") + .build(); + + app.setBannerMode(Banner.Mode.CONSOLE); + app.setAddCommandLineProperties(false); + app.addListeners(new AppCtxRefreshEventListener()); + MainContext.setApplicationContext(app.run(args)); } catch (IOException e) { logger.error("Application Startup Error", e); System.exit(1); @@ -127,19 +132,6 @@ public class Application { } public static void main(String[] args) { - Application.init(); - - /************************ - * 该APP中加载多个配置文件 - * http://roufid.com/load-multiple-configuration-files-different-directories-spring-boot/ - ************************/ - SpringApplication app = new SpringApplicationBuilder(Application.class) - .properties("spring.config.name:application,git") - .build(); - - app.setBannerMode(Banner.Mode.CONSOLE); - app.setAddCommandLineProperties(false); - app.addListeners(new AppCtxRefreshEventListener()); - MainContext.setApplicationContext(app.run(args)); + Application.serve(args); } } diff --git a/contact-center/app/src/main/java/com/chatopera/cc/acd/ACDAgentService.java b/contact-center/app/src/main/java/com/chatopera/cc/acd/ACDAgentService.java index 158517a6..750c49ec 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/acd/ACDAgentService.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/acd/ACDAgentService.java @@ -40,6 +40,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.Date; +import java.util.HashMap; import java.util.Map; @Component @@ -183,9 +184,9 @@ public class ACDAgentService { // 获得所有待服务访客的列表 final Map pendingAgentUsers = cache.getAgentUsersInQueByOrgi(orgi); - final SessionConfig sessionConfig = acdPolicyService.initSessionConfig(orgi); + // 本次批量分配访客数目 - int assigned = 0; + Map assigned = new HashMap<>(); int currentAssigned = cache.getInservAgentUsersSizeByAgentnoAndOrgi( agentStatus.getAgentno(), agentStatus.getOrgi()); @@ -226,14 +227,15 @@ public class ACDAgentService { } // 坐席未达到最大咨询访客数量,并且单次批量分配小于坐席就绪时分配最大访客数量(initMaxuser) - if (((currentAssigned + assigned) < sessionConfig.getMaxuser()) && (assigned < sessionConfig.getInitmaxuser())) { - assigned++; + final SessionConfig sessionConfig = acdPolicyService.initSessionConfig(agentUser.getSkill(), orgi); + if ((ACDServiceRouter.getAcdPolicyService().getAgentUsersBySkill(agentStatus, agentUser.getSkill()) < sessionConfig.getMaxuser()) && (assigned.getOrDefault(agentUser.getSkill(), 0) < sessionConfig.getInitmaxuser())) { + assigned.merge(agentUser.getSkill(), 1, Integer::sum); pickupAgentUserInQueue(agentUser, agentStatus); } else { logger.info( "[assignVisitors] agentno {} reach the max users limit {}/{} or batch assign limit {}/{}", agentno, - (currentAssigned + assigned), + (currentAssigned + assigned.getOrDefault(agentUser.getSkill(), 0)), sessionConfig.getMaxuser(), assigned, sessionConfig.getInitmaxuser()); break; } @@ -282,6 +284,9 @@ public class ACDAgentService { peerSyncIM.send(MainContext.ReceiverType.AGENT, MainContext.ChannelType.WEBIM, agentUser.getAppid(), MainContext.MessageType.NEW, agentUser.getAgentno(), outMessage, true); + + // 通知更新在线数据 + agentStatusProxy.broadcastAgentsStatus(agentUser.getOrgi(), "agent", "pickup", agentStatus.getAgentno()); } } catch (Exception ex) { logger.warn("[assignVisitors] fail to process service", ex); @@ -317,7 +322,7 @@ public class ACDAgentService { // 从缓存中删除agentUser缓存 agentUserRes.save(agentUser); - final SessionConfig sessionConfig = acdPolicyService.initSessionConfig(orgi); + final SessionConfig sessionConfig = acdPolicyService.initSessionConfig(agentUser.getSkill(), orgi); /** * 坐席服务 @@ -384,7 +389,7 @@ public class ACDAgentService { // 向访客发送消息 Message outMessage = new Message(); outMessage.setAgentStatus(agentStatus); - outMessage.setMessage(acdMessageHelper.getServiceFinishMessage(agentUser.getChannel(), orgi)); + outMessage.setMessage(acdMessageHelper.getServiceFinishMessage(agentUser.getChannel(), agentUser.getSkill(), orgi)); outMessage.setMessageType(MainContext.AgentUserStatusEnum.END.toString()); outMessage.setCalltype(MainContext.CallType.IN.toString()); outMessage.setCreatetime(MainUtils.dateFormate.format(new Date())); @@ -432,7 +437,7 @@ public class ACDAgentService { // 当前访客服务已经结束,为坐席寻找新访客 if (agentStatus != null) { - if ((agentStatus.getUsers() - 1) < sessionConfig.getMaxuser()) { + if ((ACDServiceRouter.getAcdPolicyService().getAgentUsersBySkill(agentStatus, agentUser.getSkill()) - 1) < sessionConfig.getMaxuser()) { assignVisitors(agentStatus.getAgentno(), orgi); } } diff --git a/contact-center/app/src/main/java/com/chatopera/cc/acd/ACDPolicyService.java b/contact-center/app/src/main/java/com/chatopera/cc/acd/ACDPolicyService.java index 13d9a39d..39f163b2 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/acd/ACDPolicyService.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/acd/ACDPolicyService.java @@ -16,12 +16,14 @@ package com.chatopera.cc.acd; +import com.chatopera.cc.basic.Constants; import com.chatopera.cc.basic.MainContext; import com.chatopera.cc.basic.MainUtils; import com.chatopera.cc.cache.Cache; import com.chatopera.cc.model.AgentStatus; import com.chatopera.cc.model.AgentUser; import com.chatopera.cc.model.SessionConfig; +import com.chatopera.cc.persistence.repository.AgentUserRepository; import com.chatopera.cc.persistence.repository.OnlineUserRepository; import com.chatopera.cc.persistence.repository.SessionConfigRepository; import com.chatopera.cc.util.HashMapUtils; @@ -33,6 +35,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import java.util.Map; @@ -52,6 +55,9 @@ public class ACDPolicyService { @Autowired private OnlineUserRepository onlineUserRes; + @Autowired + private AgentUserRepository agentUserRes; + /** * 载入坐席 ACD策略配置 * @@ -60,10 +66,10 @@ public class ACDPolicyService { @SuppressWarnings("unchecked") public List initSessionConfigList() { List sessionConfigList; - if ((sessionConfigList = cache.findOneSessionConfigListByOrgi(MainContext.SYSTEM_ORGI)) == null) { + if ((sessionConfigList = cache.findOneSessionConfigListByOrgi(Constants.SYSTEM_ORGI)) == null) { sessionConfigList = sessionConfigRes.findAll(); if (sessionConfigList != null && sessionConfigList.size() > 0) { - cache.putSessionConfigListByOrgi(sessionConfigList, MainContext.SYSTEM_ORGI); + cache.putSessionConfigListByOrgi(sessionConfigList, Constants.SYSTEM_ORGI); } } return sessionConfigList; @@ -75,14 +81,14 @@ public class ACDPolicyService { * @param orgi * @return */ - public SessionConfig initSessionConfig(final String orgi) { + public SessionConfig initSessionConfig(String organid, final String orgi) { SessionConfig sessionConfig; - if ((sessionConfig = cache.findOneSessionConfigByOrgi(orgi)) == null) { - sessionConfig = sessionConfigRes.findByOrgi(orgi); + if ((sessionConfig = cache.findOneSessionConfigByOrgi(organid, orgi)) == null) { + sessionConfig = sessionConfigRes.findByOrgiAndSkill(orgi, organid); if (sessionConfig == null) { sessionConfig = new SessionConfig(); } else { - cache.putSessionConfigByOrgi(sessionConfig, orgi); + cache.putSessionConfigByOrgi(sessionConfig, organid, orgi); } } @@ -113,14 +119,7 @@ public class ACDPolicyService { */ public AgentStatus decideAgentStatusInAverage(final List agentStatuses) { // 查找最少人数的AgentStatus - AgentStatus x = null; - int min = 0; - for (final AgentStatus o : agentStatuses) { - if ((x == null) || (o.getUsers() < min)) { - x = o; - min = o.getUsers(); - } - } + AgentStatus x = agentStatuses.stream().min(Comparator.comparingInt(AgentStatus::getUsers)).get(); if (x != null) { logger.info("[decideAgentStatusWithIdleAgent] choose agentno {} in average.", x.getAgentno()); @@ -144,7 +143,7 @@ public class ACDPolicyService { logger.info( "[filterOutAvailableAgentStatus] pre-conditions: agentUser.agentno {}, orgi {}, skill {}, onlineUser {}", agentUser.getAgentno(), orgi, agentUser.getSkill(), agentUser.getUserid() - ); + ); List agentStatuses = new ArrayList<>(); Map map = cache.findAllReadyAgentStatusByOrgi(orgi); @@ -155,10 +154,10 @@ public class ACDPolicyService { for (final Map.Entry f : map.entrySet()) { sb.append( String.format(" name %s, agentno %s, service %d/%d, status %s, busy %s, skills %s \n", - f.getValue().getUsername(), - f.getValue().getAgentno(), f.getValue().getUsers(), f.getValue().getMaxusers(), - f.getValue().getStatus(), f.getValue().isBusy(), - HashMapUtils.concatKeys(f.getValue().getSkills(), "|"))); + f.getValue().getUsername(), + f.getValue().getAgentno(), f.getValue().getUsers(), f.getValue().getMaxusers(), + f.getValue().getStatus(), f.getValue().isBusy(), + HashMapUtils.concatKeys(f.getValue().getSkills(), "|"))); } logger.info(sb.toString()); } else { @@ -198,7 +197,7 @@ public class ACDPolicyService { // 指定技能组 for (final Map.Entry entry : map.entrySet()) { if ((!entry.getValue().isBusy()) && - (entry.getValue().getUsers() < sessionConfig.getMaxuser()) && + (getAgentUsersBySkill(entry.getValue(), agentUser.getSkill()) < sessionConfig.getMaxuser()) && (entry.getValue().getSkills() != null && entry.getValue().getSkills().containsKey(agentUser.getSkill()))) { logger.info( @@ -227,26 +226,28 @@ public class ACDPolicyService { /** * 在指定的坐席和技能组中未查到坐席 * 接下来进行无差别查询 + * + * TODO 指定技能组无用户,停止分配 */ // 对于该租户的所有客服 - for (final Map.Entry entry : map.entrySet()) { - if ((!entry.getValue().isBusy()) && (entry.getValue().getUsers() < sessionConfig.getMaxuser())) { - agentStatuses.add(entry.getValue()); - logger.info( - "[filterOutAvailableAgentStatus] find ready agent {}, agentname {}, status {}, service {}/{}, skills {}", - entry.getValue().getAgentno(), entry.getValue().getUsername(), entry.getValue().getStatus(), - entry.getValue().getUsers(), - entry.getValue().getMaxusers(), - HashMapUtils.concatKeys(entry.getValue().getSkills(), "|")); - } else { - logger.info( - "[filterOutAvailableAgentStatus] skip ready agent {}, name {}, status {}, service {}/{}, skills {}", - entry.getValue().getAgentno(), entry.getValue().getUsername(), entry.getValue().getStatus(), - entry.getValue().getUsers(), - entry.getValue().getMaxusers(), - HashMapUtils.concatKeys(entry.getValue().getSkills(), "|")); - } - } + // for (final Map.Entry entry : map.entrySet()) { + // if ((!entry.getValue().isBusy()) && (entry.getValue().getUsers() < sessionConfig.getMaxuser())) { + // agentStatuses.add(entry.getValue()); + // logger.info( + // "[filterOutAvailableAgentStatus] find ready agent {}, agentname {}, status {}, service {}/{}, skills {}", + // entry.getValue().getAgentno(), entry.getValue().getUsername(), entry.getValue().getStatus(), + // entry.getValue().getUsers(), + // entry.getValue().getMaxusers(), + // HashMapUtils.concatKeys(entry.getValue().getSkills(), "|")); + // } else { + // logger.info( + // "[filterOutAvailableAgentStatus] skip ready agent {}, name {}, status {}, service {}/{}, skills {}", + // entry.getValue().getAgentno(), entry.getValue().getUsername(), entry.getValue().getStatus(), + // entry.getValue().getUsers(), + // entry.getValue().getMaxusers(), + // HashMapUtils.concatKeys(entry.getValue().getSkills(), "|")); + // } + // } } logger.info("[filterOutAvailableAgentStatus] agent status list size: {}", agentStatuses.size()); @@ -292,11 +293,11 @@ public class ACDPolicyService { logger.info("[filterOutAgentStatusWithPolicies] check agent against chat history."); // 启用了历史坐席优先 , 查找 历史服务坐席 List webIMaggs = MainUtils.getWebIMDataAgg( - onlineUserRes.findByOrgiForDistinctAgent(orgi, onlineUserId)); + onlineUserRes.findBySkillAndOrgiForDistinctAgent(sessionConfig.getSkill(), orgi, onlineUserId)); for (WebIMReport report : webIMaggs) { for (final AgentStatus o : agentStatuses) { if (StringUtils.equals( - o.getAgentno(), report.getData()) && o.getUsers() < sessionConfig.getMaxuser()) { + o.getAgentno(), report.getData()) && getAgentUsersBySkill(o, sessionConfig.getSkill()) < sessionConfig.getMaxuser()) { agentStatus = o; logger.info( "[filterOutAgentStatusWithPolicies] choose agentno {} by chat history.", @@ -349,4 +350,8 @@ public class ACDPolicyService { return agentStatus; } + public int getAgentUsersBySkill(AgentStatus agentStatus, String skill) { + return agentUserRes.countByAgentnoAndStatusAndOrgiAndSkill(agentStatus.getAgentno(), MainContext.AgentUserStatusEnum.INSERVICE.toString(), agentStatus.getOrgi(), skill); + } + } diff --git a/contact-center/app/src/main/java/com/chatopera/cc/acd/ACDWorkMonitor.java b/contact-center/app/src/main/java/com/chatopera/cc/acd/ACDWorkMonitor.java index 1c988787..659cc535 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/acd/ACDWorkMonitor.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/acd/ACDWorkMonitor.java @@ -20,8 +20,12 @@ import com.chatopera.cc.basic.MainUtils; import com.chatopera.cc.cache.Cache; import com.chatopera.cc.model.AgentReport; import com.chatopera.cc.model.AgentStatus; +import com.chatopera.cc.model.Organ; import com.chatopera.cc.model.WorkMonitor; +import com.chatopera.cc.persistence.repository.AgentServiceRepository; +import com.chatopera.cc.persistence.repository.AgentUserRepository; import com.chatopera.cc.persistence.repository.WorkMonitorRepository; +import com.chatopera.cc.proxy.OrganProxy; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,6 +46,15 @@ public class ACDWorkMonitor { @Autowired private Cache cache; + @Autowired + private OrganProxy organProxy; + + @Autowired + private AgentServiceRepository agentServiceRes; + + @Autowired + private AgentUserRepository agentUserRes; + /** * 获得 当前服务状态 * @@ -96,16 +109,26 @@ public class ACDWorkMonitor { /** * 统计当前服务中的用户数量 */ - // 服务中 - report.setUsers(cache.getInservAgentUsersSizeByOrgi(orgi)); - // 等待中 - report.setInquene(cache.getInqueAgentUsersSizeByOrgi(orgi)); + + if (organ != null) { + Organ currentOrgan = new Organ(); + currentOrgan.setId(organ); + Map organs = organProxy.findAllOrganByParentAndOrgi(currentOrgan, orgi); + + report.setUsers(agentServiceRes.countByOrgiAndStatusAndAgentskillIn(orgi, MainContext.AgentUserStatusEnum.INSERVICE.toString(), organs.keySet())); + report.setInquene(agentUserRes.countByOrgiAndStatusAndSkillIn(orgi, MainContext.AgentUserStatusEnum.INQUENE.toString(), organs.keySet())); + } else { + // 服务中 + report.setUsers(cache.getInservAgentUsersSizeByOrgi(orgi)); + // 等待中 + report.setInquene(cache.getInqueAgentUsersSizeByOrgi(orgi)); + } // DEBUG logger.info( "[getAgentReport] orgi {}, organ {}, agents {}, busy {}, users {}, inqueue {}", orgi, organ, report.getAgents(), report.getBusy(), report.getUsers(), report.getInquene() - ); + ); return report; } @@ -129,7 +152,7 @@ public class ACDWorkMonitor { String worktype, String orgi, Date lasttime - ) { + ) { WorkMonitor workMonitor = new WorkMonitor(); if (StringUtils.isNotBlank(agent) && StringUtils.isNotBlank(status)) { workMonitor.setAgent(agent); @@ -149,7 +172,7 @@ public class ACDWorkMonitor { int count = workMonitorRes.countByAgentAndDatestrAndStatusAndOrgi( agent, MainUtils.simpleDateFormat.format(new Date()), MainContext.AgentStatusEnum.READY.toString(), orgi - ); + ); if (count == 0) { workMonitor.setFirsttime(true); } diff --git a/contact-center/app/src/main/java/com/chatopera/cc/acd/basic/ACDMessageHelper.java b/contact-center/app/src/main/java/com/chatopera/cc/acd/basic/ACDMessageHelper.java index 924b72af..609863fe 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/acd/basic/ACDMessageHelper.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/acd/basic/ACDMessageHelper.java @@ -86,7 +86,7 @@ public class ACDMessageHelper { if (!MainContext.ChannelType.WEBIM.toString().equals(channel)) { queneTip = agentService.getAgentusername(); } - SessionConfig sessionConfig = acdPolicyService.initSessionConfig(orgi); + SessionConfig sessionConfig = acdPolicyService.initSessionConfig(agentService.getSkill(), orgi); String successMsg = "坐席分配成功," + queneTip + "为您服务。"; if (StringUtils.isNotBlank(sessionConfig.getSuccessmsg())) { successMsg = sessionConfig.getSuccessmsg().replaceAll("\\{agent\\}", queneTip); @@ -101,8 +101,8 @@ public class ACDMessageHelper { * @param orgi * @return */ - public String getServiceFinishMessage(String channel, String orgi) { - SessionConfig sessionConfig = acdPolicyService.initSessionConfig(orgi); + public String getServiceFinishMessage(String channel, String organid, String orgi) { + SessionConfig sessionConfig = acdPolicyService.initSessionConfig(organid, orgi); String queneTip = "坐席已断开和您的对话"; if (StringUtils.isNotBlank(sessionConfig.getFinessmsg())) { queneTip = sessionConfig.getFinessmsg(); @@ -118,8 +118,8 @@ public class ACDMessageHelper { * @param orgi * @return */ - public String getServiceOffMessage(String channel, String orgi) { - SessionConfig sessionConfig = acdPolicyService.initSessionConfig(orgi); + public String getServiceOffMessage(String channel, String organid, String orgi) { + SessionConfig sessionConfig = acdPolicyService.initSessionConfig(organid, orgi); String queneTip = "坐席已断开和您的对话,刷新页面为您分配新的坐席"; if (StringUtils.isNotBlank(sessionConfig.getFinessmsg())) { queneTip = sessionConfig.getFinessmsg(); @@ -127,7 +127,7 @@ public class ACDMessageHelper { return queneTip; } - public String getNoAgentMessage(int queneIndex, String channel, String orgi) { + public String getNoAgentMessage(int queneIndex, String channel, String organid, String orgi) { if (queneIndex < 0) { queneIndex = 0; } @@ -135,7 +135,7 @@ public class ACDMessageHelper { if (!MainContext.ChannelType.WEBIM.toString().equals(channel)) { queneTip = String.valueOf(queneIndex); } - SessionConfig sessionConfig = acdPolicyService.initSessionConfig(orgi); + SessionConfig sessionConfig = acdPolicyService.initSessionConfig(organid, orgi); String noAgentTipMsg = "坐席全忙,已进入等待队列,您也可以在其他时间再来咨询。"; if (StringUtils.isNotBlank(sessionConfig.getNoagentmsg())) { noAgentTipMsg = sessionConfig.getNoagentmsg().replaceAll("\\{num\\}", queneTip); @@ -143,13 +143,13 @@ public class ACDMessageHelper { return noAgentTipMsg; } - public String getQueneMessage(int queneIndex, String channel, String orgi) { + public String getQueneMessage(int queneIndex, String channel, String organid, String orgi) { String queneTip = "" + queneIndex + ""; if (!MainContext.ChannelType.WEBIM.toString().equals(channel)) { queneTip = String.valueOf(queneIndex); } - SessionConfig sessionConfig = acdPolicyService.initSessionConfig(orgi); + SessionConfig sessionConfig = acdPolicyService.initSessionConfig(organid, orgi); String agentBusyTipMsg = "正在排队,请稍候,在您之前,还有 " + queneTip + " 位等待用户。"; if (StringUtils.isNotBlank(sessionConfig.getAgentbusymsg())) { agentBusyTipMsg = sessionConfig.getAgentbusymsg().replaceAll("\\{num\\}", queneTip); diff --git a/contact-center/app/src/main/java/com/chatopera/cc/acd/middleware/visitor/ACDVisBodyParserMw.java b/contact-center/app/src/main/java/com/chatopera/cc/acd/middleware/visitor/ACDVisBodyParserMw.java index c592ab86..cc434dd3 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/acd/middleware/visitor/ACDVisBodyParserMw.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/acd/middleware/visitor/ACDVisBodyParserMw.java @@ -182,6 +182,7 @@ public class ACDVisBodyParserMw implements Middleware { ctx.setMessage(acdMessageHelper.getQueneMessage( ctx.getAgentService().getQueneindex(), ctx.getAgentUser().getChannel(), + ctx.getOrganid(), ctx.getOrgi())); } else { // TODO 什么是否返回 noAgentMessage, 是否在是 INQUENE 时 getQueneindex == 0 @@ -190,6 +191,7 @@ public class ACDVisBodyParserMw implements Middleware { ctx.setMessage(acdMessageHelper.getNoAgentMessage( ctx.getAgentService().getQueneindex(), ctx.getChannel(), + ctx.getOrganid(), ctx.getOrgi())); } diff --git a/contact-center/app/src/main/java/com/chatopera/cc/acd/middleware/visitor/ACDVisServiceMw.java b/contact-center/app/src/main/java/com/chatopera/cc/acd/middleware/visitor/ACDVisServiceMw.java index f8a98115..4029f6de 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/acd/middleware/visitor/ACDVisServiceMw.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/acd/middleware/visitor/ACDVisServiceMw.java @@ -59,6 +59,7 @@ public class ACDVisServiceMw implements Middleware { acdMessageHelper.getQueneMessage( queueIndex, ctx.getChannel(), + ctx.getOrganid(), ctx.getOrgi())); break; case INSERVICE: diff --git a/contact-center/app/src/main/java/com/chatopera/cc/acd/middleware/visitor/ACDVisSessionCfgMw.java b/contact-center/app/src/main/java/com/chatopera/cc/acd/middleware/visitor/ACDVisSessionCfgMw.java index 1904d321..355d70d7 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/acd/middleware/visitor/ACDVisSessionCfgMw.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/acd/middleware/visitor/ACDVisSessionCfgMw.java @@ -45,7 +45,7 @@ public class ACDVisSessionCfgMw implements Middleware { @Override public void apply(final ACDComposeContext ctx, final Functional next) { - SessionConfig sessionConfig = acdPolicyService.initSessionConfig( + SessionConfig sessionConfig = acdPolicyService.initSessionConfig(ctx.getOrganid(), ctx.getOrgi()); ctx.setSessionConfig(sessionConfig); diff --git a/contact-center/app/src/main/java/com/chatopera/cc/basic/Constants.java b/contact-center/app/src/main/java/com/chatopera/cc/basic/Constants.java index d03392c1..a023fe9e 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/basic/Constants.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/basic/Constants.java @@ -29,7 +29,9 @@ public class Constants { /** * 系统配置 */ + public static final String SYSTEM_ORGI = "cskefu"; public static final String USER_SESSION_NAME = "user"; + public static final String ORGAN_SESSION_NAME = "organ"; public static final String GUEST_USER = "guest"; public static final String IM_USER_SESSION_NAME = "im_user"; public static final String CSKEFU_SYSTEM_DIC = "com.dic.system.template"; @@ -45,7 +47,6 @@ public class Constants { public static final String CSKEFU_SYSTEM_DIS_TIME = "distime"; public static final String CSKEFU_SYSTEM_COOKIES_FLAG = "uk_flagid"; public static final String CSKEFU_SYSTEM_NO_DAT = "NOTEXIST"; - public static final String SYSTEM_INDEX = "cskefu"; public static final String CSKEFU_SYSTEM_SECFIELD = "cskefu_sec_field"; public static final String CSKEFU_SYSTEM_CALLCENTER = "callcenter"; @@ -92,6 +93,7 @@ public class Constants { public final static String CSKEFU_MODULE_ENTIM = "entim"; public final static String CSKEFU_MODULE_WORKORDERS = "workorders"; public final static String CSKEFU_MODULE_CALLCENTER = "callcenter"; + public final static String CSKEFU_MODULE_REPORT = "report"; /** * Formatter @@ -136,6 +138,10 @@ public class Constants { /** * FreeSwitch Communication */ + // callcenter + public final static String ACTIVEMQ_QUEUE_SWITCH_SYNC = "cskefu.callcenter.switch.sync"; + + // callout public final static String FS_SIP_STATUS = "pbx:%s:sips"; // 查询SIP状态 public final static String FS_CHANNEL_CC_TO_FS = "pbx/%s/execute"; // 发送外呼执行信号 public final static String FS_DIALPLAN_STATUS = "pbx:%s:status"; // 外呼执行状态存储 diff --git a/contact-center/app/src/main/java/com/chatopera/cc/basic/MainContext.java b/contact-center/app/src/main/java/com/chatopera/cc/basic/MainContext.java index a2dd4a23..0affabdc 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/basic/MainContext.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/basic/MainContext.java @@ -43,8 +43,6 @@ public class MainContext { private static boolean imServerRunning = false; // IM服务状态 - public static String SYSTEM_ORGI = "cskefu"; - private static Set modules = new HashSet(); public static Map> csKeFuResourceMap = new HashMap>(); @@ -61,13 +59,10 @@ public class MainContext { static { ConvertUtils.register(new DateConverter(), java.util.Date.class); - enableModule("report"); - csKeFuResourceMap.put(TaskType.ACTIVE.toString(), ActivityResource.class); csKeFuResourceMap.put(TaskType.BATCH.toString(), BatchResource.class); } - public enum AskSectionType { DEFAULT; @@ -435,7 +430,10 @@ public class MainContext { } } - public enum ExtentionType { + /** + * 分机类型 + */ + public enum ExtensionType { LINE, IVR, BUSINESS, @@ -446,6 +444,15 @@ public class MainContext { public String toString() { return super.toString().toLowerCase(); } + + public static ExtensionType toValue(final String str) { + for (final ExtensionType item : values()) { + if (StringUtils.equalsIgnoreCase(item.toString(), str)) { + return item; + } + } + throw new IllegalArgumentException(); + } } public enum DTMFType { diff --git a/contact-center/app/src/main/java/com/chatopera/cc/basic/MainUtils.java b/contact-center/app/src/main/java/com/chatopera/cc/basic/MainUtils.java index 7c008cc6..72c59fb4 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/basic/MainUtils.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/basic/MainUtils.java @@ -763,7 +763,7 @@ public class MainUtils { public static String processEmoti(String message) { Pattern pattern = Pattern.compile("\\[([\\d]*?)\\]"); SystemConfig systemConfig = MainContext.getCache().findOneSystemByIdAndOrgi( - "systemConfig", MainContext.SYSTEM_ORGI); + "systemConfig", Constants.SYSTEM_ORGI); Matcher matcher = pattern.matcher(message); StringBuffer strb = new StringBuffer(); @@ -839,10 +839,10 @@ public class MainUtils { */ public static SystemConfig getSystemConfig() { SystemConfig systemConfig = MainContext.getCache().findOneSystemByIdAndOrgi( - "systemConfig", MainContext.SYSTEM_ORGI); + "systemConfig", Constants.SYSTEM_ORGI); if (systemConfig == null) { SystemConfigRepository systemConfigRes = MainContext.getContext().getBean(SystemConfigRepository.class); - systemConfig = systemConfigRes.findByOrgi(MainContext.SYSTEM_ORGI); + systemConfig = systemConfigRes.findByOrgi(Constants.SYSTEM_ORGI); } return systemConfig; } @@ -856,7 +856,7 @@ public class MainUtils { if (tpRes != null) { List tpList = tpRes.findBySecfield(true); MainContext.getCache().putSystemListByIdAndOrgi( - Constants.CSKEFU_SYSTEM_SECFIELD, MainContext.SYSTEM_ORGI, tpList); + Constants.CSKEFU_SYSTEM_SECFIELD, Constants.SYSTEM_ORGI, tpList); } } @@ -866,10 +866,10 @@ public class MainUtils { * @return */ public static void initSystemArea() { - MainContext.getCache().deleteSystembyIdAndOrgi(Constants.CSKEFU_SYSTEM_AREA, MainContext.SYSTEM_ORGI); + MainContext.getCache().deleteSystembyIdAndOrgi(Constants.CSKEFU_SYSTEM_AREA, Constants.SYSTEM_ORGI); AreaTypeRepository areaTypeRes = MainContext.getContext().getBean(AreaTypeRepository.class); MainContext.getCache().putSystemListByIdAndOrgi( - Constants.CSKEFU_SYSTEM_AREA, MainContext.SYSTEM_ORGI, areaTypeRes.findAll()); + Constants.CSKEFU_SYSTEM_AREA, Constants.SYSTEM_ORGI, areaTypeRes.findAll()); } /** @@ -877,19 +877,19 @@ public class MainUtils { * * @return */ - public static void initAdv(String orgi) { - MainContext.getCache().deleteSystembyIdAndOrgi(Constants.CSKEFU_SYSTEM_ADV + "_" + orgi, orgi); + public static void initAdv(String orgi, String skill) { + MainContext.getCache().deleteSystembyIdAndOrgi(Constants.CSKEFU_SYSTEM_ADV + "_" + skill, orgi); AdTypeRepository adRes = MainContext.getContext().getBean(AdTypeRepository.class); MainContext.getCache().putSystemListByIdAndOrgi( - Constants.CSKEFU_SYSTEM_ADV + "_" + orgi, orgi, adRes.findByOrgi(orgi)); + Constants.CSKEFU_SYSTEM_ADV + "_" + skill, orgi, adRes.findByOrgiAndSkill(orgi, skill)); } public static Template getTemplate(String id) { Template templet = null; - if ((templet = MainContext.getCache().findOneSystemByIdAndOrgi(id, MainContext.SYSTEM_ORGI)) == null) { + if ((templet = MainContext.getCache().findOneSystemByIdAndOrgi(id, Constants.SYSTEM_ORGI)) == null) { TemplateRepository templateRes = MainContext.getContext().getBean(TemplateRepository.class); - templet = templateRes.findByIdAndOrgi(id, MainContext.SYSTEM_ORGI); - MainContext.getCache().putSystemByIdAndOrgi(id, MainContext.SYSTEM_ORGI, templet); + templet = templateRes.findByIdAndOrgi(id, Constants.SYSTEM_ORGI); + MainContext.getCache().putSystemByIdAndOrgi(id, Constants.SYSTEM_ORGI, templet); } return templet; } @@ -901,15 +901,15 @@ public class MainUtils { * @return */ @SuppressWarnings("unchecked") - public static AdType getPointAdv(String adpos, String orgi) { + public static AdType getPointAdv(String adpos, String skill, String orgi) { List adTypeList = new ArrayList(); List cacheAdTypeList = MainContext.getCache().findOneSystemListByIdAndOrgi( - Constants.CSKEFU_SYSTEM_ADV + "_" + orgi, orgi); + Constants.CSKEFU_SYSTEM_ADV + "_" + skill, orgi); if (cacheAdTypeList == null) { AdTypeRepository adRes = MainContext.getContext().getBean(AdTypeRepository.class); - cacheAdTypeList = adRes.findByOrgi(orgi); + cacheAdTypeList = adRes.findByOrgiAndSkill(orgi, skill); MainContext.getCache().putSystemListByIdAndOrgi( - Constants.CSKEFU_SYSTEM_ADV + "_" + orgi, orgi, cacheAdTypeList); + Constants.CSKEFU_SYSTEM_ADV + "_" + skill, orgi, cacheAdTypeList); } List sysDicList = Dict.getInstance().getDic(Constants.CSKEFU_SYSTEM_ADPOS_DIC); SysDic sysDic = null; diff --git a/contact-center/app/src/main/java/com/chatopera/cc/basic/plugins/AbstractPluginConfigurer.java b/contact-center/app/src/main/java/com/chatopera/cc/basic/plugins/AbstractPluginConfigurer.java new file mode 100644 index 00000000..847f67aa --- /dev/null +++ b/contact-center/app/src/main/java/com/chatopera/cc/basic/plugins/AbstractPluginConfigurer.java @@ -0,0 +1,24 @@ +package com.chatopera.cc.basic.plugins; + +import java.util.HashMap; +import java.util.Map; + +public abstract class AbstractPluginConfigurer implements IPluginConfigurer { + + public abstract String getPluginId(); + + public abstract String getPluginName(); + + public abstract String getIOEventHandler(); + + public Map getEnvironmentVariables() { + Map env = new HashMap<>(); + return env; + } + + public boolean isModule() { + return false; + } + + public abstract void setup(); +} diff --git a/contact-center/app/src/main/java/com/chatopera/cc/basic/plugins/IPluginDescriptor.java b/contact-center/app/src/main/java/com/chatopera/cc/basic/plugins/IPluginConfigurer.java similarity index 69% rename from contact-center/app/src/main/java/com/chatopera/cc/basic/plugins/IPluginDescriptor.java rename to contact-center/app/src/main/java/com/chatopera/cc/basic/plugins/IPluginConfigurer.java index 53a3ef41..8eb3641b 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/basic/plugins/IPluginDescriptor.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/basic/plugins/IPluginConfigurer.java @@ -17,9 +17,22 @@ package com.chatopera.cc.basic.plugins; import java.util.Map; -public interface IPluginDescriptor { +public interface IPluginConfigurer { + // 插件的ID:插件的标识,用于区别其它插件,由[a-z]组成,最大32位长度 + String getPluginId(); + + // 插件的名字:最少的概述插件 String getPluginName(); + + // 即时通信接口 String getIOEventHandler(); + // 获得环境变量及默认值 Map getEnvironmentVariables(); + + // 是否是Module(在一级菜单有入口的插件) + boolean isModule(); + + // 安装插件 + public void setup(); } diff --git a/contact-center/app/src/main/java/com/chatopera/cc/basic/plugins/PluginRegistry.java b/contact-center/app/src/main/java/com/chatopera/cc/basic/plugins/PluginRegistry.java index efa6636f..c37a70c4 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/basic/plugins/PluginRegistry.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/basic/plugins/PluginRegistry.java @@ -15,17 +15,85 @@ */ package com.chatopera.cc.basic.plugins; +import com.chatopera.cc.basic.MainContext; +import org.apache.commons.lang.StringUtils; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + /** * 插件注册表 */ +@Component public class PluginRegistry { - /** * Plugins Entry */ public final static String PLUGIN_CHANNEL_MESSAGER_SUFFIX = "ChannelMessager"; - public final static String PLUGIN_ENTRY_SKYPE = "com.chatopera.cc.plugins.skype.PluginDescriptor"; - public final static String PLUGIN_ENTRY_CALLOUT = "com.chatopera.cc.plugins.callout.PluginDescriptor"; - public final static String PLUGIN_ENTRY_CHATBOT = "com.chatopera.cc.plugins.chatbot.PluginDescriptor"; + // 插件列表 + private final List plugins = new ArrayList<>(); + + /** + * 添加插件 + * + * @param plugin + * @return + */ + public boolean addPlugin(final IPluginConfigurer plugin) { + for (final IPluginConfigurer x : plugins) { + if (StringUtils.equalsIgnoreCase(x.getPluginId(), plugin.getPluginId())) { + return false; + } + } + + if (StringUtils.isNotBlank(plugin.getPluginId())) { + MainContext.enableModule(plugin.getPluginId()); + } + + plugins.add(plugin); + return true; + } + + /** + * 获得插件列表 + * + * @return + */ + public List getPlugins() { + return plugins; + } + + /** + * 获得一个插件 + * + * @param pluginId + * @return + */ + public Optional getPlugin(final String pluginId) { + IPluginConfigurer p = null; + for (final IPluginConfigurer plugin : plugins) { + if (StringUtils.equalsIgnoreCase(plugin.getPluginId(), pluginId)) { + p = plugin; + break; + } + } + return Optional.ofNullable(p); + } + + /** + * 删除插件 + * + * @param pluginId + */ + public void removePlugin(final String pluginId) { + for (final IPluginConfigurer plugin : plugins) { + if (StringUtils.equalsIgnoreCase(plugin.getPluginId(), pluginId)) { + plugins.remove(plugin); + break; + } + } + } } diff --git a/contact-center/app/src/main/java/com/chatopera/cc/basic/plugins/PluginsLoader.java b/contact-center/app/src/main/java/com/chatopera/cc/basic/plugins/PluginsLoader.java deleted file mode 100644 index 77089e7a..00000000 --- a/contact-center/app/src/main/java/com/chatopera/cc/basic/plugins/PluginsLoader.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (C) 2019 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.basic.plugins; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -/** - * 插架装载器 - * TODO Placeholder - */ -public class PluginsLoader { - private final static Logger logger = LoggerFactory.getLogger(PluginsLoader.class); - - - /** - * 通过插件entry获得PluginName - * - * @param pluginEntry - * @return - */ - public static String getPluginName(final String pluginEntry) { - Class clazz; - try { - clazz = Class.forName(pluginEntry); - IPluginDescriptor clazzInst = (IPluginDescriptor) clazz.newInstance(); - Method method = clazz.getMethod("getPluginName"); - return (String) method.invoke(clazzInst); - } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e) { - logger.info("[postConstruct] error", e); - } - return null; - } - - - - /** - * 通过插件entry获得Plugin SocketIO Event Handler - * - * @param pluginEntry - * @return - */ - public static String getIOEventHandler(final String pluginEntry) { - Class clazz; - try { - clazz = Class.forName(pluginEntry); - IPluginDescriptor clazzInst = (IPluginDescriptor) clazz.newInstance(); - Method method = clazz.getMethod("getIOEventHandler"); - return (String) method.invoke(clazzInst); - } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e) { - logger.info("[postConstruct] error", e); - } - return null; - } - -} diff --git a/contact-center/app/src/main/java/com/chatopera/cc/cache/Cache.java b/contact-center/app/src/main/java/com/chatopera/cc/cache/Cache.java index f3ada430..6b110a3b 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/cache/Cache.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/cache/Cache.java @@ -754,24 +754,24 @@ public class Cache { * Session Config 相关 **************************/ - public void putSessionConfigByOrgi(final SessionConfig sessionConfig, final String orgi) { - redisCommand.put(RedisKey.getSessionConfig(orgi), SerializeUtil.serialize(sessionConfig)); + public void putSessionConfigByOrgi(final SessionConfig sessionConfig, String organid, final String orgi) { + redisCommand.put(RedisKey.getSessionConfig(organid, orgi), SerializeUtil.serialize(sessionConfig)); } - public SessionConfig findOneSessionConfigByOrgi(final String orgi) { - String serialized = redisCommand.get(RedisKey.getSessionConfig(orgi)); + public SessionConfig findOneSessionConfigByOrgi(String organid, final String orgi) { + String serialized = redisCommand.get(RedisKey.getSessionConfig(organid, orgi)); if (StringUtils.isNotBlank(serialized)) { return (SessionConfig) SerializeUtil.deserialize(serialized); } return null; } - public void deleteSessionConfigByOrgi(final String orgi) { - redisCommand.delete(RedisKey.getSessionConfig(orgi)); + public void deleteSessionConfigByOrgi(String organid, final String orgi) { + redisCommand.delete(RedisKey.getSessionConfig(organid, orgi)); } - public boolean existSessionConfigByOrgi(final String orgi) { - return redisCommand.exists(RedisKey.getSessionConfig(orgi)); + public boolean existSessionConfigByOrgi(String organid, final String orgi) { + return redisCommand.exists(RedisKey.getSessionConfig(organid, orgi)); } public void putSessionConfigListByOrgi(final List lis, final String orgi) { diff --git a/contact-center/app/src/main/java/com/chatopera/cc/cache/RedisKey.java b/contact-center/app/src/main/java/com/chatopera/cc/cache/RedisKey.java index 5c751563..ed3d59df 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/cache/RedisKey.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/cache/RedisKey.java @@ -238,9 +238,11 @@ public class RedisKey { return sb.toString(); } - public static String getSessionConfig(final String orgi) { + public static String getSessionConfig(String organid, final String orgi) { StringBuffer sb = new StringBuffer(); sb.append(orgi); + sb.append(":"); + sb.append(organid); sb.append(":session:config"); return sb.toString(); } diff --git a/contact-center/app/src/main/java/com/chatopera/cc/config/AppCtxRefreshEventListener.java b/contact-center/app/src/main/java/com/chatopera/cc/config/AppCtxRefreshEventListener.java index b0761e63..95d50adf 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/config/AppCtxRefreshEventListener.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/config/AppCtxRefreshEventListener.java @@ -19,6 +19,8 @@ package com.chatopera.cc.config; import com.chatopera.cc.basic.Constants; import com.chatopera.cc.basic.MainContext; import com.chatopera.cc.basic.MainUtils; +import com.chatopera.cc.basic.plugins.IPluginConfigurer; +import com.chatopera.cc.basic.plugins.PluginRegistry; import com.chatopera.cc.cache.Cache; import com.chatopera.cc.model.BlackEntity; import com.chatopera.cc.model.SysDic; @@ -49,7 +51,6 @@ public class AppCtxRefreshEventListener implements ApplicationListener sysDicList = sysDicRes.findAll(); Map> rootDictItems = new HashMap<>(); // 关联根词典及其子项 @@ -91,19 +92,19 @@ public class AppCtxRefreshEventListener implements ApplicationListener(rootDics.values()), MainContext.SYSTEM_ORGI); + cache.putSysDicByOrgi(new ArrayList<>(rootDics.values()), Constants.SYSTEM_ORGI); for (final Map.Entry> entry : rootDictItems.entrySet()) { SysDic rootDic = rootDics.get(entry.getKey()); // 打印根词典信息 logger.debug("[onApplicationEvent] root dict: {}, code {}, name {}, item size {}", entry.getKey(), rootDics.get(entry.getKey()).getCode(), rootDics.get(entry.getKey()).getName(), entry.getValue().size()); // 存储子项列表 - cache.putSysDicByOrgi(rootDic.getCode(), MainContext.SYSTEM_ORGI, entry.getValue()); + cache.putSysDicByOrgi(rootDic.getCode(), Constants.SYSTEM_ORGI, entry.getValue()); // 存储子项成员 - cache.putSysDicByOrgi(entry.getValue(), MainContext.SYSTEM_ORGI); + cache.putSysDicByOrgi(entry.getValue(), Constants.SYSTEM_ORGI); } - List blackList = blackListRes.findByOrgi(MainContext.SYSTEM_ORGI); + List blackList = blackListRes.findByOrgi(Constants.SYSTEM_ORGI); for (final BlackEntity black : blackList) { if (StringUtils.isNotBlank(black.getUserid())) { if (black.getEndtime() == null || black.getEndtime().after(new Date())) { @@ -116,9 +117,9 @@ public class AppCtxRefreshEventListener implements ApplicationListener - * This software and related documentation are provided under a license agreement containing - * restrictions on use and disclosure and are protected by intellectual property laws. - * Except as expressly permitted in your license agreement or allowed by law, you may not use, - * copy, reproduce, translate, broadcast, modify, license, transmit, distribute, exhibit, perform, - * publish, or display any part, in any form, or by any means. Reverse engineering, disassembly, - * or decompilation of this software, unless required by law for interoperability, is prohibited. - */ -package com.chatopera.cc.config.plugins; - -import com.chatopera.cc.basic.Constants; -import com.chatopera.cc.basic.MainContext; -import org.springframework.context.annotation.Condition; -import org.springframework.context.annotation.ConditionContext; -import org.springframework.core.type.AnnotatedTypeMetadata; - -/** - * Init bean based on conditions - * https://javapapers.com/spring/spring-conditional-annotation/ - */ -public class CalloutPluginPresentCondition implements Condition { - @Override - public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) { - return MainContext.hasModule(Constants.CSKEFU_MODULE_CALLOUT); - } -} diff --git a/contact-center/app/src/main/java/com/chatopera/cc/config/plugins/ChatbotPluginPresentCondition.java b/contact-center/app/src/main/java/com/chatopera/cc/config/plugins/ChatbotPluginPresentCondition.java deleted file mode 100644 index 940c1334..00000000 --- a/contact-center/app/src/main/java/com/chatopera/cc/config/plugins/ChatbotPluginPresentCondition.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2019 Chatopera Inc, All rights reserved. - * - * This software and related documentation are provided under a license agreement containing - * restrictions on use and disclosure and are protected by intellectual property laws. - * Except as expressly permitted in your license agreement or allowed by law, you may not use, - * copy, reproduce, translate, broadcast, modify, license, transmit, distribute, exhibit, perform, - * publish, or display any part, in any form, or by any means. Reverse engineering, disassembly, - * or decompilation of this software, unless required by law for interoperability, is prohibited. - */ -package com.chatopera.cc.config.plugins; - -import com.chatopera.cc.basic.Constants; -import com.chatopera.cc.basic.MainContext; -import org.springframework.context.annotation.Condition; -import org.springframework.context.annotation.ConditionContext; -import org.springframework.core.type.AnnotatedTypeMetadata; - -/** - * Init bean based on conditions - * https://javapapers.com/spring/spring-conditional-annotation/ - */ -public class ChatbotPluginPresentCondition implements Condition { - @Override - public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) { - return MainContext.hasModule(Constants.CSKEFU_MODULE_CHATBOT); - } -} diff --git a/contact-center/app/src/main/java/com/chatopera/cc/config/plugins/SkypePluginPresentCondition.java b/contact-center/app/src/main/java/com/chatopera/cc/config/plugins/SkypePluginPresentCondition.java deleted file mode 100644 index 31f938ed..00000000 --- a/contact-center/app/src/main/java/com/chatopera/cc/config/plugins/SkypePluginPresentCondition.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2019 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.config.plugins; - -import com.chatopera.cc.basic.Constants; -import com.chatopera.cc.basic.MainContext; -import org.springframework.context.annotation.Condition; -import org.springframework.context.annotation.ConditionContext; -import org.springframework.core.type.AnnotatedTypeMetadata; - -/** - * Skype渠道检测 - */ -public class SkypePluginPresentCondition implements Condition { - @Override - public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) { - return MainContext.hasModule(Constants.CSKEFU_MODULE_SKYPE); - } -} diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/ApplicationController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/ApplicationController.java index 5d360147..8cc7648d 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/ApplicationController.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/controller/ApplicationController.java @@ -17,9 +17,16 @@ package com.chatopera.cc.controller; import com.chatopera.cc.acd.ACDWorkMonitor; +import com.chatopera.cc.basic.Constants; import com.chatopera.cc.basic.MainContext; +import com.chatopera.cc.basic.MainUtils; import com.chatopera.cc.cache.Cache; +import com.chatopera.cc.model.Organ; import com.chatopera.cc.model.User; +import com.chatopera.cc.persistence.repository.ExtensionRepository; +import com.chatopera.cc.persistence.repository.OrganRepository; +import com.chatopera.cc.persistence.repository.PbxHostRepository; +import com.chatopera.cc.proxy.OrganProxy; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -27,10 +34,17 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; +import java.security.NoSuchAlgorithmException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.TimeZone; +import java.util.stream.Collectors; @Controller public class ApplicationController extends Handler { @@ -57,19 +71,39 @@ public class ApplicationController extends Handler { @Value("${tongji.baidu.sitekey}") private String tongjiBaiduSiteKey; + @Autowired + private OrganProxy organProxy; + + @Autowired + private OrganRepository organRepository; + + @Autowired + private PbxHostRepository pbxHostRes; + + @Autowired + private ExtensionRepository extensionRes; @RequestMapping("/") public ModelAndView admin(HttpServletRequest request) { // logger.info("[admin] path {} queryString {}", request.getPathInfo(),request.getQueryString()); ModelAndView view = request(super.createRequestPageTempletResponse("/apps/index")); User logined = super.getUser(request); + Organ currentOrgan = super.getOrgan(request); + TimeZone timezone = TimeZone.getDefault(); - view.addObject("agentStatusReport", acdWorkMonitor.getAgentReport(logined.getOrgi())); - view.addObject("tenant", super.getTenant(request)); - view.addObject("istenantshare", super.isEnabletneant()); - view.addObject("timeDifference", timezone.getRawOffset()); + List organs = organProxy.findOrganInIds(logined.getAffiliates()); + view.addObject( + "skills", + organProxy.findAllOrganByParentAndOrgi(currentOrgan, super.getOrgi(request)).keySet().stream().collect(Collectors.joining(",")) + ); + + view.addObject("agentStatusReport", acdWorkMonitor.getAgentReport(currentOrgan != null ? currentOrgan.getId() : null, logined.getOrgi())); + view.addObject("istenantshare", false); + view.addObject("timeDifference", timezone.getRawOffset()); + view.addObject("organList", organs); + view.addObject("currentOrgan", super.getOrgan(request)); // 增加版本信息 view.addObject("appBuildDate", appBuildDate); @@ -77,19 +111,28 @@ public class ApplicationController extends Handler { view.addObject("appVersionNumber", appVersionNumber); view.addObject("appCustomerEntity", appCustomerEntity); - if (super.isEnabletneant()) { - // 多租户启用 非管理员 一定要选择租户才能进入界面 - if (!logined.isAdmin() && StringUtils.isNotBlank( - logined.getOrgid()) && super.isTenantconsole() && MainContext.SYSTEM_ORGI.equals( - logined.getOrgi())) { - view = request(super.createRequestPageTempletResponse("redirect:/apps/tenant/index")); - } - if (StringUtils.isBlank(logined.getOrgid())) { - view = request(super.createRequestPageTempletResponse("redirect:/apps/organization/add.html")); - } - } + // 在线坐席状态信息 view.addObject("agentStatus", cache.findOneAgentStatusByAgentnoAndOrig(logined.getId(), logined.getOrgi())); + // 呼叫中心信息 + if (MainContext.hasModule(Constants.CSKEFU_MODULE_CALLCENTER) && logined.isCallcenter()) { + extensionRes.findByAgentnoAndOrgi(logined.getId(), logined.getOrgi()).ifPresent(ext -> { + pbxHostRes.findById(ext.getHostid()).ifPresent(pbx -> { + Map webrtcData = new HashMap<>(); + webrtcData.put("callCenterWebrtcIP", pbx.getWebrtcaddress()); + webrtcData.put("callCenterWebRtcPort", pbx.getWebrtcport()); + webrtcData.put("callCenterExtensionNum", ext.getExtension()); + try { + webrtcData.put("callCenterExtensionPassword", MainUtils.decryption(ext.getPassword())); + } catch (NoSuchAlgorithmException e) { + logger.error("[admin]", e); + webrtcData.put("callCenterError", "Invalid data for callcenter agent."); + } + view.addObject("webrtc", webrtcData); + }); + }); + } + if (StringUtils.isNotBlank(tongjiBaiduSiteKey) && !StringUtils.equalsIgnoreCase(tongjiBaiduSiteKey, "placeholder")) { logger.info("tongjiBaiduSiteKey: {}", tongjiBaiduSiteKey); view.addObject("tongjiBaiduSiteKey", tongjiBaiduSiteKey); @@ -98,9 +141,25 @@ public class ApplicationController extends Handler { return view; } + @RequestMapping("/setorgan") + @ResponseBody + public String setOrgan(HttpServletRequest request, @Valid String organ) { + if (StringUtils.isNotBlank(organ)) { + Organ currentOrgan = organRepository.findByIdAndOrgi(organ, super.getOrgi(request)); + if (currentOrgan != null) { + request.getSession(true).setAttribute(Constants.ORGAN_SESSION_NAME, currentOrgan); + } + } + + return "ok"; + } + @RequestMapping("/lazyAgentStatus") public ModelAndView lazyAgentStatus(HttpServletRequest request) { - ModelAndView view = request(super.createRequestPageTempletResponse("/apps/index")); + ModelAndView view = request(super.createRequestPageTempletResponse("/public/agentstatustext")); + Organ currentOrgan = super.getOrgan(request); + view.addObject("agentStatusReport", acdWorkMonitor.getAgentReport(currentOrgan != null ? currentOrgan.getId() : null, super.getOrgi(request))); + return view; } diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/Handler.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/Handler.java index 9a8fcbcf..fdc3cc41 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/Handler.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/controller/Handler.java @@ -17,20 +17,18 @@ package com.chatopera.cc.controller; import com.chatopera.cc.basic.Constants; -import com.chatopera.cc.basic.MainContext; import com.chatopera.cc.basic.MainUtils; import com.chatopera.cc.basic.Viewport; import com.chatopera.cc.basic.auth.AuthToken; import com.chatopera.cc.cache.Cache; import com.chatopera.cc.controller.api.QueryParams; import com.chatopera.cc.exception.CSKefuException; +import com.chatopera.cc.model.Organ; import com.chatopera.cc.model.StreamingFile; import com.chatopera.cc.model.SystemConfig; -import com.chatopera.cc.model.Tenant; import com.chatopera.cc.model.User; import com.chatopera.cc.persistence.blob.JpaBlobHelper; import com.chatopera.cc.persistence.repository.StreamingFileRepository; -import com.chatopera.cc.persistence.repository.TenantRepository; import org.apache.commons.lang.StringUtils; import org.elasticsearch.index.query.BoolQueryBuilder; import org.elasticsearch.index.query.QueryBuilders; @@ -50,6 +48,7 @@ import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import java.io.IOException; import java.text.ParseException; +import java.util.ArrayList; import java.util.Map; import static org.elasticsearch.index.query.QueryBuilders.termQuery; @@ -60,9 +59,6 @@ import static org.elasticsearch.index.query.QueryBuilders.termQuery; public class Handler { private static final Logger logger = LoggerFactory.getLogger(Handler.class); - @Autowired - private TenantRepository tenantRes; - @Autowired private JpaBlobHelper jpaBlobHelper; @@ -101,7 +97,7 @@ public class Handler { user = new User(); user.setId(MainUtils.getContextID(request.getSession().getId())); user.setUsername(Constants.GUEST_USER + "_" + MainUtils.genIDByKey(user.getId())); - user.setOrgi(MainContext.SYSTEM_ORGI); + user.setOrgi(Constants.SYSTEM_ORGI); user.setSessionid(user.getId()); } } else { @@ -110,6 +106,33 @@ public class Handler { return user; } + /** + * 获得登录账号的当前导航的组织机构 + * @param request + * @return + */ + public Organ getOrgan(HttpServletRequest request) { + User user = getUser(request); + if (user.getOrgans() != null) { + ArrayList organs = new ArrayList<>(user.getOrgans().values()); + + if (organs.size() == 0) { + return null; + } + + Organ organ = (Organ) request.getSession(true).getAttribute(Constants.ORGAN_SESSION_NAME); + if (organ == null) { + if (organs.size() > 0) { + organ = organs.get(0); + request.getSession(true).setAttribute(Constants.ORGAN_SESSION_NAME, organ); + } + } + return organ; + } else { + return null; + } + } + /** * 构建ElasticSearch基于部门查询的Filter * @@ -310,7 +333,7 @@ public class Handler { user.setUsername(nickname); } else { Map sessionMessage = cache.findOneSystemMapByIdAndOrgi( - request.getSession().getId(), MainContext.SYSTEM_ORGI); + request.getSession().getId(), Constants.SYSTEM_ORGI); if (sessionMessage != null) { String struname = sessionMessage.get("username"); String strcname = sessionMessage.get("company_name"); @@ -340,7 +363,7 @@ public class Handler { user.setUsername(nickname); } else { Map sessionMessage = cache.findOneSystemMapByIdAndOrgi( - sessionid, MainContext.SYSTEM_ORGI); + sessionid, Constants.SYSTEM_ORGI); if (sessionMessage != null) { String struname = sessionMessage.get("username"); String strcname = sessionMessage.get("company_name"); @@ -455,68 +478,13 @@ public class Handler { return pagesize; } + public String getOrgi() { + return Constants.SYSTEM_ORGI; + } + + // FIXME: 保存此处是为了兼容之前到代码,宜去掉 public String getOrgi(HttpServletRequest request) { - return getUser(request).getOrgi(); - } - - /** - * 机构id - * - * @param request - * @return - */ - public String getOrgid(HttpServletRequest request) { - User u = getUser(request); - return u.getOrgid(); - } - - public Tenant getTenant(HttpServletRequest request) { - return tenantRes.findById(getOrgi(request)); - } - - /** - * 根据是否租户共享获取orgi - * - * @param request - * @return - */ - public String getOrgiByTenantshare(HttpServletRequest request) { - SystemConfig systemConfig = MainUtils.getSystemConfig(); - if (systemConfig != null && systemConfig.isEnabletneant() && systemConfig.isTenantshare()) { - User user = this.getUser(request); - return user.getOrgid(); - } - return getOrgi(request); - } - - /** - * 判断是否租户共享 - * - * @return - */ - public boolean isTenantshare() { - SystemConfig systemConfig = MainUtils.getSystemConfig(); - return systemConfig != null && systemConfig.isEnabletneant() && systemConfig.isTenantshare(); - } - - /** - * 判断是否多租户 - * - * @return - */ - public boolean isEnabletneant() { - SystemConfig systemConfig = MainUtils.getSystemConfig(); - return systemConfig != null && systemConfig.isEnabletneant(); - } - - /** - * 判断是否多租户 - * - * @return - */ - public boolean isTenantconsole() { - SystemConfig systemConfig = MainUtils.getSystemConfig(); - return systemConfig != null && systemConfig.isEnabletneant() && systemConfig.isTenantconsole(); + return getOrgi(); } public long getStarttime() { diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/LoginController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/LoginController.java index 36394a8c..ef7e77eb 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/LoginController.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/controller/LoginController.java @@ -21,17 +21,14 @@ import com.chatopera.cc.basic.Constants; import com.chatopera.cc.basic.MainContext; import com.chatopera.cc.basic.MainUtils; import com.chatopera.cc.basic.auth.AuthToken; -import com.chatopera.cc.cache.Cache; import com.chatopera.cc.model.AgentStatus; import com.chatopera.cc.model.SystemConfig; import com.chatopera.cc.model.User; import com.chatopera.cc.model.UserRole; -import com.chatopera.cc.persistence.repository.AgentStatusRepository; import com.chatopera.cc.persistence.repository.UserRepository; import com.chatopera.cc.persistence.repository.UserRoleRepository; import com.chatopera.cc.proxy.AgentProxy; import com.chatopera.cc.proxy.AgentSessionProxy; -import com.chatopera.cc.proxy.OnlineUserProxy; import com.chatopera.cc.proxy.UserProxy; import com.chatopera.cc.util.Menu; import org.apache.commons.lang.StringUtils; @@ -73,12 +70,6 @@ public class LoginController extends Handler { @Autowired private AuthToken authToken; - @Autowired - private AgentStatusRepository agentStatusRes; - - @Autowired - private Cache cache; - @Autowired private AgentProxy agentProxy; @@ -161,7 +152,7 @@ public class LoginController extends Handler { view.addObject("tongjiBaiduSiteKey", tongjiBaiduSiteKey); } - if(StringUtils.isNotBlank(adsLoginBanner) && StringUtils.equalsIgnoreCase(adsLoginBanner, "on")){ + if (StringUtils.isNotBlank(adsLoginBanner) && StringUtils.equalsIgnoreCase(adsLoginBanner, "on")) { view.addObject("adsLoginBanner", "on"); } @@ -309,10 +300,6 @@ public class LoginController extends Handler { } super.setUser(request, loginUser); - // 当前用户 企业id为空 调到创建企业页面 - if (StringUtils.isBlank(loginUser.getOrgid())) { - view = new ModelAndView("redirect:/apps/organization/add.html"); - } } return view; } @@ -378,21 +365,10 @@ public class LoginController extends Handler { if (StringUtils.isNotBlank(user.getPassword())) { user.setPassword(MainUtils.md5(user.getPassword())); } - user.setOrgi(super.getOrgiByTenantshare(request)); - /*if(StringUtils.isNotBlank(super.getUser(request).getOrgid())) { - user.setOrgid(super.getUser(request).getOrgid()); - }else { - user.setOrgid(MainContext.SYSTEM_ORGI); - }*/ + user.setOrgi(super.getOrgi()); userRepository.save(user); - OnlineUserProxy.clean(super.getOrgi(request)); - } ModelAndView view = this.processLogin(request, user, ""); - //当前用户 企业id为空 调到创建企业页面 - if (StringUtils.isBlank(user.getOrgid())) { - view = request(super.createRequestPageTempletResponse("redirect:/apps/organization/add.html")); - } return view; } diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/AdminController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/AdminController.java index da7905a9..4d521342 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/AdminController.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/AdminController.java @@ -79,7 +79,7 @@ public class AdminController extends Handler { map.put("onlineUserCache", cache.getOnlineUserSizeByOrgi(orgi)); map.put("onlineUserClients", OnlineUserProxy.webIMClients.size()); map.put("chatClients", NettyClients.getInstance().size()); - map.put("systemCaches", cache.getSystemSizeByOrgi(MainContext.SYSTEM_ORGI)); + map.put("systemCaches", cache.getSystemSizeByOrgi(Constants.SYSTEM_ORGI)); map.put("agentReport", acdWorkMonitor.getAgentReport(orgi)); map.put("webIMReport", MainUtils.getWebIMReport(userEventRes.findByOrgiAndCreatetimeRange(super.getOrgi(request), MainUtils.getStartTime(), MainUtils.getEndTime()))); @@ -107,12 +107,7 @@ public class AdminController extends Handler { private List getAgent(HttpServletRequest request) { //获取当前产品or租户坐席数 - List userList = new ArrayList<>(); - if (super.isEnabletneant()) { - userList = userRes.findByOrgidAndAgentAndDatastatus(super.getOrgid(request), true, false); - } else { - userList = userRes.findByOrgiAndAgentAndDatastatus(super.getOrgi(request), true, false); - } + List userList = userRes.findByOrgiAndAgentAndDatastatus(super.getOrgi(request), true, false); return userList.isEmpty() ? new ArrayList() : userList; } diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/OrganController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/OrganController.java index 93aa35f4..4018d2a3 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/OrganController.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/OrganController.java @@ -86,8 +86,7 @@ public class OrganController extends Handler { @RequestMapping("/index") @Menu(type = "admin", subtype = "organ") public ModelAndView index(ModelMap map, HttpServletRequest request, @Valid String organ, @Valid String msg) { - List organList = organRepository.findByOrgiAndOrgid( - super.getOrgiByTenantshare(request), super.getOrgid(request)); + List organList = organRepository.findByOrgi(super.getOrgi()); map.addAttribute("organList", organList); if (organList.size() > 0) { Organ organData = null; @@ -105,15 +104,12 @@ public class OrganController extends Handler { map.addAttribute( "userList", userProxy.findByOrganAndOrgiAndDatastatus( organData.getId(), - super.getOrgiByTenantshare(request), + super.getOrgi(), false)); } } - map.addAttribute("areaList", areaRepository.findByOrgi(super.getOrgiByTenantshare(request))); - map.addAttribute( - "roleList", roleRepository.findByOrgiAndOrgid( - super.getOrgiByTenantshare(request), - super.getOrgid(request))); + map.addAttribute("areaList", areaRepository.findByOrgi(super.getOrgi())); + map.addAttribute("roleList", roleRepository.findByOrgi(super.getOrgi())); map.put("msg", msg); return request(super.createAdminTempletResponse("/admin/organ/index")); } @@ -121,18 +117,15 @@ public class OrganController extends Handler { @RequestMapping("/add") @Menu(type = "admin", subtype = "organ") public ModelAndView add(ModelMap map, HttpServletRequest request, @Valid String parent, @Valid String area) { - map.addAttribute("areaList", areaRepository.findByOrgi(super.getOrgiByTenantshare(request))); + map.addAttribute("areaList", areaRepository.findByOrgi(super.getOrgi())); if (!StringUtils.isBlank(parent)) { - map.addAttribute("organ", organRepository.findByIdAndOrgi(parent, super.getOrgiByTenantshare(request))); + map.addAttribute("organ", organRepository.findByIdAndOrgi(parent, super.getOrgi())); } if (!StringUtils.isBlank(area)) { - map.addAttribute("area", areaRepository.findByIdAndOrgi(area, super.getOrgiByTenantshare(request))); + map.addAttribute("area", areaRepository.findByIdAndOrgi(area, super.getOrgi())); } - map.addAttribute( - "organList", organRepository.findByOrgiAndOrgid( - super.getOrgiByTenantshare(request), - super.getOrgid(request))); + map.addAttribute("organList", organRepository.findByOrgi(super.getOrgi())); return request(super.createRequestPageTempletResponse("/admin/organ/add")); } @@ -140,25 +133,16 @@ public class OrganController extends Handler { @RequestMapping("/save") @Menu(type = "admin", subtype = "organ") public ModelAndView save(HttpServletRequest request, @Valid Organ organ) { - Organ tempOrgan = organRepository.findByNameAndOrgiAndOrgid( - organ.getName(), super.getOrgiByTenantshare(request), super.getOrgid(request)); + Organ tempOrgan = organRepository.findByNameAndOrgi(organ.getName(), super.getOrgi(request)); String msg = "admin_organ_new_success"; String firstId = null; if (tempOrgan != null) { msg = "admin_organ_update_name_not"; //分类名字重复 } else { - organ.setOrgi(super.getOrgiByTenantshare(request)); - - if (!StringUtils.isBlank(super.getUser(request).getOrgid())) { - organ.setOrgid(super.getUser(request).getOrgid()); - } else { - organ.setOrgid(MainContext.SYSTEM_ORGI); - } + organ.setOrgi(super.getOrgi()); firstId = organ.getId(); organRepository.save(organ); - - OnlineUserProxy.clean(super.getOrgi(request)); } return request(super.createRequestPageTempletResponse( "redirect:/admin/organ/index.html?msg=" + msg + "&organ=" + firstId)); @@ -176,11 +160,10 @@ public class OrganController extends Handler { @Menu(type = "admin", subtype = "seluser", admin = true) public ModelAndView seluser(ModelMap map, HttpServletRequest request, @Valid String organ) { map.addAttribute( - "userList", userRepository.findByOrgiAndDatastatusAndOrgid(super.getOrgiByTenantshare(request), false, - super.getOrgid(request))); - Organ organData = organRepository.findByIdAndOrgi(organ, super.getOrgiByTenantshare(request)); + "userList", userRepository.findByOrgiAndDatastatus(super.getOrgi(), false)); + Organ organData = organRepository.findByIdAndOrgi(organ, super.getOrgi()); map.addAttribute("userOrganList", userProxy - .findByOrganAndOrgiAndDatastatus(organ, super.getOrgiByTenantshare(request), false)); + .findByOrganAndOrgiAndDatastatus(organ, super.getOrgi(), false)); map.addAttribute("organ", organData); return request(super.createRequestPageTempletResponse("/admin/organ/seluser")); } @@ -200,13 +183,13 @@ public class OrganController extends Handler { HttpServletRequest request, final @Valid String[] users, final @Valid String organ - ) { + ) { logger.info("[saveuser] save users {} into organ {}", StringUtils.join(users, ","), organ); final User loginUser = super.getUser(request); if (users != null && users.length > 0) { List chosen = new ArrayList(Arrays.asList(users)); - Organ organData = organRepository.findByIdAndOrgi(organ, super.getOrgiByTenantshare(request)); + Organ organData = organRepository.findByIdAndOrgi(organ, super.getOrgi()); List organUserList = userRepository.findAll(chosen); for (final User user : organUserList) { OrganUser ou = organUserRes.findByUseridAndOrgan(user.getId(), organ); @@ -240,19 +223,18 @@ public class OrganController extends Handler { * 以下更新技能组状态 */ AgentStatus agentStatus = cache.findOneAgentStatusByAgentnoAndOrig( - user.getId(), super.getOrgiByTenantshare(request)); + user.getId(), super.getOrgi()); // TODO 因为一个用户可以包含在多个技能组中,所以,skill应该对应 // 一个List列表,此处需要重构Skill为列表 if (agentStatus != null) { userProxy.attachOrgansPropertiesForUser(user); agentStatus.setSkills(user.getSkills()); - cache.putAgentStatusByOrgi(agentStatus, super.getOrgiByTenantshare(request)); + cache.putAgentStatusByOrgi(agentStatus, super.getOrgi()); } } } userRepository.save(organUserList); - OnlineUserProxy.clean(super.getOrgi(request)); } return request(super.createRequestPageTempletResponse("redirect:/admin/organ/index.html?organ=" + organ)); @@ -264,11 +246,10 @@ public class OrganController extends Handler { final HttpServletRequest request, final @Valid String id, final @Valid String organ - ) { + ) { logger.info("[userroledelete] user id {}, organ {}", id, organ); if (id != null) { organUserRes.deleteOrganUserByUseridAndOrgan(id, organ); - OnlineUserProxy.clean(super.getOrgi(request)); } return request(super.createRequestPageTempletResponse("redirect:/admin/organ/index.html?organ=" + organ)); } @@ -277,13 +258,10 @@ public class OrganController extends Handler { @Menu(type = "admin", subtype = "organ") public ModelAndView edit(ModelMap map, HttpServletRequest request, @Valid String id) { ModelAndView view = request(super.createRequestPageTempletResponse("/admin/organ/edit")); - map.addAttribute("areaList", areaRepository.findByOrgi(super.getOrgiByTenantshare(request))); - view.addObject("organData", organRepository.findByIdAndOrgi(id, super.getOrgiByTenantshare(request))); + map.addAttribute("areaList", areaRepository.findByOrgi(super.getOrgi())); + view.addObject("organData", organRepository.findByIdAndOrgi(id, super.getOrgi())); - map.addAttribute( - "organList", organRepository.findByOrgiAndOrgid( - super.getOrgiByTenantshare(request), - super.getOrgid(request))); + map.addAttribute("organList", organRepository.findByOrgi(super.getOrgi())); return view; } @@ -306,7 +284,7 @@ public class OrganController extends Handler { } map.addAttribute("cacheList", Dict.getInstance().getDic(Constants.CSKEFU_SYSTEM_AREA_DIC)); - map.addAttribute("organData", organRepository.findByIdAndOrgi(id, super.getOrgiByTenantshare(request))); + map.addAttribute("organData", organRepository.findByIdAndOrgi(id, super.getOrgi())); return request(super.createRequestPageTempletResponse("/admin/organ/area")); } @@ -314,12 +292,11 @@ public class OrganController extends Handler { @RequestMapping("/area/update") @Menu(type = "admin", subtype = "organ") public ModelAndView areaupdate(HttpServletRequest request, @Valid Organ organ) { - Organ tempOrgan = organRepository.findByIdAndOrgi(organ.getId(), super.getOrgiByTenantshare(request)); + Organ tempOrgan = organRepository.findByIdAndOrgi(organ.getId(), super.getOrgi()); String msg = "admin_organ_update_success"; if (tempOrgan != null) { tempOrgan.setArea(organ.getArea()); organRepository.save(tempOrgan); - OnlineUserProxy.clean(super.getOrgi(request)); } else { msg = "admin_organ_update_not_exist"; } @@ -332,7 +309,7 @@ public class OrganController extends Handler { public ModelAndView delete(HttpServletRequest request, @Valid Organ organ) { String msg = "admin_organ_delete"; - Organ organSelf = organRepository.findByIdAndOrgi(organ.getId(), super.getOrgiByTenantshare(request)); + Organ organSelf = organRepository.findByIdAndOrgi(organ.getId(), super.getOrgi()); List organParentAre = organRepository.findByOrgiAndParent(organSelf.getOrgi(), organSelf.getId()); if (organ != null && organParentAre != null && organParentAre.size() > 0) { msg = "admin_oran_not_delete"; @@ -340,7 +317,6 @@ public class OrganController extends Handler { List organUsers = organUserRes.findByOrgan(organ.getId()); organUserRes.deleteInBatch(organUsers); organRepository.delete(organ); - OnlineUserProxy.clean(super.getOrgi(request)); } else { msg = "admin_organ_not_exist"; } @@ -350,8 +326,8 @@ public class OrganController extends Handler { @RequestMapping("/auth/save") @Menu(type = "admin", subtype = "role") public ModelAndView authsave(HttpServletRequest request, @Valid String id, @Valid String menus) { - Organ organData = organRepository.findByIdAndOrgi(id, super.getOrgiByTenantshare(request)); - List organRoleList = organRoleRes.findByOrgiAndOrgan(super.getOrgiByTenantshare(request), organData); + Organ organData = organRepository.findByIdAndOrgi(id, super.getOrgi()); + List organRoleList = organRoleRes.findByOrgiAndOrgan(super.getOrgi(), organData); organRoleRes.delete(organRoleList); if (!StringUtils.isBlank(menus)) { String[] menusarray = menus.split(","); @@ -364,7 +340,7 @@ public class OrganController extends Handler { organRole.setOrgan(organData); organRole.setCreater(super.getUser(request).getId()); - organRole.setOrgi(super.getOrgiByTenantshare(request)); + organRole.setOrgi(super.getOrgi(request)); organRole.setCreatetime(new Date()); organRoleRes.save(organRole); } diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/RoleController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/RoleController.java index ea3e64fe..7daf12b5 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/RoleController.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/RoleController.java @@ -61,7 +61,7 @@ public class RoleController extends Handler { @RequestMapping("/index") @Menu(type = "admin", subtype = "role") public ModelAndView index(ModelMap map, HttpServletRequest request, @Valid String role, @Valid String msg) { - List roleList = roleRepository.findByOrgiAndOrgid(super.getOrgiByTenantshare(request), super.getOrgid(request)); + List roleList = roleRepository.findByOrgi(super.getOrgi()); map.addAttribute("roleList", roleList); map.addAttribute("msg", msg); if (roleList.size() > 0) { @@ -77,7 +77,7 @@ public class RoleController extends Handler { map.addAttribute("roleData", roleData = roleList.get(0)); } if (roleData != null) { - map.addAttribute("userRoleList", userRoleRes.findByOrgiAndRole(super.getOrgiByTenantshare(request), roleData, new PageRequest(super.getP(request), super.getPs(request)))); + map.addAttribute("userRoleList", userRoleRes.findByOrgiAndRole(super.getOrgi(), roleData, new PageRequest(super.getP(request), super.getPs(request)))); } } return request(super.createAdminTempletResponse("/admin/role/index")); @@ -92,22 +92,15 @@ public class RoleController extends Handler { @RequestMapping("/save") @Menu(type = "admin", subtype = "role") public ModelAndView save(HttpServletRequest request, @Valid Role role) { - Role tempRole = roleRepository.findByNameAndOrgiAndOrgid(role.getName(), super.getOrgiByTenantshare(request), super.getOrgid(request)); + Role tempRole = roleRepository.findByNameAndOrgi(role.getName(), super.getOrgi()); String msg = "admin_role_save_success"; if (tempRole != null) { msg = "admin_role_save_exist"; } else { - role.setOrgi(super.getOrgiByTenantshare(request)); + role.setOrgi(super.getOrgi()); role.setCreater(super.getUser(request).getId()); role.setCreatetime(new Date()); role.setUpdatetime(new Date()); - - if (StringUtils.isNotBlank(super.getUser(request).getOrgid())) { - role.setOrgid(super.getUser(request).getOrgid()); - } else { - role.setOrgid(MainContext.SYSTEM_ORGI); - } - roleRepository.save(role); } return request(super.createRequestPageTempletResponse("redirect:/admin/role/index.html?msg=" + msg)); @@ -116,9 +109,9 @@ public class RoleController extends Handler { @RequestMapping("/seluser") @Menu(type = "admin", subtype = "seluser", admin = true) public ModelAndView seluser(ModelMap map, HttpServletRequest request, @Valid String role) { - map.addAttribute("userList", userRepository.findByOrgiAndDatastatusAndOrgid(super.getOrgiByTenantshare(request), false, super.getOrgid(request))); - Role roleData = roleRepository.findByIdAndOrgi(role, super.getOrgiByTenantshare(request)); - map.addAttribute("userRoleList", userRoleRes.findByOrgiAndRole(super.getOrgiByTenantshare(request), roleData)); + map.addAttribute("userList", userRepository.findByOrgiAndDatastatus(super.getOrgi(), false)); + Role roleData = roleRepository.findByIdAndOrgi(role, super.getOrgi()); + map.addAttribute("userRoleList", userRoleRes.findByOrgiAndRole(super.getOrgi(), roleData)); map.addAttribute("role", roleData); return request(super.createRequestPageTempletResponse("/admin/role/seluser")); } @@ -127,8 +120,8 @@ public class RoleController extends Handler { @RequestMapping("/saveuser") @Menu(type = "admin", subtype = "saveuser", admin = true) public ModelAndView saveuser(HttpServletRequest request, @Valid String[] users, @Valid String role) { - Role roleData = roleRepository.findByIdAndOrgi(role, super.getOrgiByTenantshare(request)); - List userRoleList = userRoleRes.findByOrgiAndRole(super.getOrgiByTenantshare(request), roleData); + Role roleData = roleRepository.findByIdAndOrgi(role, super.getOrgi()); + List userRoleList = userRoleRes.findByOrgiAndRole(super.getOrgi(), roleData); if (users != null && users.length > 0) { for (String user : users) { boolean exist = false; @@ -142,7 +135,7 @@ public class RoleController extends Handler { UserRole userRole = new UserRole(); userRole.setUser(new User(user)); userRole.setRole(new Role(role)); - userRole.setOrgi(super.getOrgiByTenantshare(request)); + userRole.setOrgi(super.getOrgi()); userRole.setCreater(super.getUser(request).getId()); userRoleRes.save(userRole); } @@ -164,27 +157,20 @@ public class RoleController extends Handler { @Menu(type = "admin", subtype = "role") public ModelAndView edit(ModelMap map, HttpServletRequest request, @Valid String id) { ModelAndView view = request(super.createRequestPageTempletResponse("/admin/role/edit")); - view.addObject("roleData", roleRepository.findByIdAndOrgi(id, super.getOrgiByTenantshare(request))); + view.addObject("roleData", roleRepository.findByIdAndOrgi(id, super.getOrgi())); return view; } @RequestMapping("/update") @Menu(type = "admin", subtype = "role") public ModelAndView update(HttpServletRequest request, @Valid Role role) { - Role tempRoleExist = roleRepository.findByNameAndOrgi(role.getName(), super.getOrgiByTenantshare(request)); + Role tempRoleExist = roleRepository.findByNameAndOrgi(role.getName(), super.getOrgi()); String msg = ""; if (tempRoleExist == null) { msg = "admin_role_update_success"; - Role tempRole = roleRepository.findByIdAndOrgi(role.getId(), super.getOrgiByTenantshare(request)); + Role tempRole = roleRepository.findByIdAndOrgi(role.getId(), super.getOrgi()); tempRole.setName(role.getName()); tempRole.setUpdatetime(new Date()); - - if (StringUtils.isNotBlank(super.getUser(request).getOrgid())) { - tempRole.setOrgid(super.getUser(request).getOrgid()); - } else { - tempRole.setOrgid(MainContext.SYSTEM_ORGI); - } - roleRepository.save(tempRole); } else if (!role.getId().equals(tempRoleExist.getId())) { msg = "admin_role_update_not_exist"; @@ -197,7 +183,7 @@ public class RoleController extends Handler { public ModelAndView delete(HttpServletRequest request, @Valid Role role) { String msg = "admin_role_delete"; if (role != null) { - userRoleRes.delete(userRoleRes.findByOrgiAndRole(super.getOrgiByTenantshare(request), role)); + userRoleRes.delete(userRoleRes.findByOrgiAndRole(super.getOrgi(), role)); roleRepository.delete(role); } else { msg = "admin_role_not_exist"; @@ -214,18 +200,18 @@ public class RoleController extends Handler { map.addAttribute("resourceList", sysDicRes.findByDicid(sysDic.getId())); } map.addAttribute("sysDic", sysDic); - Role role = roleRepository.findByIdAndOrgi(id, super.getOrgiByTenantshare(request)); + Role role = roleRepository.findByIdAndOrgi(id, super.getOrgi()); map.addAttribute("role", role); - map.addAttribute("roleAuthList", roleAuthRes.findByRoleidAndOrgi(role.getId(), super.getOrgiByTenantshare(request))); + map.addAttribute("roleAuthList", roleAuthRes.findByRoleidAndOrgi(role.getId(), super.getOrgi())); return request(super.createRequestPageTempletResponse("/admin/role/auth")); } @RequestMapping("/auth/save") @Menu(type = "admin", subtype = "role") public ModelAndView authsave(HttpServletRequest request, @Valid String id, @Valid String menus) { - logger.info("[authsave] id {}, menus {}", id, menus); + // logger.info("[authsave] id {}, menus {}", id, menus); - List roleAuthList = roleAuthRes.findByRoleidAndOrgi(id, super.getOrgiByTenantshare(request)); + List roleAuthList = roleAuthRes.findByRoleidAndOrgi(id, super.getOrgi()); roleAuthRes.delete(roleAuthList); if (StringUtils.isNotBlank(menus)) { String[] menuarray = menus.split(","); @@ -242,7 +228,7 @@ public class RoleController extends Handler { if (sysDic != null && (!StringUtils.equals(sysDic.getParentid(), "0"))) { logger.debug("[authsave] get sysdict {}, code {}, name {}, parent {}", sysDic.getId(), sysDic.getCode(), sysDic.getName(), sysDic.getParentid()); roleAuth.setCreater(super.getUser(request).getId()); - roleAuth.setOrgi(super.getOrgiByTenantshare(request)); + roleAuth.setOrgi(super.getOrgi()); roleAuth.setCreatetime(new Date()); roleAuth.setName(sysDic.getName()); roleAuth.setDicvalue(sysDic.getCode()); @@ -253,4 +239,4 @@ public class RoleController extends Handler { } return request(super.createRequestPageTempletResponse("redirect:/admin/role/index.html?role=" + id)); } -} \ No newline at end of file +} diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/UsersController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/UsersController.java index 0cdcf5cd..97480359 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/UsersController.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/UsersController.java @@ -16,12 +16,17 @@ */ package com.chatopera.cc.controller.admin; +import com.chatopera.cc.basic.Constants; +import com.chatopera.cc.basic.MainContext; import com.chatopera.cc.controller.Handler; +import com.chatopera.cc.model.Organ; +import com.chatopera.cc.model.OrganUser; import com.chatopera.cc.model.User; import com.chatopera.cc.model.UserRole; -import com.chatopera.cc.persistence.repository.UserRepository; -import com.chatopera.cc.persistence.repository.UserRoleRepository; +import com.chatopera.cc.persistence.repository.*; import com.chatopera.cc.proxy.OnlineUserProxy; +import com.chatopera.cc.proxy.OrganProxy; +import com.chatopera.cc.proxy.UserProxy; import com.chatopera.cc.util.Menu; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -37,6 +42,7 @@ import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; import java.io.IOException; import java.util.List; +import java.util.Map; /** * @author 程序猿DD @@ -54,24 +60,49 @@ public class UsersController extends Handler { @Autowired private UserRoleRepository userRoleRes; + @Autowired + OrganProxy organProxy; + + @Autowired + UserProxy userProxy; + + @Autowired + private OrganUserRepository organUserRes; + + @Autowired + private PbxHostRepository pbxHostRes; + + @Autowired + private ExtensionRepository extensionRes; + @RequestMapping("/index") @Menu(type = "admin", subtype = "user") public ModelAndView index(ModelMap map, HttpServletRequest request) throws IOException { - map.addAttribute( - "userList", - userRepository.findByDatastatusAndOrgiAndOrgidAndSuperadminNot( - false, - super.getOrgiByTenantshare(request), - super.getOrgid(request), - true, - new PageRequest( - super.getP(request), - super.getPs(request), - Sort.Direction.ASC, - "createtime" - ) - ) - ); + User logined = super.getUser(request); + if (!logined.isSuperadmin()) { + Map organs = organProxy.findAllOrganByParentAndOrgi(super.getOrgan(request), super.getOrgi(request)); + map.addAttribute("userList", userProxy.findUserInOrgans(organs.keySet(), new PageRequest( + super.getP(request), + super.getPs(request), + Sort.Direction.ASC, + "createtime" + ))); + } else { + map.addAttribute( + "userList", + userRepository.findByDatastatusAndOrgiAndSuperadminNot( + false, + super.getOrgi(), + true, + new PageRequest( + super.getP(request), + super.getPs(request), + Sort.Direction.ASC, + "createtime" + ) + ) + ); + } return request(super.createAdminTempletResponse("/admin/user/index")); } @@ -85,7 +116,20 @@ public class UsersController extends Handler { @Menu(type = "admin", subtype = "user") public ModelAndView edit(ModelMap map, HttpServletRequest request, @Valid String id) { ModelAndView view = request(super.createRequestPageTempletResponse("/admin/user/edit")); - view.addObject("userData", userRepository.findByIdAndOrgi(id, super.getOrgiByTenantshare(request))); + User user = userRepository.findById(id); + if (user != null && MainContext.hasModule(Constants.CSKEFU_MODULE_CALLCENTER)) { + // 加载呼叫中心信息 + extensionRes.findByAgentnoAndOrgi(user.getId(), user.getOrgi()).ifPresent(p -> { + user.setExtensionId(p.getId()); + user.setExtension(p); + + pbxHostRes.findById(p.getHostid()).ifPresent(b -> { + user.setPbxhostId(b.getId()); + user.setPbxHost(b); + }); + }); + } + view.addObject("userData", user); return view; } @@ -94,12 +138,19 @@ public class UsersController extends Handler { public ModelAndView delete(HttpServletRequest request, @Valid User user) { String msg = "admin_user_delete"; if (user != null) { - List userRole = userRoleRes.findByOrgiAndUser(super.getOrgiByTenantshare(request), user); - userRoleRes.delete(userRole); //删除用户的时候,同时删除用户对应的 - user = userRepository.getOne(user.getId()); - user.setDatastatus(true); - userRepository.save(user); - OnlineUserProxy.clean(super.getOrgi(request)); + User dbUser = userRepository.getOne(user.getId()); + if (dbUser.isSuperadmin()) { + msg = "admin_user_abandoned"; + } else { + // 删除用户的时候,同时删除用户对应的权限数据 + List userRole = userRoleRes.findByOrgiAndUser(super.getOrgi(), user); + userRoleRes.delete(userRole); + // 删除用户对应的组织机构关系 + List organUsers = organUserRes.findByUserid(user.getId()); + organUserRes.delete(organUsers); + + userRepository.delete(dbUser); + } } else { msg = "admin_user_not_exist"; } diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterAclController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterAclController.java deleted file mode 100644 index 4893448e..00000000 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterAclController.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (C) 2017 优客服-多渠道客服系统 - * Modifications copyright (C) 2018-2019 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.controller.admin.callcenter; - -import com.chatopera.cc.controller.Handler; -import com.chatopera.cc.model.Acl; -import com.chatopera.cc.persistence.repository.AclRepository; -import com.chatopera.cc.persistence.repository.PbxHostRepository; -import com.chatopera.cc.util.Menu; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; - -@Controller -@RequestMapping("/admin/callcenter") -public class CallCenterAclController extends Handler { - - @Autowired - private PbxHostRepository pbxHostRes ; - - @Autowired - private AclRepository aclRes ; - - @RequestMapping(value = "/acl") - @Menu(type = "callcenter" , subtype = "callcenteracl" , access = false , admin = true) - public ModelAndView acl(ModelMap map , HttpServletRequest request , @Valid String hostid) { - if(!StringUtils.isBlank(hostid)){ - map.addAttribute("pbxHost" , pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); - map.addAttribute("aclList" , aclRes.findByHostidAndOrgi(hostid, super.getOrgi(request))); - } - return request(super.createRequestPageTempletResponse("/admin/callcenter/acl/index")); - } - - @RequestMapping(value = "/acl/add") - @Menu(type = "callcenter" , subtype = "acl" , access = false , admin = true) - public ModelAndView acladd(ModelMap map , HttpServletRequest request , @Valid String hostid) { - map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))) ; - return request(super.createRequestPageTempletResponse("/admin/callcenter/acl/add")); - } - - @RequestMapping(value = "/acl/save") - @Menu(type = "callcenter" , subtype = "acl" , access = false , admin = true) - public ModelAndView aclsave(ModelMap map , HttpServletRequest request , @Valid Acl acl) { - if(!StringUtils.isBlank(acl.getName())){ - int count = aclRes.countByNameAndOrgi(acl.getName(), super.getOrgi(request)) ; - if(count == 0){ - acl.setOrgi(super.getOrgi(request)); - acl.setCreater(super.getUser(request).getId()); - aclRes.save(acl) ; - } - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/acl.html?hostid="+acl.getHostid())); - } - - @RequestMapping(value = "/acl/edit") - @Menu(type = "callcenter" , subtype = "acl" , access = false , admin = true) - public ModelAndView acledit(ModelMap map , HttpServletRequest request , @Valid String id , @Valid String hostid) { - map.addAttribute("acl" , aclRes.findByIdAndOrgi(id, super.getOrgi(request))); - map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))) ; - return request(super.createRequestPageTempletResponse("/admin/callcenter/acl/edit")); - } - - @RequestMapping(value = "/acl/update") - @Menu(type = "callcenter" , subtype = "acl" , access = false , admin = true) - public ModelAndView pbxhostupdate(ModelMap map , HttpServletRequest request , @Valid Acl acl) { - if(!StringUtils.isBlank(acl.getId())){ - Acl oldAcl = aclRes.findByIdAndOrgi(acl.getId(), super.getOrgi(request)) ; - if(oldAcl!=null){ - oldAcl.setName(acl.getName()); - oldAcl.setDefaultvalue(acl.getDefaultvalue()); - oldAcl.setStrategy(acl.getStrategy()); - aclRes.save(oldAcl); - } - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/acl.html?hostid="+acl.getHostid())); - } - - @RequestMapping(value = "/acl/delete") - @Menu(type = "callcenter" , subtype = "acl" , access = false , admin = true) - public ModelAndView acldelete(ModelMap map , HttpServletRequest request , @Valid String id , @Valid String hostid) { - if(!StringUtils.isBlank(id)){ - aclRes.delete(id); - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/acl.html?hostid="+hostid)); - } -} diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterBlackController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterBlackController.java deleted file mode 100644 index 3e6049c3..00000000 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterBlackController.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (C) 2017 优客服-多渠道客服系统 - * Modifications copyright (C) 2018-2019 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.controller.admin.callcenter; - -import com.chatopera.cc.basic.MainContext; -import com.chatopera.cc.controller.Handler; -import com.chatopera.cc.model.BlackEntity; -import com.chatopera.cc.persistence.repository.BlackListRepository; -import com.chatopera.cc.util.Menu; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; - -@Controller -@RequestMapping("/admin/callcenter") -public class CallCenterBlackController extends Handler{ - - @Autowired - private BlackListRepository blackRes ; - - @RequestMapping(value = "/black") - @Menu(type = "callcenter" , subtype = "callcenterblack" , access = false , admin = true) - public ModelAndView black(ModelMap map , HttpServletRequest request , @Valid String hostid) { - map.addAttribute("blackList" , blackRes.findByOrgi(super.getOrgi(request))); - return request(super.createRequestPageTempletResponse("/admin/callcenter/black/index")); - } - - @RequestMapping(value = "/black/add") - @Menu(type = "callcenter" , subtype = "black" , access = false , admin = true) - public ModelAndView blackadd(ModelMap map , HttpServletRequest request , @Valid String hostid) { - return request(super.createRequestPageTempletResponse("/admin/callcenter/black/add")); - } - - @RequestMapping(value = "/black/save") - @Menu(type = "callcenter" , subtype = "black" , access = false , admin = true) - public ModelAndView blacksave(ModelMap map , HttpServletRequest request , @Valid String phones) { - if(!StringUtils.isBlank(phones)){ - String[] ps = phones.split("[ ,,\t\n]") ; - for(String ph : ps){ - if(ph.length() >= 3){ - int count = blackRes.countByPhoneAndOrgi(ph.trim(), super.getOrgi(request)) ; - if(count == 0){ - BlackEntity be = new BlackEntity(); - be.setPhone(ph.trim()); - be.setChannel(MainContext.ChannelType.PHONE.toString()); - be.setOrgi(super.getOrgi(request)); - be.setCreater(super.getUser(request).getId()); - blackRes.save(be) ; - } - } - } - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/black.html")); - } - - @RequestMapping(value = "/black/edit") - @Menu(type = "callcenter" , subtype = "black" , access = false , admin = true) - public ModelAndView blackedit(ModelMap map , HttpServletRequest request , @Valid String id) { - map.addAttribute("black" , blackRes.findByIdAndOrgi(id, super.getOrgi(request))); - return request(super.createRequestPageTempletResponse("/admin/callcenter/black/edit")); - } - - @RequestMapping(value = "/black/update") - @Menu(type = "callcenter" , subtype = "black" , access = false , admin = true) - public ModelAndView pbxhostupdate(ModelMap map , HttpServletRequest request , @Valid BlackEntity black) { - if(!StringUtils.isBlank(black.getId())){ - BlackEntity oldBlack = blackRes.findByIdAndOrgi(black.getId(), super.getOrgi(request)) ; - if(oldBlack!=null){ - oldBlack.setPhone(black.getPhone()); - oldBlack.setChannel(MainContext.ChannelType.PHONE.toString()); - oldBlack.setOrgi(super.getOrgi(request)); - blackRes.save(oldBlack); - } - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/black.html")); - } - - @RequestMapping(value = "/black/delete") - @Menu(type = "callcenter" , subtype = "black" , access = false , admin = true) - public ModelAndView blackdelete(ModelMap map , HttpServletRequest request , @Valid String id) { - if(!StringUtils.isBlank(id)){ - blackRes.delete(id); - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/black.html")); - } -} diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterController.java deleted file mode 100644 index 4950e0e9..00000000 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterController.java +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright (C) 2017 优客服-多渠道客服系统 - * Modifications copyright (C) 2018-2019 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.controller.admin.callcenter; - -import com.chatopera.cc.basic.Constants; -import com.chatopera.cc.basic.MainContext; -import com.chatopera.cc.controller.Handler; -import com.chatopera.cc.model.PbxHost; -import com.chatopera.cc.persistence.interfaces.CallCenterInterface; -import com.chatopera.cc.persistence.repository.PbxHostRepository; -import com.chatopera.cc.util.Menu; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; -import java.util.List; - -@Controller -@RequestMapping("/admin/callcenter") -public class CallCenterController extends Handler { - - @Autowired - private PbxHostRepository pbxHostRes; - - @RequestMapping(value = "/index") - @Menu(type = "callcenter", subtype = "callcenter", access = false, admin = true) - public ModelAndView index(ModelMap map, HttpServletRequest request, @Valid String msg) { - List pbxHostList = pbxHostRes.findByOrgi(super.getOrgi(request)); - if (MainContext.hasModule(Constants.CSKEFU_MODULE_CALLCENTER)) { - CallCenterInterface callCenterImpl = (CallCenterInterface) MainContext.getContext().getBean("callcenter"); - - for (PbxHost pbxHost : pbxHostList) { - if (callCenterImpl != null) { - pbxHost.setConnected(callCenterImpl.connected(pbxHost.getId())); - } - } - } - map.addAttribute("pbxHostList", pbxHostList); - return request(super.createAdminTempletResponse("/admin/callcenter/index")); - } - - @RequestMapping(value = "/pbxhost") - @Menu(type = "callcenter", subtype = "pbxhost", access = false, admin = true) - public ModelAndView pbxhost(ModelMap map, HttpServletRequest request) { - List pbxHostList = pbxHostRes.findByOrgi(super.getOrgi(request)); - if (MainContext.hasModule(Constants.CSKEFU_MODULE_CALLCENTER)) { - CallCenterInterface callCenterImpl = (CallCenterInterface) MainContext.getContext().getBean("callcenter"); - - for (PbxHost pbxHost : pbxHostList) { - if (callCenterImpl != null) { - pbxHost.setConnected(callCenterImpl.connected(pbxHost.getId())); - } - } - } - map.addAttribute("pbxHostList", pbxHostList); - return request(super.createRequestPageTempletResponse("/admin/callcenter/pbxhost/index")); - } - - @RequestMapping(value = "/pbxhost/add") - @Menu(type = "callcenter", subtype = "pbxhost", access = false, admin = true) - public ModelAndView pbxhostadd(ModelMap map, HttpServletRequest request) { - return request(super.createRequestPageTempletResponse("/admin/callcenter/pbxhost/add")); - } - - @RequestMapping(value = "/pbxhost/save") - @Menu(type = "callcenter", subtype = "pbxhost", access = false, admin = true) - public ModelAndView pbxhostsave(ModelMap map, HttpServletRequest request, @Valid PbxHost pbxHost) { - ModelAndView view = request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/pbxhost.html")); - String msg = null; - if (!StringUtils.isBlank(pbxHost.getName())) { - int count = pbxHostRes.countByHostnameAndOrgi(pbxHost.getHostname(), super.getOrgi(request)); - if (count == 0) { - pbxHost.setOrgi(super.getOrgi(request)); - pbxHost.setCreater(super.getUser(request).getId()); - pbxHostRes.save(pbxHost); - if (MainContext.hasModule(Constants.CSKEFU_MODULE_CALLCENTER)) { - CallCenterInterface callCenterImpl = (CallCenterInterface) MainContext.getContext().getBean( - "callcenter"); - if (callCenterImpl != null) { - try { - callCenterImpl.init(pbxHost); - } catch (Exception ex) { - msg = ex.getMessage(); - ex.printStackTrace(); - } - } - } - } - } - if (!StringUtils.isBlank(msg)) { - view = request( - super.createRequestPageTempletResponse("redirect:/admin/callcenter/pbxhost.html?msg=" + msg)); - } - return view; - } - - @RequestMapping(value = "/pbxhost/edit") - @Menu(type = "callcenter", subtype = "pbxhost", access = false, admin = true) - public ModelAndView pbxhostedit(ModelMap map, HttpServletRequest request, @Valid String id) { - map.addAttribute("pbxHost", pbxHostRes.findByIdAndOrgi(id, super.getOrgi(request))); - return request(super.createRequestPageTempletResponse("/admin/callcenter/pbxhost/edit")); - } - - @RequestMapping(value = "/pbxhost/update") - @Menu(type = "callcenter", subtype = "pbxhost", access = false, admin = true) - public ModelAndView pbxhostupdate(ModelMap map, HttpServletRequest request, @Valid PbxHost pbxHost) { - ModelAndView view = request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/pbxhost.html")); - String msg = null; - if (!StringUtils.isBlank(pbxHost.getId())) { - PbxHost destHost = pbxHostRes.findByIdAndOrgi(pbxHost.getId(), super.getOrgi(request)); - destHost.setHostname(pbxHost.getHostname()); - destHost.setIpaddr(pbxHost.getIpaddr()); - destHost.setName(pbxHost.getName()); - destHost.setPort(pbxHost.getPort()); - if (!StringUtils.isBlank(pbxHost.getPassword())) { - destHost.setPassword(pbxHost.getPassword()); - } - pbxHostRes.save(destHost); - if (MainContext.hasModule(Constants.CSKEFU_MODULE_CALLCENTER)) { - CallCenterInterface callCenterImpl = (CallCenterInterface) MainContext.getContext().getBean( - "callcenter"); - if (callCenterImpl != null) { - try { - callCenterImpl.init(destHost); - } catch (Exception ex) { - msg = ex.getMessage(); - ex.printStackTrace(); - } - } - } - } - if (!StringUtils.isBlank(msg)) { - view = request( - super.createRequestPageTempletResponse("redirect:/admin/callcenter/pbxhost.html?msg=" + msg)); - } - return view; - } - - @RequestMapping(value = "/pbxhost/delete") - @Menu(type = "callcenter", subtype = "pbxhost", access = false, admin = true) - public ModelAndView mediadelete(ModelMap map, HttpServletRequest request, @Valid String id) { - if (!StringUtils.isBlank(id)) { - pbxHostRes.delete(id); - if (MainContext.hasModule(Constants.CSKEFU_MODULE_CALLCENTER)) { - CallCenterInterface callCenterImpl = (CallCenterInterface) MainContext.getContext().getBean( - "callcenter"); - if (callCenterImpl != null) { - callCenterImpl.remove(id); - } - } - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/pbxhost.html")); - } -} diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterExtentionController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterExtentionController.java deleted file mode 100644 index b8f805a6..00000000 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterExtentionController.java +++ /dev/null @@ -1,248 +0,0 @@ -/* - * Copyright (C) 2017 优客服-多渠道客服系统 - * Modifications copyright (C) 2018-2019 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.controller.admin.callcenter; - -import com.chatopera.cc.cache.Cache; -import com.chatopera.cc.controller.Handler; -import com.chatopera.cc.model.Extention; -import com.chatopera.cc.model.PbxHost; -import com.chatopera.cc.model.User; -import com.chatopera.cc.persistence.repository.*; -import com.chatopera.cc.proxy.CallcenterOutboundProxy; -import com.chatopera.cc.util.Menu; -import com.chatopera.cc.util.freeswitch.model.CallCenterAgent; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; -import java.util.Date; -import java.util.List; - -@Controller -@RequestMapping("/admin/callcenter") -public class CallCenterExtentionController extends Handler { - - @Autowired - private PbxHostRepository pbxHostRes; - - @Autowired - private ExtentionRepository extentionRes; - - @Autowired - private SipTrunkRepository sipTrunkRes; - - @Autowired - private MediaRepository mediaRes; - - @Autowired - private ServiceAiRepository serviceAiRes; - - @Autowired - private ProductRepository productRes; - - @Autowired - private QueSurveyProcessRepository queSurveyProcessRes; - - @Autowired - private Cache cache; - - - @RequestMapping(value = "/extention") - @Menu(type = "callcenter", subtype = "callcenterresource", access = false, admin = true) - public ModelAndView extention(ModelMap map, HttpServletRequest request, @Valid String hostid) { - List pbxHostList = pbxHostRes.findByOrgi(super.getOrgi(request)); - map.addAttribute("pbxHostList", pbxHostList); - PbxHost pbxHost = null; - if (pbxHostList.size() > 0) { - map.addAttribute("pbxHost", pbxHost = getPbxHost(pbxHostList, hostid)); - map.addAttribute("extentionList", extentionRes.findByHostidAndOrgi(pbxHost.getId(), super.getOrgi(request))); - } - return request(super.createRequestPageTempletResponse("/admin/callcenter/extention/index")); - } - - private PbxHost getPbxHost(List pbxHostList, String hostid) { - PbxHost pbxHost = pbxHostList.get(0); - if (StringUtils.isNotBlank(hostid)) { - for (PbxHost pbx : pbxHostList) { - if (pbx.getId().equals(hostid)) { - pbxHost = pbx; - break; - } - } - } - return pbxHost; - } - - @RequestMapping(value = "/extention/add") - @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) - public ModelAndView extentionadd(ModelMap map, HttpServletRequest request, @Valid String hostid) { - map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); - - map.addAttribute("sipTrunkListList", sipTrunkRes.findByHostidAndOrgi(hostid, super.getOrgi(request))); - - map.put("mediaList", mediaRes.findByHostidAndOrgi(hostid, super.getOrgi(request))); - return request(super.createRequestPageTempletResponse("/admin/callcenter/extention/add")); - } - - @RequestMapping(value = "/extention/save") - @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) - public ModelAndView extentionsave(ModelMap map, HttpServletRequest request, @Valid Extention extention) { - if (StringUtils.isNotBlank(extention.getExtention()) && StringUtils.isNotBlank(extention.getPassword())) { - String[] extstr = extention.getExtention().split("[,, ]"); - int extnum = 0; - for (String ext : extstr) { - if (ext.matches("[\\d]{3,8}")) { //分机号码最少3位数字 - createNewExtention(ext, super.getUser(request), extention.getHostid(), extention.getPassword(), super.getOrgi(request), extention); - } else { - String[] ph = ext.split("[~-]"); - if (ph.length == 2 && ph[0].matches("[\\d]{3,8}") && ph[1].matches("[\\d]{3,8}") && ph[0].length() == ph[1].length()) { - int start = Integer.parseInt(ph[0]); - int end = Integer.parseInt(ph[1]); - - for (int i = start; i <= end && extnum < 100; i++) { //最大一次批量生产的 分机号不超过100个 - createNewExtention(String.valueOf(i), super.getUser(request), extention.getHostid(), extention.getPassword(), super.getOrgi(request), extention); - } - } - } - } - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/extention.html?hostid=" + extention.getHostid())); - } - - private Extention createNewExtention(String num, User user, String hostid, String password, String orgi, Extention src) { - Extention extno = new Extention(); - extno.setExtention(num); - extno.setOrgi(orgi); - extno.setCreater(user.getId()); - extno.setHostid(hostid); - extno.setPassword(password); - - extno.setPlaynum(src.isPlaynum()); - extno.setCallout(src.isCallout()); - extno.setRecord(src.isRecord()); - extno.setExtype(src.getExtype()); - extno.setMediapath(src.getMediapath()); - - extno.setSiptrunk(src.getSiptrunk()); - extno.setEnablewebrtc(src.isEnablewebrtc()); - int count = extentionRes.countByExtentionAndHostidAndOrgi(extno.getExtention(), hostid, orgi); - if (count == 0) { - extentionRes.save(extno); - } - return extno; - } - - @RequestMapping(value = "/extention/edit") - @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) - public ModelAndView extentionedit(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String hostid) { - map.addAttribute("extention", extentionRes.findByIdAndOrgi(id, super.getOrgi(request))); - map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); - map.put("mediaList", mediaRes.findByHostidAndOrgi(hostid, super.getOrgi(request))); - map.addAttribute("sipTrunkListList", sipTrunkRes.findByHostidAndOrgi(hostid, super.getOrgi(request))); - - return request(super.createRequestPageTempletResponse("/admin/callcenter/extention/edit")); - } - - @RequestMapping(value = "/extention/update") - @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) - public ModelAndView extentionupdate(ModelMap map, HttpServletRequest request, @Valid Extention extention) { - if (StringUtils.isNotBlank(extention.getId())) { - Extention ext = extentionRes.findByIdAndOrgi(extention.getId(), super.getOrgi(request)); - if (ext != null) { -// ext.setExtention(extention.getExtention());//分机号不能修改 - if (StringUtils.isNotBlank(extention.getPassword())) { - ext.setPassword(extention.getPassword()); - } - ext.setPlaynum(extention.isPlaynum()); - ext.setCallout(extention.isCallout()); - ext.setRecord(extention.isRecord()); - ext.setExtype(extention.getExtype()); - ext.setSubtype(extention.getSubtype()); - ext.setDescription(extention.getDescription()); - - ext.setMediapath(extention.getMediapath()); - - ext.setSiptrunk(extention.getSiptrunk()); - ext.setEnablewebrtc(extention.isEnablewebrtc()); - - ext.setUpdatetime(new Date()); - extentionRes.save(ext); - - List callOutAgentList = CallcenterOutboundProxy.extention(ext.getExtention()); - for (CallCenterAgent callOutAgent : callOutAgentList) { - callOutAgent.setSiptrunk(ext.getSiptrunk()); - cache.putCallCenterAgentByIdAndOrgi(callOutAgent.getUserid(), callOutAgent.getOrgi(), callOutAgent); - } - } - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/extention.html?hostid=" + extention.getHostid())); - } - - @RequestMapping(value = "/extention/ivr") - @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) - public ModelAndView ivr(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String hostid) { - map.addAttribute("extention", extentionRes.findByIdAndOrgi(id, super.getOrgi(request))); - map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); - map.put("mediaList", mediaRes.findByHostidAndOrgi(hostid, super.getOrgi(request))); - map.addAttribute("sipTrunkListList", sipTrunkRes.findByHostidAndOrgi(hostid, super.getOrgi(request))); - - map.put("serviceAiList", serviceAiRes.findByOrgi(super.getOrgi(request))); - map.put("queList", queSurveyProcessRes.findByOrgi(super.getOrgi(request))); - map.put("productList", productRes.findByOrgi(super.getOrgi(request))); - - return request(super.createRequestPageTempletResponse("/admin/callcenter/extention/ivr")); - } - - @RequestMapping(value = "/extention/ivr/update") - @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) - public ModelAndView ivrupdate(ModelMap map, HttpServletRequest request, @Valid Extention extention) { - if (StringUtils.isNotBlank(extention.getId())) { - Extention ext = extentionRes.findByIdAndOrgi(extention.getId(), super.getOrgi(request)); - if (ext != null) { - - ext.setEnableai(extention.getEnableai()); - ext.setAiid(extention.getAiid()); - ext.setSceneid(extention.getSceneid()); - ext.setWelcomemsg(extention.getWelcomemsg()); - ext.setWaitmsg(extention.getWaitmsg()); - ext.setTipmessage(extention.getTipmessage()); - - ext.setAitype(extention.getAitype()); - ext.setBustype(extention.getBustype()); - ext.setProid(extention.getProid()); - ext.setQueid(extention.getQueid()); - - extentionRes.save(ext); - } - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/extention.html?hostid=" + extention.getHostid())); - } - - @RequestMapping(value = "/extention/delete") - @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) - public ModelAndView extentiondelete(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String hostid) { - if (StringUtils.isNotBlank(id)) { - extentionRes.delete(id); - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/extention.html?hostid=" + hostid)); - } -} diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterIvrController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterIvrController.java deleted file mode 100644 index 3f5e9834..00000000 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterIvrController.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (C) 2017 优客服-多渠道客服系统 - * Modifications copyright (C) 2018-2019 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.controller.admin.callcenter; - -import com.chatopera.cc.controller.Handler; -import com.chatopera.cc.model.Extention; -import com.chatopera.cc.persistence.repository.ExtentionRepository; -import com.chatopera.cc.persistence.repository.IvrMenuRepository; -import com.chatopera.cc.persistence.repository.PbxHostRepository; -import com.chatopera.cc.util.Menu; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; - -@Controller -@RequestMapping("/admin/callcenter") -public class CallCenterIvrController extends Handler{ - - @Autowired - private PbxHostRepository pbxHostRes ; - - @Autowired - private ExtentionRepository extentionRes ; - - @Autowired - private IvrMenuRepository ivrMenuRes; - - @RequestMapping(value = "/ivr") - @Menu(type = "callcenter" , subtype = "callcenterivr" , access = false , admin = true) - public ModelAndView ivr(ModelMap map , HttpServletRequest request , @Valid String hostid) { - if(!StringUtils.isBlank(hostid)){ - map.addAttribute("pbxHost" , pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); - map.addAttribute("ivrList" , extentionRes.findByExtypeAndOrgi("ivr", super.getOrgi(request))); - } - return request(super.createRequestPageTempletResponse("/admin/callcenter/ivr/index")); - } - - @RequestMapping(value = "/ivr/edit") - @Menu(type = "callcenter" , subtype = "extention" , access = false , admin = true) - public ModelAndView extentionedit(ModelMap map , HttpServletRequest request , @Valid String id , @Valid String hostid) { - map.addAttribute("extention" , extentionRes.findByIdAndOrgi(id, super.getOrgi(request))); - map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))) ; - return request(super.createRequestPageTempletResponse("/admin/callcenter/ivr/edit")); - } - - @RequestMapping(value = "/ivr/update") - @Menu(type = "callcenter" , subtype = "extention" , access = false , admin = true) - public ModelAndView extentionupdate(ModelMap map , HttpServletRequest request , @Valid Extention extention) { - if(!StringUtils.isBlank(extention.getId())){ - Extention ext = extentionRes.findByIdAndOrgi(extention.getId(), super.getOrgi(request)) ; - ext.setExtention(extention.getExtention()); - ext.setDescription(extention.getDescription()); - extentionRes.save(ext) ; - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/ivr.html?hostid="+extention.getHostid())); - } - - - @RequestMapping(value = "/ivr/delete") - @Menu(type = "callcenter" , subtype = "ivr" , access = false , admin = true) - public ModelAndView extentiondelete(ModelMap map , HttpServletRequest request , @Valid String id , @Valid String hostid) { - if(!StringUtils.isBlank(id)){ - extentionRes.delete(id); - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/ivr.html?hostid="+hostid)); - } - - @RequestMapping(value = "/ivr/design") - @Menu(type = "callcenter" , subtype = "callcenterivr" , access = false , admin = true) - public ModelAndView design(ModelMap map , HttpServletRequest request , @Valid String hostid , @Valid String id) { - if(!StringUtils.isBlank(hostid)){ - map.addAttribute("extention" , extentionRes.findByIdAndOrgi(id, super.getOrgi(request))); - map.addAttribute("ivrMenuList" , ivrMenuRes.findByExtentionidAndHostidAndOrgi(id, hostid, super.getOrgi(request))); - map.addAttribute("pbxHost" , pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); - } - return request(super.createRequestPageTempletResponse("/admin/callcenter/ivr/design")); - } - - @RequestMapping(value = "/ivr/menu/add") - @Menu(type = "callcenter" , subtype = "callcenterivr" , access = false , admin = true) - public ModelAndView ivrmenuadd(ModelMap map , HttpServletRequest request , @Valid String id , @Valid String hostid , @Valid String parentid) { - map.addAttribute("extention" , extentionRes.findByIdAndOrgi(id, super.getOrgi(request))); - map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))) ; - return request(super.createRequestPageTempletResponse("/admin/callcenter/ivr/menuadd")); - } -} diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterMediaController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterMediaController.java deleted file mode 100644 index 9a96a605..00000000 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterMediaController.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright (C) 2017 优客服-多渠道客服系统 - * Modifications copyright (C) 2018-2019 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.controller.admin.callcenter; - -import com.chatopera.cc.basic.MainUtils; -import com.chatopera.cc.controller.Handler; -import com.chatopera.cc.model.Media; -import com.chatopera.cc.persistence.repository.MediaRepository; -import com.chatopera.cc.persistence.repository.PbxHostRepository; -import com.chatopera.cc.util.Menu; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.util.FileCopyUtils; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.multipart.MultipartFile; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; -import java.io.File; -import java.io.IOException; - -@Controller -@RequestMapping("/admin/callcenter") -public class CallCenterMediaController extends Handler{ - - @Autowired - private PbxHostRepository pbxHostRes ; - - @Autowired - private MediaRepository mediaRes ; - - @Value("${web.upload-path}") - private String path; - - @RequestMapping(value = "/media") - @Menu(type = "callcenter" , subtype = "callcentermedia" , access = false , admin = true) - public ModelAndView media(ModelMap map , HttpServletRequest request , @Valid String hostid) { - if(!StringUtils.isBlank(hostid)){ - map.addAttribute("pbxHost" , pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); - map.addAttribute("mediaList" , mediaRes.findByHostidAndOrgi(hostid, super.getOrgi(request))); - } - return request(super.createRequestPageTempletResponse("/admin/callcenter/media/index")); - } - - @RequestMapping(value = "/media/add") - @Menu(type = "callcenter" , subtype = "media" , access = false , admin = true) - public ModelAndView mediaadd(ModelMap map , HttpServletRequest request , @Valid String hostid) { - map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))) ; - return request(super.createRequestPageTempletResponse("/admin/callcenter/media/add")); - } - - @RequestMapping(value = "/media/save") - @Menu(type = "callcenter" , subtype = "media" , access = false , admin = true) - public ModelAndView mediasave(ModelMap map , HttpServletRequest request , @RequestParam(value = "mediafile", required = false) MultipartFile mediafile) throws IOException { - Media media = new Media(); - media.setName(request.getParameter("name")); - media.setHostid(request.getParameter("hostid")); - if(!StringUtils.isBlank(media.getName())){ - int count = mediaRes.countByNameAndOrgi(media.getName(), super.getOrgi(request)) ; - if(count == 0){ - String fileName = "media/"+ MainUtils.getUUID()+mediafile.getOriginalFilename().substring(mediafile.getOriginalFilename().lastIndexOf(".")) ; - - media.setOrgi(super.getOrgi(request)); - media.setCreater(super.getUser(request).getId()); - media.setFilelength((int) mediafile.getSize()); - media.setContent(mediafile.getContentType()); - media.setFilename(fileName); - - if(mediafile!=null && mediafile.getOriginalFilename().lastIndexOf(".") > 0){ - File logoDir = new File(path , "media"); - if(!logoDir.exists()){ - logoDir.mkdirs() ; - } - FileCopyUtils.copy(mediafile.getBytes(), new File(path , fileName)); - } - - mediaRes.save(media) ; - } - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/media.html?hostid="+media.getHostid())); - } - - @RequestMapping(value = "/media/edit") - @Menu(type = "callcenter" , subtype = "media" , access = false , admin = true) - public ModelAndView mediaedit(ModelMap map , HttpServletRequest request , @Valid String id , @Valid String hostid) { - map.addAttribute("media" , mediaRes.findByIdAndOrgi(id, super.getOrgi(request))); - map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))) ; - return request(super.createRequestPageTempletResponse("/admin/callcenter/media/edit")); - } - - @RequestMapping(value = "/media/update") - @Menu(type = "callcenter" , subtype = "media" , access = false , admin = true) - public ModelAndView pbxhostupdate(ModelMap map , HttpServletRequest request , @RequestParam(value = "mediafile", required = false) MultipartFile mediafile) throws IOException { - Media media = new Media(); - media.setName(request.getParameter("name")); - media.setHostid(request.getParameter("hostid")); - media.setId(request.getParameter("id")); - if(!StringUtils.isBlank(media.getId())){ - Media oldMedia = mediaRes.findByIdAndOrgi(media.getId(), super.getOrgi(request)) ; - if(oldMedia!=null){ - if(mediafile!=null && mediafile.getSize() > 0){ - File wavFile = new File(path , oldMedia.getFilename()); - if(!wavFile.exists()){ - wavFile.deleteOnExit(); - } - - String fileName = "media/"+ MainUtils.getUUID()+mediafile.getOriginalFilename().substring(mediafile.getOriginalFilename().lastIndexOf(".")) ; - oldMedia.setFilename(fileName); - - if(mediafile!=null && mediafile.getOriginalFilename().lastIndexOf(".") > 0){ - File mediaDir = new File(path , "media"); - if(!mediaDir.exists()){ - mediaDir.mkdirs() ; - } - FileCopyUtils.copy(mediafile.getBytes(), new File(path , fileName)); - } - } - oldMedia.setName(media.getName()); - mediaRes.save(oldMedia); - } - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/media.html?hostid="+media.getHostid())); - } - - @RequestMapping(value = "/media/delete") - @Menu(type = "callcenter" , subtype = "media" , access = false , admin = true) - public ModelAndView mediadelete(ModelMap map , HttpServletRequest request , @Valid String id , @Valid String hostid) { - if(!StringUtils.isBlank(id)){ - mediaRes.delete(id); - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/media.html?hostid="+hostid)); - } - @RequestMapping(value = "/play") - @Menu(type = "callcenter" , subtype = "play" , access = false) - public ModelAndView play(ModelMap map , HttpServletRequest request ,@Valid final String id ,@Valid final String hostid) { - map.addAttribute("media", mediaRes.findByIdAndOrgi(id, super.getOrgi(request))) ; - return request(super.createRequestPageTempletResponse("/admin/callcenter/media/play")); - } -} diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterResourceController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterResourceController.java deleted file mode 100644 index 7d880c49..00000000 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterResourceController.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (C) 2017 优客服-多渠道客服系统 - * Modifications copyright (C) 2018-2019 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.controller.admin.callcenter; - -import com.chatopera.cc.basic.Constants; -import com.chatopera.cc.basic.MainContext; -import com.chatopera.cc.controller.Handler; -import com.chatopera.cc.model.PbxHost; -import com.chatopera.cc.persistence.interfaces.CallCenterInterface; -import com.chatopera.cc.persistence.repository.ExtentionRepository; -import com.chatopera.cc.persistence.repository.PbxHostRepository; -import com.chatopera.cc.persistence.repository.ServiceAiRepository; -import com.chatopera.cc.util.Menu; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; -import java.util.List; - -@Controller -@RequestMapping("/admin/callcenter") -public class CallCenterResourceController extends Handler { - - @Autowired - private PbxHostRepository pbxHostRes; - - @Autowired - private ExtentionRepository extentionRes; - - @Autowired - private ServiceAiRepository serviceAiRes; - - @RequestMapping(value = "/resource") - @Menu(type = "callcenter", subtype = "callcenter", access = false, admin = true) - public ModelAndView index(ModelMap map, HttpServletRequest request, @Valid String hostid) { - List pbxHostList = pbxHostRes.findByOrgi(super.getOrgi(request)); - map.addAttribute("pbxHostList", pbxHostList); - - map.put("serviceAiList", serviceAiRes.findByOrgi(super.getOrgi(request))); - - PbxHost pbxHost = null; - if (pbxHostList.size() > 0) { - map.addAttribute("pbxHost", pbxHost = getPbxHost(pbxHostList, hostid)); - map.addAttribute("extentionList", - extentionRes.findByHostidAndOrgi(pbxHost.getId(), super.getOrgi(request))); - } - return request(super.createAdminTempletResponse("/admin/callcenter/resource/index")); - } - - @RequestMapping(value = "/resource/config") - @Menu(type = "callcenter", subtype = "callcenter", access = false, admin = true) - public ModelAndView config(ModelMap map, HttpServletRequest request, @Valid String hostid) { - List pbxHostList = pbxHostRes.findByOrgi(super.getOrgi(request)); - map.addAttribute("pbxHostList", pbxHostList); - PbxHost pbxHost = null; - if (pbxHostList.size() > 0) { - map.addAttribute("pbxHost", pbxHost = getPbxHost(pbxHostList, hostid)); - map.addAttribute("extentionList", - extentionRes.findByHostidAndOrgi(pbxHost.getId(), super.getOrgi(request))); - } - return request(super.createRequestPageTempletResponse("/admin/callcenter/resource/config")); - } - - @RequestMapping(value = "/resource/save") - @Menu(type = "callcenter", subtype = "callcenter", access = false, admin = true) - public ModelAndView save(ModelMap map, HttpServletRequest request, @Valid PbxHost pbxHost) throws Exception { - PbxHost tempPbxHost = pbxHostRes.findByIdAndOrgi(pbxHost.getId(), super.getOrgi(request)); - if (tempPbxHost != null) { - pbxHost.setCreater(tempPbxHost.getCreater()); - pbxHost.setCreatetime(tempPbxHost.getCreatetime()); - if (StringUtils.isBlank(pbxHost.getPassword())) { - pbxHost.setPassword(tempPbxHost.getPassword()); - } - pbxHost.setOrgi(super.getOrgi(request)); - pbxHostRes.save(pbxHost); - - if (MainContext.hasModule(Constants.CSKEFU_MODULE_CALLCENTER)) { - CallCenterInterface callCenterImpl = (CallCenterInterface) MainContext.getContext().getBean( - "callcenter"); - callCenterImpl.init(pbxHost); - } - } - return request(super.createRequestPageTempletResponse( - "redirect:/admin/callcenter/resource.html?hostid=" + pbxHost.getId())); - } - - @RequestMapping(value = "/resource/pbxhost") - @Menu(type = "callcenter", subtype = "callcenter", access = false, admin = true) - public ModelAndView resourcepbx(ModelMap map, HttpServletRequest request, @Valid String hostid) { - List pbxHostList = pbxHostRes.findByOrgi(super.getOrgi(request)); - map.addAttribute("pbxHostList", pbxHostList); - PbxHost pbxHost = null; - if (pbxHostList.size() > 0) { - map.addAttribute("pbxHost", pbxHost = getPbxHost(pbxHostList, hostid)); - map.addAttribute("extentionList", - extentionRes.findByHostidAndOrgi(pbxHost.getId(), super.getOrgi(request))); - } - return request(super.createAdminTempletResponse("/admin/callcenter/resource/pbxhost")); - } - - private PbxHost getPbxHost(List pbxHostList, String hostid) { - PbxHost pbxHost = pbxHostList.get(0); - if (!StringUtils.isBlank(hostid)) { - for (PbxHost pbx : pbxHostList) { - if (pbx.getId().equals(hostid)) { - pbxHost = pbx; - break; - } - } - } - return pbxHost; - } - -} diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterRouterController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterRouterController.java deleted file mode 100644 index 7d75d8ef..00000000 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterRouterController.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (C) 2017 优客服-多渠道客服系统 - * Modifications copyright (C) 2018-2019 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.controller.admin.callcenter; - -import com.chatopera.cc.controller.Handler; -import com.chatopera.cc.model.PbxHost; -import com.chatopera.cc.model.RouterRules; -import com.chatopera.cc.persistence.repository.PbxHostRepository; -import com.chatopera.cc.persistence.repository.RouterRulesRepository; -import com.chatopera.cc.util.Menu; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; -import java.util.List; - -@Controller -@RequestMapping("/admin/callcenter") -public class CallCenterRouterController extends Handler{ - - @Autowired - private PbxHostRepository pbxHostRes ; - - - @Autowired - private RouterRulesRepository routerRulesRes ; - - - @RequestMapping(value = "/router") - @Menu(type = "callcenter" , subtype = "callcenterresource" , access = false , admin = true) - public ModelAndView skill(ModelMap map , HttpServletRequest request , @Valid String hostid) { - List pbxHostList = pbxHostRes.findByOrgi(super.getOrgi(request)) ; - map.addAttribute("pbxHostList" , pbxHostList); - if(pbxHostList.size() > 0){ - map.addAttribute("pbxHost" , pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); - map.addAttribute("routerRulesList" , routerRulesRes.findByHostidAndOrgi(hostid, super.getOrgi(request))); - } - return request(super.createRequestPageTempletResponse("/admin/callcenter/peer/index")); - } - - @RequestMapping(value = "/router/add") - @Menu(type = "callcenter" , subtype = "extention" , access = false , admin = true) - public ModelAndView extentionadd(ModelMap map , HttpServletRequest request , @Valid String hostid) { - map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))) ; - return request(super.createRequestPageTempletResponse("/admin/callcenter/peer/add")); - } - - @RequestMapping(value = "/router/save") - @Menu(type = "callcenter" , subtype = "extention" , access = false , admin = true) - public ModelAndView extentionsave(ModelMap map , HttpServletRequest request , @Valid RouterRules router) { - if(!StringUtils.isBlank(router.getName())){ - int count = routerRulesRes.countByNameAndOrgi(router.getName(), super.getOrgi(request)) ; - if(count == 0){ - router.setOrgi(super.getOrgi(request)); - router.setCreater(super.getUser(request).getId()); - routerRulesRes.save(router) ; - } - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/peer.html?hostid="+router.getHostid())); - } - - @RequestMapping(value = "/router/edit") - @Menu(type = "callcenter" , subtype = "extention" , access = false , admin = true) - public ModelAndView routeredit(ModelMap map , HttpServletRequest request , @Valid String id , @Valid String hostid) { - map.addAttribute("routerRules" , routerRulesRes.findByIdAndOrgi(id, super.getOrgi(request))); - map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))) ; - return request(super.createRequestPageTempletResponse("/admin/callcenter/peer/edit")); - } - - @RequestMapping(value = "/router/update") - @Menu(type = "callcenter" , subtype = "extention" , access = false , admin = true) - public ModelAndView pbxhostupdate(ModelMap map , HttpServletRequest request , @Valid RouterRules router) { - if(!StringUtils.isBlank(router.getId())){ - RouterRules oldRouter = routerRulesRes.findByIdAndOrgi(router.getId(), super.getOrgi(request)) ; - if(oldRouter!=null){ - oldRouter.setName(router.getName()); - oldRouter.setField(router.getField()); - oldRouter.setRegex(router.getRegex()); - oldRouter.setRouterinx(router.getRouterinx()); - oldRouter.setFalsebreak(router.isFalsebreak()); - routerRulesRes.save(oldRouter); - } - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/peer.html?hostid="+router.getHostid())); - } - - @RequestMapping(value = "/router/code") - @Menu(type = "callcenter" , subtype = "extention" , access = false , admin = true) - public ModelAndView routercode(ModelMap map , HttpServletRequest request , @Valid String id , @Valid String hostid) { - map.addAttribute("routerRules" , routerRulesRes.findByIdAndOrgi(id, super.getOrgi(request))); - map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))) ; - return request(super.createRequestPageTempletResponse("/admin/callcenter/peer/code")); - } - - @RequestMapping(value = "/router/code/update") - @Menu(type = "callcenter" , subtype = "extention" , access = false , admin = true) - public ModelAndView routercodeupdate(ModelMap map , HttpServletRequest request , @Valid RouterRules router) { - if(!StringUtils.isBlank(router.getId())){ - RouterRules oldRouter = routerRulesRes.findByIdAndOrgi(router.getId(), super.getOrgi(request)) ; - if(!StringUtils.isBlank(router.getRoutercontent())){ - oldRouter.setRoutercontent(router.getRoutercontent()); - routerRulesRes.save(oldRouter); - } - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/peer.html?hostid="+router.getHostid())); - } - - @RequestMapping(value = "/router/delete") - @Menu(type = "callcenter" , subtype = "extention" , access = false , admin = true) - public ModelAndView extentiondelete(ModelMap map , HttpServletRequest request , @Valid String id , @Valid String hostid) { - if(!StringUtils.isBlank(id)){ - routerRulesRes.delete(id); - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/peer.html?hostid="+hostid)); - } -} diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterSipTrunkController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterSipTrunkController.java deleted file mode 100644 index 4961f1aa..00000000 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterSipTrunkController.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright (C) 2017 优客服-多渠道客服系统 - * Modifications copyright (C) 2018-2019 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.controller.admin.callcenter; - -import com.chatopera.cc.cache.Cache; -import com.chatopera.cc.controller.Handler; -import com.chatopera.cc.model.SipTrunk; -import com.chatopera.cc.persistence.repository.PbxHostRepository; -import com.chatopera.cc.persistence.repository.SipTrunkRepository; -import com.chatopera.cc.util.Menu; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; - -@Controller -@RequestMapping("/admin/callcenter") -public class CallCenterSipTrunkController extends Handler { - - @Autowired - private PbxHostRepository pbxHostRes; - - @Autowired - private SipTrunkRepository sipTrunkRes; - - @Autowired - private Cache cache; - - @RequestMapping(value = "/siptrunk") - @Menu(type = "callcenter", subtype = "callcenterresource", access = false, admin = true) - public ModelAndView skill(ModelMap map, HttpServletRequest request, @Valid String hostid) { - if (!StringUtils.isBlank(hostid)) { - map.addAttribute("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); - map.addAttribute("sipTrunkListList", sipTrunkRes.findByHostidAndOrgi(hostid, super.getOrgi(request))); - } - return request(super.createRequestPageTempletResponse("/admin/callcenter/siptrunk/index")); - } - - @RequestMapping(value = "/siptrunk/add") - @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) - public ModelAndView extentionadd(ModelMap map, HttpServletRequest request, @Valid String hostid) { - map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); - return request(super.createRequestPageTempletResponse("/admin/callcenter/siptrunk/add")); - } - - @RequestMapping(value = "/siptrunk/save") - @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) - public ModelAndView extentionsave(ModelMap map, HttpServletRequest request, @Valid SipTrunk siptrunk) { - if (!StringUtils.isBlank(siptrunk.getName())) { - int count = sipTrunkRes.countByNameAndOrgi(siptrunk.getName(), super.getOrgi(request)); - if (count == 0) { - siptrunk.setOrgi(super.getOrgi(request)); - siptrunk.setCreater(super.getUser(request).getId()); - sipTrunkRes.save(siptrunk); - - cache.putSystemByIdAndOrgi(siptrunk.getId(), siptrunk.getOrgi(), siptrunk); - } - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/siptrunk.html?hostid=" + siptrunk.getHostid())); - } - - @RequestMapping(value = "/siptrunk/edit") - @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) - public ModelAndView siptrunkedit(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String hostid) { - map.addAttribute("siptrunk", sipTrunkRes.findByIdAndOrgi(id, super.getOrgi(request))); - map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); - return request(super.createRequestPageTempletResponse("/admin/callcenter/siptrunk/edit")); - } - - @RequestMapping(value = "/siptrunk/update") - @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) - public ModelAndView pbxhostupdate(ModelMap map, HttpServletRequest request, @Valid SipTrunk siptrunk) { - if (!StringUtils.isBlank(siptrunk.getId())) { - SipTrunk oldSipTrunk = sipTrunkRes.findByIdAndOrgi(siptrunk.getId(), super.getOrgi(request)); - if (oldSipTrunk != null) { - oldSipTrunk.setName(siptrunk.getName()); - oldSipTrunk.setSipserver(siptrunk.getSipserver()); - oldSipTrunk.setPort(siptrunk.getPort()); - oldSipTrunk.setProtocol(siptrunk.getProtocol()); - oldSipTrunk.setRegister(siptrunk.isRegister()); - oldSipTrunk.setDefaultsip(siptrunk.isDefaultsip()); - oldSipTrunk.setTitle(siptrunk.getTitle()); - - oldSipTrunk.setEnablecallagent(siptrunk.isEnablecallagent()); - - oldSipTrunk.setOutnumber(siptrunk.getOutnumber()); - oldSipTrunk.setBusyext(siptrunk.getBusyext()); - oldSipTrunk.setNotready(siptrunk.getNotready()); - - oldSipTrunk.setNoname(siptrunk.getNoname()); - - oldSipTrunk.setProvince(siptrunk.getProvince()); - oldSipTrunk.setCity(siptrunk.getCity()); - oldSipTrunk.setPrefix(siptrunk.getPrefix()); - - sipTrunkRes.save(oldSipTrunk); - cache.putSystemByIdAndOrgi(oldSipTrunk.getId(), oldSipTrunk.getOrgi(), oldSipTrunk); - } - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/siptrunk.html?hostid=" + siptrunk.getHostid())); - } - - @RequestMapping(value = "/siptrunk/code") - @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) - public ModelAndView siptrunkcode(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String hostid) { - map.addAttribute("siptrunk", sipTrunkRes.findByIdAndOrgi(id, super.getOrgi(request))); - map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); - return request(super.createRequestPageTempletResponse("/admin/callcenter/siptrunk/code")); - } - - @RequestMapping(value = "/siptrunk/code/update") - @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) - public ModelAndView siptrunkcodeupdate(ModelMap map, HttpServletRequest request, @Valid SipTrunk siptrunk) { - if (!StringUtils.isBlank(siptrunk.getId())) { - SipTrunk oldSipTrunk = sipTrunkRes.findByIdAndOrgi(siptrunk.getId(), super.getOrgi(request)); - if (!StringUtils.isBlank(siptrunk.getSipcontent())) { - oldSipTrunk.setSipcontent(siptrunk.getSipcontent()); - sipTrunkRes.save(oldSipTrunk); - cache.putSystemByIdAndOrgi(oldSipTrunk.getId(), oldSipTrunk.getOrgi(), oldSipTrunk); - } - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/siptrunk.html?hostid=" + siptrunk.getHostid())); - } - - @RequestMapping(value = "/siptrunk/delete") - @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) - public ModelAndView extentiondelete(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String hostid) { - if (!StringUtils.isBlank(id)) { - sipTrunkRes.delete(id); - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/siptrunk.html?hostid=" + hostid)); - } -} diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterSkillController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterSkillController.java deleted file mode 100644 index f83ce7e4..00000000 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterSkillController.java +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Copyright (C) 2017 优客服-多渠道客服系统 - * Modifications copyright (C) 2018-2019 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.controller.admin.callcenter; - -import com.chatopera.cc.controller.Handler; -import com.chatopera.cc.model.CallCenterSkill; -import com.chatopera.cc.model.Extention; -import com.chatopera.cc.model.PbxHost; -import com.chatopera.cc.model.SkillExtention; -import com.chatopera.cc.persistence.repository.CallCenterSkillRepository; -import com.chatopera.cc.persistence.repository.ExtentionRepository; -import com.chatopera.cc.persistence.repository.PbxHostRepository; -import com.chatopera.cc.persistence.repository.SkillExtentionRepository; -import com.chatopera.cc.util.Menu; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; -import java.util.Date; -import java.util.List; - -@Controller -@RequestMapping("/admin/callcenter") -public class CallCenterSkillController extends Handler { - - @Autowired - private PbxHostRepository pbxHostRes ; - - @Autowired - private ExtentionRepository extentionRes; - - @Autowired - private CallCenterSkillRepository skillRes ; - - @Autowired - private SkillExtentionRepository skillExtentionRes; - - @RequestMapping(value = "/skill") - @Menu(type = "callcenter" , subtype = "callcenterresource" , access = false , admin = true) - public ModelAndView skill(ModelMap map , HttpServletRequest request , @Valid String hostid) { - List pbxHostList = pbxHostRes.findByOrgi(super.getOrgi(request)) ; - map.addAttribute("pbxHostList" , pbxHostList); - PbxHost pbxHost = null ; - if(pbxHostList.size() > 0){ - map.addAttribute("pbxHost" , pbxHost = getPbxHost(pbxHostList, hostid)); - map.addAttribute("skillGroups" , skillRes.findByHostidAndOrgi(pbxHost.getId() , super.getOrgi(request))); - map.addAttribute("skillExtentionList" , skillExtentionRes.findByHostidAndOrgi(hostid, super.getOrgi(request))); - } - return request(super.createRequestPageTempletResponse("/admin/callcenter/skill/index")); - } - - private PbxHost getPbxHost(List pbxHostList ,String hostid){ - PbxHost pbxHost = pbxHostList.get(0) ; - if(!StringUtils.isBlank(hostid)){ - for(PbxHost pbx : pbxHostList){ - if(pbx.getId().equals(hostid)){ - pbxHost = pbx; break ; - } - } - } - return pbxHost ; - } - - @RequestMapping(value = "/skill/add") - @Menu(type = "callcenter" , subtype = "extention" , access = false , admin = true) - public ModelAndView extentionadd(ModelMap map , HttpServletRequest request , @Valid String hostid) { - map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))) ; - return request(super.createRequestPageTempletResponse("/admin/callcenter/skill/add")); - } - - @RequestMapping(value = "/skill/save") - @Menu(type = "callcenter" , subtype = "extention" , access = false , admin = true) - public ModelAndView extentionsave(ModelMap map , HttpServletRequest request , @Valid CallCenterSkill skill) { - if(!StringUtils.isBlank(skill.getSkill())){ - int count = skillRes.countBySkillAndOrgi(skill.getSkill(), super.getOrgi(request)) ; - if(count == 0){ - skill.setOrgi(super.getOrgi(request)); - skill.setCreater(super.getUser(request).getId()); - skillRes.save(skill) ; - } - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/skill.html?hostid="+skill.getHostid())); - } - - @RequestMapping(value = "/skill/edit") - @Menu(type = "callcenter" , subtype = "extention" , access = false , admin = true) - public ModelAndView extentionedit(ModelMap map , HttpServletRequest request , @Valid String id , @Valid String hostid) { - map.addAttribute("extention" , extentionRes.findByIdAndOrgi(id, super.getOrgi(request))); - map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))) ; - return request(super.createRequestPageTempletResponse("/admin/callcenter/skill/edit")); - } - - @RequestMapping(value = "/skill/update") - @Menu(type = "callcenter" , subtype = "extention" , access = false , admin = true) - public ModelAndView pbxhostupdate(ModelMap map , HttpServletRequest request , @Valid Extention extention) { - if(!StringUtils.isBlank(extention.getId())){ - Extention ext = extentionRes.findByIdAndOrgi(extention.getId(), super.getOrgi(request)) ; - if(ext!=null && !StringUtils.isBlank(ext.getExtention()) && ext.getExtention().matches("[\\d]{3,8}")){ - ext.setExtention(extention.getExtention()); - if(!StringUtils.isBlank(extention.getPassword())){ - ext.setPassword(extention.getPassword()); - } - ext.setUpdatetime(new Date()); - extentionRes.save(ext) ; - } - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/skill.html?hostid="+extention.getHostid())); - } - - @RequestMapping(value = "/skill/delete") - @Menu(type = "callcenter" , subtype = "extention" , access = false , admin = true) - public ModelAndView extentiondelete(ModelMap map , HttpServletRequest request , @Valid String id , @Valid String hostid) { - if(!StringUtils.isBlank(id)){ - extentionRes.delete(id); - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/skill.html?hostid="+hostid)); - } - - @RequestMapping(value = "/skill/imp") - @Menu(type = "callcenter" , subtype = "extention" , access = false , admin = true) - public ModelAndView skillimp(ModelMap map , HttpServletRequest request , @Valid String hostid) { - if(!StringUtils.isBlank(hostid)){ - map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))) ; - map.put("extentionList", extentionRes.findByHostidAndOrgi(hostid, super.getOrgi(request))) ; - map.addAttribute("skillGroups" , skillRes.findByHostidAndOrgi(hostid , super.getOrgi(request))); - } - return request(super.createRequestPageTempletResponse("/admin/callcenter/skill/imp")); - } - - @RequestMapping(value = "/skill/extention/delete") - @Menu(type = "callcenter" , subtype = "extention" , access = false , admin = true) - public ModelAndView skillextentiondelete(ModelMap map , HttpServletRequest request , @Valid String id , @Valid String hostid) { - if(!StringUtils.isBlank(id)){ - skillExtentionRes.delete(id); - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/skill.html?hostid="+hostid)); - } - - @RequestMapping(value = "/skill/extention/save") - @Menu(type = "callcenter" , subtype = "extention" , access = false , admin = true) - public ModelAndView skillextentionsave(ModelMap map , HttpServletRequest request , @Valid SkillExtention skillExtention, @Valid String hostid , @Valid String[] exts) { - if(exts!=null && exts.length > 0){ - List skillExtentionList = skillExtentionRes.findByHostidAndOrgi(hostid, super.getOrgi(request)) ; - for(String ext :exts){ - SkillExtention skillExt = new SkillExtention() ; - skillExt.setOrgi(super.getOrgi(request)); - skillExt.setCreater(super.getUser(request).getId()); - skillExt.setCreatetime(new Date()); - skillExt.setExtention(ext); - skillExt.setHostid(hostid); - skillExt.setSkillid(skillExtention.getSkillid()); - skillExt.setUpdatetime(new Date()); - boolean ingroup = false; - for(SkillExtention temp : skillExtentionList){ - if(temp.getSkillid().equals(skillExt.getSkillid()) && temp.getExtention().equals(skillExt.getExtention())){ - ingroup = true ; - } - } - if(ingroup == false){ - skillExtentionRes.save(skillExt) ; - } - } - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/skill.html?hostid="+hostid)); - } - -} diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/channel/SNSAccountIMController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/channel/SNSAccountIMController.java index b5d31ae2..9e09a871 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/channel/SNSAccountIMController.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/channel/SNSAccountIMController.java @@ -19,13 +19,11 @@ package com.chatopera.cc.controller.admin.channel; import com.chatopera.cc.basic.MainContext; import com.chatopera.cc.basic.MainUtils; import com.chatopera.cc.controller.Handler; -import com.chatopera.cc.model.CousultInvite; -import com.chatopera.cc.model.SNSAccount; -import com.chatopera.cc.model.Secret; -import com.chatopera.cc.model.User; +import com.chatopera.cc.model.*; import com.chatopera.cc.persistence.repository.ConsultInviteRepository; import com.chatopera.cc.persistence.repository.SNSAccountRepository; import com.chatopera.cc.persistence.repository.SecretRepository; +import com.chatopera.cc.proxy.OrganProxy; import com.chatopera.cc.util.Base62; import com.chatopera.cc.util.Menu; import org.apache.commons.lang.StringUtils; @@ -42,9 +40,9 @@ import javax.validation.Valid; import java.security.NoSuchAlgorithmException; import java.util.Date; import java.util.List; +import java.util.Map; /** - * * */ @Controller @@ -60,11 +58,20 @@ public class SNSAccountIMController extends Handler { @Autowired private SecretRepository secRes; + @Autowired + private OrganProxy organProxy; + @RequestMapping("/index") @Menu(type = "admin", subtype = "im", access = false, admin = true) - public ModelAndView index(ModelMap map, HttpServletRequest request, @Valid String execute,@RequestParam(name = "status",required = false) String status ) { - map.addAttribute("snsAccountList", snsAccountRes.findBySnstypeAndOrgi(MainContext.ChannelType.WEBIM.toString(), super.getOrgi(request), new PageRequest(super.getP(request), super.getPs(request)))); - map.addAttribute("status",status); + public ModelAndView index(ModelMap map, HttpServletRequest request, @Valid String execute, @RequestParam(name = "status", required = false) String status) { + User logined = super.getUser(request); + if (logined.isSuperadmin()) { + map.addAttribute("snsAccountList", snsAccountRes.findBySnstypeAndOrgi(MainContext.ChannelType.WEBIM.toString(), super.getOrgi(request), new PageRequest(super.getP(request), super.getPs(request)))); + } else { + Map organs = organProxy.findAllOrganByParentAndOrgi(super.getOrgan(request), super.getOrgi(request)); + map.addAttribute("snsAccountList", snsAccountRes.findBySnstypeAndOrgiAndOrgan(MainContext.ChannelType.WEBIM.toString(), super.getOrgi(request), organs.keySet(), new PageRequest(super.getP(request), super.getPs(request)))); + } + map.addAttribute("status", status); List secretConfig = secRes.findByOrgi(super.getOrgi(request)); if (secretConfig != null && secretConfig.size() > 0) { map.addAttribute("secret", secretConfig.get(0)); diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/channel/WebIMController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/channel/WebIMController.java index 1c73cf04..2dc4b718 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/channel/WebIMController.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/channel/WebIMController.java @@ -291,21 +291,10 @@ public class WebIMController extends Handler { */ private List getSkillGroups(HttpServletRequest request) { List skillgroups = new ArrayList<>(); - if (super.isTenantshare()) { - List organIdList = new ArrayList<>(); - List orgiSkillRelList = orgiSkillRelService.findByOrgi(super.getOrgi(request)); - if (!orgiSkillRelList.isEmpty()) { - for (OrgiSkillRel rel : orgiSkillRelList) { - organIdList.add(rel.getSkillid()); - } - } - skillgroups = organRes.findAll(organIdList); - } else { - List allgroups = organRes.findByOrgiAndOrgid(super.getOrgi(request), super.getOrgid(request)); - for (Organ o : allgroups) { - if (o.isSkill()) { - skillgroups.add(o); - } + List allgroups = organRes.findByOrgi(super.getOrgi(request)); + for (Organ o : allgroups) { + if (o.isSkill()) { + skillgroups.add(o); } } return skillgroups; @@ -318,19 +307,7 @@ public class WebIMController extends Handler { * @return */ private List getUsers(HttpServletRequest request) { - List userList; - if (super.isTenantshare()) { - List organIdList = new ArrayList<>(); - List orgiSkillRelList = orgiSkillRelService.findByOrgi(super.getOrgi(request)); - if (!orgiSkillRelList.isEmpty()) { - for (OrgiSkillRel rel : orgiSkillRelList) { - organIdList.add(rel.getSkillid()); - } - } - userList = userProxy.findByOrganInAndAgentAndDatastatus(organIdList, true, false); - } else { - userList = userRes.findByOrgiAndAgentAndDatastatus(super.getOrgi(request), true, false); - } + List userList = userRes.findByOrgiAndAgentAndDatastatus(super.getOrgi(request), true, false); return userList; } } \ No newline at end of file diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/config/SystemConfigController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/config/SystemConfigController.java index 6c9c596f..09241889 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/config/SystemConfigController.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/config/SystemConfigController.java @@ -194,8 +194,8 @@ public class SystemConfigController extends Handler { @Valid Secret secret) throws SQLException, IOException, NoSuchAlgorithmException { /*SystemConfig systemConfig = systemConfigRes.findByOrgi(super.getOrgi(request)) ; config.setOrgi(super.getOrgi(request));*/ - SystemConfig systemConfig = systemConfigRes.findByOrgi(MainContext.SYSTEM_ORGI); - config.setOrgi(MainContext.SYSTEM_ORGI); + SystemConfig systemConfig = systemConfigRes.findByOrgi(Constants.SYSTEM_ORGI); + config.setOrgi(Constants.SYSTEM_ORGI); String msg = "0"; if (StringUtils.isBlank(config.getJkspassword())) { config.setJkspassword(null); diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/config/SystemMessageController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/config/SystemMessageController.java index e9a50396..ff173b86 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/config/SystemMessageController.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/config/SystemMessageController.java @@ -20,11 +20,14 @@ import com.chatopera.cc.basic.MainContext; import com.chatopera.cc.basic.MainUtils; import com.chatopera.cc.controller.Handler; import com.chatopera.cc.model.Dict; +import com.chatopera.cc.model.Organ; import com.chatopera.cc.model.SystemMessage; +import com.chatopera.cc.persistence.repository.OrganRepository; import com.chatopera.cc.persistence.repository.SystemMessageRepository; import com.chatopera.cc.util.Menu; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; @@ -35,135 +38,148 @@ import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; import java.io.IOException; import java.security.NoSuchAlgorithmException; +import java.util.List; @Controller @RequestMapping("/admin") public class SystemMessageController extends Handler { - - @Autowired - private SystemMessageRepository systemMessageRepository; - + + @Autowired + private SystemMessageRepository systemMessageRepository; + + @Autowired + private OrganRepository organRes; + @RequestMapping("/email/index") - @Menu(type = "setting" , subtype = "email") - public ModelAndView index(ModelMap map , HttpServletRequest request) throws IOException { - map.addAttribute("emailList", systemMessageRepository.findByMsgtypeAndOrgi("email" , super.getOrgi(request) , new PageRequest(super.getP(request), super.getPs(request)))); - return request(super.createAdminTempletResponse("/admin/email/index")); + @Menu(type = "setting", subtype = "email") + public ModelAndView index(ModelMap map, HttpServletRequest request) throws IOException { + Page emails = systemMessageRepository.findByMsgtypeAndOrgi("email", super.getOrgi(request), new PageRequest(super.getP(request), super.getPs(request))); + List organs = organRes.findByOrgi(super.getOrgi(request)); + + emails.getContent().stream().forEach(p -> { + organs.stream().filter(o -> StringUtils.equals(p.getOrgan(), o.getId())).findAny().ifPresent(o -> p.setOrgan(o.getName())); + }); + + map.addAttribute("emailList", emails); + return request(super.createAdminTempletResponse("/admin/email/index")); } - + @RequestMapping("/email/add") - @Menu(type = "admin" , subtype = "email") - public ModelAndView add(ModelMap map , HttpServletRequest request) { + @Menu(type = "admin", subtype = "email") + public ModelAndView add(ModelMap map, HttpServletRequest request) { + map.put("organList", organRes.findByOrgi(super.getOrgi(request))); return request(super.createRequestPageTempletResponse("/admin/email/add")); } - + @RequestMapping("/email/save") - @Menu(type = "admin" , subtype = "user") - public ModelAndView save(HttpServletRequest request ,@Valid SystemMessage email) throws NoSuchAlgorithmException { - email.setOrgi(super.getOrgi(request)); - email.setMsgtype(MainContext.SystemMessageType.EMAIL.toString()); - if(!StringUtils.isBlank(email.getSmtppassword())) { - email.setSmtppassword(MainUtils.encryption(email.getSmtppassword())); - } - systemMessageRepository.save(email) ; - return request(super.createRequestPageTempletResponse("redirect:/admin/email/index.html")); + @Menu(type = "admin", subtype = "user") + public ModelAndView save(HttpServletRequest request, @Valid SystemMessage email) throws NoSuchAlgorithmException { + email.setOrgi(super.getOrgi(request)); + email.setMsgtype(MainContext.SystemMessageType.EMAIL.toString()); + if (!StringUtils.isBlank(email.getSmtppassword())) { + email.setSmtppassword(MainUtils.encryption(email.getSmtppassword())); + } + systemMessageRepository.save(email); + return request(super.createRequestPageTempletResponse("redirect:/admin/email/index.html")); } - + @RequestMapping("/email/edit") - @Menu(type = "admin" , subtype = "email") - public ModelAndView edit(ModelMap map , HttpServletRequest request , @Valid String id) { - map.addAttribute("email", systemMessageRepository.findByIdAndOrgi(id, super.getOrgi(request))) ; + @Menu(type = "admin", subtype = "email") + public ModelAndView edit(ModelMap map, HttpServletRequest request, @Valid String id) { + map.put("organList", organRes.findByOrgi(super.getOrgi(request))); + map.addAttribute("email", systemMessageRepository.findByIdAndOrgi(id, super.getOrgi(request))); return request(super.createRequestPageTempletResponse("/admin/email/edit")); } - + @RequestMapping("/email/update") - @Menu(type = "admin" , subtype = "user" , admin = true) - public ModelAndView update(HttpServletRequest request ,@Valid SystemMessage email) throws NoSuchAlgorithmException { - SystemMessage temp = systemMessageRepository.findByIdAndOrgi(email.getId(), super.getOrgi(request)) ; - if(email!=null) { - email.setCreatetime(temp.getCreatetime()); - email.setOrgi(temp.getOrgi()); - email.setMsgtype(MainContext.SystemMessageType.EMAIL.toString()); - if(!StringUtils.isBlank(email.getSmtppassword())) { - email.setSmtppassword(MainUtils.encryption(email.getSmtppassword())); - }else { - email.setSmtppassword(temp.getSmtppassword()); - } - systemMessageRepository.save(email) ; - } - return request(super.createRequestPageTempletResponse("redirect:/admin/email/index.html")); + @Menu(type = "admin", subtype = "user", admin = true) + public ModelAndView update(HttpServletRequest request, @Valid SystemMessage email) throws NoSuchAlgorithmException { + SystemMessage temp = systemMessageRepository.findByIdAndOrgi(email.getId(), super.getOrgi(request)); + if (email != null) { + email.setCreatetime(temp.getCreatetime()); + email.setOrgi(temp.getOrgi()); + email.setMsgtype(MainContext.SystemMessageType.EMAIL.toString()); + if (!StringUtils.isBlank(email.getSmtppassword())) { + email.setSmtppassword(MainUtils.encryption(email.getSmtppassword())); + } else { + email.setSmtppassword(temp.getSmtppassword()); + } + systemMessageRepository.save(email); + } + return request(super.createRequestPageTempletResponse("redirect:/admin/email/index.html")); } - + @RequestMapping("/email/delete") - @Menu(type = "admin" , subtype = "user") - public ModelAndView delete(HttpServletRequest request ,@Valid SystemMessage email) { - SystemMessage temp = systemMessageRepository.findByIdAndOrgi(email.getId(), super.getOrgi(request)) ; - if(email!=null) { - systemMessageRepository.delete(temp); - } - return request(super.createRequestPageTempletResponse("redirect:/admin/email/index.html")); + @Menu(type = "admin", subtype = "user") + public ModelAndView delete(HttpServletRequest request, @Valid SystemMessage email) { + SystemMessage temp = systemMessageRepository.findByIdAndOrgi(email.getId(), super.getOrgi(request)); + if (email != null) { + systemMessageRepository.delete(temp); + } + return request(super.createRequestPageTempletResponse("redirect:/admin/email/index.html")); } - - + + @RequestMapping("/sms/index") - @Menu(type = "setting" , subtype = "sms") - public ModelAndView smsindex(ModelMap map , HttpServletRequest request) throws IOException { - map.addAttribute("smsList", systemMessageRepository.findByMsgtypeAndOrgi("sms" , super.getOrgi(request) , new PageRequest(super.getP(request), super.getPs(request)))); - return request(super.createAdminTempletResponse("/admin/sms/index")); + @Menu(type = "setting", subtype = "sms") + public ModelAndView smsindex(ModelMap map, HttpServletRequest request) throws IOException { + map.addAttribute("smsList", systemMessageRepository.findByMsgtypeAndOrgi("sms", super.getOrgi(request), new PageRequest(super.getP(request), super.getPs(request)))); + return request(super.createAdminTempletResponse("/admin/sms/index")); } - + @RequestMapping("/sms/add") - @Menu(type = "admin" , subtype = "sms") - public ModelAndView smsadd(ModelMap map , HttpServletRequest request) { - - map.addAttribute("smsType", Dict.getInstance().getDic("com.dic.sms.type")) ; + @Menu(type = "admin", subtype = "sms") + public ModelAndView smsadd(ModelMap map, HttpServletRequest request) { + + map.addAttribute("smsType", Dict.getInstance().getDic("com.dic.sms.type")); return request(super.createRequestPageTempletResponse("/admin/sms/add")); } - + @RequestMapping("/sms/save") - @Menu(type = "admin" , subtype = "sms") - public ModelAndView smssave(HttpServletRequest request ,@Valid SystemMessage sms) throws NoSuchAlgorithmException { - sms.setOrgi(super.getOrgi(request)); - sms.setMsgtype(MainContext.SystemMessageType.SMS.toString()); - if(!StringUtils.isBlank(sms.getSmtppassword())) { - sms.setSmtppassword(MainUtils.encryption(sms.getSmtppassword())); - } - systemMessageRepository.save(sms) ; - return request(super.createRequestPageTempletResponse("redirect:/admin/sms/index.html")); + @Menu(type = "admin", subtype = "sms") + public ModelAndView smssave(HttpServletRequest request, @Valid SystemMessage sms) throws NoSuchAlgorithmException { + sms.setOrgi(super.getOrgi(request)); + sms.setMsgtype(MainContext.SystemMessageType.SMS.toString()); + if (!StringUtils.isBlank(sms.getSmtppassword())) { + sms.setSmtppassword(MainUtils.encryption(sms.getSmtppassword())); + } + systemMessageRepository.save(sms); + return request(super.createRequestPageTempletResponse("redirect:/admin/sms/index.html")); } - + @RequestMapping("/sms/edit") - @Menu(type = "admin" , subtype = "sms") - public ModelAndView smsedit(ModelMap map , HttpServletRequest request , @Valid String id) { - map.addAttribute("smsType", Dict.getInstance().getDic("com.dic.sms.type")) ; - map.addAttribute("sms", systemMessageRepository.findByIdAndOrgi(id, super.getOrgi(request))) ; + @Menu(type = "admin", subtype = "sms") + public ModelAndView smsedit(ModelMap map, HttpServletRequest request, @Valid String id) { + map.addAttribute("smsType", Dict.getInstance().getDic("com.dic.sms.type")); + map.addAttribute("sms", systemMessageRepository.findByIdAndOrgi(id, super.getOrgi(request))); return request(super.createRequestPageTempletResponse("/admin/sms/edit")); } - + @RequestMapping("/sms/update") - @Menu(type = "admin" , subtype = "sms" , admin = true) - public ModelAndView smsupdate(HttpServletRequest request ,@Valid SystemMessage sms) throws NoSuchAlgorithmException { - SystemMessage temp = systemMessageRepository.findByIdAndOrgi(sms.getId(), super.getOrgi(request)) ; - if(sms!=null) { - sms.setCreatetime(temp.getCreatetime()); - sms.setOrgi(temp.getOrgi()); - sms.setMsgtype(MainContext.SystemMessageType.SMS.toString()); - if(!StringUtils.isBlank(sms.getSmtppassword())) { - sms.setSmtppassword(MainUtils.encryption(sms.getSmtppassword())); - }else { - sms.setSmtppassword(temp.getSmtppassword()); - } - systemMessageRepository.save(sms) ; - } - return request(super.createRequestPageTempletResponse("redirect:/admin/sms/index.html")); + @Menu(type = "admin", subtype = "sms", admin = true) + public ModelAndView smsupdate(HttpServletRequest request, @Valid SystemMessage sms) throws NoSuchAlgorithmException { + SystemMessage temp = systemMessageRepository.findByIdAndOrgi(sms.getId(), super.getOrgi(request)); + if (sms != null) { + sms.setCreatetime(temp.getCreatetime()); + sms.setOrgi(temp.getOrgi()); + sms.setMsgtype(MainContext.SystemMessageType.SMS.toString()); + if (!StringUtils.isBlank(sms.getSmtppassword())) { + sms.setSmtppassword(MainUtils.encryption(sms.getSmtppassword())); + } else { + sms.setSmtppassword(temp.getSmtppassword()); + } + systemMessageRepository.save(sms); + } + return request(super.createRequestPageTempletResponse("redirect:/admin/sms/index.html")); } - + @RequestMapping("/sms/delete") - @Menu(type = "admin" , subtype = "sms") - public ModelAndView smsdelete(HttpServletRequest request ,@Valid SystemMessage sms) { - SystemMessage temp = systemMessageRepository.findByIdAndOrgi(sms.getId(), super.getOrgi(request)) ; - if(sms!=null) { - systemMessageRepository.delete(temp); - } - return request(super.createRequestPageTempletResponse("redirect:/admin/sms/index.html")); + @Menu(type = "admin", subtype = "sms") + public ModelAndView smsdelete(HttpServletRequest request, @Valid SystemMessage sms) { + SystemMessage temp = systemMessageRepository.findByIdAndOrgi(sms.getId(), super.getOrgi(request)); + if (sms != null) { + systemMessageRepository.delete(temp); + } + return request(super.createRequestPageTempletResponse("redirect:/admin/sms/index.html")); } } \ No newline at end of file diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/system/TemplateController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/system/TemplateController.java index 49f26988..5014a165 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/system/TemplateController.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/system/TemplateController.java @@ -67,7 +67,7 @@ public class TemplateController extends Handler{ @Menu(type = "admin" , subtype = "template" , access = false , admin = true) public void expall(ModelMap map , HttpServletRequest request , HttpServletResponse response) throws Exception { List