| | |
| | | import com.itextpdf.text.pdf.PdfWriter; |
| | | import com.ruoyi.common.config.RuoYiConfig; |
| | | import com.ruoyi.common.utils.file.FileUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelExp; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.common.utils.poi.ExcelUtilManySheet; |
| | | import com.ruoyi.common.utils.poi.ExcelUtilManySheetSecond; |
| | | import com.ruoyi.common.utils.poi.*; |
| | | import com.ruoyi.domain.ArchiveRecords; |
| | | import com.ruoyi.domain.DocumentMaterials; |
| | | import com.ruoyi.domain.vo.*; |
| | |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.stream.Collectors; |
| | | import java.util.zip.ZipEntry; |
| | | import java.util.zip.ZipFile; |
| | |
| | | @RestController |
| | | @RequestMapping("/system/archiveAllExport") |
| | | public class archiveAllExportController { |
| | | // 存储当天导出序号的Map,键为日期(yyyyMMdd),值为当前序号 |
| | | private static Map<String, Integer> dailySequenceMap = new ConcurrentHashMap<>(); |
| | | |
| | | @Autowired |
| | | private pdfGenerateService pdfGenerateService; |
| | |
| | | |
| | | @Autowired |
| | | private IArchiveRecordsService iArchiveRecordsService; |
| | | |
| | | // 用于生成当天导出序号的方法 |
| | | private String generateDailySequence(String date) { |
| | | // 使用synchronized确保线程安全 |
| | | synchronized (dailySequenceMap) { |
| | | // 获取当前日期的序号,如果不存在则初始化为0 |
| | | int sequence = dailySequenceMap.getOrDefault(date, 0); |
| | | // 序号递增 |
| | | sequence++; |
| | | // 更新Map中的序号 |
| | | dailySequenceMap.put(date, sequence); |
| | | // 格式化为三位字符串,不足三位补前导零 |
| | | return String.format("%03d", sequence); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | |
| | | @PostMapping("/exportChooseArchive/{ids}") |
| | | public void exportChooseArchive(HttpServletResponse response, @PathVariable Long[] ids)throws Exception |
| | | { |
| | | //计算文件的大小 |
| | | Double siz = 0.0; |
| | | for(int i = 0; i < ids.length; i++) { |
| | | |
| | | // 获取文件的保存位置,读取数据库, |
| | | DocumentMaterials documentMaterials = new DocumentMaterials(); |
| | | documentMaterials.setRecordId(ids[i]); |
| | | List<DocumentMaterialsVoLarge> docs = documentMaterialsService.selectDocumentMaterialsAllByRecordId(ids[i]); |
| | | System.out.println(docs.size()+"----009"); |
| | | for (DocumentMaterialsVoLarge dc : docs) { |
| | | if(dc!=null) |
| | | siz += dc.getFileSize()!=null?dc.getFileSize():0; |
| | | } |
| | | } |
| | | System.out.println(siz/1000); |
| | | //判断是否大于4G,是的话,直接抛出异常 |
| | | long maxSize = 4L * 1024 * 1024 * 1024; // 4GB in bytes |
| | | if (siz > maxSize) { |
| | | throw new RuntimeException("文件总大小超过4GB,无法导出"); |
| | | } |
| | | System.out.println("092939932"); |
| | | String zipFileName ="test" +".zip"; |
| | | //生成压缩包存储地址(最后会删掉) |
| | |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd"); |
| | | String formattedDate = date.format(formatter); |
| | | System.out.println(formattedDate); |
| | | String fna = "GH"+20250908+"/"; |
| | | |
| | | // 生成当天导出序号 |
| | | String sequence = generateDailySequence(formattedDate); |
| | | String fna = "GH" + formattedDate + sequence + "/"; |
| | | zos.putNextEntry(new ZipEntry(fna)); |
| | | |
| | | |
| | |
| | | archiveRecords.setIds(ids); |
| | | List<ArchiveRecords> lis = iArchiveRecordsService.selectArchiveRecordsList(archiveRecords); |
| | | //案卷目录导出 |
| | | ZipEntry entry = new ZipEntry("案卷目录" + ".xls"); |
| | | ZipEntry entry = new ZipEntry(fna + "案卷目录" + ".xls"); |
| | | ExcelUtil<ArchiveRecords> util = new ExcelUtil<ArchiveRecords>(ArchiveRecords.class); |
| | | |
| | | zos.putNextEntry(entry); |
| | |
| | | //移交清单 |
| | | List<ArchiveRecordSmall> lrs = iArchiveRecordsService.findByIds(archiveRecords); |
| | | System.out.println(lrs); |
| | | ZipEntry entry1 = new ZipEntry("移交清单" + ".xls"); |
| | | System.out.println("99999999990000"); |
| | | ZipEntry entry1 = new ZipEntry(fna + "移交清单" + ".xls"); |
| | | ExcelUtil<ArchiveRecordSmall> util1 = new ExcelUtil<ArchiveRecordSmall>(ArchiveRecordSmall.class); |
| | | |
| | | zos.putNextEntry(entry1); |
| | | ByteOutputStream bos1 = new ByteOutputStream(); |
| | | util1.byteOutputStreamExcel(bos1, lrs,"移交清单", ""); |
| | | bos1.writeTo(zos); |
| | | for(int i = 0; i < ids.length; i++) { |
| | | |
| | | |
| | | ExcelExp e6 = new ExcelExp("移交清单",lrs, ArchiveRecordSmall.class); |
| | | // ExcelExp e4 = new ExcelExp("案卷封面", arsi, recordId1, imgr1,sedcode, ArchiveInfoVo.class); |
| | | List<ExcelExp> mysheet6 = new ArrayList<ExcelExp>(); |
| | | mysheet6.add(e6); |
| | | // mysheet1.add(e4); |
| | | ByteOutputStream bos6 = new ByteOutputStream(); |
| | | ExcelUtilManySheetThird<List<ExcelExp>> util6 = new ExcelUtilManySheetThird<List<ExcelExp>>(mysheet6); |
| | | |
| | | util6.exportExcelManySheet(bos6, mysheet6); |
| | | |
| | | // System.out.println(bos2); |
| | | zos.putNextEntry(entry1); |
| | | // ByteOutputStream bos1 = new ByteOutputStream(); |
| | | // util6.byteOutputStreamExcel(bos1, lrs,"移交清单", ""); |
| | | bos6.writeTo(zos); |
| | | |
| | | |
| | | |
| | | |
| | | for(int i = 0; i < ids.length; i++) { |
| | | // 获取文件的保存位置,读取数据库, |
| | | DocumentMaterials documentMaterials = new DocumentMaterials(); |
| | | documentMaterials.setRecordId(ids[i]); |
| | |
| | | ArchiveInfoVo aIV = iArchiveRecordsService.selectByRecordId(ids[i]); |
| | | |
| | | String adir = aIV.getInquiryNumber() + " " + aIV.getRecordId(); |
| | | System.out.println(fna+adir); |
| | | System.out.println(fna + adir); |
| | | zos.putNextEntry(new ZipEntry(fna + adir + "/")); |
| | | |
| | | //在里面添加文件 |
| | |
| | | zos.putNextEntry(entry5); |
| | | ByteOutputStream bos5 = new ByteOutputStream(); |
| | | util5.byteOutputStreamExcel(bos5, docs,"电子文件目录", ""); |
| | | bos.writeTo(zos); |
| | | bos5.writeTo(zos); |
| | | |
| | | //拿到卷内目录的excel |
| | | List<DocumentMaterialsVoSmall> list2 = dsvs.stream().map(res1 -> new DocumentMaterialsVoSmall(res1.getNum(), res1.getDocumentNumber(),res1.getCreator(), |
| | |
| | | // ExcelUtil<DocumentMaterialsVo> util1 = new ExcelUtil<DocumentMaterialsVo>(DocumentMaterialsVo.class); |
| | | System.out.println(dsvs); |
| | | zos.putNextEntry(entr); |
| | | ByteOutputStream bos6 = new ByteOutputStream(); |
| | | ByteOutputStream bos8 = new ByteOutputStream(); |
| | | |
| | | util2.exportExcelManySheet(bos6, mysheet); |
| | | |
| | | // util1.byteOutputStreamExcel(bos1, dsvs,"Date List", ""); |
| | | bos6.writeTo(zos); |
| | | bos8.writeTo(zos); |
| | | } |
| | | //把excel转为pdf |
| | | |
| | |
| | | in.close(); |
| | | } |
| | | } |
| | | System.out.println(file.getName()); |
| | | writeFileToRes(response, file.getName(), file); |
| | | |
| | | //删除压缩包 |
| | | // if(file.exists()){ |
| | | // file.delete(); |
| | | // } |
| | | |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | System.out.println(file.getName()); |
| | | System.out.println(file.getTotalSpace()); |
| | | // file. |
| | | writeFileToRes(response, file.getName(), file); |
| | | |
| | | } |
| | | |
| | |
| | | |
| | | //.selectDocumentMaterialsList(documentMaterials); |
| | | List<DocumentMaterialsVo> dsvs = documentMaterialsService.findArchMInfo(id.toString()); |
| | | if(dsvs==null||dsvs.isEmpty()) |
| | | { |
| | | throw new RuntimeException("电子文件信息没有上传,请补充!"); |
| | | } |
| | | ArchiveInfoVo aIV = iArchiveRecordsService.selectByRecordId(id); |
| | | |
| | | System.out.println(dsvs.size()); |
| | | List<String> paths = new ArrayList<>(); |
| | | // System.out.println(docs); |
| | | if (docs.size() == 1) { // 直接下载 |
| | |
| | | |
| | | String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1); |
| | | String filePath = RuoYiConfig.getDownloadPath() + fileName; |
| | | |
| | | |
| | | if(file.exists()) |
| | | System.out.println("322329323232323"); |
| | | System.out.println(filePath+"0009999999999"); |
| | | response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); |
| | | FileUtils.setAttachmentResponseHeader(response, realFileName); |
| | | FileUtils.writeBytes(filePath, response.getOutputStream()); |