Skip to content

Commit a807063

Browse files
authored
🆕 #2708【企业微信】增加家校沟通-部门管理接口支持
1 parent 1fbd22e commit a807063

File tree

11 files changed

+509
-6
lines changed

11 files changed

+509
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@
182182
1. [007gzs](https://github.com/007gzs)
183183
1. [Silloy](https://github.com/silloy)
184184
1. [mgcnrx11](https://github.com/mgcnrx11)
185+
1. [0katekate0 (Wang_Wong)](https://github.com/0katekate0)
185186
1. [yuanqixun](https://github.com/yuanqixun)
186187
1. [kakotor](https://github.com/kakotor)
187188
1. [aimilin6688 (Jonk)](https://github.com/aimilin6688)

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@
9797
<email>xiaohe@53jy.net</email>
9898
<url>https://github.com/xiaohe-53</url>
9999
</developer>
100+
<developer>
101+
<name>Wang_Wong</name>
102+
<email>wangkaikate@163.com</email>
103+
<url>https://github.com/0katekate0</url>
104+
</developer>
100105
</developers>
101106

102107
<scm>

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

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
import lombok.NonNull;
44
import me.chanjar.weixin.common.error.WxErrorException;
55
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
6-
import me.chanjar.weixin.cp.bean.school.user.WxCpCreateParentRequest;
7-
import me.chanjar.weixin.cp.bean.school.user.WxCpUpdateParentRequest;
6+
import me.chanjar.weixin.cp.bean.school.user.*;
87

98
import java.util.List;
109

@@ -101,4 +100,62 @@ public interface WxCpSchoolUserService {
101100
*/
102101
WxCpBaseResp setArchSyncMode(@NonNull Integer archSyncMode) throws WxErrorException;
103102

103+
/**
104+
* 创建部门
105+
* <p>
106+
* 请求方式:POST(HTTPS)
107+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/department/create?access_token=ACCESS_TOKEN
108+
*
109+
* @param request 请求参数对象
110+
* @return
111+
* @throws WxErrorException
112+
*/
113+
WxCpCreateDepartment createDepartment(@NonNull WxCpCreateDepartmentRequest request) throws WxErrorException;
114+
115+
/**
116+
* 更新部门
117+
* <p>
118+
* 请求方式:POST(HTTPS)
119+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/department/update?access_token=ACCESS_TOKEN
120+
*
121+
* @param request
122+
* @return
123+
* @throws WxErrorException
124+
*/
125+
WxCpBaseResp updateDepartment(@NonNull WxCpUpdateDepartmentRequest request) throws WxErrorException;
126+
127+
/**
128+
* 删除部门
129+
* 请求方式:GET(HTTPS)
130+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/department/delete?access_token=ACCESS_TOKEN&id=ID
131+
*
132+
* @param id
133+
* @return
134+
* @throws WxErrorException
135+
*/
136+
WxCpBaseResp deleteDepartment(Integer id) throws WxErrorException;
137+
138+
/**
139+
* 获取部门列表
140+
* 请求方式:GET(HTTPS)
141+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/department/list?access_token=ACCESS_TOKEN&id=ID
142+
*
143+
* @param id
144+
* @return
145+
* @throws WxErrorException
146+
*/
147+
WxCpDepartmentList listDepartment(Integer id) throws WxErrorException;
148+
149+
/**
150+
* 修改自动升年级的配置
151+
* 请求方式: POST(HTTPS)
152+
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/school/set_upgrade_info?access_token=ACCESS_TOKEN
153+
*
154+
* @param upgradeTime
155+
* @param upgradeSwitch
156+
* @return
157+
* @throws WxErrorException
158+
*/
159+
WxCpSetUpgradeInfo setUpgradeInfo(Long upgradeTime, Integer upgradeSwitch) throws WxErrorException;
160+
104161
}

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

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
import me.chanjar.weixin.cp.api.WxCpSchoolUserService;
1111
import me.chanjar.weixin.cp.api.WxCpService;
1212
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
13-
import me.chanjar.weixin.cp.bean.school.user.WxCpCreateParentRequest;
14-
import me.chanjar.weixin.cp.bean.school.user.WxCpUpdateParentRequest;
13+
import me.chanjar.weixin.cp.bean.school.user.*;
1514
import org.apache.commons.lang3.StringUtils;
1615

1716
import java.util.List;
@@ -105,4 +104,46 @@ public WxCpBaseResp setArchSyncMode(@NonNull Integer archSyncMode) throws WxErro
105104
return WxCpBaseResp.fromJson(responseContent);
106105
}
107106

107+
@Override
108+
public WxCpCreateDepartment createDepartment(@NonNull WxCpCreateDepartmentRequest request) throws WxErrorException {
109+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(DEPARTMENT_CREATE);
110+
String responseContent = this.cpService.post(apiUrl, request.toJson());
111+
return WxCpCreateDepartment.fromJson(responseContent);
112+
}
113+
114+
@Override
115+
public WxCpBaseResp updateDepartment(@NonNull WxCpUpdateDepartmentRequest request) throws WxErrorException {
116+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(DEPARTMENT_UPDATE);
117+
String responseContent = this.cpService.post(apiUrl, request.toJson());
118+
return WxCpBaseResp.fromJson(responseContent);
119+
}
120+
121+
@Override
122+
public WxCpBaseResp deleteDepartment(Integer id) throws WxErrorException {
123+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(DEPARTMENT_DELETE) + id;
124+
String responseContent = this.cpService.get(apiUrl, null);
125+
return WxCpBaseResp.fromJson(responseContent);
126+
}
127+
128+
@Override
129+
public WxCpDepartmentList listDepartment(Integer id) throws WxErrorException {
130+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(DEPARTMENT_LIST) + id;
131+
String responseContent = this.cpService.get(apiUrl, null);
132+
return WxCpDepartmentList.fromJson(responseContent);
133+
}
134+
135+
@Override
136+
public WxCpSetUpgradeInfo setUpgradeInfo(Long upgradeTime, Integer upgradeSwitch) throws WxErrorException {
137+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(SET_UPGRADE_INFO);
138+
JsonObject jsonObject = new JsonObject();
139+
if (upgradeTime != null) {
140+
jsonObject.addProperty("upgrade_time", upgradeTime);
141+
}
142+
if (upgradeSwitch != null) {
143+
jsonObject.addProperty("upgrade_switch", upgradeSwitch);
144+
}
145+
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
146+
return WxCpSetUpgradeInfo.fromJson(responseContent);
147+
}
148+
108149
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package me.chanjar.weixin.cp.bean.school.user;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
6+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
7+
8+
import java.io.Serializable;
9+
10+
/**
11+
* 创建部门返回结果.
12+
*
13+
* @author Wang_Wong
14+
*/
15+
@Data
16+
public class WxCpCreateDepartment extends WxCpBaseResp implements Serializable {
17+
private static final long serialVersionUID = -5028321625140879571L;
18+
19+
@SerializedName("id")
20+
private Integer id;
21+
22+
public static WxCpCreateDepartment fromJson(String json) {
23+
return WxCpGsonBuilder.create().fromJson(json, WxCpCreateDepartment.class);
24+
}
25+
26+
public String toJson() {
27+
return WxCpGsonBuilder.create().toJson(this);
28+
}
29+
30+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package me.chanjar.weixin.cp.bean.school.user;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.*;
5+
import lombok.experimental.Accessors;
6+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
7+
8+
import java.io.Serializable;
9+
import java.util.List;
10+
11+
/**
12+
* 创建部门请求.
13+
*
14+
* @author Wang_Wong
15+
* @date 2022-06-22
16+
*/
17+
@Data
18+
@Builder
19+
@NoArgsConstructor
20+
@AllArgsConstructor
21+
@Accessors(chain = true)
22+
public class WxCpCreateDepartmentRequest implements Serializable {
23+
private static final long serialVersionUID = -4960239394895754138L;
24+
25+
@SerializedName("parentid")
26+
private Integer parentId;
27+
28+
@SerializedName("name")
29+
private String name;
30+
31+
@SerializedName("id")
32+
private Integer id;
33+
34+
@SerializedName("type")
35+
private Integer type;
36+
37+
@SerializedName("register_year")
38+
private Integer registerYear;
39+
40+
@SerializedName("standard_grade")
41+
private Integer standardGrade;
42+
43+
@SerializedName("order")
44+
private Integer order;
45+
46+
@SerializedName("department_admins")
47+
private List<DepartmentAdmin> departmentAdmins;
48+
49+
@Setter
50+
@Getter
51+
public static class DepartmentAdmin implements Serializable {
52+
53+
@SerializedName("userid")
54+
private String userId;
55+
56+
@SerializedName("type")
57+
private Integer type;
58+
59+
@SerializedName("subject")
60+
private String subject;
61+
62+
public static DepartmentAdmin fromJson(String json) {
63+
return WxCpGsonBuilder.create().fromJson(json, DepartmentAdmin.class);
64+
}
65+
66+
public String toJson() {
67+
return WxCpGsonBuilder.create().toJson(this);
68+
}
69+
70+
}
71+
72+
public static WxCpCreateDepartmentRequest fromJson(String json) {
73+
return WxCpGsonBuilder.create().fromJson(json, WxCpCreateDepartmentRequest.class);
74+
}
75+
76+
public String toJson() {
77+
return WxCpGsonBuilder.create().toJson(this);
78+
}
79+
80+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package me.chanjar.weixin.cp.bean.school.user;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
import lombok.Getter;
6+
import lombok.Setter;
7+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
8+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
9+
10+
import java.io.Serializable;
11+
import java.util.List;
12+
13+
/**
14+
* 获取部门列表返回结果.
15+
*
16+
* @author Wang_Wong
17+
*/
18+
@Data
19+
public class WxCpDepartmentList extends WxCpBaseResp implements Serializable {
20+
private static final long serialVersionUID = -5028321625140879571L;
21+
22+
@SerializedName("departments")
23+
private List<Department> departments;
24+
25+
@Setter
26+
@Getter
27+
public static class Department implements Serializable{
28+
@SerializedName("parentid")
29+
private Integer parentId;
30+
31+
@SerializedName("name")
32+
private String name;
33+
34+
@SerializedName("id")
35+
private Integer id;
36+
37+
@SerializedName("type")
38+
private Integer type;
39+
40+
@SerializedName("register_year")
41+
private Integer registerYear;
42+
43+
@SerializedName("standard_grade")
44+
private Integer standardGrade;
45+
46+
@SerializedName("order")
47+
private Integer order;
48+
49+
@SerializedName("is_graduated")
50+
private Integer isGraduated;
51+
52+
@SerializedName("open_group_chat")
53+
private Integer openGroupChat;
54+
55+
@SerializedName("group_chat_id")
56+
private String groupChatId;
57+
58+
@SerializedName("department_admins")
59+
private List<DepartmentAdmin> departmentAdmins;
60+
61+
public static Department fromJson(String json) {
62+
return WxCpGsonBuilder.create().fromJson(json, Department.class);
63+
}
64+
65+
public String toJson() {
66+
return WxCpGsonBuilder.create().toJson(this);
67+
}
68+
69+
}
70+
71+
@Setter
72+
@Getter
73+
public static class DepartmentAdmin implements Serializable {
74+
75+
@SerializedName("userid")
76+
private String userId;
77+
78+
@SerializedName("type")
79+
private Integer type;
80+
81+
@SerializedName("subject")
82+
private String subject;
83+
84+
public static DepartmentAdmin fromJson(String json) {
85+
return WxCpGsonBuilder.create().fromJson(json, DepartmentAdmin.class);
86+
}
87+
88+
public String toJson() {
89+
return WxCpGsonBuilder.create().toJson(this);
90+
}
91+
92+
}
93+
94+
public static WxCpDepartmentList fromJson(String json) {
95+
return WxCpGsonBuilder.create().fromJson(json, WxCpDepartmentList.class);
96+
}
97+
98+
public String toJson() {
99+
return WxCpGsonBuilder.create().toJson(this);
100+
}
101+
102+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package me.chanjar.weixin.cp.bean.school.user;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
6+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
7+
8+
import java.io.Serializable;
9+
10+
/**
11+
* 修改自动升年级的配置 返回结果.
12+
*
13+
* @author Wang_Wong
14+
*/
15+
@Data
16+
public class WxCpSetUpgradeInfo extends WxCpBaseResp implements Serializable {
17+
private static final long serialVersionUID = -5028321625140879571L;
18+
19+
@SerializedName("next_upgrade_time")
20+
private Long nextUpgradeTime;
21+
22+
public static WxCpSetUpgradeInfo fromJson(String json) {
23+
return WxCpGsonBuilder.create().fromJson(json, WxCpSetUpgradeInfo.class);
24+
}
25+
26+
public String toJson() {
27+
return WxCpGsonBuilder.create().toJson(this);
28+
}
29+
30+
}

0 commit comments

Comments
 (0)