diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/ChineseNumberFilter.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/ChineseNumberFilter.java new file mode 100644 index 0000000..392c30c --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/ChineseNumberFilter.java @@ -0,0 +1,224 @@ +package com.ruoyi.web.controller.system; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.Scanner; +import java.util.ArrayList; +import java.util.List; + +public class ChineseNumberFilter { + + // 中文数字字符集 + private static final String[] CHINESE_DIGITS = { + "零", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十", + "百", "千", "万", "亿", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖", "拾" + }; + + // 阿拉伯数字正则表达式 + private static final Pattern ARABIC_DIGITS_PATTERN = Pattern.compile("[0-9]+"); + + // 中文数字正则表达式 + private static final Pattern CHINESE_DIGITS_PATTERN; + + static { + // 构建中文数字正则表达式 + StringBuilder chinesePatternBuilder = new StringBuilder(); + for (String digit : CHINESE_DIGITS) { + chinesePatternBuilder.append(Pattern.quote(digit)).append("|"); + } + String chinesePattern = chinesePatternBuilder.substring(0, chinesePatternBuilder.length() - 1); + CHINESE_DIGITS_PATTERN = Pattern.compile("(" + chinesePattern + ")+"); + } + + /** + * 过滤标题中的中文数字和阿拉伯数字 + * @param title 原始标题 + * @return 过滤后的标题 + */ + public static String filterNumbers(String title) { + if (title == null || title.isEmpty()) { + return title; + } + + // 移除阿拉伯数字 + String result = removeArabicDigits(title); + + // 移除中文数字 + result = removeChineseDigits(result); + + return result.trim(); + } + + /** + * 移除阿拉伯数字 + */ + private static String removeArabicDigits(String text) { + Matcher matcher = ARABIC_DIGITS_PATTERN.matcher(text); + return matcher.replaceAll(""); + } + + /** + * 移除中文数字 + */ + private static String removeChineseDigits(String text) { + String result = text; + for (String digit : CHINESE_DIGITS) { + result = result.replace(digit, ""); + } + return result; + } + + /** + * 提取标题中的数字格式(保留数字但规范化格式) + */ + public static String extractNumberFormat(String title) { + if (title == null || title.isEmpty()) { + return ""; + } + + // 提取阿拉伯数字 + String arabicResult = extractArabicDigits(title); + + // 提取中文数字 + String chineseResult = extractChineseDigits(title); + + return arabicResult + chineseResult; + } + + /** + * 提取阿拉伯数字 + */ + private static String extractArabicDigits(String text) { + Matcher matcher = ARABIC_DIGITS_PATTERN.matcher(text); + StringBuilder result = new StringBuilder(); + while (matcher.find()) { + result.append("[数字]"); + } + return result.toString(); + } + + /** + * 提取中文数字 + */ + private static String extractChineseDigits(String text) { + Matcher matcher = CHINESE_DIGITS_PATTERN.matcher(text); + StringBuilder result = new StringBuilder(); + while (matcher.find()) { + result.append("[中文数字]"); + } + return result.toString(); + } + + /** + * 比较两个标题的数字格式是否相同 + */ + public static boolean compareNumberFormats(String title1, String title2) { + String format1 = extractNumberFormat(title1); + String format2 = extractNumberFormat(title2); + return format1.equals(format2); + } + private static String getFirstNChars(String str, int n) { + if (str == null || n <= 0) { + return ""; + } + return str.length() > n ? str.substring(0, n) : str; + } + /** + * 测试方法 + */ + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + System.out.println("中文标题数字格式比较工具"); + System.out.println("======================="); + + String useT = "第1部分 这是一级标题"; + String useTFormat = extractNumberFormat(useT); + + System.out.println("参考标题: " + useT); + System.out.println("参考标题数字格式: " + useTFormat); + System.out.println("请输入要比较的标题(输入'exit'退出):"); + + while (true) { + System.out.print("> "); + String input = scanner.nextLine(); + + if ("exit".equalsIgnoreCase(input)) { + break; + } + + String result = filterNumbers(input); + String inputFormat = extractNumberFormat(input); + + + int aa = input.length(); + String useTT = getFirstNChars(useT, aa); + String textResult = filterNumbers(useTT); + // 比较数字格式 + boolean formatsMatch = compareNumberFormats(input, useTT); + + System.out.println("原始模板标题: " + input); + System.out.println("过滤后模板标题: " + result); + + System.out.println("原始标题: " + useTT); + System.out.println("过滤后标题: " + textResult); + + + System.out.println("检测到的数字格式: " + inputFormat); + System.out.println("与参考格式匹配: " + formatsMatch); + + + + if(result.equals("")){ + if (textResult.equals("")){ + System.out.println("是一级标题"); + }else { + System.out.println("不是"); + } + }else { + // 判断是否是一级标题的逻辑 + if (result.equals("")) { + if (textResult.equals("")) { + System.out.println("判断: 是一级标题"); + } else { + System.out.println("判断: 不是一级标题"); + } + } else { + if(textResult.contains(result)){ + if (formatsMatch) { + System.out.println("判断: 数字格式匹配,可能是同级标题"); + } else { + System.out.println("判断: 数字格式不匹配,不是同级标题"); + } + }else { + System.out.println("判断: 不是一级标题"); + } + + } + } + + + + + + char lastChar = input.charAt(input.length() - 1); + System.out.println(lastChar); + + // 在实际标题中查找这个字符第一次出现的位置 + int position = useT.indexOf(lastChar); + + if (position == -1) { + // 如果没有找到,返回整个实际标题 + System.out.println("没有"); + }else { + String content = useT.substring(position + 1).trim(); + System.out.println(content); + } + + System.out.println(); + } + + scanner.close(); + System.out.println("程序已退出。"); + } +} \ No newline at end of file diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/TitleFormatterController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/TitleFormatterController.java index 6071556..cbeb7d3 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/TitleFormatterController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/TitleFormatterController.java @@ -2,8 +2,8 @@ package com.ruoyi.web.controller.system; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; -import com.ruoyi.api.domain.TitleTemplate; -import com.ruoyi.api.service.impl.TitleTemplateServiceImpl; +import com.ruoyi.system.domain.TitleTemplate; +import com.ruoyi.system.service.impl.TitleTemplateServiceImpl; import com.ruoyi.common.core.domain.AjaxResult; import org.apache.poi.xwpf.usermodel.*; import org.springframework.beans.factory.annotation.Autowired; @@ -151,7 +151,6 @@ public class TitleFormatterController { return result; } - /** * 精确模板匹配 */ diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/TitleFormatterControllerCopy.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/TitleFormatterControllerCopy.java new file mode 100644 index 0000000..5fdddfa --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/TitleFormatterControllerCopy.java @@ -0,0 +1,297 @@ +package com.ruoyi.web.controller.system; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.ruoyi.system.domain.TitleTemplate; +import com.ruoyi.system.service.impl.TitleTemplateServiceImpl; +import com.ruoyi.common.core.domain.AjaxResult; +import org.apache.poi.xwpf.usermodel.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import java.io.*; +import java.util.*; + +@RestController +@RequestMapping("/system/formatterCopy") +public class TitleFormatterControllerCopy { + + @Autowired + private TitleTemplateServiceImpl titleTemplateService; + + @PostMapping + public AjaxResult formatDocument(@RequestParam("file") MultipartFile file, + @RequestParam("template") String templateJson) { + try { + // 解析模板参数 + JSONObject templateObj = JSON.parseObject(templateJson); + Long templateType = Long.parseLong(templateObj.getString("id")); + TitleTemplate titleTemplate = titleTemplateService.selectTitleTemplateById(templateType); + + if (titleTemplate == null) { + return AjaxResult.error("未找到对应的标题模板"); + } + + // 检查文件类型 + if (!file.getOriginalFilename().endsWith(".docx")) { + return AjaxResult.error("仅支持.docx格式的文档"); + } + + // 处理文档 + Map result = processDocumentWithNumbering(file, titleTemplate); + + return AjaxResult.success("文档处理成功", result); + } catch (Exception e) { + e.printStackTrace(); + return AjaxResult.error("文档处理失败: " + e.getMessage()); + } + } + + /** + * 处理文档并添加多级标题编号 + */ + private Map processDocumentWithNumbering(MultipartFile file, TitleTemplate titleTemplate) + throws IOException { + Map result = new HashMap<>(); + List> paragraphsInfo = new ArrayList<>(); + + // 初始化各级标题计数器 + int[] levelCounters = new int[5]; // 0不使用,1-4对应各级标题 + Arrays.fill(levelCounters, 0); + + try (InputStream inputStream = file.getInputStream(); + XWPFDocument document = new XWPFDocument(inputStream)) { + + // 获取模板中的标题配置 + String firstTitle = titleTemplate.getFirstTitle(); + String secondTitle = titleTemplate.getSecondTitle(); + String thirdTitle = titleTemplate.getThirdTitle(); + String fourthTitle = titleTemplate.getFourthTitle(); + + System.out.println("=== 开始处理文档 ==="); + System.out.println("模板配置: 一级标题='" + firstTitle + "', 二级标题='" + secondTitle + + "', 三级标题='" + thirdTitle + "', 四级标题='" + fourthTitle + "'"); + + // 遍历文档中的所有段落 + List paragraphs = document.getParagraphs(); + for (int i = 0; i < paragraphs.size(); i++) { + XWPFParagraph paragraph = paragraphs.get(i); + + // 获取段落文本 + String fullText = getParagraphText(paragraph); + if (fullText.isEmpty()) { + continue; + } + + System.out.println("\n--- 处理段落 " + (i + 1) + " ---"); + System.out.println("完整文本: '" + fullText + "'"); + + Map paraInfo = new HashMap<>(); + paraInfo.put("originalText", fullText); + + String numberedText = fullText; + int levelNumber = 0; + String levelName = "正文"; + + // 检查段落是否包含模板字符串并确定标题级别(精确匹配) + if (isExactTemplateMatch(fullText, firstTitle)) { + levelCounters[1]++; + resetLowerLevels(levelCounters, 1); + numberedText = generateLevelNumber(levelCounters, 1) + " " + extractPureContent(fullText, firstTitle); + levelNumber = 1; + levelName = "一级标题"; + setParagraphStyle(paragraph, "Heading1"); + System.out.println("识别为一级标题,新编号: " + numberedText); + } else if (isExactTemplateMatch(fullText, secondTitle)) { + levelCounters[2]++; + resetLowerLevels(levelCounters, 2); + numberedText = generateLevelNumber(levelCounters, 2) + " " + extractPureContent(fullText, secondTitle); + levelNumber = 2; + levelName = "二级标题"; + setParagraphStyle(paragraph, "Heading2"); + System.out.println("识别为二级标题,新编号: " + numberedText); + } else if (isExactTemplateMatch(fullText, thirdTitle)) { + levelCounters[3]++; + resetLowerLevels(levelCounters, 3); + numberedText = generateLevelNumber(levelCounters, 3) + " " + extractPureContent(fullText, thirdTitle); + levelNumber = 3; + levelName = "三级标题"; + setParagraphStyle(paragraph, "Heading3"); + System.out.println("识别为三级标题,新编号: " + numberedText); + } else if (isExactTemplateMatch(fullText, fourthTitle)) { + levelCounters[4]++; + resetLowerLevels(levelCounters, 4); + numberedText = generateLevelNumber(levelCounters, 4) + " " + extractPureContent(fullText, fourthTitle); + levelNumber = 4; + levelName = "四级标题"; + setParagraphStyle(paragraph, "Heading4"); + System.out.println("识别为四级标题,新编号: " + numberedText); + } else { + System.out.println("识别为正文"); + } + + // 设置段落信息 + paraInfo.put("level", levelName); + paraInfo.put("levelNumber", levelNumber); + paraInfo.put("numberedText", numberedText); + paragraphsInfo.add(paraInfo); + + // 更新段落文本 + updateParagraphText(paragraph, numberedText); + } + + } + + result.put("paragraphs", paragraphsInfo); + result.put("summary", String.format( + "文档处理完成:一级标题%d个,二级标题%d个,三级标题%d个,四级标题%d个", + levelCounters[1], levelCounters[2], levelCounters[3], levelCounters[4] + )); + + return result; + } + /** + * 精确模板匹配 + */ + private boolean isExactTemplateMatch(String text, String template) { + if (text == null || template == null || template.isEmpty()) { + return false; + } + + return text.trim().startsWith(template.trim()); + } + + /** + * 提取纯文本内容 + */ + private String extractPureContent(String fullText, String template) { + if (fullText.startsWith(template)) { + return fullText.substring(template.length()).trim(); + } + return fullText; + } + + /** + * 获取段落文本 + */ + private String getParagraphText(XWPFParagraph paragraph) { + StringBuilder textBuilder = new StringBuilder(); + for (XWPFRun run : paragraph.getRuns()) { + if (run.getText(0) != null) { + textBuilder.append(run.getText(0)); + } + } + return textBuilder.toString().trim(); + } + + /** + * 生成级别编号 + */ + private String generateLevelNumber(int[] levelCounters, int level) { + for (int i = 1; i < levelCounters.length; i++) { + if (levelCounters[i] == 0) { + levelCounters[i] = 1; + } + } + + switch (level) { + case 1: + return generateChineseNumber(levelCounters[1]) + "、"; + case 2: + return "(" + generateChineseNumber(levelCounters[2]) + ")"; + case 3: + return levelCounters[3] + "."; + case 4: + return "(" + levelCounters[4] + ")"; + default: + return ""; + } + } + + /** + * 生成中文数字 + */ + private String generateChineseNumber(int number) { + String[] chineseNumbers = {"", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十"}; + if (number <= 10) { + return chineseNumbers[number]; + } else if (number < 20) { + return "十" + (number > 10 ? chineseNumbers[number - 10] : ""); + } else if (number < 100) { + int tens = number / 10; + int units = number % 10; + return chineseNumbers[tens] + "十" + (units > 0 ? chineseNumbers[units] : ""); + } else { + return String.valueOf(number); + } + } + + /** + * 重置下级标题计数器 + */ + private void resetLowerLevels(int[] levelCounters, int currentLevel) { + for (int i = currentLevel + 1; i < levelCounters.length; i++) { + levelCounters[i] = 0; + } + } + + /** + * 更新段落文本 + */ + private void updateParagraphText(XWPFParagraph paragraph, String newText) { + // 清除原有的runs + for (int i = paragraph.getRuns().size() - 1; i >= 0; i--) { + paragraph.removeRun(i); + } + + // 创建新的run并设置文本 + XWPFRun run = paragraph.createRun(); + run.setText(newText); + + // 设置字体样式 + run.setFontSize(12); + if (paragraph.getStyle() != null && paragraph.getStyle().startsWith("Heading")) { + run.setBold(true); + // 根据标题级别设置不同的字体大小 + switch (paragraph.getStyle()) { + case "Heading1": + run.setFontSize(16); + break; + case "Heading2": + run.setFontSize(14); + break; + case "Heading3": + run.setFontSize(13); + break; + case "Heading4": + run.setFontSize(12); + break; + } + } + } + + /** + * 设置段落样式 + */ + private void setParagraphStyle(XWPFParagraph paragraph, String style) { + paragraph.setStyle(style); + if (style.startsWith("Heading")) { + // 设置不同的缩进 + switch (style) { + case "Heading1": + paragraph.setIndentationLeft(0); + break; + case "Heading2": + paragraph.setIndentationLeft(200); + break; + case "Heading3": + paragraph.setIndentationLeft(400); + break; + case "Heading4": + paragraph.setIndentationLeft(600); + break; + } + } + } +} \ No newline at end of file diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/TitleTemplateController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/TitleTemplateController.java index 89d26b2..5f76f7b 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/TitleTemplateController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/TitleTemplateController.java @@ -3,8 +3,8 @@ package com.ruoyi.web.controller.system; import java.util.List; import javax.servlet.http.HttpServletResponse; -import com.ruoyi.api.domain.TitleTemplate; -import com.ruoyi.api.service.ITitleTemplateService; +import com.ruoyi.system.domain.TitleTemplate; +import com.ruoyi.system.service.ITitleTemplateService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -27,11 +27,11 @@ public class TitleTemplateController extends BaseController private ITitleTemplateService titleTemplateService; @GetMapping("/list") - public TableDataInfo list(TitleTemplate titleTemplate) + public List list(TitleTemplate titleTemplate) { - startPage(); + List list = titleTemplateService.selectTitleTemplateList(titleTemplate); - return getDataTable(list); + return list; } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/ZhyFileManageController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/ZhyFileManageController.java index 910b69b..fb9819b 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/ZhyFileManageController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/ZhyFileManageController.java @@ -10,15 +10,13 @@ import com.ruoyi.common.utils.Neo4jUtil; import com.ruoyi.common.utils.file.FileUploadUtils; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.framework.config.ServerConfig; -import com.ruoyi.system.domain.ZhyArticle; -import com.ruoyi.system.domain.ZhyDoc; -import com.ruoyi.system.domain.ZhyDocRelation; -import com.ruoyi.system.domain.ZhyFileManage; +import com.ruoyi.system.domain.*; import com.ruoyi.system.mapper.Test1Mapper; import com.ruoyi.system.mapper.ZhyArticleMapper; import com.ruoyi.system.mapper.ZhyDocRelationMapper; import com.ruoyi.system.service.impl.LuceneUtil; import com.ruoyi.system.service.impl.ZhyFileManageServiceImpl; +import lombok.Data; import org.apache.poi.util.Units; import org.apache.poi.xwpf.usermodel.ParagraphAlignment; import org.apache.poi.xwpf.usermodel.XWPFDocument; @@ -97,45 +95,25 @@ public class ZhyFileManageController extends BaseController { util.exportExcel(response, list, "用户数据"); } - @PostMapping("/addFile") - public AjaxResult addFile(MultipartFile file) throws IOException { - String url = saveFileWithStructure(file); - FileInputStream fileInputStream = new FileInputStream(url + "\\" + file.getOriginalFilename()); - ZhyFileManage zhyFileManage = new ZhyFileManage(); - zhyFileManage.setCreateTime(new Date()); - zhyFileManage.setFileName(file.getOriginalFilename()); - zhyFileManage.setFileUrl(url + "\\" + file.getOriginalFilename()); - zhyFileManage.setIsShow("0"); - zhyFileManage.setIsDelete("0"); - zhyFileManage.setCreateBy(getUserId()); - webSocket.sendOneMessage(String.valueOf(getUserId()), "正在保存原文件"); - zhyFileManageService.insertFile(zhyFileManage); - webSocket.sendOneMessage(String.valueOf(getUserId()), "正在解析分词"); - zhyFileManageService.wordSplitter(fileInputStream, url + "\\wordSplitter", zhyFileManage.getId(),null); - webSocket.sendOneMessage(String.valueOf(getUserId()), "正在创建索引"); - zhyFileManageService.createIndex(url + "\\wordSplitter", "D:\\project\\gyx\\tupudata\\fileManager\\index"); - webSocket.sendOneMessage(String.valueOf(getUserId()), "正在建立关系"); - zhyFileManageService.getRelationShip(zhyFileManage.getId()); - webSocket.sendOneMessage(String.valueOf(getUserId()), "正在创建图谱"); - zhyFileManageService.createGraph(); - return AjaxResult.success().put("msg", "成功"); - } - @PostMapping("/addFile1") - public AjaxResult addFile1(MultipartFile file) throws IOException { - String url = saveFileWithStructure(file); - FileInputStream fileInputStream = new FileInputStream(url + "\\" + file.getOriginalFilename()); + + @PostMapping("/addFile") + public AjaxResult addFile(FileUploadDTO fileInfo) throws IOException { + System.out.println(fileInfo.getTitleInfo()); + System.out.println(fileInfo.getFirstTitle()); + String url = saveFileWithStructure(fileInfo.getFile()); + FileInputStream fileInputStream = new FileInputStream(url + "\\" + fileInfo.getFile().getOriginalFilename()); ZhyFileManage zhyFileManage = new ZhyFileManage(); zhyFileManage.setCreateTime(new Date()); - zhyFileManage.setFileName(file.getOriginalFilename()); - zhyFileManage.setFileUrl(url + "\\" + file.getOriginalFilename()); + zhyFileManage.setFileName(fileInfo.getFile().getOriginalFilename()); + zhyFileManage.setFileUrl(url + "\\" + fileInfo.getFile().getOriginalFilename()); zhyFileManage.setIsShow("0"); zhyFileManage.setIsDelete("0"); zhyFileManage.setCreateBy(getUserId()); webSocket.sendOneMessage(String.valueOf(getUserId()), "正在保存原文件"); zhyFileManageService.insertFile(zhyFileManage); webSocket.sendOneMessage(String.valueOf(getUserId()), "正在解析分词"); - zhyFileManageService.wordSplitter(fileInputStream, url + "\\wordSplitter", zhyFileManage.getId(),null); + zhyFileManageService.wordSplitter(fileInputStream, url + "\\wordSplitter", zhyFileManage.getId(),null,fileInfo); webSocket.sendOneMessage(String.valueOf(getUserId()), "正在创建索引"); zhyFileManageService.createIndex(url + "\\wordSplitter", "D:\\project\\gyx\\tupudata\\fileManager\\index"); webSocket.sendOneMessage(String.valueOf(getUserId()), "正在建立关系"); @@ -145,6 +123,30 @@ public class ZhyFileManageController extends BaseController { return AjaxResult.success().put("msg", "成功"); } +// @PostMapping("/addFile1") +// public AjaxResult addFile1(MultipartFile file) throws IOException { +// String url = saveFileWithStructure(file); +// FileInputStream fileInputStream = new FileInputStream(url + "\\" + file.getOriginalFilename()); +// ZhyFileManage zhyFileManage = new ZhyFileManage(); +// zhyFileManage.setCreateTime(new Date()); +// zhyFileManage.setFileName(file.getOriginalFilename()); +// zhyFileManage.setFileUrl(url + "\\" + file.getOriginalFilename()); +// zhyFileManage.setIsShow("0"); +// zhyFileManage.setIsDelete("0"); +// zhyFileManage.setCreateBy(getUserId()); +// webSocket.sendOneMessage(String.valueOf(getUserId()), "正在保存原文件"); +// zhyFileManageService.insertFile(zhyFileManage); +// webSocket.sendOneMessage(String.valueOf(getUserId()), "正在解析分词"); +// zhyFileManageService.wordSplitter(fileInputStream, url + "\\wordSplitter", zhyFileManage.getId(),null); +// webSocket.sendOneMessage(String.valueOf(getUserId()), "正在创建索引"); +// zhyFileManageService.createIndex(url + "\\wordSplitter", "D:\\project\\gyx\\tupudata\\fileManager\\index"); +// webSocket.sendOneMessage(String.valueOf(getUserId()), "正在建立关系"); +// zhyFileManageService.getRelationShip(zhyFileManage.getId()); +// webSocket.sendOneMessage(String.valueOf(getUserId()), "正在创建图谱"); +// zhyFileManageService.createGraph(); +// +// return AjaxResult.success().put("msg", "成功"); +// } @PostMapping("/insertRelationByFile") public AjaxResult insertRelationByFile(MultipartFile file) throws IOException { @@ -675,7 +677,7 @@ public class ZhyFileManageController extends BaseController { } } - zhyFileManageService.wordSplitter(null , url +"\\wordSplitter", 0,list); + zhyFileManageService.wordSplitterOld(null , url +"\\wordSplitter", 0,list); zhyFileManageService.createIndex(url + "\\wordSplitter", "D:\\project\\gyx\\tupudata\\fileManager\\index"); test1Mapper.updateParentId(list); diff --git a/ruoyi-api/src/main/java/com/ruoyi/api/domain/TitleTemplate.java b/ruoyi-api/src/main/java/com/ruoyi/api/domain/TitleTemplate.java deleted file mode 100644 index abf2162..0000000 --- a/ruoyi-api/src/main/java/com/ruoyi/api/domain/TitleTemplate.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.ruoyi.api.domain; - -public class TitleTemplate { - private String name; - private Long id; - private String firstTitle; - private String secondTitle; - private String thirdTitle; - private String fourthTitle; - - public Long getId() { - return id; - } - public void setId(Long id) { - this.id = id; - } - public String getName() { - return name; - } - public void setName(String name) { - this.name = name; - } - public String getFirstTitle() { - return firstTitle; - } - public void setFirstTitle(String firstTitle) { - this.firstTitle = firstTitle; - } - public String getSecondTitle() { - return secondTitle; - } - public void setSecondTitle(String secondTitle) { - this.secondTitle = secondTitle; - } - public String getThirdTitle() { - return thirdTitle; - } - public void setThirdTitle(String thirdTitle) { - this.thirdTitle = thirdTitle; - } - public String getFourthTitle() { - return fourthTitle; - } - public void setFourthTitle(String fourthTitle) { - this.fourthTitle = fourthTitle; - } - -} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/FileUploadDTO.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/FileUploadDTO.java new file mode 100644 index 0000000..302d589 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/FileUploadDTO.java @@ -0,0 +1,90 @@ +package com.ruoyi.system.domain; + +import org.springframework.web.multipart.MultipartFile; + +public class FileUploadDTO { + + private MultipartFile file; + private TitleTemplate titleInfo; + + + private String firstTitle; + private String secondTitle; + private String thirdTitle; + private String fourthTitle; + private String fiveTitle; + private String sixTitle; + private String sevenTitle; + + public MultipartFile getFile() { + return file; + } + + public void setFile(MultipartFile file) { + this.file = file; + } + + public TitleTemplate getTitleInfo() { + return titleInfo; + } + + public void setTitleInfo(TitleTemplate titleInfo) { + this.titleInfo = titleInfo; + } + + public String getFirstTitle() { + return firstTitle; + } + + public void setFirstTitle(String firstTitle) { + this.firstTitle = firstTitle; + } + + public String getSecondTitle() { + return secondTitle; + } + + public void setSecondTitle(String secondTitle) { + this.secondTitle = secondTitle; + } + + public String getThirdTitle() { + return thirdTitle; + } + + public void setThirdTitle(String thirdTitle) { + this.thirdTitle = thirdTitle; + } + + public String getFourthTitle() { + return fourthTitle; + } + + public void setFourthTitle(String fourthTitle) { + this.fourthTitle = fourthTitle; + } + + public String getFiveTitle() { + return fiveTitle; + } + + public void setFiveTitle(String fiveTitle) { + this.fiveTitle = fiveTitle; + } + + public String getSixTitle() { + return sixTitle; + } + + public void setSixTitle(String sixTitle) { + this.sixTitle = sixTitle; + } + + public String getSevenTitle() { + return sevenTitle; + } + + public void setSevenTitle(String sevenTitle) { + this.sevenTitle = sevenTitle; + } +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/TitleTemplate.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/TitleTemplate.java new file mode 100644 index 0000000..46fb658 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/TitleTemplate.java @@ -0,0 +1,100 @@ +package com.ruoyi.system.domain; + +public class TitleTemplate { + private String name; + private Long id; + private String firstTitle; + private String secondTitle; + private String thirdTitle; + private String fourthTitle; + private String fiveTitle; + private String sixTitle; + private String sevenTitle; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getFirstTitle() { + return firstTitle; + } + + public void setFirstTitle(String firstTitle) { + this.firstTitle = firstTitle; + } + + public String getSecondTitle() { + return secondTitle; + } + + public void setSecondTitle(String secondTitle) { + this.secondTitle = secondTitle; + } + + public String getThirdTitle() { + return thirdTitle; + } + + public void setThirdTitle(String thirdTitle) { + this.thirdTitle = thirdTitle; + } + + public String getFourthTitle() { + return fourthTitle; + } + + public void setFourthTitle(String fourthTitle) { + this.fourthTitle = fourthTitle; + } + + public String getFiveTitle() { + return fiveTitle; + } + + public void setFiveTitle(String fiveTitle) { + this.fiveTitle = fiveTitle; + } + + public String getSixTitle() { + return sixTitle; + } + + public void setSixTitle(String sixTitle) { + this.sixTitle = sixTitle; + } + + public String getSevenTitle() { + return sevenTitle; + } + + public void setSevenTitle(String sevenTitle) { + this.sevenTitle = sevenTitle; + } + + @Override + public String toString() { + return "TitleTemplate{" + + "name='" + name + '\'' + + ", id=" + id + + ", firstTitle='" + firstTitle + '\'' + + ", secondTitle='" + secondTitle + '\'' + + ", thirdTitle='" + thirdTitle + '\'' + + ", fourthTitle='" + fourthTitle + '\'' + + ", fiveTitle='" + fiveTitle + '\'' + + ", sixTitle='" + sixTitle + '\'' + + ", sevenTitle='" + sevenTitle + '\'' + + '}'; + } +} diff --git a/ruoyi-api/src/main/java/com/ruoyi/api/mapper/TitleTemplateMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/TitleTemplateMapper.java similarity index 74% rename from ruoyi-api/src/main/java/com/ruoyi/api/mapper/TitleTemplateMapper.java rename to ruoyi-system/src/main/java/com/ruoyi/system/mapper/TitleTemplateMapper.java index 628f33d..114802c 100644 --- a/ruoyi-api/src/main/java/com/ruoyi/api/mapper/TitleTemplateMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/TitleTemplateMapper.java @@ -1,10 +1,11 @@ -package com.ruoyi.api.mapper; +package com.ruoyi.system.mapper; -import com.ruoyi.api.domain.TitleTemplate; +import com.ruoyi.system.domain.TitleTemplate; +import org.apache.ibatis.annotations.Mapper; import java.util.List; - +@Mapper public interface TitleTemplateMapper { diff --git a/ruoyi-api/src/main/java/com/ruoyi/api/service/ITitleTemplateService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ITitleTemplateService.java similarity index 83% rename from ruoyi-api/src/main/java/com/ruoyi/api/service/ITitleTemplateService.java rename to ruoyi-system/src/main/java/com/ruoyi/system/service/ITitleTemplateService.java index fe81372..120c355 100644 --- a/ruoyi-api/src/main/java/com/ruoyi/api/service/ITitleTemplateService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ITitleTemplateService.java @@ -1,11 +1,10 @@ -package com.ruoyi.api.service; +package com.ruoyi.system.service; -import com.ruoyi.api.domain.TitleTemplate; +import com.ruoyi.system.domain.TitleTemplate; import java.util.List; - public interface ITitleTemplateService { public TitleTemplate selectTitleTemplateById(Long id); diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/LuceneUtil.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/LuceneUtil.java index 2bbb022..01c18c0 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/LuceneUtil.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/LuceneUtil.java @@ -547,7 +547,7 @@ public class LuceneUtil { String url = doc.get("url"); String snippet = null; String snippet1 = null; - Map ttt = wordSplitter.startsWithHeading1(id); + Map ttt = wordSplitter.startsWithHeadingOld(id); try { snippet = highlighter.getBestFragment(new IKAnalyzer(true), "content", text); snippet1 = highlighter.getBestFragment(new IKAnalyzer(true), "id", String.valueOf(ttt.get("title"))); diff --git a/ruoyi-api/src/main/java/com/ruoyi/api/service/impl/TitleTemplateServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TitleTemplateServiceImpl.java similarity index 84% rename from ruoyi-api/src/main/java/com/ruoyi/api/service/impl/TitleTemplateServiceImpl.java rename to ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TitleTemplateServiceImpl.java index fef6766..b53736e 100644 --- a/ruoyi-api/src/main/java/com/ruoyi/api/service/impl/TitleTemplateServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TitleTemplateServiceImpl.java @@ -1,13 +1,13 @@ -package com.ruoyi.api.service.impl; +package com.ruoyi.system.service.impl; -import java.util.List; - -import com.ruoyi.api.domain.TitleTemplate; -import com.ruoyi.api.mapper.TitleTemplateMapper; -import com.ruoyi.api.service.ITitleTemplateService; +import com.ruoyi.system.domain.TitleTemplate; +import com.ruoyi.system.mapper.TitleTemplateMapper; +import com.ruoyi.system.service.ITitleTemplateService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.List; + @Service public class TitleTemplateServiceImpl implements ITitleTemplateService diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/WordSplitter.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/WordSplitter.java index 9ceb3cd..e435304 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/WordSplitter.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/WordSplitter.java @@ -5,6 +5,7 @@ import com.ruoyi.common.exception.file.InvalidExtensionException; import com.ruoyi.common.utils.file.Base64ToMultipartFile; import com.ruoyi.common.utils.file.FileUploadUtils; import com.ruoyi.common.utils.file.MimeTypeUtils; +import com.ruoyi.system.domain.FileUploadDTO; import com.ruoyi.system.domain.ZhyBattle; import com.ruoyi.system.domain.ZhyDoc; import com.ruoyi.system.domain.ZhySetInfo; @@ -49,7 +50,7 @@ public class WordSplitter { public static List levelList = new ArrayList<>(); public static List battleLevelList = new ArrayList<>(); - public void testWordOne(FileInputStream fileInputStream,String outputFolder,Integer fileId) { + public void testWordOne(FileInputStream fileInputStream, String outputFolder, Integer fileId, FileUploadDTO fileUploadDTO) { levelList = new ArrayList<>(); List list = new ArrayList<>(); ZhySetInfo zs = new ZhySetInfo(); @@ -59,6 +60,9 @@ public class WordSplitter { String picSize = info.get(0).getContent(); + + + try { // 创建文件输入流 FileInputStream fis = fileInputStream; @@ -172,9 +176,9 @@ public class WordSplitter { - String type = String.valueOf(startsWithHeading1(textss).get("type")); - String title = String.valueOf(startsWithHeading1(textss).get("title")); - String url = String.valueOf(startsWithHeading1(textss).get("docUrl")); + String type = String.valueOf(startsWithHeading1(textss,fileUploadDTO).get("type")); + String title = String.valueOf(startsWithHeading1(textss,fileUploadDTO).get("title")); + String url = String.valueOf(startsWithHeading1(textss,fileUploadDTO).get("docUrl")); //判断文件是否为空 if (!textss.equals("")) { @@ -381,8 +385,8 @@ public class WordSplitter { } } - String type = String.valueOf(startsWithHeading1(currentSectionTitle).get("type")); - String title = String.valueOf(startsWithHeading1(currentSectionTitle).get("title")); + String type = String.valueOf(startsWithHeading1(currentSectionTitle,fileUploadDTO).get("type")); + String title = String.valueOf(startsWithHeading1(currentSectionTitle,fileUploadDTO).get("title")); if (!currentSectionTitle.isEmpty()) { currentSectionTitle = currentSectionTitle.replaceAll(" ","_"); realTitle = title; @@ -404,39 +408,40 @@ public class WordSplitter { } } - public void handWord(String outputFolder,List list) throws IOException { - StringBuilder sb = new StringBuilder(); - String all = ""; - for(int i=0;i(); List list = new ArrayList<>(); ZhySetInfo zs = new ZhySetInfo(); zs.setName("imgSize"); + ZipSecureFile.setMinInflateRatio(0.001); List info = zhySetInfoMapper.selectZhySetInfoList(zs); String picSize = info.get(0).getContent(); + + + + + try { // 创建文件输入流 FileInputStream fis = fileInputStream; +// System.out.println(fis); XWPFDocument document = new XWPFDocument(fis); - // 遍历段落,寻找标题并拆分 - List paragraphs = document.getParagraphs(); + List paragraphs = document.getParagraphs(); String currentSectionTitle = ""; String realTitle = ""; String realleve = ""; XWPFDocument currentSection = new XWPFDocument(); + List currentSectionImages = new ArrayList<>(); + + + //处理图片 for (int c = 0; c < paragraphs.size(); c++) { XWPFParagraph paragraph = paragraphs.get(c); @@ -452,14 +457,47 @@ public class WordSplitter { for (XWPFPicture picture : pictures) { XWPFPictureData pictureData = picture.getPictureData(); byte[] imageData = pictureData.getData(); + // 将图片数据转换为 Base64 编码的字符串 - String base64Image = Base64.getEncoder().encodeToString(imageData); + String base64Image = Base64.getEncoder().withoutPadding().encodeToString(imageData); String contentType = getContentType(pictureData.getPictureType()); + String fileExtension = getImageExtension(pictureData.getPictureType()); + + if(picture.getWidth()<10){ + String imgTag = "
" + + "\n" + "
"; + imgs = imgs + imgTag; + - // 构建 HTML 字符串 - String imgTag = "
" + - "\n" + "
"; - imgs = imgs + imgTag; + MultipartFile multipartFile = new Base64ToMultipartFile( + base64Image, + "pic"+new Date().getTime()+fileExtension, + contentType + ); + // 上传并返回新文件名称 + String url = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), multipartFile, MimeTypeUtils.IMAGE_EXTENSION); + currentSectionImages.add(url); + System.out.println(currentSectionImages.size()); + + + }else { + // 构建 HTML 字符串 + String imgTag = "
" + + "\n" + "
"; + imgs = imgs + imgTag; + + + MultipartFile multipartFile = new Base64ToMultipartFile( + base64Image, + "pic"+new Date().getTime()+".png", + contentType + ); + // 上传文件路径 + // 上传并返回新文件名称 + String url = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), multipartFile, MimeTypeUtils.IMAGE_EXTENSION); + currentSectionImages.add(url); + System.out.println(currentSectionImages.size()); + } } } @@ -470,8 +508,7 @@ public class WordSplitter { } } } - - + List useImgs = new ArrayList<>(); for (int c = 0; c < paragraphs.size(); c++) { @@ -487,19 +524,24 @@ public class WordSplitter { if (paragraph.getRuns().size() == 1) { textss = String.valueOf(paragraph.getRuns().get(0)); - } else { + } + else { for (int aa = 0; aa < paragraph.getRuns().size(); aa++) { textss = textss + paragraph.getRuns().get(aa); + + } } - String type = String.valueOf(startsWithHeading1(textss).get("type")); - String title = String.valueOf(startsWithHeading1(textss).get("title")); - String url = String.valueOf(startsWithHeading1(textss).get("docUrl")); + + String type = String.valueOf(startsWithHeadingOld(textss).get("type")); + String title = String.valueOf(startsWithHeadingOld(textss).get("title")); + String url = String.valueOf(startsWithHeadingOld(textss).get("docUrl")); + //判断文件是否为空 if (!textss.equals("")) { //判断为几级标题 @@ -511,17 +553,17 @@ public class WordSplitter { mm.put("list", aa); String t = paragraph.getText().trim().replaceAll("[/\\\\:*?|]", "&"); t = t.replaceAll(" ","_"); - - - + System.out.println(outputFolder + "\\" + t + ".txt"); mm.put("docUrl", outputFolder + "\\" + t + ".txt"); list.add(mm); if (!currentSectionTitle.isEmpty()) { currentSectionTitle = currentSectionTitle.replace(" ","_"); String outputFilePath = outputFolder + "\\" + currentSectionTitle + ".txt"; - saveSectionBattle(currentSection, outputFolder, currentSectionTitle, realleve, outputFilePath, realTitle,outputFolder,fileId); + saveSection(currentSection, outputFolder, currentSectionTitle, realleve, outputFilePath, realTitle,outputFolder,fileId,useImgs); currentSection = new XWPFDocument(); + } + useImgs = new ArrayList<>(); currentSectionTitle = paragraph.getText().trim().replaceAll("[/\\\\:*?|]", "&"); realTitle = title; realleve = type; @@ -539,17 +581,25 @@ public class WordSplitter { bl.add(bb); aa.put("list", bl); + + if (!currentSectionTitle.isEmpty()) { currentSectionTitle = currentSectionTitle.replace(" ","_"); String outputFilePath = outputFolder + "\\" + currentSectionTitle + ".txt"; - saveSectionBattle(currentSection, outputFolder, currentSectionTitle, realleve, outputFilePath, realTitle,outputFolder,fileId); + saveSection(currentSection, outputFolder, currentSectionTitle, realleve, outputFilePath, realTitle,outputFolder,fileId,useImgs); currentSection = new XWPFDocument(); + } + useImgs = new ArrayList<>(); currentSectionTitle = paragraph.getText().trim().replaceAll("[/\\\\:*?|]", "&"); realTitle = title; realleve = type; } + + if (type.equals("3")) { + + //二级标题 Map aa = list.get(list.size() - 1); Map bb = new HashMap(); @@ -566,9 +616,11 @@ public class WordSplitter { if (!currentSectionTitle.isEmpty()) { currentSectionTitle = currentSectionTitle.replace(" ","_"); String outputFilePath = outputFolder + "\\" + currentSectionTitle + ".txt"; - saveSectionBattle(currentSection, outputFolder, currentSectionTitle, realleve, outputFilePath, realTitle,outputFolder,fileId); + saveSection(currentSection, outputFolder, currentSectionTitle, realleve, outputFilePath, realTitle,outputFolder,fileId,useImgs); currentSection = new XWPFDocument(); + } + useImgs = new ArrayList<>(); currentSectionTitle = paragraph.getText().trim().replaceAll("[/\\\\:*?|]", "&"); realTitle = title; realleve = type; @@ -591,14 +643,15 @@ public class WordSplitter { if (!currentSectionTitle.isEmpty()) { currentSectionTitle = currentSectionTitle.replace(" ","_"); String outputFilePath = outputFolder + "\\" + currentSectionTitle + ".txt"; - saveSectionBattle(currentSection, outputFolder, currentSectionTitle, realleve, outputFilePath, realTitle,outputFolder,fileId); + saveSection(currentSection, outputFolder, currentSectionTitle, realleve, outputFilePath, realTitle,outputFolder,fileId,useImgs); currentSection = new XWPFDocument(); + } + useImgs = new ArrayList<>(); currentSectionTitle = paragraph.getText().trim().replaceAll("[/\\\\:*?|]", "&");; realTitle = title; realleve = type; } - if (type.equals("5")) { //二级标题 Map aa = list.get(list.size() - 1); @@ -616,9 +669,11 @@ public class WordSplitter { if (!currentSectionTitle.isEmpty()) { currentSectionTitle = currentSectionTitle.replace(" ","_"); String outputFilePath = outputFolder + "\\" + currentSectionTitle + ".txt"; - saveSectionBattle(currentSection, outputFolder, currentSectionTitle, realleve, outputFilePath, realTitle,outputFolder,fileId); + saveSection(currentSection, outputFolder, currentSectionTitle, realleve, outputFilePath, realTitle,outputFolder,fileId,useImgs); currentSection = new XWPFDocument(); + } + useImgs = new ArrayList<>(); currentSectionTitle = paragraph.getText().trim().replaceAll("[/\\\\:*?|]", "&");; realTitle = title; realleve = type; @@ -640,16 +695,29 @@ public class WordSplitter { if (!currentSectionTitle.isEmpty()) { currentSectionTitle = currentSectionTitle.replace(" ","_"); String outputFilePath = outputFolder + "\\" + currentSectionTitle + ".txt"; - saveSectionBattle(currentSection, outputFolder, currentSectionTitle, realleve, outputFilePath, realTitle,outputFolder,fileId); + saveSection(currentSection, outputFolder, currentSectionTitle, realleve, outputFilePath, realTitle,outputFolder,fileId,useImgs); currentSection = new XWPFDocument(); + } + useImgs = new ArrayList<>(); currentSectionTitle = paragraph.getText().trim().replaceAll("[/\\\\:*?|]", "&");; realTitle = title; realleve = type; } + if (type.equals("0")) { + String[] parts = textss.split("1){ + int imgcount = parts.length-1; + useImgs.addAll(currentSectionImages.subList(0, imgcount)); + System.out.println(useImgs.size()); + currentSectionImages.subList(0, imgcount).clear(); + System.out.println(currentSectionImages.size()); + } + System.out.println("aaaaaaaaaaaaa--------saa"); + System.out.println(useImgs.size()); //正文 XWPFParagraph newParagraph = currentSection.createParagraph(); @@ -679,29 +747,43 @@ public class WordSplitter { } } - - - String type = String.valueOf(startsWithHeading1(currentSectionTitle).get("type")); - String title = String.valueOf(startsWithHeading1(currentSectionTitle).get("title")); + String type = String.valueOf(startsWithHeadingOld(currentSectionTitle).get("type")); + String title = String.valueOf(startsWithHeadingOld(currentSectionTitle).get("title")); if (!currentSectionTitle.isEmpty()) { + currentSectionTitle = currentSectionTitle.replaceAll(" ","_"); realTitle = title; realleve = type; String outputFilePath = outputFolder + "\\" + currentSectionTitle + ".txt"; - saveSectionBattle(currentSection, outputFolder, currentSectionTitle, type, outputFilePath, realTitle,outputFolder,fileId); + saveSection(currentSection, outputFolder, currentSectionTitle, type, outputFilePath, realTitle,outputFolder,fileId,currentSectionImages); + currentSectionImages = new ArrayList<>(); } - battleLevelList = list; + levelList = list; // 关闭资源 fis.close(); - int a = test1Mapper.insertBattleList(battleList); - - battleList = new ArrayList<>(); - - getLevelInfoBattle(); - + int a = test1Mapper.insertDocList(docList); + docList = new ArrayList<>(); + getLevelInfo(); } catch (IOException e) { e.printStackTrace(); + } catch (InvalidExtensionException e) { + throw new RuntimeException(e); } } + + public void handWord(String outputFolder,List list) throws IOException { + StringBuilder sb = new StringBuilder(); + String all = ""; + for(int i=0;i list) { -// levelList = new ArrayList<>(); -// ZhySetInfo zs = new ZhySetInfo(); -// zs.setName("imgSize"); -// List info = zhySetInfoMapper.selectZhySetInfoList(zs); -// String picSize = info.get(0).getContent(); -// try { -// // 创建文件输入流 -// FileInputStream fis = fileInputStream; -// -// XWPFDocument document = new XWPFDocument(fis); -// -// // 遍历段落,寻找标题并拆分 -// List paragraphs = document.getParagraphs(); -// -// String currentSectionTitle = ""; -// String realTitle = ""; -// String realleve = ""; -// XWPFDocument currentSection = new XWPFDocument(); -// -// //处理图片 -// for (int c = 0; c < paragraphs.size(); c++) { -// XWPFParagraph paragraph = paragraphs.get(c); -// -// List runs = paragraph.getRuns(); -// if (runs != null) { -// String imgs = ""; -// for (int rIndex = 0; rIndex < runs.size(); rIndex++) { -// XWPFRun run = runs.get(rIndex); -// CTR ctr = run.getCTR(); -// if (run.getEmbeddedPictures().size() > 0) { -// List pictures = run.getEmbeddedPictures(); -// for (XWPFPicture picture : pictures) { -// XWPFPictureData pictureData = picture.getPictureData(); -// byte[] imageData = pictureData.getData(); -// // 将图片数据转换为 Base64 编码的字符串 -// String base64Image = Base64.getEncoder().encodeToString(imageData); -// String contentType = getContentType(pictureData.getPictureType()); -// -// // 构建 HTML 字符串 -// String imgTag = "
" + -// "\n" + "
"; -// imgs = imgs + imgTag; -// } -// -// } -// if (!imgs.equals("")) { -// run.setText(imgs, 0); -// imgs = ""; -// } -// } -// } -// } -// -// -// for (int c = 0; c < paragraphs.size(); c++) { -// -// -// XWPFParagraph paragraph = paragraphs.get(c); -// -// List runs = paragraph.getRuns(); -// -// -// if (paragraph.getRuns().size() > 0) { -// XWPFRun run = paragraph.getRuns().get(0); -// String textss = ""; -// List charList = new ArrayList<>(); -// -// if (paragraph.getRuns().size() == 1) { -// textss = String.valueOf(paragraph.getRuns().get(0)); -// } else { -// for (int aa = 0; aa < paragraph.getRuns().size(); aa++) { -// textss = textss + paragraph.getRuns().get(aa); -// } -// } -//// paragraph.setFontAlignment(2); -// -// String type = String.valueOf(startsWithHeading1(textss).get("type")); -// String title = String.valueOf(startsWithHeading1(textss).get("title")); -// String url = String.valueOf(startsWithHeading1(textss).get("docUrl")); -// -// //判断文件是否为空 -// if (!textss.equals("")) { -// //判断为几级标题 -// if (type.equals("1")) { -// //一级标题 -// Map mm = new HashMap(); -// List aa = new ArrayList<>(); -// mm.put("title", title); -// mm.put("list", aa); -// String t = paragraph.getText().trim().replaceAll("[/\\\\:*?|]", "&"); -// t = t.replaceAll(" ","_"); -// -// -// System.out.println(outputFolder + "\\" + t + ".txt"); -// mm.put("docUrl", outputFolder + "\\" + t + ".txt"); -// list.add(mm); -// if (!currentSectionTitle.isEmpty()) { -// currentSectionTitle = currentSectionTitle.replace(" ","_"); -// String outputFilePath = outputFolder + "\\" + currentSectionTitle + ".txt"; -// saveSection(currentSection, outputFolder, currentSectionTitle, realleve, outputFilePath, realTitle,outputFolder,fileId); -// currentSection = new XWPFDocument(); -// } -// currentSectionTitle = paragraph.getText().trim().replaceAll("[/\\\\:*?|]", "&"); -// realTitle = title; -// realleve = type; -// } -// if (type.equals("2")) { -// //二级标题 -// Map aa = list.get(list.size() - 1); -// Map bb = new HashMap(); -// bb.put("type", type); -// bb.put("title", title); -// String t = paragraph.getText().trim().replaceAll("[/\\\\:*?|]", "&"); -// t = t.replaceAll(" ","_"); -// bb.put("docUrl", outputFolder + "\\" + t + ".txt"); -// List bl = (List) aa.get("list"); -// bl.add(bb); -// aa.put("list", bl); -// -// if (!currentSectionTitle.isEmpty()) { -// currentSectionTitle = currentSectionTitle.replace(" ","_"); -// String outputFilePath = outputFolder + "\\" + currentSectionTitle + ".txt"; -// saveSection(currentSection, outputFolder, currentSectionTitle, realleve, outputFilePath, realTitle,outputFolder,fileId); -// currentSection = new XWPFDocument(); -// } -// currentSectionTitle = paragraph.getText().trim().replaceAll("[/\\\\:*?|]", "&"); -// realTitle = title; -// realleve = type; -// } -// if (type.equals("3")) { -// //二级标题 -// Map aa = list.get(list.size() - 1); -// Map bb = new HashMap(); -// bb.put("type", type); -// bb.put("title", title); -// String t = paragraph.getText().trim().replaceAll("[/\\\\:*?|]", "&"); -// t = t.replaceAll(" ","_"); -// bb.put("docUrl", outputFolder + "\\" + t + ".txt"); -// List bl = (List) aa.get("list"); -// bl.add(bb); -// aa.put("list", bl); -// -// -// if (!currentSectionTitle.isEmpty()) { -// currentSectionTitle = currentSectionTitle.replace(" ","_"); -// String outputFilePath = outputFolder + "\\" + currentSectionTitle + ".txt"; -// saveSection(currentSection, outputFolder, currentSectionTitle, realleve, outputFilePath, realTitle,outputFolder,fileId); -// currentSection = new XWPFDocument(); -// } -// currentSectionTitle = paragraph.getText().trim().replaceAll("[/\\\\:*?|]", "&"); -// realTitle = title; -// realleve = type; -// } -// if (type.equals("4")) { -// //二级标题 -// Map aa = list.get(list.size() - 1); -// Map bb = new HashMap(); -// bb.put("type", type); -// bb.put("title", title); -// String t = paragraph.getText().trim().replaceAll("[/\\\\:*?|]", "&"); -// t = t.replaceAll(" ","_"); -// bb.put("docUrl", outputFolder + "\\" + t + ".txt"); -// -// List bl = (List) aa.get("list"); -// bl.add(bb); -// aa.put("list", bl); -// -// -// if (!currentSectionTitle.isEmpty()) { -// currentSectionTitle = currentSectionTitle.replace(" ","_"); -// String outputFilePath = outputFolder + "\\" + currentSectionTitle + ".txt"; -// saveSection(currentSection, outputFolder, currentSectionTitle, realleve, outputFilePath, realTitle,outputFolder,fileId); -// currentSection = new XWPFDocument(); -// } -// currentSectionTitle = paragraph.getText().trim().replaceAll("[/\\\\:*?|]", "&");; -// realTitle = title; -// realleve = type; -// } -// -// if (type.equals("5")) { -// //二级标题 -// Map aa = list.get(list.size() - 1); -// Map bb = new HashMap(); -// bb.put("type", type); -// bb.put("title", title); -// String t = paragraph.getText().trim().replaceAll("[/\\\\:*?|]", "&"); -// t = t.replaceAll(" ","_"); -// bb.put("docUrl", outputFolder + "\\" + t + ".txt"); -// List bl = (List) aa.get("list"); -// bl.add(bb); -// aa.put("list", bl); -// -// -// if (!currentSectionTitle.isEmpty()) { -// currentSectionTitle = currentSectionTitle.replace(" ","_"); -// String outputFilePath = outputFolder + "\\" + currentSectionTitle + ".txt"; -// saveSection(currentSection, outputFolder, currentSectionTitle, realleve, outputFilePath, realTitle,outputFolder,fileId); -// currentSection = new XWPFDocument(); -// } -// currentSectionTitle = paragraph.getText().trim().replaceAll("[/\\\\:*?|]", "&");; -// realTitle = title; -// realleve = type; -// } -// if (type.equals("6")) { -// //二级标题 -// Map aa = list.get(list.size() - 1); -// Map bb = new HashMap(); -// bb.put("type", type); -// bb.put("title", title); -// String t = paragraph.getText().trim().replaceAll("[/\\\\:*?|]", "&"); -// t = t.replaceAll(" ","_"); -// bb.put("docUrl", outputFolder + "\\" + t + ".txt"); -// List bl = (List) aa.get("list"); -// bl.add(bb); -// aa.put("list", bl); -// -// -// if (!currentSectionTitle.isEmpty()) { -// currentSectionTitle = currentSectionTitle.replace(" ","_"); -// String outputFilePath = outputFolder + "\\" + currentSectionTitle + ".txt"; -// saveSection(currentSection, outputFolder, currentSectionTitle, realleve, outputFilePath, realTitle,outputFolder,fileId); -// currentSection = new XWPFDocument(); -// } -// currentSectionTitle = paragraph.getText().trim().replaceAll("[/\\\\:*?|]", "&");; -// realTitle = title; -// realleve = type; -// } -// -// -// if (type.equals("0")) { -// -// //正文 -// XWPFParagraph newParagraph = currentSection.createParagraph(); -// newParagraph.setAlignment(paragraph.getAlignment()); -// newParagraph.setSpacingAfter(paragraph.getSpacingAfter()); -// newParagraph.setSpacingBefore(2); -// newParagraph.setIndentationFirstLine(paragraph.getIndentationFirstLine()); -// newParagraph.setIndentationLeft(paragraph.getIndentationLeft()); -// newParagraph.setIndentationRight(paragraph.getIndentationRight()); -// newParagraph.setIndentationHanging(paragraph.getIndentationHanging()); -// -// -// for (XWPFRun runToCopy : paragraph.getRuns()) { -// XWPFRun newRun = newParagraph.createRun(); -// newRun.setText(runToCopy.getText(0)); -// newRun.setFontFamily(runToCopy.getFontFamily()); -// newRun.setFontSize(runToCopy.getFontSize()); -// newRun.setBold(runToCopy.isBold()); -// newRun.setItalic(runToCopy.isItalic()); -// newRun.setColor(runToCopy.getColor()); -// newRun.setFontSize(runToCopy.getFontSize()); -// } -// -// } -// } -// -// } -// -// } -// -// -// String type = String.valueOf(startsWithHeading1(currentSectionTitle).get("type")); -// String title = String.valueOf(startsWithHeading1(currentSectionTitle).get("title")); -// if (!currentSectionTitle.isEmpty()) { -// realTitle = title; -// realleve = type; -// String outputFilePath = outputFolder + "\\" + currentSectionTitle + ".txt"; -// saveSection(currentSection, outputFolder, currentSectionTitle, type, outputFilePath, realTitle,outputFolder,fileId); -// } -// levelList = list; -// // 关闭资源 -// fis.close(); -// -// -// -//// System.out.println(docList.get(0).getDocUrl()); -// int a = test1Mapper.insertDocList(docList); -// -// docList = new ArrayList<>(); -// -// getLevelInfo(); -// -// } catch (IOException e) { -// e.printStackTrace(); -// } -// } - - public void testWordBattleAdd(FileInputStream fileInputStream,String outputFolder,Integer fileId,List list) { - levelList = new ArrayList<>(); - ZhySetInfo zs = new ZhySetInfo(); - zs.setName("imgSize"); - List info = zhySetInfoMapper.selectZhySetInfoList(zs); - String picSize = info.get(0).getContent(); - try { - // 创建文件输入流 - FileInputStream fis = fileInputStream; - XWPFDocument document = new XWPFDocument(fis); - // 遍历段落,寻找标题并拆分 - List paragraphs = document.getParagraphs(); - String currentSectionTitle = ""; - String realTitle = ""; - String realleve = ""; - XWPFDocument currentSection = new XWPFDocument(); - //处理图片 - for (int c = 0; c < paragraphs.size(); c++) { - XWPFParagraph paragraph = paragraphs.get(c); + public static Map startsWithHeading1(String text,FileUploadDTO fileUploadDTO) { + //一级标题 + System.out.println(fileUploadDTO.getFirstTitle()); + String first = fileUploadDTO.getFirstTitle(); + //二级标题 + String second = fileUploadDTO.getSecondTitle(); + //三级标题 + String third = fileUploadDTO.getThirdTitle(); + //四级标题 + String fourth = fileUploadDTO.getFourthTitle(); + //五级标题 + String fiveth = fileUploadDTO.getFiveTitle(); + //六级标题 + String sixth = fileUploadDTO.getSixTitle(); + //七级标题 + String seventh = fileUploadDTO.getSevenTitle(); + + int type = 0; + String title = ""; + Map contentInfo = getLevel(text,first); + //一级标题 + Map newMap = new HashMap(); + + System.out.println(contentInfo.get("content")); + if(!contentInfo.get("content").equals("查看下一级")){ + type = 1; + title = contentInfo.get("title").toString(); + newMap.put("type",1); + newMap.put("title",title); + return newMap; - List runs = paragraph.getRuns(); - if (runs != null) { - String imgs = ""; - for (int rIndex = 0; rIndex < runs.size(); rIndex++) { - XWPFRun run = runs.get(rIndex); - CTR ctr = run.getCTR(); - if (run.getEmbeddedPictures().size() > 0) { - List pictures = run.getEmbeddedPictures(); - for (XWPFPicture picture : pictures) { - XWPFPictureData pictureData = picture.getPictureData(); - byte[] imageData = pictureData.getData(); - // 将图片数据转换为 Base64 编码的字符串 - String base64Image = Base64.getEncoder().encodeToString(imageData); - String contentType = getContentType(pictureData.getPictureType()); - - // 构建 HTML 字符串 - String imgTag = "
" + - "\n" + "
"; - imgs = imgs + imgTag; - } + } + if(!second.equals("")){ + contentInfo = getLevel(text,second); + if(!contentInfo.get("content").equals("查看下一级")){ + type = 2; + title = contentInfo.get("title").toString(); + newMap.put("type",2); + newMap.put("title",title); + return newMap; - } - if (!imgs.equals("")) { - run.setText(imgs, 0); - imgs = ""; - } - } - } } + } + if(!third.equals("")){ + contentInfo = getLevel(text,third); + if(!contentInfo.get("content").equals("查看下一级")){ + type = 3; + title = contentInfo.get("title").toString(); + newMap.put("type",3); + newMap.put("title",title); + return newMap; - for (int c = 0; c < paragraphs.size(); c++) { + } + } + if(!fourth.equals("")){ + contentInfo = getLevel(text,fourth); + if(!contentInfo.get("content").equals("查看下一级")){ + type = 4; + title = contentInfo.get("title").toString(); + newMap.put("type",4); + newMap.put("title",title); + return newMap; - XWPFParagraph paragraph = paragraphs.get(c); + } + } - List runs = paragraph.getRuns(); + if(!fiveth.equals("")){ + contentInfo = getLevel(text,fiveth); + if(!contentInfo.get("content").equals("查看下一级")){ + type = 5; + title = contentInfo.get("title").toString(); + newMap.put("type",5); + newMap.put("title",title); + return newMap; + + } + } + if(!sixth.equals("")){ + contentInfo = getLevel(text,sixth); + if(!contentInfo.get("content").equals("查看下一级")){ + type = 6; + title = contentInfo.get("title").toString(); + newMap.put("type",6); + newMap.put("title",title); + return newMap; - if (paragraph.getRuns().size() > 0) { - XWPFRun run = paragraph.getRuns().get(0); - String textss = ""; - List charList = new ArrayList<>(); + } + } + if(!seventh.equals("")){ + contentInfo = getLevel(text,seventh); + if(!contentInfo.get("content").equals("查看下一级")){ + type = 7; + title = contentInfo.get("title").toString(); + newMap.put("type",7); + newMap.put("title",title); + return newMap; - if (paragraph.getRuns().size() == 1) { - textss = String.valueOf(paragraph.getRuns().get(0)); - } else { - for (int aa = 0; aa < paragraph.getRuns().size(); aa++) { - textss = textss + paragraph.getRuns().get(aa); - } - } + } + } + newMap.put("type",0); + newMap.put("title",title); + return newMap; - String type = String.valueOf(startsWithHeading1(textss).get("type")); - String title = String.valueOf(startsWithHeading1(textss).get("title")); - String url = String.valueOf(startsWithHeading1(textss).get("docUrl")); - //判断文件是否为空 - if (!textss.equals("")) { - //判断为几级标题 - if (type.equals("1")) { - //一级标题 - Map mm = new HashMap(); - List aa = new ArrayList<>(); - mm.put("title", title); - mm.put("list", aa); - String t = paragraph.getText().trim().replaceAll("[/\\\\:*?|]", "&"); - t = t.replaceAll(" ","_"); + } - System.out.println(outputFolder + "\\" + t + ".txt"); - mm.put("docUrl", outputFolder + "\\" + t + ".txt"); - list.add(mm); - if (!currentSectionTitle.isEmpty()) { - currentSectionTitle = currentSectionTitle.replace(" ","_"); - String outputFilePath = outputFolder + "\\" + currentSectionTitle + ".txt"; - saveSectionBattle(currentSection, outputFolder, currentSectionTitle, realleve, outputFilePath, realTitle,outputFolder,fileId); - currentSection = new XWPFDocument(); - } - currentSectionTitle = paragraph.getText().trim().replaceAll("[/\\\\:*?|]", "&"); - realTitle = title; - realleve = type; - } - if (type.equals("2")) { - //二级标题 - Map aa = list.get(list.size() - 1); - Map bb = new HashMap(); - bb.put("type", type); - bb.put("title", title); - String t = paragraph.getText().trim().replaceAll("[/\\\\:*?|]", "&"); - t = t.replaceAll(" ","_"); - bb.put("docUrl", outputFolder + "\\" + t + ".txt"); - List bl = (List) aa.get("list"); - bl.add(bb); - aa.put("list", bl); + //专门处理 + public static Map getLevel(String text,String temple){ + + + + //处理一级标题 + String result = filterNumbers(temple); + String inputFormat = extractNumberFormat(temple); + //获取最后一个字 + System.out.println(temple); + System.out.println("--------------------"); + char lastChar = temple.charAt(temple.length() - 1); + System.out.println("过滤后模板标题: " + result); + System.out.println("检测到的数字格式: " + inputFormat); + + //获取对应位置的字符串数量 + int aa = temple.length()+2; + String useTT = getFirstNChars(text, aa); + String textResult = filterNumbers(useTT); + + // 比较数字格式 + boolean formatsMatch = compareNumberFormats(temple, useTT); + Map info = new HashMap(); + + + if(result.equals("")){ + if (textResult.equals("")){ + System.out.println("是一级标题"); + // 在实际标题中查找这个字符第一次出现的位置 + int position = text.indexOf(lastChar); + + if (position == -1) { + // 如果没有找到,返回整个实际标题 + System.out.println("没有"); + info.put("title",text); + info.put("type",1); + info.put("content","标题"); + return info; + }else { + String content = text.substring(position + 1).trim(); + info.put("title",content); + info.put("type",1); + info.put("content","标题"); + return info; + } - if (!currentSectionTitle.isEmpty()) { - currentSectionTitle = currentSectionTitle.replace(" ","_"); - String outputFilePath = outputFolder + "\\" + currentSectionTitle + ".txt"; - saveSectionBattle(currentSection, outputFolder, currentSectionTitle, realleve, outputFilePath, realTitle,outputFolder,fileId); - currentSection = new XWPFDocument(); - } - currentSectionTitle = paragraph.getText().trim().replaceAll("[/\\\\:*?|]", "&"); - realTitle = title; - realleve = type; - } - if (type.equals("3")) { - //二级标题 - Map aa = list.get(list.size() - 1); - Map bb = new HashMap(); - bb.put("type", type); - bb.put("title", title); - String t = paragraph.getText().trim().replaceAll("[/\\\\:*?|]", "&"); - t = t.replaceAll(" ","_"); - bb.put("docUrl", outputFolder + "\\" + t + ".txt"); - List bl = (List) aa.get("list"); - bl.add(bb); - aa.put("list", bl); + }else { + System.out.println("不是"); + } + } + else { + if(textResult.contains(result)){ + if (formatsMatch) { + System.out.println("判断: 数字格式匹配,可能是同级标题"); + int position = text.indexOf(lastChar); + + if (position == -1) { + // 如果没有找到,返回整个实际标题 + System.out.println("没有"); + info.put("title",text); + info.put("type",1); + info.put("content","标题"); + return info; + }else { + String content = text.substring(position + 1).trim(); + info.put("title",content); + info.put("type",1); + info.put("content","标题"); + return info; + } + } else { + System.out.println("判断: 数字格式不匹配,不是同级标题"); + } + }else { + System.out.println("判断: 不是一级标题"); + } + } - if (!currentSectionTitle.isEmpty()) { - currentSectionTitle = currentSectionTitle.replace(" ","_"); - String outputFilePath = outputFolder + "\\" + currentSectionTitle + ".txt"; - saveSectionBattle(currentSection, outputFolder, currentSectionTitle, realleve, outputFilePath, realTitle,outputFolder,fileId); - currentSection = new XWPFDocument(); - } - currentSectionTitle = paragraph.getText().trim().replaceAll("[/\\\\:*?|]", "&"); - realTitle = title; - realleve = type; - } - if (type.equals("4")) { - //二级标题 - Map aa = list.get(list.size() - 1); - Map bb = new HashMap(); - bb.put("type", type); - bb.put("title", title); - String t = paragraph.getText().trim().replaceAll("[/\\\\:*?|]", "&"); - t = t.replaceAll(" ","_"); - bb.put("docUrl", outputFolder + "\\" + t + ".txt"); + info.put("content","查看下一级"); - List bl = (List) aa.get("list"); - bl.add(bb); - aa.put("list", bl); + return info; - if (!currentSectionTitle.isEmpty()) { - currentSectionTitle = currentSectionTitle.replace(" ","_"); - String outputFilePath = outputFolder + "\\" + currentSectionTitle + ".txt"; - saveSectionBattle(currentSection, outputFolder, currentSectionTitle, realleve, outputFilePath, realTitle,outputFolder,fileId); - currentSection = new XWPFDocument(); - } - currentSectionTitle = paragraph.getText().trim().replaceAll("[/\\\\:*?|]", "&");; - realTitle = title; - realleve = type; - } + } - if (type.equals("5")) { - //二级标题 - Map aa = list.get(list.size() - 1); - Map bb = new HashMap(); - bb.put("type", type); - bb.put("title", title); - String t = paragraph.getText().trim().replaceAll("[/\\\\:*?|]", "&"); - t = t.replaceAll(" ","_"); - bb.put("docUrl", outputFolder + "\\" + t + ".txt"); - List bl = (List) aa.get("list"); - bl.add(bb); - aa.put("list", bl); + // 中文数字字符集 + private static final String[] CHINESE_DIGITS = { + "零", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十", + "百", "千", "万", "亿", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖", "拾" + }; - if (!currentSectionTitle.isEmpty()) { - currentSectionTitle = currentSectionTitle.replace(" ","_"); - String outputFilePath = outputFolder + "\\" + currentSectionTitle + ".txt"; - saveSectionBattle(currentSection, outputFolder, currentSectionTitle, realleve, outputFilePath, realTitle,outputFolder,fileId); - currentSection = new XWPFDocument(); - } - currentSectionTitle = paragraph.getText().trim().replaceAll("[/\\\\:*?|]", "&");; - realTitle = title; - realleve = type; - } - if (type.equals("6")) { - //二级标题 - Map aa = list.get(list.size() - 1); - Map bb = new HashMap(); - bb.put("type", type); - bb.put("title", title); - String t = paragraph.getText().trim().replaceAll("[/\\\\:*?|]", "&"); - t = t.replaceAll(" ","_"); - bb.put("docUrl", outputFolder + "\\" + t + ".txt"); - List bl = (List) aa.get("list"); - bl.add(bb); - aa.put("list", bl); + // 阿拉伯数字正则表达式 + private static final Pattern ARABIC_DIGITS_PATTERN = Pattern.compile("[0-9]+"); + // 中文数字正则表达式 + private static final Pattern CHINESE_DIGITS_PATTERN; - if (!currentSectionTitle.isEmpty()) { - currentSectionTitle = currentSectionTitle.replace(" ","_"); - String outputFilePath = outputFolder + "\\" + currentSectionTitle + ".txt"; - saveSectionBattle(currentSection, outputFolder, currentSectionTitle, realleve, outputFilePath, realTitle,outputFolder,fileId); - currentSection = new XWPFDocument(); - } - currentSectionTitle = paragraph.getText().trim().replaceAll("[/\\\\:*?|]", "&");; - realTitle = title; - realleve = type; - } + static { + // 构建中文数字正则表达式 + StringBuilder chinesePatternBuilder = new StringBuilder(); + for (String digit : CHINESE_DIGITS) { + chinesePatternBuilder.append(Pattern.quote(digit)).append("|"); + } + String chinesePattern = chinesePatternBuilder.substring(0, chinesePatternBuilder.length() - 1); + CHINESE_DIGITS_PATTERN = Pattern.compile("(" + chinesePattern + ")+"); + } + /** + * 过滤标题中的中文数字和阿拉伯数字 + * @param title 原始标题 + * @return 过滤后的标题 + */ + public static String filterNumbers(String title) { + if (title == null || title.isEmpty()) { + return title; + } - if (type.equals("0")) { + // 移除阿拉伯数字 + String result = removeArabicDigits(title); - //正文 - XWPFParagraph newParagraph = currentSection.createParagraph(); - newParagraph.setAlignment(paragraph.getAlignment()); - newParagraph.setSpacingAfter(paragraph.getSpacingAfter()); - newParagraph.setSpacingBefore(2); - newParagraph.setIndentationFirstLine(paragraph.getIndentationFirstLine()); - newParagraph.setIndentationLeft(paragraph.getIndentationLeft()); - newParagraph.setIndentationRight(paragraph.getIndentationRight()); - newParagraph.setIndentationHanging(paragraph.getIndentationHanging()); + // 移除中文数字 + result = removeChineseDigits(result); + return result.trim(); + } - for (XWPFRun runToCopy : paragraph.getRuns()) { - XWPFRun newRun = newParagraph.createRun(); - newRun.setText(runToCopy.getText(0)); - newRun.setFontFamily(runToCopy.getFontFamily()); - newRun.setFontSize(runToCopy.getFontSize()); - newRun.setBold(runToCopy.isBold()); - newRun.setItalic(runToCopy.isItalic()); - newRun.setColor(runToCopy.getColor()); - newRun.setFontSize(runToCopy.getFontSize()); - } + /** + * 移除阿拉伯数字 + */ + private static String removeArabicDigits(String text) { + Matcher matcher = ARABIC_DIGITS_PATTERN.matcher(text); + return matcher.replaceAll(""); + } - } - } + /** + * 移除中文数字 + */ + private static String removeChineseDigits(String text) { + String result = text; + for (String digit : CHINESE_DIGITS) { + result = result.replace(digit, ""); + } + return result; + } - } + /** + * 提取标题中的数字格式(保留数字但规范化格式) + */ + public static String extractNumberFormat(String title) { + if (title == null || title.isEmpty()) { + return ""; + } - } + // 提取阿拉伯数字 + String arabicResult = extractArabicDigits(title); + // 提取中文数字 + String chineseResult = extractChineseDigits(title); - String type = String.valueOf(startsWithHeading1(currentSectionTitle).get("type")); - String title = String.valueOf(startsWithHeading1(currentSectionTitle).get("title")); - if (!currentSectionTitle.isEmpty()) { - realTitle = title; - realleve = type; - String outputFilePath = outputFolder + "\\" + currentSectionTitle + ".txt"; - saveSectionBattle(currentSection, outputFolder, currentSectionTitle, type, outputFilePath, realTitle,outputFolder,fileId); - } - battleLevelList = list; - // 关闭资源 - fis.close(); - int a = test1Mapper.insertBattleList(battleList); + return arabicResult + chineseResult; + } - battleList = new ArrayList<>(); + /** + * 提取阿拉伯数字 + */ + private static String extractArabicDigits(String text) { + Matcher matcher = ARABIC_DIGITS_PATTERN.matcher(text); + StringBuilder result = new StringBuilder(); + while (matcher.find()) { + result.append("[数字]"); + } + return result.toString(); + } - getLevelInfoBattle(); + /** + * 提取中文数字 + */ + private static String extractChineseDigits(String text) { + Matcher matcher = CHINESE_DIGITS_PATTERN.matcher(text); + StringBuilder result = new StringBuilder(); + while (matcher.find()) { + result.append("[中文数字]"); + } + return result.toString(); + } - } catch (IOException e) { - e.printStackTrace(); + /** + * 比较两个标题的数字格式是否相同 + */ + public static boolean compareNumberFormats(String title1, String title2) { + String format1 = extractNumberFormat(title1); + String format2 = extractNumberFormat(title2); + return format1.equals(format2); + } + private static String getFirstNChars(String str, int n) { + if (str == null || n <= 0) { + return ""; } + return str.length() > n ? str.substring(0, n) : str; } - public static Map startsWithHeading1(String text) { - //判断第一个字是不是第 + public static Map startsWithHeadingOld(String text) { + + + + + //将七个标题中的文字中文数字以及阿拉伯数字筛选去掉留下剩下的字为一个字符串 + + List charList = new ArrayList<>(); //判断是第几章 diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ZhyFileManageServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ZhyFileManageServiceImpl.java index 964aeb2..0b794c7 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ZhyFileManageServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ZhyFileManageServiceImpl.java @@ -43,10 +43,10 @@ public class ZhyFileManageServiceImpl { @Autowired Test1Mapper test1Mapper; - public String wordSplitter(FileInputStream file,String url,Integer fileId,List list){ + public String wordSplitter(FileInputStream file,String url,Integer fileId,List list,FileUploadDTO fileUploadDTO){ try { if(file!=null){ - wordSplitter.testWordOne(file,url,fileId); + wordSplitter.testWordOne(file,url,fileId,fileUploadDTO); }else{ wordSplitter.handWord(url,list); } @@ -57,9 +57,13 @@ public class ZhyFileManageServiceImpl { return "b"; } - public String wordSplitterBattle(FileInputStream file,String url,Integer fileId){ + public String wordSplitterOld(FileInputStream file,String url,Integer fileId,List list){ try { - wordSplitter.testWordBattle(file,url,fileId); + if(file!=null){ + wordSplitter.testWordOneOld(file,url,fileId); + }else{ + wordSplitter.handWord(url,list); + } return "a"; } catch (Exception e) { e.printStackTrace(); @@ -67,26 +71,12 @@ public class ZhyFileManageServiceImpl { return "b"; } -// public String wordSplitterAdd(FileInputStream file,String url,Integer fileId,List list){ -// try { -// wordSplitter.testWordOneAdd(file,url,fileId,list); -// return "a"; -// } catch (Exception e) { -// e.printStackTrace(); -// } -// return "b"; -// } - - public String wordSplitterBattleAdd(FileInputStream file,String url,Integer fileId,List list){ - try { - wordSplitter.testWordBattleAdd(file,url,fileId,list); - return "a"; - } catch (Exception e) { - e.printStackTrace(); - } - return "b"; - } + + + + + diff --git a/ruoyi-api/src/main/resources/mapper/api/TitleTemplateMapper.xml b/ruoyi-system/src/main/resources/mapper/system/TitleTemplateMapper.xml similarity index 74% rename from ruoyi-api/src/main/resources/mapper/api/TitleTemplateMapper.xml rename to ruoyi-system/src/main/resources/mapper/system/TitleTemplateMapper.xml index e25034e..7a64a31 100644 --- a/ruoyi-api/src/main/resources/mapper/api/TitleTemplateMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/TitleTemplateMapper.xml @@ -2,7 +2,7 @@ - + @@ -11,10 +11,15 @@ + + + + + - select id, name, first_title, second_title, third_title, fourth_title from title_template + select id, name, first_title, second_title, third_title, fourth_title,five_title,six_title,seven_title from title_template @@ -41,6 +49,9 @@ second_title, third_title, fourth_title, + five_title, + six_title, + seven_title, #{name}, @@ -48,6 +59,9 @@ #{secondTitle}, #{thirdTitle}, #{fourthTitle}, + #{fiveTitle}, + #{sixTitle}, + #{sevenTitle}, @@ -59,6 +73,9 @@ second_title = #{secondTitle}, third_title = #{thirdTitle}, fourth_title = #{fourthTitle}, + five_title = #{fiveTitle}, + six_title = #{sixTitle}, + seven_title = #{sevenTitle}, where id = #{id} diff --git a/ruoyi-ui/src/api/system/titleTemplate.js b/ruoyi-ui/src/api/system/titleTemplate.js new file mode 100644 index 0000000..f60db4f --- /dev/null +++ b/ruoyi-ui/src/api/system/titleTemplate.js @@ -0,0 +1,50 @@ +import request from '@/utils/request' + +export function listTemplate(query) { + return request({ + url: '/system/template/list', + method: 'get', + params: query + }) +} + +export function getTemplate(id) { + return request({ + url: '/system/template/' + id, + method: 'get' + }) +} + +export function addTemplate(data) { + return request({ + url: '/system/template', + method: 'post', + data: data + }) +} + +export function updateTemplate(data) { + return request({ + url: '/system/template', + method: 'put', + data: data + }) +} + +export function delTemplate(id) { + return request({ + url: '/system/template/' + id, + method: 'delete' + }) +} + +export function titleFormatter(formData) { + return request({ + url: '/system/formatter', + method: 'post', + headers: { + 'Content-Type': 'multipart/form-data' // 必须设置这个 + }, + data: formData // 必须是 FormData 对象 + }) +} \ No newline at end of file diff --git a/ruoyi-ui/src/views/system/fileManage/index.vue b/ruoyi-ui/src/views/system/fileManage/index.vue index 4f9571e..da3f6b5 100644 --- a/ruoyi-ui/src/views/system/fileManage/index.vue +++ b/ruoyi-ui/src/views/system/fileManage/index.vue @@ -1,13 +1,10 @@