|
@@ -1,32 +1,39 @@
|
|
package com.caimei.service.auth.impl;
|
|
package com.caimei.service.auth.impl;
|
|
|
|
|
|
import com.aliyuncs.utils.StringUtils;
|
|
import com.aliyuncs.utils.StringUtils;
|
|
|
|
+import com.caimei.mapper.cmMapper.AuthMapper;
|
|
|
|
+import com.caimei.mapper.cmMapper.AuthProductMapper;
|
|
import com.caimei.mapper.cmMapper.FileMapper;
|
|
import com.caimei.mapper.cmMapper.FileMapper;
|
|
-import com.caimei.model.en.QrCodeSize;
|
|
|
|
|
|
+import com.caimei.model.ResponseJson;
|
|
import com.caimei.model.po.ProductImagePo;
|
|
import com.caimei.model.po.ProductImagePo;
|
|
|
|
+import com.caimei.model.po.ProductParamPo;
|
|
import com.caimei.model.po.UploadFilePo;
|
|
import com.caimei.model.po.UploadFilePo;
|
|
|
|
+import com.caimei.model.vo.AuthFormVo;
|
|
import com.caimei.model.vo.AuthVo;
|
|
import com.caimei.model.vo.AuthVo;
|
|
|
|
+import com.caimei.model.vo.ProductFormVo;
|
|
import com.caimei.service.auth.DownloadService;
|
|
import com.caimei.service.auth.DownloadService;
|
|
import com.caimei.service.auth.UploadService;
|
|
import com.caimei.service.auth.UploadService;
|
|
-import com.caimei.utils.ImageUtils;
|
|
|
|
|
|
+import com.caimei.utils.FileIOUtils;
|
|
import com.caimei.utils.OSSUtils;
|
|
import com.caimei.utils.OSSUtils;
|
|
|
|
+import com.caimei.utils.PoiUtils;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFCell;
|
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFRichTextString;
|
|
|
|
+import org.apache.poi.ss.usermodel.CellType;
|
|
|
|
+import org.apache.poi.xssf.usermodel.*;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
-import javax.imageio.ImageIO;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
-import java.awt.image.BufferedImage;
|
|
|
|
-import java.io.File;
|
|
|
|
-import java.io.FileInputStream;
|
|
|
|
-import java.io.IOException;
|
|
|
|
-import java.io.OutputStream;
|
|
|
|
|
|
+import java.io.*;
|
|
import java.net.URLEncoder;
|
|
import java.net.URLEncoder;
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Description
|
|
* Description
|
|
@@ -41,6 +48,12 @@ public class DownloadServiceImpl implements DownloadService {
|
|
@Resource
|
|
@Resource
|
|
private FileMapper fileMapper;
|
|
private FileMapper fileMapper;
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private AuthMapper authMapper;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private AuthProductMapper authProductMapper;
|
|
|
|
+
|
|
private UploadService uploadService;
|
|
private UploadService uploadService;
|
|
|
|
|
|
@Value("${caimei.oldapi}")
|
|
@Value("${caimei.oldapi}")
|
|
@@ -64,40 +77,53 @@ public class DownloadServiceImpl implements DownloadService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public void downloadShopImage(Integer authUserId, Integer type, HttpServletRequest request, HttpServletResponse response) throws Exception {
|
|
|
|
- if (null == authUserId || null == type) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
|
|
+ public void downloadShopImage(String authIds, Integer type, HttpServletRequest request, HttpServletResponse response) throws Exception {
|
|
ArrayList<UploadFilePo> fileList = new ArrayList<>();
|
|
ArrayList<UploadFilePo> fileList = new ArrayList<>();
|
|
- List<ProductImagePo> productImageList = fileMapper.getProductImageList(authUserId);
|
|
|
|
- List<AuthVo> authImageList = fileMapper.getAuthImageList(authUserId);
|
|
|
|
|
|
+ HashMap<String, List<UploadFilePo>> fileMap = new HashMap<>();
|
|
|
|
+ List<AuthVo> authImageList = fileMapper.getAuthImageList(authIds);
|
|
if (1 == type) {
|
|
if (1 == type) {
|
|
- productImageList.forEach(productImage -> {
|
|
|
|
- UploadFilePo file = new UploadFilePo();
|
|
|
|
- file.setFileUrl(productImage.getCertificateImage());
|
|
|
|
- file.setFileName(productImage.getAuthParty() + "-" + productImage.getSnCode());
|
|
|
|
- if (StringUtils.isNotEmpty(file.getFileUrl())) {
|
|
|
|
|
|
+ // 机构授权牌
|
|
|
|
+ List<String> fileNameList = new ArrayList<>();
|
|
|
|
+ authImageList.forEach(authImage ->{
|
|
|
|
+ if (StringUtils.isNotEmpty(authImage.getAuthImage())) {
|
|
|
|
+ UploadFilePo file = new UploadFilePo();
|
|
|
|
+ String fileName = authImage.getAuthParty();
|
|
|
|
+ int k = 1;
|
|
|
|
+ while (fileNameList.contains(fileName)) {
|
|
|
|
+ fileName = fileName.replace("(" + (k-1) + ")", "") + "(" + k + ")";
|
|
|
|
+ k++;
|
|
|
|
+ }
|
|
|
|
+ fileNameList.add(fileName);
|
|
|
|
+ file.setFileUrl(authImage.getAuthImage());
|
|
|
|
+ file.setFileName(fileName);
|
|
fileList.add(file);
|
|
fileList.add(file);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
+ if (fileList.size() > 0) {
|
|
|
|
+ fileMap.put("机构授权牌", fileList);
|
|
|
|
+ }
|
|
} else if (2 == type) {
|
|
} else if (2 == type) {
|
|
- productImageList.forEach(productImage -> {
|
|
|
|
- String qrCodeLink = wwwServer + "/product/auth/product-" + productImage.getProductId() + ".html";
|
|
|
|
- // 生成二维码
|
|
|
|
- BufferedImage qrCodeImage = ImageUtils.createQrCode(qrCodeLink, QrCodeSize.XLARGE);
|
|
|
|
- String fileName = productImage.getAuthParty() + "-" + productImage.getSnCode();
|
|
|
|
- String imagePath = createBufferedImageFile(qrCodeImage, fileName, "png");
|
|
|
|
- UploadFilePo file = new UploadFilePo();
|
|
|
|
- file.setFileUrl(imagePath);
|
|
|
|
- file.setFileName(productImage.getAuthParty() + "-" + productImage.getSnCode());
|
|
|
|
- fileList.add(file);
|
|
|
|
|
|
+ // 设备授权牌
|
|
|
|
+ authImageList.forEach(authImage->{
|
|
|
|
+ List<ProductImagePo> productList = fileMapper.getProductImageList(authImage.getAuthId());
|
|
|
|
+ ArrayList<UploadFilePo> list = new ArrayList<>();
|
|
|
|
+ productList.forEach(product->{
|
|
|
|
+ if (StringUtils.isNotEmpty(product.getCertificateImage())) {
|
|
|
|
+ UploadFilePo file = new UploadFilePo();
|
|
|
|
+ file.setFileUrl(product.getCertificateImage());
|
|
|
|
+ file.setFileName(product.getProductName() + "-" + product.getSnCode());
|
|
|
|
+ list.add(file);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ if (list.size() > 0) {
|
|
|
|
+ fileMap.put(authImage.getAuthParty(), list);
|
|
|
|
+ }
|
|
});
|
|
});
|
|
- } else {
|
|
|
|
|
|
+ } else if (3 == type) {
|
|
|
|
+ // 机构二维码
|
|
List<String> fileNameList = new ArrayList<>();
|
|
List<String> fileNameList = new ArrayList<>();
|
|
authImageList.forEach(authImage -> {
|
|
authImageList.forEach(authImage -> {
|
|
- String qrCodeLink = zpServer + "/" + authUserId + "/app/approve/club/detail?id=" + authImage.getAuthId();
|
|
|
|
- // 生成二维码
|
|
|
|
- BufferedImage qrCodeImage = ImageUtils.createQrCode(qrCodeLink, QrCodeSize.LARGE);
|
|
|
|
|
|
+ String qrCodeLink = zpServer + "/" + authImage.getAuthUserId() + "/app/approve/club/detail?id=" + authImage.getAuthId();
|
|
String fileName = authImage.getAuthParty();
|
|
String fileName = authImage.getAuthParty();
|
|
int k = 1;
|
|
int k = 1;
|
|
while (fileNameList.contains(fileName)) {
|
|
while (fileNameList.contains(fileName)) {
|
|
@@ -105,32 +131,298 @@ public class DownloadServiceImpl implements DownloadService {
|
|
k++;
|
|
k++;
|
|
}
|
|
}
|
|
fileNameList.add(fileName);
|
|
fileNameList.add(fileName);
|
|
- String imagePath = createBufferedImageFile(qrCodeImage, fileName, "png");
|
|
|
|
UploadFilePo file = new UploadFilePo();
|
|
UploadFilePo file = new UploadFilePo();
|
|
- file.setFileUrl(imagePath);
|
|
|
|
|
|
+ file.setFileUrl(qrCodeLink);
|
|
file.setFileName(authImage.getAuthParty());
|
|
file.setFileName(authImage.getAuthParty());
|
|
fileList.add(file);
|
|
fileList.add(file);
|
|
|
|
+// String imagePath = createBufferedImageFile(qrCodeImage, fileName, "png");
|
|
|
|
+ });
|
|
|
|
+ if (fileList.size() > 0) {
|
|
|
|
+ fileMap.put("机构二维码", fileList);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ // 设备二维码
|
|
|
|
+ authImageList.forEach(authImage->{
|
|
|
|
+ List<ProductImagePo> productList = fileMapper.getProductImageList(authImage.getAuthId());
|
|
|
|
+ ArrayList<UploadFilePo> list = new ArrayList<>();
|
|
|
|
+ productList.forEach(product->{
|
|
|
|
+ String qrCodeLink = wwwServer + "/product/auth/product-" + product.getProductId() + ".html";
|
|
|
|
+ UploadFilePo file = new UploadFilePo();
|
|
|
|
+ file.setFileUrl(qrCodeLink);
|
|
|
|
+ file.setFileName(product.getProductName() + "-" + product.getSnCode());
|
|
|
|
+ list.add(file);
|
|
|
|
+ });
|
|
|
|
+ if (list.size() > 0) {
|
|
|
|
+ fileMap.put(authImage.getAuthParty(), list);
|
|
|
|
+ }
|
|
});
|
|
});
|
|
}
|
|
}
|
|
- String fileName = 1 == type ? "授权牌" : 2 == type ? "设备二维码" : "机构二维码";
|
|
|
|
|
|
+ String fileName = 1 == type ? "机构授权牌" : 2 == type ? "设备授权牌" : 3 == type ? "机构二维码" : "设备二维码";
|
|
// 将授权牌压缩成zip文件
|
|
// 将授权牌压缩成zip文件
|
|
- String imageZipPath = uploadService.createImageZip(fileList);
|
|
|
|
-// download(request, response, imageZipPath, fileName + ".zip");
|
|
|
|
|
|
+ String imageZipPath = uploadService.createImageZip(fileMap, type);
|
|
|
|
+ download(request, response, imageZipPath, fileName + ".zip");
|
|
|
|
+ // 删除临时文件夹
|
|
|
|
+ String tempPath = imageZipPath.substring(0, imageZipPath.lastIndexOf("/"));
|
|
|
|
+ File tempFile = new File(tempPath);
|
|
|
|
+ boolean delete = tempFile.delete();
|
|
|
|
+ log.info("【图片压缩包】,删除图片压缩包文件夹:" + delete);
|
|
}
|
|
}
|
|
|
|
|
|
- private String createBufferedImageFile(BufferedImage qrCodeImage, String fileName, String prefix) {
|
|
|
|
- String filePath = "/mnt/newdatadrive/data/runtime/jar-instance/zplma/tempFile/";
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseJson downloadAuthData(String authIds, HttpServletResponse response) {
|
|
|
|
+ try {
|
|
|
|
+ // 导出表格名
|
|
|
|
+ String fileName = new String("机构信息.xlsx".getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1);
|
|
|
|
+ // 机构数据
|
|
|
|
+ List<AuthFormVo> authPartyList = authMapper.getAuthPartyList(authIds);
|
|
|
|
+ OutputStream outputStream = response.getOutputStream();
|
|
|
|
+ response.reset();
|
|
|
|
+ response.setHeader("Access-Control-Allow-Origin", "*");
|
|
|
|
+ response.setHeader("Access-Control-Allow-Credentials", "true");
|
|
|
|
+ response.setHeader("Content-disposition",
|
|
|
|
+ "attachment; filename="+fileName);
|
|
|
|
+// response.setContentType("application/vnd.ms-excel"); -- xls
|
|
|
|
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
|
+ return generateAuthExcel(authPartyList, outputStream);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ return ResponseJson.error("导出失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseJson downloadProductData(String authIds, HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
|
|
+ HashMap<AuthVo, List<ProductFormVo>> fileMap = new HashMap<>();
|
|
|
|
+ // 机构列表
|
|
|
|
+ List<AuthVo> authImageList = fileMapper.getAuthImageList(authIds);
|
|
|
|
+ // 设备列表
|
|
|
|
+ authImageList.forEach(authImage->{
|
|
|
|
+ final Integer[] maxParamNum = {0};
|
|
|
|
+ List<ProductFormVo> productList = authProductMapper.getAuthProductList(authImage.getAuthId());
|
|
|
|
+ productList.forEach(product->{
|
|
|
|
+ // 参数列表
|
|
|
|
+ List<ProductParamPo> paramList = authProductMapper.getParamsByProductId(product.getProductId());
|
|
|
|
+ product.setParamList(paramList);
|
|
|
|
+ if (paramList.size() > maxParamNum[0]) {
|
|
|
|
+ maxParamNum[0] = paramList.size();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ authImage.setMaxParamNum(maxParamNum[0]);
|
|
|
|
+ if (productList.size() > 0) {
|
|
|
|
+ fileMap.put(authImage, productList);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ // 将授权牌压缩成zip文件
|
|
|
|
+ String imageZipPath = createExcelZip(fileMap);
|
|
|
|
+ download(request, response, imageZipPath, "设备信息.zip");
|
|
|
|
+ // 删除临时文件夹
|
|
|
|
+ String tempPath = imageZipPath.substring(0, imageZipPath.lastIndexOf("/"));
|
|
|
|
+ File tempFile = new File(tempPath);
|
|
|
|
+ boolean delete = tempFile.delete();
|
|
|
|
+ log.info("【图片压缩包】,删除图片压缩包文件夹:" + delete);
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private String createExcelZip(HashMap<AuthVo, List<ProductFormVo>> authMap) throws FileNotFoundException {
|
|
|
|
+ String randomStr = UUID.randomUUID().toString();
|
|
|
|
+ String filePath = "/mnt/newdatadrive/data/runtime/jar-instance/zplma/tempImage/";
|
|
if ("dev".equals(active)){
|
|
if ("dev".equals(active)){
|
|
- filePath = "D:\\WorkSpace\\file\\tempImport\\";
|
|
|
|
|
|
+ filePath = "D:\\uploadZip\\";
|
|
}
|
|
}
|
|
- filePath = filePath + fileName + "." + prefix;
|
|
|
|
- File file = new File(filePath);
|
|
|
|
|
|
+ // 压缩文件夹上层临时文件夹路径
|
|
|
|
+ String tempPath = filePath + randomStr;
|
|
|
|
+ // 压缩文件夹路径
|
|
|
|
+ String basePath = "";
|
|
|
|
+ // 生成唯一临时文件夹
|
|
|
|
+ filePath += randomStr + "/";
|
|
|
|
+ // 在临时文件夹中生成要压缩的基础文件夹
|
|
|
|
+ String baseDirName = "设备信息";
|
|
|
|
+ filePath += baseDirName;
|
|
|
|
+ basePath = filePath;
|
|
|
|
+ File fileDir = new File(filePath);
|
|
|
|
+ if (!fileDir.exists()) {
|
|
|
|
+ fileDir.mkdirs();
|
|
|
|
+ }
|
|
|
|
+ // 往基础文件夹中填充相应数据
|
|
|
|
+ for (Map.Entry<AuthVo, List<ProductFormVo>> entry : authMap.entrySet()) {
|
|
|
|
+ AuthVo auth = entry.getKey();
|
|
|
|
+ List<ProductFormVo> productList = entry.getValue();
|
|
|
|
+ generateProductExcel(filePath, auth, productList);
|
|
|
|
+ }
|
|
|
|
+ // 将文件夹转为压缩文件
|
|
|
|
+ String zipPath = tempPath + "/" + baseDirName + ".zip";
|
|
|
|
+ FileOutputStream zipOut = new FileOutputStream(zipPath);
|
|
|
|
+ FileIOUtils.zipFolder(basePath, zipOut, true);
|
|
|
|
+ return zipPath;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void generateProductExcel(String tempFilePath, AuthVo authParty, List<ProductFormVo> productList) {
|
|
|
|
+ String fileName = authParty.getAuthParty();
|
|
|
|
+ String filePath = tempFilePath + "/" + fileName + ".xlsx";
|
|
|
|
+ try {
|
|
|
|
+ FileOutputStream outputStream = new FileOutputStream(filePath);
|
|
|
|
+ XSSFWorkbook workbook = new XSSFWorkbook();
|
|
|
|
+ // 创建设备工作表
|
|
|
|
+ XSSFSheet productSheet = workbook.createSheet("设备信息");
|
|
|
|
+ // sheet样式定义
|
|
|
|
+ XSSFCellStyle topCellStyle = PoiUtils.getXSSFTopCellStyle(workbook);
|
|
|
|
+ XSSFCellStyle customCellStyle = PoiUtils.getXSSFCustomCellStyle(workbook);
|
|
|
|
+ // 创建列头行
|
|
|
|
+ XSSFRow authTopRow = productSheet.createRow(0);
|
|
|
|
+ // 添加列头单元格(4个固定列+参数列表)
|
|
|
|
+ String[] rowName = {"设备名称", "设备SN码", "所属品牌", "购买渠道",
|
|
|
|
+ "参数名1", "参数值1", "参数名2", "参数值2", "参数名3", "参数值3", "参数名4", "参数值4", "参数名5",
|
|
|
|
+ "参数值5", "参数名6", "参数值6", "参数名7", "参数值7", "参数名8", "参数值8", "参数名9", "参数值9",
|
|
|
|
+ "参数名10", "参数值10", "参数名11", "参数值11", "参数名12", "参数值12"};
|
|
|
|
+ for (int i = 0; i < 4 + (0 == authParty.getMaxParamNum() ? 4 : authParty.getMaxParamNum()) * 2; i++) {
|
|
|
|
+ XSSFCell authTopRowCell = authTopRow.createCell(i);
|
|
|
|
+ authTopRowCell.setCellType(CellType.valueOf("STRING"));
|
|
|
|
+ XSSFRichTextString columnText = new XSSFRichTextString(rowName[i]);
|
|
|
|
+ authTopRowCell.setCellValue(columnText);
|
|
|
|
+ authTopRowCell.setCellStyle(topCellStyle);
|
|
|
|
+ }
|
|
|
|
+ // 行索引
|
|
|
|
+ AtomicInteger productRowNum = new AtomicInteger(1);
|
|
|
|
+ productList.forEach(product->{
|
|
|
|
+ // 创建设备行
|
|
|
|
+ XSSFRow productRow = productSheet.createRow(productRowNum.get());
|
|
|
|
+ // 参数列表
|
|
|
|
+ List<ProductParamPo> paramList = product.getParamList();
|
|
|
|
+ // 组装设备数据
|
|
|
|
+ List<String> productData = new ArrayList<>();
|
|
|
|
+ productData.add(product.getProductName());
|
|
|
|
+ productData.add(product.getSnCode());
|
|
|
|
+ productData.add(product.getBrandName());
|
|
|
|
+ productData.add(product.getPurchaseWay());
|
|
|
|
+ paramList.forEach(param -> {
|
|
|
|
+ productData.add(param.getParamName());
|
|
|
|
+ productData.add(param.getParamContent());
|
|
|
|
+ });
|
|
|
|
+ for (int j = 0; j < 4 + paramList.size() * 2; j++) {
|
|
|
|
+ XSSFCell productCell = productRow.createCell(j);
|
|
|
|
+ productCell.setCellType(CellType.valueOf("STRING"));
|
|
|
|
+ XSSFRichTextString productCellValue = new XSSFRichTextString(productData.get(j));
|
|
|
|
+ productCell.setCellValue(productCellValue);
|
|
|
|
+ productCell.setCellStyle(customCellStyle);
|
|
|
|
+ }
|
|
|
|
+ productRowNum.getAndIncrement();
|
|
|
|
+
|
|
|
|
+ });
|
|
|
|
+ // 让列宽随着导出的列长自动适应
|
|
|
|
+ for (int colNum = 0; colNum < rowName.length; colNum++) {
|
|
|
|
+ int productColumnWidth = productSheet.getColumnWidth(colNum) / 256;
|
|
|
|
+ for (int rowNum = 0; rowNum < productSheet.getLastRowNum(); rowNum++) {
|
|
|
|
+ XSSFRow currentRow;
|
|
|
|
+ // 当前行未被使用过
|
|
|
|
+ if (productSheet.getRow(rowNum) == null) {
|
|
|
|
+ currentRow = productSheet.createRow(rowNum);
|
|
|
|
+ } else {
|
|
|
|
+ currentRow = productSheet.getRow(rowNum);
|
|
|
|
+ }
|
|
|
|
+ if (currentRow.getCell(colNum) != null) {
|
|
|
|
+ XSSFCell currentCell = currentRow.getCell(colNum);
|
|
|
|
+ if (currentCell.getCellTypeEnum().equals(CellType.valueOf("STRING"))) {
|
|
|
|
+ int length = currentCell.getStringCellValue()
|
|
|
|
+ .getBytes().length;
|
|
|
|
+ if (productColumnWidth < length) {
|
|
|
|
+ productColumnWidth = length;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ productSheet.setColumnWidth(colNum, (productColumnWidth + 4) * 256);
|
|
|
|
+ }
|
|
|
|
+ workbook.write(outputStream);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private ResponseJson generateAuthExcel(List<AuthFormVo> authPartyList, OutputStream outputStream) {
|
|
try {
|
|
try {
|
|
- ImageIO.write(qrCodeImage, prefix, file);
|
|
|
|
|
|
+ XSSFWorkbook workbook = new XSSFWorkbook();
|
|
|
|
+ // 创建机构工作表
|
|
|
|
+ XSSFSheet authPartySheet = workbook.createSheet("授权机构");
|
|
|
|
+ // sheet样式定义
|
|
|
|
+ XSSFCellStyle topCellStyle = PoiUtils.getXSSFTopCellStyle(workbook);
|
|
|
|
+ XSSFCellStyle customCellStyle = PoiUtils.getXSSFCustomCellStyle(workbook);
|
|
|
|
+ // 创建列头行
|
|
|
|
+ XSSFRow authTopRow = authPartySheet.createRow(0);
|
|
|
|
+ // 添加列头单元格
|
|
|
|
+ String[] rowName = {"机构名称(必填)", "所在地区(必填)", "详细地址(必填)", "经纬度(必填)",
|
|
|
|
+ "联系电话(必填)", "认证编号(选填)", "认证日期(选填)", "员工人数(必填)", "店铺备注(选填)"};
|
|
|
|
+ for (int i = 0; i < rowName.length; i++) {
|
|
|
|
+ XSSFCell authTopRowCell = authTopRow.createCell(i);
|
|
|
|
+ authTopRowCell.setCellType(CellType.valueOf("STRING"));
|
|
|
|
+ XSSFRichTextString columnText = new XSSFRichTextString(rowName[i]);
|
|
|
|
+ authTopRowCell.setCellValue(columnText);
|
|
|
|
+ authTopRowCell.setCellStyle(topCellStyle);
|
|
|
|
+ }
|
|
|
|
+ // 行索引
|
|
|
|
+ AtomicInteger authPartyRowNum = new AtomicInteger(1);
|
|
|
|
+
|
|
|
|
+ authPartyList.forEach(authParty -> {
|
|
|
|
+ // 创建机构行
|
|
|
|
+ XSSFRow authRow = authPartySheet.createRow(authPartyRowNum.get());
|
|
|
|
+ // 组装机构数据
|
|
|
|
+ List<String> authData = new ArrayList<>();
|
|
|
|
+ authData.add(authParty.getAuthParty());
|
|
|
|
+ authData.add(authParty.getArea());
|
|
|
|
+ authData.add(authParty.getAddress());
|
|
|
|
+ authData.add(authParty.getLngAndLat());
|
|
|
|
+ authData.add(authParty.getMobile());
|
|
|
|
+ authData.add(authParty.getAuthCode());
|
|
|
|
+ SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd");
|
|
|
|
+ Date authDate = authParty.getAuthDate();
|
|
|
|
+ authData.add(format.format(authDate));
|
|
|
|
+ authData.add(authParty.getEmpNum().toString());
|
|
|
|
+ authData.add(authParty.getRemarks());
|
|
|
|
+ for (int j = 0; j < authData.size(); j++) {
|
|
|
|
+ XSSFCell authCell = authRow.createCell(j);
|
|
|
|
+ authCell.setCellStyle(customCellStyle);
|
|
|
|
+ if (j == 7) {
|
|
|
|
+ authCell.setCellType(CellType.NUMERIC);
|
|
|
|
+ authCell.setCellValue(Integer.parseInt(authData.get(j)));
|
|
|
|
+ } else {
|
|
|
|
+ authCell.setCellType(CellType.valueOf("STRING"));
|
|
|
|
+ XSSFRichTextString authCellValue = new XSSFRichTextString(authData.get(j));
|
|
|
|
+ authCell.setCellValue(authCellValue);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ authPartyRowNum.getAndIncrement();
|
|
|
|
+ });
|
|
|
|
+ // 让列宽随着导出的列长自动适应
|
|
|
|
+ for (int colNum = 0; colNum < rowName.length; colNum++) {
|
|
|
|
+ int productColumnWidth = authPartySheet.getColumnWidth(colNum) / 256;
|
|
|
|
+ for (int rowNum = 0; rowNum < authPartySheet.getLastRowNum(); rowNum++) {
|
|
|
|
+ XSSFRow currentRow;
|
|
|
|
+ // 当前行未被使用过
|
|
|
|
+ if (authPartySheet.getRow(rowNum) == null) {
|
|
|
|
+ currentRow = authPartySheet.createRow(rowNum);
|
|
|
|
+ } else {
|
|
|
|
+ currentRow = authPartySheet.getRow(rowNum);
|
|
|
|
+ }
|
|
|
|
+ if (currentRow.getCell(colNum) != null) {
|
|
|
|
+ XSSFCell currentCell = currentRow.getCell(colNum);
|
|
|
|
+ if (currentCell.getCellTypeEnum().equals(CellType.valueOf("STRING"))) {
|
|
|
|
+ int length = currentCell.getStringCellValue()
|
|
|
|
+ .getBytes().length;
|
|
|
|
+ if (productColumnWidth < length) {
|
|
|
|
+ productColumnWidth = length;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ authPartySheet.setColumnWidth(colNum, (productColumnWidth + 4) * 256);
|
|
|
|
+ }
|
|
|
|
+ outputStream.flush();
|
|
|
|
+ workbook.write(outputStream);
|
|
|
|
+ outputStream.close();
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
|
+ return ResponseJson.error("导出失败");
|
|
}
|
|
}
|
|
- return filePath;
|
|
|
|
|
|
+ return null;
|
|
}
|
|
}
|
|
|
|
|
|
public void download(HttpServletRequest request, HttpServletResponse response, String filePath, String fileName) throws IOException {
|
|
public void download(HttpServletRequest request, HttpServletResponse response, String filePath, String fileName) throws IOException {
|