Преглед изворни кода

授权牌/二维码下载,设备导出

Aslee пре 2 година
родитељ
комит
faec9d2628

+ 0 - 11
src/main/java/com/caimei/controller/admin/auth/AuthApi.java

@@ -230,17 +230,6 @@ public class AuthApi {
         return authService.importDataByExcel(file, authUserId, createBy);
     }
 
-
-    @ApiOperation("excel导出")
-    @ApiImplicitParam(name = "authUserId", required = true, value = "供应商用户id")
-    @GetMapping("/export/excel")
-    public ResponseJson exportDataByExcel(Integer authUserId, HttpServletResponse response) {
-        if (null == authUserId) {
-            return ResponseJson.error("参数异常,请输入供应商id");
-        }
-        return authService.exportDataByExcel(authUserId, response);
-    }
-
     @ApiOperation("ldm门店图/备注导入")
     @ApiImplicitParam(name = "authUserId", required = true, value = "供应商用户id")
     @GetMapping("/ldm/image/import")

+ 1 - 1
src/main/java/com/caimei/controller/admin/auth/AuthProductApi.java

@@ -265,7 +265,7 @@ public class AuthProductApi {
     }
 
     @ApiOperation("更改查看标记")
-    @ApiImplicitParam(name = "authId", required = true, value = "productId")
+    @ApiImplicitParam(name = "productId", required = true, value = "productId")
     @PostMapping("/check")
     public ResponseJson checkAuthProduct(Integer productId) {
         return authProductService.checkAuthProduct(productId);

+ 31 - 6
src/main/java/com/caimei/controller/admin/auth/DownloadApi.java

@@ -1,5 +1,6 @@
 package com.caimei.controller.admin.auth;
 
+import com.caimei.model.ResponseJson;
 import com.caimei.service.auth.DownloadService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
@@ -7,6 +8,7 @@ import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Value;
@@ -45,14 +47,37 @@ public class DownloadApi {
         }
     }
 
-
-    @ApiOperation("一键下载授权牌/设备二维码/机构二维码")
+    @ApiOperation("一键下载机构授权牌/设备授权牌/机构二维码/设备二维码")
     @ApiImplicitParams({
-            @ApiImplicitParam(name = "authUserId", required = true, value = "供应商用户id"),
-            @ApiImplicitParam(name = "type", required = true, value = "1授权牌,2设备二维码,3机构二维码")
+            @ApiImplicitParam(name = "authIds", required = false, value = "勾选中的机构id,以,隔开"),
+            @ApiImplicitParam(name = "type", required = false, value = "1机构授权牌,2.设备授权牌,3机构二维码,4设备二维码")
     })
     @GetMapping("/shop/image")
-    public void downloadImage(Integer authUserId, Integer type, HttpServletRequest request, HttpServletResponse response) throws Exception {
-        downloadService.downloadShopImage(authUserId, type, request, response);
+    public void downloadImage(String authIds, Integer type, HttpServletRequest request, HttpServletResponse response) throws Exception {
+        if (com.aliyuncs.utils.StringUtils.isEmpty(authIds) || null == type) {
+            return;
+        }
+        downloadService.downloadShopImage(authIds, type, request, response);
+    }
+
+    @ApiOperation("excel导出机构信息")
+    @ApiImplicitParam(name = "authIds", required = true, value = "机构id,以,隔开")
+    @GetMapping("/auth/excel")
+    public ResponseJson downloadAuthData(String authIds, HttpServletResponse response) {
+        if (StringUtils.isEmpty(authIds)) {
+            return ResponseJson.error("机构id不能为空");
+        }
+        return downloadService.downloadAuthData(authIds, response);
     }
+
+    @ApiOperation("excel导出设备信息")
+    @ApiImplicitParam(name = "authIds", required = true, value = "机构id,以,隔开")
+    @GetMapping("/product/excel")
+    public ResponseJson downloadProductData(String authIds, HttpServletRequest request, HttpServletResponse response) throws IOException {
+        if (StringUtils.isEmpty(authIds)) {
+            return ResponseJson.error("机构id不能为空");
+        }
+        return downloadService.downloadProductData(authIds, request, response);
+    }
+
 }

+ 1 - 1
src/main/java/com/caimei/mapper/cmMapper/AuthMapper.java

@@ -41,7 +41,7 @@ public interface AuthMapper {
 
     Integer getAuthIdByAuthParty(@Param("authParty") String authParty, @Param("authUserId") Integer authUserId);
 
-    List<AuthFormVo> getAuthPartyList(Integer authUserId);
+    List<AuthFormVo> getAuthPartyList(@Param("authIds") String authIds);
 
     void deleteBanner(Integer authId);
 

+ 2 - 2
src/main/java/com/caimei/mapper/cmMapper/FileMapper.java

@@ -45,9 +45,9 @@ public interface FileMapper {
 
     void deleteCourseFileByFileId(Integer fileId);
 
-    List<ProductImagePo> getProductImageList(Integer authUserId);
+    List<ProductImagePo> getProductImageList(@Param("authId") Integer authId);
 
-    List<AuthVo> getAuthImageList(Integer authUserId);
+    List<AuthVo> getAuthImageList(@Param("authIds") String authIds);
 
     FilePo getFileForm(Integer fileId);
 

+ 5 - 0
src/main/java/com/caimei/model/po/ProductImagePo.java

@@ -29,4 +29,9 @@ public class ProductImagePo {
      * sn码
      */
     private String snCode;
+
+    /**
+     * 设备名称
+     */
+    private String productName;
 }

+ 58 - 16
src/main/java/com/caimei/model/vo/AuthVo.java

@@ -12,52 +12,89 @@ import java.util.Date;
  */
 @Data
 public class AuthVo {
-    @ApiModelProperty("授权id")
+    /**
+     * 授权id
+     */
     private Integer authId;
 
-    @ApiModelProperty("供应商用户id")
+    /**
+     * 供应商用户id
+     */
     private Integer authUserId;
 
-    @ApiModelProperty("授权机构")
+    /**
+     * 授权机构
+     */
     private String authParty;
 
-    @ApiModelProperty("机构用户手机号")
+    /**
+     * 机构授权牌
+     */
+    private String authImage;
+
+    /**
+     * 机构用户手机号
+     */
     private String mobile;
 
-    @ApiModelProperty("上线状态:0已下线,1已上线,2待上线")
+    /**
+     * 上线状态:0已下线,1已上线,2待上线
+     */
     private Integer status;
 
-    @ApiModelProperty("审核状态:0审核未通过,1审核通过,2待审核")
+    /**
+     * 审核状态:0审核未通过,1审核通过,2待审核
+     */
     private Integer auditStatus;
 
-    @ApiModelProperty("供应商审核状态:0审核未通过,1审核通过,2待审核")
+    /**
+     * 供应商审核状态:0审核未通过,1审核通过,2待审核
+     */
     private Integer shopAuditStatus;
 
-    @ApiModelProperty("寄送状态:0未寄送,1已寄送")
+    /**
+     * 寄送状态:0未寄送,1已寄送
+     */
     private Integer sendStatus;
 
-    @ApiModelProperty("创建时间")
+    /**
+     * 创建时间
+     */
     private Date createTime;
 
-    @ApiModelProperty("创建人")
+    /**
+     * 创建人
+     */
     private String createBy;
 
-    @ApiModelProperty("下级审核状态,0未完成审核,1已完成审核")
+    /**
+     * 下级审核状态,0未完成审核,1已完成审核
+     */
     private Integer lowerAuditStatus;
 
-    @ApiModelProperty("下级待审核数量")
+    /**
+     * 下级待审核数量
+     */
     private Integer waitAuditNum;
 
-    @ApiModelProperty("供应商审核下级待审核数量")
+    /**
+     * 供应商审核下级待审核数量
+     */
     private Integer shopWaitAuditNum;
 
-    @ApiModelProperty("审核人")
+    /**
+     * 审核人
+     */
     private String auditBy;
 
-    @ApiModelProperty("审核时间")
+    /**
+     * 审核时间
+     */
     private Date auditTime;
 
-    @ApiModelProperty("审核不通过原因")
+    /**
+     * 审核不通过原因
+     */
     private String invalidReason;
 
     /**
@@ -74,4 +111,9 @@ public class AuthVo {
      * 是否查看过:1是,0否
      */
     private Integer checkFlag;
+
+    /**
+     *  设备列表最大参数数量
+     */
+    private Integer maxParamNum;
 }

+ 0 - 9
src/main/java/com/caimei/service/auth/AuthService.java

@@ -83,15 +83,6 @@ public interface AuthService {
      */
     ResponseJson importDataByExcel(MultipartFile file, Integer authUserId, Integer createBy);
 
-
-    /**
-     * 导出授权机构和商品数据
-     * @param authUserId    供应商用户id
-     * @param response
-     * @return
-     */
-    ResponseJson exportDataByExcel(Integer authUserId, HttpServletResponse response);
-
     /**
      * 授权机构回显数据
      * @param authId    机构id

+ 14 - 2
src/main/java/com/caimei/service/auth/DownloadService.java

@@ -1,5 +1,7 @@
 package com.caimei.service.auth;
 
+import com.caimei.model.ResponseJson;
+
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
@@ -22,8 +24,18 @@ public interface DownloadService {
 
     /**
      * 一键下载授权牌,二维码
-     * @param authUserId
+     * @param authIds
      * @param type
      */
-    void downloadShopImage(Integer authUserId, Integer type, HttpServletRequest request, HttpServletResponse response) throws Exception;
+    void downloadShopImage(String authIds, Integer type, HttpServletRequest request, HttpServletResponse response) throws Exception;
+
+    /**
+     * 导出授权机构数据
+     * @param authIds
+     * @param response
+     * @return
+     */
+    ResponseJson downloadAuthData(String authIds, HttpServletResponse response);
+
+    ResponseJson downloadProductData(String authIds, HttpServletRequest request, HttpServletResponse response) throws IOException;
 }

+ 4 - 2
src/main/java/com/caimei/service/auth/UploadService.java

@@ -6,6 +6,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 import java.io.IOException;
 import java.util.List;
+import java.util.Map;
 
 /**
  * Description
@@ -37,9 +38,10 @@ public interface UploadService {
 
     /**
      * 将多张图片压缩
-     * @param fileList
+     * @param fileMap
+     * @param type
      * @return
      * @throws Exception
      */
-    String createImageZip(List<UploadFilePo> fileList) throws  Exception;
+    String createImageZip(Map<String,List<UploadFilePo>> fileMap, Integer type) throws  Exception;
 }

+ 0 - 137
src/main/java/com/caimei/service/auth/impl/AuthServiceImpl.java

@@ -501,28 +501,6 @@ public class AuthServiceImpl implements AuthService {
         return null;
     }
 
-    @Override
-    public ResponseJson exportDataByExcel(Integer authUserId, HttpServletResponse response) {
-        try {
-            // 导出表格名
-            String fileName = new String("机构信息.xlsx".getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1);
-            // 机构数据
-            List<AuthFormVo> authPartyList = authMapper.getAuthPartyList(authUserId);
-            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 exportData(authPartyList, outputStream);
-        } catch (Exception e) {
-            e.printStackTrace();
-            return ResponseJson.error("导出失败");
-        }
-    }
-
 
     private ResponseJson saveExcelData(String filePath, Integer authUserId, Integer createBy) {
         //判断是否为excel类型文件
@@ -728,119 +706,4 @@ public class AuthServiceImpl implements AuthService {
         return ResponseJson.success("导入成功");
     }
 
-    private ResponseJson exportData(List<AuthFormVo> authPartyList, OutputStream outputStream) {
-        try {
-            XSSFWorkbook workbook = new XSSFWorkbook();
-            // 创建机构工作表
-            XSSFSheet authPartySheet = workbook.createSheet("授权机构");
-            // sheet样式定义
-            XSSFCellStyle topCellStyle = PoiUtils.getXSSFTopCellStyle(workbook);
-            XSSFCellStyle customCellStyle = PoiUtils.getXSSFCustomCellStyle(workbook);
-            // 创建列头行
-            XSSFRow authTopRow = authPartySheet.createRow(0);
-            // 添加列头单元格(5个固定列+参数列表)
-            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) {
-            e.printStackTrace();
-            return ResponseJson.error("导出失败");
-        }
-        return null;
-    }
-
-    private String uploadImage(String filePath) throws IOException {
-        // 临时图片
-        File tempFile = new File(filePath);
-        log.info("【图片上传】>>>>>>>>>>>>>>>>图片临时路径:" + filePath);
-        String imageUrl = imageDomain + "/" + client.uploadFile(filePath);
-        return imageUrl;
-    }
-
-
-
-
-
-    public InputStream getImageStream(String url) {
-        try {
-            HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
-            connection.setReadTimeout(5000);
-            connection.setConnectTimeout(5000);
-            connection.setRequestMethod("GET");
-            if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
-                InputStream inputStream = connection.getInputStream();
-                return inputStream;
-            }
-        } catch (IOException e) {
-            System.out.println("获取网络图片出现异常,图片路径为:" + url);
-            e.printStackTrace();
-        }
-        return null;
-    }
 }

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

@@ -1,32 +1,39 @@
 package com.caimei.service.auth.impl;
 
 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.model.en.QrCodeSize;
+import com.caimei.model.ResponseJson;
 import com.caimei.model.po.ProductImagePo;
+import com.caimei.model.po.ProductParamPo;
 import com.caimei.model.po.UploadFilePo;
+import com.caimei.model.vo.AuthFormVo;
 import com.caimei.model.vo.AuthVo;
+import com.caimei.model.vo.ProductFormVo;
 import com.caimei.service.auth.DownloadService;
 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.PoiUtils;
 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.Value;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
-import javax.imageio.ImageIO;
 import javax.servlet.http.HttpServletRequest;
 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.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
@@ -41,6 +48,12 @@ public class DownloadServiceImpl implements DownloadService {
     @Resource
     private FileMapper fileMapper;
 
+    @Resource
+    private AuthMapper authMapper;
+
+    @Resource
+    private AuthProductMapper authProductMapper;
+
     private UploadService uploadService;
 
     @Value("${caimei.oldapi}")
@@ -64,40 +77,53 @@ public class DownloadServiceImpl implements DownloadService {
     }
 
     @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<>();
-        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) {
-            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);
                 }
             });
+            if (fileList.size() > 0) {
+                fileMap.put("机构授权牌", fileList);
+            }
         } 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<>();
             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();
                 int k = 1;
                 while (fileNameList.contains(fileName)) {
@@ -105,32 +131,298 @@ public class DownloadServiceImpl implements DownloadService {
                     k++;
                 }
                 fileNameList.add(fileName);
-                String imagePath = createBufferedImageFile(qrCodeImage, fileName, "png");
                 UploadFilePo file = new UploadFilePo();
-                file.setFileUrl(imagePath);
+                file.setFileUrl(qrCodeLink);
                 file.setFileName(authImage.getAuthParty());
                 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文件
-        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)){
-            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 {
-            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) {
             e.printStackTrace();
+            return ResponseJson.error("导出失败");
         }
-        return filePath;
+        return null;
     }
 
     public void download(HttpServletRequest request, HttpServletResponse response, String filePath, String fileName) throws IOException {

+ 131 - 55
src/main/java/com/caimei/service/auth/impl/UploadServiceImpl.java

@@ -2,23 +2,23 @@ package com.caimei.service.auth.impl;
 
 import com.alibaba.fastjson.JSONArray;
 import com.caimei.config.FastDfsClient;
+import com.caimei.model.en.QrCodeSize;
 import com.caimei.model.po.UploadFilePo;
 import com.caimei.service.auth.UploadService;
+import com.caimei.utils.FileIOUtils;
+import com.caimei.utils.ImageUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.imageio.ImageIO;
+import java.awt.image.BufferedImage;
 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;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipOutputStream;
+import java.util.*;
+import java.util.concurrent.atomic.AtomicReference;
 
 /**
  * Description
@@ -73,7 +73,9 @@ public class UploadServiceImpl implements UploadService {
             file.setFileName(imgRandomId);
             fileList.add(file);
         }
-        String imageZipPath = createImageZip(fileList);
+        HashMap<String, List<UploadFilePo>> map = new HashMap<>(1);
+        map.put("图片压缩包", fileList);
+        String imageZipPath = createImageZip(map, 5);
         // 上传zip
         String imageUrl = imageDomain + "/" + client.uploadFile(imageZipPath);
         // 删除临时图片
@@ -83,64 +85,138 @@ public class UploadServiceImpl implements UploadService {
         return imageUrl;
     }
 
+    /**
+     * 创建图片压缩包
+     * @param fileMap
+     * @param type      1机构授权牌,2设备授权牌,3机构二维码,4设备二维码,5资料库图片压缩包
+     * @return
+     * @throws Exception
+     */
     @Override
-    public String createImageZip(List<UploadFilePo> fileList) throws Exception {
+    public String createImageZip(Map<String,List<UploadFilePo>> fileMap, Integer type) throws Exception {
         String randomStr = UUID.randomUUID().toString();
         String filePath = "/mnt/newdatadrive/data/runtime/jar-instance/zplma/tempImage/";
         if ("dev".equals(active)){
             filePath = "D:\\uploadZip\\";
         }
-//        filePath += randomStr + ".zip";
-        File zipFile = new File(filePath + randomStr + ".zip");
-        String actualFilePath = filePath + "机构二维码/";
-        File actualFile = new File(actualFilePath);
-        if (!actualFile.exists()) {
-            actualFile.mkdirs();
+        // 压缩文件夹上层临时文件夹路径
+        String tempPath = filePath + randomStr;
+        // 压缩文件夹路径
+        String basePath = "";
+        // 生成唯一临时文件夹
+        filePath += randomStr + "/";
+        // 在临时文件夹中生成要压缩的基础文件夹
+        String baseDirName = "";
+        switch (type) {
+            case 1:
+                baseDirName = "机构授权牌";
+                break;
+            case 2:
+                baseDirName = "设备授权牌";
+                break;
+            case 3:
+                baseDirName = "机构二维码";
+                break;
+            case 4:
+                baseDirName = "设备二维码";
+                break;
+            case 5:
+                baseDirName = "图片包";
+                break;
+            default:
+                baseDirName = "";
         }
+//        basePath = filePath += baseDirName;
+        filePath += baseDirName;
+        basePath = filePath;
+        File baseDir = new File(basePath);
+        if (!baseDir.exists()) {
+            baseDir.mkdirs();
+        }
+        // 往基础文件夹中填充相应数据
+        if (1 == type) {
+            // 机构授权牌
+            List<UploadFilePo> fileList = fileMap.get("机构授权牌");
+            for (int i = 0; i < fileList.size(); i++) {
+                // 把机构授权牌链接转换为图片
+                UploadFilePo file = fileList.get(i);
+                String fileUrl = file.getFileUrl();
+                URL url = new URL(fileUrl);
+                InputStream inputStream = url.openStream();
+                BufferedImage authImage = ImageIO.read(inputStream);
+                String extName = fileUrl.substring(fileUrl.lastIndexOf(".") + 1);
+                String tempFilePath = filePath + "/" + file.getFileName() + "." + extName;
+                FileOutputStream outImgStream = new FileOutputStream(tempFilePath);
+                ImageIO.write(authImage, extName, outImgStream);
+                inputStream.close();
+                outImgStream.flush();
+                outImgStream.close();
+            }
+        } else if (2 == type) {
+            // 设备授权牌
+            for (Map.Entry<String, List<UploadFilePo>> entry : fileMap.entrySet()) {
+                String authParty = entry.getKey();
+                List<UploadFilePo> fileList = entry.getValue();
+                filePath = basePath + "/" + authParty;
+                File authDir = new File(filePath);
+                if (!authDir.exists()) {
+                    authDir.mkdirs();
+                }
+                for (int i = 0; i < fileList.size(); i++) {
+                    // 把设备授权牌链接转换为图片
+                    UploadFilePo file = fileList.get(i);
+                    String fileUrl = file.getFileUrl();
+                    URL url = new URL(fileUrl);
+                    InputStream inputStream = url.openStream();
+                    BufferedImage authImage = ImageIO.read(inputStream);
+                    String extName = fileUrl.substring(fileUrl.lastIndexOf(".") + 1);
+                    String tempFilePath = filePath + "/" + file.getFileName() + "." + extName;
+                    FileOutputStream outImgStream = new FileOutputStream(tempFilePath);
+                    ImageIO.write(authImage, extName, outImgStream);
+                    inputStream.close();
+                    outImgStream.flush();
+                    outImgStream.close();
+                }
 
-        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;
-            if (fileUrl.startsWith("http")) {
-                HttpURLConnection httpUrl = (HttpURLConnection) new URL(fileUrl).openConnection();
-                httpUrl.connect();
-                String prefix = fileUrl.substring(fileUrl.lastIndexOf("."));
-                image = inputStreamToFile(httpUrl.getInputStream(), file.getFileName() + "." + prefix);
-            } else {
-                image = new File(fileUrl);
             }
-            /*out.putNextEntry(new ZipEntry(image.getName()));
-            FileInputStream in = new FileInputStream(image);
-            BufferedInputStream bi = new BufferedInputStream(in);
-            int b;
-            while ((b = bi.read()) != -1) {
-                bo.write(b);
+        } else if (3 == type) {
+            // 机构二维码
+            List<UploadFilePo> fileList = fileMap.get("机构二维码");
+            for (int i = 0; i < fileList.size(); i++) {
+                // 把机构二维码链接转换为图片
+                UploadFilePo file = fileList.get(i);
+                String fileUrl = file.getFileUrl();
+                String fileName = file.getFileName();
+                BufferedImage qrCodeImage = ImageUtils.createQrCode(fileUrl, QrCodeSize.LARGE);
+                String tempFilePath = filePath + "/" + fileName;
+                ImageUtils.transferBufferdImage(qrCodeImage, tempFilePath, "png");
+            }
+        } else if (4 == type) {
+            // 设备二维码
+            for (Map.Entry<String, List<UploadFilePo>> entry : fileMap.entrySet()) {
+                String authParty = entry.getKey();
+                List<UploadFilePo> fileList = entry.getValue();
+                filePath = basePath + "/" + authParty;
+                File authDir = new File(filePath);
+                if (!authDir.exists()) {
+                    authDir.mkdirs();
+                }
+                for (int i = 0; i < fileList.size(); i++) {
+                    // 把设备授权牌链接转换为图片
+                    UploadFilePo file = fileList.get(i);
+                    String fileUrl = file.getFileUrl();
+                    String fileName = file.getFileName();
+                    BufferedImage qrCodeImage = ImageUtils.createQrCode(fileUrl, QrCodeSize.LARGE);
+                    String tempFilePath = filePath + "/" + fileName;
+                    ImageUtils.transferBufferdImage(qrCodeImage, tempFilePath, "png");
+                }
             }
-            bo.flush();
-            bi.close();
-            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();*/
-        return filePath;
+        // 将文件夹转为压缩文件
+        String zipPath = tempPath + "/" + baseDirName + ".zip";
+        FileOutputStream zipOut = new FileOutputStream(zipPath);
+        FileIOUtils.zipFolder(basePath, zipOut, true);
+        return zipPath;
     }
 
     @Override

+ 105 - 0
src/main/java/com/caimei/utils/FileIOUtils.java

@@ -0,0 +1,105 @@
+package com.caimei.utils;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+
+public class FileIOUtils {
+    /**
+     * ZIP压缩文件
+     */
+    public static void zipFile(File file, ZipOutputStream zipOut) {
+        try (FileInputStream in = new FileInputStream(file);
+             FileOutputStream out = new FileOutputStream(new File("F:\\temp\\temp-file\\aaa.zip"));) {
+            zipOut = new ZipOutputStream(out);
+            ZipEntry entry = new ZipEntry(file.getName());
+            zipOut.putNextEntry(entry);
+            //向压缩文件中输出数据
+            int len;
+            byte[] buffer = new byte[1024];
+            while ((len = in.read(buffer)) != -1) {
+                zipOut.write(buffer, 0, len);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 压缩成ZIP 方法1
+     *
+     * @param srcDir           压缩文件夹路径
+     * @param out              压缩文件输出流
+     * @param KeepDirStructure 是否保留原来的目录结构,true:保留目录结构; false:所有文件跑到压缩包根目录下(注意:不保留目录结构可能会出现同名文件,会压缩失败)
+     * @throws RuntimeException 压缩失败会抛出运行时异常
+     */
+    public static void zipFolder(String srcDir, OutputStream out, boolean KeepDirStructure) {
+        long startTime = System.currentTimeMillis();
+        try (ZipOutputStream zos = new ZipOutputStream(out)) {
+            final File sourceDir = new File(srcDir);
+            compressFolder(sourceDir, zos, sourceDir.getName(), KeepDirStructure);
+            long end = System.currentTimeMillis();
+            System.out.println("耗时:" + (end - startTime) + "ms");
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 递归压缩方法
+     *
+     * @param sourceDir        源文件
+     * @param zipOut           zip输出流
+     * @param name             压缩后的名称
+     * @param keepDirStructure 是否保留原来的目录结构,true:保留目录结构; false:所有文件跑到压缩包根目录下(注意:不保留目录结构可能会出现同名文件,会压缩失败)
+     * @throws Exception
+     */
+    private static void compressFolder(File sourceDir, ZipOutputStream zipOut, String name, boolean keepDirStructure) throws Exception {
+        byte[] buffer = new byte[1024];
+        //如果是文件
+        if (sourceDir.isFile()) {
+            // 向zip输出流中添加一个zip实体,构造器中name为zip实体的文件的名字
+            zipOut.putNextEntry(new ZipEntry(name));
+            // copy文件到zip输出流中
+            int len;
+            FileInputStream in = new FileInputStream(sourceDir);
+            while ((len = in.read(buffer)) != -1) {
+                zipOut.write(buffer, 0, len);
+            }
+            // Complete the entry
+            zipOut.closeEntry();
+            in.close();
+        } else {//如果是文件夹
+            File[] listFiles = sourceDir.listFiles();
+            if (listFiles == null || listFiles.length == 0) {
+                // 需要保留原来的文件结构时,需要对空文件夹进行处理
+                if (keepDirStructure) {
+                    // 空文件夹的处理
+                    zipOut.putNextEntry(new ZipEntry(name + "/"));
+                    // 没有文件,不需要文件的copy
+                    zipOut.closeEntry();
+                }
+            } else {
+                for (File file : listFiles) {
+                    // 判断是否需要保留原来的文件结构
+                    if (keepDirStructure){
+                        // 注意:file.getName()前面需要带上父文件夹的名字加一斜杠,
+                        // 不然最后压缩包中就不能保留原来的文件结构,即:所有文件都跑到压缩包根目录下了
+                        compressFolder(file, zipOut, name + "/" + file.getName(), true);
+                    } else {
+                        compressFolder(file, zipOut, file.getName(), false);
+                    }
+                }
+            }
+        }
+    }
+
+    /*public static void main(final String[] args) throws Exception {
+//        zipFile(new File("F:\\temp\\temp-file\\sun.text"));
+        zipFolder("D:\\uploadZip\\机构二维码", new FileOutputStream(new File("D:\\uploadZip\\aaa.zip")), true);
+    }*/
+}

+ 11 - 0
src/main/java/com/caimei/utils/ImageUtils.java

@@ -657,4 +657,15 @@ public class ImageUtils {
 		});
 		return authImagePath;
 	}
+
+	public static String transferBufferdImage(BufferedImage qrCodeImage, String filePath, String prefix) {
+		filePath = filePath + "." + prefix;
+		File file = new File(filePath);
+		try {
+			ImageIO.write(qrCodeImage, prefix, file);
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return filePath;
+	}
 }

+ 3 - 3
src/main/resources/mapper/AuthMapper.xml

@@ -198,17 +198,17 @@
         select authParty,
                concat(ifnull(p.name, ''), '/', ifnull(c.name, ''), '/', ifnull(t.name, '')) as area,
                address,
-               concat(lng, ',', lat) as lngAndLat,
+               concat(lng, ',', lat)                                                        as lngAndLat,
                mobile,
                authCode,
                authDate,
                empNum,
-               if(customFlag = 1, remarks, '') as remarks
+               if(customFlag = 1, remarks, '')                                              as remarks
         from cm_brand_auth a
                  left join province p on a.provinceId = p.provinceID
                  left join city c on a.cityId = c.cityID
                  left join town t on a.townId = t.townID
-        where authUserId = #{authUserId}
+        where a.delFlag = 0 and find_in_set(a.id, #{authIds})
         order by createTime desc
     </select>
     <select id="getBannerList" resultType="java.lang.String">

+ 1 - 1
src/main/resources/mapper/AuthProductMapper.xml

@@ -300,7 +300,7 @@
         select id from cm_brand where name = #{brand}
     </select>
     <select id="getAuthProductList" resultType="com.caimei.model.vo.ProductFormVo">
-        select p.id as productId,
+        select p.id as productId, p.purchaseWay,
                if(p.productTypeId is null,p.name,t.name) as productName,snCode,cb.name as brandName,
                if(p.productTypeId is null,p.image,t.image) as productImage,certificateImage
         from cm_brand_auth_product p

+ 13 - 6
src/main/resources/mapper/FileMapper.xml

@@ -135,16 +135,23 @@
                  left join cm_brand_auth_user u on a.authUserId = u.authUserId where u.authUserId = 4;
     </select>
     <select id="getProductImageList" resultType="com.caimei.model.po.ProductImagePo">
-        SELECT p.id as productId, certificateImage,a.authParty,p.snCode
+        SELECT p.id as productId, certificateImage, a.authParty, p.snCode,
+               if(p.productTypeId is null,p.name,t.name) as productName
         FROM cm_brand_auth_product p
-                 left join cm_brand_auth a on p.authId = a.id and a.delFlag = 0
-                 left join cm_brand_auth_user u on a.authUserId = u.authUserId where u.authUserId = #{authUserId};
+                 left join cm_brand_auth a on p.authId = a.id
+                 left join cm_brand_auth_user u on a.authUserId = u.authUserId
+                 left join cm_brand_product_type t on p.productTypeId = t.id
+        where a.delFlag = 0
+        <if test="authId != null">
+            and p.authId = #{authId}
+        </if>
     </select>
     <select id="getAuthImageList" resultType="com.caimei.model.vo.AuthVo">
-        select a.id as authId, a.authParty
+        select a.id as authId, a.authUserId, a.authImage, a.authParty
         from cm_brand_auth a
-            left join cm_brand_auth_user u on a.authUserId = u.authUserId
-        where u.authUserId = #{authUserId};
+                 left join cm_brand_auth_user u on a.authUserId = u.authUserId
+        where a.delFlag = 0
+          and find_in_set(a.id, #{authIds})
     </select>
     <select id="getFileForm" resultType="com.caimei.model.po.FilePo">
         select id,auditStatus from cm_brand_file where id = #{fileId}