From 1985dd3f7fe0b4f635a82daa135ae4369c90709b Mon Sep 17 00:00:00 2001 From: Hai Liang Wang Date: Wed, 17 Oct 2018 15:43:32 +0800 Subject: [PATCH] =?UTF-8?q?Closed=20#99=20=E4=BD=BF=E7=94=A8=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E5=8F=98=E9=87=8F=E9=85=8D=E7=BD=AE=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/chatopera/cc/app/Application.java | 76 ++++++++++++------- .../chatopera/cc/util/SystemEnvHelper.java | 32 ++++++++ .../src/main/resources/application.properties | 5 +- .../templates/apps/chatbot/edit.html | 3 +- .../main/resources/templates/apps/index.html | 2 +- 5 files changed, 84 insertions(+), 34 deletions(-) create mode 100644 contact-center/app/src/main/java/com/chatopera/cc/util/SystemEnvHelper.java diff --git a/contact-center/app/src/main/java/com/chatopera/cc/app/Application.java b/contact-center/app/src/main/java/com/chatopera/cc/app/Application.java index 1895673f..8af3c34f 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/app/Application.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/app/Application.java @@ -17,8 +17,10 @@ package com.chatopera.cc.app; import com.chatopera.cc.app.basic.MainContext; -import com.chatopera.cc.util.mobile.MobileNumberUtils; import com.chatopera.cc.app.config.StartedEventListener; +import com.chatopera.cc.util.SystemEnvHelper; +import com.chatopera.cc.util.mobile.MobileNumberUtils; +import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; @@ -42,8 +44,6 @@ import java.io.IOException; @EnableElasticsearchRepositories("com.chatopera.cc.app.persistence.es") @EnableAsync public class Application { - private static final Logger logger = LoggerFactory.getLogger(Application.class); - @Value("${web.upload-path}") private String uploaddir; @@ -51,57 +51,75 @@ public class Application { @Value("${spring.servlet.multipart.max-file-size}") private String multipartMaxUpload; - @Value("${spring.servlet.multipart.max-request-size}") private String multipartMaxRequest; - static{ - MainContext.model.put("contacts", true) ; - MainContext.model.put("sales", true); - MainContext.model.put("chatbot", true); + /** + * 记载模块 + */ + // 外呼模块 + private final static boolean isCalloutModule = SystemEnvHelper.parseModuleFlag("CSKEFU_MODULE_CALLOUT"); + // CRM模块 + private final static boolean isContactsModule = SystemEnvHelper.parseModuleFlag("CSKEFU_MODULE_CONTACTS"); + // 聊天机器人模块 + private final static boolean isChatbotModule = SystemEnvHelper.parseModuleFlag("CSKEFU_MODULE_CHATBOT"); + + static { + // 外呼模块 + if (isCalloutModule) { + MainContext.model.put("sales", true); + } + // CRM模块 + if (isContactsModule) { + MainContext.model.put("contacts", true); + } + // 聊天机器人模块 + if (isChatbotModule) { + MainContext.model.put("chatbot", true); + } } /** * Init local resources */ - protected static void init(){ + protected static void init() { try { - logger.info("init mobile number utils ..."); + System.out.println("init mobile number utils ..."); MobileNumberUtils.init(); } catch (IOException e) { - logger.error("init error ", e); + e.printStackTrace(); System.exit(1); } } - @Bean - public MultipartConfigElement multipartConfigElement() { - MultipartConfigFactory factory = new MultipartConfigFactory(); - factory.setMaxFileSize(multipartMaxUpload); //KB,MB - factory.setMaxRequestSize(multipartMaxRequest); - factory.setLocation(uploaddir); - return factory.createMultipartConfig(); - } - + @Bean + public MultipartConfigElement multipartConfigElement() { + MultipartConfigFactory factory = new MultipartConfigFactory(); + factory.setMaxFileSize(multipartMaxUpload); //KB,MB + factory.setMaxRequestSize(multipartMaxRequest); + factory.setLocation(uploaddir); + return factory.createMultipartConfig(); + } + @Bean public EmbeddedServletContainerCustomizer containerCustomizer() { return new EmbeddedServletContainerCustomizer() { @Override public void customize(ConfigurableEmbeddedServletContainer container) { - ErrorPage error = new ErrorPage("/error.html"); - container.addErrorPages(error); + ErrorPage error = new ErrorPage("/error.html"); + container.addErrorPages(error); } }; } - - public static void main(String[] args) { + + public static void main(String[] args) { Application.init(); - SpringApplication app = new SpringApplication(Application.class) ; - app.setBannerMode(Banner.Mode.CONSOLE); + SpringApplication app = new SpringApplication(Application.class); + app.setBannerMode(Banner.Mode.CONSOLE); app.setAddCommandLineProperties(false); - app.addListeners(new StartedEventListener()); - MainContext.setApplicationContext(app.run(args)); - } + app.addListeners(new StartedEventListener()); + MainContext.setApplicationContext(app.run(args)); + } } diff --git a/contact-center/app/src/main/java/com/chatopera/cc/util/SystemEnvHelper.java b/contact-center/app/src/main/java/com/chatopera/cc/util/SystemEnvHelper.java new file mode 100644 index 00000000..bd29f142 --- /dev/null +++ b/contact-center/app/src/main/java/com/chatopera/cc/util/SystemEnvHelper.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2018 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.util; + +import org.apache.commons.lang.StringUtils; + +public class SystemEnvHelper { + + /** + * 分析是否加载模块,在变量为不存在或变量值为true的情况下加载 + * 也就是说,该变量值不为空或为true时时加载 + * @param environmentVariable + * @return + */ + public static boolean parseModuleFlag(final String environmentVariable){ + String val = System.getenv(environmentVariable); + return StringUtils.isBlank(val) || StringUtils.equalsIgnoreCase(val, "true"); + } +} diff --git a/contact-center/app/src/main/resources/application.properties b/contact-center/app/src/main/resources/application.properties index 1f73bf55..5af82aae 100644 --- a/contact-center/app/src/main/resources/application.properties +++ b/contact-center/app/src/main/resources/application.properties @@ -15,10 +15,9 @@ # https://docs.spring.io/spring-boot/docs/1.5.6.RELEASE/reference/htmlsingle/ # https://stackoverflow.com/questions/35531661/using-env-variable-in-spring-boots-application-properties - # 证书相关信息 -license.client.id=bxzq -application.version=1.0.0 +license.client.id=cskefu +application.version=3.9.0 # security management.security.enabled=false diff --git a/contact-center/app/src/main/resources/templates/apps/chatbot/edit.html b/contact-center/app/src/main/resources/templates/apps/chatbot/edit.html index adbe5be2..0fac1877 100644 --- a/contact-center/app/src/main/resources/templates/apps/chatbot/edit.html +++ b/contact-center/app/src/main/resources/templates/apps/chatbot/edit.html @@ -30,9 +30,10 @@
- disabled>
+
diff --git a/contact-center/app/src/main/resources/templates/apps/index.html b/contact-center/app/src/main/resources/templates/apps/index.html index b821d1f6..f0465ae8 100644 --- a/contact-center/app/src/main/resources/templates/apps/index.html +++ b/contact-center/app/src/main/resources/templates/apps/index.html @@ -317,7 +317,7 @@ - <#if models?? && models["sales"]?? && models["sales"] == true> + <#if models?? && models["chatbot"]?? && models["chatbot"] == true> <#if user?? &&( user.roleAuthMap["A09"]?? || user.usertype == "0") >