Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
elearn
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
hqzhdj
elearn
Commits
46d3ee7c
Commit
46d3ee7c
authored
Sep 28, 2025
by
Lichen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
初始化接口添加角色查询
parent
9fea2e65
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
19 deletions
+33
-19
cloud-system/src/main/java/com/yizhi/system/application/controller/api/AuthController.java
+33
-19
No files found.
cloud-system/src/main/java/com/yizhi/system/application/controller/api/AuthController.java
View file @
46d3ee7c
...
...
@@ -31,6 +31,7 @@ import com.yizhi.site.application.vo.site.MyItemConfigVO;
import
com.yizhi.system.application.constant.SecurityError
;
import
com.yizhi.system.application.controller.manage.AccountController
;
import
com.yizhi.system.application.domain.Account
;
import
com.yizhi.system.application.domain.AuthzAccountRole
;
import
com.yizhi.system.application.domain.AuthzRole
;
import
com.yizhi.system.application.domain.Site
;
import
com.yizhi.system.application.enums.SecurityReturnCode
;
...
...
@@ -70,6 +71,7 @@ import java.io.UnsupportedEncodingException;
import
java.net.URLEncoder
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
import
java.util.stream.Collectors
;
@Api
(
tags
=
"认证接口"
)
@RestController
...
...
@@ -123,6 +125,9 @@ public class AuthController {
@Autowired
private
EventTrackApiClients
eventTrackApiClients
;
@Autowired
private
IAuthzAccountRoleService
authzAccountRoleService
;
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
AuthController
.
class
);
private
static
final
String
LOGIN_PASSWORD_ERROR_RECORD
=
"login:password:err:times:"
;
...
...
@@ -164,7 +169,7 @@ public class AuthController {
//设置用户信息
setUserInfo
(
user
,
context
,
httpResponse
,
retMap
,
token
);
//设置签到弹框
setEnableSign
(
retMap
,
user
,
context
);
setEnableSign
(
retMap
,
user
,
context
);
//添加登录记录
addLoginRecord
(
user
.
getId
(),
user
.
getCompanyId
(),
context
.
getSiteId
(),
user
.
getOrgId
(),
terminalType
==
null
?
1
:
terminalType
);
//设置最后一次登录站点信息
...
...
@@ -179,7 +184,6 @@ public class AuthController {
}
/**
* 创建token
*
...
...
@@ -230,6 +234,7 @@ public class AuthController {
/**
* 设置用户返回信息
*
* @param retMap
* @param user
* @param token
...
...
@@ -246,11 +251,12 @@ public class AuthController {
/**
* 设置登录后弹出签到
*
* @param retMap
* @param user
* @param context
*/
private
void
setEnableSign
(
Map
<
String
,
Object
>
retMap
,
Account
user
,
RequestContext
context
)
{
private
void
setEnableSign
(
Map
<
String
,
Object
>
retMap
,
Account
user
,
RequestContext
context
)
{
try
{
retMap
.
putAll
(
isEnableSign
(
context
.
getSiteId
(),
user
.
getId
()));
}
catch
(
Exception
e
)
{
...
...
@@ -262,6 +268,7 @@ public class AuthController {
/**
* 添加角色信息
*
* @param retMap
* @param user
*/
...
...
@@ -307,10 +314,10 @@ public class AuthController {
context
.
setAccountId
(
user
.
getId
());
context
.
setOrgId
(
user
.
getOrgId
());
Long
siteId
=
accountService
.
findSiteId
(
user
.
getId
());
if
(
siteId
!=
null
)
{
if
(
siteId
!=
null
)
{
context
.
setSiteId
(
siteId
);
Site
site
=
siteService
.
findById
(
siteId
);
if
(
site
!=
null
)
{
if
(
site
!=
null
)
{
context
.
setSiteCode
(
site
.
getCode
());
}
}
...
...
@@ -327,7 +334,7 @@ public class AuthController {
}
setRetMap
(
retMap
,
user
,
token
,
context
);
//设置签到弹框
setEnableSign
(
retMap
,
user
,
context
);
setEnableSign
(
retMap
,
user
,
context
);
// 添加角色
setAuthInfo
(
retMap
,
user
);
httpResponse
.
addHeader
(
GlobalConstant
.
TOKEN_HEADER
,
token
);
...
...
@@ -336,11 +343,11 @@ public class AuthController {
//登录成功,设置用户选择的语言
languageUtil
.
setStudentSelectLanguage
(
context
,
languageCode
);
if
(
Objects
.
equals
(
terminalType
,
APP
))
{
if
(
Objects
.
equals
(
terminalType
,
APP
))
{
context
.
setSiteType
(
terminalType
);
// 新增登录积分
String
shortDay
=
DateUtil
.
toShortDay
(
new
Date
());
if
(!
redisCache
.
hasKey
(
request
.
getSession
().
getId
()))
{
if
(!
redisCache
.
hasKey
(
request
.
getSession
().
getId
()))
{
pointListenerClients
.
addPoint
(
"point_login"
,
Long
.
valueOf
(
shortDay
));
// 添加登录埋点
eventTrackApiClients
.
addEvent
(
"event_login"
,
context
.
getAccountId
());
...
...
@@ -473,9 +480,9 @@ public class AuthController {
@ApiParam
(
name
=
"user"
)
@RequestBody
@Valid
LoginInfoVO
user
,
BindingResult
validResults
)
{
try
{
boolean
flag
=
accountService
.
validateCaptcha
(
user
.
getCaptchaKey
(),
user
.
getCaptchaVal
());
//图形码验证
}
catch
(
BizException
e
)
{
}
catch
(
BizException
e
)
{
logger
.
warn
(
"验证码校验错误:{}"
+
e
);
return
Response
.
fail
(
e
.
getCode
(),
e
.
getMsg
());
return
Response
.
fail
(
e
.
getCode
(),
e
.
getMsg
());
}
if
(
validResults
.
hasFieldErrors
())
{
String
error
=
ValidUtil
.
convertParamError
(
validResults
.
getFieldErrors
());
...
...
@@ -503,7 +510,7 @@ public class AuthController {
return
Response
.
fail
(
Constants
.
SYSTEM_MSG_ACCOUNT_PWD_ERROR
.
getName
());
}
}
Response
<
String
>
ret
=
login
(
request
,
httpResponse
,
accountName
,
passWord
,
false
,
user
.
getLanguageCode
(),
APP
);
Response
<
String
>
ret
=
login
(
request
,
httpResponse
,
accountName
,
passWord
,
false
,
user
.
getLanguageCode
(),
APP
);
RequestContext
context
=
ContextHolder
.
get
();
if
(
ReturnCode
.
SUCCESS
.
getCode
().
equals
(
ret
.
getCode
()))
{
logger
.
info
(
"手机APP端用户登录上下文="
+
JSON
.
toJSONString
(
ContextHolder
.
get
()));
...
...
@@ -525,7 +532,7 @@ public class AuthController {
@Extension
(
name
=
ReturnCode
.
API_SUB_FLAG
,
properties
=
{
@ExtensionProperty
(
name
=
SecurityError
.
LOGIN_INFO_ERROR
,
value
=
SecurityError
.
LOGIN_INFO_ERROR_MSG
)})})
@RequestMapping
(
value
=
"/loginPc"
,
produces
=
{
"application/json;charset=utf-8"
},
method
=
RequestMethod
.
POST
)
public
Response
<
String
>
loginPc
(
HttpServletRequest
request
,
HttpServletResponse
httpResponse
,
public
Response
<
String
>
loginPc
(
HttpServletRequest
request
,
HttpServletResponse
httpResponse
,
@ApiParam
(
name
=
"user"
)
@RequestBody
@Valid
LoginInfoVO
user
,
BindingResult
validResults
)
{
if
(
validResults
.
hasFieldErrors
())
{
String
error
=
ValidUtil
.
convertParamError
(
validResults
.
getFieldErrors
());
...
...
@@ -549,7 +556,7 @@ public class AuthController {
if
(
null
==
accountName
)
{
return
Response
.
fail
(
Constants
.
SYSTEM_MSG_ACCOUNT_PWD_ERROR
.
getName
());
}
Response
<
String
>
ret
=
login
(
request
,
httpResponse
,
accountName
,
passWord
,
true
,
user
.
getLanguageCode
(),
PC
);
Response
<
String
>
ret
=
login
(
request
,
httpResponse
,
accountName
,
passWord
,
true
,
user
.
getLanguageCode
(),
PC
);
if
(
ReturnCode
.
SUCCESS
.
getCode
().
equals
(
ret
.
getCode
()))
{
RequestContext
rc
=
ContextHolder
.
get
();
logger
.
info
(
"学员pc端用户登录上下文="
+
JSON
.
toJSONString
(
rc
));
...
...
@@ -570,13 +577,13 @@ public class AuthController {
@ExtensionProperty
(
name
=
SecurityError
.
LOGIN_INFO_ERROR
,
value
=
SecurityError
.
LOGIN_INFO_ERROR_MSG
)})})
@RequestMapping
(
value
=
"/loginManage"
,
produces
=
{
"application/json;charset=utf-8"
},
method
=
RequestMethod
.
POST
)
public
Response
<
String
>
loginManage
(
HttpServletRequest
request
,
HttpServletResponse
httpResponse
,
public
Response
<
String
>
loginManage
(
HttpServletRequest
request
,
HttpServletResponse
httpResponse
,
@ApiParam
(
name
=
"user"
)
@RequestBody
@Valid
LoginInfoVO
user
,
BindingResult
validResults
)
{
try
{
boolean
flag
=
accountService
.
validateCaptcha
(
user
.
getCaptchaKey
(),
user
.
getCaptchaVal
());
//图形码验证
}
catch
(
BizException
e
)
{
}
catch
(
BizException
e
)
{
logger
.
warn
(
"验证码校验错误:{}"
+
e
);
return
Response
.
fail
(
e
.
getCode
(),
e
.
getMsg
());
return
Response
.
fail
(
e
.
getCode
(),
e
.
getMsg
());
}
if
(
validResults
.
hasFieldErrors
())
{
String
error
=
ValidUtil
.
convertParamError
(
validResults
.
getFieldErrors
());
...
...
@@ -600,7 +607,7 @@ public class AuthController {
if
(
null
==
accountName
)
{
return
Response
.
fail
(
"4000"
,
InternationalEnums
.
AUTHCONTROLLER2
.
getCode
(),
""
);
}
Response
<
String
>
ret
=
login
(
request
,
httpResponse
,
accountName
,
passWord
,
false
,
user
.
getLanguageCode
(),
MANAGE
);
Response
<
String
>
ret
=
login
(
request
,
httpResponse
,
accountName
,
passWord
,
false
,
user
.
getLanguageCode
(),
MANAGE
);
if
(
ReturnCode
.
SUCCESS
.
getCode
().
equals
(
ret
.
getCode
()))
{
logger
.
info
(
"管理登陆上下文="
+
JSON
.
toJSONString
(
ContextHolder
.
get
()));
...
...
@@ -621,7 +628,7 @@ public class AuthController {
Map
<
String
,
Object
>
rmap
=
(
Map
<
String
,
Object
>)
ret
.
getData
();
//是否只有社群菜单判断
try
{
accountController
.
judgeWhetherIsCommunityManager
(
context
,
accessSites
);
accountController
.
judgeWhetherIsCommunityManager
(
context
,
accessSites
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
logger
.
error
(
"判断社群是否只有管理员异常"
);
...
...
@@ -642,7 +649,7 @@ public class AuthController {
logger
.
warn
(
"参数校验错误:{}"
+
error
);
return
Response
.
fail
(
Constants
.
MSG_REQUEST_ERROR
.
getName
());
}
Response
<
String
>
ret
=
login
(
request
,
httpResponse
,
user
.
getAccount
(),
user
.
getPassword
(),
false
,
user
.
getLanguageCode
(),
WECHAT
);
Response
<
String
>
ret
=
login
(
request
,
httpResponse
,
user
.
getAccount
(),
user
.
getPassword
(),
false
,
user
.
getLanguageCode
(),
WECHAT
);
if
(
ReturnCode
.
SUCCESS
.
getCode
().
equals
(
ret
.
getCode
()))
{
RequestContext
rc
=
ContextHolder
.
get
();
logger
.
info
(
"微信登陆上下文="
+
JSON
.
toJSONString
(
rc
));
...
...
@@ -1237,6 +1244,13 @@ public class AuthController {
if
(
type
!=
null
&&
!
type
.
equals
(
0
))
{
addLoginRecord
(
accountId
,
companyId
,
siteId
,
accountVO
.
getOrgId
(),
Integer
.
valueOf
(
type
));
}
// 根据用户ID集合查询角色集合
List
<
AuthzAccountRole
>
authzAccountRoleList
=
authzAccountRoleService
.
getRoleIdsByAccountIds
(
Collections
.
singletonList
(
accountId
));
// 组装角色ID集合
List
<
Long
>
roleIdList
=
authzAccountRoleList
.
stream
().
map
(
AuthzAccountRole:
:
getRoleId
).
collect
(
Collectors
.
toList
());
// 根据角色ID集合查询角色名称
List
<
AuthzRole
>
authzRoles
=
roleService
.
selectBatchIds
(
roleIdList
);
retMap
.
put
(
"authRole"
,
authzRoles
);
return
Response
.
ok
(
retMap
);
}
else
{
return
Response
.
fail
(
Constants
.
MSG_NOT_SITE_ACCESS_AUTH
.
getCode
().
toString
(),
Constants
.
MSG_NOT_SITE_ACCESS_AUTH
.
getName
());
...
...
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