修改数据表结构功能
This commit is contained in:
1 parent
1b03cf2c48
commit
9947ab3fa8
4 files changed
+75
-5
No files matched your search
+46
-3
@@ -91,6 +91,15 @@ func InsertSysTable(c *gin.Context) {
|
||||
dbtable, err := dbTable.Get()
|
||||
|
||||
dbColumn.TableName = data.TableName
|
||||
tablenamelist := strings.Split(dbColumn.TableName, "_")
|
||||
for i := 0; i < len(tablenamelist); i++ {
|
||||
strStart := string([]byte(tablenamelist[i])[:1])
|
||||
strend := string([]byte(tablenamelist[i])[1:])
|
||||
data.ClassName += strings.ToUpper(strStart) + strend
|
||||
data.PackageName += strings.ToLower(strStart) + strings.ToLower(strend)
|
||||
}
|
||||
data.TplCategory = "crud"
|
||||
|
||||
dbcolumn, err := dbColumn.GetList()
|
||||
data.CreateTime = utils.GetCurrntTime()
|
||||
data.CreateBy = utils.GetUserIdStr(c)
|
||||
@@ -110,17 +119,27 @@ func InsertSysTable(c *gin.Context) {
|
||||
column.IsPk = "1"
|
||||
column.Pk = true
|
||||
}
|
||||
|
||||
namelist := strings.Split(dbcolumn[i].ColumnName, "_")
|
||||
for i := 0; i < len(namelist); i++ {
|
||||
strStart := string([]byte(namelist[i])[:1])
|
||||
strend := string([]byte(namelist[i])[1:])
|
||||
column.GoField += strings.ToUpper(strStart) + strend
|
||||
if i == 0 {
|
||||
column.JsonField = strings.ToLower(strStart) + strend
|
||||
} else {
|
||||
column.JsonField += strings.ToUpper(strStart) + strend
|
||||
}
|
||||
}
|
||||
column.IsRequired = "0"
|
||||
if strings.Contains(dbcolumn[i].IsNullable, "NO") {
|
||||
column.IsRequired = "1"
|
||||
column.Required = true
|
||||
}
|
||||
|
||||
if strings.Contains(dbcolumn[i].ColumnType, "int") {
|
||||
column.GoType = "int64"
|
||||
column.HtmlType = "input"
|
||||
//} else if strings.Contains(dbcolumn[i].ColumnType, "char") {
|
||||
// column.GoType = "bool"
|
||||
// column.HtmlType = "input"
|
||||
} else {
|
||||
column.GoType = "string"
|
||||
column.HtmlType = "input"
|
||||
@@ -139,6 +158,30 @@ func InsertSysTable(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
// @Summary 修改表结构
|
||||
// @Description 修改表结构
|
||||
// @Tags 工具 - 生成表
|
||||
// @Accept application/json
|
||||
// @Product application/json
|
||||
// @Param data body models.Dept true "body"
|
||||
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
|
||||
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
|
||||
// @Router /api/v1/sys/tables/info [put]
|
||||
// @Security Bearer
|
||||
func UpdateSysTable(c *gin.Context) {
|
||||
var data tools.SysTables
|
||||
err := c.Bind(&data)
|
||||
pkg.AssertErr(err, "数据解析失败", -1)
|
||||
data.UpdateBy = utils.GetUserIdStr(c)
|
||||
result, err := data.Update()
|
||||
pkg.AssertErr(err, "", -1)
|
||||
|
||||
var res models.Response
|
||||
res.Data = result
|
||||
res.Msg = "修改成功"
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
// @Summary 删除表结构
|
||||
// @Description 删除表结构
|
||||
// @Tags 工具 - 生成表
|
||||
|
||||
@@ -13,6 +13,7 @@ type SysColumns struct {
|
||||
ColumnType string `gorm:"column:column_type" json:"columnType"`
|
||||
GoType string `gorm:"column:go_type" json:"goType"`
|
||||
GoField string `gorm:"column:go_field" json:"goField"`
|
||||
JsonField string `gorm:"column:json_field" json:"jsonField"`
|
||||
IsPk string `gorm:"column:is_pk" json:"isPk"`
|
||||
IsIncrement string `gorm:"column:is_increment" json:"isIncrement"`
|
||||
IsRequired string `gorm:"column:is_required" json:"isRequired"`
|
||||
@@ -65,3 +66,19 @@ func (e *SysColumns) Create() (SysColumns, error) {
|
||||
doc = *e
|
||||
return doc, nil
|
||||
}
|
||||
|
||||
func (e *SysColumns) Update() (update SysColumns, err error) {
|
||||
e.UpdateTime = utils.GetCurrntTime()
|
||||
if err = orm.Eloquent.Table("sys_columns").First(&update, e.ColumnId).Error; err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
//参数1:是要修改的数据
|
||||
//参数2:是修改的数据
|
||||
if err = orm.Eloquent.Table("sys_columns").Model(&update).Updates(&e).Error; err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -39,10 +39,16 @@ type SysTables struct {
|
||||
UpdateBy string `gorm:"column:update_By" json:"updateBy"`
|
||||
UpdateTime string `gorm:"column:update_time" json:"updateTime"`
|
||||
DataScope string `gorm:"-" json:"dataScope"`
|
||||
Params string `gorm:"-" json:"params"`
|
||||
Params Params `gorm:"-" json:"params"`
|
||||
Columns []SysColumns `gorm:"-" json:"columns"`
|
||||
}
|
||||
|
||||
type Params struct {
|
||||
TreeCode string `gorm:"-" json:"treeCode"`
|
||||
TreeParentCode string `gorm:"-" json:"treeParentCode"`
|
||||
TreeName string `gorm:"-" json:"treeName"`
|
||||
}
|
||||
|
||||
func (e *SysTables) GetPage(pageSize int, pageIndex int) ([]SysTables, int32, error) {
|
||||
var doc []SysTables
|
||||
|
||||
@@ -120,6 +126,10 @@ func (e *SysTables) Update() (update SysTables, err error) {
|
||||
if err = orm.Eloquent.Table("sys_tables").Model(&update).Updates(&e).Error; err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for i:=0;i< len(e.Columns);i++ {
|
||||
_, _ = e.Columns[i].Update()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -60,9 +60,9 @@ func InitRouter() *gin.Engine {
|
||||
apiv1.GET("/db/columns/page", GetDBColumnList)
|
||||
apiv1.GET("/sys/tables/page", GetSysTableList)
|
||||
apiv1.POST("/sys/tables/info", InsertSysTable)
|
||||
apiv1.PUT("/sys/tables/info", UpdateSysTable)
|
||||
apiv1.DELETE("/sys/tables/info/:tableId", DeleteSysTables)
|
||||
apiv1.GET("/sys/tables/info/:tableId", GetSysTables)
|
||||
|
||||
apiv1.GET("/menuTreeselect", GetMenuTreeelect)
|
||||
apiv1.GET("/rolemenu", GetRoleMenu)
|
||||
apiv1.POST("/rolemenu", InsertRoleMenu)
|
||||
|
||||
Reference in new issue
Block a user