lixiaojun
2024-07-22 686dd39ef856012c0c7f2620ffef1e3a5c1ec779
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
namespace HStation.WinFrmUI
{
    /// <summary>
    /// 
    /// </summary>
    public class ImportXhsProjectHelper
    {
        private const string _tempFolder = "project-import-temp";
 
 
        /// <summary>
        /// 导入
        /// </summary>
        /// <param name="vm">通用视图Model</param>
        /// <param name="feedBackMsg">信息反馈</param>
        /// <param name="feedBackProgress">进度反馈</param>
        /// <returns></returns>
        public static async Task<bool> Import(ImportXhsProjectViewModel vm, Action<string> feedBackMsg, Action<int, int> feedBackProgress)
        {
            #region 文件解析
 
            var tempFolderPath = Path.Combine(Yw.Service.ConfigHelper.DataPath, HStation.Settings.XhsParasHelper.Xhs.DataFolder, _tempFolder);
            var bol = Yw.FileFolderZipHelper.UnZip(vm.ZipFile, tempFolderPath, null);
            if (!bol)
            {
                feedBackMsg?.Invoke("模型文件解析失败");
                return bol;
            }
 
            var tempDirectoryInfo = new DirectoryInfo(tempFolderPath);
            var allFileInfoList = tempDirectoryInfo.GetFiles();
            if (allFileInfoList == null || allFileInfoList.Count() < 1)
            {
                feedBackMsg?.Invoke("模型文件解析失败");
                return bol;
            }
 
            #endregion
 
            #region 水力模型
 
            var jsonFileInfo = allFileInfoList.Where(x => x.Extension == ".json").FirstOrDefault();
            if (jsonFileInfo == null)
            {
                feedBackMsg?.Invoke("水力结构文件解析失败");
                return false;
            }
 
            var jsonText = File.ReadAllText(jsonFileInfo.FullName);
            var revitModel = JsonHelper.Json2Object<HStation.Model.RevitModel>(jsonText);
            var hydroId = HStation.Hydro.ParseHelper.FromRevit(revitModel);
            if (hydroId < 1)
            {
                feedBackMsg?.Invoke("水力结构文件解析失败");
                return false;
            }
 
 
            #endregion
 
            #region 创建项目
 
            var bllXhsProject = new BLL.XhsProjectExtensions();
 
            var project = new AddXhsProjectExtensionsInput();
            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<AddXhsProjectSiteExtensionsInput>() {
                new AddXhsProjectSiteExtensionsInput(){
                    Name=vm.Name,
                    Description=vm.Description
                }
            };
 
            var projectId = await bllXhsProject.Insert(project);
            if (projectId < 1)
            {
                feedBackMsg?.Invoke("项目创建失败");
                return false;
            }
 
            #endregion
 
            #region 关联模型
 
 
 
            #endregion
 
            #region 地图位置
 
            if (vm.Location != null)
            {
                var mapInfo = new Yw.Dto.AddMapInfoInput();
                mapInfo.ObjectType = HStation.Xhs.DataType.XhsProject;
                mapInfo.ObjectID = projectId;
                mapInfo.ObjectName = 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 new Yw.BLL.MapInfo().Insert(mapInfo);
                if (mapInfoId < 1)
                {
                    feedBackMsg?.Invoke("地图定位信息保存失败");
                }
                else
                {
                    feedBackMsg?.Invoke("保存地图定位信息成功");
                }
            }
 
            #endregion
 
            #region 上传模型
 
            var rvtFileInfo = allFileInfoList.Where(x => x.Extension == ".rvt").FirstOrDefault();
            if (rvtFileInfo == null)
            {
                feedBackMsg?.Invoke("Revit模型文件解析失败");
                return false;
            }
 
            var bimfaceId = await Yw.WinFrmUI.BimfaceHelper.UploadFile(rvtFileInfo.FullName);
            if (bimfaceId < 1)
            {
                feedBackMsg?.Invoke("Revit模型文件上传失败");
                return false;
            }
 
 
 
            #endregion
 
            #region 保存Bimface
 
            var bllBimfaceFile = new Yw.BLL.BimfaceFile();
 
            var bimfaceFile = new Yw.Dto.AddBimfaceFileInput();
            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));
 
            var bimfaceFileId = await bllBimfaceFile.Insert(bimfaceFile);
            if (bimfaceFileId < 1)
            {
                feedBackMsg?.Invoke("BIMFACE文件信息保存失败");
            }
            else
            {
                feedBackMsg?.Invoke("BIMFACE文件信息保存成功");
            }
 
            #endregion
 
            #region 关联Bimface
 
            var bllBimfaceRelation = new Yw.BLL.BimfaceFileRelation();
 
            var bimfaceRelation = new Yw.Dto.AddBimfaceFileRelationInput();
            bimfaceRelation.ObjectType = HStation.Xhs.DataType.XhsProject;
            bimfaceRelation.ObjectID = projectId;
            bimfaceRelation.BimfaceFileID = bimfaceFileId;
            bimfaceRelation.Purpose = HStation.Xhs.Purpose.Simulation;
            bimfaceRelation.Description = vm.Description;
 
            var bimfaceRelationId = await bllBimfaceRelation.Insert(bimfaceRelation);
            if (bimfaceRelationId < 1)
            {
                feedBackMsg?.Invoke("BIMFACE关联失败");
            }
            else
            {
                feedBackMsg?.Invoke("BIMFACE关联成功");
            }
 
            #endregion
 
            #region 发起bimface转换
 
            var bimfaceTranslateStatus = await Yw.WinFrmUI.BimfaceHelper.TranslateRvtFile(bimfaceId);
            if (bimfaceTranslateStatus != Yw.BIMFace.eTranslateStatus.Success)
            {
                await Yw.WinFrmUI.BimfaceHelper.WaitFileTranslateStatusUntilSuccess(bimfaceId, 3000);
            }
 
            #endregion
 
            #region 更新状态
 
            bol = await bllBimfaceFile.UpdateFileStatus(bimfaceFileId, (int)Yw.Bimface.eFileStatus.ConvertSucceed);
 
            feedBackMsg?.Invoke("文件状态更新");
 
            #endregion
 
            return true;
 
        }
 
 
    }
}