ningshuxia
2022-12-12 e81ca048ef4e9345e904b74ffffd3e8413d18a7e
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
using Microsoft.AspNetCore.Mvc;
using System.Net;
using System.Net.Http.Headers;
using Microsoft.Extensions.Hosting.Internal;
using Microsoft.AspNetCore.Http.Extensions;
using IStation.Untity;
using Furion.DynamicApiController;
using System.ComponentModel.DataAnnotations;
using Mapster;
using Microsoft.AspNetCore.Http;
 
namespace IStation.Application
{
    /// <summary>
    /// InspectContent
    /// </summary>
    [Route("Inspect/Record/Mobile")]
    [ApiDescriptionSettings("Inspect", Name = "巡检记录(手机)", Order = 999)]
    public class InspectRecord_MobileController : IDynamicApiController
    {
 
        private readonly IHttpContextAccessor _httpContextAccessor;
 
        /// <summary>
        /// 
        /// </summary>
        public InspectRecord_MobileController(IHttpContextAccessor httpContextAccessor)
        {
            _httpContextAccessor = httpContextAccessor;
        }
 
        #region 巡检中
        /// <summary>
        /// 获取某产品的巡检项目(正在巡检时)
        /// </summary>
        /// <param name="CorpID"></param>
        /// <param name="ProductID"></param>
        /// <param name="EmployeeID"></param>
        [Route("GetContentByProductID4Input@V1.0")]
        [HttpGet]
        public IStation.Dto.InspectRecordContent4Ing GetContentByProductID4Input(
            long CorpID,
            long ProductID,
            long EmployeeID)
        {
            IStation.Service.InspectRecord service_Record = new Service.InspectRecord();
 
            IStation.Service.InspectionContentBundle service_Content = new Service.InspectionContentBundle();
            var contents = service_Content.GetByProductID(CorpID, ProductID);
            if (contents == null || contents.Count() == 0)
            {
                throw new Exception("未配置巡检项");
            }
 
 
            var content_item_ids = contents.Select(x => x.ItemID);
 
            var model_record = service_Record.GetOrCreateRecord(CorpID, ProductID, DateTime.Now, EmployeeID, content_item_ids.ToList());
 
            List<Dto.InspectRecordDetail> vm_list = new List<Dto.InspectRecordDetail>();
 
 
            foreach (var ds_detail in model_record.Details)
            {
                var content = contents.Find(x => x.ItemID == ds_detail.ContentID);
                if (content == null)
                    continue;
 
                Dto.InspectRecordDetail detail_vm = new Dto.InspectRecordDetail();
 
                detail_vm.ContentID = content.ItemID;
                detail_vm.Name = content.ItemName;
                detail_vm.ValueType = content.ValueType;
                detail_vm.ValueNullAble = content.ValueNullAble;
                detail_vm.ValueRangeMin = content.ValueRangeMin;
                detail_vm.ValueRangeMax = content.ValueRangeMax;
                detail_vm.TipInfo = content.TipInfo;
                if (detail_vm.TipInfo == null)
                    detail_vm.TipInfo = "";
 
                detail_vm.MonitorPointID = content.MonitorPointID;
 
                detail_vm.GroupName = content.GroupName;
                if (detail_vm.GroupName == null)
                    detail_vm.GroupName = "";
                detail_vm.DetailID = ds_detail.ID;
                detail_vm.Value = ds_detail.Value;
                if (detail_vm.Value == null)
                    detail_vm.Value = "";
                detail_vm.ValueStatus = ds_detail.Status;
                detail_vm.ValueList = content.ValueList;
 
                vm_list.Add(detail_vm);
            }
 
 
            IStation.Dto.InspectRecordContent4Ing vm_record = new IStation.Dto.InspectRecordContent4Ing();
            vm_record.Details = vm_list;
            vm_record.RecordID = model_record.Record.ID;
            vm_record.Note = model_record.Record.Note;
 
            return vm_record;
        }
 
 
 
        /// <summary>
        /// 获取产品列表(正在巡检时)
        /// </summary>
        /// <param name="CorpID">公司ID</param>
        /// <param name="EmployeeID">登录的员工ID</param>
        /// <param name="PosiX">经度</param>
        /// <param name="PosiY">纬度</param>
        /// <returns></returns>
        [Route("GetProductScheduleByToDay4Input")]
        [HttpGet]
        public List<IStation.Dto.ProductInspectStatus> GetProductScheduleByToDay4Input(
            long CorpID,
            long EmployeeID,
            double PosiX,
            double PosiY)
        {
            var products = GetProductByCorpID(CorpID);
            if (products == null || products.Count() == 0)
                throw new Exception("未配置巡检项");
 
 
            IStation.Service.InspectRecord service_Record = new Service.InspectRecord();
            var records = service_Record.GetByRecordDay(CorpID, DateTime.Today);
            if (records == null)
                records = new List<Model.InspectRecord>();
 
            var allStations = new IStation.Service.Station().GetByCorpID(CorpID);
 
            //暂时不按距离排序
            List<IStation.Dto.ProductInspectStatus> items = new List<IStation.Dto.ProductInspectStatus>();
            foreach (var product in products)
            {
                IStation.Dto.ProductInspectStatus vm = new IStation.Dto.ProductInspectStatus();
                vm.ProductID = product.ID;
                vm.ProductCode = product.Code;
                vm.Catalog = product.Catalog;
 
                vm.BelongID = product.BelongID;
                vm.BelongType = product.BelongType;
 
                if (vm.BelongType == IStation.ObjectType.Station)
                {//带上泵站名字
                    vm.ProductName = string.Format("{0}({1})",
                        vm.ProductName, (from x in allStations where x.ID == product.BelongID select x.Name).FirstOrDefault());
                }
                else
                {
                    vm.ProductName = product.Name;
                }
 
                var record = records.Find(x => x.ProductID == product.ID);
                if (record != null)
                {
                    vm.RecordID = record.ID;
                    vm.WorryCount = record.WorryCount;
                    vm.ProgressInfo = record.ProgressInfo;
                    vm.CompleteStatus = (int)record.CompleteStatus;
                }
 
                items.Add(vm);
            }
 
            //暂时不按经纬度排序
            //if (PosiX > 0.001 && PosiY > 0.001)
            //{
            //}
 
 
            return items;
        }
 
        /// <summary>
        /// 根据公司,获取所有巡检配置的产品列表
        /// </summary>
        /// <param name="CorpID"></param>
        /// <returns></returns>
        private List<IStation.Model.Product> GetProductByCorpID(long CorpID)
        {
            IStation.Service.InspectionContentBundle service_Content = new Service.InspectionContentBundle();
            var product_ids = service_Content.GetProductIDList(CorpID);
            if (product_ids == null || product_ids.Count() == 0)
            {
                return null;
            }
 
            IStation.Service.Product service_product = new Service.Product();
            var all_products = service_product.GetByCorpID(CorpID);
 
            List<IStation.Model.Product> products = (from x in all_products where product_ids.Contains(x.ID) select x).ToList();
            return products;
        }
 
 
        /// <summary>
        /// 保存输入数据
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [Route("SaveRecordDetails")]
        [HttpPost]
        public IStation.Model.InspectRecord SaveRecordDetails(IStation.Dto.SaveRecordDetails_Request request)
        {
            if (request == null)
                throw new Exception("内容为空");
            if (string.IsNullOrEmpty(request.DetailContent))
                throw new Exception("内容为空");
 
            var sss = request.DetailContent.Split(new string[] { "$$$" }, StringSplitOptions.RemoveEmptyEntries);
 
            List<Model.InspectRecordDetailBase> details = new List<Model.InspectRecordDetailBase>();
 
            foreach (var s in sss)
            {
                var vvv = s.Split(new string[] { "###" }, StringSplitOptions.None);
 
                var detailID = Convert.ToInt64(vvv[0]);
                var status = Convert.ToInt32(vvv[1]);
 
                var detailValue = vvv[2];
                if (string.IsNullOrEmpty(detailValue) || string.IsNullOrWhiteSpace(detailValue) || detailValue == "null")
                    detailValue = null;
 
                details.Add(new Model.InspectRecordDetailBase() { ID = detailID, Value = detailValue, Status = status });
            }
 
            var blank_count = (from x in details where string.IsNullOrEmpty(x.Value) select x).Count();
 
            IStation.Model.InspectRecord Record = new IStation.Model.InspectRecord();
            Record.ID = request.RecordID;
            Record.ProductID = request.ProductID;
            Record.WorryCount = (from x in details where x.Status == 2 select x).Count();
            Record.ProgressInfo = string.Format("{0}/{1}", details.Count() - blank_count, details.Count());
            Record.Note = request.Note;
 
            if (blank_count == 0)
            {
                Record.CompleteStatus = IStation.Model.InspectRecord.eCompleteStatus.巡检完成;
            }
            else if (details.Count() - blank_count > 0)
            {
                Record.CompleteStatus = IStation.Model.InspectRecord.eCompleteStatus.巡检中;
            }
            else
            {
                Record.CompleteStatus = IStation.Model.InspectRecord.eCompleteStatus.未巡检;
            }
 
 
            Record.RecordDay = DateTime.Today.ToString("yyyy-MM-dd");
 
            IStation.Service.InspectRecord service_Record = new Service.InspectRecord();
            bool ret = service_Record.UpdateRecord(Record, details);
 
            return Record;
        }
 
 
 
        #endregion
 
 
        #region 根根据月份,统计 , 某日的巡检人数 
        /// <summary>
        /// 根据月份,统计 , 某日的巡检人数 ,为0表示没人巡检
        /// </summary>
        /// <param name="CorpID">公司ID</param>
        /// <param name="Year">年</param>
        /// <param name="Month">月</param> 
        /// <returns></returns>
        [Route("GetDayEmployeeCountByMonth")]
        [HttpGet]
        public List<DayAndEmployeeCount> GetDayEmployeeCountByMonth(long CorpID, int Year, int Month)
        {
            IStation.Service.InspectRecord service_Record = new Service.InspectRecord();
 
            var start_day = new DateTime(Year, Month, 1);
            var end_day = start_day.AddMonths(1).AddDays(-1);
 
            var ds_records = service_Record.GetDayEmployeeCountByDay(CorpID, start_day, end_day);
 
            List<DayAndEmployeeCount> records = new List<DayAndEmployeeCount>();
            if (ds_records == null || ds_records.Count() == 0)
            {
                return new List<DayAndEmployeeCount>();
            }
            for (int d = 1; d <= DateTime.DaysInMonth(Year, Month); d++)
            {
                records.Add(new DayAndEmployeeCount()
                {
                    Day = d,
                    Count = (from x in ds_records
                             where x.RecordDay.Day == d
                             select x.Count).FirstOrDefault()
                });
            }
 
            return records;
        }
 
 
        /// <summary>
        /// 
        /// </summary>
        public class DayAndEmployeeCount
        {
            /// <summary>
            /// 
            /// </summary>
            public int Day { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public int Count { get; set; }
        }
        #endregion
 
 
        #region 根据日期 查询巡检记录
        /// <summary>
        /// 根据日期 查询巡检记录
        /// </summary>
        /// <param name="CorpID">公司ID</param>
        /// <param name="Day">日期</param> 
        /// <returns></returns>
        [Route("GetRecordListByDay")]
        [HttpGet]
        public List<Dto.InspectRecordItem> GetRecordListByDay(long CorpID, string Day)
        {
            IStation.Service.InspectRecord service_Record = new Service.InspectRecord();
 
            DateTime t = DateTime.Today.AddDays(-1);
            DateTime.TryParse(Day, out t);
 
            var allEmployees = new IStation.Service.Employee().GetByCorpID(CorpID);
            var allProducts = new IStation.Service.Product().GetByCorpID(CorpID);
            var allStations = new IStation.Service.Station().GetByCorpID(CorpID);
 
            var ds_records = service_Record.GetByRecordDay(CorpID, t);
            List<IStation.Dto.InspectRecordItem> vs = new List<IStation.Dto.InspectRecordItem>();
            if (ds_records != null)
            {
                foreach (var record in ds_records)
                {
                    IStation.Dto.InspectRecordItem vm = new IStation.Dto.InspectRecordItem(record);
                    vm.EmployeeName = (from x in allEmployees where x.ID == record.EmployeeID select x.Name).FirstOrDefault();
                    if (vm.EmployeeName == null)
                        vm.EmployeeName = "";
 
                    var product = (from x in allProducts where x.ID == record.ProductID select x).FirstOrDefault();
                    if (product != null)
                    {
                        vm.ProductName = product.Name;
                        // vm.ProductNO = product.Code;
                        vm.ProductCode = product.Code;
                    }
 
 
                    if (product.BelongType == IStation.ObjectType.Station)
                    {
                        vm.ProductName = string.Format("{0}({1})", vm.ProductName,
                            (from x in allStations where x.ID == product.BelongID select x.Name).FirstOrDefault());
                    }
 
                    vs.Add(vm);
                }
            }
 
 
            return vs;
        }
 
        #endregion
 
 
        #region 根据产品获取巡检记录
        /// <summary>
        /// 获取所有 巡检配置的产品
        /// </summary>
        /// <param name="CorpID">公司ID</param>
        /// <returns></returns>
        [Route("GetAllInspectProduct")]
        [HttpGet]
        public List<Dto.ProductInspectLastRecord> GetAllInspectProduct(long CorpID)
        {
            var products = GetProductByCorpID(CorpID);
            if (products == null || products.Count() == 0)
                throw new Exception("未配置巡检项");
 
            var allEmployee = new Service.Employee().GetByCorpID(CorpID);
            var allStations = new IStation.Service.Station().GetByCorpID(CorpID);
 
 
            IStation.Service.InspectRecord service_Record = new Service.InspectRecord();
            var records = service_Record.GetProductLastRecordByCorpID(CorpID);
                //GetProductLastRecordByProductID((from x in products select x.ID).ToList());//最后一条巡检记录
            if (records == null)
                records = new List<IStation.Model.InspectRecord>();
 
            var worrys = service_Record.GetWorryCountStaticByProduct(CorpID, DateTime.Now.AddMonths(-1), DateTime.Now);
            if (worrys == null)
                worrys = new List<Model.Inspect.ProductWorryCountStatic>();
 
            List<Dto.ProductInspectLastRecord> items = new List<Dto.ProductInspectLastRecord>();
            foreach (var product in products)
            {
                Dto.ProductInspectLastRecord vm = new Dto.ProductInspectLastRecord();
                vm.ProductID = product.ID;
                vm.ProductName = product.Name;
                vm.ProductCode = product.Code;
 
                vm.Catalog = product.Catalog;
 
                vm.BelongID = product.BelongID;
                vm.BelongType = product.BelongType;
 
                if (product.BelongType == IStation.ObjectType.Station)
                {
                    vm.ProductName = string.Format("{0}({1})", vm.ProductName, (from x in allStations where x.ID == product.BelongID select x.Name).FirstOrDefault());
                }
 
                var record = records.Find(x => x.ProductID == product.ID);
                if (record != null)
                {
                    vm.RecordID = record.ID;
                    vm.LastRecordDay = record.RecordDay;
                    vm.LastInpectEmployee = (from x in allEmployee where x.ID == record.EmployeeID select x.Name).FirstOrDefault();
 
                    vm.WorryCount = record.WorryCount;
                    vm.ProgressInfo = record.ProgressInfo;
                    vm.CompleteStatus = (int)record.CompleteStatus;
                }
 
                var worry = worrys.Find(x => x.ProductID == product.ID);
                if (worry != null)
                {
                    vm.WorryCount = worry.WorryCount;
                }
 
 
 
                items.Add(vm);
            }
 
 
 
 
            return items;
        }
 
 
        /// <summary>
        /// 根据产品 查询巡检记录(获取分页数据)
        /// </summary>
        /// <param name="CorpID">公司ID</param>
        /// <param name="ProductID"> </param> 
        /// <param name="PageIndex">页码序号(从0开始)</param>
        /// <param name="PageSize">每一页的条数</param>
        /// <returns></returns>
        [Route("GetPageListByProduct")]
        [HttpGet]
        public List<Dto.InspectRecordItem> GetPageListByProduct(long CorpID, long ProductID, int PageIndex, int PageSize)
        {
            IStation.Service.InspectRecord service_Record = new Service.InspectRecord();
 
            var allEmployees = new Service.Employee().GetByCorpID(CorpID);
            var allProducts = new IStation.Service.Product().GetByCorpID(CorpID);
 
            int total = 0;
            var ds_records = service_Record.GetPageListByProductID(PageIndex, PageSize, CorpID, ProductID, out total);
            List<Dto.InspectRecordItem> vs = new List<Dto.InspectRecordItem>();
            if (ds_records != null)
            {
                foreach (var record in ds_records)
                {
                    Dto.InspectRecordItem v = new Dto.InspectRecordItem(record);
                    v.EmployeeName = (from x in allEmployees where x.ID == record.EmployeeID select x.Name).FirstOrDefault();
                    if (v.EmployeeName == null)
                        v.EmployeeName = "";
                    //var product = (from x in allProducts where x.ID == record.ProductID select x).FirstOrDefault();
                    //if (product != null)
                    //{
                    //    v.ProductName = product.Name;
                    //    v.ProductNO = product.NO;
                    //    v.ProductCode = product.Code;
                    //}
 
                    vs.Add(v);
                }
            }
 
 
            return vs;
        }
 
        #endregion
 
 
        #region 根据员工获取巡检记录
 
        /// <summary>
        /// 获取所有巡检员
        /// </summary>
        /// <param name="CorpID"></param>
        /// <returns></returns>
        [Route("GetAllInspectEmployee")]
        [HttpGet]
        public List<IStation.Dto.InspectorBase> GetAllInspectEmployee(long CorpID)
        {
            IStation.Service.Employee service_employee = new Service.Employee();
            var allEmployee = service_employee.GetByFlag(CorpID,IStation.LogicFlags.巡检员);
            if (allEmployee == null || allEmployee.Count() == 0)
            {
                return null;
            }
 
 
            IStation.Service.InspectRecord service_Record = new Service.InspectRecord();
            var records = service_Record.GetEmployeeLastRecord(CorpID);//最后一条巡检记录
            if (records == null)
                records = new List<IStation.Model.InspectRecord>();
 
            List<IStation.Dto.InspectorBase> vm_list = new List<IStation.Dto.InspectorBase>();
            foreach (var employee in allEmployee)
            {
                IStation.Dto.InspectorBase vm_model = new IStation.Dto.InspectorBase();
                vm_model.EmployeeID = employee.ID;
                vm_model.RealName = employee.Name;
                vm_model.LastInsepectDay = "未巡检过";
                var record = (from x in records where x.EmployeeID == employee.ID select x).FirstOrDefault();
                if (record != null)
                {
                    vm_model.LastInsepectDay = record.RecordDay;
                }
                vm_list.Add(vm_model);
            }
 
            return new List<IStation.Dto.InspectorBase>(vm_list);
        }
 
  
 
        /// <summary>
        /// 根据产品 查询巡检记录(获取分页数据)
        /// </summary>
        /// <param name="CorpID">公司ID</param>
        /// <param name="EmployeeID"> </param> 
        /// <param name="PageIndex">页码序号(从0开始)</param>
        /// <param name="PageSize">每一页的条数</param>
        /// <returns></returns>
        [Route("GetPageListByEmployee")]
        [HttpGet]
        public List<Model.Inspect.RecordDayEmployeeStatic> GetPageListByEmployee(long CorpID, long EmployeeID, int PageIndex, int PageSize)
        {
            IStation.Service.InspectRecord service_Record = new Service.InspectRecord();
 
            var ds_records = service_Record.GetPageListByEmployeeID(PageIndex, PageSize, EmployeeID);
 
            return ds_records;
        }
 
 
        #endregion
 
 
        #region 获取某产品某日的巡检项目明细
        /// <summary>
        /// 获取某产品某日的巡检项目明细
        /// </summary>
        /// <param name="CorpID"></param>
        /// <param name="ProductID"></param>
        /// <param name="EmployeeID"></param>
        /// <param name="Day"></param>
        [Route("GetRecordDetail")]
        [HttpGet]
        public IStation.Dto.InspectRecordContent4Ing GetRecordDetail(long CorpID, long ProductID, long EmployeeID, string Day)
        {
            IStation.Service.InspectRecord service_Record = new Service.InspectRecord();
            IStation.Service.InspectionContentBundle service_Content = new Service.InspectionContentBundle();
 
            var contents = service_Content.GetByProductID(CorpID, ProductID);
            if (contents == null || contents.Count() == 0)
            {
                throw new Exception("未配置巡检项");
            }
 
 
            var model_record = service_Record.GetByProductID(ProductID, DateTime.Parse(Day));
            if (model_record == null || model_record.Details == null || model_record.Details.Count() == 0)
            {
                throw new Exception("未找到巡检记录");
            }
 
            List<Dto.InspectRecordDetail> vm_list = new List<Dto.InspectRecordDetail>();
            foreach (var content in contents)
            {
                Dto.InspectRecordDetail detail_vm = new Dto.InspectRecordDetail();
                detail_vm.ContentID = content.ItemID;
                detail_vm.Name = content.ItemName;
                detail_vm.ValueType = content.ValueType;
                detail_vm.ValueNullAble = content.ValueNullAble;
                detail_vm.ValueRangeMin = content.ValueRangeMin;
                detail_vm.ValueRangeMax = content.ValueRangeMax;
                detail_vm.TipInfo = content.TipInfo;
                detail_vm.MonitorPointID = content.MonitorPointID;
                detail_vm.GroupName = content.GroupName;
                detail_vm.ValueList = content.ValueList;
 
                var ds_detail = model_record.Details.Find(x => x.ContentID == content.ItemID);
                if (ds_detail == null)
                {
                    detail_vm.DetailID = 0;
                    detail_vm.Value = "未填写";
                }
                else
                {
                    detail_vm.DetailID = ds_detail.ID;
                    detail_vm.Value = ds_detail.Value;
                    detail_vm.ValueStatus = ds_detail.Status;
                }
 
                vm_list.Add(detail_vm);
            }
 
            var files = new IStation.Service.InspectRecordFile().GetByRecordID(model_record.Record.ID);
 
            IStation.Dto.InspectRecordContent4Ing vm_record = new IStation.Dto.InspectRecordContent4Ing();
            vm_record.Details = vm_list;
            vm_record.RecordID = model_record.Record.ID;
            vm_record.Note = model_record.Record.Note;
 
            if (files != null && files.Count > 0)
            {
                vm_record.Files = (from x in files
                                   select new IStation.Dto.InspectFile()
                                   {
                                       ID = x.ID,
                                       Path = string.Format("http://api.beng35.com/Repair/InspectRecordFile/{0}/{1}", model_record.Record.ID, x.DataSetFile),
                                       ThumbPath = string.Format("http://api.beng35.com/Repair/InspectRecordFile/{0}/{1}", model_record.Record.ID, x.DataSetFile.Replace(".", "_th."))
                                   }).ToList();
            }
 
            return vm_record;
        }
        #endregion
 
 
 
        #region 获取某巡检点的历史记录
 
        /// <summary>
        /// 获取某巡检点的历史记录
        /// </summary>
        /// <param name="CorpID"></param>
        /// <param name="ContentID"></param>
        /// <param name="StartDay"></param>
        /// <param name="EndDay"></param>
        /// <returns></returns>
        [Route("GetContentHistoryValueList")]
        [HttpGet]
        public List<ContentDetailHistoryValueItem> GetContentHistoryValueList(long CorpID, long ContentID, string StartDay, string EndDay)
        {
            if (CorpID <= 0)
            {
                throw new Exception("CorpID未设置");
            }
            if (ContentID <= 0)
            {
                throw new Exception("ContentID未设置");
            }
            IStation.Service.InspectRecord service_Record = new Service.InspectRecord();
 
            int Year = DateTime.Today.Year;
            DateTime startTimeT = DateTime.Now.AddDays(-30);
            DateTime endTimeT = DateTime.Now;
            if (!string.IsNullOrEmpty(StartDay))
            {
                startTimeT = DateTime.Parse(StartDay);
                Year = DateTime.Parse(StartDay).Year;
            }
            if (!string.IsNullOrEmpty(EndDay))
                endTimeT = DateTime.Parse(EndDay);
 
            var details = service_Record.GetDetailByContentID(ContentID, startTimeT, endTimeT);
            if (details == null || details.Count() == 0)
            {
                throw new Exception("未配置巡检記錄");
            }
 
            var records = service_Record.GetRecordByContentID(ContentID, startTimeT, endTimeT);
            if (records == null || records.Count() == 0)
            {
                throw new Exception("未配置巡检記錄");
            }
 
            var allEmployees = new Service.Employee().GetByCorpID(CorpID);
 
            List<ContentDetailHistoryValueItem> vm_list = new List<ContentDetailHistoryValueItem>();
            foreach (var detail in details)
            {
                //if (detail.Time < startTimeT)
                //    continue;
                //if (detail.Time > endTimeT)
                //    continue;
 
                ContentDetailHistoryValueItem detail_vm = new ContentDetailHistoryValueItem();
                detail_vm.DetailID = detail.ID;
                detail_vm.Value = detail.Value;
                detail_vm.Status = detail.Status;
                detail_vm.Time = detail.Time.ToString("yyyy-MM-dd HH:mm:ss");
 
                var record = records.Find(x => x.ID == detail.RecordID);
                if (record != null)
                {
                    detail_vm.EmployeeName = (from x in allEmployees where x.ID == record.EmployeeID select x.Name).FirstOrDefault();
                }
 
                vm_list.Add(detail_vm);
            }
 
 
 
 
            return vm_list;
        }
        #endregion
 
        /// <summary>
        /// 
        /// </summary>
        public class ContentDetailHistoryValueItem
        {
            #region Model
            /// <summary>
            /// 标识
            /// </summary>    
            public long DetailID { get; set; }
 
            /// <summary>
            ///  填写的值
            /// </summary>
            public string Value { get; set; } = "";
 
            /// <summary>
            /// 状态  2 隐患  3 已报修
            /// </summary>
            public int Status { get; set; }
 
            /// <summary>
            /// 填写时间
            /// </summary>
            public string Time { get; set; } = "";
 
            /// <summary>
            /// 巡检人
            /// </summary>
            public string EmployeeName { get; set; } = "";
            #endregion
        }
 
 
 
 
 
 
 
 
 
 
 
    }
}