easypoi导出excel时导出图片

    /**
     * 将本地图片读取为字节流
     *
     * @param imagePath
     * @return
     * @throws IOException
     */
    public static byte[] readImageAsBytes(String imagePath) throws IOException {
        File file = new File(imagePath);
        try (InputStream inputStream = new FileInputStream(file)) {
            byte[] buffer = new byte[(int) file.length()];
            inputStream.read(buffer);
            return buffer;
        }
    }
 @Override
    public void exportXls(HttpServletResponse response, SeracherParam searchParamer) throws IOException {
        //拼接产地、等级、年份
        String leafInfo = searchParamer.getLeafInfo();
        if (StringUtils.isNotBlank(leafInfo)) {
            SerchConditionUtils.getSearch(leafInfo, searchParamer);
        }
        List<String> idList = new ArrayList<>();
        if (null != searchParamer.getSelections()) {
            idList = Arrays.asList(searchParamer.getSelections().split(","));
        }
        List<ExportVo> exportList = this.baseMapper.exportList(searchParamer, idList);
        exportList = exportList.stream()
                .collect(Collectors.collectingAndThen(Collectors.toCollection(
                        () -> new TreeSet<>(Comparator.comparing(ExportVo::getCheckNo))), ArrayList::new));
        for (ExportVo exportVo : exportList) {
            List<ExportTackRecordVo> exportInfo = itCheckRecordService.getExportInfo(exportVo.getId());
            for (ExportTackRecordVo exportTackRecordVo : exportInfo) {
                if (null != exportTackRecordVo.getPicture() || StringUtils.isNotEmpty(exportTackRecordVo.getPicture())) {
                    byte[] bytes = readImageAsBytes(upLoadPath + "/" + exportTackRecordVo.getPicture());
                    exportTackRecordVo.setImageBytes(bytes);
                }
            }
            exportVo.setExportTackRecordVoList(exportInfo);
        }
        ExportParamerUtils.createExportParamer(response, "抽检记录", ExportVo.class, exportList);
    }
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.jeecg.common.aspect.annotation.Dict;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.jeecgframework.poi.excel.annotation.ExcelCollection;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.List;

@Data
public class ExportVo {
    /**
     * 主键id
     */
    @TableId(type = IdType.ASSIGN_ID)
    @ApiModelProperty(value = "主键id")
    private java.lang.String id;
    private java.lang.String trcId;
    /**
     * 抽检编号
     */
    @Excel(name = "抽检编号", width = 15,needMerge = true)
    @ApiModelProperty(value = "抽检编号")
    private java.lang.String checkNo;
    /**
     * 抽检时间
     */
    @Excel(name = "抽检时间", width = 15,needMerge = true, format = "yyyy-MM-dd")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @ApiModelProperty(value = "抽检时间")
    private java.util.Date checkTime;
    /**
     * 存货编码
     */
    @Excel(name = "存货编码", width = 15,needMerge = true)
    @ApiModelProperty(value = "存货编码")
    private java.lang.String stockNo;
    /**
     * 产地
     */
    @Excel(name = "产地", width = 15,needMerge = true)
    @ApiModelProperty(value = "产地")
    private java.lang.String producer;

    /**
     * 年份
     */
    @Excel(name = "年份", width = 15,needMerge = true)
    @ApiModelProperty(value = "年份")
    private java.lang.String year;

    /**
     * 等级
     */
    @Excel(name = "等级", width = 15,needMerge = true)
    @ApiModelProperty(value = "等级")
    private java.lang.String grade;

    /**
     * 抽检类型 1入库 2 在库 3出库
     */
    @Dict(dicCode = "samplingType")
    @Excel(name = "抽检类型", width = 15,needMerge = true,dicCode = "samplingType")
    @ApiModelProperty(value = "抽检类型 1入库 2 在库 3出库")
    private java.lang.String type;
    /**
     * 来料类型
     */
    @Dict(dicCode = "materialType")
    @Excel(name = "来料类型", width = 15,needMerge = true,dicCode = "materialType")
    @ApiModelProperty(value = "来料类型")
    private java.lang.String inType;

    @ExcelCollection(name = "")
    private List<ExportTackRecordVo> exportTackRecordVoList;
    /**
     * 是否复检
     */
    @Dict(dicCode = "repeatFlag")
    @Excel(name = "是否复检", width = 15,needMerge = true,dicCode = "repeatFlag")
    @ApiModelProperty(value = "是否复检")
    private java.lang.String repeatFlag;
    /**
     * 复检时间
     */
    @Excel(name = "计划复检时间", width = 15,needMerge = true, format = "yyyy-MM-dd")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @ApiModelProperty(value = "计划复检时间")
    private java.util.Date repeatTime;
    /**
     * 复检状态
     */
    @Dict(dicCode = "repCheckStatus")
    @Excel(name = "复检状态", width = 15,needMerge = true,dicCode = "repCheckStatus")
    @ApiModelProperty(value = "复检状态")
    private java.lang.String repCheckStatus;
    /**
     * 抽检状态
     */
    @Dict(dicCode = "samplingState")
    @Excel(name = "抽检状态", width = 15,needMerge = true,dicCode = "samplingState")
    @ApiModelProperty(value = "抽检状态")
    private java.lang.String checkStatus;
    /**
     * 抽检人
     */
    @Excel(name = "抽检人", width = 15,needMerge = true)
    @ApiModelProperty(value = "抽检人")
    private java.lang.String checkBy;

    /**
     * 备注
     */
    @Excel(name = "备注", width = 15,needMerge = true)
    @ApiModelProperty(value = "备注")
    private java.lang.String remark;
}

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.jeecg.common.aspect.annotation.Dict;
import org.jeecgframework.poi.excel.annotation.Excel;

@Data
public class ExportTackRecordVo {
    /**
     * 箱号
     */
    @Excel(name = "箱号", width = 15)
    @ApiModelProperty(value = "箱号")
    private java.lang.String boxNo;

//    /**
//     * 货位
//     */
//    @Excel(name = "货位", width = 15)
//    @ApiModelProperty(value = "货位")
//    private java.lang.String boxNo;

    /**
     * 总分
     */
    @Excel(name = "总分", width = 15)
    @ApiModelProperty(value = "总分")
    private java.lang.String totalScore;

    /**
     * 虫情
     */
    @Dict(dicCode = "insectSituation")
    @Excel(name = "虫情", width = 15,dicCode = "insectSituation")
    @ApiModelProperty(value = "虫情")
    private java.lang.String pest;
    /**
     * 霉变
     */
    @Dict(dicCode = "mildew")
    @Excel(name = "霉变", width = 15,dicCode = "mildew")
    @ApiModelProperty(value = "霉变")
    private java.lang.String mildew;
    /**
     * 水份%
     */
    @Dict(dicCode = "moistureContent")
    @Excel(name = "水份%", width = 15,dicCode = "moistureContent")
    @ApiModelProperty(value = "水份%")
    private java.lang.Double water;
    /**
     * 包装
     */
    @Dict(dicCode = "appearance")
    @Excel(name = "包装", width = 15,dicCode = "appearance")
    @ApiModelProperty(value = "包装")
    private java.lang.String appearance;
    /**
     * 包温
     */
    @Dict(dicCode = "packageTemp")
    @Excel(name = "包温", width = 15,dicCode = "packageTemp")
    @ApiModelProperty(value = "包温")
    private java.lang.String temperature;
    /**
     * 图片
     */
//    @Excel(name = "图片", type = 2, width = 20, height = 20, imageType = 1)
    private java.lang.String picture;
    @Excel(name = "图片", type = 2, width = 20, height = 20,imageType = 2)
    private byte[] imageBytes;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值