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 6c28ff99
authored
Apr 12, 2021
by
1539136324@qq.com
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
提交多租户登录授权相关接口
1 parent
db2c68f7
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
90 additions
and
12 deletions
linkwe-admin/src/main/java/com/linkwechat/web/controller/system/SysLoginController.java
linkwe-common/src/main/java/com/linkwechat/common/utils/SecurityUtils.java
linkwe-framework/src/main/java/com/linkwechat/framework/config/MyBatisPlusConfig.java
linkwe-framework/src/main/java/com/linkwechat/framework/config/SecurityConfig.java
linkwe-wecom/pom.xml
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 @
6c28ff9
package
com
.
linkwechat
.
web
.
controller
.
system
;
package
com
.
linkwechat
.
web
.
controller
.
system
;
import
cn.hutool.core.collection.CollectionUtil
;
import
com.linkwechat.common.constant.Constants
;
import
com.linkwechat.common.constant.Constants
;
import
com.linkwechat.common.core.domain.AjaxResult
;
import
com.linkwechat.common.core.domain.AjaxResult
;
import
com.linkwechat.common.core.domain.entity.SysMenu
;
import
com.linkwechat.common.core.domain.entity.SysMenu
;
...
@@ -52,6 +53,9 @@ public class SysLoginController
...
@@ -52,6 +53,9 @@ public class SysLoginController
@Autowired
@Autowired
private
WeAccessTokenClient
weAccessTokenClient
;
private
WeAccessTokenClient
weAccessTokenClient
;
// @Autowired
// @Autowired
// private IWeGroupCodeService weGroupCodeService;
// private IWeGroupCodeService weGroupCodeService;
...
@@ -156,7 +160,30 @@ public class SysLoginController
...
@@ -156,7 +160,30 @@ public class SysLoginController
}
}
return
ajax
;
return
ajax
;
}
/**
* 通过企业id和企业密钥登录
* @param corpId
* @param corpSecret
* @return
*/
@GetMapping
(
"/corpLogin"
)
public
AjaxResult
corpLogin
(
String
corpId
,
String
corpSecret
){
List
<
WeCorpAccount
>
weCorpAccounts
=
iWxCorpAccountService
.
selectWeCorpAccountList
(
WeCorpAccount
.
builder
()
.
corpId
(
corpId
)
.
corpSecret
(
corpSecret
)
.
delFlag
(
Constants
.
NORMAL_CODE
)
.
build
());
if
(
CollectionUtil
.
isEmpty
(
weCorpAccounts
)){
return
AjaxResult
.
error
(
"当前企业id与企业密码不匹配或不存在"
);
}
return
AjaxResult
.
success
(
loginService
.
noPwdLogin
(
weCorpAccounts
.
get
(
0
).
getCropAccount
())
);
}
}
}
}
linkwe-common/src/main/java/com/linkwechat/common/utils/SecurityUtils.java
View file @
6c28ff9
...
@@ -87,4 +87,7 @@ public class SecurityUtils
...
@@ -87,4 +87,7 @@ public class SecurityUtils
{
{
return
userId
!=
null
&&
1L
==
userId
;
return
userId
!=
null
&&
1L
==
userId
;
}
}
}
}
linkwe-framework/src/main/java/com/linkwechat/framework/config/MyBatisPlusConfig.java
View file @
6c28ff9
...
@@ -10,8 +10,11 @@ import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerIntercept
...
@@ -10,8 +10,11 @@ import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerIntercept
import
com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor
;
import
com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor
;
import
com.github.pagehelper.PageInterceptor
;
import
com.github.pagehelper.PageInterceptor
;
import
com.linkwechat.common.config.WeComeConfig
;
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.Expression
;
import
net.sf.jsqlparser.expression.LongValue
;
import
net.sf.jsqlparser.expression.LongValue
;
import
net.sf.jsqlparser.expression.StringValue
;
import
org.apache.ibatis.plugin.Interceptor
;
import
org.apache.ibatis.plugin.Interceptor
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
...
@@ -32,6 +35,9 @@ public class MyBatisPlusConfig
...
@@ -32,6 +35,9 @@ public class MyBatisPlusConfig
@Autowired
@Autowired
WeComeConfig
weComeConfig
;
WeComeConfig
weComeConfig
;
@Autowired
IWeAccessTokenService
iWeAccessTokenService
;
@Bean
@Bean
public
MybatisPlusInterceptor
mybatisPlusInterceptor
()
{
public
MybatisPlusInterceptor
mybatisPlusInterceptor
()
{
MybatisPlusInterceptor
interceptor
=
new
MybatisPlusInterceptor
();
MybatisPlusInterceptor
interceptor
=
new
MybatisPlusInterceptor
();
...
@@ -46,7 +52,8 @@ public class MyBatisPlusConfig
...
@@ -46,7 +52,8 @@ public class MyBatisPlusConfig
// 获取租户 ID 值表达式,只支持单个 ID 值
// 获取租户 ID 值表达式,只支持单个 ID 值
@Override
@Override
public
Expression
getTenantId
()
{
public
Expression
getTenantId
()
{
return
new
LongValue
(
1088248166370832385L
);
return
new
StringValue
(
SecurityUtils
.
getLoginUser
().
getUser
().
getWeCorpAccount
().
getCorpId
());
}
}
// 这是 default 方法,默认返回 false 表示所有表都需要拼多租户条件,
// 这是 default 方法,默认返回 false 表示所有表都需要拼多租户条件,
// 这里设置 role表不需要该条件
// 这里设置 role表不需要该条件
...
...
linkwe-framework/src/main/java/com/linkwechat/framework/config/SecurityConfig.java
View file @
6c28ff9
...
@@ -126,6 +126,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
...
@@ -126,6 +126,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
.
antMatchers
(
"/wecom/portrait/**"
).
anonymous
()
.
antMatchers
(
"/wecom/portrait/**"
).
anonymous
()
.
antMatchers
(
"/wecom/findAddaddEmployes"
).
anonymous
()
.
antMatchers
(
"/wecom/findAddaddEmployes"
).
anonymous
()
.
antMatchers
(
"/corpLogin"
).
anonymous
()
// 除上面外的所有请求全部需要鉴权认证
// 除上面外的所有请求全部需要鉴权认证
.
anyRequest
().
authenticated
()
.
anyRequest
().
authenticated
()
.
and
()
.
and
()
...
...
linkwe-wecom/pom.xml
View file @
6c28ff9
...
@@ -27,6 +27,10 @@
...
@@ -27,6 +27,10 @@
<artifactId>
spring-test
</artifactId>
<artifactId>
spring-test
</artifactId>
<version>
5.2.9.RELEASE
</version>
<version>
5.2.9.RELEASE
</version>
</dependency>
</dependency>
<dependency>
<groupId>
com.linkwechat
</groupId>
<artifactId>
linkwe-system
</artifactId>
</dependency>
</dependencies>
</dependencies>
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeCorpAccountServiceImpl.java
View file @
6c28ff9
...
@@ -2,9 +2,17 @@ package com.linkwechat.wecom.service.impl;
...
@@ -2,9 +2,17 @@ package com.linkwechat.wecom.service.impl;
import
java.util.List
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.Optional
;
import
java.util.stream.Collectors
;
import
cn.hutool.core.util.ArrayUtil
;
import
com.linkwechat.common.config.RuoYiConfig
;
import
com.linkwechat.common.constant.Constants
;
import
com.linkwechat.common.constant.Constants
;
import
com.linkwechat.common.constant.WeConstans
;
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.utils.SecurityUtils
;
import
com.linkwechat.system.mapper.SysRoleMapper
;
import
com.linkwechat.system.service.ISysUserService
;
import
com.linkwechat.wecom.service.IWeAccessTokenService
;
import
com.linkwechat.wecom.service.IWeAccessTokenService
;
import
com.linkwechat.wecom.service.IWeCorpAccountService
;
import
com.linkwechat.wecom.service.IWeCorpAccountService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -21,13 +29,25 @@ import com.linkwechat.common.core.domain.entity.WeCorpAccount;
...
@@ -21,13 +29,25 @@ import com.linkwechat.common.core.domain.entity.WeCorpAccount;
@Service
@Service
public
class
WeCorpAccountServiceImpl
implements
IWeCorpAccountService
{
public
class
WeCorpAccountServiceImpl
implements
IWeCorpAccountService
{
@Autowired
private
WeCorpAccountMapper
weCorpAccountMapper
;
@Autowired
@Autowired
private
IWeAccessTokenService
iWeAccessTokenService
;
private
IWeAccessTokenService
iWeAccessTokenService
;
@Autowired
private
IWeCorpAccountService
iWeCorpAccountService
;
@Autowired
private
ISysUserService
iSysUserService
;
@Autowired
private
RuoYiConfig
ruoYiConfig
;
@Autowired
private
SysRoleMapper
roleMapper
;
/**
/**
* 查询企业id相关配置
* 查询企业id相关配置
*
*
...
@@ -37,7 +57,7 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
...
@@ -37,7 +57,7 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
@Override
@Override
public
WeCorpAccount
selectWeCorpAccountById
(
Long
id
)
public
WeCorpAccount
selectWeCorpAccountById
(
Long
id
)
{
{
return
weCorpAccountMapper
.
selectWeCorpAccountById
(
id
);
return
iWeCorpAccountService
.
selectWeCorpAccountById
(
id
);
}
}
/**
/**
...
@@ -49,7 +69,7 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
...
@@ -49,7 +69,7 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
@Override
@Override
public
List
<
WeCorpAccount
>
selectWeCorpAccountList
(
WeCorpAccount
wxCorpAccount
)
public
List
<
WeCorpAccount
>
selectWeCorpAccountList
(
WeCorpAccount
wxCorpAccount
)
{
{
return
weCorpAccountMapper
.
selectWeCorpAccountList
(
wxCorpAccount
);
return
iWeCorpAccountService
.
selectWeCorpAccountList
(
wxCorpAccount
);
}
}
/**
/**
...
@@ -61,8 +81,23 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
...
@@ -61,8 +81,23 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
@Override
@Override
public
int
insertWeCorpAccount
(
WeCorpAccount
wxCorpAccount
)
public
int
insertWeCorpAccount
(
WeCorpAccount
wxCorpAccount
)
{
{
int
returnCode
=
iWeCorpAccountService
.
insertWeCorpAccount
(
wxCorpAccount
);
if
(
Constants
.
SERVICE_STATUS_ERROR
<
returnCode
){
iSysUserService
.
insertUser
(
SysUser
.
builder
()
.
userName
(
wxCorpAccount
.
getCropAccount
())
.
nickName
(
wxCorpAccount
.
getCompanyName
())
.
userType
(
Constants
.
USER_TYOE_CORP_ADMIN
)
.
roleIds
(
ArrayUtil
.
toArray
(
roleMapper
.
selectRoleList
(
SysRole
.
builder
()
.
roleKey
(
Constants
.
DEFAULT_WECOME_CORP_ADMIN
)
.
build
()).
stream
().
map
(
SysRole:
:
getRoleId
).
collect
(
Collectors
.
toList
()),
Long
.
class
))
.
password
(
SecurityUtils
.
encryptPassword
(
ruoYiConfig
.
getWeUserDefaultPwd
()))
.
build
()
);
}
return
weCorpAccountMapper
.
insertWeCorpAccount
(
wxCorpAccount
)
;
return
returnCode
;
}
}
/**
/**
...
@@ -75,7 +110,7 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
...
@@ -75,7 +110,7 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
public
int
updateWeCorpAccount
(
WeCorpAccount
wxCorpAccount
)
public
int
updateWeCorpAccount
(
WeCorpAccount
wxCorpAccount
)
{
{
int
returnCode
=
weCorpAccountMapper
.
updateWeCorpAccount
(
wxCorpAccount
);
int
returnCode
=
iWeCorpAccountService
.
updateWeCorpAccount
(
wxCorpAccount
);
if
(
Constants
.
SERVICE_RETURN_SUCCESS_CODE
<
returnCode
){
if
(
Constants
.
SERVICE_RETURN_SUCCESS_CODE
<
returnCode
){
...
@@ -95,7 +130,7 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
...
@@ -95,7 +130,7 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
*/
*/
@Override
@Override
public
WeCorpAccount
findValidWeCorpAccount
()
{
public
WeCorpAccount
findValidWeCorpAccount
()
{
return
weCorpAccountMapper
.
findValidWeCorpAccount
();
return
iWeCorpAccountService
.
findValidWeCorpAccount
();
}
}
...
@@ -106,7 +141,7 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
...
@@ -106,7 +141,7 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
@Override
@Override
public
int
startVailWeCorpAccount
(
String
corpId
)
{
public
int
startVailWeCorpAccount
(
String
corpId
)
{
int
returnCode
=
weCorpAccountMapper
.
startVailWeCorpAccount
(
corpId
);
int
returnCode
=
iWeCorpAccountService
.
startVailWeCorpAccount
(
corpId
);
if
(
Constants
.
SERVICE_RETURN_SUCCESS_CODE
<
returnCode
){
if
(
Constants
.
SERVICE_RETURN_SUCCESS_CODE
<
returnCode
){
...
@@ -123,12 +158,12 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
...
@@ -123,12 +158,12 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
public
int
startCustomerChurnNoticeSwitch
(
String
status
)
{
public
int
startCustomerChurnNoticeSwitch
(
String
status
)
{
WeCorpAccount
validWeCorpAccount
=
findValidWeCorpAccount
();
WeCorpAccount
validWeCorpAccount
=
findValidWeCorpAccount
();
validWeCorpAccount
.
setCustomerChurnNoticeSwitch
(
status
);
validWeCorpAccount
.
setCustomerChurnNoticeSwitch
(
status
);
return
weCorpAccountMapper
.
updateWeCorpAccount
(
validWeCorpAccount
);
return
iWeCorpAccountService
.
updateWeCorpAccount
(
validWeCorpAccount
);
}
}
@Override
@Override
public
String
getCustomerChurnNoticeSwitch
()
{
public
String
getCustomerChurnNoticeSwitch
()
{
WeCorpAccount
validWeCorpAccount
=
weCorpAccountMapper
.
findValidWeCorpAccount
();
WeCorpAccount
validWeCorpAccount
=
iWeCorpAccountService
.
findValidWeCorpAccount
();
String
noticeSwitch
=
Optional
.
ofNullable
(
validWeCorpAccount
).
map
(
WeCorpAccount:
:
getCustomerChurnNoticeSwitch
)
String
noticeSwitch
=
Optional
.
ofNullable
(
validWeCorpAccount
).
map
(
WeCorpAccount:
:
getCustomerChurnNoticeSwitch
)
.
orElse
(
WeConstans
.
DEL_FOLLOW_USER_SWITCH_CLOSE
);
.
orElse
(
WeConstans
.
DEL_FOLLOW_USER_SWITCH_CLOSE
);
return
noticeSwitch
;
return
noticeSwitch
;
...
@@ -137,7 +172,7 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
...
@@ -137,7 +172,7 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
@Override
@Override
public
WeCorpAccount
findWeCorpByAccount
(
String
corpAccount
)
{
public
WeCorpAccount
findWeCorpByAccount
(
String
corpAccount
)
{
return
weCorpAccountMapper
.
findWeCorpByAccount
(
corpAccount
);
return
iWeCorpAccountService
.
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