Commit 2c012173 by HaoN

完成企业微信企业id的设置,token的获取,已经通讯录组织架构的增加,查询,修改

1 parent 13178aa4
Showing 24 changed files with 472 additions and 143 deletions
......@@ -2,6 +2,9 @@ package com.linkwechat.web.controller.system;
import java.util.List;
import java.util.stream.Collectors;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
......@@ -39,6 +42,7 @@ import com.linkwechat.system.service.ISysUserService;
*/
@RestController
@RequestMapping("/system/user")
@Api("系统用户管理")
public class SysUserController extends BaseController
{
@Autowired
......@@ -58,6 +62,7 @@ public class SysUserController extends BaseController
*/
@PreAuthorize("@ss.hasPermi('system:user:list')")
@GetMapping("/list")
@ApiOperation("获取用户列表")
public TableDataInfo list(SysUser user)
{
startPage();
......
......@@ -12,7 +12,6 @@ import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
......@@ -34,6 +33,7 @@ public class WeCorpAccountController extends BaseController
*/
@PreAuthorize("@ss.hasPermi('wechat:corp:list')")
@GetMapping("/list")
@ApiOperation("获取企业id列表")
public TableDataInfo list(WeCorpAccount weCorpAccount)
{
startPage();
......@@ -41,24 +41,13 @@ public class WeCorpAccountController extends BaseController
return getDataTable(list);
}
// /**
// * 导出企业id相关配置列表
// */
// @PreAuthorize("@ss.hasPermi('wechat:corp:export')")
// @Log(title = "企业id相关配置", businessType = BusinessType.EXPORT)
// @GetMapping("/export")
// public AjaxResult export(WxCorpAccount wxCorpAccount)
// {
// List<WxCorpAccount> list = wxCorpAccountService.selectWxCorpAccountList(wxCorpAccount);
// ExcelUtil<WxCorpAccount> util = new ExcelUtil<WxCorpAccount>(WxCorpAccount.class);
// return util.exportExcel(list, "corp");
// }
/**
* 获取企业id相关配置详细信息
*/
@PreAuthorize("@ss.hasPermi('wechat:corp:query')")
@GetMapping(value = "/{id}")
@ApiOperation("获取企业id相关详情")
public AjaxResult getInfo(@PathVariable("id") Long id)
{
return AjaxResult.success(weCorpAccountService.selectWeCorpAccountById(id));
......@@ -67,10 +56,10 @@ public class WeCorpAccountController extends BaseController
/**
* 新增企业id相关配置
*/
// @PreAuthorize("@ss.hasPermi('wechat:corp:add')")
// @Log(title = "企业id相关配置", businessType = BusinessType.INSERT)
@PreAuthorize("@ss.hasPermi('wechat:corp:add')")
@Log(title = "企业id相关配置", businessType = BusinessType.INSERT)
@PostMapping
@ApiOperation("新增")
@ApiOperation("新增企业id")
public AjaxResult add(@RequestBody WeCorpAccount weCorpAccount)
{
return toAjax(weCorpAccountService.insertWeCorpAccount(weCorpAccount));
......@@ -82,20 +71,22 @@ public class WeCorpAccountController extends BaseController
@PreAuthorize("@ss.hasPermi('wechat:corp:edit')")
@Log(title = "企业id相关配置", businessType = BusinessType.UPDATE)
@PutMapping
@ApiOperation("修改企业id")
public AjaxResult edit(@RequestBody WeCorpAccount weCorpAccount)
{
return toAjax(weCorpAccountService.updateWeCorpAccount(weCorpAccount));
}
/**
* 删除企业id相关配置
*/
@PreAuthorize("@ss.hasPermi('wechat:corp:remove')")
@Log(title = "企业id相关配置", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
{
return toAjax(weCorpAccountService.deleteWeCorpAccountByIds(ids));
}
// /**
// * 删除企业id相关配置
// */
// @PreAuthorize("@ss.hasPermi('wechat:corp:remove')")
// @Log(title = "企业id相关配置", businessType = BusinessType.DELETE)
// @DeleteMapping("/{ids}")
// @ApiOperation("根据id删除企业id")
// public AjaxResult remove(@PathVariable Long[] ids)
// {
// return toAjax(weCorpAccountService.deleteWeCorpAccountByIds(ids));
// }
}
......@@ -8,6 +8,8 @@ import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
......@@ -18,7 +20,6 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.linkwechat.wecom.domain.WeDepartment;
import com.linkwechat.wecom.service.IWeDepartmentService;
......@@ -28,6 +29,7 @@ import com.linkwechat.wecom.service.IWeDepartmentService;
* @author ruoyi
* @date 2020-09-01
*/
@Api("微信组织架构相关接口")
@RestController
@RequestMapping("/wecom/department")
public class WeDepartmentController extends BaseController
......@@ -40,35 +42,24 @@ public class WeDepartmentController extends BaseController
*/
@PreAuthorize("@ss.hasPermi('wecom:department:list')")
@GetMapping("/list")
public TableDataInfo list(WeDepartment weDepartment)
@ApiOperation("获取部门列表")
public TableDataInfo list()
{
startPage();
List<WeDepartment> list = weDepartmentService.selectWeDepartmentList(weDepartment);
List<WeDepartment> list = weDepartmentService.selectWeDepartmentList();
return getDataTable(list);
}
/**
* 导出企业微信组织架构相关列表
*/
@PreAuthorize("@ss.hasPermi('wecom:department:export')")
@Log(title = "企业微信组织架构相关", businessType = BusinessType.EXPORT)
@GetMapping("/export")
public AjaxResult export(WeDepartment weDepartment)
{
List<WeDepartment> list = weDepartmentService.selectWeDepartmentList(weDepartment);
ExcelUtil<WeDepartment> util = new ExcelUtil<WeDepartment>(WeDepartment.class);
return util.exportExcel(list, "department");
}
/**
* 获取企业微信组织架构相关详细信息
*/
@PreAuthorize("@ss.hasPermi('wecom:department:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id)
{
return AjaxResult.success(weDepartmentService.selectWeDepartmentById(id));
}
//
//
//
// /**
// * 获取企业微信组织架构相关详细信息
// */
// @PreAuthorize("@ss.hasPermi('wecom:department:query')")
// @GetMapping(value = "/{id}")
// public AjaxResult getInfo(@PathVariable("id") Long id)
// {
// return AjaxResult.success(weDepartmentService.selectWeDepartmentById(id));
// }
/**
* 新增企业微信组织架构相关
......@@ -76,6 +67,7 @@ public class WeDepartmentController extends BaseController
@PreAuthorize("@ss.hasPermi('wecom:department:add')")
@Log(title = "企业微信组织架构相关", businessType = BusinessType.INSERT)
@PostMapping
@ApiOperation("添加部门")
public AjaxResult add(@RequestBody WeDepartment weDepartment)
{
return toAjax(weDepartmentService.insertWeDepartment(weDepartment));
......@@ -87,19 +79,20 @@ public class WeDepartmentController extends BaseController
@PreAuthorize("@ss.hasPermi('wecom:department:edit')")
@Log(title = "企业微信组织架构相关", businessType = BusinessType.UPDATE)
@PutMapping
@ApiOperation("更新部门")
public AjaxResult edit(@RequestBody WeDepartment weDepartment)
{
return toAjax(weDepartmentService.updateWeDepartment(weDepartment));
}
/**
* 删除企业微信组织架构相关
*/
@PreAuthorize("@ss.hasPermi('wecom:department:remove')")
@Log(title = "企业微信组织架构相关", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
{
return toAjax(weDepartmentService.deleteWeDepartmentByIds(ids));
}
//
// /**
// * 删除企业微信组织架构相关
// */
// @PreAuthorize("@ss.hasPermi('wecom:department:remove')")
// @Log(title = "企业微信组织架构相关", businessType = BusinessType.DELETE)
// @DeleteMapping("/{ids}")
// public AjaxResult remove(@PathVariable Long[] ids)
// {
// return toAjax(weDepartmentService.deleteWeDepartmentByIds(ids));
// }
}
......@@ -107,7 +107,7 @@ swagger:
# 是否开启swagger
enabled: true
# 请求前缀
pathMapping: /dev-api
pathMapping:
# 防止XSS攻击
xss:
......@@ -125,4 +125,5 @@ forest:
wecome:
serverUrl: https://qyapi.weixin.qq.com/
weComePrefix: cgi-bin
\ No newline at end of file
weComePrefix: cgi-bin
noAccessTokenUrl: /gettoken
\ No newline at end of file
......@@ -151,6 +151,20 @@
</dependency>
<!-- https://mvnrepository.com/artifact/com.esotericsoftware/reflectasm -->
<dependency>
<groupId>com.esotericsoftware</groupId>
<artifactId>reflectasm</artifactId>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -18,4 +18,7 @@ public class WeComeConfig {
/** 企业微信后台地址前缀 */
private String weComePrefix;
/** 企业微信端无需token的url */
private String noAccessTokenUrl;
}
......@@ -126,4 +126,8 @@ public class Constants
* 资源映射路径 前缀
*/
public static final String RESOURCE_PREFIX = "/profile";
/** 是否为系统默认(是) */
public static final int SERVICE_STATUS_ERROR = -1;
}
......@@ -10,11 +10,17 @@ public class WeConstans {
/**
* 企业微信相关token
*/
public static final String WE_ACCESS_TOKEN = "WeAccessToken";
public static final String WE_ACCESS_TOKEN = "we_access_token";
/**
* 企业微信接口返回成功code
*/
public static final Integer WE_SUCCESS_CODE = 0;
/**
* 企业微信端根部门id
*/
public static final Long WE_ROOT_DEPARMENT_ID = new Long(1);
}
......@@ -6,6 +6,7 @@ import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import springfox.documentation.annotations.ApiIgnore;
/**
* Entity基类
......
package com.linkwechat.common.utils;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.HashMap;
import java.util.Map;
import com.esotericsoftware.reflectasm.MethodAccess;
/**
* @Author: Robin
* @Description:
* @Date: create in 2020/9/6 0006 16:35
*/
public class BeanUtils {
}
package com.linkwechat.common.utils;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
/**
* @Author: Robin
* @Description:
* @Date: create in 2020/9/6 0006 21:44
*/
public class SnowFlakeUtil {
/**
* 派号器workid:0~31
* 机房datacenterid:0~31
*/
private static Snowflake snowflake = IdUtil.createSnowflake(1, 1);
public static Long nextId() {
return snowflake.nextId();
}
}
package com.linkwechat.common.utils.bean;
import com.esotericsoftware.reflectasm.MethodAccess;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
......@@ -107,4 +113,172 @@ public class BeanUtils extends org.springframework.beans.BeanUtils
{
return m1.substring(BEAN_METHOD_PROP_INDEX).equals(m2.substring(BEAN_METHOD_PROP_INDEX));
}
/**
* 通过 ASM反射 速度比 Spring BeanUtils.copyProperties(source,target) 快一倍
* 类型不同可以转换
* 大小写可以忽略
* 下划线 _ 被忽略
*
* @param source 数据源
* @param target 目标是数据
* @param <T>
* @return
*/
public static <T> T copyPropertiesASM( Object source, Object target ) {
MethodAccess sourceMethodAccess = CacheMethodAccess.getMethodAccess(source.getClass());
MethodAccess targetMethodAccess = CacheMethodAccess.getMethodAccess(target.getClass());
Map<String, String> sourceGet = CacheAsmFiledMethod.getMethod("get", source.getClass());
Map<String, String> targetSet = CacheAsmFiledMethod.getMethod("set", target.getClass());
CacheFieldMap.getFieldMap(target.getClass()).keySet().forEach((it) -> {
String sourceIndex = sourceGet.get(it);
if (sourceIndex != null) {
Object value = sourceMethodAccess.invoke(source, sourceIndex);
String setIndex = targetSet.get(it);
targetMethodAccess.invoke(target, setIndex, value);
}
});
return (T) target;
}
/**
* 模仿Spring中 BeanUtils.copyProperties(source,target)
*类型不同不可以转换
* 但是
* 大小写可以忽略
* 下划线 _ 被忽略
* @param source
* @param target
* @param <T>
* @return
*/
public static <T> T copyPropertiesignoreOther(Object source, Object target) {
Map<String, Field> sourceMap = CacheFieldMap.getFieldMap(source.getClass());
CacheFieldMap.getFieldMap(target.getClass()).values().forEach((it) -> {
Field field = sourceMap.get(it.getName().toLowerCase().replace("_", ""));
if (field != null) {
it.setAccessible(true);
field.setAccessible(true);
try {
it.set(target,field.get(source));
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
});
return (T) target;
}
private static class CacheAsmFiledMethod {
private static Map<String, Map<String, String>> cacheGetMethod = new HashMap<>();
private static Map<String, Map<String, String>> cacheSetMethod = new HashMap<>();
private static Map<String, String> getMethod(String type, Class clazz) {
MethodAccess methodAccess = CacheMethodAccess.getMethodAccess(clazz);
Map<String, Field> allFields = CacheFieldMap.getFieldMap(clazz);
Map<String, String> result = null;
if (type.equals("get")) {
result = cacheGetMethod.get(clazz.getName());
} else if (type.equals("set")) {
result = cacheSetMethod.get(clazz.getName());
}
if (result == null) {
synchronized (CacheAsmFiledMethod.class) {
if (result == null) {
Map<String, String> set = new HashMap<>();
Map<String, String> get = new HashMap<>();
allFields.values().forEach((it) -> {
//判断是否是静态
if (!Modifier.isStatic(it.getModifiers())) {
//首字母大写
char[] f = it.getName().toCharArray();
f[0] -= 32;
String fieldName = new String(f);
get.put(fieldName.toLowerCase().replace("_", ""), "get" + fieldName);
set.put(fieldName.toLowerCase().replace("_", ""), "set" + fieldName);
}
});
cacheGetMethod.put(clazz.getName(), get);
cacheSetMethod.put(clazz.getName(), set);
if (type.equals("get")) {
result = cacheGetMethod.get(clazz.getName());
} else if (type.equals("set")) {
result = cacheSetMethod.get(clazz.getName());
}
}
}
}
return result;
}
}
private static class SingleClass {
private static Map<String, Object> cacheObject = new HashMap<>();
private SingleClass() {
}
private static <T> T getObject(Class<T> clazz) {
T result = (T) cacheObject.get(clazz.getName());
if (result == null) {
synchronized (SingleClass.class) {
if (result == null) {
try {
cacheObject.put(clazz.getName(), clazz.newInstance());
result = (T) cacheObject.get(clazz.getName());
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
return result;
}
}
private static class CacheMethodAccess {
private CacheMethodAccess() {
}
private static Map<String, MethodAccess> cache = new HashMap<>();
private static MethodAccess getMethodAccess(Class clazz) {
MethodAccess result = cache.get(clazz.getName());
if (result == null) {
synchronized (CacheMethodAccess.class) {
if (result == null) {
cache.put(clazz.getName(), MethodAccess.get(clazz));
result = cache.get(clazz.getName());
}
}
}
return result;
}
}
private static class CacheFieldMap {
private static Map<String, Map<String, Field>> cacheMap = new HashMap<>();
private static Map<String, Field> getFieldMap(Class clazz) {
Map<String, Field> result = cacheMap.get(clazz.getName());
if (result == null) {
synchronized (CacheFieldMap.class) {
if (result == null) {
Map<String, Field> fieldMap = new HashMap<>();
for (Field field : clazz.getDeclaredFields()) {
fieldMap.put(field.getName().toLowerCase().replace("_", ""), field);
}
cacheMap.put(clazz.getName(), fieldMap);
result = cacheMap.get(clazz.getName());
}
}
}
return result;
}
}
}
......@@ -3,7 +3,7 @@ package com.linkwechat.wecom.client;
import com.dtflys.forest.annotation.DataObject;
import com.dtflys.forest.annotation.Query;
import com.dtflys.forest.annotation.Request;
import com.linkwechat.wecom.domain.dto.WeDepartMentDtoDto;
import com.linkwechat.wecom.domain.dto.WeDepartMentDto;
import com.linkwechat.wecom.domain.dto.WeResultDto;
import com.linkwechat.wecom.domain.dto.WeUserQrcodeDto;
......@@ -16,25 +16,25 @@ public interface WeDepartMentClient {
/**
* 创建部门
* @param weDepartMent
* @param deartMentDto
* @return
*/
@Request(url="/department/create",
type = "POST"
)
WeResultDto createWeDepartMent(@DataObject WeDepartMentDtoDto weDepartMent);
WeResultDto createWeDepartMent(@DataObject WeDepartMentDto.DeartMentDto deartMentDto);
/**
* 更新部门
* @param weDepartMent
* @param deartMentDto
* @return
*/
@Request(url="/department/update",
type = "POST"
)
WeResultDto updateWeDepartMent(@DataObject WeDepartMentDtoDto weDepartMent);
WeResultDto updateWeDepartMent(@DataObject WeDepartMentDto.DeartMentDto deartMentDto);
/**
......@@ -51,7 +51,7 @@ public interface WeDepartMentClient {
* @return
*/
@Request(url = "/department/list")
WeDepartMentDtoDto weDepartMents();
String weDepartMents(@Query("id") Long id);
/**
......
......@@ -7,6 +7,7 @@ import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import springfox.documentation.annotations.ApiIgnore;
/**
* 企业id相关配置对象 wx_corp_account
......
package com.linkwechat.wecom.domain;
import com.linkwechat.common.annotation.Excel;
import com.linkwechat.common.core.domain.BaseEntity;
import com.linkwechat.common.utils.SnowFlakeUtil;
import com.linkwechat.common.utils.bean.BeanUtils;
import com.linkwechat.wecom.domain.dto.WeDepartMentDto;
import lombok.Data;
/**
......@@ -17,27 +19,36 @@ public class WeDepartment extends BaseEntity
private static final long serialVersionUID = 1L;
/** $column.columnComment */
private Long id;
private Long id= SnowFlakeUtil.nextId();
/** 部门名称 */
@Excel(name = "部门名称")
private String name;
/** 部门英文名称 */
@Excel(name = "部门英文名称")
private String nameEn;
/** $column.columnComment */
@Excel(name = "部门英文名称")
/** 父节点的id */
private Long parentId;
/** 是否激活(1:是;2:否)该字段主要表示当前信息是否同步微信 */
@Excel(name = "是否激活", readConverterExp = "1=:是;2:否")
private Long isActivate;
/** 在父部门中的次序值。order值大的排序靠前。 */
@Excel(name = "在父部门中的次序值。order值大的排序靠前。")
private Long order;
/** 系统通讯录部门转化为企业微信通讯录部门的dto对象 */
public WeDepartMentDto.DeartMentDto transformDeartMentDto(WeDepartment weDepartment){
WeDepartMentDto.DeartMentDto deartMentDto=new WeDepartMentDto().new DeartMentDto();
BeanUtils.copyPropertiesignoreOther(weDepartment,deartMentDto);
return deartMentDto;
}
/** 企业微信通讯录部门的dto对象转化为系统通讯录部门对象 */
public WeDepartment transformWeDepartment(WeDepartMentDto.DeartMentDto deartMentDto){
WeDepartment weDepartment=new WeDepartment();
BeanUtils.copyPropertiesignoreOther(deartMentDto,weDepartment);
return weDepartment;
}
}
package com.linkwechat.wecom.domain.dto;
import com.linkwechat.common.utils.bean.BeanUtils;
import com.linkwechat.wecom.domain.WeDepartment;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
/**
......@@ -10,24 +13,37 @@ import java.util.List;
* @create: 2020-08-27 15:54
**/
@Data
public class WeDepartMentDtoDto extends WeResultDto {
public class WeDepartMentDto extends WeResultDto {
private List<DeartMentDto> deartMents;
private List<DeartMentDto> deartMents=new ArrayList<>();
public WeDepartMentDto(){
}
public WeDepartMentDto(WeDepartment weDepartment){
WeDepartMentDto.DeartMentDto deartMentDto=new WeDepartMentDto().new DeartMentDto();
BeanUtils.copyPropertiesignoreOther(weDepartment,deartMentDto);
deartMents.add(deartMentDto);
}
@Data
class DeartMentDto{
public class DeartMentDto{
private String name;
private Long id;
private String name_en;
private String name;
private Long parentid;
private Long order;
}
}
......@@ -4,15 +4,18 @@ import com.dtflys.forest.exceptions.ForestRuntimeException;
import com.dtflys.forest.http.ForestRequest;
import com.dtflys.forest.http.ForestResponse;
import com.dtflys.forest.interceptor.Interceptor;
import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.config.WeComeConfig;
import com.linkwechat.wecom.service.IWeAccessTokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @description: 微信token拦截器
* @author: HaoN
* @create: 2020-08-27 22:36
**/
@Component
public class WeAccessTokenInterceptor implements Interceptor {
......@@ -31,10 +34,18 @@ public class WeAccessTokenInterceptor implements Interceptor {
@Override
public boolean beforeExecute(ForestRequest request) {
//添加服务器统一请求地址
request.setUrl(weComeConfig.getServerUrl()+weComeConfig.getWeComePrefix()+request.getUrl());
request.setContentType("application/json");
String uri=request.getUrl().replace("http://","");
// 添加请求参数access_token
request.addQuery("access_token", iWeAccessTokenService.findToken());
if(!weComeConfig.getNoAccessTokenUrl().equals(uri)){
request.addQuery("access_token", iWeAccessTokenService.findToken());
}
//添加服务器统一请求地址
request.setUrl(weComeConfig.getServerUrl()+weComeConfig.getWeComePrefix()+uri);
return true;
}
......
......@@ -21,11 +21,10 @@ public interface WeDepartmentMapper
/**
* 查询企业微信组织架构相关列表
*
* @param weDepartment 企业微信组织架构相关
*
* @return 企业微信组织架构相关集合
*/
public List<WeDepartment> selectWeDepartmentList(WeDepartment weDepartment);
public List<WeDepartment> selectWeDepartmentList();
/**
* 新增企业微信组织架构相关
......
......@@ -22,10 +22,9 @@ public interface IWeDepartmentService
/**
* 查询企业微信组织架构相关列表
*
* @param weDepartment 企业微信组织架构相关
* @return 企业微信组织架构相关集合
*/
public List<WeDepartment> selectWeDepartmentList(WeDepartment weDepartment);
public List<WeDepartment> selectWeDepartmentList();
/**
* 新增企业微信组织架构相关
......
......@@ -40,17 +40,18 @@ public class WeAccessTokenServiceImpl implements IWeAccessTokenService {
*/
@Override
public String findToken() {
WeCorpAccount wxCorpAccount
= iWxCorpAccountService.findValidWeCorpAccount();
if(null == wxCorpAccount){
//返回错误异常,让用户绑定企业id相关信息
throw new WeComException("无可用的corpid和secret");
}
String weAccessToken =redisCache.getCacheObject(WeConstans.WE_ACCESS_TOKEN);
//为空,请求微信服务器同时缓存到redis中
if(StringUtils.isEmpty(weAccessToken)){
WeCorpAccount wxCorpAccount
= iWxCorpAccountService.findValidWeCorpAccount();
if(null == wxCorpAccount){
//返回错误异常,让用户绑定企业id相关信息
throw new WeComException("无可用的corpid和secret");
}
WeAccessTokenDtoDto accessToken
= accessTokenClient.getToken(wxCorpAccount.getCorpId(), wxCorpAccount.getCorpSecret());
if(accessToken.getErrcode().equals(WeConstans.WE_SUCCESS_CODE)){
......
package com.linkwechat.wecom.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.linkwechat.wecom.mapper.WeDepartmentMapper;
import cn.hutool.core.collection.ListUtil;
import com.linkwechat.common.constant.HttpStatus;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.exception.wecom.WeComException;
import com.linkwechat.common.utils.bean.BeanUtils;
import com.linkwechat.wecom.client.WeDepartMentClient;
import com.linkwechat.wecom.domain.WeDepartment;
import com.linkwechat.wecom.domain.dto.WeDepartMentDto;
import com.linkwechat.wecom.domain.dto.WeResultDto;
import com.linkwechat.wecom.mapper.WeDepartmentMapper;
import com.linkwechat.wecom.service.IWeDepartmentService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.ListUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* 企业微信组织架构相关Service业务层处理
......@@ -19,6 +31,12 @@ public class WeDepartmentServiceImpl implements IWeDepartmentService
@Autowired
private WeDepartmentMapper weDepartmentMapper;
@Autowired
private WeDepartMentClient weDepartMentClient;
/**
* 查询企业微信组织架构相关
*
......@@ -34,13 +52,28 @@ public class WeDepartmentServiceImpl implements IWeDepartmentService
/**
* 查询企业微信组织架构相关列表
*
* @param weDepartment 企业微信组织架构相关
* @return 企业微信组织架构相关
*/
@Override
public List<WeDepartment> selectWeDepartmentList(WeDepartment weDepartment)
public List<WeDepartment> selectWeDepartmentList()
{
return weDepartmentMapper.selectWeDepartmentList(weDepartment);
//校验数据中中是否存在根节点,如果不存在,从微信端获取,同时入库
// WeDepartment weDepartment=weDepartmentMapper.selectWeDepartmentById(WeConstans.WE_ROOT_DEPARMENT_ID);
// if(null == weDepartment){
// String weDepartMentDto=weDepartMentClient.weDepartMents(WeConstans.WE_ROOT_DEPARMENT_ID);
// System.out.println(weDepartMentDto);
// if(WeConstans.WE_SUCCESS_CODE.equals(weDepartMentDto.getErrcode())
// && CollectionUtils.isNotEmpty(weDepartMentDto.getDeartMents())){
//
// weDepartmentMapper.insertWeDepartment(
// weDepartment.transformWeDepartment(weDepartMentDto.getDeartMents().get(0))
// );
//
// }
// }
return weDepartmentMapper.selectWeDepartmentList();
}
/**
......@@ -52,7 +85,24 @@ public class WeDepartmentServiceImpl implements IWeDepartmentService
@Override
public int insertWeDepartment(WeDepartment weDepartment)
{
return weDepartmentMapper.insertWeDepartment(weDepartment);
int returnCode=weDepartmentMapper.insertWeDepartment(weDepartment);
if(returnCode>0){
WeResultDto weResultDto=weDepartMentClient.createWeDepartMent(
weDepartment.transformDeartMentDto(weDepartment)
);
//微信端调用不成功
if(!WeConstans.WE_SUCCESS_CODE.equals(weResultDto.getErrcode())){
throw new WeComException(weResultDto.getErrmsg());
}
}
return returnCode;
}
/**
......@@ -64,7 +114,22 @@ public class WeDepartmentServiceImpl implements IWeDepartmentService
@Override
public int updateWeDepartment(WeDepartment weDepartment)
{
return weDepartmentMapper.updateWeDepartment(weDepartment);
int returnCode=weDepartmentMapper.updateWeDepartment(weDepartment);
if(returnCode>0){
WeResultDto weResultDto=weDepartMentClient.updateWeDepartMent(
weDepartment.transformDeartMentDto(weDepartment)
);
//微信端调用不成功
if(!WeConstans.WE_SUCCESS_CODE.equals(weResultDto.getErrcode())){
throw new WeComException(weResultDto.getErrmsg());
}
}
return returnCode;
}
/**
......
......@@ -18,7 +18,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectWeCorpAccountVo">
select id, company_name, corp_id, corp_secret, status, del_flag, create_by, create_time, update_by, update_time from wx_corp_account
select id, company_name, corp_id, corp_secret, status, del_flag, create_by, create_time, update_by, update_time from we_corp_account
</sql>
<select id="selectWeCorpAccountList" parameterType="WeCorpAccount" resultMap="WeCorpAccountResult">
......@@ -37,7 +37,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<insert id="insertWeCorpAccount" parameterType="WeCorpAccount" useGeneratedKeys="true" keyProperty="id">
insert into wx_corp_account
insert into we_corp_account
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="companyName != null">company_name,</if>
<if test="corpId != null">corp_id,</if>
......@@ -63,7 +63,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</insert>
<update id="updateWeCorpAccount" parameterType="WeCorpAccount">
update wx_corp_account
update we_corp_account
<trim prefix="SET" suffixOverrides=",">
<if test="companyName != null">company_name = #{companyName},</if>
<if test="corpId != null">corp_id = #{corpId},</if>
......@@ -79,11 +79,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</update>
<delete id="deleteWeCorpAccountById" parameterType="Long">
delete from wx_corp_account where id = #{id}
delete from we_corp_account where id = #{id}
</delete>
<delete id="deleteWeCorpAccountByIds" parameterType="String">
delete from wx_corp_account where id in
delete from we_corp_account where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
......
......@@ -7,25 +7,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<resultMap type="WeDepartment" id="WeDepartmentResult">
<result property="id" column="id" />
<result property="name" column="name" />
<result property="nameEn" column="name_en" />
<result property="parentId" column="parent_id" />
<result property="isActivate" column="is_activate" />
<result property="order" column="order" />
</resultMap>
<sql id="selectWeDepartmentVo">
select id, name, name_en, parent_id, is_activate, order from we_department
select id, name, parent_id from we_department
</sql>
<select id="selectWeDepartmentList" parameterType="WeDepartment" resultMap="WeDepartmentResult">
<select id="selectWeDepartmentList" resultMap="WeDepartmentResult">
<include refid="selectWeDepartmentVo"/>
<where>
<if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
<if test="nameEn != null and nameEn != ''"> and name_en = #{nameEn}</if>
<if test="parentId != null "> and parent_id = #{parentId}</if>
<if test="isActivate != null "> and is_activate = #{isActivate}</if>
<if test="order != null "> and order = #{order}</if>
</where>
</select>
<select id="selectWeDepartmentById" parameterType="Long" resultMap="WeDepartmentResult">
......@@ -38,18 +28,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="name != null and name != ''">name,</if>
<if test="nameEn != null">name_en,</if>
<if test="parentId != null">parent_id,</if>
<if test="isActivate != null">is_activate,</if>
<if test="order != null">order,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="name != null and name != ''">#{name},</if>
<if test="nameEn != null">#{nameEn},</if>
<if test="parentId != null">#{parentId},</if>
<if test="isActivate != null">#{isActivate},</if>
<if test="order != null">#{order},</if>
</trim>
</insert>
......@@ -57,10 +41,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
update we_department
<trim prefix="SET" suffixOverrides=",">
<if test="name != null and name != ''">name = #{name},</if>
<if test="nameEn != null">name_en = #{nameEn},</if>
<if test="parentId != null">parent_id = #{parentId},</if>
<if test="isActivate != null">is_activate = #{isActivate},</if>
<if test="order != null">order = #{order},</if>
</trim>
where id = #{id}
</update>
......
......@@ -33,6 +33,8 @@
<jwt.version>0.9.0</jwt.version>
<forest.version>1.4.0</forest.version>
<lombok.version>1.16.18</lombok.version>
<reflectasm.version>1.11.9</reflectasm.version>
<hutool.version>5.4.1</hutool.version>
</properties>
<!-- 依赖声明 -->
......@@ -205,6 +207,19 @@
<version>${lombok.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.esotericsoftware/reflectasm -->
<dependency>
<groupId>com.esotericsoftware</groupId>
<artifactId>reflectasm</artifactId>
<version>${reflectasm.version}</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>${hutool.version}</version>
</dependency>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!