Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
haoban-manage3.0
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
haoban3.0
haoban-manage3.0
Commits
d6097a4e
Commit
d6097a4e
authored
May 09, 2022
by
徐高华
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
login
parent
aef43022
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
96 additions
and
26 deletions
+96
-26
LoginController.java
...com/gic/haoban/manage/web/controller/LoginController.java
+96
-26
No files found.
haoban-manage3-web/src/main/java/com/gic/haoban/manage/web/controller/LoginController.java
View file @
d6097a4e
...
...
@@ -16,6 +16,7 @@ import com.gic.haoban.common.anno.IgnoreLogin;
import
com.gic.haoban.common.utils.AuthWebRequestUtil
;
import
com.gic.haoban.common.utils.EntityUtil
;
import
com.gic.haoban.common.utils.HaobanResponse
;
import
com.gic.haoban.manage.api.dto.EnterpriseDetailDTO
;
import
com.gic.haoban.manage.api.dto.LoginDTO
;
import
com.gic.haoban.manage.api.dto.StaffDTO
;
import
com.gic.haoban.manage.api.dto.WxApplicationDTO
;
...
...
@@ -143,36 +144,26 @@ public class LoginController extends WebBaseController {
*/
@IgnoreLogin
@RequestMapping
(
"yw-login"
)
public
HaobanResponse
ywLogin
(
String
wxEnterpriseId
,
String
random
,
HttpServletResponse
response
)
{
public
HaobanResponse
ywLogin
(
String
enterpriseId
,
String
wxEnterpriseId
,
String
random
,
HttpServletResponse
response
)
{
//判断是否存在random
Object
o
=
RedisUtil
.
getCache
(
random
);
if
(
o
==
null
)
{
return
resultResponse
(
HaoBanErrCode
.
ERR_4
);
}
StaffDTO
staff
=
staffApiService
.
getAndAddSupperAdmin
(
wxEnterpriseId
);
if
(
staff
==
null
)
{
logger
.
info
(
"运维登录超级管理员不存在"
);
return
resultResponse
(
HaoBanErrCode
.
ERR_6
);
if
(
StringUtils
.
isBlank
(
enterpriseId
))
{
List
<
EnterpriseDetailDTO
>
list
=
this
.
wxEnterpriseRelatedApiService
.
listEnterpriseByWxEnterpriseId
(
wxEnterpriseId
)
;
if
(
CollectionUtils
.
isEmpty
(
list
))
{
return
resultResponse
(
HaoBanErrCode
.
ERR_4
);
}
enterpriseId
=
list
.
get
(
0
).
getEnterpriseId
()
;
}
LoginDTO
loginVO
=
new
LoginDTO
();
loginVO
.
setWxEnterpriseId
(
wxEnterpriseId
);
loginVO
.
setStaffDTO
(
staff
);
WebLoginDTO
webLoginDTO
=
EntityUtil
.
changeEntityByOrika
(
WebLoginDTO
.
class
,
loginVO
);
AuthWebRequestUtil
.
setSessionUser
(
webLoginDTO
);
String
redirectUri
=
config
.
getHost
()
+
"index"
;
redirectUri
=
redirectUri
.
replace
(
"haoban-manage3-web"
,
"haoban-3/#"
);
String
token
=
ToolUtil
.
randomUUID
()
+
"-"
+
ToolUtil
.
randomStringByTime
();
AuthWebRequestUtil
.
setAppLoginUser
(
token
,
webLoginDTO
);
try
{
Cookie
cookie
=
new
Cookie
(
"token"
,
token
);
cookie
.
setPath
(
"/"
);
response
.
addCookie
(
cookie
);
response
.
sendRedirect
(
redirectUri
);
response
.
setHeader
(
"token"
,
token
);
}
catch
(
IOException
e
)
{
logger
.
error
(
"好办登录失败"
,
e
);
String
gicSuperPhone
=
clerkService
.
getSuperAdminPhoneNumber
(
enterpriseId
)
;
logger
.
info
(
"登录商户id={},超管手机={}"
,
enterpriseId
,
gicSuperPhone
);
String
result
=
this
.
doLogin
(
wxEnterpriseId
,
enterpriseId
,
gicSuperPhone
,
response
)
;
if
(
StringUtils
.
isNotBlank
(
result
))
{
return
resultResponse
(
HaoBanErrCode
.
ERR_4
);
}
return
resultResponse
(
HaoBanErrCode
.
ERR_1
)
;
return
null
;
}
/**
...
...
@@ -211,8 +202,14 @@ public class LoginController extends WebBaseController {
ModelAndView
model
=
new
ModelAndView
(
new
RedirectView
(
"/haoban-3/#/gic-error"
,
false
,
false
));
return
model
;
}
StaffDTO
staff
=
staffApiService
.
selectByNationcodeAndPhoneNumber
(
detailDTO
.
getWxEnterpriseId
(),
"86"
,
loginPhoneNumber
);
String
result
=
this
.
doLogin
(
wxEnterpriseId
,
gicEnterpriseId
,
loginPhoneNumber
,
response
)
;
if
(
StringUtils
.
isNotBlank
(
result
))
{
ModelAndView
model
=
new
ModelAndView
(
new
RedirectView
(
"/haoban-3/#/gic-error"
,
false
,
false
));
return
model
;
}
/* StaffDTO staff = staffApiService.selectByNationcodeAndPhoneNumber(detailDTO.getWxEnterpriseId(), "86", loginPhoneNumber);
if (null == staff) {
logger.info("登录用户手机号不存在!gicEnterpriseId:{}", gicEnterpriseId);
ModelAndView model = new ModelAndView(new RedirectView("/haoban-3/#/gic-error", false, false));
...
...
@@ -281,10 +278,83 @@ public class LoginController extends WebBaseController {
response.setHeader("token", token);
} catch (IOException e) {
e.printStackTrace();
}
}
*/
return
null
;
}
private
String
doLogin
(
String
wxEnterpriseId
,
String
gicEnterpriseId
,
String
loginPhoneNumber
,
HttpServletResponse
response
)
{
StaffDTO
staff
=
staffApiService
.
selectByNationcodeAndPhoneNumber
(
wxEnterpriseId
,
"86"
,
loginPhoneNumber
);
if
(
null
==
staff
)
{
logger
.
info
(
"登录用户手机号不存在!gicEnterpriseId:{}"
,
gicEnterpriseId
);
return
"登录用户手机号不存在"
;
}
WxApplicationDTO
application
=
wxApplicationApiService
.
selectByWxEnterpriseIdAndApplicationType
(
wxEnterpriseId
,
2
);
if
(
null
==
application
)
{
logger
.
info
(
"登录企业应用 没授权!gicEnterpriseId:{}"
,
gicEnterpriseId
);
return
"登录企业应用 没授权"
;
}
WxEnterpriseDTO
enterprise
=
wxEnterpriseApiService
.
getOne
(
wxEnterpriseId
);
if
(
null
==
enterprise
)
{
logger
.
info
(
"登录失败,不存在对应企业:wxEnterpriseId{}"
,
wxEnterpriseId
);
return
"登录失败,不存在对应企业"
;
}
//获取管理员列表
String
corpid
=
enterprise
.
getCorpid
();
String
adminList
=
qywxSuiteApiService
.
getAdminList
(
corpid
,
application
.
getSiteId
(),
Integer
.
parseInt
(
application
.
getAgentId
()));
List
<
String
>
userIds
=
new
ArrayList
<
String
>();
if
(
StringUtils
.
isNotBlank
(
adminList
))
{
JSONArray
jsonArr
=
JSON
.
parseArray
(
adminList
);
for
(
Object
object
:
jsonArr
)
{
JSONObject
json
=
JSON
.
parseObject
(
JSON
.
toJSONString
(
object
));
userIds
.
add
(
json
.
getString
(
"userid"
));
}
}
//兼容
if
(
corpid
.
length
()
>
20
)
{
if
(!
userIds
.
contains
(
staff
.
getWxOpenUseId
()))
{
logger
.
info
(
"登录失败,当前用户不是管理员:{}"
,
JSON
.
toJSONString
(
userIds
));
return
"登录失败,当前用户不是管理员"
;
}
}
else
{
if
(!
userIds
.
contains
(
staff
.
getWxUserId
()))
{
logger
.
info
(
"登录失败,当前用户不是管理员:{}"
,
JSON
.
toJSONString
(
userIds
));
return
"登录失败,当前用户不是管理员"
;
}
}
LoginDTO
loginDTO
=
new
LoginDTO
();
loginDTO
.
setWxEnterpriseId
(
wxEnterpriseId
);
loginDTO
.
setEnterpriseId
(
gicEnterpriseId
);
//导购id
ClerkDTO
clerk
=
clerkService
.
getClerkByPhoneNumber
(
loginPhoneNumber
,
gicEnterpriseId
);
if
(
clerk
!=
null
)
{
staff
.
setClerkId
(
clerk
.
getClerkId
());
staff
.
setClerkName
(
clerk
.
getClerkName
());
staff
.
setClerkCode
(
clerk
.
getClerkCode
());
}
loginDTO
.
setStaffDTO
(
staff
);
String
redirectUri
=
config
.
getHost
()
+
"index"
;
redirectUri
=
redirectUri
.
replace
(
"haoban-manage3-web"
,
"haoban-3/#"
);
String
token
=
ToolUtil
.
randomUUID
()
+
"-"
+
ToolUtil
.
randomStringByTime
();
WebLoginDTO
webLoginDTO
=
EntityUtil
.
changeEntityByOrika
(
WebLoginDTO
.
class
,
loginDTO
);
AuthWebRequestUtil
.
setSessionUser
(
webLoginDTO
);
AuthWebRequestUtil
.
setAppLoginUser
(
token
,
webLoginDTO
);
try
{
Cookie
cookie
=
new
Cookie
(
"token"
,
token
);
cookie
.
setPath
(
"/"
);
response
.
addCookie
(
cookie
);
response
.
sendRedirect
(
redirectUri
);
response
.
setHeader
(
"token"
,
token
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
@RequestMapping
(
"login_local"
)
@Deprecated
...
...
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