Pārlūkot izejas kodu

style:000.000.009:代码格式优化

yang yi 1 mēnesi atpakaļ
vecāks
revīzija
562f6a814e

+ 1 - 1
BI_front/index.html

@@ -4,7 +4,7 @@
     <meta charset="UTF-8" />
     <link rel="icon" type="image/svg+xml" href="/icon.svg" />
     <meta name="viewport" content="width=device-width, initial-scale=1.0" />
-    <title>BI</title>
+    <title>智能AI数据分析平台</title>
       <!--边距和内边距清零-->
       <style>
           * {

+ 1 - 1
BI_front/src/components/CommonAside.vue

@@ -2,7 +2,7 @@
   <el-menu default-active="1-4-1" class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose"
            :collapse="isCollapse" background-color="#545c64" text-color="#fff" active-text-color="#ffd04b" :router="true">
     <!-- 要放到导航栏里面 -->
-    <h3>{{isCollapse?"BI":"BI生成系统"}}</h3>
+    <h3>{{isCollapse?"菜单":"智能AI数据分析系统"}}</h3>
     <!-- 观察数据,我们发现name是唯一标识 -->
     <!-- 查看文档,index是唯一标识 -->
     <el-menu-item  :key="'/index'" :index="'/index'">

+ 6 - 0
BI_front/src/views/generateChart.vue

@@ -284,6 +284,12 @@ export default {
               type: 'success',
             });
             this.chartId = undefined;
+        }else if(res.code == 200 && res.data.state == '失败') {
+          ElMessage({
+            message: "图表生成失败",
+            type: 'error',
+            });
+          this.chartId = undefined;
         }else if (res.code == 200){
           ElMessage({
             message: res.data.state,

+ 3 - 3
serve/sql/init.sql

@@ -1,7 +1,7 @@
--- 创建一个名为bi的数据库
-create database if not exists bi;
+-- 创建一个名为data_analysis的数据库
+create database if not exists data_analysis;
 -- 切换到bi数据库
-use bi;
+use data_analysis;
 
 -- 创建一个名为users的表,用于存储用户信息
 CREATE TABLE  if NOT EXISTS `user` (

+ 1 - 1
serve/src/main/java/space/anyi/BI/config/SecurityConfig.java

@@ -58,7 +58,7 @@ public class SecurityConfig  extends WebSecurityConfigurerAdapter {
                 .authorizeRequests()
                 // 对于登录接口 允许匿名访问
                 .antMatchers(HttpMethod.POST,"/user/login","/user/register").anonymous()
-                .antMatchers(HttpMethod.GET,"/swagger/**","/v2/**","/v2/api-docs-ext/**","/swagger-resources/**").anonymous()
+                //.antMatchers(HttpMethod.GET,"/swagger/**","/v2/**","/v2/api-docs-ext/**","/swagger-resources/**").anonymous()
                 //放行对静态资源的访问
                 .antMatchers(HttpMethod.GET,"/","/*.html","/**/*.css","/**/*.js","/img/**","/fonts/**").permitAll()
                 .antMatchers(HttpMethod.GET,"/user/getUserInfo").permitAll()

+ 1 - 1
serve/src/main/java/space/anyi/BI/config/ThreadPoolExecutorConfig.java

@@ -28,7 +28,7 @@ public class ThreadPoolExecutorConfig {
         //时间单位
         TimeUnit unit = TimeUnit.SECONDS;
         //任务队列
-        BlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<>(5);
+        BlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<>(100);
         //线程工厂
         ThreadFactory threadFactory = new ThreadFactory() {
             @Override

+ 39 - 30
serve/src/main/java/space/anyi/BI/service/impl/ChartServiceImpl.java

@@ -27,6 +27,7 @@ import javax.annotation.Resource;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.RejectedExecutionException;
 import java.util.concurrent.ThreadPoolExecutor;
 
 /**
@@ -78,39 +79,47 @@ public class ChartServiceImpl extends ServiceImpl<ChartMapper, Chart>
         save(chart);
         //使用线程池优化生成图表的逻辑
         String finalCsvData = csvData;
-        threadPoolExecutor.execute(()->{
-            chart.setState("生成中");
-           updateById(chart);
+        try {
+            threadPoolExecutor.execute(()->{
+                chart.setState("生成中");
+               updateById(chart);
 
-            StringBuilder message = new StringBuilder("原始数据:\n");
-            message.append(finalCsvData);
-            message.append("分析目标:\n");
-            message.append(chartDTO.getAnalysisTarget());
-            message.append("\n.使用").append(chartDTO.getChartType()).append("进行可视化分析.\n");
-            //配置prompt向AI发送请求
-            HttpRequestData requestData = AiUtil.createDefaultRequestData(message.toString());
-            HttpResponseData responseData = AiUtil.doChat(requestData);
-            //解析AI返回的数据
-            String content = responseData.getChoices().get(0).getMessage().getContent();
-            log.info("AI返回的数据为:{}", content);
-            int index = content.indexOf("```");
-            int endIndex = content.lastIndexOf("```");
-            if (index == -1 || endIndex == -1){
-                chart.setState("失败");
-                chart.setExecuteMessage("AI生成图表失败");
+                StringBuilder message = new StringBuilder("原始数据:\n");
+                message.append(finalCsvData);
+                message.append("分析目标:\n");
+                message.append(chartDTO.getAnalysisTarget());
+                message.append("\n.使用").append(chartDTO.getChartType()).append("进行可视化分析.\n");
+                //配置prompt向AI发送请求
+                HttpRequestData requestData = AiUtil.createDefaultRequestData(message.toString());
+                HttpResponseData responseData = AiUtil.doChat(requestData);
+                //解析AI返回的数据
+                String content = responseData.getChoices().get(0).getMessage().getContent();
+                log.info("AI返回的数据为:{}", content);
+                int index = content.indexOf("```");
+                int endIndex = content.lastIndexOf("```");
+                if (index == -1 || endIndex == -1){
+                    chart.setState("失败");
+                    chart.setExecuteMessage("AI生成图表失败");
+                    updateById(chart);
+                    throw new SystemException(500, "AI生成图表失败");
+                }
+                //数据可视化,Echarts的option代码
+                chart.setGeneratedChartData(content.substring(index+7, endIndex).trim());
+                index = endIndex;
+                //分析结论
+                chart.setAnalysisConclusion(content.substring(index+3).trim());
+                //保存到数据库
+                chart.setState("成功");
+                chart.setExecuteMessage("AI生成图表成功");
                 updateById(chart);
-                throw new SystemException(500, "AI生成图表失败");
-            }
-            //数据可视化,Echarts的option代码
-            chart.setGeneratedChartData(content.substring(index+7, endIndex).trim());
-            index = endIndex;
-            //分析结论
-            chart.setAnalysisConclusion(content.substring(index+3).trim());
-            //保存到数据库
-            chart.setState("成功");
-            chart.setExecuteMessage("AI生成图表成功");
+            });
+        } catch (RejectedExecutionException e) {
+            //e.printStackTrace();
+            log.error("线程池已满,请稍后再试",e);
+            chart.setState("失败");
+            chart.setExecuteMessage("系统异常");
             updateById(chart);
-        });
+        }
 
         return chartId;
     }

+ 2 - 5
serve/src/main/resources/application.yaml

@@ -1,9 +1,9 @@
 spring:
   application:
-    name: BI
+    name: 智能AI数据分析系统
   datasource:
     driver-class-name: com.mysql.jdbc.Driver
-    url: jdbc:mysql://anyi.space:3307/data_analysis?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
+    url: jdbc:mysql://localhost:3306/data_analysis?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
     username: gdit
     password: gdit
   mvc:
@@ -12,10 +12,7 @@ spring:
   redis:
     database: 0
     host: localhost
-#    host: anyi.space
-#    port: 7000
     port: 6379
-#    password: yangyi
 server:
   port: 8888
   servlet: