实现解析压缩包功能
This commit is contained in:
+17
@@ -96,6 +96,8 @@ public class CaseApplicationController extends BaseController {
|
||||
return toAjax(caseApplicationService.submitCaseApplication(batchCaseApplication.getIds()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 删除立案数据
|
||||
*/
|
||||
@@ -158,6 +160,21 @@ public class CaseApplicationController extends BaseController {
|
||||
return success(sealUrlRecordselect);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 案件证据材料压缩包上传
|
||||
*
|
||||
* @param file 附件
|
||||
* @param id 案件申请id
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/upload")
|
||||
public AjaxResult uploadZipFile(@RequestParam("file") MultipartFile file, Long id) {
|
||||
String username = this.getUsername();
|
||||
Long userId = this.getUserId();
|
||||
return caseApplicationService.uploadZipFile(file, id, username, userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 立案申请导入模板下载
|
||||
*/
|
||||
|
||||
+3
@@ -8,6 +8,7 @@ import com.ruoyi.wisdomarbitrate.domain.CaseApplication;
|
||||
import com.ruoyi.wisdomarbitrate.domain.SealSignRecord;
|
||||
import com.ruoyi.wisdomarbitrate.domain.vo.SendRoomNoMessageVO;
|
||||
import com.ruoyi.wisdomarbitrate.domain.vo.ToDoCount;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -72,4 +73,6 @@ public interface ICaseApplicationService {
|
||||
* @return
|
||||
*/
|
||||
int updateCaseLockStatus(CaseApplication caseApplication);
|
||||
|
||||
AjaxResult uploadZipFile(MultipartFile file, Long id, String username, Long userId);
|
||||
}
|
||||
|
||||
+123
-2
@@ -35,13 +35,14 @@ import com.ruoyi.wisdomarbitrate.domain.vo.SendRoomNoMessageVO;
|
||||
import com.ruoyi.wisdomarbitrate.mapper.*;
|
||||
import com.ruoyi.wisdomarbitrate.service.ICaseApplicationService;
|
||||
import com.ruoyi.wisdomarbitrate.utils.SignAward;
|
||||
import com.ruoyi.wisdomarbitrate.utils.UnZipFileUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@@ -84,6 +85,8 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
|
||||
private SealSignRecordMapper sealSignRecordMapper;
|
||||
@Autowired
|
||||
private CaseLogRecordMapper caseLogRecordMapper;
|
||||
@Autowired
|
||||
private CaseEvidenceDirectoryMapper caseEvidenceDirectoryMapper;
|
||||
// 手机号正则
|
||||
private static final Pattern TELEPHONE_REGX = Pattern.compile("^1(3\\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\\d|9[0-35-9])\\d{8}$");
|
||||
|
||||
@@ -247,6 +250,124 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
|
||||
return caseApplicationMapper.updateCaseLockStatus(caseApplication.getId(),caseApplication.getLockStatus());
|
||||
}
|
||||
|
||||
public void inputChangeToFile(InputStream instream, File file) {
|
||||
try {
|
||||
OutputStream outStr = new FileOutputStream(file);
|
||||
int bytesRead = 0;
|
||||
byte[] buffer = new byte[8192];
|
||||
while ((bytesRead = instream.read(buffer, 0, 8192)) != -1) {
|
||||
outStr.write(buffer, 0, bytesRead);
|
||||
}
|
||||
outStr.flush();
|
||||
outStr.close();
|
||||
instream.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public AjaxResult uploadZipFile(MultipartFile file, Long id, String username, Long userId) {
|
||||
if (file.isEmpty()) {
|
||||
return AjaxResult.error("请选择要上传的文件");
|
||||
}
|
||||
// String targetPath = "/home/ruoyi/uploadPath/upload/unzipFile";
|
||||
String targetPath = "F:\\testZip\\unzipFile";
|
||||
File zipFile = null;
|
||||
InputStream ins = null;
|
||||
try {
|
||||
ins = file.getInputStream();
|
||||
zipFile = new File(file.getOriginalFilename());
|
||||
inputChangeToFile(ins, zipFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//解压缩上传的压缩包
|
||||
UnZipFileUtils.unZipFile(zipFile,targetPath);
|
||||
|
||||
//得到解压缩的所有文件
|
||||
String zipName = file.getOriginalFilename();
|
||||
String zipPath = "F:\\testZip\\unzipFile\\"+zipName;
|
||||
// String zipPath = "/home/ruoyi/uploadPath/upload/unzipFile"+zipName;
|
||||
File dirUnzipPath = new File(zipPath);
|
||||
List<File> allFiles = new ArrayList<>();
|
||||
List<String> allFilestr = new ArrayList<>();
|
||||
UnZipFileUtils.getFiles(dirUnzipPath,allFiles);
|
||||
if(allFiles!=null&&allFiles.size()>0){
|
||||
for (File fileIter : allFiles) {
|
||||
System.out.println(fileIter.getAbsolutePath());
|
||||
allFilestr.add(fileIter.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
if(allFilestr!=null&&allFilestr.size()>0){
|
||||
for (String filestr : allFilestr) {
|
||||
List<Integer> allindex = new ArrayList<>();
|
||||
int indexKey = filestr.indexOf("\\");
|
||||
allindex.add(indexKey);
|
||||
while (indexKey != -1) {
|
||||
indexKey = filestr.indexOf("\\", indexKey + 1);
|
||||
allindex.add(indexKey);
|
||||
}
|
||||
if(allindex!=null&&allindex.size()>0){
|
||||
for (int i = 0; i < allindex.size()-2; i++) {
|
||||
//得到第2个 \ 和 第3个 \ 之间的目录 为一级(i+1)目录,
|
||||
String substr = filestr.substring(allindex.get(i+1)+1,allindex.get(i+2));
|
||||
Integer series = i + 1;
|
||||
Integer idcaseEvidenceDirectory = null;
|
||||
if(series==1){
|
||||
CaseEvidenceDirectory caseEvidenceDirectory = new CaseEvidenceDirectory();
|
||||
caseEvidenceDirectory.setEvidenceName(substr);
|
||||
caseEvidenceDirectory.setSeries(series);
|
||||
|
||||
//caseEvidenceDirectory.setCaseid(id);
|
||||
caseEvidenceDirectory.setCreateBy(username);
|
||||
caseEvidenceDirectory.setCreateTime(new Date());
|
||||
|
||||
caseEvidenceDirectoryMapper.save(caseEvidenceDirectory);
|
||||
idcaseEvidenceDirectory = caseEvidenceDirectory.getId();
|
||||
|
||||
}else {
|
||||
CaseEvidenceDirectory caseEvidenceDirectory = new CaseEvidenceDirectory();
|
||||
caseEvidenceDirectory.setEvidenceName(substr);
|
||||
caseEvidenceDirectory.setSeries(series);
|
||||
|
||||
caseEvidenceDirectory.setParentId(idcaseEvidenceDirectory);
|
||||
|
||||
caseEvidenceDirectoryMapper.save(caseEvidenceDirectory);
|
||||
|
||||
|
||||
|
||||
}
|
||||
//通过 案件id 和 目录表 的各个层级的 级数 和 目录名称 查询目录表
|
||||
//判断这个级数的目录是否已经在目录表中存在,
|
||||
//若存在,不用新建这个目录,
|
||||
//若不存在,则新建这个目录
|
||||
//保存到目录表
|
||||
|
||||
|
||||
|
||||
}
|
||||
int lastIndex = allindex.size();
|
||||
//得到 最后1个 \ 之后的目录 为文件名,
|
||||
//保存到目录表
|
||||
//保存到附件表
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
return AjaxResult.success();
|
||||
|
||||
}
|
||||
|
||||
private List<CaseLogRecord> getNofinishCasenode(Integer caseStatus) {
|
||||
CaseLogRecord caseLogRecord1 = new CaseLogRecord();
|
||||
caseLogRecord1.setCaseNodeName("立案审查");
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
package com.ruoyi.wisdomarbitrate.utils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
@Slf4j
|
||||
public class UnZipFileUtils {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 压缩包路径
|
||||
// String zipPath = "F:\\testZip\\zipFile\\上传申请书证据材料.zip";
|
||||
// 解压后存放路径
|
||||
// String targetPath = "F:\\testZip\\unzipFile";
|
||||
// unZipFile(new File(zipPath),targetPath);
|
||||
|
||||
|
||||
// String zipPath = "F:\\testZip\\unzipFile\\上传申请书证据材料";
|
||||
// File dirUnzipPath = new File(zipPath);
|
||||
// List<File> allFiles = new ArrayList<>();
|
||||
// getFiles(dirUnzipPath,allFiles);
|
||||
// if(allFiles!=null&&allFiles.size()>0){
|
||||
// for (File fileIter : allFiles) {
|
||||
// System.out.println(fileIter.getName());
|
||||
// System.out.println(fileIter.getAbsolutePath());
|
||||
// }
|
||||
// }
|
||||
|
||||
String key = "\\";
|
||||
String str = "F:\\testZip\\上传申请书证据材料\\证据材料\\仲裁裁决书模板.docx";
|
||||
List<Integer> allindex = new ArrayList<>();
|
||||
int a = str.indexOf(key);//*第一个出现的索引位置
|
||||
allindex.add(a);
|
||||
while (a != -1) {
|
||||
System.out.print(a + "\t");
|
||||
a = str.indexOf(key, a + 1);//*从这个索引往后开始第一个出现的位置
|
||||
allindex.add(a);
|
||||
}
|
||||
String substr = str.substring(allindex.get(1)+1,allindex.get(2));
|
||||
System.out.println("substr---"+substr);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static boolean unZipFile(File aboriginalFile, String targetPath) {
|
||||
if (!aboriginalFile.exists()) {
|
||||
log.error("此文件不存在:",aboriginalFile.getPath());
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
ZipFile srcZipFile = new ZipFile(aboriginalFile, Charset.forName("GBK"));
|
||||
for (Enumeration enumeration = srcZipFile.entries(); enumeration.hasMoreElements(); ) {
|
||||
ZipEntry entryZip = (ZipEntry) enumeration.nextElement();
|
||||
//若是文件夹,就创建文件夹
|
||||
if (entryZip.isDirectory()) {
|
||||
String directPath = targetPath + File.separator + entryZip.getName();
|
||||
File directFile = new File(directPath);
|
||||
boolean makeDirs = directFile.mkdirs();
|
||||
System.out.println("创建文件夹是否成功:" +makeDirs);
|
||||
} else {
|
||||
//若是文件,就创建文件
|
||||
File sourceFile = new File(targetPath + File.separator + entryZip.getName());
|
||||
if(!sourceFile.getParentFile().exists()){
|
||||
boolean mDirect = sourceFile.getParentFile().mkdirs();
|
||||
System.out.println("创建压缩文件时,创建父文件夹是否成功:" +mDirect);
|
||||
}
|
||||
boolean newUnZipFile = sourceFile.createNewFile();
|
||||
if (newUnZipFile){
|
||||
// 将压缩文件内容写入到这个文件中
|
||||
try{
|
||||
InputStream is = srcZipFile.getInputStream(entryZip);
|
||||
FileOutputStream fos = new FileOutputStream(sourceFile);
|
||||
int len;
|
||||
byte[] buf = new byte[2048];
|
||||
while ((len = is.read(buf)) != -1) {
|
||||
fos.write(buf, 0, len);
|
||||
}
|
||||
} catch (Exception e){
|
||||
log.error("解压失败",e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
} catch (IOException e) {
|
||||
log.error("解压失败",e);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void getFiles(File fileSource, List<File> allFiles) {
|
||||
if (!fileSource.exists()) {
|
||||
System.out.println("目录不存在");
|
||||
return;
|
||||
}
|
||||
File[] fileArray = fileSource.listFiles();
|
||||
if(fileArray!=null&&fileArray.length>0){
|
||||
for (File fileIter : fileArray) {
|
||||
if (fileIter.isDirectory()) {
|
||||
getFiles(fileIter,allFiles);
|
||||
}else {
|
||||
allFiles.add(fileIter);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user