Пример #1
0
        /// <summary>
        /// 数据库基础表数据导出到json文件
        /// </summary>
        /// <param name="tableName">指定表名称</param>
        /// <param name="path">存放路径</param>
        /// <returns></returns>
        public async Task <string> ExportTable(string tableName, string path)
        {
            string outPaths = string.Empty;
            Dictionary <string, string> dic = new Dictionary <string, string>();

            switch (tableName.ToLower())
            {
            case "user":
                dic.Add(typeof(User).Name, JsonHelper.JSON(await _userSvc.Query()));
                break;

            case "dept":
                dic.Add(typeof(Dept).Name, JsonHelper.JSON(await _deptSvc.Query()));
                break;

            case "role":
                dic.Add(typeof(Role).Name, JsonHelper.JSON(await _roleSvc.Query()));
                break;

            case "menu":
                dic.Add(typeof(Menu).Name, JsonHelper.JSON(await _menuSvc.Query()));
                break;

            case "tasksqz":
                dic.Add(typeof(TasksQz).Name, JsonHelper.JSON(await _tasksQzSvc.Query()));
                break;

            default:
                dic.Add(typeof(User).Name, JsonHelper.JSON(await _userSvc.Query()));
                dic.Add(typeof(Dept).Name, JsonHelper.JSON(await _deptSvc.Query()));
                dic.Add(typeof(Role).Name, JsonHelper.JSON(await _roleSvc.Query()));
                dic.Add(typeof(Menu).Name, JsonHelper.JSON(await _menuSvc.Query()));
                dic.Add(typeof(TasksQz).Name, JsonHelper.JSON(await _tasksQzSvc.Query()));
                break;
            }

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            foreach (var item in dic)
            {
                string filePath = Path.Combine(path, $@"{item.Key}.json");

                using (FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))
                {
                    fs.SetLength(0); //清空文件内容
                    using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
                    {
                        sw.WriteLine(item.Value);
                    }
                }

                outPaths += $"表{item.Key}-数据生成:{filePath} || ";
            }
            return(outPaths[0..^ 4]);
Пример #2
0
        public static void UseQuartzJobMildd(this IApplicationBuilder app, ITasksQzSvc tasksQzSvc, ISchedulerCenter schedulerCenter)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }

            try
            {
                if (Appsettings.App("Middleware", "QuartzNetJob", "Enabled").ToBoolReq())
                {
                    var allQzServices = tasksQzSvc.Query().Result;
                    foreach (var item in allQzServices)
                    {
                        if (item.JobStatus == JobStatus.运行中)
                        {
                            var ResuleModel = schedulerCenter.AddScheduleJobAsync(item).Result;
                            if (ResuleModel.Success)
                            {
                                Console.WriteLine($"QuartzNetJob{item.JobName}启动成功!");
                            }
                            else
                            {
                                Console.WriteLine($"QuartzNetJob{item.JobName}启动失败!错误信息:{ResuleModel.Message}");
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                log.Error($"An error was reported when starting the job service.\n{e.Message}");
                throw;
            }
        }
Пример #3
0
        public async Task <object> GetTasksQz(string ids, string jobName = "")
        {
            var data = await _tasksQzSvc.Query();

            if (!string.IsNullOrEmpty(ids))
            {
                data = data.Where(a => ids.SplitInt(",").Contains(a.Id)).ToList();
            }

            if (!string.IsNullOrEmpty(jobName))
            {
                data = data.Where(a => a.JobName != null && a.JobName.Contains(jobName)).ToList();
            }

            if (data.Count > 0)
            {
                foreach (var item in data)
                {
                    item.Triggers = await _schedulerCenter.GetTaskStaus(item);
                }
            }

            return(new MessageModel <List <TasksQz> >()
            {
                Message = "获取成功",
                Success = true,
                Response = data
            });
        }