文档库-导入
This commit is contained in:
+46
-5
@@ -2283,6 +2283,31 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
|
||||
FileUtils.copyInputStreamToFile(file.getInputStream(), new File(path + "/" + file.getOriginalFilename()));
|
||||
//解压缩
|
||||
String zipEntryName = FileUnZip.unZipFiles(path + "/" + file.getOriginalFilename(), path);
|
||||
//判断压缩包下是否只有一个文件夹
|
||||
File fileTemp = new File(path);
|
||||
int length = fileTemp.listFiles().length;
|
||||
if(length > 2){
|
||||
//删除原上传文件
|
||||
FileUnZip.deleteDir(saveDirectory);
|
||||
return "压缩包中必须有且仅有一个文件夹,请重新上传";
|
||||
}
|
||||
File fileNew = new File(zipEntryName);
|
||||
List<File> fileList = new ArrayList<>();
|
||||
for (File file1 : fileNew.listFiles()) {
|
||||
if(file1.getName().contains(".xls") || file1.getName().contains(".xlsx")){
|
||||
fileList.add(file1);
|
||||
}
|
||||
}
|
||||
if(fileList.size() ==0 ){
|
||||
//删除原上传文件
|
||||
FileUnZip.deleteDir(saveDirectory);
|
||||
return "压缩包根目录下没有excel作为导入数据,请重新上传";
|
||||
}else if(fileList.size() > 1){
|
||||
//删除原上传文件
|
||||
FileUnZip.deleteDir(saveDirectory);
|
||||
return "压缩包根目录下仅能存在一个excel为导入数据,请重新上传";
|
||||
}
|
||||
|
||||
// 数据相关处理,
|
||||
// 1.获取其中的Excel,
|
||||
List<File> excelfilelist = FileUnZip.readImpExcelFile(zipEntryName);
|
||||
@@ -2367,6 +2392,8 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
|
||||
//表头
|
||||
List<Map<String, Object>> addForm = getAddForm(ModuleEnum.DOCUMENT_LIBRARY.getValue(), "cn", "add");
|
||||
result = exportDatas(dataList, addForm, categoryList, dictItemList, zipEntryName);
|
||||
//删除原上传文件
|
||||
FileUnZip.deleteDir(saveDirectory);
|
||||
return result;
|
||||
|
||||
}
|
||||
@@ -2382,8 +2409,9 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
|
||||
List<String> itemNameList = dictItemList.stream().map(SysDictItem::getItemText).collect(Collectors.toList());
|
||||
int i = 2;
|
||||
List<String> msgList = new ArrayList<>();
|
||||
Map<String, Object> mapResult = new HashMap<>();
|
||||
List<Map<String,Object>> mapList = new ArrayList<>();
|
||||
for (Map<String, String> stringStringMap : dataList) {
|
||||
Map<String, Object> mapResult = new HashMap<>();
|
||||
i++;
|
||||
for (Map.Entry<String, String> entry : stringStringMap.entrySet()) {
|
||||
int countError = 0; //记录失败数据数量
|
||||
@@ -2450,7 +2478,7 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
|
||||
|
||||
|
||||
} else if (FieldTypeEnum.PULL_SINGLE.getValue().equals(fieldShowType)) {
|
||||
//下拉单选或下拉多选
|
||||
//下拉单选
|
||||
//判断是否必填
|
||||
if (IsMustEnum.YES.getValue().equals(mustInput) && StringUtils.isBlank(value)) {
|
||||
errorMsg += key + "为必填项,不能为空";
|
||||
@@ -2495,10 +2523,10 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
|
||||
for (String valueTemp : value.split(",")) {
|
||||
if (itemNameList.contains(valueTemp)) {
|
||||
List<SysDictItem> collect = dictItemList.stream().filter(e -> e.getItemText().equals(valueTemp)).collect(Collectors.toList());
|
||||
valueId += collect.get(0).getItemValue();
|
||||
valueId += collect.get(0).getItemValue() + ",";
|
||||
}
|
||||
}
|
||||
value = valueId;
|
||||
value = valueId.substring(0,valueId.length()-1);
|
||||
}
|
||||
|
||||
|
||||
@@ -2542,6 +2570,7 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
|
||||
countError++;
|
||||
}
|
||||
if (StringUtils.isNotBlank(value)) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String fileName : value.split(",")) {
|
||||
List<File> nowFileList = FileUnZip.readFileByFilename(zipEntryName, fileName);
|
||||
if (nowFileList.size() == 0) {
|
||||
@@ -2554,11 +2583,18 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
|
||||
new MockMultipartFile(nowFileList.get(0).getName(), nowFileList.get(0).getName(), "text/plain", input);
|
||||
//文件存入文件表
|
||||
OSSFile ossFile = iOSSFileService.uploadLocal(multipartFile, "");
|
||||
if(ObjectUtils.isNotEmpty(ossFile)){
|
||||
sb.append(ossFile.getId()+",");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
if(StringUtils.isNotBlank(sb)){
|
||||
String substring = sb.substring(0, sb.length() - 1);
|
||||
value = substring;
|
||||
}
|
||||
}
|
||||
|
||||
} else if (FieldTypeEnum.STANDARD.getValue().equals(fieldShowType)) {
|
||||
@@ -2595,6 +2631,7 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
|
||||
}
|
||||
mapResult.put(field, value);
|
||||
}
|
||||
mapList.add(mapResult);
|
||||
}
|
||||
if (msgList.size() > 0) {
|
||||
//返回报错信息
|
||||
@@ -2604,7 +2641,11 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
|
||||
}
|
||||
return html;
|
||||
} else {
|
||||
this.addInfo(mapResult);
|
||||
if(mapList.size() != 0){
|
||||
for (Map<String, Object> map : mapList) {
|
||||
this.addInfo(map);
|
||||
}
|
||||
}
|
||||
}
|
||||
return "数据导入成功";
|
||||
|
||||
|
||||
+33
-3
@@ -113,21 +113,51 @@ public class FileUnZip {
|
||||
* @param filename
|
||||
*/
|
||||
public static List<File> readFileByFilename(String path,String filename) {
|
||||
if(filename.contains("/")){
|
||||
filename = filename.split("/")[1];
|
||||
}
|
||||
List<File> resultlist = new ArrayList<>();
|
||||
if (StringUtil.isNotEmpty(path)){
|
||||
File file = new File(path);
|
||||
if (file.isDirectory()) {
|
||||
File[] files = file.listFiles();
|
||||
for (File fi : files) {
|
||||
// 对文件进行过滤
|
||||
if (fi.getName().equals(filename)) {
|
||||
resultlist.add(fi);
|
||||
if(fi.isDirectory()){
|
||||
File[] filesTemp = fi.listFiles();
|
||||
for (File fileTemp : filesTemp) {
|
||||
// 对文件进行过滤
|
||||
if (fileTemp.getName().equals(filename)) {
|
||||
resultlist.add(fileTemp);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
// 对文件进行过滤
|
||||
if (fi.getName().equals(filename)) {
|
||||
resultlist.add(fi);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return resultlist;
|
||||
}
|
||||
// public static List<File> readFileByFilename(String path,String filename) {
|
||||
// List<File> resultlist = new ArrayList<>();
|
||||
// if (StringUtil.isNotEmpty(path)){
|
||||
// File file = new File(path);
|
||||
// if (file.isDirectory()) {
|
||||
// File[] files = file.listFiles();
|
||||
// for (File fi : files) {
|
||||
// // 对文件进行过滤
|
||||
// if (fi.getName().equals(filename)) {
|
||||
// resultlist.add(fi);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return resultlist;
|
||||
// }
|
||||
|
||||
/**
|
||||
*@Description: 删除某个文件
|
||||
|
||||
Reference in New Issue
Block a user