public TaskModuleExecuteResult(TaskContext context)
 {
     Context       = context;
     _taskActuator = Context
                     .HttpContextAccessor
                     .HttpContext
                     .RequestServices
                     .GetService <ITaskActuator>();
     _taskManager = Context
                    .HttpContextAccessor
                    .HttpContext
                    .RequestServices
                    .GetService <TaskManager>();
 }
Beispiel #2
0
        private void HandleQueueAsync(ITaskActuator taskActuator,
                                      TaskManager taskManager, long queueId)
        {
            var shareOrder = Resolve <IShareOrderService>().GetSingle(r => r.Id == queueId);

            if (shareOrder == null)
            {
                throw new MessageQueueHandleException(queueId, $"shareOrder queue with id {queueId} not found.");
            }

            try
            {
                if (shareOrder.Status != ShareOrderStatus.Pending)
                {
                    throw new MessageQueueHandleException(queueId, "分润订单状态不是待处理状态");
                }

                var moduleTypeArray = taskManager.GetModulePriceArray();
                foreach (var type in moduleTypeArray)
                {
                    if (shareOrder.TriggerType == TriggerType.Order)
                    {
                        taskActuator.ExecuteTask(type, shareOrder,
                                                 new { ShareOrderId = queueId, shareOrder.TriggerType, OrderId = shareOrder.EntityId });
                    }
                    else
                    {
                        taskActuator.ExecuteTask(type, shareOrder,
                                                 new { ShareOrderId = queueId, shareOrder.TriggerType, BaseFenRunAmount = shareOrder.Amount });
                    }
                }

                //更新成功
                Resolve <IShareOrderService>().Update(r =>
                {
                    r.Status     = ShareOrderStatus.Handled;
                    r.UpdateTime = DateTime.Now;
                }, r => r.Id == shareOrder.Id);
            }
            catch (Exception ex)
            {
                //处理失败
                Resolve <IShareOrderService>().Update(r =>
                {
                    r.Status           = ShareOrderStatus.Error;
                    r.UpdateTime       = DateTime.Now;
                    shareOrder.Summary = ex.Message;
                }, r => r.Id == shareOrder.Id);
            }
        } /*end*/
Beispiel #3
0
        private void HandleQueueAsync(ITaskActuator taskActuator, TaskManager taskManager, long queueId, IScope scope)
        {
            var shareOrder = scope.Resolve <ITradeService>().GetSingle(r => r.Id == queueId);

            if (shareOrder != null)
            {
                try
                {
                    if (shareOrder.Status != ShareOrderStatus.Pending)
                    {
                        throw new MessageQueueHandleException(queueId, "分润订单状态不是待处理状态");
                    }

                    var order = scope.Resolve <IShareRepository>().GetSingleNative(shareOrder.Id);
                    if (order.Status != ShareOrderStatus.Pending)
                    {
                        throw new MessageQueueHandleException(queueId, "分润订单状态不是待处理状态");
                    }

                    var moduleTypeArray = taskManager.GetModulePriceArray();
                    foreach (var type in moduleTypeArray)
                    {
                        if (shareOrder.TriggerType == TriggerType.Order)
                        {
                            //// 确认收货的时候,产生分润
                            //if (shareOrder.SystemStatus != ShareOrderSystemStatus.Pending)
                            //{
                            //    continue;
                            //}
                            taskActuator.ExecuteTask(type, shareOrder,
                                                     new { ShareOrderId = queueId, shareOrder.TriggerType, OrderId = shareOrder.EntityId });
                        }
                        //else {
                        //    taskActuator.ExecuteTask(type, shareOrder,
                        //        new { ShareOrderId = queueId, shareOrder.TriggerType, BaseFenRunAmount = shareOrder.Amount });
                        //}
                    }

                    //更新成功
                    scope.Resolve <ITradeService>().Update(r =>
                    {
                        r.Status        = ShareOrderStatus.Handled;
                        r.ExecuteCount += 1;
                        r.UpdateTime    = DateTime.Now;
                    }, r => r.Id == shareOrder.Id);
                    //原生数据库才插入一次
                    var             unitOfWork           = scope.Resolve <IUnitOfWork>();
                    ShareRepository shareOrderRepository = new ShareRepository(unitOfWork);
                    shareOrderRepository.SuccessOrder(shareOrder.Id);
                } catch (Exception ex)
                {
                    //处理失败
                    scope.Resolve <ITradeService>().Update(r =>
                    {
                        r.Status           = ShareOrderStatus.Error;
                        r.UpdateTime       = DateTime.Now;
                        shareOrder.Summary = ex.Message;
                    }, r => r.Id == shareOrder.Id);
                }
            }
        }