| | |
| | | import cn.iocoder.yudao.module.wxcp.controller.admin.member.vo.WxCpMemberRespVO; |
| | | import jakarta.annotation.Resource; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import me.chanjar.weixin.common.error.WxErrorException; |
| | | import me.chanjar.weixin.cp.api.WxCpService; |
| | | import me.chanjar.weixin.cp.bean.WxCpDepart; |
| | | import me.chanjar.weixin.cp.bean.WxCpUser; |
| | |
| | | users = wxCpService.getUserService().listSimpleByDepartment(deptId, child, null); |
| | | } catch (Exception e) { |
| | | log.error("[getMemberList][获取企业微信成员失败 deptId={} fetchChild={}]", deptId, child, e); |
| | | throw exception(WXCP_API_ERROR); |
| | | throwWxCpApiError(e); |
| | | return List.of(); |
| | | } |
| | | |
| | | // 部门名映射,用于把成员的部门ID翻译成可读名称 |
| | |
| | | return departs != null ? departs : List.of(); |
| | | } catch (Exception e) { |
| | | log.error("[listDeparts][获取企业微信部门失败]", e); |
| | | throw exception(WXCP_API_ERROR); |
| | | throwWxCpApiError(e); |
| | | return List.of(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 把企业微信接口异常转成带 errcode/errmsg 的可读提示,便于定位 IP 白名单、Secret 等问题 |
| | | */ |
| | | private void throwWxCpApiError(Exception e) { |
| | | if (e instanceof WxErrorException wxError && wxError.getError() != null) { |
| | | throw exception(WXCP_API_ERROR, |
| | | wxError.getError().getErrorCode(), wxError.getError().getErrorMsg()); |
| | | } |
| | | throw exception(WXCP_API_ERROR, "unknown", e.getMessage()); |
| | | } |
| | | |
| | | private WxCpDepartmentRespVO toDeptVO(WxCpDepart depart) { |
| | | WxCpDepartmentRespVO vo = new WxCpDepartmentRespVO(); |
| | | vo.setId(depart.getId()); |