|
楼主 |
发表于 2020-6-18 09:47:09
|
显示全部楼层
本帖最后由 胡屠户 于 2020-6-18 09:53 编辑
第一步,在插入数据后,需要启动多个流程,放在一个map中。
第二步,遍历循环启动流程,存在流程执行人失效的
第三步,提交事务。
以上所有都被try catch包裹,且异常中回滚
但是依旧造成,数据没插入流程启动了,显示一堆空页面
// 事务控制
Connection conn = null;
PreparedStatement ps = null;
Transaction tx = new Transaction();
// 待发流程
Map<String, JSONObject> toStartProcessMap = new HashMap<String, JSONObject>();
try {
// ================开启事务================
tx.begin();
// 打开连接
conn = tx.getConnection(data);
// 解析JSONArray字符串
Map<String, JSONArray> dataMap = getMapData(xmlStr);
Iterator<Entry<String, JSONArray>> iter = dataMap.entrySet().iterator();
while (iter.hasNext()) {
Entry<String, JSONArray> entry = iter.next();
JSONArray vJsonArray = entry.getValue();
// 插入主从表数据
String mainUUID = getUUID();
JSONObject mJson = vJsonArray.getJSONObject(0);
createRecode(conn, ps, mainUUID, mJson, vJsonArray);
// 装载待启动流程
String processTitle = getProcessTitle(mJson);
Map<String,String> inMap = getFIDAndFNAME(mJson);
JSONObject pJson = new JSONObject();
pJson.put("excutorFID", inMap.get("SFID"));
pJson.put("excutorFName", inMap.get("SFNAME"));
pJson.put("processTitle", processTitle);
toStartProcessMap.put(mainUUID, pJson);
}
// 执行批量启动流程
Iterator<Entry<String, JSONObject>> iterator = toStartProcessMap.entrySet().iterator();
while (iterator.hasNext()) {
Entry<String, JSONObject> entry = iterator.next();
JSONObject vJson = entry.getValue();
String excutorFID = vJson.getString("excutorFID");
String excutorFName = vJson.getString("excutorFName");
String processTitle = vJson.getString("processTitle");
startProcess(entry.getKey(), excutorFID, excutorFName, processTitle);
}
// ================提交事务================
tx.commit();
} catch (Exception e) {
// ================回滚事务================
tx.rollback();
throw new RuntimeException(e);
} finally {
try {
if (ps != null) {
ps.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
System.out.println("##close.SQLException");
}
}
启动流程:
private static void startProcess(String sData1, String excutorFID, String excutorFName,String processTitle) throws Exception {
try {
List<Map<String, String>> list = ProcessUtils.startProcess(processFullName, processTitle, sData1, creatorFID, creatorFID);
for (Map<String, String> map : list) {
String task = map.get("task");
ProcessControl control = ProcessUtils.advanceProcessQuery(task);
for (ProcessControlItem to : control.getFlowTos()) {
Task t = to.getTask();
t.setCreatorFID(creatorFID);
t.setCreatorFName(creatorFName);
//修改默认执行者
to.clearExecutors();
to.addExecutor(new OrgUnit(excutorFID, excutorFName));
}
ProcessUtils.advanceProcess(task, control);
}
} catch (Exception e) {
throw new Exception("启动流程异常!", e);
}
}
|
|