Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
wangming
/
kzy-wx
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 670aec9d
authored
Mar 13, 2020
by
魏文甫
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'wei_master' into '105'
update See merge request
!11
2 parents
c7508fad
5736145d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
237 additions
and
17 deletions
src/main/java/com/server/utils/DateUtils.java
src/main/java/com/server/web/common/service/Impl/UserServiceImpl.java
src/main/java/com/server/utils/DateUtils.java
0 → 100644
View file @
670aec9
package
com
.
server
.
utils
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.TimeZone
;
/**
* @author ZMS
*/
public
class
DateUtils
{
public
static
long
MINUTE_PER_HOUR
=
60
;
// 一个小时有多少分钟
public
static
long
MINUTE_PER_DAY
=
1440
;
// 一天有多少分钟
public
static
long
HOUT_PER_DAY
=
24
;
// 一天有多少小时
public
static
long
SECOND_PER_MINUTE
=
60
;
// 一分钟有多少秒
public
static
long
SECOND_PER_HOUR
=
3600
;
// 一个小时有多少秒
public
static
long
SECOND_PER_DAY
=
86400
;
// 一天有多少秒
public
static
long
MILLIS_PER_SECOND
=
1000
;
// 一秒钟有多少毫秒
public
static
long
MILLIS_PER_MINUTE
=
60000
;
// 一分钟有多少毫秒
public
static
long
MILLIS_PER_HOUR
=
3600000
;
// 一个小时有多少毫秒
public
static
long
MILLIS_PER_DAY
=
86400000
;
// 一天有多少毫秒
public
static
long
NANO_PER_MILLIS
=
1000000
;
// 一毫秒有多少纳秒
/**
* formate date
*
* @param formatter
* @param time
* @return
*/
public
static
String
format
(
String
formatter
,
long
time
)
{
return
new
SimpleDateFormat
(
formatter
).
format
(
new
Date
(
time
));
}
public
static
String
format
(
String
formatter
,
Date
time
)
{
return
new
SimpleDateFormat
(
formatter
).
format
(
time
);
}
public
static
String
format
(
Date
time
)
{
return
new
SimpleDateFormat
(
"yyyy-MM-dd"
).
format
(
time
);
}
/**
* rawoffset
*
* @param time
* @return
*/
public
static
long
getRawOffsetMils
(
long
time
)
{
return
time
+
TimeZone
.
getDefault
().
getRawOffset
();
}
/**
* 拆分时间
*
* @param timeMils
* @return
*/
public
static
long
[]
splitTime
(
long
timeMils
)
{
if
(
timeMils
<=
0
)
{
return
new
long
[]{
0
,
0
,
0
,
0
};
}
long
day
=
timeMils
/
86400000
;
long
hour
=
(
timeMils
%
86400000
)
/
3600000
;
long
min
=
(
timeMils
%
3600000
)
/
60000
;
long
sec
=
(
timeMils
%
60000
)
/
1000
;
return
new
long
[]{
day
,
hour
,
min
,
sec
};
}
public
static
Date
parse
(
String
format
,
String
str
)
throws
ParseException
{
return
new
SimpleDateFormat
(
format
).
parse
(
str
);
}
public
static
Date
firstDayOfMonth
()
{
Calendar
c
=
Calendar
.
getInstance
();
c
.
set
(
Calendar
.
DAY_OF_MONTH
,
1
);
c
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
c
.
set
(
Calendar
.
MINUTE
,
0
);
c
.
set
(
Calendar
.
SECOND
,
0
);
c
.
set
(
Calendar
.
MILLISECOND
,
0
);
return
c
.
getTime
();
}
public
static
Date
lastDayOfMonth
()
{
Calendar
c
=
Calendar
.
getInstance
();
c
.
set
(
Calendar
.
DAY_OF_MONTH
,
c
.
getActualMaximum
(
Calendar
.
DAY_OF_MONTH
));
c
.
set
(
Calendar
.
HOUR_OF_DAY
,
c
.
getMaximum
(
Calendar
.
HOUR_OF_DAY
));
c
.
set
(
Calendar
.
MINUTE
,
c
.
getMaximum
(
Calendar
.
MINUTE
));
c
.
set
(
Calendar
.
SECOND
,
c
.
getMaximum
(
Calendar
.
SECOND
));
c
.
set
(
Calendar
.
MILLISECOND
,
c
.
getMaximum
(
Calendar
.
MILLISECOND
));
return
c
.
getTime
();
}
public
static
Date
firstDayOfMonth
(
int
year
,
int
month
)
{
Calendar
c
=
Calendar
.
getInstance
();
c
.
set
(
Calendar
.
YEAR
,
year
);
c
.
set
(
Calendar
.
MONTH
,
month
);
c
.
set
(
Calendar
.
DAY_OF_MONTH
,
1
);
c
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
c
.
set
(
Calendar
.
MINUTE
,
0
);
c
.
set
(
Calendar
.
SECOND
,
0
);
c
.
set
(
Calendar
.
MILLISECOND
,
0
);
return
c
.
getTime
();
}
public
static
Date
lastDayOfMonth
(
int
year
,
int
month
)
{
Calendar
c
=
Calendar
.
getInstance
();
c
.
set
(
Calendar
.
YEAR
,
year
);
c
.
set
(
Calendar
.
MONTH
,
month
);
c
.
set
(
Calendar
.
DAY_OF_MONTH
,
c
.
getActualMaximum
(
Calendar
.
DAY_OF_MONTH
));
c
.
set
(
Calendar
.
HOUR_OF_DAY
,
c
.
getMaximum
(
Calendar
.
HOUR_OF_DAY
));
c
.
set
(
Calendar
.
MINUTE
,
c
.
getMaximum
(
Calendar
.
MINUTE
));
c
.
set
(
Calendar
.
SECOND
,
c
.
getMaximum
(
Calendar
.
SECOND
));
c
.
set
(
Calendar
.
MILLISECOND
,
c
.
getMaximum
(
Calendar
.
MILLISECOND
));
return
c
.
getTime
();
}
public
static
int
getMonthDayCount
(
int
year
,
int
month
)
{
Calendar
c
=
Calendar
.
getInstance
();
c
.
set
(
Calendar
.
YEAR
,
year
);
c
.
set
(
Calendar
.
MONTH
,
month
);
return
c
.
getActualMaximum
(
Calendar
.
DAY_OF_MONTH
);
}
public
static
long
getStartTimeOfDate
(
long
time
)
{
Calendar
c
=
Calendar
.
getInstance
();
c
.
setTimeInMillis
(
time
);
c
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
c
.
set
(
Calendar
.
MINUTE
,
0
);
c
.
set
(
Calendar
.
SECOND
,
0
);
c
.
set
(
Calendar
.
MILLISECOND
,
0
);
return
c
.
getTimeInMillis
();
}
public
static
long
curDay
()
{
return
getRawOffsetMils
(
System
.
currentTimeMillis
())
/
MILLIS_PER_DAY
;
}
public
static
long
curHour
()
{
return
getRawOffsetMils
(
System
.
currentTimeMillis
())
/
MILLIS_PER_HOUR
;
}
public
static
long
curMinute
()
{
return
getRawOffsetMils
(
System
.
currentTimeMillis
())
/
MILLIS_PER_MINUTE
;
}
/**
* 时间比较(如果myDate>compareDate返回1,<返回-1,相等返回0)
*
* @param myDate 时间
* @param compareDate 要比较的时间
* @return int
*/
public
static
int
dateCompare
(
Date
myDate
,
Date
compareDate
)
{
Calendar
myCal
=
Calendar
.
getInstance
();
Calendar
compareCal
=
Calendar
.
getInstance
();
myCal
.
setTime
(
myDate
);
compareCal
.
setTime
(
compareDate
);
return
myCal
.
compareTo
(
compareCal
);
}
/**
* 时间加减天数
*
* @param startDate 要处理的时间,Null则为当前时间
* @param days 加减的天数
* @return Date
*/
public
static
Date
dateAddDays
(
Date
startDate
,
int
days
)
{
if
(
startDate
==
null
)
{
startDate
=
new
Date
();
}
Calendar
c
=
Calendar
.
getInstance
();
c
.
setTime
(
startDate
);
c
.
set
(
Calendar
.
DATE
,
c
.
get
(
Calendar
.
DATE
)
+
days
);
return
c
.
getTime
();
}
public
static
int
dateCompare
(
String
myDate
,
String
compareDate
,
String
dateformat
)
{
Date
myDate2
=
null
;
Date
compareDate2
=
null
;
try
{
myDate2
=
new
SimpleDateFormat
(
dateformat
).
parse
(
myDate
);
compareDate2
=
new
SimpleDateFormat
(
dateformat
).
parse
(
compareDate
);
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
Calendar
myCal
=
Calendar
.
getInstance
();
Calendar
compareCal
=
Calendar
.
getInstance
();
myCal
.
setTime
(
myDate2
);
compareCal
.
setTime
(
compareDate2
);
return
myCal
.
compareTo
(
compareCal
);
}
public
static
void
main
(
String
[]
args
)
{
}
}
src/main/java/com/server/web/common/service/Impl/UserServiceImpl.java
View file @
670aec9
package
com
.
server
.
web
.
common
.
service
.
Impl
;
package
com
.
server
.
web
.
common
.
service
.
Impl
;
import
com.server.utils.DateUtils
;
import
com.server.utils.ResultMapUtil
;
import
com.server.utils.ResultMapUtil
;
import
com.server.web.common.mapper.TKzyUserIntegralFlowingMapper
;
import
com.server.web.common.mapper.TKzyUserIntegralFlowingMapper
;
import
com.server.web.common.mapper.TKzyUserMapper
;
import
com.server.web.common.mapper.TKzyUserMapper
;
...
@@ -33,6 +34,12 @@ public class UserServiceImpl implements UserService {
...
@@ -33,6 +34,12 @@ public class UserServiceImpl implements UserService {
}
}
public
static
void
main
(
String
[]
args
)
{
Date
last
=
DateUtils
.
firstDayOfMonth
();
System
.
out
.
println
(
last
);
}
@Override
@Override
public
Map
signIn
(
TKzyUser
loginUser
)
{
public
Map
signIn
(
TKzyUser
loginUser
)
{
if
(
loginUser
==
null
||
loginUser
.
getId
()
==
null
)
{
if
(
loginUser
==
null
||
loginUser
.
getId
()
==
null
)
{
...
@@ -42,6 +49,7 @@ public class UserServiceImpl implements UserService {
...
@@ -42,6 +49,7 @@ public class UserServiceImpl implements UserService {
if
(
loginUser
.
getLastSignDt
()
!=
null
&&
simpleDateFormat
.
format
(
loginUser
.
getLastSignDt
()).
equals
(
simpleDateFormat
.
format
(
new
Date
())))
{
if
(
loginUser
.
getLastSignDt
()
!=
null
&&
simpleDateFormat
.
format
(
loginUser
.
getLastSignDt
()).
equals
(
simpleDateFormat
.
format
(
new
Date
())))
{
return
ResultMapUtil
.
returnMap
(
"0"
,
"您已签到!"
,
null
);
return
ResultMapUtil
.
returnMap
(
"0"
,
"您已签到!"
,
null
);
}
}
TKzyUserIntegralFlowing
tKzyUserIntegralFlowing
=
new
TKzyUserIntegralFlowing
();
TKzyUserIntegralFlowing
tKzyUserIntegralFlowing
=
new
TKzyUserIntegralFlowing
();
tKzyUserIntegralFlowing
.
setCreateDt
(
new
Date
());
tKzyUserIntegralFlowing
.
setCreateDt
(
new
Date
());
tKzyUserIntegralFlowing
.
setSourceType
(
1
);
tKzyUserIntegralFlowing
.
setSourceType
(
1
);
...
@@ -53,26 +61,33 @@ public class UserServiceImpl implements UserService {
...
@@ -53,26 +61,33 @@ public class UserServiceImpl implements UserService {
if
(
loginUser
.
getSignInCount
()
==
null
)
{
if
(
loginUser
.
getSignInCount
()
==
null
)
{
loginUser
.
setSignInCount
(
0
);
loginUser
.
setSignInCount
(
0
);
}
}
if
(
loginUser
.
getSignInCount
()
<=
2
)
{
String
firstDay
=
simpleDateFormat
.
format
(
DateUtils
.
firstDayOfMonth
());
if
(
firstDay
.
equals
(
simpleDateFormat
.
format
(
new
Date
())))
{
loginUser
.
setIntegral
(
loginUser
.
getIntegral
()
+
1
);
loginUser
.
setIntegral
(
loginUser
.
getIntegral
()
+
1
);
loginUser
.
setSignInCount
(
loginUser
.
getSignInCount
()
+
1
);
tKzyUserIntegralFlowing
.
setIntegral
(
1
);
}
else
if
(
loginUser
.
getSignInCount
()
==
3
)
{
loginUser
.
setIntegral
(
loginUser
.
getIntegral
()
+
3
);
loginUser
.
setSignInCount
(
loginUser
.
getSignInCount
()
+
1
);
tKzyUserIntegralFlowing
.
setIntegral
(
3
);
}
else
if
(
loginUser
.
getSignInCount
()
==
4
)
{
loginUser
.
setIntegral
(
loginUser
.
getIntegral
()
+
3
);
loginUser
.
setSignInCount
(
loginUser
.
getSignInCount
()
+
1
);
tKzyUserIntegralFlowing
.
setIntegral
(
1
);
}
else
if
(
loginUser
.
getSignInCount
()
==
5
)
{
loginUser
.
setIntegral
(
loginUser
.
getIntegral
()
+
5
);
loginUser
.
setSignInCount
(
1
);
tKzyUserIntegralFlowing
.
setIntegral
(
5
);
}
else
{
loginUser
.
setIntegral
(
1
);
loginUser
.
setSignInCount
(
1
);
loginUser
.
setSignInCount
(
1
);
tKzyUserIntegralFlowing
.
setIntegral
(
1
);
tKzyUserIntegralFlowing
.
setIntegral
(
1
);
}
else
{
if
(
loginUser
.
getSignInCount
()
<=
2
)
{
loginUser
.
setIntegral
(
loginUser
.
getIntegral
()
+
1
);
loginUser
.
setSignInCount
(
loginUser
.
getSignInCount
()
+
1
);
tKzyUserIntegralFlowing
.
setIntegral
(
1
);
}
else
if
(
loginUser
.
getSignInCount
()
==
3
)
{
loginUser
.
setIntegral
(
loginUser
.
getIntegral
()
+
3
);
loginUser
.
setSignInCount
(
loginUser
.
getSignInCount
()
+
1
);
tKzyUserIntegralFlowing
.
setIntegral
(
3
);
}
else
if
(
loginUser
.
getSignInCount
()
==
4
)
{
loginUser
.
setIntegral
(
loginUser
.
getIntegral
()
+
3
);
loginUser
.
setSignInCount
(
loginUser
.
getSignInCount
()
+
1
);
tKzyUserIntegralFlowing
.
setIntegral
(
1
);
}
else
if
(
loginUser
.
getSignInCount
()
==
5
)
{
loginUser
.
setIntegral
(
loginUser
.
getIntegral
()
+
5
);
loginUser
.
setSignInCount
(
1
);
tKzyUserIntegralFlowing
.
setIntegral
(
5
);
}
else
{
loginUser
.
setIntegral
(
1
);
loginUser
.
setSignInCount
(
1
);
tKzyUserIntegralFlowing
.
setIntegral
(
1
);
}
}
}
loginUser
.
setLastSignDt
(
new
Date
());
loginUser
.
setLastSignDt
(
new
Date
());
tKzyUserMapper
.
updateByPrimaryKeySelective
(
loginUser
);
tKzyUserMapper
.
updateByPrimaryKeySelective
(
loginUser
);
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment