Esempio n. 1
0
 /// <summary>
 /// 功能:添加电站单元
 /// 描述:根据电站id和单元id添加
 /// 作者:张月
 /// 时间:2011年3月12日 12:07:53
 /// </summary>
 /// <param name="plantunit">电站单元实体</param>
 /// <returns>添加列</returns>
 public int AddPlantUnit(PlantUnit plantunit)
 {
     //先清理缓存,以便解析器能获取新的对应关系
     string cacheKey = CacheKeyUtil.buildPlantUnitKey();
     MemcachedClientSatat.getInstance().Delete(cacheKey);
     return _plantUnit.Insert(plantunit);
 }
Esempio n. 2
0
        PlantUnitService plantUnitService = PlantUnitService.GetInstance(); //电站单元服务

        #endregion Fields

        #region Methods

        /// <summary>
        /// 功能:跳转到添加页面
        /// </summary>
        /// <returns>添加页面</returns>
        public ActionResult Bind(int id, string name, string code)
        {
            if (TempData["error"] != null)
            {
                ModelState.AddModelError("Error", TempData["error"] as string);
            }
            PlantUnit plantUnit = new PlantUnit();
            plantUnit.displayname = name;
            plantUnit.collector = new Collector();
            plantUnit.collector.code = code;
            ViewData["unit"] = plantUnit;
            UserUtil.ResetLogin(UserUtil.getCurUser());
            return View(FindPlant(id));
        }
Esempio n. 3
0
        PlantUnitService plantUnitService = PlantUnitService.GetInstance(); //电站单元服务

        #endregion Fields

        #region Methods

        /// <summary>
        /// 功能:跳转到添加页面
        /// </summary>
        /// <returns>添加页面</returns>
        public ActionResult Bind(int id, string name, string code)
        {
            if (TempData["error"] != null)
            {
                ModelState.AddModelError("Error", TempData["error"] as string);
            }
            //绑定采集器的时候 同时将电站BindCollector 标示更改
            Plant plant = PlantService.GetInstance().GetPlantInfoById(id);
            if (!plant.BindCollector)
            {
                plant.BindCollector = true;
                PlantService.GetInstance().Save(plant);
            }

            PlantUnit plantUnit = new PlantUnit();
            plantUnit.displayname = name;
            plantUnit.collector = new Collector();
            plantUnit.collector.code = code;
            ViewData["unit"] = plantUnit;
            UserUtil.ResetLogin(UserUtil.getCurUser());
            return View(plant);
        }
 /// <summary>
 /// 取得单元跨月度数据报表
 /// </summary>
 /// <param name="has">unitid,startYear,endYear</param>
 /// <returns>年度数据列表</returns>
 public IList<CollectorYearMonthData> GetUnitBetweenYearData(PlantUnit unit, int startYear, int endYear)
 {
     return _plantYearDataDao.GetUnitBetweenYearData(unit, startYear, endYear);
 }
Esempio n. 5
0
        public ActionResult Save(int plantid, PlantUnit plantunit)
        {
            //根据采集器名称和密码判断该采集器设否存在
            Collector collector = collectorInfoService.GetClollectorByCodePass(plantunit.collector.code, plantunit.collector.password);
            if (collector != null && (collector.userId == 0 || collector.userId == UserUtil.getCurUser().id))
            {
                PlantUnit plantUnit = plantUnitService.GetPlantUnitByCollectorId(collector.id);//根据collectorID去查询,该采集器是否已经绑定了电站
                if (plantUnit == null)
                {
                    plantunit.collector.id = collector.id;
                    plantunit.collectorID = collector.id;
                    plantunit.collector = collector;
                    int plantUnitId = plantUnitService.AddPlantUnit(plantunit);//添加电站单元
                    collector.isUsed = true;//如果采集器已经和单元绑定了就为已用状态
                    collectorInfoService.Save(collector);
                    //绑定采集器要更新没有plantunitid的设备的plantunitid parenid
                    PlantUnit tmpPU = null;
                    foreach (Device device in collector.devices)
                    {
                        //判断原有属主是否存在,如果不存在,并且不是自己
                        if (device.plantUnitId != null && device.plantUnitId.Value > 0 && device.plantUnitId.Value != plantUnitId)
                        {
                            tmpPU = plantUnitService.GetPlantUnitById(device.plantUnitId.Value);//根据unitid去查询,判断是否存在
                            if (tmpPU != null)//已有属主并且属主不是当前单元则不纳入该单元
                                continue;
                        }
                        device.parentId = 0;
                        device.plantUnitId = plantUnitId;
                        if (device.deviceModel == null) device.deviceModel = new DeviceModel();
                        DeviceService.GetInstance().Save(device);
                    }

                    if (Request["fromurl"] == null || Request["fromurl"].Equals(""))
                        return RedirectToAction("list", "unit", new { @id = plantid });
                    else
                        return Redirect(Request["fromurl"]);
                }
                else
                {
                    collector.isUsed = true;//如果采集器已经和单元绑定了就为已用状态
                    collectorInfoService.Save(collector);
                    TempData["error"] = Resources.SunResource.PLANT_UNIT_BIND_COLLECTOR_BINDED;
                    return RedirectToAction("bind", "unit", new { @id = plantid, @name = plantunit.displayname, @code = plantunit.collector.code, @fromurl = Request["fromurl"] });
                }
            }
            else
            {
                TempData["error"] = Resources.SunResource.PLANT_UNIT_BIND_COLLECTOR_ERROR + "!";
                return RedirectToAction("bind", "unit", new { @id = plantid, @name = plantunit.displayname, @code = plantunit.collector.code, @fromurl = Request["fromurl"] });
            }
        }
Esempio n. 6
0
 public ActionResult Edit(int plantid, PlantUnit plantunit)
 {
     plantUnitService.EditPlantUnit(plantunit);//修改电站单元
     return RedirectToAction("list", "unit", new { @id = plantid });
 }
Esempio n. 7
0
 /// <summary>
 /// 功能:根据主键id修改电站单元
 /// 作者:张月
 /// 时间:2011年3月12日 13:29:21
 /// </summary> 
 /// <param name="plantSubPlant">电站单元实体对象</param>
 /// <returns>成功与否</returns>
 public int EditPlantUnit(PlantUnit plantUnit)
 {
     return _plantUnit.Update(plantUnit);
 }
Esempio n. 8
0
        /// <summary>
        /// 循环发送某个单元下面的设备
        /// </summary>
        /// <param name="pu"></param>
        private void handleUnitDevice(PlantUnit pu)
        {
            String plantName = "";//上上即电站名称
            Console.WriteLine("unitname" + pu.displayname);
            //if (!pu.displayname.ToLower().Equals("e01")) return;
            //包括隐藏的

            IList<Device> devices = null;
            if(send_hide.Equals("false")){
                devices = pu.displayDevices;
            }else{
                devices = pu.devices;
            }
            foreach (Device device in devices)
            {
                plantName = plantId;//接口约定好的
                //Plant plant = PlantService.GetInstance().GetPlantInfoById(pu.plantID);
                //if(plant!=null){
                //plantName = plant.name;
                //if(plant.parentPlant!=null){
                //plantName = plant.parentPlant.name;
                //}
                //}
                if (device != null && pu != null && device.runData != null)
                {
                    string deviceId = string.Format("{0}-{1}-{2}", pu.displayname, device.deviceTypeCode, StringUtil.getstr(device.deviceAddress, 3));

                    try
                    {
                        bool isSended = false;
                        //发送过的不再发送了
                        if (send_repeattime.Equals("false")) {
                            isSended = compareSendTime(deviceId, device.runData.updateTime);
                        }

                        if (!isSended)
                            handleDevice(device, pu, plantName);
                        else
                        {
                            Console.WriteLine("-----设备" + deviceId + "已经发送过,上次数据采集时间:" + device.runData.updateTime.ToString() + "-------------");
                            FileLogUtil.info("-----设备" + deviceId + "已经发送过,上次数据采集时间:" + device.runData.updateTime.ToString() + "-------------");
                        }
                    }
                    catch (Exception e)
                    {
                        FileLogUtil.info("-----设备" + deviceId + "处理失败" + e.Message + "-------------");
                        Console.WriteLine("-----设备" + deviceId + "处理失败" + e.Message + "-------------");
                    }
                }
            }
        }
Esempio n. 9
0
        /// <summary>
        /// 发送单个设备
        /// </summary>
        /// <param name="device"></param>
        private void handleDevice(Device device, PlantUnit pu, String plantName)
        {
            if (pu == null) return;
            //实时数据串“,”逗号分隔
            string realDataValueStr = "";
            if (device.runData != null)
            {//组织数据串
                switch (device.deviceTypeCode)
                {
                    case DeviceData.INVERTER_CODE:
                        realDataValueStr = getInverterRunDataStr(device, pu.collector);
                        break;
                    case DeviceData.HUILIUXIANG_CODE:
                        realDataValueStr = getHlxRunDataStr(device);
                        break;
                    case DeviceData.AMMETER_CODE:
                        realDataValueStr = getAmmeterRunDataStr(device);
                        break;
                    case DeviceData.ENVRIOMENTMONITOR_CODE:
                        realDataValueStr = getDetectorRunDataStr(device);
                        break;
                    default:
                        break;
                }
            }
            string DataCollectTime = device.runData == null ? "" : device.runData.updateTime.ToString("yyyy-MM-dd HH:mm:ss");
            try
            {
                callwebservice(server_url, plantName, pu.displayname, device.deviceAddress, device.deviceTypeCode, DataCollectTime, realDataValueStr);
            }
            catch (Exception e)
            {
                FileLogUtil.info("-----设备" + pu.displayname + "-" + device.deviceTypeCode + "-" + StringUtil.getstr(device.deviceAddress, 3) + "上传失败" + e.Message + "-------------");
                Console.WriteLine("-----设备" + pu.displayname + "-" + device.deviceTypeCode + "-" + StringUtil.getstr(device.deviceAddress, 3) + "上传失败" + e.Message + "-------------");

            }
        }
Esempio n. 10
0
        public ActionResult UnitSave(string unitid, int plantid, string code, string password, string displayname)
        {
            int uid = 0;
            int.TryParse(unitid, out uid);
            if (uid > 0)
            {
                PlantUnitService.GetInstance().EditPlantUnit(new PlantUnit { id = uid, displayname = displayname });//修改电站单元
                return Content(true.ToString());
            }
            PlantUnit unit = new PlantUnit();
            unit.plantID = plantid;
            unit.collector = new Collector() { code = code, password = password };
            unit.displayname = displayname;
            Collector collector = CollectorInfoService.GetInstance().GetClollectorByCodePass(code, password);
            if (collector != null && (collector.userId == 0 || collector.userId == UserUtil.getCurUser().id))
            {
                PlantUnit plantUnit = PlantUnitService.GetInstance().GetPlantUnitByCollectorId(collector.id);//根据collectorID去查询,该采集器是否已经绑定了电站
                if (plantUnit == null)
                {
                    unit.collector.id = collector.id;
                    unit.collectorID = collector.id;
                    unit.collector = collector;
                    PlantUnitService.GetInstance().AddPlantUnit(unit);//添加电站单元
                    collector.isUsed = true;//如果采集器已经和单元绑定了就为已用状态
                    CollectorInfoService.GetInstance().Save(collector);
                    return Content(true.ToString());
                }
                else
                {
                    collector.isUsed = true;//如果采集器已经和单元绑定了就为已用状态
                    CollectorInfoService.GetInstance().Save(collector);
                    return Content(Resources.SunResource.PLANT_UNIT_BIND_COLLECTOR_BINDED);
                }

            }
            else
            {
                return Content(Resources.SunResource.PLANT_UNIT_BIND_COLLECTOR_ERROR + "!");
            }
        }
Esempio n. 11
0
        public ActionResult Save(int plantid, PlantUnit plantunit)
        {
            //foreach (PlantUnit plantunit in plantunits)
            //{  //根据采集器名称和密码判断该采集器设否存在
            Collector collector = collectorInfoService.GetClollectorByCodePass(plantunit.collector.code, plantunit.collector.password);
            if (collector != null && (collector.userId == 0 || collector.userId == UserUtil.getCurUser().id))
            {
                PlantUnit plantUnit = plantUnitService.GetPlantUnitByCollectorId(collector.id);//根据collectorID去查询,该采集器是否已经绑定了电站
                if (plantUnit == null)
                {
                    plantunit.collector.id = collector.id;
                    plantunit.collectorID = collector.id;
                    plantunit.collector = collector;
                    plantUnitService.AddPlantUnit(plantunit);//添加电站单元
                    collector.isUsed = true;//如果采集器已经和单元绑定了就为已用状态
                    collectorInfoService.Save(collector);
                    if (Request["fromurl"] == null || Request["fromurl"].Equals(""))
                        return RedirectToAction("list", "unit", new { @id = plantid });
                    else
                        return Redirect(Request["fromurl"]);
                }
                else
                {
                    collector.isUsed = true;//如果采集器已经和单元绑定了就为已用状态
                    collectorInfoService.Save(collector);
                    TempData["error"] = Resources.SunResource.PLANT_UNIT_BIND_COLLECTOR_BINDED;
                    return RedirectToAction("bind", "unit", new { @id = plantid, @name = plantunit.displayname, @code = plantunit.collector.code, @fromurl = Request["fromurl"] });

                }

            }
            else
            {
                TempData["error"] = Resources.SunResource.PLANT_UNIT_BIND_COLLECTOR_ERROR + "!";
                return RedirectToAction("bind", "unit", new { @id = plantid, @name = plantunit.displayname, @code = plantunit.collector.code, @fromurl = Request["fromurl"] });
            }
            //}
        }