package com.tuoheng.admin.service.report.export;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.lowagie.text.*;
import com.tuoheng.admin.entity.*;
import com.tuoheng.admin.enums.code.questiontype.QuestionTypeEnum;
import com.tuoheng.admin.enums.code.report.GenerateReportCodeEnum;
import com.tuoheng.admin.mapper.*;
import com.tuoheng.admin.utils.ShiroUtils;
import com.tuoheng.admin.utils.WordUtils;
import com.tuoheng.common.core.config.UploadFileConfig;
import com.tuoheng.common.core.config.common.CommonConfig;
import com.tuoheng.common.core.utils.DateUtils;
import com.tuoheng.common.core.utils.JsonResult;
import com.tuoheng.common.core.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.UrlResource;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 导出巡检报告业务层处理
 *
 * @author wanjing
 * @team tuoheng
 * @date 2022-12-09
 */
@Slf4j
@Service
public class ExportInspectionReportService {

    @Autowired
    private ReportMapper reportMapper;

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private TenantMapper tenantMapper;

    @Autowired
    private InspectionFileMapper inspectionFileMapper;

    @Autowired
    private InspectionFileHandleMapper inspectionFileHandleMapper;

    public JsonResult exportReport(String reportId, HttpServletResponse response) {
        String tenantId = ShiroUtils.getTenantId();

        JsonResult result = this.check(reportId);
        if (0 != result.getCode()) {
            log.info("导出巡检报告业务：校验失败：{}", result.getMsg());
            return result;
        }

        //查询报告
        Report report = (Report) result.getData();

//        BeanUtils.copyProperties(report, reportInfoVo);

        //  查询问题清单
        List<InspectionFile> inspectionFileList = inspectionFileMapper.selectList(new LambdaQueryWrapper<InspectionFile>()
                                            .eq(InspectionFile::getTenantId, tenantId)
                                            .eq(InspectionFile::getInspectionId, report.getInspectionId()));

        //  查询问题处理结果
        List<String> inspectionFileIdList = inspectionFileList.stream().map(o -> o.getId()).collect(Collectors.toList());
        List<InspectionFileHandle> inspectionFileHandleList = inspectionFileHandleMapper.selectList(new LambdaQueryWrapper<InspectionFileHandle>()
                .in(InspectionFileHandle::getInspectionFileId, inspectionFileIdList));

        //创建word
        String filename = report.getReportCode() + ".doc";
        String filepath = UploadFileConfig.uploadFolder + "/doc/" + filename;
        File fd = new File(UploadFileConfig.uploadFolder + "/doc");
        File f = new File(filepath);
        if (!fd.exists()) {
            fd.mkdirs();
        }

        WordUtils wordUtils = new WordUtils();
        try {
            Tenant tenant = tenantMapper.selectById(ShiroUtils.getTenantId());
            String areaName = "";
            if(ObjectUtil.isNotNull(tenant)){
//                areaName = tenant.getProvinceName() + tenant.getCityName() + tenant.getDistrictName();
                if (!StringUtils.isEmpty(tenant.getProvinceName())) {
                    areaName += tenant.getProvinceName();
                }
                if (!StringUtils.isEmpty(tenant.getCityName())) {
                    areaName += tenant.getCityName();
                }
                if (!StringUtils.isEmpty(tenant.getDistrictName())) {
                    areaName += tenant.getDistrictName();
                }
            }
            if (!f.exists() || f.length() < 1000) {
                f.delete();
                f.createNewFile();
                wordUtils.openDocument(filepath);
                wordUtils.getDocument().setPageSize(PageSize.A4);
                wordUtils.getDocument().setMargins(71f, 71f, 72f, 72f);

                //标题
                wordUtils.insertTitlePattern(areaName + "高速巡检报告", wordUtils.rtfGsBt1);
                wordUtils.insertContext("报告编号：" + report.getReportCode(), 10, Font.NORMAL, Element.ALIGN_RIGHT, 20, 0, 0);

//                wordUtils.insertTitlePatternThird("一：高速信息", wordUtils.rtfGsBt3);
//                //wordUtils.getDocument().add(new Paragraph(""));
//                Table inspectionTable = this.buildInspectionTable();
//                wordUtils.getDocument().add(inspectionTable);

                wordUtils.insertTitlePatternThird("巡检信息", wordUtils.rtfGsBt3);
                Table table2 = this.buildInspectionTable(report);
                wordUtils.getDocument().add(table2);

                wordUtils.insertTitlePatternThird("巡检结果", wordUtils.rtfGsBt3);
                Table table3 = this.buildTable3();
                wordUtils.getDocument().add(table3);

                wordUtils.insertTitlePatternThird("问题清单", wordUtils.rtfGsBt3);
                Table inspectionFileTable = this.buildInspectionFileTable(inspectionFileList);
                wordUtils.getDocument().add(inspectionFileTable);

//                if (reportInfoVo.getImageList().size() > 0) {
//                    wordUtils.insertTitlePatternThird("四：问题清单", wordUtils.rtfGsBt3);
//                    for (int i = 0; i < reportInfoVo.getImageList().size(); i++) {
//                        InspectionFileInfoVo inspectionFileInfoVo = reportInfoVo.getImageList().get(i);
//
//                        InspectionQuestionItem item = inspectionQuestionItemMapper.selectOne(new LambdaQueryWrapper<InspectionQuestionItem>()
//                                .eq(inspectionFileInfoVo.getId() != null, InspectionQuestionItem::getInspectionFileId, inspectionFileInfoVo.getId())
//                                .eq(InspectionQuestionItem::getTenantId, tenantId));
//                        if (item != null) {
//                            inspectionFileInfoVo.setHandImg(item.getHandlerImage());
//                            inspectionFileInfoVo.setHandContent(item.getHandlerResult());
//                            inspectionFileInfoVo.setHandTime(DateUtils.dateTime(item.getHandlerTime()));
//                            User user = userMapper.selectById(item.getHandlerUser());
//                            inspectionFileInfoVo.setHanderName(user.getRealname());
//                        }
//
//                        Table table4 = this.buildTable4();
//                        wordUtils.getDocument().add(table4);
//                    }
//                }
                wordUtils.closeDocument();
            }

            //清空缓存
            response.reset();
            // 定义浏览器响应表头，并定义下载名
            String fileName = URLEncoder.encode(areaName + "高速巡检报告【" + report.getReportCode() + "】.doc", "UTF-8");
            response.setHeader("Content-Disposition", "attachment;filename*=utf-8''" + URLEncoder.encode(fileName,"UTF-8"));
            response.setCharacterEncoding("utf-8");
            //定义下载的类型
            response.setContentType("application/msword;charset=UTF-8");
            OutputStream out;
            File files = new File(UploadFileConfig.uploadFolder + "doc/", filename);

            FileInputStream inputStream = new FileInputStream(files);
            //3.通过response获取ServletOutputStream对象(out)
            out = response.getOutputStream();
            int b = 0;
            byte[] buffer = new byte[512];
            while (b != -1) {
                b = inputStream.read(buffer);
                //4.写到输出流(out)中
                out.write(buffer, 0, b);
            }
            inputStream.close();
            out.close();
            out.flush();
            System.out.println("结束。。。。。。");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                wordUtils.closeDocument();
            } catch (DocumentException e) {
                throw new RuntimeException(e);
            }
        }
        return JsonResult.success();
    }

    /**
     * 检查
     *
     * @param id
     * @return
     */
    private JsonResult check(String id) {
        if (StringUtils.isEmpty(id)) {
            return JsonResult.error(GenerateReportCodeEnum.INSPECTION_ID_IS_NULL.getCode(), GenerateReportCodeEnum.INSPECTION_ID_IS_NULL.getMsg());
        }
        Report report = reportMapper.selectOne(Wrappers.<Report>lambdaQuery()
                .eq(Report::getId, id)
                .eq(Report::getMark, 1));
        if (null == report) {
            return JsonResult.error(GenerateReportCodeEnum.INSPECTION_IS_NOT_EXIST.getCode(), GenerateReportCodeEnum.INSPECTION_IS_NOT_EXIST.getMsg());
        }
        return JsonResult.success(report);
    }

    /**
     *
     * 构建巡检信息
     *
     */
    private Table buildInspectionTable1() throws DocumentException {
        Table table = new Table(6); //生成一表格
        table.setOffset(1f);
        int width[] = {1, 1, 1, 1, 1, 1};
        table.setWidths(width);//设置系列所占比例
        table.setWidth(100);
        table.setAutoFillEmptyCells(true);
        table.setAlignment(Element.ALIGN_LEFT);//居中显示
        for (int i = 0; i < 11; i++) {
            Cell cell = new Cell();
            String str = null;
            cell.setVerticalAlignment(Element.ALIGN_RIGHT);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            Font font = new Font();
            font.setSize(10.5f);
            font.setStyle(Font.BOLD);
            if (i == 0) {
                str = "河道基本信息";
                cell.setColspan(6);
            } else if (i == 1) {
                str = "责任单位";
            } else if (i == 2) {
//                str = reportInfoVo.getStreamArea();
                font.setStyle(Font.NORMAL);
            } else if (i == 3) {
                str = "河流名称";
            } else if (i == 4) {
//                str = reportInfoVo.getStreamName();
                font.setStyle(Font.NORMAL);
            } else if (i == 5) {
                str = "河段长度";
            } else if (i == 6) {
//                str = reportInfoVo.getStreamLength();
                font.setStyle(Font.NORMAL);
            } else if (i == 7) {
                str = "起讫位置";
            } else if (i == 8) {
//                str = reportInfoVo.getStreamLocation();
                font.setStyle(Font.NORMAL);
                cell.setColspan(3);
            } else if (i == 9) {
                str = "巡查里程";
            } else if (i == 10) {
//                str = reportInfoVo.getStreamLength();
                font.setStyle(Font.NORMAL);
            }
            Paragraph p = new Paragraph(str, font);
            cell.add(p);
            table.addCell(cell);
        }
        return table;
    }

    /**
     *
     * 构建巡检信息
     *
     */
    private Table buildInspectionTable(Report report) throws DocumentException {
        Table table = new Table(2);//生成一表格
        table.setOffset(1f);
        int width2[] = {1, 1};
        table.setWidths(width2);//设置系列所占比例
        table.setWidth(100);
        table.setAutoFillEmptyCells(true);
        table.setAlignment(Element.ALIGN_CENTER);   //居中显示
        table.setAlignment(Element.ALIGN_MIDDLE);   //垂直居中显示
        for (int i = 0; i < 14; i++) {
            Cell cell = new Cell();
            String str = null;
            cell.setVerticalAlignment(Element.ALIGN_LEFT);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            Font font = new Font();
            font.setSize(10.5f);
            font.setStyle(Font.BOLD);
            if (i == 0) {
                str = "气象信息";
            } else if (i == 1) {
                str = report.getWeather();
                font.setStyle(Font.NORMAL);
            } else if (i == 2) {
                str = "巡检部门";
            } else if (i == 3) {
                str = "";
                font.setStyle(Font.NORMAL);
            } else if (i == 4) {
                str = "巡检方式";
            } else if (i == 5) {
                if (report.getInspectionType() == 1) {
                    str = "无人机";
                } else if (report.getInspectionType() == 2) {
                    str = "机场巡逻";
                } else if (report.getInspectionType() == 3) {
                    str = "飞手值飞";
                }
                font.setStyle(Font.NORMAL);
            } else if (i == 6) {
                str = "巡查设备";
            } else if (i == 7) {
                str = report.getEquipmentName();
                font.setStyle(Font.NORMAL);
            } else if (i == 8) {
                str = "巡查开始时间";
            } else if (i == 9) {
                str = report.getExecutionStartTime() == null ? "" : DateUtils.dateTime(report.getExecutionStartTime());
                font.setStyle(Font.NORMAL);
            } else if (i == 10) {
                str = "巡查结束时间";
            } else if (i == 11) {
                str = report.getExecutionEndTime() == null ? "" : DateUtils.dateTime(report.getExecutionEndTime());
                font.setStyle(Font.NORMAL);
            } else if (i == 12) {
                str = "巡检高速";
            } else if (i == 13) {
                str = "G2";
                font.setStyle(Font.NORMAL);
            }
            Paragraph p = new Paragraph(str, font);
            cell.add(p);
            table.addCell(cell);
        }
        return table;
    }

    /**
     *
     * 构建巡检信息
     *
     */
    private Table buildTable3() throws DocumentException {
        Table table = new Table(5);//生成一表格
//        Map<String, Object> params = getInsCount(reportInfoVo);
//        table.setOffset(1f);
//        int width[] = {1, 2, 3, 14, 3};
//        table.setWidths(width);//设置系列所占比例
//        table.setWidth(100);
//        table.setAutoFillEmptyCells(true);
//        // table3.setAlignment(Element.ALIGN_CENTER);//居中显示
//        // table3.setAlignment(Element.ALIGN_MIDDLE);//垂直居中显示
//        for (int i = 0; i < 44; i++) {
//            Cell cell = new Cell();
//            String str = null;
//            cell.setVerticalAlignment(Element.ALIGN_CENTER);
//            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
//            Font font = new Font();
//            font.setSize(10.5f);
//            font.setStyle(Font.BOLD);
//            if (i == 0) {
//                str = "序号";
//            } else if (i == 1) {
//                str = "项目";
//                cell.setColspan(2);
//            } else if (i == 2) {
//                str = "巡检内容";
//            } else if (i == 3) {
//                str = "巡检监测结果";
//            } else if (i == 4) {
//                str = "一";
//                cell.setRowspan(6);
//            } else if (i == 5) {
//                str = QuestionNameEnum.WATER_SURFACE.getName();
//                cell.setRowspan(6);
//            } else if (i == 6) {
//                str = QuestionTypeEnum.DAILY_MONITORING.getName();
//                cell.setRowspan(3);
//            } else if (i == 7) {
//                str = "水面有漂浮物";
//                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
//                font.setStyle(Font.NORMAL);
//            } else if (i == 8) {
//                str = params.get("${totalCount1}").toString();
//                font.setStyle(Font.NORMAL);
//            } else if (i == 9) {
//                str = "水面有明显鱼类翻肚现象";
//                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
//                font.setStyle(Font.NORMAL);
//            } else if (i == 10) {
//                str = params.get("${totalCount2}").toString();
//                font.setStyle(Font.NORMAL);
//            } else if (i == 11) {
//                str = "河道内存在水生植被";
//                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
//                font.setStyle(Font.NORMAL);
//            } else if (i == 12) {
//                str = params.get("${totalCount3}").toString();
//                font.setStyle(Font.NORMAL);
//            } else if (i == 13) {
//                str = QuestionTypeEnum.KEY_VERIFICATION.getName();
//                cell.setRowspan(3);
//            } else if (i == 14) {
//                str = "河道内有蓝藻爆发";
//                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
//                font.setStyle(Font.NORMAL);
//            } else if (i == 15) {
//                str = params.get("${totalCount4}").toString();
//                font.setStyle(Font.NORMAL);
//            } else if (i == 16) {
//                str = "水生动、植物死亡";
//                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
//                font.setStyle(Font.NORMAL);
//            } else if (i == 17) {
//                str = params.get("${totalCount5}").toString();
//                font.setStyle(Font.NORMAL);
//            } else if (i == 18) {
//                str = "河道有违规阻水物";
//                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
//                font.setStyle(Font.NORMAL);
//            } else if (i == 19) {
//                str = params.get("${totalCount6}").toString();
//                font.setStyle(Font.NORMAL);
//            } else if (i == 20) {
//                str = "二";
//                cell.setRowspan(4);
//            } else if (i == 21) {
//                str = QuestionNameEnum.WATER_FRONT.getName();
//                cell.setRowspan(4);
//            } else if (i == 22) {
//                str = QuestionTypeEnum.DAILY_MONITORING.getName();
//                cell.setRowspan(3);
//            } else if (i == 23) {
//                str = "河道养护范围内种菜";
//                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
//                font.setStyle(Font.NORMAL);
//            } else if (i == 24) {
//                str = params.get("${totalCount7}").toString();
//                font.setStyle(Font.NORMAL);
//            } else if (i == 25) {
//                str = "河堤、栏杆等设施有损坏";
//                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
//                font.setStyle(Font.NORMAL);
//            } else if (i == 26) {
//                str = params.get("${totalCount8}").toString();
//                font.setStyle(Font.NORMAL);
//            } else if (i == 27) {
//                str = "岸坡有垃圾";
//                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
//                font.setStyle(Font.NORMAL);
//            } else if (i == 28) {
//                str = params.get("${totalCount9}").toString();
//                font.setStyle(Font.NORMAL);
//            } else if (i == 29) {
//                str = QuestionTypeEnum.KEY_VERIFICATION.getName();
//            } else if (i == 30) {
//                str = "河道蓝线内（岸上）新增违法建筑或构造物";
//                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
//                font.setStyle(Font.NORMAL);
//            } else if (i == 31) {
//                str = params.get("${totalCount10}").toString();
//                font.setStyle(Font.NORMAL);
//            } else if (i == 32) {
//                str = "三";
//            } else if (i == 33) {
//                str = QuestionNameEnum.WATER_QUALITY.getName();
//            } else if (i == 34) {
//                str = QuestionTypeEnum.DAILY_MONITORING.getName();
//            } else if (i == 35) {
//                str = "水体出现水质明显突变（感官、颜色）";
//                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
//                font.setStyle(Font.NORMAL);
//            } else if (i == 36) {
//                str = params.get("${totalCount11}").toString();
//                font.setStyle(Font.NORMAL);
//            } else if (i == 37) {
//                str = "四";
//                cell.setRowspan(2);
//            } else if (i == 38) {
//                str = QuestionNameEnum.OUTFALL.getName();
//                cell.setRowspan(2);
//            } else if (i == 39) {
//                str = QuestionTypeEnum.DAILY_MONITORING.getName();
//                cell.setRowspan(2);
//            } else if (i == 40) {
//                str = "入河、湖支流、泵站、入河排口晴天排放异常水体";
//                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
//                font.setStyle(Font.NORMAL);
//            } else if (i == 41) {
//                str = params.get("${totalCount12}").toString();
//                font.setStyle(Font.NORMAL);
//            } else if (i == 42) {
//                str = "存在排口";
//                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
//                font.setStyle(Font.NORMAL);
//            } else if (i == 43) {
//                str = params.get("${totalCount13}").toString();
//                font.setStyle(Font.NORMAL);
//            }
//            Paragraph p = new Paragraph(str, font);
//            cell.add(p);
//            table.addCell(cell);
//        }
        return table;
    }

    /**
     *
     * 构建巡检问题信息
     *
     */
    private Table buildInspectionFileTable(List<InspectionFile> inspectionFileList) throws DocumentException, IOException {
        Table table = new Table(2); //生成一表格
        table.setOffset(1f);
        int width2[] = {1, 1};
        table.setWidths(width2);    //设置系列所占比例
        table.setWidth(100);
        table.setAutoFillEmptyCells(true);

        InspectionFile inspectionFile;
        Font font = new Font();
        font.setSize(10.5f);
        for (int i = 0; i < inspectionFileList.size(); i++) {
            inspectionFile = inspectionFileList.get(i);
            for (int j = 0; j < 7; j++) {
                Cell cell = new Cell();
                cell.setVerticalAlignment(Element.ALIGN_CENTER);    // 设置单元格的垂直对齐方式 ： 居中
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);   // 设置单元格的水平对齐方式 ：居中对齐
                String str = "";
                if (j == 0) {
                    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                    font.setSize(12);
                    str = " 问题" + (i + 1);
                    cell.add(new Paragraph(str, font));
                    cell.setColspan(2);
                    font.setStyle(Font.BOLD);
                } else if (j == 1) {
                    str = " 坐标";
                    cell.add(new Paragraph(str, font));
                } else if (j == 2) {
                    str = inspectionFile.getLongitude() + "," + inspectionFile.getLatitude();
                    cell.add(new Paragraph(str, font));
                } else if (j == 3) {
                    str = " 问题描述";
                    cell.add(new Paragraph(str, font));
                } else if (j == 4) {
                    str = inspectionFile.getQuestionDesc();
                    cell.add(new Paragraph(str, font));
                } else if (j == 5) {
                    str = " 问题图片";
                    cell.add(new Paragraph(str, font));
                } else if (j == 6) {
                    Image image = null;
                    String url = CommonConfig.imageURL + inspectionFile.getFileThumbnail();
                    url = "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic1.win4000.com%2Fwallpaper%2Ff%2F57a42b9002e19.jpg&refer=http%3A%2F%2Fpic1.win4000.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1673509195&t=57d6710dc11bdd1ff75f5121a7d6c73f";

                    if (new UrlResource(url).exists()) {
                        image = Image.getInstance(url);
                        image.setAlignment(Image.ALIGN_CENTER);
                        image.scalePercent(100); //依照比例缩放
                        image.setAbsolutePosition(400, 600);
                        image.scaleToFit(300, 300);//自定义大
                    } else {
                        log.error("图片不存在！" + url);
                    }
                    if (new UrlResource(url).exists()) {
                        cell.add(image);
                    } else {
                        cell.add(new Paragraph(""));
                    }
                }
                table.addCell(cell);
            }
        }
        return table;
    }

    /**
     *
     * 构建巡检问题信息
     *
     */
    private Table buildInspectionFileTable2() throws DocumentException, IOException {
        Table table = new Table(2); //生成一表格
        table.setOffset(1f);
        int width4[] = {1, 2};
        table.setWidths(width4);//设置系列所占比例
        table.setWidth(100);
        table.setAutoFillEmptyCells(true);
        for (int i = 0; i < 8; i++) {
            Cell cell = new Cell();
            String str = "";
            Font font = new Font();
            font.setSize(10.5f);
            cell.setVerticalAlignment(Element.ALIGN_CENTER);
//            if (i == 0) {
//                font.setSize(12);
//                str = " 问题" + (i + 1);
//                cell.add(new Paragraph(str, font));
//                cell.setColspan(2);
//                font.setStyle(Font.BOLD);
//            } else if (i == 1) {
//                str = " 坐标";
//                cell.add(new Paragraph(str, font));
//            } else if (i == 2) {
//                str = report.getImageList().get(i).getLongitude() + "," + reportInfoVo.getImageList().get(i).getLatitude();
//                cell.add(new Paragraph(str, font));
//            } else if (i == 3) {
//                str = " 问题描述";
//                cell.add(new Paragraph(str, font));
//            } else if (i == 4) {
//                str = reportInfoVo.getImageList().get(i).getContent();
//                cell.add(new Paragraph(str, font));
//            } else if (i == 5) {
//                str = " 问题图片";
//                cell.add(new Paragraph(str, font));
//            } else if (i == 6) {
//                Image image = null;
//                String url = CommonConfig.imageURL + reportInfoVo.getImageList().get(i).getFileImage();
//                if (new UrlResource(url).exists()) {
//                    image = Image.getInstance(url);
//                    image.setAlignment(Image.ALIGN_CENTER);
//                    image.scalePercent(100); //依照比例缩放
//                    image.setAbsolutePosition(400, 600);
//                    image.scaleToFit(300, 300);//自定义大
//                } else {
//                    log.error("图片不存在！" + url);
//                }
//                if (new UrlResource(url).exists()) {
//                    cell.add(image);
//                } else {
//                    cell.add(new Paragraph(""));
//                }
//            } else if (i == 7) {
//                str = " 处理结果";
//                cell.add(new Paragraph(str, font));
//                cell.setColspan(2);
//                font.setStyle(Font.BOLD);
//            } else if (i == 8) {
//                str = " 处理人";
//                cell.add(new Paragraph(str, font));
//            } else if (i == 9) {
//                str = inspectionFileInfoVo.getHanderName();
//                cell.add(new Paragraph(str, font));
//            } else if (j == 10) {
//                str = " 处理时间";
//                cell.add(new Paragraph(str, font));
//            } else if (j == 11) {
//                str = inspectionFileInfoVo.getHandTime();
//                cell.add(new Paragraph(str, font));
//            } else if (j == 12) {
//                str = " 备注";
//                cell.add(new Paragraph(str, font));
//            } else if (j == 13) {
//                str = inspectionFileInfoVo.getHandContent();
//                cell.add(new Paragraph(str, font));
//            } else if (j == 14) {
//                String[] handUrls = inspectionFileInfoVo.getHandImg().split(",");
//                for (int k = 0; k < handUrls.length; k++) {
//                    cell = new Cell();
//                    cell.setVerticalAlignment(Element.ALIGN_CENTER);
//                    if (handUrls.length == 1) {
//                        cell.add(new Paragraph(" 结果图片", font));
//                    } else {
//                        cell.add(new Paragraph(" 结果图片" + (k + 1), font));
//                    }
//                    table.addCell(cell);
//                    cell = new Cell();
//                    Image image = null;
//                    String url = CommonConfig.imageURL + handUrls[k];
//                    if (new UrlResource(url).exists()) {
//                        image = Image.getInstance(url);
//                        image.setAlignment(Image.ALIGN_CENTER);
//                        image.scalePercent(100); //依照比例缩放
//                        image.setAbsolutePosition(400, 600);
//                        image.scaleToFit(300, 300);//自定义大
//                    } else {
//                        System.out.println("图片不存在！" + url);
//                    }
//                    if (new UrlResource(url).exists()) {
//                        cell.add(image);
//                    } else {
//                        cell.add(new Paragraph(""));
//                    }
//                    table.addCell(cell);
//                }
//            }
            if (i != 14) {
                table.addCell(cell);
            }
        }
        return table;
    }
}
