mirror of
https://github.com/chatopera/cosin.git
synced 2025-08-01 16:38:02 +08:00
Closed #99 使用环境变量配置模块
This commit is contained in:
parent
d7f135f0ba
commit
1985dd3f7f
@ -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,36 +51,54 @@ 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();
|
||||
MultipartConfigFactory factory = new MultipartConfigFactory();
|
||||
factory.setMaxFileSize(multipartMaxUpload); //KB,MB
|
||||
factory.setMaxRequestSize(multipartMaxRequest);
|
||||
factory.setLocation(uploaddir);
|
||||
return factory.createMultipartConfig();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ -89,19 +107,19 @@ public class Application {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -30,9 +30,10 @@
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">智能问答引擎地址</label>
|
||||
<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>>
|
||||
</div>
|
||||
<label class="layui-form-label"></label>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">名称</label>
|
||||
|
@ -317,7 +317,7 @@
|
||||
</dd>
|
||||
</#if>
|
||||
</#if>
|
||||
<#if models?? && models["sales"]?? && models["sales"] == true>
|
||||
<#if models?? && models["chatbot"]?? && models["chatbot"] == true>
|
||||
<#if user?? &&( user.roleAuthMap["A09"]?? || user.usertype == "0") >
|
||||
<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">
|
||||
|
Loading…
x
Reference in New Issue
Block a user