企业微信组织机构、成员同步优化
This commit is contained in:
parent
a46e1be094
commit
a357d733a0
|
|
@ -22,7 +22,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-devtools</artifactId>
|
<artifactId>spring-boot-devtools</artifactId>
|
||||||
<optional>true</optional> <!-- 表示依赖不会传递 -->
|
<optional>false</optional> <!-- 表示依赖不会传递 -->
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- swagger2-->
|
<!-- swagger2-->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
||||||
|
|
@ -26,25 +26,29 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Binary Wang(https://github.com/binarywang)
|
* 同步
|
||||||
|
* @author zhujj
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/wx/cp/user/group")
|
@RequestMapping("/wx/cp/department")
|
||||||
public class WxUserGroupController {
|
public class WxDepartmentController {
|
||||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
||||||
private WxCpProperties properties;
|
private WxCpProperties properties;
|
||||||
|
|
||||||
@Log(title = "获取组织机构列表", businessType = BusinessType.INSERT)
|
/**
|
||||||
|
* 获取指定部门及其下的子部门。 如果不填,默认获取全量组织架构
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@GetMapping("/departAllList")
|
@GetMapping("/departAllList")
|
||||||
public AjaxResult departAllList() {
|
public AjaxResult departAllList(Long id) {
|
||||||
this.logger.info("\n获取组织机构");
|
|
||||||
try {
|
try {
|
||||||
final WxCpService wxCpService = WxCpConfiguration.getCpService(999999);
|
final WxCpService wxCpService = WxCpConfiguration.getCpService(999999);
|
||||||
WxCpDepartmentService departmentService = wxCpService.getDepartmentService();
|
WxCpDepartmentService departmentService = wxCpService.getDepartmentService();
|
||||||
List<WxCpDepart> list = departmentService.list(null);
|
List<WxCpDepart> list = departmentService.list(id);
|
||||||
return AjaxResult.success(list,"获取组织机构成功");
|
return AjaxResult.success(list,"获取组织机构成功");
|
||||||
} catch (WxErrorException e) {
|
} catch (WxErrorException e) {
|
||||||
return AjaxResult.error("获取组织机构出错,错误码【"+ e.getError().getErrorCode()+"】,原因:"+ ErrorCodeText.errorMsg(e.getError().getErrorCode()));
|
return AjaxResult.error("获取组织机构出错,错误码【"+ e.getError().getErrorCode()+"】,原因:"+ ErrorCodeText.errorMsg(e.getError().getErrorCode()));
|
||||||
|
|
@ -54,7 +58,6 @@ public class WxUserGroupController {
|
||||||
@Log(title = "新增组织机构", businessType = BusinessType.INSERT)
|
@Log(title = "新增组织机构", businessType = BusinessType.INSERT)
|
||||||
@PostMapping("/insert")
|
@PostMapping("/insert")
|
||||||
public AjaxResult insert(@RequestBody WxCpDepart wxCpDepart) {
|
public AjaxResult insert(@RequestBody WxCpDepart wxCpDepart) {
|
||||||
this.logger.info("新增组织机构");
|
|
||||||
try {
|
try {
|
||||||
WxCpDepartmentService departmentService = WxCpConfiguration.getCpService(999999).getDepartmentService();
|
WxCpDepartmentService departmentService = WxCpConfiguration.getCpService(999999).getDepartmentService();
|
||||||
Integer id = departmentService.create(wxCpDepart);
|
Integer id = departmentService.create(wxCpDepart);
|
||||||
|
|
@ -77,7 +80,7 @@ public class WxUserGroupController {
|
||||||
return AjaxResult.error("全量新增组织机构失败,错误码【"+ e.getError().getErrorCode()+"】,原因:"+ ErrorCodeText.errorMsg(e.getError().getErrorCode()));
|
return AjaxResult.error("全量新增组织机构失败,错误码【"+ e.getError().getErrorCode()+"】,原因:"+ ErrorCodeText.errorMsg(e.getError().getErrorCode()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Log(title = "获取组织机构", businessType = BusinessType.INSERT)
|
@Log(title = "获取组织机构", businessType = BusinessType.UPDATE)
|
||||||
@PostMapping("/update")
|
@PostMapping("/update")
|
||||||
public AjaxResult update(@RequestBody WxCpDepart wxCpDepart) {
|
public AjaxResult update(@RequestBody WxCpDepart wxCpDepart) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -90,7 +93,7 @@ public class WxUserGroupController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Log(title = "删除组织机构", businessType = BusinessType.INSERT)
|
@Log(title = "删除组织机构", businessType = BusinessType.DELETE)
|
||||||
@GetMapping("/delete/{id}")
|
@GetMapping("/delete/{id}")
|
||||||
public AjaxResult delete(@PathVariable("id") Long id) {
|
public AjaxResult delete(@PathVariable("id") Long id) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -0,0 +1,121 @@
|
||||||
|
package com.ruoyi.wx.cp.controller;
|
||||||
|
|
||||||
|
import com.ruoyi.common.annotation.Log;
|
||||||
|
import com.ruoyi.common.base.AjaxResult;
|
||||||
|
import com.ruoyi.common.enums.BusinessType;
|
||||||
|
import com.ruoyi.wx.cp.config.WxCpConfiguration;
|
||||||
|
import com.ruoyi.wx.cp.config.WxCpProperties;
|
||||||
|
import com.ruoyi.wx.cp.constant.ErrorCodeText;
|
||||||
|
import me.chanjar.weixin.common.error.WxErrorException;
|
||||||
|
import me.chanjar.weixin.cp.api.WxCpDepartmentService;
|
||||||
|
import me.chanjar.weixin.cp.api.WxCpService;
|
||||||
|
import me.chanjar.weixin.cp.api.WxCpUserService;
|
||||||
|
import me.chanjar.weixin.cp.bean.WxCpDepart;
|
||||||
|
import me.chanjar.weixin.cp.bean.WxCpUser;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 成员同步
|
||||||
|
* @author zhujj
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/wx/cp/user")
|
||||||
|
public class WxUserController {
|
||||||
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private WxCpProperties properties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取成员列表详情
|
||||||
|
* @param departId 部门id
|
||||||
|
* @param fetch_child 是否递归获取子部门下面的成员
|
||||||
|
* @param state 成员状态 默认0-正常
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/userList")
|
||||||
|
public AjaxResult userList(Long departId,boolean fetch_child,Integer state) {
|
||||||
|
try {
|
||||||
|
WxCpUserService userService = WxCpConfiguration.getCpService(999999).getUserService();
|
||||||
|
|
||||||
|
List<WxCpUser> wxCpUsers = userService.listByDepartment(departId, fetch_child, state);
|
||||||
|
return AjaxResult.success(wxCpUsers,"获取成员成功");
|
||||||
|
} catch (WxErrorException e) {
|
||||||
|
return AjaxResult.error("获取成员出错,错误码【"+ e.getError().getErrorCode()+"】,原因:"+ ErrorCodeText.errorMsg(e.getError().getErrorCode()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取成员列表(只返回成员简洁信息)
|
||||||
|
* @param departId 部门id
|
||||||
|
* @param fetch_child 是否递归获取子部门下面的成员
|
||||||
|
* @param state 成员状态 默认0-正常
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/userSimpleList")
|
||||||
|
public AjaxResult userSimpleList(Long departId,boolean fetch_child,Integer state) {
|
||||||
|
try {
|
||||||
|
WxCpUserService userService = WxCpConfiguration.getCpService(999999).getUserService();
|
||||||
|
List<WxCpUser> wxCpUsers = userService.listSimpleByDepartment(departId, fetch_child, state);
|
||||||
|
return AjaxResult.success(wxCpUsers,"获取成员成功");
|
||||||
|
} catch (WxErrorException e) {
|
||||||
|
return AjaxResult.error("获取成员出错,错误码【"+ e.getError().getErrorCode()+"】,原因:"+ ErrorCodeText.errorMsg(e.getError().getErrorCode()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Log(title = "新增成员", businessType = BusinessType.INSERT)
|
||||||
|
@PostMapping("/insert")
|
||||||
|
public AjaxResult insert(@RequestBody WxCpUser wxCpUuser) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
WxCpUserService userService = WxCpConfiguration.getCpService(999999).getUserService();
|
||||||
|
userService.create(wxCpUuser);
|
||||||
|
return AjaxResult.success("新增成员成功");
|
||||||
|
} catch (WxErrorException e) {
|
||||||
|
return AjaxResult.error("新增成员出错,错误码【"+ e.getError().getErrorCode()+"】,原因:"+ ErrorCodeText.errorMsg(e.getError().getErrorCode()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Log(title = "全量新增成员", businessType = BusinessType.INSERT)
|
||||||
|
@PostMapping("/insertList")
|
||||||
|
public AjaxResult insertList(@RequestBody List<WxCpUser> wxCpUsers) {
|
||||||
|
this.logger.info("全量新增成员");
|
||||||
|
int i=0;
|
||||||
|
try {
|
||||||
|
WxCpUserService userService = WxCpConfiguration.getCpService(999999).getUserService();
|
||||||
|
for (WxCpUser wxCpUser : wxCpUsers) {
|
||||||
|
userService.create(wxCpUser);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return AjaxResult.success(i,"全量新增成员成功");
|
||||||
|
} catch (WxErrorException e) {
|
||||||
|
return AjaxResult.error("全量新增成员成功【"+i+"】条,其余失败,错误码【"+ e.getError().getErrorCode()+"】,原因:"+ ErrorCodeText.errorMsg(e.getError().getErrorCode()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Log(title = "获取成员", businessType = BusinessType.UPDATE)
|
||||||
|
@PostMapping("/update")
|
||||||
|
public AjaxResult update(@RequestBody WxCpUser wxCpUser) {
|
||||||
|
try {
|
||||||
|
WxCpUserService userService = WxCpConfiguration.getCpService(999999).getUserService();
|
||||||
|
userService.update(wxCpUser);
|
||||||
|
return AjaxResult.success("更新成员成功");
|
||||||
|
} catch (WxErrorException e) {
|
||||||
|
return AjaxResult.error("更新成员失败,错误码【"+ e.getError().getErrorCode()+"】,原因:"+ ErrorCodeText.errorMsg(e.getError().getErrorCode()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Log(title = "删除成员", businessType = BusinessType.DELETE)
|
||||||
|
@GetMapping("/delete")
|
||||||
|
public AjaxResult delete(@RequestBody String[] ids) {
|
||||||
|
try {
|
||||||
|
WxCpUserService userService = WxCpConfiguration.getCpService(999999).getUserService();
|
||||||
|
userService.delete(ids);
|
||||||
|
return AjaxResult.success("删除成员成功");
|
||||||
|
} catch (WxErrorException e) {
|
||||||
|
return AjaxResult.error("删除成员出错,错误码【"+ e.getError().getErrorCode()+"】,原因:"+ ErrorCodeText.errorMsg(e.getError().getErrorCode()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue