Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
8
8timerapiv200
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
8timerv2
8timerapiv200
Commits
08e50bb2
Commit
08e50bb2
authored
Jul 30, 2020
by
leialin
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'lal' into 'develop'
提交二维码登录 See merge request 8timerv2/8timerapiv200!358
parents
b1df5ea9
680a1618
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
175 additions
and
0 deletions
+175
-0
src/main/java/cn/timer/api/controller/LoginController.java
+156
-0
src/main/java/cn/timer/api/dto/yggl/ScancodeloginparametersDto.java
+16
-0
src/main/resources/application-dev.yml
+1
-0
src/main/resources/application-pro.yml
+1
-0
src/main/resources/application-test.yml
+1
-0
No files found.
src/main/java/cn/timer/api/controller/LoginController.java
View file @
08e50bb2
package
cn
.
timer
.
api
.
controller
;
import
java.io.IOException
;
import
java.io.PrintWriter
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
javax.servlet.ServletOutputStream
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpSession
;
import
org.apache.commons.lang3.StringUtils
;
...
...
@@ -56,6 +61,7 @@ import cn.timer.api.config.enums.CommonEnum;
import
cn.timer.api.config.enums.SysRoleType
;
import
cn.timer.api.config.exception.CustomException
;
import
cn.timer.api.controller.jxgl.service.JxglService
;
import
cn.timer.api.controller.kqgl.ClockInTool
;
import
cn.timer.api.controller.qyzx.service.RegisterHelper
;
import
cn.timer.api.controller.spmk.service.SpmkServiceImpl
;
import
cn.timer.api.dao.kqmk.KqglAssoLeaveRulesMapper
;
...
...
@@ -66,6 +72,7 @@ import cn.timer.api.dao.yggl.YgglMainEmpMapper;
import
cn.timer.api.dao.zzgl.ZzglBmgwMMapper
;
import
cn.timer.api.dto.login.QysDto
;
import
cn.timer.api.dto.qyzx.EntRegisterDto
;
import
cn.timer.api.dto.yggl.ScancodeloginparametersDto
;
import
cn.timer.api.utils.Md5
;
import
cn.timer.api.utils.Result
;
import
cn.timer.api.utils.ResultUtil
;
...
...
@@ -880,4 +887,153 @@ public class LoginController {
return
ResultUtil
.
error
(
"绑定失败"
);
}
@Value
(
"${config-8timer.expiration_time}"
)
public
Integer
expiration_time
;
static
SimpleDateFormat
df1
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
//////PC
@PostMapping
(
value
=
"/extracting_code"
)
@ApiOperation
(
value
=
"获取二维码"
,
httpMethod
=
"POST"
,
notes
=
"接口发布说明"
)
public
Result
<
Object
>
Extracting_QR_code
(
HttpServletResponse
response
)
throws
Exception
{
//生成数据块,传给客户端,同时二维码里的内容也是这个数据块
String
timercode
=
String
.
valueOf
(
new
Date
().
getTime
());
String
randomnum
=
String
.
valueOf
((
int
)(
1
+
Math
.
random
()*(
10
-
1
+
1
)));
//随机数
String
key
=
Md5
.
md5
(
timercode
+
randomnum
);
//加密
HashMap
<
String
,
String
>
hashMap
=
new
HashMap
<
String
,
String
>();
hashMap
.
put
(
"type"
,
"longin"
);
hashMap
.
put
(
"scancode"
,
key
);
//转json格式,这里需要用到fastjson包
// String result = JSONObject.fromObject(hashMap).toString();
String
result
=
new
cn
.
hutool
.
json
.
JSONObject
(
hashMap
).
toString
();
//转化为json格式
System
.
out
.
println
(
"全部信息="
+
result
);
//打印json串
session
.
setAttribute
(
key
,
timercode
);
session
.
setAttribute
(
key
+
"_code"
,
"1"
);
// PrintWriter pw = response.getWriter();
ServletOutputStream
pw
=
response
.
getOutputStream
();
pw
.
print
(
result
);
pw
.
flush
();
pw
.
close
();
return
ResultUtil
.
data
(
key
,
"成功"
);
}
@PostMapping
(
value
=
"/scan_code_login"
)
@ApiOperation
(
value
=
"扫码登录"
,
httpMethod
=
"POST"
,
notes
=
"接口发布说明"
)
public
Result
<
QyzxEmpLogin
>
Scan_code_login
(
@CurrentUser
UserBean
userBean
,
@RequestBody
ScancodeloginparametersDto
scancodelogin
,
HttpServletRequest
request
)
throws
ParseException
{
String
current_time
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
).
format
(
new
Date
());
String
timer_code
=
session
.
getAttribute
(
scancodelogin
.
getKey
()+
"_code"
).
toString
();
//扫码状态
String
timercode
=
session
.
getAttribute
(
scancodelogin
.
getKey
()).
toString
();
//扫码时间
timercode
=
ClockInTool
.
stampToDate
(
timercode
);
long
changed_time
=
Long
.
valueOf
(
ClockInTool
.
dateToStamp
(
ClockInTool
.
addtime
(
timercode
,
"+"
+
expiration_time
)));
//key
//计算
//1:没人扫码 2:扫码成功 3:登录成功
Date
sd1
=
df1
.
parse
(
ClockInTool
.
stampToDate
(
String
.
valueOf
(
changed_time
)));
//当天应打的首次上班卡时间
Date
sd2
=
df1
.
parse
(
current_time
);
//当前时间
if
(
sd1
.
after
(
sd2
))
{
if
(
timer_code
.
equals
(
"1"
))
{
return
ResultUtil
.
success
(
"..没人扫码.."
);
}
else
if
(
timer_code
.
equals
(
"2"
))
{
return
ResultUtil
.
success
(
"扫码成功."
);
}
else
if
(
timer_code
.
equals
(
"3"
)){
YgglMainEmp
ygam
=
YgglMainEmp
.
builder
().
build
().
selectOne
(
new
QueryWrapper
<
YgglMainEmp
>().
lambda
().
eq
(
YgglMainEmp:
:
getEmpNum
,
userBean
.
getEmpNum
()).
eq
(
YgglMainEmp:
:
getOrgCode
,
userBean
.
getOrgCode
()));
if
(
ygam
!=
null
)
{
QyzxEmpLogin
qyzxEmpLogin1
=
new
LambdaQueryChainWrapper
<
QyzxEmpLogin
>(
qyzxEmpLoginMapper
)
.
eq
(
QyzxEmpLogin:
:
getPhone
,
ygam
.
getPhone
()).
one
();
if
(
qyzxEmpLogin1
!=
null
)
{
return
loginhan
(
qyzxEmpLogin1
,
request
);
}
else
{
return
ResultUtil
.
error
(
"登录失败"
);
}
}
else
{
return
ResultUtil
.
error
(
"登录有误"
);
}
}
else
{
return
ResultUtil
.
error
(
"验证失败"
);
}
}
else
{
return
ResultUtil
.
error
(
"二维码已过期"
);
}
}
//////APP
@PostMapping
(
value
=
"/scanLogin"
)
@ApiOperation
(
value
=
"手机端扫码登录"
,
httpMethod
=
"POST"
,
notes
=
"接口发布说明"
)
public
Result
<
Object
>
scanLogin
(
@RequestBody
ScancodeloginparametersDto
scancodelogin
)
throws
ParseException
{
String
current_time
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
).
format
(
new
Date
());
if
(
scancodelogin
.
getKey
()
!=
null
)
{
String
timercode
=
session
.
getAttribute
(
scancodelogin
.
getKey
()).
toString
();
//扫码时间
timercode
=
ClockInTool
.
stampToDate
(
timercode
);
long
changed_time
=
Long
.
valueOf
(
ClockInTool
.
dateToStamp
(
ClockInTool
.
addtime
(
timercode
,
"+"
+
expiration_time
)));
Date
sd1
=
df1
.
parse
(
ClockInTool
.
stampToDate
(
String
.
valueOf
(
changed_time
)));
//当天应打的首次上班卡时间
Date
sd2
=
df1
.
parse
(
current_time
);
//当前时间
if
(
sd1
.
after
(
sd2
))
{
session
.
setAttribute
(
scancodelogin
.
getKey
()+
"_code"
,
"2"
);
return
ResultUtil
.
success
(
"扫码成功"
);
}
else
{
return
ResultUtil
.
error
(
"二维码已过期"
);
}
}
else
{
return
ResultUtil
.
error
(
"验证失败"
);
}
}
@PostMapping
(
value
=
"/scanLoginOk"
)
@ApiOperation
(
value
=
"手机端扫码登录确认"
,
httpMethod
=
"POST"
,
notes
=
"接口发布说明"
)
public
Result
<
QyzxEmpLogin
>
scanLoginOk
(
@CurrentUser
UserBean
userBean
,
@RequestBody
ScancodeloginparametersDto
scancodelogin
,
HttpServletRequest
request
)
throws
ParseException
{
String
current_time
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
).
format
(
new
Date
());
if
(
scancodelogin
.
getKey
()
!=
null
)
{
String
timercode
=
session
.
getAttribute
(
scancodelogin
.
getKey
()).
toString
();
//扫码时间
timercode
=
ClockInTool
.
stampToDate
(
timercode
);
long
changed_time
=
Long
.
valueOf
(
ClockInTool
.
dateToStamp
(
ClockInTool
.
addtime
(
timercode
,
"+"
+
expiration_time
)));
Date
sd1
=
df1
.
parse
(
ClockInTool
.
stampToDate
(
String
.
valueOf
(
changed_time
)));
//当天应打的首次上班卡时间
Date
sd2
=
df1
.
parse
(
current_time
);
//当前时间
if
(
sd1
.
after
(
sd2
))
{
session
.
setAttribute
(
scancodelogin
.
getKey
()+
"_code"
,
"3"
);
YgglMainEmp
ygam
=
YgglMainEmp
.
builder
().
build
().
selectOne
(
new
QueryWrapper
<
YgglMainEmp
>().
lambda
().
eq
(
YgglMainEmp:
:
getEmpNum
,
userBean
.
getEmpNum
()).
eq
(
YgglMainEmp:
:
getOrgCode
,
userBean
.
getOrgCode
()));
if
(
ygam
!=
null
)
{
QyzxEmpLogin
qyzxEmpLogin1
=
new
LambdaQueryChainWrapper
<
QyzxEmpLogin
>(
qyzxEmpLoginMapper
)
.
eq
(
QyzxEmpLogin:
:
getPhone
,
ygam
.
getPhone
()).
one
();
if
(
qyzxEmpLogin1
!=
null
)
{
return
loginhan
(
qyzxEmpLogin1
,
request
);
}
else
{
return
ResultUtil
.
error
(
"登录失败"
);
}
}
else
{
return
ResultUtil
.
error
(
"登录有误"
);
}
}
else
{
return
ResultUtil
.
error
(
"二维码已过期"
);
}
}
else
{
return
ResultUtil
.
error
(
"验证失败"
);
}
}
}
src/main/java/cn/timer/api/dto/yggl/ScancodeloginparametersDto.java
0 → 100644
View file @
08e50bb2
package
cn
.
timer
.
api
.
dto
.
yggl
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public
class
ScancodeloginparametersDto
{
private
String
key
;
}
src/main/resources/application-dev.yml
View file @
08e50bb2
...
...
@@ -171,6 +171,7 @@ logging:
# operations-sorter: method # 它提供了两个配置项:alpha和method,分别代表了按字母表排序以及按方法定义顺序排序
config-8timer
:
expiration_time
:
2
#扫码登录过期时长
machine8timerUrl
:
'
http://test-8timer-fk.youlingrc.com'
#machine8timerUrl: 'http://192.168.3.38:8088'
authentication-code
:
'
888888'
...
...
src/main/resources/application-pro.yml
View file @
08e50bb2
...
...
@@ -146,6 +146,7 @@ logging:
# operations-sorter: method # 它提供了两个配置项:alpha和method,分别代表了按字母表排序以及按方法定义顺序排序
config-8timer
:
expiration_time
:
2
#扫码登录过期时长
machine8timerUrl
:
'
http://test-8timer-fk.youlingrc.com'
#machine8timerUrl: 'http://192.168.3.38:8088'
authentication-code
:
'
'
...
...
src/main/resources/application-test.yml
View file @
08e50bb2
...
...
@@ -145,6 +145,7 @@ logging:
# operations-sorter: method # 它提供了两个配置项:alpha和method,分别代表了按字母表排序以及按方法定义顺序排序
config-8timer
:
expiration_time
:
2
#扫码登录过期时长
machine8timerUrl
:
'
http://test-8timer-fk.youlingrc.com'
#machine8timerUrl: 'http://192.168.3.38:8088'
authentication-code
:
'
888888'
...
...
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