package cn.autoform.web.controller.workflow;
|
|
import cn.autoform.bean.FormSolidiFication;
|
import cn.autoform.bean.ProcessCon;
|
import cn.autoform.bean.ProcessState;
|
import cn.autoform.bean.system.UserInfo;
|
import cn.autoform.db.entity.ProcessApproval;
|
import cn.autoform.db.entity.ProcessInstance;
|
import cn.autoform.db.entity.ProcessTask;
|
import cn.autoform.db.exten.Process;
|
import cn.autoform.fw.exception.FormClientException;
|
import cn.autoform.fw.exception.IEMRuntimeException;
|
import cn.autoform.util.form.FormDataCodeToNameFilter;
|
import cn.autoform.util.thread.Keys;
|
import cn.autoform.util.thread.ThreadData;
|
import cn.autoform.util.tool.JSONTool;
|
import cn.autoform.util.tool.ObjectUtil;
|
import cn.autoform.web.client.CscApiService;
|
import cn.autoform.web.client.WorkflowClient;
|
import cn.autoform.web.client.impl.FormClientImpl;
|
import cn.autoform.web.client.util.WorkflowTool;
|
import cn.autoform.web.client.util.WorkflowTwe;
|
import cn.autoform.web.controller.resumable.util.FastDFSClient;
|
import cn.autoform.web.service.datamanagement.DataManagementService;
|
import cn.autoform.web.service.process.*;
|
import com.alibaba.fastjson.TypeReference;
|
import com.codingapi.tx.annotation.TxTransaction;
|
import lombok.extern.slf4j.Slf4j;
|
import net.sf.json.JSONObject;
|
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.math.NumberUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.ui.ModelMap;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletRequest;
|
import java.io.IOException;
|
import java.util.*;
|
import java.util.concurrent.TimeoutException;
|
|
@Slf4j
|
@RestController
|
public class WorkflowController {
|
|
@Autowired
|
private FormClientImpl formClient;
|
@Autowired
|
private ProcessApprovalService processApp;
|
|
|
@Autowired
|
private ProcessInstanceService processInstance;
|
|
@Autowired(required = false)
|
private ProcessFilter processFilter;
|
|
@Autowired
|
private WorkflowClient workflowClient;
|
|
|
@Resource(name = "processStateServiceImpl")
|
private ProcessStateService process;
|
|
@Value("${process-service-id}")
|
private Integer processServiceId;
|
|
@Resource
|
private FastDFSClient fastDFSClient;
|
|
/**
|
* 流程logservice
|
*/
|
@Resource(name = "processLogServiceImpl")
|
private ProcessLogService processLogService;
|
|
@Autowired
|
private WorkflowTool workflowTool;
|
|
@Autowired
|
private WorkflowTwe workflowTwe;
|
|
@Autowired
|
private CscApiService cscApi;
|
|
@Autowired
|
private DataManagementService dataManagementService;
|
public static final String Q = "[%s]:10";
|
|
public static final String A = "[%s]:20";
|
|
/**
|
* 当前待办信息key
|
*/
|
private static final String PROCESSINFORMATION = "processInformation";
|
|
/**
|
* 项目负责人
|
*/
|
private static final String PROJECT_LEADER_PHONE = "projectLeaderPhone";
|
|
|
/**
|
* 删除流程定义
|
*
|
* @param jsonStr
|
* @param request
|
* @return
|
* @throws TimeoutException
|
* @throws IOException
|
*/
|
@RequestMapping(value = "${requset.processdefine01}", method = RequestMethod.POST)
|
public Map<String, Object> defineDelete(@RequestBody String jsonStr, HttpServletRequest request) throws TimeoutException, IOException {
|
JSONObject jsonObject = JSONObject.fromObject(jsonStr);
|
workflowTool.setRequest(request);
|
Process process = workflowTool.getProcess(jsonObject);
|
Map<String, Object> result = workflowClient.defineDelete(process);
|
return result;
|
}
|
|
/**
|
* 部署流程定义
|
*
|
* @param jsonStr
|
* @param request
|
* @return
|
* @throws TimeoutException
|
* @throws IOException
|
*/
|
@RequestMapping(value = "${requset.processdefine02}", method = RequestMethod.POST)
|
public Map<String, Object> definePeploy(@RequestBody String jsonStr, HttpServletRequest request) throws TimeoutException, IOException {
|
JSONObject jsonObject = JSONObject.fromObject(jsonStr);
|
jsonObject.remove("tenantID");
|
jsonObject.remove("formID");
|
//写死版本号
|
jsonObject.put("version", "1.1.1");
|
System.out.println("参数:" + JSONTool.toJson(jsonStr));
|
workflowTool.setRequest(request);
|
Process process = workflowTool.getProcess(jsonObject);
|
Map<String, Object> result = workflowClient.definePeploy(process);
|
//修改数据库流程定义json信息
|
processApp.definePeploy(result);
|
System.out.println("结果:" + JSONTool.toJson(result));
|
return result;
|
}
|
|
/**
|
* 流程定义分页查询
|
*
|
* @param jsonStr
|
* @param request
|
* @return
|
* @throws TimeoutException
|
* @throws IOException
|
*/
|
@RequestMapping(value = "${requset.processdefine03}", method = RequestMethod.POST)
|
public Map<String, Object> defineSeache(@RequestBody String jsonStr, HttpServletRequest request) throws TimeoutException, IOException {
|
JSONObject jsonObject = JSONObject.fromObject(jsonStr);
|
workflowTool.setRequest(request);
|
Process process = workflowTool.getProcess(jsonObject);
|
Map<String, Object> result = workflowClient.defineSeache(process);
|
return result;
|
}
|
|
/**
|
* 创建流程定义
|
*
|
* @param jsonStr
|
* @param request
|
* @return
|
* @throws TimeoutException
|
* @throws IOException
|
*/
|
@RequestMapping(value = "${requset.processdefine04}", method = RequestMethod.POST)
|
public Map<String, Object> defineCreate(@RequestBody String jsonStr, HttpServletRequest request) throws TimeoutException, IOException {
|
JSONObject jsonObject = JSONObject.fromObject(jsonStr);
|
//取出本地流程定义,没有则创建
|
ProcessApproval pro = processApp.selectApp(jsonObject.getString("formID"));
|
if (pro != null) {
|
return JSONTool.toObj(JSONTool.toJson(pro), new TypeReference<Map<String, Object>>() {
|
});
|
// return RestResultGenerator.genBussinessSuccessResult(pro);
|
}
|
workflowTool.setRequest(request);
|
//查询是否已经初始化过
|
Process process = workflowTool.getProcess(jsonObject);
|
Map<String, Object> flag = workflowClient.check(workflowTwe.getProcess(getRse(new JSONObject())));
|
String flag1 = Objects.toString(flag.get("data"), "true");
|
System.out.println("返回结果:" + JSONTool.toJson(flag));
|
//若没有初始化过,进行初始化
|
if (flag1.equals("false")) {
|
Map<String, Object> o = workflowClient.initialization(workflowTwe.getProcess(getRse(new JSONObject())));
|
System.out.println("初始化接口:" + JSONTool.toJson(o));
|
}
|
Map<String, Object> result = workflowClient.defineCreate(process);
|
//新创建的定义添加到本端
|
ProcessApproval proc = new ProcessApproval();
|
//proc.setOrganizationId(jsonObject.getString("organizationId"));
|
proc.setFormId(jsonObject.getString("formID"));
|
processApp.addProcessApproval(result, proc);
|
System.out.println("返回结果:" + JSONTool.toJson(result));
|
// return RestResultGenerator.genBussinessSuccessResult(result.get("data"));
|
return JSONTool.toObj(JSONTool.toJson(result.get("data")), new TypeReference<Map<String, Object>>() {
|
});
|
}
|
|
public JSONObject getRse(JSONObject js) {
|
js.put("tenantId", ThreadData.get(Keys.TENANT_ID));
|
js.put("companyId", ThreadData.get(Keys.COMPANY_ID));
|
js.put("serviceId", ThreadData.get(Keys.SERVICE_ID));
|
return js;
|
}
|
|
/**
|
* 退回流程实例
|
*
|
* @param jsonStr
|
* @param request
|
* @return
|
* @throws TimeoutException
|
* @throws IOException
|
* @throws FormClientException
|
*/
|
@RequestMapping(value = "${requset.processinst01}", method = RequestMethod.POST)
|
public Map<String, String> instBack(@RequestBody Map<String, Object> jsonStr, HttpServletRequest request) throws TimeoutException, IOException, FormClientException {
|
System.out.println("参数:" + JSONTool.toJson(jsonStr));
|
//添加流程log
|
processLogService.addProcessLog(jsonStr, "20", null);
|
//重新构造参数
|
Map<String, Object> maps = new HashMap<String, Object>();
|
maps.put("activityInstId", jsonStr.get("activityInstId"));
|
maps.put("activityDefId", jsonStr.get("activityDefId"));
|
maps.put("processInstId", jsonStr.get("processInstId"));
|
maps.put("data", jsonStr.get("data"));
|
System.out.println("工作流参数:" + JSONTool.toJson(maps));
|
JSONObject jsonObject = JSONObject.fromObject(JSONTool.toJson(maps));
|
workflowTool.setRequest(request);
|
Process process = workflowTool.getProcess(jsonObject);
|
Map<String, String> result = workflowClient.instBack(process);
|
System.out.println("返回结果:" + JSONTool.toJson(result));
|
// if(result.get("data").equals("1")){
|
// //添加退回Log
|
// ProcessLog proLog = JSONTool.toObj(JSONTool.toJson(jsonStr),ProcessLog.class);
|
// System.out.println(JSONTool.toJson(proLog));
|
// processLogService.insertLog(proLog);
|
// }
|
//流程引擎执行失败,不进行表单状态的处理
|
if(null != result && null != result.get("resCode") && result.get("resCode").contains("ErrCode")){
|
return result;
|
}
|
if (true) {
|
record(Objects.toString(jsonStr.get("processInstId"), ""), 1, jsonStr.get("activityDefId").toString());
|
}
|
|
if(workflowTool.isOne(Objects.toString(jsonStr.get("processInstId")))){
|
processFilter.executeRollBack(
|
Objects.toString(jsonStr.get("formID"))
|
, Optional.ofNullable(jsonStr.get("dataRowNum")).map(Object::toString).map(Integer::valueOf).orElse(0)
|
, ThreadData.get(Keys.TENANT_ID));
|
}
|
|
return result;
|
}
|
|
/**
|
* 设置代理
|
*
|
* @param jsonStr
|
* @param request
|
* @return
|
* @throws TimeoutException
|
* @throws IOException
|
*/
|
@RequestMapping(value = "${requset.processinst02}", method = RequestMethod.POST)
|
public Map<String, Object> agentCreate(@RequestBody String jsonStr, HttpServletRequest request) throws TimeoutException, IOException {
|
JSONObject jsonObject = JSONObject.fromObject(jsonStr);
|
workflowTool.setRequest(request);
|
Process process = workflowTool.getProcess(jsonObject);
|
Map<String, Object> result = workflowClient.agentCreat(process);
|
return result;
|
}
|
|
@PostMapping("/test/html")
|
public Object testHtml(@RequestBody String jsonStr) {
|
JSONObject jsonObject = JSONObject.fromObject(jsonStr);
|
String htmlUrl = uploadHtml(jsonObject.getString("html"));
|
return htmlUrl;
|
}
|
|
@RequestMapping(value = "/set/html", method = RequestMethod.POST)
|
public Map<String, Object> setHtml(@RequestBody String jsonStr) throws TimeoutException {
|
JSONObject jsonObject = JSONObject.fromObject(jsonStr);
|
ProcessState ps = new ProcessState(jsonObject.getString("formID"), jsonObject.getInt("dataRowNum"), ThreadData.get(Keys.TENANT_ID));
|
ps.setHtmlUrl(uploadHtml(jsonObject.getString("html")));
|
this.process.updateState(ps);
|
return new ModelMap("resCode", "000000");
|
}
|
|
/**
|
* 创建流程实例
|
*
|
* @param jsonStr
|
* @param request
|
* @return
|
* @throws Exception
|
*/
|
@RequestMapping(value = "${requset.processinst03}", method = RequestMethod.POST)
|
@TxTransaction(isStart = true)
|
@Transactional
|
public Map<String, Object> instCreat(@RequestBody String jsonStr, HttpServletRequest request) throws Exception {
|
//添加流程办理中
|
Integer dNum = null;
|
JSONObject jsonObject = JSONObject.fromObject(jsonStr);
|
String formId = jsonObject.getString("formID");
|
Integer dataRowNun = jsonObject.getInt("dataRowNum");
|
String htmlUrl = uploadHtml(jsonObject.getString("html"));
|
// 清除无用参数,参数超长问题
|
jsonObject.remove("html");
|
|
String tenantId = ThreadData.get(Keys.TENANT_ID);
|
if (processFilter != null) {
|
processFilter.executeBefor(jsonObject.getString("formID"), jsonObject.getInt("dataRowNum"), ThreadData.get(Keys.TENANT_ID));
|
}
|
//查看本条数据是否创建过流程
|
ProcessApproval pro = null;
|
ProcessInstance pros = new ProcessInstance();
|
pros.setDataRowNum(jsonObject.getInt("dataRowNum"));
|
pros.setFormID(jsonObject.getString("formID"));
|
Map<String, Object> res = new HashMap<>();
|
//判断是否已经创建流程实例,以创建返回
|
//取出当前流程大状态
|
ProcessInstance p = processInstance.selectInst(pros);
|
ProcessState pse = process.selectState(new ProcessState(jsonObject.getString("formID"), jsonObject.getInt("dataRowNum"), ThreadData.get(Keys.TENANT_ID)));
|
//验证操作人员
|
checkData(pse);
|
if (p != null) {
|
ProcessState pgo = new ProcessState(jsonObject.getString("formID"), jsonObject.getInt("dataRowNum"), ThreadData.get(Keys.TENANT_ID));
|
//取出当前流程大状态
|
ProcessState ps = process.selectState(pgo);
|
if (!ObjectUtil.empty(ps) && "10".equals(ps.getProcessState())) {
|
//已有流程实例,并且状态为10,重新提交
|
String i = instOne(htmlUrl, jsonObject.getString("formID"), jsonObject.getInt("dataRowNum"), ThreadData.get(Keys.TENANT_ID), p.getProcessInstId(), p.getProcessDefId());
|
if (i != null) {
|
|
if (processFilter != null) {
|
processFilter.executeCreate(jsonObject.getString("formID"), jsonObject.getInt("dataRowNum"), ThreadData.get(Keys.TENANT_ID));
|
}
|
|
res.put("resCode", "00000");
|
return res;
|
} else {
|
|
}
|
}
|
res.put("data", "2");
|
|
if (processFilter != null) {
|
processFilter.executeCreate(jsonObject.getString("formID"), jsonObject.getInt("dataRowNum"), ThreadData.get(Keys.TENANT_ID));
|
}
|
return res;
|
}
|
pro = processApp.selectApp(jsonObject.getString("formID"));
|
if (pro == null) {
|
res.put("data", "3");
|
return res;
|
}
|
|
jsonObject.put("processDefName", pro.getProcessDefName());
|
jsonObject.put("processDefId", pro.getProcessDefId());
|
jsonObject.put("processInstName", pse.getNumber());
|
jsonObject.put("params", processApp.getProcessParam(
|
formId
|
, tenantId
|
, dataRowNun));
|
setSearchParam(jsonObject, pse);
|
Process process = workflowTool.getProcess(jsonObject);
|
Map<String, Object> result = workflowClient.autoFinish(process);
|
//将流程实例添加在本端
|
Object obj = result.get("data");
|
if (ObjectUtil.empty(obj)) {
|
throw new IEMRuntimeException("流程自动提交待办异常,自动提交失败");
|
}
|
StringBuffer tasks = new StringBuffer();
|
ProcessInstance proInst = JSONTool.toObj(JSONTool.toJson(obj), ProcessInstance.class);
|
try {
|
//添加流程日志
|
Map<String, Object> logMap = JSONTool.toObj(jsonStr, Map.class);
|
logMap.put("processInstId", proInst.getProcessInstId());
|
|
proInst.setFormID(formId);
|
proInst.setTenantID(tenantId);
|
proInst.setDataRowNum(dataRowNun);
|
|
dNum = processLogService.addProcessLog(logMap, "30", null);
|
|
ProcessState ps = new ProcessState(formId, dataRowNun, tenantId);
|
ps.setProcessUser(ThreadData.get(Keys.OPEN_ID));
|
ps.setProcessLog(null);
|
ps.setHtmlUrl(htmlUrl);
|
|
List<ProcessTask> list = proInst.getWorkItems();
|
if (ObjectUtil.notEmpty(list)) {
|
for (ProcessTask pr : list) {
|
tasks.append("[").append(pr.getParticipantId()).append("],");
|
// proInst.setActivityInstId(pr.getActivityDefId());
|
}
|
ps.setProcessTask(tasks.toString().replaceAll(",$", ""));
|
ps.setOrderStatus("21");
|
ps.setProcessState("20");
|
} else {
|
this.budgetDeduction(tenantId, formId, dataRowNun);
|
ps.setOrderStatus("40");
|
ps.setProcessState("30");
|
}
|
proInst.setActivityInstId(proInst.getOneActivityDefId());
|
processInstance.addProcess(proInst);
|
|
this.process.updateState(ps);
|
|
// if (workflowTool.isOver(result)) {
|
// if (processFilter != null) {
|
// processFilter.executeOver(jsonObject.getString("formID"), jsonObject.getInt("dataRowNum"), ThreadData.get(Keys.TENANT_ID));
|
// }
|
// }
|
|
if (processFilter != null) {
|
processFilter.executeAfter(jsonObject.getString("formID"), jsonObject.getInt("dataRowNum"), ThreadData.get(Keys.TENANT_ID));
|
}
|
|
if (processFilter != null) {
|
processFilter.executeCreate(jsonObject.getString("formID"), jsonObject.getInt("dataRowNum"), ThreadData.get(Keys.TENANT_ID));
|
}
|
} catch (Exception e) {
|
System.err.println("------------------------手动结束当前流程----------------");
|
jsonObject.clear();
|
jsonObject.put("processInstId", proInst.getProcessInstId());
|
processLogService.delProcessLog(dNum);
|
workflowClient.instOver(workflowTool.getProcess(jsonObject));
|
log.error(e.getMessage(), e);
|
|
res.put("resCode", "00018");
|
return res;
|
}
|
return result;
|
}
|
|
public String uploadHtml(String html) {
|
// log.debug("上传大小:{}", html.length());
|
String url = fastDFSClient.uploadFile(html.getBytes(), "json");
|
// log.debug("上传成功:{}", url);
|
if (ObjectUtil.empty(url)) {
|
throw new IEMRuntimeException("固化html失败!");
|
}
|
return url;
|
}
|
|
private void setSearchParam(JSONObject jsonObject, ProcessState pse) {
|
log.debug("流程状态:{}", JSONTool.toJson(pse));
|
Map<String, Object> name = new HashMap<>(pse.getMainInfo());
|
FormDataCodeToNameFilter.accept(name);
|
jsonObject.put("sourceSystem", "epc");
|
if (StringUtils.isEmpty((String)pse.getMainInfo().get("reimburseMan"))
|
|| StringUtils.isEmpty((String)name.get("reimburseMan"))) {
|
//todo set
|
UserInfo userInfo = formClient.getUserInfo();
|
jsonObject.put("search_1", userInfo.getUserCode());
|
jsonObject.put("search_2", userInfo.getUserName());
|
} else {
|
jsonObject.put("search_1", pse.getMainInfo().get("reimburseMan"));
|
jsonObject.put("search_2", name.get("reimburseMan"));
|
}
|
jsonObject.put("search_3", pse.getMainInfo().get("C_Type"));
|
jsonObject.put("search_4", name.get("C_Type"));
|
jsonObject.put("search_5", name.get("Remark"));
|
log.debug("添加查询参数:{}", jsonObject.toString());
|
}
|
//
|
// @RequestMapping(value = "${requset.processinst03}", method = RequestMethod.POST)
|
// public JSONObject setSearchParam1(@RequestBody String jsonStr) {
|
// JSONObject jsonObject = JSONObject.fromObject(jsonStr);
|
// jsonObject.put("sourceSystem", "epc");
|
// //todo set
|
// UserInfo userInfo = formClient.getUserInfo();
|
// jsonObject.put("search_1", userInfo.getUserCode());
|
// jsonObject.put("search_2", userInfo.getUserName());
|
// log.debug("添加查询参数:{}", jsonObject.toString());
|
// return jsonObject;
|
// }
|
|
|
/**
|
* 撤销流程实例
|
*
|
* @param jsonStr
|
* @param request
|
* @return
|
* @throws TimeoutException
|
* @throws IOException
|
* @throws FormClientException
|
*/
|
@RequestMapping(value = "${requset.processinst04}", method = RequestMethod.POST)
|
public Map<String, Object> instDrawBack(@RequestBody String jsonStr, HttpServletRequest request) throws TimeoutException, IOException, FormClientException {
|
// System.out.println("撤回参数"+jsonStr);
|
JSONObject jsonObject = JSONObject.fromObject(jsonStr);
|
workflowTool.setRequest(request);
|
Process process = workflowTool.getProcess(jsonObject);
|
Map<String, Object> result = workflowClient.instDrawBack(process);
|
// System.out.println(" 撤销返回结果:"+JSONTool.toJson(result));
|
//修改流程大状态
|
if (result != null && "00000".equals(result.get("resCode"))) {
|
this.updateState(jsonObject.getString("processInstId"));
|
}
|
if(workflowTool.isOne(jsonObject.getString("processInstId"))){
|
processFilter.executeRollBack(jsonObject.getString("formID"), jsonObject.getInt("datarowNum"), ThreadData.get(Keys.TENANT_ID));
|
}
|
return result;
|
}
|
|
/**
|
* 结束流程实例
|
*
|
* @param jsonStr
|
* @param request
|
* @return
|
* @throws TimeoutException
|
* @throws IOException
|
*/
|
@RequestMapping(value = "${requset.processinst05}", method = RequestMethod.POST)
|
public Map<String, Object> instOver(@RequestBody String jsonStr, HttpServletRequest request) throws TimeoutException, IOException {
|
JSONObject jsonObject = JSONObject.fromObject(jsonStr);
|
workflowTool.setRequest(request);
|
Process process = workflowTool.getProcess(jsonObject);
|
Map<String, Object> result = workflowClient.instOver(process);
|
System.out.println("返回参数:" + JSONTool.toJson(result));
|
return result;
|
}
|
|
/**
|
* 设置代办
|
*
|
* @param jsonStr
|
* @param request
|
* @return
|
* @throws TimeoutException
|
* @throws IOException
|
*/
|
@RequestMapping(value = "${requset.processinst06}", method = RequestMethod.POST)
|
public Map<String, Object> chargeCreate(@RequestBody String jsonStr, HttpServletRequest request) throws TimeoutException, IOException {
|
JSONObject jsonObject = JSONObject.fromObject(jsonStr);
|
workflowTool.setRequest(request);
|
Process process = workflowTool.getProcess(jsonObject);
|
Map<String, Object> result = workflowClient.chargeCreate(process);
|
return result;
|
}
|
|
/**
|
* 执行流程实例
|
*
|
* @param
|
* @param request
|
* @return
|
* @throws Exception
|
*/
|
@RequestMapping(value = "${requset.processinst07}", method = RequestMethod.POST)
|
@TxTransaction(isStart = true)
|
@Transactional
|
public Map<String, Object> instFinish(@RequestBody Map<String, Object> map, HttpServletRequest request) throws Exception {
|
//添加流程log
|
processLogService.addProcessLog(map, "10", null);
|
String formId = Objects.toString(map.get("formID"), "");
|
Integer dataRowNum = NumberUtils.createInteger(Objects.toString(map.get("dataRowNum"), "0"));
|
String tenantId = Objects.toString(map.get("tenantID"), "");
|
if (processFilter != null) {
|
processFilter.executeBefor(formId, dataRowNum, tenantId);
|
}
|
Map<String, Object> workFlowParam = new HashMap<>();
|
workFlowParam.put("processInstId", map.get("processInstId"));
|
workFlowParam.put("activityInstId", map.get("activityInstId"));
|
workFlowParam.put("data", map.get("data"));
|
workFlowParam.put("formID", map.get("formID"));
|
workFlowParam.put("dataRowNum", map.get("dataRowNum"));
|
workFlowParam.put("tenantID", map.get("tenantID"));
|
workFlowParam.put("userName", map.get("userName"));
|
workFlowParam.put("params", processApp.getProcessParam(
|
Objects.toString(map.get("formID"))
|
, Objects.toString(map.get("tenantID"))
|
, NumberUtils.createInteger(Objects.toString(map.get("dataRowNum"), "0"))));
|
JSONObject jsonObject = JSONObject.fromObject(JSONTool.toJson(workFlowParam));
|
//执行前判断是否是项目负责人审批
|
setProjectleader(JSONTool.toObj(JSONTool.toJson(map.get(PROCESSINFORMATION)), ProcessTask.class)
|
, new ProcessState(formId, dataRowNum, tenantId), jsonObject);
|
workflowTool.setRequest(request);
|
Process process = workflowTool.getProcess(jsonObject);
|
Map<String, Object> result = workflowClient.instFinish(process);
|
// System.out.println("执行返回结果:"+JSONTool.toJson(result));
|
if (workflowTool.isOver(result)) {
|
this.budgetDeduction(tenantId, formId, dataRowNum);
|
} else {
|
record(Objects.toString(map.get("processInstId"), ""), 0, map.get("activityInstId").toString());//if(result.get("data") != null)
|
}
|
if (processFilter != null) {
|
processFilter.executeAfter(formId, dataRowNum, tenantId);
|
}
|
return result;
|
}
|
|
/**
|
* 查询流程待办
|
*
|
* @param jsonStr
|
* @param request
|
* @return
|
* @throws TimeoutException
|
* @throws IOException
|
*/
|
@RequestMapping(value = "${requset.processinst08}", method = RequestMethod.POST)
|
public Map<String, Object> instSeacheHandle(@RequestBody String jsonStr, HttpServletRequest request) throws TimeoutException, IOException {
|
JSONObject jsonObject = JSONObject.fromObject(jsonStr);
|
jsonObject.put("appId", processServiceId);
|
jsonObject.put("tenantId", ThreadData.get(Keys.TENANT_ID));
|
jsonObject.put("compId", ThreadData.get(Keys.COMPANY_ID));
|
Process process = workflowTool.getProcess(jsonObject);
|
Map<String, Object> result = workflowClient.instSeacheHandle(process);
|
return result;
|
}
|
|
/**
|
* 流程实例log
|
*
|
* @param jsonStr
|
* @param request
|
* @return
|
* @throws TimeoutException
|
* @throws IOException
|
*/
|
@RequestMapping(value = "${requset.processinst09}", method = RequestMethod.POST)
|
public Map<String, Object> instLog(@RequestBody String jsonStr, HttpServletRequest request) throws TimeoutException, IOException {
|
JSONObject jsonObject = JSONObject.fromObject(jsonStr);
|
ProcessInstance pros = new ProcessInstance();
|
pros.setDataRowNum(Integer.parseInt(jsonObject.getString("dataRowNum")));
|
pros.setFormID(jsonObject.getString("formID"));
|
ProcessInstance prop = processInstance.selectInst(pros);
|
System.out.println("流程实例:" + JSONTool.toJson(prop));
|
if (prop == null) {
|
Map<String, Object> remap = new HashMap<>();
|
remap.put("data", null);
|
return remap;
|
}
|
jsonObject.put("processInstId", prop.getProcessInstId());
|
|
workflowTool.setRequest(request);
|
Process process = workflowTool.getProcess(jsonObject);
|
Map<String, Object> result = workflowClient.instLog(process);
|
//每次操作更新本端节点,暂时不操作
|
//processNodeService.operation(result,jsonObject.get("processInstId").toString());
|
System.out.println("流程Log:" + JSONTool.toJson(result));
|
return result;
|
}
|
|
/**
|
* 获取所有可退回项目
|
*
|
* @param jsonStr
|
* @param request
|
* @return
|
* @throws TimeoutException
|
* @throws IOException
|
*/
|
@RequestMapping(value = "${requset.processinst10}", method = RequestMethod.POST)
|
public Map<String, Object> getBack(@RequestBody String jsonStr, HttpServletRequest request) throws TimeoutException, IOException {
|
JSONObject jsonObject = JSONObject.fromObject(jsonStr);
|
workflowTool.setRequest(request);
|
Process process = workflowTool.getProcess(jsonObject);
|
Map<String, Object> result = workflowClient.getBack(process);
|
return result;
|
}
|
|
/**
|
* 查询代理
|
*
|
* @param jsonStr
|
* @param request
|
* @return
|
* @throws TimeoutException
|
* @throws IOException
|
*/
|
@RequestMapping(value = "${requset.processinst11}", method = RequestMethod.POST)
|
public Map<String, Object> instAgent(@RequestBody String jsonStr, HttpServletRequest request) throws TimeoutException, IOException {
|
JSONObject jsonObject = JSONObject.fromObject(jsonStr);
|
workflowTool.setRequest(request);
|
Process process = workflowTool.getProcess(jsonObject);
|
Map<String, Object> result = workflowClient.instAgent(process);
|
return result;
|
}
|
|
/**
|
* 查询代理去除流程定义信息
|
*
|
* @param jsonStr
|
* @param request
|
* @return
|
* @throws TimeoutException
|
* @throws IOException
|
*/
|
@RequestMapping(value = "${requset.processinst12}", method = RequestMethod.POST)
|
public Map<String, Object> instAgentDefMsg(@RequestBody String jsonStr, HttpServletRequest request) throws TimeoutException, IOException {
|
JSONObject jsonObject = JSONObject.fromObject(jsonStr);
|
workflowTool.setRequest(request);
|
Process process = workflowTool.getProcess(jsonObject);
|
Map<String, Object> result = workflowClient.instAgentDefMsg(process);
|
return result;
|
}
|
|
/**
|
* 查询流程实例
|
*
|
* @param jsonStr
|
* @param request
|
* @return
|
* @throws TimeoutException
|
* @throws IOException
|
*/
|
@RequestMapping(value = "${requset.processinst13}", method = RequestMethod.POST)
|
public Map<String, Object> instSeache(@RequestBody String jsonStr, HttpServletRequest request) throws TimeoutException, IOException {
|
JSONObject jsonObject = JSONObject.fromObject(jsonStr);
|
workflowTool.setRequest(request);
|
Process process = workflowTool.getProcess(jsonObject);
|
Map<String, Object> result = workflowClient.instSeache(process);
|
return result;
|
}
|
|
/**
|
* 租户注册系统
|
*
|
* @param jsonStr
|
* @param request
|
* @return
|
* @throws TimeoutException
|
* @throws IOException
|
*/
|
@RequestMapping(value = "${requset.processapp01}", method = RequestMethod.POST)
|
public Map<String, Object> appCreate(@RequestBody String jsonStr, HttpServletRequest request) throws TimeoutException, IOException {
|
JSONObject jsonObject = JSONObject.fromObject(jsonStr);
|
workflowTool.setRequest(request);
|
Process process = workflowTool.getProcess(jsonObject);
|
Map<String, Object> result = workflowClient.appCreate(process);
|
return result;
|
}
|
|
/**
|
* 初始化租户接口
|
*
|
* @param jsonStr
|
* @param request
|
* @return
|
* @throws TimeoutException
|
* @throws IOException
|
*/
|
@RequestMapping(value = "process/initialization", method = RequestMethod.POST)
|
public Map<String, Object> initialization(@RequestBody String jsonStr, HttpServletRequest request) throws TimeoutException, IOException {
|
JSONObject jsonObject = JSONObject.fromObject(jsonStr);
|
Process process = workflowTwe.getProcess(jsonObject);
|
Map<String, Object> result = workflowClient.initialization(process);
|
return result;
|
}
|
|
|
/**
|
* 检查初始化
|
*
|
* @param jsonStr
|
* @param request
|
* @return
|
* @throws TimeoutException
|
* @throws IOException
|
*/
|
@RequestMapping(value = "process/check", method = RequestMethod.POST)
|
public Map<String, Object> check(@RequestBody String jsonStr, HttpServletRequest request) throws TimeoutException, IOException {
|
JSONObject jsonObject = JSONObject.fromObject(jsonStr);
|
Process process = workflowTwe.getProcess(jsonObject);
|
Map<String, Object> result = workflowClient.check(process);
|
return result;
|
}
|
|
public static final String unsubmitted = "20";
|
|
/**
|
* 提交流程时,添加表单大状态
|
*
|
* @throws TimeoutException
|
* @throws FormClientException
|
*/
|
public int updateState(String formId, Integer dataRowNun, String tenantId, String processIntsId) throws FormClientException, TimeoutException {
|
ProcessState pro = new ProcessState();
|
pro.setFormId(formId);
|
/*10:未提交,20:审核中,30审核完成 */
|
pro.setProcessState(unsubmitted);
|
pro.setDataRowNum(dataRowNun);
|
pro.setProcessTask(processIntsId);
|
pro.setTenantId(tenantId);
|
pro.setProcessUser(cscApi.getUserId(ThreadData.get(Keys.OPEN_ID)));
|
process.updateState(pro);
|
return process.updateState(pro);
|
}
|
// @Resource(name = "processStateServiceImpl")
|
// ProcessStateService pros;
|
// @PostMapping("/qwe")
|
// public void dfds() throws TimeoutException, FormClientException{
|
//// pros.selectState(null);
|
//// pros.updateState(null);
|
// ThreadData.set(Keys.COMPANY_ID, "17");
|
// ThreadData.set(Keys.OPEN_ID, "7d65637b5d634dae");
|
//
|
// }
|
|
/**
|
* 每次审批后修改表单大状态
|
*/
|
public int instState() {
|
return 1;
|
}
|
|
|
/**
|
* 自动提交流程第一步
|
*
|
* @throws Exception
|
*/
|
@SuppressWarnings("unchecked")
|
public String instOne(String htmlUrl, String formId, Integer dataRowNun, String tenantId, String processIntsId, String processDefId) throws Exception {
|
//查询待办
|
// System.err.println("--------------------开始自动提交------------------------");
|
JSONObject o = new JSONObject();
|
o.put("processInstId", processIntsId);
|
o.put("params", processApp.getProcessOneActivityParam(
|
processIntsId
|
, processDefId
|
, formId
|
, tenantId
|
, dataRowNun));
|
Map<String, Object> result = workflowClient.instSeacheHandle(workflowTool.getProcess(o));
|
Map<String, Object> map = JSONTool.toObj(JSONTool.toJson(result.get("data")), Map.class);
|
String arctiv = null;
|
if (!ObjectUtil.empty(map.get("data"))) {
|
List<ProcessTask> list = JSONTool.toList(JSONTool.toJson(map.get("data")), ProcessTask.class);
|
if (!ObjectUtil.empty(list) && list.size() > 0) {
|
// System.out.println("-----------------查询自动提交待办-------------------------");
|
o.put("activityInstId", list.get(0).getActivityInstId());
|
arctiv = list.get(0).getActivityDefId();
|
//执行前判断是否是项目负责人审批
|
setProjectleader(list.get(0)
|
, new ProcessState(formId, dataRowNun, tenantId), o);
|
} else {
|
throw new IEMRuntimeException("流程自动提交待办异常,无待办信息!!");
|
}
|
}
|
o.getString("activityInstId");
|
//自动审批第一步
|
Map<String, Object> result1 = workflowClient.instFinish(workflowTool.getProcess(o));
|
Object c = result1.get("data");
|
ProcessState p = new ProcessState(formId, dataRowNun, tenantId);
|
p.setProcessUser(ThreadData.get(Keys.OPEN_ID));
|
String tasks = "";
|
if (!ObjectUtil.empty(c)) {
|
ProcessInstance pro = JSONTool.toObj(JSONTool.toJson(c), ProcessInstance.class);
|
List<ProcessTask> list = pro.getWorkItems();
|
if (list.size() > 0) {
|
StringBuffer s = new StringBuffer();
|
for (ProcessTask pr : list) {
|
// System.out.println("["+cscApi.getUserId(pr.getOpenId())+"]");
|
// s.append("["+cscApi.getUserId(pr.getOpenId())+"]");
|
s.append("[" + pr.getParticipantId() + "]");
|
}
|
tasks = s.toString().replaceAll(",$", "");
|
|
p.setProcessTask(tasks);
|
p.setOrderStatus("21");
|
p.setProcessState("20");
|
} else {
|
this.budgetDeduction(tenantId, formId, dataRowNun);
|
p.setOrderStatus("40");
|
p.setProcessState("30");
|
// return arctiv;
|
}
|
} else {
|
throw new IEMRuntimeException("流程自动提交待办异常,自动提交失败");
|
}
|
//查询待办,把待办人存储到大状态中
|
o.remove("activityInstId");
|
JSONObject jsonObject = new JSONObject();
|
jsonObject.put("processInstId", processIntsId);
|
p.setProcessLog(null);
|
p.setProcessTask(tasks);
|
p.setHtmlUrl(htmlUrl);
|
//单据状态改为审核中
|
System.err.println("---------------------自动审批第一步----------------------");
|
System.out.println("------------------------圆满结束--------------------------");
|
|
process.updateState(p);
|
return arctiv;
|
}
|
|
/**
|
* 审批,退回后后记录已办,和下个节点待办
|
*
|
* @throws FormClientException
|
* @throws TimeoutException
|
*/
|
@SuppressWarnings("unchecked")
|
public int record(String processIntsId, Integer flag, String activityInstId) throws TimeoutException, FormClientException {
|
//取出表单id
|
ProcessInstance pros = processInstance.selectInsts(processIntsId);
|
System.out.println("当前流程:" + JSONTool.toJson(pros));
|
ProcessState pro = new ProcessState(pros.getFormID(), pros.getDataRowNum(), pros.getTenantID());
|
//取出当前流程大状态
|
ProcessState p = process.selectState(pro);
|
p.setDataRowNum(pros.getDataRowNum());
|
p.setFormId(pros.getFormID());
|
p.setTenantId(pros.getTenantID());
|
System.out.println("当前流程大状态:" + JSONTool.toJson(p));
|
//添加已办,已退回
|
ProcessCon con = new ProcessCon();
|
con.setRetired(p.getProcessLog());
|
String z = null;
|
if (flag == 0) {
|
//添加已办
|
con.getRetired().add(String.format(Q, cscApi.getUserId(ThreadData.get(Keys.OPEN_ID))));
|
z = con.getLog();
|
} else {
|
//添加已退
|
con.getRetired().add(String.format(A, cscApi.getUserId(ThreadData.get(Keys.OPEN_ID))));
|
z = con.getLog();
|
if (activityInstId.equals(pros.getActivityInstId())) {
|
p.setProcessState("10");
|
p.setOrderStatus(p.getOrderCode() != null && !p.getOrderCode().isEmpty() ? "15" : "20");
|
z = "";
|
// //修改流程log得状态
|
// ProcessLog plog = new ProcessLog(pros.getFormID(),pros.getDataRowNum()
|
// ,pros.getTenantID(),processIntsId
|
// ,ThreadData.get(Keys.COMPANY_ID),ThreadData.get(Keys.OPEN_ID));
|
// plog.setDataType("30");
|
// processLogService.updateState(plog);
|
//结束流程
|
// this.processInstOver(processIntsId);
|
}
|
}
|
p.setProcessLog(z);
|
//添加新的待办--------------------------
|
JSONObject o = new JSONObject();
|
o.put("processInstId", processIntsId);
|
Map<String, Object> result3 = workflowClient.instSeacheHandle(workflowTool.getProcess(o));
|
Map<String, Object> map1 = JSONTool.toObj(JSONTool.toJson(result3.get("data")), Map.class);
|
if (!ObjectUtil.empty(map1.get("data"))) {
|
List<ProcessTask> list = JSONTool.toList(JSONTool.toJson(map1.get("data")), ProcessTask.class);
|
if (list.size() > 0) {
|
StringBuffer s = new StringBuffer();
|
for (ProcessTask pr : list) {
|
s.append("[" + cscApi.getUserId(pr.getOpenId()) + "]");
|
}
|
p.setProcessTask(s.toString().replaceAll(",$", ""));
|
}
|
}
|
//修改当表单大状态
|
System.out.println("当前状态:" + JSONTool.toJson(p));
|
process.updateState(p);
|
return 1;
|
}
|
|
//判断是否撤回到了 提交活动步骤
|
@SuppressWarnings("unchecked")
|
public boolean updateState(String proId) throws TimeoutException, FormClientException {
|
System.out.println("------------------判断是否撤销到提交活动------------------------");
|
//取出当前流程实例
|
ProcessInstance pro = processInstance.selectInsts(proId);
|
System.out.println("当前流程实例:" + JSONTool.toJson(pro));
|
//查询当前待办
|
JSONObject o = new JSONObject();
|
o.put("processInstId", pro.getProcessInstId());
|
Map<String, Object> result = workflowClient.instSeacheHandle(workflowTool.getProcess(o));
|
Map<String, Object> map1 = JSONTool.toObj(JSONTool.toJson(result.get("data")), Map.class);
|
System.out.println("当前待办信息:" + JSONTool.toJson(map1));
|
if (!ObjectUtil.empty(map1.get("data"))) {
|
List<ProcessTask> list = JSONTool.toList(JSONTool.toJson(map1.get("data")), ProcessTask.class);
|
ProcessState p = new ProcessState(pro.getFormID(), pro.getDataRowNum(), pro.getTenantID());
|
//查询流程大状态
|
ProcessState processState = process.selectState(p);
|
StringBuffer s = new StringBuffer();
|
for (ProcessTask pr : list) {
|
s.append("[" + cscApi.getUserId(pr.getOpenId()) + "]");
|
}
|
p.setProcessTask(s.toString().replaceAll(",$", ""));
|
|
System.out.println("修改流程大状态成功");
|
//判断是否是撤销到第一节点
|
if (pro.getActivityInstId().equals(list.get(0).getActivityDefId())) {
|
//修改流程大状态为未提交
|
p.setProcessState("10");
|
p.setOrderStatus(processState.getOrderCode() != null
|
&& !Objects.equals("", processState.getOrderCode()) ? "15" : "20");
|
p.setProcessLog("");
|
//结束流程
|
// this.processInstOver(proId);
|
// //修改流程log得状态
|
// ProcessLog plog = new ProcessLog(pro.getFormID(),pro.getDataRowNum()
|
// ,pro.getTenantID(),proId
|
// ,ThreadData.get(Keys.COMPANY_ID),ThreadData.get(Keys.OPEN_ID));
|
// plog.setDataType("30");
|
// processLogService.updateState(plog);
|
}
|
process.updateState(p);
|
|
}
|
return true;
|
}
|
|
//流程结束后执行预算逻辑
|
public void budgetDeduction(String tenantId, String formId, Integer dataRowNum) throws FormClientException, TimeoutException {
|
if (this.processFilter != null) {
|
this.processFilter.executeOver(formId, dataRowNum, tenantId);
|
}
|
}
|
|
// //取出表单的自动生成编号
|
// public String getNumber(pse, String formId,Integer dataRowNum,String tenantId) throws TimeoutException, FormClientException{
|
// return getProcessState(formId, dataRowNum,tenantId).getNumber();
|
// }
|
|
public ProcessState getProcessState(String formId, Integer dataRowNum, String tenantId) throws TimeoutException, FormClientException {
|
return process.selectState(new ProcessState(formId, dataRowNum, tenantId));
|
}
|
|
public FormSolidiFication formSolidiFication(String formId, Integer dataRowNum, String tenantId) throws TimeoutException {
|
return dataManagementService.formSolidiFication(formId, dataRowNum, tenantId);
|
}
|
|
/**
|
* 结束流程操作-1
|
*
|
* @throws TimeoutException
|
*/
|
public int processStateOver(String proId) throws TimeoutException {
|
|
return processInstance.updateProState(proId);
|
}
|
|
|
/**
|
* 结束流程操作-2
|
*
|
* @throws TimeoutException
|
*/
|
public int processInstOver(String proId) throws TimeoutException {
|
JSONObject jsonObject = new JSONObject();
|
jsonObject.put("processInstId", proId);
|
workflowClient.instOver(workflowTool.getProcess(jsonObject));
|
return 1;
|
}
|
|
public void checkData(ProcessState ps) {
|
if (Objects.equals(ps.getCreateUser(), ThreadData.get(Keys.OPEN_ID))) {
|
log.debug("当前数据操作人员通过验证");
|
} else {
|
throw new IEMRuntimeException("FORM_USER_AGREEMENT");
|
}
|
}
|
|
|
//到账状态
|
private static final String CONFORMINGSTATE = "conformingstate";
|
|
//回执号
|
private static final String VOUCHERNO = "voucherno";
|
|
//未到账,常量
|
private static final String WDZ = "T00001";
|
|
//交易号
|
private static final String TRADENUMBER = "tradeNumber";
|
|
/**
|
* 新接口 ,编辑并提交,编辑并退回
|
*/
|
@RequestMapping(value = "${requset.processinst14}", method = RequestMethod.POST)
|
public Map vouchernoWirte(@RequestBody Map<String, Object> map, HttpServletRequest request) throws Exception {
|
String state = Objects.toString(map.get(CONFORMINGSTATE), null);
|
String proInstId = Objects.toString(map.get("processInstId"));//当前流程实例id
|
//修改表单数据
|
ProcessState st = new ProcessState(Objects.toString(map.get("formID")), Integer.parseInt(map.get("dataRowNum").toString()), Objects.toString(map.get("tenantID")));
|
st.setConformingstate(state);
|
st.setTradeNumber(Objects.toString(map.get(TRADENUMBER), ""));
|
st.setVoucherno(Objects.toString(map.get(VOUCHERNO), ""));
|
process.updateState(st);
|
//判断执行还是退回
|
if (Objects.equals(WDZ, state)) {
|
log.debug("进入退回");
|
//获取可退回活动项
|
Map<String, Object> ms = this.getBack(JSONTool.toJson(
|
new ModelMap("processInstId", proInstId)), request);
|
Map<String, Object> m = ((List<Map>) ms.get("data")).get(0);
|
m.put("formID", map.get("formID"));
|
m.put("dataRowNum", map.get("dataRowNum"));
|
m.put("tenantID", map.get("tenantID"));
|
m.put("processInstId", proInstId);
|
m.put("activityInstId", map.get("activityInstId"));
|
return this.instBack(m, request);
|
} else {
|
log.debug("进入执行");
|
map.remove(CONFORMINGSTATE);
|
map.remove(VOUCHERNO);
|
map.remove(TRADENUMBER);
|
return this.instFinish(map, request);
|
}
|
|
}
|
|
|
public void setProjectleader(ProcessTask processTask, ProcessState processState, JSONObject jsonObject) throws TimeoutException {
|
log.debug("当前是否活动指派前:" + processTask.getAppointActivity());
|
if (processTask.getAppointActivity() != null && processTask.getAppointActivity()) {
|
ProcessState ps = process.selectState(processState);
|
String phone = Objects.toString(ps.getMainInfo().get(PROJECT_LEADER_PHONE), null);
|
if (phone != null && !Objects.equals(phone, "")) {
|
String id = cscApi.getUserId(phone);
|
log.debug("当前人员id:" + id);
|
if (id != null && !Objects.equals(id, "")) {
|
jsonObject.put("wfpIds", Arrays.asList(id));
|
jsonObject.put("workItemId", processTask.getWorkItemId());
|
}
|
}
|
}
|
}
|
}
|