初始化
This commit is contained in:
6
WEB-INF/src_signtask/pluginCfg.xml
Normal file
6
WEB-INF/src_signtask/pluginCfg.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<plugin>
|
||||
<id>src_signtask</id>
|
||||
<name>禹龙签署任务集成</name>
|
||||
<category>20260121</category>
|
||||
</plugin>
|
||||
12
WEB-INF/src_signtask/spring/spring.xml
Normal file
12
WEB-INF/src_signtask/spring/spring.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
|
||||
<beans default-autowire="byName">
|
||||
<bean id="signTaskPluginApi" class="com.seeyon.apps.src_signtask.SignTaskPluginApi"/>
|
||||
<bean id="signTaskConfigProvider" class="com.seeyon.apps.src_signtask.config.SignTaskConfigProvider"/>
|
||||
<bean id="formCreateService" class="com.seeyon.apps.src_signtask.service.FormCreateService"/>
|
||||
<bean id="signTaskJob" class="com.seeyon.apps.src_signtask.job.SignTaskJob"/>
|
||||
<bean id="fileHandlerService" class="com.seeyon.apps.src_signtask.service.FileHandlerService"/>
|
||||
<bean id="esignCallbackFormBizService" class="com.seeyon.apps.src_signtask.callback.EsignCallbackFormBizService"/>
|
||||
<bean name="/signtaskcallback.do" class="com.seeyon.apps.src_signtask.controller.SignTaskCallBackController">
|
||||
</bean>
|
||||
</beans>
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.seeyon.apps.src_signtask;
|
||||
|
||||
import com.seeyon.apps.common.plugin.api.APluginInfoApi;
|
||||
import com.seeyon.apps.common.plugin.vo.ConfigVo;
|
||||
import com.seeyon.apps.src_signtask.constants.SignTaskConstants;
|
||||
|
||||
public class SignTaskPluginApi extends APluginInfoApi {
|
||||
public SignTaskPluginApi() {
|
||||
}
|
||||
|
||||
public String getPluginId() {
|
||||
return SignTaskConstants.getPluginId();
|
||||
}
|
||||
|
||||
public String getCreateUser() {
|
||||
return "橙阳科技";
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return "禹龙签署任务集成集成";
|
||||
}
|
||||
|
||||
public ConfigVo getDefaultConfig() {
|
||||
ConfigVo configVo = new ConfigVo();
|
||||
SignTaskConstants[] var2 = SignTaskConstants.values();
|
||||
int var3 = var2.length;
|
||||
|
||||
for(int var4 = 0; var4 < var3; ++var4) {
|
||||
SignTaskConstants value = var2[var4];
|
||||
if (value != SignTaskConstants.plugin) {
|
||||
configVo.getDevParams().put(value.name(), value.getDefaultValue());
|
||||
configVo.getProdParams().put(value.name(), value.getDefaultValue());
|
||||
configVo.getParamMap().put(value.name(), value.getDescription());
|
||||
}
|
||||
}
|
||||
|
||||
return configVo;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.seeyon.apps.src_signtask.callback;
|
||||
|
||||
import com.seeyon.apps.esign.service.EsignCallbackBizService;
|
||||
import com.seeyon.apps.esign.utils.FileUtil;
|
||||
import com.seeyon.apps.src_signtask.config.SignTaskConfigProvider;
|
||||
import com.seeyon.apps.src_signtask.constants.SignTaskConstants;
|
||||
import com.seeyon.ctp.common.AppContext;
|
||||
import com.seeyon.ctp.common.filemanager.manager.AttachmentManager;
|
||||
import com.seeyon.utils.form.*;
|
||||
import com.seeyon.utils.http.HttpClient;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
public class EsignCallbackFormBizService implements EsignCallbackBizService {
|
||||
|
||||
private static final Log log = LogFactory.getLog(EsignCallbackFormBizService.class);
|
||||
private SignTaskConfigProvider configProvider = (SignTaskConfigProvider) AppContext.getBean("signTaskConfigProvider");
|
||||
private AttachmentManager attachmentManager = (AttachmentManager) AppContext.getBean("attachmentManager");
|
||||
|
||||
public void handleSuccessSignCallbackBiz(String tablename,String updatefield,String statusField,String formId,Object[] fileInfos) throws Exception {;
|
||||
String[] statusParams = statusField.split("_");
|
||||
String status = statusParams[0];
|
||||
String enumId = statusParams[1];
|
||||
String enumItemId = EnumMapUtils.getEnumItemValueByEnumId("已签署",Long.parseLong(enumId));
|
||||
//下载文件到本地
|
||||
List<FormWhereCondition> conditions = new ArrayList<>();
|
||||
String refId = FileUtil.uploadContractToOA(fileInfos, formId,
|
||||
configProvider.getBizConfigByKey(SignTaskConstants.LOGINNAME),
|
||||
configProvider.getBizConfigByKey(SignTaskConstants.updateAccountName));
|
||||
List<FormUpdateField> updateFields = new ArrayList<>();
|
||||
updateFields.add(FormUpdateField.build().fieldName(updatefield).value(refId));
|
||||
updateFields.add(FormUpdateField.build().fieldName(status).value(enumItemId));
|
||||
conditions.add(FormWhereCondition.build().value(formId).fieldName("ID"));
|
||||
FormTableExecutor.update(tablename,updateFields,conditions);
|
||||
//调用第三方回调接口
|
||||
}
|
||||
|
||||
private void handleThireePartyCallback(String formId,String refId) throws Exception {
|
||||
List<FormWhereCondition> conditions = new ArrayList<>();
|
||||
conditions.add(FormWhereCondition.build().value(formId).fieldName("ID"));
|
||||
TableContext master = FormTableExecutor.master(configProvider.getBizConfigByKey(SignTaskConstants.SIGNTASK_FORMNO));
|
||||
FormColumn formColumn = FormTableExecutor.queryOne(master, conditions, true);
|
||||
Map<String, Object> fieldsMap = formColumn.getFieldsMap();
|
||||
String callbackUrl = (String) fieldsMap.get("签署任务第三方系统回调地址");
|
||||
List<Long> fileUrls = attachmentManager.getBySubReference(Long.parseLong(refId));
|
||||
String fileList = fileUrls.stream().map(f -> f + "").collect(Collectors.joining(","));
|
||||
String paramString = "?taskId=" + formId + "&task_finished=true" + "&signFiles=" + fileList;
|
||||
HttpClient.httpGet(callbackUrl + paramString,null,null);
|
||||
}
|
||||
|
||||
public void handleFailSignCallbackBiz(String tableName,String statusField,String formId,String failMsg) throws Exception {
|
||||
String[] statusParams = statusField.split("_");
|
||||
String status = statusParams[0];
|
||||
String enumId = statusParams[1];
|
||||
String enumItemId = EnumMapUtils.getEnumItemValueByEnumId("签署失败",Long.parseLong(enumId));
|
||||
List<FormWhereCondition> conditions = new ArrayList<>();
|
||||
List<FormUpdateField> updateFields = new ArrayList<>();
|
||||
updateFields.add(FormUpdateField.build().fieldName(status).value(enumItemId));
|
||||
conditions.add(FormWhereCondition.build().value(formId).fieldName("签署任务编号"));
|
||||
FormTableExecutor.update(tableName,updateFields,conditions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean support(String bizType) {
|
||||
return "FORM".equals(bizType);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.seeyon.apps.src_signtask.config;
|
||||
|
||||
import com.seeyon.apps.common.config.ICstConfigApi;
|
||||
import com.seeyon.apps.common.plugin.vo.ConfigVo;
|
||||
import com.seeyon.apps.src_signtask.constants.SignTaskConstants;
|
||||
import com.seeyon.ctp.common.AppContext;
|
||||
|
||||
import static com.seeyon.apps.src_signtask.constants.SignTaskConstants.getPluginId;
|
||||
|
||||
public class SignTaskConfigProvider {
|
||||
|
||||
protected ICstConfigApi cstConfigApi = (ICstConfigApi) AppContext.getBean("cstConfigApi");
|
||||
|
||||
public String getBizConfigByKey(SignTaskConstants key) {
|
||||
ConfigVo config = cstConfigApi.getConfig(getPluginId());
|
||||
return config.getParamVal(key.name());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.seeyon.apps.src_signtask.constants;
|
||||
|
||||
public enum SignTaskConstants {
|
||||
plugin("src_signtask","插件ID"),
|
||||
SIGNTASK_FORMNO("","签署任务档案底表"),
|
||||
LOGINNAME("",""),
|
||||
updateAccountName("",""),
|
||||
;
|
||||
|
||||
SignTaskConstants(String defaultValue, String description) {
|
||||
this.defaultValue = defaultValue;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
private String defaultValue;
|
||||
private String description;
|
||||
|
||||
public String getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public static String getPluginId() {
|
||||
return plugin.defaultValue;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.seeyon.apps.src_signtask.controller;
|
||||
|
||||
import cn.hutool.log.Log;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.seeyon.apps.esign.po.esignapi.EsignCallbackParams;
|
||||
import com.seeyon.apps.esign.service.EsignUploadFileService;
|
||||
import com.seeyon.apps.src_signtask.callback.EsignCallbackFormBizService;
|
||||
import com.seeyon.ctp.common.AppContext;
|
||||
import com.seeyon.ctp.common.controller.BaseController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class SignTaskCallBackController extends BaseController {
|
||||
|
||||
private static final Log log = Log.get(SignTaskCallBackController.class);
|
||||
|
||||
private EsignUploadFileService esignUploadFileService = (EsignUploadFileService) AppContext.getBean("esignUploadFileService");
|
||||
private EsignCallbackFormBizService callbackService = (EsignCallbackFormBizService) AppContext.getBean("esignCallbackFormBizService");
|
||||
private ConcurrentHashMap<String,String> callbackMap = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
public void callback(HttpServletRequest request, HttpServletResponse response) {
|
||||
try {
|
||||
log.info("签署回调触发");
|
||||
// 签署回调处理,改变超级节点状态
|
||||
String formId = request.getParameter("formId");
|
||||
String tableName = request.getParameter("tablename");
|
||||
String updatefield = request.getParameter("updatefield");
|
||||
String statusfield = request.getParameter("statusfield");
|
||||
BufferedReader reader = request.getReader();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
sb.append(line);
|
||||
}
|
||||
String body = sb.toString();
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
EsignCallbackParams callbackParams = mapper.readValue(body, new TypeReference<EsignCallbackParams>() {
|
||||
});
|
||||
String flowId = callbackParams.getSignFlowId();
|
||||
String action = callbackParams.getAction();
|
||||
log.info("签署回调当前流程: " + flowId);
|
||||
if(action.equals("SIGN_FLOW_COMPLETE")) {
|
||||
if(callbackParams.getSignFlowStatus() == 2) {
|
||||
Object[] fileInfos = esignUploadFileService.getDownloadFileInfo(flowId);
|
||||
callbackService.handleSuccessSignCallbackBiz(tableName,updatefield,statusfield,formId,fileInfos);
|
||||
}else if(callbackParams.getSignFlowStatus() == 5){
|
||||
//合同过期
|
||||
//esignCallbackBizService.handleExpiredSignCallbackBiz(tableName,statusfield,formId);
|
||||
}else {
|
||||
callbackService.handleFailSignCallbackBiz(tableName,statusfield,formId,callbackParams.getResultDescription());
|
||||
}
|
||||
//signLinkService.del(flowId);
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
return;
|
||||
}else if(action.equals("SIGN_MISSON_COMPLETE") && callbackParams.getSignResult() == 2 && callbackParams.getSignOrder() == 2){
|
||||
//发送消息
|
||||
// MessageVo messageVo = new MessageVo();
|
||||
// messageVo.setBizId(flowId);
|
||||
// messageVo.setMessageType("SIGN");
|
||||
|
||||
// thirdMessageService.sendMessage();
|
||||
}
|
||||
//下载合同
|
||||
response.setContentType("application/json;charset=UTF-8");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
try (OutputStream out = response.getOutputStream()) {
|
||||
out.write("{\"code\":\"200\",\"msg\":\"success\"}".getBytes(StandardCharsets.UTF_8));
|
||||
out.flush();
|
||||
}
|
||||
log.info("回调处理完成: " + flowId);
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
log.error("回调处理失败", e);
|
||||
}
|
||||
// response.setStatus(HttpServletResponse.SC_OK);
|
||||
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.seeyon.apps.src_signtask.job;
|
||||
|
||||
|
||||
import com.seeyon.apps.esign.po.param.JsonParamSource;
|
||||
import com.seeyon.apps.esign.service.ContractCreateService;
|
||||
import com.seeyon.apps.ext.quartz.AbstractQuartzTask;
|
||||
import com.seeyon.apps.src_signtask.config.SignTaskConfigProvider;
|
||||
import com.seeyon.apps.src_signtask.constants.SignTaskConstants;
|
||||
import com.seeyon.ctp.common.AppContext;
|
||||
import com.seeyon.ctp.common.exceptions.BusinessException;
|
||||
import com.seeyon.utils.form.*;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class SignTaskJob extends AbstractQuartzTask {
|
||||
|
||||
private static final Log log = LogFactory.getLog(SignTaskJob.class);
|
||||
private SignTaskConfigProvider signTaskConfigProvider = (SignTaskConfigProvider) AppContext.getBean("signTaskConfigProvider");
|
||||
private ContractCreateService contractCreateService = (ContractCreateService) AppContext.getBean("contractCreateService");
|
||||
|
||||
@Override
|
||||
public String taskRun(String s) throws Exception {
|
||||
log.info("开始批量发起签署任务");
|
||||
startSignTask();
|
||||
log.info("批量发起签署任务结束");
|
||||
return "";
|
||||
}
|
||||
|
||||
private void startSignTask() throws BusinessException {
|
||||
Integer pageNum = 1;
|
||||
Integer pageSize = 20;
|
||||
Map<String,Object> dataMap = null;
|
||||
TableContext tableContext = FormTableExecutor.master(signTaskConfigProvider.getBizConfigByKey(SignTaskConstants.SIGNTASK_FORMNO));
|
||||
List<FormWhereCondition> conditionList = new ArrayList<>();
|
||||
conditionList.add(FormWhereCondition.build().display("签署状态").value(EnumMapUtils.getEnumItemValueByDisplayValue(tableContext.getTableBean(),"签署状态","未签署")));
|
||||
List<FormColumn> formColumns = FormTableExecutor.pageQuery(tableContext, null, conditionList, pageNum, pageSize, true);
|
||||
if(formColumns.size() <= 0) {
|
||||
return;
|
||||
}
|
||||
do {
|
||||
for (FormColumn formColumn : formColumns) {
|
||||
dataMap = new HashMap<>();
|
||||
Map<String, Object> fieldsMap = formColumn.getFieldsMap();
|
||||
dataMap.put("formId",formColumn.getId());
|
||||
dataMap.put("contractTitle",fieldsMap.get("签署任务名称"));
|
||||
dataMap.put("byFile",true);
|
||||
dataMap.put("tableName",tableContext.getTableBean().getTableName());
|
||||
dataMap.put("signFileRefId",fieldsMap.get("签署任务文件"));
|
||||
dataMap.put("signedFileField",tableContext.getTableBean().getFieldBeanByDisplay("签署后合同文件").getColumnName());
|
||||
dataMap.put("signStatusField",tableContext.getTableBean().getFieldBeanByDisplay("签署状态").getColumnName());
|
||||
dataMap.put("signStatusEnumId",tableContext.getTableBean().getFieldBeanByDisplay("签署状态").getEnumId());
|
||||
dataMap.put("signers",fieldsMap.get("签署方配置"));
|
||||
JsonParamSource jsonParamSource = new JsonParamSource(dataMap);
|
||||
jsonParamSource.setCallbackBaseUrl("/signtaskcallback.do?method=callback");
|
||||
try{
|
||||
String flowId = contractCreateService.startSign(jsonParamSource);
|
||||
log.info("签署任务编号为"+fieldsMap.get("签署任务编号")+"的签署任务发起成功,流程编号为"+flowId);
|
||||
List<FormWhereCondition> updateConditions = new ArrayList<FormWhereCondition>();
|
||||
updateConditions.add(FormWhereCondition.build().display("ID").value(formColumn.getId()));
|
||||
List<FormUpdateField> updateFields = new ArrayList<>();
|
||||
updateFields.add(FormUpdateField.build().display("E签宝流程编号").value(flowId));
|
||||
FormTableExecutor.update(tableContext,updateFields,updateConditions);
|
||||
}catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
log.error("签署任务编号为"+fieldsMap.get("签署任务编号")+"的签署任务发起失败");
|
||||
}
|
||||
}
|
||||
pageNum++;
|
||||
formColumns = FormTableExecutor.pageQuery(tableContext, null, conditionList, pageNum, pageSize, true);
|
||||
}while (formColumns.size() > 0 );
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "批量发起签署任务";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.seeyon.apps.src_signtask.service;
|
||||
|
||||
import com.seeyon.ctp.common.AppContext;
|
||||
import com.seeyon.ctp.common.filemanager.manager.AttachmentManager;
|
||||
import com.seeyon.ctp.common.filemanager.manager.FileManager;
|
||||
import com.seeyon.ctp.common.po.filemanager.Attachment;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
public class FileHandlerService {
|
||||
|
||||
private AttachmentManager attachmentManager = (AttachmentManager) AppContext.getBean("attachmentManager");
|
||||
private FileManager fileManager = (FileManager) AppContext.getBean("fileManager");
|
||||
|
||||
public void handleFile(String refId, HttpServletResponse response) throws Exception {
|
||||
File file = null;
|
||||
try {
|
||||
Attachment attachment = attachmentManager.getAttachmentByFileURL(Long.valueOf(refId));
|
||||
InputStream inputStream = fileManager.getFileInputStream(attachment.getFileUrl());
|
||||
String encodedFileName = URLEncoder.encode(attachment.getFilename(), "UTF-8")
|
||||
.replaceAll("\\+", "%20");
|
||||
response.setHeader(
|
||||
"Content-Disposition",
|
||||
"attachment; filename=\"" + attachment.getFilename() + "\"; " +
|
||||
"filename*=UTF-8''" + encodedFileName
|
||||
);
|
||||
try (OutputStream outputStream = new BufferedOutputStream(response.getOutputStream())) {
|
||||
byte[] buffer = new byte[2048];
|
||||
int bytesRead;
|
||||
while ((bytesRead = inputStream.read(buffer)) != -1) {
|
||||
outputStream.write(buffer, 0, bytesRead);
|
||||
}
|
||||
outputStream.flush();
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}finally {
|
||||
if(file != null) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
package com.seeyon.apps.src_signtask.service;
|
||||
|
||||
|
||||
import cn.hutool.log.Log;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.seeyon.apps.src_signtask.config.SignTaskConfigProvider;
|
||||
import com.seeyon.apps.src_signtask.constants.SignTaskConstants;
|
||||
import com.seeyon.ctp.common.AppContext;
|
||||
import com.seeyon.ctp.common.filemanager.manager.AttachmentManager;
|
||||
import com.seeyon.ctp.common.po.filemanager.Attachment;
|
||||
import com.seeyon.ctp.organization.bo.V3xOrgAccount;
|
||||
import com.seeyon.ctp.organization.bo.V3xOrgMember;
|
||||
import com.seeyon.ctp.organization.manager.OrgManager;
|
||||
import com.seeyon.ctp.services.FileUploadExporter;
|
||||
import com.seeyon.utils.form.*;
|
||||
import com.seeyon.utils.http.FileUtil;
|
||||
import com.seeyon.utils.http.HttpClient;
|
||||
import com.seeyon.v3x.services.form.FormFactory;
|
||||
|
||||
|
||||
import java.io.*;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
public class FormCreateService {
|
||||
|
||||
private static final Log log = Log.get(FormCreateService.class);
|
||||
private SignTaskConfigProvider signTaskConfigProvider = (SignTaskConfigProvider) AppContext.getBean("signTaskConfigProvider");
|
||||
private FormFactory formFactory = (FormFactory) AppContext.getBean("formFactory");
|
||||
private OrgManager orgManager = (OrgManager) AppContext.getBean("orgManager");
|
||||
private static final String TEMP_DIR = System.getProperty("java.io.tmpdir") + File.separator + "seeyontempfile";
|
||||
private static final long MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
|
||||
private static final String CATEGORY_CODE = "66";
|
||||
|
||||
public void formCreate(JSONObject params) throws Exception {
|
||||
// 创建表单对象
|
||||
String formNo = signTaskConfigProvider.getBizConfigByKey(SignTaskConstants.SIGNTASK_FORMNO);
|
||||
String updateAccountName = signTaskConfigProvider.getBizConfigByKey(SignTaskConstants.updateAccountName);
|
||||
|
||||
// 提取主表字段
|
||||
Map<String, Object> mainFormData = new HashMap<>();
|
||||
String taskId = params.getString("taskId");
|
||||
mainFormData.put("签署任务编号", taskId);
|
||||
mainFormData.put("签署任务名称", params.getString("signTaskName"));
|
||||
mainFormData.put("签署任务创建时间", params.getString("taskCreateTime"));
|
||||
String linkType = params.getString("signFileUrlType");
|
||||
JSONArray urls = params.getJSONArray("signFileUrls");
|
||||
|
||||
TableContext tableContext = FormTableExecutor.master(formNo);
|
||||
mainFormData.put("签署状态", EnumMapUtils.getEnumItemValueByDisplayValue(tableContext.getTableBean(),"签署状态","未签署"));
|
||||
List<FormWhereCondition> conditions = new ArrayList<>();
|
||||
conditions.add(FormWhereCondition.build().value(taskId).display("签署任务编号"));
|
||||
long count = FormTableExecutor.count(tableContext, new ArrayList<>(), conditions);
|
||||
if(count > 0) {
|
||||
throw new RuntimeException("该签署任务ID的签署任务已存在");
|
||||
}
|
||||
File tempDir = new File(TEMP_DIR);
|
||||
if (!tempDir.exists()) {
|
||||
tempDir.mkdirs();
|
||||
}
|
||||
V3xOrgMember creator = orgManager.getMemberByLoginName(params.getString("taskCreator"));
|
||||
if(creator != null) {
|
||||
mainFormData.put("签署任务创建者", creator.getId());
|
||||
}
|
||||
mainFormData.put("签署任务第三方系统回调地址", params.getString("callbackUrl"));
|
||||
mainFormData.put("第三方系统唯一标识", params.getString("thirdSysFlag"));
|
||||
// 将 signers 转成 JSON 字符串存入
|
||||
if (params.containsKey("signers")) {
|
||||
mainFormData.put("签署方配置", params.getJSONArray("signers").toString());
|
||||
}
|
||||
String loginName = creator.getLoginName();
|
||||
// 导入业务表单
|
||||
FormSaveUtil.formSave(loginName,formNo,formFactory,mainFormData,null);
|
||||
|
||||
List<FormUpdateField> updateFields = new ArrayList<>();
|
||||
FormColumn formColumn = FormTableExecutor.queryOne(tableContext, conditions, true);
|
||||
if(formColumn == null) {
|
||||
return;
|
||||
}
|
||||
String formId = formColumn.getId();
|
||||
if("LINK".equals(linkType)) {
|
||||
List<String> fileNames = new ArrayList<>();
|
||||
for (int i = 0; i < urls.size(); i++) {
|
||||
String savePath = TEMP_DIR + File.separator + i +".pdf";
|
||||
HttpClient.httpDownloadFile((String)urls.get(i),null,savePath,"UTF-8");
|
||||
fileNames.add(savePath);
|
||||
}
|
||||
String refId = uploadSignTaskFileToOA(fileNames, formId, loginName, updateAccountName);
|
||||
updateFields.add(FormUpdateField.build().display("签署任务文件").value(refId));
|
||||
}else if("REFID".equals(linkType)) {
|
||||
FileUtil fileUtil = new FileUtil();
|
||||
for (int i = 0; i < urls.size(); i++) {
|
||||
List<String> filePaths = fileUtil.fieldFileDownload(Long.parseLong((String) urls.get(i)), TEMP_DIR + File.separator);
|
||||
String refId = uploadSignTaskFileToOA(filePaths, formId, loginName, updateAccountName);
|
||||
updateFields.add(FormUpdateField.build().display("签署任务文件").value(refId));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(updateFields.size() > 0){
|
||||
FormTableExecutor.update(tableContext,updateFields,conditions);
|
||||
}
|
||||
}
|
||||
|
||||
public String uploadSignTaskFileToOA(List<String> fileNames, String formId, String loginName, String updateAccountName) throws Exception {
|
||||
|
||||
OrgManager orgManager = (OrgManager) AppContext.getBean("orgManager");
|
||||
V3xOrgMember member = orgManager.getMemberByLoginName(loginName);
|
||||
V3xOrgAccount account = orgManager.getAccountByName(updateAccountName);
|
||||
String refId = String.valueOf(Math.abs(UUID.randomUUID().getLeastSignificantBits()));
|
||||
List<Attachment> attachments = new ArrayList<>();
|
||||
File tempDir = new File(TEMP_DIR);
|
||||
if (!tempDir.exists()) {
|
||||
tempDir.mkdirs();
|
||||
}
|
||||
for (String fileName : fileNames) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
FileUploadExporter fileUpload = new FileUploadExporter();
|
||||
File file = new File(fileName);
|
||||
if (file.exists() && file.length() <= MAX_FILE_SIZE) {
|
||||
String uploadedPath = fileUpload.processUpload(new String[]{file.getAbsolutePath()});
|
||||
Map<String, String> attachMeta = new HashMap<>();
|
||||
attachMeta.put("type", "0");
|
||||
attachMeta.put("fileUrl", uploadedPath);
|
||||
attachMeta.put("size", String.valueOf(file.length()));
|
||||
attachMeta.put("subReference", refId);
|
||||
attachMeta.put("category", CATEGORY_CODE);
|
||||
attachMeta.put("createdate", sdf.format(new Date()));
|
||||
attachMeta.put("filename", file.getName());
|
||||
attachMeta.put("reference", formId);
|
||||
attachMeta.put("mimeType", "application/" + "pdf");
|
||||
attachments.add(new Attachment(attachMeta));
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
if (attachments.isEmpty()) return null;
|
||||
AttachmentManager attachmentManager = (AttachmentManager) AppContext.getBean("attachmentManager");
|
||||
attachmentManager.create(attachments, member.getId(), account.getId());
|
||||
return refId;
|
||||
}
|
||||
|
||||
public String uploadContractToOA(Object[] fileInfos, String formId, String loginName, String updateAccountName) throws Exception {
|
||||
|
||||
OrgManager orgManager = (OrgManager) AppContext.getBean("orgManager");
|
||||
V3xOrgMember member = orgManager.getMemberByLoginName(loginName);
|
||||
V3xOrgAccount account = orgManager.getAccountByName(updateAccountName);
|
||||
String refId = String.valueOf(Math.abs(UUID.randomUUID().getLeastSignificantBits()));
|
||||
List<Attachment> attachments = new ArrayList<>();
|
||||
File tempDir = new File(TEMP_DIR);
|
||||
if (!tempDir.exists()) {
|
||||
tempDir.mkdirs();
|
||||
}
|
||||
for (Object fileInfo : fileInfos) {
|
||||
Map<String, Object> fileInfoMap = (Map<String, Object>) fileInfo;
|
||||
String fileName = (String) fileInfoMap.get("fileName");
|
||||
String url = (String) fileInfoMap.get("downloadUrl");
|
||||
String savePath = TEMP_DIR + File.separator + fileName;
|
||||
com.seeyon.apps.esign.utils.HttpClient.httpDownloadFile(url, null,savePath,"ITF-8");
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
FileUploadExporter fileUpload = new FileUploadExporter();
|
||||
File file = new File(savePath);
|
||||
if (file.exists() && file.length() <= MAX_FILE_SIZE) {
|
||||
String uploadedPath = fileUpload.processUpload(new String[]{file.getAbsolutePath()});
|
||||
Map<String, String> attachMeta = new HashMap<>();
|
||||
attachMeta.put("type", "0");
|
||||
attachMeta.put("fileUrl", uploadedPath);
|
||||
attachMeta.put("size", String.valueOf(file.length()));
|
||||
attachMeta.put("subReference", refId);
|
||||
attachMeta.put("category", CATEGORY_CODE);
|
||||
attachMeta.put("createdate", sdf.format(new Date()));
|
||||
attachMeta.put("filename", fileName);
|
||||
attachMeta.put("reference", formId);
|
||||
attachMeta.put("mimeType", "application/" + "pdf");
|
||||
attachments.add(new Attachment(attachMeta));
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
if (attachments.isEmpty()) return null;
|
||||
AttachmentManager attachmentManager = (AttachmentManager) AppContext.getBean("attachmentManager");
|
||||
attachmentManager.create(attachments, member.getId(), account.getId());
|
||||
return refId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.seeyon.ctp.rest.resources;
|
||||
|
||||
import cn.hutool.log.Log;
|
||||
import com.seeyon.apps.src_signtask.service.FileHandlerService;
|
||||
import com.seeyon.ctp.common.AppContext;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.core.Context;
|
||||
|
||||
/**
|
||||
* 提供给外部下载OA文件
|
||||
*/
|
||||
@Path("/fileTransport")
|
||||
public class FileTransportResource extends BaseResource {
|
||||
|
||||
private static final Log log = Log.get(FileTransportResource.class);
|
||||
private FileHandlerService fileHandlerService = (FileHandlerService) AppContext.getBean("fileHandlerService");
|
||||
|
||||
@GET
|
||||
@Path("/downloadFile")
|
||||
public void downloadFile(@Context HttpServletRequest request,@Context HttpServletResponse response) {
|
||||
try {
|
||||
fileHandlerService.handleFile(request.getParameter("refId"), response);
|
||||
} catch (Exception e) {
|
||||
log.error("外部系统下载oa文件失败");
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.seeyon.ctp.rest.resources;
|
||||
|
||||
import cn.hutool.log.Log;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.seeyon.apps.src_signtask.service.FormCreateService;
|
||||
import com.seeyon.ctp.common.AppContext;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
@Path("/signtask")
|
||||
@Produces({"application/json", "application/xml"})
|
||||
public class SignTaskSaveResource extends BaseResource{
|
||||
|
||||
private static final Log log = Log.get(SignTaskSaveResource.class);
|
||||
private FormCreateService formCreateService = (FormCreateService) AppContext.getBean("formCreateService");
|
||||
|
||||
@POST
|
||||
@Path("/save")
|
||||
@Produces({"application/json"})
|
||||
@Consumes({"application/json"})
|
||||
public Response saveSignTask(JSONObject params){
|
||||
try {
|
||||
formCreateService.formCreate(params);
|
||||
return success("创建成功");
|
||||
}catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
}
|
||||
return fail("创建失败");
|
||||
}
|
||||
}
|
||||
7
src/test/Test.java
Normal file
7
src/test/Test.java
Normal file
@@ -0,0 +1,7 @@
|
||||
import com.seeyon.apps.src_signtask.service.FormCreateService;
|
||||
|
||||
public class Test {
|
||||
public static void main(String[] args) {
|
||||
FormCreateService formCreateService = new FormCreateService();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user