提交 e1d590ce 编写于 作者: O o2sword

签批4

上级 02147dca
......@@ -243,6 +243,7 @@ class ActionHtmlToImage extends BaseAction {
page.navigate("file:///Users/chengjian/dev/temp/test.html");
Page.ScreenshotOptions screenshotOptions = new Page.ScreenshotOptions();
screenshotOptions.setFullPage(true);
screenshotOptions.setClip(0,0, 800, 2310);
//screenshotOptions.setQuality(2);
screenshotOptions.setPath(Paths.get("/Users/chengjian/dev/temp/screenshot-" + browserType.name() + ".png"));
page.screenshot(screenshotOptions);
......
package com.x.processplatform.assemble.surface.jaxrs.sign;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.microsoft.playwright.*;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.exception.ExceptionAccessDenied;
import com.x.base.core.project.exception.ExceptionEntityNotExist;
import com.x.base.core.project.exception.ExceptionFieldEmpty;
......@@ -13,12 +16,20 @@ import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WoId;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.DateTools;
import com.x.base.core.project.tools.FileTools;
import com.x.base.core.project.tools.ListTools;
import com.x.processplatform.assemble.surface.Business;
import com.x.processplatform.core.entity.content.DocSign;
import com.x.processplatform.core.entity.content.DocSignScrawl;
import com.x.processplatform.core.entity.content.Task;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.omg.CORBA.ExceptionDefPOA;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
......@@ -32,8 +43,8 @@ class ActionSave extends BaseAction {
if(wi.getStatus() == null){
throw new ExceptionFieldEmpty(DocSign.status_FIELDNAME);
}
if(wi.getStatus().equals(DocSign.STATUS_3) && StringUtils.isBlank(wi.getContent())){
throw new ExceptionFieldEmpty("content");
if(wi.getStatus().equals(DocSign.STATUS_3) && StringUtils.isBlank(wi.getHtmlContent())){
throw new ExceptionFieldEmpty("htmlContent");
}
Task task = null;
Wo wo = new Wo();
......@@ -55,6 +66,7 @@ class ActionSave extends BaseAction {
private String saveDocSign(Wi wi, Task task) throws Exception{
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
boolean flag = false;
emc.beginTransaction(DocSign.class);
DocSign docSign = emc.firstEqual(DocSign.class, DocSign.taskId_FIELDNAME, task.getId());
if(docSign == null) {
flag = true;
......@@ -63,18 +75,84 @@ class ActionSave extends BaseAction {
}
docSign.getProperties().setInputList(wi.getInputList());
docSign.getProperties().setScrawlList(wi.getScrawlList());
if(!wi.getStatus().equals(DocSign.STATUS_1)){
if(wi.getStatus().equals(DocSign.STATUS_2)){
docSign.setCommitTime(new Date());
emc.beginTransaction(DocSignScrawl.class);
emc.deleteEqual(DocSignScrawl.class, DocSignScrawl.signId_FIELDNAME, docSign.getId());
if(ListTools.isNotEmpty(wi.getScrawlList())){
for (String data : wi.getScrawlList()){
JsonObject jsonObject = gson.fromJson(data, JsonObject.class);
DocSignScrawl signScrawl = new DocSignScrawl(docSign, data, null);
if(jsonObject.has("src")){
signScrawl.setType(DocSignScrawl.SCRAWL_TYPE_BASE64);
}
emc.persist(signScrawl);
}
}
}else if(wi.getStatus().equals(DocSign.STATUS_3)){
docSign.setCommitTime(new Date());
}
if(flag){
emc.persist(docSign);
}
emc.commit();
return docSign.getId();
}
}
private void html2Img(DocSign docSign, Wi wi, EntityManagerContainer emc) throws Exception{
String html = wi.getHtmlContent();
if (html.toLowerCase().indexOf("<html") == -1) {
html = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></head><body>" + html + "</body></html>";
}
String name = StringUtils.split(docSign.getPerson(),"@")[0] + docSign.getTaskId() + ".png";
byte[] bytes = null;
try (Playwright playwright = Playwright.create()) {
List<BrowserType> browserTypes = Arrays.asList(
playwright.chromium(),
playwright.firefox(),
playwright.webkit()
);
for (BrowserType browserType : browserTypes) {
BrowserType.LaunchOptions options = new BrowserType.LaunchOptions();
options.setHeadless(true);
try (Browser browser = browserType.launch(options)) {
BrowserContext context = browser.newContext();
Page page = context.newPage();
page.setContent(html);
Page.ScreenshotOptions screenshotOptions = new Page.ScreenshotOptions();
screenshotOptions.setFullPage(true);
if(wi.getHtmlWidth()!=null && wi.getHtmlHeight()!=null){
screenshotOptions.setClip(0, 0, wi.getHtmlWidth(), wi.getHtmlHeight());
}
File tempDir = Config.dir_local_temp();
FileTools.forceMkdir(tempDir);
File file = new File(tempDir, name);
screenshotOptions.setPath(file.toPath());
page.screenshot(screenshotOptions);
bytes = FileUtils.readFileToByteArray(file);
break;
} catch (Exception e) {
logger.warn("Playwright user browser:{} error:{}",browserType.name(), e.getMessage());
}
}
}
if(bytes==null){
throw new IllegalStateException("签批转图片异常!");
}
return "";
}
public static class Wi extends GsonPropertyObject {
@FieldDescribe("状态:1(暂存)|2(签批正文不可以修改)|3(签批正文可以修改,正文保存为图片).")
private Integer status;
@FieldDescribe("包含签批的html正文后内容,状态为3时必传.")
private String content;
private String htmlContent;
@FieldDescribe("html宽度,允许为空.")
private Double htmlWidth;
@FieldDescribe("html宽度长度,允许为空.")
private Double htmlHeight;
@FieldDescribe("输入框列表.")
private List<String> inputList = new ArrayList<>();
@FieldDescribe("涂鸦列表.")
......@@ -88,12 +166,28 @@ class ActionSave extends BaseAction {
this.status = status;
}
public String getContent() {
return content;
public String getHtmlContent() {
return htmlContent;
}
public void setHtmlContent(String htmlContent) {
this.htmlContent = htmlContent;
}
public Double getHtmlWidth() {
return htmlWidth;
}
public void setHtmlWidth(Double htmlWidth) {
this.htmlWidth = htmlWidth;
}
public Double getHtmlHeight() {
return htmlHeight;
}
public void setContent(String content) {
this.content = content;
public void setHtmlHeight(Double htmlHeight) {
this.htmlHeight = htmlHeight;
}
public List<String> getInputList() {
......
......@@ -51,10 +51,12 @@ public class Attachment extends StorageObject {
private static final long serialVersionUID = -6564254194819206271L;
private static final String TABLE = PersistenceProperties.Content.Attachment.table;
@Override
public String getId() {
return id;
}
@Override
public void setId(String id) {
this.id = id;
}
......@@ -66,6 +68,7 @@ public class Attachment extends StorageObject {
/* 以上为 JpaObject 默认字段 */
@Override
public void onPersist() throws Exception {
this.extension = StringUtils.trimToEmpty(this.extension);
this.site = StringUtils.trimToEmpty(this.site);
......
package com.x.processplatform.core.entity.content;
import com.x.base.core.entity.AbstractPersistenceProperties;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.entity.SliceJpaObject;
import com.x.base.core.entity.StorageObject;
import com.x.base.core.entity.annotation.CheckPersist;
import com.x.base.core.entity.annotation.ContainerEntity;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.tools.DateTools;
import com.x.processplatform.core.entity.PersistenceProperties;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.openjpa.persistence.jdbc.Index;
import javax.persistence.*;
import java.util.Date;
/**
* 签批涂鸦列表
* 签批涂鸦信息
* @author sword
*/
@Entity
......@@ -22,12 +28,18 @@ import java.util.Date;
+ JpaObject.DefaultUniqueConstraintSuffix, columnNames = { JpaObject.IDCOLUMN,
JpaObject.CREATETIMECOLUMN, JpaObject.UPDATETIMECOLUMN, JpaObject.SEQUENCECOLUMN }) })
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class DocSignScrawl extends SliceJpaObject {
public class DocSignScrawl extends StorageObject {
private static final long serialVersionUID = -8648872600208475747L;
private static final String TABLE = PersistenceProperties.Content.DocSignScrawl.table;
public static String SCRAWL_TYPE_PLACEHOLDER = "placeholder";
public static String SCRAWL_TYPE_BASE64 = "base64";
public static String SCRAWL_TYPE_IMAGE = "image";
@Override
public String getId() {
return id;
......@@ -51,14 +63,132 @@ public class DocSignScrawl extends SliceJpaObject {
// nothing
}
public DocSignScrawl(DocSign docSign, String data) {
public DocSignScrawl(DocSign docSign, String data, String name) {
this.signId = docSign.getId();
this.job = docSign.getJob();
this.activity = docSign.getActivity();
this.activityName = docSign.getActivityName();
this.person = docSign.getPerson();
this.commitTime = new Date();
this.data = data;
this.type = SCRAWL_TYPE_PLACEHOLDER;
if(StringUtils.isNotBlank(name)){
this.lastUpdateTime = new Date();
this.name = name;
this.extension = StringUtils.lowerCase(FilenameUtils.getExtension(name));
}
}
@Override
public String path() {
String str = DateTools.format(this.getCreateTime(), DateTools.formatCompact_yyyyMMdd);
str += PATHSEPARATOR;
str += this.job;
str += PATHSEPARATOR;
str += this.id;
str += StringUtils.isEmpty(this.extension) ? "" : ("." + this.extension);
return str;
}
public static final String name_FIELDNAME = "name";
@FieldDescribe("文件名称,带扩展名的文件名.")
@Column(length = AbstractPersistenceProperties.processPlatform_name_length, name = ColumnNamePrefix
+ name_FIELDNAME)
@Index(name = TABLE + IndexNameMiddle + name_FIELDNAME)
@CheckPersist(allowEmpty = true, fileNameString = true)
private String name;
public static final String extension_FIELDNAME = "extension";
@FieldDescribe("扩展名。")
@Column(length = JpaObject.length_16B, name = ColumnNamePrefix + extension_FIELDNAME)
@CheckPersist(allowEmpty = true, fileNameString = true)
private String extension;
public static final String storage_FIELDNAME = "storage";
@FieldDescribe("关联的存储名称.")
@Column(length = JpaObject.length_64B, name = ColumnNamePrefix + storage_FIELDNAME)
@CheckPersist(allowEmpty = true, simplyString = true)
@Index(name = TABLE + IndexNameMiddle + storage_FIELDNAME)
private String storage;
public static final String length_FIELDNAME = "length";
@FieldDescribe("文件大小.")
@Column(name = ColumnNamePrefix + length_FIELDNAME)
@Index(name = TABLE + IndexNameMiddle + length_FIELDNAME)
@CheckPersist(allowEmpty = true)
private Long length;
public static final String lastUpdateTime_FIELDNAME = "lastUpdateTime";
@FieldDescribe("最后更新时间")
@Column(name = ColumnNamePrefix + lastUpdateTime_FIELDNAME)
@Index(name = TABLE + IndexNameMiddle + lastUpdateTime_FIELDNAME)
@CheckPersist(allowEmpty = true)
private Date lastUpdateTime;
public static final String deepPath_FIELDNAME = "deepPath";
@FieldDescribe("是否使用更深的路径.")
@CheckPersist(allowEmpty = true)
@Column(name = ColumnNamePrefix + deepPath_FIELDNAME)
@Index(name = TABLE + IndexNameMiddle + deepPath_FIELDNAME)
private Boolean deepPath;
@Override
public String getStorage() {
return storage;
}
@Override
public void setStorage(String storage) {
this.storage = storage;
}
@Override
public Long getLength() {
return length;
}
@Override
public void setLength(Long length) {
this.length = length;
}
@Override
public String getName() {
return name;
}
@Override
public void setName(String name) {
this.name = name;
}
@Override
public String getExtension() {
return extension;
}
@Override
public void setExtension(String extension) {
this.extension = extension;
}
@Override
public Date getLastUpdateTime() {
return lastUpdateTime;
}
@Override
public void setLastUpdateTime(Date lastUpdateTime) {
this.lastUpdateTime = lastUpdateTime;
}
@Override
public Boolean getDeepPath() {
return BooleanUtils.isTrue(this.deepPath);
}
@Override
public void setDeepPath(Boolean deepPath) {
this.deepPath = deepPath;
}
public static final String signId_FIELDNAME = "signId";
......@@ -102,17 +232,17 @@ public class DocSignScrawl extends SliceJpaObject {
@CheckPersist(allowEmpty = true)
private Date commitTime;
public static final String hasScrawlPic_FIELDNAME = "hasScrawlPic";
@FieldDescribe("是否有涂鸦图片")
@Column(name = ColumnNamePrefix + hasScrawlPic_FIELDNAME)
public static final String type_FIELDNAME = "type";
@FieldDescribe("涂鸦类型:placeholder(占位符)|base64(图片base64存储在data字段中)|image(图片存储在附件中)")
@Column(name = ColumnNamePrefix + type_FIELDNAME)
@CheckPersist(allowEmpty = true)
private Boolean hasScrawlPic = false;
private String type;
public static final String data_FIELDNAME = "data";
@FieldDescribe("涂鸦信息.")
@Lob
@Basic(fetch = FetchType.EAGER)
@Column(length = JpaObject.length_10M, name = ColumnNamePrefix + data_FIELDNAME)
@Column(length = JpaObject.length_20M, name = ColumnNamePrefix + data_FIELDNAME)
@CheckPersist(allowEmpty = true)
private String data;
......@@ -168,12 +298,12 @@ public class DocSignScrawl extends SliceJpaObject {
this.signId = signId;
}
public Boolean getHasScrawlPic() {
return hasScrawlPic;
public String getType() {
return type;
}
public void setHasScrawlPic(Boolean hasScrawlPic) {
this.hasScrawlPic = hasScrawlPic;
public void setType(String type) {
this.type = type;
}
public String getData() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册