Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
D
device-back
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
1
议题
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Matrix
device-back
Commits
e6fd1ee7
提交
e6fd1ee7
authored
10月 20, 2020
作者:
Matrix
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[全局配置] 修正了时间类的问题
上级
db360dfe
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
122 行增加
和
167 行删除
+122
-167
Java8TimeConfig.java
...ig/src/main/java/com/tykj/dev/config/Java8TimeConfig.java
+0
-133
WebMvcConfigConfig.java
...src/main/java/com/tykj/dev/config/WebMvcConfigConfig.java
+119
-0
CheckStatTableVo.java
...j/dev/device/confirmcheck/entity/vo/CheckStatTableVo.java
+0
-1
CheckStatVo.java
...m/tykj/dev/device/confirmcheck/entity/vo/CheckStatVo.java
+0
-2
FinalCheckController.java
...ev/device/finalcheck/controller/FinalCheckController.java
+0
-29
DeviceLibrary.java
.../tykj/dev/device/library/subject/domin/DeviceLibrary.java
+3
-2
没有找到文件。
dev-config/src/main/java/com/tykj/dev/config/Java8TimeConfig.java
deleted
100644 → 0
浏览文件 @
db360dfe
package
com
.
tykj
.
dev
.
config
;
import
com.fasterxml.jackson.core.JsonGenerator
;
import
com.fasterxml.jackson.core.JsonParser
;
import
com.fasterxml.jackson.databind.*
;
import
com.fasterxml.jackson.databind.ser.std.DateSerializer
;
import
com.fasterxml.jackson.datatype.jdk8.Jdk8Module
;
import
com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
;
import
com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer
;
import
com.fasterxml.jackson.module.paramnames.ParameterNamesModule
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
java.io.IOException
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.time.Instant
;
import
java.time.LocalDateTime
;
import
java.time.ZoneId
;
import
java.time.format.DateTimeFormatter
;
import
java.util.Date
;
/**
* 描述:使jackson能够正确的接收时间格式
*
* @author HuangXiahao
* @version V1.0
* @class Java8TimeConfig
* @data 2020/5/20
**/
@Configuration
public
class
Java8TimeConfig
{
@Value
(
"${spring.jackson.date-format}"
)
private
String
formatValue
;
@Bean
(
name
=
"format"
)
DateTimeFormatter
format
()
{
return
DateTimeFormatter
.
ofPattern
(
formatValue
);
}
@Bean
public
ObjectMapper
serializingObjectMapper
(
@Qualifier
(
"format"
)
DateTimeFormatter
format
)
{
JavaTimeModule
javaTimeModule
=
new
JavaTimeModule
();
javaTimeModule
.
addSerializer
(
LocalDateTime
.
class
,
new
LocalDateTimeSerializer
(
format
));
javaTimeModule
.
addSerializer
(
Instant
.
class
,
new
InstantCustomSerializer
(
format
));
javaTimeModule
.
addSerializer
(
Date
.
class
,
new
DateSerializer
(
false
,
new
SimpleDateFormat
(
formatValue
)));
javaTimeModule
.
addDeserializer
(
Instant
.
class
,
new
InstantCustomDeserializer
());
javaTimeModule
.
addDeserializer
(
Date
.
class
,
new
DateCustomDeserializer
());
return
new
ObjectMapper
()
.
registerModule
(
new
ParameterNamesModule
())
.
configure
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
,
false
)
.
registerModule
(
javaTimeModule
)
.
disable
(
SerializationFeature
.
FAIL_ON_EMPTY_BEANS
);
}
/**
* Support for Java date and time API.
*
* @return the corresponding Jackson module.
*/
@Bean
public
JavaTimeModule
javaTimeModule
()
{
return
new
JavaTimeModule
();
}
@Bean
public
Jdk8Module
jdk8TimeModule
()
{
return
new
Jdk8Module
();
}
static
class
InstantCustomSerializer
extends
JsonSerializer
<
Instant
>
{
private
final
DateTimeFormatter
format
;
private
InstantCustomSerializer
(
DateTimeFormatter
formatter
)
{
this
.
format
=
formatter
;
}
@Override
public
void
serialize
(
Instant
instant
,
JsonGenerator
jsonGenerator
,
SerializerProvider
serializerProvider
)
throws
IOException
{
if
(
instant
==
null
)
{
return
;
}
String
jsonValue
=
format
.
format
(
instant
.
atZone
(
ZoneId
.
systemDefault
()));
jsonGenerator
.
writeString
(
jsonValue
);
}
}
static
class
InstantCustomDeserializer
extends
JsonDeserializer
<
Instant
>
{
@Override
public
Instant
deserialize
(
JsonParser
p
,
DeserializationContext
ctxt
)
throws
IOException
{
String
dateString
=
p
.
getText
().
trim
();
if
(
StringUtils
.
isNotBlank
(
dateString
))
{
Date
pareDate
;
try
{
pareDate
=
DateFormatUtil
.
pareDate
(
dateString
);
if
(
null
!=
pareDate
)
{
return
pareDate
.
toInstant
();
}
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
}
return
null
;
}
}
static
class
DateCustomDeserializer
extends
JsonDeserializer
<
Date
>
{
@Override
public
Date
deserialize
(
JsonParser
p
,
DeserializationContext
ctxt
)
throws
IOException
{
String
dateString
=
p
.
getText
().
trim
();
if
(
StringUtils
.
isNotBlank
(
dateString
))
{
try
{
return
DateFormatUtil
.
pareDate
(
dateString
);
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
}
return
null
;
}
}
}
\ No newline at end of file
dev-config/src/main/java/com/tykj/dev/config/WebMvcConfigConfig.java
浏览文件 @
e6fd1ee7
package
com
.
tykj
.
dev
.
config
;
package
com
.
tykj
.
dev
.
config
;
import
com.fasterxml.jackson.core.JsonGenerator
;
import
com.fasterxml.jackson.core.JsonParser
;
import
com.fasterxml.jackson.databind.*
;
import
com.fasterxml.jackson.databind.ser.std.DateSerializer
;
import
com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
;
import
com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer
;
import
com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer
;
import
com.fasterxml.jackson.module.paramnames.ParameterNamesModule
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
...
@@ -8,12 +17,22 @@ import org.springframework.format.datetime.DateFormatterRegistrar;
...
@@ -8,12 +17,22 @@ import org.springframework.format.datetime.DateFormatterRegistrar;
import
org.springframework.format.datetime.standard.DateTimeFormatterRegistrar
;
import
org.springframework.format.datetime.standard.DateTimeFormatterRegistrar
;
import
org.springframework.format.support.DefaultFormattingConversionService
;
import
org.springframework.format.support.DefaultFormattingConversionService
;
import
org.springframework.format.support.FormattingConversionService
;
import
org.springframework.format.support.FormattingConversionService
;
import
org.springframework.http.converter.HttpMessageConverter
;
import
org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
;
import
org.springframework.security.web.method.annotation.AuthenticationPrincipalArgumentResolver
;
import
org.springframework.security.web.method.annotation.AuthenticationPrincipalArgumentResolver
;
import
org.springframework.web.method.support.HandlerMethodArgumentResolver
;
import
org.springframework.web.method.support.HandlerMethodArgumentResolver
;
import
org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
;
import
org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport
;
import
java.io.IOException
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.time.Instant
;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
import
java.time.ZoneId
;
import
java.time.format.DateTimeFormatter
;
import
java.time.format.DateTimeFormatter
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -30,6 +49,17 @@ public class WebMvcConfigConfig extends WebMvcConfigurationSupport {
...
@@ -30,6 +49,17 @@ public class WebMvcConfigConfig extends WebMvcConfigurationSupport {
@Value
(
"${file.path}"
)
@Value
(
"${file.path}"
)
private
String
path
;
private
String
path
;
@Value
(
"${spring.jackson.date-format}"
)
private
String
formatValue
;
@Value
(
"${spring.jackson.local-date-format:yyyy-MM-dd}"
)
private
String
localDatePattern
;
@Bean
(
name
=
"format"
)
DateTimeFormatter
format
()
{
return
DateTimeFormatter
.
ofPattern
(
formatValue
);
}
/**
/**
* 发现如果继承了WebMvcConfigurationSupport,则需要在这里重新指定静态资源
* 发现如果继承了WebMvcConfigurationSupport,则需要在这里重新指定静态资源
*/
*/
...
@@ -63,8 +93,97 @@ public class WebMvcConfigConfig extends WebMvcConfigurationSupport {
...
@@ -63,8 +93,97 @@ public class WebMvcConfigConfig extends WebMvcConfigurationSupport {
return
conversionService
;
return
conversionService
;
}
}
@Override
@Override
protected
void
addArgumentResolvers
(
List
<
HandlerMethodArgumentResolver
>
argumentResolvers
)
{
protected
void
addArgumentResolvers
(
List
<
HandlerMethodArgumentResolver
>
argumentResolvers
)
{
argumentResolvers
.
add
(
new
AuthenticationPrincipalArgumentResolver
());
argumentResolvers
.
add
(
new
AuthenticationPrincipalArgumentResolver
());
}
}
/**
* Override this method to extend or modify the list of converters after it has
* been configured. This may be useful for example to allow default converters
* to be registered and then insert a custom converter through this method.
*
* @param converters the list of configured converters to extend
* @since 4.1.3
*/
@Override
protected
void
extendMessageConverters
(
List
<
HttpMessageConverter
<?>>
converters
)
{
DateTimeFormatter
format
=
DateTimeFormatter
.
ofPattern
(
formatValue
);
MappingJackson2HttpMessageConverter
converter
=
new
MappingJackson2HttpMessageConverter
();
JavaTimeModule
javaTimeModule
=
new
JavaTimeModule
();
javaTimeModule
.
addSerializer
(
LocalDateTime
.
class
,
new
LocalDateTimeSerializer
(
format
));
javaTimeModule
.
addSerializer
(
LocalDate
.
class
,
new
LocalDateSerializer
(
DateTimeFormatter
.
ofPattern
(
localDatePattern
)));
javaTimeModule
.
addSerializer
(
Instant
.
class
,
new
InstantCustomSerializer
(
format
));
javaTimeModule
.
addSerializer
(
Date
.
class
,
new
DateSerializer
(
false
,
new
SimpleDateFormat
(
formatValue
)));
javaTimeModule
.
addDeserializer
(
Instant
.
class
,
new
InstantCustomDeserializer
());
javaTimeModule
.
addDeserializer
(
Date
.
class
,
new
DateCustomDeserializer
());
ObjectMapper
mapper
=
new
ObjectMapper
()
.
registerModule
(
new
ParameterNamesModule
())
.
configure
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
,
false
)
.
registerModule
(
javaTimeModule
)
.
disable
(
SerializationFeature
.
FAIL_ON_EMPTY_BEANS
);
converter
.
setObjectMapper
(
mapper
);
converters
.
add
(
0
,
converter
);
super
.
extendMessageConverters
(
converters
);
}
static
class
InstantCustomSerializer
extends
JsonSerializer
<
Instant
>
{
private
final
DateTimeFormatter
format
;
private
InstantCustomSerializer
(
DateTimeFormatter
formatter
)
{
this
.
format
=
formatter
;
}
@Override
public
void
serialize
(
Instant
instant
,
JsonGenerator
jsonGenerator
,
SerializerProvider
serializerProvider
)
throws
IOException
{
if
(
instant
==
null
)
{
return
;
}
String
jsonValue
=
format
.
format
(
instant
.
atZone
(
ZoneId
.
systemDefault
()));
jsonGenerator
.
writeString
(
jsonValue
);
}
}
static
class
InstantCustomDeserializer
extends
JsonDeserializer
<
Instant
>
{
@Override
public
Instant
deserialize
(
JsonParser
p
,
DeserializationContext
ctxt
)
throws
IOException
{
String
dateString
=
p
.
getText
().
trim
();
if
(
StringUtils
.
isNotBlank
(
dateString
))
{
Date
pareDate
;
try
{
pareDate
=
DateFormatUtil
.
pareDate
(
dateString
);
if
(
null
!=
pareDate
)
{
return
pareDate
.
toInstant
();
}
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
}
return
null
;
}
}
static
class
DateCustomDeserializer
extends
JsonDeserializer
<
Date
>
{
@Override
public
Date
deserialize
(
JsonParser
p
,
DeserializationContext
ctxt
)
throws
IOException
{
String
dateString
=
p
.
getText
().
trim
();
if
(
StringUtils
.
isNotBlank
(
dateString
))
{
try
{
return
DateFormatUtil
.
pareDate
(
dateString
);
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
}
return
null
;
}
}
}
}
dev-confirmcheck/src/main/java/com/tykj/dev/device/confirmcheck/entity/vo/CheckStatTableVo.java
浏览文件 @
e6fd1ee7
...
@@ -37,7 +37,6 @@ public class CheckStatTableVo {
...
@@ -37,7 +37,6 @@ public class CheckStatTableVo {
private
List
<
String
>
checkUserNames
;
private
List
<
String
>
checkUserNames
;
@ApiModelProperty
(
"创建时间"
)
@ApiModelProperty
(
"创建时间"
)
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
private
LocalDateTime
createTime
;
private
LocalDateTime
createTime
;
@ApiModelProperty
(
"完成情况"
)
@ApiModelProperty
(
"完成情况"
)
...
...
dev-confirmcheck/src/main/java/com/tykj/dev/device/confirmcheck/entity/vo/CheckStatVo.java
浏览文件 @
e6fd1ee7
...
@@ -52,13 +52,11 @@ public class CheckStatVo {
...
@@ -52,13 +52,11 @@ public class CheckStatVo {
/**
/**
* 开始时间
* 开始时间
*/
*/
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
private
LocalDateTime
startTime
;
private
LocalDateTime
startTime
;
/**
/**
* 结束时间
* 结束时间
*/
*/
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
private
LocalDateTime
endTime
;
private
LocalDateTime
endTime
;
private
LocalDateTime
createTime
;
private
LocalDateTime
createTime
;
...
...
dev-finalcheck/src/main/java/com/tykj/dev/device/finalcheck/controller/FinalCheckController.java
浏览文件 @
e6fd1ee7
...
@@ -51,35 +51,6 @@ public class FinalCheckController {
...
@@ -51,35 +51,6 @@ public class FinalCheckController {
@Autowired
@Autowired
private
FinalCheckService
fcService
;
private
FinalCheckService
fcService
;
public
static
void
downloadExcel
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Workbook
wb
,
String
excelName
)
{
// 判断数据
if
(
wb
==
null
)
{
throw
new
ApiException
(
"workbook can not be null!"
);
}
// 重置响应对象
response
.
reset
();
// 当前日期,用于导出文件名称
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyyMMdd"
);
String
dateStr
=
excelName
+
sdf
.
format
(
new
Date
())
+
".xls"
;
// 指定下载的文件名--设置响应头
response
.
addHeader
(
"Content-Disposition"
,
"attachment;filename="
+
dateStr
);
response
.
setContentType
(
"application/octet-stream;charset=UTF-8"
);
response
.
setHeader
(
"Pragma"
,
"no-cache"
);
response
.
setDateHeader
(
"Expires"
,
0
);
// 写出数据输出流到页面
try
{
OutputStream
output
=
response
.
getOutputStream
();
BufferedOutputStream
bufferedOutPut
=
new
BufferedOutputStream
(
output
);
wb
.
write
(
bufferedOutPut
);
bufferedOutPut
.
flush
();
bufferedOutPut
.
close
();
output
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
@GetMapping
(
"/reports"
)
@GetMapping
(
"/reports"
)
@ApiOperation
(
value
=
"查询所有决算报告(不附带详情数据)"
)
@ApiOperation
(
value
=
"查询所有决算报告(不附带详情数据)"
)
public
Page
<
FinalReportVo
>
findAllReports
(
public
Page
<
FinalReportVo
>
findAllReports
(
...
...
dev-library/src/main/java/com/tykj/dev/device/library/subject/domin/DeviceLibrary.java
浏览文件 @
e6fd1ee7
...
@@ -13,6 +13,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
...
@@ -13,6 +13,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import
javax.persistence.*
;
import
javax.persistence.*
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -160,7 +161,7 @@ public class DeviceLibrary {
...
@@ -160,7 +161,7 @@ public class DeviceLibrary {
*/
*/
@CreatedDate
@CreatedDate
@ApiModelProperty
(
value
=
"创建时间"
)
@ApiModelProperty
(
value
=
"创建时间"
)
private
java
.
util
.
Date
createTime
;
private
Date
createTime
;
/**
/**
* 更新用户id
* 更新用户id
*/
*/
...
@@ -172,7 +173,7 @@ public class DeviceLibrary {
...
@@ -172,7 +173,7 @@ public class DeviceLibrary {
*/
*/
@LastModifiedDate
@LastModifiedDate
@ApiModelProperty
(
value
=
"更新时间"
)
@ApiModelProperty
(
value
=
"更新时间"
)
private
java
.
util
.
Date
updateTime
;
private
Date
updateTime
;
/**
/**
* 删除标记(0:未删除,1:已删除)
* 删除标记(0:未删除,1:已删除)
*/
*/
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论