-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
实现企业微信人事助手 API (HR Assistant) #3892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpHrService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| package me.chanjar.weixin.cp.api; | ||
|
|
||
| import me.chanjar.weixin.common.error.WxErrorException; | ||
| import me.chanjar.weixin.cp.bean.hr.WxCpHrEmployeeFieldData; | ||
| import me.chanjar.weixin.cp.bean.hr.WxCpHrEmployeeFieldDataResp; | ||
| import me.chanjar.weixin.cp.bean.hr.WxCpHrEmployeeFieldInfoResp; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * 人事助手相关接口. | ||
| * 官方文档:https://developer.work.weixin.qq.com/document/path/99132 | ||
| * | ||
| * @author <a href="https://github.com/leejoker">leejoker</a> created on 2024-01-01 | ||
| */ | ||
| public interface WxCpHrService { | ||
|
|
||
| /** | ||
| * 获取员工档案字段信息. | ||
| * <p> | ||
| * 请求方式:POST(HTTPS) | ||
| * 请求地址:https://qyapi.weixin.qq.com/cgi-bin/hr/employee/get_field_info?access_token=ACCESS_TOKEN | ||
| * 权限说明: | ||
| * 需要配置人事助手的secret,调用接口前需给对应成员赋予人事小助手应用的权限。 | ||
| * | ||
| * @param fields 指定字段key列表,不填则返回全部字段 | ||
| * @return 字段信息响应 wx cp hr employee field info resp | ||
| * @throws WxErrorException the wx error exception | ||
| */ | ||
| WxCpHrEmployeeFieldInfoResp getFieldInfo(List<String> fields) throws WxErrorException; | ||
|
|
||
| /** | ||
| * 获取员工档案数据. | ||
| * <p> | ||
| * 请求方式:POST(HTTPS) | ||
| * 请求地址:https://qyapi.weixin.qq.com/cgi-bin/hr/employee/get_employee_field_info?access_token=ACCESS_TOKEN | ||
| * 权限说明: | ||
| * 需要配置人事助手的secret,调用接口前需给对应成员赋予人事小助手应用的权限。 | ||
| * | ||
| * @param userids 员工userid列表,不超过20个 | ||
| * @param fields 指定字段key列表,不填则返回全部字段 | ||
| * @return 员工档案数据响应 wx cp hr employee field data resp | ||
| * @throws WxErrorException the wx error exception | ||
| */ | ||
| WxCpHrEmployeeFieldDataResp getEmployeeFieldInfo(List<String> userids, List<String> fields) throws WxErrorException; | ||
|
|
||
| /** | ||
| * 更新员工档案数据. | ||
| * <p> | ||
| * 请求方式:POST(HTTPS) | ||
| * 请求地址:https://qyapi.weixin.qq.com/cgi-bin/hr/employee/update_employee_field_info?access_token=ACCESS_TOKEN | ||
| * 权限说明: | ||
| * 需要配置人事助手的secret,调用接口前需给对应成员赋予人事小助手应用的权限。 | ||
| * | ||
| * @param userid 员工userid | ||
| * @param fieldList 字段数据列表 | ||
| * @throws WxErrorException the wx error exception | ||
| */ | ||
| void updateEmployeeFieldInfo(String userid, List<WxCpHrEmployeeFieldData.FieldItem> fieldList) throws WxErrorException; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpHrServiceImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| package me.chanjar.weixin.cp.api.impl; | ||
|
|
||
| import com.google.gson.JsonObject; | ||
| import lombok.RequiredArgsConstructor; | ||
| import me.chanjar.weixin.common.error.WxErrorException; | ||
| import me.chanjar.weixin.cp.api.WxCpHrService; | ||
| import me.chanjar.weixin.cp.api.WxCpService; | ||
| import me.chanjar.weixin.cp.bean.hr.WxCpHrEmployeeFieldData; | ||
| import me.chanjar.weixin.cp.bean.hr.WxCpHrEmployeeFieldDataResp; | ||
| import me.chanjar.weixin.cp.bean.hr.WxCpHrEmployeeFieldInfoResp; | ||
| import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Hr.*; | ||
|
|
||
| /** | ||
| * 人事助手相关接口实现类. | ||
| * 官方文档:https://developer.work.weixin.qq.com/document/path/99132 | ||
| * | ||
| * @author <a href="https://github.com/leejoker">leejoker</a> created on 2024-01-01 | ||
| */ | ||
| @RequiredArgsConstructor | ||
| public class WxCpHrServiceImpl implements WxCpHrService { | ||
|
|
||
| private final WxCpService cpService; | ||
|
|
||
| @Override | ||
| public WxCpHrEmployeeFieldInfoResp getFieldInfo(List<String> fields) throws WxErrorException { | ||
| JsonObject jsonObject = new JsonObject(); | ||
| if (fields != null && !fields.isEmpty()) { | ||
| jsonObject.add("fields", WxCpGsonBuilder.create().toJsonTree(fields)); | ||
| } | ||
| String response = this.cpService.post( | ||
| this.cpService.getWxCpConfigStorage().getApiUrl(GET_FIELD_INFO), | ||
| jsonObject.toString() | ||
| ); | ||
| return WxCpHrEmployeeFieldInfoResp.fromJson(response); | ||
| } | ||
|
|
||
| @Override | ||
| public WxCpHrEmployeeFieldDataResp getEmployeeFieldInfo(List<String> userids, List<String> fields) throws WxErrorException { | ||
| if (userids == null || userids.isEmpty()) { | ||
| throw new IllegalArgumentException("userids 不能为空"); | ||
| } | ||
| if (userids.size() > 20) { | ||
| throw new IllegalArgumentException("userids 每次最多传入20个"); | ||
| } | ||
| JsonObject jsonObject = new JsonObject(); | ||
| jsonObject.add("userids", WxCpGsonBuilder.create().toJsonTree(userids)); | ||
| if (fields != null && !fields.isEmpty()) { | ||
| jsonObject.add("fields", WxCpGsonBuilder.create().toJsonTree(fields)); | ||
| } | ||
| String response = this.cpService.post( | ||
| this.cpService.getWxCpConfigStorage().getApiUrl(GET_EMPLOYEE_FIELD_INFO), | ||
| jsonObject.toString() | ||
| ); | ||
| return WxCpHrEmployeeFieldDataResp.fromJson(response); | ||
| } | ||
|
|
||
| @Override | ||
| public void updateEmployeeFieldInfo(String userid, List<WxCpHrEmployeeFieldData.FieldItem> fieldList) throws WxErrorException { | ||
| if (userid == null || userid.trim().isEmpty()) { | ||
| throw new IllegalArgumentException("userid 不能为空"); | ||
| } | ||
| if (fieldList == null || fieldList.isEmpty()) { | ||
| throw new IllegalArgumentException("fieldList 不能为空"); | ||
| } | ||
| JsonObject jsonObject = new JsonObject(); | ||
| jsonObject.addProperty("userid", userid); | ||
| jsonObject.add("field_list", WxCpGsonBuilder.create().toJsonTree(fieldList)); | ||
| this.cpService.post( | ||
| this.cpService.getWxCpConfigStorage().getApiUrl(UPDATE_EMPLOYEE_FIELD_INFO), | ||
| jsonObject.toString() | ||
| ); | ||
binarywang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
52 changes: 52 additions & 0 deletions
52
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/hr/WxCpHrEmployeeFieldData.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package me.chanjar.weixin.cp.bean.hr; | ||
|
|
||
| import com.google.gson.annotations.SerializedName; | ||
| import lombok.Data; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| import java.io.Serializable; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * 人事助手-员工档案数据(单个员工). | ||
| * | ||
| * @author <a href="https://github.com/leejoker">leejoker</a> created on 2024-01-01 | ||
| */ | ||
| @Data | ||
| @NoArgsConstructor | ||
| public class WxCpHrEmployeeFieldData implements Serializable { | ||
| private static final long serialVersionUID = 4593693598671765396L; | ||
|
|
||
| /** | ||
| * 员工userid. | ||
| */ | ||
| @SerializedName("userid") | ||
| private String userid; | ||
|
|
||
| /** | ||
| * 字段数据列表. | ||
| */ | ||
| @SerializedName("field_list") | ||
| private List<FieldItem> fieldList; | ||
|
|
||
| /** | ||
| * 字段数据项. | ||
| */ | ||
| @Data | ||
| @NoArgsConstructor | ||
| public static class FieldItem implements Serializable { | ||
| private static final long serialVersionUID = 1L; | ||
|
|
||
| /** | ||
| * 字段key. | ||
| */ | ||
| @SerializedName("field_key") | ||
| private String fieldKey; | ||
|
|
||
| /** | ||
| * 字段值. | ||
| */ | ||
| @SerializedName("field_value") | ||
| private WxCpHrEmployeeFieldValue fieldValue; | ||
| } | ||
| } |
38 changes: 38 additions & 0 deletions
38
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/hr/WxCpHrEmployeeFieldDataResp.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package me.chanjar.weixin.cp.bean.hr; | ||
|
|
||
| import com.google.gson.annotations.SerializedName; | ||
| import lombok.Data; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.NoArgsConstructor; | ||
| import me.chanjar.weixin.cp.bean.WxCpBaseResp; | ||
| import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * 人事助手-获取员工档案数据响应. | ||
| * | ||
| * @author <a href="https://github.com/leejoker">leejoker</a> created on 2024-01-01 | ||
| */ | ||
| @Data | ||
| @NoArgsConstructor | ||
| @EqualsAndHashCode(callSuper = true) | ||
| public class WxCpHrEmployeeFieldDataResp extends WxCpBaseResp { | ||
| private static final long serialVersionUID = 6593693598671765396L; | ||
|
|
||
| /** | ||
| * 员工档案数据列表. | ||
| */ | ||
| @SerializedName("employee_field_list") | ||
| private List<WxCpHrEmployeeFieldData> employeeFieldList; | ||
|
|
||
| /** | ||
| * From json wx cp hr employee field data resp. | ||
| * | ||
| * @param json the json | ||
| * @return the wx cp hr employee field data resp | ||
| */ | ||
| public static WxCpHrEmployeeFieldDataResp fromJson(String json) { | ||
| return WxCpGsonBuilder.create().fromJson(json, WxCpHrEmployeeFieldDataResp.class); | ||
| } | ||
| } |
103 changes: 103 additions & 0 deletions
103
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/hr/WxCpHrEmployeeFieldInfo.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| package me.chanjar.weixin.cp.bean.hr; | ||
|
|
||
| import com.google.gson.annotations.SerializedName; | ||
| import lombok.Data; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| import java.io.Serializable; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * 人事助手-员工档案字段信息. | ||
| * | ||
| * @author <a href="https://github.com/leejoker">leejoker</a> created on 2024-01-01 | ||
| */ | ||
| @Data | ||
| @NoArgsConstructor | ||
| public class WxCpHrEmployeeFieldInfo implements Serializable { | ||
| private static final long serialVersionUID = 2593693598671765396L; | ||
|
|
||
| /** | ||
| * 字段key. | ||
| */ | ||
| @SerializedName("field_key") | ||
| private String fieldKey; | ||
|
|
||
| /** | ||
| * 字段英文名称. | ||
| */ | ||
| @SerializedName("field_en_name") | ||
| private String fieldEnName; | ||
|
|
||
| /** | ||
| * 字段中文名称. | ||
| */ | ||
| @SerializedName("field_zh_name") | ||
| private String fieldZhName; | ||
|
|
||
| /** | ||
| * 字段类型. | ||
| * 具体取值参见 {@link WxCpHrFieldType} | ||
| */ | ||
| @SerializedName("field_type") | ||
| private Integer fieldType; | ||
binarywang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * 获取字段类型枚举. | ||
| * | ||
| * @return 字段类型枚举,未匹配时返回 null | ||
| */ | ||
| public WxCpHrFieldType getFieldTypeEnum() { | ||
| return fieldType == null ? null : WxCpHrFieldType.fromCode(fieldType); | ||
| } | ||
|
|
||
| /** | ||
| * 是否系统字段. | ||
| * 0: 否 | ||
| * 1: 是 | ||
| */ | ||
| @SerializedName("is_sys") | ||
| private Integer isSys; | ||
|
|
||
| /** | ||
| * 字段详情. | ||
| */ | ||
| @SerializedName("field_detail") | ||
| private FieldDetail fieldDetail; | ||
|
|
||
| /** | ||
| * 字段详情. | ||
| */ | ||
| @Data | ||
| @NoArgsConstructor | ||
| public static class FieldDetail implements Serializable { | ||
| private static final long serialVersionUID = 1L; | ||
|
|
||
| /** | ||
| * 选项列表(单选/多选字段专用). | ||
| */ | ||
| @SerializedName("option_list") | ||
| private List<Option> optionList; | ||
| } | ||
|
|
||
| /** | ||
| * 选项. | ||
| */ | ||
| @Data | ||
| @NoArgsConstructor | ||
| public static class Option implements Serializable { | ||
| private static final long serialVersionUID = 1L; | ||
|
|
||
| /** | ||
| * 选项key. | ||
| */ | ||
| @SerializedName("key") | ||
| private String key; | ||
|
|
||
| /** | ||
| * 选项值. | ||
| */ | ||
| @SerializedName("value") | ||
| private String value; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.