feat: 对接百度开发者中心文心一言的聊天

This commit is contained in:
weizhiqiang 2024-10-05 18:23:02 +08:00
parent 5bd8ac3620
commit 875a0b78b3
23 changed files with 972 additions and 0 deletions

17
skyeye-ai/.gitignore vendored Normal file
View file

@ -0,0 +1,17 @@
*.class
# Package Files #
*.war
*.ear
class
.idea
*.iml
.settings
*.classpath
/bin
classes
/target/
/.project/
/.metadata/
/logs/

View file

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>skyeye-ai</artifactId>
<groupId>com.skyeye</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ai-common</artifactId>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- 引入公共模块 -->
<dependency>
<groupId>com.skyeye</groupId>
<artifactId>skyeye-common-rest</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

Binary file not shown.

View file

@ -0,0 +1,5 @@
#Generated by Maven
#Sat Oct 05 12:34:57 CST 2024
version=1.0-SNAPSHOT
groupId=com.skyeye
artifactId=ai-common

62
skyeye-ai/ai-pro/pom.xml Normal file
View file

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>skyeye-ai</artifactId>
<groupId>com.skyeye</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ai-pro</artifactId>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- db -->
<c3p0.version>0.9.5.2</c3p0.version>
<druid.version>1.0.25</druid.version>
</properties>
<dependencies>
<!-- 引入common的依赖 -->
<dependency>
<groupId>com.skyeye</groupId>
<artifactId>ai-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.8.0</version>
</dependency>
<!-- db -->
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>${c3p0.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid.version}</version>
</dependency>
<dependency>
<groupId>com.baidubce</groupId>
<artifactId>qianfan</artifactId>
<version>0.1.1</version>
</dependency>
</dependencies>
</project>

View file

@ -0,0 +1,30 @@
/*******************************************************************************
* Copyright 卫志强 QQ598748873@qq.com Inc. All rights reserved. 开源地址https://gitee.com/doc_wei01/skyeye
******************************************************************************/
package com.skyeye.ai.core.config;
import com.skyeye.ai.core.factory.AiFactory;
import com.skyeye.ai.core.factory.AiFactoryImpl;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @ClassName: AiConfiguration
* @Description: AI配置类
* @author: skyeye云系列--卫志强
* @date: 2024/8/18 22:10
* @Copyright: 2024 https://gitee.com/doc_wei01/skyeye Inc. All rights reserved.
* 注意本内容仅限购买后使用.禁止私自外泄以及用于其他的商业目的
*/
@Configuration
@EnableConfigurationProperties(SkyeyeAiProperties.class)
public class AiConfiguration {
@Bean
public AiFactory aiClientFactory() {
return new AiFactoryImpl();
}
}

View file

@ -0,0 +1,29 @@
/*******************************************************************************
* Copyright 卫志强 QQ598748873@qq.com Inc. All rights reserved. 开源地址https://gitee.com/doc_wei01/skyeye
******************************************************************************/
package com.skyeye.ai.core.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* @ClassName: SkyeyeAiProperties
* @Description: Skyeye AI 配置类
* @author: skyeye云系列--卫志强
* @date: 2024/10/5 18:03
* @Copyright: 2024 https://gitee.com/doc_wei01/skyeye Inc. All rights reserved.
* 注意本内容仅限购买后使用.禁止私自外泄以及用于其他的商业目的
*/
@Data
@ConfigurationProperties(prefix = "spring.ai")
public class SkyeyeAiProperties {
private QianfanProperties qianfan;
@Data
public static class QianfanProperties {
private String apiKey;
private String secretKey;
}
}

View file

@ -0,0 +1,48 @@
/*******************************************************************************
* Copyright 卫志强 QQ598748873@qq.com Inc. All rights reserved. 开源地址https://gitee.com/doc_wei01/skyeye
******************************************************************************/
package com.skyeye.ai.core.enums;
import cn.hutool.core.util.StrUtil;
import com.skyeye.common.base.classenum.SkyeyeEnumClass;
import com.skyeye.exception.CustomException;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
/**
* @ClassName: AiPlatformEnum
* @Description: AI 模型平台
* @author: skyeye云系列--卫志强
* @date: 2024/10/5 11:33
* @Copyright: 2024 https://gitee.com/doc_wei01/skyeye Inc. All rights reserved.
* 注意本内容仅限购买后使用.禁止私自外泄以及用于其他的商业目的
*/
@Getter
@NoArgsConstructor
@AllArgsConstructor
public enum AiPlatformEnum implements SkyeyeEnumClass {
YI_YAN("YiYan", "文心一言", "百度", true, false);
private String key;
private String value;
private String remark;
private Boolean show;
private Boolean isDefault;
public static AiPlatformEnum getName(String key) {
for (AiPlatformEnum bean : AiPlatformEnum.values()) {
if (StrUtil.equals(key, bean.getKey())) {
return bean;
}
}
throw new CustomException("非法的AI平台状态");
}
}

View file

@ -0,0 +1,63 @@
/*******************************************************************************
* Copyright 卫志强 QQ598748873@qq.com Inc. All rights reserved. 开源地址https://gitee.com/doc_wei01/skyeye
******************************************************************************/
package com.skyeye.ai.core.factory;
import com.skyeye.ai.core.enums.AiPlatformEnum;
/**
* @ClassName: AiFactory
* @Description: AI Model 模型工厂的接口类
* @author: skyeye云系列--卫志强
* @date: 2024/10/5 11:33
* @Copyright: 2024 https://gitee.com/doc_wei01/skyeye Inc. All rights reserved.
* 注意本内容仅限购买后使用.禁止私自外泄以及用于其他的商业目的
*/
public interface AiFactory {
/**
* 基于指定配置获得 ChatModel 对象
* <p>
* 如果不存在则进行创建
*
* @param platform 平台
* @param apiKey API KEY
* @param url API URL
* @return ChatModel 对象
*/
Object getOrCreateChatModel(AiPlatformEnum platform, String apiKey, String secretKey, String url);
/**
* 基于默认配置获得 ChatModel 对象
* <p>
* 默认配置指的是在 application.yaml 配置文件中的 spring.ai 相关的配置
*
* @param platform 平台
* @return ChatModel 对象
*/
Object getDefaultChatModel(AiPlatformEnum platform);
/**
* 基于默认配置获得 ImageModel 对象
* <p>
* 默认配置指的是在 application.yaml 配置文件中的 spring.ai 相关的配置
*
* @param platform 平台
* @return ImageModel 对象
*/
Object getDefaultImageModel(AiPlatformEnum platform);
/**
* 基于指定配置获得 ImageModel 对象
* <p>
* 如果不存在则进行创建
*
* @param platform 平台
* @param apiKey API KEY
* @param url API URL
* @return ImageModel 对象
*/
Object getOrCreateImageModel(AiPlatformEnum platform, String apiKey, String url);
}

View file

@ -0,0 +1,82 @@
/*******************************************************************************
* Copyright 卫志强 QQ598748873@qq.com Inc. All rights reserved. 开源地址https://gitee.com/doc_wei01/skyeye
******************************************************************************/
package com.skyeye.ai.core.factory;
import cn.hutool.core.lang.Singleton;
import cn.hutool.core.lang.func.Func0;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import com.baidubce.qianfan.Qianfan;
import com.baidubce.qianfan.core.auth.Auth;
import com.skyeye.ai.core.config.SkyeyeAiProperties;
import com.skyeye.ai.core.enums.AiPlatformEnum;
import com.skyeye.exception.CustomException;
import org.springframework.beans.factory.annotation.Autowired;
/**
* @ClassName: AiFactoryImpl
* @Description: AI Model 模型工厂的实现类
* @author: skyeye云系列--卫志强
* @date: 2024/10/5 14:09
* @Copyright: 2024 https://gitee.com/doc_wei01/skyeye Inc. All rights reserved.
* 注意本内容仅限购买后使用.禁止私自外泄以及用于其他的商业目的
*/
public class AiFactoryImpl implements AiFactory {
@Autowired
private SkyeyeAiProperties skyeyeAiProperties;
@Override
public Object getOrCreateChatModel(AiPlatformEnum platform, String apiKey, String secretKey, String url) {
String cacheKey = buildClientCacheKey(platform, apiKey, url);
return Singleton.get(cacheKey, (Func0<Object>) () -> {
switch (platform) {
case YI_YAN:
return buildYiYanChatModel(apiKey, secretKey);
default:
throw new IllegalArgumentException(StrUtil.format("未知平台({})", platform));
}
});
}
@Override
public Object getDefaultChatModel(AiPlatformEnum platform) {
return getOrCreateChatModel(platform, skyeyeAiProperties.getQianfan().getApiKey(), skyeyeAiProperties.getQianfan().getSecretKey(), null);
}
@Override
public Object getDefaultImageModel(AiPlatformEnum platform) {
switch (platform) {
case YI_YAN:
// return SpringUtil.getBean(Qianfan.class);
default:
throw new CustomException(StrUtil.format("未知平台({})", platform));
}
}
@Override
public Object getOrCreateImageModel(AiPlatformEnum platform, String apiKey, String url) {
switch (platform) {
case YI_YAN:
default:
throw new CustomException(StrUtil.format("未知平台({})", platform));
}
}
private static String buildClientCacheKey(Object... params) {
if (ArrayUtil.isEmpty(params)) {
throw new CustomException("请指定参数");
}
return StrUtil.format("{}", ArrayUtil.join(params, "_"));
}
// ========== 各种创建 spring-ai 客户端的方法 ==========
private static Qianfan buildYiYanChatModel(String apiKey, String secretKey) {
Qianfan qianFanApi = new Qianfan(Auth.TYPE_OAUTH, apiKey, secretKey);
return qianFanApi;
}
}

View file

@ -0,0 +1,41 @@
/*******************************************************************************
* Copyright 卫志强 QQ598748873@qq.com Inc. All rights reserved. 开源地址https://gitee.com/doc_wei01/skyeye
******************************************************************************/
package com.skyeye.message.controller;
import com.skyeye.annotation.api.Api;
import com.skyeye.annotation.api.ApiImplicitParam;
import com.skyeye.annotation.api.ApiImplicitParams;
import com.skyeye.annotation.api.ApiOperation;
import com.skyeye.common.object.InputObject;
import com.skyeye.common.object.OutputObject;
import com.skyeye.message.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @ClassName: MessageController
* @Description: 消息控制层
* @author: skyeye云系列--卫志强
* @date: 2024/10/5 17:24
* @Copyright: 2024 https://gitee.com/doc_wei01/skyeye Inc. All rights reserved.
* 注意本内容仅限购买后使用.禁止私自外泄以及用于其他的商业目的
*/
@RestController
@Api(value = "消息管理", tags = "消息管理", modelName = "消息管理")
public class MessageController {
@Autowired
private MessageService messageService;
@ApiOperation(id = "sendMessage", value = "发送消息", method = "POST", allUse = "0")
@ApiImplicitParams({
@ApiImplicitParam(id = "message", name = "message", value = "消息", required = "required")})
@RequestMapping("/post/MessageController/sendMessage")
public void sendMessage(InputObject inputObject, OutputObject outputObject) {
messageService.sendMessage(inputObject, outputObject);
}
}

View file

@ -0,0 +1,22 @@
/*******************************************************************************
* Copyright 卫志强 QQ598748873@qq.com Inc. All rights reserved. 开源地址https://gitee.com/doc_wei01/skyeye
******************************************************************************/
package com.skyeye.message.service;
import com.skyeye.common.object.InputObject;
import com.skyeye.common.object.OutputObject;
/**
* @ClassName: MessageService
* @Description: 消息服务接口
* @author: skyeye云系列--卫志强
* @date: 2024/10/5 17:24
* @Copyright: 2024 https://gitee.com/doc_wei01/skyeye Inc. All rights reserved.
* 注意本内容仅限购买后使用.禁止私自外泄以及用于其他的商业目的
*/
public interface MessageService {
void sendMessage(InputObject inputObject, OutputObject outputObject);
}

View file

@ -0,0 +1,50 @@
/*******************************************************************************
* Copyright 卫志强 QQ598748873@qq.com Inc. All rights reserved. 开源地址https://gitee.com/doc_wei01/skyeye
******************************************************************************/
package com.skyeye.message.service.impl;
import com.baidubce.qianfan.Qianfan;
import com.baidubce.qianfan.core.builder.ChatBuilder;
import com.baidubce.qianfan.model.chat.ChatResponse;
import com.skyeye.ai.core.enums.AiPlatformEnum;
import com.skyeye.ai.core.factory.AiFactory;
import com.skyeye.annotation.service.SkyeyeService;
import com.skyeye.common.constans.CommonNumConstants;
import com.skyeye.common.object.InputObject;
import com.skyeye.common.object.OutputObject;
import com.skyeye.message.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
/**
* @ClassName: MessageServiceImpl
* @Description: 消息服务实现类
* @author: skyeye云系列--卫志强
* @date: 2024/10/5 17:25
* @Copyright: 2024 https://gitee.com/doc_wei01/skyeye Inc. All rights reserved.
* 注意本内容仅限购买后使用.禁止私自外泄以及用于其他的商业目的
*/
@Service
@SkyeyeService(name = "消息管理", groupName = "消息管理")
public class MessageServiceImpl implements MessageService {
@Autowired
private AiFactory aiFactory;
@Override
public void sendMessage(InputObject inputObject, OutputObject outputObject) {
Map<String, Object> params = inputObject.getParams();
String message = params.get("message").toString();
Qianfan qianfan = (Qianfan) aiFactory.getDefaultChatModel(AiPlatformEnum.YI_YAN);
ChatBuilder bulder = qianfan.chatCompletion()
.model("ERNIE-Speed-8K");//你要使用的大模型款式最好和我一样其他的很有可能是收费的
bulder.addMessage("user", message);//你的问题
ChatResponse response = bulder.execute();
outputObject.setBean(response);
outputObject.settotal(CommonNumConstants.NUM_ONE);
}
}

91
skyeye-ai/ai-web/pom.xml Normal file
View file

@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>skyeye-ai</artifactId>
<groupId>com.skyeye</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ai-web</artifactId>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.skyeye</groupId>
<artifactId>ai-pro</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- actuator监控 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- Spring Boot Actuator对外暴露引用的监控信息, Jolokia提供使用HTTP接口获取json -->
<dependency>
<groupId>org.jolokia</groupId>
<artifactId>jolokia-core</artifactId>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<!-- 资源文件拷贝插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!--spring-boot打包 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal> <!-- 将引入的 jar 打入其中 -->
</goals>
</execution>
</executions>
</plugin>
<!--打包跳过测试 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<!-- java编译插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>

View file

@ -0,0 +1,29 @@
/*******************************************************************************
* Copyright 卫志强 QQ598748873@qq.com Inc. All rights reserved. 开源地址https://gitee.com/doc_wei01/skyeye
******************************************************************************/
package com.skyeye;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@SpringBootApplication
@EnableAutoConfiguration(exclude = {
org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class
})
@EnableTransactionManagement//启注解事务管理等同于xml配置方式的 <tx:annotation-driven />
@EnableDiscoveryClient // 开启服务发现
@EnableFeignClients
public class SkyAiApplication {
public static void main(String[] args) {
System.setProperty("spring.devtools.restart.enabled", "false");
SpringApplication.run(SkyAiApplication.class, args);
}
}

View file

@ -0,0 +1,163 @@
/*******************************************************************************
* Copyright 卫志强 QQ598748873@qq.com Inc. All rights reserved. 开源地址https://gitee.com/doc_wei01/skyeye
******************************************************************************/
package com.skyeye.db.config;
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
import com.skyeye.common.constans.CommonConstants;
import com.skyeye.exception.CustomException;
import org.apache.commons.collections.CollectionUtils;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import javax.sql.DataSource;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
@Configuration
@MapperScan(basePackages = {
"com.skyeye.eve.*.dao",
"com.skyeye.*.dao"}, sqlSessionFactoryRef = "baseSqlSessionFactory")
public class BaseDataSourceConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(BaseDataSourceConfig.class);
protected static Properties databaseTypeMappings = CommonConstants.getDefaultDatabaseTypeMappings();
@Autowired
protected ResourceLoader resourceLoader;
/**
* Primary 必须加此注解不然报错下一个类则不需要添加表示这个数据源是默认数据源
* ConfigurationProperties(prefix)值必须是application.properteis中对应属性的前缀
*
* @return
*/
@Bean(name = "baseDataSource")
@Primary
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource baseDataSource() {
return DataSourceBuilder.create().build();
}
/**
* aSqlSessionFactory 一旦被创建就应该在应用的运行期间一直存在没有任何理由对它进行清除或重建
* b使用 SqlSessionFactory 的最佳实践是在应用运行期间不要重复创建多次多次重建 SqlSessionFactory 被视为一种代码坏味道bad smell
* c因此 SqlSessionFactory 的最佳作用域是应用作用域有很多方法可以做到最简单的就是使用单例模式或者静态单例模式
*
* @param dataSource
* @return
*/
@Primary
@Bean(name = "baseSqlSessionFactory")
public SqlSessionFactory baseSqlSessionFactory(@Qualifier("baseDataSource") DataSource dataSource) {
MybatisSqlSessionFactoryBean sqlSessionFactoryBean = new MybatisSqlSessionFactoryBean();
sqlSessionFactoryBean.setDataSource(dataSource);
String databaseType = this.initDatabaseType(dataSource);
if (databaseType == null) {
throw new CustomException("couldn't deduct database type");
} else {
try {
// 添加XML目录
sqlSessionFactoryBean.setMapperLocations(resolveMapperLocations());
sqlSessionFactoryBean.afterPropertiesSet();
return sqlSessionFactoryBean.getObject();
} catch (Exception var5) {
throw new CustomException("Could not create sqlSessionFactory", var5);
}
}
}
public Resource[] resolveMapperLocations() {
ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();
List<String> mapperLocations = new ArrayList<>();
mapperLocations.add("classpath*:mapper/**/*.xml");
List<Resource> resources = new ArrayList();
if (!CollectionUtils.isEmpty(mapperLocations)) {
for (String mapperLocation : mapperLocations) {
try {
Resource[] mappers = resourceResolver.getResources(mapperLocation);
resources.addAll(Arrays.asList(mappers));
} catch (IOException e) {
LOGGER.error("Get myBatis resources happened exception", e);
}
}
}
return resources.toArray(new Resource[resources.size()]);
}
@Primary
@Bean(name = "transactionManager")
public PlatformTransactionManager transactionManager(@Qualifier("baseDataSource") DataSource dataSourceOne) {
return new DataSourceTransactionManager(dataSourceOne);
}
@Primary
@Bean(name = "sqlSessionTemplate")
public SqlSessionTemplate sqlSessionTemplate(@Qualifier("baseSqlSessionFactory") SqlSessionFactory sqlSessionFactory) {
// 使用上面配置的Factory
return new SqlSessionTemplate(sqlSessionFactory);
}
/**
* 初始化
*
* @param dataSource
* @return
*/
protected String initDatabaseType(@Qualifier("baseDataSource") DataSource dataSource) {
String databaseType = null;
Connection connection = null;
try {
connection = dataSource.getConnection();
DatabaseMetaData databaseMetaData = connection.getMetaData();
String databaseProductName = databaseMetaData.getDatabaseProductName();
LOGGER.info("database product name: '{}'", databaseProductName);
databaseType = databaseTypeMappings.getProperty(databaseProductName);
if (databaseType == null) {
throw new CustomException("couldn't deduct database type from database product name '" + databaseProductName + "'");
}
LOGGER.info("using database type: {}", databaseType);
} catch (SQLException var14) {
LOGGER.error("Exception while initializing Database connection", var14);
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException var13) {
LOGGER.error("Exception while closing the Database connection", var13);
}
}
databaseType = ("dm".equals(databaseType)) ? "oracle" : databaseType;
return databaseType;
}
}

View file

@ -0,0 +1,34 @@
/**
* _ooOoo_
* o8888888o
* 88" . "88
* (| -_- |)
* O\ = /O
* ____/`---'\____
* .' \\| |// `.
* / \\||| : |||// \
* / _||||| -:- |||||- \
* | | \\\ - /// | |
* | \_| ''\---/'' | |
* \ .-\__ `-` ___/-. /
* ___`. .' /--.--\ `. . __
* ."" '< `.___\_<|>_/___.' >'"".
* | | : `- \`.;`\ _ /`;.`/ - ` : | |
* \ \ `-. \_ __\ /__ _/ .-` / /
* ======`-.____`-.___\_____/___.-`____.-'======
* `=---='
* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* 佛祖保佑 永无BUG
* 佛曰:
* 写字楼里写字间,写字间里程序员;
* 程序人员写程序,又拿程序换酒钱。
* 酒醒只在网上坐,酒醉还来网下眠;
* 酒醉酒醒日复日,网上网下年复年。
* 但愿老死电脑间,不愿鞠躬老板前;
* 奔驰宝马贵者趣,公交自行程序员。
* 别人笑我忒疯癫,我笑自己命太贱;
* 不见满街漂亮妹,哪个归得程序员?
* :: springboot 2.x
* :: Skyeye系列框架作者卫志强
* :: 作者独家专属,未购买禁止私自使用
*/

View file

@ -0,0 +1,47 @@
server:
port: 8120
spring:
application:
name: skyeye-ai-${spring.profiles.active} # 服务名
main:
allow-circular-references: true # 允许循环依赖,因为项目是三层架构,无法避免这个情况。
allow-bean-definition-overriding: true # 允许 Bean 覆盖,例如说 Feign 等会存在重复定义的服务
data:
redis:
repositories:
enabled: false # 项目未使用到 Spring Data Redis 的 Repository所以直接禁用保证启动速度
profiles:
active: dev
cloud:
nacos:
discovery:
server-addr: 172.18.92.40:8848 # 配置服务注册nacos地址
namespace: ${spring.profiles.active} # 配置命名空间
service: ${spring.application.name} # 配置服务名
config:
# 指定nacos server的地址
server-addr: 172.18.92.40:8848
# 配置文件后缀
file-extension: yml
# 命名空间 常用场景之一是不同环境的配置的区分隔离,例如开发测试环境和生产环境的资源(如配置、服务)隔离等
namespace: ${spring.profiles.active} # 配置命名空间
# 支持多个共享 Data Id 的配置优先级小于ext-config,自定义 Data Id 配置 属性是个集合,内部由 Config POJO 组成。Config 有 3 个属性,分别是 dataId, group 以及 refresh
ext-config:
- data-id: skyeye-common.yml # 配置文件名-Data Id
group: DEFAULT_GROUP # 默认为DEFAULT_GROUP
refresh: true # 是否动态刷新默认为false
ai:
qianfan: # 文心一言 https://console.bce.baidu.com/qianfan/ais/console/applicationConsole/application/v1
apiKey: EVdFG9fbFMmwtjQ57Efwftox
secretKey: XJ8jcR6jK06S5BCrPRYFoWqqlqbwyCXx
logging:
level:
com.skyeye: debug
feign:
client:
config:
# 全局配置
default:
loggerLevel: FULL

View file

@ -0,0 +1,22 @@
-- jvm堆的最小值3G
-Xms3072m
-- jvm堆的最大值3G
-Xmx3072m
-- 新生代内存区域的大小,设置新生代区域后,老年代内存=堆内存 - 新生代内存;老年代的最大内存 = 堆内存 - 新生代最大内存
-Xmn2048M
-- 新生代内存区域中Eden和Survivor的比例SurvivorRatio=8那么Eden区占8/102个Survivor区各占1/10
-XX:SurvivorRatio=8
-- 大小为区间为[0,15],如果高于15JDK7 会默认15JDK 8会启动报错
-XX:MaxTenuringThreshold=15
-- 输出GC的时间戳以日期的形式如 2019-05-04T21:53:59.234+0800
-XX:+PrintGCDateStamps
-- 打印出GC的详细信息
-XX:+PrintGCDetails
-- 在进行GC的前后打印出堆的信息
-XX:+PrintHeapAtGC
-- 打印年轻代各个引用的数量以及时长
-XX:+PrintReferenceGC
-- 开启gc日志
-verbose:gc
-- gc日志的存放位置
-Xloggc:d:/gc.log

View file

@ -0,0 +1,70 @@
### set log levels这里的INFO,Stdout,D,E可以理解为变量也可以说是输出平台在下面我们可以看到 ###
log4j.rootLogger = INFO, C, D, E
### console控制台输出 ###
log4j.appender.C = org.apache.log4j.ConsoleAppender
### System.out也就是输出 out输出是黑色字体err输出的字体是红色 ###
log4j.appender.C.Target = System.out
### layout是指布局也就是说输出日志信息的格式样式在这里我们使用的是log4j提供的 ###
log4j.appender.C.layout = org.apache.log4j.PatternLayout
### 这里就是指定我们日志文件以哪一种格式去输出 ###
log4j.appender.C.layout.ConversionPattern = [skyeye-promote][%p] [%-d{yyyy-MM-dd HH:mm:ss}] %C.%M(%L) | %m%n
### log file INFO级别输出日志文件 ###
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
### 指定日志输出位置 ###
log4j.appender.D.File = ../logs/skyeye.log
### 这个的意思是指是追加还是覆盖 默认是 true true是追加 false是覆盖 ###
log4j.appender.D.Append = true
### 这个是指日志输出的级别在这里指定的是 INFO级别 ###
log4j.appender.D.Threshold = INFO
### layout是指布局也就是说输出日志信息的格式样式在这里我们使用的是log4j提供的 ###
log4j.appender.D.layout = org.apache.log4j.PatternLayout
### 这里就是指定我们日志文件以哪一种格式去输出 ###
log4j.appender.D.layout.ConversionPattern = [skyeye-promote][%p] [%-d{yyyy-MM-dd HH:mm:ss}] %C.%M(%L) | %m%n
### exception ERROR级别输出日志文件 ###
#这个跟上面一样 只不过是日志级别是 ERROR级的方便我们直接查看系统异常信息
log4j.appender.E = org.apache.log4j.DailyRollingFileAppender
log4j.appender.E.File = ../logs/skyeye_error.log
log4j.appender.E.Append = true
log4j.appender.E.Threshold = ERROR
log4j.appender.E.layout = org.apache.log4j.PatternLayout
log4j.appender.E.layout.ConversionPattern = [skyeye-promote][%p] [%-d{yyyy-MM-dd HH:mm:ss}] %C.%M(%L) | %m%n
#localhost日志文件输出级别为INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = INFO
#localhost日志文件输出处理类2localhost.org.apache.juli.FileHandler
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = 2localhost.org.apache.juli.FileHandler
#manager日志文件输出级别为INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].level = INFO
#manager日志文件输出处理类3manager.org.apache.juli.FileHandler
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].handlers = 3manager.org.apache.juli.FileHandler
#host-manager日志文件输出级别为INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].level = INFO
#host-manager日志文件输出处理类4host-manager.org.apache.juli.FileHandler
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].handlers = 4host-manager.org.apache.juli.FileHandler
#设置包名的输出级别
log4j.logger.com.skyeye.common.filter=info, database
# 记录日志至数据库
# 这里定义了数据源
log4j.appender.database=org.apache.log4j.jdbc.JDBCAppender
log4j.appender.database.driver=com.mysql.jdbc.Driver
# BufferSize就是每次缓存多少条数据然后插入数据库为了演示这里设置为1
log4j.appender.database.BufferSize=1
# 数据库连接池
# 设置要将日志插入到数据库的驱动
log4j.appender.database.Threshold=info
log4j.appender.database.URL=${jdbc.database.path}
log4j.appender.database.user=${jdbc.database.username}
log4j.appender.database.password=${jdbc.database.password}
# 看名字也该明白这里是定义Sql语句的啦
log4j.appender.database.sql=insert into sys_work_log (id, class, mothod, create_time, log_level, log_line, message, user_name, file_name, real_path, req_ip) values (REPLACE(UUID(), '-', ''), '%C', '%M', '%d{yyyy-MM-dd HH:mm:ss}', '%p', '%l', '%m', '%X{userName}', '%F', '%X{realPath}', '%X{ip}')
log4j.appender.database.layout=org.apache.log4j.PatternLayout

38
skyeye-ai/pom.xml Normal file
View file

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.skyeye</groupId>
<artifactId>skyeye-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.skyeye</groupId>
<artifactId>skyeye-ai</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>ai-web</module>
<module>ai-pro</module>
<module>ai-common</module>
</modules>
<!-- 使用 huawei / aliyun 的 Maven 源,提升下载速度 -->
<repositories>
<repository>
<id>huaweicloud</id>
<name>huawei</name>
<url>https://mirrors.huaweicloud.com/repository/maven/</url>
</repository>
<repository>
<id>aliyunmaven</id>
<name>aliyun</name>
<url>https://maven.aliyun.com/repository/public</url>
</repository>
</repositories>
</project>