Example #1
0
        /// <summary>
        /// 获取资产使用情况
        /// </summary>
        /// <param name="Mode"></param>
        /// <param name="Level1"></param>
        /// <returns></returns>
        public List <AssProRecordOutputDto> GetUseAnalyse(string Mode)
        {
            var list        = _AssProcessRecordRepository.GetUserData(Mode).AsNoTracking();
            var resultFirst = from AssPR in list
                              join Ass in SMOWMSDbContext.Assetss on AssPR.ASSID equals Ass.ASSID
                              join AssType in SMOWMSDbContext.AssetsTypes on Ass.TYPEID equals AssType.TYPEID
                              select new AssProRecordOutputDto()
            {
                TYPEID     = Ass.TYPEID,
                TYPENAME   = AssType.NAME,
                QUANTITY   = AssPR.QUANTITY,
                CREATEDATE = AssPR.CREATEDATE,
                TLEVEL     = (int)AssType.TLEVEL,
                Level1     = GetLevel1TypeID(AssType.TYPEID)
            };
            Dictionary <String, List <BarChartOutputDto> > AssetsData = new Dictionary <string, List <BarChartOutputDto> >();

            foreach (AssProRecordOutputDto Row in resultFirst)
            {
                var result = from AssPR in list
                             from Ass in SMOWMSDbContext.Assetss
                             from AssType in SMOWMSDbContext.AssetsTypes
                             where AssPR.ASSID == Ass.ASSID && Ass.TYPEID == AssType.TYPEID
                             select new AssProRecordOutputDto()
                {
                    TYPEID     = Ass.TYPEID,
                    TYPENAME   = AssType.NAME,
                    QUANTITY   = AssPR.QUANTITY,
                    CREATEDATE = AssPR.CREATEDATE
                };
                var Data = Mapper.Map <List <AssProRecordOutputDto>, List <AssProcessRecord> >(result.ToList());
                if (result.Count() > 0)            //数据超过一条,则进行数据缩减
                {
                    Data = ReduceData(Mode, Data); //同一天的行项数据归并为一条
                }
                List <BarChartOutputDto> ChartData = new List <BarChartOutputDto>();
                foreach (AssProcessRecord NowRow in Data)
                {
                    BarChartOutputDto NewRow = new BarChartOutputDto();
                    NewRow.QUANTITY   = NowRow.QUANTITY;
                    NewRow.CREATEDATE = NowRow.CREATEDATE;
                    ChartData.Add(NewRow);
                }
                String TypeName = _AssetsTypeRepository.GetByID(Row.Level1).FirstOrDefault().NAME;
                if (AssetsData.ContainsKey(TypeName) == false)
                {
                    AssetsData.Add(TypeName, ChartData);
                }
            }

            List <int>             xData   = new List <int>();
            List <List <decimal> > Assetss = new List <List <decimal> >();
            DateTime date  = DateTime.Now;
            int      year  = date.Year;
            int      month = date.Month;
            int      day   = date.Day;

            switch (Mode)
            {
            case "OM":
                for (int i = 0; i < day; i++)
                {
                    xData.Add(i + 1);
                }
                for (int j = 0; j < AssetsData.Count; j++)
                {
                    List <decimal> Assets = new List <decimal>();
                    for (int i = 0; i < day; i++)
                    {
                        Boolean isAdd = false;
                        foreach (String key in AssetsData.Keys)
                        {
                            foreach (BarChartOutputDto Row in AssetsData[key])
                            {
                                int DayThat = Row.CREATEDATE.Day;
                                if (i + 1 == DayThat)
                                {
                                    Assets[i] = Row.QUANTITY;
                                    isAdd     = true;
                                }
                            }
                            if (isAdd == false)
                            {
                                Assets[i] = 0;
                            }
                        }
                    }
                    Assetss[j] = Assets;
                }
                break;

            case "TM":
                for (int i = 0; i < 12; i++)
                {
                }
                break;

            case "OY":

                break;
            }
            return(resultFirst.AsNoTracking().ToList());
        }