package com.izouma.awesomeadmin.web;

import com.aliyun.oss.OSSClient;
import com.aliyun.oss.model.OSSObject;
import com.izouma.awesomeadmin.constant.AppConstant;
import com.izouma.awesomeadmin.dto.Page;
import com.izouma.awesomeadmin.dto.Result;
import com.izouma.awesomeadmin.model.ImageDownLog;
import com.izouma.awesomeadmin.model.ImageUploadLog;
import com.izouma.awesomeadmin.model.OrderImage;
import com.izouma.awesomeadmin.model.UserOrder;
import com.izouma.awesomeadmin.service.*;
import com.izouma.awesomeadmin.util.ExportExcelUtil;
import com.izouma.awesomeadmin.util.ImagesUtil;
import com.izouma.awesomeadmin.util.PropertiesFileLoader;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.util.*;
import java.util.zip.Adler32;
import java.util.zip.CheckedOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

/**
 * controller类
 */
@Controller
@RequestMapping("/orderImage")
public class OrderImageController {


    /**
     * 日志对象zipFilesDown
     */
    private static Logger logger = Logger.getLogger(OrderImageController.class);


    @Autowired
    private OrderImageService orderImageService;

    @Autowired
    private UserOrderService userOrderService;

    @Autowired
    private OSSFileService OSSFileService;

    @Autowired
    private ImageUploadLogService imageUploadLogService;

    @Autowired
    private ImageDownLogService imageDownLogService;

    /**
     * <p>获取全部记录。</p>
     */
    @RequiresAuthentication
    @RequestMapping(value = "/all", method = RequestMethod.GET)
    @ResponseBody
    public Result all(OrderImage record) {
        List<OrderImage> pp = orderImageService.getOrderImageList(record);
        return new Result(true, pp);
    }

    /**
     * <p>根据Id。</p>
     */
    @RequestMapping(value = "/getOrderImage", method = RequestMethod.GET)
    @ResponseBody
    @RequiresAuthentication
    public Result getOrderImage(@RequestParam(required = false, value = "id") String id) {
        OrderImage data = orderImageService.getOrderImageById(id);
        return new Result(true, data);
    }

    /**
     * <p>根据条件获取。</p>
     */
    @RequestMapping(value = "/getOne", method = RequestMethod.GET)
    @ResponseBody
    @RequiresAuthentication
    public Result getOne(OrderImage record) {
        OrderImage data = orderImageService.getOrderImage(record);
        return new Result(true, data);
    }


    /**
     * <p>分页查询。</p>
     */
    @RequestMapping(value = "/page", method = RequestMethod.GET)
    @ResponseBody
    @RequiresAuthentication
    public Result page(Page page, OrderImage record) {
        Map<String, Object> result = new HashMap<>();

        List<OrderImage> pp = orderImageService.getOrderImageByPage(page, record);

        result.put(AppConstant.PAGE, page);
        result.put("pp", pp);
        return new Result(true, result);
    }


    /**
     * <p>保存。</p>
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ResponseBody
    @RequiresAuthentication
    public Result save(OrderImage record) {

        boolean num = orderImageService.createOrderImage(record);
        if (num) {
            return new Result(true, record.getId());
        }
        return new Result(false, "保存异常");
    }

    /**
     * <p>更新信息。</p>
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    @RequiresAuthentication
    public Result updateOrderImage(OrderImage record) {

        boolean num = orderImageService.updateOrderImage(record);
        if (num) {
            return new Result(true, "保存成功");
        }
        return new Result(false, "保存异常");
    }

    /**
     * <p>删除。</p>
     */
    @RequestMapping(value = "/del", method = RequestMethod.POST)
    @ResponseBody
    @RequiresAuthentication
    public Result deleteOrderImage(@RequestParam(required = true, value = "id") String id) {

        boolean num = orderImageService.deleteOrderImage(id);
        if (num) {
            return new Result(true, "删除成功");
        }
        return new Result(false, "删除异常");
    }

    /**
     * 导出Excel
     *
     * @param request
     * @param response
     * @param record
     * @throws Exception
     */
    @RequestMapping(value = "/exportExcel", method = RequestMethod.GET)
    @ResponseBody
    public void exportExcel(HttpServletRequest request, HttpServletResponse response, OrderImage record) throws Exception {

        List<OrderImage> orderImages = orderImageService.getOrderImageList(record);


        String sheetName = "order_image";
        String titleName = "订单图片数据表";
        String fileName = "订单图片表";
        int columnNumber = 16;
        int[] columnWidth = {20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20};
        String[] columnName = {"", "删除标识", "更新时间", "更新人", "创建时间", "创建人", "订单", "用户", "店铺", "原片地址", "原片大小", "成片地址", "成片大小", "修图人", "状态", "备注"};
        String[][] dataList = new String[orderImages.size()][16];

        for (int i = 0; i < orderImages.size(); i++) {

            dataList[i][0] = String.valueOf(orderImages.get(i).getId());
            dataList[i][1] = String.valueOf(orderImages.get(i).getDelFlag());
            dataList[i][2] = String.valueOf(orderImages.get(i).getUpdateTime());
            dataList[i][3] = String.valueOf(orderImages.get(i).getUpdateUser());
            dataList[i][4] = String.valueOf(orderImages.get(i).getCreateTime());
            dataList[i][5] = String.valueOf(orderImages.get(i).getCreateUser());
            dataList[i][6] = String.valueOf(orderImages.get(i).getOrderId());
            dataList[i][7] = String.valueOf(orderImages.get(i).getUserId());
            dataList[i][8] = String.valueOf(orderImages.get(i).getStoreId());
            dataList[i][9] = String.valueOf(orderImages.get(i).getOriginalImage());
            dataList[i][10] = String.valueOf(orderImages.get(i).getOriginalSize());
            dataList[i][11] = String.valueOf(orderImages.get(i).getFinishedImage());
            dataList[i][12] = String.valueOf(orderImages.get(i).getFinishedSize());
            dataList[i][13] = String.valueOf(orderImages.get(i).getDealUser());
            dataList[i][14] = String.valueOf(orderImages.get(i).getStatusFlag());
            dataList[i][15] = String.valueOf(orderImages.get(i).getRemark());
        }


        ExportExcelUtil.ExportWithResponse(sheetName, titleName, fileName,
                columnNumber, columnWidth, columnName, dataList, response);


    }


    /**
     * <p>返修。</p>
     */
    @RequestMapping(value = "/repair", method = RequestMethod.POST)
    @ResponseBody
    @RequiresAuthentication
    public Result repair(OrderImage record) {
        boolean num = orderImageService.repair(record);
        if (num) {
            return new Result(true, "保存成功");
        }
        return new Result(false, "保存异常");
    }

    @RequestMapping(value = "/uploadFileForOrder")
    @ResponseBody
    public Result uploadFile(HttpServletRequest request, String storeId, String orderId, String userId, String typeFlag) {


        CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(request.getSession().getServletContext());
        if (multipartResolver.isMultipart(request)) {
            MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
            Iterator it = multiRequest.getFileNames();
            List<OrderImage> paths = new ArrayList<>();
            while (it.hasNext()) {
                MultipartFile file = multiRequest.getFile(it.next().toString());
                if (file != null) {
                    try {


                        String originalFilename = file.getOriginalFilename();

                        OrderImage orderImage = new OrderImage();
                        orderImage.setOrderId(orderId);
                        orderImage.setImageName(originalFilename);
                        orderImage = orderImageService.getOrderImage(orderImage);

                        if (orderImage == null) {
                            if ("finished".equals(typeFlag)) {
                                return new Result(false, originalFilename + "不在原图中");
                            }
                        } else {
                            if ("finished".equals(typeFlag) && orderImage.getStatusFlag() == 1) {
                                return new Result(false, originalFilename + "已经审核通过");
                            }
                        }

                        String fileType = originalFilename.split("[.]")[originalFilename.split("[.]").length - 1];

                        long srcSize = file.getSize();


                        String uploadPath = storeId + "/" + orderId + "/" + typeFlag + "/" + originalFilename;


                        String path = OSSFileService.upload(file.getInputStream(), uploadPath);

                        ImageUploadLog imageUploadLog = new ImageUploadLog();

                        imageUploadLog.setStoreId(storeId);
                        imageUploadLog.setOrderId(orderId);
                        imageUploadLog.setTypeFlag(typeFlag);
                        imageUploadLog.setUserId(userId);
                        imageUploadLog.setImageName(originalFilename);
                        imageUploadLog.setUrl(path);
                        imageUploadLog.setArtworkUrl(path);
                        imageUploadLog.setImageSize(BigDecimal.valueOf(file.getSize()));

                        int bigSize = 2 * 1024 * 1024;
                        if (srcSize > bigSize) {

                            String minPath = storeId + "/" + orderId + "/" + typeFlag + "/" + "min/" + originalFilename;

                            String min = OSSFileService.upload(ImagesUtil.changeMinPhoto(
                                    file.getInputStream(),
                                    fileType,
                                    2000, 1), minPath);

                            imageUploadLog.setUrl(min);
                        }

                        imageUploadLogService.createImageUploadLog(imageUploadLog);


                        if (orderImage != null) {

                            orderImage.setImageName(originalFilename);

                            if ("original".equals(typeFlag)) {
                                orderImage.setOriginalSize(imageUploadLog.getImageSize());
                                orderImage.setOriginalImage(imageUploadLog.getUrl());
                                orderImage.setOriginalArtwork(imageUploadLog.getArtworkUrl());

                            } else if ("finished".equals(typeFlag)) {

                                if (orderImage.getStatusFlag() != 1) {
                                    orderImage.setStatusFlag(0);
                                }

                                orderImage.setFinishedSize(imageUploadLog.getImageSize());
                                orderImage.setFinishedImage(imageUploadLog.getUrl());
                                orderImage.setFinishedArtwork(imageUploadLog.getArtworkUrl());
                            }

                            orderImageService.updateOrderImage(orderImage);

                        } else {
                            if ("original".equals(typeFlag)) {

                                OrderImage param = new OrderImage();
                                param.setOrderId(orderId);
                                param = orderImageService.getOrderImageTotalNum(param);

                                if (param != null) {
                                    if (param.getTotalNum() >= param.getOrderNum()) {
                                        return new Result(false, "订单上传" + param.getTotalNum() + "张图片。不能再传了");
                                    }
                                }

                                orderImage = new OrderImage();

                                orderImage.setOrderId(orderId);
                                orderImage.setUserId(userId);
                                orderImage.setStoreId(storeId);
                                orderImage.setImageName(originalFilename);


                                orderImage.setOriginalSize(imageUploadLog.getImageSize());
                                orderImage.setOriginalImage(imageUploadLog.getUrl());
                                orderImage.setOriginalArtwork(imageUploadLog.getArtworkUrl());


                                orderImageService.createOrderImage(orderImage);
                            }

                        }

                        paths.add(orderImage);
                    } catch (IOException e) {
                        logger.error("上传订单图片失败", e);
                        return new Result(false, "上传失败");
                    }
                }
            }
            return new Result(true, paths);
        }
        return new Result(false, "上传失败");
    }


    /**
     * 清空未使用图片
     *
     * @param orderId
     * @return
     */
    @RequestMapping(value = "/delOssImage", method = RequestMethod.POST)
    @ResponseBody
    public Result delOssImage(@RequestParam(required = true, value = "orderId") String orderId) {


        List<ImageUploadLog> imageUploadLogs = imageUploadLogService.queryDelOssImage(orderId);

        for (ImageUploadLog imageUploadLog : imageUploadLogs) {

            try {

                if (StringUtils.isNotEmpty(imageUploadLog.getUrl())) {
                    String artwork = imageUploadLog.getUrl().replace(PropertiesFileLoader.getProperties("aliImageSever") + "/", "");
                    OSSFileService.deleteObject(artwork);
                }
            } catch (Exception e) {
                logger.error("删除图片异常", e);
            }


        }


        return new Result(true, "删除成功");
    }


    /**
     * 批量更新成片
     *
     * @param orderId
     * @param imageIds
     * @return
     */
    @RequestMapping(value = "/updateFinishedImages", method = RequestMethod.POST)
    @ResponseBody
    public Result updateFinishedImages(@RequestParam(required = true, value = "orderId") String orderId, @RequestParam(required = true, value = "imageIds") String imageIds) {
        ImageUploadLog record = new ImageUploadLog();
        record.setOrderId(orderId);
        record.setIdStr(imageIds);
        List<ImageUploadLog> imageUploadLogs = imageUploadLogService.getImageUploadLogList(record);

        for (ImageUploadLog imageUploadLog : imageUploadLogs) {
            OrderImage orderImage = new OrderImage();

            orderImage.setOrderId(orderId);
            orderImage.setImageName(imageUploadLog.getImageName());
            orderImage = orderImageService.getOrderImage(orderImage);

            if (orderImage != null) {

                if (orderImage.getStatusFlag() != 1) {

                    orderImage.setStatusFlag(0);
                    orderImage.setFinishedImage(imageUploadLog.getUrl());
                    orderImage.setFinishedSize(imageUploadLog.getImageSize());
                    orderImage.setFinishedArtwork(imageUploadLog.getArtworkUrl());
                    orderImageService.updateOrderImage(orderImage);
                }

            }


        }

        return new Result(true, "保存成功");
    }

    /**
     * 获取店铺存储情况
     *
     * @param record
     * @return
     */
    @RequestMapping(value = "/getMemorySize", method = RequestMethod.GET)
    @ResponseBody
    public Result getMemorySize(OrderImage record) {
        OrderImage data = orderImageService.getMemorySize(record);
        return new Result(true, data);
    }

    /**
     * 获取订单数量
     *
     * @param record
     * @return
     */
    @RequestMapping(value = "/getTotalNum", method = RequestMethod.GET)
    @ResponseBody
    public Result getTotalNum(OrderImage record) {
        OrderImage data = orderImageService.getOrderImageTotalNum(record);
        return new Result(true, data);
    }


    /**
     * 下载压缩包
     *
     * @param orderId  订单ID
     * @param typeFlag 类型  original / finished
     * @param code     编码 下载标识
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/zipFilesDown", method = RequestMethod.GET)
    @ResponseBody
    public void zipFilesDown(@RequestParam(required = true, value = "orderId") String orderId,
                             @RequestParam(required = true, value = "typeFlag") String typeFlag,
                             @RequestParam(required = true, value = "code") String code,
                             HttpServletRequest request, HttpServletResponse response) {

        try {
            OrderImage record = new OrderImage();
            record.setOrderId(orderId);
            List<OrderImage> orderImageList = orderImageService.getOrderImageList(record);
            if (orderImageList.size() > 0) {
                UserOrder userOrder = userOrderService.getUserOrderById(orderId);
                if (userOrder != null) {

                    List<String> keyList = new ArrayList<>();
                    String zipName = userOrder.getOrderCode() + "_" + typeFlag;

                    for (OrderImage orderImage : orderImageList) {


                        if ("original".equals(typeFlag)) {
                            if (StringUtils.isNotEmpty(orderImage.getOriginalImage())) {
                                if (StringUtils.isNotEmpty(orderImage.getOriginalArtwork())) {
                                    String imageName = orderImage.getOriginalArtwork().replace(PropertiesFileLoader.getProperties("aliImageSever") + "/", "");
                                    keyList.add(imageName);
                                } else {

                                    String imageName = orderImage.getOriginalImage().replace(PropertiesFileLoader.getProperties("aliImageSever") + "/", "");
                                    keyList.add(imageName);
                                }
                            }
                        } else if ("finished".equals(typeFlag)) {
                            if (StringUtils.isNotEmpty(orderImage.getFinishedImage())) {

                                if (StringUtils.isNotEmpty(orderImage.getFinishedArtwork())) {
                                    String imageName = orderImage.getFinishedArtwork().replace(PropertiesFileLoader.getProperties("aliImageSever") + "/", "");
                                    keyList.add(imageName);
                                } else {

                                    String imageName = orderImage.getFinishedImage().replace(PropertiesFileLoader.getProperties("aliImageSever") + "/", "");
                                    keyList.add(imageName);
                                }

                                //更新成已下载
                                orderImage.setDownloadFlag("Y");
                                orderImageService.updateOrderImage(orderImage);
                            }
                        }
                    }

                    if (keyList.size() > 0) {
                        //OSSFileService.zipFilesDown(keyList, zipName, request, response);

                        String accessKeyId = PropertiesFileLoader.getDefaultProperties("aliossid", "");
                        String accessKeySecret = PropertiesFileLoader.getDefaultProperties("aliosskey", "");
                        String endpoint = PropertiesFileLoader.getDefaultProperties("aliossendpoit", "");
                        String bucketName = PropertiesFileLoader.getDefaultProperties("alibucketname", "");

                        // endpoint以杭州为例，其它region请按实际情况填写
                        // 云账号AccessKey有所有API访问权限，建议遵循阿里云安全最佳实践，创建并使用RAM子账号进行API访问或日常运维，请登录 https://ram.console.aliyun.com 创建
                        try {
                            // 初始化
                            OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
                            String fileName = zipName + ".zip";
                            // 创建临时文件
                            File zipFile = File.createTempFile(zipName, ".zip");
                            FileOutputStream f = new FileOutputStream(zipFile);
                            /**
                             * 作用是为任何OutputStream产生校验和
                             * 第一个参数是制定产生校验和的输出流，第二个参数是指定Checksum的类型 （Adler32（较快）和CRC32两种）
                             */
                            CheckedOutputStream csum = new CheckedOutputStream(f, new Adler32());
                            // 用于将数据压缩成Zip文件格式
                            ZipOutputStream zos = new ZipOutputStream(csum);

                            for (int i = 0; i < keyList.size(); i++) {
                                try {
                                    String ossfile = keyList.get(i);

                                    ImageDownLog imageDownLog = new ImageDownLog();

                                    imageDownLog.setOrderId(orderId);
                                    imageDownLog.setTypeFlag(typeFlag);
                                    imageDownLog.setImageCode(code);
                                    imageDownLog.setImageName(ossfile.split("/")[ossfile.split("/").length - 1]);
                                    imageDownLog.setTotalNum(keyList.size());
                                    imageDownLog.setNowNum(i + 1);

                                    imageDownLogService.createImageDownLog(imageDownLog);


                                    // 获取Object，返回结果为OSSObject对象
                                    OSSObject ossObject = ossClient.getObject(bucketName, ossfile);

                                    imageDownLog.setImageSize(BigDecimal.valueOf(ossObject.getObjectMetadata().getContentLength()));

                                    // 读去Object内容  返回
                                    InputStream inputStream = ossObject.getObjectContent();
                                    // 对于每一个要被存放到压缩包的文件，都必须调用ZipOutputStream对象的putNextEntry()方法，确保压缩包里面文件不同名

                                    zos.putNextEntry(new ZipEntry(ossfile.split("/")[ossfile.split("/").length - 1]));
                                    int bytesRead = 0;
                                    // 向压缩文件中输出数据
                                    while ((bytesRead = inputStream.read()) != -1) {
                                        zos.write(bytesRead);
                                    }
                                    inputStream.close();
                                    zos.closeEntry(); // 当前文件写完，定位为写入下一条项目


                                    imageDownLog.setStatusFlag(1);

                                    imageDownLogService.updateImageDownLog(imageDownLog);


                                } catch (Exception e) {
                                    logger.error("ossfile, 压缩失败", e);
                                }
                            }
                            zos.close();
                            String header = request.getHeader("User-Agent").toUpperCase();
                            if (header.contains("MSIE") || header.contains("TRIDENT") || header.contains("EDGE")) {
                                fileName = URLEncoder.encode(fileName, "utf-8");
                                fileName = fileName.replace("+", "%20");    //IE下载文件名空格变+号问题
                            } else {
                                fileName = new String(fileName.getBytes(), "ISO8859-1");
                            }
                            response.reset();
                            response.setContentType("text/plain");
                            response.setContentType("application/octet-stream; charset=utf-8");
                            response.setHeader("Location", fileName);
                            response.setHeader("Cache-Control", "max-age=0");
                            response.setHeader("Content-Disposition", "attachment; filename=" + fileName);

                            FileInputStream fis = new FileInputStream(zipFile);
                            BufferedInputStream buff = new BufferedInputStream(fis);
                            BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());
                            byte[] car = new byte[1024];
                            int l = 0;
                            while (l < zipFile.length()) {
                                int j = buff.read(car, 0, 1024);
                                l += j;
                                out.write(car, 0, j);
                            }
                            // 关闭流
                            fis.close();
                            buff.close();
                            out.close();

                            ossClient.shutdown();
                            // 删除临时文件
                            zipFile.delete();
                        } catch (Exception e) {
                            logger.error("压缩失败", e);
                        }

                    }


                }

            }


        } catch (Exception e) {
            logger.error("zipFilesDown,批量下载异常", e);
        }

    }


    /**
     * 单张下载
     *
     * @param id       orderImage id
     * @param typeFlag 类型  original / finished
     * @param request
     * @param response
     */
    @RequestMapping(value = "/singleFileDown", method = RequestMethod.GET)
    @ResponseBody
    public void singleFileDown(@RequestParam(required = true, value = "id") String id,
                               @RequestParam(required = true, value = "typeFlag") String typeFlag,
                               HttpServletRequest request, HttpServletResponse response) {

        try {
            OrderImage orderImage = orderImageService.getOrderImageById(id);

            if (orderImage != null) {
                if ("original".equals(typeFlag)) {
                    if (StringUtils.isNotEmpty(orderImage.getOriginalImage())) {
                        if (StringUtils.isNotEmpty(orderImage.getOriginalArtwork())) {

                            String imageName = orderImage.getOriginalArtwork().replace(PropertiesFileLoader.getProperties("aliImageSever") + "/", "");
                            OSSFileService.singleFileDown(imageName, request, response);
                        } else {
                            String imageName = orderImage.getOriginalImage().replace(PropertiesFileLoader.getProperties("aliImageSever") + "/", "");
                            OSSFileService.singleFileDown(imageName, request, response);
                        }
                    }
                } else if ("finished".equals(typeFlag)) {
                    if (StringUtils.isNotEmpty(orderImage.getFinishedImage())) {
                        if (StringUtils.isNotEmpty(orderImage.getFinishedArtwork())) {

                            String imageName = orderImage.getFinishedArtwork().replace(PropertiesFileLoader.getProperties("aliImageSever") + "/", "");
                            OSSFileService.singleFileDown(imageName, request, response);
                        } else {
                            String imageName = orderImage.getFinishedImage().replace(PropertiesFileLoader.getProperties("aliImageSever") + "/", "");
                            OSSFileService.singleFileDown(imageName, request, response);
                        }

                        //更新成已下载
                        orderImage.setDownloadFlag("Y");
                        orderImageService.updateOrderImage(orderImage);
                    }
                }
            }


        } catch (Exception e) {
            logger.error("singleFileDown,单张下载异常", e);
        }

    }


    @RequestMapping(value = "/autoCleanOrderImage", method = RequestMethod.GET)
    @ResponseBody
    public Result autoCleanOrderImage() {

        return orderImageService.autoCleanOrderImage(null);
    }

    @RequestMapping(value = "/handCleanOrderImage", method = RequestMethod.POST)
    @ResponseBody
    @RequiresAuthentication
    public Result handCleanOrderImage(OrderImage record) {

        return orderImageService.autoCleanOrderImage(record);
    }

    /**
     * 导出注释
     *
     * @param request
     * @param response
     * @param record
     * @throws Exception
     */
    @RequestMapping(value = "/exportRemark", method = RequestMethod.GET)
    @ResponseBody
    public void exportRemark(HttpServletRequest request, HttpServletResponse response, OrderImage record) throws Exception {

        List<OrderImage> orderImages = orderImageService.getOrderImageList(record);


        String sheetName = "图片备注";
        String titleName = "订单图片数据表";
        String fileName = "订单图片表";
        int columnNumber = 2;
        int[] columnWidth = {30, 30};
        String[] columnName = {"图片", "备注"};
        String[][] dataList = new String[orderImages.size()][2];

        for (int i = 0; i < orderImages.size(); i++) {

            dataList[i][0] = String.valueOf(orderImages.get(i).getImageName());
            dataList[i][1] = StringUtils.isNotEmpty(orderImages.get(i).getRemark()) ? orderImages.get(i).getRemark() : "";
        }


        ExportExcelUtil.ExportWithResponse(sheetName, titleName, fileName,
                columnNumber, columnWidth, columnName, dataList, response);


    }


}

