| | |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Path; |
| | | import java.nio.file.Paths; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | | import java.util.*; |
| | | import java.util.List; |
| | |
| | | import javax.imageio.ImageIO; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import cn.hutool.core.date.DateTime; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import com.aspose.words.License; |
| | | import com.deepoove.poi.XWPFTemplate; |
| | | import com.drew.imaging.ImageMetadataReader; |
| | |
| | | |
| | | import static com.ruoyi.common.core.page.TableSupport.PAGE_NUM; |
| | | import static com.ruoyi.common.core.page.TableSupport.PAGE_SIZE; |
| | | import static com.ruoyi.framework.datasource.DynamicDataSourceContextHolder.log; |
| | | |
| | | /** |
| | | * 【文件材料综合信息】Controller |
| | |
| | | |
| | | @Autowired |
| | | private IArchiveRecordsService iArchiveRecordsService; |
| | | |
| | | /** |
| | | * 文件分隔符 |
| | | */ |
| | | private static final String FILE_DELIMETER = ","; |
| | | /** |
| | | * 判断PageNumber是否连续 |
| | | */ |
| | |
| | | @PostMapping("/exportDir") |
| | | public void exportDir(HttpServletResponse response, DocumentMaterials documentMaterials, @RequestParam(value = "ids", required = false) Long[] ids) |
| | | { |
| | | List<DocumentMaterials> list; |
| | | System.out.println(ids); |
| | | // 如果提供了ids参数,则根据ids导出指定记录 |
| | | if (ids != null && ids.length > 0) { |
| | | list = documentMaterialsService.selectDocumentMaterialsByIds(ids); |
| | | } else { |
| | | list = documentMaterialsService.selectDocumentMaterialsList(documentMaterials); |
| | | |
| | | } |
| | | // 根据visible字段筛选,只保留visible为1的记录 |
| | | List<DocumentMaterials> filteredList = list.stream() |
| | | .filter(doc -> doc.getVisible() != null && doc.getVisible() == 1 && !Objects.equals(doc.getFileStyle(), "其他材料")) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 使用AtomicLong实现序号的递增 |
| | | AtomicLong nm = new AtomicLong(1L); |
| | | // 将筛选后的DocumentMaterials转换为DocumentMaterialsVo |
| | | List<DocumentMaterialsVoSmall> list1 = filteredList.stream().map(doc -> { |
| | | DocumentMaterialsVoSmall vo = new DocumentMaterialsVoSmall(); |
| | | // 手动映射字段,使用getAndIncrement()方法获取当前值并递增 |
| | | vo.setNum(nm.getAndIncrement()); |
| | | List<DocumentMaterialsVo> dsvs = documentMaterialsService.findArchMInfo(documentMaterials.getRecordId().toString()); |
| | | |
| | | vo.setDocumentNumber(doc.getDocumentNumber()); |
| | | vo.setCreator(doc.getCreator()); |
| | | vo.setTitle(doc.getTitle()); |
| | | vo.setDate(doc.getDate()); |
| | | vo.setPageNumber(doc.getPageNumber()); |
| | | vo.setRemarks(doc.getRemarks()); |
| | | // vo.setRecordId(doc.getRecordId() != null ? doc.getRecordId().toString() : null); |
| | | // vo.setPublicity(doc.getPublicity()); |
| | | return vo; |
| | | }).collect(Collectors.toList()); |
| | | List<DocumentMaterialsVoSmall> list2 = dsvs.stream().map(res1 -> new DocumentMaterialsVoSmall(res1.getNum(), res1.getDocumentNumber(),res1.getCreator(), |
| | | res1.getTitle(), res1.getDate(), res1.getPageNumberFormatted(), res1.getRemarks())).collect(Collectors.toList()); |
| | | |
| | | // List<DocumentMaterials> list; |
| | | // System.out.println(ids); |
| | | // // 如果提供了ids参数,则根据ids导出指定记录 |
| | | // if (ids != null && ids.length > 0) { |
| | | // list = documentMaterialsService.selectDocumentMaterialsByIds(ids); |
| | | // } else { |
| | | // list = documentMaterialsService.selectDocumentMaterialsList(documentMaterials); |
| | | // |
| | | // } |
| | | // // 根据visible字段筛选,只保留visible为1的记录 |
| | | // List<DocumentMaterials> filteredList = list.stream() |
| | | // .filter(doc -> doc.getVisible() != null && doc.getVisible() == 1 && !Objects.equals(doc.getFileStyle(), "其他材料")) |
| | | // .collect(Collectors.toList()); |
| | | // |
| | | // // 使用AtomicLong实现序号的递增 |
| | | // AtomicLong nm = new AtomicLong(1L); |
| | | // // 将筛选后的DocumentMaterials转换为DocumentMaterialsVo |
| | | // List<DocumentMaterialsVoSmall> list1 = filteredList.stream().map(doc -> { |
| | | // DocumentMaterialsVoSmall vo = new DocumentMaterialsVoSmall(); |
| | | // // 手动映射字段,使用getAndIncrement()方法获取当前值并递增 |
| | | // vo.setNum(nm.getAndIncrement()); |
| | | // |
| | | // vo.setDocumentNumber(doc.getDocumentNumber()); |
| | | // vo.setCreator(doc.getCreator()); |
| | | // vo.setTitle(doc.getTitle()); |
| | | // vo.setDate(doc.getDate()); |
| | | // vo.setPageNumberFormatted(doc.getPageNumber().toString()); |
| | | // vo.setRemarks(doc.getRemarks()); |
| | | //// vo.setRecordId(doc.getRecordId() != null ? doc.getRecordId().toString() : null); |
| | | //// vo.setPublicity(doc.getPublicity()); |
| | | // return vo; |
| | | // }).collect(Collectors.toList()); |
| | | |
| | | ExcelUtil<DocumentMaterialsVoSmall> util = new ExcelUtil<DocumentMaterialsVoSmall>(DocumentMaterialsVoSmall.class); |
| | | util.exportExcel(response, list1, "卷内目录"); |
| | | util.exportExcel(response, list2, "卷内目录"); |
| | | } |
| | | |
| | | // List<DocumentMaterialsVo> dsvs = documentMaterialsService.findArchMInfo(id.toString()); |
| | |
| | | String li_person = "仇翀"; |
| | | String sh_person = "曾瑞莹"; |
| | | ArchiveRecords archiveRecords = iArchiveRecordsService.selectArchiveRecordsById(id); |
| | | if(!StringUtils.isEmpty(archiveRecords.getLiPerson())) |
| | | li_person = archiveRecords.getLiPerson(); |
| | | ArchiveProjectName tmp = new ArchiveProjectName(); |
| | | tmp.setName(archiveRecords.getProjectName()); |
| | | List<ArchiveProjectName> projectName = iArchiveProjectNameService.selectArchiveProjectNameList(tmp); |
| | | if(!projectName.isEmpty()) |
| | | { |
| | | if(StringUtils.isEmpty(projectName.get(0).getCompanyName())) |
| | | System.out.println(projectName.get(0).getCompanyName()); |
| | | if(!StringUtils.isEmpty(projectName.get(0).getCompanyName())) |
| | | compName = projectName.get(0).getCompanyName(); |
| | | if(StringUtils.isEmpty(projectName.get(0).getCreatePerson())) |
| | | li_person = projectName.get(0).getCreatePerson(); |
| | | if(!StringUtils.isEmpty(projectName.get(0).getCreatePerson())) |
| | | sh_person = projectName.get(0).getCreatePerson(); |
| | | |
| | | System.out.println(compName+"--+"+sh_person); |
| | | |
| | | } |
| | | |
| | | |
| | | System.out.println(compName+"--+"+sh_person); |
| | | // pdfGenerateService.generateFileStyleInfo(pdf09Path, aIV.getRecordId(), id); |
| | | //拿到相关数据 |
| | | List<DocumentMaterialFileStyle> dmfs = documentMaterialsService.findFileStyleInfo(Math.toIntExact(id)); |
| | |
| | | hs.put("texPages", texPages); |
| | | hs.put("volumeNumber", recordId); |
| | | hs.put("company", compName); |
| | | hs.put("liPerson", li_person); |
| | | hs.put("shPerson", sh_person); |
| | | hs.put("time", cdt); |
| | | |
| | | if (!getLicense()) { |
| | |
| | | |
| | | //导出案卷封面 |
| | | @PostMapping("/exportPageInfo/{id}/{recordId}") |
| | | public void exportPageInfo(HttpServletResponse response, @PathVariable Long id, @PathVariable String recordId) throws IOException { |
| | | public void exportPageInfo(HttpServletResponse response, @PathVariable Long id, @PathVariable String recordId) throws IOException, ParseException { |
| | | |
| | | ArchiveInfoVo aIV = iArchiveRecordsService.selectByRecordId(id); |
| | | |
| | |
| | | arsi.add(aIV); |
| | | |
| | | String recordId1 = recordId; |
| | | if(aIV!=null) |
| | | { |
| | | String date = ""; |
| | | if(arsi.get(0).getPreparationDate()!=null) { |
| | | System.out.println(arsi.get(0).getPreparationDate().toString() + "]]]]]]]]"); |
| | | |
| | | System.out.println(DateUtil.parseCST(arsi.get(0).getPreparationDate().toString())); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | DateTime dat = DateUtil.parseCST(arsi.get(0).getPreparationDate().toString()); |
| | | date = new SimpleDateFormat("yyyy-MM-dd").format(dat); |
| | | } |
| | | |
| | | |
| | | String tmp = "档号:" + |
| | | arsi.get(0).getRecordId() + |
| | | ";档案馆(室)号:" + arsi.get(0).getArchiveRoomNumber()+ |
| | | ";缩微号:" + arsi.get(0).getMicrofilmNumber()+ |
| | | ";发文号:" + arsi.get(0).getInquiryNumber()+ |
| | | ";案卷题名:" + arsi.get(0).getCaseTitle() + |
| | | ";编制日期:" + date + |
| | | ";编制单位:" + arsi.get(0).getPreparationUnit() + |
| | | ";保管期限:" + arsi.get(0).getRetentionPeriod() + |
| | | ";密级:" + arsi.get(0).getSecurityClassification(); |
| | | byte[] imgr1 = barcodeService.generateBarcodeImage(recordId1); |
| | | byte[] sedcode = pdfGenerateService.createQrCodeN(recordId1, 200, 200); |
| | | byte[] sedcode = pdfGenerateService.createQrCodeN(tmp, 210, 210); |
| | | ExcelExp e3 = new ExcelExp("案卷封面数据",arsi, ArchiveInfoVo.class); |
| | | ExcelExp e4 = new ExcelExp("案卷封面", arsi, recordId1, imgr1,sedcode, ArchiveInfoVo.class); |
| | | List<ExcelExp> mysheet1 = new ArrayList<ExcelExp>(); |
| | |
| | | |
| | | // System.out.println(bos2); |
| | | bos2.writeTo(response.getOutputStream()); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | @PostMapping("/uploads/{recordId}") |
| | | public AjaxResult uploadFiles(List<MultipartFile> files, @PathVariable Long recordId) throws Exception { |
| | | try { |
| | | // 上传文件路径 |
| | | String filePath = RuoYiConfig.getUploadPath(); |
| | | List<String> urls = new ArrayList<>(); |
| | | List<String> fileNames = new ArrayList<>(); |
| | | List<String> newFileNames = new ArrayList<>(); |
| | | List<String> originalFilenames = new ArrayList<>(); |
| | | |
| | | // 批量处理文件上传 |
| | | for (MultipartFile file : files) { |
| | | // 根据文件名称,然后修改对应数据的url |
| | | String fname = file.getOriginalFilename(); |
| | | if (StringUtils.isBlank(fname)) { |
| | | continue; |
| | | } |
| | | |
| | | // 上传并返回新文件名称 |
| | | String fileName = FileUploadUtils.upload(filePath, file); |
| | | String url = serverConfig.getUrl() + fileName; |
| | | |
| | | // 分割文件名 |
| | | String[] nams = fname.split("\\."); |
| | | if (nams.length < 2) { |
| | | continue; |
| | | } |
| | | |
| | | Long nam = Long.parseLong(nams[0]); |
| | | |
| | | // 根据页号拿到案卷的详细信息 |
| | | DocumentMaterials doc = documentMaterialsService.selectByPageNumber(nam, Math.toIntExact(recordId)); |
| | | if (doc != null) { |
| | | if (doc.getSecurityLevel() != null && doc.getSecurityLevel().equals("该页另存")) { |
| | | // 替换为了准备好的图像 |
| | | String fp = filePath + "\\glc.jpg"; |
| | | Path path = Paths.get(fp); |
| | | // 拿到图像属性 |
| | | BufferedImage bufferedImage = ImageIO.read(Files.newInputStream(path)); |
| | | int wid = bufferedImage.getWidth(); |
| | | int hei = bufferedImage.getHeight(); |
| | | double sz = Double.parseDouble(String.format("%.2f", Files.size(path) * 1.0 / 1024)); |
| | | |
| | | // 拿到图像的dpi信息 |
| | | ImageInfo info = Imaging.getImageInfo(Files.readAllBytes(path)); |
| | | int wdpi = info.getPhysicalWidthDpi(); |
| | | int hdpi = info.getPhysicalHeightDpi(); |
| | | |
| | | // 计算fileNumber |
| | | Long fileNumber = documentMaterialsService.getFiNum(nam, recordId); |
| | | // 计算sizeType |
| | | String sizeType = getPageSize(wid * hei); |
| | | |
| | | Graphics2D g2d = bufferedImage.createGraphics(); |
| | | g2d.setFont(new Font("Arial", Font.BOLD, 80)); |
| | | g2d.setColor(Color.black); |
| | | String pageNumber = doc.getPageNumber() + ""; |
| | | int fontHeight = g2d.getFontMetrics().getHeight(); |
| | | int x = bufferedImage.getWidth() - g2d.getFontMetrics().stringWidth(pageNumber) - 80; |
| | | int y = bufferedImage.getHeight() - fontHeight / 2 - 100; |
| | | g2d.drawString(pageNumber, x, y); |
| | | g2d.dispose(); |
| | | |
| | | // 将BufferedImage转换为MultipartFile |
| | | MultipartFile multipartFile = null; |
| | | ByteArrayOutputStream os = new ByteArrayOutputStream(); |
| | | ImageIO.write(bufferedImage, "jpg", os); |
| | | InputStream input = new ByteArrayInputStream(os.toByteArray()); |
| | | multipartFile = new MockMultipartFile(pageNumber, pageNumber + ".jpg", "text/plain", input); |
| | | |
| | | // 上传并返回新文件名称 |
| | | String fileName1 = FileUploadUtils.upload(filePath, multipartFile); |
| | | |
| | | // 更新数据库 |
| | | documentMaterialsService.updateByPageNumber(nam, sizeType, fileNumber, wid, hei, wdpi, hdpi, sz, fileName1, "jpg", recordId); |
| | | |
| | | urls.add(serverConfig.getUrl() + fileName1); |
| | | fileNames.add(fileName1); |
| | | newFileNames.add(FileUtils.getName(fileName1)); |
| | | originalFilenames.add(pageNumber + ".jpg"); |
| | | } else { |
| | | // 文件名称 |
| | | String pname = nams[1]; |
| | | |
| | | // 拿到图像属性 |
| | | BufferedImage bufferedImage = ImageIO.read(file.getInputStream()); |
| | | int wid = bufferedImage.getWidth(); |
| | | int hei = bufferedImage.getHeight(); |
| | | double sz = Double.parseDouble(String.format("%.2f", file.getSize() * 1.0 / 1024)); |
| | | |
| | | // 拿到图像的dpi信息 |
| | | ImageInfo info = Imaging.getImageInfo(file.getBytes()); |
| | | int wdpi = info.getPhysicalWidthDpi(); |
| | | int hdpi = info.getPhysicalHeightDpi(); |
| | | |
| | | // 计算fileNumber |
| | | Long fileNumber = documentMaterialsService.getFiNum(nam, recordId); |
| | | // 计算sizeType |
| | | String sizeType = getPageSize(wid * hei); |
| | | |
| | | // 更新数据库 |
| | | documentMaterialsService.updateByPageNumber(nam, sizeType, fileNumber, wid, hei, wdpi, hdpi, sz, fileName, pname, recordId); |
| | | |
| | | urls.add(url); |
| | | fileNames.add(fileName); |
| | | newFileNames.add(FileUtils.getName(fileName)); |
| | | originalFilenames.add(fname); |
| | | } |
| | | } |
| | | } |
| | | |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | ajax.put("urls", StringUtils.join(urls, FILE_DELIMETER)); |
| | | ajax.put("fileNames", StringUtils.join(fileNames, FILE_DELIMETER)); |
| | | ajax.put("newFileNames", StringUtils.join(newFileNames, FILE_DELIMETER)); |
| | | ajax.put("originalFilenames", StringUtils.join(originalFilenames, FILE_DELIMETER)); |
| | | return ajax; |
| | | } catch (Exception e) { |
| | | log.error("批量上传文件失败", e); |
| | | return AjaxResult.error(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |