Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
attendance-performance-platform
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
赵啸非
attendance-performance-platform
Commits
b78c26c8
Commit
b78c26c8
authored
Jul 15, 2023
by
赵啸非
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加h5钉钉用户授权登录与注册绑定
parent
71bc4695
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
21 deletions
+72
-21
attendance-performance-manager/src/main/java/com/mortals/xhx/busiz/h5/req/DingTalkReq.java
...c/main/java/com/mortals/xhx/busiz/h5/req/DingTalkReq.java
+6
-0
attendance-performance-manager/src/main/java/com/mortals/xhx/busiz/h5/web/DingTalkLoginController.java
...com/mortals/xhx/busiz/h5/web/DingTalkLoginController.java
+62
-21
attendance-performance-manager/src/main/java/com/mortals/xhx/common/key/ErrorCode.java
...r/src/main/java/com/mortals/xhx/common/key/ErrorCode.java
+4
-0
No files found.
attendance-performance-manager/src/main/java/com/mortals/xhx/busiz/h5/req/DingTalkReq.java
View file @
b78c26c8
...
...
@@ -11,4 +11,10 @@ public class DingTalkReq extends BaseReq {
*/
private
String
code
;
private
String
userName
;
private
String
phone
;
private
String
openId
;
}
attendance-performance-manager/src/main/java/com/mortals/xhx/busiz/h5/web/DingTalkLoginController.java
View file @
b78c26c8
...
...
@@ -2,6 +2,7 @@ package com.mortals.xhx.busiz.h5.web;
import
cn.hutool.core.util.IdUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
com.mortals.framework.annotation.UnAuth
;
import
com.mortals.framework.ap.CookieService
;
import
com.mortals.framework.ap.GlobalSysInfo
;
import
com.mortals.framework.ap.SysConstains
;
...
...
@@ -31,6 +32,7 @@ import com.mortals.xhx.module.dept.model.DeptQuery;
import
com.mortals.xhx.module.dept.service.DeptService
;
import
com.mortals.xhx.module.dingding.IDingTalkService
;
import
com.mortals.xhx.module.dingding.personal.service.IDingPersonService
;
import
com.mortals.xhx.module.staff.model.StaffEntity
;
import
com.mortals.xhx.module.staff.model.StaffQuery
;
import
com.mortals.xhx.module.staff.service.StaffService
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -46,8 +48,7 @@ import java.math.BigDecimal;
import
java.util.List
;
import
java.util.Set
;
import
static
com
.
mortals
.
xhx
.
common
.
key
.
ErrorCode
.
ERROR_TOKEN_EXPIRED
;
import
static
com
.
mortals
.
xhx
.
common
.
key
.
ErrorCode
.
ERROR_TOKEN_EXPIRED_CONTENT
;
import
static
com
.
mortals
.
xhx
.
common
.
key
.
ErrorCode
.*;
/**
...
...
@@ -80,18 +81,20 @@ public class DingTalkLoginController extends BaseCRUDJsonBodyMappingController<U
@Autowired
private
DeptService
deptService
;
@Autowired
private
IDingPersonService
dingPersonService
;
@RequestMapping
(
"authlogin"
)
@UnAuth
public
String
login
(
@RequestBody
DingTalkReq
req
)
throws
Exception
{
JSONObject
ret
=
new
JSONObject
();
UserEntity
userEntity
=
null
;
try
{
if
(
ObjectUtils
.
isEmpty
(
req
.
getCode
()))
{
throw
new
AppException
(
"钉钉
code
不能为空!"
);
throw
new
AppException
(
"钉钉
code
不能为空!"
);
}
//根据code 查询钉钉用户id
Rest
<
String
>
personRest
=
dingPersonService
.
getPersonByCode
(
req
.
getCode
());
...
...
@@ -102,15 +105,9 @@ public class DingTalkLoginController extends BaseCRUDJsonBodyMappingController<U
UserQuery
userQuery
=
new
UserQuery
();
userQuery
.
setDingUserId
(
personRest
.
getData
());
userEntity
=
userService
.
selectOne
(
userQuery
);
if
(
ObjectUtils
.
isEmpty
(
userEntity
))
throw
new
AppException
(
"不存在当前匹配的钉钉关联用户!"
);
String
currUserName
=
userEntity
.
getRealName
();
if
(
currUserName
==
null
||
currUserName
.
trim
().
length
()
==
0
)
{
currUserName
=
"管理员"
;
}
if
(
ObjectUtils
.
isEmpty
(
userEntity
))
throw
new
AppException
(
REGISTER_AUTH_FAIL
,
"不存在当前匹配的钉钉关联用户!"
);
JSONObject
data
=
new
JSONObject
();
data
.
put
(
"currUserName"
,
currUserName
);
data
.
put
(
"id"
,
userEntity
.
getId
());
data
.
put
(
"userType"
,
userEntity
.
getUserType
());
userEntity
.
setLoginTime
(
System
.
currentTimeMillis
());
...
...
@@ -136,8 +133,61 @@ public class DingTalkLoginController extends BaseCRUDJsonBodyMappingController<U
}
}
@RequestMapping
(
"register"
)
@UnAuth
public
String
resgister
(
@RequestBody
DingTalkReq
req
)
{
JSONObject
ret
=
new
JSONObject
();
UserEntity
userEntity
=
null
;
try
{
if
(
ObjectUtils
.
isEmpty
(
req
.
getUserName
()))
throw
new
AppException
(
"用户姓名不能为空!"
);
if
(
ObjectUtils
.
isEmpty
(
req
.
getPhone
()))
throw
new
AppException
(
"手机号码不能为空!"
);
if
(
ObjectUtils
.
isEmpty
(
req
.
getOpenId
()))
throw
new
AppException
(
"openId不能为空!"
);
StaffEntity
staffEntity
=
staffService
.
selectOne
(
new
StaffQuery
().
phoneNumber
(
req
.
getPhone
()).
name
(
req
.
getUserName
()));
if
(
ObjectUtils
.
isEmpty
(
staffEntity
))
throw
new
AppException
(
String
.
format
(
"系统未找到当前用户,姓名:%s,手机:%s,请联系管理员!"
,
req
.
getUserName
(),
req
.
getPhone
()));
UserQuery
userQuery
=
new
UserQuery
();
userQuery
.
setCustomerId
(
staffEntity
.
getId
());
userEntity
=
userService
.
selectOne
(
userQuery
);
if
(
ObjectUtils
.
isEmpty
(
userEntity
))
throw
new
AppException
(
String
.
format
(
"员工未与系统用户绑定,staffId:%s"
,
staffEntity
.
getId
()));
userEntity
.
setDingUserId
(
req
.
getOpenId
());
JSONObject
data
=
new
JSONObject
();
data
.
put
(
"id"
,
userEntity
.
getId
());
data
.
put
(
"userType"
,
userEntity
.
getUserType
());
userEntity
.
setLoginTime
(
System
.
currentTimeMillis
());
userEntity
.
setToken
(
IdUtil
.
fastSimpleUUID
());
userEntity
.
setExpireTime
(
DateUtils
.
addCurrDate
(
7
).
getTime
());
String
token
=
authTokenService
.
createToken
(
userEntity
);
data
.
put
(
"token"
,
token
);
ret
.
put
(
KEY_RESULT_DATA
,
data
);
ret
.
put
(
KEY_RESULT_CODE
,
VALUE_RESULT_SUCCESS
);
ret
.
put
(
KEY_RESULT_MSG
,
"钉钉用户登录系统成功!"
);
recordSysLog
(
request
,
userEntity
,
"钉钉用户登录系统成功!"
);
return
ret
.
toJSONString
();
}
catch
(
AppException
e
)
{
log
.
error
(
"dinding register error "
,
e
);
ret
.
put
(
KEY_RESULT_CODE
,
e
.
getCode
());
ret
.
put
(
KEY_RESULT_MSG
,
super
.
convertException
(
e
));
return
ret
.
toJSONString
();
}
catch
(
Exception
e
)
{
log
.
error
(
"系统异常 error "
,
e
);
ret
.
put
(
KEY_RESULT_CODE
,
VALUE_RESULT_FAILURE
);
ret
.
put
(
KEY_RESULT_MSG
,
super
.
convertException
(
e
));
return
ret
.
toJSONString
();
}
}
@RequestMapping
(
"logout"
)
public
void
logout
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
Exception
{
public
void
logout
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
recordSysLog
(
request
,
"退出登录"
);
super
.
removeCurrUser
(
request
);
this
.
deleteBlackCookie
(
request
,
response
);
...
...
@@ -151,13 +201,4 @@ public class DingTalkLoginController extends BaseCRUDJsonBodyMappingController<U
}
@RequestMapping
(
"parseToken"
)
public
IUser
parseToken
()
throws
Exception
{
IUser
userEntity
=
authTokenService
.
getLoginUser
(
request
);
if
(!
ObjectUtils
.
isEmpty
(
userEntity
))
{
authTokenService
.
verifyToken
(
userEntity
);
return
userEntity
;
}
return
null
;
}
}
attendance-performance-manager/src/main/java/com/mortals/xhx/common/key/ErrorCode.java
View file @
b78c26c8
...
...
@@ -112,6 +112,10 @@ public interface ErrorCode {
public
static
final
String
TOKEN_AUTH_FAIL_CONTENT
=
"token认证失败!"
;
public
static
final
int
REGISTER_AUTH_FAIL
=
1011
;
public
static
final
String
REGISTER_AUTH_FAIL_CONTENT
=
"token认证失败!"
;
public
static
final
int
ERROR_TOKEN_EXPIRED
=
9001
;
public
static
final
String
ERROR_TOKEN_EXPIRED_CONTENT
=
"用户登录过期,请重新登录!"
;
public
static
final
int
ERROR_TOKEN_UNAUTHORIZED
=
9002
;
...
...
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