コード例 #1
0
        public async Task <int> CreateFrom(DateTime carryoutDate, DateTime fromDate)
        {
            int workerId = await GetCurrentUserWorkerIdAsync();

            workerId = WorkManager.GetCaptainOrAgentId(workerId);     // Agent

            int depotId = WorkManager.GetWorkerDepotId(workerId);
            var list    = _affairRepository.GetAllList(e => e.DepotId == depotId && e.CarryoutDate == fromDate);

            foreach (Affair a in list)
            {
                Affair affair = new Affair();
                affair.DepotId        = depotId;
                affair.CarryoutDate   = carryoutDate;
                affair.Status         = "安排";
                affair.Content        = a.Content;
                affair.WorkplaceId    = a.WorkplaceId;
                affair.StartTime      = a.StartTime;
                affair.EndTime        = a.EndTime;
                affair.Remark         = a.Remark;
                affair.CreateWorkerId = workerId;
                affair.CreateTime     = DateTime.Now;
                int affairId = await _affairRepository.InsertAndGetIdAsync(affair);

                var workers = _workerRepository.GetAllList(e => e.AffairId == a.Id);
                foreach (AffairWorker w in workers)
                {
                    AffairWorker worker = new AffairWorker();
                    worker.AffairId   = affairId;
                    worker.WorkerId   = w.WorkerId;
                    worker.WorkRoleId = w.WorkRoleId;
                    await _workerRepository.InsertAsync(worker);
                }


                // var tasks =  _taskRepository.GetAllList(e => e.AffairId == a.Id);
                // foreach (AffairTask t in tasks)
                // {
                //     AffairTask task = new AffairTask();
                //     task.AffairId = affairId;
                //     task.WorkplaceId = t.WorkplaceId;
                //     task.Content = t.Content;
                //     task.StartTime = t.StartTime;
                //     task.EndTime = t.EndTime;
                //     task.CreateWorkerId = workerId;
                //     task.CreateTime = DateTime.Now;
                //     await _taskRepository.InsertAsync(task);
                // }
            }
            return(list.Count);
        }
コード例 #2
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);
        }
コード例 #3
0
        public async Task <(string, int)> Activate(List <int> ids, bool finger)
        {
            int workerId = await GetCurrentUserWorkerIdAsync();

            workerId = WorkManager.GetCaptainOrAgentId(workerId);     // Agent

            int count = 0;

            foreach (int id in ids)
            {
                Affair affair = _affairRepository.Get(id);
                if (affair.Status != "安排")
                {
                    continue;                                 // Skip
                }
                var reason = affair.CarryoutDate > DateTime.Now.Date ? null : CanActivateAffair(affair);
                if (reason != null)
                {
                    var wp = WorkManager.GetWorkplace(affair.WorkplaceId);
                    return($"{wp.Name}因({reason})不能激活", count);
                }
                affair.Status = "激活";
                await _affairRepository.UpdateAsync(affair);

                // for affairEvent
                var    worker = WorkManager.GetWorker(workerId);
                string issuer = string.Format("{0} {1}", worker.Cn, worker.Name);
                var    ae     = new AffairEvent()
                {
                    AffairId = affair.Id, EventTime = DateTime.Now, Name = "激活任务", Description = finger?"指纹":"密码", Issurer = issuer
                };
                await _eventRepository.InsertAsync(ae);

                count++;
            }
            return(null, count);
        }