IEmptyContainerOutApp.cs 3.87 KB
using System;
using System.Collections.Generic;
using Infrastructure;
using WebRepository;

namespace WebApp
{
    /// <summary>
    /// 入库口补充空托请求接口App
    /// </summary>

    public partial class IEmptyContainerOutApp : ApiApp
    {

        public IEmptyContainerOutApp(IUnitWork unitWork, IAuth auth, BaseDBContext context) : base(unitWork, auth, context)
        {

        }

        public string GetEmptyContainer(string station)
        {
            using (var tran = _context.Database.BeginTransaction())
            {
                Response<Location> Response = new Response<Location>();
                try
                {
                    StationRoadway st = _unitWork.FindSingle<StationRoadway>(u => u.StationCode.Equals(station));
                    Location loc = _unitWork.FindSingle<Location>(u => u.Roadway.Equals(st.RoadWay) && u.Status == LocationStatus.空容器 && u.IsStop == false);
                    if (loc == null)
                    {
                        Response.Code = 500;
                        Response.Status = false;
                        Response.Message = "库位中没有足够的空容器!";
                    }
                    else
                    {
                        Task task = new Task();
                        TaskDetail taskDetail = new TaskDetail();

                        var tno = _unitWork.GetTaskNo(TaskNo.空板补充);
                        task.TaskNo = tno;
                        task.OrderCode = tno;
                        task.BusinessType = BusinessType.出库_其他出库单;
                        task.FirstStatus = TaskStatus.下达任务;
                        task.LastStatus = TaskStatus.下达任务;
                        task.CreateTime = DateTime.Now;

                        if (task.UpdateBy == null)
                        {
                            task.UpdateBy = "wms";
                            task.UpdateTime = DateTime.Now;
                        }
                        _unitWork.Add(task);

                        taskDetail.TaskNo = tno;
                        taskDetail.OrderCode = tno;
                        taskDetail.TaskType = TaskType.空容器出库;
                        taskDetail.ContainerCode = loc.ContainerCode;
                        taskDetail.SourceLocation = loc.Code;
                        taskDetail.DestinationLocation = station;
                        taskDetail.OderQty = 0;
                        taskDetail.ContainerQty = 0;
                        taskDetail.HadQty = 0;
                        taskDetail.Roadway = loc.Roadway;
                        taskDetail.Station = station;
                        taskDetail.Status = TaskStatus.下达任务;
                        taskDetail.CreateTime = DateTime.Now;
                        if (taskDetail.UpdateBy == null)
                        {
                            taskDetail.UpdateBy = "wms";
                            taskDetail.UpdateTime = DateTime.Now;
                        }
                        _unitWork.Add(taskDetail);


                        loc.Status = LocationStatus.任务锁定中;
                        loc.UpdateTime = DateTime.Now;
                        if (loc.UpdateBy == null)
                        {
                            loc.UpdateBy = "wms";
                            loc.UpdateTime = DateTime.Now;
                        }
                        _unitWork.Update(loc);
                        tran.Commit();

                        Response.Result = loc;
                    }
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    Response.Code = 500;
                    Response.Status = false;
                    Response.Message = ex.Message;
                }

                return JsonHelper.Instance.Serialize(Response);
            }
        }
    }
}