Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gs1-office-web-sit
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
吴迪
gs1-office-web-sit
Commits
ac993fce
Commit
ac993fce
authored
Oct 12, 2021
by
吴迪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
磁盘映射、文件上传
parent
4af53a29
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
1038 additions
and
65 deletions
+1038
-65
ErrorCodeEnum.java
src/main/java/io/office/common/enumpack/ErrorCodeEnum.java
+37
-0
RRException.java
src/main/java/io/office/common/exception/RRException.java
+8
-0
SwaggerConfig.java
src/main/java/io/office/config/SwaggerConfig.java
+62
-62
WebMvcConfig.java
src/main/java/io/office/config/WebMvcConfig.java
+20
-0
WebMvcConfig.java
src/main/java/io/office/modules/app/config/WebMvcConfig.java
+19
-0
FileController.java
...a/io/office/modules/manage/controller/FileController.java
+31
-0
NewsColumnServiceImpl.java
...ce/modules/manage/service/impl/NewsColumnServiceImpl.java
+9
-1
DateUtils.java
src/main/java/io/office/modules/manage/utils/DateUtils.java
+763
-0
UploadUtils.java
...main/java/io/office/modules/manage/utils/UploadUtils.java
+77
-0
application-dev.yml
src/main/resources/application-dev.yml
+12
-2
No files found.
src/main/java/io/office/common/enumpack/ErrorCodeEnum.java
0 → 100644
View file @
ac993fce
package
io
.
office
.
common
.
enumpack
;
/**
*
* @description:
*
* @author wudi
* @date 22:08 2021/10/12
*/
public
enum
ErrorCodeEnum
{
SUCCESS
(
0
,
"成功"
),
//成功
FAIL
(-
1
,
"失败"
),
//失败
FILE_IS_NULL
(
10001
,
"上传文件不能为空!"
);
private
Integer
code
;
private
String
msg
;
ErrorCodeEnum
(
int
code
)
{
this
.
code
=
code
;
}
ErrorCodeEnum
(
Integer
code
,
String
message
)
{
this
.
code
=
code
;
this
.
msg
=
message
;
}
public
Integer
code
()
{
return
this
.
code
;
}
public
String
message
()
{
return
this
.
msg
;
}
}
src/main/java/io/office/common/exception/RRException.java
View file @
ac993fce
...
@@ -8,6 +8,8 @@
...
@@ -8,6 +8,8 @@
package
io
.
office
.
common
.
exception
;
package
io
.
office
.
common
.
exception
;
import
io.office.common.enumpack.ErrorCodeEnum
;
/**
/**
* 自定义异常
* 自定义异常
*
*
...
@@ -41,6 +43,12 @@ public class RRException extends RuntimeException {
...
@@ -41,6 +43,12 @@ public class RRException extends RuntimeException {
this
.
code
=
code
;
this
.
code
=
code
;
}
}
public
RRException
(
ErrorCodeEnum
errorCodeEnum
)
{
super
(
errorCodeEnum
.
message
());
this
.
code
=
errorCodeEnum
.
code
();
this
.
msg
=
errorCodeEnum
.
message
();
}
public
String
getMsg
()
{
public
String
getMsg
()
{
return
msg
;
return
msg
;
}
}
...
...
src/main/java/io/office/config/SwaggerConfig.java
View file @
ac993fce
/**
///**
* Copyright (c) 2016-2019 人人开源 All rights reserved.
// * Copyright (c) 2016-2019 人人开源 All rights reserved.
*
// *
* https://www.renren.io
// * https://www.renren.io
*
// *
* 版权所有,侵权必究!
// * 版权所有,侵权必究!
*/
// */
//
package
io
.
office
.
config
;
//package io.office.config;
//
import
io.swagger.annotations.ApiOperation
;
//import io.swagger.annotations.ApiOperation;
import
org.springframework.context.annotation.Bean
;
//import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Configuration
;
//import org.springframework.context.annotation.Configuration;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
//import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import
springfox.documentation.builders.ApiInfoBuilder
;
//import springfox.documentation.builders.ApiInfoBuilder;
import
springfox.documentation.builders.PathSelectors
;
//import springfox.documentation.builders.PathSelectors;
import
springfox.documentation.builders.RequestHandlerSelectors
;
//import springfox.documentation.builders.RequestHandlerSelectors;
import
springfox.documentation.service.ApiInfo
;
//import springfox.documentation.service.ApiInfo;
import
springfox.documentation.service.ApiKey
;
//import springfox.documentation.service.ApiKey;
import
springfox.documentation.spi.DocumentationType
;
//import springfox.documentation.spi.DocumentationType;
import
springfox.documentation.spring.web.plugins.Docket
;
//import springfox.documentation.spring.web.plugins.Docket;
import
springfox.documentation.swagger2.annotations.EnableSwagger2
;
//import springfox.documentation.swagger2.annotations.EnableSwagger2;
//
import
java.util.List
;
//import java.util.List;
//
import
static
com
.
google
.
common
.
collect
.
Lists
.
newArrayList
;
//import static com.google.common.collect.Lists.newArrayList;
//
@Configuration
//@Configuration
@EnableSwagger2
//@EnableSwagger2
public
class
SwaggerConfig
implements
WebMvcConfigurer
{
//public class SwaggerConfig implements WebMvcConfigurer {
//
@Bean
// /* @Bean
public
Docket
createRestApi
()
{
// public Docket createRestApi() {
return
new
Docket
(
DocumentationType
.
SWAGGER_2
)
// return new Docket(DocumentationType.SWAGGER_2)
.
apiInfo
(
apiInfo
())
// .apiInfo(apiInfo())
.
select
()
// .select()
//加了ApiOperation注解的类,才生成接口文档
// //加了ApiOperation注解的类,才生成接口文档
.
apis
(
RequestHandlerSelectors
.
withMethodAnnotation
(
ApiOperation
.
class
))
// .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
//包下的类,才生成接口文档
// //包下的类,才生成接口文档
//.apis(RequestHandlerSelectors.basePackage("io.renren.controller"))
// //.apis(RequestHandlerSelectors.basePackage("io.renren.controller"))
.
paths
(
PathSelectors
.
any
())
// .paths(PathSelectors.any())
.
build
()
// .build()
.
securitySchemes
(
security
());
// .securitySchemes(security());
}
// }
//
private
ApiInfo
apiInfo
()
{
// private ApiInfo apiInfo() {
return
new
ApiInfoBuilder
()
// return new ApiInfoBuilder()
.
title
(
"人人开源"
)
// .title("人人开源")
.
description
(
"renren-fast文档"
)
// .description("renren-fast文档")
.
termsOfServiceUrl
(
"https://www.renren.io"
)
// .termsOfServiceUrl("https://www.renren.io")
.
version
(
"3.0.0"
)
// .version("3.0.0")
.
build
();
// .build();
}
// }
//
private
List
<
ApiKey
>
security
()
{
// private List<ApiKey> security() {
return
newArrayList
(
// return newArrayList(
new
ApiKey
(
"token"
,
"token"
,
"header"
)
// new ApiKey("token", "token", "header")
);
// );
}
// }*/
//
}
//}
\ No newline at end of file
\ No newline at end of file
src/main/java/io/office/config/WebMvcConfig.java
0 → 100644
View file @
ac993fce
package
io
.
office
.
config
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
;
/**
* TODO
*
* @author wudi
* @version 1.0
* @date 2021/3/24 9:44
*/
//@Configuration
public
class
WebMvcConfig
extends
WebMvcConfigurerAdapter
{
}
src/main/java/io/office/modules/app/config/WebMvcConfig.java
View file @
ac993fce
...
@@ -11,9 +11,11 @@ package io.office.modules.app.config;
...
@@ -11,9 +11,11 @@ package io.office.modules.app.config;
import
io.office.modules.app.interceptor.AuthorizationInterceptor
;
import
io.office.modules.app.interceptor.AuthorizationInterceptor
;
import
io.office.modules.app.resolver.LoginUserHandlerMethodArgumentResolver
;
import
io.office.modules.app.resolver.LoginUserHandlerMethodArgumentResolver
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.method.support.HandlerMethodArgumentResolver
;
import
org.springframework.web.method.support.HandlerMethodArgumentResolver
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
import
java.util.List
;
import
java.util.List
;
...
@@ -25,6 +27,11 @@ import java.util.List;
...
@@ -25,6 +27,11 @@ import java.util.List;
*/
*/
@Configuration
@Configuration
public
class
WebMvcConfig
implements
WebMvcConfigurer
{
public
class
WebMvcConfig
implements
WebMvcConfigurer
{
@Value
(
"${request.upload.file.prefix}"
)
private
String
requestUploadFilePrefix
;
@Value
(
"${file.save.path}"
)
private
String
fileSavePath
;
@Autowired
@Autowired
private
AuthorizationInterceptor
authorizationInterceptor
;
private
AuthorizationInterceptor
authorizationInterceptor
;
@Autowired
@Autowired
...
@@ -39,4 +46,15 @@ public class WebMvcConfig implements WebMvcConfigurer {
...
@@ -39,4 +46,15 @@ public class WebMvcConfig implements WebMvcConfigurer {
public
void
addArgumentResolvers
(
List
<
HandlerMethodArgumentResolver
>
argumentResolvers
)
{
public
void
addArgumentResolvers
(
List
<
HandlerMethodArgumentResolver
>
argumentResolvers
)
{
argumentResolvers
.
add
(
loginUserHandlerMethodArgumentResolver
);
argumentResolvers
.
add
(
loginUserHandlerMethodArgumentResolver
);
}
}
@Override
public
void
addResourceHandlers
(
ResourceHandlerRegistry
registry
)
{
//注意前面要加file,不然是访问不了的
registry
.
addResourceHandler
(
"/"
+
requestUploadFilePrefix
+
"/**"
).
addResourceLocations
(
"file"
+
":"
+
fileSavePath
);
}
}
}
\ No newline at end of file
src/main/java/io/office/modules/manage/controller/FileController.java
0 → 100644
View file @
ac993fce
package
io
.
office
.
modules
.
manage
.
controller
;
import
io.office.common.utils.R
;
import
io.office.modules.manage.utils.UploadUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.MultipartFile
;
/**
*
* @description:
*
* @author wudi
* @date 22:03 2021/10/12
*/
@RestController
@RequestMapping
(
value
=
"/file"
)
@Slf4j
public
class
FileController
{
@Autowired
private
UploadUtils
uploadUtils
;
@PostMapping
(
"/uploadFile"
)
public
R
uploadFile
(
@RequestParam
(
"file"
)
MultipartFile
file
)
{
return
R
.
ok
().
put
(
"data"
,
uploadUtils
.
fileUpload
(
file
));
}
}
src/main/java/io/office/modules/manage/service/impl/NewsColumnServiceImpl.java
View file @
ac993fce
package
io
.
office
.
modules
.
manage
.
service
.
impl
;
package
io
.
office
.
modules
.
manage
.
service
.
impl
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.util.Map
;
import
java.util.Map
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
...
@@ -16,14 +17,20 @@ import io.office.modules.manage.service.NewsColumnService;
...
@@ -16,14 +17,20 @@ import io.office.modules.manage.service.NewsColumnService;
@Service
(
"newsColumnService"
)
@Service
(
"newsColumnService"
)
public
class
NewsColumnServiceImpl
extends
ServiceImpl
<
NewsColumnDao
,
NewsColumnEntity
>
implements
NewsColumnService
{
public
class
NewsColumnServiceImpl
extends
ServiceImpl
<
NewsColumnDao
,
NewsColumnEntity
>
implements
NewsColumnService
{
@Override
@Override
public
PageUtils
queryPage
(
Map
<
String
,
Object
>
params
)
{
public
PageUtils
queryPage
(
Map
<
String
,
Object
>
params
)
{
IPage
<
NewsColumnEntity
>
page
=
this
.
page
(
IPage
<
NewsColumnEntity
>
page
=
this
.
page
(
new
Query
<
NewsColumnEntity
>().
getPage
(
params
),
new
Query
<
NewsColumnEntity
>().
getPage
(
params
),
new
QueryWrapper
<
NewsColumnEntity
>()
new
QueryWrapper
<
NewsColumnEntity
>()
);
);
return
new
PageUtils
(
page
);
return
new
PageUtils
(
page
);
}
}
}
}
\ No newline at end of file
src/main/java/io/office/modules/manage/utils/DateUtils.java
0 → 100644
View file @
ac993fce
package
io
.
office
.
modules
.
manage
.
utils
;
import
lombok.extern.slf4j.Slf4j
;
import
java.sql.Timestamp
;
import
java.text.DateFormat
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.GregorianCalendar
;
/**
* TODO
*
* @author wudi
* @version 1.0
* @date 2021/4/19 11:09
*/
@Slf4j
public
class
DateUtils
{
/**
* 获取两个日期 相差的时间
* @param startTime
* @param endTime
* @param format
* @return
* @throws ParseException
*/
public
static
String
dateDiff
(
String
startTime
,
String
endTime
,
String
format
)
throws
ParseException
{
//按照传入的格式生成一个simpledateformate对象
SimpleDateFormat
sd
=
new
SimpleDateFormat
(
format
);
long
nd
=
1000
*
24
*
60
*
60
;
//一天的毫秒数
long
nh
=
1000
*
60
*
60
;
//一小时的毫秒数
long
nm
=
1000
*
60
;
//一分钟的毫秒数
long
ns
=
1000
;
//一秒钟的毫秒数
long
diff
;
//获得两个时间的毫秒时间差异
diff
=
sd
.
parse
(
endTime
).
getTime
()
-
sd
.
parse
(
startTime
).
getTime
();
long
day
=
diff
/
nd
;
//计算差多少天
long
hour
=
diff
%
nd
/
nh
;
//计算差多少小时
long
min
=
diff
%
nd
%
nh
/
nm
;
//计算差多少分钟
long
sec
=
diff
%
nd
%
nh
%
nm
/
ns
;
//计算差多少秒//输出结果
StringBuffer
stringBuffer
=
new
StringBuffer
();
if
(
day
>
0
){
stringBuffer
.
append
(
day
+
"天"
);
}
else
{
stringBuffer
.
append
(
"0天"
);
}
if
(
hour
>
0
){
stringBuffer
.
append
(
hour
+
"小时"
);
}
else
{
stringBuffer
.
append
(
"0小时"
);
}
if
(
min
>
0
){
stringBuffer
.
append
(
min
+
"分钟"
);
}
else
{
stringBuffer
.
append
(
"0分钟"
);
}
if
(
sec
>
0
){
stringBuffer
.
append
(
sec
+
"秒"
);
}
else
{
stringBuffer
.
append
(
"0秒"
);
}
//System.out.println("时间相差:"+day+"天"+hour+"小时"+min+"分钟");
return
stringBuffer
.
toString
()
;
}
public
static
void
main
(
String
[]
args
)
throws
ParseException
{
System
.
out
.
println
(
getAfterMinCycleByHour
(
new
Date
(),
"-5"
));
}
public
final
static
String
FORMAT1
=
"yyyy-MM-dd HH:mm:ss"
;
public
final
static
String
FORMAT2
=
"yyyyMMddHHmmss"
;
public
final
static
String
FORMAT3
=
"yyyy年MM月dd日HH时mm分"
;
public
final
static
String
FORMAT4
=
"yyyy-MM-dd"
;
private
DateUtils
()
{
throw
new
IllegalStateException
();
}
/**
* 获取YYYY格式
*/
public
static
String
getYear
()
{
SimpleDateFormat
sdfYear
=
new
SimpleDateFormat
(
"yyyy"
);
return
sdfYear
.
format
(
new
Date
());
}
/**
* 获取YYYY-MM-DD格式
*/
public
static
String
getDay
()
{
SimpleDateFormat
sdfDay
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
return
sdfDay
.
format
(
new
Date
());
}
/**
* 获取YYYYMMDD格式
*/
public
static
String
getDays
()
{
SimpleDateFormat
sdfDays
=
new
SimpleDateFormat
(
"yyyyMMdd"
);
return
sdfDays
.
format
(
new
Date
());
}
/**
* 获取YYYY-MM-DD hh:mm:ss格式
*/
public
static
String
getTime
()
{
SimpleDateFormat
sdfTime
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
return
sdfTime
.
format
(
new
Date
());
}
public
static
String
formatDateToString
(
Date
date
,
String
format
)
{
SimpleDateFormat
fmt
=
new
SimpleDateFormat
(
format
);
return
fmt
.
format
(
date
);
}
public
static
Date
fomatDate
(
String
date
)
{
return
fomatDate
(
date
,
"yyyy-MM-dd"
);
}
public
static
Date
fomatDateTime
(
String
dateTime
)
{
return
fomatDate
(
dateTime
,
"yyyy-MM-dd HH:mm:ss"
);
}
/**
* 格式化日期
*/
public
static
Date
fomatDate
(
String
date
,
String
format
)
{
DateFormat
fmt
=
new
SimpleDateFormat
(
format
);
try
{
return
fmt
.
parse
(
date
);
}
catch
(
ParseException
e
)
{
log
.
error
(
"fomatDate:"
,
e
);
return
null
;
}
}
/**
* 格式化日期
*/
public
static
String
fomatMSELDate
(
String
date
)
{
if
(
date
.
contains
(
"."
))
{
String
[]
strs
=
date
.
split
(
"\\."
);
return
strs
[
0
];
}
else
{
return
date
;
}
}
/**
* 校验日期是否合法
*/
public
static
boolean
isValidDate
(
String
s
)
{
DateFormat
fmt
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
try
{
fmt
.
parse
(
s
);
return
true
;
}
catch
(
Exception
e
)
{
log
.
error
(
"isValidDate:"
,
e
);
return
false
;
}
}
public
static
int
getDiffYear
(
String
startTime
,
String
endTime
)
{
DateFormat
fmt
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
try
{
long
aa
=
0
;
int
years
=
(
int
)
(((
fmt
.
parse
(
endTime
).
getTime
()
-
fmt
.
parse
(
startTime
).
getTime
())
/
(
1000
*
60
*
60
*
24
))
/
365
);
return
years
;
}
catch
(
Exception
e
)
{
log
.
error
(
"getDiffYear:"
,
e
);
return
0
;
}
}
/**
* <li>功能描述:时间相减得到天数
*
* @return long
* @author Administrator
*/
public
static
long
getDaySub
(
String
beginDateStr
,
String
endDateStr
)
{
long
day
=
0
;
try
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
Date
beginDate
=
null
;
Date
endDate
=
null
;
beginDate
=
format
.
parse
(
beginDateStr
);
endDate
=
format
.
parse
(
endDateStr
);
day
=
(
endDate
.
getTime
()
-
beginDate
.
getTime
())
/
(
24
*
60
*
60
*
1000
);
}
catch
(
ParseException
e
)
{
log
.
error
(
"getDaySub:"
,
e
);
}
return
day
;
}
/**
* 得到周期单位为月/季的日期
*/
public
static
String
getAfterDayCycleByMonth
(
Date
date
,
String
days
)
{
int
daysInt
=
Integer
.
parseInt
(
days
);
Calendar
canlendar
=
Calendar
.
getInstance
();
canlendar
.
setTime
(
date
);
canlendar
.
add
(
Calendar
.
MONTH
,
daysInt
);
SimpleDateFormat
sdfd
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
String
dateStr
=
sdfd
.
format
(
canlendar
.
getTime
());
return
dateStr
;
}
/**
* 得到周期单位为年的日期
*/
public
static
String
getAfterDayCycleByYear
(
Date
date
,
String
days
)
{
int
daysInt
=
Integer
.
parseInt
(
days
);
Calendar
canlendar
=
Calendar
.
getInstance
();
canlendar
.
setTime
(
date
);
canlendar
.
add
(
Calendar
.
YEAR
,
daysInt
);
SimpleDateFormat
sdfd
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
String
dateStr
=
sdfd
.
format
(
canlendar
.
getTime
());
return
dateStr
;
}
/**
* 得到n天之后的日期
*/
public
static
String
getAfterDayCycleByDay
(
Date
date
,
String
days
)
{
int
daysInt
=
Integer
.
parseInt
(
days
);
Calendar
canlendar
=
Calendar
.
getInstance
();
canlendar
.
setTime
(
date
);
canlendar
.
add
(
Calendar
.
DATE
,
daysInt
);
SimpleDateFormat
sdfd
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
String
dateStr
=
sdfd
.
format
(
canlendar
.
getTime
());
return
dateStr
;
}
/**
* 得到n小时之后的日期
*/
public
static
String
getAfterHourCycleByHour
(
Date
date
,
String
days
)
{
int
daysInt
=
Integer
.
parseInt
(
days
);
Calendar
canlendar
=
Calendar
.
getInstance
();
canlendar
.
setTime
(
date
);
canlendar
.
add
(
Calendar
.
HOUR
,
daysInt
);
SimpleDateFormat
sdfd
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
String
dateStr
=
sdfd
.
format
(
canlendar
.
getTime
());
return
dateStr
;
}
/**
* 得到n小时之后的日期
*/
public
static
String
getAfterMinCycleByHour
(
Date
date
,
String
mins
)
{
int
daysInt
=
Integer
.
parseInt
(
mins
);
Calendar
canlendar
=
Calendar
.
getInstance
();
canlendar
.
setTime
(
date
);
canlendar
.
add
(
Calendar
.
MINUTE
,
daysInt
);
SimpleDateFormat
sdfd
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
String
dateStr
=
sdfd
.
format
(
canlendar
.
getTime
());
return
dateStr
;
}
/**
* 得到n天之后的日期
*/
public
static
String
getAfterDayDate
(
String
days
)
{
int
daysInt
=
Integer
.
parseInt
(
days
);
Calendar
canlendar
=
Calendar
.
getInstance
();
canlendar
.
add
(
Calendar
.
DATE
,
daysInt
);
Date
date
=
canlendar
.
getTime
();
SimpleDateFormat
sdfd
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
String
dateStr
=
sdfd
.
format
(
date
);
return
dateStr
;
}
/**
* 得到n天之后是周几
*/
public
static
String
getAfterDayWeek
(
String
days
)
{
int
daysInt
=
Integer
.
parseInt
(
days
);
Calendar
canlendar
=
Calendar
.
getInstance
();
canlendar
.
add
(
Calendar
.
DATE
,
daysInt
);
Date
date
=
canlendar
.
getTime
();
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"E"
);
String
dateStr
=
sdf
.
format
(
date
);
return
dateStr
;
}
/**
* 根据出生日期计算年龄
*
* @return 未来日期返回0
*/
public
static
int
getAge
(
Date
birthDay
)
throws
Exception
{
Calendar
cal
=
Calendar
.
getInstance
();
if
(
cal
.
before
(
birthDay
))
{
return
0
;
}
int
yearNow
=
cal
.
get
(
Calendar
.
YEAR
);
int
monthNow
=
cal
.
get
(
Calendar
.
MONTH
);
int
dayOfMonthNow
=
cal
.
get
(
Calendar
.
DAY_OF_MONTH
);
cal
.
setTime
(
birthDay
);
int
yearBirth
=
cal
.
get
(
Calendar
.
YEAR
);
int
monthBirth
=
cal
.
get
(
Calendar
.
MONTH
);
int
dayOfMonthBirth
=
cal
.
get
(
Calendar
.
DAY_OF_MONTH
);
int
age
=
yearNow
-
yearBirth
;
if
(
monthNow
<=
monthBirth
)
{
if
(
monthNow
==
monthBirth
)
{
if
(
dayOfMonthNow
<
dayOfMonthBirth
)
{
age
--;
}
}
else
{
age
--;
}
}
return
age
;
}
/**
* 根据出生日期计算年龄
*
* @param strBirthDay 字符串型日期
* @param format 日期格式
* @return 未来日期返回0
*/
public
static
int
getAge
(
String
strBirthDay
,
String
format
)
throws
Exception
{
DateFormat
df
=
new
SimpleDateFormat
(
format
);
Date
birthDay
=
df
.
parse
(
strBirthDay
);
return
getAge
(
birthDay
);
}
public
static
String
getCurrentTime
(
String
formatValue
)
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
formatValue
);
Calendar
calendar
=
Calendar
.
getInstance
();
return
format
.
format
(
calendar
.
getTime
());
}
public
static
long
getCurrentDateTime
()
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
getTimeInMillis
();
return
calendar
.
getTimeInMillis
();
}
public
static
String
getCurrentStartTime
(
String
formatValue
)
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
formatValue
);
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
calendar
.
set
(
Calendar
.
SECOND
,
0
);
calendar
.
set
(
Calendar
.
MINUTE
,
0
);
return
format
.
format
(
calendar
.
getTime
());
}
public
static
String
getCurrentStartTime
(
String
formatValue
,
String
datetime
)
throws
Exception
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
formatValue
);
Date
tempDatetime
=
format
.
parse
(
datetime
);
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
tempDatetime
);
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
calendar
.
set
(
Calendar
.
SECOND
,
0
);
calendar
.
set
(
Calendar
.
MINUTE
,
0
);
return
format
.
format
(
calendar
.
getTime
());
}
public
static
String
getCurrentEndTime
(
String
formatValue
)
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
formatValue
);
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
23
);
calendar
.
set
(
Calendar
.
SECOND
,
59
);
calendar
.
set
(
Calendar
.
MINUTE
,
59
);
return
format
.
format
(
calendar
.
getTime
());
}
public
static
String
getCurrentEndTime
(
String
formatValue
,
String
datetime
)
throws
Exception
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
formatValue
);
Date
tempDatetime
=
format
.
parse
(
datetime
);
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
tempDatetime
);
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
23
);
calendar
.
set
(
Calendar
.
SECOND
,
59
);
calendar
.
set
(
Calendar
.
MINUTE
,
59
);
return
format
.
format
(
calendar
.
getTime
());
}
public
static
String
getCurrentMonth
()
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
"yyyy-MM"
);
Calendar
calendar
=
Calendar
.
getInstance
();
return
format
.
format
(
calendar
.
getTime
());
}
public
static
String
getCurrentMonth
(
String
datetime
)
throws
Exception
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
"yyyy-MM"
);
Date
tempDatetime
=
format
.
parse
(
datetime
);
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
tempDatetime
);
return
format
.
format
(
calendar
.
getTime
());
}
public
static
String
getCurrentWeek
()
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
"MM-W"
);
Calendar
calendar
=
new
GregorianCalendar
();
calendar
.
setFirstDayOfWeek
(
Calendar
.
MONDAY
);
calendar
.
setTime
(
new
Date
());
calendar
.
set
(
Calendar
.
DAY_OF_WEEK
,
calendar
.
getFirstDayOfWeek
());
return
format
.
format
(
calendar
.
getTime
());
}
public
static
String
getCurrentWeek
(
String
datetime
)
throws
Exception
{
SimpleDateFormat
currentFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
Date
tempDatetime
=
currentFormat
.
parse
(
datetime
);
SimpleDateFormat
format
=
new
SimpleDateFormat
(
"MM-W"
);
Calendar
calendar
=
new
GregorianCalendar
();
calendar
.
setFirstDayOfWeek
(
Calendar
.
MONDAY
);
calendar
.
setTime
(
tempDatetime
);
calendar
.
set
(
Calendar
.
DAY_OF_WEEK
,
calendar
.
getFirstDayOfWeek
());
return
format
.
format
(
calendar
.
getTime
());
}
public
static
String
getCurrentLastYearStartTime
(
String
formatValue
)
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
formatValue
);
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
add
(
Calendar
.
YEAR
,
-
1
);
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
calendar
.
set
(
Calendar
.
SECOND
,
0
);
calendar
.
set
(
Calendar
.
MINUTE
,
0
);
return
format
.
format
(
calendar
.
getTime
());
}
public
static
String
getCurrentLastMonthStartTime
(
String
formatValue
)
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
formatValue
);
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
add
(
Calendar
.
MONTH
,
-
1
);
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
calendar
.
set
(
Calendar
.
SECOND
,
0
);
calendar
.
set
(
Calendar
.
MINUTE
,
0
);
return
format
.
format
(
calendar
.
getTime
());
}
public
static
String
getCurrentLastWeekStartTime
(
String
formatValue
)
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
formatValue
);
Calendar
calendar
=
new
GregorianCalendar
();
calendar
.
set
(
Calendar
.
DAY_OF_YEAR
,
calendar
.
get
(
Calendar
.
DAY_OF_YEAR
)
-
7
);
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
calendar
.
set
(
Calendar
.
SECOND
,
0
);
calendar
.
set
(
Calendar
.
MINUTE
,
0
);
return
format
.
format
(
calendar
.
getTime
());
}
public
static
String
getCurrentMonthStartTime
(
String
formatValue
)
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
formatValue
);
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
add
(
Calendar
.
MONTH
,
0
);
calendar
.
set
(
Calendar
.
DAY_OF_MONTH
,
1
);
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
calendar
.
set
(
Calendar
.
SECOND
,
0
);
calendar
.
set
(
Calendar
.
MINUTE
,
0
);
return
format
.
format
(
calendar
.
getTime
());
}
public
static
String
getCurrentMonthStartTime
(
String
formatValue
,
String
datetime
)
throws
Exception
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
formatValue
);
Date
tempDatetime
=
format
.
parse
(
datetime
);
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
tempDatetime
);
calendar
.
add
(
Calendar
.
MONTH
,
0
);
calendar
.
set
(
Calendar
.
DAY_OF_MONTH
,
1
);
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
calendar
.
set
(
Calendar
.
SECOND
,
0
);
calendar
.
set
(
Calendar
.
MINUTE
,
0
);
return
format
.
format
(
calendar
.
getTime
());
}
public
static
String
getCurrentMonthEndTime
(
String
formatValue
)
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
formatValue
);
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
add
(
Calendar
.
MONTH
,
0
);
calendar
.
set
(
Calendar
.
DAY_OF_MONTH
,
calendar
.
getActualMaximum
(
Calendar
.
DAY_OF_MONTH
));
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
23
);
calendar
.
set
(
Calendar
.
SECOND
,
59
);
calendar
.
set
(
Calendar
.
MINUTE
,
59
);
return
format
.
format
(
calendar
.
getTime
());
}
public
static
String
getCurrentMonthEndTime
(
String
formatValue
,
String
datetime
)
throws
Exception
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
formatValue
);
Date
tempDatetime
=
format
.
parse
(
datetime
);
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
tempDatetime
);
calendar
.
add
(
Calendar
.
MONTH
,
0
);
calendar
.
set
(
Calendar
.
DAY_OF_MONTH
,
calendar
.
getActualMaximum
(
Calendar
.
DAY_OF_MONTH
));
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
23
);
calendar
.
set
(
Calendar
.
SECOND
,
59
);
calendar
.
set
(
Calendar
.
MINUTE
,
59
);
return
format
.
format
(
calendar
.
getTime
());
}
public
static
String
getCurrentYearStartTime
(
String
formatValue
)
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
formatValue
);
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
add
(
Calendar
.
YEAR
,
0
);
calendar
.
set
(
Calendar
.
MONTH
,
0
);
calendar
.
set
(
Calendar
.
DAY_OF_MONTH
,
1
);
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
calendar
.
set
(
Calendar
.
SECOND
,
0
);
calendar
.
set
(
Calendar
.
MINUTE
,
0
);
return
format
.
format
(
calendar
.
getTime
());
}
public
static
String
getCurrentYearStartTime
(
String
formatValue
,
String
datetime
)
throws
Exception
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
formatValue
);
Date
tempDatetime
=
format
.
parse
(
datetime
);
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
tempDatetime
);
calendar
.
add
(
Calendar
.
YEAR
,
0
);
calendar
.
set
(
Calendar
.
MONTH
,
0
);
calendar
.
set
(
Calendar
.
DAY_OF_MONTH
,
1
);
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
calendar
.
set
(
Calendar
.
SECOND
,
0
);
calendar
.
set
(
Calendar
.
MINUTE
,
0
);
return
format
.
format
(
calendar
.
getTime
());
}
public
static
String
getCurrentYearEndTime
(
String
formatValue
)
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
formatValue
);
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
set
(
Calendar
.
YEAR
,
calendar
.
get
(
Calendar
.
YEAR
)
+
1
);
calendar
.
set
(
Calendar
.
MONTH
,
11
);
calendar
.
set
(
Calendar
.
DAY_OF_YEAR
,
0
);
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
23
);
calendar
.
set
(
Calendar
.
SECOND
,
59
);
calendar
.
set
(
Calendar
.
MINUTE
,
59
);
return
format
.
format
(
calendar
.
getTime
());
}
public
static
String
getCurrentYearEndTime
(
String
formatValue
,
String
datetime
)
throws
Exception
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
formatValue
);
Date
tempDatetime
=
format
.
parse
(
datetime
);
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
tempDatetime
);
calendar
.
set
(
Calendar
.
YEAR
,
calendar
.
get
(
Calendar
.
YEAR
)
+
1
);
calendar
.
set
(
Calendar
.
MONTH
,
11
);
calendar
.
set
(
Calendar
.
DAY_OF_YEAR
,
0
);
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
23
);
calendar
.
set
(
Calendar
.
SECOND
,
59
);
calendar
.
set
(
Calendar
.
MINUTE
,
59
);
return
format
.
format
(
calendar
.
getTime
());
}
public
static
String
getCurrentWeekStartTime
(
String
formatValue
)
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
formatValue
);
Calendar
calendar
=
new
GregorianCalendar
();
calendar
.
setFirstDayOfWeek
(
Calendar
.
MONDAY
);
calendar
.
setTime
(
new
Date
());
calendar
.
set
(
Calendar
.
DAY_OF_WEEK
,
calendar
.
getFirstDayOfWeek
());
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
calendar
.
set
(
Calendar
.
SECOND
,
0
);
calendar
.
set
(
Calendar
.
MINUTE
,
0
);
return
format
.
format
(
calendar
.
getTime
());
}
public
static
String
getCurrentWeekStartTime
(
String
formatValue
,
String
datetime
)
throws
Exception
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
formatValue
);
Date
tempDatetime
=
format
.
parse
(
datetime
);
Calendar
calendar
=
new
GregorianCalendar
();
calendar
.
setFirstDayOfWeek
(
Calendar
.
MONDAY
);
calendar
.
setTime
(
tempDatetime
);
calendar
.
set
(
Calendar
.
DAY_OF_WEEK
,
calendar
.
getFirstDayOfWeek
());
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
calendar
.
set
(
Calendar
.
SECOND
,
0
);
calendar
.
set
(
Calendar
.
MINUTE
,
0
);
return
format
.
format
(
calendar
.
getTime
());
}
public
static
String
getCurrentWeekEndTime
(
String
formatValue
)
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
formatValue
);
Calendar
calendar
=
new
GregorianCalendar
();
calendar
.
setFirstDayOfWeek
(
Calendar
.
MONDAY
);
calendar
.
setTime
(
new
Date
());
calendar
.
set
(
Calendar
.
DAY_OF_WEEK
,
calendar
.
getFirstDayOfWeek
()
+
6
);
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
23
);
calendar
.
set
(
Calendar
.
SECOND
,
59
);
calendar
.
set
(
Calendar
.
MINUTE
,
59
);
return
format
.
format
(
calendar
.
getTime
());
}
public
static
String
getCurrentWeekEndTime
(
String
formatValue
,
String
datetime
)
throws
Exception
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
formatValue
);
Date
tempDatetime
=
format
.
parse
(
datetime
);
Calendar
calendar
=
new
GregorianCalendar
();
calendar
.
setFirstDayOfWeek
(
Calendar
.
MONDAY
);
calendar
.
setTime
(
tempDatetime
);
calendar
.
set
(
Calendar
.
DAY_OF_WEEK
,
calendar
.
getFirstDayOfWeek
()
+
6
);
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
23
);
calendar
.
set
(
Calendar
.
SECOND
,
59
);
calendar
.
set
(
Calendar
.
MINUTE
,
59
);
return
format
.
format
(
calendar
.
getTime
());
}
public
static
String
getCurrentWeekStartTimePlusWeek
(
String
formatValue
,
int
week
)
{
int
day
=
week
*
7
;
log
.
info
(
String
.
valueOf
(
day
));
SimpleDateFormat
format
=
new
SimpleDateFormat
(
formatValue
);
Calendar
calendar
=
new
GregorianCalendar
();
calendar
.
setFirstDayOfWeek
(
Calendar
.
MONDAY
);
calendar
.
setTime
(
new
Date
());
calendar
.
add
(
Calendar
.
DATE
,
day
);
calendar
.
set
(
Calendar
.
DAY_OF_WEEK
,
calendar
.
getFirstDayOfWeek
());
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
calendar
.
set
(
Calendar
.
SECOND
,
0
);
calendar
.
set
(
Calendar
.
MINUTE
,
0
);
return
format
.
format
(
calendar
.
getTime
());
}
public
static
String
getCurrentWeekEndTimePlusWeek
(
String
formatValue
,
int
week
)
{
int
day
=
week
*
7
;
SimpleDateFormat
format
=
new
SimpleDateFormat
(
formatValue
);
Calendar
calendar
=
new
GregorianCalendar
();
calendar
.
setFirstDayOfWeek
(
Calendar
.
MONDAY
);
calendar
.
setTime
(
new
Date
());
calendar
.
add
(
Calendar
.
DATE
,
day
);
calendar
.
add
(
Calendar
.
DAY_OF_WEEK
,
calendar
.
getFirstDayOfWeek
()
+
6
);
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
23
);
calendar
.
set
(
Calendar
.
SECOND
,
59
);
calendar
.
set
(
Calendar
.
MINUTE
,
59
);
return
format
.
format
(
calendar
.
getTime
());
}
// 获取本周的开始时间
public
static
Date
getBeginDayOfWeek
()
{
Date
date
=
new
Date
();
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
setTime
(
date
);
int
dayofweek
=
cal
.
get
(
Calendar
.
DAY_OF_WEEK
);
if
(
dayofweek
==
1
)
{
dayofweek
+=
7
;
}
cal
.
add
(
Calendar
.
DATE
,
2
-
dayofweek
);
return
getDayStartTime
(
cal
.
getTime
());
}
// 获取本周的结束时间
public
static
Date
getEndDayOfWeek
()
{
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
setTime
(
getBeginDayOfWeek
());
cal
.
add
(
Calendar
.
DAY_OF_WEEK
,
6
);
Date
weekEndSta
=
cal
.
getTime
();
return
getDayEndTime
(
weekEndSta
);
}
// 获取某个日期的开始时间
public
static
Timestamp
getDayStartTime
(
Date
d
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
d
);
calendar
.
set
(
calendar
.
get
(
Calendar
.
YEAR
),
calendar
.
get
(
Calendar
.
MONTH
),
calendar
.
get
(
Calendar
.
DAY_OF_MONTH
),
0
,
0
,
0
);
calendar
.
set
(
Calendar
.
MILLISECOND
,
0
);
return
new
Timestamp
(
calendar
.
getTimeInMillis
());
}
// 获取某个日期的结束时间
public
static
Timestamp
getDayEndTime
(
Date
d
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
if
(
null
!=
d
)
{
calendar
.
setTime
(
d
);
}
calendar
.
set
(
calendar
.
get
(
Calendar
.
YEAR
),
calendar
.
get
(
Calendar
.
MONTH
),
calendar
.
get
(
Calendar
.
DAY_OF_MONTH
),
23
,
59
,
59
);
calendar
.
set
(
Calendar
.
MILLISECOND
,
999
);
return
new
Timestamp
(
calendar
.
getTimeInMillis
());
}
// 获取本月的开始时间
public
static
Date
getBeginDayOfMonth
()
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
set
(
getNowYear
(),
getNowMonth
()
-
1
,
1
);
return
getDayStartTime
(
calendar
.
getTime
());
}
// 获取本月的结束时间
public
static
Date
getEndDayOfMonth
()
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
set
(
getNowYear
(),
getNowMonth
()
-
1
,
1
);
int
day
=
calendar
.
getActualMaximum
(
5
);
calendar
.
set
(
getNowYear
(),
getNowMonth
()
-
1
,
day
);
return
getDayEndTime
(
calendar
.
getTime
());
}
// 获取上月的开始时间
public
static
Date
getBeginDayOfLastMonth
()
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
set
(
getNowYear
(),
getNowMonth
()
-
2
,
1
);
return
getDayStartTime
(
calendar
.
getTime
());
}
// 获取上月的结束时间
public
static
Date
getEndDayOfLastMonth
()
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
set
(
getNowYear
(),
getNowMonth
()
-
2
,
1
);
int
day
=
calendar
.
getActualMaximum
(
5
);
calendar
.
set
(
getNowYear
(),
getNowMonth
()
-
2
,
day
);
return
getDayEndTime
(
calendar
.
getTime
());
}
// 获取本年的开始时间
public
static
Date
getBeginDayOfYear
()
{
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
set
(
Calendar
.
YEAR
,
getNowYear
());
cal
.
set
(
Calendar
.
MONTH
,
Calendar
.
JANUARY
);
cal
.
set
(
Calendar
.
DATE
,
1
);
return
getDayStartTime
(
cal
.
getTime
());
}
// 获取本年的结束时间
public
static
Date
getEndDayOfYear
()
{
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
set
(
Calendar
.
YEAR
,
getNowYear
());
cal
.
set
(
Calendar
.
MONTH
,
Calendar
.
DECEMBER
);
cal
.
set
(
Calendar
.
DATE
,
31
);
return
getDayEndTime
(
cal
.
getTime
());
}
// 获取今年是哪一年
public
static
Integer
getNowYear
()
{
Date
date
=
new
Date
();
GregorianCalendar
gc
=
(
GregorianCalendar
)
Calendar
.
getInstance
();
gc
.
setTime
(
date
);
return
Integer
.
valueOf
(
gc
.
get
(
1
));
}
// 获取本月是哪一月
public
static
int
getNowMonth
()
{
Date
date
=
new
Date
();
GregorianCalendar
gc
=
(
GregorianCalendar
)
Calendar
.
getInstance
();
gc
.
setTime
(
date
);
return
gc
.
get
(
2
)
+
1
;
}
}
src/main/java/io/office/modules/manage/utils/UploadUtils.java
0 → 100644
View file @
ac993fce
package
io
.
office
.
modules
.
manage
.
utils
;
import
com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper
;
import
io.office.common.enumpack.ErrorCodeEnum
;
import
io.office.common.exception.RRException
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.annotation.Resource
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.Date
;
import
java.util.List
;
/**
* TODO
*
* @author wudi
* @version 1.0
* @date 2021/3/19 18:50
*/
@Slf4j
@Component
public
class
UploadUtils
{
@Value
(
"${file.save.path}"
)
private
String
fileSavePath
;
/* @Value("${file.save.type}")
private List fileSaveTypeList;*/
@Value
(
"${file.request.prefix}"
)
private
String
fileRequestPrefix
;
/**
* @param file 上传的文件
* @return
* @描述:上传文件到临时目录
*/
public
String
fileUpload
(
MultipartFile
file
)
{
if
(
file
==
null
)
{
throw
new
RRException
(
ErrorCodeEnum
.
FILE_IS_NULL
);
}
String
filename
=
""
;
//String originalFilename = file.getOriginalFilename();
filename
=
file
.
getOriginalFilename
();
File
fileDir
=
new
File
(
fileSavePath
+
DateUtils
.
formatDateToString
(
new
Date
(),
DateUtils
.
FORMAT4
)
+
"/"
);
if
(!
fileDir
.
exists
())
{
fileDir
.
mkdirs
();
}
String
dateDirPath
=
DateUtils
.
formatDateToString
(
new
Date
(),
DateUtils
.
FORMAT4
);
String
returnFilename
=
fileRequestPrefix
+
dateDirPath
+
"/"
+
filename
;
filename
=
fileSavePath
+
dateDirPath
+
"/"
+
filename
;
File
dest
=
new
File
(
filename
);
try
{
file
.
transferTo
(
dest
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
returnFilename
;
}
/**
* 根据全路径名获取businessId
* "http://10.0.20.46:6051/emgcysys/uploadFile/2021-03-23/1374288822837604352.JAVA核心面试知识整理.pdf",
*/
// public static void main(String[] args) {
// System.out.println(getBusinessIdByFullPath("http://10.0.20.46:6051/emgcysys/uploadFile/2021-03-23" +
// "/1374288822837604352.JAVA核心面试知识整理.pdf"));
// }
}
src/main/resources/application-dev.yml
View file @
ac993fce
...
@@ -47,4 +47,15 @@ spring:
...
@@ -47,4 +47,15 @@ spring:
# username: renren
# username: renren
server
:
server
:
port
:
9091
port
:
9091
# password: 123456
# password: 123456
\ No newline at end of file
#自定义文件上传路径
request
:
upload
:
file
:
prefix
:
uploadFileResource
file
:
save
:
path
:
F:/
request
:
prefix
:
http://localhost:9091/office/uploadFileResource/
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment