示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
 private bool AffairTaskCanAsk(AffairCacheItem affair)
 {
     foreach (var task in affair.Tasks)
     {
         if (ClcUtils.NowInTimeZone(task.StartTime, task.EndTime))
         {
             return(true);
         }
     }
     return(false);
 }
示例#5
0
        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);
        }
示例#6
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 }));
        }
示例#7
0
        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);
        }
示例#8
0
        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, "刷卡验入成功");
        }
示例#9
0
        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);
        }
示例#10
0
        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);
        }
示例#11
0
        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);
        }