1.增加外销合同上传附件 只校验 word格式存在标签;

2.增加框架合同上传附件 只校验 word格式存在标签;
3.增加框架合同合同签章同步云之家;
4.增加框架合同签章同步云之家回写;
This commit is contained in:
zhouc 2024-09-20 17:04:04 +08:00
parent b3b819cd61
commit ea7b0e6279
5 changed files with 316 additions and 48 deletions

View File

@ -22,18 +22,15 @@ import java.util.EventObject;
* @Created by ZZSLL
*/
public class SalesContractEdit extends AbstractBillPlugIn implements BeforeF7SelectListener
{
public class SalesContractEdit extends AbstractBillPlugIn implements BeforeF7SelectListener {
@Override
public void afterDoOperation(AfterDoOperationEventArgs e)
{
public void afterDoOperation(AfterDoOperationEventArgs e) {
super.afterDoOperation(e);
IFormView view = this.getView();
IDataModel model = this.getModel();
DynamicObject dataEntity = model.getDataEntity();
String operateKey = e.getOperateKey();
if ("save".equals(operateKey))
{
if ("save".equals(operateKey)) {
String billno = dataEntity.getString("billno");
boolean isLastCharLetter = billno.matches(".*[A-Za-z]$");
if (isLastCharLetter) return;
@ -42,6 +39,13 @@ public class SalesContractEdit extends AbstractBillPlugIn implements BeforeF7Se
view.updateView("billno");
SaveServiceHelper.save(new DynamicObject[]{model.getDataEntity(true)});
}
if ("signature".equals(operateKey)) {
view.invokeOperation("refresh");
}
if ("dosign".equals(operateKey)) {
// view.invokeOperation("refresh");
view.showSuccessNotification("合同盖章完成!");
}
}
@Override
@ -52,6 +56,7 @@ public class SalesContractEdit extends AbstractBillPlugIn implements BeforeF7Se
yem_internationalrate.addBeforeF7SelectListener(this);
}
}
@Override
public void beforeF7Select(BeforeF7SelectEvent e) {
IDataModel model = this.getModel();

View File

@ -0,0 +1,189 @@
package com.yem.wm.es.salescontrac.op;
import com.alibaba.fastjson.JSONObject;
import com.yem.ia.intebilllogon.Utils.ObjectToJsonUtils;
import com.yem.wm.utils.YEM;
import com.yem.wm.utils.YunzhijiaUtils;
import kd.bos.dataentity.OperateOption;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.EntityMetadataCache;
import kd.bos.entity.ExtendedDataEntity;
import kd.bos.entity.MainEntityType;
import kd.bos.entity.operate.result.OperationResult;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.PreparePropertysEventArgs;
import kd.bos.entity.plugin.args.BeforeOperationArgs;
import kd.bos.entity.validate.ErrorLevel;
import kd.bos.entity.validate.ValidationErrorInfo;
import kd.bos.exception.KDBizException;
import kd.bos.exception.KDException;
import kd.bos.id.ID;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.AttachmentServiceHelper;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* @author zhouc
* @date 2024/9/20 16:30
* @className SalesContracSignatureOp
* @description 框架合同 合同签章申请服务插件
*/
public class SalesContracSignatureOp extends AbstractOperationServicePlugIn {
@Override
public void onPreparePropertys(PreparePropertysEventArgs e) {
super.onPreparePropertys(e);
List<String> fieldKeys = e.getFieldKeys();
fieldKeys.add("yem_sigforminstid");
fieldKeys.add("yem_sigflowinstid");
fieldKeys.add("yem_sigstatus");
fieldKeys.add("yem_siguser");
fieldKeys.add("yem_sigdatetime");
fieldKeys.add("yem_sigmag");
}
@Override
public void beforeExecuteOperationTransaction(BeforeOperationArgs e) {
super.beforeExecuteOperationTransaction(e);
List<ExtendedDataEntity> selectedRows = e.getSelectedRows();
ArrayList<ExtendedDataEntity> ArrayList = new ArrayList<>();
for (ExtendedDataEntity selectedRow : selectedRows) {
DynamicObject dynamicObject = selectedRow.getDataEntity();
Object pkid = dynamicObject.getPkValue();
boolean yem_sigstatus = dynamicObject.getBoolean("yem_sigstatus");
List<Map<String, Object>> attachments = AttachmentServiceHelper.getAttachments(dynamicObject.getDynamicObjectType().getName(), pkid, "yem_approval");
if (attachments.size() > 0 && !yem_sigstatus) {
JSONObject json = GetintebilllogonJson(pkid, dynamicObject);
DynamicObject yem_billtype = BusinessDataServiceHelper.loadSingle("bos_entityobject", new QFilter[]{new QFilter("number", QCP.equals, dynamicObject.getDynamicObjectType().getName())});
MainEntityType entityType = EntityMetadataCache.getDataEntityType("yem_ialog");
DynamicObject yemIalog = new DynamicObject(entityType);
try {
String s = YunzhijiaUtils.doPost(YunzhijiaUtils.yzjurl + "/cmmpapi/cmmp/flowCreate.do?tokenId=0C89F5DBEB704C1F8671721B148E8224", json.toString());
System.out.println(s);
JSONObject retJson = JSONObject.parseObject(s);
Boolean success = retJson.getBoolean("success");
if (success) {
// dynamicObject.set("yem_synfalt",null);
JSONObject data = retJson.getJSONObject("data");
String formInstId = data.getString("formInstId");//表单定义ID
String flowInstId = data.getString("flowInstId");//流程实例ID
dynamicObject = BusinessDataServiceHelper.loadSingle(dynamicObject.get("id"), dynamicObject.getDynamicObjectType().getName());
dynamicObject.set("yem_sigforminstid", formInstId);
dynamicObject.set("yem_sigflowinstid", flowInstId);
dynamicObject.set("yem_sigstatus", true);
dynamicObject.set("yem_siguser", YEM.getCurrentUserId());
dynamicObject.set("yem_sigdatetime", new Date());
dynamicObject.set("yem_sigmag", "同步云之家成功!");
SaveServiceHelper.update(dynamicObject, OperateOption.create());
// 根据实体名构建元数据并创建DynamicObject
yemIalog.getDataEntityType().getPrimaryKey().setValueFast(yemIalog, ID.genLongId());
yemIalog.set("billno", dynamicObject.get("billno"));//单据编号
yemIalog.set("yem_billtype", yem_billtype);//单据类型
yemIalog.set("yem_success", success);//是否成功
yemIalog.set("yem_req", json.toString());//请求参数
yemIalog.set("billstatus", "A");//请求参数
yemIalog.set("yem_response", s);//返回参数
yemIalog.set("yem_flowinstid", flowInstId);//流程实例ID
yemIalog.set("yem_forminstid", formInstId);//表单实例ID
} else {
// 根据实体名构建元数据并创建DynamicObject
yemIalog.getDataEntityType().getPrimaryKey().setValueFast(yemIalog, ID.genLongId());
yemIalog.set("billstatus", "A");//请求参数
yemIalog.set("billno", dynamicObject.get("billno"));//单据编号yemIalog.set("yem_billtype", yem_billtype);//单据类型
yemIalog.set("yem_success", false);//是否成功
yemIalog.set("yem_req", json.toString());//请求参数
yemIalog.set("yem_response", s);//返回参数
addErrMessage(operationResult, dynamicObject, "云之家生成流程异常:" + s);
dynamicObject.set("yem_sigforminstid", null);
dynamicObject.set("yem_sigflowinstid", null);
dynamicObject.set("yem_sigstatus", false);
dynamicObject.set("yem_sigmag", "同步失败,请查看《智能审批日志》日志!");
dynamicObject.set("yem_siguser", YEM.getCurrentUserId());
dynamicObject.set("yem_sigdatetime", new Date());
SaveServiceHelper.update(dynamicObject, OperateOption.create());
}
} catch (Exception ex) {
ex.printStackTrace();
yemIalog.getDataEntityType().getPrimaryKey().setValueFast(yemIalog, ID.genLongId());
yemIalog.set("billstatus", "A");//请求参数
yemIalog.set("billno", dynamicObject.get("billno"));//单据编号
yemIalog.set("yem_billtype", yem_billtype);//单据类型
yemIalog.set("yem_success", false);//是否成功
yemIalog.set("yem_req", json.toString());//请求参数
if (ex instanceof KDException) {
yemIalog.set("yem_error", ((KDException) ex).getStackTraceMessage());//异常信息
addErrMessage(operationResult, dynamicObject, "云之家接口调用异常:" + ((KDException) ex).getStackTraceMessage());
} else {
yemIalog.set("yem_error", ex.toString());//异常信息
addErrMessage(operationResult, dynamicObject, "云之家接口调用异常:" + ex.toString());
}
dynamicObject.set("yem_sigforminstid", null);
dynamicObject.set("yem_sigflowinstid", null);
dynamicObject.set("yem_sigstatus", false);
dynamicObject.set("yem_sigmag", "同步失败,请查看《智能审批日志》日志!");
dynamicObject.set("yem_siguser", YEM.getCurrentUserId());
dynamicObject.set("yem_sigdatetime", new Date());
SaveServiceHelper.update(dynamicObject, OperateOption.create());
}
SaveServiceHelper.save(new DynamicObject[]{yemIalog});
} else {
addErrMessage(operationResult, dynamicObject, "当前订单未上传国贸经理签批附件、当期订单已同步至云之家,禁止执行合同签章申请!");
}
}
}
/**
* 获取当前单据入参
*
* @param pkid
* @return
*/
public JSONObject GetintebilllogonJson(Object pkid, DynamicObject dynamicObject) {
JSONObject Object = new JSONObject();
QFilter qFilter = new QFilter("yem_isdisable", QCP.equals, false);
qFilter.and(new QFilter("billno", QCP.equals, "WXHT-YZJ"));
DynamicObject yem_ia_intebilllogon = BusinessDataServiceHelper.loadSingle("yem_ia_intebilllogon", "id", qFilter.toArray());
if (yem_ia_intebilllogon != null) {
long intebilllogonID = yem_ia_intebilllogon.getLong("id");
//查询单据注册数据
DynamicObject data = BusinessDataServiceHelper.loadSingle(intebilllogonID, "yem_ia_intebilllogon");
if (data != null && pkid != null && pkid != "") {
Object = ObjectToJsonUtils.ToJson(data, pkid, dynamicObject.getDynamicObjectType().getName(), ObjectToJsonUtils.getpostcreator());
}
} else {
this.operationResult.addErrorInfo(new ValidationErrorInfo("", pkid,
0, 0, "err", "合同签章申请", "未读取启用的《智能审批单据注册》,请修改后重试!", ErrorLevel.Error));
}
return Object;
}
/**
* 向操作结果添加一条错误提示
*
* @param operationResult 操作结果参数
* @param dataEntity 校验数据
* @param errMsg 异常信息
* @return
*/
private static void addErrMessage(OperationResult operationResult, DynamicObject dataEntity, String errMsg) {
operationResult.setSuccess(false);
// Object pkId = dataEntity.getPkValue();
// int rowIndex = 0;
// ErrorLevel errorLevel = ErrorLevel.Error;
//
// ValidationErrorInfo errInfo = new ValidationErrorInfo("",
// pkId, 0, rowIndex,
// "BeforeExecuteOperationTransactionSample",
// "接口调用异常",
// "单据编号:【" + dataEntity.get("billno") + "" + errMsg,
// errorLevel);
// operationResult.setMessage("合同签章申请失败!");
// operationResult.addErrorInfo(errInfo);
throw new KDBizException("单据编号:【" + dataEntity.get("billno") + "" + errMsg);
}
}

View File

@ -48,7 +48,7 @@ public class SalesOrderAutoSignOp extends AbstractOperationServicePlugIn {
// Word中的书签名称
final String BOOKMARK = "ensign";
// 修改Word后上传的附件面板
final String UPLOAD_ATTACHMENT_KEY = "attachmentpanel";
final String UPLOAD_ATTACHMENT_KEY = "yem_approval";
for (DynamicObject dynamicObject : entities) {
String formId = dynamicObject.getDataEntityType().getName();
@ -104,31 +104,33 @@ public class SalesOrderAutoSignOp extends AbstractOperationServicePlugIn {
AttachmentDto attDao = AttachmentServiceHelper.getAttachmentInfoByAttPk(attachment.get("attPkId"));
String fileUrl = attDao.getResourcePath();
String filename = attDao.getFilename();
validatorFileExtension(filename);
ByteArrayOutputStream out = new ByteArrayOutputStream();
FileServiceFactory.getAttachmentFileService().download(fileUrl, out, null);
InputStream in = new ByteArrayInputStream(out.toByteArray());
InputStream validatorStream = new ByteArrayInputStream(out.toByteArray());
if (filename.endsWith(".docx") || filename.endsWith(".doc")) {
validatorFileExtension(filename);
ByteArrayOutputStream out = new ByteArrayOutputStream();
FileServiceFactory.getAttachmentFileService().download(fileUrl, out, null);
InputStream in = new ByteArrayInputStream(out.toByteArray());
InputStream validatorStream = new ByteArrayInputStream(out.toByteArray());
// 获取书签
List<CTBookmark> bookMarks = ContactSignUtils.getFileBookMarks(validatorStream);
validatorSignAble(bookMarks, BOOKMARK, filename);
// 获取书签
List<CTBookmark> bookMarks = ContactSignUtils.getFileBookMarks(validatorStream);
validatorSignAble(bookMarks, BOOKMARK, filename);
File file;
try {
File file;
try {
ByteArrayInputStream stream = new ByteArrayInputStream(imageData);
ByteArrayInputStream stream = new ByteArrayInputStream(imageData);
// 书签位置替换为图片书签不会删除
file = ContactSignUtils.replaceBookmarkWithImage(in, stream, filename, BOOKMARK);
AttachmentUtil.uploadAttachment(appId, formId, String.valueOf(pkId), UPLOAD_ATTACHMENT_KEY, file.getName(), file.getPath());
List<Map<String, Object>> uploaded = AttachmentServiceHelper.getAttachments(formId, pkId, UPLOAD_ATTACHMENT_KEY);
File pdf = ContactSignUtils.convertToPDF(uploaded);
if (pdf != null) {
AttachmentUtil.uploadAttachment(appId, formId, String.valueOf(pkId), UPLOAD_ATTACHMENT_KEY, pdf.getName(), pdf.getPath());
// 书签位置替换为图片书签不会删除
file = ContactSignUtils.replaceBookmarkWithImage(in, stream, filename, BOOKMARK);
AttachmentUtil.uploadAttachment(appId, formId, String.valueOf(pkId), UPLOAD_ATTACHMENT_KEY, file.getName(), file.getPath());
List<Map<String, Object>> uploaded = AttachmentServiceHelper.getAttachments(formId, pkId, UPLOAD_ATTACHMENT_KEY);
File pdf = ContactSignUtils.convertToPDF(uploaded);
if (pdf != null) {
AttachmentUtil.uploadAttachment(appId, formId, String.valueOf(pkId), UPLOAD_ATTACHMENT_KEY, pdf.getName(), pdf.getPath());
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
}

View File

@ -105,31 +105,36 @@ public class SalesOrderAutoSignOp extends AbstractOperationServicePlugIn {
AttachmentDto attDao = AttachmentServiceHelper.getAttachmentInfoByAttPk(attachment.get("attPkId"));
String fileUrl = attDao.getResourcePath();
String filename = attDao.getFilename();
validatorFileExtension(filename);
ByteArrayOutputStream out = new ByteArrayOutputStream();
FileServiceFactory.getAttachmentFileService().download(fileUrl, out, null);
InputStream in = new ByteArrayInputStream(out.toByteArray());
InputStream validatorStream = new ByteArrayInputStream(out.toByteArray());
/**
* 2024-09-20 增加只校验 word文件
*/
if(filename.endsWith(".docx")|| filename.endsWith(".doc")){
// validatorFileExtension(filename);
ByteArrayOutputStream out = new ByteArrayOutputStream();
FileServiceFactory.getAttachmentFileService().download(fileUrl, out, null);
InputStream in = new ByteArrayInputStream(out.toByteArray());
InputStream validatorStream = new ByteArrayInputStream(out.toByteArray());
// 获取书签
List<CTBookmark> bookMarks = ContactSignUtils.getFileBookMarks(validatorStream);
validatorSignAble(bookMarks, BOOKMARK, filename);
// 获取书签
List<CTBookmark> bookMarks = ContactSignUtils.getFileBookMarks(validatorStream);
validatorSignAble(bookMarks, BOOKMARK, filename);
File file;
try {
File file;
try {
ByteArrayInputStream stream = new ByteArrayInputStream(imageData);
ByteArrayInputStream stream = new ByteArrayInputStream(imageData);
// 书签位置替换为图片书签不会删除
file = ContactSignUtils.replaceBookmarkWithImage(in, stream, filename, BOOKMARK);
AttachmentUtil.uploadAttachment(appId, formId, String.valueOf(pkId), UPLOAD_ATTACHMENT_KEY, file.getName(), file.getPath());
List<Map<String, Object>> uploaded = AttachmentServiceHelper.getAttachments(formId, pkId, UPLOAD_ATTACHMENT_KEY);
File pdf = ContactSignUtils.convertToPDF(uploaded);
if (pdf != null) {
AttachmentUtil.uploadAttachment(appId, formId, String.valueOf(pkId), UPLOAD_ATTACHMENT_KEY, pdf.getName(), pdf.getPath());
// 书签位置替换为图片书签不会删除
file = ContactSignUtils.replaceBookmarkWithImage(in, stream, filename, BOOKMARK);
AttachmentUtil.uploadAttachment(appId, formId, String.valueOf(pkId), UPLOAD_ATTACHMENT_KEY, file.getName(), file.getPath());
List<Map<String, Object>> uploaded = AttachmentServiceHelper.getAttachments(formId, pkId, UPLOAD_ATTACHMENT_KEY);
File pdf = ContactSignUtils.convertToPDF(uploaded);
if (pdf != null) {
AttachmentUtil.uploadAttachment(appId, formId, String.valueOf(pkId), UPLOAD_ATTACHMENT_KEY, pdf.getName(), pdf.getPath());
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
}

View File

@ -200,7 +200,74 @@ public class YZJAuditController {
CustomApiResult<Object> ces = CustomApiResult.success("调用成功");
return ces;
}
/**
* 云之家框架合同 合同签章回写
*
* @param data
* @return
* @throws IOException
*/
@ApiPostMapping("/SalescontracCallback")
public CustomApiResult<Object> SalescontracCallback(@NotNull @ApiParam("参数") String data) throws IOException {
try {
JSONObject json = JSONObject.parseObject(data);
// JSONObject data1 = json.getJSONObject("data");
JSONObject basicInfo = json.getJSONObject("basicInfo");
String formCodeId = basicInfo.getString("formCodeId");
//通过表单定义ID获取模板
String formInstId = basicInfo.getString("formInstId");
ArrayList<QFilter> qFilters = new ArrayList<>();
qFilters.add(new QFilter("yem_yzjid", QCP.equals, formCodeId));
qFilters.add(new QFilter("yem_isdisable", QCP.equals, false));
DynamicObject yem_ia_intebilllogon = BusinessDataServiceHelper.loadSingle("yem_ia_intebilllogon", qFilters.toArray(new QFilter[0]));
if (yem_ia_intebilllogon != null) {
yem_ia_intebilllogon = BusinessDataServiceHelper.loadSingle(yem_ia_intebilllogon.getLong("id"), "yem_ia_intebilllogon");
} else {
return CustomApiResult.success("调用成功");
}
//单据类型
String bos_entityobjectnum = yem_ia_intebilllogon.getString("yem_formid.number");
//获取单据
DynamicObject billObj = BusinessDataServiceHelper.loadSingle(bos_entityobjectnum, new QFilter[]{new QFilter("yem_sigforminstid", QCP.equals, formInstId)});
if (billObj != null) {
billObj = BusinessDataServiceHelper.loadSingle(billObj.get("id"), bos_entityobjectnum);
//通过表单实例ID获取日志对象 yem_sigforminstid
DynamicObject ialog = BusinessDataServiceHelper.loadSingle("yem_ialog", new QFilter[]{new QFilter("yem_forminstid", QCP.equals, billObj.get("yem_sigforminstid"))});
ialog.set("yem_writeback", data);
SaveServiceHelper.save(new DynamicObject[]{ialog});
//TODO 调用云之家获取审批结果接口
JSONObject reqjson = new JSONObject();
reqjson.put("flowInstId", billObj.get("yem_sigflowinstid"));
String retStr = YunzhijiaUtils.doPost(YunzhijiaUtils.yzjurl + "/gateway/yun/common/approve", reqjson.toString());
JSONObject retJson = JSONObject.parseObject(retStr);
//状态码 FINISH同意已完成
// DISAGRE不同意已完成
// RUNNING待审批
// SUSPEND挂起
// RETURNED待提交(审批人退回到发起节点)
// TOSUBMIT待提交(发起人自己撤回)
// ABANDON废弃
// DELETE已删除
//驳回更新 合同签章同步状态
if ("DISAGREE".equals(retJson.getString("data"))) {
billObj.set("yem_sigstatus", false);//合同签章同步状态
billObj.set("yem_sigmag", null);//合同签章同步说明
billObj.set("yem_sigforminstid", null);//合同签章云之家表单实例id
billObj.set("yem_sigflowinstid", null);//合同签章云之家流程实例id
SaveServiceHelper.save(new DynamicObject[]{billObj});
} else {
return CustomApiResult.success("根据云之家审批示例ID获取到的状态为【" + retJson.getString("data") + "】,无需更新!");
}
} else {
return CustomApiResult.fail("501", "未获取到框架合同合同签章云之家表单实例id为【" + formInstId + "】的数据!");
}
} catch (Exception e) {
CustomApiResult<Object> fail = CustomApiResult.fail("501", e.getMessage());
return fail;
}
CustomApiResult<Object> ces = CustomApiResult.success("调用成功");
return ces;
}
private String result(OperationResult result, String operation) {
if (!result.isSuccess()) {