Shuxia Ning
2024-10-24 0711485ecb4fe66fbe820478d92eb9f04b77c042
WinFrmUI/HStation.WinFrmUI.Xhs.Core/02-project/01-import/00-core/ImportXhsProjectHelper.cs
@@ -1,4 +1,6 @@
using DevExpress.XtraEditors;
using Castle.Core.Internal;
using DevExpress.XtraEditors;
using HStation.Model;
using HStation.Vmo;
using static DevExpress.XtraEditors.XtraInputBox;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
@@ -23,8 +25,6 @@
        {
            var msg = string.Empty;
            var IsContinue = true;
            #region 第一步 临时文件处理(进度5%)
            msg = "开始导入项目...";
@@ -48,8 +48,6 @@
            feedBackMsg?.Invoke("正在创建项目...", Color.Black);
            var bllXhsProjectExtensions = new Lazy<BLL.XhsProjectExtensions>(() => new BLL.XhsProjectExtensions());
            var project = new Vmo.XhsProjectExtensionsVmo();
            project.NO = vm.NO;
            project.Name = vm.Name;
@@ -58,15 +56,16 @@
            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
                     }
             };
            project.SiteList = new List<XhsProjectSiteVmo>() {
                new XhsProjectSiteVmo(){
                    Name=vm.Name,
                    Description=vm.Description
                }
            };
            var projectId = await bllXhsProjectExtensions.Value.Insert(project);
            var projectId = await BLLFactory<HStation.BLL.XhsProjectExtensions>.Instance.Insert(project);
            if (projectId < 1)
            {
                feedBackMsg?.Invoke("项目创建失败!!!", Color.Red);
@@ -87,7 +86,7 @@
            if (vm.Location != null)
            {
                var mapInfo = new Yw.Vmo.Map.MapInfo();
                var mapInfo = new Yw.Vmo.MapInfoVmo();
                mapInfo.ObjectType = HStation.Xhs.DataType.XhsProject;
                mapInfo.ObjectID = projectId;
                mapInfo.ObjectName = project.Name;
@@ -96,7 +95,7 @@
                mapInfo.Shape = Yw.Map.Shape.Marker;
                mapInfo.Position = vm.Location.ToJson();
                var mapInfoId = await new Yw.BLL.MapInfo().Insert(mapInfo);
                var mapInfoId = await BLLFactory<Yw.BLL.MapInfo>.Instance.Insert(mapInfo);
                if (mapInfoId < 1)
                {
                    feedBackMsg?.Invoke("设置地图位置失败!!!", Color.Red);
@@ -120,20 +119,13 @@
            msg = "正在解析模型文件...";
            feedBackMsg?.Invoke(msg, Color.Black);
            var bol = Yw.FileFolderZipHelper.UnZip(vm.ZipFile, tempFolder, null);
            var zipFilePwd = HStation.Settings.XhsParasHelper.Xhs.File.Password;
            var bol = Yw.FileFolderZipHelper.UnZip(vm.ZipFile, tempFolder, zipFilePwd);
            if (!bol)
            {
                feedBackMsg?.Invoke("模型文件解析失败!!!", Color.Red);
                //return false;
            }
            else
            {
                IsContinue = false;
            }
            if (IsContinue)
            {
                feedBackMsg?.Invoke("项目导入成功。。。", Color.Green);
                feedBackMsg?.Invoke("项目导入结束。。。", Color.Blue);
                feedBackProgress?.Invoke(100, 100);
                return true;
            }
@@ -143,7 +135,9 @@
            if (allFileInfoList == null || allFileInfoList.Count() < 1)
            {
                feedBackMsg?.Invoke("模型文件格式错误!!!", Color.Red);
                return false;
                feedBackMsg?.Invoke("项目导入结束。。。", Color.Blue);
                feedBackProgress?.Invoke(100, 100);
                return true;
            }
            feedBackMsg?.Invoke("模型文件解析成功。。。", Color.Green);
@@ -155,39 +149,113 @@
            #region 第五步 解析水力结构文件 (进度30%)
            feedBackMsg?.Invoke("正在解析水力结构文件...", Color.Black);
            var jsonFileInfo = allFileInfoList.Where(x => x.Extension == ".json").FirstOrDefault();
            if (jsonFileInfo == null)
            var structFileInfo = allFileInfoList.Find(x => x.Name == HStation.Revit.ConstParas.StructFileName);
            if (structFileInfo == null)
            {
                feedBackMsg?.Invoke("水力结构文件格式错误!!!", Color.Red);
                return false;
                feedBackMsg?.Invoke("项目导入结束。。。", Color.Blue);
                feedBackProgress?.Invoke(100, 100);
                return true;
            }
            var revitModel = HStation.Service.RevitParseHelper.FromJsonFile(jsonFileInfo.FullName, out msg);
            if (revitModel == null)
            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);
            //解析结果判断
            if (!structFileResult)
            {
                feedBackMsg?.Invoke($"{msg}!!!", Color.Red);
                return false;
                structFileMsgList?.ForEach(x => feedBackMsg?.Invoke(x, Color.Red));
            }
            //Revit属性错误处理
            var hasRevitPropError = false;
            if (structRevitModel != null)
            {
                var allRevitParterList = structRevitModel.GetAllParters();
                foreach (var revitParter in allRevitParterList)
                {
                    if (revitParter.PropStatusList != null && revitParter.PropStatusList.Count > 0)
                    {
                        foreach (var revitParterPropStatus in revitParter.PropStatusList)
                        {
                            if (revitParterPropStatus.PropStatus == HStation.Revit.ePropStatus.Error)
                            {
                                hasRevitPropError = true;
                            }
                            switch (revitParterPropStatus.PropStatus)
                            {
                                case Revit.ePropStatus.Error:
                                    {
                                        feedBackMsg?.Invoke($"构件类型:{revitParter.Catalog},构件编码:{revitParter.Code},构件属性:{revitParterPropStatus.PropName},错误:{revitParterPropStatus.StatusInfo} ", Color.Red);
                                    }
                                    break;
                                case Revit.ePropStatus.Lack:
                                    {
                                        //feedBackMsg?.Invoke($"构件编码:{revitParter.Id},构件属性:{revitParterPropStatus.PropName},缺省:{revitParterPropStatus.StatusInfo} ", Color.Gray);
                                    }
                                    break;
                                case Revit.ePropStatus.Abnormal:
                                    {
                                        //feedBackMsg?.Invoke($"构件编码:{revitParter.Id},构件属性:{revitParterPropStatus.PropName},异常:{revitParterPropStatus.StatusInfo} ", Color.Orange);
                                    }
                                    break;
                                default: break;
                            }
                        }
                    }
                }
            }
            if (hasRevitPropError || !structFileResult)
            {
                feedBackMsg?.Invoke($"水力结构文件解析错误!!!", Color.Red);
                feedBackMsg?.Invoke("项目导入结束。。。", Color.Blue);
                feedBackProgress?.Invoke(100, 100);
                return true;
            }
            var hydroInfo = HStation.Hydro.TransferHelper.FromRevit(revitModel, out msg);
            vm.RevitModel = structRevitModel;
            var hydroInfo = HStation.Hydro.TransferHelper.FromRevit(structRevitModel, out msg);
            if (hydroInfo == null)
            {
                feedBackMsg?.Invoke($"水力结构文件解析失败,{msg}!!!", Color.Red);
                return false;
                feedBackMsg?.Invoke("项目导入结束。。。", Color.Blue);
                feedBackProgress?.Invoke(100, 100);
                return true;
            }
            var bllHydroInfo = new Yw.BLL.HydroModelInfo();
            var hydroId = await bllHydroInfo.Save(hydroInfo);
            var hydroId = await BLLFactory<Yw.BLL.HydroModelInfo>.Instance.Save(hydroInfo);
            if (hydroId < 1)
            {
                feedBackMsg?.Invoke("水力结构信息保存失败!!!", Color.Red);
                return false;
                feedBackMsg?.Invoke("项目导入结束。。。", Color.Blue);
                feedBackProgress?.Invoke(100, 100);
                return true;
            }
            feedBackMsg?.Invoke("正在进行产品匹配...", Color.Black);
            hydroInfo = await BLLFactory<Yw.BLL.HydroModelInfo>.Instance.GetByID(hydroId);
            var matchingParas = AssetsMatchingParasHelper.Create(hydroInfo, null);
            if (AssetsMatchingHelper.Matching(matchingParas, out string error))
            {
                if (AssetsMatchingParasHelper.Apply(hydroInfo, matchingParas))
                {
                    feedBackMsg?.Invoke("产品匹配完成。。。", Color.Green);
                }
                else
                {
                    feedBackMsg?.Invoke("产品匹配失败!!!", Color.Red);
                }
            }
            else
            {
                feedBackMsg?.Invoke("产品匹配失败!!!", Color.Red);
            }
            hydroId = await BLLFactory<Yw.BLL.HydroModelInfo>.Instance.Save(hydroInfo);
            feedBackMsg?.Invoke("水力结构文件解析成功。。。", Color.Green);
            feedBackProgress?.Invoke(100, 30);
            vm.HydroID = hydroId;
            #endregion 第五步 解析水力结构文件 (进度30%)
@@ -198,7 +266,9 @@
            if (projectSite == null)
            {
                feedBackMsg?.Invoke("项目站信息错误...", Color.Red);
                return false;
                feedBackMsg?.Invoke("项目导入结束。。。", Color.Blue);
                feedBackProgress?.Invoke(100, 100);
                return true;
            }
            var projectSiteId = projectSite.ID;
@@ -206,26 +276,25 @@
            feedBackMsg?.Invoke("正在关联水力结构模型...", Color.Black);
            var hydroRelation = new Yw.Dto.AddHydroModelRelationInput();
            var hydroRelation = new Yw.Vmo.HydroModelRelationVmo();
            hydroRelation.ObjectType = HStation.Xhs.DataType.XhsProjectSite;
            hydroRelation.ObjectID = projectSiteId;
            hydroRelation.ModelID = hydroId;
            hydroRelation.Purpose = Yw.Hydro.Purpose.Simulation;
            hydroRelation.Purpose = HStation.Xhs.Purpose.Simulation;
            hydroRelation.Content = null;
            hydroRelation.Description = null;
            var bllHydroRelation = new Yw.BLL.HydroModelRelation();
            var hydroRelationId = await bllHydroRelation.Insert(hydroRelation);
            var hydroRelationId = await BLLFactory<Yw.BLL.HydroModelRelation>.Instance.Insert(hydroRelation);
            if (hydroRelationId < 1)
            {
                feedBackMsg?.Invoke("关联水力结构模型失败!!!", Color.Red);
                return false;
                feedBackMsg?.Invoke("项目导入结束。。。", Color.Blue);
                feedBackProgress?.Invoke(100, 100);
                return true;
            }
            vm.HydroRelationID = hydroRelationId;
            feedBackMsg?.Invoke("关联水力结构模型成功。。。", Color.Green);
            feedBackProgress?.Invoke(100, 40);
            #endregion 第六步 关联水力结构模型(进度 40%)
@@ -233,27 +302,27 @@
            #region 第七步 上传Revit模型文件(进度 45%)
            feedBackMsg?.Invoke("正在解析Revit模型文件...", Color.Black);
            var rvtFileInfo = allFileInfoList.Where(x => x.Extension == ".rvt").FirstOrDefault();
            var rvtFileInfo = allFileInfoList.Find(x => x.Name == HStation.Revit.ConstParas.RvtFileName);
            if (rvtFileInfo == null)
            {
                feedBackMsg?.Invoke("Revit模型文件解析失败!!!", Color.Red);
                feedBackMsg?.Invoke("项目导入结束。。。", Color.Blue);
                feedBackProgress?.Invoke(100, 100);
                return true;
            }
            //var bimfaceId = await Yw.WinFrmUI.BimfaceHelper.UploadFile(rvtFileInfo.FullName);//上传
            var bimfaceId = 10000872887098; //测试用例
            var bimfaceId = 10000884702464; //测试用例 10000878572231 10000882826621  10000884283372 10000884362886 10000884702464
            if (bimfaceId < 1)
            {
                feedBackMsg?.Invoke("Revit模型文件上传失败!!!", Color.Red);
                feedBackMsg?.Invoke("项目导入结束。。。", Color.Blue);
                feedBackProgress?.Invoke(100, 100);
                return true;
            }
            vm.BimfaceId = bimfaceId;
            feedBackMsg?.Invoke("解析Revit模型文件成功。。。", Color.Green);
            feedBackProgress?.Invoke(100, 45);
            #endregion 第七步 上传Revit模型文件(进度 45%)
@@ -271,18 +340,17 @@
            bimfaceFile.FileSuffix = rvtFileInfo.Extension;
            bimfaceFile.FileSize = string.Format("{0}MB", System.Math.Ceiling(rvtFileInfo.Length / 1024.0 / 1024.0));
            var bllBimfaceFile = new Yw.BLL.BimfaceFile();
            var bimfaceFileId = await bllBimfaceFile.Insert(bimfaceFile);
            var bimfaceFileId = await BLLFactory<Yw.BLL.BimfaceFile>.Instance.Insert(bimfaceFile);
            if (bimfaceFileId < 1)
            {
                feedBackMsg?.Invoke("Bimface文件保存失败!!!", Color.Red);
                feedBackMsg?.Invoke("项目导入结束。。。", Color.Blue);
                feedBackProgress?.Invoke(100, 100);
                return true;
            }
            vm.BimfaceFileID = bimfaceFileId;
            feedBackMsg?.Invoke("Bimface文件保存成功。。。", Color.Green);
            feedBackProgress?.Invoke(100, 50);
            #endregion 第八步 保存Bimface文件 (进度 50%)
@@ -295,15 +363,15 @@
            bimfaceRelation.ObjectType = HStation.Xhs.DataType.XhsProjectSite;
            bimfaceRelation.ObjectID = projectSiteId;
            bimfaceRelation.BimfaceFileID = bimfaceFileId;
            bimfaceRelation.Purpose = Yw.Bimface.Purpose.Simulation;
            bimfaceRelation.Purpose = HStation.Xhs.Purpose.Simulation;
            bimfaceRelation.Description = vm.Description;
            var bllBimfaceRelation = new Yw.BLL.BimfaceFileRelation();
            var bimfaceRelationId = await bllBimfaceRelation.Insert(bimfaceRelation);
            var bimfaceRelationId = await BLLFactory<Yw.BLL.BimfaceFileRelation>.Instance.Insert(bimfaceRelation);
            if (bimfaceRelationId < 1)
            {
                feedBackMsg?.Invoke("Bimface文件关联失败!!!", Color.Red);
                feedBackMsg?.Invoke("项目导入结束。。。", Color.Blue);
                feedBackProgress?.Invoke(100, 100);
                return true;
            }
            vm.BimfaceFileRelationID = bimfaceRelationId;
@@ -330,6 +398,9 @@
                else
                {
                    feedBackMsg?.Invoke("跳过Bimface模型轻量化等待。。。", Color.Black);
                    feedBackMsg?.Invoke("项目导入结束。。。", Color.Blue);
                    feedBackProgress?.Invoke(100, 100);
                    return true;
                }
            }
            else
@@ -345,7 +416,7 @@
            #region 第十一步 更新Bimface文件状态(进度 100%)
            feedBackMsg?.Invoke("正在更新Bimface文件状态...", Color.Black);
            bol = await bllBimfaceFile.UpdateFileStatus(bimfaceFileId, (int)Yw.Bimface.eFileStatus.ConvertSucceed);
            bol = await BLLFactory<Yw.BLL.BimfaceFile>.Instance.UpdateFileStatus(bimfaceFileId, (int)Yw.Bimface.eFileStatus.ConvertSucceed);
            if (bol)
            {
                feedBackMsg?.Invoke("Bimface文件状态更新成功。。。", Color.Green);
@@ -358,29 +429,10 @@
            }
            feedBackProgress?.Invoke(100, 100);
            #endregion 第十一步 更新Bimface文件状态(进度 100%)
            #region 弃用  第十二步 项目发布(进度 100%)
            /*    feedBackMsg?.Invoke("正在发布项目...");
                var bllXhsProject = new BLL.XhsProject();
                bol = await bllXhsProject.Publish(projectId);
                if (!bol)
                {
                    feedBackMsg?.Invoke("项目发布失败...");
                }
                else
                {
                    vm.IsPublished = true;
                    feedBackMsg?.Invoke("项目发布成功...");
                }
                feedBackProgress?.Invoke(100, 100);
                feedBackMsg?.Invoke("项目导入结束。。。");*/
            feedBackMsg?.Invoke("项目导入完成。。。", Color.Green);
            return true;
            #endregion 弃用  第十二步 项目发布(进度 100%)
            #endregion 第十一步 更新Bimface文件状态(进度 100%)
        }
    }
}