Commit a0e8d2f3 by 水库浪子 Committed by Gitee

Merge branch 'multi-tenant-lw' of gitee.com:LinkWeChat/link-wechat into back_end_dev

2 parents 7f4af205 4530fae1
Showing 27 changed files with 528 additions and 160 deletions
......@@ -8,9 +8,9 @@
<div align="center">
![GVP Stars](http://img.shields.io/badge/GPV%20Stars-700+-yellow)
![GVP Forks](http://img.shields.io/badge/GPV%20Forks-200+-yellow)
![license](http://img.shields.io/badge/license-GPL%203.0-green)
[![star](https://gitee.com/LinkWeChat/link-wechat/badge/star.svg?theme=gvp)](https://gitee.com/LinkWeChat/link-wechat/stargazers)
[![fork](https://gitee.com/LinkWeChat/link-wechat/badge/fork.svg?theme=gvp)](https://gitee.com/LinkWeChat/link-wechat/members)
[![license](http://img.shields.io/badge/license-GPL%203.0-green)](https://gitee.com/LinkWeChat/link-wechat/blob/master/LICENSE)
</div>
......@@ -18,9 +18,20 @@
<p></p>
<p></p>
<p></p>
<p></p>
<p></p>
<p></p>
<p></p>
![输入图片说明](https://images.gitee.com/uploads/images/2020/1231/233450_65d03349_1480777.png "LinkWeChat 企业微信私域流量营销专家-V1.0.4_00.png")
---
**如果您觉得我们的开源项目很有帮助,请帮忙点击右上方的 :star: Star ,您的认可就是我们最大的动力,谢谢支持!:heart:**
---
### 平台简介
> LinkWeChat, Link to WeChat
......@@ -213,13 +224,13 @@ com.linkwechat
#### 在线体验
演示地址:http://106.13.201.219/
演示地址:http://demo.linkwechat.cn
演示账号/密码:test/123456
演示账号/密码:Wecome/123456
#### 开发进度
![输入图片说明](https://images.gitee.com/uploads/images/2020/1231/233603_09dc4ac4_1480777.png "LinkWeChat 1.0.png")
![输入图片说明](https://images.gitee.com/uploads/images/2021/0315/205221_36f5b3f3_1480777.png "LinkWeChat 1.0.png")
### 联系作者加入群
......@@ -246,4 +257,64 @@ com.linkwechat
### 版权声明
LinkWeChat 开源版遵循 [GPL-3.0](https://gitee.com/LinkWeChat/link-wechat/blob/master/LICENSE) 开源协议发布,并提供免费使用,但 **绝不允许修改后和衍生的代码做为闭源的商业软件发布和销售!**
\ No newline at end of file
LinkWeChat 开源版遵循 [GPL-3.0](https://gitee.com/LinkWeChat/link-wechat/blob/master/LICENSE) 开源协议发布,并提供免费使用,但 **绝不允许修改后和衍生的代码做为闭源的商业软件发布和销售!**
### 捐赠支持
#### 来一杯卡布奇诺
如果您觉得我们的开源项目 `LinkWeChat` 对您有帮助,那就请项目开发者们来一杯卡布奇诺吧!当前我们接受来自于**微信**、**支付宝**或者**码云**的捐赠,请在捐赠时备注自己的昵称或附言。
您的捐赠将用于支付该项目的一些费用支出,并激励开发者们以便更好的推动项目的发展,同时欢迎捐赠**公网服务器**用于提高在线演示系统体验。
![输入图片说明](https://images.gitee.com/uploads/images/2021/0222/221344_727a0e80_1480777.png "image-20210222214357456.png")
#### 长期捐赠
如果您是企业的经营者并且有计划将 `LinkWeChat` 用在公司的经营产品中,欢迎进行长期捐赠。长期捐赠有商业上的益处有:
* 积极响应,快速维护,及时更新;
* 企业名称、Logo 及官网链接将长期展示在开源仓库、`LinkWeChat` 官网及宣发材料中;
* 捐赠金额同比例抵扣未来 `LinkWeChat` 的付费产品价格。
如果您对长期赞助 `LinkWeChat` 团队感兴趣,或者有其他好想法,欢迎联系开发团队微信 `sxjiangdongqin`,或发送邮件到 iamxiarui@foxmail.com。
#### 捐赠记录
`LinkWeChat` 全体开发团队感谢以下全部小伙伴们的赞助(排名不分先后):
| 昵称 | 金额 | 渠道 | 时间 | 附言 |
| :------: | :-----: | :--: | :-----------------: | :----------------: |
| yang | ¥10.00 | 码云 | 2021-02-22 22:08:59 | 感谢您的开源项目! |
| 水库浪子 | ¥1.00 | 码云 | 2021-02-22 22:09:03 | 感谢您的开源项目! |
| 楼* | ¥166.60 | 微信 | 2021-02-22 22:27:25 | 希望这个好项目能长久发展 |
| joygezxp | ¥66.60 | 微信 | 2021-02-22 22:39:41 | 愿项目一路666 |
| iamxiarui | ¥10.00 | 微信 | 2021-02-22 22:37:52 | 坚持开源不容易 |
| godricV | ¥10.00 | 微信 | 2021-02-22 22:28:55 | 感谢您的开源项目! |
| *标 | ¥20.00 | 微信 | 2021-03-05 16:03:19 | 感谢您的开源项目! |
| *涯 | ¥30.00 | 微信 | 2021-03-09 12:14:02 | 加油,感谢开源! |
| *魂 | ¥30.00 | 微信 | 2021-03-11 10:52:47 | 感谢开源供大家学习 |
| *J | ¥10.00 | 微信 | 2021-03-12 14:20:22 | 感谢开源供大家学习 |
| 杨*源 | ¥10.00 | 码云 | 2021-03-23 11:07:22 | 期待月底的大更新 |
| 骆*升 | ¥66.66 | 支付宝 | 2021-03-23 11:31:58 | 感谢开源供大家学习 |
| 曲*旭 | ¥20.00 | 码云 | 2021-03-23 11:31:58 | 感谢您的开源项目! |
| 郑* | ¥ 50.00 | 码云 | 2021-03-23 11:31:58 | 虽然之前做过类似的,还是感谢下开源和分享的奉献精神 |
| *喵 | ¥ 66.00 | 微信 | 2021-03-24 11:06:31 | 感谢您的开源项目! |
| q*s | ¥ 50.00 | 微信 | 2021-03-29 19:57:49 | 感谢您的开源项目! |
| *海 | ¥ 1.00 | 微信 | 2021-03-30 10:47:03 | 感谢您的开源项目! |
| m*r | ¥ 50.00 | 微信 | 2021-03-30 17:55:30 | 感谢您的开源项目! |
| *祺 | ¥ 20.00 | 支付宝 | 2021-03-30 19:03:59 | 感谢您的开源项目! |
| *桥 | ¥ 66.66 | 支付宝 | 2021-04-07 16:38:31 | 祝项目一路 666 |
| *力 | ¥ 66.00 | 微信 | 2021-04-09 10:30:11 | 支持开源 |
`LinkWeChat` 全体开发团队感谢以下全部合作伙伴的服务器赞助(排名不分先后):
| 公司/个人名称 | 服务器 |
| :------: | :-----: |
| 上海六感科技有限公司 | 八核 16G 服务器一台 |
| Happy | 两核 8G 服务器一台 |
| 平山阑槛倚晴空 | 两核 4G 服务器一台 |
---
**如果您觉得我们的开源项目很有帮助,请帮忙点击右上方的 :star: Star ,您的认可就是我们最大的动力,谢谢支持!:heart:**
\ No newline at end of file
package com.linkwechat.web.controller.system;
import cn.hutool.core.collection.CollectionUtil;
import com.linkwechat.common.constant.Constants;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.domain.entity.SysMenu;
......@@ -12,7 +13,7 @@ import com.linkwechat.framework.web.service.SysPermissionService;
import com.linkwechat.framework.web.service.TokenService;
import com.linkwechat.system.service.ISysMenuService;
import com.linkwechat.wecom.client.WeAccessTokenClient;
import com.linkwechat.wecom.domain.WeCorpAccount;
import com.linkwechat.common.core.domain.entity.WeCorpAccount;
import com.linkwechat.wecom.domain.dto.WeLoginUserInfoDto;
import com.linkwechat.wecom.service.IWeCorpAccountService;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -53,6 +54,12 @@ public class SysLoginController
private WeAccessTokenClient weAccessTokenClient;
// @Autowired
// private IWeGroupCodeService weGroupCodeService;
/**
* 登录方法
*
......@@ -86,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);
......@@ -121,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();
}
......@@ -155,18 +164,26 @@ public class SysLoginController
/**
* 租户登录
* 通过企业id和企业密钥登录
* @param corpId
* @param corpSecret
* @return
*/
@GetMapping("/tenantLogin")
public AjaxResult tenantLogin(String corpId,String corpSecret){
AjaxResult ajax = AjaxResult.success();
@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 ajax;
return AjaxResult.success(
loginService.noPwdLogin(weCorpAccounts.get(0).getCropAccount())
);
}
}
package com.linkwechat.web.controller.wecom;
import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.constant.HttpStatus;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.wecom.domain.WeCorpAccount;
import com.linkwechat.common.core.domain.entity.WeCorpAccount;
import com.linkwechat.wecom.service.IWeCorpAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
......
#spring.cloud.nacos.config.server-addr=
#spring.cloud.nacos.config.namespace=
#spring.application.name=
#spring.cloud.nacos.config.file-extension=
\ No newline at end of file
spring.cloud.nacos.config.server-addr=${NACOS_SERVER:119.45.28.29:10848}
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
......@@ -39,12 +39,6 @@
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- 自定义验证注解 -->
......@@ -260,6 +254,12 @@
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.68</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.github.jsqlparser</groupId>-->
<!-- <artifactId>jsqlparser</artifactId>-->
<!-- </dependency>-->
</dependencies>
</project>
\ No newline at end of file
......@@ -36,4 +36,7 @@ public class WeComeConfig {
/** 第三方自建应用得url*/
private String[] thirdAppUrl;
/**多租户相关表*/
private String[] needTenant=new String[]{};
}
......@@ -2,7 +2,7 @@ package com.linkwechat.common.constant;
/**
* 通用常量信息
*
*
* @author ruoyi
*/
public class Constants
......@@ -61,7 +61,7 @@ public class Constants
* 登录用户 redis key
*/
public static final String LOGIN_TOKEN_KEY = "login_tokens:";
/**
* 防重提交 redis key
*/
......@@ -151,18 +151,17 @@ public class Constants
public static final String USER_TYPE_WECOME="11";
/** 企业管理 */
public static final String USER_TYOE_CORP_ADMIN="22";
/** 企业微信用户系统中默认用户 */
public static final String DEFAULT_WECOME_ROLE_KEY="WeCome";
/** 企业微信用户系统中默认用户 */
public static final String DEFAULT_WECOME_CORP_ADMIN="CROP_ADMIN_ROLE";
/**完成待办*/
public static final String HANDLE_SUCCESS="1";
}
......@@ -21,7 +21,7 @@ import java.util.List;
/**
* 用户对象 sys_user
*
*
* @author ruoyi
*/
@Data
......@@ -88,8 +88,8 @@ public class SysUser extends BaseEntity
/** 部门对象 */
@Excels({
@Excel(name = "部门名称", targetAttr = "deptName", type = Type.EXPORT),
@Excel(name = "部门负责人", targetAttr = "leader", type = Type.EXPORT)
@Excel(name = "部门名称", targetAttr = "deptName", type = Type.EXPORT),
@Excel(name = "部门负责人", targetAttr = "leader", type = Type.EXPORT)
})
private SysDept dept;
......@@ -105,6 +105,9 @@ public class SysUser extends BaseEntity
/** 是否具有有效得cropId */
private boolean validCropId=false;
private WeCorpAccount weCorpAccount;
public SysUser()
{
......@@ -211,7 +214,7 @@ public class SysUser extends BaseEntity
this.avatar = avatar;
}
@JsonIgnore
@JsonIgnore
@JsonProperty
public String getPassword()
{
......@@ -316,26 +319,26 @@ public class SysUser extends BaseEntity
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("userId", getUserId())
.append("deptId", getDeptId())
.append("userName", getUserName())
.append("nickName", getNickName())
.append("email", getEmail())
.append("phonenumber", getPhonenumber())
.append("sex", getSex())
.append("avatar", getAvatar())
.append("password", getPassword())
.append("salt", getSalt())
.append("status", getStatus())
.append("delFlag", getDelFlag())
.append("loginIp", getLoginIp())
.append("loginDate", getLoginDate())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.append("remark", getRemark())
.append("dept", getDept())
.toString();
.append("userId", getUserId())
.append("deptId", getDeptId())
.append("userName", getUserName())
.append("nickName", getNickName())
.append("email", getEmail())
.append("phonenumber", getPhonenumber())
.append("sex", getSex())
.append("avatar", getAvatar())
.append("password", getPassword())
.append("salt", getSalt())
.append("status", getStatus())
.append("delFlag", getDelFlag())
.append("loginIp", getLoginIp())
.append("loginDate", getLoginDate())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.append("remark", getRemark())
.append("dept", getDept())
.toString();
}
}
package com.linkwechat.wecom.domain;
package com.linkwechat.common.core.domain.entity;
import com.linkwechat.common.core.domain.BaseEntity;
import com.linkwechat.common.utils.SnowFlakeUtil;
......@@ -14,7 +14,7 @@ import javax.validation.constraints.NotBlank;
/**
* 企业id相关配置对象 wx_corp_account
*
*
* @author ruoyi
* @date 2020-08-24
*/
......@@ -76,4 +76,8 @@ public class WeCorpAccount extends BaseEntity
@ApiModelProperty("客户流失通知开关 0:关闭 1:开启")
private String customerChurnNoticeSwitch = new String("0");
@ApiModelProperty("企业管理员账号")
private String cropAccount;
}
......@@ -87,4 +87,7 @@ public class SecurityUtils
{
return userId != null && 1L == userId;
}
}
package com.linkwechat.framework.config;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor;
import com.github.pagehelper.PageInterceptor;
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.Arrays;
/**
* Mybatis支持*匹配扫描包
......@@ -14,9 +27,103 @@ import org.springframework.context.annotation.Configuration;
@Configuration
public class MyBatisPlusConfig
{
@Autowired
WeComeConfig weComeConfig;
//
// @Bean
// public MybatisPlusInterceptor mybatisPlusInterceptor() {
// MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
// // 如果用了分页插件注意先 add TenantLineInnerInterceptor 再 add PaginationInnerInterceptor
// // 用了分页插件必须设置 MybatisConfiguration#useDeprecatedExecutor = false
// // interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
//
// interceptor.addInnerInterceptor(new TenantLineInnerInterceptor(
// new TenantLineHandler() {
// // 获取租户 ID 值表达式,只支持单个 ID 值
// @Override
// public Expression getTenantId() {
//
// WeCorpAccount weCorpAccount
// = SecurityUtils.getLoginUser().getUser().getWeCorpAccount();
// if(null != weCorpAccount){
// return new StringValue(weCorpAccount.getCorpId());
// }
//
// return null;
// }
// // 这是 default 方法,默认返回 false 表示所有表都需要拼多租户条件,
// // 这里设置 role表不需要该条件
// @Override
// public boolean ignoreTable(String tableName) {
//
// if (Arrays.asList(weComeConfig.getNeedTenant())
// .contains(tableName)){
// return false;
// }
// return true;
// }
//
// @Override
// public String getTenantIdColumn() {
// return "corp_id";
// }
// }));
// interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
// return interceptor;
// }
// @Bean
// public ConfigurationCustomizer configurationCustomizer() {
// return configuration -> configuration.setUseDeprecatedExecutor(false);
// }
@Bean
public Interceptor[] plugins() {
return new Interceptor[]{new PageInterceptor()};
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new TenantLineInnerInterceptor(
new TenantLineHandler() {
// 获取租户 ID 值表达式,只支持单个 ID 值
@Override
public Expression getTenantId() {
WeCorpAccount weCorpAccount
= SecurityUtils.getLoginUser().getUser().getWeCorpAccount();
if(null != weCorpAccount){
return new StringValue(weCorpAccount.getCorpId());
}
return null;
}
// 这是 default 方法,默认返回 false 表示所有表都需要拼多租户条件,
// 这里设置 role表不需要该条件
@Override
public boolean ignoreTable(String tableName) {
if (Arrays.asList(weComeConfig.getNeedTenant())
.contains(tableName)){
return false;
}
return true;
}
@Override
public String getTenantIdColumn() {
return "corp_id";
}
}));
//
return new Interceptor[]{interceptor,new PageInterceptor()
};
}
}
\ No newline at end of file
......@@ -130,6 +130,13 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
.antMatchers("/wecom/community/h5/**").anonymous()
//微信授权接口
.antMatchers("/weixin/auth/**").anonymous()
// .antMatchers("/common/uploadFile2Cos").anonymous()
.antMatchers("/wecom/material/temporaryMaterialMediaId").anonymous()
.antMatchers("/wecom/portrait/**").anonymous()
.antMatchers("/wecom/findAddaddEmployes").anonymous()
.antMatchers("/corpLogin").anonymous()
// 除上面外的所有请求全部需要鉴权认证
.anyRequest().authenticated()
.and()
......
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;
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.enums.UserStatus;
import com.linkwechat.common.exception.BaseException;
......@@ -12,7 +14,7 @@ import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.system.mapper.SysRoleMapper;
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.LoggerFactory;
......@@ -51,35 +53,58 @@ public class UserDetailsServiceImpl implements UserDetailsService
private SysRoleMapper roleMapper;
@Autowired
private IWeCorpAccountService iWeCorpAccountService;
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException
{
SysUser user = userService.selectUserByUserName(username);
System.out.println(user.getUserType());
if (StringUtils.isNull(user))
{
//we_user表中去查询,如果该表为空则提示用户不存在,如果不为空,则将用户记录注册到系统用户表中
WeUser weUser
= iWeUserService.getById(username);
if(null == weUser){
log.info("登录用户:{} 不存在.", username);
throw new UsernameNotFoundException("登录用户:" + username + " 不存在");
//企业管理登录
//查询企业管理相关账号
WeCorpAccount weCorpByAccount = iWeCorpAccountService.findWeCorpByAccount(username);
if(null != weCorpByAccount){
//注册到we_user表中
user= SysUser.builder()
.userName(weCorpByAccount.getCropAccount())
.nickName(weCorpByAccount.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();
}
//注册到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();
// else{
//
// //we_user表中去查询,如果该表为空则提示用户不存在,如果不为空,则将用户记录注册到系统用户表中
// WeUser weUser
// = 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
);
......@@ -95,6 +120,13 @@ public class UserDetailsServiceImpl implements UserDetailsService
throw new BaseException("对不起,您的账号:" + username + " 已停用");
}
//当前登录用户为企业管理,设置corpId和密钥相关
if(Constants.USER_TYOE_CORP_ADMIN.equals(user.getUserType())){
user.setWeCorpAccount(
iWeCorpAccountService.findWeCorpByAccount(username)
);
}
return createLoginUser(user);
}
......
......@@ -23,6 +23,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
<result property="userType" column="user_type" />
<association property="dept" column="dept_id" javaType="SysDept" resultMap="deptResult" />
<collection property="roles" javaType="java.util.List" resultMap="RoleResult" />
</resultMap>
......@@ -47,7 +48,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<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,
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
from sys_user u
left join sys_dept d on u.dept_id = d.dept_id
......
......@@ -27,6 +27,10 @@
<artifactId>spring-test</artifactId>
<version>5.2.9.RELEASE</version>
</dependency>
<dependency>
<groupId>com.linkwechat</groupId>
<artifactId>linkwe-system</artifactId>
</dependency>
</dependencies>
......
......@@ -2,6 +2,7 @@ package com.linkwechat.wecom.factory.impl.customer;
import com.alibaba.fastjson.JSONObject;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.core.domain.entity.WeCorpAccount;
import com.linkwechat.common.enums.MessageType;
import com.linkwechat.wecom.client.WeMessagePushClient;
import com.linkwechat.wecom.domain.*;
......
......@@ -8,6 +8,7 @@ import com.dtflys.forest.interceptor.Interceptor;
import com.dtflys.forest.utils.ForestDataType;
import com.linkwechat.common.config.WeComeConfig;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.wecom.domain.dto.WeResultDto;
import com.linkwechat.wecom.service.IWeAccessTokenService;
import lombok.extern.slf4j.Slf4j;
......
package com.linkwechat.wecom.mapper;
import java.util.List;
import com.linkwechat.wecom.domain.WeCorpAccount;
import com.baomidou.mybatisplus.annotation.SqlParser;
import com.linkwechat.common.core.domain.entity.WeCorpAccount;
import org.apache.ibatis.annotations.Param;
/**
......@@ -18,6 +20,7 @@ public interface WeCorpAccountMapper
* @param id 企业id相关配置ID
* @return 企业id相关配置
*/
@SqlParser(filter = true)
public WeCorpAccount selectWeCorpAccountById(Long id);
/**
......@@ -26,6 +29,7 @@ public interface WeCorpAccountMapper
* @param wxCorpAccount 企业id相关配置
* @return 企业id相关配置集合
*/
@SqlParser(filter = true)
public List<WeCorpAccount> selectWeCorpAccountList(WeCorpAccount wxCorpAccount);
/**
......@@ -34,6 +38,7 @@ public interface WeCorpAccountMapper
* @param wxCorpAccount 企业id相关配置
* @return 结果
*/
@SqlParser(filter = true)
public int insertWeCorpAccount(WeCorpAccount wxCorpAccount);
/**
......@@ -42,6 +47,7 @@ public interface WeCorpAccountMapper
* @param wxCorpAccount 企业id相关配置
* @return 结果
*/
@SqlParser(filter = true)
public int updateWeCorpAccount(WeCorpAccount wxCorpAccount);
......@@ -50,6 +56,7 @@ public interface WeCorpAccountMapper
* 获取有效cropid
* @return
*/
@SqlParser(filter = true)
public WeCorpAccount findValidWeCorpAccount();
......@@ -58,5 +65,15 @@ public interface WeCorpAccountMapper
* @param corpId
* @return
*/
@SqlParser(filter = true)
public int startVailWeCorpAccount(@Param("corpId") String corpId);
/**
* 根据企业账号获取企业相关配置
* @param corpAccount
* @return
*/
@SqlParser(filter = true)
WeCorpAccount findWeCorpByAccount(@Param("corpAccount") String corpAccount);
}
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
package com.linkwechat.wecom.service;
import java.util.List;
import com.linkwechat.wecom.domain.WeCorpAccount;
import org.apache.ibatis.annotations.Param;
import com.linkwechat.common.core.domain.entity.WeCorpAccount;
/**
* 企业id相关配置Service接口
......@@ -71,4 +70,6 @@ public interface IWeCorpAccountService
* 客户流失通知开关查询
*/
public String getCustomerChurnNoticeSwitch();
WeCorpAccount findWeCorpByAccount(String corpAccount);
}
......@@ -3,12 +3,15 @@ package com.linkwechat.wecom.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.linkwechat.common.constant.Constants;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.core.domain.entity.SysUser;
import com.linkwechat.common.core.domain.model.LoginUser;
import com.linkwechat.common.core.redis.RedisCache;
import com.linkwechat.common.exception.wecom.WeComException;
import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.wecom.client.WeAccessTokenClient;
import com.linkwechat.wecom.domain.WeApp;
import com.linkwechat.wecom.domain.WeCorpAccount;
import com.linkwechat.common.core.domain.entity.WeCorpAccount;
import com.linkwechat.wecom.domain.dto.WeAccessTokenDtoDto;
import com.linkwechat.wecom.service.IWeAccessTokenService;
import com.linkwechat.wecom.service.IWeAppService;
......@@ -133,16 +136,25 @@ public class WeAccessTokenServiceImpl implements IWeAccessTokenService {
private String findAccessToken(String accessTokenKey){
String weAccessToken =redisCache.getCacheObject(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)){
WeCorpAccount wxCorpAccount
= iWxCorpAccountService.findValidWeCorpAccount();
if(null == wxCorpAccount){
//返回错误异常,让用户绑定企业id相关信息
throw new WeComException("无可用的corpid和secret");
}
String token="";
Long expires_in=null;
if(WeConstans.WE_COMMON_ACCESS_TOKEN.equals(accessTokenKey) || WeConstans.WE_CONTACT_ACCESS_TOKEN.equals(accessTokenKey)){
......@@ -166,7 +178,7 @@ public class WeAccessTokenServiceImpl implements IWeAccessTokenService {
}
if(StringUtils.isNotEmpty(token)){
redisCache.setCacheObject(accessTokenKey,token,expires_in.intValue(), TimeUnit.SECONDS);
redisCache.setCacheObject(accessTokenKey+"::"+wxCorpAccount.getCorpId(),token,expires_in.intValue(), TimeUnit.SECONDS);
weAccessToken = token;
}
......@@ -180,10 +192,10 @@ public class WeAccessTokenServiceImpl implements IWeAccessTokenService {
* 清空redis中的相关token
*/
@Override
public void removeToken() {
redisCache.deleteObject(WeConstans.WE_COMMON_ACCESS_TOKEN);
redisCache.deleteObject(WeConstans.WE_CONTACT_ACCESS_TOKEN);
redisCache.deleteObject(WeConstans.WE_PROVIDER_ACCESS_TOKEN);
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());
}
......
package com.linkwechat.wecom.service.impl;
import java.util.List;
import java.util.Optional;
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.utils.DateUtils;
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.wecom.domain.WeCorpAccount;
import org.springframework.transaction.annotation.Transactional;
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业务层处理
......@@ -23,13 +33,28 @@ import org.springframework.transaction.annotation.Transactional;
@Service
public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
@Autowired
private WeCorpAccountMapper weCorpAccountMapper;
@Autowired
private IWeAccessTokenService iWeAccessTokenService;
@Autowired
private ISysUserService iSysUserService;
@Autowired
private RuoYiConfig ruoYiConfig;
@Autowired
private SysRoleMapper roleMapper;
@Autowired
private WeCorpAccountMapper weCorpAccountMapper;
/**
* 查询企业id相关配置
*
......@@ -63,8 +88,23 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
@Override
public int insertWeCorpAccount(WeCorpAccount wxCorpAccount)
{
int returnCode = weCorpAccountMapper.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;
}
/**
......@@ -81,7 +121,7 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
if(Constants.SERVICE_RETURN_SUCCESS_CODE<returnCode){
iWeAccessTokenService.removeToken();
iWeAccessTokenService.removeToken(wxCorpAccount);
}
......@@ -108,17 +148,30 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
@Override
public int startVailWeCorpAccount(String corpId) {
int returnCode = weCorpAccountMapper.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
......@@ -137,4 +190,10 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
}
@Override
public WeCorpAccount findWeCorpByAccount(String corpAccount) {
return weCorpAccountMapper.findWeCorpByAccount(corpAccount);
}
}
......@@ -63,19 +63,19 @@ public class WeDepartmentServiceImpl extends ServiceImpl<WeDepartmentMapper,WeDe
{
//校验数据中中是否存在根节点,如果不存在,从微信端获取,同时入库
WeDepartment weDepartment=this.baseMapper.selectWeDepartmentById(WeConstans.WE_ROOT_DEPARMENT_ID);
if(null == weDepartment){
WeDepartMentDto weDepartMentDto=weDepartMentClient.weDepartMents(WeConstans.WE_ROOT_DEPARMENT_ID);
if(WeConstans.WE_SUCCESS_CODE.equals(weDepartMentDto.getErrcode())
&& CollectionUtils.isNotEmpty(weDepartMentDto.getDepartment())){
this.baseMapper.insertWeDepartment(
WeDepartment.transformWeDepartment(
weDepartMentDto.getDepartment().stream().filter(item->item.getId().equals(WeConstans.WE_ROOT_DEPARMENT_ID)).findFirst().get()
)
);
}
}
// WeDepartment weDepartment=this.baseMapper.selectWeDepartmentById(WeConstans.WE_ROOT_DEPARMENT_ID);
// if(null == weDepartment){
// WeDepartMentDto weDepartMentDto=weDepartMentClient.weDepartMents(WeConstans.WE_ROOT_DEPARMENT_ID);
// if(WeConstans.WE_SUCCESS_CODE.equals(weDepartMentDto.getErrcode())
// && CollectionUtils.isNotEmpty(weDepartMentDto.getDepartment())){
// this.baseMapper.insertWeDepartment(
// WeDepartment.transformWeDepartment(
// weDepartMentDto.getDepartment().stream().filter(item->item.getId().equals(WeConstans.WE_ROOT_DEPARMENT_ID)).findFirst().get()
// )
// );
//
// }
// }
return this.baseMapper.selectWeDepartmentList();
}
......
......@@ -13,7 +13,7 @@ import com.linkwechat.common.utils.DateUtils;
import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.wecom.client.WeMessagePushClient;
import com.linkwechat.wecom.domain.WeCorpAccount;
import com.linkwechat.common.core.domain.entity.WeCorpAccount;
import com.linkwechat.wecom.domain.WeSensitive;
import com.linkwechat.wecom.domain.WeSensitiveAuditScope;
import com.linkwechat.wecom.domain.WeUser;
......
......@@ -22,10 +22,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="providerSecret" column="provider_secret" />
<result property="customerChurnNoticeSwitch" column="customer_churn_notice_switch" />
<result property="wxQrLoginRedirectUri" column="wx_qr_login_redirect_uri"/>
<result property="cropAccount" column="corp_account"/>
</resultMap>
<sql id="selectWeCorpAccountVo">
select id,chat_secret,provider_secret,company_name, corp_id, corp_secret,agent_id, agent_secret, status, del_flag, create_by, create_time, update_by, update_time,contact_secret, customer_churn_notice_switch,wx_qr_login_redirect_uri from we_corp_account
select id,chat_secret,corp_account,provider_secret,company_name, corp_id, corp_secret,agent_id, agent_secret, status, del_flag, create_by, create_time, update_by, update_time,contact_secret, customer_churn_notice_switch,wx_qr_login_redirect_uri from we_corp_account
</sql>
<select id="selectWeCorpAccountList" parameterType="WeCorpAccount" resultMap="WeCorpAccountResult">
......@@ -62,6 +63,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="customerChurnNoticeSwitch != null ">customer_churn_notice_switch,</if>
<if test="providerSecret != null ">provider_secret,</if>
<if test="wxQrLoginRedirectUri != null ">wx_qr_login_redirect_uri,</if>
<if test="cropAccount != null">corp_account,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="companyName != null">#{companyName},</if>
......@@ -80,6 +82,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="customerChurnNoticeSwitch != null ">#{customerChurnNoticeSwitch},</if>
<if test="providerSecret != null ">#{providerSecret},</if>
<if test="wxQrLoginRedirectUri != null ">#{wxQrLoginRedirectUri},</if>
<if test="cropAccount != null">#{cropAccount},</if>
</trim>
</insert>
......@@ -100,11 +103,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="agentId != null ">agent_id = #{agentId},</if>
<if test="agentSecret != null ">agent_secret =#{agentSecret},</if>
<if test="customerChurnNoticeSwitch != null ">customer_churn_notice_switch = #{customerChurnNoticeSwitch},</if>
<if test="providerSecret != null ">provider_secret = #{providerSecret},</if>
<if test="wxQrLoginRedirectUri != null ">wx_qr_login_redirect_uri = #{wxQrLoginRedirectUri},</if>
<if test="cropAccount != null">corp_account = #{cropAccount},</if>
</trim>
where id = #{id}
</update>
......@@ -125,8 +126,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</update>
<select id="findWeCorpByAccount" resultMap="WeCorpAccountResult">
<include refid="selectWeCorpAccountVo"/>
WHERE
del_flag = 0
AND corp_account = #{corpAccount}
</select>
</mapper>
\ No newline at end of file
......@@ -77,7 +77,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectWeCustomerList" parameterType="WeCustomer" resultMap="WeCustomerResult">
SELECT
DISTINCT wc.external_userid,
DISTINCT wc.external_userid,
wc.`name`,
wc.avatar,
wc.type,
......
......@@ -83,6 +83,16 @@
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>${pagehelper.boot.version}</version>
<exclusions>
<!-- <exclusion>-->
<!-- <groupId>com.github.jsqlparser</groupId>-->
<!-- <artifactId>jsqlparser</artifactId>-->
<!-- </exclusion>-->
<exclusion>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- 获取系统信息 -->
......@@ -245,6 +255,12 @@
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatis-plus.version}</version>
<exclusions>
<exclusion>
<groupId>com.github.jsqlparser</groupId>
<artifactId>jsqlparser</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
......@@ -271,6 +287,9 @@
<version>${nacos.version}</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!