IStationTaskApp.cs 3.01 KB
using System;
using System.Linq;
using Infrastructure;
using WebRepository;

namespace WebApp
{
    /// <summary>
    /// 站台下发接口
    /// </summary>
    public partial class IStationTaskApp : ApiApp
    {
        public IRepository<ReceiptHeader> _app;
        public IStationTaskApp(IUnitWork unitWork, IAuth auth, BaseDBContext context, IRepository<ReceiptHeader> app) : base(unitWork, auth, context)
        {
            _app = app;
        }

        public string StationTask(string containerCode, string startStation, string endStation)
        {
            Response response = new Response();
            try
            {
                Station SStation = _unitWork.Find<Station>(n => n.Code == startStation).FirstOrDefault();
                Station EStation = _unitWork.Find<Station>(n => n.Code == endStation).FirstOrDefault();
                if (SStation == null)
                {
                    response.Code = 300;
                    response.Message = startStation + ":无此站台!";
                    return JsonHelper.Instance.Serialize(response);
                }
                else if (EStation == null)
                {
                    response.Code = 300;
                    response.Message = endStation + ":无此站台!";
                    return JsonHelper.Instance.Serialize(response);
                }
                else if (EStation != null)
                {
                    Task ptask = new Task();
                    TaskDetail ptaskDetail = new TaskDetail();
                    var taskNo = _app.GetTaskNo(TaskNo.站台到站台);
                    ptask.TaskNo = taskNo;
                    ptask.OrderCode = taskNo;
                    ptask.BusinessType = BusinessType.出库_其他出库单;
                    ptask.FirstStatus = TaskStatus.待下发任务;
                    ptask.LastStatus = TaskStatus.待下发任务;
                    _unitWork.Add(ptask);

                    ptaskDetail.TaskNo = taskNo;
                    ptaskDetail.OrderCode = taskNo;
                    ptaskDetail.TaskType = TaskType.站台到站台;
                    ptaskDetail.ContainerCode = containerCode;
                    ptaskDetail.SourceLocation = startStation;
                    ptaskDetail.DestinationLocation = endStation;
                    ptaskDetail.OderQty = 0;
                    ptaskDetail.ContainerQty = 0;
                    ptaskDetail.HadQty = 0;
                    ptaskDetail.Roadway = 0;
                    ptaskDetail.Station = endStation;
                    ptaskDetail.Status = TaskStatus.待下发任务;
                    ptaskDetail.Priority = 0;
                    _unitWork.Add(ptaskDetail);
                }
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Status = false;
                response.Message = ex.Message;
                return JsonHelper.Instance.Serialize(response);
            }
            return JsonHelper.Instance.Serialize(response);
        }
    }
}