监听事件

This commit is contained in:
xiang2lin 2025-03-13 13:59:42 +08:00
parent 7e4174b729
commit fbe53afa68
2 changed files with 179 additions and 169 deletions

View File

@ -6,6 +6,7 @@ import com.hzya.frame.web.entity.JsonResultEntity;
/**
* 致远OA接口类
*
* @author 👻👻👻👻👻👻👻👻👻👻 gjh
* @version 1.0
* @content
@ -24,7 +25,6 @@ public interface ISeeYonInterFace {
JsonResultEntity thirdInterfaceSend(JSONObject requestData);
/***
* @Content: 提供给OA的标准接口方法包含参数 entity 为OA 的data信息 , eventType 为事件类型
* @Author 👻👻👻👻👻👻👻👻 gjh
@ -59,13 +59,16 @@ public interface ISeeYonInterFace {
/**
* seeyon流程事件监听前置方法绑定数据源
*
* @param sysExtensionApi
* @return
* @throws Exception
*/
SysExtensionApiEntity colEventPre(SysExtensionApiEntity sysExtensionApi) throws Exception;
/**
* seeyon流程事件监听
*
* @param jsonObject
* @return
* @throws Exception
@ -74,11 +77,18 @@ public interface ISeeYonInterFace {
/**
* seeyon流程事件监听后置方法调用三方接口
*
* @param jsonStr
* @param formAppId
* @param eventType
* @return
* @throws Exception
*/
String colEventPost(String jsonStr,String formAppId,String eventType)throws Exception;
JsonResultEntity colEventPost(String jsonStr, String formAppId, String eventType) throws Exception;
JsonResultEntity chengeBody(JSONObject jsonObject) throws Exception;
SysExtensionApiEntity chengeBodySetPlug(SysExtensionApiEntity entity);
}

View File

@ -2,13 +2,14 @@ package com.hzya.frame.seeyon.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.map.MapBuilder;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hzya.frame.base.PluginBaseEntity;
import com.hzya.frame.seeyon.dao.ISeeYonInterFaceDao;
import com.hzya.frame.seeyon.entity.OAWorkflowEventDataEntity;
import com.hzya.frame.seeyon.entity.SeeYonInterFaceEntity;
@ -19,16 +20,18 @@ import com.hzya.frame.sysnew.application.database.dao.ISysApplicationDatabaseDao
import com.hzya.frame.sysnew.application.database.entity.SysApplicationDatabaseEntity;
import com.hzya.frame.sysnew.application.entity.SysApplicationEntity;
import com.hzya.frame.sysnew.application.entity.SysExtensionApiEntity;
import com.hzya.frame.util.PluginUtils;
import com.hzya.frame.web.entity.BaseResult;
import com.hzya.frame.web.entity.JsonResultEntity;
import com.hzya.frame.web.exception.BaseSystemException;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
@ -49,16 +52,32 @@ public class SeeYonInterFaceImpl implements ISeeYonInterFace {
private static final String RESTPASSWORD = "a5ce21b8-91db-4cec-b3e3-3e44719655fd";
// TODO 此处URL暂时写死后续根据传递的应用ID获取
private static final String sendUrl = "http://60.204.152.210/seeyon/";
@Value("${zt.url}")
private static String baseUrl;
@Resource
private ISysApplicationDatabaseDao sysApplicationDatabaseDao;
@Autowired
private ISysApplicationApiService sysApplicationApiService;
//速网esb地址
private static final String baseUrl = "http://hzya.ufyct.com:9067/kangarooDataCenter/entranceController/externalCallInterface";
/**
* 定义所支持的事件静态代码块
*/
private static final StringBuffer eventTypeBuffer = new StringBuffer();
//基础档案类型
private final String ARCHIVESTYPE = "archives";
//流程表单类型
private final String FLOWTYPE = "flow";
//创建基础档案
private final String CREATEARCHIVES = "create";
//更新基础档案
private final String UPDATEARCHIVES = "update";
//创建基础档案
private final String CREATEARCHIVESURL = "rest/form/import/";
//创建基础档案
private final String UPDATEARCHIVESURL = "rest/form/update";
@Resource
private ISysApplicationDatabaseDao sysApplicationDatabaseDao;
@Autowired
private ISysApplicationApiService sysApplicationApiService;
@Resource
private ISeeYonInterFaceDao seeYonInterFaceDao;
//上一次同步时间
private final String LAST_SYNCHRONISED_TIME = "";
{
eventTypeBuffer.append("发起前事件 onBeforeStart ,");
@ -76,24 +95,6 @@ public class SeeYonInterFaceImpl implements ISeeYonInterFace {
eventTypeBuffer.append("取回事件 onTakeBack,");
}
//基础档案类型
private final String ARCHIVESTYPE = "archives";
//流程表单类型
private final String FLOWTYPE = "flow";
//创建基础档案
private final String CREATEARCHIVES = "create";
//更新基础档案
private final String UPDATEARCHIVES = "update";
//创建基础档案
private final String CREATEARCHIVESURL = "rest/form/import/";
//创建基础档案
private final String UPDATEARCHIVESURL = "rest/form/update";
@Resource
private ISeeYonInterFaceDao seeYonInterFaceDao;
//上一次同步时间
private String LAST_SYNCHRONISED_TIME = "";
/****
* @Content:发起无流程表单接口实现
* @Author 👻👻👻👻👻👻👻👻 gjh
@ -223,74 +224,14 @@ public class SeeYonInterFaceImpl implements ISeeYonInterFace {
//formApp 最好过滤一下
String result = null;
JsonResultEntity result = null;
try {
//流程事件处理
result = colEventPost(jsonStr, formApp, eventType);
} catch (Exception e) {
return BaseResult.getFailureMessageEntity("传递失败", e.getMessage());
}
try {
/** 根据事件类型处理相关事件*/
switch (eventType) {
/** 发起前事件*/
case "onBeforeStart":
break;
/** 发起事件*/
case "onStart":
//流程发起 新增grpu8单据
break;
/** 终止前事件*/
case "onBeforeStop":
break;
/** 终止事件*/
case "onStop":
//流程终止更新grpu8单据
break;
/** 撤销前事件*/
case "onBeforeCancel":
break;
/** 撤销事件*/
case "onCancel":
//流程撤销更新grpu8单据
break;
/** 结束事件*/
case "onProcessFinished":
break;
/** 处理前事件*/
case "onBeforeFinishWorkitem":
/** 根据form处理相关业务表单的数据*/
switch (formApp) {
case "abc123":
break;
default:
return BaseResult.getFailureMessageEntity("未匹配到表单当前formID" + formApp, "");
}
break;
/** 处理事件*/
case "onFinishWorkitem":
break;
/** 回退前事件*/
case "onBeforeStepBack":
break;
/** 回退事件*/
case "onStepBack":
break;
/** 取回前事件*/
case "onBeforeTakeBack":
break;
/** 取回事件*/
case "onTakeBack":
break;
default:
// throw new RuntimeException("传入了非法事件类型!请参照:" + eventTypeBuffer.toString());
return BaseResult.getFailureMessageEntity("传入了非法事件类型!请参照:" + eventTypeBuffer.toString(), "", "");
}
return BaseResult.getSuccessMessageEntity("传递成功", result);
}catch (Exception e){
return BaseResult.getFailureMessageEntity("传递失败",e.getMessage());
}
return result;
}
@ -413,6 +354,7 @@ public class SeeYonInterFaceImpl implements ISeeYonInterFace {
/**
* seeyon流程事件监听前置方法绑定数据源
*
* @param entity
* @return
* @throws Exception
@ -481,7 +423,7 @@ public class SeeYonInterFaceImpl implements ISeeYonInterFace {
* @throws Exception
*/
@Override
public String colEventPost(String jsonStr, String formAppId, String eventType) throws Exception {
public JsonResultEntity colEventPost(String jsonStr, String formAppId, String eventType) throws Exception {
if (StrUtil.isNotEmpty(jsonStr) && StrUtil.isNotEmpty(formAppId) && StrUtil.isNotEmpty(eventType)) {
SysApplicationApiEntity sysApplicationApiEntity = new SysApplicationApiEntity();
sysApplicationApiEntity.setHeaderIn(formAppId + "_" + eventType);
@ -490,19 +432,77 @@ public class SeeYonInterFaceImpl implements ISeeYonInterFace {
if (applist.size() > 1) {
throw new BaseSystemException("根据formID" + formAppId + "查询出多条数据");
}
if (applist.size() == 0 ) {
throw new BaseSystemException("根据formID" + formAppId + "eventType:"+eventType+"未查询到API配置");
}
SysApplicationApiEntity sysApp = applist.get(0);
Map<String, String> headerMap = MapBuilder.<String, String>create(true)
.put("apiCode", String.valueOf(sysApp.getApiCode()))
//这里用中台做为发送方
.put("publicKey","ZJYAWb7lhAUTYqekPkU+uHJv1/ObJxb7dT7sD8HPRDGAgyhCe7eDIk+3zDUT+v578prj")
.put("secretKey","fviZnLBsQUAGF8w8FSOdJi7XlIm/XAZclMxRagDLfTyJFlvnIBF3w66Hrpfzs8cYj3JzOP8MtA1LSGvL+2BWG8c/o7DKi92S4mr3zcGearA=")
.put("appId",String.valueOf(sysApp.getAppCode()))
.build();
String body = HttpRequest.post(baseUrl).addHeaders(headerMap).body(jsonStr).timeout(60000).execute().body();
logger.info("调用中台返回的参数:{}",body);
return body;
//数据源配置
SysApplicationDatabaseEntity sysApiDatabase = new SysApplicationDatabaseEntity();
sysApiDatabase.setAppId(sysApp.getAppId());
List<SysApplicationDatabaseEntity> apiDataBaseList = sysApplicationDatabaseDao.queryDSBase(sysApiDatabase);
if (CollectionUtils.isNotEmpty(apiDataBaseList) && apiDataBaseList.size() == 1){
sysApiDatabase = apiDataBaseList.get(0);
}
JSONArray headerArray = JSONArray.parseArray(sysApp.getHeaderIn());
Map<String,String> headerMap = new HashMap<>();
if (null != headerArray && headerArray.size() > 0) {
for (int i = 0; i < headerArray.size(); i++) {
JSONObject querys = headerArray.getJSONObject(i);
//query 只有基本类型不用循环判断下级
//判断参数是否有值
//获取对象下面的层级数据
String parameterName = querys.getString("parameterName");
String example = querys.getString("example");
headerMap.put(parameterName,example);
}
if (headerMap.isEmpty()){
throw new BaseSystemException("根据formID" + formAppId + "未获取到head参数");
}
PluginBaseEntity pluginBaseEntity = PluginUtils.getPluginsById(headerMap.get("plugId"));
if (null == pluginBaseEntity) {
throw new BaseSystemException("根据ID获取插件错误请传入正确的 pluginId");
}
//执行业务逻辑代码
JSONObject reqJson = new JSONObject();
reqJson.put("jsonStr",jsonStr);
reqJson.put("formAppId",formAppId);
reqJson.put("eventType",eventType);
reqJson.put("headers",JSON.toJSONString(headerMap));
reqJson.put("apiDataSourceCode",sysApiDatabase.getSourceCode());
JsonResultEntity result = pluginBaseEntity.executeBusiness(reqJson);
return result;
} else {
throw new BaseSystemException("根据formID" + formAppId + "未获取到head参数");
}
}
}
return null;
}
@Override
public JsonResultEntity chengeBody(JSONObject object) throws Exception {
JSONObject jsonstr = object.getJSONObject("jsonStr");
PluginBaseEntity pluginBaseEntity = null;
JsonResultEntity result;
String pluginId = jsonstr.getString("plugId");
pluginBaseEntity = PluginUtils.getPluginsById(pluginId);
if (null == pluginBaseEntity) {
throw new BaseSystemException("根据ID获取插件错误请传入正确的 pluginId");
} else {
//执行业务逻辑代码
result = pluginBaseEntity.executeBusiness(object);
}
return result;
}
@Override
public SysExtensionApiEntity chengeBodySetPlug(SysExtensionApiEntity entity) {
Map<String, String> headers = entity.getHeaders();
JSONObject jsonObject = JSONObject.parseObject(entity.getBodys());
jsonObject.put("plugId", headers.get("plugId"));
entity.setBodys(jsonObject.toJSONString());
return entity;
}
}