前后置流程功能开发,流程发布、变更、废止相关处理

This commit is contained in:
446052889@qq.com 2022-10-25 16:49:32 +08:00
parent 9e7a4a5d72
commit 0470c7cee8
2 changed files with 179 additions and 3 deletions

View File

@ -1,10 +1,14 @@
package com.actionsoft.apps.coe.pal.publisher.event;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import com.actionsoft.apps.coe.pal.constant.CoEConstant;
import com.actionsoft.apps.coe.pal.log.CoEOpLogAPI;
import com.actionsoft.apps.coe.pal.log.CoEOpLogConst;
import com.actionsoft.apps.coe.pal.pal.manage.publish.dao.PublishHistory;
import com.actionsoft.apps.coe.pal.pal.manage.publish.dao.PublishListHistory;
import com.actionsoft.apps.coe.pal.pal.manage.publish.model.PublishHistoryModel;
@ -15,8 +19,11 @@ import com.actionsoft.apps.coe.pal.pal.repository.PALRepositoryQueryAPIManager;
import com.actionsoft.apps.coe.pal.pal.repository.cache.PALRepositoryCache;
import com.actionsoft.apps.coe.pal.pal.repository.dao.PALRepository;
import com.actionsoft.apps.coe.pal.pal.repository.dao.PALRepositoryPropertyDao;
import com.actionsoft.apps.coe.pal.pal.repository.designer.constant.CoeDesignerConstant;
import com.actionsoft.apps.coe.pal.pal.repository.designer.manage.CoeDesignerAPIManager;
import com.actionsoft.apps.coe.pal.pal.repository.designer.model.BaseModel;
import com.actionsoft.apps.coe.pal.pal.repository.designer.relation.dao.DesignerShapeRelationDao;
import com.actionsoft.apps.coe.pal.pal.repository.designer.relation.model.DesignerShapeRelationModel;
import com.actionsoft.apps.coe.pal.pal.repository.designer.util.CoeDesignerUtil;
import com.actionsoft.apps.coe.pal.pal.repository.model.PALRepositoryModel;
import com.actionsoft.apps.coe.pal.pal.repository.model.PALRepositoryPropertyModel;
@ -176,6 +183,8 @@ public class PublishExecuteListenerInterfaceImpl extends ExecuteListener impleme
repositoryDao.updatePublishStatusAndDate("S", boS.get("STOPFILEID").toString(), null, model.getPublishDate());
}
}
// 将发布相关的流程作为前后置流程的流程接口名称调整
updatePublishRepositoryRelationRearLeadhape(param.getUserContext(), bo, bolistN, bolistC, bolistS);
// 生效日期信息处理&并创建手册
updateEffectiveDateProperty(processInstId, bo, nowTime, bolistN, bolistC);
// 流程发布范围权限单独存储
@ -185,6 +194,173 @@ public class PublishExecuteListenerInterfaceImpl extends ExecuteListener impleme
}
/**
* 以当前发布变更停用的流程作为前后置流程的流程对其流程接口的文本进行调整
* @param bo
* @param bolistN
* @param bolistC
* @param bolistS
*/
private void updatePublishRepositoryRelationRearLeadhape(UserContext uc, BO bo, List<BO> bolistN, List<BO> bolistC, List<BO> bolistS) {
Set<String> newSet = new HashSet<>();
Set<String> changeSet = new HashSet<>();
Set<String> stopSet= new HashSet<>();
if (bolistN != null) {
for (BO boN : bolistN) {
String palId = boN.get("PUBLISHFILEID").toString();
newSet.add(palId);
}
}
if (bolistC != null) {
for (BO boC : bolistC) {
String palId = boC.get("CHANGEDFILEIDNEW").toString();
changeSet.add(palId);
}
}
if (bolistS != null) {
for (BO boS : bolistS) {
String palId = boS.get("STOPFILEID").toString();
stopSet.add(palId);
}
}
DesignerShapeRelationDao relationDao = new DesignerShapeRelationDao();
updateLeadRear(uc, newSet, relationDao, "new");
updateLeadRear(uc, changeSet, relationDao, "change");
updateLeadRear(uc, stopSet, relationDao, "stop");
}
private void updateLeadRear(UserContext uc, Set<String> set, DesignerShapeRelationDao relationDao, String type) {
for (String id : set) {
PALRepositoryModel model = PALRepositoryCache.getCache().get(id);
if (model == null) {
continue;
}
Set<String> rearSet = new HashSet<>();
Set<String> leadSet = new HashSet<>();
List<DesignerShapeRelationModel> list1 = relationDao.query(null, null, null, model.getVersionId(), null);
for (DesignerShapeRelationModel m1 : list1) {
if (UtilString.isEmpty(m1.getRelationShapeId())) {
// 伊利前后置流程的数据处理 by sunlh 20221025
if ("rear_process".equals(m1.getAttrId())) {// 后置流程
rearSet.add(m1.getFileId());
} else if ("lead_process".equals(m1.getAttrId())) {// 前置流程
leadSet.add(m1.getFileId());
}
}
}
// 更新将该模型作为前后置流程相关模型 伊利 by sunlh 20221025
updateLeadRearRepositoryDesigner(uc, leadSet, "top", model, type);
updateLeadRearRepositoryDesigner(uc, rearSet, "bottom", model, type);
}
}
/**
* 更新将该模型作为前后置流程相关模型 伊利 by sunlh 20221025
*/
private void updateLeadRearRepositoryDesigner(UserContext uc, Set<String> set, String position, PALRepositoryModel pubilshModel, String type) {
for (String uuid : set) {
PALRepositoryModel model = PALRepositoryCache.getCache().get(uuid);
if (model != null) {
String define = PALRepositoryQueryAPIManager.getInstance().getProcessDefinition(null, uuid);
try {
boolean update = false;
JSONObject definition = JSONObject.parseObject(define);
JSONObject elements = definition.getJSONObject("elements");
JSONArray procedureShapeArr= getProcedureShapeArr(elements);
for (int i = 0; i < procedureShapeArr.size(); i++) {
JSONObject shape = procedureShapeArr.getJSONObject(i);
if (matchProcedureObj(shape, pubilshModel.getVersionId(), pubilshModel.getName(), position)) {
update = true;
String id = shape.getString("id");
elements.getJSONObject(id).put("text", ("new".equals(type) || "change".equals(type)) ? pubilshModel.getName() : pubilshModel.getName() + "(已废止)");
}
}
if (update) {
// 保存
BaseModel defineModel = CoeDesignerAPIManager.getInstance().getDefinition(uuid, 0);
if (defineModel == null) {
defineModel = CoeDesignerUtil.createModel(uuid, 0);
defineModel.setCreateHistory(false);
}
definition.put("elements", elements);
defineModel.setDefinition(definition.toString());
defineModel.setUpdateTime(new SimpleDateFormat(CoeDesignerConstant.DATE_TIME_STYLE_YYYY_MM_DD_HH_MM_SS).format(new Date()));
// 保存文件
CoeDesignerAPIManager.getInstance().storeDefinition(defineModel);// dao操作
// 记录操作行为日志
if (SDK.getAppAPI().getPropertyBooleanValue(CoEConstant.APP_ID, "IS_RECORD_OP_LOG", false)) {
CoEOpLogAPI.auditOkOp(uc, CoEOpLogConst.MODULE_CATEGORY_REPOSITORY, CoEOpLogConst.OP_UPDATE, CoEOpLogConst.INFO_REPOSITORY_DESIGNER_UPDATE + ",文件属性["+ ("top".equals(position) ? "前置" : "后置") +"流程]触发流程接口形状更新");
SDK.getLogAPI().consoleInfo("[成功][" + pubilshModel.getName() + "]被"+ ("new".equals(type) ? "发布" : "change".equals(type) ? "变更" : "废止") +",文件属性["+ ("top".equals(position) ? "前置" : "后置") +"流程]触发流程[" + model.getName() + "][" + model.getId() + "]流程接口形状更新");
}
}
} catch (Exception e) {
e.printStackTrace();
SDK.getLogAPI().consoleErr("模型["+ model.getName() +"][" + model.getId() + "]模型文件转换JSON异常");
continue;
}
}
}
}
private boolean matchProcedureObj(JSONObject shape, String versionId, String name, String position) {
if (shape.containsKey("attrMark") && shape.getJSONObject("attrMark") != null) {
return versionId.equals(shape.getJSONObject("attrMark").getString("versionId")) && !name.equals(shape.getString("shapeText"));
}
return false;
}
private JSONArray getProcedureShapeArr(JSONObject elements) {
JSONArray result = new JSONArray();
Iterator<String> it = elements.keySet().iterator();
while (it.hasNext()) {
String key = it.next();
JSONObject shape = elements.getJSONObject(key);
String name = shape.getString("name");
if ("procedure".equals(name)) {// 流程接口
JSONObject obj = new JSONObject();
String shapeText = shape.getString("text");
JSONArray fromLinkerArr = new JSONArray();
JSONArray toLinkerArr = new JSONArray();
JSONObject attrMark = shape.getJSONObject("attrMark");
obj.put("id", key);
obj.put("shapeText", shapeText);
obj.put("fromLinkerArr", fromLinkerArr);
obj.put("toLinkerArr", toLinkerArr);
obj.put("attrMark", attrMark);
getInterfaceShapeLink(obj, elements);
result.add(obj);
}
}
return result;
}
private void getInterfaceShapeLink(JSONObject obj, JSONObject elements) {
Iterator<String> it = elements.keySet().iterator();
while (it.hasNext()) {
String key = it.next();
JSONObject shape = elements.getJSONObject(key);
String name = shape.getString("name");
if ("linker".equals(name)) {// 连线
// 出线
JSONObject from = shape.getJSONObject("from");
// 入线
JSONObject to = shape.getJSONObject("to");
if (from != null && to != null) {
String fromId = from.getString("id");
String toId = to.getString("id");
if (obj.getString("id").equals(fromId)) {
obj.getJSONArray("fromLinkerArr").add(key);
}
if (obj.getString("id").equals(toId)) {
obj.getJSONArray("toLinkerArr").add(key);
}
}
}
}
}
private void updateEffectiveDateProperty(String processInstId, BO bo, Timestamp publishDate, List<BO> bolistN, List<BO> bolistC) {
// 对epc表单制度图进行生效日期更新和手册重新生成
// epc:process.epc effective_date
@ -333,7 +509,7 @@ public class PublishExecuteListenerInterfaceImpl extends ExecuteListener impleme
* 创建手册
* @param model
* @param wsId
* @param _uc
* @param userId
* @param teamId
* @param uuid
* @return
@ -366,7 +542,7 @@ public class PublishExecuteListenerInterfaceImpl extends ExecuteListener impleme
* 更新文件属性生效日期
*
* @param model
* @param publishDate
* @param date
* @param propertyDao
*/
private boolean updatePropertyEffectiveDate(PALRepositoryModel model, String date, PALRepositoryPropertyDao propertyDao) {
@ -413,7 +589,7 @@ public class PublishExecuteListenerInterfaceImpl extends ExecuteListener impleme
/**
* 流程发布范围权限单独存储
* @param bo 流程发布bo主表
* @param publish 流程发布bo主表
* @param bolistN 新增发布流程信息
* @param bolistC 变更发布流程信息需要将已存在的相应流程权限信息进行删除再进行权限存储
* @param bolistS 停用发布流程信息删除相应流程权限信息