Exemple #1
0
        /// <summary>
        /// 添加表结构及字段结构记录
        /// </summary>
        private BuilderTable AddTableAndColumns(BuilderTable obj)
        {
            if (string.IsNullOrEmpty(obj.ClassName))
            {
                obj.ClassName = obj.TableName;
            }
            if (string.IsNullOrEmpty(obj.ModuleCode))
            {
                obj.ModuleCode = obj.TableName;
            }

            //todo:补充或调整自己需要的字段
            obj.CreateTime = DateTime.Now;
            var user = _auth.GetCurrentUser().User;

            obj.CreateUserId   = user.Id;
            obj.CreateUserName = user.Name;
            UnitWork.Add(obj);

            var columns = _dbExtension.GetDbTableStructure(obj.TableName);

            if (!columns.Any())
            {
                throw new Exception($"未能找到{obj.TableName}表结构定义");
            }
            foreach (var column in columns)
            {
                var builderColumn = new BuilderTableColumn
                {
                    ColumnName = column.ColumnName,
                    Comment    = column.Comment,
                    ColumnType = column.ColumnType,
                    EntityType = column.EntityType,
                    EntityName = column.ColumnName,

                    IsKey      = column.IsKey == 1,
                    IsRequired = column.IsNull != 1,
                    IsEdit     = true,
                    IsInsert   = true,
                    IsList     = true,
                    MaxLength  = column.MaxLength,
                    TableName  = obj.TableName,
                    TableId    = obj.Id,

                    CreateUserId   = user.Id,
                    CreateUserName = user.Name,
                    CreateTime     = DateTime.Now
                };
                UnitWork.Add(builderColumn);
            }

            return(obj);
        }
Exemple #2
0
        public string Add(AddOrUpdateBuilderTableReq req)
        {
            if (string.IsNullOrEmpty(req.TableName))
            {
                throw new Exception("英文表名不能为空");
            }

            if (string.IsNullOrEmpty(req.ModuleName))
            {
                throw new Exception("模块名称不能为空");
            }

            if (string.IsNullOrEmpty(req.Namespace))
            {
                throw new Exception("命名空间不能为空");
            }

            var columns = _dbExtension.GetDbTableStructure(req.TableName);

            if (!columns.Any())
            {
                throw new Exception($"未能找到{req.TableName}表结构定义");
            }

            var obj = req.MapTo <BuilderTable>();

            if (string.IsNullOrEmpty(obj.ClassName))
            {
                obj.ClassName = obj.TableName;
            }
            if (string.IsNullOrEmpty(obj.ModuleCode))
            {
                obj.ModuleCode = obj.TableName;
            }

            //todo:补充或调整自己需要的字段
            obj.CreateTime = DateTime.Now;
            var user = _auth.GetCurrentUser().User;

            obj.CreateUserId   = user.Id;
            obj.CreateUserName = user.Name;
            UnitWork.Add(obj);

            foreach (var column in columns)
            {
                var builderColumn = new BuilderTableColumn
                {
                    ColumnName = column.ColumnName,
                    Comment    = column.Comment,
                    ColumnType = column.ColumnType,
                    EntityType = column.EntityType,
                    EntityName = column.ColumnName,

                    IsKey      = column.IsKey == 1,
                    IsRequired = column.IsNull != 1,
                    IsEdit     = true,
                    IsInsert   = true,
                    IsList     = true,
                    MaxLength  = column.MaxLength,
                    TableName  = obj.TableName,
                    TableId    = obj.Id,

                    CreateUserId   = user.Id,
                    CreateUserName = user.Name,
                    CreateTime     = DateTime.Now
                };
                UnitWork.Add(builderColumn);
            }

            UnitWork.Save();
            return(obj.Id);
        }