Skip to content

Commit a19aa03

Browse files
Copilotbinarywang
andcommitted
实现企业微信人事助手相关API
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
1 parent 42a2dd4 commit a19aa03

File tree

11 files changed

+582
-0
lines changed

11 files changed

+582
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package me.chanjar.weixin.cp.api;
2+
3+
import me.chanjar.weixin.common.error.WxErrorException;
4+
import me.chanjar.weixin.cp.bean.hr.WxCpHrEmployeeFieldData;
5+
import me.chanjar.weixin.cp.bean.hr.WxCpHrEmployeeFieldDataResp;
6+
import me.chanjar.weixin.cp.bean.hr.WxCpHrEmployeeFieldInfoResp;
7+
8+
import java.util.List;
9+
10+
/**
11+
* 人事助手相关接口.
12+
* 官方文档:https://developer.work.weixin.qq.com/document/path/99132
13+
*
14+
* @author <a href="https://github.com/leejoker">leejoker</a> created on 2024-01-01
15+
*/
16+
public interface WxCpHrService {
17+
18+
/**
19+
* 获取员工档案字段信息.
20+
* <p>
21+
* 请求方式:POST(HTTPS)
22+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/hr/employee/get_field_info?access_token=ACCESS_TOKEN
23+
* 权限说明:
24+
* 需要配置人事助手的secret,调用接口前需给对应成员赋予人事小助手应用的权限。
25+
*
26+
* @param fields 指定字段key列表,不填则返回全部字段
27+
* @return 字段信息响应 wx cp hr employee field info resp
28+
* @throws WxErrorException the wx error exception
29+
*/
30+
WxCpHrEmployeeFieldInfoResp getFieldInfo(List<String> fields) throws WxErrorException;
31+
32+
/**
33+
* 获取员工档案数据.
34+
* <p>
35+
* 请求方式:POST(HTTPS)
36+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/hr/employee/get_employee_field_info?access_token=ACCESS_TOKEN
37+
* 权限说明:
38+
* 需要配置人事助手的secret,调用接口前需给对应成员赋予人事小助手应用的权限。
39+
*
40+
* @param userids 员工userid列表,不超过20个
41+
* @param fields 指定字段key列表,不填则返回全部字段
42+
* @return 员工档案数据响应 wx cp hr employee field data resp
43+
* @throws WxErrorException the wx error exception
44+
*/
45+
WxCpHrEmployeeFieldDataResp getEmployeeFieldInfo(List<String> userids, List<String> fields) throws WxErrorException;
46+
47+
/**
48+
* 更新员工档案数据.
49+
* <p>
50+
* 请求方式:POST(HTTPS)
51+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/hr/employee/update_employee_field_info?access_token=ACCESS_TOKEN
52+
* 权限说明:
53+
* 需要配置人事助手的secret,调用接口前需给对应成员赋予人事小助手应用的权限。
54+
*
55+
* @param userid 员工userid
56+
* @param fieldList 字段数据列表
57+
* @throws WxErrorException the wx error exception
58+
*/
59+
void updateEmployeeFieldInfo(String userid, List<WxCpHrEmployeeFieldData.FieldItem> fieldList) throws WxErrorException;
60+
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,4 +594,11 @@ public interface WxCpService extends WxService {
594594
* @return 智能机器人服务 intelligent robot service
595595
*/
596596
WxCpIntelligentRobotService getIntelligentRobotService();
597+
598+
/**
599+
* 获取人事助手服务
600+
*
601+
* @return 人事助手服务 hr service
602+
*/
603+
WxCpHrService getHrService();
597604
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpServiceImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestH
7575
private final WxCpMeetingService meetingService = new WxCpMeetingServiceImpl(this);
7676
private final WxCpCorpGroupService corpGroupService = new WxCpCorpGroupServiceImpl(this);
7777
private final WxCpIntelligentRobotService intelligentRobotService = new WxCpIntelligentRobotServiceImpl(this);
78+
private final WxCpHrService hrService = new WxCpHrServiceImpl(this);
7879

7980
/**
8081
* 全局的是否正在刷新access token的锁.
@@ -708,4 +709,9 @@ public WxCpCorpGroupService getCorpGroupService() {
708709
public WxCpIntelligentRobotService getIntelligentRobotService() {
709710
return this.intelligentRobotService;
710711
}
712+
713+
@Override
714+
public WxCpHrService getHrService() {
715+
return this.hrService;
716+
}
711717
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package me.chanjar.weixin.cp.api.impl;
2+
3+
import com.google.gson.JsonObject;
4+
import lombok.RequiredArgsConstructor;
5+
import me.chanjar.weixin.common.error.WxErrorException;
6+
import me.chanjar.weixin.cp.api.WxCpHrService;
7+
import me.chanjar.weixin.cp.api.WxCpService;
8+
import me.chanjar.weixin.cp.bean.hr.WxCpHrEmployeeFieldData;
9+
import me.chanjar.weixin.cp.bean.hr.WxCpHrEmployeeFieldDataResp;
10+
import me.chanjar.weixin.cp.bean.hr.WxCpHrEmployeeFieldInfoResp;
11+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
12+
13+
import java.util.List;
14+
15+
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Hr.*;
16+
17+
/**
18+
* 人事助手相关接口实现类.
19+
* 官方文档:https://developer.work.weixin.qq.com/document/path/99132
20+
*
21+
* @author <a href="https://github.com/leejoker">leejoker</a> created on 2024-01-01
22+
*/
23+
@RequiredArgsConstructor
24+
public class WxCpHrServiceImpl implements WxCpHrService {
25+
26+
private final WxCpService cpService;
27+
28+
@Override
29+
public WxCpHrEmployeeFieldInfoResp getFieldInfo(List<String> fields) throws WxErrorException {
30+
JsonObject jsonObject = new JsonObject();
31+
if (fields != null && !fields.isEmpty()) {
32+
jsonObject.add("fields", WxCpGsonBuilder.create().toJsonTree(fields));
33+
}
34+
String response = this.cpService.post(
35+
this.cpService.getWxCpConfigStorage().getApiUrl(GET_FIELD_INFO),
36+
jsonObject.toString()
37+
);
38+
return WxCpHrEmployeeFieldInfoResp.fromJson(response);
39+
}
40+
41+
@Override
42+
public WxCpHrEmployeeFieldDataResp getEmployeeFieldInfo(List<String> userids, List<String> fields) throws WxErrorException {
43+
JsonObject jsonObject = new JsonObject();
44+
jsonObject.add("userids", WxCpGsonBuilder.create().toJsonTree(userids));
45+
if (fields != null && !fields.isEmpty()) {
46+
jsonObject.add("fields", WxCpGsonBuilder.create().toJsonTree(fields));
47+
}
48+
String response = this.cpService.post(
49+
this.cpService.getWxCpConfigStorage().getApiUrl(GET_EMPLOYEE_FIELD_INFO),
50+
jsonObject.toString()
51+
);
52+
return WxCpHrEmployeeFieldDataResp.fromJson(response);
53+
}
54+
55+
@Override
56+
public void updateEmployeeFieldInfo(String userid, List<WxCpHrEmployeeFieldData.FieldItem> fieldList) throws WxErrorException {
57+
JsonObject jsonObject = new JsonObject();
58+
jsonObject.addProperty("userid", userid);
59+
jsonObject.add("field_list", WxCpGsonBuilder.create().toJsonTree(fieldList));
60+
this.cpService.post(
61+
this.cpService.getWxCpConfigStorage().getApiUrl(UPDATE_EMPLOYEE_FIELD_INFO),
62+
jsonObject.toString()
63+
);
64+
}
65+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package me.chanjar.weixin.cp.bean.hr;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
import lombok.NoArgsConstructor;
6+
7+
import java.io.Serializable;
8+
import java.util.List;
9+
10+
/**
11+
* 人事助手-员工档案数据(单个员工).
12+
*
13+
* @author <a href="https://github.com/leejoker">leejoker</a> created on 2024-01-01
14+
*/
15+
@Data
16+
@NoArgsConstructor
17+
public class WxCpHrEmployeeFieldData implements Serializable {
18+
private static final long serialVersionUID = 4593693598671765396L;
19+
20+
/**
21+
* 员工userid.
22+
*/
23+
@SerializedName("userid")
24+
private String userid;
25+
26+
/**
27+
* 字段数据列表.
28+
*/
29+
@SerializedName("field_list")
30+
private List<FieldItem> fieldList;
31+
32+
/**
33+
* 字段数据项.
34+
*/
35+
@Data
36+
@NoArgsConstructor
37+
public static class FieldItem implements Serializable {
38+
private static final long serialVersionUID = 1L;
39+
40+
/**
41+
* 字段key.
42+
*/
43+
@SerializedName("field_key")
44+
private String fieldKey;
45+
46+
/**
47+
* 字段值.
48+
*/
49+
@SerializedName("field_value")
50+
private WxCpHrEmployeeFieldValue fieldValue;
51+
}
52+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package me.chanjar.weixin.cp.bean.hr;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
import lombok.EqualsAndHashCode;
6+
import lombok.NoArgsConstructor;
7+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
8+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
9+
10+
import java.util.List;
11+
12+
/**
13+
* 人事助手-获取员工档案数据响应.
14+
*
15+
* @author <a href="https://github.com/leejoker">leejoker</a> created on 2024-01-01
16+
*/
17+
@Data
18+
@NoArgsConstructor
19+
@EqualsAndHashCode(callSuper = true)
20+
public class WxCpHrEmployeeFieldDataResp extends WxCpBaseResp {
21+
private static final long serialVersionUID = 6593693598671765396L;
22+
23+
/**
24+
* 员工档案数据列表.
25+
*/
26+
@SerializedName("employee_field_list")
27+
private List<WxCpHrEmployeeFieldData> employeeFieldList;
28+
29+
/**
30+
* From json wx cp hr employee field data resp.
31+
*
32+
* @param json the json
33+
* @return the wx cp hr employee field data resp
34+
*/
35+
public static WxCpHrEmployeeFieldDataResp fromJson(String json) {
36+
return WxCpGsonBuilder.create().fromJson(json, WxCpHrEmployeeFieldDataResp.class);
37+
}
38+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package me.chanjar.weixin.cp.bean.hr;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
import lombok.NoArgsConstructor;
6+
7+
import java.io.Serializable;
8+
import java.util.List;
9+
10+
/**
11+
* 人事助手-员工档案字段信息.
12+
*
13+
* @author <a href="https://github.com/leejoker">leejoker</a> created on 2024-01-01
14+
*/
15+
@Data
16+
@NoArgsConstructor
17+
public class WxCpHrEmployeeFieldInfo implements Serializable {
18+
private static final long serialVersionUID = 2593693598671765396L;
19+
20+
/**
21+
* 字段key.
22+
*/
23+
@SerializedName("field_key")
24+
private String fieldKey;
25+
26+
/**
27+
* 字段英文名称.
28+
*/
29+
@SerializedName("field_en_name")
30+
private String fieldEnName;
31+
32+
/**
33+
* 字段中文名称.
34+
*/
35+
@SerializedName("field_zh_name")
36+
private String fieldZhName;
37+
38+
/**
39+
* 字段类型.
40+
* 1: 文本
41+
* 2: 日期
42+
* 3: 数字
43+
* 4: 单选
44+
* 5: 多选
45+
* 6: 附件
46+
* 7: 手机
47+
* 8: 邮箱
48+
*/
49+
@SerializedName("field_type")
50+
private Integer fieldType;
51+
52+
/**
53+
* 是否系统字段.
54+
* 0: 否
55+
* 1: 是
56+
*/
57+
@SerializedName("is_sys")
58+
private Integer isSys;
59+
60+
/**
61+
* 字段详情.
62+
*/
63+
@SerializedName("field_detail")
64+
private FieldDetail fieldDetail;
65+
66+
/**
67+
* 字段详情.
68+
*/
69+
@Data
70+
@NoArgsConstructor
71+
public static class FieldDetail implements Serializable {
72+
private static final long serialVersionUID = 1L;
73+
74+
/**
75+
* 选项列表(单选/多选字段专用).
76+
*/
77+
@SerializedName("option_list")
78+
private List<Option> optionList;
79+
}
80+
81+
/**
82+
* 选项.
83+
*/
84+
@Data
85+
@NoArgsConstructor
86+
public static class Option implements Serializable {
87+
private static final long serialVersionUID = 1L;
88+
89+
/**
90+
* 选项key.
91+
*/
92+
@SerializedName("key")
93+
private String key;
94+
95+
/**
96+
* 选项值.
97+
*/
98+
@SerializedName("value")
99+
private String value;
100+
}
101+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package me.chanjar.weixin.cp.bean.hr;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
import lombok.EqualsAndHashCode;
6+
import lombok.NoArgsConstructor;
7+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
8+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
9+
10+
import java.util.List;
11+
12+
/**
13+
* 人事助手-获取员工档案字段信息响应.
14+
*
15+
* @author <a href="https://github.com/leejoker">leejoker</a> created on 2024-01-01
16+
*/
17+
@Data
18+
@NoArgsConstructor
19+
@EqualsAndHashCode(callSuper = true)
20+
public class WxCpHrEmployeeFieldInfoResp extends WxCpBaseResp {
21+
private static final long serialVersionUID = 5593693598671765396L;
22+
23+
/**
24+
* 字段信息列表.
25+
*/
26+
@SerializedName("field_info_list")
27+
private List<WxCpHrEmployeeFieldInfo> fieldInfoList;
28+
29+
/**
30+
* From json wx cp hr employee field info resp.
31+
*
32+
* @param json the json
33+
* @return the wx cp hr employee field info resp
34+
*/
35+
public static WxCpHrEmployeeFieldInfoResp fromJson(String json) {
36+
return WxCpGsonBuilder.create().fromJson(json, WxCpHrEmployeeFieldInfoResp.class);
37+
}
38+
}

0 commit comments

Comments
 (0)