From d723d5c1413bb38ceb7d7404f4817e6540c3c2a0 Mon Sep 17 00:00:00 2001
From: yanjinhui <3306209981@qq.com>
Date: 星期四, 12 六月 2025 16:18:33 +0800
Subject: [PATCH] 人脸识别

---
 project/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/MaintenanceService.cs |  272 ++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 184 insertions(+), 88 deletions(-)

diff --git a/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/MaintenanceService.cs b/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/MaintenanceService.cs
index 0454faa..bd567dd 100644
--- a/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/MaintenanceService.cs
+++ b/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/MaintenanceService.cs
@@ -15,6 +15,7 @@
 using WIDESEAWCS_DTO.Telescopic;
 using SqlSugar.DistributedSystem.Snowflake;
 using System.IO;
+using System.Net;
 
 namespace WIDESEAWCS_TelescopicService
 {
@@ -22,14 +23,16 @@
     {
         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_Maintenance> BaseDal, IRepository<Sys_User> user, IRepository<Dt_MaintenanceTeam> team) : base(BaseDal)
+        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;
         }
 
 
@@ -117,58 +120,101 @@
         /// <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 sys = _user.Db.Queryable<Sys_User>();
 
+                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);
 
-                var query = sys.InnerJoin<Dt_Maintenance>((a, b) => a.UserName == b.UserAccount)
-                              .Where((a, b) => b.MaintenanceStatus==1); // 灞曠ず杩愯妫�淇殑
-
-                // 鎼滅储鍏抽敭瀛�
                 if (!string.IsNullOrEmpty(pagination.searchKeyword))
                 {
-                    query = query.Where((a, b) =>
+                    query = query.Where((b, a, c) =>
                         a.UserTrueName.Contains(pagination.searchKeyword) ||
                         a.Userteam.Contains(pagination.searchKeyword));
                 }
 
-                //// 鐘舵�佸弬鏁�
-                //if (pagination.status.HasValue) //澶氫紶涓�涓姸鎬�
-                //{
-                //    query = query.Where((a, b) => b.MaintenanceStatus == pagination.status.Value);
-                //}
-
-                var result = query
-                    .Select((a, b) => new
-                    {
-                        a.UserTrueName,
-                        a.Userteam,//鐝粍
-                        a.Unit,//鍗曚綅
-                        b.MaintenanceStatus,//妫�淇姸鎬�
-                        b.CreateDate,//鏃ユ湡
-                        b.MaintenancStartTime,//寮�濮嬫椂闂�
-                    })
-                    .ToPageList(pagination.pageIndex, pagination.pageSize, ref totalCount);
+                var result = query.Select((b, a, c) => new
+                {
+                    b.UserAccount,
+                    a.UserTrueName,
+                    a.Userteam,
+                    a.Unit,
+                    a.RoleName,
+                    IPAddress = c.Addressname ?? b.IPAddress ?? "鏃營P",
+                    b.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
-                    }
+                    Data = new { totalCount, pagination.pageIndex, pagination.pageSize, result }
                 };
             }
             catch (Exception ex)
             {
-                return new WebResponseContent { Status = false, Data = ex.Message };
+                return new WebResponseContent { Status = false, Message = ex.Message };
             }
         }
 
@@ -177,48 +223,62 @@
 
 
         /// <summary>
-        /// 鏇存柊鐘舵�佹槸鍚﹀厑璁歌繘鍏ユ淇紙娣诲姞浜嗘淇褰曪級
+        /// 鏇存柊鐘舵�佸己鍒朵笅绾匡紙娣诲姞浜嗘淇褰�
         /// </summary>
-        /// <param name="id"></param>
-        /// <param name="ispossible"></param>
+        /// <param name="id">瑕佸己鍒惰皝涓嬬嚎</param>
+        /// <param name="account">鐧诲叆浜哄憳璐﹀彿</param>
+        /// <param name="LocalIP">鍦板潃ip</param>
         /// <returns></returns>
-        public WebResponseContent RunOperation(int id, string  ispossible)
+        public WebResponseContent RunOperation(int id, string account, string LocalIP)
         {
             try
             {
-                var mon = BaseDal.QueryFirst(x => x.ID == id);
-                if (mon == null)
+                // 1. 鏌ユ壘鐩爣鐢ㄦ埛锛堣琚己鍒朵笅绾跨殑浜猴級
+                var maint = BaseDal.QueryData().FirstOrDefault(x => x.ID == id);
+                var sysuer = _user.QueryData(x => x.UserName == maint.UserAccount).FirstOrDefault();//user琛�
+                if (maint == null || sysuer==null)
                 {
-                    return new WebResponseContent { Status = false, Message = "鏃犳硶鏇存敼锛屾病鏈夋壘鍒拌鐢ㄦ埛" };
+                    return new WebResponseContent { Status = false, Message = "娌℃湁鎵惧埌璇ョ敤鎴�" };
                 }
-                var sysuer = _user.QueryData(x => x.UserName == mon.UserAccount).FirstOrDefault();
-                if (ispossible == "true")
-                {
-                    mon.IsPossible = "true";
-                    mon.MaintenanceDate = DateTime.Now;
-                    BaseDal.UpdateData(mon);
-                    var recording = new Dt_MaintenanceTeam  //娣诲姞璁板綍
-                    {
-                        OperatorName = sysuer.UserTrueName,
-                        TeamName = sysuer.RoleName,
-                        DistributionTime = DateTime.Now,
-                        Creater = "admin",
-                        CreateDate = DateTime.Now,
+               
 
-                    };
-                    _team.AddData(recording);
-                }
-                else
+                // 2. 鏌ユ壘褰撳墠鐧诲綍鐢ㄦ埛锛堟墽琛屾搷浣滅殑浜猴級
+                var currentUser = _user.QueryData(x => x.UserName == account).FirstOrDefault();
+                if (currentUser == null)
                 {
-                    mon.IsPossible = "false";
-                    BaseDal.UpdateData(mon);
+                    return new WebResponseContent { Status = false, Message = "褰撳墠鐧诲綍鐢ㄦ埛鏃犳晥" };
                 }
-                return new WebResponseContent { Status = true, Data = mon };
+
+                // 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);
+
+                // 5. 璁板綍鎿嶄綔鏃ュ織
+                var recording = new Dt_MaintenanceTeam
+                {
+                    Account = maint.UserAccount,
+                    MaintenanceStatus = 0,
+                    OperatorName = sysuer.UserTrueName,  // 鎿嶄綔浜哄鍚�
+                    TeamName = sysuer.RoleName,         // 鎿嶄綔浜鸿鑹�
+                    DistributionTime = DateTime.Now,
+                    IPAddress = LocalIP,
+                };
+                _team.AddData(recording);
+
+                return new WebResponseContent { Status = true, Message = "寮哄埗涓嬬嚎鎴愬姛" };
             }
             catch (Exception ex)
             {
-
-                return new WebResponseContent { Status = false, Message = "澶辫触锛�" + ex };
+                return new WebResponseContent { Status = false, Message = "澶辫触锛�" + ex.Message };
             }
         }
 
@@ -554,11 +614,12 @@
                 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 琛ㄤ腑鐨勬渶鏂颁竴鏉¤褰�
+                // 鏌ユ壘璇ョ敤鎴峰湪 Dt_MaintenanceTeam 琛ㄤ腑鐨勬渶鏂颁竴鏉¤褰�
                 var lastRecord = _team.QueryData(x => x.Account == account)
                                       .OrderByDescending(x => x.CreateDate)
                                       .FirstOrDefault();
@@ -574,18 +635,25 @@
                     bool leaderStarted = user.Any(x =>  x.IsLeader == 1 && x.MaintenanceStatus == 1); //鍚︽湁婊¤冻鏉′欢 鎵惧埌涓�鏉″氨杩斿洖true MaintenanceStatus锛�0娌℃湁寮�濮嬶紝1寮�濮嬶級
                     if (!leaderStarted)
                     {
-                        return new WebResponseContent { Status = false, Message = "璇风瓑寰呯粍闀垮紑濮嬫淇�" };
+                        return new WebResponseContent { Status = false, Message = "璇风瓑寰呬竴绾т汉鍛樺紑濮嬫淇�" };
                     }
-
-                }
-                if (true)
-                {
 
                 }
                 //濡傛灉婊¤冻涓嬮潰鐨勬潯浠跺氨寮�濮�
                 maint.MaintenancStartTime = DateTime.Now;//璁板綍寮�濮嬫椂闂�
                 maint.MaintenanceStatus = 1;//鏇存敼鐘舵��
+                maint.IPAddress = LocalIP;//鏇存敼ip鍦板潃
                 BaseDal.UpdateData(maint);
+                var address = _ipaddress.QueryData(x=>x.IPaddress== LocalIP).FirstOrDefault();
+                var addressIp = "";
+                if (address!=null) //鎵惧埌浜�
+                {
+                     addressIp = address.Addressname;
+                }
+                else
+                {
+                    addressIp = LocalIP;
+                }
                 //鎻掑叆璁板綍琛�
                 var recording = new Dt_MaintenanceTeam  //娣诲姞璁板綍
                 {
@@ -594,7 +662,7 @@
                     OperatorName = sysuer.UserTrueName,
                     TeamName = sysuer.RoleName,
                     DistributionTime = DateTime.Now,
-                    IPAddress = LocalIP,
+                    IPAddress = addressIp,
                 };
                 _team.AddData(recording);
 
@@ -606,19 +674,19 @@
             }
         }
 
-
         /// <summary>
         /// 缁撴潫妫�淇�
-        /// </summary>MaintenanceStatus 0浠h〃妫�淇畬鎴�  1浠h〃妫�淇腑
+        /// </summary>
         /// <param name="account"></param>
         /// <returns></returns>
-        public WebResponseContent StopMaintenanceTask(string account)
+        public WebResponseContent StopMaintenanceTask(string account,string LocalIP)
         {
             try
             {
-                var user = BaseDal.QueryData();//妫�淇〃
+                var user = BaseDal.QueryData(); // 妫�淇〃
                 var maint = user.Where(x => x.UserAccount == account).FirstOrDefault();
-                var sysuer = _user.QueryData(x => x.UserName == account).FirstOrDefault();//鐢ㄦ埛琛�
+                var sysuer = _user.QueryData(x => x.UserName == account).FirstOrDefault(); // 鐢ㄦ埛琛�
+
                 if (maint == null || sysuer == null)
                 {
                     return new WebResponseContent { Status = false, Message = "娌℃湁鎵惧埌璇ョ敤鎴�" };
@@ -626,35 +694,63 @@
 
                 // 鏌ユ壘璇ョ敤鎴峰湪 _team 琛ㄤ腑鐨勬渶鏂颁竴鏉¤褰�
                 var lastRecord = _team.QueryData(x => x.Account == account)
-                                      .OrderByDescending(x => x.CreateDate)
-                                      .FirstOrDefault();
+                                    .OrderByDescending(x => x.CreateDate)
+                                    .FirstOrDefault();
 
                 if (lastRecord == null || lastRecord.MaintenanceStatus != 1)
                 {
                     return new WebResponseContent { Status = false, Message = "浣犺繕娌℃湁寮�濮嬫淇紝璇峰厛鐐瑰嚮寮�濮嬫淇�" };
                 }
 
-                if (maint.IsLeader == 1)//濡傛灉璇ョ敤鎴锋槸鐝暱锛岄偅涔堣绛夊叏閮ㄤ汉閮芥淇畬鎴愶紝浠栨墠鍙互缁撴潫妫�淇�
+                // 妫�鏌ユ槸鍚﹁嚦灏戞湁涓�涓粍闀垮湪鍦�
+                var activeLeaders = user.Where(x => x.IsLeader == 1 && x.MaintenanceStatus == 1).ToList();
+
+                // 濡傛灉褰撳墠鐢ㄦ埛鏄粍闀�
+                if (maint.IsLeader == 1)
                 {
-                    //鍏堟煡鎵炬墍鏈夌敤鎴风殑缁勬槸閭d釜缁勭殑锛岀粍鍛樼姸鎬佹湁涓�涓笉鏄�1               
-                    // 鏌ユ壘鍚岀粍鏈畬鎴愮殑缁勫憳锛圛sLeader=0 && MaintenanceStatus=1锛�
-                    var hasUnfinishedMembers = user.Where(x =>x.IsLeader == 0 &&x.MaintenanceStatus == 1).ToList(); //锛欰ny()鏈変竴涓弧瓒冲氨杩斿洖true琛ㄧず瀛樺湪婊¤冻鏉′欢鐨勮褰�
-                    if (hasUnfinishedMembers.Count>0)
+                    // 濡傛灉鏄渶鍚庝竴涓湪鍦虹殑缁勯暱
+                    if (activeLeaders.Count == 1 && activeLeaders[0].UserAccount == account)
                     {
-                        return new WebResponseContent { Status = false, Message = "杩樻湁缁勫憳鏈畬鎴愬綋鍓嶆壒娆℃淇�" };
+                        // 妫�鏌ユ槸鍚﹁繕鏈夋湭瀹屾垚鐨勭粍鍛�
+                        var unfinishedMembers = user.Where(x => x.IsLeader == 0 && x.MaintenanceStatus == 1).Any();
+                        if (unfinishedMembers)
+                        {
+                            return new WebResponseContent
+                            {
+                                Status = false,
+                                Message = "鎮ㄦ槸鏈�鍚庝竴涓湪鍦虹殑缁勯暱锛岃绛夊緟鎵�鏈夌粍鍛樺畬鎴愭淇悗鍐嶇粨鏉�"
+                            };
+                        }
                     }
                 }
-                //濡傛灉婊¤冻涓嬮潰鐨勬潯浠跺氨寮�濮�
-                maint.MaintenancEendTime = DateTime.Now;//璁板綍缁撴潫鏃堕棿
-                maint.MaintenanceStatus = 0;//鏇存敼鐘舵��
+                //if (LocalIP!=maint.IPAddress)
+                //{
+                //    return new WebResponseContent { Status = false, Message = "鎿嶄綔璁惧涓嶅悓锛岃鍥炲埌鍘熸湰璁惧鍐嶇偣鍑荤粨鏉熸淇�" };
+                //}
+                var address = _ipaddress.QueryData(x => x.IPaddress == LocalIP).FirstOrDefault();
+                var addressIp = "";
+                if (address != null) //鎵惧埌浜�
+                {
+                    addressIp = address.Addressname;
+                }
+                else
+                {
+                    addressIp = LocalIP;
+                }
+
+                // 鏇存柊褰撳墠鐢ㄦ埛鐨勬淇姸鎬�
+                maint.MaintenancEendTime = DateTime.Now; // 璁板綍缁撴潫鏃堕棿
+                maint.MaintenanceStatus = 0; // 鏇存敼鐘舵��
                 BaseDal.UpdateData(maint);
-                ////鎻掑叆璁板綍琛�
-                var recording = new Dt_MaintenanceTeam  //娣诲姞璁板綍
+
+                // 鎻掑叆璁板綍琛�
+                var recording = new Dt_MaintenanceTeam  // 娣诲姞璁板綍
                 {
                     Account = account,
-                    MaintenanceStatus=0,
+                    MaintenanceStatus = 0,
                     OperatorName = sysuer.UserTrueName,
                     TeamName = sysuer.RoleName,
+                    IPAddress = addressIp,
                     EndTime = DateTime.Now,
                 };
                 _team.AddData(recording);

--
Gitblit v1.9.3