Example #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]);
Example #2
0
        public async Task <object> PostRole([FromBody] Role model)
        {
            var data = new MessageModel <Role>()
            {
                Message = "添加成功", Success = true
            };

            var dataList = await _roleSvc.Query(a => a.RoleName == model.RoleName);

            if (dataList.Count > 0)
            {
                data.Message = "该角色已存在";
                data.Success = false;
            }
            else
            {
                model.Id = await _roleSvc.Add(model);

                data.Response = model;
            }

            return(data);
        }