NouYouLocationMonitorApp.cs 5.4 KB
using Infrastructure;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
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
            {
                if (roadway == 5)
                {
                    var list = (from location in _unitWork.Find<Location>(n => n.Roadway == 5 && n.Line == line && (n.Code.Contains("EA") || n.Code.Contains("EB")))
                                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;
                }
                else if (roadway == 6)
                {
                    var list = (from location in _unitWork.Find<Location>(n => n.Roadway == 5 && n.Line == line && (n.Code.Contains("EC") || n.Code.Contains("ED")))
                                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;
                }
                else
                {
                    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
            {
                if (roadway == 5)
                {
                    var list = (from location in _unitWork.Find<Location>(null)
                                where location.Roadway == roadway && (location.Code.Contains("EA") || location.Code.Contains("EB"))
                                group location by new {location.Line } into line
                                select new { line.Key }).OrderBy(n => n.Key.Line).ToList();
                    tab.data = list;
                }
                else if (roadway == 6)
                {
                    var list = (from location in _unitWork.Find<Location>(null)
                                where location.Roadway == 5  && (location.Code.Contains("EC") || location.Code.Contains("ED"))
                                group location by new { location.Line } into line
                                select new { line.Key }).OrderBy(n => n.Key.Line).ToList();
                    tab.data = list;
                }
                else
                {
                    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)
        {
            TableData tab = new TableData();
            try
            {
                List<Inventory> 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;

        }
    }
}