1
0
mirror of synced 2025-12-21 08:30:11 +08:00

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

This commit is contained in:
0katekate0
2022-06-27 14:48:19 +08:00
committed by GitHub
parent 1fbd22efac
commit a807063f4c
11 changed files with 509 additions and 6 deletions

View File

@@ -3,8 +3,7 @@ package me.chanjar.weixin.cp.api;
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;
@@ -101,4 +100,62 @@ public interface WxCpSchoolUserService {
*/
WxCpBaseResp setArchSyncMode(@NonNull Integer archSyncMode) throws WxErrorException;
/**
* 创建部门
* <p>
* 请求方式POSTHTTPS
* 请求地址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>
* 请求方式POSTHTTPS
* 请求地址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;
/**
* 删除部门
* 请求方式GETHTTPS
* 请求地址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;
/**
* 获取部门列表
* 请求方式GETHTTPS
* 请求地址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;
/**
* 修改自动升年级的配置
* 请求方式: POSTHTTPS
* 请求地址: 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;
}

View File

@@ -10,8 +10,7 @@ import me.chanjar.weixin.common.error.WxErrorException;
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;
@@ -105,4 +104,46 @@ public class WxCpSchoolUserServiceImpl implements WxCpSchoolUserService {
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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -0,0 +1,86 @@
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 WxCpUpdateDepartmentRequest implements Serializable {
private static final long serialVersionUID = -4960239394895754138L;
@SerializedName("parentid")
private Integer parentId;
@SerializedName("name")
private String name;
@SerializedName("id")
private Integer id;
@SerializedName("new_id")
private Integer newId;
@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("op")
private Integer op;
@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 WxCpUpdateDepartmentRequest fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpUpdateDepartmentRequest.class);
}
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}

View File

@@ -190,6 +190,12 @@ public interface WxCpApiPathConsts {
String UPDATE_PARENT = "/cgi-bin/school/user/update_parent";
String DELETE_PARENT = "/cgi-bin/school/user/delete_parent?userid=";
String SET_ARCH_SYNC_MODE = "/cgi-bin/school/set_arch_sync_mode";
String SET_UPGRADE_INFO = "/cgi-bin/school/set_upgrade_info";
String DEPARTMENT_CREATE = "/cgi-bin/school/department/create";
String DEPARTMENT_UPDATE = "/cgi-bin/school/department/update";
String DEPARTMENT_DELETE = "/cgi-bin/school/department/delete?id=";
String DEPARTMENT_LIST = "/cgi-bin/school/department/list?id=";
String GET_PAYMENT_RESULT = "/cgi-bin/school/get_payment_result";
String GET_TRADE = "/cgi-bin/school/get_trade";