文档库--导入(空excel判断)
This commit is contained in:
+7
-2
@@ -387,8 +387,13 @@ public class BussDocumentLibraryEOController extends JeroController<BussDocument
|
|||||||
@PostMapping(value = "/importZip")
|
@PostMapping(value = "/importZip")
|
||||||
@RequiresPermissions("document:importZip")
|
@RequiresPermissions("document:importZip")
|
||||||
public Result<?> importZip(@RequestParam(value = "file", required = false) MultipartFile file) throws Exception {
|
public Result<?> importZip(@RequestParam(value = "file", required = false) MultipartFile file) throws Exception {
|
||||||
String result = bussDocumentLibraryEOService.importZip(file);
|
try {
|
||||||
return Result.OK(result);
|
bussDocumentLibraryEOService.importZip(file);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return Result.error(e.getMessage());
|
||||||
|
}
|
||||||
|
return Result.OK("导入成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "推送")
|
@ApiOperation(value = "推送")
|
||||||
|
|||||||
+1
-1
@@ -187,6 +187,6 @@ public interface IBussDocumentLibraryEOService extends IService<BussDocumentLibr
|
|||||||
|
|
||||||
String pullMessage(String departIds, String ids, String documentIds);
|
String pullMessage(String departIds, String ids, String documentIds);
|
||||||
|
|
||||||
String importZip(MultipartFile file);
|
void importZip(MultipartFile file);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-16
@@ -2309,15 +2309,14 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
|
|||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
@Override
|
@Override
|
||||||
public String importZip(MultipartFile file) {
|
public void importZip(MultipartFile file) {
|
||||||
List<String> list = getWorkbookTitle("cn");
|
List<String> list = getWorkbookTitle("cn");
|
||||||
String result = "";
|
|
||||||
int pos = file.getOriginalFilename().lastIndexOf(".");
|
int pos = file.getOriginalFilename().lastIndexOf(".");
|
||||||
String str = file.getOriginalFilename().substring(pos + 1).toLowerCase();
|
String str = file.getOriginalFilename().substring(pos + 1).toLowerCase();
|
||||||
String filenameorg = file.getOriginalFilename().substring(0, pos);
|
String filenameorg = file.getOriginalFilename().substring(0, pos);
|
||||||
//判断上传文件必须是zip
|
//判断上传文件必须是zip
|
||||||
if (!str.equals("zip") && !str.equals("rar")) {
|
if (!str.equals("zip") && !str.equals("rar")) {
|
||||||
return "请上传zip格式的文件或rar格式的文件";
|
throw new JeroBootException("请上传zip格式的文件或rar格式的文件") ;
|
||||||
}
|
}
|
||||||
String path = uploadpath + "/modal/" + filenameorg;
|
String path = uploadpath + "/modal/" + filenameorg;
|
||||||
File saveDirectory = new File(path);
|
File saveDirectory = new File(path);
|
||||||
@@ -2333,7 +2332,7 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
|
|||||||
if(length > 2){
|
if(length > 2){
|
||||||
//删除原上传文件
|
//删除原上传文件
|
||||||
FileUnZip.deleteDir(saveDirectory);
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
return "压缩包中必须有且仅有一个文件夹,请重新上传";
|
throw new JeroBootException("压缩包中必须有且仅有一个文件夹,请重新上传");
|
||||||
}
|
}
|
||||||
File fileNew = new File(zipEntryName);
|
File fileNew = new File(zipEntryName);
|
||||||
List<File> fileList = new ArrayList<>();
|
List<File> fileList = new ArrayList<>();
|
||||||
@@ -2345,11 +2344,11 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
|
|||||||
if(fileList.size() ==0 ){
|
if(fileList.size() ==0 ){
|
||||||
//删除原上传文件
|
//删除原上传文件
|
||||||
FileUnZip.deleteDir(saveDirectory);
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
return "压缩包根目录下没有excel作为导入数据,请重新上传";
|
throw new JeroBootException("压缩包根目录下没有excel作为导入数据,请重新上传");
|
||||||
}else if(fileList.size() > 1){
|
}else if(fileList.size() > 1){
|
||||||
//删除原上传文件
|
//删除原上传文件
|
||||||
FileUnZip.deleteDir(saveDirectory);
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
return "压缩包根目录下仅能存在一个excel为导入数据,请重新上传";
|
throw new JeroBootException("压缩包根目录下仅能存在一个excel为导入数据,请重新上传") ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 数据相关处理,
|
// 数据相关处理,
|
||||||
@@ -2359,11 +2358,11 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
|
|||||||
if (excelfilelist.size() < 1) {
|
if (excelfilelist.size() < 1) {
|
||||||
//删除原上传文件
|
//删除原上传文件
|
||||||
FileUnZip.deleteDir(saveDirectory);
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
return "压缩包内没有上传Excel数据";
|
throw new JeroBootException( "压缩包内没有上传Excel数据");
|
||||||
} else if (excelfilelist.size() > 1) {
|
} else if (excelfilelist.size() > 1) {
|
||||||
//删除原上传文件
|
//删除原上传文件
|
||||||
FileUnZip.deleteDir(saveDirectory);
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
return "压缩包内有多个Excel数据源";
|
throw new JeroBootException("压缩包内有多个Excel数据源");
|
||||||
}
|
}
|
||||||
File excelfile = excelfilelist.get(0);
|
File excelfile = excelfilelist.get(0);
|
||||||
|
|
||||||
@@ -2417,6 +2416,11 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(dataList.size() == 0){
|
||||||
|
//删除原上传文件
|
||||||
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
|
throw new JeroBootException("请填写必填字段内容,带*的为必填");
|
||||||
|
}
|
||||||
// 校验头部是否符合模板
|
// 校验头部是否符合模板
|
||||||
String fields = list.get(0);
|
String fields = list.get(0);
|
||||||
String substring = headerSb.substring(0, headerSb.length() - 1);
|
String substring = headerSb.substring(0, headerSb.length() - 1);
|
||||||
@@ -2425,7 +2429,7 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
|
|||||||
workbook.close();
|
workbook.close();
|
||||||
//删除原上传文件
|
//删除原上传文件
|
||||||
FileUnZip.deleteDir(saveDirectory);
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
return "读取失败,请严格按照模板文件导入数据";
|
throw new JeroBootException("读取失败,请严格按照模板文件导入数据");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2435,14 +2439,13 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
|
|||||||
List<SysDictItem> dictItemList = sysDictItemServiceImpl.selectItemsAll();
|
List<SysDictItem> dictItemList = sysDictItemServiceImpl.selectItemsAll();
|
||||||
//表头
|
//表头
|
||||||
List<Map<String, Object>> addForm = getAddForm(ModuleEnum.DOCUMENT_LIBRARY.getValue(), "cn", "add");
|
List<Map<String, Object>> addForm = getAddForm(ModuleEnum.DOCUMENT_LIBRARY.getValue(), "cn", "add");
|
||||||
result = exportDatas(dataList, addForm, categoryList, dictItemList, zipEntryName);
|
exportDatas(dataList, addForm, categoryList, dictItemList, zipEntryName);
|
||||||
//删除原上传文件
|
//删除原上传文件
|
||||||
FileUnZip.deleteDir(saveDirectory);
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
return result;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String exportDatas(List<Map<String, String>> dataList,
|
private void exportDatas(List<Map<String, String>> dataList,
|
||||||
List<Map<String, Object>> fieldList,
|
List<Map<String, Object>> fieldList,
|
||||||
List<SysCategory> categoryList,
|
List<SysCategory> categoryList,
|
||||||
List<SysDictItem> dictItemList,
|
List<SysDictItem> dictItemList,
|
||||||
@@ -2570,7 +2573,9 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
|
|||||||
valueId += collect.get(0).getItemValue() + ",";
|
valueId += collect.get(0).getItemValue() + ",";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
value = valueId.substring(0,valueId.length()-1);
|
if(StringUtils.isNotBlank(valueId)){
|
||||||
|
value = valueId.substring(0,valueId.length()-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -2683,7 +2688,7 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
|
|||||||
for (String s : msgList) {
|
for (String s : msgList) {
|
||||||
html += s + "</br>";
|
html += s + "</br>";
|
||||||
}
|
}
|
||||||
return html;
|
throw new JeroBootException(html) ;
|
||||||
} else {
|
} else {
|
||||||
if(mapList.size() != 0){
|
if(mapList.size() != 0){
|
||||||
for (Map<String, Object> map : mapList) {
|
for (Map<String, Object> map : mapList) {
|
||||||
@@ -2691,8 +2696,6 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "数据导入成功";
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user