|
@@ -3,6 +3,7 @@ package com.fjhx.item.service.product.impl;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.alibaba.excel.metadata.data.WriteCellData;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
@@ -33,6 +34,7 @@ import com.fjhx.item.service.product.ProductClassifyService;
|
|
|
import com.fjhx.item.service.product.ProductInfoService;
|
|
|
import com.fjhx.item.service.product.ProductStockInfoService;
|
|
|
import com.fjhx.item.util.CodeEnum;
|
|
|
+import com.fjhx.item.util.excel.ExcelImgUtils;
|
|
|
import com.fjhx.item.util.excel.util.ExcelUtil;
|
|
|
import com.fjhx.tenant.entity.dict.dto.DictTenantDataSelectDto;
|
|
|
import com.fjhx.tenant.entity.dict.vo.DictTenantDataVo;
|
|
@@ -51,10 +53,13 @@ import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.imageio.ImageIO;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.awt.image.BufferedImage;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.net.MalformedURLException;
|
|
|
import java.net.URL;
|
|
|
import java.util.*;
|
|
|
import java.util.function.Function;
|
|
@@ -792,19 +797,28 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
width = ObjectUtil.isEmpty(width) ? BigDecimal.ZERO : width;
|
|
|
height = ObjectUtil.isEmpty(height) ? BigDecimal.ZERO : height;
|
|
|
|
|
|
+ ProductExcelExportBo bo = new ProductExcelExportBo();
|
|
|
//获取产品图片信息
|
|
|
- String fileUrl = "";
|
|
|
List<FileInfoVo> fileInfoVoList = fileMap.get(productInfo.getId());
|
|
|
if (ObjectUtil.isNotEmpty(fileInfoVoList)) {
|
|
|
- fileUrl = fileInfoVoList.get(0).getFileUrl();
|
|
|
+ try {
|
|
|
+ String fileUrl = fileInfoVoList.get(0).getFileUrl();
|
|
|
+ BufferedImage image = ImageIO.read(new URL(fileUrl));
|
|
|
+ if (ObjectUtil.isNotEmpty(image)) {
|
|
|
+ //获取图片宽高,用以计算比例
|
|
|
+ Double imgWidth = Double.valueOf(image.getWidth());
|
|
|
+ Double imgHeight = Double.valueOf(image.getHeight());
|
|
|
+ //------------------
|
|
|
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
+ ImageIO.write(image, "png", baos);
|
|
|
+ WriteCellData<Void> voidWriteCellData = ExcelImgUtils.imageCells(baos.toByteArray(), imgWidth, imgHeight, 10.0 * 5.8, 50.0);
|
|
|
+ bo.setProductImg(voidWriteCellData);
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new ServiceException("导出失败" + e.getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- ProductExcelExportBo bo = new ProductExcelExportBo();
|
|
|
- try {
|
|
|
- bo.setProductImg(new URL(fileUrl));
|
|
|
- } catch (MalformedURLException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- }
|
|
|
bo.setProductCode(productInfo.getCustomCode());
|
|
|
bo.setProductName(productInfo.getName());
|
|
|
bo.setProductSize(String.format("%s * %s * %s", length, width, height));
|