fei
2026-01-05 6f0797731657022e9812b92fb4d78bcf56a65c1d
ruoyi-admin/src/main/java/com/ruoyi/web/controller/archive/DocumentMaterialsController.java
@@ -8,6 +8,8 @@
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;
@@ -17,6 +19,8 @@
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;
@@ -25,17 +29,20 @@
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.common.utils.file.FileUtils;
import com.ruoyi.common.utils.poi.ExcelExp;
import com.ruoyi.common.utils.poi.ExcelUtilManySheet;
import com.ruoyi.common.utils.poi.ExcelUtilManySheetSecond;
import com.ruoyi.domain.ArchiveCategory;
import com.ruoyi.domain.ArchiveProjectName;
import com.ruoyi.domain.ArchiveRecords;
import com.ruoyi.domain.DocumentMaterials;
import com.ruoyi.domain.vo.*;
import com.ruoyi.framework.config.ServerConfig;
import com.ruoyi.framework.web.domain.server.Sys;
import com.ruoyi.service.IArchiveProjectNameService;
import com.ruoyi.service.IArchiveRecordsService;
import com.ruoyi.service.IDocumentMaterialsService;
import com.ruoyi.service.impl.BarcodeService;
@@ -61,6 +68,7 @@
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
@@ -73,6 +81,8 @@
public class DocumentMaterialsController extends BaseController
{
    @Autowired
    private IArchiveProjectNameService iArchiveProjectNameService;
    @Autowired
    private BarcodeService barcodeService;
    @Autowired
    private ServerConfig serverConfig;
@@ -83,6 +93,11 @@
    @Autowired
    private IArchiveRecordsService iArchiveRecordsService;
    /**
     * 文件分隔符
     */
    private static final String FILE_DELIMETER = ",";
    /**
     * 判断PageNumber是否连续
     */
@@ -170,41 +185,47 @@
    @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());
@@ -452,6 +473,32 @@
    {
        //09-备考表.pdf
        String pdf09Path = "09-备考表.pdf";
        //根据项目名称拿到公司名称和项目负责人
        String compName = "广州盈家档案管理有限公司";
        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())
        {
            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()))
                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));
@@ -484,6 +531,9 @@
        hs.put("picPages", picPages);
        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()) {
@@ -494,9 +544,21 @@
        try {
            // 获取 Word 模板所在路径
            String filepath = "09-备考表.docx";
//            String filepath = "09-备考表.docx";
//            // 通过 XWPFTemplate 编译文件并渲染数据到模板中
//            XWPFTemplate template = XWPFTemplate.compile(filepath).render(hs
//            );
            // 获取 Word 模板所在路径
            ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
            org.springframework.core.io.Resource resource = resolver.getResource("classpath:09.docx");
//                String filepath = resource.getFile().getAbsolutePath();
//                // 通过 XWPFTemplate 编译文件并渲染数据到模板中
//                XWPFTemplate template = XWPFTemplate.compile(filepath).render(hs
//                       );
            InputStream inputStream = resource.getInputStream();
            // 通过 XWPFTemplate 编译文件并渲染数据到模板中
            XWPFTemplate template = XWPFTemplate.compile(filepath).render(hs
            XWPFTemplate template = XWPFTemplate.compile(inputStream).render(hs
            );
            String renderedDocPath = "rendered_output.docx";
@@ -530,7 +592,7 @@
        //拿到卷内目录的excel
        List<DocumentMaterialsVoSmall> list2 = dsvs.stream().map(res1 -> new DocumentMaterialsVoSmall(res1.getNum(), res1.getDocumentNumber(),res1.getCreator(),
                res1.getTitle(), res1.getDate(), res1.getPageNumber(), res1.getRemarks())).collect(Collectors.toList());
                res1.getTitle(), res1.getDate(), res1.getPageNumberFormatted(), res1.getRemarks())).collect(Collectors.toList());
        if(!dsvs.isEmpty()) {
            String recordId = dsvs.get(0).getRecordId();
            byte[] imgr = barcodeService.generateBarcodeImage(recordId);
@@ -556,7 +618,7 @@
    //导出案卷封面
    @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);
@@ -564,8 +626,31 @@
        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>();
@@ -578,8 +663,134 @@
        //  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());
        }
    }
}