Skip to content
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

【企业微信】增加家校沟通-部门管理接口支持 #2708

Merged
merged 1 commit into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@
1. [007gzs](https://github.com/007gzs)
1. [Silloy](https://github.com/silloy)
1. [mgcnrx11](https://github.com/mgcnrx11)
1. [0katekate0 (Wang_Wong)](https://github.com/0katekate0)
1. [yuanqixun](https://github.com/yuanqixun)
1. [kakotor](https://github.com/kakotor)
1. [aimilin6688 (Jonk)](https://github.com/aimilin6688)
Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@
<email>xiaohe@53jy.net</email>
<url>https://github.com/xiaohe-53</url>
</developer>
<developer>
<name>Wang_Wong</name>
<email>wangkaikate@163.com</email>
<url>https://github.com/0katekate0</url>
</developer>
</developers>

<scm>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import lombok.NonNull;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.bean.school.user.WxCpCreateParentRequest;
import me.chanjar.weixin.cp.bean.school.user.WxCpUpdateParentRequest;
import me.chanjar.weixin.cp.bean.school.user.*;

import java.util.List;

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

/**
* 创建部门
* <p>
* 请求方式:POST(HTTPS)
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/department/create?access_token=ACCESS_TOKEN
*
* @param request 请求参数对象
* @return
* @throws WxErrorException
*/
WxCpCreateDepartment createDepartment(@NonNull WxCpCreateDepartmentRequest request) throws WxErrorException;

/**
* 更新部门
* <p>
* 请求方式:POST(HTTPS)
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/department/update?access_token=ACCESS_TOKEN
*
* @param request
* @return
* @throws WxErrorException
*/
WxCpBaseResp updateDepartment(@NonNull WxCpUpdateDepartmentRequest request) throws WxErrorException;

/**
* 删除部门
* 请求方式:GET(HTTPS)
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/department/delete?access_token=ACCESS_TOKEN&id=ID
*
* @param id
* @return
* @throws WxErrorException
*/
WxCpBaseResp deleteDepartment(Integer id) throws WxErrorException;

/**
* 获取部门列表
* 请求方式:GET(HTTPS)
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/department/list?access_token=ACCESS_TOKEN&id=ID
*
* @param id
* @return
* @throws WxErrorException
*/
WxCpDepartmentList listDepartment(Integer id) throws WxErrorException;

/**
* 修改自动升年级的配置
* 请求方式: POST(HTTPS)
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/school/set_upgrade_info?access_token=ACCESS_TOKEN
*
* @param upgradeTime
* @param upgradeSwitch
* @return
* @throws WxErrorException
*/
WxCpSetUpgradeInfo setUpgradeInfo(Long upgradeTime, Integer upgradeSwitch) throws WxErrorException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
import me.chanjar.weixin.cp.api.WxCpSchoolUserService;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.bean.school.user.WxCpCreateParentRequest;
import me.chanjar.weixin.cp.bean.school.user.WxCpUpdateParentRequest;
import me.chanjar.weixin.cp.bean.school.user.*;
import org.apache.commons.lang3.StringUtils;

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

@Override
public WxCpCreateDepartment createDepartment(@NonNull WxCpCreateDepartmentRequest request) throws WxErrorException {
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(DEPARTMENT_CREATE);
String responseContent = this.cpService.post(apiUrl, request.toJson());
return WxCpCreateDepartment.fromJson(responseContent);
}

@Override
public WxCpBaseResp updateDepartment(@NonNull WxCpUpdateDepartmentRequest request) throws WxErrorException {
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(DEPARTMENT_UPDATE);
String responseContent = this.cpService.post(apiUrl, request.toJson());
return WxCpBaseResp.fromJson(responseContent);
}

@Override
public WxCpBaseResp deleteDepartment(Integer id) throws WxErrorException {
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(DEPARTMENT_DELETE) + id;
String responseContent = this.cpService.get(apiUrl, null);
return WxCpBaseResp.fromJson(responseContent);
}

@Override
public WxCpDepartmentList listDepartment(Integer id) throws WxErrorException {
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(DEPARTMENT_LIST) + id;
String responseContent = this.cpService.get(apiUrl, null);
return WxCpDepartmentList.fromJson(responseContent);
}

@Override
public WxCpSetUpgradeInfo setUpgradeInfo(Long upgradeTime, Integer upgradeSwitch) throws WxErrorException {
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(SET_UPGRADE_INFO);
JsonObject jsonObject = new JsonObject();
if (upgradeTime != null) {
jsonObject.addProperty("upgrade_time", upgradeTime);
}
if (upgradeSwitch != null) {
jsonObject.addProperty("upgrade_switch", upgradeSwitch);
}
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
return WxCpSetUpgradeInfo.fromJson(responseContent);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package me.chanjar.weixin.cp.bean.school.user;

import com.google.gson.annotations.SerializedName;
import lombok.Data;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;

import java.io.Serializable;

/**
* 创建部门返回结果.
*
* @author Wang_Wong
*/
@Data
public class WxCpCreateDepartment extends WxCpBaseResp implements Serializable {
private static final long serialVersionUID = -5028321625140879571L;

@SerializedName("id")
private Integer id;

public static WxCpCreateDepartment fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpCreateDepartment.class);
}

public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package me.chanjar.weixin.cp.bean.school.user;

import com.google.gson.annotations.SerializedName;
import lombok.*;
import lombok.experimental.Accessors;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;

import java.io.Serializable;
import java.util.List;

/**
* 创建部门请求.
*
* @author Wang_Wong
* @date 2022-06-22
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class WxCpCreateDepartmentRequest implements Serializable {
private static final long serialVersionUID = -4960239394895754138L;

@SerializedName("parentid")
private Integer parentId;

@SerializedName("name")
private String name;

@SerializedName("id")
private Integer id;

@SerializedName("type")
private Integer type;

@SerializedName("register_year")
private Integer registerYear;

@SerializedName("standard_grade")
private Integer standardGrade;

@SerializedName("order")
private Integer order;

@SerializedName("department_admins")
private List<DepartmentAdmin> departmentAdmins;

@Setter
@Getter
public static class DepartmentAdmin implements Serializable {

@SerializedName("userid")
private String userId;

@SerializedName("type")
private Integer type;

@SerializedName("subject")
private String subject;

public static DepartmentAdmin fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, DepartmentAdmin.class);
}

public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

}

public static WxCpCreateDepartmentRequest fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpCreateDepartmentRequest.class);
}

public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package me.chanjar.weixin.cp.bean.school.user;

import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;

import java.io.Serializable;
import java.util.List;

/**
* 获取部门列表返回结果.
*
* @author Wang_Wong
*/
@Data
public class WxCpDepartmentList extends WxCpBaseResp implements Serializable {
private static final long serialVersionUID = -5028321625140879571L;

@SerializedName("departments")
private List<Department> departments;

@Setter
@Getter
public static class Department implements Serializable{
@SerializedName("parentid")
private Integer parentId;

@SerializedName("name")
private String name;

@SerializedName("id")
private Integer id;

@SerializedName("type")
private Integer type;

@SerializedName("register_year")
private Integer registerYear;

@SerializedName("standard_grade")
private Integer standardGrade;

@SerializedName("order")
private Integer order;

@SerializedName("is_graduated")
private Integer isGraduated;

@SerializedName("open_group_chat")
private Integer openGroupChat;

@SerializedName("group_chat_id")
private String groupChatId;

@SerializedName("department_admins")
private List<DepartmentAdmin> departmentAdmins;

public static Department fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, Department.class);
}

public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

}

@Setter
@Getter
public static class DepartmentAdmin implements Serializable {

@SerializedName("userid")
private String userId;

@SerializedName("type")
private Integer type;

@SerializedName("subject")
private String subject;

public static DepartmentAdmin fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, DepartmentAdmin.class);
}

public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

}

public static WxCpDepartmentList fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpDepartmentList.class);
}

public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package me.chanjar.weixin.cp.bean.school.user;

import com.google.gson.annotations.SerializedName;
import lombok.Data;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;

import java.io.Serializable;

/**
* 修改自动升年级的配置 返回结果.
*
* @author Wang_Wong
*/
@Data
public class WxCpSetUpgradeInfo extends WxCpBaseResp implements Serializable {
private static final long serialVersionUID = -5028321625140879571L;

@SerializedName("next_upgrade_time")
private Long nextUpgradeTime;

public static WxCpSetUpgradeInfo fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpSetUpgradeInfo.class);
}

public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

}
Loading