IStationTaskApp.cs 2.99 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 TableData StationTask(string containerCode, string startStation, string endStation)
        {
            TableData response = new TableData();
            response.code = 200;
            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.msg = startStation + ":无此站台!";
                    return response;
                }
                else if (EStation == null)
                {
                    response.code = 300;
                    response.msg = endStation + ":无此站台!";
                    return 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.待下发任务;
                    ptask.CreateTime = DateTime.Now;
                    _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 = 99;
                    ptaskDetail.CreateTime = DateTime.Now;
                    _unitWork.Add(ptaskDetail);
                }
            }
            catch (Exception ex)
            {
                response.code = 500;
                response.msg = ex.Message;
                return response;
            }
            return response;
        }
    }
}