补充完整的索引

master
zhanghai 2 years ago
parent 20c19cd6a6
commit 401dd0cad9

@ -21,6 +21,9 @@ public class Document {
private Integer dpi;
private String name;
//写一个方法判断是 A3 还是 A4
public Boolean isA3() {

@ -295,7 +295,7 @@ public class FenpanService {
BufferedImage image = ImageIO.read(file);
int height = image.getHeight();
int width = image.getWidth();
Document document = new Document(width, height, 300);
Document document = new Document(width, height, 300,file.getName());
documentList.add(document);
} catch (IOException e) {
throw new RuntimeException(e);
@ -307,7 +307,7 @@ public class FenpanService {
int height = imageInfo.getHeight();
int width = imageInfo.getWidth();
int physicalHeightDpi = imageInfo.getPhysicalHeightDpi();
Document document = new Document(width, height, physicalHeightDpi);
Document document = new Document(width, height, physicalHeightDpi,file.getName());
documentList.add(document);
} catch (IOException e) {
FileUtils.delete(file);
@ -335,7 +335,7 @@ public class FenpanService {
BufferedImage image = ImageIO.read(file);
int height = image.getHeight();
int width = image.getWidth();
Document document = new Document(width, height, 300);
Document document = new Document(width, height, 300,file.getName());
return document;
} catch (IOException e) {
throw new RuntimeException(e);
@ -347,7 +347,7 @@ public class FenpanService {
int height = imageInfo.getHeight();
int width = imageInfo.getWidth();
int physicalHeightDpi = imageInfo.getPhysicalHeightDpi();
Document document = new Document(width, height, physicalHeightDpi);
Document document = new Document(width, height, physicalHeightDpi,file.getName());
return document;
} catch (IOException e) {
FileUtils.delete(file);

@ -0,0 +1,33 @@
package com.docus.sw.souyin;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
@AllArgsConstructor
@Data
public class FullIndexPageRow {
@ExcelProperty("全宗名")
private String zongName;
@ExcelProperty("盘号")
private String phNum;
@ExcelProperty("卷号")
private String rollName;
@ExcelProperty("件名")
private String piecesName;
@ExcelProperty("文件名")
private String documentName;
@ExcelProperty("画幅幅面")
private String sizeStr;
@ExcelProperty("缩微id码")
private Integer start;
}

@ -41,7 +41,7 @@ public class SuoyinService {
}
public void index(String path) throws IOException {
Map<String,IndexPlate> map = new HashMap<>();
Map<String, IndexPlate> map = new HashMap<>();
findAllDir(path, map);
//计算出宗
@ -69,53 +69,53 @@ public class SuoyinService {
//
List<Pieces> pieceList = new ArrayList<>();
File[] piecesFile = rollFile.listFiles();
for(File piece:piecesFile){
for (File piece : piecesFile) {
//区分word和pdf
if(piece.getName().endsWith(".doc")){
if (piece.getName().endsWith(".doc")) {
Pieces pieces = new Pieces(FileTypeEnum.DOC, piece.getAbsolutePath(), piece.getName());
String teamName = "tempIndex/"+ UUID.randomUUID();
String teamName = "tempIndex/" + UUID.randomUUID();
File temp = new File(teamName);
if(!temp.exists()){
if (!temp.exists()) {
temp.mkdirs();
}
ReadImgDoc.readPicture(piece.getAbsolutePath(),temp.getAbsolutePath());
ReadImgDoc.readPicture(piece.getAbsolutePath(), temp.getAbsolutePath());
File[] listFiles = temp.listFiles();
genPieces(pieces, listFiles,FileTypeEnum.DOC);
genPieces(pieces, listFiles, FileTypeEnum.DOC);
pieceList.add(pieces);
//删除对应的temp 文件
FileUtils.delete(temp);
}else if(piece.getName().endsWith(".docx")){
} else if (piece.getName().endsWith(".docx")) {
Pieces pieces = new Pieces(FileTypeEnum.DOCX, piece.getAbsolutePath(), piece.getName());
String teamName = "tempIndex/"+ UUID.randomUUID();
String teamName = "tempIndex/" + UUID.randomUUID();
File temp = new File(teamName);
if(!temp.exists()){
if (!temp.exists()) {
temp.mkdirs();
}
GetPicsDocx.getPics(piece.getAbsolutePath(),temp.getAbsolutePath());
GetPicsDocx.getPics(piece.getAbsolutePath(), temp.getAbsolutePath());
File[] listFiles = temp.listFiles();
genPieces(pieces, listFiles,FileTypeEnum.DOCX);
genPieces(pieces, listFiles, FileTypeEnum.DOCX);
pieceList.add(pieces);
//删除对应的temp 文件
FileUtils.delete(temp);
}else if(piece.getName().endsWith(".pdf")){
} else if (piece.getName().endsWith(".pdf")) {
Pieces pieces = new Pieces(FileTypeEnum.DOC, piece.getAbsolutePath(), piece.getName());
String teamName = "tempIndex/"+ UUID.randomUUID();
String teamName = "tempIndex/" + UUID.randomUUID();
File temp = new File(teamName);
if(!temp.exists()){
if (!temp.exists()) {
temp.mkdirs();
}
try {
PdfBoxUtils.pdf2image(piece.getAbsolutePath(),temp.getAbsolutePath());
PdfBoxUtils.pdf2image(piece.getAbsolutePath(), temp.getAbsolutePath());
File[] listFiles = temp.listFiles();
genPieces(pieces, listFiles,FileTypeEnum.DOC);
genPieces(pieces, listFiles, FileTypeEnum.DOC);
pieceList.add(pieces);
} catch (IOException e) {
@ -124,10 +124,10 @@ public class SuoyinService {
//删除对应的temp 文件
// temp.delete();
FileUtils.delete(temp);
}else{
} else {
Pieces pieces = new Pieces(FileTypeEnum.JPG, piece.getAbsolutePath(), piece.getName());
File[] listFiles = piece.listFiles();
genPieces(pieces, listFiles,FileTypeEnum.JPG);
genPieces(pieces, listFiles, FileTypeEnum.JPG);
pieceList.add(pieces);
}
@ -140,7 +140,6 @@ public class SuoyinService {
}
}
indexPlate.putAll(rollList);
@ -149,7 +148,7 @@ public class SuoyinService {
FileUtils.delete(new File("tempIndex"));
//生成索引目录
for(IndexPlate indexPlate : map.values()){
for (IndexPlate indexPlate : map.values()) {
List<Roll> rollList = indexPlate.getRollList();
@ -157,83 +156,98 @@ public class SuoyinService {
//计算出总size
Double totalPage = 0d;
for(Roll roll:rollList){
for (Roll roll : rollList) {
List<Pieces> piecesList = roll.getPiecesList();
totalPage+=piecesList.size();
totalPage += piecesList.size();
}
Integer pianPageNum = 0;
Integer totalSize = 0;
for(Roll roll:rollList){
for (Roll roll : rollList) {
//跳过片头
if(roll.getName().equals("片头")){
if (roll.getName().equals("片头")) {
continue;
}
//跳过片尾
if(roll.getName().equals("片尾")){
if (roll.getName().equals("片尾")) {
continue;
}
List<Pieces> piecesList = roll.getPiecesList();
for(Pieces pieces:piecesList){
for (Pieces pieces : piecesList) {
Integer size = pieces.getDocumentList().size();
totalSize+=size;
totalSize += size;
}
}
List<IndexPageRow> indexPageRows= indexGen(indexPlate, rollList, pianPageNum, totalSize);
List<IndexPageRow> indexPageRows = indexGen(indexPlate, rollList, pianPageNum, totalSize);
//修正数据
System.out.println(new Gson().toJson(indexPageRows));
//生成excel
List<MesEasyExcel> mesEasyExcels = new ArrayList<>();
for(IndexPageRow indexPageRowTemp:indexPageRows){
for (IndexPageRow indexPageRowTemp : indexPageRows) {
mesEasyExcels.add(MesEasyExcel.create(indexPageRowTemp));
}
EasyExcel.write(indexPlate.getAbsolutePath()+"/"+indexPlate.getName()+".xls", MesEasyExcel.class).sheet("test").doWrite(mesEasyExcels);
ExcelUtil.toPdf(indexPlate.getAbsolutePath()+"/"+indexPlate.getName()+".xls",indexPlate.getAbsolutePath()+"/"+indexPlate.getName()+".pdf");
EasyExcel.write(indexPlate.getAbsolutePath() + "/" + indexPlate.getName() + ".xls", MesEasyExcel.class).sheet("test").doWrite(mesEasyExcels);
Integer page = PdfUtil.getPage(indexPlate.getAbsolutePath() +"/"+ indexPlate.getName()+".pdf");
ExcelUtil.toPdf(indexPlate.getAbsolutePath() + "/" + indexPlate.getName() + ".xls", indexPlate.getAbsolutePath() + "/" + indexPlate.getName() + ".pdf");
Integer page = PdfUtil.getPage(indexPlate.getAbsolutePath() + "/" + indexPlate.getName() + ".pdf");
indexPageRows= indexGen(indexPlate, rollList, page, totalSize);
indexPageRows = indexGen(indexPlate, rollList, page, totalSize);
//修正数据
System.out.println(new Gson().toJson(indexPageRows));
//生成excel
mesEasyExcels = new ArrayList<>();
for(IndexPageRow indexPageRowTemp:indexPageRows){
for (IndexPageRow indexPageRowTemp : indexPageRows) {
mesEasyExcels.add(MesEasyExcel.create(indexPageRowTemp));
}
EasyExcel.write(indexPlate.getAbsolutePath()+"/"+indexPlate.getName()+".xls", MesEasyExcel.class).sheet("test").doWrite(mesEasyExcels);
EasyExcel.write(indexPlate.getAbsolutePath() + "/" + indexPlate.getName() + ".xls", MesEasyExcel.class).sheet("test").doWrite(mesEasyExcels);
ExcelUtil.toPdf(indexPlate.getAbsolutePath()+"/"+indexPlate.getName()+".xls",indexPlate.getAbsolutePath()+"/"+indexPlate.getName()+".pdf");
ExcelUtil.toPdf(indexPlate.getAbsolutePath() + "/" + indexPlate.getName() + ".xls", indexPlate.getAbsolutePath() + "/" + indexPlate.getName() + ".pdf");
//写入文件夹。
PdfToPic.toPic(indexPlate.getAbsolutePath()+"/"+indexPlate.getName()+".pdf",indexPlate.getAbsolutePath()+"/片头","01","jpg");
PdfToPic.toPic(indexPlate.getAbsolutePath() + "/" + indexPlate.getName() + ".pdf", indexPlate.getAbsolutePath() + "/片头", "01", "jpg");
PdfToPic.toPicDesc(indexPlate.getAbsolutePath()+"/"+indexPlate.getName()+".pdf",indexPlate.getAbsolutePath()+"/片尾","00","jpg");
PdfToPic.toPicDesc(indexPlate.getAbsolutePath() + "/" + indexPlate.getName() + ".pdf", indexPlate.getAbsolutePath() + "/片尾", "00", "jpg");
File pdf = new File(indexPlate.getAbsolutePath() + "/" + indexPlate.getName() + ".pdf");
//再重算一次索引,以及将文件进行替换。
File parentFile = pdf.getParentFile().getParentFile();
File file = new File(parentFile.getAbsolutePath() + "/" + indexPlate.getName() + ".pdf");
Files.move(pdf.toPath(),file.toPath(), StandardCopyOption.ATOMIC_MOVE);
Files.move(pdf.toPath(), file.toPath(), StandardCopyOption.ATOMIC_MOVE);
File xls = new File(indexPlate.getAbsolutePath() + "/" + indexPlate.getName() + ".xls");
//再重算一次索引,以及将文件进行替换。
File xlsParentFile = xls.getParentFile().getParentFile();
File file2 = new File(xlsParentFile.getAbsolutePath() + "/" + indexPlate.getName() + ".xls");
Files.move(xls.toPath(),file2.toPath());
Files.move(xls.toPath(), file2.toPath());
//计算完整索引
List<FullIndexPageRow> fullIndexPageRows = new ArrayList<>();
int i = 1;
for (Roll roll : rollList) {
List<Pieces> piecesList = roll.getPiecesList();
for (Pieces pieces : piecesList) {
List<Document> documentList = pieces.getDocumentList();
for (Document document : documentList) {
FullIndexPageRow fullIndexPageRow = new FullIndexPageRow(indexPlate.getZongName(), indexPlate.getName(), roll.getName(), pieces.getName(), document.getName(), document.isA3() ? "A3" : "A4", i);
fullIndexPageRows.add(fullIndexPageRow);
}
}
}
EasyExcel.write(indexPlate.getAbsolutePath() + "/full-index-" + indexPlate.getName() + ".xls", MesEasyExcel.class).sheet("test").doWrite(fullIndexPageRows);
}
@ -245,103 +259,102 @@ public class SuoyinService {
//
}
private static void genPieces(Pieces pieces, File[] listFiles,FileTypeEnum fileTypeEnum) {
private static void genPieces(Pieces pieces, File[] listFiles, FileTypeEnum fileTypeEnum) {
List<Document> documentList = new ArrayList<>();
for (File docfile : listFiles) {
//非图片模式,跳过。
if(!(docfile.getName().endsWith(".jpg") || docfile.getName().endsWith(".png")
|| docfile.getName().endsWith(".jpeg") || docfile.getName().endsWith(".tif")
|| docfile.getName().endsWith(".tiff")|| docfile.getName().endsWith(".jp2") || docfile.getName().endsWith(".jpm"))|| docfile.getName().endsWith(".gif")){
continue;
for (File docfile : listFiles) {
//非图片模式,跳过。
if (!(docfile.getName().endsWith(".jpg") || docfile.getName().endsWith(".png")
|| docfile.getName().endsWith(".jpeg") || docfile.getName().endsWith(".tif")
|| docfile.getName().endsWith(".tiff") || docfile.getName().endsWith(".jp2") || docfile.getName().endsWith(".jpm")) || docfile.getName().endsWith(".gif")) {
continue;
}
if (docfile.getName().endsWith(".jp2") || docfile.getName().endsWith(".jpm")) {
// 读取 JPEG 2000 图像文件
try {
BufferedImage image = ImageIO.read(docfile);
int height = image.getHeight();
int width = image.getWidth();
Document document = new Document(width, height, 300, docfile.getName());
documentList.add(document);
} catch (IOException e) {
throw new RuntimeException(e);
}
if (docfile.getName().endsWith(".jp2") || docfile.getName().endsWith(".jpm")) {
// 读取 JPEG 2000 图像文件
try {
BufferedImage image = ImageIO.read(docfile);
int height = image.getHeight();
int width = image.getWidth();
Document document = new Document(width, height, 300);
documentList.add(document);
} catch (IOException e) {
throw new RuntimeException(e);
}
} else {
try {
ImageInfo imageInfo = Imaging.getImageInfo(docfile);
int height = imageInfo.getHeight();
int width = imageInfo.getWidth();
int physicalHeightDpi = imageInfo.getPhysicalHeightDpi();
Document document = new Document(width, height, physicalHeightDpi);
documentList.add(document);
} catch (IOException e) {
throw new RuntimeException("非图片格式", e);
} catch (ImageReadException e) {
throw new RuntimeException(e);
} catch (IllegalArgumentException e) {
throw new RuntimeException(e);
}
} else {
try {
ImageInfo imageInfo = Imaging.getImageInfo(docfile);
int height = imageInfo.getHeight();
int width = imageInfo.getWidth();
int physicalHeightDpi = imageInfo.getPhysicalHeightDpi();
Document document = new Document(width, height, physicalHeightDpi, docfile.getName());
documentList.add(document);
} catch (IOException e) {
throw new RuntimeException("非图片格式", e);
} catch (ImageReadException e) {
throw new RuntimeException(e);
} catch (IllegalArgumentException e) {
throw new RuntimeException(e);
}
pieces.put(documentList);
}
pieces.put(documentList);
}
}
private List<IndexPageRow> indexGen(IndexPlate indexPlate, List<Roll> rollList, Integer pianPageNum, Integer totalSize) {
private List<IndexPageRow> indexGen(IndexPlate indexPlate, List<Roll> rollList, Integer pianPageNum, Integer totalSize) {
List<IndexPageRow> indexPageRows = new ArrayList<>();
int start = 1;
//添加片头
for(Roll roll: rollList){
for (Roll roll : rollList) {
//跳过片头
if(roll.getName().equals("片头")){
if (roll.getName().equals("片头")) {
File file = new File(roll.getAbsolutePath());
int fileasize = file.listFiles().length;
fileasize+=pianPageNum;
fileasize += pianPageNum;
IndexPageRow indexPageRow = new IndexPageRow(indexPlate.getZongName(), indexPlate.getName(), roll.getName(), "", fileasize, start);
start+=fileasize;
start += fileasize;
indexPageRows.add(indexPageRow);
start+=1;
start += 1;
}
}
//处理偏中
for(Roll roll: rollList){
for (Roll roll : rollList) {
//跳过片头
if(roll.getName().equals("片头")){
if (roll.getName().equals("片头")) {
continue;
}
//跳过片尾
if(roll.getName().equals("片尾")){
if (roll.getName().equals("片尾")) {
continue;
}
List<Pieces> piecesList = roll.getPiecesList();
for(Pieces pieces:piecesList){
for (Pieces pieces : piecesList) {
IndexPageRow indexPageRow = new IndexPageRow(indexPlate.getZongName(), indexPlate.getName(), roll.getName(), pieces.getName(), pieces.getDocumentList().size(), start);
start+=pieces.getDocumentList().size();
start += pieces.getDocumentList().size();
indexPageRows.add(indexPageRow);
}
start+=1;
start += 1;
}
//添加片尾
for(Roll roll: rollList){
for (Roll roll : rollList) {
//跳过片头
if(roll.getName().equals("片尾")){
if (roll.getName().equals("片尾")) {
File file = new File(roll.getAbsolutePath());
int fileasize = file.listFiles().length;
fileasize+=pianPageNum;
fileasize += pianPageNum;
IndexPageRow indexPageRow = new IndexPageRow(indexPlate.getZongName(), indexPlate.getName(), roll.getName(), "", fileasize, start);
start+=fileasize;
start += fileasize;
indexPageRows.add(indexPageRow);
start+=1;
start += 1;
}
}
@ -353,7 +366,7 @@ public class SuoyinService {
}
private void findAllDir(String absolutePath, Map<String,IndexPlate> map) {
private void findAllDir(String absolutePath, Map<String, IndexPlate> map) {
File sourceFile = new File(absolutePath);
@ -369,23 +382,23 @@ public class SuoyinService {
File rofile = o.getParentFile().getParentFile();
// new Plate()
if(map.get(rofile.getAbsolutePath())==null){
IndexPlate indexPlate = new IndexPlate(rofile.getAbsolutePath(), rofile.getName(),rofile.getParentFile().getName());
map.put(rofile.getAbsolutePath(),indexPlate);
if (map.get(rofile.getAbsolutePath()) == null) {
IndexPlate indexPlate = new IndexPlate(rofile.getAbsolutePath(), rofile.getName(), rofile.getParentFile().getName());
map.put(rofile.getAbsolutePath(), indexPlate);
}
} else if (o.getName().endsWith(".docx") || o.getName().endsWith(".doc")) {
File rofile = o.getParentFile().getParentFile();
// new Plate()
if(map.get(rofile.getAbsolutePath())==null){
IndexPlate indexPlate = new IndexPlate(rofile.getAbsolutePath(), rofile.getName(),rofile.getParentFile().getName());
map.put(rofile.getAbsolutePath(),indexPlate);
if (map.get(rofile.getAbsolutePath()) == null) {
IndexPlate indexPlate = new IndexPlate(rofile.getAbsolutePath(), rofile.getName(), rofile.getParentFile().getName());
map.put(rofile.getAbsolutePath(), indexPlate);
}
} else if (o.getName().endsWith(".jpg") || o.getName().endsWith(".png")
|| o.getName().endsWith(".jpeg") || o.getName().endsWith(".tif")
|| o.getName().endsWith(".tiff")) {
if(o.getParentFile().getName().equals("片头")||o.getParentFile().getName().equals("片尾")){
if (o.getParentFile().getName().equals("片头") || o.getParentFile().getName().equals("片尾")) {
continue;
}
@ -397,9 +410,9 @@ public class SuoyinService {
//盘
.getParentFile();
if(map.get(parentFile.getAbsolutePath())==null){
IndexPlate indexPlate = new IndexPlate(parentFile.getAbsolutePath(), parentFile.getName(),parentFile.getParentFile().getName());
map.put(parentFile.getAbsolutePath(),indexPlate);
if (map.get(parentFile.getAbsolutePath()) == null) {
IndexPlate indexPlate = new IndexPlate(parentFile.getAbsolutePath(), parentFile.getName(), parentFile.getParentFile().getName());
map.put(parentFile.getAbsolutePath(), indexPlate);
}
} else {

Loading…
Cancel
Save