|
@@ -5,6 +5,7 @@
|
|
|
package com.tofly.dataCheck.controller;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.tofly.common.core.entity.ResultRespone;
|
|
@@ -12,15 +13,26 @@ import com.tofly.common.core.util.StringUtil;
|
|
|
import com.tofly.common.log.annotation.ToFlyAppLog;
|
|
|
import com.tofly.common.oauth.util.SecurityUtils;
|
|
|
import com.tofly.dataCheck.config.FileTableEnum;
|
|
|
+import com.tofly.dataCheck.em.FileSuffixEnum;
|
|
|
+import com.tofly.dataCheck.em.FileTypeEnum;
|
|
|
import com.tofly.dataCheck.entity.*;
|
|
|
+import com.tofly.dataCheck.excel.entity.SpecialFileExcel;
|
|
|
+import com.tofly.dataCheck.excel.entity.TaskDataExcel;
|
|
|
+import com.tofly.dataCheck.excel.listener.SpecialFileListener;
|
|
|
+import com.tofly.dataCheck.excel.listener.TaskDataListener;
|
|
|
import com.tofly.dataCheck.service.DetectDataService;
|
|
|
import com.tofly.dataCheck.service.RecordManagerService;
|
|
|
+import com.tofly.dataCheck.service.SpecialFileDataService;
|
|
|
import com.tofly.dataCheck.service.ToflyFileService;
|
|
|
+import com.tofly.dataCheck.utils.ReadWordDataUtils;
|
|
|
+import com.tofly.service.CommonFileService;
|
|
|
import io.swagger.annotations.*;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
|
|
|
+import java.io.InputStream;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -41,11 +53,15 @@ public class RecordManagerController {
|
|
|
|
|
|
private final DetectDataService detectDataService;
|
|
|
|
|
|
+ private final SpecialFileDataService specialFileDataService;
|
|
|
+
|
|
|
+ private final CommonFileService commonFileService;
|
|
|
+
|
|
|
|
|
|
|
|
|
* 分页查询
|
|
|
*
|
|
|
- * @param page 分页对象
|
|
|
+ * @param page 分页对象
|
|
|
* @param recordManagerDto
|
|
|
* @return
|
|
|
*/
|
|
@@ -67,8 +83,8 @@ public class RecordManagerController {
|
|
|
public ResultRespone getRecordImportPage(Page page, @ModelAttribute RecordManager recordManager) {
|
|
|
return ResultRespone.success(recordManagerService.page(page, Wrappers.query(recordManager)
|
|
|
.isNotNull("file_count")
|
|
|
- .ge(recordManager.getStartTime()!=null,"CREATE_TIME", recordManager.getStartTime())
|
|
|
- .le(recordManager.getEndTime()!=null,"CREATE_TIME",recordManager.getEndTime())));
|
|
|
+ .ge(recordManager.getStartTime() != null, "CREATE_TIME", recordManager.getStartTime())
|
|
|
+ .le(recordManager.getEndTime() != null, "CREATE_TIME", recordManager.getEndTime())));
|
|
|
}
|
|
|
|
|
|
|
|
@@ -185,76 +201,123 @@ public class RecordManagerController {
|
|
|
if (save) {
|
|
|
List<ToflyFile> toflyFiles = recordManager.getToflyFiles();
|
|
|
if (CollUtil.isNotEmpty(toflyFiles)) {
|
|
|
- RecorManagerImportResult recorManagerImportResult=new RecorManagerImportResult();
|
|
|
- int fileCount=toflyFiles.size();
|
|
|
- AtomicInteger checkFileCount= new AtomicInteger();
|
|
|
- AtomicInteger checkFailedCount= new AtomicInteger();
|
|
|
- List<String> checkFailedNames=new ArrayList<>();
|
|
|
+ RecorManagerImportResult recorManagerImportResult = new RecorManagerImportResult();
|
|
|
+ int fileCount = toflyFiles.size();
|
|
|
+ AtomicInteger checkFileCount = new AtomicInteger();
|
|
|
+ AtomicInteger checkFailedCount = new AtomicInteger();
|
|
|
+ List<String> checkFailedNames = new ArrayList<>();
|
|
|
|
|
|
List<DetectDataVo> detectDataVos = detectDataService.detectGroupData();
|
|
|
- if(CollUtil.isNotEmpty(detectDataVos)){
|
|
|
- List<String> roadNames=new ArrayList<>();
|
|
|
- List<String> testingZones=new ArrayList<>();
|
|
|
- List<String> areas=new ArrayList<>();
|
|
|
- detectDataVos.forEach(d->{
|
|
|
- if(StringUtil.isNotEmpty(d.getRoadName())) {
|
|
|
+ if (CollUtil.isNotEmpty(detectDataVos)) {
|
|
|
+ List<String> roadNames = new ArrayList<>();
|
|
|
+ List<String> testingZones = new ArrayList<>();
|
|
|
+ List<String> areas = new ArrayList<>();
|
|
|
+
|
|
|
+ for (DetectDataVo d : detectDataVos) {
|
|
|
+ if (StringUtil.isNotEmpty(d.getRoadName())) {
|
|
|
roadNames.add(d.getRoadName());
|
|
|
}
|
|
|
- if(StringUtil.isNotEmpty(d.getTestingZone())) {
|
|
|
+ if (StringUtil.isNotEmpty(d.getTestingZone())) {
|
|
|
testingZones.add(d.getTestingZone());
|
|
|
}
|
|
|
- if(StringUtil.isNotEmpty(d.getArea())) {
|
|
|
+ if (StringUtil.isNotEmpty(d.getArea())) {
|
|
|
areas.add(d.getArea());
|
|
|
}
|
|
|
- });
|
|
|
+ }
|
|
|
+
|
|
|
+ if (CollUtil.isNotEmpty(testingZones)) {
|
|
|
+ testingZones = testingZones.stream().distinct().collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ if (CollUtil.isNotEmpty(areas)) {
|
|
|
+ areas = areas.stream().distinct().collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> finalTestingZones = testingZones;
|
|
|
+ List<String> finalAreas = areas;
|
|
|
toflyFiles.forEach(d -> {
|
|
|
d.setSourceId(recordManager.getId());
|
|
|
d.setTableName(FileTableEnum.RECORD_MANAGER.getTableName());
|
|
|
d.setCreateUser(SecurityUtils.getUserId());
|
|
|
d.setCreateTime(new Date());
|
|
|
String fileName = d.getFileName();
|
|
|
- if(StringUtil.isNotEmpty(fileName)){
|
|
|
- String subFileName=null;
|
|
|
- if(fileName.contains(".")){
|
|
|
+ if (StringUtil.isNotEmpty(fileName)) {
|
|
|
+ String subFileName = null;
|
|
|
+ if (fileName.contains(".")) {
|
|
|
subFileName = fileName.substring(0, fileName.indexOf("."));
|
|
|
- }else{
|
|
|
- subFileName=fileName;
|
|
|
+ } else {
|
|
|
+ subFileName = fileName;
|
|
|
}
|
|
|
- Boolean flag=false;
|
|
|
+ Boolean flag = false;
|
|
|
|
|
|
String[] split = subFileName.split("-");
|
|
|
- String linkName=null;
|
|
|
- if(null!=split){
|
|
|
+ String roadName = null;
|
|
|
+ String tzName = null;
|
|
|
+ String areaName = null;
|
|
|
+ String linkName = null;
|
|
|
+ if (null != split) {
|
|
|
List<String> strings = Arrays.asList(split);
|
|
|
- for(int i=strings.size()-1;i<strings.size();i--){
|
|
|
- if(roadNames.contains(strings.get(i))){
|
|
|
- linkName=strings.get(i);
|
|
|
- flag=true;
|
|
|
- break;
|
|
|
- }else if(testingZones.contains(strings.get(i))){
|
|
|
- linkName=strings.get(i);
|
|
|
- flag=true;
|
|
|
- break;
|
|
|
- }else if(areas.contains(strings.get(i))){
|
|
|
- linkName=strings.get(i);
|
|
|
- flag=true;
|
|
|
- break;
|
|
|
- }else{
|
|
|
+ for (int i = strings.size() - 1; i < strings.size(); i--) {
|
|
|
+ if (roadNames.contains(strings.get(i))) {
|
|
|
+ roadName = strings.get(i);
|
|
|
break;
|
|
|
}
|
|
|
+ if (finalTestingZones.contains(strings.get(i))) {
|
|
|
+ tzName = strings.get(i);
|
|
|
+ }
|
|
|
+ if (finalAreas.contains(strings.get(i))) {
|
|
|
+ areaName = strings.get(i);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- if(flag){
|
|
|
+
|
|
|
+ if (StringUtil.isNotEmpty(roadName)) {
|
|
|
+ linkName = roadName;
|
|
|
+ flag = true;
|
|
|
+ } else if (StringUtil.isNotEmpty(tzName)) {
|
|
|
+ linkName = tzName;
|
|
|
+ flag = true;
|
|
|
+ } else if (StringUtil.isNotEmpty(areaName)) {
|
|
|
+ linkName = areaName;
|
|
|
+ flag = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (flag) {
|
|
|
checkFileCount.getAndIncrement();
|
|
|
d.setLinkName(linkName);
|
|
|
- toflyFileService.save(d);
|
|
|
- }else{
|
|
|
+ boolean save1 = toflyFileService.save(d);
|
|
|
+ if (save1) {
|
|
|
+ if (recordManager.getFileType().equals(FileTypeEnum.RIAN.getCode())
|
|
|
+ && (fileName.contains(FileSuffixEnum.XLS.getCode()) || fileName.contains(FileSuffixEnum.XLSX.getCode()))) {
|
|
|
+
|
|
|
+ try {
|
|
|
+ final InputStream inputStream = commonFileService.downFile(d.getFileId());
|
|
|
+ EasyExcel.read(inputStream, SpecialFileExcel.class, new SpecialFileListener(specialFileDataService, subFileName)).sheet().doRead();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (recordManager.getFileType().equals(FileTypeEnum.HANDLE.getCode())
|
|
|
+ && (fileName.contains(FileSuffixEnum.DOC.getCode()) || fileName.contains(FileSuffixEnum.DOCX.getCode()))) {
|
|
|
+
|
|
|
+ try {
|
|
|
+ final InputStream inputStream = commonFileService.downFile(d.getFileId());
|
|
|
+ List<SpecialFileData> wordData = ReadWordDataUtils.getWordData(fileName, inputStream);
|
|
|
+ if (CollUtil.isNotEmpty(wordData)) {
|
|
|
+ specialFileDataService.insertBatch(wordData);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
checkFailedNames.add(fileName);
|
|
|
checkFailedCount.getAndIncrement();
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
- recordManager.setFileCount(fileCount+"");
|
|
|
+ recordManager.setFileCount(fileCount + "");
|
|
|
recordManager.setCheckFailedCount(checkFailedCount.toString());
|
|
|
recordManager.setCheckFileCount(checkFileCount.toString());
|
|
|
recordManagerService.updateById(recordManager);
|
|
@@ -263,7 +326,7 @@ public class RecordManagerController {
|
|
|
recorManagerImportResult.setCheckFileCount(checkFileCount.get());
|
|
|
recorManagerImportResult.setFiles(checkFailedNames);
|
|
|
return ResultRespone.success(recorManagerImportResult);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
return ResultRespone.failed("探测数据为空");
|
|
|
}
|
|
|
}
|