From a6d4b6e6abd08d7e0d45d4c33435eaab2819d811 Mon Sep 17 00:00:00 2001
From: 0katekate0 <32161300+0katekate0@users.noreply.github.com>
Date: Thu, 19 May 2022 14:06:39 +0800
Subject: [PATCH] =?UTF-8?q?:new:=20#2651=E3=80=90=E4=BC=81=E4=B8=9A?=
=?UTF-8?q?=E5=BE=AE=E4=BF=A1=E3=80=91=E6=96=B0=E5=A2=9E=E5=BE=AE=E7=9B=98?=
=?UTF-8?q?=E6=96=87=E4=BB=B6=E7=AE=A1=E7=90=86=E6=8E=A5=E5=8F=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../weixin/cp/api/WxCpOaWeDriveService.java | 43 +++++++
.../cp/api/impl/WxCpOaWeDriveServiceImpl.java | 29 ++++-
.../oa/wedrive/WxCpFileDeleteRequest.java | 39 +++++++
.../cp/bean/oa/wedrive/WxCpFileInfo.java | 89 +++++++++++++++
.../cp/bean/oa/wedrive/WxCpFileMove.java | 105 ++++++++++++++++++
.../bean/oa/wedrive/WxCpFileMoveRequest.java | 58 ++++++++++
.../weixin/cp/constant/WxCpApiPathConsts.java | 3 +
.../cp/api/WxCpOaWeDriveServiceTest.java | 28 +++++
8 files changed, 393 insertions(+), 1 deletion(-)
create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpFileDeleteRequest.java
create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpFileInfo.java
create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpFileMove.java
create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpFileMoveRequest.java
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaWeDriveService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaWeDriveService.java
index 32182f9f3..c4c4376d5 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaWeDriveService.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaWeDriveService.java
@@ -5,6 +5,8 @@ import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.bean.oa.wedrive.*;
+import java.util.List;
+
/**
* 企业微信微盘相关接口.
* https://developer.work.weixin.qq.com/document/path/93654
@@ -194,4 +196,45 @@ public interface WxCpOaWeDriveService {
WxCpFileCreate fileCreate(@NonNull String userId, @NonNull String spaceId,
@NonNull String fatherId, @NonNull Integer fileType, @NonNull String fileName) throws WxErrorException;
+ /**
+ * 移动文件
+ * 该接口用于将文件移动到指定位置。
+ *
+ * 请求方式:POST(HTTPS)
+ * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_move?access_token=ACCESS_TOKEN
+ *
+ * @param request 移动文件的请求参数
+ * @return
+ * @throws WxErrorException
+ */
+ WxCpFileMove fileMove(@NonNull WxCpFileMoveRequest request) throws WxErrorException;
+
+ /**
+ * 删除文件
+ * 该接口用于删除指定文件。
+ *
+ * 请求方式:POST(HTTPS)
+ * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_delete?access_token=ACCESS_TOKEN
+ *
+ * @param userId 操作者userid
+ * @param fileId 文件fileid列表
+ * @return
+ * @throws WxErrorException
+ */
+ WxCpBaseResp fileDelete(@NonNull String userId, @NonNull List fileId) throws WxErrorException;
+
+ /**
+ * 文件信息
+ * 该接口用于获取指定文件的信息。
+ *
+ * 请求方式:POST(HTTPS)
+ * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_info?access_token=ACCESS_TOKEN
+ *
+ * @param userId
+ * @param fileId
+ * @return
+ * @throws WxErrorException
+ */
+ WxCpFileInfo fileInfo(@NonNull String userId, @NonNull String fileId) throws WxErrorException;
+
}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaWeDriveServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaWeDriveServiceImpl.java
index 771e5c00c..63095ed4e 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaWeDriveServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaWeDriveServiceImpl.java
@@ -10,6 +10,8 @@ import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.bean.oa.wedrive.*;
+import java.util.List;
+
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Oa.*;
/**
@@ -117,7 +119,7 @@ public class WxCpOaWeDriveServiceImpl implements WxCpOaWeDriveService {
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(FILE_RENAME);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("userid", userId);
- jsonObject.addProperty("fileiid", fileId);
+ jsonObject.addProperty("fileid", fileId);
jsonObject.addProperty("new_name", newName);
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
return WxCpFileRename.fromJson(responseContent);
@@ -136,4 +138,29 @@ public class WxCpOaWeDriveServiceImpl implements WxCpOaWeDriveService {
return WxCpFileCreate.fromJson(responseContent);
}
+ @Override
+ public WxCpFileMove fileMove(@NonNull WxCpFileMoveRequest request) throws WxErrorException {
+ String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(FILE_MOVE);
+ String responseContent = this.cpService.post(apiUrl, request.toJson());
+ return WxCpFileMove.fromJson(responseContent);
+ }
+
+ @Override
+ public WxCpBaseResp fileDelete(@NonNull String userId, @NonNull List fileId) throws WxErrorException {
+ String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(FILE_DELETE);
+ WxCpFileDeleteRequest request = new WxCpFileDeleteRequest(userId, fileId);
+ String responseContent = this.cpService.post(apiUrl, request.toJson());
+ return WxCpBaseResp.fromJson(responseContent);
+ }
+
+ @Override
+ public WxCpFileInfo fileInfo(@NonNull String userId, @NonNull String fileId) throws WxErrorException {
+ String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(FILE_INFO);
+ JsonObject jsonObject = new JsonObject();
+ jsonObject.addProperty("userid", userId);
+ jsonObject.addProperty("fileid", fileId);
+ String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
+ return WxCpFileInfo.fromJson(responseContent);
+ }
+
}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpFileDeleteRequest.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpFileDeleteRequest.java
new file mode 100644
index 000000000..65e19c8a1
--- /dev/null
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpFileDeleteRequest.java
@@ -0,0 +1,39 @@
+package me.chanjar.weixin.cp.bean.oa.wedrive;
+
+import com.google.gson.annotations.SerializedName;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.experimental.Accessors;
+import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * 删除文件请求.
+ */
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+@Accessors(chain = true)
+public class WxCpFileDeleteRequest implements Serializable {
+ private static final long serialVersionUID = -4960239393895754138L;
+
+ @SerializedName("userid")
+ private String userId;
+
+ @SerializedName("fileid")
+ private List fileId;
+
+ public static WxCpFileDeleteRequest fromJson(String json) {
+ return WxCpGsonBuilder.create().fromJson(json, WxCpFileDeleteRequest.class);
+ }
+
+ public String toJson() {
+ return WxCpGsonBuilder.create().toJson(this);
+ }
+
+}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpFileInfo.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpFileInfo.java
new file mode 100644
index 000000000..222105379
--- /dev/null
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpFileInfo.java
@@ -0,0 +1,89 @@
+package me.chanjar.weixin.cp.bean.oa.wedrive;
+
+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;
+
+/**
+ * 文件信息.
+ *
+ * @author Wang_Wong
+ */
+@Data
+public class WxCpFileInfo extends WxCpBaseResp implements Serializable {
+ private static final long serialVersionUID = -5028321625142879581L;
+
+ @SerializedName("file_info")
+ private FileInfo fileInfo;
+
+ @Getter
+ @Setter
+ public static class FileInfo implements Serializable {
+ private static final long serialVersionUID = -4960239393895754598L;
+
+ @SerializedName("fileid")
+ private String fileId;
+
+ @SerializedName("file_name")
+ private String fileName;
+
+ @SerializedName("spaceid")
+ private String spaceId;
+
+ @SerializedName("fatherid")
+ private String fatherId;
+
+ @SerializedName("file_size")
+ private Long fileSize;
+
+ @SerializedName("ctime")
+ private Long cTime;
+
+ @SerializedName("mtime")
+ private Long mTime;
+
+ @SerializedName("file_type")
+ private Integer fileType;
+
+ @SerializedName("file_status")
+ private Integer fileStatus;
+
+ @SerializedName("create_userid")
+ private String createUserId;
+
+ @SerializedName("update_userid")
+ private String updateUserId;
+
+ @SerializedName("sha")
+ private String sha;
+
+ @SerializedName("md5")
+ private String md5;
+
+ @SerializedName("url")
+ private String url;
+
+ public static FileInfo fromJson(String json) {
+ return WxCpGsonBuilder.create().fromJson(json, FileInfo.class);
+ }
+
+ public String toJson() {
+ return WxCpGsonBuilder.create().toJson(this);
+ }
+
+ }
+
+ public static WxCpFileInfo fromJson(String json) {
+ return WxCpGsonBuilder.create().fromJson(json, WxCpFileInfo.class);
+ }
+
+ public String toJson() {
+ return WxCpGsonBuilder.create().toJson(this);
+ }
+
+}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpFileMove.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpFileMove.java
new file mode 100644
index 000000000..f9d232df2
--- /dev/null
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpFileMove.java
@@ -0,0 +1,105 @@
+package me.chanjar.weixin.cp.bean.oa.wedrive;
+
+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 WxCpFileMove extends WxCpBaseResp implements Serializable {
+ private static final long serialVersionUID = -5028321625142879581L;
+
+ @SerializedName("file_list")
+ private FileList fileList;
+
+ @Getter
+ @Setter
+ public static class FileList implements Serializable {
+ private static final long serialVersionUID = -4960239393895754598L;
+
+ @SerializedName("item")
+ private List- item;
+
+ public static FileList fromJson(String json) {
+ return WxCpGsonBuilder.create().fromJson(json, FileList.class);
+ }
+
+ public String toJson() {
+ return WxCpGsonBuilder.create().toJson(this);
+ }
+
+ }
+
+ @Getter
+ @Setter
+ public static class Item implements Serializable {
+ private static final long serialVersionUID = -4960239393895754598L;
+
+ @SerializedName("fileid")
+ private String fileId;
+
+ @SerializedName("file_name")
+ private String fileName;
+
+ @SerializedName("spaceid")
+ private String spaceId;
+
+ @SerializedName("fatherid")
+ private String fatherId;
+
+ @SerializedName("file_size")
+ private Long fileSize;
+
+ @SerializedName("ctime")
+ private Long cTime;
+
+ @SerializedName("mtime")
+ private Long mTime;
+
+ @SerializedName("file_type")
+ private Integer fileType;
+
+ @SerializedName("file_status")
+ private Integer fileStatus;
+
+ @SerializedName("create_userid")
+ private String createUserId;
+
+ @SerializedName("update_userid")
+ private String updateUserId;
+
+ @SerializedName("sha")
+ private String sha;
+
+ @SerializedName("md5")
+ private String md5;
+
+ public static Item fromJson(String json) {
+ return WxCpGsonBuilder.create().fromJson(json, Item.class);
+ }
+
+ public String toJson() {
+ return WxCpGsonBuilder.create().toJson(this);
+ }
+
+ }
+
+ public static WxCpFileMove fromJson(String json) {
+ return WxCpGsonBuilder.create().fromJson(json, WxCpFileMove.class);
+ }
+
+ public String toJson() {
+ return WxCpGsonBuilder.create().toJson(this);
+ }
+
+}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpFileMoveRequest.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpFileMoveRequest.java
new file mode 100644
index 000000000..8f8a178aa
--- /dev/null
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpFileMoveRequest.java
@@ -0,0 +1,58 @@
+package me.chanjar.weixin.cp.bean.oa.wedrive;
+
+import com.google.gson.annotations.SerializedName;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.experimental.Accessors;
+import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
+
+import java.io.Serializable;
+
+/**
+ * 移动文件请求.
+ */
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+@Accessors(chain = true)
+public class WxCpFileMoveRequest implements Serializable {
+ private static final long serialVersionUID = -4960239393895754138L;
+
+ /**
+ * 操作者userid
+ */
+ @SerializedName("userid")
+ private String userId;
+
+ /**
+ * 如果移动到的目标目录与需要移动的文件重名时,是否覆盖。
+ * true:重名文件覆盖
+ * false:重名文件进行冲突重命名处理(移动后文件名格式如xxx(1).txt xxx(1).doc等)
+ */
+ @SerializedName("replace")
+ private Boolean replace;
+
+ /**
+ * 当前目录的fileid,根目录时为空间spaceid
+ */
+ @SerializedName("fatherid")
+ private String fatherId;
+
+ /**
+ * 文件fileid
+ */
+ @SerializedName("fileid")
+ private String[] fileId;
+
+ public static WxCpFileMoveRequest fromJson(String json) {
+ return WxCpGsonBuilder.create().fromJson(json, WxCpFileMoveRequest.class);
+ }
+
+ public String toJson() {
+ return WxCpGsonBuilder.create().toJson(this);
+ }
+
+}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java
index 05af6660c..180f5f594 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java
@@ -158,6 +158,9 @@ public interface WxCpApiPathConsts {
String FILE_DOWNLOAD = "/cgi-bin/wedrive/file_download";
String FILE_RENAME = "/cgi-bin/wedrive/file_rename";
String FILE_CREATE = "/cgi-bin/wedrive/file_create";
+ String FILE_MOVE = "/cgi-bin/wedrive/file_move";
+ String FILE_DELETE = "/cgi-bin/wedrive/file_delete";
+ String FILE_INFO = "/cgi-bin/wedrive/file_info";
/**
* 审批流程引擎
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpOaWeDriveServiceTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpOaWeDriveServiceTest.java
index 5d0016ae8..a1205df24 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpOaWeDriveServiceTest.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpOaWeDriveServiceTest.java
@@ -1,5 +1,6 @@
package me.chanjar.weixin.cp.api;
+import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
@@ -47,6 +48,33 @@ public class WxCpOaWeDriveServiceTest {
String fileId = "s.ww45d3e188865aca30.652091685u4h_f.652344507ysDL";
String fileId2 = "s.ww45d3e188865aca30.652091685u4h_f.652696024TU4P";
+
+ /**
+ * 删除文件
+ */
+ ArrayList fileIds = Lists.newArrayList();
+ fileIds.add(fileId);
+ WxCpBaseResp fileDelete = cpService.getOaWeDriveService().fileDelete(uId, fileIds);
+ log.info("删除文件数据为:{}", fileDelete.toJson());
+
+ /**
+ * 文件信息
+ */
+ WxCpFileInfo fileInfo = cpService.getOaWeDriveService().fileInfo(uId, fileId);
+ log.info("fileInfo数据为:{}", fileInfo.toJson());
+
+ /**
+ * 移动文件
+ */
+ WxCpFileMoveRequest fileMoveRequest = new WxCpFileMoveRequest();
+ fileMoveRequest.setUserId(uId);
+ fileMoveRequest.setFatherId(spId);
+ fileMoveRequest.setReplace(true);
+ fileMoveRequest.setFileId(new String[]{fileId});
+
+ WxCpFileMove fileMove = cpService.getOaWeDriveService().fileMove(fileMoveRequest);
+ log.info("fileMove数据为:{}", fileMove.toJson());
+
/**
* 新建文件/微文档
*/