Example #1
0
        public async Task <ResponsResult> DelTaskAsync(TaskScheduleModel model)
        {
            ResponsResult result = new ResponsResult();

            if (model == null)
            {
                return(result.SetError("Model 不能为空!"));
            }
            if (string.IsNullOrEmpty(model.JobName))
            {
                return(result.SetError("JobName 不能为空!"));
            }
            if (string.IsNullOrEmpty(model.JobGroup))
            {
                return(result.SetError("JobGroup 不能为空!"));
            }
            //search
            var taskInfo = base.Single <TaskSchedule>(t => t.Id.Equals(model.Id));
            var info     = await jobCenter.StopScheduleJobAsync(model.JobGroup, model.JobName);

            if (!info.Status.Equals(200))
            {
                return(result.SetError(info.Message));
            }
            //del
            base.Delete(taskInfo, true);
            return(result);
        }
        public ResponsResult SaveHelp(InformationModel model)
        {
            ResponsResult result = new ResponsResult();

            if ((int)model.Type < 1)
            {
                return(result.SetError("请选择类型"));
            }
            if (model.Type != InformationType.UseGuide)
            {
                var info = this.First <Informations>(t => t.Type == (int)model.Type);
                if (info == null)
                {
                    info = new Informations {
                        Id = this.GenNewGuid(), CreateTime = DateTime.Now, Type = (int)model.Type, Title = model.Type.GetString()
                    };
                    this.Add(info);
                }
                else
                {
                    info.UpdateTime = DateTime.Now;
                    this.Update(info);
                }
                info.Description = model.Description;
                model.Id         = info.Id;
                this.Save();
            }
            else
            {
                if (string.IsNullOrEmpty(model.Title))
                {
                    return(result.SetError("请输入标题"));
                }
                var info = this.Single <Informations>(t => t.Id == model.Id);
                if (info == null)
                {
                    info = new Informations {
                        Id = this.GenNewGuid(), CreateTime = DateTime.Now, Type = (int)model.Type
                    };
                    this.Add(info);
                }
                else
                {
                    info.UpdateTime = DateTime.Now;
                    this.Update(info);
                }
                info.Title       = model.Title.Trim();
                info.Description = model.Description;
                model.Id         = info.Id;
                this.Save();
            }
            result.Data = model.Id;
            return(result);
        }
Example #3
0
        public ResponsResult Post([FromBody] FileUploadModel model)
        {
            ResponsResult result = new ResponsResult();

            try
            {
                var ext = System.IO.Path.GetExtension(model.FileName);
                if (string.IsNullOrEmpty(ext))
                {
                    ext = ".jpg";
                }
                string _fileName  = $"{model.Type}_{DateTime.Now.ToString("yyyyMMddHHmmssfffffff")}{ext}";
                var    _virtual   = PathServerUtility.Combine(System.Enum.GetName(typeof(FileType), model.Type), model.Id.ToString(), _fileName);
                var    webApiPath = ConfigLocator.Instance[TbConstant.WebSiteKey] + "/api/UploadBase64File";
                var    sign       = Security.Sign(Domain.Config.TbConstant.UploadKey, _virtual);
                model.Picture = Convert.ToBase64String(ImageHandler.ShrinkImage(ImageHandler.Base64ToBytes(model.Picture)));
                string response;
                if (!string.IsNullOrEmpty(model.WaterMarks))
                {
                    response = HttpUtility.PostString(webApiPath, new { sign = sign, base64 = model.Picture, fileName = _virtual, watermarks = model.WaterMarks }.GetJson(), "application/json");
                }
                else
                {
                    response = HttpUtility.PostString(webApiPath, new { sign = sign, base64 = model.Picture, fileName = _virtual }.GetJson(), "application/json");
                }
                var uploadModel = (response.GetModel <ResponsResult>().Data as Newtonsoft.Json.Linq.JObject).ToObject <UploadModel>();
                result.Data = uploadModel;
                return(result);
            }
            catch (Exception ex)
            {
                Log4Net.Error($"[上传图片异常]_:{ex}");
                return(result.SetError("上传图片异常"));
            }
        }
Example #4
0
        /// <summary>
        /// 删除指定角色
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponsResult DeleteRoles(RoleModel model)
        {
            ResponsResult result = new ResponsResult();
            //
            var backageUser = base.First <BackstageUser>(t => t.RoleId == model.Id);

            if (backageUser != null)
            {
                return(result.SetError("该角色下有管理人员,禁止删除该角色!"));
            }
            var role = base.Single <SystemRoles>(t => t.Id == model.Id);

            if (role != null)
            {
                var o1 = base.Where <SystemRolePermission>(t => t.RoleId == role.Id).ToList();
                o1.ForEach((Action <SystemRolePermission>)(t =>
                {
                    if (!model.Menus.Contains(t.ActionId))
                    {
                        base.Delete((object)t);
                    }
                }));
                base.Delete(role, true);
            }
            return(result);
        }
Example #5
0
        public async Task <ResponsResult> AddTaskAsync(TaskScheduleModel model)
        {
            ResponsResult result = new ResponsResult();

            if (model == null)
            {
                return(result.SetError("Model 不能为空!"));
            }
            if (string.IsNullOrEmpty(model.JobName))
            {
                return(result.SetError("JobName 不能为空!"));
            }
            if (string.IsNullOrEmpty(model.JobGroup))
            {
                return(result.SetError("JobGroup 不能为空!"));
            }
            if (model.StarRunTime == null)
            {
                model.StarRunTime = DateTime.Now;
            }
            if (model.EndRunTime == null)
            {
                model.EndRunTime = DateTime.MaxValue.AddDays(-1);
            }
            var info = await jobCenter.AddScheduleJobAsync(model);

            if (info.Status != 200)
            {
                return(result.SetError(info.Message));
            }
            base.Add(new TaskSchedule
            {
                Id          = Guid.NewGuid().ToString("N"),
                CreateAuthr = identity.Name,
                CronExpress = model.CronExpress,
                EndRunTime  = model.EndRunTime,
                StarRunTime = model.StarRunTime,
                JobGroup    = model.JobGroup,
                JobName     = model.JobName,
                RunStatus   = model.RunStatus
            }, true);
            return(result);
        }
Example #6
0
        /// <summary>
        /// 添加任务计划//或者进程终止后的开启
        /// </summary>
        /// <returns></returns>
        public async Task <ResponsResult> AddScheduleJobAsync(TaskScheduleModel m)
        {
            ResponsResult result = new ResponsResult();

            try
            {
                if (m != null)
                {
                    DateTimeOffset starRunTime = DateBuilder.NextGivenSecondDate(m.StarRunTime, 1);
                    DateTimeOffset endRunTime  = DateBuilder.NextGivenSecondDate(m.EndRunTime, 1);
                    scheduler = await GetSchedulerAsync();

                    IJobDetail job = JobBuilder.Create <HttpJob>()
                                     .WithIdentity(m.JobName, m.JobGroup)
                                     .Build();
                    ICronTrigger trigger = (ICronTrigger)TriggerBuilder.Create()
                                           .StartAt(starRunTime)
                                           .EndAt(endRunTime)
                                           .WithIdentity(m.JobName, m.JobGroup)
                                           .WithCronSchedule(m.CronExpress)
                                           .Build();
                    await scheduler.ScheduleJob(job, trigger);

                    await scheduler.Start();

                    result.Data = m;
                    return(result);
                }
                return(result.SetError("传入实体为空"));
            }
            catch (Exception ex)
            {
                Log4Net.Error($"[JobCenter_AddScheduleJobAsync]_{ex}");
                return(result.SetError(ex.Message));
            }
        }
Example #7
0
        public async Task <ResponsResult> ModifyTaskAsync(TaskScheduleModel model)
        {
            ResponsResult result = new ResponsResult();

            if (model == null)
            {
                return(result.SetError("Model 不能为空!"));
            }
            if (string.IsNullOrEmpty(model.JobName))
            {
                return(result.SetError("JobName 不能为空!"));
            }
            if (string.IsNullOrEmpty(model.JobGroup))
            {
                return(result.SetError("JobGroup 不能为空!"));
            }
            if (model.StarRunTime == null)
            {
                model.StarRunTime = DateTime.Now;
            }
            if (model.EndRunTime == null)
            {
                model.EndRunTime = DateTime.MaxValue.AddDays(-1);
            }
            //modify
            var taskInfo = base.Single <TaskSchedule>(t => t.Id.Equals(model.Id));

            if (taskInfo == null)
            {
                return(result.SetError("无此任务!"));
            }
            //cron
            if (!taskInfo.CronExpress.Equals(model.CronExpress))
            {
                taskInfo.CronExpress = model.CronExpress;
                var stopInfo = await jobCenter.StopScheduleJobAsync(model.JobGroup, model.JobName);

                if (!stopInfo.Status.Equals(200))
                {
                    return(result.SetError(stopInfo.Message));
                }

                var info = await jobCenter.AddScheduleJobAsync(model);

                if (!stopInfo.Status.Equals(200))
                {
                    return(result.SetError(info.Message));
                }
            }


            //状态
            if (!taskInfo.RunStatus.Equals(model.RunStatus))
            {
                taskInfo.RunStatus = model.RunStatus;
                if (model.RunStatus != (int)TaskJobStatus.PauseJob)
                {
                    var stopInfo = await jobCenter.StopScheduleJobAsync(model.JobGroup, model.JobName);

                    if (!stopInfo.Status.Equals(200))
                    {
                        return(result.SetError(stopInfo.Message));
                    }
                    var info = await jobCenter.AddScheduleJobAsync(model);

                    if (!stopInfo.Status.Equals(200))
                    {
                        return(result.SetError(info.Message));
                    }
                }
                else
                {
                    var stopInfo = await jobCenter.StopScheduleJobAsync(model.JobGroup, model.JobName);

                    if (!stopInfo.Status.Equals(200))
                    {
                        return(result.SetError(stopInfo.Message));
                    }
                }
            }
            //
            taskInfo.CreateAuthr = identity.Name;
            taskInfo.UpdateTime  = DateTime.Now;
            taskInfo.EndRunTime  = model.EndRunTime;
            taskInfo.StarRunTime = model.StarRunTime;
            taskInfo.JobGroup    = model.JobGroup;
            taskInfo.JobName     = model.JobName;

            base.Update(taskInfo, true);
            return(result);
        }