开发手账(一)

一、 关于设计

(一)数据库

  1. 确定外键标识,需判断该外键是否有可能被修改。如菜单id,菜单code,菜单名,前两者都可做外键,后面一个则不应做外键。

二、关于组件

(一)POI

1. 文档页数统计

import lombok.extern.slf4j.Slf4j;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.ofdrw.reader.OFDReader;
import org.springframework.web.multipart.MultipartFile;import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
@Slf4j
public class LvDocPageCounter {public static final String DOCUMENT_PAGE_TEMP = "DOCUMENT_PAGE_TEMP";public static int getPageCount(String filePath) {String fileType = getFileType(filePath);try {switch (fileType) {case "pdf":return getPdfPageCount(filePath);case "docx":return getDocxPageCount(filePath);case "doc":return getDocPageCount(filePath);case "ofd":return getOfdPageCount(filePath);// Add more cases for other document types as neededdefault:log.warn("不支持的文件类型:{}", filePath);return 1;
//                throw new IllegalArgumentException("Unsupported file type");}} catch (Exception e) {log.warn("读取文件异常:{},{}", filePath,e);return 0;}}/*** 文件类型* @param filePath* @return*/private static String getFileType(String filePath) {int dotIndex = filePath.lastIndexOf('.');if (dotIndex == -1 || dotIndex == filePath.length() - 1) {log.warn("文件名中没有找到扩展名:{}", filePath);return "";}return filePath.substring(dotIndex + 1).toLowerCase();}/*** 获取PDF文档页数* @param filePath* @return* @throws IOException*/private static int getPdfPageCount(String filePath) throws IOException {try (PDDocument document = Loader.loadPDF(new File(filePath))) {
//            PDDocument document = new PDDocument();int numberOfPages = document.getNumberOfPages();document.close();return numberOfPages;}}/*** 获取doc文档页数* @param filePath* @return* @throws IOException*/private static int getDocPageCount(String filePath) throws IOException {
//        try (InputStream inputStream = new FileInputStream(filePath);
//             HWPFDocument document = new HWPFDocument(inputStream)) {
//            int pageCount = document.getSummaryInformation().getPageCount();
//            document.close();
//            return pageCount;
//        }try (InputStream inputStream = new FileInputStream(filePath)) {com.aspose.words.Document doc = new com.aspose.words.Document(inputStream);int num = doc.getPageCount();doc.cleanup();return num;} catch (Exception e) {e.printStackTrace();return 0;}}/*** 获取docx页数* @param filePath* @return* @throws IOException*/private static int getDocxPageCount(String filePath) throws IOException {
//        try (InputStream inputStream = new FileInputStream(filePath);
//             XWPFDocument document = new XWPFDocument(inputStream)) {
//            int pages = document.getProperties().getExtendedProperties().getUnderlyingProperties().getPages();
//            document.close();
//            return pages;
//        }try (InputStream inputStream = new FileInputStream(filePath)) {com.aspose.words.Document doc = new com.aspose.words.Document(inputStream);int num = doc.getPageCount();doc.cleanup();return num;} catch (Exception e) {e.printStackTrace();return 0;}}/*** pdf页数* @param filePath* @return* @throws IOException*/private static int getOfdPageCount(String filePath) throws IOException {Path ofdFile = Paths.get(filePath);OFDReader ofdReader = new OFDReader(ofdFile);int numberOfPages = ofdReader.getNumberOfPages();ofdReader.close();return numberOfPages;}/*** 获取缓存文件页数* @param inputStream* @param originalFilename* @return*/public static Integer getPageCount(MultipartFile inputStream, String originalFilename) {try (InputStream inputStream1 = inputStream.getInputStream()) {return getPageCount(inputStream1,originalFilename);} catch (IOException e) {log.warn("读取文件异常:{},{}", originalFilename,e);return 0;}}// Add methods for other document types as needed
}

2. 文本提取

import cn.hutool.core.io.FileUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FilenameUtils;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.extractor.WordExtractor;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.ofdrw.converter.export.TextExporter;import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.concurrent.atomic.AtomicInteger;/*** @author yilv* @version 1.0* @description: TODO* @date 2023/11/16 16:12*/
@Slf4j
public class LvDocTxTHunter {private static AtomicInteger  UPPER_LIMIT=new AtomicInteger(50);/*** 读取文档内容* @param filePath* @return*/public static String readText(String filePath) {int pageCount = LvDocPageCounter.getPageCount(filePath);if (pageCount >UPPER_LIMIT.get()) {log.warn("文件过大:{},{}", filePath,pageCount);return "";}String fileType = getFileType(filePath);try {switch (fileType) {case "pdf":return readPdfText(filePath);case "doc":return readDocText(filePath);case "docx":return readDocxText(filePath);case "ofd":return readOfdText(filePath);// Add more cases for other document types as neededdefault:log.warn("不支持的文件类型:{}", filePath);return "";}} catch (IOException e) {log.warn("读取文件异常:{},{}", filePath,e);return "";}}/*** 获取文件类型* @param filePath* @return*/private static String getFileType(String filePath) {int dotIndex = filePath.lastIndexOf('.');if (dotIndex == -1 || dotIndex == filePath.length() - 1) {log.warn("文件名中没有找到扩展名:{}", filePath);return "";}return filePath.substring(dotIndex + 1).toLowerCase();}/*** 获取pdf文本* @param filePath* @return* @throws IOException*/private static String readPdfText(String filePath) throws IOException {try (PDDocument document = Loader.loadPDF(filePath)) {String text = new PDFTextStripper().getText(document);document.close();return text;}}/*** 获取doc文本* @param filePath* @return* @throws IOException*/private static String readDocText(String filePath) throws IOException {try (InputStream inputStream = new FileInputStream(filePath);HWPFDocument document = new HWPFDocument(inputStream)) {WordExtractor extractor = new WordExtractor(document);String text = extractor.getText();document.close();return text;}}/*** 获取docx文本* @param filePath* @return* @throws IOException*/private static String readDocxText(String filePath) throws IOException {try (InputStream inputStream = new FileInputStream(filePath);XWPFDocument document = new XWPFDocument(inputStream)) {XWPFWordExtractor extractor = new XWPFWordExtractor(document);String text = extractor.getText();document.close();return text;}}/*** pdf页数* @param filePath* @return* @throws IOException*/private static String readOfdText(String filePath) throws IOException {Path txtPath = Paths.get("DOCUMENT_PAGE_TEMP", FilenameUtils.getBaseName(filePath) + ".txt");TextExporter textExporter = new TextExporter(Paths.get(filePath), txtPath);textExporter.export();String s = FileUtil.readUtf8String(txtPath.toFile());textExporter.close();return s;}/*** 获取文件文本* @param tempFile* @return*/public static String readText(File tempFile) {return readText(tempFile.getPath());}// Add methods for other document types as needed
}

3. 文案转换

  • ofd转换
    • ①启动加载字体
    /*** 前置系统数据加载*/private static void systemInit() {FontLoader preload = FontLoader.Preload();preload.scanFontDir(Paths.get(FileUtil.local, "font"));Field namePathMapping = ReflectUtil.getField(FontLoader.class, "fontNamePathMapping");Map<String, String> fontNamePathMapping = (Map<String, String>) ReflectUtil.getFieldValue(preload,namePathMapping);System.out.println("加载字体:" + JSONUtil.toJsonStr(fontNamePathMapping.keySet()));}
    • ②使用ofdrw进行pdf转换
    /*** 将OFD转换为PDF** @param ofdPath OFD路径* @param distPath 输出路径* @param pdfPath 输出PDF路径* @throws IOException*/public static void convertOfdToPDFByBridge(String ofdPath, String distPath, String pdfPath) throws IOException {log.debug("解析文件:{}",ofdPath);Path ofdFilePath = Paths.get(ofdPath);Path dir = Paths.get(distPath);PDFExporterIText exporter = new PDFExporterIText(ofdFilePath, Paths.get(pdfPath));exporter.export();exporter.close();}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/155288.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

CISP模拟试题(六)

免责声明 文章仅做经验分享用途,利用本文章所提供的信息而造成的任何直接或者间接的后果及损失,均由使用者本人负责,作者不为此承担任何责任,一旦造成后果请自行承担!!! 1、下列对于信息安全保障深度防御模型的说法错误的是: A、信息安全外部环境、信息安全保障是组织…

凸包的学习之路

凸包的学习之路-CSDN博客 5.算法策略5&#xff1a;Graham Scan Algorithm 算法思路&#xff1a; 给定二维点集&#xff0c;求其凸包 1&#xff09;presorting&#xff1a; &#xff08;1&#xff09;先找到 ltl点 &#xff0c;也就是y值最小的点&#xff0c;若是存在y值相…

thinkphp8 DB_PREFIX 属性

设计表的时候使用**_user, **就是前缀&#xff0c;DB_PREFIX就是默认把前缀给去掉 在config/database.php prefix&#xff0c;改成你的前缀&#xff0c;数据库的表重命名‘ltf_user’ 代码调用 $user Db::name("user")->select();return json($user);之前是使用…

css取消移动端长按元素背景色

在开发微信小程序的时候&#xff0c;发现有的元素长按之后&#xff0c;出现了讨厌人的背景色&#xff0c;这就很奇怪&#xff0c;就想把它去掉&#xff0c;所以这里教一下方法&#xff1a; 在所在元素添加css样式&#xff1a; // 取消长按的背景色-webkit-tap-highlight-color:…

674. 最长连续递增序列

给定一个未经排序的整数数组&#xff0c;找到最长且 连续递增的子序列&#xff0c;并返回该序列的长度。 连续递增的子序列 可以由两个下标 l 和 r&#xff08;l < r&#xff09;确定&#xff0c;如果对于每个 l < i < r&#xff0c;都有 nums[i] < nums[i 1] &a…

解放双手!一键助你快速发圈、批量加好友,好用哭了!

朋友们&#xff0c;你们有没有经历过管理多个微信账号的繁琐和压力&#xff1f; 会不会因为忙不过来&#xff0c;忘记及时回复客户&#xff0c;错过了推广的时机&#xff1f; 别担心&#xff0c;现在有了微信管理系统&#xff0c;一切都变得简单轻松起来&#xff01; 微信管…

03-瑞吉外卖关于菜品/套餐分类表的增删改查

新增菜品/套餐分类 页面原型 当我们在后台系统中添加菜品/套餐时,需要选择一个菜品/套餐分类,在移动端也会按照菜品分类和套餐分类来展示对应的菜品和套餐 第一步: 用户点击确定按钮执行submitForm函数发送Ajax请求,将新增菜品/套餐表单中输入的数据以json形式提交给服务端,…

Apache DolphinScheduler 3.0.0 升级到 3.1.8 教程

安装部署的流程可参考官网的文档 Version 3.1.8/部署指南/伪集群部署(Pseudo-Cluster) https://dolphinscheduler.apache.org/zh-cn/docs/3.1.8/guide/installation/pseudo-cluster 本文开始之前&#xff0c;我先补充说明一下升级 Apache DolphinScheduler 的几个关键点 元数…

低代码服务商,中小型数字化软件服务商的新出路

数字化时代大背景下&#xff0c;企业信息化向数字化转型成为所有企业发展的必由之路&#xff0c;企业在对业务模式、流程、组织形式、信息技术等方面进行重新定义时&#xff0c;软件必然参与价值创造的全过程&#xff0c;这势必驱使软件成为推动数字化转型的“引擎”&#xff0…

debian 12 配置

1. 修改apt源 修改apt源为http版本 # 默认注释了源码镜像以提高 apt update 速度&#xff0c;如有需要可自行取消注释 deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware # deb-src http://mirrors.tuna.tsinghua.edu.cn/d…

文化传承与数字技术的完美结合:十八数藏的新纪元

在这数字化的时代&#xff0c;十八数藏犹如一座连接过去与未来的桥梁&#xff0c;展现出文化传承与数字技术完美结合的新纪元。十八数藏以其独特的视角&#xff0c;将传统文化注入现代数字技术的脉络&#xff0c;呈现出一幅文化传承的全新画卷。 十八数藏的文化传承并不是简单的…

软件测评中心进行安全测试有哪些流程?安全测试报告如何收费?

在当今数字化时代&#xff0c;软件安全测试是每个软件开发团队都不能忽视的重要环节。安全测试是指对软件产品进行系统、全面的安全性评测与检测的过程。它旨在发现并修复软件中存在的漏洞和安全隐患&#xff0c;以确保软件能够在使用过程中保护用户的数据和隐私不被非法访问和…

深入了解Java 8 新特性:Stream流的实践应用(二)

阅读建议 嗨&#xff0c;伙计&#xff01;刷到这篇文章咱们就是有缘人&#xff0c;在阅读这篇文章前我有一些建议&#xff1a; 本篇文章大概8000多字&#xff0c;预计阅读时间长需要10分钟&#xff08;不要害怕字数过多&#xff0c;其中有一大部分是示例代码&#xff0c;读起…

RAAGR2-Net:一种使用多个空间帧的并行处理的脑肿瘤分割网络

RAAGR2-Net: A brain tumor segmentation network using parallel processing of multiple spatial frames RAAGR2-Net&#xff1a;一种使用多个空间帧的并行处理的脑肿瘤分割网络背景贡献实验N4 bias-field-correction 数据预处理Z-score and re-sampling Z-score归一化&#…

redis高可用---持久化

redis高可用 在集群当中有一个非常重要的指标&#xff0c;提供正常服务的时间的百分比(365天) 99.9%&#xff0c;redis高可用含义更广泛&#xff0c;支持服务是指标之一&#xff0c;数据容量扩展&#xff0c;数局的安全性。&#xff08;容量、安全性&#xff09; redis中实现高…

【蓝桥杯软件赛 零基础备赛20周】第4周——简单模拟1

文章目录 什么是简单模拟简单模拟和编程能力刷题 什么是简单模拟 正在学编程语言&#xff08;C/C、Python、Java&#xff09;&#xff0c;或者刚学过语言&#xff0c;还没有开始学数据结构和算法的同学&#xff0c;有一些疑问&#xff1a;如何快速入门算法竞赛&#xff1f;如何…

数据仓库模式之详解 Inmon 和 Kimball

目录 一、前言 二、企业信息工厂&#xff08;Inmon&#xff09; 2.1 概念 2.2 主要组件 2.3 流程 三、多维数据仓库&#xff08;Kimball&#xff09; 3.1 概念 3.2 核心组件 3.3 流程 四、异同及用途对比 4.1 异同对比 4.2 特征比较 一、前言 大部分关于数据仓库构建…

小微初创企业,如何利用媒体宣传快速成长

传媒如春雨&#xff0c;润物细无声&#xff0c;大家好&#xff0c;我是51媒体网胡老师。 对于小微初创企业来说&#xff0c;利用媒体宣传可以快速提升品牌知名度、扩大影响力&#xff0c;进而促进企业的成长。 1.确定宣传目标&#xff1a;是增加销售、提升品牌知名度、还是推…

JVM对象创建与内存分配

对象的创建 对象创建的主要流程&#xff1a; 类加载推荐博客&#xff1a;JVM类加载机制详解 类加载检查 虚拟机遇到一条new指令时&#xff0c;首先将去检查这个指令的参数是否能在常量池中定位到一个类的符号引用&#xff0c;并且检查这个符号引用代表的类是否已被加载、解析…

Failed to load resource: net::ERR_UPLOAD_FILE_CHANGED 谷歌浏览器就会有这个问题 其他的浏览器没有

Failed to load resource: net::ERR_UPLOAD_FILE_CHANGED 10 10: Difficulties in file uploading through all browsers and applications