zero 6 months ago
parent
commit
c97b3fd5e3

+ 13 - 4
src/main/java/cn/cslg/wdc/controller/WordDiffCompareController.java

@@ -1,6 +1,7 @@
 package cn.cslg.wdc.controller;
 
 import cn.cslg.wdc.common.core.base.Constants;
+import cn.cslg.wdc.common.utils.FileUtils;
 import cn.cslg.wdc.dto.DiscrepancyIdDTO;
 import cn.cslg.wdc.dto.SelectCaseInfoDTO;
 import cn.cslg.wdc.service.CaseFileService;
@@ -9,10 +10,10 @@ import io.swagger.v3.oas.annotations.Operation;
 import lombok.RequiredArgsConstructor;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.File;
 
 @RequestMapping(Constants.API_XiaoSHI + "/wordDiffCompare")
 @RestController
@@ -36,4 +37,12 @@ public class WordDiffCompareController {
     public String selectDiscrepancy(@RequestBody DiscrepancyIdDTO vo){
         return discrepancyService.selectDiscrepancy(vo);
     }
+
+    @Operation(summary = "导出二叉树")
+    @PostMapping("/compareWord")
+    public String compareWord(@RequestParam(value = "multipartFile", required = false) MultipartFile multipartFile,
+                                @RequestParam(value = "multipartFile1", required = false) MultipartFile multipartFile1) throws Exception {
+        File file = FileUtils.multipartFileToFile(multipartFile);
+        return "";
+    }
 }

+ 15 - 0
src/main/java/cn/cslg/wdc/dto/CompareDetailWordDTO.java

@@ -0,0 +1,15 @@
+package cn.cslg.wdc.dto;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class CompareDetailWordDTO {
+
+    private List<String> fileName;
+
+    private String paragraphText;
+
+    private Integer paragraphNum;
+}

+ 23 - 0
src/main/java/cn/cslg/wdc/dto/CompareWordDTO.java

@@ -0,0 +1,23 @@
+package cn.cslg.wdc.dto;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class CompareWordDTO {
+
+    private List<CompareDetailWordDTO> list;
+    private List<CompareDetailWordDTO> list1;
+    private List<CompareDetailWordDTO> list2;
+    private List<CompareDetailWordDTO> list3;
+    private List<CompareDetailWordDTO> list4;
+
+    private Integer number;
+    private Integer number1;
+    private Integer number2;
+    private Integer number3;
+    private Integer number4;
+
+    private Integer total;
+}

+ 580 - 1
src/main/java/cn/cslg/wdc/service/DiscrepancyService.java

@@ -1,7 +1,12 @@
 package cn.cslg.wdc.service;
 
 import cn.cslg.wdc.common.core.auth.Response;
+import cn.cslg.wdc.common.utils.ExcelUtils;
+import cn.cslg.wdc.common.utils.FileUtils;
+import cn.cslg.wdc.dto.CompareDetailWordDTO;
+import cn.cslg.wdc.dto.CompareWordDTO;
 import cn.cslg.wdc.dto.DiscrepancyIdDTO;
+import cn.cslg.wdc.dto.common.SectionDiffCommandVisitor;
 import cn.cslg.wdc.entity.AssoCaseFile;
 import cn.cslg.wdc.entity.CaseFile;
 import cn.cslg.wdc.entity.Discrepancy;
@@ -15,11 +20,36 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.io.output.ByteArrayOutputStream;
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.text.diff.EditScript;
+import org.apache.commons.text.diff.StringsComparator;
+import org.apache.poi.hssf.usermodel.*;
+import org.apache.poi.hssf.util.HSSFColor;
+import org.apache.poi.ss.usermodel.FillPatternType;
+import org.apache.poi.ss.usermodel.HorizontalAlignment;
+import org.apache.poi.ss.usermodel.VerticalAlignment;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
+import org.apache.poi.xwpf.usermodel.XWPFParagraph;
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Document;
+import org.jsoup.nodes.Element;
+import org.jsoup.nodes.Node;
+import org.jsoup.select.Elements;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
 
-import java.util.List;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.*;
+import java.util.stream.Collectors;
 
 
 @Slf4j
@@ -64,4 +94,553 @@ public class DiscrepancyService extends ServiceImpl<DiscrepancyMapper, Discrepan
         infoVO.setDiscrepancyDetails(discrepancyDetails);
         return Response.success(infoVO);
     }
+
+    public void compare(String fileName, String fileName1, String fileName2, String fileName3, String fileName4) throws Exception {
+        CompareWordDTO compareWordDTO = new CompareWordDTO();
+        List<String> list = this.getWordContent(fileName);
+        List<String> list1 = this.getWordContent(fileName1);
+        List<String> list2 = this.getWordContent(fileName2);
+        List<String> list3 = this.getWordContent(fileName3);
+        List<String> list4 = this.getWordContent(fileName4);
+
+        List<String> collect = list.stream().distinct().collect(Collectors.toList());
+        List<String> collect1 = list1.stream().distinct().collect(Collectors.toList());
+        List<String> collect2 = list2.stream().distinct().collect(Collectors.toList());
+        List<String> collect3 = list3.stream().distinct().collect(Collectors.toList());
+        List<String> collect4 = list4.stream().distinct().collect(Collectors.toList());
+        System.out.println("First Text:" + StringUtils.join(collect, "").length());
+
+        List<CompareDetailWordDTO> wordDTOS = new ArrayList<>();
+        collect.forEach(i -> {
+            CompareDetailWordDTO dto = new CompareDetailWordDTO();
+            List<String> strings = new ArrayList<>();
+            strings.add(fileName.substring(36));
+            dto.setFileName(strings);
+            dto.setParagraphText(i);
+            dto.setParagraphNum(i.length());
+            wordDTOS.add(dto);
+        });
+        compareWordDTO.setList(wordDTOS);
+        compareWordDTO.setNumber(StringUtils.join(collect, "").length());
+//        List<CompareDetailWordDTO> wordDTOS1 = new ArrayList<>();
+//        collect1.removeAll(collect);
+        System.out.println("Second Text:" + StringUtils.join(collect1, "").length());
+        collect1.forEach(i -> {
+            if (collect.contains(i)) {
+                CompareDetailWordDTO wordDTO = wordDTOS.stream().filter(j -> j.getParagraphText().equals(i)).findFirst().orElse(null);
+                if (ObjectUtils.isNotEmpty(wordDTO)) {
+                    List<String> strings = wordDTO.getFileName();
+                    strings.add(fileName1.substring(36));
+                }
+            } else {
+                CompareDetailWordDTO dto = new CompareDetailWordDTO();
+                List<String> strings = new ArrayList<>();
+                strings.add(fileName1.substring(36));
+                dto.setFileName(strings);
+                dto.setParagraphText(i);
+                dto.setParagraphNum(i.length());
+                wordDTOS.add(dto);
+            }
+        });
+//        compareWordDTO.setList1(wordDTOS1);
+        compareWordDTO.setNumber1(StringUtils.join(collect1, "").length());
+//        List<CompareDetailWordDTO> wordDTOS2 = new ArrayList<>();
+//        collect2.removeAll(collect);
+//        collect2.removeAll(collect1);
+        collect2.forEach(i -> {
+            if (collect.contains(i) || collect1.contains(i)) {
+                CompareDetailWordDTO wordDTO = wordDTOS.stream().filter(j -> j.getParagraphText().equals(i)).findFirst().orElse(null);
+                if (ObjectUtils.isNotEmpty(wordDTO)) {
+                    List<String> strings = wordDTO.getFileName();
+                    strings.add(fileName2.substring(36));
+                }
+            } else {
+                CompareDetailWordDTO dto = new CompareDetailWordDTO();
+                List<String> strings = new ArrayList<>();
+                strings.add(fileName2.substring(36));
+                dto.setFileName(strings);
+                dto.setParagraphText(i);
+                dto.setParagraphNum(i.length());
+                wordDTOS.add(dto);
+            }
+        });
+//        compareWordDTO.setList2(wordDTOS2);
+        compareWordDTO.setNumber2(StringUtils.join(collect2, "").length());
+//        List<CompareDetailWordDTO> wordDTOS3 = new ArrayList<>();
+//        collect3.removeAll(collect);
+//        collect3.removeAll(collect1);
+//        collect3.removeAll(collect2);
+        collect3.forEach(i -> {
+            if (collect.contains(i) || collect1.contains(i) || collect2.contains(i)) {
+                CompareDetailWordDTO wordDTO = wordDTOS.stream().filter(j -> j.getParagraphText().equals(i)).findFirst().orElse(null);
+                if (ObjectUtils.isNotEmpty(wordDTO)) {
+                    List<String> strings = wordDTO.getFileName();
+                    strings.add(fileName3.substring(36));
+                }
+            } else {
+                CompareDetailWordDTO dto = new CompareDetailWordDTO();
+                List<String> strings = new ArrayList<>();
+                strings.add(fileName3.substring(36));
+                dto.setFileName(strings);
+                dto.setParagraphText(i);
+                dto.setParagraphNum(i.length());
+                wordDTOS.add(dto);
+            }
+        });
+//        compareWordDTO.setList3(wordDTOS3);
+        compareWordDTO.setNumber3(StringUtils.join(collect3, "").length());
+//        List<CompareDetailWordDTO> wordDTOS4 = new ArrayList<>();
+//        collect4.removeAll(collect);
+//        collect4.removeAll(collect1);
+//        collect4.removeAll(collect2);
+//        collect4.removeAll(collect3);
+        collect4.forEach(i -> {
+            if (collect.contains(i) || collect1.contains(i) || collect2.contains(i) || collect3.contains(i)) {
+                CompareDetailWordDTO wordDTO = wordDTOS.stream().filter(j -> j.getParagraphText().equals(i)).findFirst().orElse(null);
+                if (ObjectUtils.isNotEmpty(wordDTO)) {
+                    List<String> strings = wordDTO.getFileName();
+                    strings.add(fileName4.substring(36));
+                }
+            } else {
+                CompareDetailWordDTO dto = new CompareDetailWordDTO();
+                List<String> strings = new ArrayList<>();
+                strings.add(fileName4.substring(36));
+                dto.setFileName(strings);
+                dto.setParagraphText(i);
+                dto.setParagraphNum(i.length());
+                wordDTOS.add(dto);
+            }
+        });
+//        compareWordDTO.setList4(wordDTOS4);
+        compareWordDTO.setNumber4(StringUtils.join(collect4, "").length());
+        int sum = this.getNumber(collect) + this.getNumber(collect1)
+                + this.getNumber(collect2) + this.getNumber(collect3) + this.getNumber(collect4);
+        compareWordDTO.setList(wordDTOS);
+        compareWordDTO.setTotal(sum);
+        System.out.println("Total Text:" + sum);
+        this.loadExport5(compareWordDTO);
+
+//        System.out.println(compareWordDTO);
+//        this.loadExport(compareWordDTO,"第一篇翻译汇总");
+//        this.loadExport1(compareWordDTO,"第二篇翻译汇总");
+//        this.loadExport2(compareWordDTO,"第三篇翻译汇总");
+//        this.loadExport3(compareWordDTO,"第四篇翻译汇总");
+//        this.loadExport4(compareWordDTO,"第五篇翻译汇总");
+    }
+
+    public List<String> getWordContent(String fileName) throws IOException {
+        List<String> list = new ArrayList<>();
+        XWPFDocument document = new XWPFDocument(new FileInputStream(fileName));
+        List<XWPFParagraph> paragraphs = document.getParagraphs();
+        for (XWPFParagraph paragraph : paragraphs) {
+            final String s = paragraph.getText().trim();
+            if (StringUtils.isNotEmpty(s)) {
+                list.add(s);
+            }
+        }
+        return list;
+    }
+
+    public Integer getNumber(List<String> list) {
+        int sum = 0;
+        for (String s : list) {
+            int length = s.length();
+            sum += length;
+        }
+        return sum;
+    }
+
+    public void loadExport5(CompareWordDTO vo) throws Exception {
+        try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+            List<String> headers = Arrays.asList("文件内容", "翻译总数", "第一篇翻译数量","第二篇翻译数量","第三篇翻译数量","第四篇翻译数量","第五篇翻译数量",
+                    "段落数量","出现过的文档");
+            HSSFWorkbook hssfWorkbook = new HSSFWorkbook();//新建工作簿
+            HSSFSheet sheet = hssfWorkbook.createSheet();//新建sheet页
+            sheet.setDefaultColumnWidth(30);
+            HSSFRow headerRow = sheet.createRow(0);//新建标头行
+            headerRow.setHeight((short) 500);
+            HSSFCellStyle headerCellStyle = hssfWorkbook.createCellStyle();//新建标头行格式
+            HSSFCellStyle commonCellStyle = hssfWorkbook.createCellStyle();//新建普通行格式
+            for (int i = 0; i < headers.size(); i++) {//遍历设置标头
+                HSSFCell cell = headerRow.createCell(i);
+                ExcelUtils.setExcelCellStyle(headerCellStyle);
+                headerCellStyle.setAlignment(HorizontalAlignment.CENTER);
+                headerCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
+                headerCellStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.SKY_BLUE.getIndex());
+                headerCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+                headerCellStyle.setWrapText(true);
+                cell.setCellStyle(headerCellStyle);
+                cell.setCellValue(headers.get(i));
+            }
+            List<CompareDetailWordDTO> list = vo.getList();
+            for (int i = 0; i < list.size(); i++) {
+                CompareDetailWordDTO wordDTO = list.get(i);
+                HSSFRow row = sheet.createRow(i + 1);//新建一普通行
+                row.setHeight((short) 1000);
+
+                HSSFCell cell = row.createCell(0);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell.setCellStyle(commonCellStyle);
+                cell.setCellValue(wordDTO.getParagraphText());
+                HSSFCell cell1 = row.createCell(1);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell1.setCellStyle(commonCellStyle);
+                cell1.setCellValue(vo.getTotal());
+                HSSFCell cell2 = row.createCell(2);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell2.setCellStyle(commonCellStyle);
+                cell2.setCellValue(vo.getNumber());
+                HSSFCell cell3 = row.createCell(3);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell3.setCellStyle(commonCellStyle);
+                cell3.setCellValue(vo.getNumber1());
+                HSSFCell cell4 = row.createCell(4);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell4.setCellStyle(commonCellStyle);
+                cell4.setCellValue(vo.getNumber2());
+                HSSFCell cell5 = row.createCell(5);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell5.setCellStyle(commonCellStyle);
+                cell5.setCellValue(vo.getNumber3());
+                HSSFCell cell6 = row.createCell(6);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell6.setCellStyle(commonCellStyle);
+                cell6.setCellValue(vo.getNumber4());
+                HSSFCell cell7 = row.createCell(7);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell7.setCellStyle(commonCellStyle);
+                cell7.setCellValue(wordDTO.getParagraphNum());
+                HSSFCell cell8 = row.createCell(8);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell8.setCellStyle(commonCellStyle);
+                cell8.setCellValue(StringUtils.join(wordDTO.getFileName(), "\n"));
+            }
+            hssfWorkbook.write(out);
+            byte[] bytes = out.toByteArray();
+            FileUtils.getFileByBytes(bytes, "翻译汇总文档", ".xlsx");
+        } catch (FileNotFoundException e) {
+            throw new FileNotFoundException();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    public void loadExport(CompareWordDTO vo, String name) throws Exception {
+        try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+            List<String> headers = Arrays.asList("翻译总数", "翻译数量", "文件名称", "文件内容");
+            HSSFWorkbook hssfWorkbook = new HSSFWorkbook();//新建工作簿
+            HSSFSheet sheet = hssfWorkbook.createSheet();//新建sheet页
+            sheet.setDefaultColumnWidth(30);
+            HSSFRow headerRow = sheet.createRow(0);//新建标头行
+            headerRow.setHeight((short) 500);
+            HSSFCellStyle headerCellStyle = hssfWorkbook.createCellStyle();//新建标头行格式
+            HSSFCellStyle commonCellStyle = hssfWorkbook.createCellStyle();//新建普通行格式
+            for (int i = 0; i < headers.size(); i++) {//遍历设置标头
+                HSSFCell cell = headerRow.createCell(i);
+                ExcelUtils.setExcelCellStyle(headerCellStyle);
+                headerCellStyle.setAlignment(HorizontalAlignment.CENTER);
+                headerCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
+                headerCellStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.SKY_BLUE.getIndex());
+                headerCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+                headerCellStyle.setWrapText(true);
+                cell.setCellStyle(headerCellStyle);
+                cell.setCellValue(headers.get(i));
+            }
+            List<String> list = vo.getList().stream().map(CompareDetailWordDTO::getParagraphText).collect(Collectors.toList());
+            for (int i = 0; i < list.size(); i++) {
+                String content = list.get(i);
+                HSSFRow row = sheet.createRow(i + 1);//新建一普通行
+                row.setHeight((short) 1000);
+                HSSFCell cell = row.createCell(0);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell.setCellStyle(commonCellStyle);
+                cell.setCellValue(vo.getTotal());
+                HSSFCell cell1 = row.createCell(1);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell1.setCellStyle(commonCellStyle);
+                cell1.setCellValue(vo.getNumber());
+                HSSFCell cell2 = row.createCell(2);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell2.setCellStyle(commonCellStyle);
+                cell2.setCellValue(vo.getNumber1());
+                HSSFCell cell3 = row.createCell(3);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell3.setCellStyle(commonCellStyle);
+                cell3.setCellValue(content);
+            }
+            hssfWorkbook.write(out);
+            byte[] bytes = out.toByteArray();
+            FileUtils.getFileByBytes(bytes, name, ".xlsx");
+        } catch (FileNotFoundException e) {
+            throw new FileNotFoundException();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+    public void loadExport1(CompareWordDTO vo, String name) throws Exception {
+        try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+            List<String> headers = Arrays.asList("翻译总数", "翻译数量", "文件名称", "文件内容");
+            HSSFWorkbook hssfWorkbook = new HSSFWorkbook();//新建工作簿
+            HSSFSheet sheet = hssfWorkbook.createSheet();//新建sheet页
+            sheet.setDefaultColumnWidth(30);
+            HSSFRow headerRow = sheet.createRow(0);//新建标头行
+            headerRow.setHeight((short) 500);
+            HSSFCellStyle headerCellStyle = hssfWorkbook.createCellStyle();//新建标头行格式
+            HSSFCellStyle commonCellStyle = hssfWorkbook.createCellStyle();//新建普通行格式
+            for (int i = 0; i < headers.size(); i++) {//遍历设置标头
+                HSSFCell cell = headerRow.createCell(i);
+                ExcelUtils.setExcelCellStyle(headerCellStyle);
+                headerCellStyle.setAlignment(HorizontalAlignment.CENTER);
+                headerCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
+                headerCellStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.SKY_BLUE.getIndex());
+                headerCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+                headerCellStyle.setWrapText(true);
+                cell.setCellStyle(headerCellStyle);
+                cell.setCellValue(headers.get(i));
+            }
+            List<String> list = vo.getList1().stream().map(CompareDetailWordDTO::getParagraphText).collect(Collectors.toList());
+            for (int i = 0; i < list.size(); i++) {
+                String content = list.get(i);
+                HSSFRow row = sheet.createRow(i + 1);//新建一普通行
+                row.setHeight((short) 1000);
+                HSSFCell cell = row.createCell(0);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell.setCellStyle(commonCellStyle);
+                cell.setCellValue(vo.getTotal());
+                HSSFCell cell1 = row.createCell(1);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell1.setCellStyle(commonCellStyle);
+                cell1.setCellValue(vo.getNumber1());
+                HSSFCell cell2 = row.createCell(2);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell2.setCellStyle(commonCellStyle);
+                cell2.setCellValue(vo.getNumber1());
+                HSSFCell cell3 = row.createCell(3);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell3.setCellStyle(commonCellStyle);
+                cell3.setCellValue(content);
+            }
+            hssfWorkbook.write(out);
+            byte[] bytes = out.toByteArray();
+            FileUtils.getFileByBytes(bytes, name, ".xlsx");
+        } catch (FileNotFoundException e) {
+            throw new FileNotFoundException();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+    public void loadExport2(CompareWordDTO vo, String name) throws Exception {
+        try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+            List<String> headers = Arrays.asList("翻译总数", "翻译数量", "文件名称", "文件内容");
+            HSSFWorkbook hssfWorkbook = new HSSFWorkbook();//新建工作簿
+            HSSFSheet sheet = hssfWorkbook.createSheet();//新建sheet页
+            sheet.setDefaultColumnWidth(30);
+            HSSFRow headerRow = sheet.createRow(0);//新建标头行
+            headerRow.setHeight((short) 500);
+            HSSFCellStyle headerCellStyle = hssfWorkbook.createCellStyle();//新建标头行格式
+            HSSFCellStyle commonCellStyle = hssfWorkbook.createCellStyle();//新建普通行格式
+            for (int i = 0; i < headers.size(); i++) {//遍历设置标头
+                HSSFCell cell = headerRow.createCell(i);
+                ExcelUtils.setExcelCellStyle(headerCellStyle);
+                headerCellStyle.setAlignment(HorizontalAlignment.CENTER);
+                headerCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
+                headerCellStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.SKY_BLUE.getIndex());
+                headerCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+                headerCellStyle.setWrapText(true);
+                cell.setCellStyle(headerCellStyle);
+                cell.setCellValue(headers.get(i));
+            }
+            List<String> list = vo.getList2().stream().map(CompareDetailWordDTO::getParagraphText).collect(Collectors.toList());
+            for (int i = 0; i < list.size(); i++) {
+                String content = list.get(i);
+                HSSFRow row = sheet.createRow(i + 1);//新建一普通行
+                row.setHeight((short) 1000);
+                HSSFCell cell = row.createCell(0);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell.setCellStyle(commonCellStyle);
+                cell.setCellValue(vo.getTotal());
+                HSSFCell cell1 = row.createCell(1);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell1.setCellStyle(commonCellStyle);
+                cell1.setCellValue(vo.getNumber2());
+                HSSFCell cell2 = row.createCell(2);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell2.setCellStyle(commonCellStyle);
+                cell2.setCellValue(vo.getNumber1());
+                HSSFCell cell3 = row.createCell(3);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell3.setCellStyle(commonCellStyle);
+                cell3.setCellValue(content);
+            }
+            hssfWorkbook.write(out);
+            byte[] bytes = out.toByteArray();
+            FileUtils.getFileByBytes(bytes, name, ".xlsx");
+        } catch (FileNotFoundException e) {
+            throw new FileNotFoundException();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+    public void loadExport3(CompareWordDTO vo, String name) throws Exception {
+        try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+            List<String> headers = Arrays.asList("翻译总数", "翻译数量", "文件名称", "文件内容");
+            HSSFWorkbook hssfWorkbook = new HSSFWorkbook();//新建工作簿
+            HSSFSheet sheet = hssfWorkbook.createSheet();//新建sheet页
+            sheet.setDefaultColumnWidth(30);
+            HSSFRow headerRow = sheet.createRow(0);//新建标头行
+            headerRow.setHeight((short) 500);
+            HSSFCellStyle headerCellStyle = hssfWorkbook.createCellStyle();//新建标头行格式
+            HSSFCellStyle commonCellStyle = hssfWorkbook.createCellStyle();//新建普通行格式
+            for (int i = 0; i < headers.size(); i++) {//遍历设置标头
+                HSSFCell cell = headerRow.createCell(i);
+                ExcelUtils.setExcelCellStyle(headerCellStyle);
+                headerCellStyle.setAlignment(HorizontalAlignment.CENTER);
+                headerCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
+                headerCellStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.SKY_BLUE.getIndex());
+                headerCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+                headerCellStyle.setWrapText(true);
+                cell.setCellStyle(headerCellStyle);
+                cell.setCellValue(headers.get(i));
+            }
+            List<String> list = vo.getList3().stream().map(CompareDetailWordDTO::getParagraphText).collect(Collectors.toList());
+            for (int i = 0; i < list.size(); i++) {
+                String content = list.get(i);
+                HSSFRow row = sheet.createRow(i + 1);//新建一普通行
+                row.setHeight((short) 1000);
+                HSSFCell cell = row.createCell(0);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell.setCellStyle(commonCellStyle);
+                cell.setCellValue(vo.getTotal());
+                HSSFCell cell1 = row.createCell(1);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell1.setCellStyle(commonCellStyle);
+                cell1.setCellValue(vo.getNumber3());
+                HSSFCell cell2 = row.createCell(2);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell2.setCellStyle(commonCellStyle);
+                cell2.setCellValue(vo.getNumber1());
+                HSSFCell cell3 = row.createCell(3);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell3.setCellStyle(commonCellStyle);
+                cell3.setCellValue(content);
+            }
+            hssfWorkbook.write(out);
+            byte[] bytes = out.toByteArray();
+            FileUtils.getFileByBytes(bytes, name, ".xlsx");
+        } catch (FileNotFoundException e) {
+            throw new FileNotFoundException();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+    public void loadExport4(CompareWordDTO vo, String name) throws Exception {
+        try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+            List<String> headers = Arrays.asList("翻译总数", "翻译数量", "文件名称", "文件内容");
+            HSSFWorkbook hssfWorkbook = new HSSFWorkbook();//新建工作簿
+            HSSFSheet sheet = hssfWorkbook.createSheet();//新建sheet页
+            sheet.setDefaultColumnWidth(30);
+            HSSFRow headerRow = sheet.createRow(0);//新建标头行
+            headerRow.setHeight((short) 500);
+            HSSFCellStyle headerCellStyle = hssfWorkbook.createCellStyle();//新建标头行格式
+            HSSFCellStyle commonCellStyle = hssfWorkbook.createCellStyle();//新建普通行格式
+            for (int i = 0; i < headers.size(); i++) {//遍历设置标头
+                HSSFCell cell = headerRow.createCell(i);
+                ExcelUtils.setExcelCellStyle(headerCellStyle);
+                headerCellStyle.setAlignment(HorizontalAlignment.CENTER);
+                headerCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
+                headerCellStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.SKY_BLUE.getIndex());
+                headerCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+                headerCellStyle.setWrapText(true);
+                cell.setCellStyle(headerCellStyle);
+                cell.setCellValue(headers.get(i));
+            }
+            List<String> list = vo.getList4().stream().map(CompareDetailWordDTO::getParagraphText).collect(Collectors.toList());
+            for (int i = 0; i < list.size(); i++) {
+                String content = list.get(i);
+                HSSFRow row = sheet.createRow(i + 1);//新建一普通行
+                row.setHeight((short) 1000);
+                HSSFCell cell = row.createCell(0);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell.setCellStyle(commonCellStyle);
+                cell.setCellValue(vo.getTotal());
+                HSSFCell cell1 = row.createCell(1);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell1.setCellStyle(commonCellStyle);
+                cell1.setCellValue(vo.getNumber4());
+                HSSFCell cell2 = row.createCell(2);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell2.setCellStyle(commonCellStyle);
+                cell2.setCellValue(vo.getNumber1());
+                HSSFCell cell3 = row.createCell(3);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell3.setCellStyle(commonCellStyle);
+                cell3.setCellValue(content);
+            }
+            hssfWorkbook.write(out);
+            byte[] bytes = out.toByteArray();
+            FileUtils.getFileByBytes(bytes, name, ".xlsx");
+        } catch (FileNotFoundException e) {
+            throw new FileNotFoundException();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
 }

+ 17 - 0
src/test/java/cn/cslg/wdc/WordDiffCompareTest.java

@@ -10,6 +10,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
 
+import java.io.IOException;
+
 @SpringBootTest
 @RunWith(SpringRunner.class)
 public class WordDiffCompareTest {
@@ -43,4 +45,19 @@ public class WordDiffCompareTest {
         String info = discrepancyService.selectDiscrepancy(vo);
         System.out.println(info);
     }
+
+    @Test
+    public void compare() throws Exception {
+        String path = "F:\\file\\word对比\\5件-美国发明PCT需删除重复部分的字数\\20230175WO4-PCT新申请原文-(67310字).docx";
+        String path1 = "F:\\file\\word对比\\5件-美国发明PCT需删除重复部分的字数\\20230177WO4-PCT新申请原文-(31692字).docx";
+        String path2 = "F:\\file\\word对比\\5件-美国发明PCT需删除重复部分的字数\\20230181WO4-PCT新申请原文 -(123096字).docx";
+        String path3 = "F:\\file\\word对比\\5件-美国发明PCT需删除重复部分的字数\\20230183WO4-PCT新申请新增内容后文本-(共51812字).docx";
+        String path4 = "F:\\file\\word对比\\5件-美国发明PCT需删除重复部分的字数\\20240006WO4-在申请PCT递交文本-含新增内容-(50294字).docx";
+//        discrepancyService.compare(path, path1, path2, path3, path4);
+        String s = "本申请要求于2023年04月27日提交国际专利局、申请号为PCT/CN2023/091116,发明名称为“一种用于液体中的行走装置以及泳池清洁机器人”的国际专利申请的优先权,其全部内容通过引用结合在本申请中;";
+        final String trim = s.trim();
+        final int length = trim.length();
+        System.out.println(length);
+    }
+
 }