Commit 2c012173 by HaoN

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

1 parent 13178aa4
Showing 24 changed files with 467 additions and 138 deletions
...@@ -2,6 +2,9 @@ package com.linkwechat.web.controller.system; ...@@ -2,6 +2,9 @@ package com.linkwechat.web.controller.system;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; 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.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
...@@ -39,6 +42,7 @@ import com.linkwechat.system.service.ISysUserService; ...@@ -39,6 +42,7 @@ import com.linkwechat.system.service.ISysUserService;
*/ */
@RestController @RestController
@RequestMapping("/system/user") @RequestMapping("/system/user")
@Api("系统用户管理")
public class SysUserController extends BaseController public class SysUserController extends BaseController
{ {
@Autowired @Autowired
...@@ -58,6 +62,7 @@ public class SysUserController extends BaseController ...@@ -58,6 +62,7 @@ public class SysUserController extends BaseController
*/ */
@PreAuthorize("@ss.hasPermi('system:user:list')") @PreAuthorize("@ss.hasPermi('system:user:list')")
@GetMapping("/list") @GetMapping("/list")
@ApiOperation("获取用户列表")
public TableDataInfo list(SysUser user) public TableDataInfo list(SysUser user)
{ {
startPage(); startPage();
......
...@@ -12,7 +12,6 @@ import io.swagger.annotations.ApiOperation; ...@@ -12,7 +12,6 @@ import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
/** /**
...@@ -34,6 +33,7 @@ public class WeCorpAccountController extends BaseController ...@@ -34,6 +33,7 @@ public class WeCorpAccountController extends BaseController
*/ */
@PreAuthorize("@ss.hasPermi('wechat:corp:list')") @PreAuthorize("@ss.hasPermi('wechat:corp:list')")
@GetMapping("/list") @GetMapping("/list")
@ApiOperation("获取企业id列表")
public TableDataInfo list(WeCorpAccount weCorpAccount) public TableDataInfo list(WeCorpAccount weCorpAccount)
{ {
startPage(); startPage();
...@@ -41,24 +41,13 @@ public class WeCorpAccountController extends BaseController ...@@ -41,24 +41,13 @@ public class WeCorpAccountController extends BaseController
return getDataTable(list); 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相关配置详细信息 * 获取企业id相关配置详细信息
*/ */
@PreAuthorize("@ss.hasPermi('wechat:corp:query')") @PreAuthorize("@ss.hasPermi('wechat:corp:query')")
@GetMapping(value = "/{id}") @GetMapping(value = "/{id}")
@ApiOperation("获取企业id相关详情")
public AjaxResult getInfo(@PathVariable("id") Long id) public AjaxResult getInfo(@PathVariable("id") Long id)
{ {
return AjaxResult.success(weCorpAccountService.selectWeCorpAccountById(id)); return AjaxResult.success(weCorpAccountService.selectWeCorpAccountById(id));
...@@ -67,10 +56,10 @@ public class WeCorpAccountController extends BaseController ...@@ -67,10 +56,10 @@ public class WeCorpAccountController extends BaseController
/** /**
* 新增企业id相关配置 * 新增企业id相关配置
*/ */
// @PreAuthorize("@ss.hasPermi('wechat:corp:add')") @PreAuthorize("@ss.hasPermi('wechat:corp:add')")
// @Log(title = "企业id相关配置", businessType = BusinessType.INSERT) @Log(title = "企业id相关配置", businessType = BusinessType.INSERT)
@PostMapping @PostMapping
@ApiOperation("新增") @ApiOperation("新增企业id")
public AjaxResult add(@RequestBody WeCorpAccount weCorpAccount) public AjaxResult add(@RequestBody WeCorpAccount weCorpAccount)
{ {
return toAjax(weCorpAccountService.insertWeCorpAccount(weCorpAccount)); return toAjax(weCorpAccountService.insertWeCorpAccount(weCorpAccount));
...@@ -82,20 +71,22 @@ public class WeCorpAccountController extends BaseController ...@@ -82,20 +71,22 @@ public class WeCorpAccountController extends BaseController
@PreAuthorize("@ss.hasPermi('wechat:corp:edit')") @PreAuthorize("@ss.hasPermi('wechat:corp:edit')")
@Log(title = "企业id相关配置", businessType = BusinessType.UPDATE) @Log(title = "企业id相关配置", businessType = BusinessType.UPDATE)
@PutMapping @PutMapping
@ApiOperation("修改企业id")
public AjaxResult edit(@RequestBody WeCorpAccount weCorpAccount) public AjaxResult edit(@RequestBody WeCorpAccount weCorpAccount)
{ {
return toAjax(weCorpAccountService.updateWeCorpAccount(weCorpAccount)); return toAjax(weCorpAccountService.updateWeCorpAccount(weCorpAccount));
} }
/** // /**
* 删除企业id相关配置 // * 删除企业id相关配置
*/ // */
@PreAuthorize("@ss.hasPermi('wechat:corp:remove')") // @PreAuthorize("@ss.hasPermi('wechat:corp:remove')")
@Log(title = "企业id相关配置", businessType = BusinessType.DELETE) // @Log(title = "企业id相关配置", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}") // @DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids) // @ApiOperation("根据id删除企业id")
{ // public AjaxResult remove(@PathVariable Long[] ids)
return toAjax(weCorpAccountService.deleteWeCorpAccountByIds(ids)); // {
} // return toAjax(weCorpAccountService.deleteWeCorpAccountByIds(ids));
// }
} }
...@@ -8,6 +8,8 @@ import com.linkwechat.common.core.domain.AjaxResult; ...@@ -8,6 +8,8 @@ import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.page.TableDataInfo; import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.enums.BusinessType; import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.common.utils.poi.ExcelUtil; 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.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
...@@ -18,7 +20,6 @@ import org.springframework.web.bind.annotation.PathVariable; ...@@ -18,7 +20,6 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.linkwechat.wecom.domain.WeDepartment; import com.linkwechat.wecom.domain.WeDepartment;
import com.linkwechat.wecom.service.IWeDepartmentService; import com.linkwechat.wecom.service.IWeDepartmentService;
...@@ -28,6 +29,7 @@ import com.linkwechat.wecom.service.IWeDepartmentService; ...@@ -28,6 +29,7 @@ import com.linkwechat.wecom.service.IWeDepartmentService;
* @author ruoyi * @author ruoyi
* @date 2020-09-01 * @date 2020-09-01
*/ */
@Api("微信组织架构相关接口")
@RestController @RestController
@RequestMapping("/wecom/department") @RequestMapping("/wecom/department")
public class WeDepartmentController extends BaseController public class WeDepartmentController extends BaseController
...@@ -40,35 +42,24 @@ public class WeDepartmentController extends BaseController ...@@ -40,35 +42,24 @@ public class WeDepartmentController extends BaseController
*/ */
@PreAuthorize("@ss.hasPermi('wecom:department:list')") @PreAuthorize("@ss.hasPermi('wecom:department:list')")
@GetMapping("/list") @GetMapping("/list")
public TableDataInfo list(WeDepartment weDepartment) @ApiOperation("获取部门列表")
public TableDataInfo list()
{ {
startPage(); List<WeDepartment> list = weDepartmentService.selectWeDepartmentList();
List<WeDepartment> list = weDepartmentService.selectWeDepartmentList(weDepartment);
return getDataTable(list); return getDataTable(list);
} }
//
/** //
* 导出企业微信组织架构相关列表 //
*/ // /**
@PreAuthorize("@ss.hasPermi('wecom:department:export')") // * 获取企业微信组织架构相关详细信息
@Log(title = "企业微信组织架构相关", businessType = BusinessType.EXPORT) // */
@GetMapping("/export") // @PreAuthorize("@ss.hasPermi('wecom:department:query')")
public AjaxResult export(WeDepartment weDepartment) // @GetMapping(value = "/{id}")
{ // public AjaxResult getInfo(@PathVariable("id") Long id)
List<WeDepartment> list = weDepartmentService.selectWeDepartmentList(weDepartment); // {
ExcelUtil<WeDepartment> util = new ExcelUtil<WeDepartment>(WeDepartment.class); // return AjaxResult.success(weDepartmentService.selectWeDepartmentById(id));
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));
}
/** /**
* 新增企业微信组织架构相关 * 新增企业微信组织架构相关
...@@ -76,6 +67,7 @@ public class WeDepartmentController extends BaseController ...@@ -76,6 +67,7 @@ public class WeDepartmentController extends BaseController
@PreAuthorize("@ss.hasPermi('wecom:department:add')") @PreAuthorize("@ss.hasPermi('wecom:department:add')")
@Log(title = "企业微信组织架构相关", businessType = BusinessType.INSERT) @Log(title = "企业微信组织架构相关", businessType = BusinessType.INSERT)
@PostMapping @PostMapping
@ApiOperation("添加部门")
public AjaxResult add(@RequestBody WeDepartment weDepartment) public AjaxResult add(@RequestBody WeDepartment weDepartment)
{ {
return toAjax(weDepartmentService.insertWeDepartment(weDepartment)); return toAjax(weDepartmentService.insertWeDepartment(weDepartment));
...@@ -87,19 +79,20 @@ public class WeDepartmentController extends BaseController ...@@ -87,19 +79,20 @@ public class WeDepartmentController extends BaseController
@PreAuthorize("@ss.hasPermi('wecom:department:edit')") @PreAuthorize("@ss.hasPermi('wecom:department:edit')")
@Log(title = "企业微信组织架构相关", businessType = BusinessType.UPDATE) @Log(title = "企业微信组织架构相关", businessType = BusinessType.UPDATE)
@PutMapping @PutMapping
@ApiOperation("更新部门")
public AjaxResult edit(@RequestBody WeDepartment weDepartment) public AjaxResult edit(@RequestBody WeDepartment weDepartment)
{ {
return toAjax(weDepartmentService.updateWeDepartment(weDepartment)); return toAjax(weDepartmentService.updateWeDepartment(weDepartment));
} }
//
/** // /**
* 删除企业微信组织架构相关 // * 删除企业微信组织架构相关
*/ // */
@PreAuthorize("@ss.hasPermi('wecom:department:remove')") // @PreAuthorize("@ss.hasPermi('wecom:department:remove')")
@Log(title = "企业微信组织架构相关", businessType = BusinessType.DELETE) // @Log(title = "企业微信组织架构相关", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}") // @DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids) // public AjaxResult remove(@PathVariable Long[] ids)
{ // {
return toAjax(weDepartmentService.deleteWeDepartmentByIds(ids)); // return toAjax(weDepartmentService.deleteWeDepartmentByIds(ids));
} // }
} }
...@@ -107,7 +107,7 @@ swagger: ...@@ -107,7 +107,7 @@ swagger:
# 是否开启swagger # 是否开启swagger
enabled: true enabled: true
# 请求前缀 # 请求前缀
pathMapping: /dev-api pathMapping:
# 防止XSS攻击 # 防止XSS攻击
xss: xss:
...@@ -126,3 +126,4 @@ forest: ...@@ -126,3 +126,4 @@ forest:
wecome: wecome:
serverUrl: https://qyapi.weixin.qq.com/ serverUrl: https://qyapi.weixin.qq.com/
weComePrefix: cgi-bin weComePrefix: cgi-bin
noAccessTokenUrl: /gettoken
\ No newline at end of file \ No newline at end of file
...@@ -151,6 +151,20 @@ ...@@ -151,6 +151,20 @@
</dependency> </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> </dependencies>
</project> </project>
\ No newline at end of file \ No newline at end of file
...@@ -18,4 +18,7 @@ public class WeComeConfig { ...@@ -18,4 +18,7 @@ public class WeComeConfig {
/** 企业微信后台地址前缀 */ /** 企业微信后台地址前缀 */
private String weComePrefix; private String weComePrefix;
/** 企业微信端无需token的url */
private String noAccessTokenUrl;
} }
...@@ -126,4 +126,8 @@ public class Constants ...@@ -126,4 +126,8 @@ public class Constants
* 资源映射路径 前缀 * 资源映射路径 前缀
*/ */
public static final String RESOURCE_PREFIX = "/profile"; public static final String RESOURCE_PREFIX = "/profile";
/** 是否为系统默认(是) */
public static final int SERVICE_STATUS_ERROR = -1;
} }
...@@ -10,11 +10,17 @@ public class WeConstans { ...@@ -10,11 +10,17 @@ public class WeConstans {
/** /**
* 企业微信相关token * 企业微信相关token
*/ */
public static final String WE_ACCESS_TOKEN = "WeAccessToken"; public static final String WE_ACCESS_TOKEN = "we_access_token";
/** /**
* 企业微信接口返回成功code * 企业微信接口返回成功code
*/ */
public static final Integer WE_SUCCESS_CODE = 0; 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; ...@@ -6,6 +6,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import springfox.documentation.annotations.ApiIgnore;
/** /**
* Entity基类 * 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; 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.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
...@@ -107,4 +113,172 @@ public class BeanUtils extends org.springframework.beans.BeanUtils ...@@ -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)); 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; ...@@ -3,7 +3,7 @@ package com.linkwechat.wecom.client;
import com.dtflys.forest.annotation.DataObject; import com.dtflys.forest.annotation.DataObject;
import com.dtflys.forest.annotation.Query; import com.dtflys.forest.annotation.Query;
import com.dtflys.forest.annotation.Request; 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.WeResultDto;
import com.linkwechat.wecom.domain.dto.WeUserQrcodeDto; import com.linkwechat.wecom.domain.dto.WeUserQrcodeDto;
...@@ -16,25 +16,25 @@ public interface WeDepartMentClient { ...@@ -16,25 +16,25 @@ public interface WeDepartMentClient {
/** /**
* 创建部门 * 创建部门
* @param weDepartMent * @param deartMentDto
* @return * @return
*/ */
@Request(url="/department/create", @Request(url="/department/create",
type = "POST" type = "POST"
) )
WeResultDto createWeDepartMent(@DataObject WeDepartMentDtoDto weDepartMent); WeResultDto createWeDepartMent(@DataObject WeDepartMentDto.DeartMentDto deartMentDto);
/** /**
* 更新部门 * 更新部门
* @param weDepartMent * @param deartMentDto
* @return * @return
*/ */
@Request(url="/department/update", @Request(url="/department/update",
type = "POST" type = "POST"
) )
WeResultDto updateWeDepartMent(@DataObject WeDepartMentDtoDto weDepartMent); WeResultDto updateWeDepartMent(@DataObject WeDepartMentDto.DeartMentDto deartMentDto);
/** /**
...@@ -51,7 +51,7 @@ public interface WeDepartMentClient { ...@@ -51,7 +51,7 @@ public interface WeDepartMentClient {
* @return * @return
*/ */
@Request(url = "/department/list") @Request(url = "/department/list")
WeDepartMentDtoDto weDepartMents(); String weDepartMents(@Query("id") Long id);
/** /**
......
...@@ -7,6 +7,7 @@ import lombok.AllArgsConstructor; ...@@ -7,6 +7,7 @@ import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import springfox.documentation.annotations.ApiIgnore;
/** /**
* 企业id相关配置对象 wx_corp_account * 企业id相关配置对象 wx_corp_account
......
package com.linkwechat.wecom.domain; package com.linkwechat.wecom.domain;
import com.linkwechat.common.annotation.Excel;
import com.linkwechat.common.core.domain.BaseEntity; 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; import lombok.Data;
/** /**
...@@ -17,27 +19,36 @@ public class WeDepartment extends BaseEntity ...@@ -17,27 +19,36 @@ public class WeDepartment extends BaseEntity
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** $column.columnComment */ /** $column.columnComment */
private Long id; private Long id= SnowFlakeUtil.nextId();
/** 部门名称 */ /** 部门名称 */
@Excel(name = "部门名称")
private String name; private String name;
/** 部门英文名称 */
@Excel(name = "部门英文名称")
private String nameEn;
/** $column.columnComment */ /** 父节点的id */
@Excel(name = "部门英文名称")
private Long parentId; private Long parentId;
/** 是否激活(1:是;2:否)该字段主要表示当前信息是否同步微信 */
@Excel(name = "是否激活", readConverterExp = "1=:是;2:否")
private Long isActivate;
/** 在父部门中的次序值。order值大的排序靠前。 */
@Excel(name = "在父部门中的次序值。order值大的排序靠前。") /** 系统通讯录部门转化为企业微信通讯录部门的dto对象 */
private Long order; 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; package com.linkwechat.wecom.domain.dto;
import com.linkwechat.common.utils.bean.BeanUtils;
import com.linkwechat.wecom.domain.WeDepartment;
import lombok.Data; import lombok.Data;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
...@@ -10,24 +13,37 @@ import java.util.List; ...@@ -10,24 +13,37 @@ import java.util.List;
* @create: 2020-08-27 15:54 * @create: 2020-08-27 15:54
**/ **/
@Data @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 @Data
class DeartMentDto{ public class DeartMentDto{
private String name; private Long id;
private String name_en; private String name;
private Long parentid; private Long parentid;
private Long order;
} }
} }
...@@ -4,15 +4,18 @@ import com.dtflys.forest.exceptions.ForestRuntimeException; ...@@ -4,15 +4,18 @@ import com.dtflys.forest.exceptions.ForestRuntimeException;
import com.dtflys.forest.http.ForestRequest; import com.dtflys.forest.http.ForestRequest;
import com.dtflys.forest.http.ForestResponse; import com.dtflys.forest.http.ForestResponse;
import com.dtflys.forest.interceptor.Interceptor; import com.dtflys.forest.interceptor.Interceptor;
import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.config.WeComeConfig; import com.linkwechat.common.config.WeComeConfig;
import com.linkwechat.wecom.service.IWeAccessTokenService; import com.linkwechat.wecom.service.IWeAccessTokenService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/** /**
* @description: 微信token拦截器 * @description: 微信token拦截器
* @author: HaoN * @author: HaoN
* @create: 2020-08-27 22:36 * @create: 2020-08-27 22:36
**/ **/
@Component
public class WeAccessTokenInterceptor implements Interceptor { public class WeAccessTokenInterceptor implements Interceptor {
...@@ -31,10 +34,18 @@ public class WeAccessTokenInterceptor implements Interceptor { ...@@ -31,10 +34,18 @@ public class WeAccessTokenInterceptor implements Interceptor {
@Override @Override
public boolean beforeExecute(ForestRequest request) { public boolean beforeExecute(ForestRequest request) {
//添加服务器统一请求地址 request.setContentType("application/json");
request.setUrl(weComeConfig.getServerUrl()+weComeConfig.getWeComePrefix()+request.getUrl()); String uri=request.getUrl().replace("http://","");
// 添加请求参数access_token // 添加请求参数access_token
if(!weComeConfig.getNoAccessTokenUrl().equals(uri)){
request.addQuery("access_token", iWeAccessTokenService.findToken()); request.addQuery("access_token", iWeAccessTokenService.findToken());
}
//添加服务器统一请求地址
request.setUrl(weComeConfig.getServerUrl()+weComeConfig.getWeComePrefix()+uri);
return true; return true;
} }
......
...@@ -22,10 +22,9 @@ public interface WeDepartmentMapper ...@@ -22,10 +22,9 @@ public interface WeDepartmentMapper
/** /**
* 查询企业微信组织架构相关列表 * 查询企业微信组织架构相关列表
* *
* @param weDepartment 企业微信组织架构相关
* @return 企业微信组织架构相关集合 * @return 企业微信组织架构相关集合
*/ */
public List<WeDepartment> selectWeDepartmentList(WeDepartment weDepartment); public List<WeDepartment> selectWeDepartmentList();
/** /**
* 新增企业微信组织架构相关 * 新增企业微信组织架构相关
......
...@@ -22,10 +22,9 @@ public interface IWeDepartmentService ...@@ -22,10 +22,9 @@ public interface IWeDepartmentService
/** /**
* 查询企业微信组织架构相关列表 * 查询企业微信组织架构相关列表
* *
* @param weDepartment 企业微信组织架构相关
* @return 企业微信组织架构相关集合 * @return 企业微信组织架构相关集合
*/ */
public List<WeDepartment> selectWeDepartmentList(WeDepartment weDepartment); public List<WeDepartment> selectWeDepartmentList();
/** /**
* 新增企业微信组织架构相关 * 新增企业微信组织架构相关
......
...@@ -40,6 +40,11 @@ public class WeAccessTokenServiceImpl implements IWeAccessTokenService { ...@@ -40,6 +40,11 @@ public class WeAccessTokenServiceImpl implements IWeAccessTokenService {
*/ */
@Override @Override
public String findToken() { public String findToken() {
String weAccessToken =redisCache.getCacheObject(WeConstans.WE_ACCESS_TOKEN);
//为空,请求微信服务器同时缓存到redis中
if(StringUtils.isEmpty(weAccessToken)){
WeCorpAccount wxCorpAccount WeCorpAccount wxCorpAccount
= iWxCorpAccountService.findValidWeCorpAccount(); = iWxCorpAccountService.findValidWeCorpAccount();
if(null == wxCorpAccount){ if(null == wxCorpAccount){
...@@ -47,10 +52,6 @@ public class WeAccessTokenServiceImpl implements IWeAccessTokenService { ...@@ -47,10 +52,6 @@ public class WeAccessTokenServiceImpl implements IWeAccessTokenService {
throw new WeComException("无可用的corpid和secret"); throw new WeComException("无可用的corpid和secret");
} }
String weAccessToken =redisCache.getCacheObject(WeConstans.WE_ACCESS_TOKEN);
//为空,请求微信服务器同时缓存到redis中
if(StringUtils.isEmpty(weAccessToken)){
WeAccessTokenDtoDto accessToken WeAccessTokenDtoDto accessToken
= accessTokenClient.getToken(wxCorpAccount.getCorpId(), wxCorpAccount.getCorpSecret()); = accessTokenClient.getToken(wxCorpAccount.getCorpId(), wxCorpAccount.getCorpSecret());
if(accessToken.getErrcode().equals(WeConstans.WE_SUCCESS_CODE)){ if(accessToken.getErrcode().equals(WeConstans.WE_SUCCESS_CODE)){
......
package com.linkwechat.wecom.service.impl; package com.linkwechat.wecom.service.impl;
import java.util.List; import cn.hutool.core.collection.ListUtil;
import org.springframework.beans.factory.annotation.Autowired; import com.linkwechat.common.constant.HttpStatus;
import org.springframework.stereotype.Service; import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.wecom.mapper.WeDepartmentMapper; 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.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 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业务层处理 * 企业微信组织架构相关Service业务层处理
...@@ -19,6 +31,12 @@ public class WeDepartmentServiceImpl implements IWeDepartmentService ...@@ -19,6 +31,12 @@ public class WeDepartmentServiceImpl implements IWeDepartmentService
@Autowired @Autowired
private WeDepartmentMapper weDepartmentMapper; private WeDepartmentMapper weDepartmentMapper;
@Autowired
private WeDepartMentClient weDepartMentClient;
/** /**
* 查询企业微信组织架构相关 * 查询企业微信组织架构相关
* *
...@@ -34,13 +52,28 @@ public class WeDepartmentServiceImpl implements IWeDepartmentService ...@@ -34,13 +52,28 @@ public class WeDepartmentServiceImpl implements IWeDepartmentService
/** /**
* 查询企业微信组织架构相关列表 * 查询企业微信组织架构相关列表
* *
* @param weDepartment 企业微信组织架构相关
* @return 企业微信组织架构相关 * @return 企业微信组织架构相关
*/ */
@Override @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 ...@@ -52,7 +85,24 @@ public class WeDepartmentServiceImpl implements IWeDepartmentService
@Override @Override
public int insertWeDepartment(WeDepartment weDepartment) 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 ...@@ -64,7 +114,22 @@ public class WeDepartmentServiceImpl implements IWeDepartmentService
@Override @Override
public int updateWeDepartment(WeDepartment weDepartment) 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" ...@@ -18,7 +18,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap> </resultMap>
<sql id="selectWeCorpAccountVo"> <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> </sql>
<select id="selectWeCorpAccountList" parameterType="WeCorpAccount" resultMap="WeCorpAccountResult"> <select id="selectWeCorpAccountList" parameterType="WeCorpAccount" resultMap="WeCorpAccountResult">
...@@ -37,7 +37,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -37,7 +37,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select> </select>
<insert id="insertWeCorpAccount" parameterType="WeCorpAccount" useGeneratedKeys="true" keyProperty="id"> <insert id="insertWeCorpAccount" parameterType="WeCorpAccount" useGeneratedKeys="true" keyProperty="id">
insert into wx_corp_account insert into we_corp_account
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="companyName != null">company_name,</if> <if test="companyName != null">company_name,</if>
<if test="corpId != null">corp_id,</if> <if test="corpId != null">corp_id,</if>
...@@ -63,7 +63,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -63,7 +63,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</insert> </insert>
<update id="updateWeCorpAccount" parameterType="WeCorpAccount"> <update id="updateWeCorpAccount" parameterType="WeCorpAccount">
update wx_corp_account update we_corp_account
<trim prefix="SET" suffixOverrides=","> <trim prefix="SET" suffixOverrides=",">
<if test="companyName != null">company_name = #{companyName},</if> <if test="companyName != null">company_name = #{companyName},</if>
<if test="corpId != null">corp_id = #{corpId},</if> <if test="corpId != null">corp_id = #{corpId},</if>
...@@ -79,11 +79,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -79,11 +79,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</update> </update>
<delete id="deleteWeCorpAccountById" parameterType="Long"> <delete id="deleteWeCorpAccountById" parameterType="Long">
delete from wx_corp_account where id = #{id} delete from we_corp_account where id = #{id}
</delete> </delete>
<delete id="deleteWeCorpAccountByIds" parameterType="String"> <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=")"> <foreach item="id" collection="array" open="(" separator="," close=")">
#{id} #{id}
</foreach> </foreach>
......
...@@ -7,25 +7,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -7,25 +7,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<resultMap type="WeDepartment" id="WeDepartmentResult"> <resultMap type="WeDepartment" id="WeDepartmentResult">
<result property="id" column="id" /> <result property="id" column="id" />
<result property="name" column="name" /> <result property="name" column="name" />
<result property="nameEn" column="name_en" />
<result property="parentId" column="parent_id" /> <result property="parentId" column="parent_id" />
<result property="isActivate" column="is_activate" />
<result property="order" column="order" />
</resultMap> </resultMap>
<sql id="selectWeDepartmentVo"> <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> </sql>
<select id="selectWeDepartmentList" parameterType="WeDepartment" resultMap="WeDepartmentResult"> <select id="selectWeDepartmentList" resultMap="WeDepartmentResult">
<include refid="selectWeDepartmentVo"/> <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>
<select id="selectWeDepartmentById" parameterType="Long" resultMap="WeDepartmentResult"> <select id="selectWeDepartmentById" parameterType="Long" resultMap="WeDepartmentResult">
...@@ -38,18 +28,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -38,18 +28,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if> <if test="id != null">id,</if>
<if test="name != null and name != ''">name,</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="parentId != null">parent_id,</if>
<if test="isActivate != null">is_activate,</if>
<if test="order != null">order,</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if> <if test="id != null">#{id},</if>
<if test="name != null and name != ''">#{name},</if> <if test="name != null and name != ''">#{name},</if>
<if test="nameEn != null">#{nameEn},</if>
<if test="parentId != null">#{parentId},</if> <if test="parentId != null">#{parentId},</if>
<if test="isActivate != null">#{isActivate},</if>
<if test="order != null">#{order},</if>
</trim> </trim>
</insert> </insert>
...@@ -57,10 +41,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -57,10 +41,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
update we_department update we_department
<trim prefix="SET" suffixOverrides=","> <trim prefix="SET" suffixOverrides=",">
<if test="name != null and name != ''">name = #{name},</if> <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="parentId != null">parent_id = #{parentId},</if>
<if test="isActivate != null">is_activate = #{isActivate},</if>
<if test="order != null">order = #{order},</if>
</trim> </trim>
where id = #{id} where id = #{id}
</update> </update>
......
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
<jwt.version>0.9.0</jwt.version> <jwt.version>0.9.0</jwt.version>
<forest.version>1.4.0</forest.version> <forest.version>1.4.0</forest.version>
<lombok.version>1.16.18</lombok.version> <lombok.version>1.16.18</lombok.version>
<reflectasm.version>1.11.9</reflectasm.version>
<hutool.version>5.4.1</hutool.version>
</properties> </properties>
<!-- 依赖声明 --> <!-- 依赖声明 -->
...@@ -205,6 +207,19 @@ ...@@ -205,6 +207,19 @@
<version>${lombok.version}</version> <version>${lombok.version}</version>
</dependency> </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!