فهرست منبع

产品库图片导出问题处理

yzc 1 سال پیش
والد
کامیت
233f3df903

+ 13 - 15
hx-common/src/main/java/com/fjhx/common/service/file/impl/FtpFileServiceImpl.java

@@ -13,7 +13,6 @@ import org.springframework.stereotype.Service;
 
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
 
@@ -82,20 +81,19 @@ public class FtpFileServiceImpl implements FtpFileService {
 
     @Override
     public List<String> getFileList(String folderPath) {
-        return Arrays.asList("ftp不可用,临时提示文字");
-//        try {
-//            HttpPost httpPost = new HttpPost(fileServiceUrl + "/fileService/getFileList");
-//            List<BasicNameValuePair> params = new ArrayList<>();
-//            params.add(new BasicNameValuePair("folderPath", folderPath));
-//            httpPost.setEntity(new UrlEncodedFormEntity(params));
-//            JSONObject responseJson = Utils.getJSON(httpPost);
-//            if (responseJson.getInteger("code") != 200) {
-//                throw new ServiceException(responseJson.getString("msg"));
-//            }
-//            return responseJson.getList("data", String.class);
-//        } catch (IOException e) {
-//            throw new ServiceException("操作失败:" + e.getMessage());
-//        }
+        try {
+            HttpPost httpPost = new HttpPost(fileServiceUrl + "/fileService/getFileList");
+            List<BasicNameValuePair> params = new ArrayList<>();
+            params.add(new BasicNameValuePair("folderPath", folderPath));
+            httpPost.setEntity(new UrlEncodedFormEntity(params));
+            JSONObject responseJson = Utils.getJSON(httpPost);
+            if (responseJson.getInteger("code") != 200) {
+                throw new ServiceException(responseJson.getString("msg"));
+            }
+            return responseJson.getList("data", String.class);
+        } catch (IOException e) {
+            throw new ServiceException("操作失败:" + e.getMessage());
+        }
     }
 
 }

+ 0 - 3
hx-item/src/main/java/com/fjhx/item/entity/product/bo/ProductExcelExportBo.java

@@ -35,7 +35,4 @@ public class ProductExcelExportBo {
     @ColumnWidth(15)
     @ExcelProperty("生产图片")
     private String prodImgPath;
-    @ColumnWidth(15)
-    @ExcelProperty("生产文件")
-    private String prodFilePath;
 }

+ 7 - 10
hx-item/src/main/java/com/fjhx/item/service/product/impl/ProductInfoServiceImpl.java

@@ -28,7 +28,6 @@ import com.fjhx.item.entity.product.po.ProductStockInfo;
 import com.fjhx.item.entity.product.vo.ProductInfoVo;
 import com.fjhx.item.enums.ProductAvailableRecordType;
 import com.fjhx.item.mapper.product.ProductInfoMapper;
-import com.fjhx.item.service.product.ProductAvailableRecordService;
 import com.fjhx.item.service.product.ProductClassifyService;
 import com.fjhx.item.service.product.ProductInfoService;
 import com.fjhx.item.service.product.ProductStockInfoService;
@@ -83,8 +82,6 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
     @Autowired
     private FtpFileService ftpFileService;
     @Autowired
-    private ProductAvailableRecordService productAvailableRecordService;
-    @Autowired
     private ISysDeptService sysDeptService;
     @Autowired
     private ProductStockInfoService productStockInfoService;
@@ -901,7 +898,7 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
         List<Long> pIds = productInfoList.stream().map(ProductInfo::getId).collect(Collectors.toList());
 
         //处理产品图片
-        Map<Long, List<FileInfoVo>> fileMap = ObsFileUtil.getFileMap(pIds);
+        Map<Long, List<FileInfoVo>> fileMap = ObsFileUtil.getFileMap(pIds, 0);
 
         List<ProductExcelExportBo> productExcelExportBoList = new ArrayList<>();
 
@@ -923,6 +920,11 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
             if (ObjectUtil.isNotEmpty(fileInfoVoList)) {
                 try {
                     String fileUrl = fileInfoVoList.get(0).getFileUrl();
+
+                    //解析图片后缀
+                    int lastIndex = fileUrl.lastIndexOf(".");
+                    String suffix = fileUrl.substring(lastIndex + 1, fileUrl.length());
+
                     BufferedImage image = ImageIO.read(new URL(fileUrl));
                     if (ObjectUtil.isNotEmpty(image)) {
                         //获取图片宽高,用以计算比例
@@ -930,7 +932,7 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
                         Double imgHeight = Double.valueOf(image.getHeight());
                         //------------------
                         ByteArrayOutputStream baos = new ByteArrayOutputStream();
-                        ImageIO.write(image, "png", baos);
+                        ImageIO.write(image, suffix, baos);
                         WriteCellData<Void> voidWriteCellData = ExcelImgUtils.imageCells(baos.toByteArray(), imgWidth, imgHeight, 10.0 * 5.8, 50.0);
                         bo.setProductImg(voidWriteCellData);
                     }
@@ -953,11 +955,6 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
             if (ObjectUtil.isNotEmpty(prodImgList)) {
                 bo.setProdImgPath(FtpFileServiceImpl.fileServiceUrl + prodImgList.get(0));
             }
-            //赋值生产文件
-            List<String> prodFileList = ftpFileService.getFileList(productInfo.getProdFilePath());
-            if (ObjectUtil.isNotEmpty(prodFileList)) {
-                bo.setProdFilePath(FtpFileServiceImpl.fileServiceUrl + prodFileList.get(0));
-            }
 
             productExcelExportBoList.add(bo);
         }