|
@@ -26,6 +26,7 @@ import io.swagger.annotations.ApiOperation;
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+
|
|
|
import javax.validation.Valid;
|
|
|
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
@@ -42,15 +43,14 @@ import org.springblade.core.mp.support.Condition;
|
|
|
import org.springblade.core.mp.support.Query;
|
|
|
import org.springblade.core.oss.model.BladeFile;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
-import org.springblade.core.tool.utils.BeanUtil;
|
|
|
-import org.springblade.core.tool.utils.Func;
|
|
|
-import org.springblade.core.tool.utils.IoUtil;
|
|
|
-import org.springblade.core.tool.utils.ObjectUtil;
|
|
|
+import org.springblade.core.tool.utils.*;
|
|
|
import org.springblade.manager.dto.AlbumDTO;
|
|
|
import org.springblade.manager.dto.AlbumDTO1;
|
|
|
+import org.springblade.manager.entity.AlbumImages;
|
|
|
import org.springblade.manager.entity.ExcelTab;
|
|
|
import org.springblade.manager.feign.ExcelTabClient;
|
|
|
import org.springblade.manager.feign.ImageClassificationConfigClient;
|
|
|
+import org.springblade.manager.service.AlbumImagesService;
|
|
|
import org.springblade.manager.utils.FileUtils;
|
|
|
import org.springblade.resource.feign.CommonFileClient;
|
|
|
import org.springblade.resource.feign.NewIOSSClient;
|
|
@@ -77,7 +77,7 @@ import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
- * 控制器
|
|
|
+ * 控制器
|
|
|
*
|
|
|
* @author BladeX
|
|
|
* @since 2025-07-15
|
|
@@ -88,37 +88,39 @@ import java.util.List;
|
|
|
@Api(value = "", tags = "接口")
|
|
|
public class AlbumController extends BladeController {
|
|
|
|
|
|
- private final IAlbumService albumService;
|
|
|
+ private final IAlbumService albumService;
|
|
|
+
|
|
|
+ private final NewIOSSClient newIOSSClient;
|
|
|
|
|
|
- private final NewIOSSClient newIOSSClient;
|
|
|
+ private final ExcelTabClient excelTabClient;
|
|
|
|
|
|
- private final ExcelTabClient excelTabClient;
|
|
|
+ private final ImageClassificationFileClient imageClassificationFileClient;
|
|
|
|
|
|
- private final ImageClassificationFileClient imageClassificationFileClient;
|
|
|
+ private final CommonFileClient commonFileClient;
|
|
|
|
|
|
- private final CommonFileClient commonFileClient;
|
|
|
+ private final AlbumImagesService albumImagesService;
|
|
|
|
|
|
- /**
|
|
|
- * 详情
|
|
|
- */
|
|
|
- @GetMapping("/detail")
|
|
|
- @ApiOperationSupport(order = 1)
|
|
|
- @ApiOperation(value = "详情", notes = "传入album")
|
|
|
- public R<AlbumVO> detail(Album album) {
|
|
|
- Album detail = albumService.getOne(Condition.getQueryWrapper(album));
|
|
|
- return R.data(AlbumWrapper.build().entityVO(detail));
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 详情
|
|
|
+ */
|
|
|
+ @GetMapping("/detail")
|
|
|
+ @ApiOperationSupport(order = 1)
|
|
|
+ @ApiOperation(value = "详情", notes = "传入album")
|
|
|
+ public R<AlbumVO> detail(Album album) {
|
|
|
+ Album detail = albumService.getOne(Condition.getQueryWrapper(album));
|
|
|
+ return R.data(AlbumWrapper.build().entityVO(detail));
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * 分页
|
|
|
- */
|
|
|
- @PostMapping("/page")
|
|
|
- @ApiOperationSupport(order = 2)
|
|
|
- @ApiOperation(value = "分页", notes = "传入album")
|
|
|
- public R<IPage<AlbumVO>> page(Long projectId,Long contractId,Query query) {
|
|
|
- IPage<AlbumVO> pages = albumService.selectPage1(projectId,contractId,Condition.getPage(query));
|
|
|
- return R.data(pages);
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 分页
|
|
|
+ */
|
|
|
+ @PostMapping("/page")
|
|
|
+ @ApiOperationSupport(order = 2)
|
|
|
+ @ApiOperation(value = "分页", notes = "传入album")
|
|
|
+ public R<IPage<AlbumVO>> page(Long projectId, Long contractId, Query query) {
|
|
|
+ IPage<AlbumVO> pages = albumService.selectPage1(projectId, contractId, Condition.getPage(query));
|
|
|
+ return R.data(pages);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
// /**
|
|
@@ -132,54 +134,55 @@ public class AlbumController extends BladeController {
|
|
|
// return R.data(pages);
|
|
|
// }
|
|
|
|
|
|
- /**
|
|
|
- * 新增
|
|
|
- */
|
|
|
- @PostMapping("/save")
|
|
|
- @ApiOperationSupport(order = 4)
|
|
|
- @ApiOperation(value = "新增", notes = "传入album")
|
|
|
- public R save(@Valid @RequestBody AlbumDTO albumDTO) {
|
|
|
- if(albumDTO.getMargePdfUrls().isEmpty()){
|
|
|
- throw new ServiceException("相册不能为空");
|
|
|
- }
|
|
|
- List<String>uris=new ArrayList<>();
|
|
|
- HashMap<String, Long> map = new HashMap<>();
|
|
|
- for (AlbumDTO1 margePdfUrl : albumDTO.getMargePdfUrls()) {
|
|
|
- String imageUrl = margePdfUrl.getImageUrl();
|
|
|
- String[] urlss = imageUrl.split(",");
|
|
|
- for (String string : urlss) {
|
|
|
- map.put(string,margePdfUrl.getId());
|
|
|
- uris.add(string);
|
|
|
- }
|
|
|
- }
|
|
|
- if(uris.isEmpty()){
|
|
|
- throw new ServiceException("相册不能为空");
|
|
|
- }
|
|
|
- Album album=new Album();
|
|
|
- BeanUtil.copy(albumDTO,album);
|
|
|
- String dateValue = albumDTO.getDateValue();
|
|
|
- String[] strings = dateValue.split("~");
|
|
|
- album.setStartDate(strings[0]);
|
|
|
- album.setEndDate(strings[1]);
|
|
|
- //获取固定表格
|
|
|
- ExcelTab excelTab = this.excelTabClient.getById("1950465427890794498"); //影像资料模板
|
|
|
- String file_path = null;
|
|
|
- if (SystemUtils.isWindows()) {
|
|
|
- file_path = "C:\\pdfFiles\\";
|
|
|
- File file = new File(file_path);
|
|
|
- if (!file.exists()) {
|
|
|
- file.mkdirs();
|
|
|
- }
|
|
|
- }
|
|
|
- if (SystemUtils.isLinux()) {
|
|
|
- file_path = "/home/pdfFiles";
|
|
|
- File file = new File(file_path);
|
|
|
- if (!file.exists()) {
|
|
|
- file.mkdirs();
|
|
|
- }
|
|
|
- }
|
|
|
- if (excelTab != null) {
|
|
|
- //获取数据
|
|
|
+ /**
|
|
|
+ * 新增
|
|
|
+ */
|
|
|
+ @PostMapping("/save")
|
|
|
+ @ApiOperationSupport(order = 4)
|
|
|
+ @ApiOperation(value = "新增", notes = "传入album")
|
|
|
+ public R save(@Valid @RequestBody AlbumDTO albumDTO) {
|
|
|
+ if (albumDTO.getMargePdfUrls().isEmpty()) {
|
|
|
+ throw new ServiceException("相册不能为空");
|
|
|
+ }
|
|
|
+ List<String> uris = new ArrayList<>();
|
|
|
+ HashMap<String, Long> map = new HashMap<>();
|
|
|
+ for (AlbumDTO1 margePdfUrl : albumDTO.getMargePdfUrls()) {
|
|
|
+ String imageUrl = margePdfUrl.getImageUrl();
|
|
|
+ String[] urlss = imageUrl.split(",");
|
|
|
+ for (String string : urlss) {
|
|
|
+ map.put(string, margePdfUrl.getId());
|
|
|
+ uris.add(string);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (uris.isEmpty()) {
|
|
|
+ throw new ServiceException("相册不能为空");
|
|
|
+ }
|
|
|
+ Album album = new Album();
|
|
|
+ BeanUtil.copy(albumDTO, album);
|
|
|
+ album.setId(SnowFlakeUtil.getId());
|
|
|
+ String dateValue = albumDTO.getDateValue();
|
|
|
+ String[] strings = dateValue.split("~");
|
|
|
+ album.setStartDate(strings[0]);
|
|
|
+ album.setEndDate(strings[1]);
|
|
|
+ //获取固定表格
|
|
|
+ ExcelTab excelTab = this.excelTabClient.getById("1950465427890794498"); //影像资料模板
|
|
|
+ String file_path = null;
|
|
|
+ if (SystemUtils.isWindows()) {
|
|
|
+ file_path = "C:\\pdfFiles\\";
|
|
|
+ File file = new File(file_path);
|
|
|
+ if (!file.exists()) {
|
|
|
+ file.mkdirs();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (SystemUtils.isLinux()) {
|
|
|
+ file_path = "/home/pdfFiles";
|
|
|
+ File file = new File(file_path);
|
|
|
+ if (!file.exists()) {
|
|
|
+ file.mkdirs();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (excelTab != null) {
|
|
|
+ //获取数据
|
|
|
// try {
|
|
|
// //需要删除的本地文件集合
|
|
|
// List<String> removeList = new ArrayList<>();
|
|
@@ -294,139 +297,349 @@ public class AlbumController extends BladeController {
|
|
|
// } 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> 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(0, 8) : new DataVO(0, 3));
|
|
|
-
|
|
|
- //定位其它信息
|
|
|
- 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)
|
|
|
- String a=albumDTO.getImagesName()!=null?albumDTO.getImagesName():"";
|
|
|
- String b=file.getTextContent() != null ? file.getTextContent() : "";
|
|
|
- sheet.getRow(baseRow+4).getCell(1).setCellValue(a+b);
|
|
|
-
|
|
|
- } 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();
|
|
|
- }
|
|
|
- }
|
|
|
- return R.status(albumService.save(album));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 修改
|
|
|
- */
|
|
|
- @PostMapping("/update")
|
|
|
- @ApiOperationSupport(order = 5)
|
|
|
- @ApiOperation(value = "修改", notes = "传入album")
|
|
|
- public R update(@Valid @RequestBody AlbumDTO albumDTO) {
|
|
|
- Album album=new Album();
|
|
|
- BeanUtil.copy(albumDTO,album);
|
|
|
- String dateValue = albumDTO.getDateValue();
|
|
|
- String[] strings = dateValue.split("~");
|
|
|
- album.setStartDate(strings[0]);
|
|
|
- album.setEndDate(strings[1]);
|
|
|
- return R.status(albumService.updateById(album));
|
|
|
- }
|
|
|
+ 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(0, 8) : new DataVO(0, 3));
|
|
|
+
|
|
|
+ //定位其它信息
|
|
|
+ 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)
|
|
|
+ String a = albumDTO.getImagesName() != null ? albumDTO.getImagesName() : "";
|
|
|
+ String b = file.getTextContent() != null ? file.getTextContent() : "";
|
|
|
+ sheet.getRow(baseRow + 4).getCell(1).setCellValue(a + b);
|
|
|
+
|
|
|
+ } 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();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //添加相册与照片的关联关系 用于编辑时重新生成pdf
|
|
|
+ List<AlbumImages> albumImages = new ArrayList<>();
|
|
|
+ albumDTO.getMargePdfUrls().forEach(f -> {
|
|
|
+ AlbumImages albumImage = new AlbumImages();
|
|
|
+ albumImage.setId(SnowFlakeUtil.getId());
|
|
|
+ albumImage.setAlbumId(album.getId());
|
|
|
+ albumImage.setImageId(f.getId());
|
|
|
+ albumImages.add(albumImage);
|
|
|
+ });
|
|
|
+ albumImagesService.saveBatch(albumImages);
|
|
|
+
|
|
|
+ return R.status(albumService.save(album));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改
|
|
|
+ */
|
|
|
+ @PostMapping("/update")
|
|
|
+ @ApiOperationSupport(order = 5)
|
|
|
+ @ApiOperation(value = "修改", notes = "传入album")
|
|
|
+ public R update(@Valid @RequestBody AlbumDTO albumDTO) {
|
|
|
+
|
|
|
+ //查询关联关系
|
|
|
+ List<ImageClassificationFile> list = albumImagesService.selectImageUrlByAlbumId(albumDTO.getId());
|
|
|
+ if (CollectionUtil.isNotEmpty(list)) {
|
|
|
+ //可能存在一条数据多张照片的情况
|
|
|
+ List<ImageClassificationFile> images = new ArrayList<>();
|
|
|
+ list.forEach(f -> {
|
|
|
+ //多个照片
|
|
|
+ if (f.getImageUrl().contains(",")) {
|
|
|
+ String[] split = f.getImageUrl().split(",");
|
|
|
+ for (String imageUrl : split) {
|
|
|
+ ImageClassificationFile file = BeanUtil.copyProperties(f, ImageClassificationFile.class);
|
|
|
+ file.setImageUrl(imageUrl);
|
|
|
+ images.add(file);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ images.add(f);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ //旧pdf地址
|
|
|
+ String imagesPdf = albumDTO.getImagesPdf();
|
|
|
+
|
|
|
+ //获取起止编码
|
|
|
+ String codes = albumDTO.getCodes();
|
|
|
+ //初始值
|
|
|
+ Integer startInt = null, endInt = null, middleInt = null;
|
|
|
+ //图片计算值 最终值
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(codes)) {
|
|
|
+ startInt = 1;
|
|
|
+ } else if (codes.contains("~")) {
|
|
|
+ String[] split = codes.split("~");
|
|
|
+ try {
|
|
|
+ startInt = Integer.valueOf(split[0]);
|
|
|
+ endInt = Integer.valueOf(split[1]);
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ throw new ServiceException("无法识别的数字");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ startInt = Integer.valueOf(codes);
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ throw new ServiceException("无法识别的数字");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ int count = startInt;
|
|
|
+
|
|
|
+ //重新生成pdf 并设置起止编号
|
|
|
+ //获取固定表格
|
|
|
+ //影像资料模板
|
|
|
+ ExcelTab excelTab = this.excelTabClient.getById("1950465427890794498");
|
|
|
+ String file_path = null;
|
|
|
+ if (SystemUtils.isWindows()) {
|
|
|
+ file_path = "C:\\pdfFiles\\";
|
|
|
+ File file = new File(file_path);
|
|
|
+ if (!file.exists()) {
|
|
|
+ file.mkdirs();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Album album = new Album();
|
|
|
+ BeanUtil.copy(albumDTO, album);
|
|
|
+ String dateValue = albumDTO.getDateValue();
|
|
|
+ String[] strings = dateValue.split("~");
|
|
|
+ album.setStartDate(strings[0]);
|
|
|
+ album.setEndDate(strings[1]);
|
|
|
+ if (SystemUtils.isLinux()) {
|
|
|
+ file_path = "/home/pdfFiles";
|
|
|
+ File file = new File(file_path);
|
|
|
+ if (!file.exists()) {
|
|
|
+ file.mkdirs();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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<ImageClassificationFile>> batchSize = CommonUtil.getBatchSize(images, 2);
|
|
|
+
|
|
|
+
|
|
|
+ for (List<ImageClassificationFile> imageClassificationFiles : batchSize) {
|
|
|
+ try {
|
|
|
+ //创建模板Workbook
|
|
|
+ modInput = CommonUtil.getOSSInputStream(excelTab.getFileUrl());
|
|
|
+ if (modInput != null) {
|
|
|
+ workbook = WorkbookFactory.create(modInput);
|
|
|
+
|
|
|
+ //一个pdf 两个图片
|
|
|
+ int i = 0;
|
|
|
+ for (ImageClassificationFile file : imageClassificationFiles) {
|
|
|
+ try {
|
|
|
+ CreationHelper helper = workbook.getCreationHelper();
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
+ Drawing<?> drawing = sheet.createDrawingPatriarch();
|
|
|
+ ClientAnchor anchor = helper.createClientAnchor();
|
|
|
+ //获取文件流
|
|
|
+ byte[] bytes = CommonUtil.InputStreamToBytes(CommonUtil.getOSSInputStream(file.getImageUrl()));
|
|
|
+ if (bytes[0] == 82 && bytes[1] == 73 && bytes[2] == 70) {
|
|
|
+ bytes = CommonUtil.webpToPngBytes(CommonUtil.getOSSInputStream(file.getImageUrl()));
|
|
|
+ }
|
|
|
+ //压缩文件大小
|
|
|
+ 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(0, 8) : new DataVO(0, 3));
|
|
|
+ //定位其它信息
|
|
|
+ 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(endInt != null && count > endInt ? "" : count + "");
|
|
|
+ // 摄影者 (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)
|
|
|
+ String a = albumDTO.getImagesName() != null ? albumDTO.getImagesName() : "";
|
|
|
+ String b = file.getTextContent() != null ? file.getTextContent() : "";
|
|
|
+ sheet.getRow(baseRow + 4).getCell(1).setCellValue(a + b);
|
|
|
+ i++;
|
|
|
+
|
|
|
+ if (endInt != null && count > endInt) {
|
|
|
+ middleInt = count - 1;
|
|
|
+ } else {
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ } 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());
|
|
|
+ //删除旧pdf
|
|
|
+ if (StringUtils.isNotBlank(imagesPdf)) {
|
|
|
+ String pdfName = imagesPdf.split("upload")[1];
|
|
|
+ this.newIOSSClient.removeFile("upload" + pdfName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (removeList.size() > 0) {
|
|
|
+ //删除本地文件
|
|
|
+ CommonUtil.removeFile(removeList);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (middleInt != null) {
|
|
|
+ album.setCodes(startInt + "~" + middleInt);
|
|
|
+ } else {
|
|
|
+ album.setCodes(startInt + "~" + (count - 1));
|
|
|
+ }
|
|
|
+ return R.status(albumService.updateById(album));
|
|
|
+ }
|
|
|
+ throw new ServiceException("相册不能为空");
|
|
|
+ }
|
|
|
|
|
|
// /**
|
|
|
// * 新增或修改
|
|
@@ -438,7 +651,7 @@ public class AlbumController extends BladeController {
|
|
|
// return R.status(albumService.saveOrUpdate(album));
|
|
|
// }
|
|
|
|
|
|
-
|
|
|
+
|
|
|
// /**
|
|
|
// * 删除
|
|
|
// */
|
|
@@ -450,13 +663,15 @@ public class AlbumController extends BladeController {
|
|
|
// }
|
|
|
|
|
|
|
|
|
+ @PostMapping("/remove")
|
|
|
+ @ApiOperationSupport(order = 7)
|
|
|
+ @ApiOperation(value = "逻辑删除", notes = "传入ids")
|
|
|
+ public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam Long id) {
|
|
|
+ //同时删除关联关系
|
|
|
+ albumImagesService.remove(Wrappers.<AlbumImages>lambdaQuery()
|
|
|
+ .eq(AlbumImages::getAlbumId, id));
|
|
|
+ return R.status(albumService.removeById(id));
|
|
|
+ }
|
|
|
|
|
|
- @PostMapping("/remove")
|
|
|
- @ApiOperationSupport(order = 7)
|
|
|
- @ApiOperation(value = "逻辑删除", notes = "传入ids")
|
|
|
- public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam Long id) {
|
|
|
- return R.status(albumService.removeById(id));
|
|
|
- }
|
|
|
|
|
|
-
|
|
|
}
|