|
|
@@ -1,6 +1,11 @@
|
|
|
package com.cnd3b.restcontroller.customer.wechatapplet;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.aliyun.oss.OSS;
|
|
|
+import com.aliyun.oss.OSSClientBuilder;
|
|
|
+import com.aliyun.oss.model.ListObjectsRequest;
|
|
|
+import com.aliyun.oss.model.OSSObjectSummary;
|
|
|
+import com.aliyun.oss.model.ObjectListing;
|
|
|
import com.cnd3b.common.Controller;
|
|
|
import com.cnd3b.common.data.Row;
|
|
|
import com.cnd3b.common.data.Rows;
|
|
|
@@ -8,16 +13,25 @@ import com.cnd3b.common.data.RowsMap;
|
|
|
import com.cnd3b.common.data.SQLFactory;
|
|
|
import com.cnd3b.common.parameter.parameter;
|
|
|
import com.cnd3b.utility.WebRequest;
|
|
|
+import com.cnd3b.utility.aliyun.oss.AliyunOSSConfigConstant;
|
|
|
import com.cnd3b.utility.wechatdock.WechatDock_Enterprise;
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
|
+import p2.common.parse.A;
|
|
|
import p2.pao.PaoRemote;
|
|
|
import p2.pao.PaoSetRemote;
|
|
|
import p2.util.P2Exception;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Calendar;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import static com.cnd3b.utility.aliyun.oss.AliyunOSSConfigConstant.BUCKE_NAME_2;
|
|
|
|
|
|
public class wechatapplet extends Controller {
|
|
|
+
|
|
|
+ String url = BUCKE_NAME_2 + "." + AliyunOSSConfigConstant.END_POINT;
|
|
|
+
|
|
|
/**
|
|
|
* 构造函数
|
|
|
*
|
|
|
@@ -25,6 +39,7 @@ public class wechatapplet extends Controller {
|
|
|
*/
|
|
|
public wechatapplet(JSONObject content) {
|
|
|
super(content);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -162,4 +177,73 @@ public class wechatapplet extends Controller {
|
|
|
}.start();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取指定目录下的文件和文件夹
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String getFilesOfPath() {
|
|
|
+ String folderPath = content.getString("folderPath");
|
|
|
+ // 构造ListObjectsRequest请求。
|
|
|
+ ListObjectsRequest listObjectsRequest = new ListObjectsRequest(BUCKE_NAME_2);
|
|
|
+ // 设置正斜线(/)为文件夹的分隔符。
|
|
|
+ listObjectsRequest.setDelimiter("/");
|
|
|
+ // 列出fun目录下的所有文件和文件夹。
|
|
|
+ listObjectsRequest.setPrefix(folderPath);
|
|
|
+ ObjectListing listing = ossClient.listObjects(listObjectsRequest);
|
|
|
+ // 遍历所有文件。
|
|
|
+ System.out.println("Objects:");
|
|
|
+ List<JSONObject> objectSummaryList = new ArrayList<>();
|
|
|
+ for (OSSObjectSummary objectSummary : listing.getObjectSummaries()) {
|
|
|
+ if (!objectSummary.getKey().equals(folderPath)) {
|
|
|
+ JSONObject object = new JSONObject();
|
|
|
+ object.put("key", objectSummary.getKey());
|
|
|
+ object.put("name", objectSummary.getKey().replace(folderPath, ""));
|
|
|
+ object.put("size", objectSummary.getSize() / 1024);
|
|
|
+ object.put("time", getDateTime_Str(objectSummary.getLastModified()));
|
|
|
+ object.put("url", url + "/" + objectSummary.getKey());
|
|
|
+ objectSummaryList.add(object);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询对应账号下有哪些有权限的目录
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "查询账号目录");
|
|
|
+ sqlFactory.addParameter("tuserid", parameter.tuserid);
|
|
|
+ Rows rows = dbConnect.runSqlQuery(sqlFactory);
|
|
|
+ ArrayList<String> listFolders = new ArrayList<>();
|
|
|
+ if (!rows.isEmpty()) {
|
|
|
+ for (Row row : rows) {
|
|
|
+ listFolders.add(row.getString("fpath"));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 遍历所有commonPrefix。
|
|
|
+ List<JSONObject> commonPrefixList = new ArrayList<>();
|
|
|
+ for (String commonPrefix : listing.getCommonPrefixes()) {
|
|
|
+ JSONObject object = new JSONObject();
|
|
|
+ object.put("folderpath", commonPrefix);
|
|
|
+ if (listFolders.size() == 0) {
|
|
|
+
|
|
|
+ commonPrefixList.add(object);
|
|
|
+ } else {
|
|
|
+ for (String str : listFolders) {
|
|
|
+ if (str.equals(object)) {
|
|
|
+ commonPrefixList.add(object);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ // 关闭OSSClient。
|
|
|
+ ossClient.shutdown();
|
|
|
+
|
|
|
+ JSONObject object = new JSONObject();
|
|
|
+ object.put("files", objectSummaryList);
|
|
|
+ object.put("folder", commonPrefixList);
|
|
|
+ return getSucReturnObject().setData(object).toString();
|
|
|
+ }
|
|
|
+
|
|
|
}
|