using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using EntityDataSet; using IntelligentControlForsx.Model; using IntelligentControlForsx.Common; using log4net; namespace IntelligentControlForsx.Service { public class PointService { private static ILog logger = LogManager.GetLogger("AppInfoLog"); public static IList GetTestingPoints(PointType ptype, string[] uniformcodes) { IList ret = new List(); if (ptype == PointType.Windturbine) { var lstAI = GetWindTurbineAIPoints(uniformcodes); if (lstAI != null && lstAI.Count > 0) { foreach (var obj in lstAI) { PointMapModel pmm = new PointMapModel(); pmm.ThingId = CommonMethod.GetShortWindturbineId( obj.WINDTURBINEID); pmm.ThingType = PointType.Windturbine; pmm.DataType = PointDataType.AI; pmm.UniformCode = obj.UNIFORMCODE; pmm.PointId = obj.ID; if (!ret.Contains(pmm)) ret.Add(pmm); else logger.Info(pmm.PointId); } } var lstDI = GetWindTurbineDIPoints(uniformcodes); if (lstDI != null && lstDI.Count > 0) { foreach (var obj in lstDI) { PointMapModel pmm = new PointMapModel(); pmm.ThingId = CommonMethod.GetShortWindturbineId( obj.WINDTURBINEID); pmm.ThingType = PointType.Windturbine; pmm.DataType = PointDataType.DI; pmm.UniformCode = obj.UNIFORMCODE; pmm.PointId = obj.ID; if (!ret.Contains(pmm)) ret.Add(pmm); else logger.Info(pmm.PointId); } } } else if (ptype == PointType.Station) { var lstP = GetStationTestingPoints(uniformcodes); if (lstP != null && lstP.Count > 0) { foreach (var obj in lstP) { PointMapModel pmm = new PointMapModel(); pmm.ThingId = obj.WINDPOWERSTATIONID; pmm.ThingType = PointType.Station; pmm.DataType = PointDataType.AI; pmm.UniformCode = obj.UNIFORMCODE; pmm.PointId = obj.CODE; if (!ret.Contains(pmm)) ret.Add(pmm); } } } else { } return ret; } public static IList GetWindTurbineAIPoints(string[] filters) { using (wisdom_cs_entity ctx = new wisdom_cs_entity()) { return ctx.windturbinetestingpointai .Where(q => filters.Contains(q.UNIFORMCODE)) //.Select(q => q.Id) .ToList(); } } public static IList GetWindTurbineDIPoints(string[] filters) { using (wisdom_cs_entity ctx = new wisdom_cs_entity()) { return ctx.windturbinetestingpointdi .Where(q => filters.Contains(q.UNIFORMCODE)) //.Select(q => q.Id) .ToList(); } } public static IList GetWindTurbineAIPoints(string uniformCode) { using (wisdom_cs_entity ctx = new wisdom_cs_entity()) { return ctx.windturbinetestingpointai .Where(q => q.UNIFORMCODE == uniformCode) .ToList(); } } public static IList GetStationTestingPointsByUniformCode(string uniformcode) { using (wisdom_cs_entity ctx = new wisdom_cs_entity()) { return ctx.windpowerstationtestingpoint.Where(a => a.UNIFORMCODE == uniformcode && a.WINDPOWERSTATIONID.EndsWith("_FDC")).ToList(); } } public static string GetStationTestingPointByUniformCode(string stationId, string uniformcode) { using (wisdom_cs_entity ctx = new wisdom_cs_entity()) { return ctx.windpowerstationtestingpoint.Where(a => a.UNIFORMCODE == uniformcode && a.WINDPOWERSTATIONID == stationId).ToList().First().CODE; } } public static IList GetStationTestingPoints(string[] uniformcodes) { if (uniformcodes == null) return null; if (uniformcodes.Length == 1) return GetStationTestingPointsByUniformCode(uniformcodes[0]); using (wisdom_cs_entity ctx = new wisdom_cs_entity()) { //return ctx.windpowerstationtestingpoint.Where(a => uniformcodes.Contains(a.UNIFORMCODE) && a.WINDPOWERSTATIONID.EndsWith("_FDC")).ToList(); return ctx.windpowerstationtestingpoint.Where(a => uniformcodes.Contains(a.UNIFORMCODE)).ToList(); } } } }