NouYouLocationMonitorApp.cs 6.11 KB
using Infrastructure;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Newtonsoft.Json.Linq;
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 NouYouLocationMonitorApp
    {
        private IUnitWork _unitWork;

        public NouYouLocationMonitorApp(IUnitWork unitWork)
        {
            _unitWork = unitWork;
        }
        
        public TableData GetRoadwayApp(int roadway,int line)
        {
            TableData tab = new TableData();
            try
            {
                var list = (from location in _unitWork.Find<Location>( n => n.Roadway == roadway && n.Line == line)
                            join con in _unitWork.Find<Container>(null)
                            on location.ContainerCode equals con.Code into lc
                            from con in lc.DefaultIfEmpty()
                            select new { Code = location.Code, Row = location.Row, Layer = location.Layer, ContainerCode = location.ContainerCode, Status = location.Status, Type = con == null ? null : con.Type }).OrderByDescending(n => n.Layer).ToList();
                tab.data = list;

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

        }

        public TableData GetLineApp(int roadway)
        {
            TableData tab = new TableData();
            try
            {
                var list = (from location in _unitWork.Find<Location>(null)
                            where location.Roadway == roadway
                            group location by new { location.Line } into line
                            select new { line.Key }).OrderBy(n => n.Key.Line).ToList();
                tab.data = list;

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

        }

        public TableData GetInveApp(string code,string type,string roadway)
        {
            TableData tab = new TableData();
            try
            {
                List<Inventory> inventories;
                if (type == ContainerType.木栈板母板_2 && (int.Parse(roadway) == 5 || int.Parse(roadway) == 6))
                {
                    string contiguousCode = _unitWork.Find<Location>(n => n.Code == code).FirstOrDefault().ContiguousCode; ;
                    inventories = _unitWork.Find<Inventory>(n => n.LocationCode == code || n.LocationCode == contiguousCode).ToList();
                    
                }
                else
                {
                    inventories = _unitWork.Find<Inventory>(n => n.LocationCode == code).ToList();
                }

                if (inventories.Count == 0)
                {
                    tab.data = null;
                }
                else
                {
                    tab.data = inventories;
                }
                tab.code = 0;
            }
            catch (Exception ex)
            {
                tab.code = 300;
                tab.msg = ex.Message;
            }
            return tab;

        }

        public TableData GetLocDataApp(int roadway,int line)
        {
            TableData tab = new TableData();
            try
            {
                List<Location> list = new List<Location>();
                
                list = _unitWork.Find<Location>(n => n.Roadway == roadway && n.Line == line).ToList();

                decimal sum;
                //有托盘仓位
                decimal consum;
                //空仓位
                decimal empty;
                //有货仓位
                decimal some;
                //空栈板
                decimal emptycontainer;
                //利用率 包含空栈板
                decimal consumsum;
                //利用率
                decimal somesum;

                
                //库位总数
                sum = list.Count(n => n.IsStop == false && n.Roadway == roadway && n.Line == line);
                //有托盘仓位
                consum = list.Count(n => n.IsStop == false && n.Roadway == roadway && n.Line == line && !string.IsNullOrEmpty(n.ContainerCode));
                //空仓位
                empty = list.Count(n => n.IsStop == false && n.Roadway == roadway && n.Line == line && n.Status == "empty");
                //有货仓位
                some = list.Count(n => n.IsStop == false && n.Roadway == roadway && n.Line == line && n.Status == "some");
                //空栈板
                emptycontainer = list.Count(n => n.IsStop == false && n.Roadway == roadway && n.Line == line && n.Status == "emptycontainer");
                //利用率 包含空栈板
                consumsum = (consum / sum) * 100;
                //利用率
                somesum = (some / sum) * 100;


                dynamic temp = new ExpandoObject();
                temp.sum = sum;
                temp.consum = consum;
                temp.empty = empty;
                temp.some = some;
                temp.emptycontainer = emptycontainer;
                temp.consumsum = ((consum / sum) * 100).ToString("f0") + "%";
                temp.somesum = ((some / sum) * 100).ToString("f0") + "%";
                //string str = $"库位总数:{temp.sum} 有托盘仓位:{temp.consum} 空仓位:{temp.empty} 有货仓位:{temp.some} " +
                //    $"空栈板:{temp.emptycontainer} 利用率(含空栈板):{temp.consumsum} 利用率:{temp.somesum}";

                string str = $"库位总数:{temp.sum}   空仓位:{temp.empty}   空栈板:{temp.emptycontainer}   利用率(空):{temp.consumsum}   利用率:{temp.somesum}";
                tab.data = str;
                tab.code = 0;
            }
            catch (Exception ex)
            {
                tab.code = 300;
                tab.msg = ex.Message;
            }
            return tab;

        }
    }
}