Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
向汉
/
uc-engine
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
6149fc4c
...
6149fc4c9cf8b0cae7cb1aa64b71f05b9d111649
authored
2022-04-22 00:21:25 +0800
by
xianghan
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
1.手动发放积分时默认过期时间为第二年的最后一天
1 parent
07430150
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
190 additions
and
2 deletions
member-service-impl/src/main/java/com/topdraw/business/process/service/impl/PointsOperationServiceImpl.java
member-service-impl/src/main/java/com/topdraw/util/DateUtil.java
member-service-impl/src/test/java/com/topdraw/test/business/process/rest/PointsOperationControllerTest.java
member-service-impl/src/main/java/com/topdraw/business/process/service/impl/PointsOperationServiceImpl.java
View file @
6149fc4
...
...
@@ -17,11 +17,13 @@ import com.topdraw.business.process.service.dto.CustomPointsResult;
import
com.topdraw.business.process.service.member.MemberOperationService
;
import
com.topdraw.business.process.service.PointsOperationService
;
import
com.topdraw.business.process.domian.TempPoints
;
import
com.topdraw.util.DateUtil
;
import
com.topdraw.util.IdWorker
;
import
com.topdraw.util.TimestampUtil
;
import
com.topdraw.utils.RedisUtils
;
import
com.topdraw.utils.StringUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.time.DateUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.aop.framework.AopContext
;
...
...
@@ -35,6 +37,7 @@ import org.springframework.util.CollectionUtils;
import
java.time.LocalDateTime
;
import
java.util.*
;
import
java.util.concurrent.TimeUnit
;
import
java.util.stream.Collectors
;
/**
...
...
@@ -92,6 +95,7 @@ public class PointsOperationServiceImpl implements PointsOperationService {
@Override
public
void
grantPointsByManualByTempPoints
(
TempPoints
tempPoints
)
{
if
(
Objects
.
nonNull
(
tempPoints
)
&&
Objects
.
nonNull
(
tempPoints
.
getPoints
()))
{
tempPoints
.
setExpireTime
(
DateUtil
.
getLastDateTimeSecondYear
());
this
.
refresh
(
tempPoints
);
}
}
...
...
member-service-impl/src/main/java/com/topdraw/util/DateUtil.java
View file @
6149fc4
package
com
.
topdraw
.
util
;
import
java.time.Instant
;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
import
java.time.ZoneId
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.TimeZone
;
public
class
DateUtil
{
...
...
@@ -13,5 +18,184 @@ public class DateUtil {
return
System
.
currentTimeMillis
();
}
public
static
LocalDateTime
getLastDateTimeCurrentYear
(){
Long
currentTime
=
System
.
currentTimeMillis
();
Long
yearEnd
=
getYearEndTime
(
currentTime
,
"GMT+8:00"
);
LocalDateTime
localDateTime
=
TimestampUtil
.
long2LocalDateTime
(
yearEnd
);
return
localDateTime
;
}
public
static
LocalDateTime
getLastDateTimeSecondYear
(){
int
year
=
LocalDateTime
.
now
().
getYear
()+
1
;
Long
yearEndTime
=
getYearEndTime
(
year
,
"GMT+8:00"
);
LocalDateTime
localDateTime
=
TimestampUtil
.
long2LocalDateTime
(
yearEndTime
);
return
localDateTime
;
}
/**
* 获取指定某一天的开始时间戳
*
* @param timeStamp 毫秒级时间戳
* @param timeZone 如 GMT+8:00
* @return
*/
public
static
Long
getDailyStartTime
(
Long
timeStamp
,
String
timeZone
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTimeZone
(
TimeZone
.
getTimeZone
(
timeZone
));
calendar
.
setTimeInMillis
(
timeStamp
);
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
calendar
.
set
(
Calendar
.
SECOND
,
0
);
calendar
.
set
(
Calendar
.
MINUTE
,
0
);
calendar
.
set
(
Calendar
.
MILLISECOND
,
0
);
return
calendar
.
getTimeInMillis
();
}
/**
* 获取指定某一天的结束时间戳
*
* @param timeStamp 毫秒级时间戳
* @param timeZone 如 GMT+8:00
* @return
*/
public
static
Long
getDailyEndTime
(
Long
timeStamp
,
String
timeZone
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTimeZone
(
TimeZone
.
getTimeZone
(
timeZone
));
calendar
.
setTimeInMillis
(
timeStamp
);
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
23
);
calendar
.
set
(
Calendar
.
MINUTE
,
59
);
calendar
.
set
(
Calendar
.
SECOND
,
59
);
calendar
.
set
(
Calendar
.
MILLISECOND
,
999
);
return
calendar
.
getTimeInMillis
();
}
/**
* 获取当月开始时间戳
*
* @param timeStamp 毫秒级时间戳
* @param timeZone 如 GMT+8:00
* @return
*/
public
static
Long
getMonthStartTime
(
Long
timeStamp
,
String
timeZone
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
// 获取当前日期
calendar
.
setTimeZone
(
TimeZone
.
getTimeZone
(
timeZone
));
calendar
.
setTimeInMillis
(
timeStamp
);
calendar
.
add
(
Calendar
.
YEAR
,
0
);
calendar
.
add
(
Calendar
.
MONTH
,
0
);
calendar
.
set
(
Calendar
.
DAY_OF_MONTH
,
1
);
// 设置为1号,当前日期既为本月第一天
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
calendar
.
set
(
Calendar
.
MINUTE
,
0
);
calendar
.
set
(
Calendar
.
SECOND
,
0
);
calendar
.
set
(
Calendar
.
MILLISECOND
,
0
);
return
calendar
.
getTimeInMillis
();
}
/**
* 获取当月的结束时间戳
*
* @param timeStamp 毫秒级时间戳
* @param timeZone 如 GMT+8:00
* @return
*/
public
static
Long
getMonthEndTime
(
Long
timeStamp
,
String
timeZone
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
// 获取当前日期
calendar
.
setTimeZone
(
TimeZone
.
getTimeZone
(
timeZone
));
calendar
.
setTimeInMillis
(
timeStamp
);
calendar
.
add
(
Calendar
.
YEAR
,
0
);
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
.
MINUTE
,
59
);
calendar
.
set
(
Calendar
.
SECOND
,
59
);
calendar
.
set
(
Calendar
.
MILLISECOND
,
999
);
return
calendar
.
getTimeInMillis
();
}
/**
* 获取当年的开始时间戳
*
* @param timeStamp 毫秒级时间戳
* @param timeZone 如 GMT+8:00
* @return
*/
public
static
Long
getYearStartTime
(
Long
timeStamp
,
String
timeZone
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
// 获取当前日期
calendar
.
setTimeZone
(
TimeZone
.
getTimeZone
(
timeZone
));
calendar
.
setTimeInMillis
(
timeStamp
);
calendar
.
add
(
Calendar
.
YEAR
,
0
);
calendar
.
add
(
Calendar
.
DATE
,
0
);
calendar
.
add
(
Calendar
.
MONTH
,
0
);
calendar
.
set
(
Calendar
.
DAY_OF_YEAR
,
1
);
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
calendar
.
set
(
Calendar
.
MINUTE
,
0
);
calendar
.
set
(
Calendar
.
SECOND
,
0
);
calendar
.
set
(
Calendar
.
MILLISECOND
,
0
);
return
calendar
.
getTimeInMillis
();
}
/**
* 获取当年的最后时间戳
*
* @param timeStamp 毫秒级时间戳
* @param timeZone 如 GMT+8:00
* @return
*/
public
static
Long
getYearEndTime
(
Long
timeStamp
,
String
timeZone
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
// 获取当前日期
calendar
.
setTimeZone
(
TimeZone
.
getTimeZone
(
timeZone
));
calendar
.
setTimeInMillis
(
timeStamp
);
int
year
=
calendar
.
get
(
Calendar
.
YEAR
);
calendar
.
clear
();
calendar
.
set
(
Calendar
.
YEAR
,
year
);
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
23
);
calendar
.
set
(
Calendar
.
MINUTE
,
59
);
calendar
.
set
(
Calendar
.
SECOND
,
59
);
calendar
.
set
(
Calendar
.
MILLISECOND
,
999
);
calendar
.
roll
(
Calendar
.
DAY_OF_YEAR
,
-
1
);
return
calendar
.
getTimeInMillis
();
}
public
static
Long
getYearEndTime
(
int
year
,
String
timeZone
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
// 获取当前日期
calendar
.
setTimeZone
(
TimeZone
.
getTimeZone
(
timeZone
));
calendar
.
clear
();
calendar
.
set
(
Calendar
.
YEAR
,
year
);
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
23
);
calendar
.
set
(
Calendar
.
MINUTE
,
59
);
calendar
.
set
(
Calendar
.
SECOND
,
59
);
calendar
.
set
(
Calendar
.
MILLISECOND
,
000
);
calendar
.
roll
(
Calendar
.
DAY_OF_YEAR
,
-
1
);
return
calendar
.
getTimeInMillis
();
}
/**
* 时间戳转字符串
*
* @param timestamp 毫秒级时间戳
* @param zoneId 如 GMT+8或UTC+08:00
* @return
*/
public
static
String
timestampToStr
(
long
timestamp
,
String
zoneId
)
{
ZoneId
timezone
=
ZoneId
.
of
(
zoneId
);
LocalDateTime
localDateTime
=
LocalDateTime
.
ofInstant
(
Instant
.
ofEpochMilli
(
timestamp
),
timezone
);
return
localDateTime
.
toString
();
}
public
static
void
main
(
String
[]
args
)
{
/*Long currentTime = System.currentTimeMillis();
System.out.println("Current Time : " + currentTime + " = " + timestampToStr(currentTime, "GMT+8"));
Long dailyStart = getDailyStartTime(currentTime, "GMT+8:00");
Long dailyEnd = getDailyEndTime(currentTime, "GMT+8:00");
Long monthStart = getMonthStartTime(currentTime, "GMT+8:00");
Long monthEnd = getMonthEndTime(currentTime, "GMT+8:00");
Long yearStart = getYearStartTime(currentTime, "GMT+8:00");
Long yearEnd = getYearEndTime(currentTime, "GMT+8:00");
System.out.println("Daily Start : " + dailyStart + " = " + timestampToStr(dailyStart, "GMT+8") + " Daily End : " + dailyEnd + " = " + timestampToStr(dailyEnd, "GMT+8"));
System.out.println("Month Start : " + monthStart + " = " + timestampToStr(monthStart, "GMT+8") + " Month End : " + monthEnd + " = " + timestampToStr(monthEnd, "GMT+8"));
System.out.println("Year Start : " + yearStart + " = " + timestampToStr(yearStart, "GMT+8") + " Year End : " + yearEnd + " = " + timestampToStr(yearEnd, "GMT+8"));
*/
LocalDateTime
lastDateTimeCurrentYear
=
getLastDateTimeSecondYear
();
}
}
...
...
member-service-impl/src/test/java/com/topdraw/test/business/process/rest/PointsOperationControllerTest.java
View file @
6149fc4
...
...
@@ -47,8 +47,8 @@ public class PointsOperationControllerTest extends BaseTest {
tempPoints
.
setActivityId
(
null
);
tempPoints
.
setItemId
(
null
);
tempPoints
.
setDescription
(
"系统发放"
);
tempPoints
.
setEvtType
(
1
);
tempPoints
.
setActivityId
(
1L
);
tempPoints
.
setEvtType
(
98
);
//
tempPoints.setActivityId(1L);
String
s
=
JSON
.
toJSONString
(
tempPoints
);
ResultInfo
byId
=
this
.
pointsOperationController
.
addPoints
(
tempPoints
);
LOG
.
info
(
"===>>>"
+
byId
);
...
...
Please
register
or
sign in
to post a comment