|
@@ -8,17 +8,21 @@ import com.hssx.bms.mapper.BookCategoryMapper;
|
|
import com.hssx.bms.mapper.BookPageMapper;
|
|
import com.hssx.bms.mapper.BookPageMapper;
|
|
import com.hssx.bms.service.BookPageService;
|
|
import com.hssx.bms.service.BookPageService;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.hssx.bms.until.FileCopyToFolderUtil;
|
|
import com.hssx.bms.until.HttpRespMsg;
|
|
import com.hssx.bms.until.HttpRespMsg;
|
|
import com.hssx.bms.until.UploadFileToFileNameUtil;
|
|
import com.hssx.bms.until.UploadFileToFileNameUtil;
|
|
import net.lingala.zip4j.core.ZipFile;
|
|
import net.lingala.zip4j.core.ZipFile;
|
|
import net.lingala.zip4j.exception.ZipException;
|
|
import net.lingala.zip4j.exception.ZipException;
|
|
import net.lingala.zip4j.model.FileHeader;
|
|
import net.lingala.zip4j.model.FileHeader;
|
|
|
|
+import org.apache.ibatis.scripting.xmltags.DynamicSqlSource;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -49,12 +53,14 @@ public class BookPageServiceImpl extends ServiceImpl<BookPageMapper, BookPage> i
|
|
Unzip4j1(filePath,path+bookPage.getBookId(),bookPage);
|
|
Unzip4j1(filePath,path+bookPage.getBookId(),bookPage);
|
|
} catch (ZipException e) {
|
|
} catch (ZipException e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return msg;
|
|
return msg;
|
|
}
|
|
}
|
|
// 解压方法2
|
|
// 解压方法2
|
|
- public void Unzip4j1(String zipFile,String folderPath,BookPage bookPage) throws ZipException {
|
|
|
|
|
|
+ public void Unzip4j1(String zipFile,String folderPath,BookPage bookPage) throws ZipException, IOException {
|
|
long startTime = System.currentTimeMillis();
|
|
long startTime = System.currentTimeMillis();
|
|
File folder = new File(folderPath);
|
|
File folder = new File(folderPath);
|
|
deleteDir(folder);
|
|
deleteDir(folder);
|
|
@@ -67,26 +73,53 @@ public class BookPageServiceImpl extends ServiceImpl<BookPageMapper, BookPage> i
|
|
//检查是否需要密码
|
|
//检查是否需要密码
|
|
// checkEncrypted(zipFile2);
|
|
// checkEncrypted(zipFile2);
|
|
List<FileHeader> fileHeaderList = zipFile2.getFileHeaders();
|
|
List<FileHeader> fileHeaderList = zipFile2.getFileHeaders();
|
|
- for (int i = 0; i < fileHeaderList.size(); i++) {
|
|
|
|
- FileHeader fileHeader = fileHeaderList.get(i);
|
|
|
|
- if(!fileHeader.isDirectory()){
|
|
|
|
|
|
+ boolean iscontain=false;
|
|
|
|
+ String destInfolder = "";
|
|
|
|
+// for (FileHeader fileHeader : fileHeaderList) {
|
|
|
|
+// System.out.println(fileHeader.getFileName());
|
|
|
|
+// System.out.println(fileHeader.getFileName().indexOf("/"));
|
|
|
|
+// System.out.println(destInfolder.substring(0,fileHeader.getFileName().indexOf("/")-1));
|
|
|
|
+// }
|
|
|
|
+ for (FileHeader fileHeader : fileHeaderList) {
|
|
|
|
+ if(fileHeader.getFileName().indexOf("/")!=-1){
|
|
|
|
+ iscontain = true;
|
|
|
|
+ destInfolder = fileHeader.getFileName().substring(0,fileHeader.getFileName().indexOf("/"));
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(iscontain){
|
|
|
|
+ //有文件夹
|
|
|
|
+ List<String> fileList = new ArrayList<>();
|
|
|
|
+ for (int i = 0; i < fileHeaderList.size(); i++) {
|
|
|
|
+ FileHeader fileHeader = fileHeaderList.get(i);
|
|
|
|
+ if(i>0){
|
|
|
|
+ fileList.add(folderPath+File.separator+fileHeader.getFileName());
|
|
|
|
+ System.out.println(destInfolder);
|
|
|
|
+ String fileName = fileHeader.getFileName().substring(destInfolder.length()+1);
|
|
|
|
+ System.out.println(fileName);
|
|
|
|
+ bookPage.setFile(fileName);
|
|
|
|
+ Integer pageNum = Integer.parseInt(fileName.substring(0,fileName.indexOf(".")));
|
|
|
|
+ bookPage.setPageNum(pageNum);
|
|
|
|
+ bookPageMapper.insert(bookPage);
|
|
|
|
+ }
|
|
|
|
+ zipFile2.extractFile(fileHeader, folderPath);
|
|
|
|
+ }
|
|
|
|
+ if(fileList.size()>0){
|
|
|
|
+ System.out.println(fileList);
|
|
|
|
+ System.out.println(folderPath);
|
|
|
|
+ FileCopyToFolderUtil.copy(fileList, folderPath);
|
|
|
|
+ File oldFolder = new File(folderPath+File.separator+destInfolder);
|
|
|
|
+ deleteDir(oldFolder);
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+ for (int i = 0; i < fileHeaderList.size(); i++) {
|
|
|
|
+ FileHeader fileHeader = fileHeaderList.get(i);
|
|
bookPage.setFile(fileHeader.getFileName());
|
|
bookPage.setFile(fileHeader.getFileName());
|
|
Integer pageNum = Integer.parseInt(fileHeader.getFileName().substring(0,fileHeader.getFileName().indexOf(".")));
|
|
Integer pageNum = Integer.parseInt(fileHeader.getFileName().substring(0,fileHeader.getFileName().indexOf(".")));
|
|
bookPage.setPageNum(pageNum);
|
|
bookPage.setPageNum(pageNum);
|
|
bookPageMapper.insert(bookPage);
|
|
bookPageMapper.insert(bookPage);
|
|
zipFile2.extractFile(fileHeader, folderPath);
|
|
zipFile2.extractFile(fileHeader, folderPath);
|
|
- }else{
|
|
|
|
- zipFile2.extractFile(fileHeader, folderPath);
|
|
|
|
- File destFolder = new File(folderPath);
|
|
|
|
- File[] files = destFolder.listFiles();
|
|
|
|
- for (File file : files) {
|
|
|
|
- bookPage.setFile(fileHeader.getFileName());
|
|
|
|
- Integer pageNum = Integer.parseInt(file.getName().substring(0,file.getName().indexOf(".")));
|
|
|
|
- bookPage.setPageNum(pageNum);
|
|
|
|
- bookPageMapper.insert(bookPage);
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
System.out.println("解压成功!");
|
|
System.out.println("解压成功!");
|
|
long endTime = System.currentTimeMillis();
|
|
long endTime = System.currentTimeMillis();
|