1
0
mirror of https://github.com/chatopera/cosin.git synced 2025-08-01 16:38:02 +08:00
This commit is contained in:
Hai Liang Wang 2022-03-27 10:31:24 +08:00
parent bd2c5bd8e5
commit 411f00e154
10 changed files with 167 additions and 97 deletions

View File

@ -81,8 +81,6 @@ public class Application {
if (StringUtils.equalsIgnoreCase(SystemEnvHelper.parseFromApplicationProps("cskefu.modules.report"), "true")) {
MainContext.enableModule(Constants.CSKEFU_MODULE_REPORT);
}
}
/**
@ -98,10 +96,11 @@ public class Application {
SpringApplication app = new SpringApplicationBuilder(Application.class)
.properties("spring.config.name:application,git")
.build();
BlessingAndUnblessing.print();
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);

View File

@ -940,6 +940,7 @@ public class MainContext {
public static void setApplicationContext(ApplicationContext context) {
applicationContext = context;
context.getBean(TerminateBean.class);
}
public static ApplicationContext getContext() {

View File

@ -0,0 +1,22 @@
/*
* Copyright (C) 2022 Chatopera Inc, All rights reserved.
* <https://www.chatopera.com>
* 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.basic;
import javax.annotation.PreDestroy;
import com.chatopera.cc.BlessingAndUnblessing;
public class TerminateBean {
@PreDestroy
public void onDestroy() throws Exception {
BlessingAndUnblessing.print();
}
}

View File

@ -0,0 +1,25 @@
/*
* Copyright (C) 2022 Chatopera Inc, All rights reserved.
* <https://www.chatopera.com>
* 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;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.chatopera.cc.basic.TerminateBean;
@Configuration
public class ShutdownConfig {
@Bean
public TerminateBean getTerminateBean() {
return new TerminateBean();
}
}

View File

@ -24,92 +24,94 @@ import java.io.InputStream;
import java.util.Properties;
public class SystemEnvHelper {
private final static Logger logger = LoggerFactory.getLogger(SystemEnvHelper.class);
private static Properties props;
private final static Logger logger = LoggerFactory.getLogger(SystemEnvHelper.class);
private static Properties props;
/**
* 根据类的全名查找是否存在
*
* @param classFullName
* @return
*/
public static boolean isClassExistByFullName(final String classFullName) {
try {
/**
* 根据类的全名查找是否存在
*
* @param classFullName
* @return
*/
public static boolean isClassExistByFullName(final String classFullName) {
try {
// Class<?> uriClass =
Class.forName(classFullName);
return true;
} catch (ClassNotFoundException ex) {
return false;
}
}
Class.forName(classFullName);
return true;
} catch (ClassNotFoundException ex) {
return false;
}
}
/**
* 获得环境变量的值如果不存在返回默认值
*
* @param variable
* @param defaultvalue
* @return
*/
public static String getenv(final String variable, final String defaultvalue) {
final String val = System.getenv(variable);
/**
* 获得环境变量的值如果不存在返回默认值
*
* @param variable
* @param defaultvalue
* @return
*/
public static String getenv(final String variable, final String defaultvalue) {
final String val = System.getenv(variable);
if (StringUtils.isBlank(val)) {
return defaultvalue;
}
return val;
}
if (StringUtils.isBlank(val)) {
return defaultvalue;
}
return val;
}
/**
* 加载配置先检查环境变量再从application properties加载
*
* @param property
* @return
*/
public static String parseFromApplicationProps(final String property) {
// property 转化为环境变量
String P = StringUtils.upperCase(property);
P = StringUtils.replaceChars(P, "-", "_");
P = StringUtils.replaceChars(P, ".", "_");
String val = System.getenv(P);
/**
* 加载配置先检查环境变量再从application properties加载
*
* @param property
* @return
*/
public static String parseFromApplicationProps(final String property) {
// property 转化为环境变量
String P = StringUtils.upperCase(property);
if (StringUtils.isBlank(val)) {
try {
val = getProps().getProperty(property);
} catch (java.lang.NullPointerException ex) {
return "NULL";
}
}
return val;
}
P = StringUtils.replaceChars(P, "-", "_");
P = StringUtils.replaceChars(P, ".", "_");
String val = System.getenv(P);
/**
* Get properties filename
*
* @return
*/
private static String getPropsFileName() {
String profile = getenv("SPRING_PROFILES_ACTIVE", "");
if (StringUtils.isNotBlank(profile)) {
return "application-" + profile + ".properties";
}
return "application.properties";
}
if (StringUtils.isBlank(val)) {
val = getProps().getProperty(property);
}
return val;
}
/**
* Get properties filename
* @return
*/
private static String getPropsFileName() {
String profile = getenv("SPRING_PROFILES_ACTIVE", "");
if (StringUtils.isNotBlank(profile)) {
return "application-" + profile + ".properties";
}
return "application.properties";
}
/**
* 加载 application.properties
*
* @return
*/
private static Properties getProps() {
if (props == null) {
try (InputStream input = SystemEnvHelper.class.getClassLoader().getResourceAsStream(
getPropsFileName())) {
// load a properties file
props = new Properties();
props.load(input);
} catch (IOException ex) {
logger.error("[getProps] error", ex);
}
}
return props;
}
/**
* 加载 application.properties
*
* @return
*/
private static Properties getProps() {
if (props == null) {
try (InputStream input = SystemEnvHelper.class.getClassLoader().getResourceAsStream(getPropsFileName())) {
// load a properties file
props = new Properties();
props.load(input);
} catch (IOException ex) {
logger.error("[getProps] error", ex);
}
}
return props;
}
}

View File

@ -117,7 +117,7 @@ public class MailSender {
props.put("mail.smtp.host", smtpHostName);
//ssl
if(!StringUtils.isBlank(seclev)&&seclev.equals("true")) {
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
// Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
props.put("mail.smtp.socketFactory.class", SSL_FACTORY);
props.put("mail.smtp.socketFactory.fallback", "false");

View File

@ -5,11 +5,11 @@
'|...' '|..|' .||. ||. '|.' '|..'|' '|...' '|.' '|...' '|...' .||. ||. '|.' '|...' .||.
==================== Powered by Chatopera Inc. =================
春松客服: 越是重视客户服务,越是好的企业 v${git.build.version} build ${git.commit.id.abbrev}
版权所有 © 北京华夏春松科技有限公司️ https://www.chatopera.com/
商业许可授权联系商务顾问 https://www.chatopera.com/mail.html
春松客服: 做好开源客服系统 v${git.build.version} build ${git.commit.id.abbrev}
开源许可证Apache License 2.0
开源地址https://github.com/chatopera/cskefu
第一次安装后,参考系统初始化文档,对系统进行初始化,再使用
第一次安装后,参考系统初始化文档,对系统进行初始化,再使用
https://docs.chatopera.com/products/cskefu/initialization.html
使用过程中,进行维护:备份、回复、升级等,参考文档
@ -17,9 +17,4 @@ https://docs.chatopera.com/products/cskefu/osc/maintainence.html
开源社区反馈建议& 提交 BUG
https://github.com/chatopera/cskefu/issues
春松客服之所以开源,是基于这样一种信念:爱人也是爱己,利他也是利己。
对人和人美好关系的向往,对人潜力的信任。让我们相信因春松客服而受益的人,会回报给春松客服开源社区,我们所有贡献者基于共赢的信念合作。
回报方式包括:提交 PR、购买春松客服相关的付费产品和服务等。
因春松客服受益,而不回报开源社区的用户,我们不欢迎使用春松客服:我们开源并不是为了你们,你们是不被祝福的。
----------------------------------------------------------------

View File

@ -6,7 +6,7 @@
<version>7.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>cc-root</name>
<description>春松客服:多渠道智能客服系统</description>
<description>春松客服:做好开源客服系统</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
@ -18,6 +18,13 @@
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>com.chatopera.cc</groupId>
<artifactId>pep</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>

View File

@ -30,7 +30,10 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
import org.apache.commons.lang.StringUtils;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -699,7 +702,13 @@ public class ApiChatbotController extends Handler {
resp.addProperty(RestUtils.RESP_KEY_RC, RestUtils.RESP_RC_FAIL_5);
resp.addProperty(RestUtils.RESP_KEY_DATA, "查询不成功,智能问答引擎服务异常。");
}
} catch (JsonSyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return resp;
}

View File

@ -86,7 +86,12 @@ public class ChatbotEventSubscription {
public void onMessage(final String payload) {
ChatMessage message = SerializeUtil.deserialize(payload);
try {
chat(message);
try {
chat(message);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (MalformedURLException e) {
logger.error("[onMessage] error", e);
} catch (ChatbotException e) {
@ -346,9 +351,14 @@ public class ChatbotEventSubscription {
private void updateAgentUserWithRespData(final String userid, final String orgi, final JSONObject data) throws JSONException {
cache.findOneAgentUserByUserIdAndOrgi(userid, orgi).ifPresent(p -> {
p.setChatbotround(p.getChatbotround() + 1);
if (data.has("logic_is_unexpected") && data.getBoolean("logic_is_unexpected")) {
p.setChatbotlogicerror(p.getChatbotlogicerror() + 1);
}
try {
if (data.has("logic_is_unexpected") && data.getBoolean("logic_is_unexpected")) {
p.setChatbotlogicerror(p.getChatbotlogicerror() + 1);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
agentUserRes.save(p);
});