Shuxia Ning
2025-01-15 9eb94e9eec2e2e164698e34d0481d66093c8655b
WinFrmUI/HStation.WinFrmUI.Xhs.Core/02-project/01-import/00-core/ImportXhsProjectHelper.cs
@@ -1,10 +1,4 @@
using Castle.Core.Internal;
using DevExpress.XtraEditors;
using HStation.Model;
using HStation.Vmo;
using Microsoft.Extensions.DependencyInjection;
using static DevExpress.XtraEditors.XtraInputBox;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
namespace HStation.WinFrmUI
{
@@ -43,87 +37,85 @@
            feedBackProgress?.Invoke(100, 5);
            #endregion
            #endregion 第一步 临时文件处理(进度5%)
            #region 第二步 创建项目(进度 10%)
            //尚未创建项目
            //判断项目数据合法性
            if (vm.Project == null)
            {
                feedBackMsg?.Invoke("项目数据初始化错误!!!", Color.Red);
                return false;
            }
            if (vm.Project.ID < 1)
            {
                feedBackMsg?.Invoke("正在创建项目...", Color.Black);
                var project = new Vmo.XhsProjectExtensionsVmo();
                project.NO = vm.NO;
                project.Name = vm.Name;
                project.Address = vm.Address;
                project.Customer = vm.Customer;
                project.Flags = vm.Flags;
                project.TagName = vm.TagName;
                project.Description = vm.Description;
                project.SiteList = new List<XhsProjectSiteVmo>()
                {
                        new XhsProjectSiteVmo()
                         {
                                Name=vm.Name,
                                Description=vm.Description
                         }
                };
                var projectId = await BLLFactory<HStation.BLL.XhsProjectExtensions>.Instance.Insert(project);
                if (projectId < 1)
                vm.Project.ID = await BLLFactory<HStation.BLL.XhsProjectExtensions>.Instance.Insert(vm.Project);
                if (vm.Project.ID < 1)
                {
                    feedBackMsg?.Invoke("项目创建失败!!!", Color.Red);
                    return false;
                }
                vm.ProjectID = projectId;
                vm.Project = await BLLFactory<HStation.BLL.XhsProjectExtensions>.Instance.GetByID(projectId);
                vm.ProjectSiteID = vm.Project.SiteList.FirstOrDefault().ID;
                vm.Project = await BLLFactory<HStation.BLL.XhsProjectExtensions>.Instance.GetByID(vm.Project.ID);
                feedBackMsg?.Invoke("项目创建成功。。。", Color.Green);
            }
            else
            {
                feedBackMsg?.Invoke("正在更新项目...", Color.Black);
                if (!await BLLFactory<HStation.BLL.XhsProjectExtensions>.Instance.Update(vm.Project))
                {
                    feedBackMsg?.Invoke("项目更新失败!!!", Color.Red);
                    return false;
                }
                vm.Project = await BLLFactory<HStation.BLL.XhsProjectExtensions>.Instance.GetByID(vm.Project.ID);
                feedBackMsg?.Invoke("项目更新成功。。。", Color.Green);
            }
            feedBackProgress?.Invoke(100, 10);
            #endregion
            #endregion 第二步 创建项目(进度 10%)
            #region 第三步 设置地图位置(进度 20%)
            if (vm.MapInfo == null)
            //已有地图信息才需要进行设置
            if (vm.MapInfo != null)
            {
                feedBackMsg?.Invoke("正在设置地图位置...", Color.Black);
                if (vm.Location != null)
                feedBackMsg?.Invoke("正在设置位置信息...", Color.Black);
                vm.MapInfo.ObjectID = vm.Project.ID;
                vm.MapInfo.ObjectName = vm.Project.Name;
                if (vm.MapInfo.ID < 1)
                {
                    var mapInfo = new Yw.Vmo.MapInfoVmo();
                    mapInfo.ObjectType = HStation.Xhs.DataType.XhsProject;
                    mapInfo.ObjectID = vm.ProjectID.Value;
                    mapInfo.ObjectName = vm.Project.Name;
                    mapInfo.Purpose = Yw.Map.Purpose.Location;
                    mapInfo.Kind = Yw.Map.Kind.Gaodei;
                    mapInfo.Shape = Yw.Map.Shape.Marker;
                    mapInfo.Position = vm.Location.ToJson();
                    var mapInfoId = await BLLFactory<Yw.BLL.MapInfo>.Instance.Insert(mapInfo);
                    if (mapInfoId < 1)
                    vm.MapInfo.ID = await BLLFactory<Yw.BLL.MapInfo>.Instance.Insert(vm.MapInfo);
                    if (vm.MapInfo.ID < 1)
                    {
                        feedBackMsg?.Invoke("设置地图位置失败!!!", Color.Red);
                        feedBackMsg?.Invoke("位置信息设置失败!!!", Color.Red);
                    }
                    else
                    {
                        vm.MapInfoID = mapInfoId;
                        vm.MapInfo = await BLLFactory<Yw.BLL.MapInfo>.Instance.GetByID(mapInfoId);
                        feedBackMsg?.Invoke("设置地图位置成功。。。", Color.Green);
                        feedBackMsg?.Invoke("位置信息设置成功。。。", Color.Green);
                    }
                }
                else
                {
                    feedBackMsg?.Invoke("未设置地图位置信息!!!", Color.Red);
                    if (!await BLLFactory<Yw.BLL.MapInfo>.Instance.Update(vm.MapInfo))
                    {
                        feedBackMsg?.Invoke("位置信息设置失败!!!", Color.Red);
                    }
                    else
                    {
                        feedBackMsg?.Invoke("位置信息设置成功。。。", Color.Green);
                    }
                }
            }
            else
            {
                feedBackMsg?.Invoke("未设置位置信息!!!", Color.Red);
            }
            feedBackProgress?.Invoke(100, 20);
            #endregion
            #endregion 第三步 设置地图位置(进度 20%)
            #region 第四步 压缩文件解析 (进度30%)
@@ -138,8 +130,7 @@
                    feedBackMsg?.Invoke("模型文件下载完成!!!", Color.Green);
                }
            }
            msg = "正在解析模型文件...";
            feedBackMsg?.Invoke(msg, Color.Black);
            feedBackMsg?.Invoke("正在解析模型文件...", Color.Black);
            var bol = Yw.FileFolderZipHelper.UnZip(localZipFile, tempFolder, zipFilePwd);
            if (!bol)
            {
@@ -163,7 +154,7 @@
            feedBackProgress?.Invoke(100, 30);
            #endregion
            #endregion 第四步 压缩文件解析 (进度30%)
            #region 第五步 解析水力结构文件 (进度40%)
@@ -177,9 +168,8 @@
                return true;
            }
            var structOthersFileInfo = allFileInfoList.Find(x => x.Name == HStation.Revit.ConstParas.StructOthersFileName);
            var structRevitModel = HStation.Service.RevitParseHelper.FromJsonFile
                (structFileInfo.FullName, structOthersFileInfo?.FullName, out bool structFileResult, out List<string> structFileMsgList);
            vm.RevitModel = structRevitModel;
            vm.RevitModel = HStation.Service.RevitParseHelper.FromJsonFile
               (structFileInfo.FullName, structOthersFileInfo?.FullName, out bool structFileResult, out List<string> structFileMsgList);
            //解析结果判断
            if (!structFileResult)
            {
@@ -187,9 +177,9 @@
            }
            //Revit属性错误处理
            var hasRevitPropError = false;
            if (structRevitModel != null)
            if (vm.RevitModel != null)
            {
                var allRevitParterList = structRevitModel.GetAllParters();
                var allRevitParterList = vm.RevitModel.GetAllParters();
                foreach (var revitParter in allRevitParterList)
                {
                    if (revitParter.PropStatusList != null && revitParter.PropStatusList.Count > 0)
@@ -207,6 +197,7 @@
                                        feedBackMsg?.Invoke($"构件类型:{revitParter.Catalog},构件编码:{revitParter.Id},构件属性:{revitParterPropStatus.PropName},错误:{revitParterPropStatus.StatusInfo} ", Color.Red);
                                    }
                                    break;
                                default: break;
                            }
                        }
@@ -221,8 +212,15 @@
                return true;
            }
            var hydroInfo = HStation.Hydro.TransferHelper.FromRevit(structRevitModel, out msg);
            if (hydroInfo == null)
            vm.HydroInfo = HStation.Hydro.TransferHelper.FromRevit
                (
                    vm.RevitModel,
                    out List<Yw.Model.HydroParterPropStatusInfo> allPropStatusDbList,
                    out List<Yw.Model.HydroParterScenePropValueInfo> allScenePropValueList,
                    out List<Yw.Model.HydroDecoratorInfo> allDecoratorList,
                    out msg
                );
            if (vm.HydroInfo == null)
            {
                feedBackMsg?.Invoke($"水力结构文件解析失败,{msg}!!!", Color.Red);
                feedBackMsg?.Invoke("项目导入结束。。。", Color.Blue);
@@ -230,11 +228,13 @@
                return true;
            }
            var propStatusHelper = new HydroPropStatusHelper(vm.HydroInfo, allPropStatusDbList);
            feedBackMsg?.Invoke("正在进行产品匹配...", Color.Black);
            var matchingParas = Yw.WinFrmUI.HydroMatchingHelper.Create(hydroInfo);
            var matchingParas = Yw.WinFrmUI.HydroMatchingHelper.Create(vm.HydroInfo);
            if (AssetsMatchingHelper.Matching(matchingParas, out string error))
            {
                if (Yw.WinFrmUI.HydroMatchingHelper.Apply(hydroInfo, matchingParas))
                if (Yw.WinFrmUI.HydroMatchingHelper.Apply(vm.HydroInfo, matchingParas))
                {
                    feedBackMsg?.Invoke("产品匹配完成。。。", Color.Green);
                }
@@ -248,18 +248,8 @@
                feedBackMsg?.Invoke("产品匹配失败!!!", Color.Red);
            }
            feedBackMsg?.Invoke("正在进行管网修复...", Color.Black);
            if (hydroInfo.RepairLinksDirection(out msg))
            {
                feedBackMsg?.Invoke(msg, Color.Green);
            }
            else
            {
                feedBackMsg?.Invoke(msg, Color.Red);
            }
            feedBackMsg?.Invoke("正在进行管网参数修复...", Color.Black);
            hydroInfo.RepairParas(out msg);
            vm.HydroInfo.RepairParas(propStatusHelper, out msg);
            if (string.IsNullOrEmpty(msg))
            {
                feedBackMsg?.Invoke("管网参数修复完成。。。", Color.Green);
@@ -270,8 +260,8 @@
            }
            feedBackMsg?.Invoke("正在保存水力结构信息...", Color.Black);
            var hydroId = await BLLFactory<Yw.BLL.HydroModelInfo>.Instance.Save(hydroInfo);
            if (hydroId < 1)
            vm.HydroInfo.ID = await BLLFactory<Yw.BLL.HydroModelInfo>.Instance.Save(vm.HydroInfo);
            if (vm.HydroInfo.ID < 1)
            {
                feedBackMsg?.Invoke("水力结构信息保存失败!!!", Color.Red);
                feedBackMsg?.Invoke("项目导入结束。。。", Color.Blue);
@@ -282,36 +272,54 @@
            feedBackMsg?.Invoke("水力结构文件解析成功。。。", Color.Green);
            feedBackProgress?.Invoke(100, 40);
            vm.HydroID = hydroId;
            vm.HydroInfo = await BLLFactory<Yw.BLL.HydroModelInfo>.Instance.GetByID(vm.HydroInfo.ID);
            #endregion
            //属性状态
            if (allPropStatusDbList != null && allPropStatusDbList.Count > 0)
            {
                await BLLFactory<Yw.BLL.HydroParterPropStatusInfo>.Instance.Save(vm.HydroInfo.ID, allPropStatusDbList);
            }
            //场景属性
            if (allScenePropValueList != null && allScenePropValueList.Count > 0)
            {
                await BLLFactory<Yw.BLL.HydroParterScenePropValueInfo>.Instance.Save(vm.HydroInfo.ID, HStation.Revit.ConstParas.Scene, allScenePropValueList);
            }
            //装饰件
            if (allDecoratorList != null && allDecoratorList.Count > 0)
            {
                await BLLFactory<Yw.BLL.HydroDecoratorInfo>.Instance.Save(vm.HydroInfo.ID, HStation.Revit.ConstParas.Scene, allDecoratorList);
            }
            #endregion 第五步 解析水力结构文件 (进度40%)
            #region 第六步 关联水力结构模型(进度 50%)
            feedBackMsg?.Invoke("正在关联水力结构模型...", Color.Black);
            var hydroRelation = new Yw.Vmo.HydroModelRelationVmo();
            hydroRelation.ObjectType = HStation.Xhs.DataType.XhsProjectSite;
            hydroRelation.ObjectID = vm.ProjectSiteID.Value;
            hydroRelation.ModelID = vm.HydroID.Value;
            hydroRelation.Purpose = HStation.Xhs.Purpose.Simulation;
            hydroRelation.Content = null;
            hydroRelation.Description = null;
            vm.HydroRelation = new Yw.Vmo.HydroModelRelationVmo();
            vm.HydroRelation.ObjectType = HStation.Xhs.DataType.XhsProjectSite;
            vm.HydroRelation.ObjectID = vm.Project.SiteList.First().ID;
            vm.HydroRelation.ModelID = vm.HydroInfo.ID;
            vm.HydroRelation.Purpose = Yw.Hydro.Purpose.Simulation;
            vm.HydroRelation.Content = null;
            vm.HydroRelation.Description = "导入自动生成";
            var hydroRelationId = await BLLFactory<Yw.BLL.HydroModelRelation>.Instance.Insert(hydroRelation);
            if (hydroRelationId < 1)
            vm.HydroRelation.ID = await BLLFactory<Yw.BLL.HydroModelRelation>.Instance.Insert(vm.HydroRelation);
            if (vm.HydroRelation.ID < 1)
            {
                feedBackMsg?.Invoke("关联水力结构模型失败!!!", Color.Red);
                feedBackMsg?.Invoke("项目导入结束。。。", Color.Blue);
                feedBackProgress?.Invoke(100, 100);
                return true;
            }
            vm.HydroRelation = await BLLFactory<Yw.BLL.HydroModelRelation>.Instance.GetByID(vm.HydroRelation.ID);
            vm.HydroRelationID = hydroRelationId;
            feedBackMsg?.Invoke("关联水力结构模型成功。。。", Color.Green);
            feedBackProgress?.Invoke(100, 50);
            #endregion
            #endregion 第六步 关联水力结构模型(进度 50%)
            #region 第七步 上传Revit模型文件(进度 60%)
@@ -325,17 +333,8 @@
                return true;
            }
            //var bimfaceId = await Yw.WinFrmUI.BimfaceHelper.UploadFile(rvtFileInfo.FullName);//上传
            long bimfaceId = 0;
            if (hydroInfo.Pumps.Count > 6)
            {
                bimfaceId = 10000894297457;
            }
            else
            {
                bimfaceId = 10000884893369;
            }
            //var bimfaceId = 10000894297457; //测试用例  10000884893369  10000894297457
            //var bimfaceId = await Yw.WinFrmUI.BimfaceHelper.UploadFile(rvtFileInfo.FullName);//正式代码
            var bimfaceId = 10000899666805;//测试用例  10000884893369  10000894297457  10000895957527  10000896316958 10000896755736
            if (bimfaceId < 1)
            {
                feedBackMsg?.Invoke("Revit模型文件上传失败!!!", Color.Red);
@@ -344,83 +343,90 @@
                return true;
            }
            vm.BimfaceId = bimfaceId;
            feedBackMsg?.Invoke("解析Revit模型文件成功。。。", Color.Green);
            feedBackProgress?.Invoke(100, 60);
            #endregion
            #endregion 第七步 上传Revit模型文件(进度 60%)
            #region 第八步 保存Bimface文件 (进度 65%)
            feedBackMsg?.Invoke("正在保存Bimface文件...", Color.Black);
            var bimfaceFile = new Yw.Vmo.BimfaceFileVmo();
            bimfaceFile.BimfaceId = bimfaceId.ToString();
            bimfaceFile.Name = vm.Name;
            bimfaceFile.ModelType = (int)Yw.Bimface.eModelType.File;
            bimfaceFile.FileStatus = (int)Yw.Bimface.eFileStatus.UploadSucceed;
            bimfaceFile.FormatType = (int)Yw.Bimface.eFormatType._3D;
            bimfaceFile.FileSuffix = rvtFileInfo.Extension;
            bimfaceFile.FileSize = string.Format("{0}MB", System.Math.Ceiling(rvtFileInfo.Length / 1024.0 / 1024.0));
            vm.BimfaceFile = new Yw.Vmo.BimfaceFileVmo();
            vm.BimfaceFile.BimfaceId = bimfaceId.ToString();
            vm.BimfaceFile.Name = vm.Project.Name;
            vm.BimfaceFile.ModelType = (int)Yw.Bimface.eModelType.File;
            vm.BimfaceFile.FileStatus = (int)Yw.Bimface.eFileStatus.UploadSucceed;
            vm.BimfaceFile.FormatType = (int)Yw.Bimface.eFormatType._3D;
            vm.BimfaceFile.FileSuffix = rvtFileInfo.Extension;
            vm.BimfaceFile.FileSize = string.Format("{0}MB", System.Math.Ceiling(rvtFileInfo.Length / 1024.0 / 1024.0));
            var bimfaceFileId = await BLLFactory<Yw.BLL.BimfaceFile>.Instance.Insert(bimfaceFile);
            if (bimfaceFileId < 1)
            vm.BimfaceFile.ID = await BLLFactory<Yw.BLL.BimfaceFile>.Instance.Insert(vm.BimfaceFile);
            if (vm.BimfaceFile.ID < 1)
            {
                feedBackMsg?.Invoke("Bimface文件保存失败!!!", Color.Red);
                feedBackMsg?.Invoke("项目导入结束。。。", Color.Blue);
                feedBackProgress?.Invoke(100, 100);
                return true;
            }
            vm.BimfaceFileID = bimfaceFileId;
            vm.BimfaceFile = await BLLFactory<Yw.BLL.BimfaceFile>.Instance.GetByID(vm.BimfaceFile.ID);
            feedBackMsg?.Invoke("Bimface文件保存成功。。。", Color.Green);
            feedBackProgress?.Invoke(100, 65);
            #endregion
            #endregion 第八步 保存Bimface文件 (进度 65%)
            #region 第九步 关联Bimface文件(进度 70%)
            feedBackMsg?.Invoke("正在关联Bimface文件...", Color.Black);
            var bimfaceRelation = new Yw.Vmo.BimfaceFileRelationVmo();
            bimfaceRelation.ObjectType = HStation.Xhs.DataType.XhsProjectSite;
            bimfaceRelation.ObjectID = vm.ProjectSiteID.Value;
            bimfaceRelation.BimfaceFileID = bimfaceFileId;
            bimfaceRelation.Purpose = HStation.Xhs.Purpose.Simulation;
            bimfaceRelation.Description = vm.Description;
            vm.BimfaceRelation = new Yw.Vmo.BimfaceFileRelationVmo();
            vm.BimfaceRelation.ObjectType = HStation.Xhs.DataType.XhsProjectSite;
            vm.BimfaceRelation.ObjectID = vm.Project.SiteList.First().ID;
            vm.BimfaceRelation.BimfaceFileID = vm.BimfaceFile.ID;
            vm.BimfaceRelation.Purpose = Yw.Bimface.Purpose.Simulation;
            vm.BimfaceRelation.Description = "导入自动生成";
            var bimfaceRelationId = await BLLFactory<Yw.BLL.BimfaceFileRelation>.Instance.Insert(bimfaceRelation);
            if (bimfaceRelationId < 1)
            vm.BimfaceRelation.ID = await BLLFactory<Yw.BLL.BimfaceFileRelation>.Instance.Insert(vm.BimfaceRelation);
            if (vm.BimfaceRelation.ID < 1)
            {
                feedBackMsg?.Invoke("Bimface文件关联失败!!!", Color.Red);
                feedBackMsg?.Invoke("项目导入结束。。。", Color.Blue);
                feedBackProgress?.Invoke(100, 100);
                return true;
            }
            vm.BimfaceFileRelationID = bimfaceRelationId;
            vm.BimfaceRelation = await BLLFactory<Yw.BLL.BimfaceFileRelation>.Instance.GetByID(vm.BimfaceRelation.ID);
            feedBackMsg?.Invoke("Bimface文件关联成功。。。", Color.Green);
            feedBackProgress?.Invoke(100, 70);
            #endregion
            #endregion 第九步 关联Bimface文件(进度 70%)
            #region 第十步 发起bimface转换(进度 90%)
            #region 第十步 发起模型转换(进度 90%)
            feedBackMsg?.Invoke("正在进行Bimface模型轻量化...", Color.Black);
            feedBackProgress?.Invoke(100, 60);
            feedBackMsg?.Invoke("正在进行模型轻量化...", Color.Black);
            //var bimfaceTranslateStatus = await Yw.WinFrmUI.BimfaceHelper.TranslateRvtFile(bimfaceId);//发起转换
            var bimfaceTranslateStatus = Yw.BIMFace.eTranslateStatus.Processing;//测试代码
            feedBackProgress?.Invoke(100, 60);
            if (bimfaceTranslateStatus != Yw.BIMFace.eTranslateStatus.Success)
            {
                var dlgResult = XtraMessageBox.Show("Bimface模型轻量化需要一定的时间,是否继续等待?", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dlgResult == DialogResult.Yes)
                {
                    await Yw.WinFrmUI.BimfaceHelper.WaitFileTranslateStatusUntilSuccess(bimfaceId, 3000);
                    vm.BimfaceConverted = true;
                    feedBackMsg?.Invoke("Bimface模型轻量化完成。。。", Color.Green);
                    feedBackMsg?.Invoke("模型轻量化完成。。。", Color.Green);
                }
                else
                {
                    feedBackMsg?.Invoke("跳过Bimface模型轻量化等待。。。", Color.Black);
                    bol = await BLLFactory<Yw.BLL.BimfaceFile>.Instance.UpdateFileStatus(vm.BimfaceFile.ID, (int)Yw.Bimface.eFileStatus.Converting);
                    if (bol)
                    {
                        vm.BimfaceFile.FileStatus = (int)Yw.Bimface.eFileStatus.Converting;
                    }
                    else
                    {
                        feedBackMsg?.Invoke("模型文件状态更新失败!!!", Color.Red);
                    }
                    feedBackMsg?.Invoke("跳过模型轻量化等待。。。", Color.Black);
                    feedBackMsg?.Invoke("项目导入结束。。。", Color.Blue);
                    feedBackProgress?.Invoke(100, 100);
                    return true;
@@ -428,26 +434,26 @@
            }
            else
            {
                vm.BimfaceConverted = true;
                feedBackMsg?.Invoke("Bimface模型轻量化完成。。。", Color.Green);
                feedBackMsg?.Invoke("模型轻量化完成。。。", Color.Green);
            }
            feedBackProgress?.Invoke(100, 90);
            #endregion
            #endregion 第十步 发起模型转换(进度 90%)
            #region 第十一步 更新Bimface文件状态(进度 100%)
            #region 第十一步 更新模型文件状态(进度 100%)
            feedBackMsg?.Invoke("正在更新Bimface文件状态...", Color.Black);
            bol = await BLLFactory<Yw.BLL.BimfaceFile>.Instance.UpdateFileStatus(bimfaceFileId, (int)Yw.Bimface.eFileStatus.ConvertSucceed);
            feedBackMsg?.Invoke("正在更新模型文件状态...", Color.Black);
            bol = await BLLFactory<Yw.BLL.BimfaceFile>.Instance.UpdateFileStatus(vm.BimfaceFile.ID, (int)Yw.Bimface.eFileStatus.ConvertSucceed);
            if (bol)
            {
                feedBackMsg?.Invoke("Bimface文件状态更新成功。。。", Color.Green);
                vm.BimfaceFile.FileStatus = (int)Yw.Bimface.eFileStatus.ConvertSucceed;
                feedBackMsg?.Invoke("模型文件状态更新成功。。。", Color.Green);
            }
            else
            {
                feedBackMsg?.Invoke("Bimface文件状态更新失败!!!", Color.Red);
                feedBackMsg?.Invoke("项目导入结束。。。", Color.Black);
                feedBackMsg?.Invoke("模型文件状态更新失败!!!", Color.Red);
                feedBackMsg?.Invoke("项目导入结束。。。", Color.Blue);
                return true;
            }
@@ -455,9 +461,7 @@
            feedBackMsg?.Invoke("项目导入完成。。。", Color.Green);
            return true;
            #endregion
            #endregion 第十一步 更新模型文件状态(进度 100%)
        }
    }
}