Exemplo n.º 1
0
        /// <summary>
        /// 取得电站简要数据和单元列表
        /// </summary>
        /// <param name="pid"></param>
        /// <returns></returns>
        public ActionResult PlantUnits(int pid, string lan)
        {
            setlan(lan);

            string data;
            Plant  plant = PlantService.GetInstance().GetPlantInfoById(pid);

            if (plant == null)
            {
                AppError appError = new AppError(AppError.plantnoexist, Resources.SunResource.CHART_PLANT_DONT_EXISTED);
                data = JsonUtil.convertToJson(appError, typeof(AppError));
            }
            else
            {
                User         user        = UserService.GetInstance().Get((int)plant.userID);
                Plant2UnitVO userPlantVO = new Plant2UnitVO();
                userPlantVO.totalEnergy      = plant.upTotalEnergy;
                userPlantVO.todayEnergy      = plant.upTotalDayEnergy;
                userPlantVO.plantId          = plant.id;
                userPlantVO.name             = plant.name;
                userPlantVO.co2Reduction     = this.getCO2Rate() * plant.TotalEnergy;
                userPlantVO.revenue          = user.revenueRate * plant.TotalEnergy;
                userPlantVO.power            = plant.TodayTotalPower;
                userPlantVO.powerUnit        = "kW";
                userPlantVO.revenueUnit      = plant.currencies;
                userPlantVO.totalEnergyUnit  = plant.TotalEnergyUnit;
                userPlantVO.todayEnergyUnit  = plant.TotalDayEnergyUnit;
                userPlantVO.co2ReductionUnit = plant.ReductiongUnit;
                IList <int> workYears = CollectorYearDataService.GetInstance().GetWorkYears(new List <Plant>()
                {
                    plant
                });
                userPlantVO.errorcount = FaultService.GetInstance().getNewLogNums(new List <Plant>()
                {
                    plant
                }, workYears);
                userPlantVO.pic     = base.getCurWebContext() + "/ufile/small/" + plant.onePic;
                userPlantVO.city    = plant.city;
                userPlantVO.country = plant.country;
                userPlantVO.units   = convertToSUnitVOs(plant.plantUnits);
                data = JsonUtil.convertToJson(userPlantVO, typeof(Plant2UnitVO));
            }
            return(Content(data));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 将数据放入缓存
        /// </summary>
        /// <param name="tcpmessage"></param>
        public static void CacheData()
        {
            try
            {
                DateTime curdt = DateTime.Now;

                //将采集器天数据批量加入缓存
                CollectorDayDataService.GetInstance().batchToCache(BaseMessage.collectordayDataMap);
                LogUtil.writeline("memcached collectordayDataMap用时:" + (DateTime.Now.Subtract(curdt).TotalSeconds));
            }
            catch (Exception e)
            {
                LogUtil.error("batch Cache day data error:" + e.Message);
            }
            try
            {
                DateTime curdt = DateTime.Now;
                //DeviceDayDataService.GetInstance().batchToCache(BaseMessage.devicedayDataMapList);
                ////将设备天数据批量放入缓存
                DeviceDayDataCacheHandler ddch = null;
                for (int i = 0; i < 50; i++)
                {
                    if (cacheDayOjectMap.ContainsKey(i))
                    {
                        ddch = cacheDayOjectMap[i];
                    }
                    else
                    {
                        ddch = new DeviceDayDataCacheHandler(i);
                        cacheDayOjectMap[i] = ddch;
                    }

                    Thread m_thread = new Thread(new ThreadStart(ddch.batchToCacheList));
                    m_thread.Name = "memcache Handel Thread-" + i;
                    m_thread.Start();
                }
                int  times  = 0;
                bool iswork = isWork();
                //如果线程都在工作并且持续时间一分钟之内继续循环,否则跳出循环,进行以后动作,add by qhb in 20120927 for 解析其中有个现场死了,整个程序
                //就停在这里了。
                while (iswork && times < 60)
                {
                    times++;
                    iswork = isWork();
                    Thread.Sleep(1000);
                }
                LogUtil.writeline("memcached devicedayDataMap用时:" + (DateTime.Now.Subtract(curdt).TotalSeconds));
            }
            catch (Exception e)
            {
                LogUtil.error("batch Cache device day data  error:" + e.Message);
            }

            try
            {
                DateTime curdt = DateTime.Now;
                //缓存采集器实时数据
                CollectorRunDataService.GetInstance().batchCache(BaseMessage.collectorRunDataMap.Values);
                LogUtil.writeline("memcached collectorRunDataMap用时:" + (DateTime.Now.Subtract(curdt).TotalSeconds));
            }
            catch (Exception e)
            {
                LogUtil.error("batch Cache run data error:" + e.Message);
            }

            try
            {
                DateTime curdt = DateTime.Now;
                //批量保存设备实时数据到缓存
                DeviceRunDataService.GetInstance().BatchCache(BaseMessage.deviceRunDataMap.Values);
                LogUtil.writeline("memcached deviceRunDataMap用时:" + (DateTime.Now.Subtract(curdt).TotalSeconds));
            }
            catch (Exception e)
            {
                LogUtil.error("batch Cache device run data error:" + e.Message);
            }

            try
            {
                FaultService.GetInstance().batchSave(BaseMessage.faultList);
                BaseMessage.faultList.Clear();
            }
            catch (Exception e)
            {
                LogUtil.info("batch Cache fualt error:" + e.Message);
            }
            try
            {
                DateTime curdt = DateTime.Now;
                //将设备最大值统计数据放入缓存
                DeviceDataCountService.GetInstance().batchCache(BaseMessage.deviceDataCounts);
                BaseMessage.deviceDataCounts.Clear();
                LogUtil.writeline("memcached deviceDataCounts用时:" + (DateTime.Now.Subtract(curdt).TotalSeconds));
            }
            catch (Exception e)
            {
                LogUtil.error("save max value error:" + e.Message);
            }

            //将本地内存数据放入缓存后,就要清理本地内存,否有内存溢出问题
            //clearDayDataMap();

            //每次缓存后 同时将同步到memcahced
            if (syndata != null && syndata.Equals("true"))
            {
                SynDataService.GetInstance().synRunData();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 获取电站信息
        /// </summary>
        /// <param name="pid">电站id</param>
        /// <param name="app_key">第三方应用唯一key</param>
        /// <param name="call_id">请求序号</param>
        /// <param name="sig">签名</param>
        /// <param name="v">api版本</param>
        /// <param name="format">返回结果格式,暂时值支持json</param>
        /// <param name="lan">语言环境,暂时只支持中英文</param>
        /// <returns></returns>
        public ActionResult plantinfo(int pid, string app_key, string call_id, string sig, string v, string format, string lan)
        {
            setlan(lan);
            Plant   plant = PlantService.GetInstance().GetPlantInfoById(pid);
            PlantVO vo    = new PlantVO();

            if (plant != null)
            {
                vo.CQ2reduce     = plant.Reductiong.ToString();
                vo.CQ2reduceUnit = plant.ReductiongUnit;
                vo.curPower      = plant.TodayTotalPower.ToString();
                vo.curPowerUnit  = "kW";
                vo.dayEnergy     = plant.DisplayTotalDayEnergy;
                vo.dayEnergyUnit = plant.TotalDayEnergyUnit;
                IList <int> workYears = CollectorYearDataService.GetInstance().GetWorkYears(new List <Plant>()
                {
                    plant
                });
                vo.logCount = FaultService.GetInstance().getNewLogNums(new List <Plant>()
                {
                    plant
                }, workYears);
                vo.plantId            = pid;
                vo.plantName          = plant.name;
                vo.solarIntensity     = plant.Sunstrength.ToString();
                vo.solarIntensityUnit = MonitorType.getMonitorTypeByCode(MonitorType.PLANT_MONITORITEM_LINGT_CODE).unit;
                //add by qhb in 20120106 for 增加逆变器数量
                IList <Device> inverterDevices = plant.typeDevices(DeviceData.INVERTER_CODE);
                vo.inverterCount   = inverterDevices.Count.ToString();
                vo.inverterTypeStr = getMainType(inverterDevices, 3);
                string ts   = "";
                double t    = plant.Temperature;
                User   user = UserService.GetInstance().Get((int)plant.userID);
                if (t == 0)
                {
                    CityCodeService codeService = CityCodeService.GetInstance();
                    t = codeService.GetTemperature(plant.city);
                    if (!double.IsNaN(t))
                    {
                        ts = t.ToString("0.0");
                    }
                }
                else
                {
                    ts = t.ToString("0.0");
                }
                if (user != null && !user.TemperatureType.ToLower().Equals("c"))
                {
                    t  = (32 + (t * 1.8));
                    ts = t.ToString("0.0");
                }
                vo.temprature      = ts;
                vo.tempratureUnit  = user.TemperatureType.ToUpper();
                vo.totalEnergy     = plant.DisplayTotalEnergy;
                vo.totalEnergyUnit = plant.TotalEnergyUnit;
                vo.imageArray      = "http://" + Request.Url.Authority + "/ufile/" + (string.IsNullOrEmpty(plant.onePic) ? "Nopic/nopico02.gif" : plant.onePic);
                vo.DesignPower     = plant.design_power + " kWp";
                vo.Country         = plant.country;
                vo.City            = plant.city;
                vo.organize        = user.organize;
                vo.installDate     = plant.installdate.ToString("yyyy-MM-dd");
            }
            string data = JsonUtil.convertToJson(vo, typeof(PlantVO));

            return(Content(data));
        }
Exemplo n.º 4
0
        /// <summary>
        /// 取得用户的所有故障列表
        /// </summary>
        /// <param name="userId">用户id</param>
        /// <param name="pagecount">第几页</param>
        /// <param name="pagesize">每页显示数量</param>
        /// <param name="errortype">告警类型:all是所有,error:错误,warning:警告,fault:故障,inf:信息</param>
        /// <param name="errorby">排序字段</param>
        /// <returns></returns>
        public ActionResult ErrorList(int userId, string pagecount, string pagesize, string errortype, string errorby, string lan)
        {
            setlan(lan);
            User        user      = UserService.GetInstance().Get(userId);
            IList <int> years     = CollectorYearDataService.GetInstance().GetWorkYears(user.plants);
            int         manyear   = years.Count > 0 ? years[0] : DateTime.Now.Year;
            DateTime    startTime = Convert.ToDateTime(string.Format("{0}-{1}", manyear, "01-01"));
            DateTime    endTime   = DateTime.Now;
            int         psize     = 0;

            int.TryParse(pagesize, out psize);
            FaultService service = FaultService.GetInstance();

            string inforank = "";

            if (errortype.Equals("all"))
            {
                inforank = ErrorType.ERROR_TYPE_ERROR + "," + ErrorType.ERROR_TYPE_FAULT + "," + ErrorType.ERROR_TYPE_INFORMATRION + "," + ErrorType.ERROR_TYPE_WARN;
            }
            if (errortype.Equals("error"))
            {
                inforank = ErrorType.ERROR_TYPE_ERROR.ToString();
            }
            if (errortype.Equals("warning"))
            {
                inforank = ErrorType.ERROR_TYPE_WARN.ToString();
            }
            if (errortype.Equals("fault"))
            {
                inforank = ErrorType.ERROR_TYPE_FAULT.ToString();
            }
            if (errortype.Equals("info"))
            {
                inforank = ErrorType.ERROR_TYPE_INFORMATRION.ToString();
            }

            Hashtable table = new Hashtable();
            Pager     page  = new Pager()
            {
                PageIndex = int.Parse(pagecount), PageSize = psize
            };

            table.Add("page", page);
            table.Add("user", user);
            table.Add("startTime", startTime);
            table.Add("endTime", endTime);
            table.Add("items", inforank);
            table.Add("state", "0");

            service.GetAllLogs(table);
            IList <Fault> faultList = (IList <Fault>)table["source"];

            FaultVoResult faultResult = new FaultVoResult();

            faultResult.totalpagecount = page.PageCount;

            IList <FaultVO> faults  = new List <FaultVO>();
            FaultVO         faultVO = null;

            PlantUnit tmpunit;

            foreach (Fault fault in faultList)
            {
                faultVO = new FaultVO();
                //faultVO.deviceAddress = fault.address;
                faultVO.deviceAddress = fault.device.xinhaoName + "#" + fault.address; //临时方案,设备地址字段放设备设备型号名称+地址,这样不用修改app
                //faultVO.deviceModel =  fault.device.xinhaoName;
                faultVO.deviceModel = fault.device.typeName;;                          //临时方案,设备型号字段放设备类型,这样不用修改app
                //faultVO.deviceType = fault.device.typeName;
                tmpunit             = PlantUnitService.GetInstance().GetPlantUnitByCollectorId(fault.collectorID);
                faultVO.deviceType  = tmpunit.displayname;//临时方案,设备类型字段放单元名称,这样不用修改app
                faultVO.faultDesc   = fault.content;
                faultVO.faultId     = fault.id;
                faultVO.isConfirmed = fault.confirm ? "true" : "false";
                faultVO.datetime    = fault.sendTime.ToString("yyyy-MM-dd HH:mm:ss");
                faultVO.errorType   = getAppErrorType(fault.errorTypeCode);
                faults.Add(faultVO);
            }

            faultResult.faults = faults;
            string data = JsonUtil.convertToJson(faultResult, typeof(FaultVoResult));

            return(Content(data));
        }
Exemplo n.º 5
0
        /// <summary>
        /// 登录验证
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public ActionResult loginvalid(string username, string password, string lan)
        {
            //FileLogUtil.info("username:"******"Username don`t existed");
                //data = JsonUtil.convertToJson(appError, typeof(AppError));
            }
            if (user != null)
            {
                if (!user.depassword.Equals(password))
                {
                    AppError appError = new AppError(AppError.usernameOrpasswordError, "Username or password error");
                    data = JsonUtil.convertToJson(appError, typeof(AppError));
                }
                else
                {
                    MonitorType energyMt    = MonitorType.getMonitorTypeByCode(MonitorType.PLANT_MONITORITEM_ENERGY_CODE);
                    MonitorType powerMt     = MonitorType.getMonitorTypeByCode(MonitorType.PLANT_MONITORITEM_POWER_CODE);
                    UserPlantVO userPlantVO = new UserPlantVO();
                    userPlantVO.totalEnergy      = user.upTotalEnergy;
                    userPlantVO.totalEnergyUnit  = user.TotalEnergyUnit;
                    userPlantVO.todayEnergy      = user.upTotalDayEnergy;
                    userPlantVO.todayEnergyUnit  = user.TotalDayEnergyUnit;
                    userPlantVO.userId           = user.id;
                    userPlantVO.username         = user.username;
                    userPlantVO.co2Reduction     = user.TotalReductiong;
                    userPlantVO.co2ReductionUnit = user.TotalReductiongUnit;
                    userPlantVO.revenue          = Math.Round(user.revenue, 2);
                    userPlantVO.revenueUnit      = user.currencies;
                    userPlantVO.power            = user.upTotalPower;
                    userPlantVO.powerUnit        = user.TotalPowerUnit;
                    userPlantVO.families         = user.TotalFamilies.ToString();
                    IList <int> workYears = CollectorYearDataService.GetInstance().GetWorkYears(user.plants);
                    userPlantVO.warnNums = FaultService.GetInstance().getNewLogNums(user.plants, workYears);
                    userPlantVO.plants   = convertToSPlantVOs(user.plants);

                    data = JsonUtil.convertToJson(userPlantVO, typeof(UserPlantVO));
                }
            }
            else
            {
                AppError appError = new AppError(AppError.usernameOrpasswordError, "Username don`t existed");
                data = JsonUtil.convertToJson(appError, typeof(AppError));
            }
            return(Content(data));
        }
Exemplo n.º 6
0
        /// <summary>
        /// 将数据放入缓存
        /// </summary>
        /// <param name="tcpmessage"></param>
        public static void CacheData()
        {
            try
            {
                DateTime curdt = DateTime.Now;

                //将采集器天数据批量加入缓存
                CollectorDayDataService.GetInstance().batchToCache(BaseMessage.collectordayDataMap);
                LogUtil.writeline("memcached collectordayDataMap用时:" + (DateTime.Now.Subtract(curdt).TotalSeconds));
            }
            catch (Exception e)
            {
                LogUtil.error("batch Cache day data error:" + e.Message);
            }
            try
            {
                DateTime curdt = DateTime.Now;
                //DeviceDayDataService.GetInstance().batchToCache(BaseMessage.devicedayDataMapList);
                ////将设备天数据批量放入缓存
                DeviceDayDataCacheHandler ddch = null;
                for (int i = 0; i < 50; i++)
                {
                    if (cacheDayOjectMap.ContainsKey(i))
                    {
                        ddch = cacheDayOjectMap[i];
                    }
                    else
                    {
                        ddch = new DeviceDayDataCacheHandler(i);
                        cacheDayOjectMap[i] = ddch;
                    }

                    Thread m_thread = new Thread(new ThreadStart(ddch.batchToCacheList));
                    m_thread.Name = "memcache Handel Thread-" + i;
                    m_thread.Start();
                }
                while (isWork())
                {
                    Thread.Sleep(1000);
                }
                LogUtil.writeline("memcached devicedayDataMap用时:" + (DateTime.Now.Subtract(curdt).TotalSeconds));
            }
            catch (Exception e)
            {
                LogUtil.error("batch Cache device day data  error:" + e.Message);
            }

            try
            {
                DateTime curdt = DateTime.Now;
                //缓存采集器实时数据
                CollectorRunDataService.GetInstance().batchCache(BaseMessage.collectorRunDataMap.Values);
                LogUtil.writeline("memcached collectorRunDataMap用时:" + (DateTime.Now.Subtract(curdt).TotalSeconds));
            }
            catch (Exception e)
            {
                LogUtil.error("batch Cache run data error:" + e.Message);
            }

            try
            {
                DateTime curdt = DateTime.Now;
                //批量保存设备实时数据到缓存
                DeviceRunDataService.GetInstance().BatchCache(BaseMessage.deviceRunDataMap.Values);
                LogUtil.writeline("memcached deviceRunDataMap用时:" + (DateTime.Now.Subtract(curdt).TotalSeconds));
            }
            catch (Exception e)
            {
                LogUtil.error("batch Cache device run data error:" + e.Message);
            }

            try
            {
                FaultService.GetInstance().batchSave(BaseMessage.faultList);
                BaseMessage.faultList.Clear();
            }
            catch (Exception e)
            {
                LogUtil.info("batch Cache fualt error:" + e.Message);
            }
            try
            {
                DateTime curdt = DateTime.Now;
                //将设备最大值统计数据放入缓存
                DeviceDataCountService.GetInstance().batchCache(BaseMessage.deviceDataCounts);
                BaseMessage.deviceDataCounts.Clear();
                LogUtil.writeline("memcached deviceDataCounts用时:" + (DateTime.Now.Subtract(curdt).TotalSeconds));
            }
            catch (Exception e)
            {
                LogUtil.error("save max value error:" + e.Message);
            }

            clearDayDataMap();
        }