Jelajahi Sumber

1.7.1-机构导出

Aslee 2 tahun lalu
induk
melakukan
c21edf5ed3

+ 7 - 6
src/main/java/com/caimei/service/auth/impl/AuthServiceImpl.java

@@ -15,6 +15,7 @@ import com.caimei.service.auth.UploadService;
 import com.caimei.utils.Base64Util;
 import com.caimei.utils.ExcelOperateUtil;
 import com.caimei.utils.ImageUtils;
+import com.caimei.utils.PoiUtils;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import com.github.tobato.fastdfs.service.FastFileStorageClient;
@@ -513,7 +514,7 @@ public class AuthServiceImpl implements AuthService {
             response.setHeader("Access-Control-Allow-Credentials", "true");
             response.setHeader("Content-disposition",
                     "attachment; filename="+fileName);
-//            response.setContentType("application/vnd.ms-excel");
+//            response.setContentType("application/vnd.ms-excel"); -- xls
             response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
             return exportData(authPartyList, outputStream);
         } catch (Exception e) {
@@ -733,8 +734,8 @@ public class AuthServiceImpl implements AuthService {
             // 创建机构工作表
             XSSFSheet authPartySheet = workbook.createSheet("授权机构");
             // sheet样式定义
-//            HSSFCellStyle topCellStyle = this.getTopCellStyle(workbook);
-//            HSSFCellStyle customCellStyle = this.getCustomCellStyle(workbook);
+            XSSFCellStyle topCellStyle = PoiUtils.getXSSFTopCellStyle(workbook);
+            XSSFCellStyle customCellStyle = PoiUtils.getXSSFCustomCellStyle(workbook);
             // 创建列头行
             XSSFRow authTopRow = authPartySheet.createRow(0);
             // 添加列头单元格(5个固定列+参数列表)
@@ -745,7 +746,7 @@ public class AuthServiceImpl implements AuthService {
                 authTopRowCell.setCellType(CellType.valueOf("STRING"));
                 XSSFRichTextString columnText = new XSSFRichTextString(rowName[i]);
                 authTopRowCell.setCellValue(columnText);
-//                productTopRowCell.setCellStyle(topCellStyle);
+                authTopRowCell.setCellStyle(topCellStyle);
             }
             // 行索引
             AtomicInteger authPartyRowNum = new AtomicInteger(1);
@@ -768,7 +769,7 @@ public class AuthServiceImpl implements AuthService {
                 authData.add(authParty.getRemarks());
                 for (int j = 0; j < authData.size(); j++) {
                     XSSFCell authCell = authRow.createCell(j);
-//                    authCell.setCellStyle(customCellStyle);
+                    authCell.setCellStyle(customCellStyle);
                     if (j == 7) {
                         authCell.setCellType(CellType.NUMERIC);
                         authCell.setCellValue(Integer.parseInt(authData.get(j)));
@@ -811,7 +812,7 @@ public class AuthServiceImpl implements AuthService {
             e.printStackTrace();
             return ResponseJson.error("导出失败");
         }
-        return ResponseJson.success("导出成功");
+        return null;
     }
 
     private String uploadImage(String filePath) throws IOException {

+ 1 - 1
src/main/java/com/caimei/service/auth/impl/DownloadServiceImpl.java

@@ -115,7 +115,7 @@ public class DownloadServiceImpl implements DownloadService {
         String fileName = 1 == type ? "授权牌" : 2 == type ? "设备二维码" : "机构二维码";
         // 将授权牌压缩成zip文件
         String imageZipPath = uploadService.createImageZip(fileList);
-        download(request, response, imageZipPath, fileName + ".zip");
+//        download(request, response, imageZipPath, fileName + ".zip");
     }
 
     private String createBufferedImageFile(BufferedImage qrCodeImage, String fileName, String prefix) {

+ 29 - 7
src/main/java/com/caimei/service/auth/impl/UploadServiceImpl.java

@@ -13,6 +13,7 @@ import org.springframework.web.multipart.MultipartFile;
 import java.io.*;
 import java.net.HttpURLConnection;
 import java.net.URL;
+import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.UUID;
@@ -89,11 +90,20 @@ public class UploadServiceImpl implements UploadService {
         if ("dev".equals(active)){
             filePath = "D:\\uploadZip\\";
         }
-        filePath += randomStr + ".zip";
-        File zipFile = new File(filePath);
+//        filePath += randomStr + ".zip";
+        File zipFile = new File(filePath + randomStr + ".zip");
+        String actualFilePath = filePath + "机构二维码/";
+        File actualFile = new File(actualFilePath);
+        if (!actualFile.exists()) {
+            actualFile.mkdirs();
+        }
+
         log.info("【图片上传】>>>>>>>>>>>>>>>>图片压缩包临时路径:" + filePath);
         ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFile));
         BufferedOutputStream bo = new BufferedOutputStream(out);
+
+
+
         for (UploadFilePo file : fileList) {
             String fileUrl = file.getFileUrl();
             File image = null;
@@ -105,7 +115,7 @@ public class UploadServiceImpl implements UploadService {
             } else {
                 image = new File(fileUrl);
             }
-            out.putNextEntry(new ZipEntry(image.getName()));
+            /*out.putNextEntry(new ZipEntry(image.getName()));
             FileInputStream in = new FileInputStream(image);
             BufferedInputStream bi = new BufferedInputStream(in);
             int b;
@@ -114,11 +124,22 @@ public class UploadServiceImpl implements UploadService {
             }
             bo.flush();
             bi.close();
-            in.close();
-            image.delete();
+            in.close();*/
+//            image.delete();
+        }
+        /*out.putNextEntry(new ZipEntry(actualFile.getName()));
+        FileInputStream in = new FileInputStream(actualFile);
+        BufferedInputStream bi = new BufferedInputStream(in);
+        int b;
+        while ((b = bi.read()) != -1) {
+            bo.write(b);
         }
+        bo.flush();
+        bi.close();
+        in.close();
+
         bo.close();
-        out.close();
+        out.close();*/
         return filePath;
     }
 
@@ -141,7 +162,8 @@ public class UploadServiceImpl implements UploadService {
      * inputStream 转 File
      */
     public static File inputStreamToFile(InputStream ins, String name) throws Exception{
-        File file = new File(System.getProperty("java.io.tmpdir") + File.separator + name);
+//        File file = new File(System.getProperty("java.io.tmpdir") + File.separator + name);
+        File file = new File("D:\\uploadZip\\机构二维码\\" + File.separator + name);
         if (file.exists()) {
             return file;
         }

+ 9 - 9
src/main/java/com/caimei/utils/PoiUtils.java

@@ -21,7 +21,7 @@ public class PoiUtils {
     /**
      * XLS列头单元格样式
      */
-    private HSSFCellStyle getHSSFTopCellStyle(HSSFWorkbook workbook) {
+    public static HSSFCellStyle getHSSFTopCellStyle(HSSFWorkbook workbook) {
 
         // 设置字体
         HSSFFont font = workbook.createFont();
@@ -30,7 +30,7 @@ public class PoiUtils {
         // 字体加粗
         font.setBold(true);
         // 设置字体名字
-        font.setFontName("Courier New");
+        font.setFontName("宋体");
         // 设置样式;
         HSSFCellStyle style = workbook.createCellStyle();
         // 设置底边框;
@@ -64,7 +64,7 @@ public class PoiUtils {
     /**
      * XLSX列头单元格样式
      */
-    private XSSFCellStyle getXSSFTopCellStyle(XSSFWorkbook workbook) {
+    public static XSSFCellStyle getXSSFTopCellStyle(XSSFWorkbook workbook) {
 
         // 设置字体
         XSSFFont font = workbook.createFont();
@@ -73,7 +73,7 @@ public class PoiUtils {
         // 字体加粗
         font.setBold(true);
         // 设置字体名字
-        font.setFontName("Courier New");
+        font.setFontName("宋体");
         // 设置样式;
         XSSFCellStyle style = workbook.createCellStyle();
         // 设置底边框;
@@ -107,7 +107,7 @@ public class PoiUtils {
     /**
      * XLS列数据信息单元格样式
      */
-    private HSSFCellStyle getHSSFCustomCellStyle(HSSFWorkbook workbook) {
+    public static HSSFCellStyle getHSSFCustomCellStyle(HSSFWorkbook workbook) {
         // 设置字体
         HSSFFont font = workbook.createFont();
         // 设置字体大小
@@ -115,7 +115,7 @@ public class PoiUtils {
         // 字体加粗
         // font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
         // 设置字体名字
-        font.setFontName("Courier New");
+        font.setFontName("宋体");
         // 设置样式;
         HSSFCellStyle style = workbook.createCellStyle();
         // 设置底边框;
@@ -148,15 +148,15 @@ public class PoiUtils {
     /**
      * XLSX列数据信息单元格样式
      */
-    private XSSFCellStyle getXSSFCustomCellStyle(XSSFWorkbook workbook) {
+    public static XSSFCellStyle getXSSFCustomCellStyle(XSSFWorkbook workbook) {
         // 设置字体
         XSSFFont font = workbook.createFont();
         // 设置字体大小
-        // font.setFontHeightInPoints((short)10);
+         font.setFontHeightInPoints((short)11);
         // 字体加粗
         // font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
         // 设置字体名字
-        font.setFontName("Courier New");
+        font.setFontName("宋体");
         // 设置样式;
         XSSFCellStyle style = workbook.createCellStyle();
         // 设置底边框;