|
@@ -1,10 +1,13 @@
|
|
|
package com.fdkankan.sale.util;
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
import com.fdkankan.fyun.face.FYunFileServiceInterface;
|
|
|
+import com.fdkankan.sale.common.CacheUtil;
|
|
|
import com.fdkankan.sale.common.FilePath;
|
|
|
import com.fdkankan.sale.entity.Customer;
|
|
|
import com.fdkankan.sale.entity.PriceList;
|
|
|
import com.fdkankan.sale.service.IPriceListService;
|
|
|
+import com.fdkankan.sale.util.pdf.ExportImg;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
@@ -13,7 +16,10 @@ import com.alibaba.excel.write.metadata.WriteSheet;
|
|
|
import com.alibaba.excel.write.metadata.fill.FillConfig;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+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.io.UnsupportedEncodingException;
|
|
@@ -28,7 +34,7 @@ public class MyExcelUtil {
|
|
|
FYunFileServiceInterface fYunFileServiceInterface;
|
|
|
|
|
|
//根据模板导出excel
|
|
|
- public void listFill(HttpServletResponse response,String excelName,Object obj,Object obj2,Integer type) {
|
|
|
+ public void listFill(HttpServletResponse response, String excelName, Object obj, Object obj2, ExportImg exportImg,Integer type) {
|
|
|
response.setContentType("application/vnd.ms-excel");
|
|
|
response.setCharacterEncoding("utf-8");
|
|
|
String fileName = excelName + ".xlsx";
|
|
@@ -71,9 +77,46 @@ public class MyExcelUtil {
|
|
|
if(excelWriter != null &&obj2 != null){
|
|
|
excelWriter.fill(obj2, fillConfig, writeSheet);
|
|
|
}
|
|
|
+ if(excelWriter != null &&exportImg != null){
|
|
|
+ Map<String, Object> map = BeanUtil.beanToMap(exportImg);
|
|
|
+ imageHandleByParam(map);
|
|
|
+ excelWriter.fill(map, fillConfig, writeSheet);
|
|
|
+ }
|
|
|
assert excelWriter != null;
|
|
|
excelWriter.finish();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 图片处理
|
|
|
+ *
|
|
|
+ * @param param
|
|
|
+ */
|
|
|
+ private void imageHandleByParam(Map<String, Object> param) {
|
|
|
+ for (Map.Entry<String, Object> entry : param.entrySet()) {
|
|
|
+ try {
|
|
|
+ String mapKey = entry.getKey();
|
|
|
+ String ossPath = entry.getValue().toString();
|
|
|
+ String downloadPath = FilePath.file_path + ossPath.replaceAll(CacheUtil.host,"");
|
|
|
+ // 填充图片
|
|
|
+ ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
|
|
|
+ BufferedImage bufferImg = ImageIO.read(new File(downloadPath));
|
|
|
+ // 图片后缀格式
|
|
|
+ String suffix = ".png";
|
|
|
+ if(downloadPath.contains(".")){
|
|
|
+ suffix = downloadPath.split("\\.")[1];
|
|
|
+ }
|
|
|
+ ImageIO.write(bufferImg, suffix, byteArrayOut);
|
|
|
+
|
|
|
+ bufferImg.flush();
|
|
|
+ // 注意:这里需要put回原来的key里
|
|
|
+ param.put(mapKey, byteArrayOut.toByteArray());
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
}
|