Explorar el Código

Merge branch 'master' of http://gogs.seec.seecoder.cn/DingXiaoYu/AI-Backend

191250028 hace 3 años
padre
commit
6b4015b0cd

+ 1 - 1
.idea/sqldialects.xml

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
   <component name="SqlDialectMappings">
-    <file url="file://$PROJECT_DIR$/java_compile/src/main/resources/script.sql" dialect="GenericSQL" />
+    <file url="file://$PROJECT_DIR$/java_compile/src/main/resources/script.sql" dialect="MySQL" />
   </component>
 </project>

+ 0 - 6
java_compile/a.csv

@@ -1,6 +0,0 @@
- score,label
-1,1
-2,1
-3,0
-4,0
-5,0

+ 1 - 1
java_compile/src/main/java/com/example/controller/FileController.java

@@ -39,7 +39,7 @@ public class FileController {
             return rsl != 0 ? new NormalRes(rsl) : new ErrorRes(40002, "Server error.");
         } catch (Exception e) {
             log.info("error fileLoader");
-            return new ErrorRes();
+            return new ErrorRes(40002,e.getMessage());
         }
     }
 

+ 1 - 1
java_compile/src/main/java/com/example/entity/HeaderInfo.java

@@ -16,7 +16,7 @@ import javax.persistence.*;
 @Table(name = "header_info")
 public class HeaderInfo {
     @Id
-    @GeneratedValue(strategy = GenerationType.AUTO)
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
     private int id;
     private int fileInfoId;  //文件id
     private String fieldName;   //文件头的字段信息

+ 13 - 4
java_compile/src/main/java/com/example/services/FileService.java

@@ -64,10 +64,19 @@ public class FileService {
         String fileType = FileHelper.getFileType(filename);
         File file = FileHelper.multipartToFile(inFile);
         log.info("server file location: " + file.getAbsolutePath());
-        int rsl = "csv".equals(fileType) ? csvLoader.loadCsv(file.getAbsolutePath(), userId) :
-                sasLoader.loadSas(file.getAbsolutePath(), userId);
-        file.delete();
-        return rsl;
+        try{
+//          return  "csv".equals(fileType) ? csvLoader.loadCsv(file.getAbsolutePath(), userId) :
+//                    sasLoader.loadSas(file.getAbsolutePath(), userId);
+            //数据库中不能用同名文件
+            if (fileInfoDao.findByUserIdAndFilename(userId,filename)!=null){
+                throw new Exception("文件已经存在了。");
+            }
+            //暂时只接受csv
+            return  "csv".equals(fileType) ? csvAdapter.Csv2Parquet(file.getAbsolutePath(), filename, userId) : 0;
+        }finally {
+            //上传失败也必须将文件在本地删除,否则会堆积
+            file.delete();
+        }
     }
 
     public void deleteFile(int fileId) throws Exception {

+ 5 - 6
java_compile/src/main/resources/script.sql

@@ -1,3 +1,6 @@
+drop database ai_program;
+create database ai_program;
+use ai_program;
 create table config
 (
     id            int auto_increment
@@ -46,7 +49,7 @@ create table func_info
 
 create table header_info
 (
-    id           int          not null
+    id              int auto_increment
         primary key,
     alias_name   varchar(255) null,
     con_or_dis   int          not null,
@@ -58,11 +61,6 @@ create table header_info
     value_info   varchar(255) null
 );
 
-create table hibernate_sequence
-(
-    next_val bigint null
-);
-
 create table layer_argument
 (
     id          int          not null
@@ -98,6 +96,7 @@ create table model_type
     model_detail_name varchar(255) null,
     model_type_name   varchar(255) null
 );
+INSERT INTO `model_type` VALUES (1,NULL,NULL,NULL,'LogisticRegression','逻辑回归'),(2,NULL,NULL,NULL,'DecisionTree','决策树'),(3,NULL,NULL,NULL,'RandomForest','随机森林'),(4,NULL,NULL,NULL,'GBDT','梯度提升决策树'),(5,NULL,NULL,NULL,'K-Means','K-均值'),(6,NULL,NULL,NULL,'MultilayerPerceptronClassifier','多层感知器分类器'),(7,NULL,NULL,NULL,'NaiveBayes','朴素贝叶斯'),(8,NULL,NULL,NULL,'RandomForestRegression','随机森林回归');
 
 create table model_type_argument
 (

+ 1 - 1
java_compile/src/main/scala/com/example/data/CsvAdapter.scala

@@ -96,7 +96,7 @@ class CsvAdapter extends SparkConnect{
       headerInfoDao.save(new HeaderInfo(fileId, field.name, field.dataType.catalogString))
     })
     //7. 分析文件
-     fileService.analysis(fileId);
+    fileService.analysis(fileId);
     fileId
   }
 }