Commit 36cf79e7 by 水库浪子

整合多租户框架,便于后期拓展多租户;

1 parent 9e7cdf8a
package com.linkwechat.web.controller.wecom; package com.linkwechat.web.controller.wecom;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.linkwechat.common.core.controller.BaseController; import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.ConversationArchiveQuery; import com.linkwechat.common.core.domain.ConversationArchiveQuery;
...@@ -11,7 +10,6 @@ import io.swagger.annotations.Api; ...@@ -11,7 +10,6 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
......
# 数据源配置 # 项目相关配置
ruoyi:
# 名称
name: RuoYi
# 版本
version: 3.1.0
# 版权年份
copyrightYear: 2019
startTenant: false
# 实例演示开关
demoEnabled: true
# 是否开启文件云上传(使用的是腾讯云,如果开启了,则需要配置腾讯云存储相关信息;如果关闭了则文件存储再本地,需要配置本地路径)
file:
startCosUpload: true
imgUrlPrefix:
#腾讯云对象存储
cos:
secretId:
secretKey:
#link-wechat-1251309172.cos.ap-nanjing.myqcloud.com
region:
bucketName:
# 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /app/project/pic)
#profile: /data/jenkins_home/app/project/
# 获取ip地址开关
addressEnabled: false
# 验证码类型 math 数组计算 char 字符验证
captchaType: math
# 企业微信用户首次登录系统默认密码
weUserDefaultPwd: 123456
#匿名访问的URL
anonUrl:
- /login
- /captchaImage
- /findWxQrLoginInfo
- /wxQrLogin
- /profile/**
- /common/download**
- /common/download/resource**
- /common/download/url**
- /swagger-ui.html
- /swagger-resources/**
- /webjars/**
- /*/api-docs
- /druid/**
- /wecom/callback/**
- /wecom/chat/item/list
- /wecom/chat/collection/list
- /wecom/chat/collection/cancleCollection
- /wecom/chat/collection/addCollection
- /wecom/chat/side/h5List
- /wecom/ticket/**
- /wecom/user/getUserInfo
- /wecom/portrait/**
- /wecom/fission/poster
- /wecom/fission/complete/**
- /wecom/fission/*/progress/*
- /wecom/reward/getRewardByFissionId/**
- /wecom/groupCode/getActualCode/**
- /wecom/community/h5/**
- /weixin/auth/**
- /wecom/material/temporaryMaterialMediaId
# 开发环境配置
server:
# 服务器的HTTP端口,默认为8090
port: 8090
servlet:
# 应用的访问路径
context-path: /
tomcat:
# tomcat的URI编码
uri-encoding: UTF-8
# tomcat最大线程数,默认为200
max-threads: 800
# Tomcat启动初始化的线程数,默认值25
min-spare-threads: 30
# 日志配置
logging:
level:
com.ruoyi: debug
org.springframework: warn
path: ./logs
path:
log: ./logs
#H5地址路径
H5:
url:
fissionUrl:
fissionGroupUrl:
# Spring配置
spring: spring:
# 资源信息
messages:
# 国际化资源文件路径
basename: i18n/messages
datasource: datasource:
type: com.alibaba.druid.pool.DruidDataSource type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver driverClassName: com.mysql.cj.jdbc.Driver
...@@ -8,7 +104,7 @@ spring: ...@@ -8,7 +104,7 @@ spring:
master: master:
url: jdbc:mysql://127.0.0.1:3306/link-wechat-prod?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 url: jdbc:mysql://127.0.0.1:3306/link-wechat-prod?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root username: root
password: root password: 123456
# 从库数据源 # 从库数据源
slave: slave:
# 从数据源开关/默认关闭 # 从数据源开关/默认关闭
...@@ -55,3 +151,186 @@ spring: ...@@ -55,3 +151,186 @@ spring:
wall: wall:
config: config:
multi-statement-allow: true multi-statement-allow: true
# 文件上传
servlet:
multipart:
# 单个文件大小
max-file-size: 10MB
# 设置总上传的文件大小
max-request-size: 20MB
task:
execution:
pool:
keep-alive: 10s
thread-name-prefix: common-pool-
# 服务模块
devtools:
restart:
# 热部署开关
enabled: true
# redis 配置
redis:
# 地址
host: 127.0.0.1
# 端口,默认为6379
port: 6379
# 密码
password:
# 连接超时时间
timeout: 10s
lettuce:
pool:
# 连接池中的最小空闲连接
min-idle: 0
# 连接池中的最大空闲连接
max-idle: 8
# 连接池的最大数据库连接数
max-active: 8
# #连接池最大阻塞等待时间(使用负值表示没有限制)
max-wait: -1ms
# token配置
token:
# 令牌自定义标识
header: Authorization
# 令牌密钥
secret: abcdefghijklmnopqrstuvwxyz
# 令牌有效期(默认30分钟)
expireTime: 30
mybatis-plus:
mapper-locations: classpath*:mapper/**/*Mapper.xml
type-aliases-package: com.linkwechat.**.domain
type-handlers-package: com.linkwechat.framework.handler.GenericTypeHandler,com.linkwechat.framework.handler.StringArrayJoinTypeHandler
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
global-config:
db-config:
logic-delete-field: delFlag
logic-delete-value: 1
logic-not-delete-value: 0
## MyBatis配置
#mybatis:
# # 搜索指定包别名
# typeAliasesPackage: com.linkwechat.**.domain
# # 配置mapper的扫描,找到所有的mapper.xml映射文件
# mapperLocations: classpath*:mapper/**/*Mapper.xml
# # 加载全局的配置文件
# configLocation: classpath:mybatis/mybatis-config.xml
# PageHelper分页插件
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql
# Swagger配置
swagger:
# 是否开启swagger
enabled: true
# 请求前缀
pathMapping:
# 防止XSS攻击
xss:
# 过滤开关
enabled: true
# 排除链接(多个用逗号分隔)
excludes: /system/notice/*
# 匹配链接
urlPatterns: /system/*,/monitor/*,/tool/*
# elasticsearch配置
elasticsearch:
schema: http
address:
userName:
password:
connectTimeout: 10000
socketTimeout: 10000
connectionRequestTimeout: 10000
maxConnectNum: 100
maxConnectPerRoute: 100
# forest配置
forest:
backend: httpclient
retry-count: 1 # 请求失败后重试次数,默认为0次不重试
max-retry-interval: 1000 #重试间隔时间
connect-timeout: 3000 #链接超时时间
timeout: 3000 # 请求超时时间
wecome:
chatKey: finance_new
serverUrl: https://qyapi.weixin.qq.com/
weComePrefix: cgi-bin
noAccessTokenUrl:
- /gettoken
- /service/get_provider_token
- /wecom/chat/side/list
- /wecom/chat/item/list
- /wecom/chat/collection/addCollection
- /wecom/chat/collection/cancleCollection
- /wecom/chat/collection/list
needContactTokenUrl:
- /externalcontact/get_follow_user_list
- /externalcontact/add_contact_way
- /externalcontact/update_contact_way
- /externalcontact/add_corp_tag
- /externalcontact/get_corp_tag_list
- /externalcontact/del_corp_tag
- /externalcontact/edit_corp_tag
- /externalcontact/list
- /externalcontact/get
- /externalcontact/batch/get_by_user
- /externalcontact/groupchat/list
- /externalcontact/groupchat/get
- /externalcontact/mark_tag
- /externalcontact/transfer
- /externalcontact/groupchat/transfer
- /externalcontact/get_unassigned_list
- /externalcontact/send_welcome_msg
- /externalcontact/unionid_to_external_userid
- /externalcontact/add_msg_template
- /externalcontact/get_group_msg_result
- /externalcontact/get_user_behavior_data
- /externalcontact/groupchat/statistic
- /externalcontact/groupchat/statistic_group_by_day
fileUplodUrl: /media/upload,/media/uploadimg
needProviderTokenUrl:
- /service/get_login_info
needChatTokenUrl:
- /msgaudit/get_permit_user_list
- /msgaudit/check_single_agree
- /msgaudit/check_room_agree
- /msgaudit/groupchat/get
thirdAppUrl:
- /user/getuserinfo
- /get_jsapi_ticket
- /ticket/get
- /agent/list
- /message/send
- /agent/get
- /agent/set
needTenant:
- we_department
- we_user
- we_customer
- we_tag_group
#企微回调通知配置
callBack:
appIdOrCorpId: ww38152475d1bca752
token: Fm05d6n0NpuFrvOlgVxIbeSXtjgz
encodingAesKey: laevP8xCEG7BUqv5GuYXfg9HaRecxe4MU5F5cmnAI7n
# JS SDK 身份校验url
authorizeUrl: https://open.weixin.qq.com/connect/oauth2/authorize
# JS SDK身份校验成功后的redirect url
authorizeRedirectUrl: http://linkwechat.cn/mobile/#/task
weixin:
appid:
secret:
\ No newline at end of file \ No newline at end of file
...@@ -39,12 +39,6 @@ ...@@ -39,12 +39,6 @@
<dependency> <dependency>
<groupId>com.github.pagehelper</groupId> <groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId> <artifactId>pagehelper-spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<!-- 自定义验证注解 --> <!-- 自定义验证注解 -->
...@@ -266,6 +260,11 @@ ...@@ -266,6 +260,11 @@
<artifactId>spring-boot-starter-aop</artifactId> <artifactId>spring-boot-starter-aop</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.github.jsqlparser</groupId>
<artifactId>jsqlparser</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>
\ No newline at end of file \ No newline at end of file
...@@ -38,6 +38,10 @@ public class RuoYiConfig ...@@ -38,6 +38,10 @@ public class RuoYiConfig
private FileConfig file; private FileConfig file;
/**是否开启多租户*/
private boolean startTenant=false;
/**匿名访问的URL*/ /**匿名访问的URL*/
private String[] anonUrl; private String[] anonUrl;
...@@ -161,4 +165,12 @@ public class RuoYiConfig ...@@ -161,4 +165,12 @@ public class RuoYiConfig
public void setFile(FileConfig file) { public void setFile(FileConfig file) {
this.file = file; this.file = file;
} }
public boolean isStartTenant() {
return startTenant;
}
public void setStartTenant(boolean startTenant) {
this.startTenant = startTenant;
}
} }
...@@ -36,4 +36,7 @@ public class WeComeConfig { ...@@ -36,4 +36,7 @@ public class WeComeConfig {
/** 第三方自建应用得url*/ /** 第三方自建应用得url*/
private String[] thirdAppUrl; private String[] thirdAppUrl;
/**多租户相关表*/
private String[] needTenant=new String[]{};
} }
...@@ -120,7 +120,7 @@ public class Finance { ...@@ -120,7 +120,7 @@ public class Finance {
System.loadLibrary("libcurl"); System.loadLibrary("libcurl");
System.loadLibrary("WeWorkFinanceSdk"); System.loadLibrary("WeWorkFinanceSdk");
} else { } else {
System.load("/data/jenkins_home/app/projects/libWeWorkFinanceSdk_Java.so"); System.load("/app/projects/libWeWorkFinanceSdk_Java.so");
} }
} }
......
...@@ -30,6 +30,7 @@ import java.util.concurrent.atomic.AtomicLong; ...@@ -30,6 +30,7 @@ import java.util.concurrent.atomic.AtomicLong;
* @date 2020/12/2 16:01 * @date 2020/12/2 16:01
**/ **/
@Slf4j @Slf4j
public class FinanceUtils { public class FinanceUtils {
/** /**
* NewSdk返回的sdk指针 * NewSdk返回的sdk指针
...@@ -100,7 +101,7 @@ public class FinanceUtils { ...@@ -100,7 +101,7 @@ public class FinanceUtils {
} }
String content = Finance.GetContentFromSlice(slice); String content = Finance.GetContentFromSlice(slice);
JSONArray chatdataArr = JSONObject.parseObject(content).getJSONArray("chatdata"); JSONArray chatdataArr = JSONObject.parseObject(content).getJSONArray("chatdata");
log.info("开始执行数据解析:------------"); log.info("开始执行数据解析:------------"+content);
AtomicLong LocalSEQ = new AtomicLong(); AtomicLong LocalSEQ = new AtomicLong();
if (CollectionUtil.isNotEmpty(chatdataArr)) { if (CollectionUtil.isNotEmpty(chatdataArr)) {
chatdataArr.stream().map(data -> (JSONObject) data).forEach(data -> { chatdataArr.stream().map(data -> (JSONObject) data).forEach(data -> {
......
package com.linkwechat.framework.config; package com.linkwechat.framework.config;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler;
import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor;
import com.github.pagehelper.PageInterceptor; import com.github.pagehelper.PageInterceptor;
import com.linkwechat.common.config.RuoYiConfig;
import com.linkwechat.common.config.WeComeConfig;
import com.linkwechat.common.core.domain.entity.WeCorpAccount;
import com.linkwechat.common.utils.SecurityUtils;
import net.sf.jsqlparser.expression.Expression;
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.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import java.util.Arrays;
/** /**
* Mybatis支持*匹配扫描包 * Mybatis支持*匹配扫描包
...@@ -12,11 +25,65 @@ import org.springframework.context.annotation.Configuration; ...@@ -12,11 +25,65 @@ import org.springframework.context.annotation.Configuration;
* @author ruoyi * @author ruoyi
*/ */
@Configuration @Configuration
public class MyBatisPlusConfig public class MyBatisPlusConfig {
{ @Autowired
WeComeConfig weComeConfig;
@Autowired
RuoYiConfig ruoYiConfig;
@Bean @Bean
public Interceptor[] plugins() { public Interceptor[] plugins() {
if(ruoYiConfig.isStartTenant()){ //多租户相关
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new TenantLineInnerInterceptor(
new TenantLineHandler() {
// 获取租户 ID 值表达式,只支持单个 ID 值
@Override
public Expression getTenantId() {
try {
WeCorpAccount weCorpAccount
= SecurityUtils.getLoginUser().getUser().getWeCorpAccount();
if(null != weCorpAccount){
return new StringValue(weCorpAccount.getCorpId());
}
}catch (Exception e){
return null;
}
return null;
}
// 这是 default 方法,默认返回 false 表示所有表都需要拼多租户条件,
// 这里设置 role表不需要该条件
@Override
public boolean ignoreTable(String tableName) {
if(this.getTenantId()==null){
return true;
}
if (Arrays.asList(weComeConfig.getNeedTenant())
.contains(tableName)){
return false;
}
return true;
}
@Override
public String getTenantIdColumn() {
return "corp_id";
}
}));
return new Interceptor[]{interceptor,new PageInterceptor()
};
}else{
return new Interceptor[]{new PageInterceptor()}; return new Interceptor[]{new PageInterceptor()};
} }
}
} }
\ No newline at end of file \ No newline at end of file
package com.linkwechat.framework.web.service; package com.linkwechat.framework.web.service;
import cn.hutool.core.util.ArrayUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.SysUser;
import com.linkwechat.common.core.domain.entity.WeCorpAccount;
import com.linkwechat.common.core.domain.model.LoginUser; import com.linkwechat.common.core.domain.model.LoginUser;
import com.linkwechat.common.enums.UserStatus; import com.linkwechat.common.enums.UserStatus;
import com.linkwechat.common.exception.BaseException; import com.linkwechat.common.exception.BaseException;
import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.common.utils.StringUtils; import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.system.service.ISysRoleService;
import com.linkwechat.system.service.ISysUserService; import com.linkwechat.system.service.ISysUserService;
import com.linkwechat.wecom.domain.WeUser;
import com.linkwechat.wecom.service.IWeCorpAccountService;
import com.linkwechat.wecom.service.IWeUserService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -14,6 +26,8 @@ import org.springframework.security.core.userdetails.UserDetailsService; ...@@ -14,6 +26,8 @@ import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.stream.Collectors;
/** /**
* 用户验证处理 * 用户验证处理
* *
...@@ -31,6 +45,22 @@ public class UserDetailsServiceImpl implements UserDetailsService ...@@ -31,6 +45,22 @@ public class UserDetailsServiceImpl implements UserDetailsService
private SysPermissionService permissionService; private SysPermissionService permissionService;
@Autowired
private IWeCorpAccountService iWeCorpAccountService;
@Autowired
private ISysRoleService iSysRoleService;
@Autowired
private RuoYiConfig ruoYiConfig;
@Autowired
private IWeUserService iWeUserService;
...@@ -41,52 +71,54 @@ public class UserDetailsServiceImpl implements UserDetailsService ...@@ -41,52 +71,54 @@ public class UserDetailsServiceImpl implements UserDetailsService
if (StringUtils.isNull(user)) if (StringUtils.isNull(user))
{ {
log.info("登录用户:{} 不存在.", username); // //查询企业管理相关账号
WeCorpAccount weCorpByAccount = iWeCorpAccountService.getOne(new LambdaQueryWrapper<WeCorpAccount>().eq(WeCorpAccount::getCorpAccount, username)
.eq(WeCorpAccount::getDelFlag, Constants.NORMAL_CODE));
if(null != weCorpByAccount){
//注册到we_user表中
user=SysUser.builder()
.userName(weCorpByAccount.getCorpAccount())
.nickName(weCorpByAccount.getCompanyName())
.userType(Constants.USER_TYOE_CORP_ADMIN)
.roleIds(ArrayUtil.toArray(iSysRoleService.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();
} else{
//we_user表中去查询,如果该表为空则提示用户不存在,如果不为空,则将用户记录注册到系统用户表中
WeUser weUser
= new WeUser();
try {
weUser=iWeUserService.getOne(new LambdaQueryWrapper<WeUser>()
.eq(WeUser::getUserId,username));
}catch (Exception e){
e.printStackTrace();
}
if(null == weUser){
throw new BaseException("对不起,您的账号:" + username + " 不存在"); throw new BaseException("对不起,您的账号:" + username + " 不存在");
// //企业管理登录 }
// //查询企业管理相关账号 //注册到we_user表中
// WeCorpAccount weCorpByAccount = iWeCorpAccountService.findWeCorpByAccount(username); user=SysUser.builder()
// if(null != weCorpByAccount){ .userName(weUser.getUserId())
// //注册到we_user表中 .nickName(weUser.getName())
// user=SysUser.builder() .userType(Constants.USER_TYPE_WECOME)
// .userName(weCorpByAccount.getCropAccount()) .email(weUser.getEmail())
// .nickName(weCorpByAccount.getCompanyName()) .phonenumber(weUser.getMobile())
// .userType(Constants.USER_TYOE_CORP_ADMIN) .sex(weUser.getGender() ==0 ? "1": weUser.getGender() .toString())
// .roleIds(ArrayUtil.toArray(roleMapper.selectRoleList(SysRole.builder() .avatar(weUser.getAvatarMediaid())
// .roleKey(Constants.DEFAULT_WECOME_CORP_ADMIN) .roleIds(ArrayUtil.toArray(iSysRoleService.selectRoleList(SysRole.builder()
// .build()).stream().map(SysRole::getRoleId).collect(Collectors.toList()), Long.class)) .roleKey(Constants.DEFAULT_WECOME_ROLE_KEY)
// .password(SecurityUtils.encryptPassword(ruoYiConfig.getWeUserDefaultPwd())) .build()).stream().map(SysRole::getRoleId).collect(Collectors.toList()), Long.class))
// .build(); .password(SecurityUtils.encryptPassword(ruoYiConfig.getWeUserDefaultPwd()))
// } .build();
}
// else{
// if(user != null){
// //we_user表中去查询,如果该表为空则提示用户不存在,如果不为空,则将用户记录注册到系统用户表中 userService.insertUser(
// WeUser weUser user
// = iWeUserService.getById(username); );
// if(null == weUser){ }
// log.info("登录用户:{} 不存在.", username);
// throw new UsernameNotFoundException("登录用户:" + username + " 不存在");
// }
//
// //注册到we_user表中
// user=SysUser.builder()
// .userName(weUser.getUserId())
// .nickName(weUser.getName())
// .userType(Constants.USER_TYPE_WECOME)
// .email(weUser.getEmail())
// .phonenumber(weUser.getMobile())
// .sex(weUser.getGender() ==0 ? "1": weUser.getGender() .toString())
// .avatar(weUser.getAvatarMediaid())
// .roleIds(ArrayUtil.toArray(roleMapper.selectRoleList(SysRole.builder()
// .roleKey(Constants.DEFAULT_WECOME_ROLE_KEY)
// .build()).stream().map(SysRole::getRoleId).collect(Collectors.toList()), Long.class))
// .password(SecurityUtils.encryptPassword(ruoYiConfig.getWeUserDefaultPwd()))
// .build();
// }
// userService.insertUser(
// user
// );
} }
else if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) else if (UserStatus.DELETED.getCode().equals(user.getDelFlag()))
{ {
...@@ -99,12 +131,14 @@ public class UserDetailsServiceImpl implements UserDetailsService ...@@ -99,12 +131,14 @@ public class UserDetailsServiceImpl implements UserDetailsService
throw new BaseException("对不起,您的账号:" + username + " 已停用"); throw new BaseException("对不起,您的账号:" + username + " 已停用");
} }
//当前登录用户为企业管理,设置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.getOne(new LambdaQueryWrapper<WeCorpAccount>().eq(WeCorpAccount::getCorpAccount, username)
// ); .eq(WeCorpAccount::getDelFlag, Constants.NORMAL_CODE))
// } );
}
return createLoginUser(user); return createLoginUser(user);
......
...@@ -23,6 +23,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -23,6 +23,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="updateBy" column="update_by" /> <result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" /> <result property="updateTime" column="update_time" />
<result property="remark" column="remark" /> <result property="remark" column="remark" />
<result property="userType" column="user_type"/>
<association property="dept" column="dept_id" javaType="SysDept" resultMap="deptResult" /> <association property="dept" column="dept_id" javaType="SysDept" resultMap="deptResult" />
<collection property="roles" javaType="java.util.List" resultMap="RoleResult" /> <collection property="roles" javaType="java.util.List" resultMap="RoleResult" />
</resultMap> </resultMap>
...@@ -47,7 +48,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -47,7 +48,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<sql id="selectUserVo"> <sql id="selectUserVo">
select u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, select u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
d.dept_id, d.parent_id, d.dept_name, d.order_num, d.leader, d.status as dept_status, d.dept_id, d.parent_id, d.dept_name, d.order_num, d.leader, d.status as dept_status,u.user_type,
r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status
from sys_user u from sys_user u
left join sys_dept d on u.dept_id = d.dept_id left join sys_dept d on u.dept_id = d.dept_id
......
...@@ -52,61 +52,61 @@ public class ConversationArchiveVo { ...@@ -52,61 +52,61 @@ public class ConversationArchiveVo {
private String msgType; private String msgType;
@ApiModelProperty("文本消息内容") @ApiModelProperty("文本消息内容")
private Content text; private Content text=new Content();
@ApiModelProperty("图片消息内容") @ApiModelProperty("图片消息内容")
private Content image; private Content image=new Content();
@ApiModelProperty("撤回消息") @ApiModelProperty("撤回消息")
private Content revoke; private Content revoke=new Content();
@ApiModelProperty("同意会话聊天内容") @ApiModelProperty("同意会话聊天内容")
private Content disagree; private Content disagree=new Content();
@ApiModelProperty("语音内容") @ApiModelProperty("语音内容")
private Content voice; private Content voice=new Content();
@ApiModelProperty("视频内容") @ApiModelProperty("视频内容")
private Content video; private Content video=new Content();
@ApiModelProperty("名片") @ApiModelProperty("名片")
private Content card; private Content card=new Content();
@ApiModelProperty("位置") @ApiModelProperty("位置")
private Content location; private Content location=new Content();
@ApiModelProperty("表情") @ApiModelProperty("表情")
private Content emotion; private Content emotion=new Content();
@ApiModelProperty("文件") @ApiModelProperty("文件")
private Content file; private Content file=new Content();
@ApiModelProperty("链接") @ApiModelProperty("链接")
private Content link; private Content link=new Content();
@ApiModelProperty("小程序消息") @ApiModelProperty("小程序消息")
private Content weApp; private Content weApp=new Content();
@ApiModelProperty("会话记录消息") @ApiModelProperty("会话记录消息")
private Content chatReCord; private Content chatReCord=new Content();
@ApiModelProperty("待办消息") @ApiModelProperty("待办消息")
private Content todo; private Content todo=new Content();
@ApiModelProperty("投票消息") @ApiModelProperty("投票消息")
private Content vote; private Content vote=new Content();
@ApiModelProperty("填表消息") @ApiModelProperty("填表消息")
private Collect collect; private Collect collect=new Collect();
@ApiModelProperty("红包消息") @ApiModelProperty("红包消息")
private RedPacket redPacket; private RedPacket redPacket=new RedPacket();
@ApiModelProperty("会议邀请消息") @ApiModelProperty("会议邀请消息")
private Meeting meeting; private Meeting meeting=new Meeting();
@ApiModelProperty("在线文档消息") @ApiModelProperty("在线文档消息")
private Content doc; private Content doc=new Content();
@ApiModelProperty("MarkDown格式消息/图文消息") @ApiModelProperty("MarkDown格式消息/图文消息")
private JSONObject info; private JSONObject info;
...@@ -118,7 +118,7 @@ public class ConversationArchiveVo { ...@@ -118,7 +118,7 @@ public class ConversationArchiveVo {
private JSONObject meetingVoiceCall; private JSONObject meetingVoiceCall;
@ApiModelProperty("日程消息") @ApiModelProperty("日程消息")
private Calendar calendar; private Calendar calendar=new Calendar();
@ApiModel @ApiModel
@Data @Data
......
package com.linkwechat.wecom.service; package com.linkwechat.wecom.service;
import com.linkwechat.common.core.domain.entity.WeCorpAccount;
import com.linkwechat.wecom.domain.WeApp; import com.linkwechat.wecom.domain.WeApp;
/** /**
...@@ -25,5 +26,5 @@ public interface IWeAccessTokenService { ...@@ -25,5 +26,5 @@ public interface IWeAccessTokenService {
public void removeToken(); public void removeToken(WeCorpAccount wxCorpAccount);
} }
\ No newline at end of file \ No newline at end of file
package com.linkwechat.wecom.service.impl; package com.linkwechat.wecom.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.redis.RedisCache; import com.linkwechat.common.core.redis.RedisCache;
import com.linkwechat.common.exception.wecom.WeComException; import com.linkwechat.common.exception.wecom.WeComException;
import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.common.utils.StringUtils; import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.wecom.client.WeAccessTokenClient; import com.linkwechat.wecom.client.WeAccessTokenClient;
import com.linkwechat.wecom.domain.WeApp; import com.linkwechat.wecom.domain.WeApp;
...@@ -42,6 +44,10 @@ public class WeAccessTokenServiceImpl implements IWeAccessTokenService { ...@@ -42,6 +44,10 @@ public class WeAccessTokenServiceImpl implements IWeAccessTokenService {
private IWeAppService iWeAppService; private IWeAppService iWeAppService;
@Autowired
private RuoYiConfig ruoYiConfig;
/** /**
* 获取通用accessToken * 获取通用accessToken
...@@ -143,6 +149,68 @@ public class WeAccessTokenServiceImpl implements IWeAccessTokenService { ...@@ -143,6 +149,68 @@ public class WeAccessTokenServiceImpl implements IWeAccessTokenService {
private String findAccessToken(String accessTokenKey){ private String findAccessToken(String accessTokenKey){
return ruoYiConfig.isStartTenant()?findAccessTokenForTenant(accessTokenKey):findAccessTokenForNoTenant(accessTokenKey);
}
//多租户环境下获取token
private String findAccessTokenForTenant(String accessTokenKey){
WeCorpAccount wxCorpAccount
= SecurityUtils.getLoginUser().getUser().getWeCorpAccount();
if(null == wxCorpAccount){
//返回错误异常,让用户绑定企业id相关信息
throw new WeComException("无可用的corpid和secret");
}
String weAccessToken =redisCache.getCacheObject(accessTokenKey+"::"+wxCorpAccount.getCorpId());
//为空,请求微信服务器同时缓存到redis中
if(StringUtils.isEmpty(weAccessToken)){
String token="";
Long expires_in=null;
if(WeConstans.WE_COMMON_ACCESS_TOKEN.equals(accessTokenKey) || WeConstans.WE_CONTACT_ACCESS_TOKEN.equals(accessTokenKey)){
WeAccessTokenDtoDto weAccessTokenDtoDto = accessTokenClient.getToken(wxCorpAccount.getCorpId(),
WeConstans.WE_COMMON_ACCESS_TOKEN.equals(accessTokenKey) ? wxCorpAccount.getCorpSecret() : wxCorpAccount.getContactSecret());
token=weAccessTokenDtoDto.getAccess_token();
expires_in=weAccessTokenDtoDto.getExpires_in();
}else if(WeConstans.WE_PROVIDER_ACCESS_TOKEN.equals(accessTokenKey)){
WeAccessTokenDtoDto providerToken = accessTokenClient.getProviderToken(wxCorpAccount.getCorpId(), wxCorpAccount.getProviderSecret());
token=providerToken.getProvider_access_token();
expires_in=providerToken.getExpires_in();
}else if (WeConstans.WE_CHAT_ACCESS_TOKEN.equals(accessTokenKey)){
WeAccessTokenDtoDto weAccessTokenDtoDto = accessTokenClient.getToken(wxCorpAccount.getCorpId(),wxCorpAccount.getChatSecret());
token=weAccessTokenDtoDto.getAccess_token();
expires_in=weAccessTokenDtoDto.getExpires_in();
}else if (WeConstans.WE_AGENT_ACCESS_TOKEN.equals(accessTokenKey)){
WeAccessTokenDtoDto weAccessTokenDtoDto = accessTokenClient.getToken(wxCorpAccount.getCorpId(),wxCorpAccount.getAgentSecret());
token=weAccessTokenDtoDto.getAccess_token();
expires_in=weAccessTokenDtoDto.getExpires_in();
}
if(StringUtils.isNotEmpty(token)){
redisCache.setCacheObject(accessTokenKey+"::"+wxCorpAccount.getCorpId(),token,expires_in.intValue(), TimeUnit.SECONDS);
weAccessToken = token;
}
}
return weAccessToken;
}
//非多租户环境下获取token
private String findAccessTokenForNoTenant(String accessTokenKey){
String weAccessToken =redisCache.getCacheObject(accessTokenKey); String weAccessToken =redisCache.getCacheObject(accessTokenKey);
//为空,请求微信服务器同时缓存到redis中 //为空,请求微信服务器同时缓存到redis中
...@@ -190,11 +258,18 @@ public class WeAccessTokenServiceImpl implements IWeAccessTokenService { ...@@ -190,11 +258,18 @@ public class WeAccessTokenServiceImpl implements IWeAccessTokenService {
* 清空redis中的相关token * 清空redis中的相关token
*/ */
@Override @Override
public void removeToken() { public void removeToken(WeCorpAccount wxCorpAccount) {
if(ruoYiConfig.isStartTenant()){
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());
}else{
redisCache.deleteObject(WeConstans.WE_COMMON_ACCESS_TOKEN); redisCache.deleteObject(WeConstans.WE_COMMON_ACCESS_TOKEN);
redisCache.deleteObject(WeConstans.WE_CONTACT_ACCESS_TOKEN); redisCache.deleteObject(WeConstans.WE_CONTACT_ACCESS_TOKEN);
redisCache.deleteObject(WeConstans.WE_PROVIDER_ACCESS_TOKEN); redisCache.deleteObject(WeConstans.WE_PROVIDER_ACCESS_TOKEN);
} }
}
} }
...@@ -2,6 +2,7 @@ package com.linkwechat.wecom.service.impl; ...@@ -2,6 +2,7 @@ package com.linkwechat.wecom.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
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.WeCorpAccount; import com.linkwechat.common.core.domain.entity.WeCorpAccount;
...@@ -28,6 +29,9 @@ public class WeCorpAccountServiceImpl extends ServiceImpl<WeCorpAccountMapper,We ...@@ -28,6 +29,9 @@ public class WeCorpAccountServiceImpl extends ServiceImpl<WeCorpAccountMapper,We
@Autowired @Autowired
private IWeAccessTokenService iWeAccessTokenService; private IWeAccessTokenService iWeAccessTokenService;
@Autowired
private RuoYiConfig ruoYiConfig;
/** /**
* 修改企业id相关配置 * 修改企业id相关配置
...@@ -41,8 +45,7 @@ public class WeCorpAccountServiceImpl extends ServiceImpl<WeCorpAccountMapper,We ...@@ -41,8 +45,7 @@ public class WeCorpAccountServiceImpl extends ServiceImpl<WeCorpAccountMapper,We
if(this.updateById(wxCorpAccount)){ if(this.updateById(wxCorpAccount)){
iWeAccessTokenService.removeToken(wxCorpAccount);
iWeAccessTokenService.removeToken();
} }
...@@ -58,7 +61,7 @@ public class WeCorpAccountServiceImpl extends ServiceImpl<WeCorpAccountMapper,We ...@@ -58,7 +61,7 @@ public class WeCorpAccountServiceImpl extends ServiceImpl<WeCorpAccountMapper,We
@Override @Override
public WeCorpAccount findValidWeCorpAccount() { public WeCorpAccount findValidWeCorpAccount() {
return this.getOne(new LambdaQueryWrapper<WeCorpAccount>() return ruoYiConfig.isStartTenant()? WeCorpAccount.builder().build():this.getOne(new LambdaQueryWrapper<WeCorpAccount>()
.eq(WeCorpAccount::getDelFlag,Constants.NORMAL_CODE) .eq(WeCorpAccount::getDelFlag,Constants.NORMAL_CODE)
.eq(WeCorpAccount::getStatus,Constants.NORMAL_CODE)); .eq(WeCorpAccount::getStatus,Constants.NORMAL_CODE));
} }
...@@ -75,8 +78,7 @@ public class WeCorpAccountServiceImpl extends ServiceImpl<WeCorpAccountMapper,We ...@@ -75,8 +78,7 @@ public class WeCorpAccountServiceImpl extends ServiceImpl<WeCorpAccountMapper,We
if(Constants.SERVICE_RETURN_SUCCESS_CODE<returnCode){ if(Constants.SERVICE_RETURN_SUCCESS_CODE<returnCode){
iWeAccessTokenService.removeToken(WeCorpAccount.builder().build());
iWeAccessTokenService.removeToken();
} }
......
...@@ -39,7 +39,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -39,7 +39,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="name != null and name != ''"> and user_name like concat('%', #{name}, '%')</if> <if test="name != null and name != ''"> and user_name like concat('%', #{name}, '%')</if>
<if test="alias != null and alias != ''"> and alias = #{alias}</if> <if test="alias != null and alias != ''"> and alias = #{alias}</if>
<if test="userId != null and userId != ''"> and user_id = #{userId}</if> <if test="userId != null and userId != ''"> and user_id = #{userId}</if>
<if test="isActivate != null"> and is_activate = #{isActivate}</if>
<if test="gender != null "> and gender = #{gender}</if> <if test="gender != null "> and gender = #{gender}</if>
<if test="mobile != null and mobile != ''"> and mobile = #{mobile}</if> <if test="mobile != null and mobile != ''"> and mobile = #{mobile}</if>
<if test="email != null and email != ''"> and email = #{email}</if> <if test="email != null and email != ''"> and email = #{email}</if>
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
<bitwalker.version>1.19</bitwalker.version> <bitwalker.version>1.19</bitwalker.version>
<swagger.version>2.9.2</swagger.version> <swagger.version>2.9.2</swagger.version>
<kaptcha.version>2.3.2</kaptcha.version> <kaptcha.version>2.3.2</kaptcha.version>
<pagehelper.boot.version>1.2.7</pagehelper.boot.version> <pagehelper.boot.version>1.3.0</pagehelper.boot.version>
<fastjson.version>1.2.73</fastjson.version> <fastjson.version>1.2.73</fastjson.version>
<oshi.version>3.9.1</oshi.version> <oshi.version>3.9.1</oshi.version>
<commons.io.version>2.5</commons.io.version> <commons.io.version>2.5</commons.io.version>
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
<netty-version>4.1.49.Final</netty-version> <netty-version>4.1.49.Final</netty-version>
<nacos.version>2.2.5.RELEASE</nacos.version> <nacos.version>2.2.5.RELEASE</nacos.version>
<jaxb.version>2.3.1</jaxb.version> <jaxb.version>2.3.1</jaxb.version>
<jsqlparser.version>4.0</jsqlparser.version>
</properties> </properties>
<!-- 依赖声明 --> <!-- 依赖声明 -->
...@@ -83,6 +84,12 @@ ...@@ -83,6 +84,12 @@
<groupId>com.github.pagehelper</groupId> <groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId> <artifactId>pagehelper-spring-boot-starter</artifactId>
<version>${pagehelper.boot.version}</version> <version>${pagehelper.boot.version}</version>
<exclusions>
<exclusion>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<!-- 获取系统信息 --> <!-- 获取系统信息 -->
...@@ -283,6 +290,13 @@ ...@@ -283,6 +290,13 @@
<artifactId>spring-boot-starter-aop</artifactId> <artifactId>spring-boot-starter-aop</artifactId>
<version>${springboot.version}</version> <version>${springboot.version}</version>
</dependency> </dependency>
<dependency>
<groupId>com.github.jsqlparser</groupId>
<artifactId>jsqlparser</artifactId>
<version>${jsqlparser.version}</version>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!