lixiaojun
2024-07-23 ec9bc16c81d897549568d826047da0189b8e85a3
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
using DevExpress.XtraScheduler.VCalendar;
 
namespace HStation.WinFrmUI
{
    /// <summary>
    /// 
    /// </summary>
    public class ImportXhsProjectHelper
    {
        private const string _tempFolder = "ImportProjectTemp";//导入项目临时文件夹
 
 
        /// <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 tempFolder = Path.Combine(Yw.Service.ConfigHelper.DataPath, HStation.Settings.XhsParasHelper.Xhs.DataFolder, _tempFolder);
            //如果存在临时文件夹
            if (Directory.Exists(tempFolder))
            {
                //删除临时文件夹及子目录与文件
                Directory.Delete(tempFolder, true);
            }
            //创建临时文件夹
            Directory.CreateDirectory(tempFolder);
 
            #endregion
 
            #region 压缩文件解析
 
            feedBackMsg?.Invoke("正在解析模型文件...");
            var bol = Yw.FileFolderZipHelper.UnZip(vm.ZipFile, tempFolder, null);
            if (!bol)
            {
                feedBackMsg?.Invoke("模型文件解析失败!!!");
                return bol;
            }
 
            var tempFolderInfo = new DirectoryInfo(tempFolder);
            var allFileInfoList = tempFolderInfo.GetFiles();
            if (allFileInfoList == null || allFileInfoList.Count() < 1)
            {
                feedBackMsg?.Invoke("模型文件解析失败!!!");
                return bol;
            }
 
            feedBackMsg?.Invoke("模型文件解析成功。。。");
 
            feedBackProgress?.Invoke(100, 10);
 
            #endregion
 
            #region 水力结构文件
 
            feedBackMsg?.Invoke("正在解析水力结构文件...");
            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 hydroInfo = HStation.Hydro.ParseHelper.FromRevit(revitModel);
            if (hydroInfo == null)
            {
                feedBackMsg?.Invoke("水力结构文件解析失败!!!");
                return false;
            }
 
            var bllHydro = new Lazy<Yw.BLL.HydroModelInfo>(() => new Yw.BLL.HydroModelInfo());
            var hydroId = await bllHydro.Value.Save(hydroInfo);
            if (hydroId < 1)
            {
                feedBackMsg?.Invoke("水力结构保存失败!!!");
                return false;
            }
 
            feedBackMsg?.Invoke("水力结构文件解析成功。。。");
 
            feedBackProgress?.Invoke(100, 20);
 
            vm.HydroID = hydroId;
 
            #endregion
 
            #region 创建保存项目
 
            feedBackMsg?.Invoke("正在创建项目...");
 
            var bllXhsProject = new Lazy<BLL.XhsProjectExtensions>(() => 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.Value.Insert(project);
            if (projectId < 1)
            {
                feedBackMsg?.Invoke("项目创建失败!!!");
                return false;
            }
 
            feedBackMsg?.Invoke("项目创建成功。。。");
 
            vm.ProjectID = projectId;
 
            feedBackProgress?.Invoke(100, 25);
 
            #endregion
 
            #region 关联水力模型
 
            var bllXhsProjectSite = new Lazy<BLL.XhsProjectSite>(() => new BLL.XhsProjectSite());
            var allProjectSiteList = await bllXhsProjectSite.Value.GetByProjectID(projectId);
            var projectSiteId = allProjectSiteList.First().ID;
 
            vm.ProjectSiteID = projectSiteId;
 
            feedBackMsg?.Invoke("正在关联水力模型...");
 
            var hydroRelation = new Yw.Dto.AddHydroModelRelationInput();
            hydroRelation.ObjectType = HStation.Xhs.DataType.XhsProjectSite;
            hydroRelation.ObjectID = projectSiteId;
            hydroRelation.ModelID = hydroId;
            hydroRelation.Purpose = Yw.Hydro.Purpose.Simulation;
            hydroRelation.Content = null;
            hydroRelation.Description = null;
 
            var bllHydroRelation = new Lazy<Yw.BLL.HydroModelRelation>(() => new Yw.BLL.HydroModelRelation());
            var hydroRelationId = await bllHydroRelation.Value.Insert(hydroRelation);
            if (hydroRelationId < 1)
            {
                feedBackMsg?.Invoke("关联水力模型失败!!!");
                return false;
            }
 
            feedBackMsg?.Invoke("关联水力成功。。。");
 
            vm.HydroRelationID = hydroRelationId;
 
            feedBackProgress?.Invoke(100, 30);
 
            #endregion
 
            #region 设置地图位置
 
            feedBackMsg?.Invoke("正在设置地图位置...");
 
            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("设置地图位置成功。。。");
                }
            }
            else
            {
                feedBackMsg?.Invoke("设置地图位置失败!!!");
            }
 
            feedBackMsg?.Invoke("设置地图位置完成。。。");
 
            feedBackProgress?.Invoke(100, 40);
 
            #endregion
 
            #region 上传Revit模型
 
            feedBackMsg?.Invoke("正在解析Revit模型文件...");
            var rvtFileInfo = allFileInfoList.Where(x => x.Extension == ".rvt").FirstOrDefault();
            if (rvtFileInfo == null)
            {
                feedBackMsg?.Invoke("Revit模型文件解析失败!!!");
            }
 
            var bimfaceId = await Yw.WinFrmUI.BimfaceHelper.UploadFile(rvtFileInfo.FullName);
            if (bimfaceId < 1)
            {
                feedBackMsg?.Invoke("Revit模型文件上传失败!!!");
                return true;
            }
 
            feedBackMsg?.Invoke("解析Revit模型文件成功。。。");
 
            feedBackProgress?.Invoke(100, 60);
 
            vm.BimfaceId = bimfaceId;
 
            #endregion
 
            #region 保存Bimface文件
 
            feedBackMsg?.Invoke("正在保存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文件保存失败!!!");
                return true;
            }
 
            feedBackMsg?.Invoke("Bimface文件保存成功。。。");
 
            feedBackProgress?.Invoke(100, 70);
 
            vm.BimfaceFileID = bimfaceFileId;
 
            #endregion
 
            #region 关联Bimface文件
 
            feedBackMsg?.Invoke("正在关联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文件关联失败!!!");
                return true;
            }
            feedBackMsg?.Invoke("Bimface文件关联成功。。。");
 
            feedBackProgress?.Invoke(100, 80);
 
            vm.BimfaceFileRelationID = bimfaceRelationId;
            #endregion
 
            #region 发起bimface转换
 
            feedBackMsg?.Invoke("正在进行Bimface模型轻量化...");
            var bimfaceTranslateStatus = await Yw.WinFrmUI.BimfaceHelper.TranslateRvtFile(bimfaceId);
            if (bimfaceTranslateStatus != Yw.BIMFace.eTranslateStatus.Success)
            {
                await Yw.WinFrmUI.BimfaceHelper.WaitFileTranslateStatusUntilSuccess(bimfaceId, 3000);
            }
            feedBackMsg?.Invoke("Bimface模型轻量化完成。。。");
 
            feedBackProgress?.Invoke(100, 90);
            #endregion
 
            #region 更新状态
 
            feedBackMsg?.Invoke("正在更新Bimface文件状态...");
            bol = await bllBimfaceFile.UpdateFileStatus(bimfaceFileId, (int)Yw.Bimface.eFileStatus.ConvertSucceed);
 
            if (bol)
            {
                feedBackMsg?.Invoke("正在Bimface文件状态更新成功。。。");
            }
            else
            {
                feedBackMsg?.Invoke("正在Bimface文件状态更新失败!!!");
            }
 
            feedBackProgress?.Invoke(100, 100);
 
            #endregion
 
            return true;
 
        }
 
 
    }
}