lixiaojun
2024-11-07 31cca463443f7bc8b6b1bd02889844b864d93e11
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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
using HStation.Model;
 
namespace HStation.Service
{
    /// <summary>
    /// 修正辅助类
    /// </summary>
    public static class RevitCorrectHelper
    {
        /// <summary>
        /// 修正
        /// </summary>
        public static bool Correct(this Model.RevitModel rhs, ref List<string> msgList)
        {
            if (rhs == null)
            {
                return false;
            }
            if (msgList == null)
            {
                msgList = new List<string>();
            }
            var result = true;
            if (!CorrectCollection(rhs, ref msgList))
            {//修正集合
                result = false;
            }
            if (!CorrectName(rhs, ref msgList))
            {//修正名称
                result = false;
            }
            if (!CorrectExchanger(rhs, ref msgList))
            {//修正换热器
                result = false;
            }
            if (!CorrectCompressor(rhs, ref msgList))
            {//修正空压机
                result = false;
            }
            if (!CorrectCode(rhs, ref msgList))
            {//修正编码
                result = false;
            }
            if (!CorrectLink(rhs, ref msgList))
            {//修正连接
                result = false;
            }
 
            return result;
        }
 
        //修正集合
        private static bool CorrectCollection(Model.RevitModel rhs, ref List<string> msgList)
        {
            if (rhs == null)
            {
                return false;
            }
            if (msgList == null)
            {
                msgList = new List<string>();
            }
            if (rhs.Reservoirs == null)
            {//水库
                rhs.Reservoirs = new List<Model.RevitReservoir>();
            }
            if (rhs.Tanks == null)
            {//水池
                rhs.Tanks = new List<Model.RevitTank>();
            }
            if (rhs.Waterboxs == null)
            {//水箱
                rhs.Waterboxs = new List<Model.RevitWaterbox>();
            }
            if (rhs.Junctions == null)
            {//连接节点
                rhs.Junctions = new List<Model.RevitJunction>();
            }
            if (rhs.Bluntheads == null)
            {//闷头
                rhs.Bluntheads = new List<Model.RevitBlunthead>();
            }
            if (rhs.Elbows == null)
            {//弯头
                rhs.Elbows = new List<Model.RevitElbow>();
            }
            if (rhs.Threelinks == null)
            {//三通
                rhs.Threelinks = new List<Model.RevitThreelink>();
            }
            if (rhs.Fourlinks == null)
            {//四通
                rhs.Fourlinks = new List<Model.RevitFourlink>();
            }
            if (rhs.Nozzles == null)
            {//喷头
                rhs.Nozzles = new List<Model.RevitNozzle>();
            }
            if (rhs.Hydrants == null)
            {//消火栓
                rhs.Hydrants = new List<Model.RevitHydrant>();
            }
            if (rhs.Meters == null)
            {//水表
                rhs.Meters = new List<RevitMeter>();
            }
            if (rhs.Flowmeters == null)
            {//流量计
                rhs.Flowmeters = new List<Model.RevitFlowmeter>();
            }
            if (rhs.Pressmeters == null)
            {//压力表
                rhs.Pressmeters = new List<Model.RevitPressmeter>();
            }
 
            if (rhs.Pipes == null)
            {//管道
                rhs.Pipes = new List<Model.RevitPipe>();
            }
            if (rhs.Translations == null)
            {//过渡件
                rhs.Translations = new List<Model.RevitTranslation>();
            }
            if (rhs.Pumps == null)
            {//水泵
                rhs.Pumps = new List<Model.RevitPump>();
            }
            if (rhs.Valves == null)
            {//阀门
                rhs.Valves = new List<Model.RevitValve>();
            }
            if (rhs.Exchangers == null)
            {//换热器
                rhs.Exchangers = new List<RevitExchanger>();
            }
            if (rhs.Compressors == null)
            {//空压机
                rhs.Compressors = new List<RevitCompressor>();
            }
            return true;
        }
 
        //修正名称
        private static bool CorrectName(Model.RevitModel rhs, ref List<string> msgList)
        {
            if (rhs == null)
            {
                return false;
            }
            if (msgList == null)
            {
                msgList = new List<string>();
            }
            if (rhs.Reservoirs != null && rhs.Reservoirs.Count > 0)
            {//水库
                var reservoirNameList = rhs.Reservoirs.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).Distinct().ToList();
                foreach (var reservoir in rhs.Reservoirs)
                {
                    if (string.IsNullOrEmpty(reservoir.Name))
                    {
                        var reservoirName = Yw.Untity.UniqueHelper.CreateFromFirst("水库", reservoirNameList);
                        reservoir.Name = reservoirName;
                        reservoirNameList.Add(reservoirName);
                    }
                }
            }
            if (rhs.Tanks != null && rhs.Tanks.Count > 0)
            {//水池
                var tankNameList = rhs.Tanks.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).Distinct().ToList();
                foreach (var tank in rhs.Tanks)
                {
                    if (string.IsNullOrEmpty(tank.Name))
                    {
                        var tankName = Yw.Untity.UniqueHelper.CreateFromFirst("水池", tankNameList);
                        tank.Name = tankName;
                        tankNameList.Add(tankName);
                    }
                }
            }
            if (rhs.Waterboxs != null && rhs.Waterboxs.Count > 0)
            {//水箱
                var waterboxNameList = rhs.Waterboxs.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).Distinct().ToList();
                foreach (var waterbox in rhs.Waterboxs)
                {
                    if (string.IsNullOrEmpty(waterbox.Name))
                    {
                        var waterboxName = Yw.Untity.UniqueHelper.CreateFromFirst("水箱", waterboxNameList);
                        waterbox.Name = waterboxName;
                        waterboxNameList.Add(waterboxName);
                    }
                }
            }
            if (rhs.Junctions != null && rhs.Junctions.Count > 0)
            {//连接节点
                var junctionNameList = rhs.Junctions.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).Distinct().ToList();
                foreach (var junction in rhs.Junctions)
                {
                    if (string.IsNullOrEmpty(junction.Name))
                    {
                        var junctionName = Yw.Untity.UniqueHelper.CreateFromFirst("连接节点", junctionNameList);
                        junction.Name = junctionName;
                        junctionNameList.Add(junctionName);
                    }
                }
            }
            if (rhs.Bluntheads != null && rhs.Bluntheads.Count > 0)
            {//闷头
                var bluntheadNameList = rhs.Bluntheads.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).Distinct().ToList();
                foreach (var blunthead in rhs.Bluntheads)
                {
                    if (string.IsNullOrEmpty(blunthead.Name))
                    {
                        var bluntheadName = Yw.Untity.UniqueHelper.CreateFromFirst("闷头", bluntheadNameList);
                        blunthead.Name = bluntheadName;
                        bluntheadNameList.Add(bluntheadName);
                    }
                }
            }
            if (rhs.Elbows != null && rhs.Elbows.Count > 0)
            {//弯头
                var elbowNameList = rhs.Elbows.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).Distinct().ToList();
                foreach (var elbow in rhs.Elbows)
                {
                    if (string.IsNullOrEmpty(elbow.Name))
                    {
                        var elbowName = Yw.Untity.UniqueHelper.CreateFromFirst("弯头", elbowNameList);
                        elbow.Name = elbowName;
                        elbowNameList.Add(elbowName);
                    }
                }
            }
            if (rhs.Threelinks != null && rhs.Threelinks.Count > 0)
            {//三通
                var threelinkNameList = rhs.Threelinks.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).Distinct().ToList();
                foreach (var threelink in rhs.Threelinks)
                {
                    if (string.IsNullOrEmpty(threelink.Name))
                    {
                        var threelinkName = Yw.Untity.UniqueHelper.CreateFromFirst("三通", threelinkNameList);
                        threelink.Name = threelinkName;
                        threelinkNameList.Add(threelinkName);
                    }
                }
            }
            if (rhs.Fourlinks != null && rhs.Fourlinks.Count > 0)
            {//四通
                var fourlinkNameList = rhs.Fourlinks.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).Distinct().ToList();
                foreach (var fourlink in rhs.Fourlinks)
                {
                    if (string.IsNullOrEmpty(fourlink.Name))
                    {
                        var fourlinkName = Yw.Untity.UniqueHelper.CreateFromFirst("四通", fourlinkNameList);
                        fourlink.Name = fourlinkName;
                        fourlinkNameList.Add(fourlinkName);
                    }
                }
            }
            if (rhs.Nozzles != null && rhs.Nozzles.Count > 0)
            {//喷头
                var nozzleNameList = rhs.Nozzles.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).Distinct().ToList();
                foreach (var nozzle in rhs.Nozzles)
                {
                    if (string.IsNullOrEmpty(nozzle.Name))
                    {
                        var nozzleName = Yw.Untity.UniqueHelper.CreateFromFirst("喷头", nozzleNameList);
                        nozzle.Name = nozzleName;
                        nozzleNameList.Add(nozzleName);
                    }
                }
            }
            if (rhs.Hydrants != null && rhs.Hydrants.Count > 0)
            {//消火栓
                var hydrantNameList = rhs.Hydrants.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).Distinct().ToList();
                foreach (var hydrant in rhs.Hydrants)
                {
                    if (string.IsNullOrEmpty(hydrant.Name))
                    {
                        var hydrantName = Yw.Untity.UniqueHelper.CreateFromFirst("消火栓", hydrantNameList);
                        hydrant.Name = hydrantName;
                        hydrantNameList.Add(hydrantName);
                    }
                }
            }
            if (rhs.Meters != null && rhs.Meters.Count > 0)
            {//水表
                var meterNameList = rhs.Meters.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).Distinct().ToList();
                foreach (var meter in rhs.Meters)
                {
                    if (string.IsNullOrEmpty(meter.Name))
                    {
                        var meterName = Yw.Untity.UniqueHelper.CreateFromFirst("水表", meterNameList);
                        meter.Name = meterName;
                        meterNameList.Add(meterName);
                    }
                }
            }
            if (rhs.Flowmeters != null && rhs.Flowmeters.Count > 0)
            {//流量计
                var flowmeterNameList = rhs.Flowmeters.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).Distinct().ToList();
                foreach (var flowmeter in rhs.Flowmeters)
                {
                    if (string.IsNullOrEmpty(flowmeter.Name))
                    {
                        var flowmeterName = Yw.Untity.UniqueHelper.CreateFromFirst("流量计", flowmeterNameList);
                        flowmeter.Name = flowmeterName;
                        flowmeterNameList.Add(flowmeterName);
                    }
                }
            }
            if (rhs.Pressmeters != null && rhs.Pressmeters.Count > 0)
            {//压力表
                var pressmeterNameList = rhs.Pressmeters.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).Distinct().ToList();
                foreach (var pressmeter in rhs.Pressmeters)
                {
                    if (string.IsNullOrEmpty(pressmeter.Name))
                    {
                        var pressmeterName = Yw.Untity.UniqueHelper.CreateFromFirst("压力表", pressmeterNameList);
                        pressmeter.Name = pressmeterName;
                        pressmeterNameList.Add(pressmeterName);
                    }
                }
            }
            if (rhs.Pipes != null && rhs.Pipes.Count > 0)
            {//管道
                var pipeNameList = rhs.Pipes.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).Distinct().ToList();
                foreach (var pipe in rhs.Pipes)
                {
                    if (string.IsNullOrEmpty(pipe.Name))
                    {
                        var pipeName = Yw.Untity.UniqueHelper.CreateFromFirst("管道", pipeNameList);
                        pipe.Name = pipeName;
                        pipeNameList.Add(pipeName);
                    }
                }
            }
            if (rhs.Translations != null && rhs.Translations.Count > 0)
            {//过渡件
                var translationNameList = rhs.Translations.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).Distinct().ToList();
                foreach (var translation in rhs.Translations)
                {
                    if (string.IsNullOrEmpty(translation.Name))
                    {
                        var translationName = Yw.Untity.UniqueHelper.CreateFromFirst("过渡件", translationNameList);
                        translation.Name = translationName;
                        translationNameList.Add(translationName);
                    }
                }
            }
            if (rhs.Pumps != null && rhs.Pumps.Count > 0)
            {//水泵
                var pumpNameList = rhs.Pumps.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).Distinct().ToList();
                foreach (var pump in rhs.Pumps)
                {
                    if (string.IsNullOrEmpty(pump.Name))
                    {
                        var pumpName = Yw.Untity.UniqueHelper.CreateFromFirst("水泵", pumpNameList);
                        pump.Name = pumpName;
                        pumpNameList.Add(pumpName);
                    }
                }
            }
            if (rhs.Valves != null && rhs.Valves.Count > 0)
            {//阀门
                var valveNameList = rhs.Valves.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).Distinct().ToList();
                foreach (var valve in rhs.Valves)
                {
                    if (string.IsNullOrEmpty(valve.Name))
                    {
                        var valveName = Yw.Untity.UniqueHelper.CreateFromFirst("阀门", valveNameList);
                        valve.Name = valveName;
                        valveNameList.Add(valveName);
                    }
                }
            }
            if (rhs.Exchangers != null && rhs.Exchangers.Count > 0)
            {//换热器
                var exchangerNameList = rhs.Exchangers.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).Distinct().ToList();
                foreach (var exchanger in rhs.Exchangers)
                {
                    if (string.IsNullOrEmpty(exchanger.Name))
                    {
                        var exchangerName = Yw.Untity.UniqueHelper.CreateFromFirst("换热器", exchangerNameList);
                        exchanger.Name = exchangerName;
                        exchangerNameList.Add(exchangerName);
                    }
                }
            }
            if (rhs.Compressors != null && rhs.Compressors.Count > 0)
            {//空压机
                var compressorNameList = rhs.Compressors.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).Distinct().ToList();
                foreach (var compressor in rhs.Compressors)
                {
                    if (string.IsNullOrEmpty(compressor.Name))
                    {
                        var compressorName = Yw.Untity.UniqueHelper.CreateFromFirst("空压机", compressorNameList);
                        compressor.Name = compressorName;
                        compressorNameList.Add(compressorName);
                    }
                }
            }
            return true;
        }
 
        //修复换热器
        private static bool CorrectExchanger(Model.RevitModel rhs, ref List<string> msgList)
        {
            if (rhs == null)
            {
                return false;
            }
            if (msgList == null)
            {
                msgList = new List<string>();
            }
            var result = true;
            if (rhs.Exchangers != null && rhs.Exchangers.Count > 0)
            {
                var allParterList = rhs.GetAllParters();
                foreach (var exchanger in rhs.Exchangers)
                {
                    if (exchanger.ConnectList != null && exchanger.ConnectList.Count > 0)
                    {
                        #region 去除无效连接和闷头
 
                        foreach (var connect in exchanger.ConnectList.ToList())
                        {
                            var connectParter = allParterList.Find(x => x.Id == connect.Id);
                            if (connectParter == null)
                            {
                                exchanger.ConnectList.Remove(connect);
                            }
                            else
                            {
                                if (connectParter is RevitBlunthead blunthead)
                                {
                                    var decorator = new Model.RevitDecorator();
                                    decorator.Id = blunthead.Id;
                                    decorator.Name = blunthead.Name;
                                    decorator.Category = RevitJsonCatalog.Blunthead;
                                    decorator.Decoration = null;
                                    decorator.Description = blunthead.Description;
                                    rhs.Decorators.Add(decorator);
                                    rhs.Bluntheads.Remove(blunthead);
                                    allParterList.Remove(connectParter);
                                }
                            }
                        }
 
                        #endregion
 
                        #region 开始连接
 
                        var startConnectList = exchanger.ConnectList.GetStartConnects();
                        if (startConnectList.Count < 1)
                        {
                            var startConnect = exchanger.ConnectList.GetStartConnect();
                            if (startConnect != null)
                            {
                                startConnectList.Add(startConnect);
                            }
                        }
                        if (startConnectList.Count < 1)
                        {
                            msgList.Add($"换热器[{exchanger.Id}]上游连接组件不存在");
                            result = false;
                            continue;
                        }
                        var startJunction = new Model.RevitJunction();
                        startJunction.Id = Yw.Untity.UniqueHelper.CreateFromFirst("junction", allParterList.Select(x => x.Id).ToList());
                        startJunction.Name = UniqueHelper.CreateFromFirst("连接节点", allParterList.Select(x => x.Name).Distinct().ToList());
                        startJunction.Flags = null;
                        startJunction.ModelType = null;
                        startJunction.Description = "换热器修正时,自动添加";
                        startJunction.Position = startConnectList.GetCenterPosition();
                        startJunction.Elev = exchanger.Elev;
                        startJunction.Demand = null;
                        startJunction.DemandPattern = null;
                        rhs.Junctions.Add(startJunction);
                        exchanger.StartCode = startJunction.Id;
                        foreach (var startConnect in startConnectList)
                        {
                            var startConnectParter = allParterList.Find(x => x.Id == startConnect.Id);
                            if (startConnectParter is RevitLink revitLink)
                            {
                                if (revitLink.StartCode == exchanger.Id)
                                {
                                    revitLink.StartCode = startJunction.Id;
                                }
                                else if (revitLink.EndCode == exchanger.Id)
                                {
                                    revitLink.EndCode = startJunction.Id;
                                }
                            }
                        }
                        allParterList.Add(startJunction);
 
                        #endregion
 
                        #region 结束连接
 
                        var endConnectList = exchanger.ConnectList.GetEndConnects();
                        if (endConnectList.Count < 1)
                        {
                            var endConnect = exchanger.ConnectList.GetEndConnect();
                            if (endConnect != null)
                            {
                                endConnectList.Add(endConnect);
                            }
                        }
                        if (endConnectList.Count < 1)
                        {
                            msgList.Add($"换热器[{exchanger.Id}]下游连接组件不存在");
                            result = false;
                            continue;
                        }
                        var endJunction = new Model.RevitJunction();
                        endJunction.Id = Yw.Untity.UniqueHelper.CreateFromFirst("junction", allParterList.Select(x => x.Id).ToList());
                        endJunction.Name = UniqueHelper.CreateFromFirst("连接节点", allParterList.Select(x => x.Name).Distinct().ToList());
                        endJunction.Flags = null;
                        endJunction.ModelType = null;
                        endJunction.Description = "换热器修正时,自动添加";
                        endJunction.Position = endConnectList.GetCenterPosition();
                        endJunction.Elev = exchanger.Elev;
                        endJunction.Demand = null;
                        endJunction.DemandPattern = null;
                        rhs.Junctions.Add(endJunction);
                        exchanger.EndCode = endJunction.Id;
                        foreach (var endConnect in endConnectList)
                        {
                            var endConnectParter = allParterList.Find(x => x.Id == endConnect.Id);
                            if (endConnectParter is RevitLink revitLink)
                            {
                                if (revitLink.StartCode == exchanger.Id)
                                {
                                    revitLink.StartCode = endJunction.Id;
                                }
                                else if (revitLink.EndCode == exchanger.Id)
                                {
                                    revitLink.EndCode = endJunction.Id;
                                }
                            }
                        }
                        allParterList.Add(endJunction);
 
                        #endregion
                    }
                    else
                    {
                        msgList.Add($"换热器[{exchanger.Id}]连接列表为空");
                        result = false;
                    }
                }
            }
            return result;
        }
 
        //修复空压机
        private static bool CorrectCompressor(Model.RevitModel rhs, ref List<string> msgList)
        {
            if (rhs == null)
            {
                return false;
            }
            if (msgList == null)
            {
                msgList = new List<string>();
            }
            var result = true;
            if (rhs.Compressors != null && rhs.Compressors.Count > 0)
            {
                var allParterList = rhs.GetAllParters();
                foreach (var compressor in rhs.Compressors)
                {
                    if (compressor.ConnectList != null && compressor.ConnectList.Count > 0)
                    {
                        #region 去除无效连接和闷头
 
                        foreach (var connect in compressor.ConnectList.ToList())
                        {
                            var connectParter = allParterList.Find(x => x.Id == connect.Id);
                            if (connectParter == null)
                            {
                                compressor.ConnectList.Remove(connect);
                            }
                            else
                            {
                                if (connectParter is RevitBlunthead blunthead)
                                {
                                    var decorator = new Model.RevitDecorator();
                                    decorator.Id = blunthead.Id;
                                    decorator.Name = blunthead.Name;
                                    decorator.Category = RevitJsonCatalog.Blunthead;
                                    decorator.Decoration = null;
                                    decorator.Description = blunthead.Description;
                                    rhs.Decorators.Add(decorator);
                                    rhs.Bluntheads.Remove(blunthead);
                                    allParterList.Remove(connectParter);
                                }
                            }
                        }
 
                        #endregion
 
                        #region 开始连接
 
                        var startConnectList = compressor.ConnectList.GetStartConnects();
                        if (startConnectList.Count < 1)
                        {
                            var startConnect = compressor.ConnectList.GetStartConnect();
                            if (startConnect != null)
                            {
                                startConnectList.Add(startConnect);
                            }
                        }
                        if (startConnectList.Count < 1)
                        {
                            msgList.Add($"空压机[{compressor.Id}]上游连接组件不存在");
                            result = false;
                            continue;
                        }
                        var startJunction = new Model.RevitJunction();
                        startJunction.Id = Yw.Untity.UniqueHelper.CreateFromFirst("junction", allParterList.Select(x => x.Id).ToList());
                        startJunction.Name = UniqueHelper.CreateFromFirst("连接节点", allParterList.Select(x => x.Name).Distinct().ToList());
                        startJunction.Flags = null;
                        startJunction.ModelType = null;
                        startJunction.Description = "空压机修正时,自动添加";
                        startJunction.Position = startConnectList.GetCenterPosition();
                        startJunction.Elev = compressor.Elev;
                        startJunction.Demand = null;
                        startJunction.DemandPattern = null;
                        rhs.Junctions.Add(startJunction);
                        compressor.StartCode = startJunction.Id;
                        foreach (var startConnect in startConnectList)
                        {
                            var startConnectParter = allParterList.Find(x => x.Id == startConnect.Id);
                            if (startConnectParter is RevitLink revitLink)
                            {
                                if (revitLink.StartCode == compressor.Id)
                                {
                                    revitLink.StartCode = startJunction.Id;
                                }
                                else if (revitLink.EndCode == compressor.Id)
                                {
                                    revitLink.EndCode = startJunction.Id;
                                }
                            }
                        }
                        allParterList.Add(startJunction);
 
                        #endregion
 
                        #region 结束连接
 
                        var endConnectList = compressor.ConnectList.GetEndConnects();
                        if (endConnectList.Count < 1)
                        {
                            var endConnect = compressor.ConnectList.GetEndConnect();
                            if (endConnect != null)
                            {
                                endConnectList.Add(endConnect);
                            }
                        }
                        if (endConnectList.Count < 1)
                        {
                            msgList.Add($"空压机[{compressor.Id}]下游连接组件不存在");
                            result = false;
                            continue;
                        }
                        var endJunction = new Model.RevitJunction();
                        endJunction.Id = Yw.Untity.UniqueHelper.CreateFromFirst("junction", allParterList.Select(x => x.Id).ToList());
                        endJunction.Name = UniqueHelper.CreateFromFirst("连接节点", allParterList.Select(x => x.Name).Distinct().ToList());
                        endJunction.Flags = null;
                        endJunction.ModelType = null;
                        endJunction.Description = "空压机修正时,自动添加";
                        endJunction.Position = endConnectList.GetCenterPosition();
                        endJunction.Elev = compressor.Elev;
                        endJunction.Demand = null;
                        endJunction.DemandPattern = null;
                        rhs.Junctions.Add(endJunction);
                        compressor.EndCode = endJunction.Id;
                        foreach (var endConnect in endConnectList)
                        {
                            var endConnectParter = allParterList.Find(x => x.Id == endConnect.Id);
                            if (endConnectParter is RevitLink revitLink)
                            {
                                if (revitLink.StartCode == compressor.Id)
                                {
                                    revitLink.StartCode = endJunction.Id;
                                }
                                else if (revitLink.EndCode == compressor.Id)
                                {
                                    revitLink.EndCode = endJunction.Id;
                                }
                            }
                        }
                        allParterList.Add(endJunction);
 
                        #endregion
                    }
                    else
                    {
                        msgList.Add($"空压机[{compressor.Id}]连接列表为空");
                        result = false;
                    }
                }
            }
            return result;
        }
 
        //修正编码
        private static bool CorrectCode(Model.RevitModel rhs, ref List<string> msgList)
        {
            if (rhs == null)
            {
                return false;
            }
            if (msgList == null)
            {
                msgList = new List<string>();
            }
            var result = true;
            var allParterList = rhs.GetAllParters();
            var allLinks = rhs.GetAllLinks();
            foreach (var link in allLinks)
            {
                var startLinkParter = allParterList.Find(x => x.Id == link.StartCode);
                if (startLinkParter == null)
                {
                    msgList.Add($"管段:[{link.Id}]上游节点错误");
                    result = false;
                }
                else
                {
                    link.StartCode = startLinkParter.Id;
                }
 
                var endLinkParter = allParterList.Find(x => x.Id == link.EndCode);
                if (endLinkParter == null)
                {
                    msgList.Add($"管段:[{link.Id}]下游节点错误");
                    result = false;
                }
                else
                {
                    link.EndCode = endLinkParter.Id;
                }
 
            }
            return result;
        }
 
        //修正连接
        private static bool CorrectLink(Model.RevitModel rhs, ref List<string> msgList)
        {
            if (rhs == null)
            {
                return false;
            }
            if (msgList == null)
            {
                msgList = new List<string>();
            }
            var allParterList = rhs.GetAllParters();
            var allLinks = rhs.GetAllLinks();
            foreach (var link in allLinks)
            {
                var startLinkParter = allParterList.Find(x => x.Id == link.StartCode);
                if (startLinkParter is RevitLink startLink)
                {
                    var junction = new Model.RevitJunction();
                    junction.Id = Yw.Untity.UniqueHelper.CreateFromFirst("junction", allParterList.Select(x => x.Id).ToList());
                    junction.Name = UniqueHelper.CreateFromFirst("连接节点", allParterList.Select(x => x.Name).Distinct().ToList());
                    junction.Flags = null;
                    junction.ModelType = null;
                    junction.Description = "水力修正时,自动添加";
                    junction.Position = link.StartPosition;
                    junction.Elev = link.StartPosition.Z;
                    junction.Demand = null;
                    junction.DemandPattern = null;
                    rhs.Junctions.Add(junction);
                    link.StartCode = junction.Id;
 
                    if (startLink.StartCode == link.Id)
                    {
                        startLink.StartCode = junction.Id;
                    }
                    else if (startLink.EndCode == link.Id)
                    {
                        startLink.EndCode = junction.Id;
                    }
                    allParterList.Add(junction);
                }
 
                var endLinkParter = allParterList.Find(x => x.Id == link.EndCode);
                if (endLinkParter is RevitLink endLink)
                {
                    var junction = new Model.RevitJunction();
                    junction.Id = Yw.Untity.UniqueHelper.CreateFromFirst("junction", allParterList.Select(x => x.Id).ToList());
                    junction.Name = UniqueHelper.CreateFromFirst("连接节点", allParterList.Select(x => x.Name).Distinct().ToList());
                    junction.Flags = null;
                    junction.ModelType = null;
                    junction.Description = "水力修正时,自动添加";
                    junction.Position = link.EndPosition;
                    junction.Elev = link.EndPosition.Z;
                    junction.Demand = null;
                    junction.DemandPattern = null;
                    rhs.Junctions.Add(junction);
                    link.EndCode = junction.Id;
                    if (endLink.StartCode == link.Id)
                    {
                        endLink.StartCode = junction.Id;
                    }
                    else if (endLink.EndCode == link.Id)
                    {
                        endLink.EndCode = junction.Id;
                    }
                    allParterList.Add(junction);
                }
            }
            return true;
        }
 
 
 
    }
}