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 {
@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;
@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 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;
private java.lang.String picture;
@Excel(name = "图片", type = 2, width = 20, height = 20,imageType = 2)
private byte[] imageBytes;
}