EchartsDataApp.cs 2.54 KB
using Infrastructure;
using Microsoft.AspNetCore.Hosting;
using System;
using System.Dynamic;
using System.Linq;
using WebRepository;

namespace WebApp
{
    /// <summary>
    /// 仓库地图
    /// </summary>

    public class EchartsDataApp
    {
        private IUnitWork _unitWork;
        TableData result = new TableData();

        public EchartsDataApp(IUnitWork unitWork)
        {
            _unitWork = unitWork;
        }
        public TableData GetWeekTask()
        {
            DateTime dt = DateTime.Now.AddDays(-6).Date;
            dynamic sp = new ExpandoObject();
            var weektask = _unitWork.Find<InventoryTransaction>(a => a.CreateTime > dt).GroupBy(a =>a.Type).SelectMany(g => g.GroupBy(b => ((DateTime)b.CreateTime).ToString("yyyy-MM-dd"))).Select(g => (new { name = g.Key, count = g.Count(),type=g.AsQueryable().Select(u=>u.Type).First() })).OrderBy(a => a.name);
            result.data = weektask.ToList();
            return result;
        }

        public TableData GetWareCellCount()
        {
            var lct = _unitWork.Find<Location>(null).GroupBy(a => a.Status).SelectMany(g => g.GroupBy(b => b.Status)).Select(g => (new { name = g.Key, count = g.Count(), Status = g.AsQueryable().Select(u => u.Status).First() })).OrderBy(a => a.name);
            result.data = lct.ToList();
            return result;
        }

        public TableData GetWaitTask()
        {
            //var task = _unitWork.Find<TaskDetail>(null).GroupBy(a => a.TaskType ).SelectMany(g => g.GroupBy(b => b.TaskType )).Select(g => (new { name = g.Key, count = g.Count(), TaskType = g.AsQueryable().Select(u => u.TaskType).First() })).OrderBy(a => a.name);
            var task = from t in _unitWork.Find<TaskDetail>(null)
                        group t by new { t.TaskType, t.ContainerCode} into g
                        select new
                        {
                            value = g.Count(),
                            name = g.Key.TaskType,
                        };
            result.data = task.ToList();
            return result;
        }


        public TableData GetMaterielByGroup()
        {
            var mcdata = from it in _unitWork.Find <Inventory>(null)
                       group it by it.MaterialCode into g
                       select new
                       {
                           value = g.Sum(p => decimal.Parse(p.Qty.ToString())),
                           name = g.Key,
                       };

            result.data = mcdata.ToList().OrderByDescending(u=>u.value);
            return result;
        }

    }
}