|
@@ -1,6 +1,7 @@
|
|
|
package com.qmth.sop.business.activiti.listener;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.qmth.sop.business.bean.result.FlowFormWidgetResult;
|
|
|
import com.qmth.sop.business.bean.result.FlowResult;
|
|
|
import com.qmth.sop.business.bean.result.FlowTablePropResult;
|
|
@@ -62,110 +63,13 @@ public class ProcessEventListener implements ActivitiEventListener, Serializable
|
|
|
log.info("ENTITY_CREATED,id:{},name:{},deploymentId:{},persistentState:{}", resourceEntity.getId(), resourceEntity.getName(), resourceEntity.getDeploymentId(), resourceEntity.getPersistentState());
|
|
|
String xml = new String(resourceEntity.getBytes(), StandardCharsets.UTF_8);
|
|
|
if (resourceEntity.getName().endsWith(SystemConstant.BPMN_PREFIX)) {
|
|
|
- log.info("ENTITY_CREATED,xml:{}", xml);
|
|
|
- try {
|
|
|
- Document doc = DocumentHelper.parseText(xml);
|
|
|
- Element rootElement = doc.getRootElement();
|
|
|
- // 通过element对象的elementIterator方法获取迭代器
|
|
|
- Iterator iterator = rootElement.elementIterator();
|
|
|
- LinkedHashMap<String, FlowTaskResult> setupMap = new LinkedHashMap<>();//流程审批步骤map
|
|
|
- TFCustomTypeEnum customTypeEnum = null;
|
|
|
- while (iterator.hasNext()) {
|
|
|
- Element element = (Element) iterator.next();
|
|
|
- List<Attribute> attributes = element.attributes();
|
|
|
- for (Attribute attr : attributes) {
|
|
|
-// log.info("属性:{},---值:{}", attr.getName(), attr.getValue());
|
|
|
- if (Objects.equals(attr.getName(), SystemConstant.ID) &&
|
|
|
- (Objects.equals(attr.getValue(), TFCustomTypeEnum.OFFICE_SOP_FLOW.name())
|
|
|
- || Objects.equals(attr.getValue(), TFCustomTypeEnum.CLOUD_MARK_SOP_FLOW.name())
|
|
|
- || Objects.equals(attr.getValue(), TFCustomTypeEnum.DING_EXCEPTION_FLOW.name())
|
|
|
- || Objects.equals(attr.getValue(), TFCustomTypeEnum.PROJECT_EXCHANGE_FLOW.name())
|
|
|
- || Objects.equals(attr.getValue(), TFCustomTypeEnum.QUALITY_PROBLEM_FLOW.name()))) {
|
|
|
- customTypeEnum = TFCustomTypeEnum.valueOf(attr.getValue());
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- Iterator itt = element.elementIterator();
|
|
|
- while (itt.hasNext()) {
|
|
|
- FlowTaskResult flowTaskResult = new FlowTaskResult();
|
|
|
- Element node = (Element) itt.next();
|
|
|
- attributes = node.attributes();
|
|
|
-// log.info("节点:{},---值:{}", node.getName(), node.getStringValue());
|
|
|
- if (Objects.equals(node.getName(), SystemConstant.USER_TASK) || Objects.equals(node.getName(), SystemConstant.END_EVENT)) {
|
|
|
- for (Attribute attr : attributes) {
|
|
|
-// log.info("节点属性:{},---节点值:{}", attr.getName(), attr.getValue());
|
|
|
- if (Objects.equals(attr.getName(), SystemConstant.ID)) {
|
|
|
- flowTaskResult.setTaskKey(attr.getValue());
|
|
|
- flowTaskResult.setSetup(Integer.valueOf(attr.getValue().substring(attr.getValue().length() - 1, attr.getValue().length())));
|
|
|
- setupMap.put(attr.getValue(), flowTaskResult);
|
|
|
- } else if (Objects.equals(attr.getName(), SystemConstant.NAME)) {
|
|
|
- flowTaskResult.setTaskName(attr.getValue());
|
|
|
- }
|
|
|
-// else if (Objects.equals(attr.getName(), SystemConstant.ASSIGNEE_USER)) {
|
|
|
-// flowTaskResult.setFlowTaskVar(attr.getValue().replaceAll("\\$\\{", "").replaceAll("\\}", ""));
|
|
|
-// }
|
|
|
- else if (Objects.equals(attr.getName(), SystemConstant.FORM_KEY) && SystemConstant.FLOW_MAP.containsKey(resourceEntity.getDeploymentId() + SystemConstant.FLOW_FORM_ID_SPACE + attr.getValue())) {
|
|
|
- flowTaskResult.setFormKey(attr.getValue());
|
|
|
- List<String> list = SystemConstant.FLOW_MAP.get(resourceEntity.getDeploymentId() + SystemConstant.FLOW_FORM_ID_SPACE + attr.getValue());
|
|
|
- String data = list.get(list.size() - 1);
|
|
|
- List<FlowFormWidgetResult> listData = JSONArray.parseArray(data, FlowFormWidgetResult.class);
|
|
|
- for (FlowFormWidgetResult f : listData) {
|
|
|
- f.setFormId(flowTaskResult.getTaskKey() + SystemConstant.FLOW_FORM_ID_SPACE + f.getFormId());
|
|
|
- f.setFormName(flowTaskResult.getTaskKey() + SystemConstant.FLOW_FORM_ID_SPACE + f.getFormName());
|
|
|
- if (!CollectionUtils.isEmpty(f.getTablePropList())) {
|
|
|
- for (FlowTablePropResult t : f.getTablePropList()) {
|
|
|
- t.setTdId(flowTaskResult.getTaskKey() + SystemConstant.FLOW_FORM_ID_SPACE + t.getWidgetId() + SystemConstant.FLOW_FORM_ID_SPACE + t.getTdId());
|
|
|
- t.setTdName(flowTaskResult.getTaskKey() + SystemConstant.FLOW_FORM_ID_SPACE + t.getWidgetId() + SystemConstant.FLOW_FORM_ID_SPACE + t.getTdName());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- flowTaskResult.setFormProperty(listData);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- List<Map.Entry<String, FlowTaskResult>> entryList = new ArrayList<Map.Entry<String, FlowTaskResult>>(setupMap.entrySet());
|
|
|
- //比较器
|
|
|
- Collections.sort(entryList, new Comparator<Map.Entry<String, FlowTaskResult>>() {
|
|
|
- @Override
|
|
|
- public int compare(Map.Entry<String, FlowTaskResult> o1, Map.Entry<String, FlowTaskResult> o2) {
|
|
|
- if (o2.getValue().getSetup() < o1.getValue().getSetup()) {
|
|
|
- return 1;
|
|
|
- } else if (o2.getValue().getSetup() > o1.getValue().getSetup()) {
|
|
|
- return -1;
|
|
|
- } else {
|
|
|
- return 0;
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- setupMap.clear();
|
|
|
- Iterator<Map.Entry<String, FlowTaskResult>> iter = entryList.iterator();
|
|
|
- Map.Entry<String, FlowTaskResult> tmpEntry = null;
|
|
|
- while (iter.hasNext()) {
|
|
|
- tmpEntry = iter.next();
|
|
|
- setupMap.put(tmpEntry.getKey(), tmpEntry.getValue());
|
|
|
- }
|
|
|
- FlowResult flowResult = new FlowResult(resourceEntity.getDeploymentId(), resourceEntity.getName(), setupMap);
|
|
|
- log.info("flowResult:{}", JacksonUtil.parseJson(flowResult));
|
|
|
- TFCustomFlowService tfCustomFlowService = SpringContextHolder.getBean(TFCustomFlowService.class);
|
|
|
- TFCustomFlow maxTfCustomFlow = tfCustomFlowService.findMaxVersion(null, flowResult.getFlowName(), customTypeEnum);
|
|
|
- TFCustomFlow tfCustomFlow = new TFCustomFlow(null, flowResult.getFlowName(), customTypeEnum, flowResult.getFlowDeploymentId(), TFCustomModelTypeEnum.USER_FIXED);
|
|
|
- flowResult.setId(tfCustomFlow.getId());
|
|
|
- if (Objects.nonNull(maxTfCustomFlow)) {
|
|
|
- tfCustomFlow.setVersion(maxTfCustomFlow.getVersion() + 1);
|
|
|
- } else {
|
|
|
- tfCustomFlow.setVersion(1);
|
|
|
- }
|
|
|
- flowResult.setVersion(tfCustomFlow.getVersion());
|
|
|
- tfCustomFlow.setFlowProcessVar(JacksonUtil.parseJson(flowResult));
|
|
|
- tfCustomFlowService.save(tfCustomFlow);
|
|
|
- } catch (DocumentException e) {
|
|
|
- log.error(SystemConstant.LOG_ERROR, e);
|
|
|
- }
|
|
|
+ parseXml(xml, resourceEntity);
|
|
|
} else {
|
|
|
// log.info("ENTITY_CREATED,data:{}", data);
|
|
|
SystemConstant.FLOW_MAP.add(resourceEntity.getDeploymentId() + SystemConstant.FLOW_FORM_ID_SPACE + resourceEntity.getName(), xml);
|
|
|
+ if (SystemConstant.FLOW_MAP.containsKey(resourceEntity.getDeploymentId() + SystemConstant.BPMN_PREFIX)) {
|
|
|
+ parseXml(SystemConstant.FLOW_MAP.get(resourceEntity.getDeploymentId() + SystemConstant.BPMN_PREFIX).get(0), resourceEntity);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
@@ -179,4 +83,122 @@ public class ProcessEventListener implements ActivitiEventListener, Serializable
|
|
|
public boolean isFailOnException() {
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解析xml
|
|
|
+ *
|
|
|
+ * @param xml
|
|
|
+ * @param resourceEntity
|
|
|
+ */
|
|
|
+ protected void parseXml(String xml, ResourceEntity resourceEntity) {
|
|
|
+ log.info("ENTITY_CREATED,xml:{}", xml);
|
|
|
+ try {
|
|
|
+ Document doc = DocumentHelper.parseText(xml);
|
|
|
+ Element rootElement = doc.getRootElement();
|
|
|
+ // 通过element对象的elementIterator方法获取迭代器
|
|
|
+ Iterator iterator = rootElement.elementIterator();
|
|
|
+ LinkedHashMap<String, FlowTaskResult> setupMap = new LinkedHashMap<>();//流程审批步骤map
|
|
|
+ TFCustomTypeEnum customTypeEnum = null;
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ Element element = (Element) iterator.next();
|
|
|
+ List<Attribute> attributes = element.attributes();
|
|
|
+ for (Attribute attr : attributes) {
|
|
|
+// log.info("属性:{},---值:{}", attr.getName(), attr.getValue());
|
|
|
+ if (Objects.equals(attr.getName(), SystemConstant.ID) &&
|
|
|
+ (Objects.equals(attr.getValue(), TFCustomTypeEnum.OFFICE_SOP_FLOW.name())
|
|
|
+ || Objects.equals(attr.getValue(), TFCustomTypeEnum.CLOUD_MARK_SOP_FLOW.name())
|
|
|
+ || Objects.equals(attr.getValue(), TFCustomTypeEnum.DING_EXCEPTION_FLOW.name())
|
|
|
+ || Objects.equals(attr.getValue(), TFCustomTypeEnum.PROJECT_EXCHANGE_FLOW.name())
|
|
|
+ || Objects.equals(attr.getValue(), TFCustomTypeEnum.QUALITY_PROBLEM_FLOW.name()))) {
|
|
|
+ customTypeEnum = TFCustomTypeEnum.valueOf(attr.getValue());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Iterator itt = element.elementIterator();
|
|
|
+ while (itt.hasNext()) {
|
|
|
+ FlowTaskResult flowTaskResult = new FlowTaskResult();
|
|
|
+ Element node = (Element) itt.next();
|
|
|
+ attributes = node.attributes();
|
|
|
+// log.info("节点:{},---值:{}", node.getName(), node.getStringValue());
|
|
|
+ if (Objects.equals(node.getName(), SystemConstant.USER_TASK) || Objects.equals(node.getName(), SystemConstant.END_EVENT)) {
|
|
|
+ for (Attribute attr : attributes) {
|
|
|
+// log.info("节点属性:{},---节点值:{}", attr.getName(), attr.getValue());
|
|
|
+ if (Objects.equals(attr.getName(), SystemConstant.ID)) {
|
|
|
+ flowTaskResult.setTaskKey(attr.getValue());
|
|
|
+ flowTaskResult.setSetup(Integer.valueOf(attr.getValue().substring(attr.getValue().length() - 1, attr.getValue().length())));
|
|
|
+ setupMap.put(attr.getValue(), flowTaskResult);
|
|
|
+ } else if (Objects.equals(attr.getName(), SystemConstant.NAME)) {
|
|
|
+ flowTaskResult.setTaskName(attr.getValue());
|
|
|
+ }
|
|
|
+// else if (Objects.equals(attr.getName(), SystemConstant.ASSIGNEE_USER)) {
|
|
|
+// flowTaskResult.setFlowTaskVar(attr.getValue().replaceAll("\\$\\{", "").replaceAll("\\}", ""));
|
|
|
+// }
|
|
|
+ else if (Objects.equals(attr.getName(), SystemConstant.FORM_KEY) && SystemConstant.FLOW_MAP.containsKey(resourceEntity.getDeploymentId() + SystemConstant.FLOW_FORM_ID_SPACE + attr.getValue())) {
|
|
|
+ flowTaskResult.setFormKey(attr.getValue());
|
|
|
+ List<String> list = SystemConstant.FLOW_MAP.get(resourceEntity.getDeploymentId() + SystemConstant.FLOW_FORM_ID_SPACE + attr.getValue());
|
|
|
+ String data = list.get(list.size() - 1);
|
|
|
+ List<FlowFormWidgetResult> listData = JSONArray.parseArray(data, FlowFormWidgetResult.class);
|
|
|
+ for (FlowFormWidgetResult f : listData) {
|
|
|
+ f.setFormId(flowTaskResult.getTaskKey() + SystemConstant.FLOW_FORM_ID_SPACE + f.getFormId());
|
|
|
+ f.setFormName(flowTaskResult.getTaskKey() + SystemConstant.FLOW_FORM_ID_SPACE + f.getFormName());
|
|
|
+ if (!CollectionUtils.isEmpty(f.getTablePropList())) {
|
|
|
+ for (FlowTablePropResult t : f.getTablePropList()) {
|
|
|
+ t.setTdId(flowTaskResult.getTaskKey() + SystemConstant.FLOW_FORM_ID_SPACE + t.getWidgetId() + SystemConstant.FLOW_FORM_ID_SPACE + t.getTdId());
|
|
|
+ t.setTdName(flowTaskResult.getTaskKey() + SystemConstant.FLOW_FORM_ID_SPACE + t.getWidgetId() + SystemConstant.FLOW_FORM_ID_SPACE + t.getTdName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ flowTaskResult.setFormProperty(listData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<Map.Entry<String, FlowTaskResult>> entryList = new ArrayList<Map.Entry<String, FlowTaskResult>>(setupMap.entrySet());
|
|
|
+ //比较器
|
|
|
+ Collections.sort(entryList, new Comparator<Map.Entry<String, FlowTaskResult>>() {
|
|
|
+ @Override
|
|
|
+ public int compare(Map.Entry<String, FlowTaskResult> o1, Map.Entry<String, FlowTaskResult> o2) {
|
|
|
+ if (o2.getValue().getSetup() < o1.getValue().getSetup()) {
|
|
|
+ return 1;
|
|
|
+ } else if (o2.getValue().getSetup() > o1.getValue().getSetup()) {
|
|
|
+ return -1;
|
|
|
+ } else {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ setupMap.clear();
|
|
|
+ Iterator<Map.Entry<String, FlowTaskResult>> iter = entryList.iterator();
|
|
|
+ Map.Entry<String, FlowTaskResult> tmpEntry = null;
|
|
|
+ while (iter.hasNext()) {
|
|
|
+ tmpEntry = iter.next();
|
|
|
+ setupMap.put(tmpEntry.getKey(), tmpEntry.getValue());
|
|
|
+ }
|
|
|
+ FlowResult flowResult = new FlowResult(resourceEntity.getDeploymentId(), resourceEntity.getName(), setupMap);
|
|
|
+// log.info("flowResult:{}", JacksonUtil.parseJson(flowResult));
|
|
|
+ TFCustomFlowService tfCustomFlowService = SpringContextHolder.getBean(TFCustomFlowService.class);
|
|
|
+ TFCustomFlow tfCustomFlow = tfCustomFlowService.getOne(new QueryWrapper<TFCustomFlow>().lambda().eq(TFCustomFlow::getFlowDeploymentId, flowResult.getFlowDeploymentId()));
|
|
|
+ if (Objects.isNull(tfCustomFlow)) {
|
|
|
+ TFCustomFlow maxTfCustomFlow = tfCustomFlowService.findMaxVersion(null, flowResult.getFlowName(), customTypeEnum);
|
|
|
+ tfCustomFlow = new TFCustomFlow(null, flowResult.getFlowName(), customTypeEnum, flowResult.getFlowDeploymentId(), TFCustomModelTypeEnum.USER_FIXED);
|
|
|
+ flowResult.setId(tfCustomFlow.getId());
|
|
|
+ if (Objects.nonNull(maxTfCustomFlow)) {
|
|
|
+ tfCustomFlow.setVersion(maxTfCustomFlow.getVersion() + 1);
|
|
|
+ } else {
|
|
|
+ tfCustomFlow.setVersion(1);
|
|
|
+ }
|
|
|
+ flowResult.setVersion(tfCustomFlow.getVersion());
|
|
|
+ } else {
|
|
|
+ flowResult.setId(tfCustomFlow.getId());
|
|
|
+ flowResult.setVersion(tfCustomFlow.getVersion());
|
|
|
+ tfCustomFlow.setUpdateTime(System.currentTimeMillis());
|
|
|
+ }
|
|
|
+ tfCustomFlow.setFlowProcessVar(JacksonUtil.parseJson(flowResult));
|
|
|
+ tfCustomFlowService.saveOrUpdate(tfCustomFlow);
|
|
|
+ } catch (DocumentException e) {
|
|
|
+ log.error(SystemConstant.LOG_ERROR, e);
|
|
|
+ }
|
|
|
+ SystemConstant.FLOW_MAP.add(resourceEntity.getDeploymentId() + SystemConstant.BPMN_PREFIX, xml);
|
|
|
+ }
|
|
|
}
|