Пример #1
0
        public async Task <TData> ChangeJobStatus(AutoJobEntity entity)
        {
            TData obj = new TData();

            await autoJobService.SaveForm(entity);

            obj.Tag = 1;
            return(obj);
        }
Пример #2
0
 public void SubmitForm(AutoJobEntity areaEntity, string f_Id)
 {
     if (!string.IsNullOrEmpty(f_Id))
     {
         areaEntity.Modify(f_Id);
         service.Update(areaEntity);
     }
     else
     {
         areaEntity.Create();
         service.Insert(areaEntity);
     }
 }
Пример #3
0
        public async Task SaveForm(AutoJobEntity entity)
        {
            if (entity.Id.IsNullOrZero())
            {
                await entity.Create();

                await this.BaseRepository().Insert <AutoJobEntity>(entity);
            }
            else
            {
                await entity.Modify();

                await this.BaseRepository().Update <AutoJobEntity>(entity);
            }
        }
Пример #4
0
        public bool ExistJob(AutoJobEntity entity)
        {
            var expression = LinqExtensions.True <AutoJobEntity>();

            expression = expression.And(t => t.BaseIsDelete == 0);
            if (entity.Id.IsNullOrZero())
            {
                expression = expression.And(t => t.JobGroupName == entity.JobGroupName && t.JobName == entity.JobName);
            }
            else
            {
                expression = expression.And(t => t.JobGroupName == entity.JobGroupName && t.JobName == entity.JobName && t.Id != entity.Id);
            }
            return(this.BaseRepository().IQueryable(expression).Count() > 0 ? true : false);
        }
Пример #5
0
        public async Task <TData <string> > SaveForm(AutoJobEntity entity)
        {
            TData <string> obj = new TData <string>();

            if (autoJobService.ExistJob(entity))
            {
                obj.Message = "任务已经存在!";
                return(obj);
            }
            await autoJobService.SaveForm(entity);

            obj.Result = entity.Id.ParseToString();
            obj.Tag    = 1;
            return(obj);
        }
Пример #6
0
        public async Task <TData> DeleteForm(string ids)
        {
            TData <long> obj = new TData <long>();

            foreach (long id in TextHelper.SplitToArray <long>(ids, ','))
            {
                AutoJobEntity dbEntity = await autoJobService.GetEntity(id);

                if (dbEntity.JobStatus == StatusEnum.Yes.ParseToInt())
                {
                    obj.Message = "请先暂停 " + dbEntity.JobName + " 定时任务";
                    return(obj);
                }
            }
            await autoJobService.DeleteForm(ids);

            obj.Tag = 1;
            return(obj);
        }
Пример #7
0
        public Task Execute(IJobExecutionContext context)
        {
            return(Task.Run(async() =>
            {
                TData obj = new TData();
                long jobId = 0;
                JobDataMap jobData = null;
                AutoJobEntity dbJobEntity = null;
                try
                {
                    jobData = context.JobDetail.JobDataMap;
                    jobId = jobData["Id"].ParseToLong();
                    // 获取数据库中的任务
                    dbJobEntity = await autoJobService.GetEntity(jobId);
                    if (dbJobEntity != null)
                    {
                        if (dbJobEntity.JobStatus == StatusEnum.Yes.ParseToInt())
                        {
                            CronTriggerImpl trigger = context.Trigger as CronTriggerImpl;
                            if (trigger != null)
                            {
                                if (trigger.CronExpressionString != dbJobEntity.CronExpression)
                                {
                                    // 更新任务周期
                                    trigger.CronExpressionString = dbJobEntity.CronExpression;
                                    await JobScheduler.GetScheduler().RescheduleJob(trigger.Key, trigger);
                                }

                                #region 执行任务
                                switch (context.JobDetail.Key.Name)
                                {
                                case "数据库备份":
                                    obj = await new DatabasesBackupJob().Start();
                                    break;
                                }
                                #endregion
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    obj.Message = ex.GetOriginalException().Message;
                    LogHelper.Error(ex);
                }

                try
                {
                    if (dbJobEntity != null)
                    {
                        if (dbJobEntity.JobStatus == StatusEnum.Yes.ParseToInt())
                        {
                            #region 更新下次运行时间
                            await autoJobService.SaveForm(new AutoJobEntity
                            {
                                Id = dbJobEntity.Id,
                                NextStartTime = context.NextFireTimeUtc.Value.DateTime.AddHours(8)
                            });
                            #endregion

                            #region 记录执行状态
                            await autoJobLogService.SaveForm(new AutoJobLogEntity
                            {
                                JobGroupName = context.JobDetail.Key.Group,
                                JobName = context.JobDetail.Key.Name,
                                LogStatus = obj.Tag,
                                Remark = obj.Message
                            });
                            #endregion
                        }
                    }
                }
                catch (Exception ex)
                {
                    obj.Message = ex.GetOriginalException().Message;
                    LogHelper.Error(ex);
                }
            }));
        }
Пример #8
0
        public async Task <IActionResult> ChangeJobStatusJson(AutoJobEntity entity)
        {
            TData obj = await autoJobBLL.ChangeJobStatus(entity);

            return(Json(obj));
        }
Пример #9
0
        public async Task <IActionResult> SaveFormJson(AutoJobEntity entity)
        {
            TData <string> obj = await autoJobBLL.SaveForm(entity);

            return(Json(obj));
        }
Пример #10
0
        public Task Execute(IJobExecutionContext context)
        {
            return(Task.Run(async() =>
            {
                string f_Id = "", msg = "成功";
                int logStatus = 1;
                JobDataMap jobData = null;
                AutoJobEntity autoJobEntity = null;
                try
                {
                    jobData = context.JobDetail.JobDataMap;
                    f_Id = jobData["Id"].ToString();
                    // 获取数据库中的任务
                    autoJobEntity = autoJobApp.GetForm(f_Id);
                    if (autoJobEntity != null)
                    {
                        if (autoJobEntity.JobStatus == 1)
                        {
                            CronTriggerImpl trigger = context.Trigger as CronTriggerImpl;
                            if (trigger != null)
                            {
                                if (trigger.CronExpressionString != autoJobEntity.CronExpression)
                                {
                                    // 更新任务周期
                                    trigger.CronExpressionString = autoJobEntity.CronExpression;
                                    await JobScheduler.GetScheduler().RescheduleJob(trigger.Key, trigger);
                                }

                                #region 执行任务
                                switch (context.JobDetail.Key.Name)
                                {
                                case "Comrms":    //期货
                                    if (!new GetComrmsJob().Start())
                                    {
                                        logStatus = 0;
                                        msg = "失败";
                                    }
                                    break;

                                default:
                                    //todo
                                    break;
                                }
                                #endregion
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    msg = ex.ToString();
                    logStatus = 0;
                }

                try
                {
                    if (autoJobEntity != null)
                    {
                        if (autoJobEntity.JobStatus == 1)
                        {
                            //更新下次运行时间
                            DbHelper.ExecuteNonQuery("update Sys_AutoJob set NextStartTime='" + context.NextFireTimeUtc.Value.DateTime.AddHours(8) + "' where F_Id='" + autoJobEntity.F_Id + "'");

                            //记录执行状态
                            FRow fRow = new FRow("Sys_AutoJobLog");
                            fRow["F_CreatorTime"] = context.JobDetail.Key.Group;
                            fRow["JobGroupName"] = context.JobDetail.Key.Name;
                            fRow["LogStatus"] = logStatus;
                            fRow["F_Description"] = msg;
                            fRow.Insert();
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogFactory.GetLogger().Error(ex);
                }
            }));
        }
Пример #11
0
 public ActionResult SubmitForm(AutoJobEntity autoJobEntity, string keyValue)
 {
     autoJobApp.SubmitForm(autoJobEntity, keyValue);
     return(Success("操作成功。"));
 }
Пример #12
0
        public async Task <IActionResult> SyncDatabaseJson(AutoJobEntity entity)
        {
            TData obj = await databaseTableBLL.SyncDatabase();

            return(Json(obj));
        }