|
|
@@ -1,6 +1,5 @@
|
|
|
package com.example.services;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
import com.example.analysis.FileAnalysis;
|
|
|
import com.example.dao.*;
|
|
|
import com.example.data.CsvAdapter;
|
|
|
@@ -13,14 +12,14 @@ import com.example.entity.Model;
|
|
|
import com.example.services.pojo.*;
|
|
|
import com.example.util.FileHelper;
|
|
|
import com.example.util.Json2Object;
|
|
|
-import lombok.Data;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import lombok.val;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.File;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
@@ -30,32 +29,26 @@ import java.util.stream.Collectors;
|
|
|
* File-related service Created by lucas on 2016/11/14.
|
|
|
*/
|
|
|
@Slf4j
|
|
|
-@Component
|
|
|
-@Data
|
|
|
+@Service
|
|
|
public class FileService {
|
|
|
@Autowired
|
|
|
- private SasLoader sasLoader;
|
|
|
+ private SasLoader sasLoader;
|
|
|
@Autowired
|
|
|
- private CsvLoader csvLoader;
|
|
|
+ private CsvLoader csvLoader;
|
|
|
@Autowired
|
|
|
private CsvAdapter csvAdapter;
|
|
|
@Autowired
|
|
|
- private HdfsDao hdfsDao;
|
|
|
-
|
|
|
+ private HdfsDao hdfsDao;
|
|
|
@Autowired
|
|
|
private FileInfoDao fileInfoDao;
|
|
|
-
|
|
|
@Autowired
|
|
|
private ConfigDao configDao;
|
|
|
-
|
|
|
@Autowired
|
|
|
private HeaderInfoDao headerInfoDao;
|
|
|
@Autowired
|
|
|
private FileAnalysis fileAnalysis;
|
|
|
-
|
|
|
@Autowired
|
|
|
private ModelDao modelDao;
|
|
|
-
|
|
|
@Autowired
|
|
|
private FuncInfoDao funcInfoDao;
|
|
|
|
|
|
@@ -71,9 +64,8 @@ public class FileService {
|
|
|
String fileType = FileHelper.getFileType(filename);
|
|
|
File file = FileHelper.multipartToFile(inFile);
|
|
|
log.info("server file location: " + file.getAbsolutePath());
|
|
|
- int rsl = fileType.equals("csv") ? csvLoader.loadCsv(file.getAbsolutePath(), userId) :
|
|
|
+ int rsl = "csv".equals(fileType) ? csvLoader.loadCsv(file.getAbsolutePath(), userId) :
|
|
|
sasLoader.loadSas(file.getAbsolutePath(), userId);
|
|
|
-
|
|
|
file.delete();
|
|
|
return rsl;
|
|
|
}
|
|
|
@@ -99,8 +91,8 @@ public class FileService {
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public List<FileNamePojo> getAllFiles(int userId) throws Exception {
|
|
|
- val files = fileInfoDao.findByUserId(userId);
|
|
|
- val rsl = files.stream().map((file) -> new FileNamePojo(String.valueOf(file.getId()), file.getFilename()))
|
|
|
+ List<FileInfo> files = fileInfoDao.findByUserId(userId);
|
|
|
+ List<FileNamePojo> rsl = files.stream().map((file) -> new FileNamePojo(String.valueOf(file.getId()), file.getFilename()))
|
|
|
.collect(Collectors.toList());
|
|
|
return rsl;
|
|
|
}
|
|
|
@@ -120,8 +112,8 @@ public class FileService {
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public FileDetailPojo getFileDetailInfo(int fileId) throws Exception {
|
|
|
- val fileInfo = fileInfoDao.findById(fileId);
|
|
|
- val headerInfos = headerInfoDao.findByFileInfoId(fileId);
|
|
|
+ FileInfo fileInfo = fileInfoDao.findById(fileId);
|
|
|
+ List<HeaderInfo> headerInfos = headerInfoDao.findByFileInfoId(fileId);
|
|
|
return new FileDetailPojo(fileInfo.getFilename(), fileInfo.getUploadTime(), new Json2Object().Json2HashMap(fileInfo.getFileStrucInfo()), headerInfos);
|
|
|
}
|
|
|
|
|
|
@@ -130,7 +122,6 @@ public class FileService {
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public void analysis(int fileId) throws Exception {
|
|
|
-
|
|
|
try {
|
|
|
fileAnalysis.fileAnalysis(fileId, (float) 0.01);
|
|
|
} catch (Exception e) {
|
|
|
@@ -195,16 +186,14 @@ public class FileService {
|
|
|
* @return
|
|
|
*/
|
|
|
public boolean updateHeaderInfo(int headerId, String aliasName, String fieldDes) {
|
|
|
-
|
|
|
HeaderInfo headerInfo = headerInfoDao.findById(headerId);
|
|
|
if (headerInfo == null) {
|
|
|
return false;
|
|
|
}
|
|
|
headerInfo.setFieldDes(fieldDes);
|
|
|
headerInfo.setAliasName(aliasName);
|
|
|
- val headerInfo_get = headerInfoDao.save(headerInfo);
|
|
|
- return headerInfo_get != null;
|
|
|
-
|
|
|
+ headerInfoDao.save(headerInfo);
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -213,22 +202,18 @@ public class FileService {
|
|
|
* @return
|
|
|
*/
|
|
|
public boolean updateAllHeaders(List<InnerHeaderInfo> innerHeaderInfos, List<Integer> headerToUpdate) {
|
|
|
-
|
|
|
if (innerHeaderInfos == null || headerToUpdate == null) {
|
|
|
return false;
|
|
|
}
|
|
|
int currLen = headerToUpdate.size();
|
|
|
System.out.println("headerInfos = [" + innerHeaderInfos + "], headerToUpdate = [" + headerToUpdate + "]");
|
|
|
System.out.println(currLen);
|
|
|
- for (int i = 0; i < currLen; i++) {
|
|
|
- int index = headerToUpdate.get(i);
|
|
|
+ for (int index : headerToUpdate) {
|
|
|
InnerHeaderInfo innerheaderInfo = innerHeaderInfos.get(index);
|
|
|
- if (updateHeaderInfo(Integer.parseInt(innerheaderInfo.getId()), innerheaderInfo.getAliasName(),
|
|
|
- innerheaderInfo.getFieldDes()) == false) {
|
|
|
+ if (!updateHeaderInfo(Integer.parseInt(innerheaderInfo.getId()), innerheaderInfo.getAliasName(),
|
|
|
+ innerheaderInfo.getFieldDes())) {
|
|
|
return false;
|
|
|
}
|
|
|
- ;
|
|
|
-
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
@@ -240,7 +225,7 @@ public class FileService {
|
|
|
*/
|
|
|
public HashMap<String, HashMap<String, Object>> getFieldDistribution(String[] fieldIds) throws Exception {
|
|
|
try {
|
|
|
- val res = fileAnalysis.getFieldDistribution(fieldIds);
|
|
|
+ HashMap<String,HashMap<String,Object>> res = fileAnalysis.getFieldDistribution(fieldIds);
|
|
|
return res;
|
|
|
} catch (Exception e) {
|
|
|
log.error("file analysis error");
|
|
|
@@ -257,7 +242,7 @@ public class FileService {
|
|
|
public Object getFieldAnalysis(String[] fieldIds, int funcId) throws Exception {
|
|
|
try {
|
|
|
|
|
|
- if (fieldIds == null || fieldIds.length < 0 || funcId == 0) {
|
|
|
+ if (fieldIds == null || fieldIds.length == 0 || funcId == 0) {
|
|
|
return null;
|
|
|
}
|
|
|
String funcName = funcInfoDao.findById(funcId).getFuncName();
|
|
|
@@ -266,19 +251,19 @@ public class FileService {
|
|
|
}
|
|
|
switch (funcName) {
|
|
|
case "数据分布":
|
|
|
- val res_1 = fileAnalysis.getFieldDistribution(fieldIds);
|
|
|
+ HashMap<String, HashMap<String, Object>> res_1 = fileAnalysis.getFieldDistribution(fieldIds);
|
|
|
return res_1;
|
|
|
case "散点图":
|
|
|
- val res_2 = fileAnalysis.getFieldScatterDiagram(fieldIds);
|
|
|
+ HashMap<String,ArrayList<Object>> res_2 = fileAnalysis.getFieldScatterDiagram(fieldIds);
|
|
|
return res_2;
|
|
|
case "数据统计":
|
|
|
- val res_3 = fileAnalysis.getFieldDescription(fieldIds);
|
|
|
+ HashMap<String, HashMap<String, Object>> res_3 = fileAnalysis.getFieldDescription(fieldIds);
|
|
|
return res_3;
|
|
|
case "偏度-峰度":
|
|
|
- val res_4 = fileAnalysis.getFieldSkewnessAndKurtosis(fieldIds);
|
|
|
+ HashMap<String, HashMap<String, Object>> res_4 = fileAnalysis.getFieldSkewnessAndKurtosis(fieldIds);
|
|
|
return res_4;
|
|
|
case "皮尔森相关系数":
|
|
|
- val res_5 = fileAnalysis.getFieldCorr(fieldIds);
|
|
|
+ HashMap<String, Object> res_5 = fileAnalysis.getFieldCorr(fieldIds);
|
|
|
return res_5;
|
|
|
default:
|
|
|
break;
|
|
|
@@ -292,7 +277,7 @@ public class FileService {
|
|
|
|
|
|
public Object getFieldClassificationAnalysis(int fieldId, String[] fieldIds, int funcId) throws Exception {
|
|
|
try {
|
|
|
- if (fieldId == 0 || fieldIds == null || fieldIds.length < 0 || funcId == 0) {
|
|
|
+ if (fieldId == 0 || fieldIds == null || fieldIds.length == 0 || funcId == 0) {
|
|
|
return null;
|
|
|
}
|
|
|
String funcName = funcInfoDao.findById(funcId).getFuncName();
|
|
|
@@ -301,7 +286,7 @@ public class FileService {
|
|
|
}
|
|
|
switch (funcName) {
|
|
|
case "平均值":
|
|
|
- val res_1 = fileAnalysis.getFieldClassificationAverage(fieldId,fieldIds);
|
|
|
+ HashMap<String, HashMap<String, Object>> res_1 = fileAnalysis.getFieldClassificationAverage(fieldId,fieldIds);
|
|
|
return res_1;
|
|
|
default:
|
|
|
break;
|
|
|
@@ -312,5 +297,4 @@ public class FileService {
|
|
|
throw e;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|