| | |
| | | import com.deepoove.poi.data.Pictures; |
| | | import com.deepoove.poi.policy.PictureRenderPolicy; |
| | | import com.deepoove.poi.render.RenderContext; |
| | | import com.product.common.lang.StringUtils; |
| | | import com.product.core.dao.BaseDao; |
| | | import com.product.core.entity.FieldSetEntity; |
| | | import com.product.core.spring.context.SpringMVCContextHolder; |
| | | import com.product.file.service.FileManagerService; |
| | | import com.product.print.config.CmnCode; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | |
| | | public PictureRenderData cast(Object source) throws Exception { |
| | | FileManagerService fileManagerService = SpringUtil.getBean(FileManagerService.class); |
| | | String templateUid = source.toString(); |
| | | if (StringUtils.isEmpty(templateUid)) { |
| | | return null; |
| | | } |
| | | int width = 0; |
| | | int height = 0; |
| | | if (templateUid.contains(" ")) { |
| | | String[] infoArr = templateUid.split(" "); |
| | | templateUid = infoArr[0]; |
| | | width = Integer.parseInt(infoArr[1]); |
| | | height = Integer.parseInt(infoArr[2]); |
| | | } |
| | | BaseDao baseDao = SpringUtil.getBean(BaseDao.class); |
| | | FieldSetEntity attachmentFse = baseDao.getFieldSetEntity("product_sys_attachments", templateUid, false); |
| | | fileManagerService.getFile(templateUid); |
| | | |
| | | // 遇错跳过,默认使用透明背景不拦截,记录日志到文件 |
| | | try { |
| | | fileManagerService.getFile(templateUid); |
| | | } catch (Exception e) { |
| | | attachmentFse = baseDao.getFieldSetEntityByFilter("product_sys_attachments", "attachment_title=?", new Object[]{"sys_sp_deal_透明背景"}, false); |
| | | fileManagerService.getFile(attachmentFse.getUUID()); |
| | | SpringMVCContextHolder.getSystemLogger().error(String.format("%s-附件uuid:%s", CmnCode.EXISTS_FILE_RECORD_BUT_NO_FILE.getText(), templateUid)); |
| | | } |
| | | |
| | | String fileName = attachmentFse.getString("file_name"); |
| | | String type = fileName.substring(fileName.lastIndexOf(".") + 1); |
| | | File file = fileManagerService.getFile(attachmentFse); |
| | |
| | | } else if ("svg".equals(type)) { |
| | | imgType = PictureType.SVG; |
| | | } |
| | | return converter.convert(Pictures.ofStream(new FileInputStream(file), imgType).create()); |
| | | if (width > 0 && height > 0) { |
| | | return converter.convert(Pictures.ofStream(new FileInputStream(file), imgType).size(width, height).create()); |
| | | } else { |
| | | return converter.convert(Pictures.ofStream(new FileInputStream(file), imgType).create()); |
| | | } |
| | | } |
| | | |
| | | @Override |