List<CouponCodeExchangeListVO> list;
public ExportCouponCodeTask(List<CouponCodeExchangeListVO> list){
this.list = list;
}
@
Override public List<CouponCodeExchangeListExcelVO> call() throws Exception {
log.info("执行任务");
List<CouponCodeExchangeListExcelVO> couponCodeExchangeListExcelVOS = new ArrayList<>();
for (CouponCodeExchangeListVO couponCodeExchangeListVO : list) {
CouponCodeExchangeListExcelVO couponCodeExchangeListExcelVO = new CouponCodeExchangeListExcelVO();
BeanUtils.copyProperties(couponCodeExchangeListVO, couponCodeExchangeListExcelVO);
couponCodeExchangeListExcelVO.setByteArray(generateJpg(couponCodeExchangeListVO.getQrCodeUrl(), 500, 500));
if (StringUtils.isNotBlank(couponCodeExchangeListVO.getSuWxSubscribe())){
couponCodeExchangeListExcelVO.setSuWxSubscribe(couponCodeExchangeListVO.getSuWxSubscribe().split(":")[1]);
}
if (StringUtils.isNotBlank(couponCodeExchangeListVO.getEnterpriseWechat())){
couponCodeExchangeListExcelVO.setEnterpriseWechat(couponCodeExchangeListVO.getEnterpriseWechat().split(":")[1]);
}
couponCodeExchangeListExcelVOS.add(couponCodeExchangeListExcelVO);
}
return couponCodeExchangeListExcelVOS;
}
private static byte[] generateJpg(String content, int width, int height) {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
generate(content, width, height, ImgUtil.IMAGE_TYPE_JPG, out);
return out.toByteArray();
}