Ejemplo n.º 1
0
        /// <summary>
        /// 推送业务服务 Rest 请求接 入口
        /// </summary>
        /// <param name="proEventMessage"></param>
        /// <returns></returns>
        public Task <bool> PushBusinessServiceEntrance(ProcessEventMessage proEventMessage)
        {
            _logger.Info(LogSource, $"Start PushBusinessServiceEntrance Data:{ JsonConvert.SerializeObject(proEventMessage) }");

            return(Task.Factory.StartNew(() =>
            {
                var returnInfo = new ResponseResultInfo();

                CheckProcessEventMessage(proEventMessage, returnInfo);
                if (returnInfo.returnStatus != 200)
                {
                    _logger.Warn(LogSource, $"End PushBusinessServiceEntrance Data:{ JsonConvert.SerializeObject(proEventMessage) },RequestMessage:{ JsonConvert.SerializeObject(returnInfo) }");
                    throw new Exception(returnInfo.returnMsg);
                }

                returnInfo = CallBusinessService(proEventMessage);
                //如果接口出错,则抛出来给队列
                if (returnInfo.returnStatus != 200)
                {
                    _logger.Warn(LogSource, $"End PushBusinessServiceEntrance Data:{ JsonConvert.SerializeObject(proEventMessage) },RequestMessage:{ JsonConvert.SerializeObject(returnInfo) }");
                    throw new Exception(returnInfo.returnMsg);
                }

                _logger.Info(LogSource, $"End PushBusinessServiceEntrance Data:{ JsonConvert.SerializeObject(proEventMessage) }");
                return true;
            }));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取请求接口参数字符串
        /// </summary>
        /// <param name="dataType"></param>
        /// <param name="submitUser"></param>
        /// <param name="proEventMsgInfo"></param>
        /// <param name="pushBusInfo"></param>
        /// <returns></returns>
        private string GetRequstParameter(string dataType, string submitUser, ProcessEventMessage proEventMsgInfo, PushBusInterfaceModel pushBusInfo)
        {
            ResultModel <PushBusInterfaceModel> paramData = new ResultModel <PushBusInterfaceModel>();
            string requstParameter = string.Empty;

            if (dataType == "FormData")
            {
                pushBusInfo.actionResult = string.Empty;
                pushBusInfo.bizData      = _formInstanceSevice.GetPrcFormContent(proEventMsgInfo.FormId);
            }
            else
            {
                var approverInfo = GetApproverInfo(proEventMsgInfo, submitUser, pushBusInfo.actionResult);

                if (dataType == "ApprovalData")
                {
                    pushBusInfo.activityName = proEventMsgInfo.ActivityName;
                    pushBusInfo.comment      = approverInfo.Comment;
                }
                else if (dataType == "FormAndApprovalData")
                {
                    pushBusInfo.activityName = proEventMsgInfo.ActivityName;
                    pushBusInfo.comment      = approverInfo.Comment;
                    pushBusInfo.bizData      = _formInstanceSevice.GetPrcFormContent(proEventMsgInfo.FormId);
                }

                pushBusInfo.activityName = proEventMsgInfo.ActivityName;
                pushBusInfo.comment      = approverInfo.Comment;
            }

            paramData.resultInfo = pushBusInfo;
            requstParameter      = Newtonsoft.Json.JsonConvert.SerializeObject(paramData);
            return(requstParameter);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 校验推送消息
 /// </summary>
 /// <param name="proEventMessage"></param>
 /// <param name="returnInfo"></param>
 /// <returns></returns>
 private void CheckProcessEventMessage(ProcessEventMessage proEventMessage, ResponseResultInfo returnInfo)
 {
     if (!_prcEventInterfaceService.IsEnableEventInterface(proEventMessage.EventInterfaceId))
     {
         returnInfo.returnMsg = string.Format("FormId:{0},EventInterfaceId:{1},未获取到流程事件接口配置。", proEventMessage.FormId, proEventMessage.EventInterfaceId);
         ReturnErrorInfo(proEventMessage, returnInfo);
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 获取上次审批信息
        /// </summary>
        /// <param name="msgItem"></param>
        /// <param name="applyUserCode"></param>
        /// <param name="actionResult"></param>
        /// <returns></returns>
        private PrcServer_FormApprovalHistory GetApproverInfo(ProcessEventMessage msgItem, string applyUserCode, string actionResult)
        {
            var processLogEntity = new PrcServer_FormApprovalHistory()
            {
                UserAccount = applyUserCode,
                EndDate     = DateTime.Now
            };

            if (msgItem.EventType == ProcessEventEnum.ActivityRejected.ToString())
            {
                var logItem = _formInstanceSevice.GetFormApprovalHistoryByActionType(msgItem.FormId, ActionType.Reject.ToString(), msgItem.ActivityName, msgItem.RejectActivityName);
                if (logItem != null)
                {
                    return(logItem);
                }
            }

            if (msgItem.ActivityName.StartsWith("000_"))
            {
                //ActionType.Reject驳回同步 意见类型、意见到业务系统
                //ActionType.ReSubmit驳回再提交同步 意见类型、意见到业务系统
                var logItem = _formInstanceSevice.GetFormApprovalHistoryByActionType(msgItem.FormId, actionResult);
                if (logItem != null)
                {
                    processLogEntity = logItem;
                }
                return(processLogEntity);
            }
            else
            {
                var processOpType = actionResult;                         //默认查审批日志
                if (actionResult == ActionType.AdminFinalPass.ToString()) //流程结束归档
                {
                    //获取最后一个审批日志作为推送接口审批人
                    var logItem = _formInstanceSevice.GetFormApprovalHistoryByActionType(msgItem.FormId, ActionType.Approve.ToString());
                    if (logItem != null)
                    {
                        return(logItem);
                    }
                }
                else if (actionResult == ActionType.Cancel.ToString()) //作废
                {
                    //查作废类型的日志Refused、AdminInvalid
                    processOpType = string.Format("{0},{1}", ActionType.Refused.ToString(), ActionType.AdminInvalid.ToString());
                }

                //获取最后一条审批记录日志
                var latestLog = _formInstanceSevice.GetFormApprovalHistoryByActionType(msgItem.FormId, processOpType);
                if (latestLog != null)
                {
                    processLogEntity = latestLog;
                }
            }
            return(processLogEntity);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 调用业务服务系统接口
        /// </summary>
        /// <param name="proEventMsg"></param>
        /// <param name="pushInfo"></param>
        /// <returns></returns>
        public ResponseResultInfo RequestBusInterface(ProcessEventMessage proEventMsg, PushBusInterfaceModel pushInfo)
        {
            var serviceInfo = InitBusinessServiceInfo(proEventMsg, pushInfo);

            try
            {
                //验证单据是否发起
                var formInstanceInfo = _formInstanceSevice.GetPrcFormInstanceByFormId(proEventMsg.FormId);
                if (formInstanceInfo == null)
                {
                    serviceInfo.ResultInfo.returnMsg = string.Format("FormId:{0},未获取到表单实例数据。", proEventMsg.FormId);
                    AddBusErrorLog(serviceInfo);
                    return(serviceInfo.ResultInfo);
                }
                pushInfo.bizId = formInstanceInfo.BizId;
                serviceInfo.ProEventMsgInfo.K2ID = pushInfo.k2Id = formInstanceInfo.Folio;

                serviceInfo.InterfaceConfig = _eventInterfaceService.GetProEventInterfaceInfo(proEventMsg.EventInterfaceId);

                string param          = GetRequstParameter(serviceInfo.InterfaceConfig.DataType, formInstanceInfo.SubmitterAccount, proEventMsg, pushInfo);
                string responseString = string.Empty;
                try
                {
                    serviceInfo.BegInterfaceTime = DateTime.Now;
                    responseString = HttpHelper.HttpPostRequest(serviceInfo.InterfaceConfig.Url, param, 60);
                    serviceInfo.EndInterfaceTime = DateTime.Now;

                    var resInfo = JsonConvert.DeserializeObject <ResultModel <ResponseResultInfo> >(responseString);
                    serviceInfo.ResultInfo = resInfo.resultInfo;
                    AddBusinessInterfaceLog(serviceInfo, param, responseString);
                }
                catch (Exception ex)
                {
                    _logger.Error(ex, $"FormId:{ proEventMsg.FormId }");
                    serviceInfo.ResultInfo.returnMsg = "访问ESB服务异常;" + ex.Message.ToString();
                    AddBusErrorLog(serviceInfo, 9, param, responseString);
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex, $"FormId:{ proEventMsg.FormId }");
                if (serviceInfo.ResultInfo == null)
                {
                    serviceInfo.ResultInfo = new ResponseResultInfo()
                    {
                        returnStatus = 500
                    };                                                                       //返回的格式不对
                }
                serviceInfo.ResultInfo.returnMsg = "调用业务接口异常!" + ex.Message;
                AddBusErrorLog(serviceInfo, 999);
            }

            return(serviceInfo.ResultInfo);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 错误信息返回信息、记录错误日志
        /// </summary>
        /// <param name="proEventMsgInfo"></param>
        /// <param name="resResultInfo"></param>
        private void ReturnErrorInfo(ProcessEventMessage proEventMsgInfo, ResponseResultInfo resResultInfo)
        {
            resResultInfo.returnStatus = 500;
            resResultInfo.returnCode   = "E0001";
            var logItem = new Domain.Models.PrcServer_BusinessInterfaceLog()
            {
                Status           = 500,
                FormID           = proEventMsgInfo.FormId,
                ActivityName     = proEventMsgInfo.ActivityName,
                EventInterfaceId = proEventMsgInfo.EventInterfaceId.ToString(),
                RequstID         = proEventMsgInfo.RequstID,

                RequestTime     = DateTime.Now,
                Parameters      = Newtonsoft.Json.JsonConvert.SerializeObject(proEventMsgInfo),
                ResponseMessage = Newtonsoft.Json.JsonConvert.SerializeObject(resResultInfo),
                ResponseTime    = DateTime.Now,
                IsRetry         = 0
            };

            _interfaceLogService.AddBusInterfaceLog(logItem);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 调用业务系统接口 推送状态处理
        /// </summary>
        /// <param name="msgItem"></param>
        /// <returns></returns>
        private ResponseResultInfo CallBusinessService(ProcessEventMessage msgItem)
        {
            PushBusInterfaceModel pushInfo = new PushBusInterfaceModel();

            if (msgItem.EventType == ProcessEventEnum.ProcessStarted.ToString())       //流程开始
            {
                pushInfo.actionResult = ActionType.Submit.ToString();                  //已提交
            }
            else if (msgItem.EventType == ProcessEventEnum.ActivityStarted.ToString()) //节点开始
            {
                pushInfo.actionResult = ActionType.Approve.ToString();                 //同意
                if (msgItem.ActivityName == SystemSettings.ReActivity)
                {
                    //000重新发起环节开始 审批结果为驳回
                    pushInfo.actionResult = ActionType.Reject.ToString();//驳回
                }
            }
            else if (msgItem.EventType == ProcessEventEnum.ActivityCompleted.ToString()) //节点结束
            {
                pushInfo.actionResult = ActionType.Approve.ToString();                   //同意
                if (msgItem.ActivityName == SystemSettings.ReActivity)
                {
                    pushInfo.actionResult = ActionType.ReSubmit.ToString();//重新提交
                }
            }
            else if (msgItem.EventType == ProcessEventEnum.ProcessCompleted.ToString()) //流程结束
            {
                pushInfo.actionResult = ActionType.AdminFinalPass.ToString();           //审批通过
                if (_formInstanceSevice.IsProcessDelete(msgItem.FormId))                //单据有作废 则 审批结果为作废
                {
                    pushInfo.actionResult = ActionType.Cancel.ToString();               //作废
                }
            }
            else if (msgItem.EventType == ProcessEventEnum.ActivityRejected.ToString()) //节点驳回
            {
                pushInfo.actionResult = ActionType.Reject.ToString();                   //驳回
            }

            return(_requestBusinessService.RequestBusInterface(msgItem, pushInfo));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 初始化 调用业务系统总模型
        /// </summary>
        /// <param name="proEventMsgInfo"></param>
        /// <param name="pushBusInfo"></param>
        /// <returns></returns>
        private BusinessServiceInfo InitBusinessServiceInfo(ProcessEventMessage proEventMsgInfo, PushBusInterfaceModel pushBusInfo)
        {
            var busServiceInfo = new BusinessServiceInfo()
            {
                ProEventMsgInfo = proEventMsgInfo,
                ResultInfo      = new ResponseResultInfo(),

                BusInterfaceLog = new Domain.Models.PrcServer_BusinessInterfaceLog()
                {
                    FormID           = proEventMsgInfo.FormId,
                    K2ID             = proEventMsgInfo.K2ID,
                    ActivityName     = proEventMsgInfo.ActivityName,
                    ActionResult     = pushBusInfo.actionResult,
                    EventInterfaceId = proEventMsgInfo.EventInterfaceId.ToString(),

                    RequstID    = proEventMsgInfo.RequstID,
                    RequestTime = DateTime.Now,
                    Parameters  = Newtonsoft.Json.JsonConvert.SerializeObject(proEventMsgInfo),
                    IsRetry     = 0
                }
            };

            return(busServiceInfo);
        }