流程手册横竖表样式规范、流程图分页展示处理
This commit is contained in:
parent
e2ca6bcf72
commit
dbdf20b00f
Binary file not shown.
@ -94,7 +94,7 @@ public class Report1Gener {
|
||||
OutputAppProfile appModel = OutputAppManager.getProfile(model.getProfileId());
|
||||
String tempPath = appModel.getAppContext().getPath();
|
||||
//String tempName = "步骤横表-流程手册.xml";
|
||||
String tempName = "步骤横表-流程手册2.xml";
|
||||
String tempName = "步骤横表-流程手册3.xml";
|
||||
log.info("begin...");
|
||||
log.info("-------------------");
|
||||
// ----文件处理-----
|
||||
|
||||
@ -90,7 +90,7 @@ public class Report2Gener {
|
||||
// ----预处理、校验----
|
||||
OutputAppProfile appModel = OutputAppManager.getProfile(model.getProfileId());
|
||||
String tempPath = appModel.getAppContext().getPath();
|
||||
String tempName = "步骤竖表-流程手册2.xml";
|
||||
String tempName = "步骤竖表-流程手册3.xml";
|
||||
log.info("begin...");
|
||||
log.info("-------------------");
|
||||
// ----文件处理-----
|
||||
|
||||
@ -0,0 +1,45 @@
|
||||
package com.actionsoft.apps.coe.pal.output.pr.util;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.CropImageFilter;
|
||||
import java.awt.image.FilteredImageSource;
|
||||
import java.awt.image.ImageFilter;
|
||||
import java.io.File;
|
||||
|
||||
public class ImageUtil {
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 图像切割(按指定起点坐标和宽高切割)
|
||||
* @param srcImg 源图像地址
|
||||
* @param outImg 切片后的图像地址
|
||||
* @param x 目标切片起点坐标X
|
||||
* @param y 目标切片起点坐标Y
|
||||
* @param width 目标切片宽度
|
||||
* @param height 目标切片高度
|
||||
* @param imageType 图片类型
|
||||
*/
|
||||
public static void cut(File srcImg, File outImg, int x, int y, int width, int height, String imageType) throws Exception{
|
||||
//读取源图像
|
||||
BufferedImage bi = ImageIO.read(srcImg);
|
||||
int srcWidth = bi.getWidth();//源图宽度
|
||||
int srcHeight = bi.getHeight();//源图高度
|
||||
if (srcWidth > 0 && srcHeight > 0) {
|
||||
Image image = bi.getScaledInstance(srcWidth, srcHeight,Image.SCALE_DEFAULT);
|
||||
//四个参数分别为图像起点坐标和宽高
|
||||
//即:CropImageFilter(int x,int y,int width,int height)
|
||||
ImageFilter cropFilter = new CropImageFilter(x, y, width,height);
|
||||
Image img = Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(image.getSource(), cropFilter));
|
||||
BufferedImage tag = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);
|
||||
Graphics g = tag.getGraphics();
|
||||
g.drawImage(img, 0, 0, width, height, null);//绘制切割后的图
|
||||
g.dispose();
|
||||
//输出为文件
|
||||
ImageIO.write(tag, imageType, outImg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
package com.actionsoft.apps.coe.pal.output.pr.util;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
@ -14,12 +15,14 @@ import com.actionsoft.apps.coe.pal.pal.manage.publish.dao.PublishListHistory;
|
||||
import com.actionsoft.apps.coe.pal.pal.output.util.OutputWordUtil;
|
||||
import com.actionsoft.apps.coe.pal.pal.repository.PALRepositoryQueryAPIManager;
|
||||
import com.actionsoft.apps.coe.pal.pal.repository.model.PALRepositoryModel;
|
||||
import com.actionsoft.apps.coe.pal.pal.repository.upfile.constant.CoeFileConstant;
|
||||
import com.actionsoft.apps.coe.pal.pal.repository.util.CoeProcessLevelUtil;
|
||||
import com.actionsoft.apps.resource.plugin.profile.DCPluginProfile;
|
||||
import com.actionsoft.bpms.org.cache.UserCache;
|
||||
import com.actionsoft.bpms.util.Base64;
|
||||
import com.actionsoft.bpms.util.UtilDate;
|
||||
import com.actionsoft.bpms.util.UtilFile;
|
||||
import com.actionsoft.bpms.util.UtilString;
|
||||
import com.actionsoft.bpms.server.DispatcherRequest;
|
||||
import com.actionsoft.bpms.server.fs.DCContext;
|
||||
import com.actionsoft.bpms.server.fs.dc.DCProfileManager;
|
||||
import com.actionsoft.bpms.util.*;
|
||||
import com.actionsoft.sdk.local.SDK;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
@ -121,7 +124,10 @@ public class PrReportComment {
|
||||
dataMap.put(OutputWordUtil.PL_RESPONSIBLE_DEPARTMENT, relationDept); // 责任部门
|
||||
|
||||
// 流程图
|
||||
|
||||
double px = (double)(4/3);
|
||||
int prMaxWidth = (int)(472*px);// 固定宽度
|
||||
int prMaxHeight = (int)(650*px);// 固定高度
|
||||
|
||||
String diagram = "";
|
||||
// 流程图
|
||||
int newWidth = 0;
|
||||
@ -131,42 +137,86 @@ public class PrReportComment {
|
||||
if (UtilString.isEmpty(imageFilePath)) {
|
||||
imageFilePath = photo;
|
||||
}
|
||||
JSONArray imageArr = new JSONArray();
|
||||
UtilFile utilFile = new UtilFile(imageFilePath);
|
||||
if (utilFile != null && utilFile.exists()) {
|
||||
byte[] base64Bytes = Base64.encode(utilFile.readBytes());
|
||||
diagram = new String(base64Bytes);
|
||||
// 计算流程图片页数
|
||||
try {
|
||||
BufferedImage sourceImg = ImageIO.read(new FileInputStream(utilFile));
|
||||
int width = sourceImg.getWidth();
|
||||
int height = sourceImg.getHeight();
|
||||
// 如果宽高比大于最大值的宽高比,说明图形较宽,需判断宽度是否大于最大值
|
||||
if (width / height > OutputWordUtil.PL_DIAGRAM_MAX_WIDTH / OutputWordUtil.PL_DIAGRAM_MAX_HEIGHT) {
|
||||
if (width > OutputWordUtil.PL_DIAGRAM_MAX_WIDTH) {
|
||||
newWidth = OutputWordUtil.PL_DIAGRAM_MAX_WIDTH;
|
||||
newHeight = height * OutputWordUtil.PL_DIAGRAM_MAX_WIDTH / width;
|
||||
} else {
|
||||
newWidth = width;
|
||||
newHeight = height;
|
||||
// System.out.println("A4宽高:" + "宽:" + prMaxWidth + " 高:" + prMaxHeight);
|
||||
// System.out.println("图片宽高:" + "宽:" + width + " 高:" + height);
|
||||
double zoom = prMaxWidth >= width ? 1 : (double) prMaxWidth/width;// 放大缩小比例
|
||||
// System.out.println("缩小比例:" + zoom);
|
||||
newWidth = (int)(width * zoom);// 占用文档宽度
|
||||
int zoomHeight = (int)(height * zoom);// 缩放后的高度
|
||||
// 计算页数
|
||||
int page = zoomHeight / prMaxHeight + (zoomHeight % prMaxHeight != 0 ? 1 : 0);// 图片要切割成的页数
|
||||
if (page <= 1) {// 只有一页
|
||||
JSONObject object = new JSONObject();
|
||||
newHeight = zoomHeight;
|
||||
byte[] base64Bytes = Base64.encode(utilFile.readBytes());
|
||||
diagram = new String(base64Bytes);
|
||||
object.put("diagram", diagram);
|
||||
object.put("height", newHeight);
|
||||
object.put("width", newWidth);
|
||||
object.put("id", UUIDGener.getUUID());
|
||||
imageArr.add(object);
|
||||
} else {// 存在多页,进行切割
|
||||
// dc
|
||||
DCContext dcContext = null;
|
||||
DCPluginProfile dcProfile = DCProfileManager.getDCProfile("com.actionsoft.apps.coe.pal.output.pr", "tmp");
|
||||
dcContext = new DCContext(DispatcherRequest.getUserContext(), dcProfile, "com.actionsoft.apps.coe.pal.output.pr", "cutImage", UUIDGener.getUUID());
|
||||
String path = dcContext.getPath();
|
||||
File file = new File(path);
|
||||
if (!file.exists()) {
|
||||
file.mkdirs();
|
||||
}
|
||||
} else {// 如果宽高比小于最大值的宽高比,说明图形较高,需判断高度是否大于最大值
|
||||
if (height > OutputWordUtil.PL_DIAGRAM_MAX_HEIGHT) {
|
||||
newWidth = width * OutputWordUtil.PL_DIAGRAM_MAX_HEIGHT / height;
|
||||
newHeight = OutputWordUtil.PL_DIAGRAM_MAX_HEIGHT;
|
||||
} else {
|
||||
newWidth = width;
|
||||
newHeight = height;
|
||||
String type = utilFile.getName().substring(utilFile.getName().lastIndexOf(".") + 1);
|
||||
int posY = 0;
|
||||
for (int i = 1; i <= page; i++) {
|
||||
// System.out.println("截取第" + i + "页");
|
||||
String imgName = getNoStr(i) + "." + type;
|
||||
UtilFile img = new UtilFile(path + File.separator + imgName);
|
||||
img.createNewFile();
|
||||
int height2;
|
||||
if (i == page) {// 最后一页
|
||||
height2 = height - (i - 1 ) * ((int)(prMaxHeight / zoom));
|
||||
} else {// 非最后一页
|
||||
height2 = (int)(prMaxHeight / zoom);
|
||||
}
|
||||
// System.out.println("截取第" + i + "页高度:" + height2);
|
||||
// System.out.println("截取第" + i + "页y坐标:" + posY);
|
||||
// System.out.println("截取第" + i + "页宽度:" + width);
|
||||
|
||||
try {
|
||||
ImageUtil.cut(utilFile, img, 0, posY, width, height2, type);
|
||||
// ImageUtil.cut(utilFile, img, 0, 0, 4800, 2000, type);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
posY += height2;
|
||||
BufferedImage image = ImageIO.read(img);
|
||||
JSONObject object = new JSONObject();
|
||||
byte[] base64Bytes = Base64.encode(img.readBytes());
|
||||
object.put("diagram", new String(base64Bytes));
|
||||
object.put("height", image.getHeight()*zoom/px);
|
||||
object.put("width", image.getWidth()*zoom/px);
|
||||
object.put("id", UUIDGener.getUUID());
|
||||
imageArr.add(object);
|
||||
}
|
||||
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
dataMap.put("diagramArr", imageArr);
|
||||
}
|
||||
|
||||
dataMap.put(OutputWordUtil.PL_DIAGRAM, diagram);
|
||||
dataMap.put(OutputWordUtil.PL_DIAGRAM_WIDTH, String.valueOf(newWidth));
|
||||
dataMap.put(OutputWordUtil.PL_DIAGRAM_HEIGHT, String.valueOf(newHeight));
|
||||
private String getNoStr(int no) {
|
||||
return no <= 0 ? (no + "") : no < 10 ? ("0" + no) : (no + "");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user