yzc 1 жил өмнө
parent
commit
8d69ffaea2

+ 1 - 0
hx-admin/src/main/resources/application-dev.yml

@@ -45,6 +45,7 @@ mail:
 
 hx:
     httpUrl: http://36.134.91.96:10006/test-api/
+        fileServiceUrl: http://localhost:8080
 
 # token配置
 token:

+ 4 - 0
hx-common/pom.xml

@@ -22,6 +22,10 @@
             <groupId>com.fjhx</groupId>
             <artifactId>hx-base</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient</artifactId>
+        </dependency>
     </dependencies>
 
 </project>

+ 76 - 0
hx-common/src/main/java/com/fjhx/common/controller/FileServiceController.java

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

+ 34 - 0
hx-common/src/main/java/com/fjhx/common/utils/Utils.java

@@ -0,0 +1,34 @@
+package com.fjhx.common.utils;
+
+import com.alibaba.fastjson2.JSONObject;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.io.IOUtils;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.methods.HttpRequestBase;
+import org.apache.http.impl.client.HttpClients;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+
+@Slf4j
+public class Utils {
+
+    /**
+     * 请求API工具方法
+     */
+    public static JSONObject getJSON(HttpRequestBase httpRequestBase) throws IOException {
+        HttpClient client = HttpClients.createDefault();
+        httpRequestBase.setConfig(RequestConfig.custom().setConnectTimeout(3000).build());
+        HttpResponse response = client.execute(httpRequestBase);
+        int statusCode = response.getStatusLine().getStatusCode();
+        HttpEntity entity = response.getEntity();
+        String responseStr = IOUtils.toString(entity.getContent(), StandardCharsets.UTF_8);
+        if (statusCode != 200) {
+            log.error("请求失败 {} {} {}", statusCode, httpRequestBase.getURI(), responseStr);
+        }
+        return JSONObject.parseObject(responseStr);
+    }
+}

+ 1 - 2
hx-item/src/main/java/com/fjhx/item/controller/product/ProductInfoController.java

@@ -185,9 +185,8 @@ public class ProductInfoController {
      * 产品类型统计
      */
     @GetMapping("/statisticsProduct")
-    public Map<String,Object> statisticsProduct() {
+    public Map<String, Object> statisticsProduct() {
         return productInfoService.statisticsProduct();
     }
 
-
 }

+ 9 - 0
hx-item/src/main/java/com/fjhx/item/entity/product/dto/ProductInfoDto.java

@@ -63,4 +63,13 @@ public class ProductInfoDto extends ProductInfo {
      * 产品id列表
      */
     private List<Long> productIds;
+
+    /**
+     * 生产图片临时地址
+     */
+    private String prodImgTempPath;
+    /**
+     * 生产文件临时地址
+     */
+    private String prodFileTempPath;
 }

+ 10 - 0
hx-item/src/main/java/com/fjhx/item/entity/product/po/ProductInfo.java

@@ -92,6 +92,16 @@ public class ProductInfo extends BasePo {
      */
     private String remark;
 
+    /**
+     * 生产图片地址
+     */
+    private String prodImgPath;
+
+    /**
+     * 生产文件地址
+     */
+    private String prodFilePath;
+
     //---------------------------------------------------------------
 
     /**

+ 21 - 0
hx-item/src/main/java/com/fjhx/item/service/product/impl/ProductInfoServiceImpl.java

@@ -10,6 +10,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fjhx.common.constant.SourceConstant;
+import com.fjhx.common.controller.FileServiceController;
 import com.fjhx.common.utils.Assert;
 import com.fjhx.file.utils.ObsFileUtil;
 import com.fjhx.item.entity.product.bo.ProductAnalysisBo;
@@ -39,6 +40,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.io.File;
 import java.math.BigDecimal;
 import java.util.*;
 import java.util.function.Function;
@@ -61,6 +63,8 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
     private ProductClassifyService productClassifyService;
     @Autowired
     private DictTenantDataService dictTenantDataService;
+    @Autowired
+    private FileServiceController fileServiceController;
 
     @Override
     public Page<ProductInfoVo> getPage(ProductInfoSelectDto dto) {
@@ -188,6 +192,23 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
             throw new ServiceException("产品条码编码重复");
         }
 
+        //操作ftp文件
+        String prodImgTempPath = productInfoDto.getProdImgTempPath();
+        String prodFileTempPath = productInfoDto.getProdFileTempPath();
+        //生产图片
+        if (ObjectUtil.isNotEmpty(prodImgTempPath)) {
+            File prodImgTemp = new File(prodImgTempPath);
+            String prodImgPath = File.separator + "product" + File.separator + "prodImg" + File.separator + productInfoDto.getCustomCode() + File.separator + prodImgTemp.getName();
+//            fileServiceController.moveFolder(prodImgTempPath, prodImgPath);
+            productInfoDto.setProdImgPath(prodImgPath);
+        }
+        //生产文件
+        if (ObjectUtil.isNotEmpty(prodFileTempPath)) {
+            File prodFileTemp = new File(prodFileTempPath);
+            String prodFilePath = File.separator + "product" + File.separator + "prodFile" + File.separator + productInfoDto.getCustomCode() + File.separator + prodFileTemp.getName();
+//            fileServiceController.moveFolder(prodFileTempPath, prodFilePath);
+            productInfoDto.setProdFilePath(prodFilePath);
+        }
 
         this.save(productInfoDto);
         ObsFileUtil.saveFile(productInfoDto.getFileList(), productInfoDto.getId());