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 |  205 ++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 146 insertions(+), 59 deletions(-)

diff --git a/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/MaintenanceService.cs b/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/MaintenanceService.cs
index a99fa9d..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,59 +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.ID,//id
-                        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 };
             }
         }
 
@@ -178,43 +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 LocalIP)
+        public WebResponseContent RunOperation(int id, string account, string LocalIP)
         {
             try
             {
-                var user = BaseDal.QueryData();//妫�淇〃
-                
-                var maint = user.Where(x => x.ID == id).FirstOrDefault(); //鍦ㄦ淇〃涓厛鎵惧埌璇ョ敤鎴�
-                var sysuer = _user.QueryData(x => x.UserName == maint.UserAccount).FirstOrDefault();
-                if (maint == null ||sysuer==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 = "娌℃湁鎵惧埌璇ョ敤鎴�" };
                 }
-                 maint.MaintenanceStatus = 0;//鏀瑰彉鐘舵�佸己鍒朵笅绾�
+               
+
+                // 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 recording = new Dt_MaintenanceTeam  //娣诲姞璁板綍
+
+                // 5. 璁板綍鎿嶄綔鏃ュ織
+                var recording = new Dt_MaintenanceTeam
                 {
                     Account = maint.UserAccount,
                     MaintenanceStatus = 0,
-                    OperatorName = sysuer.UserTrueName,
-                    TeamName = sysuer.RoleName,
+                    OperatorName = sysuer.UserTrueName,  // 鎿嶄綔浜哄鍚�
+                    TeamName = sysuer.RoleName,         // 鎿嶄綔浜鸿鑹�
                     DistributionTime = DateTime.Now,
                     IPAddress = LocalIP,
                 };
                 _team.AddData(recording);
 
-                return new WebResponseContent { Status = true,Message="寮哄埗涓嬬嚎鎴愬姛", Data = 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 };
             }
         }
 
@@ -550,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();
@@ -570,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  //娣诲姞璁板綍
                 {
@@ -590,7 +662,7 @@
                     OperatorName = sysuer.UserTrueName,
                     TeamName = sysuer.RoleName,
                     DistributionTime = DateTime.Now,
-                    IPAddress = LocalIP,
+                    IPAddress = addressIp,
                 };
                 _team.AddData(recording);
 
@@ -607,7 +679,7 @@
         /// </summary>
         /// <param name="account"></param>
         /// <returns></returns>
-        public WebResponseContent StopMaintenanceTask(string account)
+        public WebResponseContent StopMaintenanceTask(string account,string LocalIP)
         {
             try
             {
@@ -651,6 +723,20 @@
                         }
                     }
                 }
+                //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; // 璁板綍缁撴潫鏃堕棿
@@ -664,6 +750,7 @@
                     MaintenanceStatus = 0,
                     OperatorName = sysuer.UserTrueName,
                     TeamName = sysuer.RoleName,
+                    IPAddress = addressIp,
                     EndTime = DateTime.Now,
                 };
                 _team.AddData(recording);

--
Gitblit v1.9.3