1
yanjinhui
6 天以前 a3b1d7bfe497ca5ece2a51eb15a5534a98b33dcb
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AutoMapper;
using SqlSugar;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.BaseRepository;
using WIDESEAWCS_Core.BaseServices;
using WIDESEAWCS_ITelescopicService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_DTO;
using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
using WIDESEAWCS_DTO.Telescopic;
using SqlSugar.DistributedSystem.Snowflake;
using System.IO;
using System.Net;
 
namespace WIDESEAWCS_TelescopicService
{
    public class MaintenanceService : ServiceBase<Dt_Maintenance, IRepository<Dt_Maintenance>>, IMaintenanceService
    {
        public IRepository<Dt_Maintenance> Repository => BaseDal;
        public readonly IRepository<Dt_MaintenanceTeam> _team;
        private readonly IRepository<Dt_CustomIPaddress> _ipaddress;
        private readonly IRepository<Sys_User> _user;
        
       
 
        public MaintenanceService(IRepository<Dt_CustomIPaddress>ipaddress,IRepository<Dt_Maintenance> BaseDal, IRepository<Sys_User> user, IRepository<Dt_MaintenanceTeam> team) : base(BaseDal)
        {
            _user = user;
            _team = team;
            _ipaddress = ipaddress;
        }
 
 
 
        /// <summary>
        /// 设置检修权限
        /// </summary>
        /// <param name="pagination"></param>
        /// <returns></returns>
        public WebResponseContent ShowMaintence(PaginationDTO pagination)
        {
            try
            {
                int totalCount = 0;
                var sys = _user.Db.Queryable<Sys_User>().Where(x=>x.Enable==1);
                var main = Db.Queryable<Dt_Maintenance>();
 
                var query = sys.InnerJoin<Dt_Maintenance>((a, b) => a.UserName == b.UserAccount);
 
                // 筛选搜索关键字(无论admin还是普通用户都适用)
                if (!string.IsNullOrEmpty(pagination.searchKeyword))
                {
                    query = query.Where((a, b) =>
                       a.UserTrueName.Contains(pagination.searchKeyword) ||
                       a.UserName.Contains(pagination.searchKeyword) ||
                       a.CardNumber.ToString().Contains(pagination.searchKeyword) ||
                       a.Userteam.Contains(pagination.searchKeyword)
                    );
                }
 
                // 如果不是管理员,根据部门过滤
                if (pagination.account != "admin")
                {
                    var currentUser = _user.Db.Queryable<Sys_User>()
                        .Where(u => u.UserName == pagination.account)
                        .First();
 
                    if (currentUser == null)
                    {
                        return new WebResponseContent { Status = false, Data = "未获取到用户信息" };
                    }
 
                    int? deptId = currentUser.Dept_Id;
 
                    query = query.Where((a, b) => a.Dept_Id == deptId);
                }
                // 执行分页查询
                var result = query.Select((a, b) => new
                {
                    b.ID,
                    a.UserTrueName,
                    a.UserName,
                    a.CardNumber,
                    a.Userteam,
                    a.HeadImageUrl,
                    b.IsPossible
                }).ToPageList(pagination.pageIndex, pagination.pageSize, ref totalCount);
 
                return new WebResponseContent
                {
                    Status = true,
                    Data = new
                    {
                        TotalCount = totalCount,
                        PageIndex = pagination.pageIndex,
                        PageSize = pagination.pageSize,
                        Items = result
                    }
                };
            }
            catch (Exception ex)
            {
                return new WebResponseContent { Status = false, Data = ex.Message };
            }
        }
 
 
 
 
 
        /// <summary>
        /// 人员监控(数字大屏)
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="searchKeyword"></param>
        /// <returns></returns>
        //public WebResponseContent PersonnelMonitoring(PaginationDTO pagination)
        //{
        //    try
        //    {
        //        int totalCount = 0;
        //        var sys = _user.Db.Queryable<Sys_User>();
 
 
        //        var query = sys.InnerJoin<Dt_Maintenance>((a, b) => a.UserName == b.UserAccount)
        //                        .RightJoin<Dt_CustomIPaddress>((a,b,c)=>b.IPAddress==c.IPaddress)
        //                      .Where((a, b) => b.MaintenanceStatus==1); // 展示运行检修的
 
        //        // 搜索关键字
        //        if (!string.IsNullOrEmpty(pagination.searchKeyword))
        //        {
        //            query = query.Where((a, b) =>
        //                a.UserTrueName.Contains(pagination.searchKeyword) ||
        //                a.Userteam.Contains(pagination.searchKeyword));
        //        }
 
        //        var result = query
        //            .Select((a, b,c) => new
        //            {
        //                b.UserAccount,//账号
        //                a.UserTrueName,
        //                a.Userteam,//班组
        //                a.Unit,//单位
        //                a.RoleName,//角色名称
        //                //b.IPAddress,//站台
        //                IPAddress = c.Addressname ?? b.IPAddress, // 优先显示自定义名称
        //                b.ID,//id
        //                b.MaintenanceStatus,//检修状态
        //                b.CreateDate,//日期
        //                b.MaintenancStartTime,//开始时间
        //            })
        //            .ToPageList(pagination.pageIndex, pagination.pageSize, ref totalCount);
 
        //        return new WebResponseContent
        //        {
        //            Status = true,
        //            Data = new
        //            {
        //                TotalCount = totalCount,
        //                PageIndex = pagination.pageIndex,
        //                PageSize = pagination.pageSize,
        //                Items = result
        //            }
        //        };
        //    }
        //    catch (Exception ex)
        //    {
        //        return new WebResponseContent { Status = false, Data = ex.Message };
        //    }
        //}
        public WebResponseContent PersonnelMonitoring(PaginationDTO pagination)
        {
            try
            {
                int totalCount = 0;
 
                var query = _user.Db.Queryable<Dt_Maintenance>()
                    .Where(b => b.MaintenanceStatus == 1)
                    .InnerJoin<Sys_User>((b, a) => b.UserAccount == a.UserName)
                    .LeftJoin<Dt_CustomIPaddress>((b, a, c) => b.IPAddress == c.IPaddress);
 
                if (!string.IsNullOrEmpty(pagination.searchKeyword))
                {
                    query = query.Where((b, a, c) =>
                        a.UserTrueName.Contains(pagination.searchKeyword) ||
                        a.Userteam.Contains(pagination.searchKeyword));
                }
 
                var result = query.Select((b, a, c) => new
                {
                    b.UserAccount,
                    a.UserTrueName,
                    a.Userteam,
                    a.Unit,
                    a.RoleName,
                    IPAddress = c.Addressname ?? b.IPAddress ?? "无IP",
                    b.ID,
                    b.MaintenanceStatus,
                    b.CreateDate,
                    b.MaintenancStartTime
                }).ToPageList(pagination.pageIndex, pagination.pageSize, ref totalCount);
 
                return new WebResponseContent
                {
                    Status = true,
                    Data = new { totalCount, pagination.pageIndex, pagination.pageSize, result }
                };
            }
            catch (Exception ex)
            {
                return new WebResponseContent { Status = false, Message = ex.Message };
            }
        }
 
 
 
 
 
        /// <summary>
        /// 更新状态强制下线(添加了检修记录
        /// </summary>
        /// <param name="id">要强制谁下线</param>
        /// <param name="account">登入人员账号</param>
        /// <param name="LocalIP">地址ip</param>
        /// <returns></returns>
        public WebResponseContent RunOperation(int id, string account, string LocalIP)
        {
            try
            {
                // 1. 查找目标用户(要被强制下线的人)
                var maint = BaseDal.QueryData().FirstOrDefault(x => x.ID == id);
                if (maint==null)
                {
                    return new WebResponseContent { Status = false, Message = "没有找到该用户" };
                }
                var sysuer = _user.QueryData(x => x.UserName == maint.UserAccount).FirstOrDefault();//user表
               
               
 
                // 2. 查找当前登录用户(执行操作的人)
                var currentUser = _user.QueryData(x => x.UserName == account).FirstOrDefault();
                if (currentUser == null)
                {
                    return new WebResponseContent { Status = false, Message = "当前登录用户无效" };
                }
 
                // 3. 权限检查:当前用户是 admin 或 当前用户是组长(IsLeader == 1)
                bool isAdmin = account == "admin";
                bool isLeader = currentUser.IsLeader == 1;  // 假设 Sys_User 表有 IsLeader 字段
 
                if (!isAdmin && !isLeader)
                {
                    return new WebResponseContent { Status = false, Message = "你没有权限强制下线" };
                }
 
                // 4. 执行强制下线
                maint.MaintenanceStatus = 0;  // 改变状态为下线
                BaseDal.UpdateData(maint);
 
                var ip = LocalIP?.Replace("::ffff:", "") ?? ""; // 如果 LocalIP 是 null,ip 会是 ""
 
                // 5. 记录操作日志
                var recording = new Dt_MaintenanceTeam
                {
                    Account = maint.UserAccount,
                    MaintenanceStatus = 0,
                    OperatorName = sysuer.UserTrueName,  // 操作人姓名
                    TeamName = sysuer.RoleName,         // 操作人角色
                    DistributionTime = DateTime.Now,
                    IPAddress = ip,
                };
                _team.AddData(recording);
 
                return new WebResponseContent { Status = true, Message = "强制下线成功" };
            }
            catch (Exception ex)
            {
                return new WebResponseContent { Status = false, Message = "失败:" + ex.Message };
            }
        }
 
 
        /// <summary>
        /// 更改状态(暂时没有用到)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public WebResponseContent ChangeTasState(int id)
        {
            try
            {
                var change = BaseDal.QueryFirst(x => x.ID == id);
                //将数据库中的int 值转为 枚举型
                if (!Enum.IsDefined(typeof(Maint), change.MaintenanceStatus))
                {
                    return new WebResponseContent { Status = false, Message = "当前状态不合法,无法更新" };
                }
 
                Maint Status = (Maint)change.MaintenanceStatus; //int ->枚举
 
                switch (Status)
                {
                    case Maint.待开始:
                        change.MaintenanceStatus = (int)Maint.检修中;
                        change.MaintenancStartTime = DateTime.Now;
                        break;
                    case Maint.检修中:
                        change.MaintenanceStatus = (int)Maint.已完成;
                        break;
                    case Maint.已完成:
                        change.MaintenancEendTime = DateTime.Now;
                        return new WebResponseContent { Status = false, Message = "当前任务已完成" };
                    default:
                        return new WebResponseContent { Status = false, Message = "更新失败" };
                }
                return new WebResponseContent { Status = true, Data = change };
            }
            catch (Exception ex)
            {
 
                return new WebResponseContent { Status = false, Message = "错误:" + ex };
            }
 
 
        }
 
        /// <summary>
        /// 检修操作记录
        /// </summary>
        /// <param name="pageIndex">页数</param>
        /// <param name="pageSize">一页多少个数据</param>
        /// <returns></returns>
        public WebResponseContent MaintenanceOperationRecord(PaginationDTO pagination)
        {
            try
            {
                int totalCount = 0;
                var sys = _user.Db.Queryable<Sys_User>();
                var main = Db.Queryable<Dt_Maintenance>();
 
                //模糊查询
                var query = sys.InnerJoin<Dt_Maintenance>((a, b) => a.UserName == b.UserAccount);
                if (!string.IsNullOrEmpty(pagination.searchKeyword))
                {
                    query = query.Where((a, b) =>
                        a.UserTrueName.Contains(pagination.searchKeyword)||
                        a.Userteam.Contains(pagination.searchKeyword)||
                        a.HeadImageUrl.Contains(pagination.searchKeyword)
                    );
                }
                //时间查询
                if (pagination.startDate.HasValue && pagination.endDate.HasValue)
                {
                    query = query.Where((a, b) => b.MaintenancStartTime >= pagination.startDate.Value && b.MaintenancStartTime <= pagination.endDate.Value);
                }
                //排序
                if (!string.IsNullOrEmpty(pagination.sortField))
                {
                    var isAcs = pagination.sortOrder?.ToLower() == "asc";
                    query = pagination.sortField.ToLower() switch
                    {
                       
 
                        "maintenancstarttime" => isAcs ? query.OrderBy((a, b) => b.MaintenancStartTime) : query.OrderByDescending((a, b) => b.MaintenancStartTime),
 
                        "maintenancenendtime" => isAcs ? query.OrderBy((a, b) => b.MaintenancEendTime) : query.OrderByDescending((a, b) => b.MaintenancEendTime),
 
                        _ => query.OrderByDescending((a, b) => b.Creater) // 默认按创建时间降序
                    };
 
                }
                else
                {
                  query=query.OrderByDescending((a, b) => b.Creater);
                }
 
              
                //返回结果
                var result = query.Select((a, b) => new
                {
                    a.UserTrueName,
                    a.Userteam,
                    a.HeadImageUrl,
                    a.Dept_Id,
                    b.MaintenancStartTime,
                    b.MaintenancEendTime,
                }).ToPageList(pagination.pageIndex, pagination.pageSize, ref totalCount);
 
                return new WebResponseContent
                {
                    Status = true,
                    Data = new
                    {
                        TotalCount = totalCount,//总数
                        PageIndex = pagination.pageIndex,//页数
                        PageSize = pagination.pageSize,//一页多少个数据
                        Items = result
                    }
                };
            }
            catch (Exception ex)
            {
 
                return new WebResponseContent { Status = false, Message = "错误信息:" + ex.Message };
            }
        }
 
 
        /// <summary>
        /// 查看今天的检修任务(运行检修隐藏了,这个接口也用不道)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public WebResponseContent MaintenanceTasksOfTheDay(string account)
        {
            try
            {
                var today = DateTime.Today;               // 今天的零点
                var tomorrow = today.AddDays(1);         // 明天的零点
 
                var query = _user.Db.Queryable<Sys_User>()
                    .InnerJoin<Dt_Maintenance>((a, b) => a.UserName == b.UserAccount)
                    .Where((a, b) => b.IsPossible == "true" && b.UserAccount == account &&
                    b.MaintenanceDate >= today && b.MaintenanceDate < tomorrow).Select((a, b) => new
                    {
                        b.ID,
                        a.UserTrueName,
                        a.UserName,
                        a.CardNumber,
                        a.Userteam,
                        a.HeadImageUrl,
                        b.IsPossible,
                        b.MaintenanceDate,
                        b.MaintenancStartTime,
                        b.MaintenancEendTime,
                    }).ToList();
                if (query == null)
                {
                    return new WebResponseContent { Status = false, Message = "你今天没有检修任务" };
                }
 
 
 
                return new WebResponseContent { Status = true, Data = query };
            }
            catch (Exception ex)
            {
 
                return new WebResponseContent { Status = false, Message = "错误信息:" + ex.Message };
            }
 
        }
 
        /// <summary>
        /// 看今天的检修任务(运行检修隐藏了,这个接口也用不道)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        //public WebResponseContent MaintenanceTasksOfTheDay(string account)
        //{
        //    try
        //    {
 
        //        var query = _user.Db.Queryable<Sys_User>()
        //            .InnerJoin<Dt_Maintenance>((a, b) => a.UserName == b.UserAccount)
        //            .Where((a,b) =>  b.UserAccount == account ).Select((a, b) => new
        //            {
        //                b.ID,
        //                a.UserTrueName,
        //                a.UserName,
        //                a.CardNumber,
        //                a.Userteam,
        //                a.HeadImageUrl,
        //                b.IsPossible,
        //                b.MaintenanceStatus,
        //                b.MaintenanceDate,
        //                b.MaintenancStartTime,
        //                b.MaintenancEendTime,
        //            }).ToList();
        //        if (query == null)
        //        {
        //            return new WebResponseContent { Status = false, Message = "你今天没有检修任务" };
        //        }
 
 
 
        //        return new WebResponseContent { Status = true, Data = query };
        //    }
        //    catch (Exception ex)
        //    {
 
        //        return new WebResponseContent { Status = false, Message = "错误信息:" + ex.Message };
        //    }
 
        //}
 
 
 
        /// <summary>
        /// 开始检修
        /// </summary>
        /// <param name="account">账号</param>
        /// <param name="LocalIP">那台电脑登入的ip地址</param>
        /// <returns></returns>
        public WebResponseContent StartMaintenceTask(string account, string LocalIP)
        {
            try
            {
                var user = BaseDal.QueryData();//检修表
                var maint = user.Where(x => x.UserAccount == account).FirstOrDefault(); //在检修表中先找到该用户
                var sysuer = _user.QueryData(x => x.UserName == account).FirstOrDefault();//在用户表中找到用户
                
                if (maint == null || sysuer == null)
                {
                    return new WebResponseContent { Status = false, Message = "没有找到该用户" };
                }
                // 查找该用户在 Dt_MaintenanceTeam 表中的最新一条记录
                var lastRecord = _team.QueryData(x => x.Account == account)
                                      .OrderByDescending(x => x.CreateDate)
                                      .FirstOrDefault();
 
                if (lastRecord != null && lastRecord.MaintenanceStatus == 1)
                {
                    return new WebResponseContent { Status = false, Message = "你已经在开始检修了,请不要重复点击" };
                }
 
                //先要找到该用户属于那个角色的,这个角色中属于那个什么类型(组长/组员)
                if (maint.IsLeader != 1)//如果该用户不是班长,那么要等班长先做,他才可以做
                {
                    bool leaderStarted = user.Any(x =>  x.IsLeader == 1 && x.MaintenanceStatus == 1); //否有满足条件 找到一条就返回true MaintenanceStatus(0没有开始,1开始)
                    if (!leaderStarted)
                    {
                        return new WebResponseContent { Status = false, Message = "请等待一级人员开始检修" };
                    }
 
                }
               
                var ip = LocalIP?.Replace("::ffff:", "") ?? ""; // 如果 LocalIP 是 null,ip 会是 ""
                //如果满足下面的条件就开始
                maint.MaintenancStartTime = DateTime.Now;//记录开始时间
                maint.MaintenanceStatus = 1;//更改状态
                maint.IPAddress = ip;//更改ip地址
                BaseDal.UpdateData(maint);
                var address = _ipaddress.QueryData(x=>x.IPaddress== ip).FirstOrDefault();
                var addressIp = "";
                if (address!=null) //找到了
                {
                     addressIp = address.Addressname;
                }
                else
                {
                    addressIp = ip;
                }
                //插入记录表
                var recording = new Dt_MaintenanceTeam  //添加记录
                {
                    Account = account,
                    MaintenanceStatus=1,
                    OperatorName = sysuer.UserTrueName,
                    TeamName = sysuer.Userteam,
                    DistributionTime = DateTime.Now,
                    IPAddress = addressIp,
                };
                _team.AddData(recording);
 
                return new WebResponseContent { Status = true, Data = maint, Message = "开始检修" };
            }
            catch (Exception ex)
            {
                return new WebResponseContent { Status = false, Message = "错误信息:" + ex.Message };
            }
        }
 
        /// <summary>
        /// 结束检修
        /// </summary>
        /// <param name="account"></param>
        /// <returns></returns>
        public WebResponseContent StopMaintenanceTask(string account,string LocalIP)
        {
            try
            {
                var user = BaseDal.QueryData(); // 检修表
                var maint = user.Where(x => x.UserAccount == account).FirstOrDefault();
                var sysuer = _user.QueryData(x => x.UserName == account).FirstOrDefault(); // 用户表
 
                if (maint == null || sysuer == null)
                {
                    return new WebResponseContent { Status = false, Message = "没有找到该用户" };
                }
 
                // 查找该用户在 _team 表中的最新一条记录
                var lastRecord = _team.QueryData(x => x.Account == account)
                                    .OrderByDescending(x => x.CreateDate)
                                    .FirstOrDefault();
 
                if (lastRecord == null || lastRecord.MaintenanceStatus != 1)
                {
                    return new WebResponseContent { Status = false, Message = "你还没有开始检修,请先点击开始检修" };
                }
 
                // 检查是否至少有一个组长在场
                var activeLeaders = user.Where(x => x.IsLeader == 1 && x.MaintenanceStatus == 1).ToList();
 
                // 如果当前用户是组长
                if (maint.IsLeader == 1)
                {
                    // 如果是最后一个在场的组长
                    if (activeLeaders.Count == 1 && activeLeaders[0].UserAccount == account)
                    {
                        // 检查是否还有未完成的组员
                        var unfinishedMembers = user.Where(x => x.IsLeader == 0 && x.MaintenanceStatus == 1).Any();
                        if (unfinishedMembers)
                        {
                            return new WebResponseContent
                            {
                                Status = false,
                                Message = "您是最后一个在场的一级人员,请等待所有二级人员完成检修后再结束"
                            };
                        }
                    }
                }
                //if (LocalIP!=maint.IPAddress)
                //{
                //    return new WebResponseContent { Status = false, Message = "操作设备不同,请回到原本设备再点击结束检修" };
                //}
                var address = _ipaddress.QueryData(x => x.IPaddress == LocalIP).FirstOrDefault();
                var ip = LocalIP?.Replace("::ffff:", "") ?? ""; // 如果 LocalIP 是 null,ip 会是 ""
                var addressIp = "";
                if (address != null) //找到了
                {
                    addressIp = address.Addressname;
                }
                else
                {
                    addressIp = ip;
                }
 
                // 更新当前用户的检修状态
                maint.MaintenancEendTime = DateTime.Now; // 记录结束时间
                maint.MaintenanceStatus = 0; // 更改状态
                BaseDal.UpdateData(maint);
 
                // 插入记录表
                var recording = new Dt_MaintenanceTeam  // 添加记录
                {
                    Account = account,
                    MaintenanceStatus = 0,
                    OperatorName = sysuer.UserTrueName,
                    TeamName = sysuer.Userteam,
                    IPAddress = addressIp,
                    EndTime = DateTime.Now,
                };
                _team.AddData(recording);
 
                return new WebResponseContent { Status = true, Data = maint, Message = "完成检修" };
            }
            catch (Exception ex)
            {
                return new WebResponseContent { Status = false, Message = "错误信息:" + ex.Message };
            }
        }
 
 
        /// <summary>
        ///  展示开始检修人员
        /// </summary>
        /// <returns></returns>
        public WebResponseContent YShowStartTake()
        {
            try
            {
                var reslut=BaseDal.QueryData(x => x.MaintenanceStatus == 1).ToList();
                if (reslut.Count<=0)
                {
                    return new WebResponseContent { Status = false, Message = "还没有人开始检修" };
                }
                return new WebResponseContent { Status = true, Data = reslut,Message="检修人员有以下" };
            }
            catch (Exception ex)
            {
 
                return new WebResponseContent { Status = false, Message = ex.Message };
            }
        }
 
        /// <summary>
        /// 状态枚举
        /// </summary>
        private enum Maint
        {
            //待检修=0,
            待开始=0,
            检修中=1,
            已完成=2
 
        }
 
    }
}