| | |
| | | using WIDESEAWCS_DTO.Telescopic; |
| | | using SqlSugar.DistributedSystem.Snowflake; |
| | | using System.IO; |
| | | using System.Net; |
| | | |
| | | namespace WIDESEAWCS_TelescopicService |
| | | { |
| | |
| | | { |
| | | 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; |
| | | } |
| | | |
| | | |
| | |
| | | /// <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 ?? "无IP", |
| | | 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 }; |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | |
| | | /// <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 }; |
| | | } |
| | | } |
| | | |
| | |
| | | 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(); |
| | |
| | | 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 //添加记录 |
| | | { |
| | |
| | | OperatorName = sysuer.UserTrueName, |
| | | TeamName = sysuer.RoleName, |
| | | DistributionTime = DateTime.Now, |
| | | IPAddress = LocalIP, |
| | | IPAddress = addressIp, |
| | | }; |
| | | _team.AddData(recording); |
| | | |
| | |
| | | /// </summary> |
| | | /// <param name="account"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent StopMaintenanceTask(string account) |
| | | public WebResponseContent StopMaintenanceTask(string account,string LocalIP) |
| | | { |
| | | try |
| | | { |
| | |
| | | } |
| | | } |
| | | } |
| | | //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; // 记录结束时间 |
| | |
| | | MaintenanceStatus = 0, |
| | | OperatorName = sysuer.UserTrueName, |
| | | TeamName = sysuer.RoleName, |
| | | IPAddress = addressIp, |
| | | EndTime = DateTime.Now, |
| | | }; |
| | | _team.AddData(recording); |