|
@@ -0,0 +1,76 @@
|
|
|
+package com.fjhx.common.controller;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.extra.spring.SpringUtil;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.fjhx.common.utils.Utils;
|
|
|
+import com.ruoyi.common.exception.ServiceException;
|
|
|
+import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
|
+import org.apache.http.client.methods.HttpPost;
|
|
|
+import org.apache.http.message.BasicNameValuePair;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * FTP文件服务控制器
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/fileService")
|
|
|
+public class FileServiceController {
|
|
|
+ /**
|
|
|
+ * 创建临时文件夹
|
|
|
+ */
|
|
|
+ @PostMapping("/createTempFolder")
|
|
|
+ public JSONObject createTempFolder(String folderName) {
|
|
|
+ try {
|
|
|
+ String fileServiceUrl = SpringUtil.getProperty("hx.fileServiceUrl");
|
|
|
+ if (ObjectUtil.isEmpty(fileServiceUrl)) {
|
|
|
+ throw new ServiceException("未配置文件服务控制程序!!!");
|
|
|
+ }
|
|
|
+ HttpPost httpPost = new HttpPost(fileServiceUrl + "/fileService/createFolder");
|
|
|
+ List<BasicNameValuePair> params = new ArrayList<>();
|
|
|
+ params.add(new BasicNameValuePair("folderPath", File.separator + "temp" + File.separator + folderName));
|
|
|
+ httpPost.setEntity(new UrlEncodedFormEntity(params));
|
|
|
+ JSONObject responseJson = Utils.getJSON(httpPost);
|
|
|
+ if (responseJson.getInteger("code") != 200) {
|
|
|
+ throw new ServiceException(responseJson.getString("msg"));
|
|
|
+ }
|
|
|
+ return responseJson.getJSONObject("data");
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new ServiceException("操作失败:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将临时文件移动到永久文件夹
|
|
|
+ */
|
|
|
+ @PostMapping("/moveTempFolderToPermanent")
|
|
|
+ public void moveFolder(String sourceFolderPath, String targetFolderPath) {
|
|
|
+ try {
|
|
|
+ String fileServiceUrl = SpringUtil.getProperty("hx.fileServiceUrl");
|
|
|
+ if (ObjectUtil.isEmpty(fileServiceUrl)) {
|
|
|
+ throw new ServiceException("未配置文件服务控制程序!!!");
|
|
|
+ }
|
|
|
+ HttpPost httpPost = new HttpPost(fileServiceUrl + "/fileService/moveTempFolderToPermanent");
|
|
|
+
|
|
|
+ List<BasicNameValuePair> params = new ArrayList<>();
|
|
|
+ params.add(new BasicNameValuePair("sourceFolderPath", sourceFolderPath));
|
|
|
+ params.add(new BasicNameValuePair("targetFolderPath", File.separator + "permanent" + File.separator + targetFolderPath));
|
|
|
+ httpPost.setEntity(new UrlEncodedFormEntity(params));
|
|
|
+
|
|
|
+ JSONObject responseJson = Utils.getJSON(httpPost);
|
|
|
+
|
|
|
+ if (responseJson.getInteger("code") != 200) {
|
|
|
+ throw new ServiceException(responseJson.getString("msg"));
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new ServiceException("操作失败:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|