예제 #1
0
 /// <summary>
 /// 在当前时间添加一个周期,获得新的下个周期时间
 /// </summary>
 /// <param name="time"></param>
 /// <param name="config"></param>
 /// <returns></returns>
 public static DateTime addCycleTime(DateTime time, MonitoringConfigData config)
 {
     if (config.CycleTypeId == DictionaryCache.PeriodYear.Id)
     {
         return(time.AddYears(1));
     }
     else if (config.CycleTypeId == DictionaryCache.PeriodMonth.Id)
     {
         return(time.AddMonths(1));
     }
     else if (config.CycleTypeId == DictionaryCache.PeriodWeek.Id)
     {
         return(time.AddDays(7));
     }
     else if (config.CycleTypeId == DictionaryCache.PeriodDay.Id)
     {
         return(time.AddDays(1));
     }
     else if (config.CycleTypeId == DictionaryCache.PeriodHour.Id)
     {
         return(time.AddHours(1));
     }
     else
     {
         return(time);
     }
 }
예제 #2
0
 public static MonitoringConfig ToModel(this MonitoringConfigData node)
 {
     return(new MonitoringConfig()
     {
         Id = node.Id,
         Name = node.Name,
         Description = node.Description,
         TargetTypeId = node.TargetTypeId,
         TargetId = node.TargetId,
         EnergyCategoryId = node.EnergyCategoryId,
         ConfigTypeId = node.ConfigTypeId,
         WayId = node.WayId,
         UnitValue = node.UnitValue,
         LowerLimit = node.LowerLimit,
         UpperLimit = node.UpperLimit,
         Value = node.Value,
         ValidStartTime = node.ValidStartTime,
         ValidEndTime = node.ValidEndTime,
         Priority = node.Priority,
         Enabled = node.Enabled,
         TemplateId = node.TemplateId,
         OverTimeDate = node.OverTimeDate,
         StartTime = node.StartTime,
         EndTime = node.EndTime,
         RegeneratorId = node.RegeneratorId,
         RegeneratorName = node.RegeneratorName,
         UpdatingTime = node.UpdatingTime,
         ParameterId = node.ParameterId,
         CycleTime = node.CycleTime,
         CycleTypeId = node.CycleTypeId,
         AlarmLevelId = node.AlarmLevelId,
         IsvalidNextCycle = node.IsvalidNextCycle,
     });
 }
예제 #3
0
 /// <summary>
 /// 获得配置的总定额数据
 /// </summary>
 /// <param name="quota"></param>
 /// <param name="quotaValue"></param>
 /// <returns></returns>
 private decimal GetQuotaValue(MonitoringConfigData quota, decimal quotaValue)
 {
     if (quota.WayId == DictionaryCache.QuotaWayPerCapita.Id)
     {
         if (quota.TargetTypeId == DictionaryCache.ConfigToOrg.Id)
         {
             var org = db.Organizations.FirstOrDefault(o => o.Id == quota.TargetId);
             if (org.CustomerCount == null)
             {
                 throw new Exception("组织机构没有设置人数,无法计算人均定额数据");
             }
             quotaValue = (int)org.CustomerCount * (decimal)quota.UnitValue;
         }
         else
         {
             var building = db.Buildings.FirstOrDefault(o => o.Id == quota.TargetId);
             if (building.CustomerCount == null)
             {
                 throw new Exception("建筑没有设置人数,无法计算人均定额数据");
             }
             quotaValue = (int)building.CustomerCount * (decimal)quota.UnitValue;
         }
     }
     else if (quota.WayId == DictionaryCache.QuotaWayPerUnitArea.Id)
     {
         if (quota.TargetTypeId == DictionaryCache.ConfigToOrg.Id)
         {
             var     org  = db.Organizations.FirstOrDefault(o => o.Id == quota.TargetId);
             decimal area = (decimal)org.Buildings.Sum(o => o.TotalArea);
             if (area == 0)
             {
                 throw new Exception("组织机构下属建筑均没有设置总面积,无法计算单位面积定额数据");
             }
             quotaValue = area * (decimal)quota.UnitValue;
         }
         else
         {
             var building = db.Buildings.FirstOrDefault(o => o.Id == quota.TargetId);
             if (building.TotalArea == null)
             {
                 throw new Exception("建筑没有设置总面积,无法计算单位面积定额数据");
             }
             quotaValue = (int)building.TotalArea * (decimal)quota.UnitValue;
         }
     }
     else
     {
         quotaValue = (decimal)quota.Value;
     }
     return(quotaValue);
 }
예제 #4
0
        /// <summary>
        /// 根据配置文件获得指定检测循环周期的结束时间
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        public DateTime GetEndTime(MonitoringConfigData config, DateTime thisTime)
        {
            DateTime endTime = (DateTime)config.CycleTime;

            if (DictionaryCache.PeriodYear.Id == config.CycleTypeId)
            {
                endTime = new DateTime(thisTime.Year, endTime.Month, endTime.Day, endTime.Hour, endTime.Minute, endTime.Second);
                if (endTime <= thisTime)
                {
                    endTime = endTime.AddYears(1);
                }
            }
            else if (DictionaryCache.PeriodMonth.Id == config.CycleTypeId)
            {
                endTime = new DateTime(thisTime.Year, thisTime.Month, endTime.Day, endTime.Hour, endTime.Minute, endTime.Second);
                if (endTime <= thisTime)
                {
                    endTime = endTime.AddMonths(1);
                }
            }
            else if (DictionaryCache.PeriodWeek.Id == config.CycleTypeId)
            {
                TimeSpan ts        = thisTime - endTime;
                var      totalDays = ts.TotalDays;
                endTime = thisTime.AddDays(0 - (totalDays % 7)).AddDays(7);
            }
            else if (DictionaryCache.PeriodDay.Id == config.CycleTypeId)
            {
                endTime = new DateTime(thisTime.Year, thisTime.Month, thisTime.Day, endTime.Hour, endTime.Minute, endTime.Second);
                if (endTime <= thisTime)
                {
                    endTime = endTime.AddDays(1);
                }
            }
            else if (DictionaryCache.PeriodHour.Id == config.CycleTypeId)
            {
                endTime = new DateTime(thisTime.Year, thisTime.Month, thisTime.Day, thisTime.Hour, endTime.Minute, endTime.Second);
                if (endTime <= thisTime)
                {
                    endTime = endTime.AddHours(1);
                }
            }
            else if (DictionaryCache.PeriodTCustomer != null && DictionaryCache.PeriodTCustomer.Id == config.CycleTypeId)
            {
                endTime = (DateTime)config.CycleTime;
            }
            return(endTime);
        }
예제 #5
0
        /// <summary>
        /// 根据配置文件获得指定检测循环周期的开始时间
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        public DateTime GetBeginTime(MonitoringConfigData config, DateTime thisTime)
        {
            DateTime beginTime = (DateTime)config.CycleTime;

            if (DictionaryCache.PeriodYear.Id == config.CycleTypeId)
            {
                beginTime = new DateTime(thisTime.Year, beginTime.Month, beginTime.Day, beginTime.Hour, beginTime.Minute, beginTime.Second);
                if (beginTime > thisTime)
                {
                    beginTime = beginTime.AddYears(-1);
                }
            }
            else if (DictionaryCache.PeriodMonth.Id == config.CycleTypeId)
            {
                beginTime = new DateTime(thisTime.Year, thisTime.Month, beginTime.Day, beginTime.Hour, beginTime.Minute, beginTime.Second);
                if (beginTime > thisTime)
                {
                    beginTime = beginTime.AddMonths(-1);
                }
            }
            else if (DictionaryCache.PeriodWeek.Id == config.CycleTypeId)
            {
                TimeSpan ts        = thisTime - beginTime;
                var      totalDays = ts.TotalDays;
                beginTime = thisTime.AddDays(0 - (totalDays % 7));
            }
            else if (DictionaryCache.PeriodDay.Id == config.CycleTypeId)
            {
                beginTime = new DateTime(thisTime.Year, thisTime.Month, thisTime.Day, beginTime.Hour, beginTime.Minute, beginTime.Second);
                if (beginTime > thisTime)
                {
                    beginTime = beginTime.AddDays(-1);
                }
            }
            else if (DictionaryCache.PeriodHour.Id == config.CycleTypeId)
            {
                beginTime = new DateTime(thisTime.Year, thisTime.Month, thisTime.Day, thisTime.Hour, beginTime.Minute, beginTime.Second);
                if (beginTime > thisTime)
                {
                    beginTime = beginTime.AddHours(-1);
                }
            }
            return(beginTime);
        }
예제 #6
0
        public static MonitoringConfigData ToViewData(this MonitoringConfig node, CategoryDictionary suffix = CategoryDictionary.None)
        {
            MonitoringConfigBLL MonitoringConfigBLL = new MonitoringConfigBLL();

            if (node == null)
            {
                return(null);
            }
            var model = new MonitoringConfigData()
            {
                Id                                          = node.Id,
                Name                                        = node.Name,
                Description                                 = node.Description,
                TargetTypeId                                = node.TargetTypeId,
                TargetId                                    = node.TargetId,
                EnergyCategoryId                            = node.EnergyCategoryId,
                ConfigTypeId                                = node.ConfigTypeId,
                WayId                                       = node.WayId,
                UnitValue                                   = node.UnitValue,
                LowerLimit                                  = node.LowerLimit,
                UpperLimit                                  = node.UpperLimit,
                Value                                       = node.Value,
                ValidStartTime                              = node.ValidStartTime,
                ValidEndTime                                = node.ValidEndTime,
                Priority                                    = node.Priority,
                Enabled                                     = node.Enabled,
                StartTime                                   = node.StartTime,
                EndTime                                     = node.EndTime,
                RegeneratorId                               = node.RegeneratorId,
                RegeneratorName                             = node.RegeneratorName,
                UpdatingTime                                = node.UpdatingTime,
                ParameterId                                 = node.ParameterId,
                TemplateId                                  = node.TemplateId,
                OverTimeDate                                = node.OverTimeDate,
                CycleTime                                   = node.CycleTime,
                CycleTypeId                                 = node.CycleTypeId,
                AlarmLevelId                                = node.AlarmLevelId,
                IsvalidNextCycle                            = node.IsvalidNextCycle,
                ValidTypeId                                 = node.ValidTypeId,
                ValidType                                   = node.ValidTypeId == null ? null : node.ValidType == null?DictionaryCache.Get()[(int)node.ValidTypeId].ToViewData() : node.ValidType.ToViewData(),
                                                 AlarmLevel = node.AlarmLevelId == null ? null : node.AlarmLevel == null?DictionaryCache.Get()[(int)node.AlarmLevelId].ToViewData() : node.AlarmLevel.ToViewData(),
                                                                  ConfigType = node.ConfigType == null?DictionaryCache.Get()[(int)node.ConfigTypeId].ToViewData() : node.ConfigType.ToViewData(),
                                                                                   CycleType = node.CycleTypeId == null ? null : node.CycleType == null?DictionaryCache.Get()[(int)node.CycleTypeId].ToViewData() : node.CycleType.ToViewData(),
                                                                                                   EnergyCategory = node.EnergyCategoryId == null ? null : node.EnergyCategory == null?DictionaryCache.Get()[(int)node.EnergyCategoryId].ToViewData() : node.EnergyCategory.ToViewData(),
                                                                                                                        TargetType                     = node.TargetType == null?DictionaryCache.Get()[(int)node.TargetTypeId].ToViewData() : node.TargetType.ToViewData(),
                                                                                                                                                   Way = node.WayId == null ? null : node.Way == null?DictionaryCache.Get()[(int)node.WayId].ToViewData() : node.Way.ToViewData(),
                                                                                                                                                             TemplateName = node.TemplateId.HasValue ? null : MonitoringConfigBLL.Filter(o => o.TemplateId == node.TemplateId).Take(1).Select(o => o.Name).ToList()[0]
            };

            //模板联动动作
            if (node.Value.HasValue)
            {
                try
                {
                    int actionId = Convert.ToInt32(node.Value);
                    model.ActionName = DictionaryCache.Get()[actionId].ChineseName;
                }
                catch { }
            }

            if (node.ConfigCycleSettings != null)
            {
                ConfigCycleSettingBLL ConfigCycleSettingBLL = new ConfigCycleSettingBLL();
                int id = model.Id;
                model.ConfigCycleSettings = ConfigCycleSettingBLL.Filter(o => o.ConfigId == id).ToViewList();
            }


            if (node.CycleTypeId != null)
            {
                if (model.CycleType.ChineseName == "每年")
                {
                    //model.CycleTimeName = "按年";
                    //model.CycleTimeDesc = Convert.ToDateTime(node.CycleTime).Year + "年";
                    model.CycleTimeName = model.CycleType.ChineseName;
                    model.CycleTimeDesc = Convert.ToDateTime(node.CycleTime).Month + "月" + Convert.ToDateTime(node.CycleTime).Day + "日" + Convert.ToDateTime(node.CycleTime).Hour + "时";
                }
                else if (model.CycleType.ChineseName == "每月")
                {
                    model.CycleTimeName = model.CycleType.ChineseName;
                    model.CycleTimeDesc = Convert.ToDateTime(node.CycleTime).Day + "日" + Convert.ToDateTime(node.CycleTime).Hour + "时";
                    //model.CycleTimeName = model.CycleType.ChineseName;
                    //model.CycleTimeDesc = Convert.ToDateTime(node.CycleTime).Month + "月"+Convert.ToDateTime(node.CycleTime).Day + "日"+Convert.ToDateTime(node.CycleTime).Hour + "时";
                }
                else if (model.CycleType.ChineseName == "每周")
                {
                    model.CycleTimeName = model.CycleType.ChineseName;
                    model.CycleTimeDesc = "第" + Convert.ToDateTime(node.CycleTime).DayOfWeek + "日" + Convert.ToDateTime(node.CycleTime).Hour + "时";
                    //model.CycleTimeName = "每周";
                    //model.CycleTimeDesc = "第" + Convert.ToDateTime(node.CycleTime).DayOfWeek + "日";
                }
                else if (model.CycleType.ChineseName == "每日")
                {
                    model.CycleTimeName = model.CycleType.ChineseName;
                    model.CycleTimeDesc = Convert.ToDateTime(node.CycleTime).Hour + "时";
                    //model.CycleTimeName = "每月";
                    //model.CycleTimeDesc = "第" + Convert.ToDateTime(node.CycleTime).Day + "日";
                }
                else if (model.CycleType.ChineseName == "每小时")
                {
                    model.CycleTimeName = model.CycleType.ChineseName;
                    //model.CycleTimeName = "每天";
                    //model.CycleTimeDesc = "第" + Convert.ToDateTime(node.CycleTime).Year + "时";
                }
            }
            if (node.ValidTypeId != null)
            {
                if (model.ValidType.ChineseName == "每年")
                {
                    model.ValidTypeDesc = "检测";
                    model.ValidTypeDesc = model.ValidTypeDesc + Convert.ToDateTime(model.ValidStartTime).Year;
                    if (Convert.ToDateTime(model.ValidStartTime).Year != Convert.ToDateTime(model.ValidEndTime).Year)
                    {
                        model.ValidTypeDesc = model.ValidTypeDesc + "至" + Convert.ToDateTime(model.ValidEndTime).Year;
                    }
                    model.ValidTypeDesc = model.ValidTypeDesc + "年数据";
                }
                else if (model.ValidType.ChineseName == "每月")
                {
                    model.ValidTypeDesc = "每年检测";
                    model.ValidTypeDesc = model.ValidTypeDesc + Convert.ToDateTime(model.ValidStartTime).Month;
                    if (Convert.ToDateTime(model.ValidStartTime).Month != Convert.ToDateTime(model.ValidEndTime).Month)
                    {
                        model.ValidTypeDesc = model.ValidTypeDesc + "至" + Convert.ToDateTime(model.ValidEndTime).Month;
                    }
                    model.ValidTypeDesc = model.ValidTypeDesc + "月数据";
                }
                else if (model.ValidType.ChineseName == "每周")
                {
                    model.ValidTypeDesc = "每周检测周";
                    model.ValidTypeDesc = model.ValidTypeDesc + Convert.ToDateTime(model.ValidStartTime).DayOfWeek;
                    if (Convert.ToDateTime(model.ValidStartTime).DayOfWeek != Convert.ToDateTime(model.ValidEndTime).DayOfWeek)
                    {
                        model.ValidTypeDesc = model.ValidTypeDesc + "至" + Convert.ToDateTime(model.ValidEndTime).DayOfWeek;
                    }
                    model.ValidTypeDesc = model.ValidTypeDesc + "数据";
                }
                else if (model.ValidType.ChineseName == "每日")
                {
                    model.ValidTypeDesc = "每月检测第";
                    model.ValidTypeDesc = model.ValidTypeDesc + Convert.ToDateTime(model.ValidStartTime).Day;
                    if (Convert.ToDateTime(model.ValidStartTime).Day != Convert.ToDateTime(model.ValidEndTime).Day)
                    {
                        model.ValidTypeDesc = model.ValidTypeDesc + "至" + Convert.ToDateTime(model.ValidEndTime).Day;
                    }
                    model.ValidTypeDesc = model.ValidTypeDesc + "日数据";
                }
                else if (model.ValidType.ChineseName == "每小时")
                {
                    model.ValidTypeDesc = "每天检测第";
                    model.ValidTypeDesc = model.ValidTypeDesc + Convert.ToDateTime(model.ValidStartTime).Hour;
                    if (Convert.ToDateTime(model.ValidStartTime).Hour != Convert.ToDateTime(model.ValidEndTime).Hour)
                    {
                        model.ValidTypeDesc = model.ValidTypeDesc + "至" + Convert.ToDateTime(model.ValidEndTime).Hour;
                    }
                    model.ValidTypeDesc = model.ValidTypeDesc + "时数据";
                }
            }
            if (node.ParameterId != null && (suffix & CategoryDictionary.Parameter) == CategoryDictionary.Parameter)
            {
                if (node.Parameter != null)
                {
                    model.Parameter = node.Parameter.ToViewData();
                }
                else
                {
                    ParameterBLL parameterBLL = new ParameterBLL();
                    model.Parameter = parameterBLL.Find(node.ParameterId).ToViewData();
                }
            }

            //string TargetTypeStr = node.TargetType == null ? DictionaryCache.Get()[node.TargetTypeId].Description : node.TargetType.Description;
            //if (TargetTypeStr != null)
            //{
            //    ViewMeterFullInfoBLL meterBLL = new ViewMeterFullInfoBLL();
            //    BuildingBLL buildingBLL = new BuildingBLL();
            //    OrganizationBLL organizationBLL = new OrganizationBLL();
            //    BrandBLL brandBLL = new BrandBLL();
            //    MessageBLL messageBLL = new MessageBLL();
            //    int id = -1;
            //    if (model.TargetId != null)
            //    {
            //        id=model.TargetId;
            //        if (TargetTypeStr.ToLower() == "meter")
            //            model.Target = meterBLL.Find(id).ToViewData();
            //        else if (TargetTypeStr.ToLower() == "building")
            //            model.Target = buildingBLL.Find(id).ToViewData();
            //        else if (TargetTypeStr.ToLower() == "organization")
            //            model.Target = organizationBLL.Find(id).ToViewData();
            //        else if (TargetTypeStr.ToLower() == "brand")
            //            model.Target = brandBLL.Find(id).ToViewData();
            //        else if (TargetTypeStr.ToLower() == "message")
            //            model.Target = messageBLL.Find(id).ToViewData();
            //    }
            //}
            return(model);
        }
예제 #7
0
        public static IList<ConfigDetailData> ToViewList(this IQueryable<ConfigDetail> nodes, CategoryDictionary suffix = CategoryDictionary.None)
        {
            if (nodes == null)
                return null;
            var nodeList = nodes.ToList();
            var results = nodeList.Select(node => new ConfigDetailData()
            {
                Id = node.Id,
                TemplateId = node.TemplateId,
                MeterId = node.MeterId,
                BuildingId = node.BuildingId,
                OrganizationId = node.OrganizationId,
                Enabled = node.Enabled,
                OperatorId = node.OperatorId,
                OperatorName = node.OperatorName,
                CreateTime = node.CreateTime,
                BuildingCategoryId = node.BuildingCategoryId,
                EnergyCategoryId = node.EnergyCategoryId,
                IsOpenOverLoadAlert = node.IsOpenOverLoadAlert,
                IsOpenMalignantLoadAlert = node.IsOpenMalignantLoadAlert,
                IsControlPower = node.IsControlPower,
                IsControlWater = node.IsControlWater,
                IsControlWaterByPower = node.IsControlWaterByPower,
                VacationTimeControlTemplateId = node.VacationTimeControlTemplateId,
                HolidayTimeControlTemplateId = node.HolidayTimeControlTemplateId,
                WeekEndTimeControlTemplateId = node.WeekEndTimeControlTemplateId,
                PeacetimeTimeControlTemplateId = node.PeacetimeTimeControlTemplateId,
                IsControlByAccount = node.IsControlByAccount,
                IsControlByTime = node.IsControlByTime,
                MinThresholdForMalignantLoad = node.MinThresholdForMalignantLoad,
                MinThresholdForOverLoad = node.MinThresholdForOverLoad

            }).ToList();
            using (MonitoringConfigBLL configBLL = new MonitoringConfigBLL())
            {
                for (int i = 0; i < results.Count; i++)
                {
                    if (nodeList[i].MonitoringConfigTemplate != null)
                        results[i].Template = nodeList[i].MonitoringConfigTemplate.ToViewData();
                    else
                    {

                        MonitoringConfigData config = null;
                        for (int j = 0; j < i; j++)
                        {
                            if (results[j].TemplateId == results[i].TemplateId)
                                config = results[j].Template;
                        }
                        if (config == null)
                            results[i].Template = configBLL.Find(nodeList[i].TemplateId).ToViewData();
                        else
                            results[i].Template = config;
                    }
                    if (nodeList[i].MonitoringConfigTemplate == null)
                        results[i].VacationTimeControlTemplate = configBLL.Find(nodeList[i].VacationTimeControlTemplateId).ToViewData();
                    else
                        results[i].VacationTimeControlTemplate = nodeList[i].VacationTimeControlTemplate.ToViewData();

                    if (nodeList[i].HolidayTimeControlTemplate == null)
                        results[i].HolidayTimeControlTemplate = configBLL.Find(nodeList[i].HolidayTimeControlTemplateId).ToViewData();
                    else
                        results[i].HolidayTimeControlTemplate = nodeList[i].HolidayTimeControlTemplate.ToViewData();

                    if (nodeList[i].WeekEndTimeControlTemplate == null)
                        results[i].WeekEndTimeControlTemplate = configBLL.Find(nodeList[i].WeekEndTimeControlTemplateId).ToViewData();
                    else
                        results[i].WeekEndTimeControlTemplate = nodeList[i].WeekEndTimeControlTemplate.ToViewData();

                    if (nodeList[i].PeacetimeTimeControlTemplate == null)
                        results[i].PeacetimeTimeControlTemplate = configBLL.Find(nodeList[i].PeacetimeTimeControlTemplateId).ToViewData();
                    else
                        results[i].PeacetimeTimeControlTemplate = nodeList[i].PeacetimeTimeControlTemplate.ToViewData();

                }
            }
            return results;
        }
예제 #8
0
        /// <summary>
        /// 用于postsearch中,转换旧版本搜索格式支持新版本格式
        /// </summary>
        /// <param name="me"></param>
        /// <param name="targetType"></param>
        /// <param name="targetId"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <param name="templateIds"></param>
        /// <returns></returns>
        public IList <MonitoringConfigData> GetConfigsByTargetAndTime(DAL.EmpModels.User me, int targetType, int targetId, DateTime?startTime, DateTime?endTime, List <int?> templateIds)
        {
            IQueryable <ConfigDetail> details;

            if (targetId != -1)
            {
                details = db.ConfigDetail.Where(o => templateIds.Contains(o.Id) &&
                                                ((targetType == DictionaryCache.ConfigToBuilding.Id && o.BuildingId == targetId) ||
                                                 (targetType == DictionaryCache.ConfigToMeter.Id && o.MeterId == targetId) ||
                                                 (targetType == DictionaryCache.ConfigToOrg.Id && o.OrganizationId == targetId))
                                                );
            }
            else
            {
                details = this.db.ConfigDetail.Where(o => templateIds.Contains(o.Id)
                                                     );
            }
            if (startTime != null)
            {
                details = details.Where(o => o.Template.ConfigCycleSettings.Any(c => c.BeginTime <= startTime));
            }
            if (endTime != null)
            {
                details = details.Where(o => o.Template.ConfigCycleSettings.Any(c => c.EndTime >= endTime));
            }
            var detailsList = details.ToList();
            IList <MonitoringConfigData> results = new List <MonitoringConfigData>();
            List <string> hasRightUserIds        = new List <string>();
            List <string> notHasRightUserIds     = new List <string>();
            var           tempIDs           = detailsList.Select(o => o.TemplateId).ToList();
            var           monitoringConfigs = this.Filter(o => tempIDs.Contains((int)o.TemplateId)).ToList();

            foreach (var detail in detailsList)
            {
                bool isHasRight = true;
                if (notHasRightUserIds.Contains(detail.OperatorId))
                {
                    isHasRight = false;
                }
                else if (hasRightUserIds.Contains(detail.OperatorId))
                {
                    isHasRight = true;
                }
                else
                {
                    //修改是否允许配置参数
                    var editUser = this.db.Users.FirstOrDefault(o => o.Id == detail.OperatorId);

                    //如果配置者有权限的机构存在任意一是当前用户有权限机构的上级机构,则不允许修改
                    var orgsForEditUser = editUser.Organizations;
                    var orgsForMe       = me.Organizations;
                    var count           = orgsForEditUser.Where(o => orgsForMe.Any(c => c.TreeId.StartsWith(o.TreeId + "-"))).Count();
                    if (count > 0)
                    {
                        isHasRight = false;
                        notHasRightUserIds.Add(editUser.Id);
                    }
                    else
                    {
                        hasRightUserIds.Add(editUser.Id);
                    }
                }
                var templates = monitoringConfigs.Where(o => o.TemplateId == detail.TemplateId).ToList();
                foreach (var template in templates)
                {
                    foreach (var cycleSetting in template.ConfigCycleSettings)
                    {
                        MonitoringConfigData config = new MonitoringConfigData();
                        EntityTools.EntityCopy(template.ToViewData(), config, "");
                        if (config.TargetTypeId == DictionaryCache.ConfigToBuilding.Id)
                        {
                            detail.BuildingId = config.TargetId;
                        }
                        else if (config.TargetTypeId == DictionaryCache.ConfigToOrg.Id)
                        {
                            detail.OrganizationId = config.TargetId;
                        }
                        else if (config.TargetTypeId == DictionaryCache.ConfigToMeter.Id)
                        {
                            detail.MeterId = config.TargetId;
                        }
                        config.StartTime  = cycleSetting.BeginTime;
                        config.EndTime    = cycleSetting.EndTime;
                        config.isAlowEdit = isHasRight;
                        results.Add(config);
                    }
                }
            }
            return(results);
        }
예제 #9
0
        /// <summary>
        /// 获得配置对象在指定周期内的定额数据
        /// </summary>
        /// <param name="needConfigs"></param>
        /// <param name="startTime"></param>
        /// <param name="finishTime"></param>
        /// <param name="meterIds"></param>
        private decimal GetQuota(MonitoringConfigData quota, DateTime startTime, DateTime finishTime, List <int> meterIds)
        {
            //获得当前定额周期用量
            var beginTime1  = GetBeginTime(quota, startTime);
            var finishTime1 = GetEndTime(quota, startTime);
            var beginTime2  = GetBeginTime(quota, finishTime.AddMilliseconds(-1));
            var finishTime2 = GetEndTime(quota, finishTime.AddMilliseconds(-1));

            if (beginTime1 != beginTime2 || finishTime1 != finishTime2 || beginTime1 > startTime || finishTime1 < finishTime)
            {
                throw new Exception("当前定额周期应包含定价周期");
            }
            decimal total = 0;
            //先统计月表数据
            var beginMonthTime  = new DateTime(beginTime1.AddMonths(1).Year, beginTime1.AddMonths(1).Month, 1, 0, 0, 0);
            var finishMonthTime = new DateTime(finishTime1.Year, finishTime1.Month, 1, 0, 0, 0);

            if (finishMonthTime > beginMonthTime)
            {
                try
                {
                    total = total + db.MeterMonthlyResults.Where(o => meterIds.Contains(o.MeterId) && DictionaryCache.EnergyStatusActiveIds.Contains(o.Status) && o.StartTime >= beginMonthTime && o.FinishTime <= finishMonthTime).Sum(o => o.Total * o.Meter.Rate);
                }
                catch { }
            }
            //再统计日表数据
            //在同一个月
            if (beginTime1.Year + " " + beginTime1.Month == finishTime1.Year + " " + finishTime1.Month)
            {
                var beginDayTime  = new DateTime(beginTime1.AddDays(1).Year, beginTime1.AddDays(1).Month, beginTime1.AddDays(1).Day, 0, 0, 0);
                var finishDayTime = new DateTime(finishTime1.Year, finishTime1.Month, finishTime1.Day, 0, 0, 0);
                try
                {
                    total = total + db.MeterDailyResults.Where(o => meterIds.Contains(o.MeterId) && DictionaryCache.EnergyStatusActiveIds.Contains(o.Status) && o.StartTime >= beginDayTime && o.FinishTime <= finishDayTime).Sum(o => o.Total * o.Meter.Rate);
                }
                catch { }
            }
            else
            {
                //不在同一个月
                var beginDayTime  = new DateTime(beginTime1.AddDays(1).Year, beginTime1.AddDays(1).Month, beginTime1.AddDays(1).Day, 0, 0, 0);
                var finishDayTime = new DateTime(beginTime1.AddMonths(1).Year, beginTime1.AddMonths(1).Month, 1, 0, 0, 0);
                try
                {
                    total = total + db.MeterDailyResults.Where(o => meterIds.Contains(o.MeterId) && DictionaryCache.EnergyStatusActiveIds.Contains(o.Status) && o.StartTime >= beginDayTime && o.FinishTime <= finishDayTime).Sum(o => o.Total * o.Meter.Rate);
                }
                catch { }
                beginDayTime  = new DateTime(finishTime1.Year, finishTime1.Month, 1, 0, 0, 0);
                finishDayTime = new DateTime(finishTime1.Year, finishTime1.Month, finishTime1.Day, 0, 0, 0);
                try
                {
                    total = total + db.MeterDailyResults.Where(o => meterIds.Contains(o.MeterId) && DictionaryCache.EnergyStatusActiveIds.Contains(o.Status) && o.StartTime >= beginDayTime && o.FinishTime <= finishDayTime).Sum(o => o.Total * o.Meter.Rate);
                }
                catch { }
            }
            //再统计头尾两天小时表数据
            var endDayTime2 = new DateTime(beginTime1.AddDays(1).Year, beginTime1.AddDays(1).Month, beginTime1.AddDays(1).Day, 0, 0, 0);

            try
            {
                total = total + db.MeterDailyResults.Where(o => meterIds.Contains(o.MeterId) && DictionaryCache.EnergyStatusActiveIds.Contains(o.Status) && o.StartTime >= beginTime1 && o.FinishTime <= endDayTime2).Sum(o => o.Total * o.Meter.Rate);
            }
            catch { }
            var beginDayTime2 = new DateTime(finishTime1.Year, finishTime1.Month, 1, 0, 0, 0);

            try
            {
                total = total + db.MeterDailyResults.Where(o => meterIds.Contains(o.MeterId) && DictionaryCache.EnergyStatusActiveIds.Contains(o.Status) && o.StartTime >= beginDayTime2 && o.FinishTime <= finishTime1).Sum(o => o.Total * o.Meter.Rate);
            }
            catch { }

            return(total);
        }