Esempio n. 1
0
        public IActionResult Update([FromBody] DutyCheckPackageTimePlan model)
        {
            try
            {
                if (model == null)
                {
                    return(BadRequest());
                }
                using (var db = new AllInOneContext.AllInOneContext())
                {
                    using (var transaction = db.Database.BeginTransaction())
                    {
                        DutyCheckPackageTimePlan plan = db.DutyCheckPackageTimePlan
                                                        .Include(t => t.Schedule).ThenInclude(t => t.ScheduleCycle).ThenInclude(t => t.DayPeriods).ThenInclude(t => t.TimePeriods)
                                                        .Include(t => t.Schedule).ThenInclude(t => t.ScheduleCycle).ThenInclude(t => t.CycleType)
                                                        .Include(t => t.Organization)
                                                        .FirstOrDefault(p => p.DutyCheckPackageTimePlanId.Equals(model.DutyCheckPackageTimePlanId));
                        if (plan == null)
                        {
                            return(BadRequest());
                        }
                        //转换普通数据
                        plan.OrganizationId = model.OrganizationId;
                        plan.RandomRate     = model.RandomRate;

                        //更新排程中查勤设置
                        UpdateSchedule(model, db, plan);
                        //
                        plan.ScheduleId = model.ScheduleId;
                        //
                        DutyCheckPackageHelper.DutyCheckPackageTimePlanOnChange(plan.OrganizationId);
                        //
                        db.DutyCheckPackageTimePlan.Update(plan);
                        db.SaveChanges();

                        transaction.Commit();
                        DutyCheckPackageHelper.AllocationDutychekPackage(plan.OrganizationId, DateTime.Now);
                        return(new NoContentResult());
                    }
                }
            }
            catch (DbUpdateException dbEx)
            {
                return(BadRequest(new ApplicationException {
                    ErrorCode = "DBUpdate", ErrorMessage = "数据保存异常:" + dbEx.Message
                }));
            }
            catch (System.Exception ex)
            {
                return(BadRequest(new ApplicationException {
                    ErrorCode = "Unknown", ErrorMessage = ex.Message
                }));
            }
        }
Esempio n. 2
0
 public IActionResult GetAllMonitorSiteCountPlanByOrganization(Guid addressId)
 {
     try
     {
         //int count = DutyCheckPackageHelper.GetAllMonitorySite(addressId).Count;
         int count = DutyCheckPackageHelper.GetAllMonitorySite(addressId);
         return(new ObjectResult(count));
     }
     catch (Exception ex)
     {
         return(BadRequest(new ApplicationException {
             ErrorCode = "Unknown", ErrorMessage = ex.Message
         }));
     }
 }
Esempio n. 3
0
        public IActionResult Add([FromBody] DutyCheckPackageTimePlan model)
        {
            try
            {
                if (model == null)
                {
                    return(BadRequest());
                }
                using (var db = new AllInOneContext.AllInOneContext())
                {
                    using (var tran = db.Database.BeginTransaction())
                    {
                        DutyCheckPackageTimePlan plan = db.DutyCheckPackageTimePlan
                                                        .FirstOrDefault(p => p.OrganizationId.Equals(model.OrganizationId));
                        if (plan != null) //每级节点只允许存在一个查勤包计划表
                        {
                            return(BadRequest(new ApplicationException {
                                ErrorCode = "Exist", ErrorMessage = "已存在查勤计划"
                            }));
                        }

                        db.DutyCheckPackageTimePlan.Add(model);
                        db.SaveChanges();

                        tran.Commit();
                        DutyCheckPackageHelper.AllocationDutychekPackage(plan.OrganizationId, DateTime.Now);
                        return(Created("", "OK"));
                    }
                }
            }
            catch (DbUpdateException dbEx)
            {
                return(BadRequest(new ApplicationException {
                    ErrorCode = "DBUpdate", ErrorMessage = "数据保存异常:" + dbEx.Message
                }));
            }
            catch (System.Exception ex)
            {
                return(BadRequest(new ApplicationException {
                    ErrorCode = "Unknown", ErrorMessage = ex.Message
                }));
            }
        }
Esempio n. 4
0
 private void Run()
 {
     while (true)
     {
         try
         {
             DutyCheckPackageTimePlan executeTask = m_timerList.OrderBy(t => t.Schedule.ScheduleCycle.NextExecute).FirstOrDefault(t => !t.Running);
             if (executeTask == null)
             {
                 m_planExecutorWaiter.WaitOne();
             }
             //休眠
             Schedule planSchedule = executeTask.Schedule;
             DateTime currTime     = DateTime.Now;
             if (planSchedule.ScheduleCycle.NextExecute != null && !executeTask.Running)
             {
                 int waitTimeout = (int)((planSchedule.ScheduleCycle.NextExecute.Value - currTime).TotalMilliseconds);
                 //误差2分钟内,有效执行
                 if (waitTimeout < 0 && waitTimeout > -2 * 60 * 1000)
                 {
                     waitTimeout = 0;
                 }
                 if (waitTimeout >= 0)
                 {
                     TimePeriod tp = ScheduleUtility.GetPlanTaskTimePeriod(planSchedule, planSchedule.ScheduleCycle.NextExecute.Value);
                     executeTask.Running = true;
                     bool isGenerate = DutyCheckPackageHelper.CheckDutyPackageExist(executeTask.OrganizationId);
                     if (isGenerate)
                     {
                         DutyCheckPackageHelper.AllocationDutychekPackage(executeTask.OrganizationId, DateTime.Now);
                     }
                     var planTask = Task.Delay(waitTimeout).ContinueWith((runTask) => GetDutyCheckPackage());
                 }
             }
         }
         catch (Exception ex)
         {
             _logger.LogError("执行查勤包异常:Message:{0}\r\nStackTrace:{1}", ex.Message, ex.StackTrace);
         }
     }
 }