Example #1
0
 public HistoryViewModel(IDialogService dialogService, HistoryClientServiceFactory historyClientServiceFactory,
                         ConvertingClientServiceFactory convertingClientServiceFactory,
                         IConverterClientPackageDataFromDto converterClientPackageDataFromDto)
 {
     DialogService        = dialogService;
     HistoryDataViewModel = new HistoryDataViewModel(historyClientServiceFactory, convertingClientServiceFactory,
                                                     converterClientPackageDataFromDto, dialogService);
     HistoryFilterViewModel = new HistoryFilterViewModel(historyClientServiceFactory,
                                                         HistoryDataViewModel.HistoryDataViewModelPart.UpdateHistoryData);
 }
        public async Task <List <HistoryDataViewModel> > GetLocalHistoryList(string monitorID, string start, string end)
        {
            //  Do:查找匹配数据
            var realdata = this._dbContext.ehc_dv_historys.Where(l => l.MonitorID == monitorID && l.CDate.ToDateTime() > start.ToDateTime() && l.CDate.ToDateTime() < end.ToDateTime());

            Func <ehc_dv_history, string> convert = l =>
            {
                return(l?.Value);
            };

            //  Do:按创建时间分组
            var group = realdata.GroupBy(l => l.CDate).Take(30);

            List <HistoryDataViewModel> result = new List <HistoryDataViewModel>();

            foreach (var item in group)
            {
                HistoryDataViewModel history = new HistoryDataViewModel();

                history.Heart  = realdata.FirstOrDefault(l => l.DataType == DataTypeConfiger.Heart && l.CDate.ToDateTime() <= item.Key.ToDateTime() && l.UDate.ToDateTime() >= item.Key.ToDateTime())?.Value;
                history.Breath = realdata.FirstOrDefault(l => l.DataType == DataTypeConfiger.Breath && l.CDate.ToDateTime() <= item.Key.ToDateTime() && l.UDate.ToDateTime() >= item.Key.ToDateTime())?.Value;
                history.Move   = realdata.FirstOrDefault(l => l.DataType == DataTypeConfiger.State && l.CDate.ToDateTime() <= item.Key.ToDateTime() && l.UDate.ToDateTime() >= item.Key.ToDateTime())?.Value == "mov" ? "1" : "0";;
                history.Leave  = realdata.FirstOrDefault(l => l.DataType == DataTypeConfiger.State && l.CDate.ToDateTime() <= item.Key.ToDateTime() && l.UDate.ToDateTime() >= item.Key.ToDateTime())?.Value == "off" ? "1" : "0";;
                history.Sleep  = realdata.FirstOrDefault(l => l.DataType == DataTypeConfiger.SleepTime && l.CDate.ToDateTime() <= item.Key.ToDateTime() && l.UDate.ToDateTime() >= item.Key.ToDateTime())?.Value == null ? "0" : "1";
                history.Date   = item.Key;
                result.Add(history);
            }

            //Func<IGrouping<string, ehc_dv_history>, HistoryDataViewModel> convertTo = l =>
            //   {
            //       HistoryDataViewModel history = new HistoryDataViewModel();
            //       history.Heart = l.FirstOrDefault(k => k.DataType == DataTypeConfiger.Heart)?.Value;
            //       history.Breath = l.FirstOrDefault(k => k.DataType == DataTypeConfiger.Breath)?.Value;
            //       history.Move = l.FirstOrDefault(k => k.DataType == DataTypeConfiger.State)?.Value == "mov" ? "1" : "0";
            //       history.Leave = l.FirstOrDefault(k => k.DataType == DataTypeConfiger.State)?.Value == "off" ? "1" : "0";
            //       history.Sleep = string.IsNullOrEmpty(l.FirstOrDefault(k => k.DataType == DataTypeConfiger.SleepTime)?.Value) ? "0" : "1";
            //       history.Date = l.Key;
            //       return history;
            //   };

            //var result = await realdata.Select(l => convertTo(l)).ToListAsync();

            return(null);
        }
        public ActionResult HistoryData(HistoryDataViewModel model)
        {
            var page = string.IsNullOrWhiteSpace(Request["page"]) ? 1 : int.Parse(Request["page"]);

            var pageSize = string.IsNullOrWhiteSpace(Request["pageSize"]) ? 10 : int.Parse(Request["pageSize"]);

            var queryName = Request["queryName"];

            int count;

            var conditions = new List <Expression <Func <ProtocolData, bool> > >();

            if (model.StartDateTime == DateTime.MinValue)
            {
                model.StartDateTime = DateTime.Now.AddDays(-7);
            }

            Expression <Func <ProtocolData, bool> > startCondition = ex => ex.UpdateTime > model.StartDateTime;

            conditions.Add(startCondition);

            if (model.EndDateTime == DateTime.MinValue)
            {
                model.EndDateTime = DateTime.Now;
            }

            Expression <Func <ProtocolData, bool> > endCondition = ex => ex.UpdateTime < model.EndDateTime;

            conditions.Add(endCondition);

            var historyData = ProcessInvoke <HotelRestaurantProcess>()
                              .GetPagedHistoryData(page, pageSize, queryName, out count, conditions);

            model.PageIndex   = page;
            model.PageSize    = pageSize;
            model.QueryName   = queryName;
            model.Count       = count;
            model.HistoryData = historyData;
            model.PageCount   = (count % pageSize) > 0 ? (count / pageSize) + 1 : (count / pageSize);

            return(View(model));
        }