fei
9 小时以前 359f1d48b1d859a23cd35a425d2cffb1e9d1c811
ruoyi-admin/src/main/java/com/ruoyi/web/controller/archive/DocumentMaterialsController.java
@@ -8,30 +8,47 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.HashMap;
import java.time.LocalDate;
import java.util.*;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import com.aspose.words.License;
import com.deepoove.poi.XWPFTemplate;
import com.drew.imaging.ImageMetadataReader;
import com.drew.metadata.Metadata;
import com.drew.metadata.exif.ExifIFD0Directory;
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.DocumentMaterialFileSmallVo;
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;
import com.ruoyi.service.impl.pdfGenerateService;
import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream;
import com.sun.xml.internal.ws.api.addressing.WSEndpointReference;
import org.apache.commons.imaging.ImageInfo;
import org.apache.commons.imaging.Imaging;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
@@ -59,12 +76,18 @@
public class DocumentMaterialsController extends BaseController
{
    @Autowired
    private IArchiveProjectNameService iArchiveProjectNameService;
    @Autowired
    private BarcodeService barcodeService;
    @Autowired
    private ServerConfig serverConfig;
    @Autowired
    private pdfGenerateService pdfGenerateService;
    @Autowired
    private IDocumentMaterialsService documentMaterialsService;
    @Autowired
    private IArchiveRecordsService iArchiveRecordsService;
    /**
     * 判断PageNumber是否连续
     */
@@ -81,7 +104,7 @@
        return AjaxResult.success(data);
    }
    /**
     * 拿到除了其它类型材料的个数
     * 拿到对应的案卷材料个数
     */
    @PreAuthorize("@ss.hasPermi('system:materials:list')")
    @GetMapping("/getFileCount/{recordId}")
@@ -90,6 +113,29 @@
        int cnt = documentMaterialsService.getFileCount(recordId);
        return AjaxResult.success(cnt);
    }
    /**
     * 判断卷内目录是否上传了附件
     */
    @PreAuthorize("@ss.hasPermi('system:materials:list')")
    @GetMapping("/judge/{recordId}")
    public AjaxResult judge(@PathVariable("recordId") Integer recordId)
    {
        Boolean cnt = documentMaterialsService.judgeInfo(recordId);
        return AjaxResult.success(cnt);
    }
    /**
     * 根据页号添加中间记录的接口
     * 例如页号1,5,7,则添加页号为2,3,4(信息与1保持一致),6(信息与5保持一致)
     */
    @PreAuthorize("@ss.hasPermi('system:materials:edit')")
    @GetMapping("/addMiddleRecords/{recordId}/{maxPageNumber}")
    public AjaxResult addMiddleRecords(@PathVariable("recordId") Long recordId,@PathVariable("maxPageNumber")  Long maxPageNumber)
    {
        return documentMaterialsService.addMiddleRecordsByPageNumbers(recordId, maxPageNumber);
    }
    /**
     * 查询【文件材料综合信息】列表
@@ -121,8 +167,52 @@
        }
        ExcelUtil<DocumentMaterials> util = new ExcelUtil<DocumentMaterials>(DocumentMaterials.class);
        util.exportExcel(response, list, "【文件材料综合信息】数据");
        util.exportExcel(response, list, "电子文件目录");
    }
    @PreAuthorize("@ss.hasPermi('system:materials:export')")
    @Log(title = "【导出卷内目录】", businessType = BusinessType.EXPORT)
    @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());
            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());
        ExcelUtil<DocumentMaterialsVoSmall> util = new ExcelUtil<DocumentMaterialsVoSmall>(DocumentMaterialsVoSmall.class);
        util.exportExcel(response, list1, "卷内目录");
    }
   // List<DocumentMaterialsVo> dsvs = documentMaterialsService.findArchMInfo(id.toString());
    /**
     * 获取【文件材料综合信息】详细信息
@@ -142,6 +232,7 @@
    @PostMapping
    public AjaxResult add(@RequestBody DocumentMaterials documentMaterials)
    {
        documentMaterials.setVisible(1);
        int res = documentMaterialsService.insertDocumentMaterials(documentMaterials);
        System.out.println(res+"][[[[[[[[[[[[[[[[[[");
        return toAjax(res);
@@ -204,15 +295,17 @@
            AjaxResult ajax = AjaxResult.success();
            //分割文件名
            String [] nams = fname.split("\\.");
            System.out.println(fname);
            Long nam = Long.parseLong(nams[0]);
            //根据页号拿到案卷的详细信息
            System.out.println("0-------------");
            System.out.println(recordId);
            System.out.println("0-------------");
            DocumentMaterials doc = documentMaterialsService.selectByPageNumber(nam, Math.toIntExact(recordId));
            if(doc==null)
                return AjaxResult.error("无对应页号,请检查清楚附件以及对应的输入!");
            else{
                if(doc.getSecurityLevel().equals("该页另存"))
                if(doc.getSecurityLevel()!=null&&doc.getSecurityLevel().equals("该页另存"))
                {
                    //替换为了准备好的图像
@@ -300,7 +393,7 @@
                    int wdpi = info.getPhysicalWidthDpi() ;
                    int hdpi = info.getPhysicalHeightDpi();
                    System.out.println("DPI: " + info.getPhysicalWidthDpi());
                    System.out.println("DPI: " + info.getPhysicalWidthDpi()+nam+"dds");
                    //计算fileNumber
                    Long fileNumber = documentMaterialsService.getFiNum(nam, recordId);
                    //计算sizeType
@@ -320,6 +413,7 @@
        }
        catch (Exception e)
        {
            System.out.println("88888888882222222222222");
            System.out.println(e);
            return AjaxResult.error(e.getMessage());
        }
@@ -340,6 +434,187 @@
        ExcelUtil<DocumentMaterialFileSmallVo> util = new ExcelUtil<>(DocumentMaterialFileSmallVo.class);
        util.exportExcel(response,list,"档案详细信息导入模板");
    }
    public  boolean getLicense() {
        boolean result = false;
        try {
            InputStream is = null;
    //导出material
            ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
            org.springframework.core.io.Resource[] resources = resolver.getResources("classpath:words.xml");
            is = resources[0].getInputStream();
            // ��Ŀ��lincense.xml��·��
            License aposeLic = new License();
            aposeLic.setLicense(is);
            result = true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
    //导出备考表
    @PostMapping("/exportBack/{id}/{recordId}")
    public void exportBackInfo(HttpServletResponse response, @PathVariable Long id, @PathVariable String recordId)
    {
        //09-备考表.pdf
        String pdf09Path = "09-备考表.pdf";
        //根据项目名称拿到公司名称和项目负责人
        String compName = "广州盈家档案管理有限公司";
        String li_person = "仇翀";
        String sh_person = "曾瑞莹";
        ArchiveRecords archiveRecords = iArchiveRecordsService.selectArchiveRecordsById(id);
        ArchiveProjectName tmp = new ArchiveProjectName();
        tmp.setName(archiveRecords.getProjectName());
        List<ArchiveProjectName> projectName = iArchiveProjectNameService.selectArchiveProjectNameList(tmp);
        if(!projectName.isEmpty())
        {
            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();
        }
        //  pdfGenerateService.generateFileStyleInfo(pdf09Path, aIV.getRecordId(), id);
        //拿到相关数据
        List<DocumentMaterialFileStyle> dmfs = documentMaterialsService.findFileStyleInfo(Math.toIntExact(id));
        LocalDate currentDate = LocalDate.now();
        String cdt = currentDate.getYear()+"年"+currentDate.getMonthValue()+"月"+currentDate.getDayOfMonth()+"日";
        HashMap<String, Object> hs = new HashMap<String, Object>();
        int allPages = 0;
        int texPages = 0;
        int picPages = 0;
        int patPages = 0;
        if(!dmfs.isEmpty())
        {
            for(DocumentMaterialFileStyle documentMaterialFileStyle:dmfs)
            {
                if(documentMaterialFileStyle.getFileStyle()!=null&&documentMaterialFileStyle.getFileStyle().equals("文字材料"))
                    texPages = documentMaterialFileStyle.getCnt();
                if(documentMaterialFileStyle.getFileStyle()!=null&&documentMaterialFileStyle.getFileStyle().equals("图样材料"))
                    patPages = documentMaterialFileStyle.getCnt();
                if(documentMaterialFileStyle.getFileStyle()!=null&&documentMaterialFileStyle.getFileStyle().equals("照片材料"))
                    picPages = documentMaterialFileStyle.getCnt();
            }
        }
        allPages = texPages + picPages + patPages;
        hs.put("pages", allPages);
        hs.put("patPages", patPages);
        hs.put("picPages", picPages);
        hs.put("texPages", texPages);
        hs.put("volumeNumber", recordId);
        hs.put("company", compName);
        hs.put("time", cdt);
        if (!getLicense()) {
            System.out.println("没有相关证书!");
        }
        try {
            // 获取 Word 模板所在路径
//            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(inputStream).render(hs
            );
            String renderedDocPath = "rendered_output.docx";
            File renderedFile = new File(renderedDocPath);
            try {
                // 将完成数据渲染的文档写出
                template.writeAndClose(new FileOutputStream(renderedFile));
            } catch (IOException e) {
                e.printStackTrace();
            }
            com.aspose.words.Document doc = new com.aspose.words.Document("rendered_output.docx");
            // 创建临时字节输出流
            ByteArrayOutputStream baobk = new ByteArrayOutputStream();
            // 将Word文档转换为PDF字节数组
            doc.save(response.getOutputStream(), com.aspose.words.SaveFormat.PDF);//ȫ��֧��DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF �໥ת��
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    //导出卷内目录
    @PostMapping("/exportJuan/{id}")
    public void exportJuanInfo(HttpServletResponse response, @PathVariable Long id) throws IOException {
        List<DocumentMaterialsVo> dsvs = documentMaterialsService.findArchMInfo(id.toString());
        //拿到卷内目录的excel
        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());
        if(!dsvs.isEmpty()) {
            String recordId = dsvs.get(0).getRecordId();
            byte[] imgr = barcodeService.generateBarcodeImage(recordId);
            ExcelExp e1 = new ExcelExp("卷内目录数据", dsvs, DocumentMaterialsVo.class);
            ExcelExp e2 = new ExcelExp("卷内数据", list2, recordId, imgr, DocumentMaterialsVoSmall.class);
            List<ExcelExp> mysheet = new ArrayList<ExcelExp>();
            mysheet.add(e1);
            mysheet.add(e2);
            ExcelUtilManySheet<List<ExcelExp>> util2 = new ExcelUtilManySheet<List<ExcelExp>>(mysheet);
          //  ZipEntry entr = new ZipEntry(fna + adir + "/" + "卷内目录" + ".xls");
            // ExcelUtil<DocumentMaterialsVo> util1 = new ExcelUtil<DocumentMaterialsVo>(DocumentMaterialsVo.class);
         //   System.out.println(dsvs);
         //  zos.putNextEntry(entr);
            ByteOutputStream bos8 = new ByteOutputStream();
            util2.exportExcelManySheet(bos8, mysheet);
            bos8.writeTo( response.getOutputStream());
        }
    }
    //导出案卷封面
    @PostMapping("/exportPageInfo/{id}/{recordId}")
    public void exportPageInfo(HttpServletResponse response, @PathVariable Long id, @PathVariable String recordId) throws IOException {
        ArchiveInfoVo aIV = iArchiveRecordsService.selectByRecordId(id);
        List<ArchiveInfoVo> arsi = new ArrayList<>();
        arsi.add(aIV);
        String recordId1 = recordId;
        byte[] imgr1 = barcodeService.generateBarcodeImage(recordId1);
        byte[] sedcode = pdfGenerateService.createQrCodeN(recordId1, 200, 200);
        ExcelExp e3 = new ExcelExp("案卷封面数据",arsi, ArchiveInfoVo.class);
        ExcelExp e4 = new ExcelExp("案卷封面",  arsi, recordId1, imgr1,sedcode, ArchiveInfoVo.class);
        List<ExcelExp> mysheet1 = new ArrayList<ExcelExp>();
        mysheet1.add(e3);
        mysheet1.add(e4);
        ByteOutputStream bos2 = new ByteOutputStream();
        ExcelUtilManySheetSecond<List<ExcelExp>> util3 = new ExcelUtilManySheetSecond<List<ExcelExp>>(mysheet1);
        util3.exportExcelManySheet(bos2, mysheet1);
        //  System.out.println(bos2);
        bos2.writeTo(response.getOutputStream());
    }
}