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 | 310 ++++++++++++++++++++++++++++++-------------------- 1 files changed, 185 insertions(+), 125 deletions(-) diff --git a/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/MaintenanceService.cs b/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/MaintenanceService.cs index 81671f3..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; } @@ -111,100 +114,107 @@ /// <summary> - /// 浜哄憳鐩戞帶 + /// 浜哄憳鐩戞帶锛堟暟瀛楀ぇ灞忥級 /// </summary> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <param name="searchKeyword"></param> - /// <returns></returns>(杩欎釜娌℃湁鐢ㄥ埌浜�) + /// <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 { - // 绗竴姝ワ細鑷姩娓呯悊杩囨湡妫�淇姸鎬� - var today = DateTime.Today; - var recordsToUpdate = Db.Queryable<Dt_Maintenance>() - .Where(b => b.MaintenanceDate != null && - b.MaintenanceDate.Value.Date < today ) - .ToList(); - - if (recordsToUpdate.Count > 0) - { - foreach (var record in recordsToUpdate)//鏇存柊 - { - record.MaintenanceDate = null;//娓呯┖妫�淇棩鏈� - record.MaintenancStartTime = null;//娓呯┖寮�濮嬫椂闂� - record.MaintenancEendTime = null;//娓呯┖缁撴潫鏃堕棿 - record.MaintenanceStatus = 0; // Set to false - record.IsPossible = "NULL"; //鏇存敼鐘舵�佷负false涓嶈繍琛屾淇�//榛樿涓篘ULL - } - Db.Updateable(recordsToUpdate).ExecuteCommand(); - } - 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) - .Where((a, b) => b.IsPossible == "true"); // 灞曠ず杩愯妫�淇殑 + 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((a, b) => + query = query.Where((b, a, c) => a.UserTrueName.Contains(pagination.searchKeyword) || a.Userteam.Contains(pagination.searchKeyword)); } - // 鐘舵�佸弬鏁� - if (pagination.status.HasValue) + var result = query.Select((b, a, c) => new { - query = query.Where((a, b) => b.MaintenanceStatus == pagination.status.Value); - } - - // 濡傛灉涓嶆槸绠$悊鍛橈紝璇锋寜閮ㄩ棬杩囨护 - 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 - { - a.UserTrueName, - a.Userteam, - a.HeadImageUrl, - b.MaintenanceStatus, - b.MaintenanceDate, - b.IsPossible, - }) - .ToPageList(pagination.pageIndex, pagination.pageSize, ref totalCount); + 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 }; } } @@ -213,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 }; } } @@ -590,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(); @@ -610,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 //娣诲姞璁板綍 { @@ -630,7 +662,7 @@ OperatorName = sysuer.UserTrueName, TeamName = sysuer.RoleName, DistributionTime = DateTime.Now, - IPAddress = LocalIP, + IPAddress = addressIp, }; _team.AddData(recording); @@ -642,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 = "娌℃湁鎵惧埌璇ョ敤鎴�" }; @@ -662,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