流程发布完成后生效日期更新,流程手册重新生成并挂载到表单

This commit is contained in:
446052889@qq.com 2022-07-28 17:35:27 +08:00
parent c9b8e64e42
commit 66377dcc60
3 changed files with 246 additions and 4 deletions

View File

@ -2,23 +2,36 @@ package com.actionsoft.apps.coe.pal.publisher.event;
import java.sql.Timestamp;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
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;
import com.actionsoft.apps.coe.pal.pal.manage.publish.model.PublishListHistoryModel;
import com.actionsoft.apps.coe.pal.pal.output.dao.OutputTask;
import com.actionsoft.apps.coe.pal.pal.output.model.OutputTaskModel;
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.model.PALRepositoryModel;
import com.actionsoft.apps.coe.pal.publisher.client.util.ProcesNumberUtil;
import com.actionsoft.apps.coe.pal.pal.repository.model.PALRepositoryPropertyModel;
import com.actionsoft.apps.coe.pal.publisher.client.util.ProcessStatusAPIManager;
import com.actionsoft.apps.coe.pal.publisher.constant.PublisherConstant;
import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.bpmn.engine.core.delegate.ProcessExecutionContext;
import com.actionsoft.bpms.bpmn.engine.listener.ExecuteListener;
import com.actionsoft.bpms.bpmn.engine.listener.ExecuteListenerInterface;
import com.actionsoft.bpms.commons.mvc.view.ResponseObject;
import com.actionsoft.bpms.server.UserContext;
import com.actionsoft.bpms.util.DBSql;
import com.actionsoft.bpms.util.UUIDGener;
import com.actionsoft.bpms.util.UtilDate;
import com.actionsoft.bpms.util.UtilString;
import com.actionsoft.exception.AWSException;
import com.actionsoft.sdk.local.SDK;
import com.alibaba.fastjson.JSONObject;
public class PublishExecuteListenerInterfaceImpl extends ExecuteListener implements ExecuteListenerInterface {
@ -48,6 +61,7 @@ public class PublishExecuteListenerInterfaceImpl extends ExecuteListener impleme
return;
}
BO bo = SDK.getBOAPI().query(PublisherConstant.BOTABLENAME).detailByBindId(processInstId);
Timestamp nowTime = new Timestamp(System.currentTimeMillis());
model.setId(UUIDGener.getUUID());
model.setProcessInstId(processInstId);
model.setWsId(bo.get("WSID").toString());
@ -61,7 +75,7 @@ public class PublishExecuteListenerInterfaceImpl extends ExecuteListener impleme
auditorId = bo.get("AUDITOR1").toString();
}
model.setAuditorId(auditorId);
model.setPublishDate(Timestamp.valueOf(bo.get("UPDATEDATE").toString()));
model.setPublishDate(nowTime);
model.setPublishDesc(bo.get("PUBLISHDESC") == null ? "" : bo.get("PUBLISHDESC").toString());
model.setTeamId(bo.get("TEAMID").toString());
@ -74,7 +88,7 @@ public class PublishExecuteListenerInterfaceImpl extends ExecuteListener impleme
PublishHistory dao = new PublishHistory();
dao.insert(model);
PublishListHistory listDao = new PublishListHistory();
PALRepository repositoryDao = new PALRepository();
//将发布信息保存至coe的发布子表中
@ -137,10 +151,238 @@ public class PublishExecuteListenerInterfaceImpl extends ExecuteListener impleme
repositoryDao.updatePublishStatusAndDate("S", boS.get("STOPFILEID").toString(), null, model.getPublishDate());
}
}
// 生效日期信息处理&并创建手册
updateEffectiveDateProperty(processInstId, bo, nowTime, bolistN, bolistC);
// 流程发布范围权限单独存储
savePublishScope(bo, bolistN, bolistC, bolistS);
}
private void updateEffectiveDateProperty(String processInstId, BO bo, Timestamp publishDate, List<BO> bolistN, List<BO> bolistC) {
// 对epc表单制度图进行生效日期更新和手册重新生成
// epc:process.epc effective_date
// 表单:data.form form_effective_date
// 制度:control.policy effective_date
String applyUser = bo.getString("APPLYUSERID");// 以申请人身份创建流程手册
String date = UtilDate.datetimeFormat(publishDate);
PALRepositoryPropertyDao propertyDao = new PALRepositoryPropertyDao();
// 创建线程池进行流程手册的处理
ExecutorService service = Executors.newFixedThreadPool(4);
//将发布范围权限信息保存至范围权限表
if (bolistN != null) {
for (BO boN : bolistN) {
String palId = boN.get("PUBLISHFILEID").toString();
PALRepositoryModel model = PALRepositoryCache.getCache().get(palId);
if (model == null) {
SDK.getLogAPI().consoleErr("[更新生效日期和创建手册]更新失败,模型不存在,模型[" + palId + "]");
continue;
}
// 新增模型时间
if (updatePropertyEffectiveDate(model, date, propertyDao)) {
// 重新创建手册
service.execute(new Runnable() {
@Override
public void run() {
updateProcessReport(model.getId(), processInstId, "N", applyUser);
}
});
}
}
}
if (bolistC != null) {
for (BO boC : bolistC) {
String palId = boC.get("CHANGEDFILEIDNEW").toString();
PALRepositoryModel model = PALRepositoryCache.getCache().get(palId);
if (model == null) {
SDK.getLogAPI().consoleErr("[更新生效日期和创建手册]更新失败,模型不存在,模型[" + palId + "]");
continue;
}
// 新增模型时间
if (updatePropertyEffectiveDate(model, date, propertyDao)) {
// 重新创建手册
service.execute(new Runnable() {
@Override
public void run() {
updateProcessReport(model.getId(), processInstId, "C", applyUser);
}
});
}
}
}
}
/**
* 新生成流程手册编号进行处理
* @param uuid
*/
private void updateProcessReport(String uuid, String processInstId, String type, String appUser) {
// epc:process.epc effective_date
// 表单:data.form form_effective_date
// 制度:control.policy effective_date
PALRepositoryModel model = PALRepositoryCache.getCache().get(uuid);
String category = model.getMethodCategory();
if ("default".equals(model.getMethodId())) {
return;
}
// 校验流程手册是否安装并启动
if ("process".equals(category) && !SDK.getAppAPI().isActive("com.actionsoft.apps.coe.pal.output.pr")) {
SDK.getLogAPI().consoleErr("[流程手册未安装]流程手册更新失败");
return;
}
if ("data".equals(category) && !SDK.getAppAPI().isActive("com.awspaas.user.apps.coe.pal.output.bd")) {
SDK.getLogAPI().consoleErr("[表单手册未安装]流程手册更新失败");
return;
}
if ("control".equals(category) && !SDK.getAppAPI().isActive("com.awspaas.user.apps.coe.pal.output.zd")) {
SDK.getLogAPI().consoleErr("[表单手册未安装]流程手册更新失败");
return;
}
if ("N".equals(type)) {
BO nBo = SDK.getBOAPI().query(PublisherConstant.BOSUBTABLE_N, true)
.bindId(processInstId)
.addQuery("PUBLISHFILEID=", uuid)
.detail();
if (nBo != null) {
String boId = nBo.getId();
// 创建流程手册
String oldTaskId = nBo.getString("TASKID");
// 获取报告类型
OutputTaskModel taskModel = new OutputTask().getTaskReportById(oldTaskId);
if (taskModel != null) {
String taskId = createOutputReport(model, model.getWsId(), appUser, "", model.getId());
if (UtilString.isNotEmpty(taskId)) {
// 更新流程发布表
SDK.getLogAPI().consoleInfo("流程发布[发布]审核完成后创建手册,流程名称:" + model.getName() + "[" + model.getId() + "],taskId:" + taskId + " 成功");
// 更新BO表taskId字段
int r1 = DBSql.update("UPDATE BO_ACT_COE_PUBLISH_N SET TASKID='" + taskId + "'WHERE ID ='" + boId + "'");
PublishHistory dao = new PublishHistory();// 发布结果主表
PublishHistoryModel history = dao.queryBy("PROCESSINSTID = ?", processInstId);
int r2 = -1;
if (history != null) {
r2 = DBSql.update("UPDATE APP_ACT_COE_PAL_PUBLISH_LIST SET TASKID='" + taskId + "'WHERE PID ='" + history.getId() + "' AND PALREPOSITORYID='" + uuid + "'");
}
SDK.getLogAPI().consoleInfo("流程发布[发布]审核完成后更新数据库taskId,流程名称:" + model.getName() + "[" + model.getId() + "],影响结果数量:BO_ACT_COE_PUBLISH_N[" + r1 + "],APP_ACT_COE_PAL_PUBLISH_LIST[" + r2 + "]");
} else {
SDK.getLogAPI().consoleInfo("流程发布[发布]审核完成后创建手册,流程名称:" + model.getName() + "[" + model.getId() + "] 失败");
}
}
}
}
if ("C".equals(type)) {
BO cBo = SDK.getBOAPI().query(PublisherConstant.BOSUBTABLE_C, true)
.bindId(processInstId)
.addQuery("CHANGEDFILEIDNEW=", uuid)
.detail();
if (cBo != null) {
String boId = cBo.getId();
// 创建流程手册
String oldTaskId = cBo.getString("TASKID");
// 获取报告类型
OutputTaskModel taskModel = new OutputTask().getTaskReportById(oldTaskId);
if (taskModel != null) {
String taskId = createOutputReport(model, model.getWsId(), appUser, "", model.getId());
if (UtilString.isNotEmpty(taskId)) {
// 更新流程发布表
SDK.getLogAPI().consoleInfo("流程发布[变更]审核完成后创建手册,流程名称:" + model.getName() + "[" + model.getId() + "],taskId:" + taskId + " 成功");
// 更新BO表taskId字段
int r1 = DBSql.update("UPDATE BO_ACT_COE_PUBLISH_C SET TASKID='" + taskId + "'WHERE ID ='" + boId + "'");
PublishHistory dao = new PublishHistory();// 发布结果主表
PublishHistoryModel history = dao.queryBy("PROCESSINSTID = ?", processInstId);
int r2 = -1;
if (history != null) {
r2 = DBSql.update("UPDATE APP_ACT_COE_PAL_PUBLISH_LIST SET TASKID='" + taskId + "'WHERE PID ='" + history.getId() + "' AND PALREPOSITORYID='" + uuid + "'");
}
SDK.getLogAPI().consoleInfo("流程发布[变更]审核完成后更新数据库taskId,流程名称:" + model.getName() + "[" + model.getId() + "],影响结果数量:BO_ACT_COE_PUBLISH_C[" + r1 + "],APP_ACT_COE_PAL_PUBLISH_LIST[" + r2 + "]");
} else {
SDK.getLogAPI().consoleInfo("流程发布[变更]审核完成后创建手册,流程名称:" + model.getName() + "[" + model.getId() + "] 失败");
}
}
}
}
}
/**
* 创建手册
* @param model
* @param wsId
* @param _uc
* @param teamId
* @param uuid
* @return
*/
private String createOutputReport(PALRepositoryModel model, String wsId, String userId, String teamId, String uuid) {
String taskId = "";
if ("process".equals(model.getMethodCategory())) {
taskId = PALRepositoryQueryAPIManager.getInstance().createOutputReportPr(wsId, userId, teamId, uuid);
JSONObject object = JSONObject.parseObject(taskId);
if ("ok".equals(object.getString("result"))) {
taskId = object.getJSONObject("data").getString("taskId");
}
} else if ("data".equals(model.getMethodCategory())) {
taskId = PALRepositoryQueryAPIManager.getInstance().createOutputReportBd(wsId, userId, teamId, uuid);
JSONObject object = JSONObject.parseObject(taskId);
if ("ok".equals(object.getString("result"))) {
taskId = object.getJSONObject("data").getString("taskId");
}
} else if ("control".equals(model.getMethodCategory())) {
taskId = PALRepositoryQueryAPIManager.getInstance().createOutputReportZd(wsId, userId, teamId, uuid);
JSONObject object = JSONObject.parseObject(taskId);
if ("ok".equals(object.getString("result"))) {
taskId = object.getJSONObject("data").getString("taskId");
}
}
return taskId;
}
/**
* 更新文件属性生效日期
*
* @param model
* @param publishDate
* @param propertyDao
*/
private boolean updatePropertyEffectiveDate(PALRepositoryModel model, String date, PALRepositoryPropertyDao propertyDao) {
// epc:process.epc effective_date
// 表单:data.form form_effective_date
// 制度:control.policy effective_date
String method = model.getMethodId();
String attrId = "";
if ("process.epc".equals(method)) {
attrId = "effective_date";
} else if ("data.form".equals(method)) {
attrId = "form_effective_date";
} else if ("control.policy".equals(method)) {
attrId = "effective_date";
}
if (UtilString.isEmpty(attrId)) {
return false;
}
// 更新生效时间
boolean existProp = false;
List<PALRepositoryPropertyModel> list = propertyDao.getPropertysByPlid(model.getId(), attrId);
for (PALRepositoryPropertyModel propertyModel : list) {
if (attrId.equals(propertyModel.getPropertyId())) {
propertyDao.updatePropertyByPropertyId(model.getId(), attrId, date);
SDK.getLogAPI().consoleInfo("[更新模型生效时间]成功,模型[" + model.getName() + "][" + model.getId() + "],生效时间[" + date + "]");
existProp = true;
}
}
if (!existProp) {
// 属性不存在新增一个
PALRepositoryPropertyModel property = new PALRepositoryPropertyModel();
property.setId(UUIDGener.getUUID());
property.setOrderIndex(0);
property.setPlId(model.getId());
property.setPropertyId(attrId);
property.setPropertyName("生效时间");
property.setPropertyValue(date);
propertyDao.insert(property);
SDK.getLogAPI().consoleInfo("[新增模型生效时间]成功,模型[" + model.getName() + "][" + model.getId() + "],生效时间[" + date + "]");
}
return true;
}
/**
* 流程发布范围权限单独存储
* @param bo 流程发布bo主表
@ -228,7 +470,7 @@ public class PublishExecuteListenerInterfaceImpl extends ExecuteListener impleme
}
if (list.size() > 0) {
SDK.getBOAPI().create(newBoName, list, bindId, applyUser);
SDK.getLogAPI().consoleErr("[发布范围权限信息保存至范围权限表]更新成功");
SDK.getLogAPI().consoleInfo("[发布范围权限信息保存至范围权限表]更新成功");
}
}