using System.IO; using Yw; namespace PBS.BLL { public class PackageCurveFileModel { public long PcakageID { get; set; } public string PackageName { get; set; } public List PumpInfos { get; set; } public static async void SaveCurveFile(long facilityId, long packageId) { if (packageId < 0) return; var model = new PackageCurveFileModel(); model.PcakageID = packageId; model.PumpInfos = new List(); var package = await new HStation.BLL.AssetsPackageMain().GetByID(packageId); if (package != null) { model.PackageName = package.Name; } var pumpList = await new HStation.BLL.AssetsPackagePumpMapping().GetByPackageID(packageId); foreach (var item in pumpList) { var allList = await BLLFactory.Instance .GetByObjectTypeAndObjectID(HStation.Assets.DataType.PumpMain, item.PumpMainID); var maxImportance = allList.OrderByDescending(x => x.Importance).FirstOrDefault(); var vmo = await BLLFactory.Instance.GetByID(maxImportance.DiagramID); model.PumpInfos.Add(new PumpInfo { PumpID = item.ID, PumpName = await GetPumpName(item.PumpMainID), phartDiagramExGraphListVmo = vmo }); } var json = Yw.JsonHelper.Object2Json(model); string rootDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Package_Curve"); if (!Directory.Exists(rootDirectory)) { Directory.CreateDirectory(rootDirectory); } string filePath = Path.Combine(rootDirectory, $"{facilityId}.json"); if (File.Exists(filePath)) { File.Delete(filePath); } File.WriteAllText(filePath, json); } public static async Task GetPumpName(long PumpID) { var model = await new HStation.BLL.AssetsPumpMain().GetByID(PumpID); if (model != null) { return model.Name; } return string.Empty; } public static void DeleteCurveFile(long facilityId) { string rootDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Package_Curve"); string filePath = Path.Combine(rootDirectory, $"{facilityId}.json"); if (!File.Exists(filePath)) { File.Delete(filePath); } } public static PackageCurveFileModel GetPumoInfoByFacId(long facilityId) { string rootDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Package_Curve"); string filePath = Path.Combine(rootDirectory, $"{facilityId}.json"); if (File.Exists(filePath)) { var json = File.ReadAllText(filePath); return JsonHelper.Json2Object(json); } return null; } } public class PumpInfo { public long PumpID { get; set; } public string PumpName { get; set; } public Yw.Vmo.PhartDiagramExGraphListVmo phartDiagramExGraphListVmo { get; set; } } }