Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
江名洋
/
linkwe-scrm
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 8b506f47
authored
Apr 13, 2021
by
水库浪子
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
多租户登录代码提交
1 parent
6c28ff99
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
78 additions
and
68 deletions
linkwe-admin/src/main/java/com/linkwechat/web/controller/system/SysLoginController.java
linkwe-admin/src/main/resources/bootstrap.properties
linkwe-framework/src/main/java/com/linkwechat/framework/config/MyBatisPlusConfig.java
linkwe-framework/src/main/java/com/linkwechat/framework/web/service/UserDetailsServiceImpl.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/IWeAccessTokenService.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeAccessTokenServiceImpl.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeCorpAccountServiceImpl.java
linkwe-admin/src/main/java/com/linkwechat/web/controller/system/SysLoginController.java
View file @
8b506f4
...
...
@@ -93,12 +93,14 @@ public class SysLoginController
Set
<
String
>
roles
=
permissionService
.
getRolePermission
(
user
);
// 权限集合
Set
<
String
>
permissions
=
permissionService
.
getMenuPermission
(
user
);
//校验用户是否拥有可用corpid
WeCorpAccount
wxCorpAccount
=
iWxCorpAccountService
.
findValidWeCorpAccount
();
if
(
null
!=
wxCorpAccount
){
user
.
setValidCropId
(
true
);
}
// WeCorpAccount wxCorpAccount
// = iWxCorpAccountService.findValidWeCorpAccount();
// if(null != wxCorpAccount){
// user.setValidCropId(true);
// }
AjaxResult
ajax
=
AjaxResult
.
success
();
ajax
.
put
(
"user"
,
user
);
ajax
.
put
(
"roles"
,
roles
);
...
...
@@ -128,15 +130,15 @@ public class SysLoginController
@GetMapping
(
"/findWxQrLoginInfo"
)
public
AjaxResult
findQrLoginParm
(){
WeCorpAccount
validWeCorpAccount
=
iWxCorpAccountService
.
findValidWeCorpAccount
();
if
(
null
!=
validWeCorpAccount
){
validWeCorpAccount
.
setContactSecret
(
null
);
validWeCorpAccount
.
setCorpSecret
(
null
);
validWeCorpAccount
.
setProviderSecret
(
null
);
}
//
WeCorpAccount validWeCorpAccount
//
= iWxCorpAccountService.findValidWeCorpAccount();
//
if(null != validWeCorpAccount){
//
validWeCorpAccount.setContactSecret(null);
//
validWeCorpAccount.setCorpSecret(null);
//
validWeCorpAccount.setProviderSecret(null);
//
}
return
AjaxResult
.
success
(
validWeCorpAccount
);
return
AjaxResult
.
success
();
}
...
...
linkwe-admin/src/main/resources/bootstrap.properties
View file @
8b506f4
spring.cloud.nacos.config.server-
addr
=
${NACOS_SERVER:119.45.28.29:10848}
spring.cloud.nacos.config.namespace
=
ce45dbdb-7096-4d39-99ac-f3513f1341ad
spring.cloud.nacos.config.namespace
=
f3edcb53-b0f8-42c3-8c5f-37c263deb60e
spring.application.name
=
link-wechat
spring.cloud.nacos.config.file-
extension
=
yaml
\ No newline at end of file
linkwe-framework/src/main/java/com/linkwechat/framework/config/MyBatisPlusConfig.java
View file @
8b506f4
package
com
.
linkwechat
.
framework
.
config
;
import
cn.hutool.core.util.ArrayUtil
;
import
cn.hutool.core.util.StrUtil
;
import
com.baomidou.mybatisplus.annotation.DbType
;
import
com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer
;
import
com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor
;
...
...
@@ -11,9 +9,7 @@ import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerIntercept
import
com.github.pagehelper.PageInterceptor
;
import
com.linkwechat.common.config.WeComeConfig
;
import
com.linkwechat.common.utils.SecurityUtils
;
import
com.linkwechat.wecom.service.IWeAccessTokenService
;
import
net.sf.jsqlparser.expression.Expression
;
import
net.sf.jsqlparser.expression.LongValue
;
import
net.sf.jsqlparser.expression.StringValue
;
import
org.apache.ibatis.plugin.Interceptor
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -21,7 +17,6 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Configuration
;
import
java.util.Arrays
;
import
java.util.List
;
/**
...
...
@@ -35,8 +30,10 @@ public class MyBatisPlusConfig
@Autowired
WeComeConfig
weComeConfig
;
@Autowired
IWeAccessTokenService
iWeAccessTokenService
;
@Bean
public
MybatisPlusInterceptor
mybatisPlusInterceptor
()
{
...
...
@@ -47,8 +44,6 @@ public class MyBatisPlusConfig
interceptor
.
addInnerInterceptor
(
new
TenantLineInnerInterceptor
(
new
TenantLineHandler
()
{
// manager_id = 1088248166370832385
// 获取租户 ID 值表达式,只支持单个 ID 值
@Override
public
Expression
getTenantId
()
{
...
...
linkwe-framework/src/main/java/com/linkwechat/framework/web/service/UserDetailsServiceImpl.java
View file @
8b506f4
package
com
.
linkwechat
.
framework
.
web
.
service
;
import
cn.hutool.core.util.ArrayUtil
;
import
cn.hutool.core.util.StrUtil
;
import
com.linkwechat.common.config.RuoYiConfig
;
import
com.linkwechat.common.constant.Constants
;
import
com.linkwechat.common.core.domain.entity.SysRole
;
...
...
@@ -60,6 +61,7 @@ public class UserDetailsServiceImpl implements UserDetailsService
public
UserDetails
loadUserByUsername
(
String
username
)
throws
UsernameNotFoundException
{
SysUser
user
=
userService
.
selectUserByUserName
(
username
);
System
.
out
.
println
(
user
.
getUserType
());
if
(
StringUtils
.
isNull
(
user
))
{
//企业管理登录
...
...
@@ -119,7 +121,7 @@ public class UserDetailsServiceImpl implements UserDetailsService
}
//当前登录用户为企业管理,设置corpId和密钥相关
if
(
user
.
getUserType
().
equals
(
Constants
.
USER_TYOE_CORP_ADMIN
)){
if
(
Constants
.
USER_TYOE_CORP_ADMIN
.
equals
(
user
.
getUserType
()
)){
user
.
setWeCorpAccount
(
iWeCorpAccountService
.
findWeCorpByAccount
(
username
)
);
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/IWeAccessTokenService.java
View file @
8b506f4
package
com
.
linkwechat
.
wecom
.
service
;
import
com.linkwechat.common.core.domain.entity.WeCorpAccount
;
/**
* @description: 微信token相关接口
* @author: My
...
...
@@ -21,5 +23,5 @@ public interface IWeAccessTokenService {
public
String
findThirdAppAccessToken
(
String
agentId
);
public
void
removeToken
();
public
void
removeToken
(
WeCorpAccount
wxCorpAccount
);
}
\ No newline at end of file
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeAccessTokenServiceImpl.java
View file @
8b506f4
...
...
@@ -194,21 +194,10 @@ public class WeAccessTokenServiceImpl implements IWeAccessTokenService {
* 清空redis中的相关token
*/
@Override
public
void
removeToken
()
{
LoginUser
loginUser
=
SecurityUtils
.
getLoginUser
();
if
(
null
!=
loginUser
){
SysUser
user
=
loginUser
.
getUser
();
if
(
null
!=
user
){
WeCorpAccount
weCorpAccount
=
user
.
getWeCorpAccount
();
if
(
null
!=
weCorpAccount
){
redisCache
.
deleteObject
(
WeConstans
.
WE_COMMON_ACCESS_TOKEN
+
"::"
+
weCorpAccount
.
getAgentId
());
redisCache
.
deleteObject
(
WeConstans
.
WE_CONTACT_ACCESS_TOKEN
+
"::"
+
weCorpAccount
.
getAgentId
());
redisCache
.
deleteObject
(
WeConstans
.
WE_PROVIDER_ACCESS_TOKEN
+
"::"
+
weCorpAccount
.
getAgentId
());
}
}
}
public
void
removeToken
(
WeCorpAccount
wxCorpAccount
)
{
redisCache
.
deleteObject
(
WeConstans
.
WE_COMMON_ACCESS_TOKEN
+
"::"
+
wxCorpAccount
.
getAgentId
());
redisCache
.
deleteObject
(
WeConstans
.
WE_CONTACT_ACCESS_TOKEN
+
"::"
+
wxCorpAccount
.
getAgentId
());
redisCache
.
deleteObject
(
WeConstans
.
WE_PROVIDER_ACCESS_TOKEN
+
"::"
+
wxCorpAccount
.
getAgentId
());
}
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeCorpAccountServiceImpl.java
View file @
8b506f4
package
com
.
linkwechat
.
wecom
.
service
.
impl
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.stream.Collectors
;
import
cn.hutool.core.collection.CollectionUtil
;
import
cn.hutool.core.util.ArrayUtil
;
import
com.linkwechat.common.config.RuoYiConfig
;
import
com.linkwechat.common.constant.Constants
;
import
com.linkwechat.common.constant.WeConstans
;
import
com.linkwechat.common.core.domain.entity.SysRole
;
import
com.linkwechat.common.core.domain.entity.SysUser
;
import
com.linkwechat.common.core.domain.entity.WeCorpAccount
;
import
com.linkwechat.common.utils.SecurityUtils
;
import
com.linkwechat.system.mapper.SysRoleMapper
;
import
com.linkwechat.system.service.ISysUserService
;
import
com.linkwechat.wecom.mapper.WeCorpAccountMapper
;
import
com.linkwechat.wecom.service.IWeAccessTokenService
;
import
com.linkwechat.wecom.service.IWeCorpAccountService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.linkwechat.wecom.mapper.WeCorpAccountMapper
;
import
com.linkwechat.common.core.domain.entity.WeCorpAccount
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.stream.Collectors
;
//import com.linkwechat.system.mapper.SysRoleMapper;
//import com.linkwechat.system.service.ISysUserService;
/**
* 企业id相关配置Service业务层处理
...
...
@@ -35,8 +39,7 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
private
IWeAccessTokenService
iWeAccessTokenService
;
@Autowired
private
IWeCorpAccountService
iWeCorpAccountService
;
@Autowired
private
ISysUserService
iSysUserService
;
...
...
@@ -48,6 +51,10 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
@Autowired
private
SysRoleMapper
roleMapper
;
@Autowired
private
WeCorpAccountMapper
weCorpAccountMapper
;
/**
* 查询企业id相关配置
*
...
...
@@ -57,7 +64,7 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
@Override
public
WeCorpAccount
selectWeCorpAccountById
(
Long
id
)
{
return
iWeCorpAccountService
.
selectWeCorpAccountById
(
id
);
return
weCorpAccountMapper
.
selectWeCorpAccountById
(
id
);
}
/**
...
...
@@ -69,7 +76,7 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
@Override
public
List
<
WeCorpAccount
>
selectWeCorpAccountList
(
WeCorpAccount
wxCorpAccount
)
{
return
iWeCorpAccountService
.
selectWeCorpAccountList
(
wxCorpAccount
);
return
weCorpAccountMapper
.
selectWeCorpAccountList
(
wxCorpAccount
);
}
/**
...
...
@@ -81,7 +88,7 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
@Override
public
int
insertWeCorpAccount
(
WeCorpAccount
wxCorpAccount
)
{
int
returnCode
=
iWeCorpAccountService
.
insertWeCorpAccount
(
wxCorpAccount
);
int
returnCode
=
weCorpAccountMapper
.
insertWeCorpAccount
(
wxCorpAccount
);
if
(
Constants
.
SERVICE_STATUS_ERROR
<
returnCode
){
iSysUserService
.
insertUser
(
...
...
@@ -110,11 +117,11 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
public
int
updateWeCorpAccount
(
WeCorpAccount
wxCorpAccount
)
{
int
returnCode
=
iWeCorpAccountService
.
updateWeCorpAccount
(
wxCorpAccount
);
int
returnCode
=
weCorpAccountMapper
.
updateWeCorpAccount
(
wxCorpAccount
);
if
(
Constants
.
SERVICE_RETURN_SUCCESS_CODE
<
returnCode
){
iWeAccessTokenService
.
removeToken
();
iWeAccessTokenService
.
removeToken
(
wxCorpAccount
);
}
...
...
@@ -130,7 +137,7 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
*/
@Override
public
WeCorpAccount
findValidWeCorpAccount
()
{
return
iWeCorpAccountService
.
findValidWeCorpAccount
();
return
weCorpAccountMapper
.
findValidWeCorpAccount
();
}
...
...
@@ -141,29 +148,42 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
@Override
public
int
startVailWeCorpAccount
(
String
corpId
)
{
int
returnCode
=
iWeCorpAccountService
.
startVailWeCorpAccount
(
corpId
);
if
(
Constants
.
SERVICE_RETURN_SUCCESS_CODE
<
returnCode
){
iWeAccessTokenService
.
removeToken
();
}
return
returnCode
;
// List<WeCorpAccount> weCorpAccounts = weCorpAccountMapper.selectWeCorpAccountList(
// WeCorpAccount.builder()
// .corpId(corpId)
// .delFlag(Constants.NORMAL_CODE)
// .build()
// );
// if(CollectionUtil.isNotEmpty(weCorpAccounts)){
//
// WeCorpAccount weCorpAccount = weCorpAccounts.get(0);
//
// }
//
// int returnCode = weCorpAccountMapper.startVailWeCorpAccount(corpId);
//
// if(Constants.SERVICE_RETURN_SUCCESS_CODE<returnCode){
//
//
// iWeAccessTokenService.removeToken();
//
// }
//
//
// return returnCode;
return
1
;
}
@Override
public
int
startCustomerChurnNoticeSwitch
(
String
status
)
{
WeCorpAccount
validWeCorpAccount
=
findValidWeCorpAccount
();
validWeCorpAccount
.
setCustomerChurnNoticeSwitch
(
status
);
return
iWeCorpAccountService
.
updateWeCorpAccount
(
validWeCorpAccount
);
return
weCorpAccountMapper
.
updateWeCorpAccount
(
validWeCorpAccount
);
}
@Override
public
String
getCustomerChurnNoticeSwitch
()
{
WeCorpAccount
validWeCorpAccount
=
iWeCorpAccountService
.
findValidWeCorpAccount
();
WeCorpAccount
validWeCorpAccount
=
weCorpAccountMapper
.
findValidWeCorpAccount
();
String
noticeSwitch
=
Optional
.
ofNullable
(
validWeCorpAccount
).
map
(
WeCorpAccount:
:
getCustomerChurnNoticeSwitch
)
.
orElse
(
WeConstans
.
DEL_FOLLOW_USER_SWITCH_CLOSE
);
return
noticeSwitch
;
...
...
@@ -172,7 +192,7 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
@Override
public
WeCorpAccount
findWeCorpByAccount
(
String
corpAccount
)
{
return
iWeCorpAccountService
.
findWeCorpByAccount
(
corpAccount
);
return
weCorpAccountMapper
.
findWeCorpByAccount
(
corpAccount
);
}
...
...
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