/// <summary>
        ///
        /// </summary>
        /// <param name="uid"></param>
        /// <returns></returns>
        public JsonResult Detail(Guid uid)
        {
            JsonResult result = new JsonResult();
            //获取账号访问设备uid的访问次数,不设置过期时间
            Func <List <VisitCount> > initvisit = () => { return(new List <VisitCount>()); };
            List <VisitCount>         vclist    = DBHelper.getWithNoExpire <List <VisitCount> >(initvisit, UserContext.account.Usr_UId + ConfigurationManager.AppSettings["VisitFlowMeterCount"]);
            //增加账号访问设备uid的访问次数
            Func <List <VisitCount> > visitcount = () => account_Service.AddDeviceVisits(vclist, uid);

            DBHelper.getAndFresh <VisitCount>(visitcount, UserContext.account.Usr_UId + ConfigurationManager.AppSettings["VisitFlowMeterCount"]);
            //获取并返回设备uid的区域状态数据

            AreaDevice_t ad = areadevice_Service.GetAreaDeviceByDeviceUid(uid);

            Func <List <FlowMeterStatusAndArea> > fmsFunc = () => flowmeter_Service.GetFlowMeterStatusByArea(ad.AD_AreaUid);

            result.Data = DBHelper.get <FlowMeterStatusAndArea>(fmsFunc,
                                                                ConfigurationManager.AppSettings["FlowMeterStatusByAreaUid"] + ad.AD_AreaUid).Where(p => p.flowmeter.FM_UId == uid).ToList();

            //Func<List<FlowMeterStatusAndArea>> fmAndStatusArea = () => (flowmeter_Service.GetFlowMeterStatusAndArea());
            //result.Data = DBHelper.get<FlowMeterStatusAndArea>(fmAndStatusArea, ConfigurationManager.AppSettings["allFlowMeterStatusAndArea"]).Where(p => p.flowmeter.FM_UId == uid).ToList();
            return(result);
        }
Ejemplo n.º 2
0
        public JsonResult GetFlowMeterByAreaUid(Guid areaUid)
        {
            JsonResult result = new JsonResult();

            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            List <FlowMeterStatusAndArea> fms_areas_order = new List <FlowMeterStatusAndArea>();
            List <FlowMeterStatusAndArea> fms_areas       = new List <FlowMeterStatusAndArea>();

            //获取areauid对应的设备信息,并以areauid区分存储在redis
            Func <List <FlowMeterStatusAndArea> > fmAndStatusArea     = () => flowmeterService.GetFlowMeterStatusByArea(areaUid);
            List <FlowMeterStatusAndArea>         fmstatusAndAreaList = DBHelper.get <FlowMeterStatusAndArea>(fmAndStatusArea,
                                                                                                              ConfigurationManager.AppSettings["FlowMeterStatusByAreaUid"] + areaUid);

            User_t account = UserContext.account;

            if (account.Usr_Type == 3)
            {
                fms_areas = fmstatusAndAreaList.Where(p => p.flowmeter.FM_WaterConsumerUId == account.Usr_UId).ToList();
            }
            else
            {
                //筛选出子区域范围内的所有流量计
                List <Area_t> subarealist = areaService.GetSubArea(areaUid);

                foreach (var areaitem in subarealist)
                {
                    Func <List <FlowMeterStatusAndArea> > fmsFunc = () => flowmeterService.GetFlowMeterStatusByArea(areaUid);
                    var fmslist = DBHelper.get <FlowMeterStatusAndArea>(fmsFunc,
                                                                        ConfigurationManager.AppSettings["FlowMeterStatusByAreaUid"] + areaitem.Ara_UId);
                    fms_areas.AddRange(fmslist);
                }
                //foreach (var item in fmstatusAndAreaList)
                //{
                //    if (subarealist.Where(p => p.Ara_UId == item.area.Ara_UId).Count() > 0)
                //    {
                //        fms_areas.Add(item);
                //    }
                //}
            }

            //获取设备访问次数,根据访问次数排序,再将剩余的设备整合
            Func <List <VisitCount> > initvisit = () => { return(new List <VisitCount>()); };
            List <VisitCount>         vclist    = DBHelper.getWithNoExpire <List <VisitCount> >(initvisit, UserContext.account.Usr_UId + ConfigurationManager.AppSettings["VisitFlowMeterCount"]);

            vclist = vclist.OrderByDescending(p => p.count).ToList();
            foreach (var item in vclist)
            {
                var data = fms_areas.Where(p => p.flowmeter.FM_UId == Guid.Parse(item.uid)).FirstOrDefault();
                if (data != null)
                {
                    fms_areas_order.Add(data);
                }
            }
            foreach (var item in fms_areas)
            {
                if (vclist.Where(p => p.uid == item.flowmeter.FM_UId.ToString()).Count() == 0)
                {
                    fms_areas_order.Add(item);
                }
            }

            string dataresult = ToJson <List <FlowMeterStatusAndArea> > .Obj2Json <List <FlowMeterStatusAndArea> >(fms_areas_order);

            dataresult = dataresult.Replace("\\\\", "");

            result.Data = dataresult;
            return(result);
        }