Exemple #1
0
        /// <summary>
        /// Add Data To Cache
        /// </summary>
        private List <IDValuePair <BatStaticInfo, List <BatStaticInfo> > > AddDataToCache()
        {
            var userData = UserData;
            var cacheKey = WebUtility.GetCacheKeyName(userData, "bat-count-report");

            HttpRuntime.Cache.Remove(cacheKey);

            var lscUsers = new List <LscUserInfo>();

            if (LscsComboBox.SelectedIndex > 0)
            {
                var ids = WebUtility.ItemSplit(LscsComboBox.SelectedItem.Value);
                if (ids.Length == 2)
                {
                    var lscId   = Int32.Parse(ids[0]);
                    var groupId = Int32.Parse(ids[1]);
                    var lscUser = userData.LscUsers.Find(lu => { return(lu.LscID == lscId); });
                    if (lscUser != null)
                    {
                        lscUsers.Add(lscUser);
                    }
                }
            }
            else
            {
                lscUsers.AddRange(userData.LscUsers);
            }

            if (lscUsers.Count == 0)
            {
                return(null);
            }

            int?     area2Id       = null;
            int?     area3Id       = null;
            int?     staId         = null;
            int?     devId         = null;
            int?     devIndex      = null;
            DateTime?beginFromTime = null;
            DateTime?beginToTime   = null;
            DateTime?endFromTime   = null;
            DateTime?endToTime     = null;
            double   minInterval   = 0;
            double   maxInterval   = Int32.MaxValue;

            if (Area2ComboBox.SelectedIndex > 0)
            {
                area2Id = Int32.Parse(Area2ComboBox.SelectedItem.Value);
            }
            if (Area3ComboBox.SelectedIndex > 0)
            {
                area3Id = Int32.Parse(Area3ComboBox.SelectedItem.Value);
            }
            if (StaComboBox.SelectedIndex > 0)
            {
                staId = Int32.Parse(StaComboBox.SelectedItem.Value);
            }
            if (DevComboBox.SelectedIndex > 0)
            {
                devId = Int32.Parse(DevComboBox.SelectedItem.Value);
            }
            if (!DevIndexNumberField.IsEmpty)
            {
                devIndex = (Int32)DevIndexNumberField.Number;
            }
            if (!String.IsNullOrEmpty(BeginFromDate.Text.Trim()))
            {
                beginFromTime = DateTime.Parse(BeginFromDate.Text);
            }
            if (!String.IsNullOrEmpty(BeginToDate.Text.Trim()))
            {
                beginToTime = DateTime.Parse(BeginToDate.Text);
            }
            if (!String.IsNullOrEmpty(EndFromDate.Text.Trim()))
            {
                endFromTime = DateTime.Parse(EndFromDate.Text);
            }
            if (!String.IsNullOrEmpty(EndToDate.Text.Trim()))
            {
                endToTime = DateTime.Parse(EndToDate.Text);
            }
            if (FromMinNumberField.Number > 0)
            {
                minInterval = FromMinNumberField.Number / (24 * 60);
            }
            if (ToMinNumberField.Number > 0)
            {
                maxInterval = ToMinNumberField.Number / (24 * 60);
            }

            var otherEntity = new BOther();
            var records     = new List <BatStaticInfo>();

            foreach (var lu in lscUsers)
            {
                var temp = otherEntity.GetBatStatic(lu.LscID, lu.LscName, devId, devIndex, beginFromTime, beginToTime, endFromTime, endToTime, minInterval, maxInterval);
                if (temp != null && temp.Count > 0)
                {
                    var devices = otherEntity.GetDevices(lu.LscID, lu.Group.GroupID);
                    devices = devices.FindAll(d => {
                        return((area2Id == null || d.Area2ID == area2Id) &&
                               (area3Id == null || d.Area3ID == area3Id) &&
                               (staId == null || d.StaID == staId) &&
                               (devId == null || d.DevID == devId));
                    });

                    records.AddRange(
                        from tp in temp
                        join dev in devices on new { tp.LscID, tp.DevID } equals new { dev.LscID, dev.DevID }
                        select new BatStaticInfo {
                        LscID     = dev.LscID,
                        LscName   = dev.LscName,
                        Area1ID   = dev.Area1ID,
                        Area1Name = dev.Area1Name,
                        Area2ID   = dev.Area2ID,
                        Area2Name = dev.Area2Name,
                        Area3ID   = dev.Area3ID,
                        Area3Name = dev.Area3Name,
                        StaID     = dev.StaID,
                        StaName   = dev.StaName,
                        DevID     = dev.DevID,
                        DevName   = dev.DevName,
                        DevIndex  = tp.DevIndex,
                        StartTime = tp.StartTime,
                        EndTime   = tp.EndTime,
                        LastTime  = tp.LastTime
                    }
                        );
                }
            }

            var result = (from rec in records
                          group rec by new { rec.LscID, rec.DevID, rec.DevIndex } into tg
                          select new IDValuePair <BatStaticInfo, List <BatStaticInfo> > {
                ID = tg.FirstOrDefault(),
                Value = tg.ToList()
            }).ToList();

            int cacheDuration = Int32.Parse(WebConfigurationManager.AppSettings["DefaultCacheDuration"]);

            HttpRuntime.Cache.Insert(cacheKey, result, null, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(cacheDuration), CacheItemPriority.Default, null);
            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Add data to cache.
        /// </summary>
        private List <Report013Entity> AddDataToCache()
        {
            var userData = UserData;
            var cacheKey = WebUtility.GetCacheKeyName(userData, "kpi-report-013");

            HttpRuntime.Cache.Remove(cacheKey);

            var lscs = new List <LscUserInfo>();

            if (LscsComboBox.SelectedIndex > 0)
            {
                var ids = WebUtility.ItemSplit(LscsComboBox.SelectedItem.Value);
                if (ids.Length == 2)
                {
                    var lscId   = Int32.Parse(ids[0]);
                    var groupId = Int32.Parse(ids[1]);
                    var lscUser = userData.LscUsers.Find(lu => { return(lu.LscID == lscId); });
                    if (lscUser != null)
                    {
                        lscs.Add(lscUser);
                    }
                }
            }
            else
            {
                lscs.AddRange(userData.LscUsers);
            }
            if (lscs.Count == 0)
            {
                return(null);
            }

            var staTypes = new Dictionary <Int32, String>();

            foreach (var dt in StaTypeMultiCombo.SelectedItems)
            {
                staTypes[Int32.Parse(dt.Value)] = dt.Text;
            }
            if (staTypes.Count == 0)
            {
                return(null);
            }

            var fromTime = DateTime.Parse(BeginDate.Text);
            var toTime   = DateTime.Parse(EndDate.Text);

            var texts      = new List <String>();
            var auxSets    = new List <String>();
            var filterText = WebUtility.StringSplit(NodeText.Text.Trim());

            foreach (var ft in filterText)
            {
                if (String.IsNullOrEmpty(ft.Trim()))
                {
                    continue;
                }
                if (FilterTypeList.SelectedItem.Value.Equals("1"))
                {
                    auxSets.Add(ft.Trim());
                }
                else
                {
                    texts.Add(ft.Trim());
                }
            }

            var nodeEntity  = new BNode();
            var otherEntity = new BOther();
            var source1     = new List <Report013Entity>();

            foreach (var lsc in lscs)
            {
                var bats = otherEntity.GetBatStatic(lsc.LscID, lsc.LscName, null, null, fromTime, null, null, toTime, 0, Int32.MaxValue);
                var fdev = from bat in bats
                           group bat by bat.DevID into g
                           select new {
                    DevID    = g.Key,
                    Interval = g.Max(t => t.LastTime) * 24 * 60
                };

                var rdev = from fv in fdev
                           where fv.Interval >= 15
                           select fv.DevID;

                if (rdev.Any())
                {
                    var nodes  = nodeEntity.GetNodes(lsc.LscID, EnmNodeType.Aic, texts.ToArray(), auxSets.ToArray(), null);
                    var values = nodeEntity.GetMaxHisAIV(lsc.LscID, fromTime, toTime);
                    var ndWavl = from node in nodes
                                 join val in values on node.NodeID equals val.NodeID into tp
                                 from nv in tp.DefaultIfEmpty()
                                 select new {
                        Node  = node,
                        Value = nv != null ? nv.Value : 0
                    };

                    var ndWre = from na in ndWavl
                                join id in rdev on na.Node.DevID equals id
                                select na;

                    var staWall = from nr in ndWre
                                  group nr by nr.Node.StaID into g
                                  select new {
                        StaID = g.Key,
                        Value = g.Min(v => v.Value)
                    };

                    var staWhg = from sw in staWall
                                 where sw.Value >= 47
                                 select sw;

                    source1.Add(new Report013Entity {
                        LscID        = lsc.LscID,
                        LscName      = lsc.LscName,
                        CorrectCount = staWhg.Count(),
                        AllCount     = staWall.Count()
                    });
                }
                else
                {
                    source1.Add(new Report013Entity {
                        LscID        = lsc.LscID,
                        LscName      = lsc.LscName,
                        CorrectCount = 0,
                        AllCount     = 0
                    });
                }
            }

            if (source1.Count > 0)
            {
                source1.Add(new Report013Entity {
                    LscID        = -100,
                    LscName      = "汇总(平均值)",
                    CorrectCount = (Int32)source1.Average(r => r.CorrectCount),
                    AllCount     = (Int32)source1.Average(r => r.AllCount)
                });
            }

            int cacheDuration = Int32.Parse(WebConfigurationManager.AppSettings["DefaultCacheDuration"]);

            HttpRuntime.Cache.Insert(cacheKey, source1, null, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(cacheDuration), CacheItemPriority.Default, null);
            return(source1);
        }