| | |
| | | public IRepository<Dt_Maintenance> Repository => BaseDal; |
| | | public readonly IRepository<Dt_MaintenanceTeam> _team; |
| | | private readonly IRepository<Sys_User> _user; |
| | | private readonly IRepository<Sys_Role> _role; |
| | | |
| | | |
| | | public MaintenanceService(IRepository<Sys_Role> role,IRepository<Dt_Maintenance> BaseDal, IRepository<Sys_User> user, IRepository<Dt_MaintenanceTeam> team) : base(BaseDal) |
| | | public MaintenanceService(IRepository<Dt_Maintenance> BaseDal, IRepository<Sys_User> user, IRepository<Dt_MaintenanceTeam> team) : base(BaseDal) |
| | | { |
| | | _user = user; |
| | | _team = team; |
| | | _role = role; |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 人员监控 |
| | | /// 人员监控(数字大屏) |
| | | /// </summary> |
| | | /// <param name="pageIndex"></param> |
| | | /// <param name="pageSize"></param> |
| | | /// <param name="searchKeyword"></param> |
| | | /// <returns></returns>(这个没有用到了) |
| | | /// <returns></returns> |
| | | 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不运行检修//默认为NULL |
| | | } |
| | | 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"); // 展示运行检修的 |
| | | .Where((a, b) => b.MaintenanceStatus==1); // 展示运行检修的 |
| | | |
| | | // 搜索关键字 |
| | | if (!string.IsNullOrEmpty(pagination.searchKeyword)) |
| | |
| | | a.Userteam.Contains(pagination.searchKeyword)); |
| | | } |
| | | |
| | | // 状态参数 |
| | | if (pagination.status.HasValue) |
| | | { |
| | | 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); |
| | | } |
| | | //// 状态参数 |
| | | //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.HeadImageUrl, |
| | | b.MaintenanceStatus, |
| | | b.MaintenanceDate, |
| | | b.IsPossible, |
| | | a.Userteam,//班组 |
| | | a.Unit,//单位 |
| | | b.MaintenanceStatus,//检修状态 |
| | | b.CreateDate,//日期 |
| | | b.MaintenancStartTime,//开始时间 |
| | | }) |
| | | .ToPageList(pagination.pageIndex, pagination.pageSize, ref totalCount); |
| | | |
| | |
| | | try |
| | | { |
| | | var user = BaseDal.QueryData();//检修表 |
| | | var Role = _role.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 = "你已经在开始检修了,请不要重复点击" }; |
| | | } |
| | | |
| | | //先要找到该用户属于那个角色的,这个角色中属于那个什么类型(组长/组员) |
| | | if (maint.IsLeader != 1)//如果该用户不是班长,那么要等班长先做,他才可以做 |
| | | { |
| | |
| | | } |
| | | |
| | | } |
| | | if (true) |
| | | { |
| | | |
| | | } |
| | | //如果满足下面的条件就开始 |
| | | maint.MaintenancStartTime = DateTime.Now;//记录开始时间 |
| | | maint.MaintenanceStatus = 1;//更改状态 |
| | |
| | | //插入记录表 |
| | | var recording = new Dt_MaintenanceTeam //添加记录 |
| | | { |
| | | Account = account, |
| | | MaintenanceStatus=1, |
| | | OperatorName = sysuer.UserTrueName, |
| | | TeamName = sysuer.RoleName, |
| | | DistributionTime = DateTime.Now, |
| | |
| | | { |
| | | 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 = "你还没有开始检修,请先点击开始检修" }; |
| | | } |
| | | |
| | | if (maint.IsLeader == 1)//如果该用户是班长,那么要等全部人都检修完成,他才可以结束检修 |
| | | { |
| | | //先查找所有用户的组是那个组的,组员状态有一个不是1 |
| | |
| | | ////插入记录表 |
| | | var recording = new Dt_MaintenanceTeam //添加记录 |
| | | { |
| | | Account = account, |
| | | MaintenanceStatus=0, |
| | | OperatorName = sysuer.UserTrueName, |
| | | TeamName = sysuer.RoleName, |
| | | EndTime = DateTime.Now, |
| | |
| | | { |
| | | try |
| | | { |
| | | var reslut=BaseDal.QueryData(x => x.MaintenanceStatus == 1).ToList(); |
| | | var reslut=BaseDal.QueryData(x => x.MaintenanceStatus == 1).ToList(); |
| | | if (reslut.Count<=0) |
| | | { |
| | | return new WebResponseContent { Status = false, Message = "还没有人开始检修" }; |