public override void Execute()
        {
            int taskID = 0;
            try
            {
                object state = AutomationContext.Read(memoryServiceName, memoryItemName);
                if (state == null) return;

                taskID = Convert.ToInt32(state);
                if (taskID <= 0) return;

                string orderType = taskDal.GetOrderType(taskID);
                string orderID = taskDal.GetOrderID(taskID);
                int allotID = taskDal.GetAllotID(taskID);
                string originCellCode = taskDal.GetOriginCellCode(taskID);
                string targetCellCode = taskDal.GetTargetCellCode(taskID);
                string originStorageCode = taskDal.GetOriginStorageCode(taskID);
                string targetStorageCode = taskDal.GetTargetStorageCode(taskID);
                
                RestClient rest = new RestClient();
                if (!rest.FinishTask(taskID, orderType, orderID, allotID, originCellCode, targetCellCode,originStorageCode, targetStorageCode))
                {
                    AutomationContext.Write(memoryServiceName, memoryItemName, taskID);
                    Logger.Error(string.Format("{0} 完成[{1}]任务失败!", Name, taskID));
                }
                else
                {
                    taskDal.UpdateTaskStateToExecuted(taskID);
                    taskID = 0;
                }
            }
            catch (Exception ex)
            {
                if (taskID >= 0)
                {
                    AutomationContext.Write(memoryServiceName, memoryItemName, taskID);
                }
                Logger.Error("TaskFinishDataProcess 出错,原因:" + ex.Message + "/n" + ex.StackTrace);
            }
        }
Exemplo n.º 2
0
        private void FinishTask()
        {
            try
            {
                if (CurrentTask != null)
                {
                    using (TransactionScopeManager TM = new TransactionScopeManager(true, IsolationLevel.Serializable))
                    {
                        TaskDal taskDal = new TaskDal();
                        PositionDal positionDal = new PositionDal();

                        taskDal.TransactionScopeManager = TM;
                        positionDal.TransactionScopeManager = TM;

                        positionDal.UpdateHasGoodsToFalse(CurrentTask.CurrentPositionID);
                        positionDal.UpdateHasGoodsToTrue(CurrentTask.NextPositionID);

                        taskDal.UpdateTaskPosition(CurrentTask.ID, CurrentTask.NextPositionID);
                        taskDal.UpdateTaskPositionStateToArrived(CurrentTask.ID);
                        taskDal.UpdateTaskStateToWaiting(CurrentTask.ID);                        

                        if (CurrentTask.NextPositionID == CurrentTask.EndPositionID
                            && (CurrentTask.TaskType == "03" || CurrentTask.EndPositionType != "03")
                            && (CurrentTask.TaskType == "03" || CurrentTask.EndPositionType != "04"))//小品种,异型烟,由手持PDA完成;
                        {
                            if (CurrentTask.TaskType == "02")
                            {
                                string orderType = taskDal.GetOrderType(CurrentTask.ID);
                                string orderID = taskDal.GetOrderID(CurrentTask.ID);
                                int allotID = taskDal.GetAllotID(CurrentTask.ID);
                                string originCellCode = taskDal.GetOriginCellCode(CurrentTask.ID);
                                string targetCellCode = taskDal.GetTargetCellCode(CurrentTask.ID);
                                string originStorageCode = taskDal.GetOriginStorageCode(CurrentTask.ID);
                                string targetStorageCode = taskDal.GetTargetStorageCode(CurrentTask.ID);

                                RestClient rest = new RestClient();
                                if (!rest.FinishTask(CurrentTask.ID, orderType, orderID, allotID,originCellCode,targetCellCode, originStorageCode, targetStorageCode))
                                {
                                    Logger.Error(string.Format("{0} 完成[{1}]任务失败!", Name, CurrentTask.ID));
                                    return;
                                }
                                else
                                {
                                    taskDal.UpdateTaskStateToExecuted(CurrentTask.ID);
                                }
                            }
                            else
                            {
                                if (!Ops.Write(memoryServiceName, memoryItemName, CurrentTask.ID))
                                {
                                    Logger.Error(string.Format("{0} 完成[{1}]任务失败!", Name, CurrentTask.ID));
                                    return;
                                }
                            }
                        }
                        TM.Commit();

                        CurrentTask = null;
                        CurrentTaskFactory = null;                        
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("SRM.FinishTask 出错,原因:" + ex.Message + "/n" + ex.StackTrace);
            }
        }