From a357d733a08d37d05018a2f1c9b90d8381827dcc Mon Sep 17 00:00:00 2001 From: zhujj Date: Wed, 23 Jan 2019 17:26:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=81=E4=B8=9A=E5=BE=AE=E4=BF=A1=E7=BB=84?= =?UTF-8?q?=E7=BB=87=E6=9C=BA=E6=9E=84=E3=80=81=E6=88=90=E5=91=98=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-admin/pom.xml | 2 +- ...oller.java => WxDepartmentController.java} | 23 ++-- .../wx/cp/controller/WxUserController.java | 121 ++++++++++++++++++ 3 files changed, 135 insertions(+), 11 deletions(-) rename ruoyi-weixin/src/main/java/com/ruoyi/wx/cp/controller/{WxUserGroupController.java => WxDepartmentController.java} (91%) create mode 100644 ruoyi-weixin/src/main/java/com/ruoyi/wx/cp/controller/WxUserController.java diff --git a/ruoyi-admin/pom.xml b/ruoyi-admin/pom.xml index bacd01613..d0e703682 100644 --- a/ruoyi-admin/pom.xml +++ b/ruoyi-admin/pom.xml @@ -22,7 +22,7 @@ org.springframework.boot spring-boot-devtools - true + false diff --git a/ruoyi-weixin/src/main/java/com/ruoyi/wx/cp/controller/WxUserGroupController.java b/ruoyi-weixin/src/main/java/com/ruoyi/wx/cp/controller/WxDepartmentController.java similarity index 91% rename from ruoyi-weixin/src/main/java/com/ruoyi/wx/cp/controller/WxUserGroupController.java rename to ruoyi-weixin/src/main/java/com/ruoyi/wx/cp/controller/WxDepartmentController.java index cdbb71cb4..d33510fb0 100644 --- a/ruoyi-weixin/src/main/java/com/ruoyi/wx/cp/controller/WxUserGroupController.java +++ b/ruoyi-weixin/src/main/java/com/ruoyi/wx/cp/controller/WxDepartmentController.java @@ -26,25 +26,29 @@ import java.util.List; import java.util.Map; /** - * @author Binary Wang(https://github.com/binarywang) + * 同步 + * @author zhujj */ @RestController -@RequestMapping("/wx/cp/user/group") -public class WxUserGroupController { +@RequestMapping("/wx/cp/department") +public class WxDepartmentController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @Autowired private WxCpProperties properties; - @Log(title = "获取组织机构列表", businessType = BusinessType.INSERT) + /** + * 获取指定部门及其下的子部门。 如果不填,默认获取全量组织架构 + * @param id + * @return + */ @GetMapping("/departAllList") - public AjaxResult departAllList() { - this.logger.info("\n获取组织机构"); + public AjaxResult departAllList(Long id) { try { final WxCpService wxCpService = WxCpConfiguration.getCpService(999999); WxCpDepartmentService departmentService = wxCpService.getDepartmentService(); - List list = departmentService.list(null); + List list = departmentService.list(id); return AjaxResult.success(list,"获取组织机构成功"); } catch (WxErrorException e) { return AjaxResult.error("获取组织机构出错,错误码【"+ e.getError().getErrorCode()+"】,原因:"+ ErrorCodeText.errorMsg(e.getError().getErrorCode())); @@ -54,7 +58,6 @@ public class WxUserGroupController { @Log(title = "新增组织机构", businessType = BusinessType.INSERT) @PostMapping("/insert") public AjaxResult insert(@RequestBody WxCpDepart wxCpDepart) { - this.logger.info("新增组织机构"); try { WxCpDepartmentService departmentService = WxCpConfiguration.getCpService(999999).getDepartmentService(); Integer id = departmentService.create(wxCpDepart); @@ -77,7 +80,7 @@ public class WxUserGroupController { return AjaxResult.error("全量新增组织机构失败,错误码【"+ e.getError().getErrorCode()+"】,原因:"+ ErrorCodeText.errorMsg(e.getError().getErrorCode())); } } - @Log(title = "获取组织机构", businessType = BusinessType.INSERT) + @Log(title = "获取组织机构", businessType = BusinessType.UPDATE) @PostMapping("/update") public AjaxResult update(@RequestBody WxCpDepart wxCpDepart) { try { @@ -90,7 +93,7 @@ public class WxUserGroupController { } } - @Log(title = "删除组织机构", businessType = BusinessType.INSERT) + @Log(title = "删除组织机构", businessType = BusinessType.DELETE) @GetMapping("/delete/{id}") public AjaxResult delete(@PathVariable("id") Long id) { try { diff --git a/ruoyi-weixin/src/main/java/com/ruoyi/wx/cp/controller/WxUserController.java b/ruoyi-weixin/src/main/java/com/ruoyi/wx/cp/controller/WxUserController.java new file mode 100644 index 000000000..699ce914f --- /dev/null +++ b/ruoyi-weixin/src/main/java/com/ruoyi/wx/cp/controller/WxUserController.java @@ -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 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 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 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())); + } + } + +}