Browse Source

相册模板更改

cr 1 week ago
parent
commit
c4b0ca9c8d

+ 208 - 96
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/AlbumController.java

@@ -162,7 +162,7 @@ public class AlbumController extends BladeController {
 		album.setStartDate(strings[0]);
 		album.setEndDate(strings[1]);
 		//获取固定表格
-		ExcelTab excelTab = this.excelTabClient.getById("1550363881879781377"); //影像资料模板
+		ExcelTab excelTab = this.excelTabClient.getById("1950465427890794498"); //影像资料模板
 		String file_path = null;
 		if (SystemUtils.isWindows()) {
 			file_path = "C:\\pdfFiles\\";
@@ -180,117 +180,229 @@ public class AlbumController extends BladeController {
 		}
 		if (excelTab != null) {
 			//获取数据
+//			try {
+//					//需要删除的本地文件集合
+//					List<String> removeList = new ArrayList<>();
+//							//获取模板文件流
+//							InputStream modInput = null;
+//							FileInputStream excelFileInput = null;
+//							FileOutputStream outputStream = null;
+//							Workbook workbook = null;
+//
+//							List<String> pdfFileList = new ArrayList<>();
+//							//两个图片一组
+//							List<List<String>> groupUrls =  CommonUtil.getBatchSize(uris, 2);
+//							for (List<String> urls : groupUrls) {
+//								try {
+//									//创建模板Workbook
+//									modInput = CommonUtil.getOSSInputStream(excelTab.getFileUrl());
+//									if (modInput != null) {
+//										workbook = WorkbookFactory.create(modInput);
+//										for (int i = 0, l = urls.size(); i < l; i++) {
+//											try {
+//												CreationHelper helper = workbook.getCreationHelper();
+//												Sheet sheet = workbook.getSheetAt(0);
+//												Drawing<?> drawing = sheet.createDrawingPatriarch();
+//												ClientAnchor anchor = helper.createClientAnchor();
+//												Long id = map.get(urls.get(i));
+//								                ImageClassificationFile file=imageClassificationFileClient.getImageClassificationFileById(id);
+//												//获取文件流
+//												byte[] bytes = CommonUtil.InputStreamToBytes(CommonUtil.getOSSInputStream(urls.get(i)));
+//												if (bytes[0] == 82 && bytes[1] == 73 && bytes[2] == 70){
+//													bytes = CommonUtil.webpToPngBytes(CommonUtil.getOSSInputStream(urls.get(i)));
+//												}
+//												//压缩文件大小
+//												byte[] byteNew = FileUtils.compressImage(bytes);
+//												//创建图片
+//												Picture picture = drawing.createPicture(anchor, workbook.addPicture(byteNew, Workbook.PICTURE_TYPE_PNG));
+//												picture.resize();
+//
+//												//图片定位
+//												FileUtils.imageOrientation(sheet, anchor, i == 1 ? new DataVO(1, 8) : new DataVO(0, 2));
+//
+//												//定位其它信息
+//												//文字说明
+//												sheet.getRow(i == 0 ? 0 : 6).getCell(i == 0 ? 3 : 0).setCellValue("文字说明:\n" + "  " + (ObjectUtil.isNotEmpty(file.getTextContent()) ? file.getTextContent() : ""));
+//												//照片号
+//												sheet.getRow(i == 0 ? 1 : 7).getCell(i == 0 ? 3 : 0).setCellValue("照片号:\n" + "  " + (ObjectUtil.isNotEmpty(file.getPhotoCode()) ? file.getPhotoCode() : ""));
+//												//底片号
+//												sheet.getRow(i == 0 ? 2 : 8).getCell(i == 0 ? 3 : 0).setCellValue("底片号:\n" + "  " + (ObjectUtil.isNotEmpty(file.getFilmCode()) ? file.getFilmCode() : ""));
+//												//题名
+//												sheet.getRow(i == 0 ? 3 : 9).getCell(i == 0 ? 0 : 2).setCellValue("题名:\n" + "  " + (ObjectUtil.isNotEmpty(file.getTitle()) ? file.getTitle() : ""));
+//												//参见号
+//												sheet.getRow(i == 0 ? 3 : 9).getCell(i == 0 ? 2 : 0).setCellValue("参见号:\n" + "  " + (ObjectUtil.isNotEmpty(file.getSeeAlsoCode()) ? file.getSeeAlsoCode() : ""));
+//												//拍摄时间
+//												sheet.getRow(i == 0 ? 4 : 10).getCell(i == 0 ? 2 : 0).setCellValue("拍摄时间:\n" + "  " + (ObjectUtil.isNotEmpty(DateUtil.format(file.getShootingTime(), "yyyy-MM-dd")) ? DateUtil.format(file.getShootingTime(), "yyyy-MM-dd") : ""));
+//												//拍摄者
+//												sheet.getRow(i == 0 ? 5 : 11).getCell(i == 0 ? 2 : 0).setCellValue("拍摄者:\n" + "  " + (ObjectUtil.isNotEmpty(file.getShootingUser()) ? file.getShootingUser() : ""));
+//
+//											} catch (Exception e) {
+//												e.printStackTrace();
+//											}
+//										}
+//
+//										String locationFile = file_path + SnowFlakeUtil.getId() + ".xlsx";
+//										outputStream = new FileOutputStream(locationFile);
+//										//记录文件删除
+//										removeList.add(locationFile);
+//										//生成一份新的excel
+//										workbook.write(outputStream);
+//										//将excel转PDF
+//										File excelFile = new File(locationFile);
+//										excelFileInput = new FileInputStream(excelFile);
+//										MultipartFile files = new MockMultipartFile("file", excelFile.getName(), "text/plain", IOUtils.toByteArray(excelFileInput));
+//										NewBladeFile bladeFile = this.commonFileClient.excelToPdf(files);
+//										if (bladeFile != null) {
+//											pdfFileList.add(bladeFile.getPdfUrl());
+//										}
+//									}
+//								} catch (Exception e) {
+//									e.printStackTrace();
+//								} finally {
+//									if (outputStream != null) {
+//										IoUtil.closeQuietly(outputStream);
+//									}
+//									if (modInput != null) {
+//										IoUtil.closeQuietly(modInput);
+//									}
+//									if (excelFileInput != null) {
+//										IoUtil.closeQuietly(excelFileInput);
+//									}
+//									if (workbook != null) {
+//										IoUtil.closeQuietly(workbook);
+//									}
+//								}
+//							}
+//
+//							//合并pdf并上传
+//							String mergeName = SnowFlakeUtil.getId() + ".pdf";
+//							String mergeUrl = file_path + mergeName;
+//							FileUtils.mergePdfPublicMethods(pdfFileList, mergeUrl);
+//							//记录文件删除
+//							removeList.add(mergeUrl);
+//							//上传
+//							BladeFile bladeFile = this.newIOSSClient.uploadFile(mergeName, mergeUrl);
+//							if (bladeFile != null) {
+//								album.setImagesPdf(bladeFile.getLink());
+//							}
+//
+//					if (removeList.size() > 0) {
+//						//删除本地文件
+//						CommonUtil.removeFile(removeList);
+//					}
+//
+//			} catch (Exception e) {
+//				e.printStackTrace();
+//			}
 			try {
-					//需要删除的本地文件集合
-					List<String> removeList = new ArrayList<>();
-							//获取模板文件流
-							InputStream modInput = null;
-							FileInputStream excelFileInput = null;
-							FileOutputStream outputStream = null;
-							Workbook workbook = null;
+				//需要删除的本地文件集合
+				List<String> removeList = new ArrayList<>();
+				//获取模板文件流
+				InputStream modInput = null;
+				FileInputStream excelFileInput = null;
+				FileOutputStream outputStream = null;
+				Workbook workbook = null;
 
-							List<String> pdfFileList = new ArrayList<>();
-							//两个图片一组
-							List<List<String>> groupUrls =  CommonUtil.getBatchSize(uris, 2);
-							for (List<String> urls : groupUrls) {
+				List<String> pdfFileList = new ArrayList<>();
+				//两个图片一组
+				List<List<String>> groupUrls = CommonUtil.getBatchSize(uris, 2);
+				for (List<String> urls : groupUrls) {
+					try {
+						//创建模板Workbook
+						modInput = CommonUtil.getOSSInputStream(excelTab.getFileUrl());
+						if (modInput != null) {
+							workbook = WorkbookFactory.create(modInput);
+							for (int i = 0, l = urls.size(); i < l; i++) {
 								try {
-									//创建模板Workbook
-									modInput = CommonUtil.getOSSInputStream(excelTab.getFileUrl());
-									if (modInput != null) {
-										workbook = WorkbookFactory.create(modInput);
-										for (int i = 0, l = urls.size(); i < l; i++) {
-											try {
-												CreationHelper helper = workbook.getCreationHelper();
-												Sheet sheet = workbook.getSheetAt(0);
-												Drawing<?> drawing = sheet.createDrawingPatriarch();
-												ClientAnchor anchor = helper.createClientAnchor();
-												Long id = map.get(urls.get(i));
-								                ImageClassificationFile file=imageClassificationFileClient.getImageClassificationFileById(id);
-												//获取文件流
-												byte[] bytes = CommonUtil.InputStreamToBytes(CommonUtil.getOSSInputStream(urls.get(i)));
-												if (bytes[0] == 82 && bytes[1] == 73 && bytes[2] == 70){
-													bytes = CommonUtil.webpToPngBytes(CommonUtil.getOSSInputStream(urls.get(i)));
-												}
-												//压缩文件大小
-												byte[] byteNew = FileUtils.compressImage(bytes);
-												//创建图片
-												Picture picture = drawing.createPicture(anchor, workbook.addPicture(byteNew, Workbook.PICTURE_TYPE_PNG));
-												picture.resize();
+									CreationHelper helper = workbook.getCreationHelper();
+									Sheet sheet = workbook.getSheetAt(0);
+									Drawing<?> drawing = sheet.createDrawingPatriarch();
+									ClientAnchor anchor = helper.createClientAnchor();
+									Long id = map.get(urls.get(i));
+									ImageClassificationFile file = imageClassificationFileClient.getImageClassificationFileById(id);
 
-												//图片定位
-												FileUtils.imageOrientation(sheet, anchor, i == 1 ? new DataVO(1, 8) : new DataVO(0, 2));
+									//获取文件流
+									byte[] bytes = CommonUtil.InputStreamToBytes(CommonUtil.getOSSInputStream(urls.get(i)));
+									if (bytes[0] == 82 && bytes[1] == 73 && bytes[2] == 70) {
+										bytes = CommonUtil.webpToPngBytes(CommonUtil.getOSSInputStream(urls.get(i)));
+									}
+									//压缩文件大小
+									byte[] byteNew = FileUtils.compressImage(bytes);
+									//创建图片
+									Picture picture = drawing.createPicture(anchor, workbook.addPicture(byteNew, Workbook.PICTURE_TYPE_PNG));
+									picture.resize();
 
-												//定位其它信息
-												//文字说明
-												sheet.getRow(i == 0 ? 0 : 6).getCell(i == 0 ? 3 : 0).setCellValue("文字说明:\n" + "  " + (ObjectUtil.isNotEmpty(file.getTextContent()) ? file.getTextContent() : ""));
-												//照片号
-												sheet.getRow(i == 0 ? 1 : 7).getCell(i == 0 ? 3 : 0).setCellValue("照片号:\n" + "  " + (ObjectUtil.isNotEmpty(file.getPhotoCode()) ? file.getPhotoCode() : ""));
-												//底片号
-												sheet.getRow(i == 0 ? 2 : 8).getCell(i == 0 ? 3 : 0).setCellValue("底片号:\n" + "  " + (ObjectUtil.isNotEmpty(file.getFilmCode()) ? file.getFilmCode() : ""));
-												//题名
-												sheet.getRow(i == 0 ? 3 : 9).getCell(i == 0 ? 0 : 2).setCellValue("题名:\n" + "  " + (ObjectUtil.isNotEmpty(file.getTitle()) ? file.getTitle() : ""));
-												//参见号
-												sheet.getRow(i == 0 ? 3 : 9).getCell(i == 0 ? 2 : 0).setCellValue("参见号:\n" + "  " + (ObjectUtil.isNotEmpty(file.getSeeAlsoCode()) ? file.getSeeAlsoCode() : ""));
-												//拍摄时间
-												sheet.getRow(i == 0 ? 4 : 10).getCell(i == 0 ? 2 : 0).setCellValue("拍摄时间:\n" + "  " + (ObjectUtil.isNotEmpty(DateUtil.format(file.getShootingTime(), "yyyy-MM-dd")) ? DateUtil.format(file.getShootingTime(), "yyyy-MM-dd") : ""));
-												//拍摄者
-												sheet.getRow(i == 0 ? 5 : 11).getCell(i == 0 ? 2 : 0).setCellValue("拍摄者:\n" + "  " + (ObjectUtil.isNotEmpty(file.getShootingUser()) ? file.getShootingUser() : ""));
+									//图片定位
+									FileUtils.imageOrientation(sheet, anchor, i == 1 ? new DataVO(0, 8) : new DataVO(0, 3));
 
-											} catch (Exception e) {
-												e.printStackTrace();
-											}
-										}
+									//定位其它信息
+									int baseRow = i == 0 ? 0 : 5; // 第一组在0-4行,第二组在5-9行
+
+									// 分组号 (C列,索引2)
+									sheet.getRow(baseRow ).getCell(3).setCellValue(albumDTO.getGroupNumber() != null ? albumDTO.getGroupNumber() : "");
+									// 照片编号 (C列,索引2)
+									sheet.getRow(baseRow + 1).getCell(3).setCellValue(file.getPhotoCode() != null ? file.getPhotoCode() : "");
+									// 摄影者 (C列,索引2)
+									sheet.getRow(baseRow + 2).getCell(3).setCellValue(file.getShootingUser() != null ? file.getShootingUser() : "");
+									// 拍摄时间 (C列,索引2)
+									sheet.getRow(baseRow + 3).getCell(3).setCellValue(file.getShootingTime() != null ?
+											DateUtil.format(file.getShootingTime(), "yyyy-MM-dd") : "");
+									// 照片说明 (A列,索引0)
+									sheet.getRow(baseRow+4).getCell(1).setCellValue(file.getTextContent() != null ? file.getTextContent() : "");
 
-										String locationFile = file_path + SnowFlakeUtil.getId() + ".xlsx";
-										outputStream = new FileOutputStream(locationFile);
-										//记录文件删除
-										removeList.add(locationFile);
-										//生成一份新的excel
-										workbook.write(outputStream);
-										//将excel转PDF
-										File excelFile = new File(locationFile);
-										excelFileInput = new FileInputStream(excelFile);
-										MultipartFile files = new MockMultipartFile("file", excelFile.getName(), "text/plain", IOUtils.toByteArray(excelFileInput));
-										NewBladeFile bladeFile = this.commonFileClient.excelToPdf(files);
-										if (bladeFile != null) {
-											pdfFileList.add(bladeFile.getPdfUrl());
-										}
-									}
 								} catch (Exception e) {
 									e.printStackTrace();
-								} finally {
-									if (outputStream != null) {
-										IoUtil.closeQuietly(outputStream);
-									}
-									if (modInput != null) {
-										IoUtil.closeQuietly(modInput);
-									}
-									if (excelFileInput != null) {
-										IoUtil.closeQuietly(excelFileInput);
-									}
-									if (workbook != null) {
-										IoUtil.closeQuietly(workbook);
-									}
 								}
 							}
-
-							//合并pdf并上传
-							String mergeName = SnowFlakeUtil.getId() + ".pdf";
-							String mergeUrl = file_path + mergeName;
-							FileUtils.mergePdfPublicMethods(pdfFileList, mergeUrl);
+							String locationFile = file_path + SnowFlakeUtil.getId() + ".xlsx";
+							outputStream = new FileOutputStream(locationFile);
 							//记录文件删除
-							removeList.add(mergeUrl);
-							//上传
-							BladeFile bladeFile = this.newIOSSClient.uploadFile(mergeName, mergeUrl);
+							removeList.add(locationFile);
+							//生成一份新的excel
+							workbook.write(outputStream);
+							//将excel转PDF
+							File excelFile = new File(locationFile);
+							excelFileInput = new FileInputStream(excelFile);
+							MultipartFile files = new MockMultipartFile("file", excelFile.getName(), "text/plain", IOUtils.toByteArray(excelFileInput));
+							NewBladeFile bladeFile = this.commonFileClient.excelToPdf(files);
 							if (bladeFile != null) {
-								album.setImagesPdf(bladeFile.getLink());
+								pdfFileList.add(bladeFile.getPdfUrl());
 							}
-
-					if (removeList.size() > 0) {
-						//删除本地文件
-						CommonUtil.removeFile(removeList);
+						}
+					} catch (Exception e) {
+						e.printStackTrace();
+					} finally {
+						if (outputStream != null) {
+							IoUtil.closeQuietly(outputStream);
+						}
+						if (modInput != null) {
+							IoUtil.closeQuietly(modInput);
+						}
+						if (excelFileInput != null) {
+							IoUtil.closeQuietly(excelFileInput);
+						}
+						if (workbook != null) {
+							IoUtil.closeQuietly(workbook);
+						}
 					}
+				}
+
+				//合并pdf并上传
+				String mergeName = SnowFlakeUtil.getId() + ".pdf";
+				String mergeUrl = file_path + mergeName;
+				FileUtils.mergePdfPublicMethods(pdfFileList, mergeUrl);
+				//记录文件删除
+				removeList.add(mergeUrl);
+				//上传
+				BladeFile bladeFile = this.newIOSSClient.uploadFile(mergeName, mergeUrl);
+				if (bladeFile != null) {
+					album.setImagesPdf(bladeFile.getLink());
+				}
 
+				if (removeList.size() > 0) {
+					//删除本地文件
+					CommonUtil.removeFile(removeList);
+				}
 			} catch (Exception e) {
 				e.printStackTrace();
 			}