提交 b98cd09f 编写于 作者: X xinlaa

Merge branch 'master' of https://gitee.com/LinkWeChat/link-wechat into master

package com.linkwechat.web.controller.common;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.linkwechat.common.config.RuoYiConfig;
import com.linkwechat.common.config.ServerConfig;
import com.linkwechat.common.constant.Constants;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.common.utils.file.FileUploadUtils;
import com.linkwechat.common.utils.file.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -10,16 +14,9 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.linkwechat.common.config.RuoYiConfig;
import com.linkwechat.common.constant.Constants;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.common.utils.file.FileUploadUtils;
import com.linkwechat.common.utils.file.FileUtils;
import com.linkwechat.framework.config.ServerConfig;
import java.io.*;
import java.util.stream.Stream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* 通用请求处理
......
......@@ -2,6 +2,12 @@ package com.linkwechat.web.controller.system;
import java.util.List;
import java.util.Set;
import com.linkwechat.wecom.client.WeAccessTokenClient;
import com.linkwechat.wecom.domain.WeCorpAccount;
import com.linkwechat.wecom.domain.dto.WeLoginUserInfoDto;
import com.linkwechat.wecom.service.IWeAccessTokenService;
import com.linkwechat.wecom.service.IWeCorpAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
......@@ -39,6 +45,14 @@ public class SysLoginController
@Autowired
private TokenService tokenService;
@Autowired
private IWeCorpAccountService iWxCorpAccountService;
@Autowired
private WeAccessTokenClient weAccessTokenClient;
/**
* 登录方法
*
......@@ -56,6 +70,8 @@ public class SysLoginController
return ajax;
}
/**
* 获取用户信息
*
......@@ -70,6 +86,12 @@ 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);
}
AjaxResult ajax = AjaxResult.success();
ajax.put("user", user);
ajax.put("roles", roles);
......@@ -91,4 +113,39 @@ public class SysLoginController
List<SysMenu> menus = menuService.selectMenuTreeByUserId(user.getUserId());
return AjaxResult.success(menuService.buildMenus(menus));
}
/**
* 获取企业扫码登录相关参数
* @return
*/
@GetMapping("/findQrLoginParm")
public AjaxResult findQrLoginParm(){
WeCorpAccount validWeCorpAccount
= iWxCorpAccountService.findValidWeCorpAccount();
if(null != validWeCorpAccount){
validWeCorpAccount.setContactSecret(null);
validWeCorpAccount.setCorpSecret(null);
validWeCorpAccount.setProviderSecret(null);
}
return AjaxResult.success(validWeCorpAccount);
}
/**
* 扫码登录微信端回调
* @param auth_code
* @return
*/
@GetMapping("/wxQrLogin")
public AjaxResult wxQrLogin(String auth_code){
WeLoginUserInfoDto loginInfo = weAccessTokenClient.getLoginInfo(auth_code);
System.out.println(auth_code);
return AjaxResult.success();
}
}
......@@ -84,4 +84,7 @@ public class WeCorpAccountController extends BaseController
}
}
......@@ -12,6 +12,7 @@ import com.linkwechat.common.utils.poi.ExcelUtil;
import com.linkwechat.wecom.domain.vo.WeMakeCustomerTag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
......@@ -86,16 +87,17 @@ public class WeCustomerController extends BaseController
// /**
// * 修改企业微信客户
// */
// @PreAuthorize("@ss.hasPermi('wecom:customer:edit')")
// @Log(title = "企业微信客户", businessType = BusinessType.UPDATE)
// @PutMapping
// public AjaxResult edit(@RequestBody WeCustomer weCustomer)
// {
// return toAjax(weCustomerService.updateWeCustomer(weCustomer));
// }
/**
* 修改企业微信客户
*/
@PreAuthorize("@ss.hasPermi('wecom:customer:edit')")
@Log(title = "企业微信客户", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@Validated @RequestBody WeCustomer weCustomer)
{
weCustomerService.saveOrUpdate(weCustomer);
return AjaxResult.success();
}
/**
......
......@@ -70,15 +70,18 @@ public class WeDepartmentController extends BaseController
return AjaxResult.success();
}
// /**
// * 删除企业微信组织架构相关
// */
// @PreAuthorize("@ss.hasPermi('wecom:department:remove')")
// @Log(title = "企业微信组织架构相关", businessType = BusinessType.DELETE)
// @DeleteMapping("/{ids}")
// public AjaxResult remove(@PathVariable String[] ids)
// {
// return toAjax(weDepartmentService.deleteWeDepartmentByIds(ids));
// }
/**
* 删除企业微信组织架构相关
*/
@PreAuthorize("@ss.hasPermi('wecom:department:remove')")
@Log(title = "企业微信组织架构相关", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable String[] ids)
{
weDepartmentService.deleteWeDepartmentByIds(ids);
return AjaxResult.success();
}
}
......@@ -14,6 +14,8 @@ ruoyi:
addressEnabled: false
# 验证码类型 math 数组计算 char 字符验证
captchaType: math
# 企业微信用户首次登录系统默认密码
weUserDefaultPwd: 123456
# 开发环境配置
server:
......@@ -90,6 +92,8 @@ mybatis-plus:
mapper-locations: classpath*:mapper/**/*Mapper.xml
type-aliases-package: com.linkwechat.**.domain
type-handlers-package: com.linkwechat.framework.handler.**
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
## MyBatis配置
#mybatis:
......@@ -132,7 +136,9 @@ forest:
wecome:
serverUrl: https://qyapi.weixin.qq.com/
weComePrefix: cgi-bin
noAccessTokenUrl: /gettoken
noAccessTokenUrl:
- /gettoken
- /service/get_provider_token
needContactTokenUrl:
- /externalcontact/get_follow_user_list
- /externalcontact/add_contact_way
......@@ -149,3 +155,6 @@ wecome:
- /externalcontact/groupchat/transfer
- /externalcontact/get_unassigned_list
fileUplodUrl: /media/upload,/media/uploadimg
needProviderTokenUrl:
- /service/get_login_info
......@@ -30,6 +30,9 @@ public class RuoYiConfig
/** 获取地址开关 */
private static boolean addressEnabled;
/** 企业微信账号登录系统默认密码 */
private static String weUserDefaultPwd="123456";
public String getName()
{
return name;
......@@ -113,4 +116,12 @@ public class RuoYiConfig
{
return getProfile() + "/upload";
}
public String getWeUserDefaultPwd() {
return weUserDefaultPwd;
}
public void setWeUserDefaultPwd(String weUserDefaultPwd) {
RuoYiConfig.weUserDefaultPwd = weUserDefaultPwd;
}
}
package com.linkwechat.framework.config;
package com.linkwechat.common.config;
import javax.servlet.http.HttpServletRequest;
import com.google.common.collect.Lists;
import org.springframework.stereotype.Component;
import com.linkwechat.common.utils.ServletUtils;
import org.springframework.stereotype.Component;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
/**
* 服务相关配置
......
......@@ -20,11 +20,14 @@ public class WeComeConfig {
private String weComePrefix;
/** 企业微信端无需token的url */
private String noAccessTokenUrl;
private String[] noAccessTokenUrl;
/** 需要使用外部联系人token的url*/
private String[] needContactTokenUrl;
/** 文件上传url*/
private String[] fileUplodUrl;
/** 需要供应商token的url*/
private String[] needProviderTokenUrl;
}
......@@ -87,6 +87,7 @@ public class Constants
*/
public static final String LOGIN_USER_KEY = "login_user_key";
/**
* 用户ID
*/
......@@ -143,6 +144,16 @@ public class Constants
public static final Integer SERVICE_RETURN_SUCCESS_CODE=0;
/** 系统用户 */
public static final String USER_TYPE_SYS="00";
/** 企业微信用户 */
public static final String USER_TYPE_WECOME="11";
/** 企业微信用户系统中默认用户 */
public static final String DEFAULT_WECOME_ROLE_KEY="WeCome";
}
......@@ -19,6 +19,12 @@ public class WeConstans {
public static final String WE_CONTACT_ACCESS_TOKEN = "we_contact_access_token";
/**
* 供应商相关token
*/
public static final String WE_PROVIDER_ACCESS_TOKEN = "we_provider_access_token";
/**
* 企业微信接口返回成功code
*/
......
package com.linkwechat.common.core.domain.entity;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.linkwechat.common.annotation.Excel;
import com.linkwechat.common.annotation.Excel.ColumnType;
import com.linkwechat.common.core.domain.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
/**
* 角色表 sys_role
*
* @author ruoyi
*/
@Builder
@AllArgsConstructor
public class SysRole extends BaseEntity
{
private static final long serialVersionUID = 1L;
......
package com.linkwechat.common.core.domain.entity;
import java.util.Date;
import java.util.List;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.linkwechat.common.annotation.Excel;
......@@ -14,12 +7,26 @@ import com.linkwechat.common.annotation.Excel.ColumnType;
import com.linkwechat.common.annotation.Excel.Type;
import com.linkwechat.common.annotation.Excels;
import com.linkwechat.common.core.domain.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.util.Date;
import java.util.List;
/**
* 用户对象 sys_user
*
* @author ruoyi
*/
@Data
@Builder
@AllArgsConstructor
public class SysUser extends BaseEntity
{
private static final long serialVersionUID = 1L;
......@@ -40,6 +47,9 @@ public class SysUser extends BaseEntity
@Excel(name = "用户名称")
private String nickName;
/** 用户类型(00系统用户)(11:企业微信用户) */
private String userType;
/** 用户邮箱 */
@Excel(name = "用户邮箱")
private String email;
......@@ -92,6 +102,9 @@ public class SysUser extends BaseEntity
/** 岗位组 */
private Long[] postIds;
/** 是否具有有效得cropId */
private boolean validCropId=false;
public SysUser()
{
......
......@@ -69,6 +69,14 @@
<artifactId>linkwe-system</artifactId>
</dependency>
<!-- 企业微信模块-->
<dependency>
<groupId>com.linkwechat</groupId>
<artifactId>linkwe-wecom</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -97,7 +97,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
// 过滤请求
.authorizeRequests()
// 对于登录login 验证码captchaImage 允许匿名访问
.antMatchers("/login", "/captchaImage").anonymous()
.antMatchers("/login", "/captchaImage","/findQrLoginParm","/wxQrLogin").anonymous()
.antMatchers(
HttpMethod.GET,
"/*.html",
......
package com.linkwechat.framework.web.service;
import cn.hutool.core.util.ArrayUtil;
import com.linkwechat.common.config.RuoYiConfig;
import com.linkwechat.common.constant.Constants;
import com.linkwechat.common.core.domain.entity.SysRole;
import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.system.mapper.SysRoleMapper;
import com.linkwechat.system.service.ISysRoleService;
import com.linkwechat.wecom.domain.WeCorpAccount;
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;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -14,6 +25,9 @@ import com.linkwechat.common.exception.BaseException;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.system.service.ISysUserService;
import java.util.List;
import java.util.stream.Collectors;
/**
* 用户验证处理
*
......@@ -30,14 +44,49 @@ public class UserDetailsServiceImpl implements UserDetailsService
@Autowired
private SysPermissionService permissionService;
@Autowired
private IWeUserService iWeUserService;
@Autowired
private RuoYiConfig ruoYiConfig;
@Autowired
private SysRoleMapper roleMapper;
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException
{
SysUser user = userService.selectUserByUserName(username);
if (StringUtils.isNull(user))
{
log.info("登录用户:{} 不存在.", username);
throw new UsernameNotFoundException("登录用户:" + username + " 不存在");
//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().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()))
{
......@@ -50,6 +99,9 @@ public class UserDetailsServiceImpl implements UserDetailsService
throw new BaseException("对不起,您的账号:" + username + " 已停用");
}
return createLoginUser(user);
}
......
......@@ -38,7 +38,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
AND r.status = #{status}
</if>
<if test="roleKey != null and roleKey != ''">
AND r.role_key like concat('%', #{roleKey}, '%')
AND r.role_key = #{roleKey}
</if>
<if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
and date_format(r.create_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
......
......@@ -117,6 +117,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="status != null and status != ''">status,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
<if test="remark != null and remark != ''">remark,</if>
<if test="userType != null and userType != ''">user_type,</if>
create_time
)values(
<if test="userId != null and userId != ''">#{userId},</if>
......@@ -131,6 +132,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="status != null and status != ''">#{status},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="remark != null and remark != ''">#{remark},</if>
<if test="userType != null and userType != ''">#{userType},</if>
sysdate()
)
</insert>
......
......@@ -22,10 +22,6 @@
<groupId>com.linkwechat</groupId>
<artifactId>linkwe-common</artifactId>
</dependency>
<dependency>
<groupId>com.linkwechat</groupId>
<artifactId>linkwe-framework</artifactId>
</dependency>
</dependencies>
......
package com.linkwechat.wecom.client;
import com.dtflys.forest.annotation.Body;
import com.dtflys.forest.annotation.Query;
import com.dtflys.forest.annotation.Request;
import com.linkwechat.wecom.domain.dto.WeAccessTokenDtoDto;
import com.linkwechat.wecom.domain.dto.WeLoginUserInfoDto;
/**
* @description: 获取企业微信Token相关
......@@ -14,7 +16,7 @@ public interface WeAccessTokenClient {
/**
* 获取token
* 获取token(常用token,联系人token)
* @param corpId 企业id
* @param corpSecret 应用的凭证密钥
* @return
......@@ -22,4 +24,26 @@ public interface WeAccessTokenClient {
@Request(url = "/gettoken")
WeAccessTokenDtoDto getToken(@Query("corpid") String corpId, @Query("corpsecret") String corpSecret);
/**
* 获取供应商token
* @param corpid 服务商的corpid
* @param provider_secret 服务商的secret,在服务商管理后台可见
* @return
*/
@Request(url = "/service/get_provider_token",
type="POST")
WeAccessTokenDtoDto getProviderToken(@Body("corpid") String corpid,@Body("provider_secret") String provider_secret);
/**
* 获取登录用户信息(扫码)
* @param auth_code
* @return
*/
@Request(url = "/service/get_login_info",
type = "POST"
)
WeLoginUserInfoDto getLoginInfo(@Body("auth_code") String auth_code);
}
\ No newline at end of file
......@@ -58,5 +58,12 @@ public class WeCorpAccount extends BaseEntity
@NotBlank(message = "外部联系人密钥凭证不能为空")
private String contactSecret;
@ApiModelProperty("应用id")
private String agentId;
@ApiModelProperty("服务商密钥")
private String providerSecret;
}
......@@ -16,6 +16,8 @@ import lombok.NoArgsConstructor;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import javax.validation.constraints.NotBlank;
/**
* 企业微信客户对象 we_customer
*
......@@ -34,6 +36,7 @@ public class WeCustomer
/** 外部联系人的userid */
@TableId
@NotBlank(message = "外部联系人的id不可为空")
private String externalUserid;
/** 外部联系人名称 */
......
......@@ -11,4 +11,5 @@ import lombok.Data;
public class WeAccessTokenDtoDto extends WeResultDto {
private String access_token;
private Long expires_in;
private String provider_access_token;
}
package com.linkwechat.wecom.domain.dto;
import lombok.Data;
/**
* @description: 登录用户
* @author: HaoN
* @create: 2020-11-01 20:58
**/
@Data
public class WeLoginUserInfoDto extends WeResultDto{
private Integer usertype;
private UserInfo user_info;
@Data
public class UserInfo{
private String userid;
private String name;
private String avatar;
}
}
......@@ -2,16 +2,12 @@ package com.linkwechat.wecom.interceptor;
import cn.hutool.json.JSONUtil;
import com.dtflys.forest.exceptions.ForestRuntimeException;
import com.dtflys.forest.http.ForestHeader;
import com.dtflys.forest.http.ForestRequest;
import com.dtflys.forest.http.ForestResponse;
import com.dtflys.forest.interceptor.Interceptor;
import com.dtflys.forest.utils.ForestDataType;
import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.config.WeComeConfig;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.exception.wecom.WeComException;
import com.linkwechat.framework.web.domain.server.Sys;
import com.linkwechat.wecom.domain.dto.WeResultDto;
import com.linkwechat.wecom.service.IWeAccessTokenService;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -56,13 +52,21 @@ public class WeAccessTokenInterceptor implements Interceptor{
// 添加请求参数access_token
if(!weComeConfig.getNoAccessTokenUrl().equals(uri)){
request.addQuery("access_token",
Arrays.asList(weComeConfig.getNeedContactTokenUrl()).contains(uri)?
iWeAccessTokenService.findContactAccessToken():
iWeAccessTokenService.findCommonAccessToken());
if(!Arrays.asList(weComeConfig.getNoAccessTokenUrl()).contains(uri)){
String token="";
if(Arrays.asList(weComeConfig.getNeedContactTokenUrl()).contains(uri)){ //需要联系人token
token=iWeAccessTokenService.findContactAccessToken();
}else if(Arrays.asList(weComeConfig.getNeedProviderTokenUrl()).contains(uri)){ //需要供应商token
token=iWeAccessTokenService.findProviderAccessToken();
}else{
token=iWeAccessTokenService.findCommonAccessToken();
}
request.addQuery("access_token",token);
}
//添加服务器统一请求地址
request.setUrl(weComeConfig.getServerUrl()+weComeConfig.getWeComePrefix()+uri);
......
......@@ -11,4 +11,7 @@ public interface IWeAccessTokenService {
public String findContactAccessToken();
public String findProviderAccessToken();
}
\ No newline at end of file
......@@ -47,9 +47,9 @@ public interface IWeDepartmentService extends IService<WeDepartment>
public List<WeDepartment> synchWeDepartment();
// /**
// * 根据部门id删除部门
// * @param ids
// */
// public void deleteWeDepartmentByIds(String[] ids);
/**
* 根据部门id删除部门
* @param ids
*/
public void deleteWeDepartmentByIds(String[] ids);
}
......@@ -58,6 +58,16 @@ public class WeAccessTokenServiceImpl implements IWeAccessTokenService {
}
/**
* 获取服务商相关token
* @return
*/
@Override
public String findProviderAccessToken() {
return findAccessToken(WeConstans.WE_PROVIDER_ACCESS_TOKEN);
}
private String findAccessToken(String accessTokenKey){
String weAccessToken =redisCache.getCacheObject(accessTokenKey);
......@@ -70,15 +80,24 @@ public class WeAccessTokenServiceImpl implements IWeAccessTokenService {
//返回错误异常,让用户绑定企业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)){
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();
}
WeAccessTokenDtoDto accessToken
= accessTokenClient.getToken(wxCorpAccount.getCorpId(),
WeConstans.WE_COMMON_ACCESS_TOKEN.equals(accessTokenKey)? wxCorpAccount.getCorpSecret():wxCorpAccount.getContactSecret());
if(accessToken.getErrcode().equals(WeConstans.WE_SUCCESS_CODE)){
redisCache.setCacheObject(accessTokenKey,accessToken.getAccess_token(),accessToken.getExpires_in().intValue(), TimeUnit.SECONDS);
weAccessToken=accessToken.getAccess_token();
if(StringUtils.isNotEmpty(token)){
redisCache.setCacheObject(accessTokenKey,token,expires_in.intValue(), TimeUnit.SECONDS);
}
}
return weAccessToken;
......
......@@ -3,20 +3,16 @@ package com.linkwechat.wecom.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ArrayUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.utils.DateUtils;
import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.common.utils.SnowFlakeUtil;
import com.linkwechat.common.utils.bean.BeanUtils;
import com.linkwechat.framework.web.domain.server.Sys;
import com.linkwechat.wecom.client.WeCropTagClient;
import com.linkwechat.wecom.client.WeCustomerClient;
import com.linkwechat.wecom.client.WeUserClient;
import com.linkwechat.wecom.domain.*;
import com.linkwechat.wecom.domain.dto.AllocateWeCustomerDto;
import com.linkwechat.wecom.domain.dto.WeResultDto;
import com.linkwechat.wecom.domain.dto.customer.*;
import com.linkwechat.wecom.domain.dto.tag.WeCropGroupTagDto;
import com.linkwechat.wecom.domain.dto.tag.WeCropGroupTagListDto;
......
......@@ -7,6 +7,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linkwechat.common.constant.HttpStatus;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.enums.WeExceptionTip;
import com.linkwechat.common.exception.CustomException;
import com.linkwechat.common.exception.wecom.WeComException;
import com.linkwechat.common.utils.SnowFlakeUtil;
import com.linkwechat.common.utils.bean.BeanUtils;
......@@ -35,8 +37,7 @@ import java.util.List;
@Service
public class WeDepartmentServiceImpl extends ServiceImpl<WeDepartmentMapper,WeDepartment> implements IWeDepartmentService
{
@Autowired
private WeDepartmentMapper weDepartmentMapper;
@Autowired
......@@ -49,6 +50,9 @@ public class WeDepartmentServiceImpl extends ServiceImpl<WeDepartmentMapper,WeDe
/**
* 查询企业微信组织架构相关列表
*
......@@ -59,12 +63,12 @@ public class WeDepartmentServiceImpl extends ServiceImpl<WeDepartmentMapper,WeDe
{
//校验数据中中是否存在根节点,如果不存在,从微信端获取,同时入库
WeDepartment weDepartment=weDepartmentMapper.selectWeDepartmentById(WeConstans.WE_ROOT_DEPARMENT_ID);
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())){
weDepartmentMapper.insertWeDepartment(
this.baseMapper.insertWeDepartment(
WeDepartment.transformWeDepartment(
weDepartMentDto.getDepartment().stream().filter(item->item.getId().equals(WeConstans.WE_ROOT_DEPARMENT_ID)).findFirst().get()
)
......@@ -73,7 +77,7 @@ public class WeDepartmentServiceImpl extends ServiceImpl<WeDepartmentMapper,WeDe
}
}
return weDepartmentMapper.selectWeDepartmentList();
return this.baseMapper.selectWeDepartmentList();
}
/**
......@@ -137,33 +141,41 @@ public class WeDepartmentServiceImpl extends ServiceImpl<WeDepartmentMapper,WeDe
}
// /**
// * 根据部门id删除部门
// * @param ids
// */
// @Override
// public void deleteWeDepartmentByIds(String[] ids) {
//
// //查询当前部门下所有的子部门,如果存在,则不可以删除
// List<WeDepartment> weDepartments = this.list(new LambdaQueryWrapper<WeDepartment>()
// .in(WeDepartment::getParentId, ids));
// if(CollectionUtil.isNotEmpty(weDepartments)) {
// //抛出异常,请删除此部门下的成员或子部门后,再删除此部门
//
// }
//
//
// List<WeUser> weUsers = weUserService.selectWeUserList(WeUser.builder()
// .department(ids)
// .build());
// if(CollectionUtil.isNotEmpty(weUsers)){
// //该部门存在子部门或成员无法删除
//
// }
//
//
//
// }
/**
* 根据部门id删除部门
* @param ids
*/
@Override
public void deleteWeDepartmentByIds(String[] ids) {
//查询当前部门下所有的子部门,如果存在,则不可以删除
List<WeDepartment> weDepartments = this.list(new LambdaQueryWrapper<WeDepartment>()
.in(WeDepartment::getParentId, ids));
if(CollectionUtil.isNotEmpty(weDepartments)) {
//抛出异常,请删除此部门下的成员或子部门后,再删除此部门
throw new CustomException(WeExceptionTip.WE_EXCEPTION_TIP_60006.getTipMsg(),WeExceptionTip.WE_EXCEPTION_TIP_60006.getCode());
}
List<WeUser> weUsers = weUserService.selectWeUserList(WeUser.builder()
.department(ids)
.build());
if(CollectionUtil.isNotEmpty(weUsers)){
//该部门存在成员无法删除
throw new CustomException(WeExceptionTip.WE_EXCEPTION_TIP_60005.getTipMsg(),WeExceptionTip.WE_EXCEPTION_TIP_60005.getCode());
}
//删除数据库中数据
if(this.removeByIds(ListUtil.toList(ids))){
ListUtil.toList(ids).stream().forEach(k->{
//移除微信端
weDepartMentClient.deleteWeDepartMent(k);
});
}
}
}
package com.linkwechat.wecom.service.impl;
import com.linkwechat.common.config.RuoYiConfig;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.config.ServerConfig;
import com.linkwechat.common.enums.MediaType;
import com.linkwechat.common.exception.wecom.WeComException;
import com.linkwechat.common.utils.file.FileUploadUtils;
import com.linkwechat.framework.config.ServerConfig;
import com.linkwechat.wecom.client.WeMediaClient;
import com.linkwechat.wecom.domain.WeMaterial;
import com.linkwechat.wecom.domain.dto.WeMediaDto;
import com.linkwechat.wecom.domain.vo.WeMaterialFileVO;
import com.linkwechat.wecom.mapper.WeMaterialMapper;
import com.linkwechat.wecom.service.IWeMaterialService;
......
......@@ -2,18 +2,10 @@ package com.linkwechat.wecom.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linkwechat.common.constant.Constants;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.exception.wecom.WeComException;
import com.linkwechat.framework.web.domain.server.Sys;
import com.linkwechat.wecom.client.WeDepartMentClient;
import com.linkwechat.wecom.client.WeUserClient;
import com.linkwechat.wecom.domain.WeDepartment;
import com.linkwechat.wecom.domain.WeUser;
import com.linkwechat.wecom.domain.dto.LeaveWeUserListsDto;
import com.linkwechat.wecom.domain.dto.WeDepartMentDto;
import com.linkwechat.wecom.domain.dto.WeUserDto;
import com.linkwechat.wecom.domain.dto.WeUserListDto;
import com.linkwechat.wecom.domain.vo.WeAllocateCustomersVo;
import com.linkwechat.wecom.domain.vo.WeAllocateGroupsVo;
import com.linkwechat.wecom.domain.vo.WeLeaveUserInfoAllocateVo;
......@@ -25,8 +17,6 @@ import com.linkwechat.wecom.service.IWeGroupService;
import com.linkwechat.wecom.service.IWeUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
......
......@@ -16,10 +16,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="contactSecret" column="contact_secret" />
<result property="agentId" column="agent_id" />
<result property="providerSecret" column="provider_secret" />
</resultMap>
<sql id="selectWeCorpAccountVo">
select id, company_name, corp_id, corp_secret, status, del_flag, create_by, create_time, update_by, update_time,contact_secret from we_corp_account
select id,provider_secret,company_name, corp_id, corp_secret,agent_id ,status, del_flag, create_by, create_time, update_by, update_time,contact_secret from we_corp_account
</sql>
<select id="selectWeCorpAccountList" parameterType="WeCorpAccount" resultMap="WeCorpAccountResult">
......
......@@ -141,22 +141,27 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="leaveNoAllocateUserList" parameterType="WeLeaveUserVo" resultType="com.linkwechat.wecom.domain.vo.WeLeaveUserVo">
SELECT
wu.user_id,
wu.user_name,
wu.dimission_time,
(SELECT GROUP_CONCAT(wd.`name`) FROM we_department wd WHERE wd.id=wu.department) as department,
(SELECT COUNT(*) FROM we_flower_customer_rel wfcr WHERE wfcr.user_id=wu.user_id) as allocateCustomerNum,
(SELECT COUNT(*) FROM we_group wg WHERE wg.`owner`=wu.user_id) as allocateGroupNum
*
FROM
we_user wu
<where>
<if test="userName != null and userName !=''">and wu.user_name=#{userName}</if>
<if test="beginTime != null and beginTime !='' and endTime != null and endTime !=''">
DATE_FORMAT(wu.dimission_time,'%Y-%m-%d') BETWEEN #{beginTime} AND #{endTime}
</if>
<if test="isActivate != null ">and wu.is_activate = #{isActivate}</if>
<if test="isAllocate != null ">and wu.is_allocate = #{isAllocate}</if>
</where>
(
SELECT
wu.user_id,
wu.user_name,
wu.dimission_time,
(SELECT GROUP_CONCAT(wd.`name`) FROM we_department wd WHERE wd.id=wu.department) as department,
(SELECT COUNT(*) FROM we_flower_customer_rel wfcr WHERE wfcr.user_id=wu.user_id) as allocateCustomerNum,
(SELECT COUNT(*) FROM we_group wg WHERE wg.`owner`=wu.user_id) as allocateGroupNum
FROM
we_user wu
<where>
<if test="userName != null and userName !=''">and wu.user_name=#{userName}</if>
<if test="beginTime != null and beginTime !='' and endTime != null and endTime !=''">
DATE_FORMAT(wu.dimission_time,'%Y-%m-%d') BETWEEN #{beginTime} AND #{endTime}
</if>
<if test="isActivate != null ">and wu.is_activate = #{isActivate}</if>
<if test="isAllocate != null ">and wu.is_allocate = #{isAllocate}</if>
</where>
)wuu WHERE allocateCustomerNum >0 and allocateGroupNum>0
</select>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册