LocationAndTaskMonitorApp.cs 13.4 KB
using Infrastructure;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Newtonsoft.Json.Linq;
using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Linq.Expressions;
using WebRepository;

namespace WebApp
{
    /// <summary>
    //任务仓位监控
    /// </summary>

    public partial class LocationAndTaskMonitorApp
    {
        private IUnitWork _unitWork;

        public LocationAndTaskMonitorApp(IUnitWork unitWork)
        {
            _unitWork = unitWork;
        }

        public TableData FindTaskApp(int Roadway)
        {
            TableData tab = new TableData();
            try
            {
                List<ShipmentDetail> list =  (from sd in _unitWork.Find<ShipmentDetail>(n => !string.IsNullOrEmpty(n.ShipmentCode)).ToList()
                            join sh in _unitWork.Find<ShipmentHeader>(n => !string.IsNullOrEmpty(n.Code)).ToList()
                            on sd.ShipmentCode equals sh.Code
                            join st in _unitWork.Find<StationRoadway>(n => n.RoadWay == Roadway).ToList()
                            on sh.Station equals st.StationCode
                            select sd).ToList();

                List<dynamic> templist = new List<dynamic>();
                foreach (ShipmentDetail sd in list)
                {
                    Station station = (from st in _unitWork.Find<Station>(n => !string.IsNullOrEmpty(n.Code)).ToList()
                                       join sh in _unitWork.Find<ShipmentHeader>(n => !string.IsNullOrEmpty(n.Station) && n.Code == sd.ShipmentCode).ToList()
                                       on st.Code equals sh.Station
                                       select st).FirstOrDefault();
                    dynamic temp = new ExpandoObject();
                    if (station != null)
                    {
                        temp.Station = station.Name;
                    }
                    else
                    {
                        temp.Station = "未找到站台";
                    }
                    temp.Id = sd.Id;
                    temp.SourceCode = sd.SourceCode;
                    temp.MaterialCode = sd.MaterialCode;
                    temp.Qty = sd.Qty;
                    temp.QtyDivided = sd.QtyDivided;
                    templist.Add(temp);
                }
                tab.data = templist;
                tab.code = 200;
            }
            catch (Exception ex)
            {
                tab.code = 300;
                tab.msg = ex.Message;
            }
            return tab;
        }

        public TableData FindTaskNumApp(int Roadway)
        {
            TableData tab = new TableData();
            try
            {
                List<ExpandoObject> list = new List<ExpandoObject>();
                if (Roadway != 5)
                {
                    int diSnum = (from sd in _unitWork.Find<ShipmentDetail>(n => !string.IsNullOrEmpty(n.ShipmentCode) && n.Status == ShipmentHeaderStatus.分配完成).ToList()
                                  join sh in _unitWork.Find<ShipmentHeader>(n => !string.IsNullOrEmpty(n.Code)).ToList()
                                  on sd.ShipmentCode equals sh.Code
                                  join st in _unitWork.Find<StationRoadway>(n => n.RoadWay == Roadway).ToList()
                                  on sh.Station equals st.StationCode
                                  select sd).Count();
                    dynamic temp = new ExpandoObject();
                    temp.name = "分配完成";
                    temp.num = diSnum;
                    list.Add(temp);
                    int num = (from sd in _unitWork.Find<ShipmentDetail>(n => !string.IsNullOrEmpty(n.ShipmentCode) && n.Status != ShipmentHeaderStatus.分配完成).ToList()
                               join sh in _unitWork.Find<ShipmentHeader>(n => !string.IsNullOrEmpty(n.Code)).ToList()
                               on sd.ShipmentCode equals sh.Code
                               join st in _unitWork.Find<StationRoadway>(n => n.RoadWay == Roadway).ToList()
                               on sh.Station equals st.StationCode
                               select sd).Count();
                    temp = new ExpandoObject();
                    temp.name = "未分配完成";
                    temp.num = num;
                    list.Add(temp);
                }
                else if(Roadway == 5)
                {
                    int Emptynum = (from loc in _unitWork.Find<Location>(n => n.Status == LocationStatus.空容器 && n.Roadway == Roadway).ToList()
                                    join con in _unitWork.Find<Container>(n => n.Type == ContainerType.木栈板母板_2).ToList()
                                    on loc.ContainerCode equals con.Code
                                    group loc by loc.ContainerCode into code
                                    select code).Count();
                    dynamic temp = new ExpandoObject();
                    temp.name = "大板空容器";
                    temp.num = Emptynum;
                    list.Add(temp);
                    //int EmptyLocnum = (from loca in _unitWork.Find<Location>(n => n.Status == LocationStatus.空仓位 && n.IsStop == false && n.MaxHeight >= 0 && n.Roadway == Roadway && n.ContainerCode == "" && n.DistributionType != LocationDistributionType.被分配库位静态库位)
                    //                   join Cloca in _unitWork.Find<Location>(n => n.Status == LocationStatus.空仓位 && n.IsStop == false && n.MaxHeight >= 0 && n.Roadway == Roadway && n.ContainerCode == "")
                    //                   on loca.ContiguousCode equals Cloca.Code
                    //                   group loca by loca.ContainerCode into code
                    //                   select code).Count();
                    //temp = new ExpandoObject();
                    //temp.name = "大板空仓位";
                    //temp.num = EmptyLocnum;
                    //list.Add(temp);
                    int Tasknum = (from loc in _unitWork.Find<Location>(n => n.Status == LocationStatus.任务锁定中 && n.Roadway == Roadway).ToList()
                                   join con in _unitWork.Find<Container>(n => n.Type == ContainerType.木栈板母板_2).ToList()
                                   on loc.ContainerCode equals con.Code
                                   group loc by loc.ContainerCode into code
                                   select code).Count();
                    temp = new ExpandoObject();
                    temp.name = "任务中大板";
                    temp.num = Tasknum;
                    list.Add(temp);
                    int Somenum = (from loc in _unitWork.Find<Location>(n => n.Status == LocationStatus.有货 && n.Roadway == Roadway).ToList()
                                   join con in _unitWork.Find<Container>(n => n.Type == ContainerType.木栈板母板_2).ToList()
                                   on loc.ContainerCode equals con.Code
                                   group loc by loc.ContainerCode into code
                                   select code).Count();
                    temp = new ExpandoObject();
                    temp.name = "有货大板";
                    temp.num = Somenum;
                    list.Add(temp);
                }

                tab.data = list;
                tab.code = 200;
            }
            catch (Exception ex)
            {
                tab.code = 300;
                tab.msg = ex.Message;
            }
            return tab;
        }

        public TableData FindPalletApp(int Roadway)
        {
            TableData tab = new TableData();
            try
            {
                List<ExpandoObject> list = new List<ExpandoObject>();
                if (Roadway == 5)
                {
                    int Emptynum = (from loc in _unitWork.Find<Location>(n => n.Status == LocationStatus.空容器 && n.Roadway == Roadway).ToList()
                                    join con in _unitWork.Find<Container>(n => n.Type == ContainerType.木栈板母板_1).ToList()
                                    on loc.ContainerCode equals con.Code
                                    select loc).Count();
                    dynamic temp = new ExpandoObject();
                    temp.name = "小板空容器";
                    temp.num = Emptynum;
                    list.Add(temp);
                    int EmptyLocnum = _unitWork.Find<Location>(n => n.Status == LocationStatus.空仓位 && n.Roadway == Roadway).Count();
                    temp = new ExpandoObject();
                    temp.name = "小板空仓位";
                    temp.num = EmptyLocnum;
                    list.Add(temp);
                    int Tasknum = (from loc in _unitWork.Find<Location>(n => n.Status == LocationStatus.任务锁定中 && n.Roadway == Roadway).ToList()
                                   join con in _unitWork.Find<Container>(n => n.Type == ContainerType.木栈板母板_1).ToList()
                                   on loc.ContainerCode equals con.Code
                                   select loc).Count();
                    temp = new ExpandoObject();
                    temp.name = "任务中小板";
                    temp.num = Tasknum;
                    list.Add(temp);
                    int Somenum = (from loc in _unitWork.Find<Location>(n => n.Status == LocationStatus.有货 && n.Roadway == Roadway).ToList()
                                   join con in _unitWork.Find<Container>(n => n.Type == ContainerType.木栈板母板_1).ToList()
                                   on loc.ContainerCode equals con.Code
                                   select loc).Count();
                    temp = new ExpandoObject();
                    temp.name = "有货小板";
                    temp.num = Somenum;
                    list.Add(temp);
                }
                else if (Roadway == 2)
                {
                    int Emptynum = _unitWork.Find<Location>(n => n.Status == LocationStatus.空容器 && n.Roadway == Roadway).Count();
                    dynamic temp = new ExpandoObject();
                    temp.name = "空托盘";
                    temp.num = Emptynum;
                    list.Add(temp);
                    int EmptyLocnum_850 = _unitWork.Find<Location>(n => n.Status == LocationStatus.空仓位 && n.Roadway == Roadway && n.MaxHeight == 850).Count();
                    temp = new ExpandoObject();
                    temp.name = "850空仓位";
                    temp.num = EmptyLocnum_850;
                    list.Add(temp);
                    int EmptyLocnum_1150 = _unitWork.Find<Location>(n => n.Status == LocationStatus.空仓位 && n.Roadway == Roadway && n.MaxHeight == 1150).Count();
                    temp = new ExpandoObject();
                    temp.name = "1150空仓位";
                    temp.num = EmptyLocnum_1150;
                    list.Add(temp);
                    int EmptyLocnum_1350 = _unitWork.Find<Location>(n => n.Status == LocationStatus.空仓位 && n.Roadway == Roadway && n.MaxHeight == 1350).Count();
                    temp = new ExpandoObject();
                    temp.name = "1350空仓位";
                    temp.num = EmptyLocnum_1350;
                    list.Add(temp);
                    int Tasknum = _unitWork.Find<Location>(n => n.Status == LocationStatus.任务锁定中 && n.Roadway == Roadway).Count();
                    temp = new ExpandoObject();
                    temp.name = "任务中";
                    temp.num = Tasknum;
                    list.Add(temp);
                    int Somenum = _unitWork.Find<Location>(n => n.Status == LocationStatus.有货 && n.Roadway == Roadway).Count();
                    temp = new ExpandoObject();
                    temp.name = "有货";
                    temp.num = Somenum;
                    list.Add(temp);
                }
                else
                {
                    int Emptynum = _unitWork.Find<Location>(n => n.Status == LocationStatus.空容器 && n.Roadway == Roadway).Count();
                    dynamic temp = new ExpandoObject();
                    temp.name = "空容器";
                    temp.num = Emptynum;
                    list.Add(temp);
                    int EmptyLocnum = _unitWork.Find<Location>(n => n.Status == LocationStatus.空仓位 && n.Roadway == Roadway).Count();
                    temp = new ExpandoObject();
                    temp.name = "空仓位";
                    temp.num = EmptyLocnum;
                    list.Add(temp);
                    int Tasknum = _unitWork.Find<Location>(n => n.Status == LocationStatus.任务锁定中 && n.Roadway == Roadway).Count();
                    temp = new ExpandoObject();
                    temp.name = "任务中";
                    temp.num = Tasknum;
                    list.Add(temp);
                    int Somenum = _unitWork.Find<Location>(n => n.Status == LocationStatus.有货 && n.Roadway == Roadway).Count();
                    temp = new ExpandoObject();
                    temp.name = "有货";
                    temp.num = Somenum;
                    list.Add(temp);
                }
                tab.data = list;
                tab.code = 200;
            }
            catch (Exception ex)
            {
                tab.code = 300;
                tab.msg = ex.Message;
            }
            return tab;
        }

    }
}