Commit 8b506f47 by 水库浪子

多租户登录代码提交

1 parent 6c28ff99
...@@ -93,12 +93,14 @@ public class SysLoginController ...@@ -93,12 +93,14 @@ public class SysLoginController
Set<String> roles = permissionService.getRolePermission(user); Set<String> roles = permissionService.getRolePermission(user);
// 权限集合 // 权限集合
Set<String> permissions = permissionService.getMenuPermission(user); Set<String> permissions = permissionService.getMenuPermission(user);
//校验用户是否拥有可用corpid //校验用户是否拥有可用corpid
WeCorpAccount wxCorpAccount // WeCorpAccount wxCorpAccount
= iWxCorpAccountService.findValidWeCorpAccount(); // = iWxCorpAccountService.findValidWeCorpAccount();
if(null != wxCorpAccount){ // if(null != wxCorpAccount){
user.setValidCropId(true); // user.setValidCropId(true);
} // }
AjaxResult ajax = AjaxResult.success(); AjaxResult ajax = AjaxResult.success();
ajax.put("user", user); ajax.put("user", user);
ajax.put("roles", roles); ajax.put("roles", roles);
...@@ -128,15 +130,15 @@ public class SysLoginController ...@@ -128,15 +130,15 @@ public class SysLoginController
@GetMapping("/findWxQrLoginInfo") @GetMapping("/findWxQrLoginInfo")
public AjaxResult findQrLoginParm(){ public AjaxResult findQrLoginParm(){
WeCorpAccount validWeCorpAccount // WeCorpAccount validWeCorpAccount
= iWxCorpAccountService.findValidWeCorpAccount(); // = iWxCorpAccountService.findValidWeCorpAccount();
if(null != validWeCorpAccount){ // if(null != validWeCorpAccount){
validWeCorpAccount.setContactSecret(null); // validWeCorpAccount.setContactSecret(null);
validWeCorpAccount.setCorpSecret(null); // validWeCorpAccount.setCorpSecret(null);
validWeCorpAccount.setProviderSecret(null); // validWeCorpAccount.setProviderSecret(null);
} // }
return AjaxResult.success(validWeCorpAccount); return AjaxResult.success();
} }
......
spring.cloud.nacos.config.server-addr=${NACOS_SERVER:119.45.28.29:10848} 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.application.name=link-wechat
spring.cloud.nacos.config.file-extension=yaml spring.cloud.nacos.config.file-extension=yaml
\ No newline at end of file \ No newline at end of file
package com.linkwechat.framework.config; 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.annotation.DbType;
import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer; import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
...@@ -11,9 +9,7 @@ import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerIntercept ...@@ -11,9 +9,7 @@ import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerIntercept
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.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.StringValue; 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;
...@@ -21,7 +17,6 @@ import org.springframework.context.annotation.Bean; ...@@ -21,7 +17,6 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
/** /**
...@@ -35,8 +30,10 @@ public class MyBatisPlusConfig ...@@ -35,8 +30,10 @@ public class MyBatisPlusConfig
@Autowired @Autowired
WeComeConfig weComeConfig; WeComeConfig weComeConfig;
@Autowired
IWeAccessTokenService iWeAccessTokenService;
@Bean @Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() { public MybatisPlusInterceptor mybatisPlusInterceptor() {
...@@ -47,8 +44,6 @@ public class MyBatisPlusConfig ...@@ -47,8 +44,6 @@ public class MyBatisPlusConfig
interceptor.addInnerInterceptor(new TenantLineInnerInterceptor( interceptor.addInnerInterceptor(new TenantLineInnerInterceptor(
new TenantLineHandler() { new TenantLineHandler() {
// manager_id = 1088248166370832385
// 获取租户 ID 值表达式,只支持单个 ID 值 // 获取租户 ID 值表达式,只支持单个 ID 值
@Override @Override
public Expression getTenantId() { public Expression getTenantId() {
......
package com.linkwechat.framework.web.service; package com.linkwechat.framework.web.service;
import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import com.linkwechat.common.config.RuoYiConfig; import com.linkwechat.common.config.RuoYiConfig;
import com.linkwechat.common.constant.Constants; import com.linkwechat.common.constant.Constants;
import com.linkwechat.common.core.domain.entity.SysRole; import com.linkwechat.common.core.domain.entity.SysRole;
...@@ -60,6 +61,7 @@ public class UserDetailsServiceImpl implements UserDetailsService ...@@ -60,6 +61,7 @@ public class UserDetailsServiceImpl implements UserDetailsService
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException
{ {
SysUser user = userService.selectUserByUserName(username); SysUser user = userService.selectUserByUserName(username);
System.out.println(user.getUserType());
if (StringUtils.isNull(user)) if (StringUtils.isNull(user))
{ {
//企业管理登录 //企业管理登录
...@@ -119,7 +121,7 @@ public class UserDetailsServiceImpl implements UserDetailsService ...@@ -119,7 +121,7 @@ public class UserDetailsServiceImpl implements UserDetailsService
} }
//当前登录用户为企业管理,设置corpId和密钥相关 //当前登录用户为企业管理,设置corpId和密钥相关
if(user.getUserType().equals(Constants.USER_TYOE_CORP_ADMIN)){ if(Constants.USER_TYOE_CORP_ADMIN.equals(user.getUserType())){
user.setWeCorpAccount( user.setWeCorpAccount(
iWeCorpAccountService.findWeCorpByAccount(username) iWeCorpAccountService.findWeCorpByAccount(username)
); );
......
package com.linkwechat.wecom.service; package com.linkwechat.wecom.service;
import com.linkwechat.common.core.domain.entity.WeCorpAccount;
/** /**
* @description: 微信token相关接口 * @description: 微信token相关接口
* @author: My * @author: My
...@@ -21,5 +23,5 @@ public interface IWeAccessTokenService { ...@@ -21,5 +23,5 @@ public interface IWeAccessTokenService {
public String findThirdAppAccessToken(String agentId); public String findThirdAppAccessToken(String agentId);
public void removeToken(); public void removeToken(WeCorpAccount wxCorpAccount);
} }
\ No newline at end of file \ No newline at end of file
...@@ -194,21 +194,10 @@ public class WeAccessTokenServiceImpl implements IWeAccessTokenService { ...@@ -194,21 +194,10 @@ public class WeAccessTokenServiceImpl implements IWeAccessTokenService {
* 清空redis中的相关token * 清空redis中的相关token
*/ */
@Override @Override
public void removeToken() { public void removeToken(WeCorpAccount wxCorpAccount) {
redisCache.deleteObject(WeConstans.WE_COMMON_ACCESS_TOKEN+"::"+wxCorpAccount.getAgentId());
LoginUser loginUser = SecurityUtils.getLoginUser(); redisCache.deleteObject(WeConstans.WE_CONTACT_ACCESS_TOKEN+"::"+wxCorpAccount.getAgentId());
if(null != loginUser){ redisCache.deleteObject(WeConstans.WE_PROVIDER_ACCESS_TOKEN+"::"+wxCorpAccount.getAgentId());
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());
}
}
}
} }
......
package com.linkwechat.wecom.service.impl; package com.linkwechat.wecom.service.impl;
import java.util.List; import cn.hutool.core.collection.CollectionUtil;
import java.util.Optional;
import java.util.stream.Collectors;
import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ArrayUtil;
import com.linkwechat.common.config.RuoYiConfig; 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.SysRole;
import com.linkwechat.common.core.domain.entity.SysUser; 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.common.utils.SecurityUtils;
import com.linkwechat.system.mapper.SysRoleMapper; import com.linkwechat.system.mapper.SysRoleMapper;
import com.linkwechat.system.service.ISysUserService; import com.linkwechat.system.service.ISysUserService;
import com.linkwechat.wecom.mapper.WeCorpAccountMapper;
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;
import org.springframework.stereotype.Service; 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业务层处理 * 企业id相关配置Service业务层处理
...@@ -35,8 +39,7 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService { ...@@ -35,8 +39,7 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
private IWeAccessTokenService iWeAccessTokenService; private IWeAccessTokenService iWeAccessTokenService;
@Autowired
private IWeCorpAccountService iWeCorpAccountService;
@Autowired @Autowired
private ISysUserService iSysUserService; private ISysUserService iSysUserService;
...@@ -48,6 +51,10 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService { ...@@ -48,6 +51,10 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
@Autowired @Autowired
private SysRoleMapper roleMapper; private SysRoleMapper roleMapper;
@Autowired
private WeCorpAccountMapper weCorpAccountMapper;
/** /**
* 查询企业id相关配置 * 查询企业id相关配置
* *
...@@ -57,7 +64,7 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService { ...@@ -57,7 +64,7 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
@Override @Override
public WeCorpAccount selectWeCorpAccountById(Long id) public WeCorpAccount selectWeCorpAccountById(Long id)
{ {
return iWeCorpAccountService.selectWeCorpAccountById(id); return weCorpAccountMapper.selectWeCorpAccountById(id);
} }
/** /**
...@@ -69,7 +76,7 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService { ...@@ -69,7 +76,7 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
@Override @Override
public List<WeCorpAccount> selectWeCorpAccountList(WeCorpAccount wxCorpAccount) public List<WeCorpAccount> selectWeCorpAccountList(WeCorpAccount wxCorpAccount)
{ {
return iWeCorpAccountService.selectWeCorpAccountList(wxCorpAccount); return weCorpAccountMapper.selectWeCorpAccountList(wxCorpAccount);
} }
/** /**
...@@ -81,7 +88,7 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService { ...@@ -81,7 +88,7 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
@Override @Override
public int insertWeCorpAccount(WeCorpAccount wxCorpAccount) public int insertWeCorpAccount(WeCorpAccount wxCorpAccount)
{ {
int returnCode = iWeCorpAccountService.insertWeCorpAccount(wxCorpAccount); int returnCode = weCorpAccountMapper.insertWeCorpAccount(wxCorpAccount);
if(Constants.SERVICE_STATUS_ERROR<returnCode){ if(Constants.SERVICE_STATUS_ERROR<returnCode){
iSysUserService.insertUser( iSysUserService.insertUser(
...@@ -110,11 +117,11 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService { ...@@ -110,11 +117,11 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
public int updateWeCorpAccount(WeCorpAccount wxCorpAccount) public int updateWeCorpAccount(WeCorpAccount wxCorpAccount)
{ {
int returnCode = iWeCorpAccountService.updateWeCorpAccount(wxCorpAccount); int returnCode = weCorpAccountMapper.updateWeCorpAccount(wxCorpAccount);
if(Constants.SERVICE_RETURN_SUCCESS_CODE<returnCode){ if(Constants.SERVICE_RETURN_SUCCESS_CODE<returnCode){
iWeAccessTokenService.removeToken(); iWeAccessTokenService.removeToken(wxCorpAccount);
} }
...@@ -130,7 +137,7 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService { ...@@ -130,7 +137,7 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
*/ */
@Override @Override
public WeCorpAccount findValidWeCorpAccount() { public WeCorpAccount findValidWeCorpAccount() {
return iWeCorpAccountService.findValidWeCorpAccount(); return weCorpAccountMapper.findValidWeCorpAccount();
} }
...@@ -141,29 +148,42 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService { ...@@ -141,29 +148,42 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
@Override @Override
public int startVailWeCorpAccount(String corpId) { public int startVailWeCorpAccount(String corpId) {
int returnCode = iWeCorpAccountService.startVailWeCorpAccount(corpId); // List<WeCorpAccount> weCorpAccounts = weCorpAccountMapper.selectWeCorpAccountList(
// WeCorpAccount.builder()
if(Constants.SERVICE_RETURN_SUCCESS_CODE<returnCode){ // .corpId(corpId)
// .delFlag(Constants.NORMAL_CODE)
// .build()
iWeAccessTokenService.removeToken(); // );
// if(CollectionUtil.isNotEmpty(weCorpAccounts)){
} //
// WeCorpAccount weCorpAccount = weCorpAccounts.get(0);
//
return returnCode; // }
//
// int returnCode = weCorpAccountMapper.startVailWeCorpAccount(corpId);
//
// if(Constants.SERVICE_RETURN_SUCCESS_CODE<returnCode){
//
//
// iWeAccessTokenService.removeToken();
//
// }
//
//
// return returnCode;
return 1;
} }
@Override @Override
public int startCustomerChurnNoticeSwitch(String status) { public int startCustomerChurnNoticeSwitch(String status) {
WeCorpAccount validWeCorpAccount = findValidWeCorpAccount(); WeCorpAccount validWeCorpAccount = findValidWeCorpAccount();
validWeCorpAccount.setCustomerChurnNoticeSwitch(status); validWeCorpAccount.setCustomerChurnNoticeSwitch(status);
return iWeCorpAccountService.updateWeCorpAccount(validWeCorpAccount); return weCorpAccountMapper.updateWeCorpAccount(validWeCorpAccount);
} }
@Override @Override
public String getCustomerChurnNoticeSwitch() { public String getCustomerChurnNoticeSwitch() {
WeCorpAccount validWeCorpAccount = iWeCorpAccountService.findValidWeCorpAccount(); WeCorpAccount validWeCorpAccount = weCorpAccountMapper.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;
...@@ -172,7 +192,7 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService { ...@@ -172,7 +192,7 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
@Override @Override
public WeCorpAccount findWeCorpByAccount(String corpAccount) { public WeCorpAccount findWeCorpByAccount(String corpAccount) {
return iWeCorpAccountService.findWeCorpByAccount(corpAccount); return weCorpAccountMapper.findWeCorpByAccount(corpAccount);
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!