|
@@ -1,8 +1,8 @@
|
|
package com.taais.biz.controller;
|
|
package com.taais.biz.controller;
|
|
|
|
|
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
|
|
+import com.mybatisflex.core.query.QueryWrapper;
|
|
import com.taais.common.core.config.TaaisConfig;
|
|
import com.taais.common.core.config.TaaisConfig;
|
|
-import com.taais.common.core.constant.Constants;
|
|
|
|
import com.taais.common.core.core.domain.CommonResult;
|
|
import com.taais.common.core.core.domain.CommonResult;
|
|
import com.taais.common.core.core.page.PageResult;
|
|
import com.taais.common.core.core.page.PageResult;
|
|
import com.taais.common.core.utils.MapstructUtils;
|
|
import com.taais.common.core.utils.MapstructUtils;
|
|
@@ -38,6 +38,7 @@ import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 数据管理Controller
|
|
* 数据管理Controller
|
|
@@ -95,6 +96,12 @@ public class DataController extends BaseController {
|
|
@RepeatSubmit()
|
|
@RepeatSubmit()
|
|
@PostMapping
|
|
@PostMapping
|
|
public CommonResult<Void> add(@Validated @RequestBody DataBo dataBo) {
|
|
public CommonResult<Void> add(@Validated @RequestBody DataBo dataBo) {
|
|
|
|
+ QueryWrapper query = dataService.query();
|
|
|
|
+ query.eq(Data::getBatchNum, dataBo.getBatchNum());
|
|
|
|
+ long count = dataService.getMapper().selectCountByQuery(query);
|
|
|
|
+ if (count > 0) {
|
|
|
|
+ return CommonResult.fail("检测出现重复批次号,请仔细检查后重新添加!");
|
|
|
|
+ }
|
|
boolean inserted = dataService.insert(dataBo);
|
|
boolean inserted = dataService.insert(dataBo);
|
|
if (!inserted) {
|
|
if (!inserted) {
|
|
return CommonResult.fail("新增数据管理记录失败!");
|
|
return CommonResult.fail("新增数据管理记录失败!");
|
|
@@ -137,77 +144,123 @@ public class DataController extends BaseController {
|
|
}
|
|
}
|
|
|
|
|
|
@PostMapping("/zip/upload")
|
|
@PostMapping("/zip/upload")
|
|
- public CommonResult<SysOssUploadVo> uploadZipFile(@RequestParam("file") MultipartFile file, @RequestParam("excelFile") MultipartFile excelFile) throws Exception {
|
|
|
|
-
|
|
|
|
- List<DataVo> dataVos = ExcelUtil.importExcel(excelFile.getInputStream(),DataVo.class);
|
|
|
|
|
|
+ public CommonResult<SysOssUploadVo> uploadZipFile(@RequestParam("file") MultipartFile file, @RequestParam("excelFile") MultipartFile excelFile, String labeled) throws Exception {
|
|
|
|
+ System.out.println(labeled);
|
|
|
|
+ List<DataVo> dataVos = ExcelUtil.importExcel(excelFile.getInputStream(), DataVo.class);
|
|
Map<String, Data> picName2Obj = new HashMap<>();
|
|
Map<String, Data> picName2Obj = new HashMap<>();
|
|
//为插入数据库做准备
|
|
//为插入数据库做准备
|
|
- for(DataVo dataVo:dataVos){
|
|
|
|
|
|
+ for (DataVo dataVo : dataVos) {
|
|
picName2Obj.put(dataVo.getName(), MapstructUtils.convert(dataVo, Data.class));
|
|
picName2Obj.put(dataVo.getName(), MapstructUtils.convert(dataVo, Data.class));
|
|
}
|
|
}
|
|
- String originalFilename = file.getOriginalFilename();
|
|
|
|
|
|
+ String originalFilename = file.getOriginalFilename();
|
|
assert originalFilename != null;
|
|
assert originalFilename != null;
|
|
String suffix = StringUtils.substring(originalFilename, originalFilename.lastIndexOf("."), originalFilename.length());
|
|
String suffix = StringUtils.substring(originalFilename, originalFilename.lastIndexOf("."), originalFilename.length());
|
|
|
|
|
|
|
|
|
|
// 解压
|
|
// 解压
|
|
String basedir = TaaisConfig.getUploadPath();
|
|
String basedir = TaaisConfig.getUploadPath();
|
|
- File zipOrRarTemp = FileUploadUtils.getAbsoluteFile(basedir,FileUploadUtils.extractFilename2(file));// 解压目录
|
|
|
|
|
|
+ File zipOrRarTemp = FileUploadUtils.getAbsoluteFile(basedir, FileUploadUtils.extractFilename2(file));// 解压目录
|
|
String destZip = zipOrRarTemp.getAbsolutePath();
|
|
String destZip = zipOrRarTemp.getAbsolutePath();
|
|
|
|
|
|
file.transferTo(Paths.get(destZip));
|
|
file.transferTo(Paths.get(destZip));
|
|
String dest = zipOrRarTemp.getParent();
|
|
String dest = zipOrRarTemp.getParent();
|
|
|
|
|
|
List<File> extractedFileList = new ArrayList<File>();
|
|
List<File> extractedFileList = new ArrayList<File>();
|
|
- if(suffix.equals(".zip")){
|
|
|
|
- List<FileHeader> fileheaders = UnPackedUtil.unPackZip(zipOrRarTemp,dest);
|
|
|
|
|
|
+ if (suffix.equals(".zip")) {
|
|
|
|
+ List<FileHeader> fileheaders = UnPackedUtil.unPackZip(zipOrRarTemp, dest);
|
|
//添加解压目录
|
|
//添加解压目录
|
|
- for(FileHeader fileHeader : fileheaders) {
|
|
|
|
|
|
+ for (FileHeader fileHeader : fileheaders) {
|
|
if (!fileHeader.isDirectory()) {
|
|
if (!fileHeader.isDirectory()) {
|
|
String fileHeaderName = fileHeader.getFileName();
|
|
String fileHeaderName = fileHeader.getFileName();
|
|
String fileHeaderSuffix = StringUtils.substring(fileHeaderName, fileHeaderName.lastIndexOf("."), fileHeaderName.length());
|
|
String fileHeaderSuffix = StringUtils.substring(fileHeaderName, fileHeaderName.lastIndexOf("."), fileHeaderName.length());
|
|
- if(!fileHeaderSuffix.equals(".jpg")&&!fileHeaderSuffix.equals(".jpeg")
|
|
|
|
- &&!fileHeaderSuffix.equals(".png")){
|
|
|
|
|
|
+ if (!fileHeaderSuffix.equals(".jpg") && !fileHeaderSuffix.equals(".jpeg")
|
|
|
|
+ && !fileHeaderSuffix.equals(".png")) {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
- extractedFileList.add(new File(dest,fileHeader.getFileName()));
|
|
|
|
|
|
+ extractedFileList.add(new File(dest, fileHeader.getFileName()));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
- }else if(suffix.equals(".rar")){
|
|
|
|
- List<com.github.junrar.rarfile.FileHeader> fileheaders = UnPackedUtil.unPackRar(zipOrRarTemp,dest);
|
|
|
|
|
|
+ } else if (suffix.equals(".rar")) {
|
|
|
|
+ List<com.github.junrar.rarfile.FileHeader> fileheaders = UnPackedUtil.unPackRar(zipOrRarTemp, dest);
|
|
|
|
|
|
|
|
|
|
//添加解压目录
|
|
//添加解压目录
|
|
- for(com.github.junrar.rarfile.FileHeader fileHeader : fileheaders) {
|
|
|
|
|
|
+ for (com.github.junrar.rarfile.FileHeader fileHeader : fileheaders) {
|
|
|
|
|
|
if (!fileHeader.isDirectory()) {
|
|
if (!fileHeader.isDirectory()) {
|
|
String fileHeaderName = fileHeader.getFileName();
|
|
String fileHeaderName = fileHeader.getFileName();
|
|
String fileHeaderSuffix = StringUtils.substring(fileHeaderName, fileHeaderName.lastIndexOf("."), fileHeaderName.length());
|
|
String fileHeaderSuffix = StringUtils.substring(fileHeaderName, fileHeaderName.lastIndexOf("."), fileHeaderName.length());
|
|
- if(!fileHeaderSuffix.equals(".jpg")&&!fileHeaderSuffix.equals(".jpeg")
|
|
|
|
- &&!fileHeaderSuffix.equals(".png")){
|
|
|
|
|
|
+ if (!fileHeaderSuffix.equals(".jpg")
|
|
|
|
+ && !fileHeaderSuffix.equals(".jpeg")
|
|
|
|
+ && !fileHeaderSuffix.equals(".png")
|
|
|
|
+ && !fileHeaderSuffix.equals(".txt")
|
|
|
|
+ && !fileHeaderSuffix.equals(".bmp")) {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
- extractedFileList.add(new File(dest,fileHeader.getFileName()));
|
|
|
|
|
|
+ extractedFileList.add(new File(dest, fileHeader.getFileName()));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- for(File efile:extractedFileList) {
|
|
|
|
- String pathFileName = FileUploadUtils.getPathFileName(dest,efile.getName());
|
|
|
|
|
|
+ //取出最大值
|
|
|
|
+ Integer idMax = dataService.getIdMax();
|
|
|
|
+ if (idMax == null) {
|
|
|
|
+ idMax = 1;
|
|
|
|
+ } else {
|
|
|
|
+ idMax = idMax + 1;
|
|
|
|
+ }
|
|
|
|
+ List<Data> dataList = new ArrayList<>();
|
|
|
|
+ for (File efile : extractedFileList) {
|
|
|
|
+ String pathFileName = FileUploadUtils.getPathFileName(dest, efile.getName());
|
|
Data mydata = picName2Obj.get(efile.getName());
|
|
Data mydata = picName2Obj.get(efile.getName());
|
|
-
|
|
|
|
// 检查是否已标准抓住
|
|
// 检查是否已标准抓住
|
|
- if(checkLabeled(pathFileName)){
|
|
|
|
|
|
+ if (checkLabeled(pathFileName)) {
|
|
mydata.setLabeled(Boolean.TRUE);
|
|
mydata.setLabeled(Boolean.TRUE);
|
|
} else {
|
|
} else {
|
|
mydata.setLabeled(Boolean.FALSE);
|
|
mydata.setLabeled(Boolean.FALSE);
|
|
}
|
|
}
|
|
|
|
+ mydata.setFormName(mydata.getName());
|
|
|
|
+ String fileHeaderSuffix = StringUtils.substring(mydata.getName(), mydata.getName().lastIndexOf("."), mydata.getName().length());
|
|
|
|
+ mydata.setName(idMax + fileHeaderSuffix);
|
|
mydata.setUrl(pathFileName);
|
|
mydata.setUrl(pathFileName);
|
|
- dataService.save(mydata);
|
|
|
|
|
|
+ dataList.add(mydata);
|
|
|
|
+ idMax++;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ("true".equals(labeled)) {
|
|
|
|
+ List<Data> unmarkedData = dataList.stream()
|
|
|
|
+ .filter(data -> Boolean.FALSE.equals(data.getLabeled()))
|
|
|
|
+ .toList();
|
|
|
|
+
|
|
|
|
+ // 计算已标注和未标注的数据数量
|
|
|
|
+ long markedCount = dataList.stream()
|
|
|
|
+ .filter(data -> Boolean.TRUE.equals(data.getLabeled()))
|
|
|
|
+ .count();
|
|
|
|
+ long unmarkedCount = unmarkedData.size();
|
|
|
|
+
|
|
|
|
+ // 如果存在未标注的数据,则返回错误信息
|
|
|
|
+ if (unmarkedCount > 0) {
|
|
|
|
+ String format = String.format("错误: 已标注文件 %d 个,未标注文件 %d 个", markedCount, unmarkedCount);
|
|
|
|
+ return CommonResult.fail(format);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ AtomicBoolean isTrue = new AtomicBoolean(false);
|
|
|
|
+ dataList.forEach(data -> {
|
|
|
|
+ QueryWrapper query = dataService.query();
|
|
|
|
+ query.eq(Data::getBatchNum, data.getBatchNum());
|
|
|
|
+ long count = dataService.getMapper().selectCountByQuery(query);
|
|
|
|
+ if (count > 0) {
|
|
|
|
+ isTrue.set(true);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ if (isTrue.get()) {
|
|
|
|
+ return CommonResult.fail("文件检测出重复批次号,请仔细检查后重新导入!");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ dataService.saveBatch(dataList);
|
|
//删除压缩文件
|
|
//删除压缩文件
|
|
FileUtils.deleteFile(destZip);
|
|
FileUtils.deleteFile(destZip);
|
|
|
|
|