├── .gitignore ├── .idea ├── $PRODUCT_WORKSPACE_FILE$ ├── .gitignore ├── .name ├── compiler.xml ├── encodings.xml ├── inspectionProfiles │ └── Project_Default.xml ├── misc.xml └── vcs.xml ├── .mvn └── wrapper │ ├── MavenWrapperDownloader.java │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── .project ├── HELP.md ├── README.md ├── mvnw ├── mvnw.cmd ├── pom.xml └── src ├── log4j.properties ├── main ├── java │ └── com │ │ └── tangerineSpecter │ │ └── javaBaseUtils │ │ ├── JavaBaseUtilsApplication.java │ │ ├── common │ │ ├── DocumentInfo.java │ │ ├── annotation │ │ │ ├── ClassInfo.java │ │ │ └── MethodInfo.java │ │ ├── config │ │ │ └── SwaggerConfig.java │ │ ├── exception │ │ │ └── GlobalException.java │ │ ├── filter │ │ │ └── ManageLogAspect.java │ │ ├── img │ │ │ └── show_logo.gif │ │ ├── servlet │ │ │ ├── AppRunWrapper.java │ │ │ └── InitProperties.java │ │ ├── test │ │ │ └── UtilTest.java │ │ └── util │ │ │ ├── AudioUtils.java │ │ │ ├── Base64Utils.java │ │ │ ├── BaseUtils.java │ │ │ ├── CollUtils.java │ │ │ ├── Constant.java │ │ │ ├── DecipheringBaseUtils.java │ │ │ ├── DecipheringUtils.java │ │ │ ├── DirUtils.java │ │ │ ├── EasyExcelUtils.java │ │ │ ├── EncrypUtils.java │ │ │ ├── ExcelUtils.java │ │ │ ├── FileUtil.java │ │ │ ├── HttpUtils.java │ │ │ ├── IKTokenizerTool.java │ │ │ ├── ImageUtils.java │ │ │ ├── JsonUtils.java │ │ │ ├── LoggerWordPool.java │ │ │ ├── LollipopUtils.java │ │ │ ├── NumChainCal.java │ │ │ ├── NumberUtils.java │ │ │ ├── PDFUtils.java │ │ │ ├── QrCodeUtils.java │ │ │ ├── RandomUtils.java │ │ │ ├── RegExUtils.java │ │ │ ├── StringUtils.java │ │ │ ├── TimeUtils.java │ │ │ ├── ZipUtils.java │ │ │ ├── cache │ │ │ ├── JedisMapTool.java │ │ │ ├── JedisSetTool.java │ │ │ └── JedisTool.java │ │ │ └── enums │ │ │ └── FileTypeEnum.java │ │ └── controller │ │ └── util │ │ ├── EasyExcelController.java │ │ ├── PoiExcelController.java │ │ ├── StringController.java │ │ ├── TimeController.java │ │ └── ZipController.java └── resources │ └── application.properties └── test └── java └── com └── tangerineSpecter └── javaBaseUtils └── JavaBaseUtilsApplicationTests.java /.gitignore: -------------------------------------------------------------------------------- 1 | ## .gitignore for Grails 1.2 and 1.3 2 | 3 | # .gitignore for maven 4 | target/ 5 | *.releaseBackup 6 | 7 | # web application files 8 | #/web-app/WEB-INF 9 | 10 | # IDE support files 11 | /.classpath 12 | /.launch 13 | /.project 14 | /.settings 15 | /*.launch 16 | /*.tmproj 17 | /ivy* 18 | /eclipse 19 | 20 | # default HSQL database files for production mode 21 | /prodDb.* 22 | 23 | # general HSQL database files 24 | *Db.properties 25 | *Db.script 26 | 27 | # logs 28 | /stacktrace.log 29 | /test/reports 30 | /logs 31 | *.log 32 | *.log.* 33 | 34 | # project release file 35 | /*.war 36 | 37 | # plugin release file 38 | /*.zip 39 | /*.zip.sha1 40 | 41 | # older plugin install locations 42 | /plugins 43 | /web-app/plugins 44 | /web-app/WEB-INF/classes 45 | 46 | # "temporary" build files 47 | target/ 48 | out/ 49 | build/ 50 | 51 | # other 52 | *.iws 53 | 54 | #.gitignore for java 55 | *.class 56 | 57 | # Package Files # 58 | *.jar 59 | *.war 60 | *.ear 61 | 62 | ## .gitignore for eclipse 63 | 64 | *.pydevproject 65 | .project 66 | .metadata 67 | bin/** 68 | tmp/** 69 | tmp/**/* 70 | *.tmp 71 | *.bak 72 | *.swp 73 | *~.nib 74 | local.properties 75 | .classpath 76 | .settings/ 77 | .loadpath 78 | 79 | # External tool builders 80 | .externalToolBuilders/ 81 | 82 | # Locally stored "Eclipse launch configurations" 83 | *.launch 84 | 85 | # CDT-specific 86 | .cproject 87 | 88 | # PDT-specific 89 | .buildpath 90 | 91 | ## .gitignore for intellij 92 | 93 | *.iml 94 | *.ipr 95 | *.iws 96 | .idea/ 97 | 98 | ## .gitignore for linux 99 | .* 100 | !.gitignore 101 | *~ 102 | 103 | ## .gitignore for windows 104 | 105 | # Windows image file caches 106 | Thumbs.db 107 | ehthumbs.db 108 | 109 | # Folder config file 110 | Desktop.ini 111 | 112 | # Recycle Bin used on file shares 113 | $RECYCLE.BIN/ 114 | 115 | ## .gitignore for mac os x 116 | 117 | .DS_Store 118 | .AppleDouble 119 | .LSOverride 120 | Icon 121 | 122 | 123 | # Thumbnails 124 | ._* 125 | 126 | # Files that might appear on external disk 127 | .Spotlight-V100 128 | .Trashes 129 | 130 | ## hack for graddle wrapper 131 | !wrapper/*.jar 132 | !**/wrapper/*.jar -------------------------------------------------------------------------------- /.idea/$PRODUCT_WORKSPACE_FILE$: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /workspace.xml -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | javaBaseUtils -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 20 | 21 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 36 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.mvn/wrapper/MavenWrapperDownloader.java: -------------------------------------------------------------------------------- 1 | /* 2 | Licensed to the Apache Software Foundation (ASF) under one 3 | or more contributor license agreements. See the NOTICE file 4 | distributed with this work for additional information 5 | regarding copyright ownership. The ASF licenses this file 6 | to you under the Apache License, Version 2.0 (the 7 | "License"); you may not use this file except in compliance 8 | with the License. You may obtain a copy of the License at 9 | 10 | https://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, 13 | software distributed under the License is distributed on an 14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | KIND, either express or implied. See the License for the 16 | specific language governing permissions and limitations 17 | under the License. 18 | */ 19 | 20 | import java.io.File; 21 | import java.io.FileInputStream; 22 | import java.io.FileOutputStream; 23 | import java.io.IOException; 24 | import java.net.URL; 25 | import java.nio.channels.Channels; 26 | import java.nio.channels.ReadableByteChannel; 27 | import java.util.Properties; 28 | 29 | public class MavenWrapperDownloader { 30 | 31 | /** 32 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. 33 | */ 34 | private static final String DEFAULT_DOWNLOAD_URL = 35 | "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"; 36 | 37 | /** 38 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to 39 | * use instead of the default one. 40 | */ 41 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH = 42 | ".mvn/wrapper/maven-wrapper.properties"; 43 | 44 | /** 45 | * Path where the maven-wrapper.jar will be saved to. 46 | */ 47 | private static final String MAVEN_WRAPPER_JAR_PATH = 48 | ".mvn/wrapper/maven-wrapper.jar"; 49 | 50 | /** 51 | * Name of the property which should be used to override the default download url for the wrapper. 52 | */ 53 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; 54 | 55 | public static void main(String args[]) { 56 | System.out.println("- Downloader started"); 57 | File baseDirectory = new File(args[0]); 58 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); 59 | 60 | // If the maven-wrapper.properties exists, read it and check if it contains a custom 61 | // wrapperUrl parameter. 62 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); 63 | String url = DEFAULT_DOWNLOAD_URL; 64 | if(mavenWrapperPropertyFile.exists()) { 65 | FileInputStream mavenWrapperPropertyFileInputStream = null; 66 | try { 67 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); 68 | Properties mavenWrapperProperties = new Properties(); 69 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); 70 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); 71 | } catch (IOException e) { 72 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); 73 | } finally { 74 | try { 75 | if(mavenWrapperPropertyFileInputStream != null) { 76 | mavenWrapperPropertyFileInputStream.close(); 77 | } 78 | } catch (IOException e) { 79 | // Ignore ... 80 | } 81 | } 82 | } 83 | System.out.println("- Downloading from: : " + url); 84 | 85 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); 86 | if(!outputFile.getParentFile().exists()) { 87 | if(!outputFile.getParentFile().mkdirs()) { 88 | System.out.println( 89 | "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); 90 | } 91 | } 92 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); 93 | try { 94 | downloadFileFromURL(url, outputFile); 95 | System.out.println("Done"); 96 | System.exit(0); 97 | } catch (Throwable e) { 98 | System.out.println("- Error downloading"); 99 | e.printStackTrace(); 100 | System.exit(1); 101 | } 102 | } 103 | 104 | private static void downloadFileFromURL(String urlString, File destination) throws Exception { 105 | URL website = new URL(urlString); 106 | ReadableByteChannel rbc; 107 | rbc = Channels.newChannel(website.openStream()); 108 | FileOutputStream fos = new FileOutputStream(destination); 109 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); 110 | fos.close(); 111 | rbc.close(); 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TangerineSpecter/JavaBaseUtils/681ecd200def8b8a3b9aa5793d0959f785880db3/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip 2 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | BaseUtils 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /HELP.md: -------------------------------------------------------------------------------- 1 | # Getting Started 2 | 3 | ### Reference Documentation 4 | For further reference, please consider the following sections: 5 | 6 | * [Official Apache Maven documentation](https://maven.apache.org/guides/index.html) 7 | 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JavaBaseUtils 2 | 3 | ## 简介 4 | 主要收集一些平时常用的Java开发工具类,内容在不断更新补充中... 5 | 6 | 7 | ### Java基本工具包: 8 | - 工具包地址:https://github.com/TangerineSpecter/JavaBaseUtils 9 | 10 | ### 版本号: 11 | - 项目版本:2.0.4 12 | 13 | - JDK版本:1.8 14 | 15 | ### 最后更新时间: 16 | > 2021-08-05 17 | 18 | ## 目录 19 | 20 | - [开始](#Getting_Menu) 21 | - [API](#Geting_Api) 22 | - [PDF工具类](#Geting_PdfUtils) 23 | - [字符串处理工具类](#Geting_StringUtils) 24 | - [数字处理工具类](#Geting_NumberUtils) 25 | - [加密工具类](#Geting_EncrypUtils) 26 | - [Excel处理工具类](#Geting_ExcelUtils) 27 | - [分词工具类](#Geting_IkTokenizerTool) 28 | - [文件工具类](#Geting_FileUtil) 29 | - [路径处理工具类](#Geting_DirUtils) 30 | - [时间处理工具类](#Geting_TimeUtils) 31 | - [图片处理工具类](#Geting_ImageUtils) 32 | - [随机工具类](#Geting_RandomUtils) 33 | - [正则表达式工具类](#Geting_RegExUtils) 34 | - [二维码生成工具类](#Geting_QrCodeUtils) 35 | - [压缩和解压工具类](#Geting_ZipUtils) 36 | - [Http工具类](#Geting_HttpUtils) 37 | --- 38 | ## PDF工具类 -> [PdfUtils](https://github.com/TangerineSpecter/JavaBaseUtils/blob/master/src/common/util/PdfUtils.java) 39 | 方法名 | 说明 | 参数 | 返回结果 40 | ------|------|-----|----- 41 | createPdf | 创建PDF | 无 | void(无) 42 | createPdf | 创建PDF | String(生成路径),List(文本内容) | void(无) 43 | --- 44 | ## 字符串处理工具类 -> [StringUtils](https://github.com/TangerineSpecter/JavaBaseUtils/blob/master/src/common/util/StringUtils.java) 45 | 方法名 | 说明 | 参数 | 返回结果 46 | ------|------|-----|----- 47 | isAllNumber | 判断所有字符串是否都为数字 | String\[](字符串集) | boolean(判断结果) 48 | isAnyEmpty | 判断多个字符串中是否有空值 | String\[](字符串参数集) | boolean(判断结果) 49 | getOrderNum | 订单号生成 | 无 | String(订单号) 50 | getLocalHostIp | 获取本机IP地址 | 无 | String(IP地址) 51 | randomString | 伪随机字符串 | int(字符串长度) | String(随机结果) 52 | subString | 截取字符串开头指定长度 | String(字符串内容),int(截取位置) | String(截取结果) 53 | isEmpty | 判断字符串是否为空 | String(字符串内容) | boolean(判断结果) 54 | isNumber | 判断是否为数字 | 无 | boolean(判断结果) 55 | --- 56 | ## 数字处理工具类 -> [NumberUtils](https://github.com/TangerineSpecter/JavaBaseUtils/blob/master/src/common/util/NumberUtils.java) 57 | 方法名 | 说明 | 参数 | 返回结果 58 | ------|------|-----|----- 59 | getFullPermutation | 从Array中拿出n个元素进行全排列 | char\[](字符数组),int(取出的元素个数) | void(无) 60 | getFullPermutation | 从Array中拿出n个元素进行全排列 | int\[](数字数组),int(需要取出的元素个数) | List(排列结果) 61 | listAll | 从m个元素中任取n个并对结果进行全排列 | List(装载排列结果list),int\[](数字数组),int(取出的元素个数) | void(无) 62 | listAll | 从m个元素中任取n个并对结果进行全排列 | List(装载排列结果list),char\[](字符数组),int(取出的元素个数) | void(无) 63 | --- 64 | ## 加密工具类 -> [EncrypUtils](https://github.com/TangerineSpecter/JavaBaseUtils/blob/master/src/common/util/EncrypUtils.java) 65 | 方法名 | 说明 | 参数 | 返回结果 66 | ------|------|-----|----- 67 | hash | 哈希加密算法 | String(需要加密的数据),String(加密算法名称) | String(加密数据) 68 | hash | 哈希加密算法 | byte\[](加密字节数组),String(加密算法名称) | String(加密数据) 69 | encodeHex | 将字节数组转换成十六进制字符串 | byte\[](字节数组) | String(十六进制字符串) 70 | --- 71 | ## Excel处理工具类 -> [ExcelUtils](https://github.com/TangerineSpecter/JavaBaseUtils/blob/master/src/common/util/ExcelUtils.java) 72 | 方法名 | 说明 | 参数 | 返回结果 73 | ------|------|-----|----- 74 | getExcel | 获取Excel数据 | String(Excel路径) | List(数据列表) 75 | createExcel | 创建Excel | String\[](表头),List(数据列表),boolean(新旧版本) | String(生成路径) 76 | --- 77 | ## 分词工具类 -> [IkTokenizerTool](https://github.com/TangerineSpecter/JavaBaseUtils/blob/master/src/common/util/IkTokenizerTool.java) 78 | 方法名 | 说明 | 参数 | 返回结果 79 | ------|------|-----|----- 80 | tokenizeKeyWord | 切分分词 | String(关键词),boolean(智能切分) | String(分词结果) 81 | tokenizeKeyWordList | 切分分词 | String(关键词),boolean(智能切分) | List(分词结果) 82 | --- 83 | ## 文件工具类 -> [FileUtil](https://github.com/TangerineSpecter/JavaBaseUtils/blob/master/src/common/util/FileUtil.java) 84 | 方法名 | 说明 | 参数 | 返回结果 85 | ------|------|-----|----- 86 | base64 | 将二进制压缩数据转成Base64编码 | byte\[](二进制压缩数据) | String(base64编码) 87 | base64 | 读取文件并压缩数据然后转Base64编码 | String(文件的绝对路径地址) | String(转码结果) 88 | decode | 把压缩过的base64串解码解压写入磁盘中 | String(压缩过的base64串),String(文件名),String(路径地址) | void(无) 89 | createFile | 创建文件 | String(生成路径),String(文件名),List(文本内容),FileTypeEnum(文件类型) | void(无) 90 | createFile | 创建文件 | String(生成路径),List(文本内容),FileTypeEnum(文件类型) | void(无) 91 | createFile | 创建文件 | List(文本内容),FileTypeEnum(文件类型) | void(无) 92 | getAllFileName | 获取路径下的所有文件名 | String(需要遍历的文件夹路径),boolean(是否切割后缀) | List(文件名集合) 93 | deleteFile | 删除文件 | String(文件路径),String(文件名) | void(无) 94 | deleteFile | 删除文件 | String(文件路径) | void(无) 95 | getAllFilePath | 获取路径下的所有文件/文件夹 | String(需要遍历的文件夹路径),boolean(是否将子文件夹的路径也添加到list集合中) | List(文件路径集合) 96 | writeFile | 二进制文件写入文件 | byte\[](二进制数据),String(文件名),String(路径地址) | void(无) 97 | deleteFileSuffix | 目录路径 | String(目录路径),FileTypeEnum(文件后缀) | void(无) 98 | deleteDirFile | 删除文件夹 | String(文件夹路径),boolean(是否删除文件夹内容) | void(无) 99 | moveFileDir | 转移文件目录 | String(文件名),String(旧路径),String(新路径),boolean(是否覆盖) | void(无) 100 | moveFuzzyFileDir | 转移文件目录(包含名字) | String(文件名),String(旧路径),String(新路径),boolean(是否覆盖) | void(无) 101 | createDir | 创建文件夹 | String(文件夹路径) | void(无) 102 | loadingFile | 读取文件内容 | String(文件路径) | String(文件内容) 103 | downloadFile2SavePath | 根据Url下载文件到指定目录 | List(下载地址集合),String(文件存放目录) | void(无) 104 | downloadFile2SavePath | 根据Url下载文件到指定目录 | String(下载地址),String(文件存放目录) | String(无) 105 | --- 106 | ## 路径处理工具类 -> [DirUtils](https://github.com/TangerineSpecter/JavaBaseUtils/blob/master/src/common/util/DirUtils.java) 107 | 方法名 | 说明 | 参数 | 返回结果 108 | ------|------|-----|----- 109 | getImgDir | 获取系统图片的存放路径 | String(UUID) | String(图片路径) 110 | getAudioDir | 获取系统音频的存放路径 | String(UUID) | String(音频路径) 111 | getVideoDir | 获取系统视频的存放路径 | String(UUID) | String(视频路径) 112 | --- 113 | ## 时间处理工具类 -> [TimeUtils](https://github.com/TangerineSpecter/JavaBaseUtils/blob/master/src/common/util/TimeUtils.java) 114 | 方法名 | 说明 | 参数 | 返回结果 115 | ------|------|-----|----- 116 | getCurrentYear | 获取当前年份 | 无 | String(年份) 117 | timeDifForYear | 时间差计算(年-月-日) | Long(开始时间戳),Long(结束时间戳) | String(返回时间格式:yy-MM-dd) 118 | timeFormatToDay | 将时间格式精确到天 | Date(时间) | String(转换结果) 119 | getCurrentTimes | 获取当前时间戳 | 无 | Long(时间戳) 120 | getDateMillion | 将指定格式转换成毫秒 | String(时间字符串),String(时间格式) | Long(时间戳) 121 | getDayBeginTimestamp | 获取当天开始时间戳 | 无 | Long(时间戳) 122 | getDayEndTimestamp | 获取当天结束时间戳 | 无 | Long(时间戳) 123 | getDisparityDay | 获取距离某个日期的天数 | String(时间字符串) | Integer(天数) 124 | getFinalDay | 获取某年某月最后一题 | int(年份),int(月份) | Integer(天数) 125 | getFinalDay | 获取某年某月最后一天 | Date(时间) | Date(时间) 126 | getStartDay | 获取某年某月第一天 | Date(时间) | Date(时间) 127 | getTimestramp | 获取特定时间时间戳 | int(年份),int(月份),int(日期),int(小时),int(分钟),int(秒) | Long(时间戳) 128 | getYesterdayBeginTimestamp | 获取昨天开始时间戳 | 无 | Long(时间戳) 129 | judgeLeapYear | 判断某一年是否闰年 | int(年份) | Boolean(判断结果) 130 | timeDifForDay | 时间差计算(时:分:秒) | Long(开始时间戳),Long(结束时间戳) | String(返回时间格式:HH:mm:ss) 131 | timeFormat | 将时间转换成指定格式 | Date(时间),String(时间格式) | String(转换结果) 132 | timeFormat | 将时间转换成指定格式 | Date(时间) | String(转换结果) 133 | getDate | 将指定的日期字符串转化为日期对象 | String(日期字符串),String(日期格式) | Date(转换结果) 134 | getSimpleFormat | 获取指定格式当前时间 | String(时间格式) | String(时间字符串) 135 | getWeekdays | 获取某天的星期 | String(时间字符串) | String(星期) 136 | --- 137 | ## 图片处理工具类 -> [ImageUtils](https://github.com/TangerineSpecter/JavaBaseUtils/blob/master/src/common/util/ImageUtils.java) 138 | 方法名 | 说明 | 参数 | 返回结果 139 | ------|------|-----|----- 140 | base64 | 读取文件压缩后转Base64编码 | String(图片的绝对路径地址) | String(Base64编码) 141 | downloadPicture | 将Url图片下载到本地 | List(url列表) | void(无) 142 | downloadPicture | 将Url图片下载到本地 | String(url地址),String(保存路径) | void(无) 143 | addWaterMark | 给图片加水印 | String(需要处理的图片路径),String(图片保存路径),int(水印x坐标),int(水印y坐标),String(水印内容),Font(水印字体),Color(水印字体颜色) | void(无) 144 | getWatermarkLength | 获取水印文字总长度 | String(水印文字),Graphics2D(Graphics2D类) | int(水印文字总长度) 145 | getWebImage | 获取网页所有图片并下载 | String(网页地址),String(网页编码),String(存放路径) | void(无) 146 | getHtmlResourceByUrl | 获取网页源代码 | String(网页地址),String(编码集) | String(源代码) 147 | getPicData | 获取图片的二进制数据 | String(图片的绝对路径地址) | byte[](二进制数据) 148 | --- 149 | ## 随机工具类 -> [RandomUtils](https://github.com/TangerineSpecter/JavaBaseUtils/blob/master/src/common/util/RandomUtils.java) 150 | 方法名 | 说明 | 参数 | 返回结果 151 | ------|------|-----|----- 152 | getEmail | 随机生成Email | int(最小长度),int(最大长度) | String(Email) 153 | getDate | 随机生成时间 | 无 | String(时间) 154 | getNum | 随机数 | int(起始数),int(结束数) | int(随机数字) 155 | getTel | 随机生成电话号码 | 无 | String(电话号码) 156 | getChineseName | 随机生成中文名字 | 无 | String(中文名) 157 | getProvince | 随机生成省份 | 无 | String(省份) 158 | createRandomName | 创建随机字符名字 | long(名字长度) | String(随机结果) 159 | --- 160 | ## 正则表达式工具类 -> [RegExUtils](https://github.com/TangerineSpecter/JavaBaseUtils/blob/master/src/common/util/RegExUtils.java) 161 | 方法名 | 说明 | 参数 | 返回结果 162 | ------|------|-----|----- 163 | checkEmail | 校验邮箱合法化 | String(邮箱地址) | boolean(校验结果) 164 | check2Point | 校验数字为小数后两位以内 | String(校验数字) | boolean(校验结果) 165 | checkPassword | 校验密码以字母开头 | String(密码) | boolean(校验结果) 166 | removeSpecialCharacter | 移除特殊字符 | String(字符串内容) | String(处理结果) 167 | filterHtml | 去除富文本中html相关字符 | String(富文本内容) | String(处理结果) 168 | --- 169 | ## 二维码生成工具类 -> [QrCodeUtils](https://github.com/TangerineSpecter/JavaBaseUtils/blob/master/src/common/util/QrCodeUtils.java) 170 | 方法名 | 说明 | 参数 | 返回结果 171 | ------|------|-----|----- 172 | createQrCode | 生成不带logo的默认参数二维码 | String(数据),int(宽度),int(高度) | BufferedImage(二维码图片) 173 | createQrCode | 生成不带logo的二维码 | String(数据),String(编码类型),Map(二维码属性),int(宽度),int(高度) | BufferedImage(二维码图片) 174 | createQrCodeWithLogo | 生成带logo的二维码 | String(数据),String(编码类型),Map(二维码属性),int(宽度),int(高度),File(logo文件路径) | BufferedImage(二维码图片) 175 | createQrCodeWithLogo | 生成带logo的默认参数二维码 | String(数据),int(宽度),int(高度),File(logo文件路径) | BufferedImage(二维码图片) 176 | --- 177 | ## 压缩和解压工具类 -> [ZipUtils](https://github.com/TangerineSpecter/JavaBaseUtils/blob/master/src/common/util/ZipUtils.java) 178 | 方法名 | 说明 | 参数 | 返回结果 179 | ------|------|-----|----- 180 | unZip | 解压数据 | byte\[](二进制数据) | byte[](解压结果) 181 | compress | 压缩文件 | String(源文件路径),String(压缩包名字) | void(无) 182 | gZip | 压缩数据 | byte\[](二进制数据) | byte[](压缩结果) 183 | --- 184 | ## Http工具类 -> [HttpUtils](https://github.com/TangerineSpecter/JavaBaseUtils/blob/master/src/common/util/HttpUtils.java) 185 | 方法名 | 说明 | 参数 | 返回结果 186 | ------|------|-----|----- 187 | --- 188 | -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Mingw, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | ########################################################################################## 204 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 205 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 206 | ########################################################################################## 207 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 208 | if [ "$MVNW_VERBOSE" = true ]; then 209 | echo "Found .mvn/wrapper/maven-wrapper.jar" 210 | fi 211 | else 212 | if [ "$MVNW_VERBOSE" = true ]; then 213 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 214 | fi 215 | jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" 216 | while IFS="=" read key value; do 217 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 218 | esac 219 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 220 | if [ "$MVNW_VERBOSE" = true ]; then 221 | echo "Downloading from: $jarUrl" 222 | fi 223 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 224 | 225 | if command -v wget > /dev/null; then 226 | if [ "$MVNW_VERBOSE" = true ]; then 227 | echo "Found wget ... using wget" 228 | fi 229 | wget "$jarUrl" -O "$wrapperJarPath" 230 | elif command -v curl > /dev/null; then 231 | if [ "$MVNW_VERBOSE" = true ]; then 232 | echo "Found curl ... using curl" 233 | fi 234 | curl -o "$wrapperJarPath" "$jarUrl" 235 | else 236 | if [ "$MVNW_VERBOSE" = true ]; then 237 | echo "Falling back to using Java to download" 238 | fi 239 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 240 | if [ -e "$javaClass" ]; then 241 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 242 | if [ "$MVNW_VERBOSE" = true ]; then 243 | echo " - Compiling MavenWrapperDownloader.java ..." 244 | fi 245 | # Compiling the Java class 246 | ("$JAVA_HOME/bin/javac" "$javaClass") 247 | fi 248 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 249 | # Running the downloader 250 | if [ "$MVNW_VERBOSE" = true ]; then 251 | echo " - Running MavenWrapperDownloader.java ..." 252 | fi 253 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 254 | fi 255 | fi 256 | fi 257 | fi 258 | ########################################################################################## 259 | # End of extension 260 | ########################################################################################## 261 | 262 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 263 | if [ "$MVNW_VERBOSE" = true ]; then 264 | echo $MAVEN_PROJECTBASEDIR 265 | fi 266 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 267 | 268 | # For Cygwin, switch paths to Windows format before running java 269 | if $cygwin; then 270 | [ -n "$M2_HOME" ] && 271 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 272 | [ -n "$JAVA_HOME" ] && 273 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 274 | [ -n "$CLASSPATH" ] && 275 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 276 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 277 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 278 | fi 279 | 280 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 281 | 282 | exec "$JAVACMD" \ 283 | $MAVEN_OPTS \ 284 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 285 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 286 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 287 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" 124 | FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO ( 125 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 126 | ) 127 | 128 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 129 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 130 | if exist %WRAPPER_JAR% ( 131 | echo Found %WRAPPER_JAR% 132 | ) else ( 133 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 134 | echo Downloading from: %DOWNLOAD_URL% 135 | powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')" 136 | echo Finished downloading %WRAPPER_JAR% 137 | ) 138 | @REM End of extension 139 | 140 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 141 | if ERRORLEVEL 1 goto error 142 | goto end 143 | 144 | :error 145 | set ERROR_CODE=1 146 | 147 | :end 148 | @endlocal & set ERROR_CODE=%ERROR_CODE% 149 | 150 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 151 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 152 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 153 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 154 | :skipRcPost 155 | 156 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 157 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 158 | 159 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 160 | 161 | exit /B %ERROR_CODE% 162 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.5.3 9 | 10 | 11 | com.tangerineSpecter 12 | javaBaseUtils 13 | 2.0.0 14 | JavaBaseUtils 15 | Java Tools 16 | 17 | 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-test 30 | test 31 | 32 | 33 | org.junit.vintage 34 | junit-vintage-engine 35 | 36 | 37 | 38 | 39 | 40 | 41 | org.projectlombok 42 | lombok 43 | 1.18.8 44 | provided 45 | 46 | 47 | 48 | org.aspectj 49 | aspectjweaver 50 | 1.9.4 51 | 52 | 53 | 54 | org.springframework.boot 55 | spring-boot-starter-web 56 | 57 | 58 | 59 | com.google.guava 60 | guava 61 | 30.0-jre 62 | 63 | 64 | 65 | com.alibaba 66 | easyexcel 67 | 2.2.10 68 | 69 | 70 | 71 | org.apache.poi 72 | poi 73 | 3.17 74 | 75 | 76 | org.apache.poi 77 | poi-ooxml 78 | 3.17 79 | 80 | 81 | org.apache.poi 82 | poi-ooxml-schemas 83 | 3.17 84 | 85 | 86 | 87 | 88 | org.apache.lucene 89 | lucene-core 90 | 8.2.0 91 | 92 | 93 | 94 | org.apache.lucene 95 | lucene-analyzers-smartcn 96 | 8.2.0 97 | 98 | 99 | org.apache.lucene 100 | lucene-analyzers-common 101 | 8.2.0 102 | 103 | 104 | org.apache.lucene 105 | lucene-analyzers 106 | 3.6.2 107 | 108 | 109 | org.apache.lucene 110 | lucene-queryparser 111 | 8.2.0 112 | 113 | 114 | com.janeluo 115 | ikanalyzer 116 | 2012_u6 117 | 118 | 119 | 120 | org.jsoup 121 | jsoup 122 | 1.11.3 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | com.google.zxing 133 | core 134 | 3.3.3 135 | 136 | 137 | com.google.zxing 138 | javase 139 | 3.4.0 140 | 141 | 142 | 143 | com.alibaba 144 | fastjson 145 | 1.2.58 146 | 147 | 148 | 149 | redis.clients 150 | jedis 151 | 3.1.0 152 | 153 | 154 | 155 | commons-io 156 | commons-io 157 | 2.7 158 | 159 | 160 | commons-codec 161 | commons-codec 162 | 1.15 163 | 164 | 165 | org.apache.commons 166 | commons-lang3 167 | 3.12.0 168 | 169 | 170 | commons-collections 171 | commons-collections 172 | 3.2.2 173 | 174 | 175 | 176 | org.apache.httpcomponents 177 | httpclient 178 | 4.5.13 179 | 180 | 181 | org.apache.httpcomponents 182 | httpcore 183 | 4.4.11 184 | 185 | 186 | 187 | com.itextpdf 188 | itext7-core 189 | 7.1.16 190 | 191 | 192 | 193 | io.springfox 194 | springfox-swagger2 195 | 2.9.2 196 | 197 | 198 | 199 | io.springfox 200 | springfox-swagger-ui 201 | 2.9.2 202 | 203 | 204 | 205 | com.github.xiaoymin 206 | knife4j-spring-boot-starter 207 | 2.0.9 208 | 209 | 210 | 211 | cn.hutool 212 | hutool-all 213 | 5.7.7 214 | 215 | 216 | 217 | 218 | 219 | 220 | org.springframework.boot 221 | spring-boot-maven-plugin 222 | 223 | 224 | 225 | 226 | 227 | 228 | spring-milestones 229 | Spring Milestones 230 | https://repo.spring.io/milestone 231 | 232 | 233 | 234 | 235 | spring-milestones 236 | Spring Milestones 237 | https://repo.spring.io/milestone 238 | 239 | 240 | 241 | 242 | -------------------------------------------------------------------------------- /src/log4j.properties: -------------------------------------------------------------------------------- 1 | ### 设置### 2 | log4j.rootLogger = INFO,stdout,E 3 | 4 | ### 输出信息到控制抬 ### 5 | log4j.appender.stdout = org.apache.log4j.ConsoleAppender 6 | log4j.appender.stdout.Target = System.out 7 | log4j.appender.stdout.layout = org.apache.log4j.PatternLayout 8 | log4j.appender.stdout.layout.ConversionPattern = [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n 9 | 10 | ### 输出DEBUG 级别以上的日志到=E://logs/error.log ### 11 | log4j.appender.D = org.apache.log4j.DailyRollingFileAppender 12 | log4j.appender.D.File = E://logs/log.log 13 | log4j.appender.D.Append = true 14 | log4j.appender.D.Threshold = DEBUG 15 | log4j.appender.D.layout = org.apache.log4j.PatternLayout 16 | log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n 17 | 18 | ### 输出ERROR 级别以上的日志到=E://logs/error.log ### 19 | log4j.appender.E = org.apache.log4j.DailyRollingFileAppender 20 | log4j.appender.E.File =E://logs/error.log 21 | log4j.appender.E.Append = true 22 | log4j.appender.E.Threshold = ERROR 23 | log4j.appender.E.layout = org.apache.log4j.PatternLayout 24 | log4j.appender.E.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/JavaBaseUtilsApplication.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils; 2 | 3 | import com.tangerinespecter.javabaseutils.common.servlet.AppRunWrapper; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * 启动入口 8 | * 9 | * @author TangerineSpecter 10 | */ 11 | @SpringBootApplication 12 | public class JavaBaseUtilsApplication { 13 | 14 | public static void main(String[] args) throws Exception { 15 | AppRunWrapper.run(JavaBaseUtilsApplication.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/common/DocumentInfo.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.common; 2 | 3 | import com.tangerinespecter.javabaseutils.common.annotation.ClassInfo; 4 | import com.tangerinespecter.javabaseutils.common.annotation.MethodInfo; 5 | import com.tangerinespecter.javabaseutils.common.util.Constant; 6 | import com.tangerinespecter.javabaseutils.common.util.FileUtil; 7 | import com.tangerinespecter.javabaseutils.common.util.enums.FileTypeEnum; 8 | import lombok.extern.slf4j.Slf4j; 9 | 10 | import java.lang.reflect.Method; 11 | import java.text.SimpleDateFormat; 12 | import java.util.*; 13 | 14 | /** 15 | * 文档信息生成 16 | * 17 | * @author TangerineSpecter 18 | */ 19 | @Slf4j 20 | public class DocumentInfo { 21 | 22 | /** 23 | * 不需要生成文档的集合 24 | */ 25 | private static final Set IGNORE_SET = new HashSet<>(); 26 | 27 | /** 28 | * 文件名集合 29 | */ 30 | private static List allFileName = new ArrayList<>(); 31 | 32 | /** 33 | * 创建所有类的文档信息 34 | * 35 | * @throws Exception 36 | */ 37 | public static void createDocInfo() throws Exception { 38 | List textInfo = new ArrayList<>(); 39 | allFileName = FileUtil.getAllFileName(Constant.UTIL_ABSOLUTE_PATH, true); 40 | getDocHead(textInfo); 41 | for (String fileName : allFileName) { 42 | if (!IGNORE_SET.contains(fileName)) { 43 | createClassInfo(fileName, textInfo); 44 | } 45 | } 46 | FileUtil.deleteFile(System.getProperty("user.dir"), "README.md"); 47 | FileUtil.createFile(System.getProperty("user.dir"), "README", textInfo, FileTypeEnum.MARKDOWN_FILE); 48 | } 49 | 50 | /** 51 | * 创建类文档信息 52 | * 53 | * @param className 类名 54 | * @throws Exception 55 | */ 56 | public static void createClassInfo(String className, List textInfo) throws Exception { 57 | boolean flag = false; 58 | List allFilePath = FileUtil.getAllFilePath(Constant.UTIL_ABSOLUTE_PATH, false); 59 | for (String path : allFilePath) { 60 | if (path.contains(className)) { 61 | flag = true; 62 | break; 63 | } 64 | } 65 | if (flag) { 66 | Class clazz = Class.forName(Constant.UTIL_QUALIFIED_HEAD + className); 67 | ClassInfo clazzAnno = clazz.getAnnotation(ClassInfo.class); 68 | if (clazzAnno == null) { 69 | return; 70 | } 71 | textInfo.add(String.format("## %s -> [%s](%s)", className, clazzAnno.Name(), className, 72 | Constant.GIT_HUB_BLOB_URL + className + ".java")); 73 | Method[] methods = clazz.getMethods(); 74 | getDocUtilHead(textInfo); 75 | for (Method method : methods) { 76 | MethodInfo annotations = method.getAnnotation(MethodInfo.class); 77 | if (annotations != null) { 78 | textInfo.add(String.format("%s | %s | %s | %s(%s)", method.getName(), annotations.Name(), 79 | getParamInfo(method, annotations.paramInfo()), method.getReturnType().getSimpleName(), 80 | annotations.returnInfo())); 81 | } 82 | } 83 | textInfo.add("---"); 84 | } else { 85 | log.info(String.format("【需要生成文档的类不存在】:{}", className)); 86 | } 87 | } 88 | 89 | /** 90 | * 获取文档目录 91 | * 92 | * @throws Exception 93 | */ 94 | private static void getDocHead(List textInfo) throws Exception { 95 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 96 | Calendar cal = Calendar.getInstance(); 97 | textInfo.add("# JavaBaseUtils\r\n"); 98 | textInfo.add("## 简介"); 99 | textInfo.add(" 主要收集一些平时常用的Java开发工具类,内容在不断更新补充中..."); 100 | textInfo.add("\r\n"); 101 | textInfo.add("### Java基本工具包:"); 102 | textInfo.add("- 工具包地址:https://github.com/TangerineSpecter/JavaBaseUtils\r\n"); 103 | textInfo.add("### 版本号:"); 104 | textInfo.add("- 项目版本:" + Constant.VERSION + "\r\n"); 105 | textInfo.add("- JDK版本:1.8\r\n"); 106 | textInfo.add("### 最后更新时间:"); 107 | textInfo.add("> " + sdf.format(cal.getTime()) + "\r\n"); 108 | textInfo.add("## 目录 \r\n"); 109 | textInfo.add("- [开始](#Getting_Menu)"); 110 | textInfo.add("- [API](#Geting_Api)"); 111 | for (String fileName : allFileName) { 112 | if (!IGNORE_SET.contains(fileName)) { 113 | Class clazz = Class.forName(Constant.UTIL_QUALIFIED_HEAD + fileName); 114 | ClassInfo annotation = clazz.getAnnotation(ClassInfo.class); 115 | if (annotation == null) { 116 | continue; 117 | } 118 | textInfo.add(String.format(" - [%s](#Geting_%s)", annotation.Name(), fileName)); 119 | } 120 | } 121 | textInfo.add("---"); 122 | } 123 | 124 | /** 125 | * 获取文档类标题 126 | */ 127 | private static void getDocUtilHead(List textInfo) { 128 | textInfo.add("方法名 | 说明 | 参数 | 返回结果\r\n------|------|-----|-----"); 129 | } 130 | 131 | /** 132 | * 获取参数信息 133 | * 134 | * @return 135 | */ 136 | private static String getParamInfo(Method method, String[] params) { 137 | StringBuilder paramInfo = new StringBuilder(Constant.NULL_KEY_STR); 138 | int index = Constant.Number.COMMON_NUMBER_ZERO; 139 | Class[] paramTypes = method.getParameterTypes(); 140 | if (params[index].equals(Constant.Chinese.NOTHING)) { 141 | return params[index]; 142 | } 143 | for (Class param : paramTypes) { 144 | try { 145 | paramInfo.append(param.getSimpleName()).append("(").append(params[index]).append("),"); 146 | index++; 147 | } catch (Exception e) { 148 | log.info(String.format("--------------------------------------------------------\r\n" 149 | + "【文档生成信息有误】\r\n Method : {} \r\n" 150 | + "--------------------------------------------------------", method.getName())); 151 | System.exit(0); 152 | } 153 | } 154 | return paramInfo.substring(0, paramInfo.length() - 1).replace("[]", "\\[]"); 155 | } 156 | 157 | static { 158 | IGNORE_SET.add("Constant"); 159 | IGNORE_SET.add("AudioUtils"); 160 | IGNORE_SET.add("Base64Utils"); 161 | IGNORE_SET.add("DecipheringBaseUtils"); 162 | IGNORE_SET.add("DecipheringUtils"); 163 | IGNORE_SET.add("LollipopUtils"); 164 | IGNORE_SET.add("FileTypeEnum"); 165 | IGNORE_SET.add("BaseUtils"); 166 | IGNORE_SET.add("LoggerWordPool"); 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/common/annotation/ClassInfo.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.common.annotation; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | import com.tangerinespecter.javabaseutils.common.util.Constant; 10 | 11 | /** 12 | * 类注解 13 | * 14 | * @author TangerineSpecter 15 | */ 16 | @Documented 17 | @Target(ElementType.TYPE) 18 | @Retention(RetentionPolicy.RUNTIME) 19 | public @interface ClassInfo { 20 | 21 | String Name() default Constant.Chinese.TOOL; 22 | 23 | String Author() default Constant.Chinese.ANONYMOUS; 24 | 25 | String Time() default Constant.NULL_KEY_STR; 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/common/annotation/MethodInfo.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.common.annotation; 2 | 3 | import com.tangerinespecter.javabaseutils.common.util.Constant; 4 | 5 | import java.lang.annotation.*; 6 | 7 | /** 8 | * 方法注解 9 | * 10 | * @author TangerineSpecter 11 | */ 12 | @Documented 13 | @Target(ElementType.METHOD) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | public @interface MethodInfo { 16 | 17 | /** 18 | * 方法名 19 | */ 20 | String Name() default Constant.Chinese.NOTHING; 21 | 22 | /** 23 | * 参数信息 24 | */ 25 | String[] paramInfo() default Constant.Chinese.NOTHING; 26 | 27 | /** 28 | * 返回信息 29 | */ 30 | String returnInfo() default Constant.Chinese.NOTHING; 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/common/config/SwaggerConfig.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.common.config; 2 | 3 | import com.google.common.base.Predicates; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | import springfox.documentation.builders.ApiInfoBuilder; 9 | import springfox.documentation.builders.PathSelectors; 10 | import springfox.documentation.builders.RequestHandlerSelectors; 11 | import springfox.documentation.service.ApiInfo; 12 | import springfox.documentation.service.Contact; 13 | import springfox.documentation.spi.DocumentationType; 14 | import springfox.documentation.spring.web.plugins.Docket; 15 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 16 | 17 | /** 18 | * Swagger配置类 19 | */ 20 | @Slf4j 21 | @EnableSwagger2 22 | @Configuration 23 | public class SwaggerConfig { 24 | 25 | @Value("${server.port}") 26 | private Integer port; 27 | 28 | @Bean 29 | public Docket customDocket() { 30 | return new Docket(DocumentationType.SWAGGER_2) 31 | .apiInfo(apiInfo()) 32 | //选择那些路径和api会生成document 33 | .select() 34 | //对所有api进行监控 35 | .apis(RequestHandlerSelectors.any()) 36 | //错误路径不监控 37 | .paths(Predicates.not(PathSelectors.regex("/error.*"))) 38 | .paths(Predicates.not(PathSelectors.regex("/hello.*"))) 39 | .build(); 40 | } 41 | 42 | /** 43 | * 配置Api相关信息 44 | */ 45 | private ApiInfo apiInfo() { 46 | Contact contact = new Contact("丢失的橘子", "https://github.com/TangerineSpecter", "993033472@qq.com"); 47 | return new ApiInfoBuilder() 48 | .title("Java工具包文档") 49 | .description("Java工具包接口演示文档") 50 | .contact(contact) 51 | .version("2.0.4") 52 | .build(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/common/exception/GlobalException.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.common.exception; 2 | 3 | import lombok.Getter; 4 | import lombok.Setter; 5 | 6 | /** 7 | * 全局异常 8 | * 9 | * @author TangerineSpecter 10 | */ 11 | @Getter 12 | @Setter 13 | public class GlobalException extends RuntimeException { 14 | 15 | private Integer code = 500; 16 | private String message; 17 | 18 | public GlobalException(String message) { 19 | super(message); 20 | this.message = message; 21 | } 22 | 23 | public GlobalException(Throwable cause) { 24 | super(cause); 25 | } 26 | 27 | public GlobalException(String message, Throwable cause) { 28 | super(message, cause); 29 | this.message = message; 30 | } 31 | 32 | public GlobalException(Integer code, String message) { 33 | this.code = code; 34 | this.message = message; 35 | } 36 | 37 | public GlobalException(Integer code) { 38 | this.code = code; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/common/filter/ManageLogAspect.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.common.filter; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.aspectj.lang.JoinPoint; 6 | import org.aspectj.lang.annotation.Aspect; 7 | import org.aspectj.lang.annotation.Before; 8 | import org.aspectj.lang.annotation.Pointcut; 9 | import org.springframework.stereotype.Component; 10 | import org.springframework.web.context.request.RequestContextHolder; 11 | import org.springframework.web.context.request.ServletRequestAttributes; 12 | 13 | import javax.servlet.http.HttpServletRequest; 14 | import java.util.concurrent.Executor; 15 | import java.util.concurrent.Executors; 16 | 17 | @Slf4j 18 | @Aspect 19 | @Component 20 | public class ManageLogAspect { 21 | 22 | private static final Executor executor = Executors.newFixedThreadPool(20, r -> { 23 | Thread t = new Thread(r); 24 | t.setName("log-aspect-" + t.getId()); 25 | /*打开守护线程*/ 26 | t.setDaemon(true); 27 | return t; 28 | }); 29 | 30 | 31 | @Pointcut("execution(* com.tangerinespecter.javabaseutils.controller..*.*(..))") 32 | public void controllerAopPointCut() { 33 | } 34 | 35 | 36 | @Before("controllerAopPointCut()") 37 | public void controllerReturnBefore(JoinPoint joinPoint) { 38 | ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); 39 | HttpServletRequest request = attributes.getRequest(); 40 | String token = request.getHeader("token"); 41 | executor.execute(() -> logAccess(token, joinPoint.getArgs(), request.getRequestURI())); 42 | } 43 | 44 | 45 | private void logAccess(String token, Object[] args, String url) { 46 | try { 47 | String userStr = "【TangerineSpecter】"; 48 | log.info("接口日志记录, 请求url: {}, 用户信息: {}, 请求参数: {}, token:{}", url, userStr, JSON.toJSONString(args), token); 49 | } catch (Exception e) { 50 | log.warn("记录用户访问信息出错", e); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/common/img/show_logo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TangerineSpecter/JavaBaseUtils/681ecd200def8b8a3b9aa5793d0959f785880db3/src/main/java/com/tangerineSpecter/javaBaseUtils/common/img/show_logo.gif -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/common/servlet/AppRunWrapper.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.common.servlet; 2 | 3 | import com.tangerinespecter.javabaseutils.common.DocumentInfo; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.context.ApplicationContext; 7 | import org.springframework.context.ConfigurableApplicationContext; 8 | import org.springframework.core.env.Environment; 9 | 10 | @Slf4j 11 | public class AppRunWrapper { 12 | 13 | public static ApplicationContext run(Class clazz, String[] args) throws Exception { 14 | System.setProperty("appName", clazz.getSimpleName()); 15 | ConfigurableApplicationContext application = SpringApplication.run(clazz, args); 16 | Environment env = application.getEnvironment(); 17 | 18 | DocumentInfo.createDocInfo(); 19 | log.info("\n☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆\n\t" + 20 | "Application '{}' is running! Access URLs:\n\t" + 21 | "欢迎使用橘子工具包,工具文档访问地址: \t\thttp://localhost:{}{}/doc.html\n" + 22 | "☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆", 23 | env.getProperty("spring.application.name", ""), 24 | env.getProperty("server.port", ""), 25 | env.getProperty("server.servlet.context-path", "")); 26 | return application; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/common/servlet/InitProperties.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.common.servlet; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.util.Properties; 6 | 7 | /** 8 | * 初始化 9 | * 10 | * @author TangerineSpecter 11 | */ 12 | public class InitProperties { 13 | 14 | public static void init() { 15 | try { 16 | Properties properties = new Properties(); 17 | // 使用ClassLoader加载properties配置文件生成对应的输入流 18 | InputStream in = InitProperties.class.getClassLoader().getResourceAsStream("common.properties"); 19 | // 使用properties对象加载输入流 20 | properties.load(in); 21 | //获取key对应的value值 22 | String value = properties.getProperty("version"); 23 | System.out.println(value); 24 | } catch (IOException e) { 25 | e.printStackTrace(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/common/test/UtilTest.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.common.test; 2 | 3 | import com.tangerinespecter.javabaseutils.common.DocumentInfo; 4 | import com.tangerinespecter.javabaseutils.common.util.DecipheringUtils; 5 | 6 | /** 7 | * 测试 8 | * 9 | * @author TangerineSpecter 10 | */ 11 | public class UtilTest { 12 | 13 | public static void main(String[] args) throws Exception { 14 | DocumentInfo.createDocInfo(); 15 | // String a = DecipheringUtils.setRailFenceResult("THERE IS A CIPHER", 7); 16 | // System.out.println(a); 17 | // String b = DecipheringUtils.getRailFenceResult("TAHCEIRPEHIESR", 7); 18 | // System.out.println(b); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/common/util/AudioUtils.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.common.util; 2 | 3 | import com.tangerinespecter.javabaseutils.common.annotation.ClassInfo; 4 | 5 | /** 6 | * 音频处理工具类 7 | * 8 | * @author TangerineSpecter 9 | * 10 | */ 11 | @ClassInfo(Name = "音频处理工具类") 12 | public class AudioUtils { 13 | 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/common/util/Base64Utils.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.common.util; 2 | 3 | import com.tangerinespecter.javabaseutils.common.annotation.ClassInfo; 4 | 5 | /** 6 | * Base64工具类 7 | * 8 | * @author TangerineSpecter 9 | * 10 | */ 11 | @ClassInfo(Name = "Base64工具类") 12 | public class Base64Utils { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/common/util/BaseUtils.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.common.util; 2 | 3 | /** 4 | * 基础工具类 5 | * 6 | * @author TangerineSpecter 7 | * 8 | */ 9 | public class BaseUtils extends LoggerWordPool { 10 | 11 | /** 12 | * 日志信息 13 | */ 14 | public static String loggerMessage(String info, Object param) { 15 | return String.format(info, param); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/common/util/Constant.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.common.util; 2 | 3 | import com.tangerinespecter.javabaseutils.common.annotation.ClassInfo; 4 | 5 | /** 6 | * 参数常量类 7 | * 8 | * @author TangerineSpecter 9 | */ 10 | @ClassInfo(Name = "参数常量类") 11 | public class Constant { 12 | 13 | /** 14 | * 版本号 15 | */ 16 | public static final String VERSION = "2.0.4"; 17 | 18 | /** 19 | * 文件默认存放地址 20 | */ 21 | public static final String FILE_SAVE_PATH = "F:\\testFile\\"; 22 | /** 23 | * 压缩文件存放地址 24 | */ 25 | public static final String ZIP_SAVE_PATH = "F:\\testFile\\zip\\"; 26 | 27 | /** 28 | * 空定义 29 | */ 30 | public static final String NULL_KEY_STR = ""; 31 | 32 | /** 33 | * 工具类全限定名头 34 | */ 35 | public static final String UTIL_QUALIFIED_HEAD = "com.tangerinespecter.javabaseutils.common.util."; 36 | 37 | /** 38 | * 工具类绝对路径 39 | */ 40 | public static final String UTIL_ABSOLUTE_PATH = System.getProperty("user.dir") + "/src/main/java/com/tangerinespecter/javabaseutils/common/util"; 41 | 42 | /** 43 | * 日期常量 44 | */ 45 | public static class Date { 46 | /** 47 | * 一月 48 | */ 49 | public static final int MONTH_JANUARY = 1; 50 | /** 51 | * 二月 52 | */ 53 | public static final int MONTH_FEBRUARY = 2; 54 | /** 55 | * 三月 56 | */ 57 | public static final int MONTH_MARCH = 3; 58 | /** 59 | * 四月 60 | */ 61 | public static final int MONTH_APRIL = 4; 62 | /** 63 | * 五月 64 | */ 65 | public static final int MONTH_MAY = 5; 66 | /** 67 | * 六月 68 | */ 69 | public static final int MONTH_JUNE = 6; 70 | /** 71 | * 七月 72 | */ 73 | public static final int MONTH_JULY = 7; 74 | /** 75 | * 八月 76 | */ 77 | public static final int MONTH_AUGUST = 8; 78 | /** 79 | * 九月 80 | */ 81 | public static final int MONTH_SEPTEMBER = 9; 82 | /** 83 | * 十月 84 | */ 85 | public static final int MONTH_OCTOBER = 10; 86 | /** 87 | * 十一月 88 | */ 89 | public static final int MONTH_NOVEMBER = 11; 90 | /** 91 | * 十二月 92 | */ 93 | public static final int MONTH_DECEMBER = 12; 94 | /** 95 | * 润二月 96 | */ 97 | public static final int LEAP_YEAR_DAY = 29; 98 | /** 99 | * 一秒相对的毫秒数 100 | */ 101 | public static final Long ONE_SECOND = 1000L; 102 | /** 103 | * 一分钟相对的毫秒数 104 | */ 105 | public static final Long ONE_MINUTE = 60L * ONE_SECOND; 106 | /** 107 | * 一小时相对的毫秒数 108 | */ 109 | public static final Long ONE_HOUR = 60L * ONE_MINUTE; 110 | /** 111 | * 一天相对的毫秒数 112 | */ 113 | public static final Long ONE_DAY = 24L * ONE_HOUR; 114 | /** 115 | * 一分钟相对的秒数 116 | */ 117 | public static final int ONE_MINUTE_OF_SECONDS = 60; 118 | /** 119 | * 一小时相对的秒数 120 | */ 121 | public static final int ONE_HOUR_OF_SECONDS = 60 * ONE_MINUTE_OF_SECONDS; 122 | /** 123 | * 一天相对的秒数 124 | */ 125 | public static final int ONE_DAY_OF_SECONDS = 24 * ONE_HOUR_OF_SECONDS; 126 | /** 127 | * 一个月相对的秒数 128 | */ 129 | public static final int ONE_MONTH_OF_SECONDS = 30 * ONE_DAY_OF_SECONDS; 130 | /** 131 | * 一年相对的秒数 132 | */ 133 | public static final int ONE_YEAR_OF_SECONDS = 12 * ONE_MONTH_OF_SECONDS; 134 | } 135 | 136 | /** 137 | * 基本常量 138 | */ 139 | public static class Number { 140 | /** 141 | * 数字0 142 | */ 143 | public static final Integer COMMON_NUMBER_ZERO = 0; 144 | /** 145 | * 数字1 146 | */ 147 | public static final Integer COMMON_NUMBER_FIRST = 1; 148 | /** 149 | * 数字2 150 | */ 151 | public static final Integer COMMON_NUMBER_SECOND = 2; 152 | /** 153 | * 数字3 154 | */ 155 | public static final Integer COMMON_NUMBER_THIRD = 3; 156 | 157 | public static final Integer HALF_NUMBER = 2; 158 | 159 | } 160 | 161 | /** 162 | * 加密类型 163 | */ 164 | public static class Deciphering { 165 | /** 166 | * 摩斯密码 167 | */ 168 | public static final String MORSE_TYPE = "摩斯密码"; 169 | /** 170 | * 栅栏密码 171 | */ 172 | public static final String RAILFENCE_TYPE = "栅栏密码"; 173 | /** 174 | * 手机九宫格 175 | */ 176 | public static final String PHONE_TYPEWRITING_TYPE = "手机九宫格"; 177 | /** 178 | * 键盘密码 179 | */ 180 | public static final String KEYBOARD_TYPE = "键盘密码"; 181 | /** 182 | * 培根密码 183 | */ 184 | public static final String BACON_TYPE = "培根密码"; 185 | /** 186 | * 倒序密码 187 | */ 188 | public static final String REVERSE_ORDER_TYPE = "倒序密码"; 189 | 190 | /** 191 | * 摩斯密码索引 192 | */ 193 | public static final int INDEX_MORSE = 0; 194 | /** 195 | * 栅栏密码索引 196 | */ 197 | public static final int INDEX_RAILFENCE = 1; 198 | /** 199 | * 手机九宫格索引 200 | */ 201 | public static final int INDEX_PHONE_TYPEWRITING = 2; 202 | /** 203 | * 键盘密码索引 204 | */ 205 | public static final int INDEX_KEYBOARD_TYPE = 3; 206 | /** 207 | * 培根密码索引 208 | */ 209 | public static final int INDEX_BACON = 4; 210 | /** 211 | * 倒序密码索引 212 | */ 213 | public static final int INDEX_REVERSE_ORDER = 5; 214 | } 215 | 216 | public static class Chinese { 217 | /** 218 | * 无字符串定义 219 | */ 220 | public static final String NOTHING = "无"; 221 | 222 | /** 223 | * 工具类 224 | */ 225 | public static final String TOOL = "工具类"; 226 | 227 | /** 228 | * 匿名 229 | */ 230 | public static final String ANONYMOUS = "匿名"; 231 | } 232 | 233 | /** 234 | * reids缓存相关配置 235 | **/ 236 | public static class Redis { 237 | public static String REDIS_IP = "127.0.0.1"; 238 | public static String REDIS_PASSWORD = null; 239 | public static int REDIS_MAX_ACTIVE = 100; 240 | public static int REDIS_MAX_IDLE = 50; 241 | public static int REDIS_MIN_IDLE = 20; 242 | public static int REDIS_MAX_WAIT_TIME = 2000; 243 | } 244 | 245 | /** 246 | * github-blob 247 | */ 248 | public static String GIT_HUB_BLOB_URL = "https://github.com/TangerineSpecter/JavaBaseUtils/blob/master/src/common/util/"; 249 | 250 | } 251 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/common/util/DecipheringBaseUtils.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.common.util; 2 | 3 | import com.tangerinespecter.javabaseutils.common.annotation.ClassInfo; 4 | import lombok.extern.slf4j.Slf4j; 5 | 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | /** 10 | * 解密工具基础类 11 | * 12 | * @author TangerineSpecter 13 | */ 14 | @Slf4j 15 | @ClassInfo(Name = "解密工具基础类") 16 | public class DecipheringBaseUtils { 17 | 18 | /** 19 | * 日志输出信息开关 20 | */ 21 | protected static Boolean ERROR_INFO = false; 22 | /** 23 | * 密码索引列表 24 | */ 25 | protected static final int[] PASSWORD_INDEX = {0, 1, 2, 3, 4, 5}; 26 | /** 27 | * 摩斯密码 28 | */ 29 | protected static Map MORSE_CODE_MAP = new HashMap<>(); 30 | /** 31 | * 键盘密码 32 | */ 33 | protected static Map KEYBOARD_CODE_MAP = new HashMap<>(); 34 | /** 35 | * 培根密码 36 | */ 37 | protected static Map BACON_CODE_MAP = new HashMap<>(); 38 | /** 39 | * 摩斯key 40 | */ 41 | protected static final String[] MORSE_KEY = ".----,..---,...--,....-,.....,-....,--...,---..,----.,-----,.-,-...,-.-.,-..,.,..-.,--.,....,..,.---,-.-,.-..,--,-.,---,.--.,--.-,.-.,...,-,..-,...-,.--,-..-,-.--,--.." 42 | .split(","); 43 | /** 44 | * 摩斯value 45 | */ 46 | protected static final String[] MORSE_VALUE = "1,2,3,4,5,6,7,8,9,0,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z" 47 | .split(","); 48 | 49 | /** 50 | * 手机九宫格 51 | */ 52 | protected static final String[][] TYPEWRITING_BOX = {{" "}, {",", "。", "!", "?"}, {"A", "B", "C"}, 53 | {"D", "E", "F"}, {"G", "H", "I"}, {"J", "K", "L"}, {"M", "N", "O"}, {"P", "Q", "R", "S"}, 54 | {"T", "U", "V"}, {"W", "X", "Y", "Z"}}; 55 | 56 | /** 57 | * 字母表 58 | */ 59 | protected static final String[] ALPHABET = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z".split(","); 60 | 61 | /** 62 | * 键盘字母表 63 | */ 64 | protected static final String[] KEYBOARD_VALUE = "Q,W,E,R,T,Y,U,I,O,P,A,S,D,F,G,H,J,K,L,Z,X,C,V,B,N,M".split(","); 65 | 66 | /** 67 | * 培根密码表 68 | */ 69 | protected static final String[] BACON_VALUE = "aaaaa,aaaab,aaaba,aaabb,aabaa,aabab,aabba,aabbb,abaaa,abaab,ababa,ababb,abbaa,abbab,abbba,abbbb,baaaa,baaab,baaba,baabb,babaa,babab,babba,babbb,bbaaa,bbaab" 70 | .split(","); 71 | 72 | static { 73 | MORSE_CODE_MAP = getMorseCode(); 74 | KEYBOARD_CODE_MAP = getKeyboardCode(); 75 | BACON_CODE_MAP = getBaconCode(); 76 | } 77 | 78 | /** 79 | * 获取摩斯密码 80 | * 81 | * @return 82 | */ 83 | private static Map getMorseCode() { 84 | Map morseMap = new HashMap<>(16); 85 | if (MORSE_KEY.length == MORSE_VALUE.length) { 86 | for (int index = 0; index < MORSE_KEY.length; index++) { 87 | morseMap.put(MORSE_KEY[index], MORSE_VALUE[index]); 88 | } 89 | } else { 90 | log.warn("摩斯密码key,value数量不对等!"); 91 | } 92 | return morseMap; 93 | } 94 | 95 | /** 96 | * 获取键盘密码 97 | * 98 | * @return 99 | */ 100 | private static Map getKeyboardCode() { 101 | Map keyboardMap = new HashMap<>(16); 102 | if (ALPHABET.length == KEYBOARD_VALUE.length) { 103 | for (int index = 0; index < ALPHABET.length; index++) { 104 | keyboardMap.put(ALPHABET[index], KEYBOARD_VALUE[index]); 105 | } 106 | } else { 107 | log.warn("键盘密码key,value数量不对等!"); 108 | } 109 | return keyboardMap; 110 | } 111 | 112 | /** 113 | * 获取培根密码 114 | * 115 | * @return 116 | */ 117 | private static Map getBaconCode() { 118 | Map baconMap = new HashMap<>(16); 119 | if (ALPHABET.length == BACON_VALUE.length) { 120 | for (int index = 0; index < ALPHABET.length; index++) { 121 | baconMap.put(ALPHABET[index], BACON_VALUE[index]); 122 | } 123 | } else { 124 | log.warn("培根密码key,value数量不对等!"); 125 | } 126 | return baconMap; 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/common/util/DecipheringUtils.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.common.util; 2 | 3 | import com.tangerinespecter.javabaseutils.common.annotation.ClassInfo; 4 | import com.tangerinespecter.javabaseutils.common.annotation.MethodInfo; 5 | import lombok.extern.slf4j.Slf4j; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | /** 11 | * 解密工具类 12 | * 13 | * @author TangerineSpecter 14 | */ 15 | @Slf4j 16 | @ClassInfo(Name = "解密工具类") 17 | public class DecipheringUtils extends DecipheringBaseUtils { 18 | 19 | /** 20 | * 加密摩斯密码 21 | * 22 | * @param content 加密内容 23 | * @return 24 | */ 25 | @MethodInfo(Name = "加密摩斯密码", paramInfo = {"加密内容"}, returnInfo = "摩斯加密结果") 26 | public static String setMorseResult(String content) { 27 | StringBuilder result = new StringBuilder(Constant.NULL_KEY_STR); 28 | content = content.replaceAll("\\s*", "").toUpperCase(); 29 | for (int index = 0; index < content.length(); index++) { 30 | String value = content.substring(index, index + 1); 31 | for (String getKey : MORSE_CODE_MAP.keySet()) { 32 | if (MORSE_CODE_MAP.get(getKey).equals(value)) { 33 | result.append(getKey).append("/"); 34 | } 35 | } 36 | } 37 | return result.substring(0, result.length() - 1); 38 | } 39 | 40 | /** 41 | * 解密摩斯密码 42 | * 43 | * @param morseCode 摩斯密码 用 "/"进行分隔 44 | * @return 45 | */ 46 | @MethodInfo(Name = "解密摩斯密码", paramInfo = {"摩斯密码"}, returnInfo = "摩斯解密结果") 47 | public static String getMorseResult(String morseCode) { 48 | StringBuilder result = new StringBuilder(Constant.NULL_KEY_STR); 49 | String[] morseArray = morseCode.split("/"); 50 | for (String morse : morseArray) { 51 | if (MORSE_CODE_MAP.get(morse) != null) { 52 | result.append(MORSE_CODE_MAP.get(morse)); 53 | } 54 | } 55 | if (Constant.NULL_KEY_STR.equals(result.toString())) { 56 | if (ERROR_INFO) { 57 | log.info(getErrorMessage(morseCode, Constant.Deciphering.MORSE_TYPE)); 58 | } 59 | } 60 | return result.toString(); 61 | } 62 | 63 | /** 64 | * 栅栏密码解密 65 | * 66 | * @param railfence 栅栏密码 67 | * @param key 栅栏数 68 | * @return 69 | */ 70 | @MethodInfo(Name = "栅栏密码解密", paramInfo = {"栅栏密码", "栅栏数"}, returnInfo = "栅栏解密结果") 71 | public static String getRailFenceResult(String railfence, int key) { 72 | StringBuilder result = new StringBuilder(); 73 | // 剔除所有空格 74 | String code = railfence.replaceAll("\\s*", ""); 75 | if (StringUtils.isEmpty(code)) { 76 | return result.toString(); 77 | } 78 | //最小长度 79 | int minLength = 2; 80 | if (key < minLength) { 81 | return code; 82 | } 83 | int length = railfence.length() % key == 0 ? railfence.length() / key : railfence.length() / key + 1; 84 | List results = new ArrayList<>(length); 85 | for (int index = 0; index < length; index++) { 86 | results.add(new StringBuilder()); 87 | } 88 | int index = 0; 89 | for (char c : code.toCharArray()) { 90 | results.get(index).append(c); 91 | if (index == length - 1) { 92 | index = 0; 93 | continue; 94 | } 95 | index++; 96 | } 97 | for (StringBuilder row : results) { 98 | result.append(row); 99 | } 100 | return result.toString(); 101 | } 102 | 103 | /** 104 | * 栅栏密码加密 105 | * 106 | * @param railfence 栅栏密码 107 | * @param key 栅栏数 108 | * @return 109 | */ 110 | @MethodInfo(Name = "栅栏密码加密", paramInfo = {"栅栏密码", "栅栏数"}, returnInfo = "栅栏加密结果") 111 | public static String setRailFenceResult(String railfence, int key) { 112 | StringBuilder result = new StringBuilder(); 113 | // 剔除所有空格 114 | String code = railfence.replaceAll("\\s*", ""); 115 | if (StringUtils.isEmpty(code)) { 116 | return result.toString(); 117 | } 118 | List results = new ArrayList<>(key); 119 | //最小长度 120 | int minLength = 2; 121 | if (key < minLength) { 122 | return code; 123 | } 124 | for (int index = 0; index < key; index++) { 125 | results.add(new StringBuilder()); 126 | } 127 | int index = 0; 128 | for (char c : code.toCharArray()) { 129 | results.get(index).append(c); 130 | if (index == key - 1) { 131 | index = 0; 132 | continue; 133 | } 134 | index++; 135 | } 136 | for (StringBuilder row : results) { 137 | result.append(row); 138 | } 139 | return result.toString(); 140 | } 141 | 142 | /** 143 | * 字符串转unicode 144 | * 145 | * @param str 146 | * @return 147 | */ 148 | @MethodInfo(Name = "字符串转unicode", paramInfo = {"字符串"}, returnInfo = "unicode结果") 149 | public static String string2Unicode(String str) { 150 | StringBuffer unicode = new StringBuffer(); 151 | for (int i = 0; i < str.length(); i++) { 152 | // 取出每一个字符 153 | char c = str.charAt(i); 154 | // 转换为unicode 155 | unicode.append("\\u" + Integer.toHexString(c)); 156 | } 157 | return unicode.toString(); 158 | } 159 | 160 | /** 161 | * unicode转字符串 162 | * 163 | * @param str 164 | * @return 165 | */ 166 | @MethodInfo(Name = "unicode转字符串", paramInfo = {"unicode字符串"}, returnInfo = "字符串结果") 167 | public static String unicode2String(String str) { 168 | int start = 0; 169 | int end; 170 | final StringBuffer buffer = new StringBuffer(); 171 | while (start > -1) { 172 | end = str.indexOf("\\u", start + 2); 173 | String charStr; 174 | if (end == -1) { 175 | charStr = str.substring(start + 2); 176 | } else { 177 | charStr = str.substring(start + 2, end); 178 | } 179 | char letter = (char) Integer.parseInt(charStr, 16); 180 | buffer.append(letter); 181 | start = end; 182 | } 183 | return buffer.toString(); 184 | } 185 | 186 | /** 187 | * 手机九宫格输入法解密 188 | * 189 | * @param content 内容 190 | * @return 191 | */ 192 | @MethodInfo(Name = "手机九宫格输入法解密", paramInfo = "解密内容", returnInfo = "解密结果") 193 | public static String getPhoneTypewritingResult(String content) { 194 | StringBuilder result = new StringBuilder(Constant.NULL_KEY_STR); 195 | content = content.replaceAll("\\s*", ""); 196 | boolean isNumber = content.matches("[0-9]+"); 197 | if (isNumber && content.length() % Constant.Number.HALF_NUMBER == 0) { 198 | try { 199 | for (int index = 0; index < (content.length() / Constant.Number.HALF_NUMBER); index++) { 200 | String key = content.substring(index * 2, (index * 2) + 2); 201 | result.append(TYPEWRITING_BOX[Integer 202 | .parseInt(key.substring(0, 1))][(Integer.parseInt(key.substring(1, 2)) - 1)]); 203 | } 204 | } catch (Exception e) { 205 | if (ERROR_INFO) { 206 | log.info(getErrorMessage(content, Constant.Deciphering.PHONE_TYPEWRITING_TYPE)); 207 | } 208 | return Constant.NULL_KEY_STR; 209 | } 210 | } 211 | if (ERROR_INFO) { 212 | log.info(getErrorMessage(content, Constant.Deciphering.PHONE_TYPEWRITING_TYPE)); 213 | } 214 | return result.toString(); 215 | } 216 | 217 | /** 218 | * 手机九宫格输入法加密 219 | * 220 | * @param content 内容 221 | * @return 222 | */ 223 | @MethodInfo(Name = "手机九宫格输入法加密", paramInfo = "解密内容", returnInfo = "加密结果") 224 | public static String setPhoneTypewritingResult(String content) { 225 | StringBuilder result = new StringBuilder(Constant.NULL_KEY_STR); 226 | content = content.replaceAll("\\s*", "").toUpperCase(); 227 | for (int i = 0; i < content.length(); i++) { 228 | for (int index = 0; index < TYPEWRITING_BOX.length; index++) { 229 | for (int count = 0; count < TYPEWRITING_BOX[index].length; count++) { 230 | if (TYPEWRITING_BOX[index][count].equals(content.substring(i, i + 1))) { 231 | result.append(index).append((count + 1)); 232 | } 233 | } 234 | } 235 | } 236 | return result.toString(); 237 | } 238 | 239 | /** 240 | * 加密键盘密码 241 | * 242 | * @param content 加密内容 243 | * @return 244 | */ 245 | @MethodInfo(Name = "加密键盘密码", paramInfo = "加密内容", returnInfo = "加密结果") 246 | public static String setKeyboardResult(String content) { 247 | StringBuilder result = new StringBuilder(Constant.NULL_KEY_STR); 248 | content = content.replaceAll("\\s*", "").toUpperCase(); 249 | String[] keyboardArray = content.split(""); 250 | for (String keyboard : keyboardArray) { 251 | if (KEYBOARD_CODE_MAP.get(keyboard) != null) { 252 | result.append(KEYBOARD_CODE_MAP.get(keyboard)); 253 | } 254 | } 255 | if (Constant.NULL_KEY_STR.equals(result.toString())) { 256 | if (ERROR_INFO) { 257 | log.info(getErrorMessage(content, Constant.Deciphering.KEYBOARD_TYPE)); 258 | } 259 | } 260 | return result.toString(); 261 | } 262 | 263 | /** 264 | * 解密键盘密码 265 | * 266 | * @param keyboardCode 键盘密码 267 | * @return 268 | */ 269 | @MethodInfo(Name = "解密键盘密码", paramInfo = "键盘密码", returnInfo = "解密结果") 270 | public static String getKeyboardResult(String keyboardCode) { 271 | StringBuilder result = new StringBuilder(Constant.NULL_KEY_STR); 272 | keyboardCode = keyboardCode.replaceAll("\\s*", "").toUpperCase(); 273 | for (int index = 0; index < keyboardCode.length(); index++) { 274 | String value = keyboardCode.substring(index, index + 1); 275 | for (String getKey : KEYBOARD_CODE_MAP.keySet()) { 276 | if (KEYBOARD_CODE_MAP.get(getKey).equals(value)) { 277 | result.append(getKey); 278 | } 279 | } 280 | } 281 | return result.toString(); 282 | } 283 | 284 | /** 285 | * 加密培根密码 286 | * 287 | * @param content 加密内容 288 | * @return 289 | */ 290 | @MethodInfo(Name = "加密培根密码", paramInfo = "加密内容", returnInfo = "加密结果") 291 | public static String setBaconResult(String content) { 292 | StringBuilder result = new StringBuilder(Constant.NULL_KEY_STR); 293 | content = content.replaceAll("\\s*", "").toUpperCase(); 294 | String[] baconArray = content.split(""); 295 | for (String bacon : baconArray) { 296 | if (BACON_CODE_MAP.get(bacon) != null) { 297 | result.append(BACON_CODE_MAP.get(bacon)); 298 | } 299 | } 300 | if (Constant.NULL_KEY_STR.equals(result.toString())) { 301 | if (ERROR_INFO) { 302 | log.info(getErrorMessage(content, Constant.Deciphering.BACON_TYPE)); 303 | } 304 | } 305 | return result.toString(); 306 | } 307 | 308 | /** 309 | * 解密培根密码 310 | * 311 | * @param baconCode 培根密码 312 | * @return 313 | */ 314 | @MethodInfo(Name = "解密培根密码", paramInfo = "培根密码", returnInfo = "解密结果") 315 | public static String getBaconResult(String baconCode) { 316 | StringBuilder result = new StringBuilder(Constant.NULL_KEY_STR); 317 | baconCode = baconCode.replaceAll("\\s*", "").toUpperCase(); 318 | for (int index = 0; index < baconCode.length(); index++) { 319 | String value = baconCode.substring(index, index + 1); 320 | for (String getKey : BACON_CODE_MAP.keySet()) { 321 | if (BACON_CODE_MAP.get(getKey).equals(value)) { 322 | result.append(getKey); 323 | } 324 | } 325 | } 326 | return result.toString(); 327 | } 328 | 329 | /** 330 | * 倒序排列 331 | * 332 | * @param content 333 | * @return 334 | */ 335 | @MethodInfo(Name = "倒序排列", paramInfo = {"排列内容"}, returnInfo = "排列结果") 336 | public static String reverseOrder(String content) { 337 | return new StringBuffer(content.replaceAll("\\s*", "")).reverse().toString(); 338 | } 339 | 340 | /** 341 | * 解密错误提示 342 | */ 343 | private static String getErrorMessage(String content, String type) { 344 | return String.format("【错误提示】:[%s]不符合[%s]方式", content, type); 345 | } 346 | } 347 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/common/util/DirUtils.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.common.util; 2 | 3 | import com.tangerinespecter.javabaseutils.common.annotation.ClassInfo; 4 | import com.tangerinespecter.javabaseutils.common.annotation.MethodInfo; 5 | 6 | import java.io.File; 7 | import java.util.Calendar; 8 | 9 | /** 10 | * 路径处理工具类 11 | * 12 | * @author TangerineSpecter 13 | */ 14 | @ClassInfo(Name = "路径处理工具类") 15 | public class DirUtils { 16 | 17 | /** 18 | * 图片 19 | */ 20 | private static final String IMG_DIR = "img"; 21 | /** 22 | * 音频 23 | */ 24 | private static final String AUDIO_DIR = "audio"; 25 | /** 26 | * 视频 27 | */ 28 | private static final String VIDEO_DIR = "video"; 29 | 30 | /** 31 | * getImgDir 获取系统图片的存放路径 32 | * 33 | * @param uuid 34 | * @return 图片路径 35 | */ 36 | @MethodInfo(Name = "获取系统图片的存放路径", paramInfo = {"UUID"}, returnInfo = "图片路径") 37 | public static String getImgDir(String uuid) { 38 | return getDir(IMG_DIR, uuid); 39 | } 40 | 41 | /** 42 | * getAudioDir 获取系统音频的存放路径 43 | * 44 | * @param uuid 45 | * @return 音频路径 46 | */ 47 | @MethodInfo(Name = "获取系统音频的存放路径", paramInfo = {"UUID"}, returnInfo = "音频路径") 48 | public static String getAudioDir(String uuid) { 49 | return getDir(AUDIO_DIR, uuid); 50 | } 51 | 52 | /** 53 | * getVideoDir 获取系统视频的存放路径 54 | * 55 | * @param uuid 56 | * @return 视频路径 57 | */ 58 | @MethodInfo(Name = "获取系统视频的存放路径", paramInfo = {"UUID"}, returnInfo = "视频路径") 59 | public static String getVideoDir(String uuid) { 60 | return getDir(VIDEO_DIR, uuid); 61 | } 62 | 63 | /** 64 | * 获取系统各类子目录 65 | * 66 | * @param subDir 路径头 67 | * @param uuid 68 | * @return 69 | */ 70 | @MethodInfo(Name = "获取系统各类子目录", paramInfo = {"路径头", "UUID"}, returnInfo = "文件路径") 71 | private static String getDir(String subDir, String uuid) { 72 | StringBuffer path = new StringBuffer(Constant.FILE_SAVE_PATH); 73 | path.append("/").append(subDir).append("/").append(TimeUtils.timeFormatToDay(Calendar.getInstance().getTime())) 74 | .append("/").append(uuid).append("/"); 75 | File file = new File(path.toString()); 76 | if (!file.exists()) { 77 | file.mkdirs(); 78 | } 79 | return path.toString(); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/common/util/EasyExcelUtils.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.common.util; 2 | 3 | import com.alibaba.excel.EasyExcel; 4 | import com.alibaba.excel.read.builder.ExcelReaderBuilder; 5 | import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; 6 | import com.tangerinespecter.javabaseutils.common.test.pojo.ExcelTestHead; 7 | import org.springframework.web.multipart.MultipartFile; 8 | 9 | import javax.servlet.http.HttpServletResponse; 10 | import java.io.File; 11 | import java.io.FileInputStream; 12 | import java.io.IOException; 13 | import java.io.InputStream; 14 | import java.net.URLEncoder; 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | 18 | /** 19 | * EasyExcel处理工具类 20 | * 21 | * @author TangerineSpecter 22 | */ 23 | public class EasyExcelUtils { 24 | 25 | /** 26 | * 简单读取 27 | * 28 | * @param file excel文件 29 | */ 30 | public static void simpleRead(MultipartFile file) throws IOException { 31 | ExcelReaderBuilder read = EasyExcel.read(file.getInputStream()); 32 | List> list = new ArrayList<>(); 33 | read.head(list); 34 | read.doReadAll(); 35 | for (List strings : list) { 36 | System.out.println(strings); 37 | } 38 | } 39 | 40 | /** 41 | * 将列表以 Excel 响应给前端 42 | * 43 | * @param response 响应 44 | * @param filename 文件名 45 | * @param sheetName Excel sheet 名 46 | * @param head Excel head 头 47 | * @param data 数据列表哦 48 | * @param 泛型,保证 head 和 data 类型的一致性 49 | * @throws IOException 写入失败的情况 50 | */ 51 | public static void write(HttpServletResponse response, String filename, String sheetName, 52 | Class head, List data) throws IOException { 53 | // 输出 Excel 54 | EasyExcel.write(response.getOutputStream(), head) 55 | // 不要自动关闭,交给 Servlet 自己处理 56 | .autoCloseStream(false) 57 | // 基于 column 长度,自动适配。最大 255 宽度 58 | .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) 59 | .sheet(sheetName).doWrite(data); 60 | // 设置 header 和 contentType。写在最后的原因是,避免报错时,响应 contentType 已经被修改了 61 | response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename, "UTF-8")); 62 | response.setContentType("application/vnd.ms-excel;charset=UTF-8"); 63 | } 64 | 65 | public static List read(MultipartFile file, Class head) throws IOException { 66 | return EasyExcel.read(file.getInputStream(), head, null) 67 | // 不要自动关闭,交给 Servlet 自己处理 68 | .autoCloseStream(false) 69 | .doReadAllSync(); 70 | } 71 | 72 | public static List read(InputStream inputStream, Class head) throws IOException { 73 | return EasyExcel.read(inputStream, head, null) 74 | // 不要自动关闭,交给 Servlet 自己处理 75 | .autoCloseStream(false) 76 | .doReadAllSync(); 77 | } 78 | 79 | public static void main(String[] args) throws IOException { 80 | String filePath = "/Users/zhouliangjun/Downloads/生产环境机构及员工信息-0729.xlsx"; 81 | File file = new File(filePath); 82 | if (file.isFile()) { 83 | System.out.println("这是一个文件"); 84 | } 85 | List read = read(new FileInputStream(file), ExcelTestHead.class); 86 | System.out.println(read); 87 | // ExcelReaderBuilder read = EasyExcel.read(file); 88 | // ExcelReaderSheetBuilder sheet = read.sheet(); 89 | // List objects = sheet.doReadSync(); 90 | // System.out.println(objects); 91 | // System.out.println(BackgroundRemoval.hexToRgb("ffcc99")); 92 | // System.out.println(String.format("#%02x%02x%02x", 15, 204, 153)); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/common/util/EncrypUtils.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.common.util; 2 | 3 | import com.tangerinespecter.javabaseutils.common.annotation.ClassInfo; 4 | import com.tangerinespecter.javabaseutils.common.annotation.MethodInfo; 5 | import lombok.extern.slf4j.Slf4j; 6 | 7 | import java.io.UnsupportedEncodingException; 8 | import java.security.MessageDigest; 9 | import java.security.NoSuchAlgorithmException; 10 | import java.util.Map; 11 | import java.util.concurrent.ConcurrentHashMap; 12 | 13 | /** 14 | * 加密工具类 15 | * 16 | * @author TangerineSpecter 17 | */ 18 | @Slf4j 19 | @ClassInfo(Name = "加密工具类") 20 | public class EncrypUtils { 21 | 22 | /** 23 | * 24 | */ 25 | private static Map digests = new ConcurrentHashMap(); 26 | 27 | /** 28 | * 哈希加密算法 29 | * 30 | * @param data 需要加密的数据 31 | * @param algorithm 请求算法的名称,如:MD5、SHA等 32 | * @return 加密后的数据 33 | */ 34 | @MethodInfo(Name = "哈希加密算法", paramInfo = {"需要加密的数据", "加密算法名称"}, returnInfo = "加密数据") 35 | public static String hash(String data, String algorithm) { 36 | try { 37 | return hash(data.getBytes("UTF-8"), algorithm); 38 | } catch (UnsupportedEncodingException e) { 39 | log.error(e.getMessage(), e); 40 | } 41 | return data; 42 | } 43 | 44 | /** 45 | * 哈希加密算法 46 | * 47 | * @param bytes 需要加密的字节数组 48 | * @param algorithm 请求算法的名称,如:MD5、SHA等 49 | * @return 加密后的数据 50 | */ 51 | @MethodInfo(Name = "哈希加密算法", paramInfo = {"加密字节数组", "加密算法名称"}, returnInfo = "加密数据") 52 | public static String hash(byte[] bytes, String algorithm) { 53 | synchronized (algorithm.intern()) { 54 | MessageDigest digest = digests.get(algorithm); 55 | if (digest == null) { 56 | try { 57 | digest = MessageDigest.getInstance(algorithm); 58 | digests.put(algorithm, digest); 59 | } catch (NoSuchAlgorithmException nsae) { 60 | log.error("加载MessageDigest类失败:" + algorithm, nsae); 61 | return null; 62 | } 63 | } 64 | // 计算哈希值 65 | digest.update(bytes); 66 | return encodeHex(digest.digest()); 67 | } 68 | } 69 | 70 | /** 71 | * 将字节数组转换成十六进制字符串 72 | * 73 | * @param bytes 字节数组 74 | * @return 十六进制字符串 75 | */ 76 | @MethodInfo(Name = "将字节数组转换成十六进制字符串", paramInfo = {"字节数组"}, returnInfo = "十六进制字符串") 77 | public static String encodeHex(byte[] bytes) { 78 | StringBuilder buf = new StringBuilder(bytes.length * 2); 79 | int i; 80 | 81 | for (i = 0; i < bytes.length; i++) { 82 | if (((int) bytes[i] & 0xff) < 0x10) { 83 | buf.append("0"); 84 | } 85 | buf.append(Long.toString((int) bytes[i] & 0xff, 16)); 86 | } 87 | return buf.toString(); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/common/util/ExcelUtils.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.common.util; 2 | 3 | import cn.hutool.poi.excel.ExcelUtil; 4 | import com.tangerinespecter.javabaseutils.common.annotation.ClassInfo; 5 | import com.tangerinespecter.javabaseutils.common.annotation.MethodInfo; 6 | import com.tangerinespecter.javabaseutils.common.exception.GlobalException; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.apache.poi.hssf.usermodel.HSSFWorkbook; 9 | import org.apache.poi.ss.usermodel.Row; 10 | import org.apache.poi.ss.usermodel.Sheet; 11 | import org.apache.poi.ss.usermodel.Workbook; 12 | import org.apache.poi.xssf.usermodel.XSSFCell; 13 | import org.apache.poi.xssf.usermodel.XSSFRow; 14 | import org.apache.poi.xssf.usermodel.XSSFSheet; 15 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 16 | 17 | import java.io.*; 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | import java.util.UUID; 21 | 22 | 23 | /** 24 | * Excel处理工具类 25 | * 26 | * @author TangerineSpecter 27 | */ 28 | @Slf4j 29 | @ClassInfo(Name = "Excel处理工具类") 30 | public class ExcelUtils { 31 | 32 | 33 | private static Workbook wb = null; 34 | private static File file; 35 | private static FileOutputStream fos; 36 | 37 | /** 38 | * 获取Excel数据 39 | * 40 | * @param filePath 41 | * @return 42 | */ 43 | @MethodInfo(Name = "获取Excel数据", paramInfo = {"Excel路径"}, returnInfo = "数据列表") 44 | public static List getExcel(String filePath) { 45 | return getExcelForXlsx(filePath); 46 | } 47 | 48 | private static List getExcelForXlsx(String filePath) { 49 | try { 50 | List dataList = new ArrayList<>(); 51 | FileInputStream fis = new FileInputStream(filePath); 52 | // 根据Excel输入流获取工作簿对象 53 | XSSFWorkbook xss = new XSSFWorkbook(fis); 54 | // 获取工作表对象 55 | XSSFSheet sheet = xss.getSheetAt(0); 56 | Row headerRow = sheet.getRow(0); 57 | // 获取最后一列列号 58 | int cellNum = headerRow.getLastCellNum(); 59 | // 获取最后一行行号 60 | int rowNum = sheet.getLastRowNum(); 61 | for (int count = 1; count < rowNum; count++) { 62 | String[] data = new String[cellNum]; 63 | // 获取行 64 | XSSFRow row = sheet.getRow(count); 65 | // 获取列数据 66 | for (int index = 0; index < cellNum; index++) { 67 | XSSFCell cell = row.getCell(index); 68 | data[index] = cell.toString(); 69 | } 70 | dataList.add(data); 71 | } 72 | xss.close(); 73 | return dataList; 74 | } catch (Exception e) { 75 | e.printStackTrace(); 76 | log.error(String.format("【Excel数据读取异常】:%s", e)); 77 | } 78 | return null; 79 | } 80 | 81 | /** 82 | * 创建Excel文件 83 | * 84 | * @param tableHead 表头 85 | * @param dataList 数据列表 86 | * @param isExcel (true:新版;false:旧版) 87 | * @return excel生成路径 88 | */ 89 | @MethodInfo(Name = "创建Excel", paramInfo = {"表头", "数据列表", "新旧版本"}, returnInfo = "生成路径") 90 | public static String createExcel(String[] tableHead, List dataList, boolean isExcel) { 91 | String dateName = TimeUtils.getSimpleFormat("yyyy-MM-dd"); 92 | String uuid = UUID.randomUUID().toString(); 93 | String savePath = Constant.FILE_SAVE_PATH + dateName + "/" + uuid + "/"; 94 | String excelPath; 95 | if (dataList.isEmpty()) { 96 | return null; 97 | } 98 | File dir = new File(savePath); 99 | if (!dir.isDirectory()) { 100 | dir.mkdirs(); 101 | } 102 | if (isExcel) { 103 | excelPath = createExcelForXlsx(savePath, tableHead, dataList); 104 | } else { 105 | excelPath = createExcelForXls(savePath, tableHead, dataList); 106 | } 107 | return excelPath; 108 | } 109 | 110 | /** 111 | * 生成Xlsx格式Excel 112 | * 113 | * @param savePath 保存路径 114 | * @param tableHead 表头 115 | * @param dataList 数据列表 116 | */ 117 | private static String createExcelForXlsx(String savePath, String[] tableHead, List dataList) { 118 | String path = savePath + "/" + UUID.randomUUID().toString() + ".xlsx"; 119 | file = new File(path); 120 | wb = new XSSFWorkbook(); 121 | createExcelData(tableHead, dataList); 122 | return path; 123 | } 124 | 125 | /** 126 | * 生成Xls格式Excel 127 | * 128 | * @param savePath 保存路径 129 | * @param tableHead 表头 130 | * @param dataList 数据列表 131 | */ 132 | private static String createExcelForXls(String savePath, String[] tableHead, List dataList) { 133 | String path = savePath + "/" + UUID.randomUUID().toString() + ".xls"; 134 | file = new File(path); 135 | wb = new HSSFWorkbook(); 136 | createExcelData(tableHead, dataList); 137 | return path; 138 | } 139 | 140 | /** 141 | * 生成Excel文件 142 | * 143 | * @param tableHead 表头 144 | * @param dataList 数据列表 145 | */ 146 | private static void createExcelData(String[] tableHead, List dataList) { 147 | try { 148 | if (!file.exists()) { 149 | file.createNewFile(); 150 | } 151 | fos = new FileOutputStream(file); 152 | Sheet sheet = wb.createSheet("errorInfo"); 153 | Row titleRow = sheet.createRow(0); 154 | for (int index = 0; index < tableHead.length; index++) { 155 | titleRow.createCell(index).setCellValue(tableHead[index]); 156 | } 157 | createExcelData(dataList); 158 | wb.write(fos); 159 | } catch (Exception e) { 160 | log.error(String.format("【excel生成异常】:%s", e)); 161 | } finally { 162 | if (wb != null) { 163 | try { 164 | wb.close(); 165 | } catch (IOException e) { 166 | e.printStackTrace(); 167 | log.error("【流关闭失败】:%s", e); 168 | } 169 | } 170 | } 171 | } 172 | 173 | /** 174 | * 创建数据 175 | * 176 | * @param dataList 数据列表 177 | */ 178 | private static void createExcelData(List dataList) { 179 | for (String[] data : dataList) { 180 | write(data); 181 | } 182 | } 183 | 184 | /** 185 | * 写入数据 186 | * 187 | * @param data 数据 188 | */ 189 | private static void write(String[] data) { 190 | Sheet sheet = wb.getSheet("errorInfo"); 191 | int lastRowNum = sheet.getLastRowNum(); 192 | Row currentRow = sheet.createRow(lastRowNum + 1); 193 | for (int index = 0; index < data.length; index++) { 194 | currentRow.createCell(index).setCellValue(data[index]); 195 | } 196 | } 197 | 198 | public static List> readExcel(InputStream in) { 199 | final List> result = new ArrayList<>(); 200 | try { 201 | ExcelUtil.readBySax(in, -1, (sheetIndex, rowIndex, rowList) -> { 202 | if (rowList.size() < 1) { 203 | return; 204 | } 205 | ArrayList objects = new ArrayList<>(rowList); 206 | result.add(objects); 207 | }); 208 | } catch (Exception e) { 209 | log.error("读取EXCEL数据流失败...", e); 210 | throw new GlobalException("读取EXCEL数据流失败...", e); 211 | } finally { 212 | if (in != null) { 213 | try { 214 | in.close(); 215 | } catch (IOException e) { 216 | 217 | } 218 | } 219 | } 220 | return result; 221 | } 222 | } 223 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/common/util/HttpUtils.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.common.util; 2 | 3 | import com.tangerinespecter.javabaseutils.common.annotation.ClassInfo; 4 | import lombok.extern.slf4j.Slf4j; 5 | 6 | import java.io.*; 7 | import java.net.HttpURLConnection; 8 | import java.net.URL; 9 | import java.net.URLEncoder; 10 | import java.util.Map; 11 | 12 | /** 13 | * Http工具类 14 | * 15 | * @author TangerineSpecter 16 | */ 17 | @Slf4j 18 | @ClassInfo(Name = "Http工具类") 19 | public class HttpUtils { 20 | 21 | private static final String DEF_CHATSET = "UTF-8"; 22 | private static final int DEF_CONN_TIMEOUT = 30000; 23 | private static final int DEF_READ_TIMEOUT = 30000; 24 | private static String userAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36"; 25 | 26 | private static String GET_METHOD = "GET"; 27 | 28 | private static String POST_METHOD = "POST"; 29 | 30 | /** 31 | * 调用对方接口方法 32 | * 33 | * @param strUrl 对方或第三方提供的路径 34 | * @param params 向对方或第三方发送的数据,大多数情况下给对方发送JSON数据让对方解析 35 | * @param method 网络请求字符串 36 | */ 37 | public static String interfaceInvoke(String strUrl, Map params, String method) { 38 | HttpURLConnection conn = null; 39 | BufferedReader reader = null; 40 | String result = null; 41 | try { 42 | StringBuffer sb = new StringBuffer(); 43 | if (method == null || GET_METHOD.equals(method)) { 44 | strUrl = strUrl + "?" + urlEncode(params); 45 | } 46 | URL url = new URL(strUrl); 47 | // 打开和url之间的连接 48 | conn = (HttpURLConnection) url.openConnection(); 49 | // 请求方式 50 | if (method == null || GET_METHOD.equals(method.toUpperCase())) { 51 | conn.setRequestMethod("GET"); 52 | } else if (method == null || POST_METHOD.toUpperCase().equals(method)) { 53 | conn.setRequestMethod("POST"); 54 | conn.setDoOutput(true); 55 | } else { 56 | log.error(String.format("[接口请求方法错误]:{}", method)); 57 | return result; 58 | } 59 | // //设置通用的请求属性 60 | conn.setRequestProperty("accept", "*/*"); 61 | conn.setRequestProperty("connection", "Keep-Alive"); 62 | conn.setRequestProperty("user-agent", userAgent); 63 | conn.setConnectTimeout(DEF_CONN_TIMEOUT); 64 | conn.setReadTimeout(DEF_READ_TIMEOUT); 65 | conn.setInstanceFollowRedirects(false); 66 | // 设置是否向httpUrlConnection输出,设置是否从httpUrlConnection读入,此外发送post请求必须设置这两个 67 | // 最常用的Http请求无非是get和post,get请求可以获取静态页面,也可以把参数放在URL字串后面,传递给servlet, 68 | // post与get的 不同之处在于post的参数不是放在URL字串里面,而是放在http请求的正文内。 69 | conn.setDoOutput(true); 70 | conn.setDoInput(true); 71 | conn.connect(); 72 | if (params != null && POST_METHOD.equals(method)) { 73 | try { 74 | // 获取URLConnection对象对应的输出流 75 | DataOutputStream out = new DataOutputStream(conn.getOutputStream()); 76 | // 发送请求参数即数据 77 | out.writeBytes(urlEncode(params)); 78 | // 缓冲数据 79 | out.flush(); 80 | } catch (Exception e) { 81 | // TODO: handle exception 82 | } 83 | } 84 | // 获取URLConnection对象对应的输入流 85 | InputStream is = conn.getInputStream(); 86 | // 构造一个字符流缓存 87 | reader = new BufferedReader(new InputStreamReader(is, DEF_CHATSET)); 88 | String strRead = null; 89 | while ((strRead = reader.readLine()) != null) { 90 | sb.append(strRead); 91 | } 92 | result = sb.toString(); 93 | // 关闭流 94 | is.close(); 95 | } catch (Exception e) { 96 | e.printStackTrace(); 97 | log.error("[接口调用失败]:", e); 98 | throw new RuntimeException(); 99 | } finally { 100 | if (conn != null) { 101 | // 断开连接,最好写上,disconnect是在底层tcp socket链接空闲时才切断。如果正在被其他线程使用就不切断。 102 | // 固定多线程的话,如果不disconnect,链接会增多,直到收发不出信息。写上disconnect后正常一些。 103 | conn.disconnect(); 104 | } 105 | if (reader != null) { 106 | try { 107 | reader.close(); 108 | } catch (IOException e) { 109 | e.printStackTrace(); 110 | } 111 | } 112 | } 113 | return result; 114 | } 115 | 116 | /** 117 | * 将map型转为请求参数型 118 | * 119 | * @param data 请求数据 120 | */ 121 | private static String urlEncode(Map data) { 122 | StringBuilder sb = new StringBuilder(); 123 | for (Map.Entry i : data.entrySet()) { 124 | try { 125 | sb.append(i.getKey()).append("=").append(URLEncoder.encode(i.getValue() + "", "UTF-8")).append("&"); 126 | } catch (UnsupportedEncodingException e) { 127 | e.printStackTrace(); 128 | } 129 | } 130 | return sb.toString(); 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/common/util/IKTokenizerTool.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.common.util; 2 | 3 | import com.tangerinespecter.javabaseutils.common.annotation.ClassInfo; 4 | import com.tangerinespecter.javabaseutils.common.annotation.MethodInfo; 5 | import lombok.extern.slf4j.Slf4j; 6 | 7 | import java.util.List; 8 | 9 | 10 | /** 11 | * 分词工具类 12 | * 13 | * @author TangerineSpecter 14 | */ 15 | @Slf4j 16 | @ClassInfo(Name = "分词工具类") 17 | public class IkTokenizerTool { 18 | 19 | /** 20 | * 切分分词 21 | * 22 | * @param keyword 23 | * @param bol true:开启智能切分 24 | * @return 25 | */ 26 | @MethodInfo(Name = "切分分词", paramInfo = {"关键词", "智能切分"}, returnInfo = "分词结果") 27 | public static String tokenizeKeyWord(String keyword, boolean bol) { 28 | // StringBuilder sb = new StringBuilder(); 29 | // IKTokenizer tokenizer = new IKTokenizer(new StringReader(keyword), bol); 30 | // try { 31 | // while (tokenizer.incrementToken()) { 32 | // TermAttribute termAtt = tokenizer.getAttribute(TermAttribute.class); 33 | // sb.append("|").append(termAtt.term()); 34 | // } 35 | // if (sb.length() > 0) { 36 | // return sb.substring(1).toString(); 37 | // } 38 | // return keyword; 39 | // } catch (IOException e) { 40 | // log.error("切分失败", e); 41 | // return keyword; 42 | // } finally { 43 | // if (tokenizer != null) { 44 | // try { 45 | // tokenizer.close(); 46 | // } catch (IOException e) { 47 | // log.error("切分失败", e); 48 | // } 49 | // } 50 | // } 51 | return null; 52 | } 53 | 54 | /** 55 | * 切分分词 56 | * 57 | * @param keyword 58 | * @param bol true:开启智能切分 59 | * @return 60 | */ 61 | @MethodInfo(Name = "切分分词", paramInfo = {"关键词", "智能切分"}, returnInfo = "分词结果") 62 | public static List tokenizeKeyWordList(String keyword, boolean bol) { 63 | // List list = new ArrayList(); 64 | // IKTokenizer tokenizer = new IKTokenizer(new StringReader(keyword), bol); 65 | // try { 66 | // while (tokenizer.incrementToken()) { 67 | // TermAttribute termAtt = tokenizer.getAttribute(TermAttribute.class); 68 | // list.add(termAtt.term()); 69 | // } 70 | // return list; 71 | // } catch (IOException e) { 72 | // log.error("切分失败", e); 73 | // return list; 74 | // } finally { 75 | // if (tokenizer != null) { 76 | // try { 77 | // tokenizer.close(); 78 | // } catch (IOException e) { 79 | // log.error("切分失败", e); 80 | // } 81 | // } 82 | // } 83 | return null; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/common/util/ImageUtils.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.common.util; 2 | 3 | import com.tangerinespecter.javabaseutils.common.annotation.ClassInfo; 4 | import com.tangerinespecter.javabaseutils.common.annotation.MethodInfo; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.apache.commons.codec.binary.Base64; 7 | import org.jsoup.Jsoup; 8 | import org.jsoup.nodes.Document; 9 | import org.jsoup.nodes.Element; 10 | import org.jsoup.select.Elements; 11 | 12 | import javax.imageio.ImageIO; 13 | import java.awt.*; 14 | import java.awt.image.BufferedImage; 15 | import java.io.*; 16 | import java.net.HttpURLConnection; 17 | import java.net.MalformedURLException; 18 | import java.net.URL; 19 | import java.net.URLConnection; 20 | import java.util.List; 21 | import java.util.UUID; 22 | 23 | /** 24 | * 图片处理工具类 25 | * 26 | * @author TangerineSpecter 27 | */ 28 | @Slf4j 29 | @ClassInfo(Name = "图片处理工具类") 30 | public class ImageUtils { 31 | 32 | /** 33 | * jpg文件 34 | */ 35 | private static final String JPG_FILE = "jpg"; 36 | /** 37 | * png文件 38 | */ 39 | private static final String PNG_FILE = "png"; 40 | /** 41 | * jpeg文件 42 | */ 43 | private static final String JPEG_FILE = "jpeg"; 44 | 45 | /** 46 | * 传入要下载的图片的url列表,将url所对应的图片下载到本地 47 | * 48 | * @param urlList url列表 49 | * @return 50 | * @throws Exception 51 | */ 52 | @MethodInfo(Name = "将Url图片下载到本地", paramInfo = {"url列表"}) 53 | public static void downloadPicture(List urlList) { 54 | URL url = null; 55 | String uuid = UUID.randomUUID().toString(); 56 | 57 | for (String urlString : urlList) { 58 | try { 59 | url = new URL(urlString); 60 | DataInputStream dataInputStream = new DataInputStream(url.openStream()); 61 | String imagePath = Constant.FILE_SAVE_PATH + uuid + ".jpg"; 62 | File image = new File(imagePath); 63 | FileOutputStream fileOutputStream = new FileOutputStream(image); 64 | 65 | byte[] buffer = new byte[1024]; 66 | int length; 67 | 68 | while ((length = dataInputStream.read(buffer)) > 0) { 69 | fileOutputStream.write(buffer, 0, length); 70 | } 71 | 72 | image.createNewFile(); 73 | dataInputStream.close(); 74 | fileOutputStream.close(); 75 | log.info("【图片生成成功...】"); 76 | } catch (MalformedURLException e) { 77 | log.error(String.format("【下载图片url地址错误】:%s", e)); 78 | e.printStackTrace(); 79 | } catch (IOException e) { 80 | log.error(String.format("【下载图片IO异常】:%s", e)); 81 | e.printStackTrace(); 82 | } 83 | } 84 | } 85 | 86 | /** 87 | * 传入要下载的图片的url以及保存地址,将图片下载到本地 88 | * 89 | * @param imageUrl 图片地址 90 | * @param imagePath 图片保存路径 91 | */ 92 | @MethodInfo(Name = "将Url图片下载到本地", paramInfo = {"url地址", "保存路径"}) 93 | public static void downloadPicture(String imageUrl, String imagePath) { 94 | String fileName = imageUrl; 95 | 96 | try { 97 | // 创建文件目录 98 | File files = new File(imagePath); 99 | // 判断是否存在文件夹 100 | if (!files.exists()) { 101 | files.mkdirs(); 102 | } 103 | // 获取下载地址 104 | URL url = new URL(imageUrl); 105 | // 连接网络地址 106 | HttpURLConnection huc = (HttpURLConnection) url.openConnection(); 107 | // 获取连接的输出流 108 | InputStream is = huc.getInputStream(); 109 | // 创建文件 110 | File file = new File(imagePath + fileName); 111 | // 创建输入流,写入文件 112 | FileOutputStream out = null; 113 | if (file.getName().endsWith(JPG_FILE) || file.getName().endsWith(PNG_FILE) || file.getName().endsWith(JPEG_FILE) 114 | || file.getName().endsWith(JPG_FILE)) { 115 | out = new FileOutputStream(file); 116 | int i = 0; 117 | while ((i = is.read()) != -1) { 118 | out.write(i); 119 | } 120 | is.close(); 121 | out.close(); 122 | } 123 | 124 | } catch (Exception e) { 125 | log.error(String.format("【下载图片异常】:%s", e)); 126 | e.printStackTrace(); 127 | } 128 | } 129 | 130 | /** 131 | * 给图片加水印 132 | * 133 | * @param srcImgPath 需要处理图片路径 134 | * @param outImgPath 图片保存路径 135 | * @param locationX 水印x坐标 136 | * @param locationY 水印y坐标 137 | * @param content 水印内容 138 | * @param font 水印字体 139 | * @param color 水印字体颜色 140 | */ 141 | @MethodInfo(Name = "给图片加水印", paramInfo = {"需要处理的图片路径", "图片保存路径", "水印x坐标", "水印y坐标", "水印内容", "水印字体", "水印字体颜色"}) 142 | public static void addWaterMark(String srcImgPath, String outImgPath, int locationX, int locationY, String content, 143 | Font font, Color color) { 144 | try { 145 | // 读取原图片信息 146 | File srcImgFile = new File(srcImgPath); 147 | Image srcImg = ImageIO.read(srcImgFile); 148 | int srcImgWidth = srcImg.getWidth(null); 149 | int srcImgHeight = srcImg.getHeight(null); 150 | String uuid = UUID.randomUUID().toString(); 151 | // 加水印 152 | BufferedImage bufImg = new BufferedImage(srcImgWidth, srcImgHeight, BufferedImage.TYPE_INT_RGB); 153 | Graphics2D g = bufImg.createGraphics(); 154 | g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); 155 | g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER)); 156 | g.drawImage(srcImg, 0, 0, srcImgWidth, srcImgHeight, null); 157 | // 根据图片的背景设置水印颜色 158 | g.setColor(color); 159 | g.setFont(font); 160 | g.drawString(content, locationX, locationY); 161 | g.dispose(); 162 | // 输出图片 163 | File newImage = new File(outImgPath + uuid + ".jpg"); 164 | FileOutputStream outImgStream = new FileOutputStream(newImage); 165 | ImageIO.write(bufImg, JPG_FILE, outImgStream); 166 | newImage.createNewFile(); 167 | outImgStream.flush(); 168 | outImgStream.close(); 169 | log.info("【图片添加水印成功...】"); 170 | } catch (Exception e) { 171 | e.printStackTrace(); 172 | log.error(String.format("【图片添加水印失败】:%s", e)); 173 | } 174 | } 175 | 176 | /** 177 | * 获取水印文字总长度 178 | * 179 | * @param waterMarkContent 水印的文字 180 | * @param g 181 | * @return 水印文字总长度 182 | */ 183 | @MethodInfo(Name = "获取水印文字总长度", paramInfo = {"水印文字", "Graphics2D类"}, returnInfo = "水印文字总长度") 184 | public int getWatermarkLength(String waterMarkContent, Graphics2D g) { 185 | return g.getFontMetrics(g.getFont()).charsWidth(waterMarkContent.toCharArray(), 0, waterMarkContent.length()); 186 | } 187 | 188 | /** 189 | * @param imagePath 图片的绝对路径地址 190 | * @return 191 | * @description 获取图片的二进制数据 192 | */ 193 | @MethodInfo(Name = "获取图片的二进制数据", paramInfo = {"图片的绝对路径地址"}, returnInfo = "二进制数据") 194 | public static byte[] getPicData(String imagePath) { 195 | byte[] data = null; 196 | try { 197 | FileInputStream fi = new FileInputStream(imagePath); 198 | int length = fi.available(); 199 | data = new byte[length]; 200 | fi.read(data); 201 | fi.close(); 202 | } catch (Exception e) { 203 | log.error(String.format("【获取图片数据异常】:%s", e)); 204 | System.out.println(e); 205 | } 206 | return data; 207 | } 208 | 209 | /** 210 | * 读取文件并压缩数据然后转Base64编码 211 | * 212 | * @param imagePath 图片的绝对路径地址 213 | * @return 214 | */ 215 | @MethodInfo(Name = "读取文件压缩后转Base64编码", paramInfo = {"图片的绝对路径地址"}, returnInfo = "Base64编码") 216 | public static String base64(String imagePath) { 217 | byte[] data = getPicData(imagePath); 218 | if (data == null) { 219 | return null; 220 | } 221 | byte[] zipData = ZipUtils.gZip(data); 222 | return Base64.encodeBase64String(zipData); 223 | } 224 | 225 | /** 226 | * 获取网页所有图片并下载 227 | * 228 | * @param url 网页地址 229 | * @param encoding 网页编码 230 | * @param path 存放图片地址 231 | */ 232 | @MethodInfo(Name = "获取网页所有图片并下载", paramInfo = {"网页地址", "网页编码", "存放路径"}) 233 | public static void getWebImage(String url, String encoding, String path) { 234 | String htmlResouce = getHtmlResourceByUrl(url, encoding); 235 | // 解析网页源代码 236 | Document document = Jsoup.parse(htmlResouce); 237 | // 获取所以图片的地址 238 | Elements elements = document.getElementsByTag("img"); 239 | for (Element element : elements) { 240 | String imgSrc = element.attr("src"); 241 | if (!"".equals(imgSrc)) { 242 | if (imgSrc.startsWith("http://")) { 243 | downloadPicture(path, imgSrc); 244 | } else { 245 | imgSrc = "http:" + imgSrc; 246 | downloadPicture(path, imgSrc); 247 | } 248 | } 249 | } 250 | } 251 | 252 | /** 253 | * 根据网站的地址和页面的编码集来获取网页的源代码 254 | * 255 | * @param url 网址路径 256 | * @param encoding 编码集 257 | * @return String 网页的源代码 258 | */ 259 | @MethodInfo(Name = "获取网页源代码", paramInfo = {"网页地址", "编码集"}, returnInfo = "源代码") 260 | public static String getHtmlResourceByUrl(String url, String encoding) { 261 | // 用于存储网页源代码 262 | StringBuffer buf = new StringBuffer(); 263 | URL urlObj = null; 264 | URLConnection uc = null; 265 | InputStreamReader isr = null; 266 | BufferedReader buffer = null; 267 | try { 268 | // 建立网络连接 269 | urlObj = new URL(url); 270 | // 打开网络连接 271 | uc = urlObj.openConnection(); 272 | // 将连接网络的输入流转换 273 | isr = new InputStreamReader(uc.getInputStream(), encoding); 274 | // 建立缓冲写入流 275 | buffer = new BufferedReader(isr); 276 | String line = null; 277 | while ((line = buffer.readLine()) != null) { 278 | buf.append(line + "\n"); 279 | } 280 | } catch (Exception e) { 281 | e.printStackTrace(); 282 | } finally { 283 | try { 284 | if (isr != null) { 285 | isr.close(); 286 | } 287 | } catch (Exception e) { 288 | log.error(String.format("【获取网页源代码异常】:%s", e)); 289 | e.printStackTrace(); 290 | } 291 | } 292 | return buf.toString(); 293 | } 294 | } 295 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/common/util/JsonUtils.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.common.util; 2 | 3 | import cn.hutool.core.collection.CollUtil; 4 | import cn.hutool.core.map.MapUtil; 5 | import cn.hutool.core.util.ReflectUtil; 6 | import cn.hutool.core.util.StrUtil; 7 | import cn.hutool.json.JSONUtil; 8 | import com.google.common.base.Splitter; 9 | 10 | import java.lang.reflect.Field; 11 | import java.lang.reflect.ParameterizedType; 12 | import java.lang.reflect.Type; 13 | import java.util.*; 14 | 15 | /** 16 | * json处理工具类 17 | * 18 | * @author TangerineSpecter 19 | * @date 2023年11月30日10:51:35 20 | */ 21 | @SuppressWarnings("all") 22 | public class JsonUtils { 23 | 24 | /** 25 | * url参数处理成Map键值对形式 26 | * 27 | * @param params url参数,示例:?userid=test&meetingId=test 28 | * @return map数据 29 | */ 30 | public static Map urlParam2Map(String params) { 31 | Map result = MapUtil.newHashMap(); 32 | if (StrUtil.isBlank(params)) { 33 | return result; 34 | } 35 | List paramGroup = StrUtil.split(params, "&"); 36 | for (String param : paramGroup) { 37 | final List p = StrUtil.split(param, "="); 38 | Object value = CollUtil.get(p, 1); 39 | value = Objects.equals(value, "null") ? null : value; 40 | result.put(CollUtil.get(p, 0), value); 41 | } 42 | return result; 43 | } 44 | 45 | /** 46 | * url参数处理成JSON字符串 47 | * 48 | * @param params url参数,示例:?userid=test&meetingId=test 49 | * @return json字符串 50 | */ 51 | public static String urlParam2Json(String params) { 52 | return JSONUtil.toJsonStr(urlParam2Map(params)); 53 | } 54 | 55 | /** 56 | * @param obj 转换的对象 57 | * @param objStr 需要转换成成对象的字符串打印结果 58 | * @param 泛型 59 | * @return 解析成json格式的对象信息 60 | */ 61 | public static T objStr2Json(Class obj, String objStr) { 62 | final T result = ReflectUtil.newInstance(obj); 63 | //获取字段map 64 | final Map fieldMap = ReflectUtil.getFieldMap(obj); 65 | 66 | String content = getObjStrContent(obj, objStr); 67 | if (content == null) { 68 | return result; 69 | } 70 | final List fieldGroup = Splitter.on(",").splitToList(content); 71 | for (String fieldStr : fieldGroup) { 72 | handleFieldType(result, content, fieldStr, fieldMap); 73 | } 74 | return result; 75 | } 76 | 77 | /** 78 | * 填充对应字段的value 79 | * 80 | * @param result 返回对象 81 | * @param content 解析字符串内容 82 | * @param fieldPairs 键值对,格式:fieldName=value 83 | * @param fieldMap 键值对映射关系 84 | * @param 泛型 85 | */ 86 | private static void handleFieldType(T result, String content, String fieldPairs, Map fieldMap) { 87 | List fieldParam = Splitter.on("=").splitToList(fieldPairs); 88 | String paramName = CollUtil.get(fieldParam, 0); 89 | String paramValue = CollUtil.get(fieldParam, 1); 90 | paramValue = Objects.equals(paramValue, "null") ? null : paramValue; 91 | Field field = fieldMap.get(StrUtil.cleanBlank(paramName)); 92 | if (field == null) { 93 | return; 94 | } 95 | 96 | if (checkBaseType(field.getType())) { 97 | ReflectUtil.setFieldValue(result, StrUtil.cleanBlank(paramName), paramValue); 98 | } else if (Objects.equals(field.getType(), List.class) || Objects.equals(field.getType(), Set.class)) { 99 | Type listElement = ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0]; 100 | T eleObj = ReflectUtil.newInstance(listElement.getTypeName()); 101 | Class listEleClazz = eleObj.getClass(); 102 | Collection list = CollUtil.newArrayList(); 103 | if (checkBaseType(listEleClazz)) { 104 | //常规list\set 105 | String[] arrElements = StrUtil.subBetweenAll(paramValue, "[", "]"); 106 | for (String arrElement : arrElements) { 107 | list.add((T) arrElement); 108 | } 109 | ReflectUtil.setFieldValue(result, field.getName(), list); 110 | return; 111 | } else { 112 | String[] eleContents = StrUtil.subBetweenAll(content, listEleClazz.getSimpleName() + "(", ")"); 113 | for (String eleContent : eleContents) { 114 | T newInfo = ReflectUtil.newInstance(listElement.getTypeName()); 115 | final Map elefieldMap = ReflectUtil.getFieldMap(newInfo.getClass()); 116 | for (String eleFieldPairs : Splitter.on(",").splitToList(eleContent)) { 117 | handleFieldType(newInfo, eleContent, eleFieldPairs, elefieldMap); 118 | } 119 | list.add(newInfo); 120 | } 121 | } 122 | ReflectUtil.setFieldValue(result, field.getName(), list); 123 | } 124 | } 125 | 126 | /** 127 | * 检测基本类型,箱体类型,字符串类型 128 | * 129 | * @param type 字段类型 130 | * @return true:符合 131 | */ 132 | private static boolean checkBaseType(Class type) { 133 | List> boxedTypes = CollUtil.newArrayList(Integer.class, Boolean.class, Float.class, Byte.class, Short.class, Long.class, Double.class, Character.class); 134 | return type.equals(String.class) || type.isPrimitive() || boxedTypes.contains(type); 135 | } 136 | 137 | /** 138 | * 获取对象的内部信息 139 | */ 140 | private static String getObjStrContent(Class clazz, String objStr) { 141 | objStr = StrUtil.subAfter(objStr, clazz.getSimpleName() + "(", false); 142 | objStr = StrUtil.subBefore(objStr, ")", true); 143 | return objStr; 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/common/util/LoggerWordPool.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.common.util; 2 | 3 | /** 4 | * 日志信息信息池 5 | * 6 | * @author TangerineSpecter 7 | */ 8 | public class LoggerWordPool { 9 | 10 | /** 11 | * 文件工具类相关日志信息 12 | */ 13 | static class FileLogger { 14 | /** 15 | * 文件写入错误 16 | */ 17 | public static final String FILE_WRITE_ERROR = "【文件写入出错】:{}"; 18 | /** 19 | * 文件删除成功 20 | */ 21 | public static final String FILE_DELETE_SUCCESS = "【删除文件成功】文件名:{}"; 22 | /** 23 | * 文件夹删除成功 24 | */ 25 | public static final String DIRFILE_DELETE_SUCCESS = "【删除文件夹成功】文件夹名:{}"; 26 | /** 27 | * 删除文件总数 28 | */ 29 | public static final String FILE_DELETE_TOTAL_COUNT = "【删除文件总数】:{}个文件"; 30 | /** 31 | * 文件转移成功 32 | */ 33 | public static final String FILE_MOVE_SUCCESS = "【文件转移成功】转移路径:{}"; 34 | /** 35 | * 存在同名文件 36 | */ 37 | public static final String FILE_SAME_NAME_EXIST = "【存在同名文件】:{}"; 38 | /** 39 | * 总共转移文件数 40 | */ 41 | public static final String FILE_MOVE_TOTAL_COUNT = "【总共转移文件数】:{}个文件"; 42 | /** 43 | * 文件夹创建成功 44 | */ 45 | public static final String FILE_CREATE_SUCCESS = "【文件夹创建成功】文件路径:{}"; 46 | /** 47 | * 文件夹创建失败 48 | */ 49 | public static final String FILE_CREATE_FAIL = "【文件夹创建失败】:{}"; 50 | /** 51 | * 文件没有找到 52 | */ 53 | public static final String FILE_NOT_FOUND = "【文件没有找到】"; 54 | /** 55 | * 文件夹没有找到 56 | */ 57 | public static final String DIRFILE_NOT_FOUND = "【文件夹没有找到】"; 58 | /** 59 | * 文件类型不明 60 | */ 61 | public static final String FILE_TYPE_UNKNOWN = "【文件类型不明】"; 62 | } 63 | 64 | /** 65 | * 解压工具类日志信息 66 | */ 67 | class ZipLogger { 68 | /** 69 | * 压缩数据异常 70 | */ 71 | public static final String ZIP_DATA_ERROR = "【压缩数据异常】:{}"; 72 | /** 73 | * 流关闭异常 74 | */ 75 | public static final String STREAM_CLOSE_ERROR = "【流关闭异常】:{}"; 76 | /** 77 | * 解压数据异常 78 | */ 79 | public static final String UNZIP_DATA_ERROR = "【解压数据异常】:{}"; 80 | /** 81 | * 源文件路径 82 | */ 83 | public static final String SOURCE_FILE_PATH = "【源文件路径】:{}"; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/common/util/LollipopUtils.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.common.util; 2 | 3 | import com.tangerinespecter.javabaseutils.common.annotation.ClassInfo; 4 | import com.tangerinespecter.javabaseutils.common.annotation.MethodInfo; 5 | import lombok.extern.slf4j.Slf4j; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * 甜点 11 | * 12 | * @author TangerineSpecter 13 | */ 14 | @Slf4j 15 | @ClassInfo(Name = "暴力破解工具") 16 | public class LollipopUtils extends DecipheringUtils { 17 | 18 | /** 19 | * * 暴力破解密码 20 | * 21 | * @param content 破解内容 22 | * @param plies 破解层数 23 | * @param isInfo 错误信息输出 24 | */ 25 | @MethodInfo(Name = "暴力破解密码", paramInfo = {"破解内容", "破解层数", "错误信息输出"}) 26 | public static void rceAttack(String content, int plies, boolean isInfo) { 27 | String result; 28 | ERROR_INFO = isInfo; 29 | // 初始化破解列表 30 | List> lists = NumberUtils.getFullPermutation(PASSWORD_INDEX, plies); 31 | if (lists.isEmpty()) { 32 | if (ERROR_INFO) { 33 | log.info("【暴戾破解密码失败】"); 34 | } 35 | } 36 | for (List list : lists) { 37 | result = content; 38 | for (Integer index : list) { 39 | switch (index) { 40 | case Constant.Deciphering.INDEX_MORSE: 41 | result = getMorseResult(result); 42 | break; 43 | case Constant.Deciphering.INDEX_RAILFENCE: 44 | result = getRailFenceResult(result, 2); 45 | break; 46 | case Constant.Deciphering.INDEX_PHONE_TYPEWRITING: 47 | result = getPhoneTypewritingResult(result); 48 | break; 49 | case Constant.Deciphering.INDEX_KEYBOARD_TYPE: 50 | result = getKeyboardResult(result); 51 | break; 52 | case Constant.Deciphering.INDEX_BACON: 53 | result = getBaconResult(result); 54 | break; 55 | case Constant.Deciphering.INDEX_REVERSE_ORDER: 56 | result = reverseOrder(result); 57 | break; 58 | default: 59 | break; 60 | } 61 | if (StringUtils.isEmpty(result)) { 62 | break; 63 | } 64 | } 65 | if (!StringUtils.isEmpty(result)) { 66 | log.info(getProcessInfo(list) + result.toLowerCase()); 67 | } 68 | } 69 | } 70 | 71 | /** 72 | * 获取解密流程信息 73 | * 74 | * @param numbers 解密流程 75 | * @return 76 | */ 77 | private static String getProcessInfo(List numbers) { 78 | StringBuilder info = new StringBuilder(Constant.NULL_KEY_STR); 79 | for (int number : numbers) { 80 | switch (number) { 81 | case 0: 82 | info.append(Constant.Deciphering.MORSE_TYPE + "->"); 83 | break; 84 | case 1: 85 | info.append(Constant.Deciphering.RAILFENCE_TYPE + "->"); 86 | break; 87 | case 2: 88 | info.append(Constant.Deciphering.PHONE_TYPEWRITING_TYPE + "->"); 89 | break; 90 | case 3: 91 | info.append(Constant.Deciphering.KEYBOARD_TYPE + "->"); 92 | break; 93 | case 4: 94 | info.append(Constant.Deciphering.BACON_TYPE + "->"); 95 | break; 96 | case 5: 97 | info.append(Constant.Deciphering.REVERSE_ORDER_TYPE + "->"); 98 | break; 99 | default: 100 | break; 101 | } 102 | } 103 | return info.toString(); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/common/util/NumChainCal.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.common.util; 2 | 3 | import cn.hutool.core.convert.Convert; 4 | import cn.hutool.core.util.NumberUtil; 5 | 6 | import java.math.BigDecimal; 7 | import java.math.RoundingMode; 8 | 9 | /** 10 | * 链式计算 11 | * 12 | * @author TangerineSpecter 13 | * @date 2023年11月30日11:02:26 14 | */ 15 | public class NumChainCal { 16 | 17 | private BigDecimal value; 18 | 19 | public NumChainCal(Object value) { 20 | this.value = Convert.toBigDecimal(value); 21 | } 22 | 23 | /** 24 | * 计算的开始 25 | * 26 | * @param value 初始值 27 | * @return 计算器 28 | */ 29 | public static NumChainCal startOf(Object value) { 30 | if (value == null) { 31 | return new NumChainCal(0); 32 | } 33 | return new NumChainCal(value); 34 | } 35 | 36 | /** 37 | * 加法 38 | * 39 | * @param otherValue 加数 40 | * @return 结果 41 | */ 42 | public NumChainCal add(Object otherValue) { 43 | this.value = NumberUtil.add(this.value, Convert.toBigDecimal(otherValue)); 44 | return this; 45 | } 46 | 47 | /** 48 | * 加法 49 | * 50 | * @param otherValue 加数 51 | * @return 结果 52 | */ 53 | public NumChainCal add(BigDecimal... otherValue) { 54 | BigDecimal totalValue = NumberUtil.add(otherValue); 55 | this.value = NumberUtil.add(this.value, totalValue); 56 | return this; 57 | } 58 | 59 | /** 60 | * 减法 61 | * 62 | * @param otherValue 减数 63 | * @return 结果 64 | */ 65 | public NumChainCal sub(Object otherValue) { 66 | this.value = NumberUtil.sub(this.value, Convert.toBigDecimal(otherValue)); 67 | return this; 68 | } 69 | 70 | /** 71 | * 乘法 72 | * 73 | * @param otherValue 乘数 74 | * @return 结果 75 | */ 76 | public NumChainCal mul(Object otherValue) { 77 | this.value = NumberUtil.mul(this.value, Convert.toBigDecimal(otherValue)); 78 | return this; 79 | } 80 | 81 | /** 82 | * 除法 83 | * 84 | * @param otherValue 除数 85 | * @return 结果 86 | */ 87 | public NumChainCal div(Object otherValue) { 88 | BigDecimal convertValue = Convert.toBigDecimal(otherValue); 89 | if (convertValue == null || convertValue.equals(BigDecimal.ZERO)) { 90 | return new NumChainCal(0); 91 | } 92 | this.value = NumberUtil.div(this.value, Convert.toBigDecimal(otherValue)); 93 | return this; 94 | } 95 | 96 | /** 97 | * 除法 98 | * 99 | * @param otherValue 除数 100 | * @param scale – 精确度,如果为负值,取绝对值 101 | * @return 结果 102 | */ 103 | public NumChainCal div(Object otherValue, int scale) { 104 | BigDecimal convertValue = Convert.toBigDecimal(otherValue); 105 | if (convertValue.equals(BigDecimal.ZERO)) { 106 | return new NumChainCal(0); 107 | } 108 | this.value = NumberUtil.div(this.value, convertValue, scale); 109 | return this; 110 | } 111 | 112 | /** 113 | * 除法 114 | * 115 | * @param otherValue 除数 116 | * @param scale – 精确度,如果为负值,取绝对值 117 | * @param roundingMode 保留小数的模式 118 | * @return 结果 119 | */ 120 | public NumChainCal div(Object otherValue, int scale, RoundingMode roundingMode) { 121 | BigDecimal convertValue = Convert.toBigDecimal(otherValue); 122 | if (convertValue.equals(BigDecimal.ZERO)) { 123 | return new NumChainCal(0); 124 | } 125 | this.value = NumberUtil.div(this.value, convertValue, scale, roundingMode); 126 | return this; 127 | } 128 | 129 | /** 130 | * 获取int数值 131 | * 132 | * @return int结果 133 | */ 134 | public Integer getInteger() { 135 | return Convert.toInt(this.value); 136 | } 137 | 138 | /** 139 | * 获取int数值 140 | * 141 | * @param roundingMode 取整方式 142 | * @return int结果 143 | */ 144 | public Integer getInteger(RoundingMode roundingMode) { 145 | return Convert.toInt(this.value.setScale(0, roundingMode)); 146 | } 147 | 148 | /** 149 | * 获取Long数值 150 | * 151 | * @return int结果 152 | */ 153 | public Long getLong() { 154 | return Convert.toLong(this.value); 155 | } 156 | 157 | /** 158 | * 获取BigDecimal数值 159 | * 160 | * @return BigDecimal结果 161 | */ 162 | public BigDecimal getBigDecimal() { 163 | return Convert.toBigDecimal(this.value).setScale(4, RoundingMode.CEILING); 164 | } 165 | 166 | /** 167 | * 获取BigDecimal数值 168 | * 169 | * @param scale 保留小数位 170 | * @return BigDecimal结果 171 | */ 172 | public BigDecimal getBigDecimal(int scale) { 173 | return Convert.toBigDecimal(this.value).setScale(scale, RoundingMode.CEILING); 174 | } 175 | 176 | /** 177 | * 获取BigDecimal数值 178 | * 179 | * @param scale 保留小数位 180 | * @param roundingMode 舍入模式 181 | * @return BigDecimal结果 182 | */ 183 | public BigDecimal getBigDecimal(int scale, RoundingMode roundingMode) { 184 | return Convert.toBigDecimal(this.value).setScale(scale, roundingMode); 185 | } 186 | } 187 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/common/util/NumberUtils.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.common.util; 2 | 3 | import com.tangerinespecter.javabaseutils.common.annotation.ClassInfo; 4 | import com.tangerinespecter.javabaseutils.common.annotation.MethodInfo; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * 数字处理工具类 11 | * 12 | * @author TangerineSpecter 13 | */ 14 | @ClassInfo(Name = "数字处理工具类") 15 | public class NumberUtils { 16 | 17 | private static List> lists = new ArrayList<>(); 18 | 19 | /** 20 | * 从Array中拿出n个元素进行全排列 21 | * 22 | * @param number 总的数字数组 23 | * @param n 需要取出进行排列的元素个数 24 | * @return 25 | */ 26 | @MethodInfo(Name = "从Array中拿出n个元素进行全排列", paramInfo = {"数字数组", "需要取出的元素个数"}, returnInfo = "排列结果") 27 | public static List> getFullPermutation(int[] number, int n) { 28 | if (n <= 0 || number == null) { 29 | return null; 30 | } 31 | List intList = new ArrayList<>(); 32 | // 通过这一步初始化序列的长度 33 | for (int i = 0; i < n; i++) { 34 | intList.add(-1); 35 | } 36 | listAll(intList, number, n); 37 | return lists; 38 | } 39 | 40 | /** 41 | * 从m个元素中任取n个并对结果进行全排列 42 | * 43 | * @param list 用于承载可能的排列情况的List 44 | * @param number 总的数字数组,长度为m 45 | * @param n 从中取得字符个数 46 | */ 47 | @MethodInfo(Name = "从m个元素中任取n个并对结果进行全排列", paramInfo = {"装载排列结果list", "数字数组", "取出的元素个数"}) 48 | public static void listAll(List list, int[] number, int n) { 49 | if (n == 0) { 50 | List li = new ArrayList<>(); 51 | li.addAll(list); 52 | // 添加一种可能的排列 53 | lists.add(li); 54 | return; 55 | } 56 | for (int num : number) { 57 | // 若List中不包含这一位元素 58 | if (!list.contains(num)) { 59 | // 将当前元素加入 60 | list.set(list.size() - n, num); 61 | // 否则跳到下一位// 否则跳到下一位 62 | } else { 63 | continue; 64 | } 65 | // 下一位 66 | listAll(list, number, n - 1); 67 | // 还原 68 | list.set(list.size() - n, -1); 69 | } 70 | } 71 | 72 | /** 73 | * 从Array中拿出n个元素进行全排列 74 | * 75 | * @param chars 总的字符数组 76 | * @param n 需要取出进行排列的元素个数 77 | * @return 78 | */ 79 | @MethodInfo(Name = "从Array中拿出n个元素进行全排列", paramInfo = {"字符数组", "取出的元素个数"}) 80 | public static void getFullPermutation(char[] chars, int n) { 81 | if (n <= 0 || chars == null) { 82 | return; 83 | } 84 | List charList = new ArrayList<>(); 85 | // 通过这一步初始化序列的长度 86 | for (int i = 0; i < n; i++) { 87 | charList.add('#'); 88 | } 89 | listAll(charList, chars, n); 90 | } 91 | 92 | /** 93 | * 从m个元素中任取n个并对结果进行全排列 94 | * 95 | * @param list 用于承载可能的排列情况的List 96 | * @param chars 总的字符数组,长度为m 97 | * @param n 从中取得字符个数 98 | */ 99 | @MethodInfo(Name = "从m个元素中任取n个并对结果进行全排列", paramInfo = {"装载排列结果list", "字符数组", "取出的元素个数"}) 100 | public static void listAll(List list, char[] chars, int n) { 101 | if (n == 0) { 102 | // 输出一种可能的排列 103 | System.out.println(list); 104 | return; 105 | } 106 | for (char c : chars) { 107 | // 若List中不包含这一位元素 108 | if (!list.contains(c)) { 109 | // 将当前元素加入 110 | list.set(list.size() - n, c); 111 | // 否则跳到下一位 112 | } else { 113 | continue; 114 | } 115 | // 下一位 116 | listAll(list, chars, n - 1); 117 | // 还原 118 | list.set(list.size() - n, '#'); 119 | } 120 | System.out.println(lists); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/common/util/PDFUtils.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.common.util; 2 | 3 | import com.itextpdf.io.font.FontConstants; 4 | import com.itextpdf.kernel.font.PdfFontFactory; 5 | import com.itextpdf.kernel.geom.PageSize; 6 | import com.itextpdf.kernel.pdf.PdfDocument; 7 | import com.itextpdf.kernel.pdf.PdfPage; 8 | import com.itextpdf.kernel.pdf.PdfWriter; 9 | import com.itextpdf.kernel.pdf.canvas.PdfCanvas; 10 | import com.itextpdf.layout.Document; 11 | import com.itextpdf.layout.element.Paragraph; 12 | import com.tangerinespecter.javabaseutils.common.annotation.ClassInfo; 13 | import com.tangerinespecter.javabaseutils.common.annotation.MethodInfo; 14 | 15 | import java.io.File; 16 | import java.io.FileNotFoundException; 17 | import java.util.List; 18 | 19 | /** 20 | * PDF工具类 21 | * 22 | * @author PDF工具类 23 | * @doc http://itextpdf.com/ 24 | */ 25 | @ClassInfo(Name = "PDF工具类") 26 | public class PdfUtils { 27 | 28 | @MethodInfo(Name = "创建PDF", paramInfo = {"无"}) 29 | public static void createPdf() { 30 | try { 31 | File file = new File("F://world.pdf"); 32 | PdfWriter writer = new PdfWriter(file); 33 | PdfDocument pdf = new PdfDocument(writer); 34 | PageSize pageSize = PageSize.A4; 35 | PdfPage page = pdf.addNewPage(pageSize); 36 | PdfCanvas pdfCanvas = new PdfCanvas(page); 37 | Document document = new Document(pdf); 38 | document.add(new Paragraph("Hello World!")); 39 | document.close(); 40 | } catch (FileNotFoundException e) { 41 | e.printStackTrace(); 42 | } 43 | } 44 | 45 | @Deprecated 46 | @MethodInfo(Name = "创建PDF", paramInfo = {"生成路径", "文本内容"}) 47 | public static void createPdf(String path, List text) { 48 | try { 49 | File file = new File(path); 50 | PdfWriter writer = new PdfWriter(file); 51 | PdfDocument pdf = new PdfDocument(writer); 52 | PageSize pageSize = PageSize.A4; 53 | PdfPage page = pdf.addNewPage(pageSize); 54 | PdfCanvas canvas = new PdfCanvas(page); 55 | canvas.concatMatrix(1, 0, 0, 1, 0, pageSize.getHeight()); 56 | canvas.beginText().setFontAndSize(PdfFontFactory.createFont(FontConstants.COURIER_BOLD), 14) 57 | .setLeading(14 * 1.2f).moveText(70, -40); 58 | for (String s : text) { 59 | canvas.newlineShowText(s); 60 | } 61 | canvas.endText(); 62 | Document document = new Document(pdf); 63 | document.add(new Paragraph("Hello World!")); 64 | document.close(); 65 | } catch (Exception e) { 66 | e.printStackTrace(); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/common/util/QrCodeUtils.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.common.util; 2 | 3 | import com.google.zxing.BarcodeFormat; 4 | import com.google.zxing.EncodeHintType; 5 | import com.google.zxing.MultiFormatWriter; 6 | import com.google.zxing.client.j2se.MatrixToImageWriter; 7 | import com.google.zxing.common.BitMatrix; 8 | import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; 9 | import com.tangerinespecter.javabaseutils.common.annotation.ClassInfo; 10 | import com.tangerinespecter.javabaseutils.common.annotation.MethodInfo; 11 | import lombok.extern.slf4j.Slf4j; 12 | 13 | import javax.imageio.ImageIO; 14 | import java.awt.*; 15 | import java.awt.image.BufferedImage; 16 | import java.io.File; 17 | import java.util.HashMap; 18 | import java.util.Map; 19 | 20 | /** 21 | * 二维码生成工具类 22 | * 23 | * @author TangerineSpecter 24 | */ 25 | @Slf4j 26 | @ClassInfo(Name = "二维码生成工具类") 27 | public class QrCodeUtils { 28 | 29 | /** 30 | * 生成不带logo的二维码 31 | * 32 | * @param data 33 | * @param charset 34 | * @param hint 35 | * @param width 36 | * @param height 37 | * @return 38 | */ 39 | @MethodInfo(Name = "生成不带logo的二维码", paramInfo = {"数据", "编码类型", "二维码属性", "宽度", "高度"}, returnInfo = "二维码图片") 40 | public static BufferedImage createQrCode(String data, String charset, Map hint, int width, 41 | int height) { 42 | BitMatrix matrix; 43 | try { 44 | matrix = new MultiFormatWriter().encode(new String(data.getBytes(charset), charset), BarcodeFormat.QR_CODE, 45 | width, height, hint); 46 | return MatrixToImageWriter.toBufferedImage(matrix); 47 | } catch (Exception e) { 48 | log.error("【生成不带logo的二维码生成出错】"); 49 | throw new RuntimeException(e.getMessage(), e); 50 | } 51 | } 52 | 53 | /** 54 | * 以默认参数生成不带logo的二维码 55 | * 56 | * @param data 57 | * @param width 58 | * @param height 59 | * @return 60 | */ 61 | @MethodInfo(Name = "生成不带logo的默认参数二维码", paramInfo = {"数据", "宽度", "高度"}, returnInfo = "二维码图片") 62 | public static BufferedImage createQrCode(String data, int width, int height) { 63 | String charset = "utf-8"; 64 | Map hint = new HashMap(16); 65 | hint.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); 66 | hint.put(EncodeHintType.CHARACTER_SET, charset); 67 | hint.put(EncodeHintType.MARGIN, 0); 68 | return createQrCode(data, charset, hint, width, height); 69 | } 70 | 71 | /** 72 | * 生成带logo的二维码 73 | * 74 | * @param data 75 | * @param charset 76 | * @param width 77 | * @param height 78 | * @param logoFile 79 | * @return 80 | */ 81 | @MethodInfo(Name = "生成带logo的二维码", paramInfo = {"数据", "编码类型", "二维码属性", "宽度", "高度", 82 | "logo文件路径"}, returnInfo = "二维码图片") 83 | public static BufferedImage createQrCodeWithLogo(String data, String charset, Map hint, 84 | int width, int height, File logoFile) { 85 | try { 86 | BufferedImage qrcode = createQrCode(data, charset, hint, width, height); 87 | BufferedImage logo = ImageIO.read(logoFile); 88 | int deltaHeight = height - logo.getHeight(); 89 | int deltaWidth = width - logo.getWidth(); 90 | 91 | BufferedImage combined = new BufferedImage(height, width, BufferedImage.TYPE_INT_RGB); 92 | Graphics2D g = (Graphics2D) combined.getGraphics(); 93 | g.drawImage(qrcode, 0, 0, null); 94 | g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f)); 95 | g.drawImage(logo, (int) Math.round(deltaWidth / 2), (int) Math.round(deltaHeight / 2), null); 96 | return combined; 97 | } catch (Exception e) { 98 | log.error("【生成带logo的二维码生成出错】"); 99 | throw new RuntimeException(e.getMessage(), e); 100 | } 101 | } 102 | 103 | /** 104 | * 以默认参数生成带logo的二维码 105 | * 106 | * @param data 107 | * @param width 108 | * @param height 109 | * @return 110 | */ 111 | @MethodInfo(Name = "生成带logo的默认参数二维码", paramInfo = {"数据", "宽度", "高度", "logo文件路径"}, returnInfo = "二维码图片") 112 | public static BufferedImage createQrCodeWithLogo(String data, int width, int height, File logo) { 113 | String charset = "utf-8"; 114 | Map hint = new HashMap(16); 115 | hint.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); 116 | hint.put(EncodeHintType.CHARACTER_SET, charset); 117 | hint.put(EncodeHintType.MARGIN, 0); 118 | return createQrCodeWithLogo(data, charset, hint, width, height, logo); 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/common/util/RandomUtils.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.common.util; 2 | 3 | import com.tangerinespecter.javabaseutils.common.annotation.ClassInfo; 4 | import com.tangerinespecter.javabaseutils.common.annotation.MethodInfo; 5 | 6 | import java.text.SimpleDateFormat; 7 | import java.util.Calendar; 8 | import java.util.Date; 9 | import java.util.Random; 10 | 11 | /** 12 | * 随机工具类 13 | * 14 | * @author TangerineSpecter 15 | */ 16 | @ClassInfo(Name = "随机工具类") 17 | public class RandomUtils { 18 | 19 | private static final String FIRST_NAME = "赵钱孙李周吴郑王冯陈褚卫蒋沈韩杨朱秦尤许何吕施张孔曹严华金魏陶姜戚谢邹喻柏水窦章云苏潘葛奚范彭郎鲁韦昌马苗凤花方俞任袁柳酆鲍史唐费廉岑薛雷贺倪汤滕殷罗毕郝邬安常乐于时傅皮卞齐康伍余元卜顾孟平黄和穆萧尹姚邵湛汪祁毛禹狄米贝明臧计伏成戴谈宋茅庞熊纪舒屈项祝董梁杜阮蓝闵席季麻强贾路娄危江童颜郭梅盛林刁钟徐邱骆高夏蔡田樊胡凌霍虞万支柯咎管卢莫经房裘缪干解应宗宣丁贲邓郁单杭洪包诸左石崔吉钮龚程嵇邢滑裴陆荣翁荀羊於惠甄魏加封芮羿储靳汲邴糜松井段富巫乌焦巴弓牧隗山谷车侯宓蓬全郗班仰秋仲伊宫宁仇栾暴甘钭厉戎祖武符刘姜詹束龙叶幸司韶郜黎蓟薄印宿白怀蒲台从鄂索咸籍赖卓蔺屠蒙池乔阴郁胥能苍双闻莘党翟谭贡劳逄姬申扶堵冉宰郦雍却璩桑桂濮牛寿通边扈燕冀郏浦尚农温别庄晏柴瞿阎充慕连茹习宦艾鱼容向古易慎戈廖庚终暨居衡步都耿满弘匡国文寇广禄阙东殴殳沃利蔚越夔隆师巩厍聂晁勾敖融冷訾辛阚那简饶空曾毋沙乜养鞠须丰巢关蒯相查后江红游竺权逯盖益桓公万俟司马上官欧阳夏侯诸葛闻人东方赫连皇甫尉迟公羊澹台公冶宗政濮阳淳于仲孙太叔申屠公孙乐正轩辕令狐钟离闾丘长孙慕容鲜于宇文司徒司空亓官司寇仉督子车颛孙端木巫马公西漆雕乐正壤驷公良拓拔夹谷宰父谷粱晋楚阎法汝鄢涂钦段干百里东郭南门呼延归海羊舌微生岳帅缑亢况后有琴梁丘左丘东门西门商牟佘佴伯赏南宫墨哈谯笪年爱阳佟第五言福"; 20 | private static final String GIRL = "秀娟英华慧巧美娜静淑惠珠翠雅芝玉萍红娥玲芬芳燕彩春菊兰凤洁梅琳素云莲真环雪荣爱妹霞香月莺媛艳瑞凡佳嘉琼勤珍贞莉桂娣叶璧璐娅琦晶妍茜秋珊莎锦黛青倩婷姣婉娴瑾颖露瑶怡婵雁蓓纨仪荷丹蓉眉君琴蕊薇菁梦岚苑婕馨瑗琰韵融园艺咏卿聪澜纯毓悦昭冰爽琬茗羽希宁欣飘育滢馥筠柔竹霭凝晓欢霄枫芸菲寒伊亚宜可姬舒影荔枝思丽 "; 21 | private static final String BOY = "伟刚勇毅俊峰强军平保东文辉力明永健世广志义兴良海山仁波宁贵福生龙元全国胜学祥才发武新利清飞彬富顺信子杰涛昌成康星光天达安岩中茂进林有坚和彪博诚先敬震振壮会思群豪心邦承乐绍功松善厚庆磊民友裕河哲江超浩亮政谦亨奇固之轮翰朗伯宏言若鸣朋斌梁栋维启克伦翔旭鹏泽晨辰士以建家致树炎德行时泰盛雄琛钧冠策腾楠榕风航弘"; 22 | private static final String[] EMAIL_SUFFIX = "@gmail.com,@yahoo.com,@msn.com,@hotmail.com,@aol.com,@ask.com,@live.com,@qq.com,@0355.net,@163.com,@163.net,@263.net,@3721.net,@yeah.net,@googlemail.com,@126.com,@sina.com,@sohu.com,@yahoo.com.cn" 23 | .split(","); 24 | private static final String BASE = "abcdefghijklmnopqrstuvwxyz0123456789"; 25 | private static final String[] TEL_FIRST = "134,135,136,137,138,139,150,151,152,157,158,159,130,131,132,155,156,133,153" 26 | .split(","); 27 | private static final String[] PROVINCE = "北京,天津,上海,重庆,河北,山西,辽宁,吉林,黑龙江,江苏,浙江,安徽,福建,江西,山东,河南,湖北,湖南,广东,海南,四川,贵州,云南,陕西,甘肃,青海,台湾,内蒙古,广西,西藏,宁夏,新疆,香港,澳门" 28 | .split(","); 29 | private static char[][] ENCODE_CHARS_ARRAY = new char[2][]; 30 | 31 | static { 32 | ENCODE_CHARS_ARRAY[0] = new char[]{'O', 'Y', 'x', 'F', 'd', 'C', 'q', 'X', 's', '5', 'g', 'G', '6', 'l', 'M', 33 | 'W', '9', 'Q', 't', 'a', 'i', 'm', 'B', 'N', 'e', '2', 'D', '4', '3', 'o', 'K', 'H', 'y', 'Z', 'c', 'r', 34 | 'p', 'V', 'v', 'A', 'U', 'R', 'T', 'b', 'I', 'u', 'S', 'n', '1', 'f', 'k', 'E', 'J', '8', 'w', '0', 'z', 35 | 'j', '7', 'L', 'h', 'P'}; 36 | ENCODE_CHARS_ARRAY[1] = new char[]{'g', 'n', 'y', 'L', 'F', '2', '7', '3', 'I', 'b', 'H', 'Y', 'r', 't', 'A', 37 | 'S', 'v', 'f', 'M', 'a', 'j', '9', 'X', 'k', 'q', 'K', '0', 'u', 'C', 'N', 'Q', 'p', 'i', 'x', 'B', 'w', 38 | 'o', 'G', 'P', 'm', 'E', 'W', 's', 'R', 'c', '5', 'U', 'O', 'h', 'V', '8', '4', 'D', '1', 'z', 'l', 'd', 39 | 'e', 'T', '6', 'Z', 'J'}; 40 | } 41 | 42 | /** 43 | * 随机数 44 | * 45 | * @param start 起始数 46 | * @param end 结束数 47 | * @return 48 | */ 49 | @MethodInfo(Name = "随机数", paramInfo = {"起始数", "结束数"}, returnInfo = "随机数字") 50 | public static int getNum(int start, int end) { 51 | return (int) (Math.random() * (end - start + 1) + start); 52 | } 53 | 54 | /** 55 | * 随机生成电话号码 56 | * 57 | * @return 电话号码 58 | */ 59 | @MethodInfo(Name = "随机生成电话号码", returnInfo = "电话号码") 60 | public static String getTel() { 61 | int index = getNum(0, TEL_FIRST.length - 1); 62 | String first = TEL_FIRST[index]; 63 | String second = String.valueOf(getNum(1, 888) + 10000).substring(1); 64 | String thrid = String.valueOf(getNum(1, 9100) + 10000).substring(1); 65 | return first + second + thrid; 66 | } 67 | 68 | /** 69 | * 随机生成中文名字 70 | * 71 | * @return 中文名 72 | */ 73 | @MethodInfo(Name = "随机生成中文名字", returnInfo = "中文名") 74 | public static String getChineseName() { 75 | int index = getNum(0, FIRST_NAME.length() - 1); 76 | String first = FIRST_NAME.substring(index, index + 1); 77 | int sex = getNum(0, 1); 78 | String str = BOY; 79 | int length = BOY.length(); 80 | if (sex == 0) { 81 | str = GIRL; 82 | length = GIRL.length(); 83 | } 84 | index = getNum(0, length - 1); 85 | String second = str.substring(index, index + 1); 86 | int hasThird = getNum(0, 1); 87 | String third = ""; 88 | if (hasThird == 1) { 89 | index = getNum(0, length - 1); 90 | third = str.substring(index, index + 1); 91 | } 92 | return first + second + third; 93 | } 94 | 95 | /** 96 | * 随机生成Email 97 | * 98 | * @param min 最小长度 99 | * @param max 最大长度 100 | * @return 101 | */ 102 | @MethodInfo(Name = "随机生成Email", paramInfo = {"最小长度", "最大长度"}, returnInfo = "Email") 103 | public static String getEmail(int min, int max) { 104 | int length = getNum(min, max); 105 | StringBuffer sb = new StringBuffer(); 106 | for (int i = 0; i < length; i++) { 107 | int number = (int) (Math.random() * BASE.length()); 108 | sb.append(BASE.charAt(number)); 109 | } 110 | sb.append(EMAIL_SUFFIX[(int) (Math.random() * EMAIL_SUFFIX.length)]); 111 | return sb.toString(); 112 | } 113 | 114 | /** 115 | * 随机生成时间 116 | * 117 | * @return 时间 118 | */ 119 | @MethodInfo(Name = "随机生成时间", returnInfo = "时间") 120 | public static String getDate() { 121 | Random random = new Random(); 122 | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); 123 | Calendar cal = Calendar.getInstance(); 124 | Integer year = Integer.parseInt(TimeUtils.getCurrentYear()); 125 | cal.set((year - 50), 0, 1); 126 | long start = cal.getTimeInMillis(); 127 | cal.set(year, 0, 1); 128 | long end = cal.getTimeInMillis(); 129 | Date d = new Date(start + (long) (random.nextDouble() * (end - start))); 130 | return format.format(d); 131 | } 132 | 133 | /** 134 | * 随机生成省份 135 | * 136 | * @return 省份 137 | */ 138 | @MethodInfo(Name = "随机生成省份", returnInfo = "省份") 139 | public static String getProvince() { 140 | int index = getNum(0, PROVINCE.length - 1); 141 | return PROVINCE[index]; 142 | } 143 | 144 | /** 145 | * 创建随机字符名字 146 | * 147 | * @param num 148 | * @return 149 | */ 150 | @MethodInfo(Name = "创建随机字符名字", paramInfo = {"名字长度"}, returnInfo = "随机结果") 151 | public static String createRandomName(long num) { 152 | int charArrayLength = ENCODE_CHARS_ARRAY.length; 153 | int encodeCharsLength = ENCODE_CHARS_ARRAY[0].length; 154 | 155 | StringBuffer sb = new StringBuffer(); 156 | int bit = 0; 157 | while (num > 0) { 158 | long ch = num % encodeCharsLength; 159 | sb.insert(0, ENCODE_CHARS_ARRAY[bit % charArrayLength][(char) ch]); 160 | num = num / encodeCharsLength; 161 | bit++; 162 | } 163 | return sb.toString(); 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/common/util/RegExUtils.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.common.util; 2 | 3 | import com.tangerinespecter.javabaseutils.common.annotation.ClassInfo; 4 | import com.tangerinespecter.javabaseutils.common.annotation.MethodInfo; 5 | 6 | import java.util.regex.Matcher; 7 | import java.util.regex.Pattern; 8 | 9 | /** 10 | * 正则表达式工具类 11 | * 12 | * @author TangerineSpecter 13 | */ 14 | @ClassInfo(Name = "正则表达式工具类") 15 | public class RegExUtils { 16 | 17 | /** 18 | * 校验邮箱合法化 19 | * 20 | * @param email 邮箱地址 21 | */ 22 | @MethodInfo(Name = "校验邮箱合法化", paramInfo = {"邮箱地址"}, returnInfo = "校验结果") 23 | public static boolean checkEmail(String email) { 24 | String regEx = "[a-zA-Z_]{1,}[0-9]{0,}@(([a-zA-z0-9]-*){1,}\\.){1,3}[a-zA-z\\-]{1,}"; 25 | Pattern pattern = Pattern.compile(regEx); 26 | Matcher matcher = pattern.matcher(email); 27 | return matcher.matches(); 28 | } 29 | 30 | /** 31 | * 校验数字为小数后两位以内 32 | * 33 | * @param number 校验数字 34 | */ 35 | @MethodInfo(Name = "校验数字为小数后两位以内", paramInfo = {"校验数字"}, returnInfo = "校验结果") 36 | public static boolean check2Point(String number) { 37 | String regEx = "^[0-9]+(.[0-9]{2})?$"; 38 | Pattern pattern = Pattern.compile(regEx); 39 | Matcher matcher = pattern.matcher(number); 40 | return matcher.matches(); 41 | } 42 | 43 | /** 44 | * 校验密码以字母开头(长度6~18,只能包含数字、字母、下划线) 45 | * 46 | * @param password 密码 47 | */ 48 | @MethodInfo(Name = "校验密码以字母开头", paramInfo = {"密码"}, returnInfo = "校验结果") 49 | public static boolean checkPassword(String password) { 50 | String regEx = "^[a-zA-Z]\\w{5,17}$"; 51 | Pattern pattern = Pattern.compile(regEx); 52 | Matcher matcher = pattern.matcher(password); 53 | return matcher.matches(); 54 | } 55 | 56 | /** 57 | * 移除特殊字符(只保留汉字字母数字) 58 | * 59 | * @param str 60 | * @return 61 | */ 62 | @MethodInfo(Name = "移除特殊字符", paramInfo = {"字符串内容"}, returnInfo = "处理结果") 63 | public static String removeSpecialCharacter(String str) { 64 | return str.replaceAll("[^0-9a-zA-Z\\u4e00-\\u9fa5]", ""); 65 | } 66 | 67 | /** 68 | * 去除富文本中的与html相关的字符 69 | * 70 | * @param htmlString 71 | * @return 72 | */ 73 | @MethodInfo(Name = "去除富文本中html相关字符", paramInfo = {"富文本内容"}, returnInfo = "处理结果") 74 | public static String filterHtml(String htmlString) { 75 | return htmlString.replaceAll("&.*?;", "").replaceAll("<.*?>", "").replaceAll("<.*?/>", ""); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/common/util/StringUtils.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.common.util; 2 | 3 | import com.tangerinespecter.javabaseutils.common.annotation.ClassInfo; 4 | import com.tangerinespecter.javabaseutils.common.annotation.MethodInfo; 5 | import org.apache.commons.codec.digest.DigestUtils; 6 | 7 | import java.net.InetAddress; 8 | import java.net.UnknownHostException; 9 | import java.util.Random; 10 | import java.util.UUID; 11 | 12 | /** 13 | * 字符串处理工具类 14 | * 15 | * @author TangerineSpecter 16 | */ 17 | @ClassInfo(Name = "字符串处理工具类") 18 | public class StringUtils { 19 | 20 | private static Random randGen = new Random(); 21 | 22 | /** 23 | * 数字和字母的混合数组, 两份数字提高数字出现几率 24 | */ 25 | private static char[] numbersAndLetters = ("0123456789abcdefghijklmnopqrstuvwxyz" 26 | + "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ").toCharArray(); 27 | 28 | /** 29 | * 伪随机字符串(数字英文混合) 30 | * 31 | * @param length 字符串长度 32 | * @return 33 | */ 34 | @MethodInfo(Name = "伪随机字符串", paramInfo = {"字符串长度"}, returnInfo = "随机结果") 35 | public static String randomString(int length) { 36 | if (length < 1) { 37 | return null; 38 | } 39 | char[] randBuffer = new char[length]; 40 | for (int i = 0; i < randBuffer.length; i++) { 41 | randBuffer[i] = numbersAndLetters[randGen.nextInt(71)]; 42 | } 43 | return new String(randBuffer); 44 | } 45 | 46 | /** 47 | * 判断字符串是否为空 48 | */ 49 | @MethodInfo(Name = "判断字符串是否为空", paramInfo = {"字符串内容"}, returnInfo = "判断结果") 50 | public static boolean isEmpty(String str) { 51 | boolean flag = true; 52 | if (str != null && !Constant.NULL_KEY_STR.equals(str.trim())) { 53 | flag = false; 54 | } 55 | return flag; 56 | } 57 | 58 | /** 59 | * 判断多个字符串是否有任意一个为空 60 | * 61 | * @param strs 62 | * @return 63 | */ 64 | @MethodInfo(Name = "判断多个字符串中是否有空值", paramInfo = {"字符串参数集"}, returnInfo = "判断结果") 65 | public static boolean isAnyEmpty(String... strs) { 66 | for (String str : strs) { 67 | if (isEmpty(str)) { 68 | return true; 69 | } 70 | } 71 | return false; 72 | } 73 | 74 | /** 75 | * 截取String开头指定长度的部分 76 | * 77 | * @param str 78 | * @param length 79 | * @return 80 | */ 81 | @MethodInfo(Name = "截取字符串开头指定长度", paramInfo = {"字符串内容", "截取位置"}, returnInfo = "截取结果") 82 | public static String subString(String str, int length) { 83 | return str.substring(0, str.length() > length ? length : str.length()); 84 | } 85 | 86 | /** 87 | * 获取本机ip地址 88 | * 89 | * @return 90 | */ 91 | @MethodInfo(Name = "获取本机IP地址", returnInfo = "IP地址") 92 | public static String getLocalHostIp() { 93 | String ip = Constant.NULL_KEY_STR; 94 | InetAddress address; 95 | try { 96 | address = InetAddress.getLocalHost(); 97 | ip = address.getHostAddress(); 98 | } catch (UnknownHostException e) { 99 | e.printStackTrace(); 100 | } 101 | return ip; 102 | } 103 | 104 | /** 105 | * 生成订单号 106 | * 107 | * @return 108 | */ 109 | @MethodInfo(Name = "订单号生成", returnInfo = "订单号") 110 | public static String getOrderNum() { 111 | return DigestUtils.md5Hex(UUID.randomUUID().toString()).toUpperCase(); 112 | } 113 | 114 | /** 115 | * 判断是否为数字,是数字返回true否则返回false 116 | */ 117 | @MethodInfo(Name = "判断是否为数字", returnInfo = "判断结果") 118 | public static boolean isNumber(String str) { 119 | boolean flag = false; 120 | if (str != null && !Constant.NULL_KEY_STR.equals(str.trim())) { 121 | String regex = "\\d*"; 122 | flag = str.matches(regex); 123 | } 124 | return flag; 125 | } 126 | 127 | /** 128 | * 判断所有字符串都是数字,如果都是返回true, 否则返回false 129 | * 130 | * @param strs 字符串集合 131 | * @return 132 | */ 133 | @MethodInfo(Name = "判断所有字符串是否都为数字", paramInfo = {"字符串集"}, returnInfo = "判断结果") 134 | public static boolean isAllNumber(String... strs) { 135 | for (String str : strs) { 136 | if (!isNumber(str)) { 137 | return false; 138 | } 139 | } 140 | return true; 141 | } 142 | 143 | } 144 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/common/util/TimeUtils.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.common.util; 2 | 3 | import com.tangerinespecter.javabaseutils.common.annotation.ClassInfo; 4 | import com.tangerinespecter.javabaseutils.common.annotation.MethodInfo; 5 | import lombok.extern.slf4j.Slf4j; 6 | 7 | import java.text.DateFormat; 8 | import java.text.ParseException; 9 | import java.text.SimpleDateFormat; 10 | import java.time.Instant; 11 | import java.time.LocalDate; 12 | import java.time.Period; 13 | import java.time.ZoneId; 14 | import java.util.Calendar; 15 | import java.util.Date; 16 | 17 | /** 18 | * 时间处理工具类 19 | * 20 | * @author TangerineSpecter 21 | */ 22 | @Slf4j 23 | @ClassInfo(Name = "时间处理工具类") 24 | public class TimeUtils { 25 | /** 26 | * 默认格式 27 | */ 28 | private static final String DEFAULT_FORMAT = "yyyy-MM-dd"; 29 | /** 30 | * 时间格式——精确到秒 31 | */ 32 | private static final String DEFAULT_FORMAT_SECOND = "yyyy-MM-dd HH:mm:ss"; 33 | /** 34 | * 星期数 35 | */ 36 | private static final String[] WEEKDAYS = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"}; 37 | 38 | /** 39 | * 将时间转换成指定格式 yyyy-MM-dd HH:mm:ss 40 | * 41 | * @param date 时间 42 | */ 43 | @MethodInfo(Name = "将时间转换成指定格式", paramInfo = {"时间"}, returnInfo = "转换结果") 44 | public static String timeFormat(Date date) { 45 | SimpleDateFormat format = new SimpleDateFormat(DEFAULT_FORMAT_SECOND); 46 | if (date != null) { 47 | return format.format(date); 48 | } 49 | return ""; 50 | } 51 | 52 | /** 53 | * 将指定的日期字符串转化为日期对象 54 | * 55 | * @param dateStr 日期字符串 56 | * @param format 时间格式 如:yyyy-MM-dd HH:mm:ss 57 | * @return date 58 | */ 59 | @MethodInfo(Name = "将指定的日期字符串转化为日期对象", paramInfo = {"日期字符串", "日期格式"}, returnInfo = "转换结果") 60 | public static Date getDate(String dateStr, String format) { 61 | SimpleDateFormat df = new SimpleDateFormat(format); 62 | try { 63 | return df.parse(dateStr); 64 | } catch (Exception ex) { 65 | return null; 66 | } 67 | } 68 | 69 | /** 70 | * 将时间转换成指定格式 yyyy-MM-dd 精确到天 71 | * 72 | * @param date 时间 73 | */ 74 | @MethodInfo(Name = "将时间格式精确到天", paramInfo = {"时间"}, returnInfo = "转换结果") 75 | public static String timeFormatToDay(Date date) { 76 | SimpleDateFormat format = new SimpleDateFormat(DEFAULT_FORMAT); 77 | if (date != null) { 78 | return format.format(date); 79 | } 80 | return ""; 81 | } 82 | 83 | /** 84 | * 将时间转换成指定格式 85 | * 86 | * @param date 时间 87 | * @param model 时间格式 88 | * @return 转换时间 89 | */ 90 | @MethodInfo(Name = "将时间转换成指定格式", paramInfo = {"时间", "时间格式"}, returnInfo = "转换结果") 91 | public static String timeFormat(Date date, String model) { 92 | SimpleDateFormat format = new SimpleDateFormat(model); 93 | if (date != null) { 94 | return format.format(date); 95 | } 96 | return ""; 97 | } 98 | 99 | /** 100 | * 获取当前时间的时间戳 精确到毫秒 101 | * 102 | * @return 时间戳 103 | */ 104 | @MethodInfo(Name = "获取当前时间戳", returnInfo = "时间戳") 105 | public static Long getCurrentTimes() { 106 | return System.currentTimeMillis(); 107 | } 108 | 109 | /** 110 | * 获取当天开始的时间戳 111 | */ 112 | @MethodInfo(Name = "获取当天开始时间戳", returnInfo = "时间戳") 113 | public static Long getDayBeginTimestamp() { 114 | Calendar calendar = Calendar.getInstance(); 115 | calendar.set(Calendar.HOUR_OF_DAY, 0); 116 | calendar.set(Calendar.MINUTE, 0); 117 | calendar.set(Calendar.SECOND, 0); 118 | return calendar.getTimeInMillis(); 119 | } 120 | 121 | /** 122 | * 获取当天结束的时间戳 123 | */ 124 | @MethodInfo(Name = "获取当天结束时间戳", returnInfo = "时间戳") 125 | public static Long getDayEndTimestamp() { 126 | Calendar calendar = Calendar.getInstance(); 127 | calendar.set(Calendar.HOUR_OF_DAY, 24); 128 | calendar.set(Calendar.MINUTE, 0); 129 | calendar.set(Calendar.SECOND, 0); 130 | return calendar.getTimeInMillis(); 131 | } 132 | 133 | /** 134 | * 获取昨天开始的时间戳 135 | */ 136 | @MethodInfo(Name = "获取昨天开始时间戳", returnInfo = "时间戳") 137 | public static Long getYesterdayBeginTimestamp() { 138 | Calendar calendar = Calendar.getInstance(); 139 | calendar.add(Calendar.DATE, -1); 140 | calendar.set(Calendar.HOUR_OF_DAY, 0); 141 | calendar.set(Calendar.MINUTE, 0); 142 | calendar.set(Calendar.SECOND, 0); 143 | return calendar.getTimeInMillis(); 144 | } 145 | 146 | /** 147 | * 获取指定格式的当前时间 148 | * 149 | * @param format 格式,如:yyyy-MM-dd 150 | */ 151 | @MethodInfo(Name = "获取指定格式当前时间", paramInfo = {"时间格式"}, returnInfo = "时间字符串") 152 | public static String getSimpleFormat(String format) { 153 | return new SimpleDateFormat(format).format(new Date()); 154 | } 155 | 156 | 157 | /** 158 | * 获取当前年份 159 | */ 160 | @MethodInfo(Name = "获取当前年份", returnInfo = "年份") 161 | public static String getCurrentYear() { 162 | return new SimpleDateFormat("yyyy").format(new Date()); 163 | } 164 | 165 | /** 166 | * 获取特定时间的时间戳 167 | * 168 | * @param year 年 169 | * @param month 月 170 | * @param day 日 171 | * @param hour 小时 172 | * @param minute 分钟 173 | * @param second 秒 174 | */ 175 | @MethodInfo(Name = "获取特定时间时间戳", paramInfo = {"年份", "月份", "日期", "小时", "分钟", "秒"}, returnInfo = "时间戳") 176 | public static Long getTimestramp(int year, int month, int day, int hour, int minute, int second) { 177 | Calendar calendar = Calendar.getInstance(); 178 | calendar.set(year, month, day, hour, minute, second); 179 | return calendar.getTimeInMillis(); 180 | } 181 | 182 | /** 183 | * 将指定格式 转为毫秒 184 | * 185 | * @param date 时间 186 | * @param format 格式 187 | * @return 时间戳 188 | */ 189 | @MethodInfo(Name = "将指定格式转换成毫秒", paramInfo = {"时间字符串", "时间格式"}, returnInfo = "时间戳") 190 | public static Long getDateMillion(String date, String format) { 191 | Long time = null; 192 | if (null != date && !date.isEmpty()) { 193 | try { 194 | SimpleDateFormat sdf = new SimpleDateFormat(format); 195 | time = sdf.parse(date).getTime(); 196 | } catch (Exception e) { 197 | e.printStackTrace(); 198 | } 199 | } 200 | return time; 201 | } 202 | 203 | /** 204 | * 获取距离某个日期的天数 205 | * 206 | * @param time 格式:yyyy-MM-dd 207 | * @return 208 | */ 209 | @MethodInfo(Name = "获取距离某个日期的天数", paramInfo = {"时间字符串"}, returnInfo = "天数") 210 | public static Integer getDisparityDay(String time) { 211 | Integer days = null; 212 | if (null != time) { 213 | try { 214 | SimpleDateFormat sdf = new SimpleDateFormat(DEFAULT_FORMAT); 215 | long millionSeconds = sdf.parse(time).getTime(); 216 | days = Math.abs((int) ((System.currentTimeMillis() - millionSeconds) / 1000 / 60 / 60 / 24)); 217 | } catch (Exception e) { 218 | e.printStackTrace(); 219 | } 220 | } 221 | return days; 222 | } 223 | 224 | /** 225 | * 获取某天的星期 226 | * 227 | * @param date 格式:yyyy-MM-dd 228 | */ 229 | @MethodInfo(Name = "获取某天的星期", paramInfo = {"时间字符串"}, returnInfo = "星期") 230 | public static String getWeekdays(String date) { 231 | DateFormat df = new SimpleDateFormat(DEFAULT_FORMAT); 232 | try { 233 | Date time = df.parse(date); 234 | Calendar cal = Calendar.getInstance(); 235 | cal.setTime(time); 236 | int weekDay = cal.get(Calendar.DAY_OF_WEEK) - 1; 237 | return WEEKDAYS[weekDay]; 238 | } catch (ParseException e) { 239 | log.error("【数据转换出现异常】"); 240 | e.printStackTrace(); 241 | } 242 | return null; 243 | } 244 | 245 | /** 246 | * 获取某年某月最后一天 247 | * 248 | * @param year 年份 249 | * @param month 月份 250 | */ 251 | @MethodInfo(Name = "获取某年某月最后一题", paramInfo = {"年份", "月份"}, returnInfo = "天数") 252 | public static Integer getFinalDay(int year, int month) { 253 | Calendar cal = Calendar.getInstance(); 254 | cal.set(Calendar.YEAR, year); 255 | cal.set(Calendar.MONTH, month); 256 | cal.set(Calendar.DAY_OF_MONTH, 1); 257 | cal.add(Calendar.DAY_OF_MONTH, -1); 258 | Date time = cal.getTime(); 259 | return Integer.valueOf(new SimpleDateFormat("dd").format(time)); 260 | } 261 | 262 | /** 263 | * 获取某年某月第一天 264 | * 265 | * @param date 时间 266 | */ 267 | @MethodInfo(Name = "获取某年某月第一天", paramInfo = {"时间"}, returnInfo = "时间") 268 | public static Date getStartDay(Date date) { 269 | Calendar cal = Calendar.getInstance(); 270 | cal.setTime(date); 271 | cal.set(Calendar.YEAR, cal.get(Calendar.YEAR)); 272 | cal.set(Calendar.MONTH, cal.get(Calendar.MONTH)); 273 | cal.set(Calendar.DAY_OF_MONTH, 1); 274 | return cal.getTime(); 275 | } 276 | 277 | /** 278 | * 获取某年某月最后一天 279 | * 280 | * @param date 时间 281 | */ 282 | @MethodInfo(Name = "获取某年某月最后一天", paramInfo = {"时间"}, returnInfo = "时间") 283 | public static Date getFinalDay(Date date) { 284 | Calendar cal = Calendar.getInstance(); 285 | cal.setTime(date); 286 | cal.set(Calendar.YEAR, cal.get(Calendar.YEAR)); 287 | cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) + 1); 288 | cal.set(Calendar.DAY_OF_MONTH, 1); 289 | cal.add(Calendar.DAY_OF_MONTH, -1); 290 | return cal.getTime(); 291 | } 292 | 293 | /** 294 | * 判断某一年是否闰年 295 | * 296 | * @param year 年份 297 | * @return 闰年返回true 298 | */ 299 | @MethodInfo(Name = "判断某一年是否闰年", paramInfo = {"年份"}, returnInfo = "判断结果") 300 | public static Boolean judgeLeapYear(int year) { 301 | return getFinalDay(year, Constant.Date.MONTH_FEBRUARY) == Constant.Date.LEAP_YEAR_DAY; 302 | } 303 | 304 | /** 305 | * 时间差计算(年-月-日) 306 | * 307 | * @param startTime 开始时间戳 308 | * @param endTime 结束时间戳 309 | * @return yy-MM-dd 310 | */ 311 | @MethodInfo(Name = "时间差计算(年-月-日)", paramInfo = {"开始时间戳", "结束时间戳"}, returnInfo = "返回时间格式:yy-MM-dd") 312 | public static String timeDifForYear(Long startTime, Long endTime) { 313 | LocalDate endDate = Instant.ofEpochMilli(endTime).atZone(ZoneId.systemDefault()).toLocalDate(); 314 | LocalDate startDate = Instant.ofEpochMilli(startTime).atZone(ZoneId.systemDefault()).toLocalDate(); 315 | Period period = Period.between(startDate, endDate); 316 | return period.getYears() + "-" + period.getMonths() + "-" + period.getDays(); 317 | } 318 | 319 | /** 320 | * 时间差计算(时:分:秒) 321 | * 322 | * @param startTime 开始时间戳 323 | * @param endTime 结束时间戳 324 | * @return HH:mm:ss 325 | */ 326 | @MethodInfo(Name = "时间差计算(时:分:秒)", paramInfo = {"开始时间戳", "结束时间戳"}, returnInfo = "返回时间格式:HH:mm:ss") 327 | public static String timeDifForDay(Long startTime, Long endTime) { 328 | long difTime = endTime - startTime; 329 | DateFormat formatter = new SimpleDateFormat("HH:mm:ss"); 330 | Calendar calendar = Calendar.getInstance(); 331 | calendar.setTimeInMillis(difTime); 332 | calendar.add(Calendar.HOUR_OF_DAY, -8); 333 | return formatter.format(calendar.getTime()); 334 | } 335 | } 336 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/common/util/ZipUtils.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.common.util; 2 | 3 | import com.tangerinespecter.javabaseutils.common.annotation.ClassInfo; 4 | import com.tangerinespecter.javabaseutils.common.annotation.MethodInfo; 5 | import lombok.extern.slf4j.Slf4j; 6 | 7 | import java.io.*; 8 | import java.util.zip.GZIPInputStream; 9 | import java.util.zip.GZIPOutputStream; 10 | import java.util.zip.ZipEntry; 11 | import java.util.zip.ZipOutputStream; 12 | 13 | /** 14 | * 压缩和解压工具类 15 | * 16 | * @author TangerineSpecter 17 | */ 18 | @Slf4j 19 | @ClassInfo(Name = "压缩和解压工具类") 20 | public class ZipUtils extends BaseUtils { 21 | 22 | private static final int BUFFER_SIZE = 2 * 1024; 23 | 24 | /*** 25 | * 压缩数据 26 | * 27 | * @param data 28 | * 要压缩的二进制数据 29 | * @return 30 | */ 31 | @MethodInfo(Name = "压缩数据", paramInfo = {"二进制数据"}, returnInfo = "压缩结果") 32 | public static byte[] gZip(byte[] data) { 33 | ByteArrayOutputStream bos = null; 34 | GZIPOutputStream gzip = null; 35 | byte[] b = null; 36 | try { 37 | bos = new ByteArrayOutputStream(); 38 | gzip = new GZIPOutputStream(bos); 39 | gzip.write(data); 40 | gzip.finish(); 41 | b = bos.toByteArray(); 42 | } catch (Exception e) { 43 | log.error(ZipLogger.ZIP_DATA_ERROR, e.getMessage()); 44 | e.printStackTrace(); 45 | } finally { 46 | if (bos != null) { 47 | try { 48 | bos.close(); 49 | } catch (IOException e) { 50 | log.warn(ZipLogger.STREAM_CLOSE_ERROR, e.getMessage()); 51 | } 52 | } 53 | if (gzip != null) { 54 | try { 55 | gzip.close(); 56 | } catch (IOException e) { 57 | log.warn(ZipLogger.STREAM_CLOSE_ERROR, e.getMessage()); 58 | } 59 | } 60 | } 61 | return b; 62 | } 63 | 64 | /** 65 | * 解压数据 66 | * 67 | * @param data 要解压的二进制数据 68 | * @return 69 | */ 70 | @MethodInfo(Name = "解压数据", paramInfo = {"二进制数据"}, returnInfo = "解压结果") 71 | public static byte[] unZip(byte[] data) { 72 | ByteArrayInputStream bis = null; 73 | GZIPInputStream gzip = null; 74 | ByteArrayOutputStream baos = null; 75 | byte[] b = null; 76 | try { 77 | bis = new ByteArrayInputStream(data); 78 | gzip = new GZIPInputStream(bis); 79 | byte[] buf = new byte[BUFFER_SIZE]; 80 | int num = -1; 81 | baos = new ByteArrayOutputStream(); 82 | while ((num = gzip.read(buf, 0, buf.length)) != -1) { 83 | baos.write(buf, 0, num); 84 | } 85 | b = baos.toByteArray(); 86 | baos.flush(); 87 | } catch (Exception e) { 88 | log.error(ZipLogger.UNZIP_DATA_ERROR, e.getMessage()); 89 | } finally { 90 | if (bis != null) { 91 | try { 92 | bis.close(); 93 | } catch (IOException e) { 94 | log.warn(ZipLogger.STREAM_CLOSE_ERROR, e.getMessage()); 95 | } 96 | } 97 | if (gzip != null) { 98 | try { 99 | gzip.close(); 100 | } catch (IOException e) { 101 | log.warn(ZipLogger.STREAM_CLOSE_ERROR, e.getMessage()); 102 | } 103 | } 104 | if (baos != null) { 105 | try { 106 | baos.close(); 107 | } catch (IOException e) { 108 | log.warn(ZipLogger.STREAM_CLOSE_ERROR, e.getMessage()); 109 | } 110 | } 111 | } 112 | return b; 113 | } 114 | 115 | /** 116 | * 压缩文件 117 | * 118 | * @param srcFilePath 源文件路径 119 | * @param destFileName 压缩包名字 120 | */ 121 | @MethodInfo(Name = "压缩文件", paramInfo = {"源文件路径", "压缩包名字"}) 122 | public static void compress(String srcFilePath, String destFileName) { 123 | File srcFile = new File(srcFilePath); 124 | FileOutputStream fos = null; 125 | ZipOutputStream zos = null; 126 | if (!srcFile.exists()) { 127 | log.info(FileLogger.FILE_NOT_FOUND); 128 | } 129 | String destFilePath = Constant.ZIP_SAVE_PATH + destFileName; 130 | File destDir = new File(Constant.ZIP_SAVE_PATH); 131 | if (!destDir.exists()) { 132 | destDir.mkdirs(); 133 | } 134 | File destFile = new File(destFilePath); 135 | try { 136 | fos = new FileOutputStream(destFile); 137 | zos = new ZipOutputStream(fos); 138 | String baseDir = ""; 139 | compressBy(srcFile, zos, baseDir); 140 | } catch (Exception e) { 141 | log.error(String.format("【压缩文件出现异常】:%s", e)); 142 | } finally { 143 | if (fos != null) { 144 | try { 145 | fos.close(); 146 | } catch (IOException e) { 147 | log.warn(ZipLogger.STREAM_CLOSE_ERROR, e.getMessage()); 148 | } 149 | } 150 | if (zos != null) { 151 | try { 152 | zos.close(); 153 | } catch (IOException e) { 154 | log.warn(ZipLogger.STREAM_CLOSE_ERROR, e.getMessage()); 155 | } 156 | } 157 | } 158 | } 159 | 160 | /** 161 | * 对路径下文件根据类型进行压缩 162 | * 163 | * @param srcFile 源文件 164 | * @param zos 压缩流 165 | * @param baseDir 压缩路径 166 | */ 167 | @MethodInfo(Name = "对路径下文件根据类型进行压缩", paramInfo = {"源文件", "压缩流", "压缩路径"}) 168 | private static void compressBy(File srcFile, ZipOutputStream zos, String baseDir) { 169 | if (!srcFile.exists()) { 170 | log.info(FileLogger.FILE_NOT_FOUND); 171 | return; 172 | } 173 | log.info(ZipLogger.SOURCE_FILE_PATH, baseDir + srcFile.getName()); 174 | // 判断压缩是文件还是文件夹 175 | if (srcFile.isFile()) { 176 | compressFile(srcFile, zos, baseDir); 177 | } else if (srcFile.isDirectory()) { 178 | compressDir(srcFile, zos, baseDir); 179 | } else { 180 | log.info(FileLogger.FILE_TYPE_UNKNOWN); 181 | } 182 | } 183 | 184 | /** 185 | * 压缩文件 186 | * 187 | * @param srcFile 源文件 188 | * @param zos 压缩流 189 | * @param baseDir 压缩路径 190 | */ 191 | @MethodInfo(Name = "压缩文件", paramInfo = {"源文件", "压缩流", "压缩路径"}) 192 | private static void compressFile(File srcFile, ZipOutputStream zos, String baseDir) { 193 | BufferedInputStream bis = null; 194 | if (!srcFile.exists()) { 195 | log.info(FileLogger.FILE_NOT_FOUND); 196 | return; 197 | } 198 | try { 199 | bis = new BufferedInputStream(new FileInputStream(srcFile)); 200 | ZipEntry entry = new ZipEntry(baseDir + srcFile.getName()); 201 | zos.putNextEntry(entry); 202 | int len; 203 | byte[] b = new byte[BUFFER_SIZE]; 204 | while ((len = bis.read(b)) != -1) { 205 | zos.write(b, 0, len); 206 | } 207 | } catch (Exception e) { 208 | log.error(ZipLogger.ZIP_DATA_ERROR, e.getMessage()); 209 | e.printStackTrace(); 210 | } finally { 211 | if (zos != null) { 212 | try { 213 | zos.closeEntry(); 214 | } catch (IOException e) { 215 | log.warn(ZipLogger.STREAM_CLOSE_ERROR, e.getMessage()); 216 | e.printStackTrace(); 217 | } 218 | } 219 | if (bis != null) { 220 | try { 221 | bis.close(); 222 | } catch (IOException e) { 223 | log.warn(ZipLogger.STREAM_CLOSE_ERROR, e.getMessage()); 224 | e.printStackTrace(); 225 | } 226 | } 227 | } 228 | } 229 | 230 | /** 231 | * 压缩文件夹 232 | * 233 | * @param srcDir 源文件 234 | * @param zos 压缩流 235 | * @param baseDir 压缩路径 236 | */ 237 | @MethodInfo(Name = "压缩文件夹", paramInfo = {"源文件", "压缩流", "压缩路径"}) 238 | private static void compressDir(File srcDir, ZipOutputStream zos, String baseDir) { 239 | if (!srcDir.exists()) { 240 | log.info(FileLogger.DIRFILE_NOT_FOUND); 241 | return; 242 | } 243 | 244 | File[] files = srcDir.listFiles(); 245 | if (files.length == 0) { 246 | try { 247 | zos.putNextEntry(new ZipEntry(baseDir + srcDir.getName() + File.separator)); 248 | } catch (Exception e) { 249 | log.error(ZipLogger.ZIP_DATA_ERROR, e.getMessage()); 250 | e.printStackTrace(); 251 | } 252 | } 253 | for (File file : files) { 254 | compressBy(file, zos, baseDir); 255 | } 256 | } 257 | 258 | } 259 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/common/util/cache/JedisMapTool.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.common.util.cache; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.util.SerializationUtils; 5 | import redis.clients.jedis.Jedis; 6 | import redis.clients.jedis.exceptions.JedisConnectionException; 7 | 8 | import java.io.Serializable; 9 | import java.util.*; 10 | 11 | /** 12 | * Jedis工具类(Map) 13 | * 14 | * @author TangerineSpecter 15 | */ 16 | @Slf4j 17 | public class JedisMapTool extends JedisTool { 18 | 19 | /** 20 | * 向名称为key的hash中添加键值对 field->value 21 | * 22 | * @param key 23 | * @param field 24 | * @param value 25 | */ 26 | public static void setMapCache(String key, String field, String value) { 27 | Jedis jedis = null; 28 | boolean broken = false; 29 | try { 30 | jedis = getResource(); 31 | jedis.hset(key, field, value); 32 | } catch (JedisConnectionException e1) { 33 | log.warn("【Redis设置缓存连接失败】:" + e1.toString()); 34 | broken = true; 35 | returnBrokenResource(jedis); 36 | setMapCache(key, field, value); 37 | } catch (Exception e) { 38 | log.error("【Redis设置缓存失败】:" + e.toString(), e); 39 | } finally { 40 | if (!broken) { 41 | returnResource(jedis); 42 | } 43 | } 44 | } 45 | 46 | /** 47 | * 获取名称为key的集合中field元素的值 48 | * 49 | * @param key 50 | * @param field 51 | */ 52 | public static String getMapValue(String key, String field) { 53 | Jedis jedis = null; 54 | boolean broken = false; 55 | try { 56 | jedis = getResource(); 57 | return jedis.hget(key, field); 58 | } catch (JedisConnectionException e1) { 59 | log.warn("【Redis设置缓存连接失败】:" + e1.toString()); 60 | broken = true; 61 | returnBrokenResource(jedis); 62 | return getMapValue(key, field); 63 | } catch (Exception e) { 64 | log.error("【Redis设置缓存失败】:" + e.toString(), e); 65 | } finally { 66 | if (!broken) { 67 | returnResource(jedis); 68 | } 69 | } 70 | return null; 71 | } 72 | 73 | /** 74 | * 设置Map缓存 75 | * 76 | * @param key 77 | * @param field 78 | * @param o 79 | */ 80 | public static void setMapObj(String key, String field, Serializable o) { 81 | Jedis jedis = null; 82 | boolean broken = false; 83 | try { 84 | jedis = getResource(); 85 | jedis.hset(key.getBytes(), field.getBytes(), SerializationUtils.serialize(o)); 86 | } catch (JedisConnectionException e1) { 87 | log.warn("【Redis设置缓存连接失败】:" + e1.toString()); 88 | broken = true; 89 | returnBrokenResource(jedis); 90 | setMapObj(key, field, o); 91 | } catch (Exception e) { 92 | log.error("【Redis设置缓存失败】:" + e.toString(), e); 93 | } finally { 94 | if (!broken) { 95 | returnResource(jedis); 96 | } 97 | } 98 | } 99 | 100 | /** 101 | * 获取Map缓存 102 | * 103 | * @param key 104 | * @param field 105 | * @return 106 | */ 107 | public static Object getMapObj(String key, String field) { 108 | Object o = null; 109 | Jedis jedis = null; 110 | boolean broken = false; 111 | try { 112 | jedis = getResource(); 113 | byte[] temp = jedis.hget(key.getBytes(), field.getBytes()); 114 | if (temp != null) { 115 | o = SerializationUtils.deserialize(temp); 116 | } 117 | } catch (JedisConnectionException e1) { 118 | log.warn("【Redis设置缓存连接失败】:" + e1.toString()); 119 | broken = true; 120 | returnBrokenResource(jedis); 121 | return getMapObj(key, field); 122 | } catch (Exception e) { 123 | log.error("【Redis设置缓存失败】:" + e.toString(), e); 124 | } finally { 125 | if (!broken) { 126 | returnResource(jedis); 127 | } 128 | } 129 | return o; 130 | } 131 | 132 | /** 133 | * 设置Map缓存(Map形式) 134 | * 135 | * @param key 136 | * @param values 137 | */ 138 | public static void setMapObjs(String key, Map values) { 139 | Map byteValues = new HashMap(16); 140 | for (String field : values.keySet()) { 141 | byteValues.put(field.getBytes(), SerializationUtils.serialize(values.get(field))); 142 | } 143 | 144 | Jedis jedis = null; 145 | boolean broken = false; 146 | try { 147 | jedis = getResource(); 148 | jedis.hmset(key.getBytes(), byteValues); 149 | } catch (JedisConnectionException e1) { 150 | log.warn("【Redis设置缓存连接失败】:" + e1.toString()); 151 | broken = true; 152 | returnBrokenResource(jedis); 153 | setMapObjs(key, values); 154 | } catch (Exception e) { 155 | log.error("【Redis设置缓存失败】:" + e.toString(), e); 156 | } finally { 157 | if (!broken) { 158 | returnResource(jedis); 159 | } 160 | } 161 | } 162 | 163 | /** 164 | * 获取Map缓存(Map形式) 165 | * 166 | * @param key 167 | * @return 168 | */ 169 | public static Map getMapObjs(String key) { 170 | Jedis jedis = null; 171 | boolean broken = false; 172 | try { 173 | jedis = getResource(); 174 | Set keys = jedis.hkeys(key.getBytes()); 175 | if (keys == null || keys.isEmpty()) { 176 | return null; 177 | } 178 | byte[][] keyArr = new byte[keys.size()][]; 179 | keyArr = keys.toArray(keyArr); 180 | List byteValues = jedis.hmget(key.getBytes(), keyArr); 181 | Map values = new HashMap(16); 182 | for (int i = 0; i < keyArr.length; i++) { 183 | byte[] byteKey = keyArr[i]; 184 | byte[] byteValue = byteValues.get(i); 185 | values.put(new String(byteKey), (Serializable) SerializationUtils.deserialize(byteValue)); 186 | } 187 | return values; 188 | } catch (JedisConnectionException e1) { 189 | log.warn("【Redis设置缓存连接失败】:" + e1.toString()); 190 | broken = true; 191 | returnBrokenResource(jedis); 192 | return getMapObjs(key); 193 | } catch (Exception e) { 194 | log.error("【Redis设置缓存失败】:" + e.toString(), e); 195 | } finally { 196 | if (!broken) { 197 | returnResource(jedis); 198 | } 199 | } 200 | return null; 201 | } 202 | 203 | /** 204 | * 返回名称为key的hash中所有键 205 | * 206 | * @param key 207 | */ 208 | public static Set getMapKeys(String key) { 209 | Jedis jedis = null; 210 | boolean broken = false; 211 | try { 212 | jedis = getResource(); 213 | return jedis.hkeys(key); 214 | } catch (JedisConnectionException e1) { 215 | log.warn("【Redis设置缓存连接失败】:" + e1.toString()); 216 | broken = true; 217 | returnBrokenResource(jedis); 218 | return getMapKeys(key); 219 | } catch (Exception e) { 220 | log.error("【Redis设置缓存失败】:" + e.toString(), e); 221 | } finally { 222 | if (!broken) { 223 | returnResource(jedis); 224 | } 225 | } 226 | return new HashSet(); 227 | } 228 | 229 | /** 230 | * 返回名称为key的hash中所有的键(field)及其对应的value 231 | * 232 | * @param key 233 | */ 234 | public static Map getMapKeyValue(String key) { 235 | Jedis jedis = null; 236 | boolean broken = false; 237 | try { 238 | jedis = getResource(); 239 | return jedis.hgetAll(key); 240 | } catch (JedisConnectionException e1) { 241 | log.warn("【Redis设置缓存连接失败】:" + e1.toString()); 242 | broken = true; 243 | returnBrokenResource(jedis); 244 | return getMapKeyValue(key); 245 | } catch (Exception e) { 246 | log.error("【Redis设置缓存失败】:" + e.toString(), e); 247 | } finally { 248 | if (!broken) { 249 | returnResource(jedis); 250 | } 251 | } 252 | return new HashMap(16); 253 | } 254 | 255 | /** 256 | * 删除map中的指定键值对 257 | * 258 | * @param key 259 | * @param field 260 | */ 261 | public static void delMapValue(String key, String field) { 262 | Jedis jedis = null; 263 | boolean broken = false; 264 | try { 265 | jedis = getResource(); 266 | jedis.hdel(key, field); 267 | } catch (JedisConnectionException e1) { 268 | log.warn("【Redis设置缓存连接失败】:" + e1.toString()); 269 | broken = true; 270 | returnBrokenResource(jedis); 271 | delMapValue(key, field); 272 | } catch (Exception e) { 273 | log.error("【Redis设置缓存失败】:" + e.toString(), e); 274 | } finally { 275 | if (!broken) { 276 | returnResource(jedis); 277 | } 278 | } 279 | } 280 | } 281 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/common/util/cache/JedisSetTool.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.common.util.cache; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.util.SerializationUtils; 5 | import redis.clients.jedis.Jedis; 6 | import redis.clients.jedis.exceptions.JedisConnectionException; 7 | 8 | import java.io.Serializable; 9 | import java.util.HashSet; 10 | import java.util.Set; 11 | 12 | /** 13 | * Jedis工具类(Set) 14 | * 15 | * @author TangerineSpecter 16 | */ 17 | @Slf4j 18 | public class JedisSetTool extends JedisTool { 19 | 20 | /** 21 | * 设置缓存数据到Set集合中 22 | * 23 | * @param key 24 | * @param value 25 | */ 26 | public static void setSetCache(String key, String value) { 27 | Jedis jedis = null; 28 | boolean broken = false; 29 | try { 30 | jedis = getResource(); 31 | jedis.sadd(key, value); 32 | } catch (JedisConnectionException e1) { 33 | log.warn("【Redis设置缓存连接失败】:" + e1.toString()); 34 | broken = true; 35 | } catch (Exception e) { 36 | log.error("【Redis设置缓存失败】:" + e.toString(), e); 37 | } finally { 38 | if (broken) { 39 | returnBrokenResource(jedis); 40 | setSetCache(key, value); 41 | } else { 42 | returnResource(jedis); 43 | } 44 | } 45 | } 46 | 47 | /** 48 | * 设置缓存数据到Set集合中 49 | * 50 | * @param key 51 | */ 52 | public static Set getSetCache(String key) { 53 | Jedis jedis = null; 54 | boolean broken = false; 55 | try { 56 | jedis = getResource(); 57 | return jedis.smembers(key); 58 | } catch (JedisConnectionException e1) { 59 | log.warn("【Redis设置缓存连接失败】:" + e1.toString()); 60 | broken = true; 61 | return new HashSet(); 62 | } catch (Exception e) { 63 | log.error("【Redis设置缓存失败】:" + e.toString(), e); 64 | return new HashSet(); 65 | } finally { 66 | if (broken) { 67 | returnBrokenResource(jedis); 68 | getSetCache(key); 69 | } else { 70 | returnResource(jedis); 71 | } 72 | } 73 | } 74 | 75 | /** 76 | * 设置缓存数据到Set集合中 77 | * 78 | * @param key 79 | */ 80 | public static Set getSetObj(String key) { 81 | Jedis jedis = null; 82 | boolean broken = false; 83 | try { 84 | jedis = getResource(); 85 | Set byteValues = jedis.smembers(key.getBytes()); 86 | if (byteValues == null) { 87 | return new HashSet(); 88 | } 89 | 90 | Set values = new HashSet(byteValues.size()); 91 | for (byte[] byteValue : byteValues) { 92 | values.add((Serializable) SerializationUtils.deserialize(byteValue)); 93 | } 94 | 95 | return values; 96 | } catch (JedisConnectionException e1) { 97 | log.warn("【Redis设置缓存连接失败】:" + e1.toString()); 98 | broken = true; 99 | return new HashSet(); 100 | } catch (Exception e) { 101 | log.error("【Redis设置缓存失败】:" + e.toString(), e); 102 | return new HashSet(); 103 | } finally { 104 | if (broken) { 105 | returnBrokenResource(jedis); 106 | getSetObj(key); 107 | } else { 108 | returnResource(jedis); 109 | } 110 | } 111 | } 112 | 113 | /** 114 | * 删除set集合中的指定数据 115 | * 116 | * @param key 117 | * @param value 118 | */ 119 | public static void delSetValue(String key, String value) { 120 | Jedis jedis = null; 121 | boolean broken = false; 122 | try { 123 | jedis = getResource(); 124 | jedis.srem(key, value); 125 | } catch (JedisConnectionException e1) { 126 | log.warn("【Redis删除缓存连接失败】:" + e1.toString()); 127 | broken = true; 128 | } catch (Exception e) { 129 | log.error("【Redis删除缓存失败】:" + e.toString(), e); 130 | } finally { 131 | if (broken) { 132 | returnBrokenResource(jedis); 133 | delSetValue(key, value); 134 | } else { 135 | returnResource(jedis); 136 | } 137 | } 138 | } 139 | 140 | /** 141 | * 删除set集合中的指定数据 142 | * 143 | * @param key 144 | * @param value 145 | */ 146 | public static void delSetObj(String key, Serializable value) { 147 | Jedis jedis = null; 148 | boolean broken = false; 149 | try { 150 | jedis = getResource(); 151 | jedis.srem(key.getBytes(), SerializationUtils.serialize(value)); 152 | } catch (JedisConnectionException e1) { 153 | log.warn("【Redis删除缓存连接失败】:" + e1.toString()); 154 | broken = true; 155 | } catch (Exception e) { 156 | log.error("【Redis删除缓存失败】:" + e.toString(), e); 157 | } finally { 158 | if (broken) { 159 | returnBrokenResource(jedis); 160 | delSetObj(key, value); 161 | } else { 162 | returnResource(jedis); 163 | } 164 | } 165 | } 166 | 167 | /** 168 | * 删除set集合中的随机元素 169 | * 170 | * @param key 171 | */ 172 | public static void delSetRandom(String key) { 173 | Jedis jedis = null; 174 | boolean broken = false; 175 | try { 176 | jedis = getResource(); 177 | jedis.spop(key); 178 | } catch (JedisConnectionException e1) { 179 | log.warn("【Redis删除缓存连接失败】:" + e1.toString()); 180 | broken = true; 181 | } catch (Exception e) { 182 | log.error("【Redis删除缓存失败】:" + e.toString(), e); 183 | } finally { 184 | if (broken) { 185 | returnBrokenResource(jedis); 186 | delSetRandom(key); 187 | } else { 188 | returnResource(jedis); 189 | } 190 | } 191 | } 192 | 193 | /** 194 | * 获取缓存中set集合的基数 195 | * 196 | * @param key 197 | */ 198 | public static Long getSetSize(String key) { 199 | Jedis jedis = null; 200 | boolean broken = false; 201 | try { 202 | jedis = getResource(); 203 | return jedis.scard(key); 204 | } catch (JedisConnectionException e1) { 205 | log.warn("【Redis获取缓存连接失败】:" + e1.toString()); 206 | broken = true; 207 | } catch (Exception e) { 208 | log.error("【Redis获取缓存失败】:" + e.toString(), e); 209 | } finally { 210 | if (broken) { 211 | returnBrokenResource(jedis); 212 | getSetSize(key); 213 | } else { 214 | returnResource(jedis); 215 | } 216 | } 217 | return 0L; 218 | } 219 | 220 | /** 221 | * 判断set中是否有指定值 222 | * 223 | * @param key 224 | * @param value 225 | */ 226 | public static boolean checkSetValue(String key, String value) { 227 | Jedis jedis = null; 228 | boolean result = false; 229 | boolean broken = false; 230 | try { 231 | jedis = getResource(); 232 | result = jedis.sismember(key, value); 233 | } catch (JedisConnectionException e1) { 234 | log.warn("【Redis获取缓存连接失败】:" + e1.toString()); 235 | broken = true; 236 | } catch (Exception e) { 237 | log.error("【Redis获取缓存连接失败】:" + e.toString(), e); 238 | } finally { 239 | if (broken) { 240 | returnBrokenResource(jedis); 241 | checkSetValue(key, value); 242 | } else { 243 | returnResource(jedis); 244 | } 245 | } 246 | return result; 247 | } 248 | } 249 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/common/util/enums/FileTypeEnum.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.common.util.enums; 2 | 3 | /** 4 | * 文件类型枚举类 5 | * 6 | * @author TangerineSpecter 7 | */ 8 | public enum FileTypeEnum { 9 | /** Txt文件 */ 10 | TXT_FILE, 11 | /** Markdown文件 */ 12 | MARKDOWN_FILE, 13 | /** xls文件 */ 14 | XLS_EXCEL_FILE, 15 | /** xlsx文件 */ 16 | XLSX_EXCEL_FILE 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/controller/util/EasyExcelController.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.controller.util; 2 | 3 | import com.tangerinespecter.javabaseutils.common.util.EasyExcelUtils; 4 | import io.swagger.annotations.Api; 5 | import io.swagger.annotations.ApiOperation; 6 | import io.swagger.annotations.ApiParam; 7 | import org.springframework.web.bind.annotation.PostMapping; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RequestParam; 10 | import org.springframework.web.bind.annotation.RestController; 11 | import org.springframework.web.multipart.MultipartFile; 12 | 13 | import java.io.IOException; 14 | 15 | /** 16 | * EasyExcel处理工具类 17 | * 18 | * @author TangerineSpecter 19 | */ 20 | @Api(tags = "EasyExcel处理工具类") 21 | @RestController 22 | @RequestMapping("/easyExcelUtils") 23 | public class EasyExcelController { 24 | 25 | @PostMapping("/simpleRead") 26 | @ApiOperation(value = "获取Excel数据") 27 | public void simpleRead(@ApiParam("Excel路径") @RequestParam("file") MultipartFile file) throws IOException { 28 | EasyExcelUtils.simpleRead(file); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/controller/util/PoiExcelController.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.controller.util; 2 | 3 | import com.tangerinespecter.javabaseutils.common.util.ExcelUtils; 4 | import io.swagger.annotations.Api; 5 | import io.swagger.annotations.ApiOperation; 6 | import io.swagger.annotations.ApiParam; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RequestParam; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | * PoiExcel处理工具类 16 | * 17 | * @author TangerineSpecter 18 | */ 19 | @Api(tags = "PoiExcel处理工具类") 20 | @RestController 21 | @RequestMapping("/poiExcelUtils") 22 | public class PoiExcelController { 23 | 24 | @GetMapping("/getExcel") 25 | @ApiOperation(value = "获取Excel数据") 26 | public void getExcel(@ApiParam("Excel路径") @RequestParam("filePath") String filePath) { 27 | ExcelUtils.getExcel(filePath); 28 | } 29 | 30 | @GetMapping("/createExcel") 31 | @ApiOperation(value = "创建Excel") 32 | public void createExcel(@ApiParam("表头") @RequestParam("tableHead") String[] tableHead, 33 | @ApiParam("数据列表") @RequestParam("dataList") List dataList, 34 | @ApiParam("true:生成xlsx,false:生成xls格式") @RequestParam("isExcel") boolean isExcel) { 35 | ExcelUtils.createExcel(tableHead, dataList, isExcel); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/controller/util/StringController.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.controller.util; 2 | 3 | import com.tangerinespecter.javabaseutils.common.util.StringUtils; 4 | import io.swagger.annotations.Api; 5 | import io.swagger.annotations.ApiOperation; 6 | import io.swagger.annotations.ApiParam; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RequestParam; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | /** 13 | * 字符串工具类控制 14 | * 15 | * @author TangerineSpecter 16 | */ 17 | @Api(tags = "字符串工具类") 18 | @RestController 19 | @RequestMapping("/stringUtils") 20 | public class StringController { 21 | 22 | @GetMapping("/isEmpty") 23 | @ApiOperation(value = "判断字符串是否为空") 24 | public boolean isEmpty(@ApiParam("字符串内容") @RequestParam("str") String str) { 25 | return StringUtils.isEmpty(str); 26 | } 27 | 28 | @GetMapping("/isNumber") 29 | @ApiOperation(value = "判断是否为数字") 30 | public boolean isNumber(@ApiParam("字符串内容") @RequestParam("number") String number) { 31 | return StringUtils.isNumber(number); 32 | } 33 | 34 | @GetMapping("/isAllNumber") 35 | @ApiOperation(value = "判断所有字符串是否都为数字") 36 | public boolean isAllNumber(@ApiParam("字符串集") @RequestParam("numbers") String... numbers) { 37 | return StringUtils.isAllNumber(numbers); 38 | } 39 | 40 | @GetMapping("/isAnyEmpty") 41 | @ApiOperation(value = "判断多个字符串是否有任意一个为空") 42 | public boolean isAnyEmpty(@ApiParam("字符串集") @RequestParam("strs") String... strs) { 43 | return StringUtils.isAnyEmpty(strs); 44 | } 45 | 46 | @GetMapping("/getOrderNum") 47 | @ApiOperation(value = "订单号生成") 48 | public String getOrderNum() { 49 | return StringUtils.getOrderNum(); 50 | } 51 | 52 | @GetMapping("/getLocalHostIP") 53 | @ApiOperation(value = "获取本机IP地址") 54 | public String getLocalHostIp() { 55 | return StringUtils.getLocalHostIp(); 56 | } 57 | 58 | @GetMapping("/randomString") 59 | @ApiOperation(value = "伪随机字符串(数字英文混合)") 60 | public String randomString(@ApiParam("字符串长度") @RequestParam("length") int length) { 61 | return StringUtils.randomString(length); 62 | } 63 | 64 | @GetMapping("/subString") 65 | @ApiOperation(value = "截取String开头指定长度的部分") 66 | public String subString(@ApiParam("字符串内容") @RequestParam("str") String str, @ApiParam("截取位置") @RequestParam("length") int length) { 67 | return StringUtils.subString(str, length); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/controller/util/TimeController.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.controller.util; 2 | 3 | import com.tangerinespecter.javabaseutils.common.util.TimeUtils; 4 | import io.swagger.annotations.Api; 5 | import io.swagger.annotations.ApiOperation; 6 | import io.swagger.annotations.ApiParam; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RequestParam; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | import java.util.Date; 13 | 14 | /** 15 | * 时间工具类 16 | * 17 | * @author TangerineSpecter 18 | */ 19 | @Api(tags = "时间工具类") 20 | @RestController 21 | @RequestMapping("/timeUtils") 22 | public class TimeController { 23 | 24 | @GetMapping("/getCurrentYear") 25 | @ApiOperation("获取当前年份") 26 | public String getCurrentYear() { 27 | return TimeUtils.getCurrentYear(); 28 | } 29 | 30 | @GetMapping("/timeDifForYear") 31 | @ApiOperation("时间差计算(年-月-日)") 32 | public String timeDifForYear(@ApiParam("开始时间戳") @RequestParam("startTime") Long startTime, 33 | @ApiParam("结束时间戳") @RequestParam("endTime") Long endTime) { 34 | return TimeUtils.timeDifForYear(startTime, endTime); 35 | } 36 | 37 | @GetMapping("/timeFormatToDay") 38 | @ApiOperation("将时间格式精确到天") 39 | public String timeFormatToDay(@ApiParam("时间") @RequestParam("date") Date date) { 40 | return TimeUtils.timeFormatToDay(date); 41 | } 42 | 43 | @GetMapping("/getSimpleFormat") 44 | @ApiOperation("获取指定格式当前时间") 45 | public String getSimpleFormat(@ApiParam("时间格式,如:yyyy-MM-dd") @RequestParam("format") String format) { 46 | return TimeUtils.getSimpleFormat(format); 47 | } 48 | 49 | @GetMapping("/getCurrentTimes") 50 | @ApiOperation("获取当前时间戳") 51 | public Long getCurrentTimes() { 52 | return TimeUtils.getCurrentTimes(); 53 | } 54 | 55 | @GetMapping("/getDate") 56 | @ApiOperation("将指定的日期字符串转化为日期对象") 57 | public Date getDate(@ApiParam("日期字符串") @RequestParam("dateStr") String dateStr, 58 | @ApiParam("时间格式,如:yyyy-MM-dd") @RequestParam("format") String format) { 59 | return TimeUtils.getDate(dateStr, format); 60 | } 61 | 62 | @GetMapping("/getDateMillion") 63 | @ApiOperation("将指定格式转换成毫秒") 64 | public Long getDateMillion(@ApiParam("日期字符串") @RequestParam("dateStr") String dateStr, 65 | @ApiParam("时间格式,如:yyyy-MM-dd") @RequestParam("format") String format) { 66 | return TimeUtils.getDateMillion(dateStr, format); 67 | } 68 | 69 | @GetMapping("/getDayBeginTimestamp") 70 | @ApiOperation("获取当天开始时间戳") 71 | public Long getDayBeginTimestamp() { 72 | return TimeUtils.getDayBeginTimestamp(); 73 | } 74 | 75 | @GetMapping("/getDayEndTimestamp") 76 | @ApiOperation("获取当天结束时间戳") 77 | public Long getDayEndTimestamp() { 78 | return TimeUtils.getDayEndTimestamp(); 79 | } 80 | 81 | @GetMapping("/getDisparityDay") 82 | @ApiOperation("获取距离某个日期的天数") 83 | public Integer getDisparityDay(@ApiParam("时间字符串") @RequestParam("time") String time) { 84 | return TimeUtils.getDisparityDay(time); 85 | } 86 | 87 | @GetMapping("/getFinalDay") 88 | @ApiOperation("获取某年某月最后一天") 89 | public Date getFinalDay(@ApiParam("时间") @RequestParam("date") Date date) { 90 | return TimeUtils.getFinalDay(date); 91 | } 92 | 93 | @GetMapping("/getStartDay") 94 | @ApiOperation("获取某年某月第一天") 95 | public Date getStartDay(@ApiParam("时间") @RequestParam("date") Date date) { 96 | return TimeUtils.getStartDay(date); 97 | } 98 | 99 | @GetMapping("/getTimestramp") 100 | @ApiOperation("获取特定时间时间戳") 101 | public Long getTimestramp(@ApiParam("年份") @RequestParam("year") int year, 102 | @ApiParam("月份") @RequestParam("month") int month, 103 | @ApiParam("天") @RequestParam("day") int day, 104 | @ApiParam("小时") @RequestParam("hour") int hour, 105 | @ApiParam("分钟") @RequestParam("minute") int minute, 106 | @ApiParam("秒") @RequestParam("second") int second) { 107 | return TimeUtils.getTimestramp(year, month, day, hour, minute, second); 108 | } 109 | 110 | @GetMapping("/getWeekdays") 111 | @ApiOperation("获取某天的星期") 112 | public String getWeekdays(@ApiParam("时间字符串") @RequestParam("date") String date) { 113 | return TimeUtils.getWeekdays(date); 114 | } 115 | 116 | @GetMapping("/getYesterdayBeginTimestamp") 117 | @ApiOperation("获取昨天开始时间戳") 118 | public Long getYesterdayBeginTimestamp() { 119 | return TimeUtils.getYesterdayBeginTimestamp(); 120 | } 121 | 122 | @GetMapping("/judgeLeapYear") 123 | @ApiOperation("判断某一年是否闰年") 124 | public Boolean judgeLeapYear(@ApiParam("年份") @RequestParam("year") int year) { 125 | return TimeUtils.judgeLeapYear(year); 126 | } 127 | 128 | @GetMapping("/timeDifForDay") 129 | @ApiOperation("时间差计算(时:分:秒)") 130 | public String timeDifForDay(@ApiParam("开始时间戳") @RequestParam("startTime") Long startTime, 131 | @ApiParam("结束时间戳") @RequestParam("endTime") Long endTime) { 132 | return TimeUtils.timeDifForDay(startTime, endTime); 133 | } 134 | 135 | @GetMapping("/timeFormat") 136 | @ApiOperation("将时间转换成指定格式") 137 | public String timeFormat(@ApiParam("时间") @RequestParam("date") Date date, 138 | @ApiParam("时间格式") @RequestParam("model") String model) { 139 | return TimeUtils.timeFormat(date, model); 140 | } 141 | 142 | @GetMapping("/timeFormat-default") 143 | @ApiOperation("将时间转换成默认格式 yyyy-MM-dd HH:mm:ss") 144 | public String timeFormat(@ApiParam("时间") @RequestParam("date") Date date) { 145 | return TimeUtils.timeFormat(date); 146 | } 147 | 148 | } 149 | -------------------------------------------------------------------------------- /src/main/java/com/tangerineSpecter/javaBaseUtils/controller/util/ZipController.java: -------------------------------------------------------------------------------- 1 | package com.tangerinespecter.javabaseutils.controller.util; 2 | 3 | import com.tangerinespecter.javabaseutils.common.util.ZipUtils; 4 | import io.swagger.annotations.Api; 5 | import io.swagger.annotations.ApiOperation; 6 | import io.swagger.annotations.ApiParam; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RequestParam; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | /** 13 | * 压缩和解压工具类 14 | * 15 | * @author TangerineSpecter 16 | */ 17 | @Api(tags = "压缩和解压工具类") 18 | @RestController 19 | @RequestMapping("/zipUtils") 20 | public class ZipController { 21 | 22 | @GetMapping("/compress") 23 | @ApiOperation(value = "压缩文件") 24 | public void compress(@ApiParam("源文件路径") @RequestParam("srcFilePath") String srcFilePath, 25 | @ApiParam("压缩包名字") @RequestParam("destFileName") String destFileName) { 26 | ZipUtils.compress(srcFilePath, destFileName); 27 | } 28 | 29 | @GetMapping("/gZip") 30 | @ApiOperation(value = "压缩数据") 31 | public byte[] gZip(@ApiParam("二进制数据") @RequestParam("data") byte[] data) { 32 | return ZipUtils.gZip(data); 33 | } 34 | 35 | @GetMapping("/unZip") 36 | @ApiOperation(value = "解压数据") 37 | public byte[] unZip(@ApiParam("二进制数据") @RequestParam("data") byte[] data) { 38 | return ZipUtils.unZip(data); 39 | } 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8543 2 | spring.application.name=JavaBaseUtils -------------------------------------------------------------------------------- /src/test/java/com/tangerineSpecter/javaBaseUtils/JavaBaseUtilsApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.tangerineSpecter.javaBaseUtils; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class JavaBaseUtilsApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | --------------------------------------------------------------------------------