|
|
|
@ -1,13 +1,23 @@
|
|
|
|
|
package com.docus.sw.souyin;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
|
|
|
import com.alibaba.excel.util.FileUtils;
|
|
|
|
|
import com.docus.sw.Config;
|
|
|
|
|
import com.docus.sw.fenpan.Document;
|
|
|
|
|
import com.docus.sw.fenpan.FileTypeEnum;
|
|
|
|
|
import com.docus.sw.fenpan.Pieces;
|
|
|
|
|
import com.docus.sw.fenpan.Plate;
|
|
|
|
|
import com.docus.sw.fenpan.Roll;
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
|
import org.apache.commons.imaging.ImageInfo;
|
|
|
|
|
import org.apache.commons.imaging.ImageReadException;
|
|
|
|
|
import org.apache.commons.imaging.Imaging;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
public class SuoyinService {
|
|
|
|
|
|
|
|
|
@ -18,33 +28,238 @@ public class SuoyinService {
|
|
|
|
|
//统计出需要使用的 胶片量
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws IOException {
|
|
|
|
|
Config.loadConfig();
|
|
|
|
|
String path = "C:\\jiahsi-saomiao\\0001";
|
|
|
|
|
new SuoyinService().index(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void test(){
|
|
|
|
|
ArrayList<IndexPlate> indexPlates = new ArrayList<>();
|
|
|
|
|
findAllDir("",indexPlates);
|
|
|
|
|
public void index(String path) {
|
|
|
|
|
// ArrayList<IndexPlate> indexPlates = new ArrayList<>();
|
|
|
|
|
Map<String,IndexPlate> map = new HashMap<>();
|
|
|
|
|
findAllDir(path, map);
|
|
|
|
|
|
|
|
|
|
//计算出宗
|
|
|
|
|
|
|
|
|
|
//计算出每个盘的目录。
|
|
|
|
|
for (IndexPlate indexPlate : map.values()) {
|
|
|
|
|
String absolutePath = indexPlate.getAbsolutePath();
|
|
|
|
|
File file = new File(absolutePath);
|
|
|
|
|
File[] files = file.listFiles();
|
|
|
|
|
|
|
|
|
|
List<Roll> rollList = new ArrayList<>();
|
|
|
|
|
//卷
|
|
|
|
|
for (File rollFile : files) {
|
|
|
|
|
if (rollFile.getName().equals("片头")) {
|
|
|
|
|
//填充卷
|
|
|
|
|
Roll roll = new Roll(rollFile.getName(), rollFile.getAbsolutePath());
|
|
|
|
|
|
|
|
|
|
rollList.add(roll);
|
|
|
|
|
} else if (rollFile.getName().equals("片尾")) {
|
|
|
|
|
//填充卷
|
|
|
|
|
Roll roll = new Roll(rollFile.getName(), rollFile.getAbsolutePath());
|
|
|
|
|
|
|
|
|
|
rollList.add(roll);
|
|
|
|
|
} else {
|
|
|
|
|
//
|
|
|
|
|
List<Pieces> pieceList = new ArrayList<>();
|
|
|
|
|
File[] piecesFile = rollFile.listFiles();
|
|
|
|
|
for(File piece:piecesFile){
|
|
|
|
|
List<Document> documentList = new ArrayList<>();
|
|
|
|
|
Pieces pieces = new Pieces(FileTypeEnum.JPG, piece.getAbsolutePath(), piece.getName());
|
|
|
|
|
for (File docfile : piece.listFiles()) {
|
|
|
|
|
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) {
|
|
|
|
|
// FileUtils.delete(file);
|
|
|
|
|
throw new RuntimeException("非图片格式", e);
|
|
|
|
|
} catch (ImageReadException e) {
|
|
|
|
|
// FileUtils.delete(file);
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
|
// FileUtils.delete(file);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pieces.put(documentList);
|
|
|
|
|
pieceList.add(pieces);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//填充卷
|
|
|
|
|
Roll roll = new Roll(rollFile.getName(), rollFile.getAbsolutePath());
|
|
|
|
|
roll.putAll(pieceList);
|
|
|
|
|
rollList.add(roll);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
indexPlate.putAll(rollList);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//生成索引目录
|
|
|
|
|
for(IndexPlate indexPlate : map.values()){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Roll> rollList = indexPlate.getRollList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//计算出总size
|
|
|
|
|
Double totalPage = 0d;
|
|
|
|
|
for(Roll roll:rollList){
|
|
|
|
|
List<Pieces> piecesList = roll.getPiecesList();
|
|
|
|
|
totalPage+=piecesList.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Integer pianPageNum = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Integer totalSize = 0;
|
|
|
|
|
for(Roll roll:rollList){
|
|
|
|
|
//跳过片头
|
|
|
|
|
if(roll.getName().equals("片头")){
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
//跳过片尾
|
|
|
|
|
if(roll.getName().equals("片尾")){
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
List<Pieces> piecesList = roll.getPiecesList();
|
|
|
|
|
for(Pieces pieces:piecesList){
|
|
|
|
|
Integer size = pieces.getDocumentList().size();
|
|
|
|
|
totalSize+=size;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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){
|
|
|
|
|
mesEasyExcels.add(MesEasyExcel.create(indexPageRowTemp));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EasyExcel.write(indexPlate.getAbsolutePath()+"\\index.xls", MesEasyExcel.class).sheet("test").doWrite(mesEasyExcels);
|
|
|
|
|
|
|
|
|
|
ExcelUtil.toPdf(indexPlate.getAbsolutePath()+"\\index.xls",indexPlate.getAbsolutePath()+"\\index.pdf");
|
|
|
|
|
|
|
|
|
|
Integer page = PdfUtil.getPage(indexPlate.getAbsolutePath() + "\\index.pdf");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
indexPageRows= indexGen(indexPlate, rollList, page, totalSize);
|
|
|
|
|
//修正数据
|
|
|
|
|
System.out.println(new Gson().toJson(indexPageRows));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//生成excel
|
|
|
|
|
mesEasyExcels = new ArrayList<>();
|
|
|
|
|
for(IndexPageRow indexPageRowTemp:indexPageRows){
|
|
|
|
|
mesEasyExcels.add(MesEasyExcel.create(indexPageRowTemp));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EasyExcel.write(indexPlate.getAbsolutePath()+"\\index.xls", MesEasyExcel.class).sheet("test").doWrite(mesEasyExcels);
|
|
|
|
|
|
|
|
|
|
ExcelUtil.toPdf(indexPlate.getAbsolutePath()+"\\index.xls",indexPlate.getAbsolutePath()+"\\index.pdf");
|
|
|
|
|
|
|
|
|
|
//写入文件夹。
|
|
|
|
|
PdfToPic.toPic(indexPlate.getAbsolutePath()+"\\index.pdf",indexPlate.getAbsolutePath()+"/片头","0000","jpg");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PdfToPic.toPicDesc(indexPlate.getAbsolutePath()+"\\index.pdf",indexPlate.getAbsolutePath()+"/片尾","0010","jpg");
|
|
|
|
|
|
|
|
|
|
//再重算一次索引,以及将文件进行替换。
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//读取片头
|
|
|
|
|
//读取片尾
|
|
|
|
|
//生成excel
|
|
|
|
|
//生成图片
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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){
|
|
|
|
|
|
|
|
|
|
//跳过片头
|
|
|
|
|
if(roll.getName().equals("片头")){
|
|
|
|
|
File file = new File(roll.getAbsolutePath());
|
|
|
|
|
int fileasize = file.listFiles().length;
|
|
|
|
|
fileasize+=pianPageNum;
|
|
|
|
|
IndexPageRow indexPageRow = new IndexPageRow(indexPlate.getZongName(), indexPlate.getName(), roll.getName(), "", fileasize, start);
|
|
|
|
|
start+=fileasize;
|
|
|
|
|
indexPageRows.add(indexPageRow);
|
|
|
|
|
start+=1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//处理偏中
|
|
|
|
|
for(Roll roll: rollList){
|
|
|
|
|
|
|
|
|
|
//跳过片头
|
|
|
|
|
if(roll.getName().equals("片头")){
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
//跳过片尾
|
|
|
|
|
if(roll.getName().equals("片尾")){
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
List<Pieces> piecesList = roll.getPiecesList();
|
|
|
|
|
for(Pieces pieces:piecesList){
|
|
|
|
|
IndexPageRow indexPageRow = new IndexPageRow(indexPlate.getZongName(), indexPlate.getName(), roll.getName(), pieces.getName(), pieces.getDocumentList().size(), start);
|
|
|
|
|
start+=pieces.getDocumentList().size();
|
|
|
|
|
indexPageRows.add(indexPageRow);
|
|
|
|
|
}
|
|
|
|
|
start+=1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//添加片尾
|
|
|
|
|
for(Roll roll: rollList){
|
|
|
|
|
|
|
|
|
|
//跳过片头
|
|
|
|
|
if(roll.getName().equals("片尾")){
|
|
|
|
|
File file = new File(roll.getAbsolutePath());
|
|
|
|
|
int fileasize = file.listFiles().length;
|
|
|
|
|
fileasize+=pianPageNum;
|
|
|
|
|
IndexPageRow indexPageRow = new IndexPageRow(indexPlate.getZongName(), indexPlate.getName(), roll.getName(), "", fileasize, start);
|
|
|
|
|
start+=fileasize;
|
|
|
|
|
indexPageRows.add(indexPageRow);
|
|
|
|
|
start+=1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//加上统计
|
|
|
|
|
IndexPageRow indexPageRow = new IndexPageRow("", "", "", "有效画幅数", totalSize, null);
|
|
|
|
|
indexPageRows.add(indexPageRow);
|
|
|
|
|
|
|
|
|
|
return indexPageRows;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void findAllDir(String absolutePath, Map<String,IndexPlate> map) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void findAllDir(String absolutePath, List<IndexPlate> allDirectory) {
|
|
|
|
|
File sourceFile = new File(absolutePath);
|
|
|
|
|
File[] files = sourceFile.listFiles();
|
|
|
|
|
for (File o : files) {
|
|
|
|
|
if (o.isDirectory()) {
|
|
|
|
|
findAllDir(o.getAbsolutePath(), allDirectory);
|
|
|
|
|
findAllDir(o.getAbsolutePath(), map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (o.isFile()) {
|
|
|
|
@ -58,14 +273,24 @@ public class SuoyinService {
|
|
|
|
|
} 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("片尾")){
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//件
|
|
|
|
|
File parentFile = o.getParentFile()
|
|
|
|
|
//卷
|
|
|
|
|
.getParentFile()
|
|
|
|
|
//盘
|
|
|
|
|
.getParentFile();
|
|
|
|
|
IndexPlate indexPlate = new IndexPlate(parentFile.getAbsolutePath(), parentFile.getName());
|
|
|
|
|
allDirectory.add(indexPlate);
|
|
|
|
|
//卷
|
|
|
|
|
.getParentFile()
|
|
|
|
|
//盘
|
|
|
|
|
.getParentFile();
|
|
|
|
|
|
|
|
|
|
if(map.get(parentFile.getAbsolutePath())==null){
|
|
|
|
|
IndexPlate indexPlate = new IndexPlate(parentFile.getAbsolutePath(), parentFile.getName(),parentFile.getParentFile().getName());
|
|
|
|
|
map.put(parentFile.getAbsolutePath(),indexPlate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
FileUtils.delete(new File(o.getAbsolutePath()));
|
|
|
|
|
System.out.println("请删除无效的文件:" + o.getAbsolutePath());
|
|
|
|
|