public AffairCacheItem FindAltDutyAffairByDepotId(int depotId) { var wp = _workplaceCache.GetList().FirstOrDefault(x => x.DepotId == depotId && x.Name.Contains("金库")); if (wp == null) { return(null); } var list = _affairCache.Get(DateTime.Now.Date, depotId); foreach (var affair in list) { if (AllCheckout(affair.Workers)) { continue; } if (!ClcUtils.NowInTimeZone(affair.StartTime, 3, affair.EndTime)) { continue; // wp.DutyLead } // 金库 if (affair.WorkplaceId == wp.Id) { return(affair); } } return(null); }
public AffairCacheItem FindDutyAffairByWorkerId(int workerId) { int depotId = GetWorkerDepotId(workerId); foreach (var affair in _affairCache.Get(DateTime.Now.Date, depotId)) { if (AllCheckout(affair.Workers)) { continue; } var wp = _workplaceCache[affair.WorkplaceId]; if (!ClcUtils.NowInTimeZone(affair.StartTime, wp.DutyLead, affair.EndTime)) { continue; } // me in worker foreach (var worker in affair.Workers) { if (worker.CheckoutTime.HasValue) { continue; } if (worker.WorkerId == workerId) { return(affair); } } } return(null); }
public virtual async Task <JsonResult> SendVerifyCode(LoginViewModel loginModel) { var v = await SettingManager.GetSettingValueAsync(AppSettingNames.Rule.VerifyLogin); if (v == "true" && loginModel.UsernameOrEmailAddress != "admin") { var worker = _workManager.GetWorkerByCn(loginModel.UsernameOrEmailAddress); if (worker == null) { throw new UserFriendlyException("找不到此员工"); } string appName = _workManager.GetWorkerPostAppName(worker); if (string.IsNullOrEmpty(appName)) { throw new UserFriendlyException("此员工无对应的微信应用"); } string code = ClcUtils.GetRandomNumber(ClcConsts.VerifyCodeLength); WeixinUtils.SendMessage(appName, worker.Cn, string.Format("你的登录验证码为:{0}", code)); HttpContext.Session.SetString("WorkerCn", loginModel.UsernameOrEmailAddress); HttpContext.Session.SetString("VerifyCode", code); return(Json(new AjaxResponse() { Success = true })); } return(Json(new AjaxResponse { Success = false })); }
public bool IsInDepotRadius(int depotId, float lat, float lon) { int radius = int.Parse(SettingManager.GetSettingValue(AppSettingNames.Rule.Radius)); var depot = _depotCache[depotId]; if (!depot.Latitude.HasValue || !depot.Latitude.HasValue) { return(false); } int dist = (int)ClcUtils.GetDistance(lat, lon, depot.Latitude.Value, depot.Longitude.Value); if (depot.Radius.HasValue) { radius = depot.Radius.Value; } if (dist > radius) { return(false); } return(true); }
private string CanActivateRoute(Route route) { var depot = WorkManager.GetDepot(route.DepotId); if (depot.LastReportDate.HasValue && depot.LastReportDate.Value >= DateTime.Now) // route.CarryoutDate) { return("未到可激活时点"); } var routeType = _routeTypeCache[route.RouteTypeId]; // check Active Ahead var start = ClcUtils.GetDateTime(route.StartTime).Subtract(new TimeSpan(0, routeType.ActivateLead, 0)); var end = ClcUtils.GetDateTime(route.EndTime); if (!ClcUtils.NowInTimeZone(start, end)) { return($"未到激活提前量({routeType.ActivateLead}分钟)或已过结束时间"); } // check same workerId in same route var workers = _workerRepository.GetAllList(w => w.RouteId == route.Id); var r = workers.GroupBy(x => x.WorkerId).Where(g => g.Count() > 1).Select(g => g.Key).ToArray(); if (r.Length > 0) { return("同一人被多次安排"); } // check workRoles List <string> strRoles = new List <string>(routeType.WorkRoles.Split('|', ',')); var roles = _workRoleCache.GetList().FindAll(x => strRoles.Contains(x.Name)); foreach (WorkRole role in roles) { if (role.mustHave && workers.FirstOrDefault(w => w.WorkRoleId == role.Id) == null) { return($"任务中必须安排{role.Name}角色"); } } // check signin bool mustAllSignin = WorkManager.GetDepot(route.DepotId).ActiveRouteNeedCheckin; string unSigninNames = string.Empty; foreach (RouteWorker rw in workers) { var w = WorkManager.GetWorker(rw.WorkerId); unSigninNames += WorkManager.GetSigninInfo(w.DepotId, w.Id, ClcUtils.GetDateTime(route.StartTime)) == "未签到" ? w.Name + " " : string.Empty; if (mustAllSignin && unSigninNames != string.Empty) { return($"未签到的人员有{unSigninNames}"); } } return(null); }
public string GetSigninInfo(int depotId, int workerId, DateTime dt) { var s = _signinCache.Get(depotId, workerId, ClcUtils.IsMorning(dt)); if (s == null) { return("未签到"); } return(string.Format("{0} 签到", s.SigninTime.ToString("HH:mm:ss"))); }
public void SetReportDate() { int depotId = WorkManager.GetWorkerDepotId(GetCurrentUserWorkerIdAsync().Result); var depot = _depotRepository.Get(depotId); var t = SettingManager.GetSettingValue(AppSettingNames.TimeRule.ActivateTime); var time = ClcUtils.GetDateTime(t, true); depot.LastReportDate = time; _depotRepository.Update(depot); }
private bool AffairTaskCanAsk(AffairCacheItem affair) { foreach (var task in affair.Tasks) { if (ClcUtils.NowInTimeZone(task.StartTime, task.EndTime)) { return(true); } } return(false); }
public Signin Get(int depotId, int workerId, bool isMorning) { string cacheKey = DateTime.Now.Date.ToString() + depotId.ToString() + workerId.ToString(); var signin = _cacheManager.GetCache(CacheName).Get(cacheKey, () => { return(_signinRepository.GetAll() .Where(x => x.CarryoutDate == DateTime.Now.Date && x.DepotId == depotId && x.WorkerId == workerId && ClcUtils.IsMorning(x.SigninTime) == isMorning).FirstOrDefault()); }); return(signin); }
private string CanActivateAffair(Affair affair) { var depot = WorkManager.GetDepot(affair.DepotId); if (depot.LastReportDate.HasValue && depot.LastReportDate.Value >= DateTime.Now) // route.CarryoutDate) { return("未到可激活时点"); } // check workplace var wp = WorkManager.GetWorkplace(affair.WorkplaceId); // check time var start = ClcUtils.GetDateTime(affair.StartTime).Subtract(new TimeSpan(12, 0, 0)); var end = ClcUtils.GetDateTime(affair.EndTime); if (!ClcUtils.NowInTimeZone(start, end)) { return($"已过结束时间或提前了半天"); } // check same workerId in same route var workers = _workerRepository.GetAllList(w => w.AffairId == affair.Id); var r = workers.GroupBy(x => x.WorkerId).Where(g => g.Count() > 1).Select(g => g.Key).ToArray(); if (r.Length > 0) { return("同一人被多次安排"); } // check workRoles List <string> strRoles = new List <string>(wp.WorkRoles.Split('|', ',')); var roles = _workRoleCache.GetList().FindAll(x => strRoles.Contains(x.Name)); foreach (WorkRole role in roles) { if (role.mustHave && workers.FirstOrDefault(w => w.WorkRoleId == role.Id) == null) { return($"任务中必须安排{role.Name}角色"); } } return(null); }
public (Route, int) FindRouteForIdentify(int depotId, int workerId) { var query = _routeRepository.GetAllIncluding(x => x.Workers) .Where(x => x.DepotId == depotId && x.CarryoutDate == DateTime.Today && (x.Status == "激活" || x.Status == "领物")) .OrderByDescending(x => x.StartTime); var routes = query.ToList(); foreach (Route route in routes) { if (route.Status != "领物" && DateTime.Now < ClcUtils.GetDateTime(route.StartTime)) { continue; } bool found = false; int subId = 0; foreach (RouteWorker rw in route.Workers) { var workRole = _workRoleCache[rw.WorkRoleId]; if (string.IsNullOrEmpty(workRole.Duties)) { continue; } var names = workRole.Duties.Split('|', ' ', ','); if (rw.GetFactWorkerId() == workerId && names.Contains("交接")) { found = true; } if (names.Contains("辅助交接")) { subId = rw.GetFactWorkerId(); } } if (found && subId != 0) { route.Tasks = _taskRepository.GetAllList(t => t.RouteId == route.Id); return(route, subId); } } return(null, 0); }
public JsonResult AskOpen(int[] workers, int affairId, int doorId, string start, string end, int taskId, bool wait) { int minNum = int.Parse(SettingManager.GetSettingValue(AppSettingNames.Rule.MinWorkersOnDuty)); if (workers.Length < minNum) { return(Json(new { success = false, message = "确认人数不够最低要求" })); } var wp = WorkManager.GetWorkplace(doorId); if (wp.AskOpenDeadline == 0) { if (!ClcUtils.NowInTimeZone(start, end)) { return(Json(new { success = false, message = "不在申请开门时段" })); } } else { if (!ClcUtils.NowInTimeZone(start, 0, wp.AskOpenDeadline)) { return(Json(new { success = false, message = "不在申请开门时段" })); } } var ret = WorkManager.AskOpenDoor(wp.DepotId, affairId, doorId, workers, taskId, wait); if (ret.Item1) { // set start Time for VaultTask if (taskId > 0) { _affairAppService.SetTaskTime(taskId, true); } var depotName = WorkManager.GetDepot(wp.DepotId).Name; _context.Clients.All.SendAsync("getMessage", "askOpenDoor " + string.Format("你有来自{0}{1}的任务开门申请", depotName, wp.Name)); } return(Json(new { success = true, message = ret.Item2 })); }
public (bool, string) DoSignin(int depotId, int workerId, string style) { // Get Signin var signin = _signinRepository.GetAll() .Where(s => s.CarryoutDate == DateTime.Today && s.DepotId == depotId && s.WorkerId == workerId) .LastOrDefault(); if (signin == null) { signin = new Signin() { DepotId = depotId, CarryoutDate = DateTime.Today, WorkerId = workerId, SigninTime = DateTime.Now, SigninStyle = style }; _signinRepository.Insert(signin); if (ClcUtils.IsMorning(DateTime.Now)) { return(true, "上午时段签到成功"); } else { return(true, "下午时段签到成功"); } } else { var signedTz = ClcUtils.IsMorning(signin.SigninTime); if (!ClcUtils.IsMorning(DateTime.Now) && signedTz) { signin = new Signin() { DepotId = depotId, CarryoutDate = DateTime.Today, WorkerId = workerId, SigninTime = DateTime.Now, SigninStyle = style }; _signinRepository.Insert(signin); return(true, "下午时段签到成功"); } else { return(false, string.Format("你已在{0}签到过", signin.SigninTime.ToString("HH:mm:ss"))); } } }
public string CheckTimeZone(string startTime, string endTime) { DateTime start = ClcUtils.GetDateTime(startTime); DateTime end = ClcUtils.GetDateTime(endTime); if (start > end) { return("结束时间不能小于开始时间!"); } if (end.Subtract(start).TotalMinutes < MinDuration) { return(string.Format("时段长度小于规定({0}分钟)", MinDuration)); } if (end.Subtract(start).TotalHours > MaxDuration) { return(string.Format("时段长度大于规定({0}小时)", MaxDuration)); } return(null); }
private (string, RouteCacheItem, RouteWorkerCacheItem, RouteWorkerCacheItem) FindEqualRfidWorkerForArticle(bool isLend, List <RouteCacheItem> routes, string rfid, int routeId = 0) { foreach (var route in routes) { if (routeId != 0 && route.Id != routeId) { continue; } if (routeId == 0) { // 时间段 JUDGE var rt = _routeTypeCache[route.RouteTypeId]; if (isLend && !ClcUtils.NowInTimeZone(route.StartTime, rt.LendArticleLead, rt.LendArticleDeadline)) { continue; } var span = int.Parse(SettingManager.GetSettingValue(AppSettingNames.TimeRule.ReturnDeadline)); if (!isLend && DateTime.Now > ClcUtils.GetDateTime(route.EndTime).AddMinutes(span)) { continue; } } foreach (var rw in route.Workers) { var worker = WorkManager.GetWorker(rw.GetFactWorkerId()); if (worker.Rfid == rfid) { if (string.IsNullOrEmpty(_workRoleCache[rw.WorkRoleId].ArticleTypeList)) { return("此人不需要领还物", null, null, null); } RouteWorkerCacheItem rw2 = FindAnotherRouteWorker(route.Workers, _workRoleCache[rw.WorkRoleId]); return(null, route, rw, rw2); } } } return("无任务或不在时间段", null, null, null); }
public (bool, string) CheckinByRfid(string rfid, DateTime carryoutDate, int depotId, int affairId) { Worker worker = WorkManager.GetWorkerByRfid(rfid); if (worker == null) { return(false, "找不到此人"); } var aw = WorkManager.GetCacheAffairWorker(carryoutDate, depotId, affairId, worker.Id); if (aw.Item2 == null) { return(false, "此人没被安排在此任务中"); } if (!ClcUtils.NowInTimeZone(aw.Item1.StartTime, aw.Item1.EndTime)) { return(false, "没在任务时段"); } WorkManager.DoCheckin(aw.Item1, aw.Item2, worker.Id); return(true, "刷卡验入成功"); }
public (int, List <Workplace>) GetDoorsForAsk(DateTime carryoutDate, int depotId, int workerId) { var lst = new List <Workplace>(); var aw = _affairCache.GetAffairWorker(carryoutDate, depotId, workerId); var affair = aw.Item1; if (affair == null || string.IsNullOrEmpty(_workplaceCache[affair.WorkplaceId].AskOpenStyle)) { return(0, lst); } if (ClcUtils.NowInTimeZone(affair.StartTime, affair.EndTime)) { lst.Add(_workplaceCache[affair.WorkplaceId]); } if (AffairTaskCanAsk(affair)) { lst.Add(_workplaceCache[affair.Tasks[0].WorkplaceId]); } return(affair.Id, lst); }
public (bool, string) CheckinByFinger(string finger, int workerId, DateTime carryoutDate, int depotId, int affairId) { var mR = WorkManager.MatchFinger(finger, workerId); if (!mR.Item1) { return(mR); } var aw = WorkManager.GetCacheAffairWorker(carryoutDate, depotId, affairId, workerId); if (aw.Item2 == null) { return(false, "此人没被安排在此任务中"); } if (!ClcUtils.NowInTimeZone(aw.Item1.StartTime, aw.Item1.EndTime)) { return(false, "没在任务时段"); } WorkManager.DoCheckin(aw.Item1, aw.Item2, workerId); return(true, "验入成功!" + mR.Item2); }
public AffairCacheItem FindCheckinAffairByWorkerId(int workerId) { int depotId = GetWorkerDepotId(workerId); AffairCacheItem found = null; foreach (var affair in _affairCache.Get(DateTime.Now.Date, depotId)) { if (!ClcUtils.NowInTimeZone(affair.StartTime, affair.EndTime)) { continue; } var allcheckin = true; found = null; foreach (var worker in affair.Workers) { if (worker.CheckoutTime.HasValue) { continue; } if (worker.WorkerId == workerId) { found = affair; } if (!worker.CheckinTime.HasValue) { allcheckin = false; } } if (found != null && allcheckin) { return(found); } } return(null); }