1
0
mirror of https://github.com/chatopera/cosin.git synced 2025-08-01 16:38:02 +08:00

Closed #99 使用环境变量配置模块

This commit is contained in:
Hai Liang Wang 2018-10-17 15:43:32 +08:00
parent d7f135f0ba
commit 1985dd3f7f
5 changed files with 84 additions and 34 deletions

View File

@ -17,8 +17,10 @@
package com.chatopera.cc.app; package com.chatopera.cc.app;
import com.chatopera.cc.app.basic.MainContext; 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.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.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
@ -42,8 +44,6 @@ import java.io.IOException;
@EnableElasticsearchRepositories("com.chatopera.cc.app.persistence.es") @EnableElasticsearchRepositories("com.chatopera.cc.app.persistence.es")
@EnableAsync @EnableAsync
public class Application { public class Application {
private static final Logger logger = LoggerFactory.getLogger(Application.class);
@Value("${web.upload-path}") @Value("${web.upload-path}")
private String uploaddir; private String uploaddir;
@ -51,36 +51,54 @@ public class Application {
@Value("${spring.servlet.multipart.max-file-size}") @Value("${spring.servlet.multipart.max-file-size}")
private String multipartMaxUpload; private String multipartMaxUpload;
@Value("${spring.servlet.multipart.max-request-size}") @Value("${spring.servlet.multipart.max-request-size}")
private String multipartMaxRequest; 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 * Init local resources
*/ */
protected static void init(){ protected static void init() {
try { try {
logger.info("init mobile number utils ..."); System.out.println("init mobile number utils ...");
MobileNumberUtils.init(); MobileNumberUtils.init();
} catch (IOException e) { } catch (IOException e) {
logger.error("init error ", e); e.printStackTrace();
System.exit(1); System.exit(1);
} }
} }
@Bean @Bean
public MultipartConfigElement multipartConfigElement() { public MultipartConfigElement multipartConfigElement() {
MultipartConfigFactory factory = new MultipartConfigFactory(); MultipartConfigFactory factory = new MultipartConfigFactory();
factory.setMaxFileSize(multipartMaxUpload); //KB,MB factory.setMaxFileSize(multipartMaxUpload); //KB,MB
factory.setMaxRequestSize(multipartMaxRequest); factory.setMaxRequestSize(multipartMaxRequest);
factory.setLocation(uploaddir); factory.setLocation(uploaddir);
return factory.createMultipartConfig(); return factory.createMultipartConfig();
} }
@Bean @Bean
@ -89,19 +107,19 @@ public class Application {
return new EmbeddedServletContainerCustomizer() { return new EmbeddedServletContainerCustomizer() {
@Override @Override
public void customize(ConfigurableEmbeddedServletContainer container) { public void customize(ConfigurableEmbeddedServletContainer container) {
ErrorPage error = new ErrorPage("/error.html"); ErrorPage error = new ErrorPage("/error.html");
container.addErrorPages(error); container.addErrorPages(error);
} }
}; };
} }
public static void main(String[] args) { public static void main(String[] args) {
Application.init(); Application.init();
SpringApplication app = new SpringApplication(Application.class) ; SpringApplication app = new SpringApplication(Application.class);
app.setBannerMode(Banner.Mode.CONSOLE); app.setBannerMode(Banner.Mode.CONSOLE);
app.setAddCommandLineProperties(false); app.setAddCommandLineProperties(false);
app.addListeners(new StartedEventListener()); app.addListeners(new StartedEventListener());
MainContext.setApplicationContext(app.run(args)); MainContext.setApplicationContext(app.run(args));
} }
} }

View File

@ -0,0 +1,32 @@
/*
* Copyright (C) 2018 Chatopera Inc, <https://www.chatopera.com>
*
* 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");
}
}

View File

@ -15,10 +15,9 @@
# https://docs.spring.io/spring-boot/docs/1.5.6.RELEASE/reference/htmlsingle/ # 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 # https://stackoverflow.com/questions/35531661/using-env-variable-in-spring-boots-application-properties
# 证书相关信息 # 证书相关信息
license.client.id=bxzq license.client.id=cskefu
application.version=1.0.0 application.version=3.9.0
# security # security
management.security.enabled=false management.security.enabled=false

View File

@ -30,9 +30,10 @@
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">智能问答引擎地址</label> <label class="layui-form-label">智能问答引擎地址</label>
<div class="layui-input-inline"> <div class="layui-input-inline">
<input type="text" name="baseUrl" required lay-verify="required" placeholder="请输入智能问答引擎地址" <input type="text" name="baseUrl" required lay-verify="required" placeholder="联系info@chatopera.com获得智能问答引擎地址"
autocomplete="off" class="layui-input" value="${bot.baseUrl}" <#if id!=null>disabled</#if>> autocomplete="off" class="layui-input" value="${bot.baseUrl}" <#if id!=null>disabled</#if>>
</div> </div>
<label class="layui-form-label"></label>
</div> </div>
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">名称</label> <label class="layui-form-label">名称</label>

View File

@ -317,7 +317,7 @@
</dd> </dd>
</#if> </#if>
</#if> </#if>
<#if models?? && models["sales"]?? && models["sales"] == true> <#if models?? && models["chatbot"]?? && models["chatbot"] == true>
<#if user?? &&( user.roleAuthMap["A09"]?? || user.usertype == "0") > <#if user?? &&( user.roleAuthMap["A09"]?? || user.usertype == "0") >
<dd class="ukefu-left-menu" data-tooltip="智能机器人"> <dd class="ukefu-left-menu" data-tooltip="智能机器人">
<a href="javascript:void(0)" data-title="智能机器人" data-href="/apps/chatbot/index.html" class="iframe_btn" data-id="maincontent" data-type="tabChange"> <a href="javascript:void(0)" data-title="智能机器人" data-href="/apps/chatbot/index.html" class="iframe_btn" data-id="maincontent" data-type="tabChange">