Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
W
wangxiaolu-sfa-common-core
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
sfa
wangxiaolu-sfa-common-core
Commits
74847d52
提交
74847d52
authored
12月 10, 2024
作者:
吕本才
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
货需导入
上级
1953347a
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
140 行增加
和
108 行删除
+140
-108
DateUtils.java
src/main/java/com/sfa/common/core/utils/DateUtils.java
+52
-59
StringUtils.java
src/main/java/com/sfa/common/core/utils/StringUtils.java
+51
-30
ExcelUtil.java
src/main/java/com/sfa/common/core/utils/poi/ExcelUtil.java
+37
-19
没有找到文件。
src/main/java/com/sfa/common/core/utils/DateUtils.java
浏览文件 @
74847d52
package
com
.
sfa
.
common
.
core
.
utils
;
import
org.apache.commons.lang3.time.DateFormatUtils
;
import
java.lang.management.ManagementFactory
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
import
java.time.LocalTime
;
import
java.time.ZoneId
;
import
java.time.ZonedDateTime
;
import
java.time.*
;
import
java.util.Calendar
;
import
java.util.Date
;
import
org.apache.commons.lang3.time.DateFormatUtils
;
/**
* 时间工具类
*
* @author ruoyi
*/
public
class
DateUtils
extends
org
.
apache
.
commons
.
lang3
.
time
.
DateUtils
{
public
class
DateUtils
extends
org
.
apache
.
commons
.
lang3
.
time
.
DateUtils
{
public
static
String
HH_MM_SS_0
=
"yyyy-MM-dd 00:00:00"
;
public
static
String
YYYY
=
"yyyy"
;
...
...
@@ -40,8 +36,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
*
* @return Date() 当前日期
*/
public
static
Date
getNowDate
()
{
public
static
Date
getNowDate
()
{
return
new
Date
();
}
...
...
@@ -50,44 +45,34 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
*
* @return String
*/
public
static
String
getDate
()
{
public
static
String
getDate
()
{
return
dateTimeNow
(
YYYY_MM_DD
);
}
public
static
final
String
getTime
()
{
public
static
final
String
getTime
()
{
return
dateTimeNow
(
YYYY_MM_DD_HH_MM_SS
);
}
public
static
final
String
dateTimeNow
()
{
public
static
final
String
dateTimeNow
()
{
return
dateTimeNow
(
YYYYMMDDHHMMSS
);
}
public
static
final
String
dateTimeNow
(
final
String
format
)
{
public
static
final
String
dateTimeNow
(
final
String
format
)
{
return
parseDateToStr
(
format
,
new
Date
());
}
public
static
final
String
dateTime
(
final
Date
date
)
{
public
static
final
String
dateTime
(
final
Date
date
)
{
return
parseDateToStr
(
YYYY_MM_DD
,
date
);
}
public
static
final
String
parseDateToStr
(
final
String
format
,
final
Date
date
)
{
public
static
final
String
parseDateToStr
(
final
String
format
,
final
Date
date
)
{
return
new
SimpleDateFormat
(
format
).
format
(
date
);
}
public
static
final
Date
dateTime
(
final
String
format
,
final
String
ts
)
{
try
{
public
static
final
Date
dateTime
(
final
String
format
,
final
String
ts
)
{
try
{
return
new
SimpleDateFormat
(
format
).
parse
(
ts
);
}
catch
(
ParseException
e
)
{
}
catch
(
ParseException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
...
...
@@ -95,8 +80,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
/**
* 日期路径 即年/月/日 如2018/08/08
*/
public
static
final
String
datePath
()
{
public
static
final
String
datePath
()
{
Date
now
=
new
Date
();
return
DateFormatUtils
.
format
(
now
,
"yyyy/MM/dd"
);
}
...
...
@@ -104,8 +88,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
/**
* 日期路径 即年/月/日 如20180808
*/
public
static
final
String
dateTime
()
{
public
static
final
String
dateTime
()
{
Date
now
=
new
Date
();
return
DateFormatUtils
.
format
(
now
,
"yyyyMMdd"
);
}
...
...
@@ -113,18 +96,13 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
/**
* 日期型字符串转化为日期 格式
*/
public
static
Date
parseDate
(
Object
str
)
{
if
(
str
==
null
)
{
public
static
Date
parseDate
(
Object
str
)
{
if
(
str
==
null
)
{
return
null
;
}
try
{
try
{
return
parseDate
(
str
.
toString
(),
parsePatterns
);
}
catch
(
ParseException
e
)
{
}
catch
(
ParseException
e
)
{
return
null
;
}
}
...
...
@@ -132,8 +110,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
/**
* 获取服务器启动时间
*/
public
static
Date
getServerStartDate
()
{
public
static
Date
getServerStartDate
()
{
long
time
=
ManagementFactory
.
getRuntimeMXBean
().
getStartTime
();
return
new
Date
(
time
);
}
...
...
@@ -141,12 +118,11 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
/**
* 计算时间差
*
* @param endDate 最后时间
* @param endDate
最后时间
* @param startTime 开始时间
* @return 时间差(天/小时/分钟)
*/
public
static
String
timeDistance
(
Date
endDate
,
Date
startTime
)
{
public
static
String
timeDistance
(
Date
endDate
,
Date
startTime
)
{
long
nd
=
1000
*
24
*
60
*
60
;
long
nh
=
1000
*
60
*
60
;
long
nm
=
1000
*
60
;
...
...
@@ -167,8 +143,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
/**
* 增加 LocalDateTime ==> Date
*/
public
static
Date
toDate
(
LocalDateTime
temporalAccessor
)
{
public
static
Date
toDate
(
LocalDateTime
temporalAccessor
)
{
ZonedDateTime
zdt
=
temporalAccessor
.
atZone
(
ZoneId
.
systemDefault
());
return
Date
.
from
(
zdt
.
toInstant
());
}
...
...
@@ -176,8 +151,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
/**
* 增加 LocalDate ==> Date
*/
public
static
Date
toDate
(
LocalDate
temporalAccessor
)
{
public
static
Date
toDate
(
LocalDate
temporalAccessor
)
{
LocalDateTime
localDateTime
=
LocalDateTime
.
of
(
temporalAccessor
,
LocalTime
.
of
(
0
,
0
,
0
));
ZonedDateTime
zdt
=
localDateTime
.
atZone
(
ZoneId
.
systemDefault
());
return
Date
.
from
(
zdt
.
toInstant
());
...
...
@@ -185,24 +159,43 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
/**
* 获取今天开始时间00:00:00
*
* @return
*/
public
static
Date
dateStart
(
Date
date
){
public
static
Date
dateStart
(
Date
date
)
{
Calendar
start
=
Calendar
.
getInstance
();
start
.
setTime
(
date
);
start
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
start
.
set
(
Calendar
.
MINUTE
,
0
);
start
.
set
(
Calendar
.
SECOND
,
0
);
start
.
set
(
Calendar
.
MILLISECOND
,
0
);
start
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
start
.
set
(
Calendar
.
MINUTE
,
0
);
start
.
set
(
Calendar
.
SECOND
,
0
);
start
.
set
(
Calendar
.
MILLISECOND
,
0
);
return
start
.
getTime
();
}
/**
* 获取今天增加天数后的结束时间23:59:59
*
* @return
*/
public
static
Date
dateStart
(
int
day
)
{
Date
date
=
dateStart
(
new
Date
());
return
DateUtils
.
addMilliseconds
(
DateUtils
.
addDays
(
date
,
day
),
-
1000
);
}
/**
* 计算当前日期在当月属于第几周
* 以周一到周日为一周,不跨月计算
* @param date
* @return
*/
public
static
Date
dateStart
(
int
day
){
Date
date
=
dateStart
(
new
Date
());
return
DateUtils
.
addMilliseconds
(
DateUtils
.
addDays
(
date
,
day
),-
1000
);
public
static
int
calculateWeekNumber
(
LocalDate
date
)
{
// 获取当月第一天
LocalDate
firstDayOfMonth
=
date
.
withDayOfMonth
(
1
);
// 计算当月第一天是星期几(1 代表星期一,7 代表星期日)
int
firstDayWeekday
=
firstDayOfMonth
.
getDayOfWeek
().
getValue
();
// 计算给定日期与当月第一天的天数差
int
daysSinceFirstDay
=
date
.
getDayOfMonth
()
-
1
;
// 计算给定日期所在周数(从 1 开始)
return
(
daysSinceFirstDay
+
firstDayWeekday
)
/
7
+
1
;
}
}
src/main/java/com/sfa/common/core/utils/StringUtils.java
浏览文件 @
74847d52
package
com
.
sfa
.
common
.
core
.
utils
;
import
com.sfa.common.core.constant.Constants
;
import
com.sfa.common.core.text.StrFormatter
;
import
org.apache.commons.lang3.ObjectUtils
;
import
org.springframework.util.AntPathMatcher
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Map
;
import
org.springframework.util.AntPathMatcher
;
import
com.sfa.common.core.constant.Constants
;
import
com.sfa.common.core.text.StrFormatter
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
/**
* 字符串工具类
*
*
* @author ruoyi
*/
public
class
StringUtils
extends
org
.
apache
.
commons
.
lang3
.
StringUtils
...
...
@@ -25,7 +29,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/**
* 获取参数不为空值
*
*
* @param value defaultValue 要判断的value
* @return value 返回值
*/
...
...
@@ -36,7 +40,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/**
* * 判断一个Collection是否为空, 包含List,Set,Queue
*
*
* @param coll 要判断的Collection
* @return true:为空 false:非空
*/
...
...
@@ -47,7 +51,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/**
* * 判断一个Collection是否非空,包含List,Set,Queue
*
*
* @param coll 要判断的Collection
* @return true:非空 false:空
*/
...
...
@@ -58,7 +62,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/**
* * 判断一个对象数组是否为空
*
*
* @param objects 要判断的对象数组
** @return true:为空 false:非空
*/
...
...
@@ -69,7 +73,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/**
* * 判断一个对象数组是否非空
*
*
* @param objects 要判断的对象数组
* @return true:非空 false:空
*/
...
...
@@ -80,7 +84,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/**
* * 判断一个Map是否为空
*
*
* @param map 要判断的Map
* @return true:为空 false:非空
*/
...
...
@@ -91,7 +95,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/**
* * 判断一个Map是否为空
*
*
* @param map 要判断的Map
* @return true:非空 false:空
*/
...
...
@@ -102,7 +106,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/**
* * 判断一个字符串是否为空串
*
*
* @param str String
* @return true:为空 false:非空
*/
...
...
@@ -113,7 +117,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/**
* * 判断一个字符串是否为非空串
*
*
* @param str String
* @return true:非空串 false:空串
*/
...
...
@@ -124,7 +128,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/**
* * 判断一个对象是否为空
*
*
* @param object Object
* @return true:为空 false:非空
*/
...
...
@@ -135,7 +139,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/**
* * 判断一个对象是否非空
*
*
* @param object Object
* @return true:非空 false:空
*/
...
...
@@ -146,7 +150,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/**
* * 判断一个对象是否是数组类型(Java基本型别的数组)
*
*
* @param object 对象
* @return true:是数组 false:不是数组
*/
...
...
@@ -208,7 +212,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/**
* 截取字符串
*
*
* @param str 字符串
* @param start 开始
* @return 结果
...
...
@@ -239,7 +243,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/**
* 截取字符串
*
*
* @param str 字符串
* @param start 开始
* @param end 结束
...
...
@@ -285,7 +289,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/**
* 判断是否为空,并且不是空白字符
*
*
* @param str 要判断的value
* @return 结果
*/
...
...
@@ -315,7 +319,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
* 通常使用:format("this is {} for {}", "a", "b") -> this is a for b<br>
* 转义{}: format("this is \\{} for {}", "a", "b") -> this is \{} for a<br>
* 转义\: format("this is \\\\{} for {}", "a", "b") -> this is \a for b<br>
*
*
* @param template 文本模板,被替换的部分用 {} 表示
* @param params 参数值
* @return 格式化后的文本
...
...
@@ -331,7 +335,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/**
* 是否为http(s)://开头
*
*
* @param link 链接
* @return 结果
*/
...
...
@@ -417,7 +421,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/**
* 是否包含字符串
*
*
* @param str 验证字符串
* @param strs 字符串组
* @return 包含返回true
...
...
@@ -439,7 +443,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/**
* 将下划线大写方式命名的字符串转换为驼峰式。如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。 例如:HELLO_WORLD->HelloWorld
*
*
* @param name 转换前的下划线大写方式命名的字符串
* @return 转换后的驼峰式命名的字符串
*/
...
...
@@ -513,7 +517,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/**
* 查找指定字符串是否匹配指定字符串列表中的任意一个字符串
*
*
* @param str 指定字符串
* @param strs 需要检查的字符串数组
* @return 是否匹配
...
...
@@ -535,11 +539,11 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
}
/**
* 判断url是否与规则配置:
* ? 表示单个字符;
* * 表示一层路径内的任意字符串,不可跨层级;
* 判断url是否与规则配置:
* ? 表示单个字符;
* * 表示一层路径内的任意字符串,不可跨层级;
* ** 表示任意层路径;
*
*
* @param pattern 匹配规则
* @param url 需要匹配的url
* @return
...
...
@@ -558,7 +562,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/**
* 数字左边补齐0,使之达到指定长度。注意,如果数字转换为字符串后,长度大于size,则只保留 最后size个字符。
*
*
* @param num 数字对象
* @param size 字符串指定长度
* @return 返回数字的字符串格式,该字符串为指定长度。
...
...
@@ -570,7 +574,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/**
* 字符串左补齐。如果原始字符串s长度大于size,则只保留最后size个字符。
*
*
* @param s 原始字符串
* @param size 字符串指定长度
* @param c 用于补齐的字符
...
...
@@ -604,4 +608,21 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
}
return
sb
.
toString
();
}
/**
* 从文字中获取数字部分
* @param text
* @return
*/
public
static
Long
getNumberFromStr
(
String
text
)
{
if
(
ObjectUtils
.
isEmpty
(
text
))
{
return
null
;
}
Pattern
pattern
=
Pattern
.
compile
(
"\\d"
);
Matcher
matcher
=
pattern
.
matcher
(
text
);
while
(
matcher
.
find
())
{
return
Long
.
valueOf
(
matcher
.
group
());
}
return
null
;
}
}
src/main/java/com/sfa/common/core/utils/poi/ExcelUtil.java
浏览文件 @
74847d52
...
...
@@ -258,7 +258,7 @@ public class ExcelUtil<T>
/**
* 对excel表单默认第一个索引名转换成list
*
*
* @param is 输入流
* @return 转换后集合
*/
...
...
@@ -283,7 +283,7 @@ public class ExcelUtil<T>
/**
* 对excel表单默认第一个索引名转换成list
*
*
* @param is 输入流
* @param titleNum 标题占用行数
* @return 转换后集合
...
...
@@ -295,7 +295,7 @@ public class ExcelUtil<T>
/**
* 对excel表单指定表格索引名转换成list
*
*
* @param sheetName 表格索引名
* @param titleNum 标题占用行数
* @param is 输入流
...
...
@@ -504,7 +504,7 @@ public class ExcelUtil<T>
/**
* 对list数据源将其里面的数据导入到excel表单
*
*
* @return 结果
*/
public
void
exportExcel
(
HttpServletResponse
response
)
...
...
@@ -566,7 +566,7 @@ public class ExcelUtil<T>
/**
* 填充excel数据
*
*
* @param index 序号
* @param row 单元格行
*/
...
...
@@ -637,7 +637,7 @@ public class ExcelUtil<T>
/**
* 创建表格样式
*
*
* @param wb 工作薄对象
* @return 样式列表
*/
...
...
@@ -692,7 +692,7 @@ public class ExcelUtil<T>
/**
* 根据Excel注解创建表格头样式
*
*
* @param wb 工作薄对象
* @return 自定义样式列表
*/
...
...
@@ -728,7 +728,7 @@ public class ExcelUtil<T>
/**
* 根据Excel注解创建表格列样式
*
*
* @param wb 工作薄对象
* @return 自定义样式列表
*/
...
...
@@ -760,7 +760,7 @@ public class ExcelUtil<T>
/**
* 根据Excel注解创建表格列样式
*
*
* @param styles 自定义样式列表
* @param field 属性列信息
* @param excel 注解信息
...
...
@@ -822,7 +822,7 @@ public class ExcelUtil<T>
/**
* 设置单元格信息
*
*
* @param value 单元格值
* @param attr 注解相关
* @param cell 单元格信息
...
...
@@ -981,7 +981,7 @@ public class ExcelUtil<T>
/**
* 设置 POI XSSFSheet 单元格提示或选择框
*
*
* @param sheet 表单
* @param textlist 下拉框显示的内容
* @param promptContent 提示内容
...
...
@@ -1018,7 +1018,7 @@ public class ExcelUtil<T>
/**
* 设置某些列的值只能输入预制的数据,显示下拉框(兼容超出一定数量的下拉框).
*
*
* @param sheet 要设置的sheet.
* @param textlist 下拉框显示的内容
* @param promptContent 提示内容
...
...
@@ -1070,7 +1070,7 @@ public class ExcelUtil<T>
/**
* 解析导出值 0=男,1=女,2=未知
*
*
* @param propertyValue 参数值
* @param converterExp 翻译注解
* @param separator 分隔符
...
...
@@ -1107,7 +1107,7 @@ public class ExcelUtil<T>
/**
* 反向解析值 男=0,女=1,未知=2
*
*
* @param propertyValue 参数值
* @param converterExp 翻译注解
* @param separator 分隔符
...
...
@@ -1349,7 +1349,7 @@ public class ExcelUtil<T>
/**
* 创建工作表
*
*
* @param sheetNo sheet数量
* @param index 序号
*/
...
...
@@ -1366,7 +1366,7 @@ public class ExcelUtil<T>
/**
* 获取单元格值
*
*
* @param row 获取的行
* @param column 获取单元格列号
* @return 单元格值
...
...
@@ -1426,7 +1426,7 @@ public class ExcelUtil<T>
/**
* 判断是否是空行
*
*
* @param row 判断的行
* @return
*/
...
...
@@ -1449,7 +1449,7 @@ public class ExcelUtil<T>
/**
* 格式化不同类型的日期对象
*
*
* @param dateFormat 日期格式
* @param val 被格式化的日期对象
* @return 格式化后的日期字符
...
...
@@ -1515,7 +1515,7 @@ public class ExcelUtil<T>
/**
* 获取对象的子列表方法
*
*
* @param name 名称
* @param pojoClass 类对象
* @return 子列表方法
...
...
@@ -1536,4 +1536,22 @@ public class ExcelUtil<T>
}
return
method
;
}
/**
* 获取下标对应的列的英文名称
* @param columnNumber
* @return
*/
public
static
String
convertToExcelColumn
(
int
columnNumber
)
{
StringBuilder
columnName
=
new
StringBuilder
();
while
(
columnNumber
>
0
)
{
int
remainder
=
(
columnNumber
-
1
)
%
26
;
char
letter
=
(
char
)
(
'A'
+
remainder
);
columnName
.
insert
(
0
,
letter
);
columnNumber
=
(
columnNumber
-
1
)
/
26
;
}
return
columnName
.
toString
();
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论