Beispiel #1
0
        public JsonResult Create(JOB_TASKJOBSModel model)
        {
            try
            {
                string mes = "";
                if (!ValidateSQL(model.taskCmd, ref mes))
                {
                    return(Json(JsonHandler.CreateMessage(0, "为了方便测试安全" + mes)));
                }

                if (model == null || !ModelState.IsValid)
                {
                    return(Json(JsonHandler.CreateMessage(0, "上传参数错误")));
                }


                //新增
                m_BLL.Create(ref validationErrors, model);
                //写日志
                if (validationErrors.Count > 0)
                {
                    //错误写入日志
                    LogHandler.WriteServiceLog(GetUserId(), "创建任务管理ID:" + model.sno, "失败", "创建", "任务管理");
                    return(Json(JsonHandler.CreateMessage(0, validationErrors.Error)));
                }
                //成功写入日志
                LogHandler.WriteServiceLog(GetUserId(), "创建任务管理ID:" + model.sno, "成功", "创建", "任务管理");
                return(Json(JsonHandler.CreateMessage(1, Resource.DeleteSucceed)));
            }
            catch
            {
                return(Json(JsonHandler.CreateMessage(1, Resource.InsertFail)));
            }
        }
Beispiel #2
0
        public ActionResult Edit(JOB_TASKJOBSModel model)
        {
            try
            {
                if (model == null || !ModelState.IsValid)
                {
                    return(Json(JsonHandler.CreateMessage(0, "上传参数错误")));
                }

                m_BLL.Edit(ref validationErrors, model);
                //写日志
                if (validationErrors.Count > 0)
                {
                    //错误写入日志
                    LogHandler.WriteServiceLog(GetUserId(), "编辑任务管理ID:" + model.sno, "失败", "编辑", "任务管理");
                    return(Json(JsonHandler.CreateMessage(0, validationErrors.Error)));
                }
                //成功写入日志
                LogHandler.WriteServiceLog(GetUserId(), "编辑任务管理ID:" + model.sno, "成功", "编辑", "任务管理");
                return(Json(JsonHandler.CreateMessage(1, Resource.DeleteSucceed)));
            }
            catch
            {
                return(Json(JsonHandler.CreateMessage(0, Resource.UpdateFail)));
            }
        }
Beispiel #3
0
        public virtual async Task <JOB_TASKJOBSModel> GetByIdAsync(object id)
        {
            if (IsExists(id))
            {
                JOB_TASKJOBS entity = await m_Rep.GetByIdAsync(id);

                JOB_TASKJOBSModel model = new JOB_TASKJOBSModel();
                model.sno        = entity.sno;
                model.taskName   = entity.taskName;
                model.Id         = entity.Id;
                model.taskTitle  = entity.taskTitle;
                model.taskCmd    = entity.taskCmd;
                model.crtDt      = entity.crtDt;
                model.state      = entity.state;
                model.creator    = entity.creator;
                model.procName   = entity.procName;
                model.procParams = entity.procParams;

                return(model);
            }
            else
            {
                return(null);
            }
        }
Beispiel #4
0
        public ActionResult Details(string sno)
        {
            if (!ModelState.IsValid)
            {
                return(null);
            }
            JOB_TASKJOBSModel model = m_BLL.GetModelById(sno);

            return(View(model));
        }
Beispiel #5
0
        public virtual async Task <Tuple <ValidationErrors, bool> > CreateAsync(JOB_TASKJOBSModel model)
        {
            ValidationErrors errors = new ValidationErrors();

            try
            {
                JOB_TASKJOBS entity = await m_Rep.GetByIdAsync(model.sno);

                if (entity != null)
                {
                    errors.Add(Resource.PrimaryRepeat);
                    return(new Tuple <ValidationErrors, bool>(errors, false));
                }
                entity            = new JOB_TASKJOBS();
                entity.sno        = model.sno;
                entity.taskName   = model.taskName;
                entity.Id         = model.Id;
                entity.taskTitle  = model.taskTitle;
                entity.taskCmd    = model.taskCmd;
                entity.crtDt      = model.crtDt;
                entity.state      = model.state;
                entity.creator    = model.creator;
                entity.procName   = model.procName;
                entity.procParams = model.procParams;


                if (await m_Rep.CreateAsync(entity))
                {
                    return(new Tuple <ValidationErrors, bool>(errors, true));
                }
                else
                {
                    errors.Add(Resource.InsertFail);
                    return(new Tuple <ValidationErrors, bool>(errors, false));
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return(new Tuple <ValidationErrors, bool>(errors, false));
            }
        }
        public virtual bool Create(ref ValidationErrors errors, JOB_TASKJOBSModel model)
        {
            try
            {
                JOB_TASKJOBS entity = m_Rep.GetById(model.sno);
                if (entity != null)
                {
                    errors.Add(Resource.PrimaryRepeat);
                    return(false);
                }
                entity            = new JOB_TASKJOBS();
                entity.sno        = model.sno;
                entity.taskName   = model.taskName;
                entity.Id         = model.Id;
                entity.taskTitle  = model.taskTitle;
                entity.taskCmd    = model.taskCmd;
                entity.crtDt      = model.crtDt;
                entity.state      = model.state;
                entity.creator    = model.creator;
                entity.procName   = model.procName;
                entity.procParams = model.procParams;


                if (m_Rep.Create(entity))
                {
                    return(true);
                }
                else
                {
                    errors.Add(Resource.InsertFail);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return(false);
            }
        }
        public virtual bool Edit(ref ValidationErrors errors, JOB_TASKJOBSModel model)
        {
            try
            {
                JOB_TASKJOBS entity = m_Rep.GetById(model.sno);
                if (entity == null)
                {
                    errors.Add(Resource.Disable);
                    return(false);
                }
                entity.sno        = model.sno;
                entity.taskName   = model.taskName;
                entity.Id         = model.Id;
                entity.taskTitle  = model.taskTitle;
                entity.taskCmd    = model.taskCmd;
                entity.crtDt      = model.crtDt;
                entity.state      = model.state;
                entity.creator    = model.creator;
                entity.procName   = model.procName;
                entity.procParams = model.procParams;



                if (m_Rep.Edit(entity))
                {
                    return(true);
                }
                else
                {
                    errors.Add(Resource.NoDataChange);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return(false);
            }
        }
Beispiel #8
0
        //根据主键获取模型
        public JOB_TASKJOBSModel GetModelById(string sno)
        {
            var entity = m_Rep.GetById(sno);

            if (entity == null)
            {
                return(null);
            }
            JOB_TASKJOBSModel model = new JOB_TASKJOBSModel();

            //实现对象到模型转换
            model.sno       = entity.sno;
            model.taskName  = entity.taskName;
            model.Id        = entity.Id;
            model.taskTitle = entity.taskTitle;
            model.taskCmd   = entity.taskCmd;
            model.crtDt     = entity.crtDt;
            model.state     = entity.state;
            model.creator   = entity.creator;

            return(model);
        }
        public virtual JOB_TASKJOBSModel GetById(string id)
        {
            if (IsExists(id))
            {
                JOB_TASKJOBS      entity = m_Rep.GetById(id);
                JOB_TASKJOBSModel model  = new JOB_TASKJOBSModel();
                model.sno        = entity.sno;
                model.taskName   = entity.taskName;
                model.Id         = entity.Id;
                model.taskTitle  = entity.taskTitle;
                model.taskCmd    = entity.taskCmd;
                model.crtDt      = entity.crtDt;
                model.state      = entity.state;
                model.creator    = entity.creator;
                model.procName   = entity.procName;
                model.procParams = entity.procParams;

                return(model);
            }
            else
            {
                return(null);
            }
        }
Beispiel #10
0
        /// <summary>
        /// 校验Excel数据,这个方法一般用于重写校验逻辑
        /// </summary>
        public virtual bool CheckImportData(string fileName, List <JOB_TASKJOBSModel> list, ref ValidationErrors errors)
        {
            var targetFile = new FileInfo(fileName);

            if (!targetFile.Exists)
            {
                errors.Add("导入的数据文件不存在");
                return(false);
            }

            var excelFile = new ExcelQueryFactory(fileName);

            //对应列头
            excelFile.AddMapping <JOB_TASKJOBSModel>(x => x.sno, "sno");
            excelFile.AddMapping <JOB_TASKJOBSModel>(x => x.taskName, "taskName");
            excelFile.AddMapping <JOB_TASKJOBSModel>(x => x.taskTitle, "taskTitle");
            excelFile.AddMapping <JOB_TASKJOBSModel>(x => x.taskCmd, "taskCmd");
            excelFile.AddMapping <JOB_TASKJOBSModel>(x => x.crtDt, "crtDt");
            excelFile.AddMapping <JOB_TASKJOBSModel>(x => x.state, "state");
            excelFile.AddMapping <JOB_TASKJOBSModel>(x => x.creator, "creator");
            excelFile.AddMapping <JOB_TASKJOBSModel>(x => x.procName, "procName");
            excelFile.AddMapping <JOB_TASKJOBSModel>(x => x.procParams, "procParams");

            //SheetName
            var excelContent = excelFile.Worksheet <JOB_TASKJOBSModel>(0);
            int rowIndex     = 1;

            //检查数据正确性
            foreach (var row in excelContent)
            {
                var errorMessage = new StringBuilder();
                var entity       = new JOB_TASKJOBSModel();
                entity.sno        = row.sno;
                entity.taskName   = row.taskName;
                entity.Id         = row.Id;
                entity.taskTitle  = row.taskTitle;
                entity.taskCmd    = row.taskCmd;
                entity.crtDt      = row.crtDt;
                entity.state      = row.state;
                entity.creator    = row.creator;
                entity.procName   = row.procName;
                entity.procParams = row.procParams;

                //=============================================================================
                if (errorMessage.Length > 0)
                {
                    errors.Add(string.Format(
                                   "第 {0} 列发现错误:{1}{2}",
                                   rowIndex,
                                   errorMessage,
                                   "<br/>"));
                }
                list.Add(entity);
                rowIndex += 1;
            }
            if (errors.Count > 0)
            {
                return(false);
            }
            return(true);
        }
Beispiel #11
0
        /// <summary>
        /// 复杂任务
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="model"></param>
        /// <param name="errors"></param>
        /// <returns></returns>
        public int runComplex <T>(JobModel model, ref ValidationErrors errors) where T : IJob
        {
            try
            {
                //是否为简单任务
                if (model.taskType != 1)
                {
                    errors.Add("不是复杂任务");
                    return(0);
                }

                if (string.IsNullOrEmpty(model.cronExpression))
                {
                    errors.Add("任务表达式不能为空,请正确执行时间");
                    return(0);
                }

                //对表达式进行检查

                //执行前置任务
                string error = RunBefore(model);
                if (!string.IsNullOrEmpty(error))
                {
                    errors.Add(error);
                    return(0);
                }

                /////////////////////////////////////////////////////////////////
                // construct a scheduler factory
                ISchedulerFactory schedFact = new StdSchedulerFactory();

                // get a scheduler
                IScheduler sched = schedFact.GetScheduler();
                /////////////////////////////////////////////////////////////////////////

                //在开始时间的10秒后执行
                DateTimeOffset runTime = new DateTimeOffset(model.startDate).AddSeconds(10);

                string Description = model.taskName + "任务时间:" + runTime + ",创建时间:" + DateTime.Now;
                //生成作业名称,作业名称=任务名称 +任务ID+序号
                string jobName = model.taskName + "_" + model.id + "_" + NewGuid();
                //向Job_TaskJobs增加任务
                string sno = JOB_PRIFEX + jobName;

                string taskCmd;
                taskCmd = "秒:" + model.seconds + " 分:" + model.minutes + " 小时:" + model.hours +
                          " 日/月:" + model.dayOfMonth + " 月:" + model.month + " 日/周:" + model.dayOfWeek + " 指令表达式:" + model.cronExpression;

                JOB_TASKJOBSModel taskJobsModel = new JOB_TASKJOBSModel();
                taskJobsModel.sno       = sno;
                taskJobsModel.taskName  = model.taskName;
                taskJobsModel.Id        = model.id;
                taskJobsModel.taskTitle = model.taskTitle;
                taskJobsModel.taskCmd   = taskCmd;
                taskJobsModel.crtDt     = DateTime.Now;
                taskJobsModel.state     = 0;
                taskJobsModel.creator   = model.creator;
                IJOB_TASKJOBSBLL taskJobsBLL = new JOB_TASKJOBSBLL()
                {
                    m_Rep = new JOB_TASKJOBSRepository(new DBContainer())
                };
                if (!taskJobsBLL.Create(ref errors, taskJobsModel))
                {
                    return(0);
                }
                /////////////////////////////////////////////////
                IJobDetail job = JobBuilder.Create <T>()
                                 .WithIdentity(JOB_PRIFEX + jobName, "group1")
                                 .WithDescription(Description)
                                 .Build();
                //



                ICronTrigger trigger = (ICronTrigger)TriggerBuilder.Create()
                                       .WithIdentity(TRIGGER_PRIFEX + jobName, "group1")
                                       .WithCronSchedule(model.cronExpression)
                                       .WithDescription(Description)
                                       .Build();

                //如果已存在相同任务删除
                if (sched.CheckExists(job.Key))
                {
                    sched.DeleteJob(job.Key);
                }
                //传入任务关键字参数(任务ID标识、任务名称)
                job.JobDataMap.Put(TaskJob.ID, model.id);             //传入任务ID标识
                job.JobDataMap.Put(TaskJob.TASKNAME, model.taskName); //传入任务名称,带命名空间

                //传入任务其他参数列表
                if (model.param != null)
                {
                    for (int i = 0; i < model.param.GetLength(0); i++)
                    {
                        job.JobDataMap.Put(model.param[i, 0], model.param[i, 1]);
                    }
                }

                //////////////////////////////////////////////////////////
                DateTimeOffset dtoff = sched.ScheduleJob(job, trigger);
                return(1);
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                return(0);
            }
        }
Beispiel #12
0
        /// <summary>
        /// 简单任务
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="model"></param>
        /// <param name="errors"></param>
        /// <returns></returns>
        public int runSample <T>(JobModel model, ref ValidationErrors errors) where T : IJob
        {
            try
            {
                //是否为简单任务
                if (model.taskType != 0)
                {
                    errors.Add("不是简单任务");
                    return(0);
                }

                //间隔类型
                if (string.IsNullOrEmpty(model.intervalType))
                {
                    errors.Add("未设置间隔类型");
                    return(0);
                }
                //时间间隔
                if (model.intervalCount < 0)
                {
                    errors.Add("未设置间隔次数(0为无限次)");
                    return(0);
                }
                //如果开始时间少于当前时间,取当前时间

                if (DateTime.Now > model.startDate)
                {
                    model.startDate = DateTime.Now;
                }

                //执行前置任务
                string error = RunBefore(model);
                if (!string.IsNullOrEmpty(error))
                {
                    errors.Add(error);
                    return(0);
                }
                /////////////////////////////////////////////////////////////
                // construct a scheduler factory
                ISchedulerFactory schedFact = new StdSchedulerFactory();

                // get a scheduler
                IScheduler sched = schedFact.GetScheduler();
                /////////////////////////////////////////////////////////////////////////

                //在开始时间的10秒后执行
                DateTimeOffset runTime = new DateTimeOffset(model.startDate).AddSeconds(10);

                string Description = model.taskName + "任务时间:" + runTime + ",创建时间:" + DateTime.Now;
                //生成作业名称,作业名称=任务名称 +任务ID
                string jobName = model.taskName + "_" + model.id + "_" + NewGuid();

                //向Job_TaskJobs增加任务

                string sno           = JOB_PRIFEX + jobName;
                string intervalTitle = model.intervalType == "second" ? "秒" : model.intervalType == "minute" ? "分" : model.intervalType == "hour" ? "小时" : "天";

                string teskCmd;
                if (model.repeatForever)
                {
                    teskCmd = "start:" + model.startDate + " 重复:无限次 间隔:" + model.intervalCount + " " + intervalTitle + " ";
                }
                else
                {
                    teskCmd = "start:" + model.startDate + " 重复:" + model.repeatCount + " 间隔:" + model.intervalCount + " " + intervalTitle + " ";
                }
                JOB_TASKJOBSModel taskJobsModel = new JOB_TASKJOBSModel();
                taskJobsModel.sno        = sno;
                taskJobsModel.taskName   = model.taskName;
                taskJobsModel.Id         = model.id;
                taskJobsModel.taskTitle  = model.taskTitle;
                taskJobsModel.taskCmd    = teskCmd;
                taskJobsModel.crtDt      = DateTime.Now;
                taskJobsModel.state      = 0;
                taskJobsModel.creator    = model.creator;
                taskJobsModel.procName   = model.procName;
                taskJobsModel.procParams = model.procParams;

                IJOB_TASKJOBSBLL taskJobsBLL = new JOB_TASKJOBSBLL()
                {
                    m_Rep = new JOB_TASKJOBSRepository(new DBContainer())
                };
                if (!taskJobsBLL.Create(ref errors, taskJobsModel))
                {
                    return(0);
                }
                /////////////////////////////////////////////////

                IJobDetail job = JobBuilder.Create <T>()
                                 .WithIdentity(JOB_PRIFEX + jobName, "group1")
                                 .WithDescription(Description)
                                 .Build();
                //

                ITrigger trigger = null;
                //执行重复次数
                if (model.repeatForever)
                {
                    //无限次
                    switch (model.intervalType.ToLower())
                    {
                    case "day":    //日
                        TimeSpan ts = new TimeSpan(model.intervalCount, 0, 0, 0);

                        trigger = TriggerBuilder.Create()
                                  .WithIdentity(TRIGGER_PRIFEX + jobName, "group1")
                                  .StartAt(model.startDate)
                                  .WithSimpleSchedule(a => a.WithInterval(ts).RepeatForever())
                                  .WithDescription(Description)
                                  .Build();

                        break;

                    case "hour":    //小时
                        trigger = TriggerBuilder.Create()
                                  .WithIdentity(TRIGGER_PRIFEX + jobName, "group1")
                                  .StartAt(model.startDate)
                                  .WithSimpleSchedule(a => a.WithIntervalInHours(model.intervalCount).RepeatForever())
                                  .WithDescription(Description)
                                  .Build();
                        break;

                    case "minute":    //分
                        trigger = TriggerBuilder.Create()
                                  .WithIdentity(TRIGGER_PRIFEX + jobName, "group1")
                                  .StartAt(model.startDate)
                                  .WithSimpleSchedule(a => a.WithIntervalInMinutes(model.intervalCount).RepeatForever())
                                  .WithDescription(Description)
                                  .Build();
                        break;

                    case "second":    //秒
                        trigger = TriggerBuilder.Create()
                                  .WithIdentity(TRIGGER_PRIFEX + jobName, "group1")
                                  .StartAt(model.startDate)
                                  .WithSimpleSchedule(a => a.WithIntervalInSeconds(model.intervalCount).RepeatForever())
                                  .WithDescription(Description)
                                  .Build();
                        break;

                    default:
                        trigger = TriggerBuilder.Create()
                                  .WithIdentity(TRIGGER_PRIFEX + jobName, "group1")
                                  .StartAt(model.startDate)
                                  .WithDescription(Description)
                                  .Build();
                        break;
                    }
                }
                else
                {
                    //有限次
                    switch (model.intervalType.ToLower())
                    {
                    case "day":    //日
                        TimeSpan ts = new TimeSpan(model.intervalCount, 0, 0, 0);

                        trigger = TriggerBuilder.Create()
                                  .WithIdentity(TRIGGER_PRIFEX + jobName, "group1")
                                  .StartAt(model.startDate)
                                  .WithSimpleSchedule(a => a.WithInterval(ts).WithRepeatCount(model.repeatCount))
                                  .WithDescription(Description)
                                  .Build();

                        break;

                    case "hour":    //小时
                        trigger = TriggerBuilder.Create()
                                  .WithIdentity(TRIGGER_PRIFEX + jobName, "group1")
                                  .StartAt(model.startDate)
                                  .WithSimpleSchedule(a => a.WithIntervalInHours(model.intervalCount).WithRepeatCount(model.repeatCount))
                                  .WithDescription(Description)
                                  .Build();
                        break;

                    case "minute":    //分
                        trigger = TriggerBuilder.Create()
                                  .WithIdentity(TRIGGER_PRIFEX + jobName, "group1")
                                  .StartAt(model.startDate)
                                  .WithSimpleSchedule(a => a.WithIntervalInMinutes(model.intervalCount).WithRepeatCount(model.repeatCount))
                                  .WithDescription(Description)
                                  .Build();
                        break;

                    case "second":    //秒
                        trigger = TriggerBuilder.Create()
                                  .WithIdentity(TRIGGER_PRIFEX + jobName, "group1")
                                  .StartAt(model.startDate)
                                  .WithSimpleSchedule(a => a.WithIntervalInSeconds(model.intervalCount).WithRepeatCount(model.repeatCount))
                                  .WithDescription(Description)
                                  .Build();
                        break;

                    default:
                        trigger = TriggerBuilder.Create()
                                  .WithIdentity(TRIGGER_PRIFEX + jobName, "group1")
                                  .StartAt(model.startDate)
                                  .WithDescription(Description)
                                  .Build();
                        break;
                    }
                }

                //如果已存在相同任务删除
                if (sched.CheckExists(job.Key))
                {
                    sched.DeleteJob(job.Key);
                }
                //传入任务关键字参数(任务ID标识、任务名称)
                job.JobDataMap.Put(TaskJob.ID, model.id);             //传入任务ID标识
                job.JobDataMap.Put(TaskJob.TASKNAME, model.taskName); //传入任务名称,带命名空间

                //传入任务其他参数列表
                if (model.param != null)
                {
                    for (int i = 0; i < model.param.GetLength(0); i++)
                    {
                        job.JobDataMap.Put(model.param[i, 0], model.param[i, 1]);
                    }
                }
                //////////////////////////////////////////////////////////
                DateTimeOffset dtoff = sched.ScheduleJob(job, trigger);


                return(1);
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                return(0);
            }
        }