修改生成数据库模型,添加批量删除
This commit is contained in:
1 parent
02255240fe
commit
0cec342fac
2 files changed
+28
-17
No files matched your search
@@ -31,7 +31,7 @@ func GetSysTableList(c *gin.Context) {
|
|||||||
pageIndex = tools2.StrToInt(err, index)
|
pageIndex = tools2.StrToInt(err, index)
|
||||||
}
|
}
|
||||||
|
|
||||||
data.TableName = c.Request.FormValue("tableName")
|
data.TBName = c.Request.FormValue("tableName")
|
||||||
result, count, err := data.GetPage(pageSize, pageIndex)
|
result, count, err := data.GetPage(pageSize, pageIndex)
|
||||||
tools2.HasError(err, "", -1)
|
tools2.HasError(err, "", -1)
|
||||||
|
|
||||||
@@ -83,13 +83,13 @@ func InsertSysTable(c *gin.Context) {
|
|||||||
var data tools.SysTables
|
var data tools.SysTables
|
||||||
var dbTable tools.DBTables
|
var dbTable tools.DBTables
|
||||||
var dbColumn tools.DBColumns
|
var dbColumn tools.DBColumns
|
||||||
data.TableName = c.Request.FormValue("tables")
|
data.TBName = c.Request.FormValue("tables")
|
||||||
data.CreateBy = tools2.GetUserIdStr(c)
|
data.CreateBy = tools2.GetUserIdStr(c)
|
||||||
|
|
||||||
dbTable.TableName = data.TableName
|
dbTable.TableName = data.TBName
|
||||||
dbtable, err := dbTable.Get()
|
dbtable, err := dbTable.Get()
|
||||||
|
|
||||||
dbColumn.TableName = data.TableName
|
dbColumn.TableName = data.TBName
|
||||||
tablenamelist := strings.Split(dbColumn.TableName, "_")
|
tablenamelist := strings.Split(dbColumn.TableName, "_")
|
||||||
for i := 0; i < len(tablenamelist); i++ {
|
for i := 0; i < len(tablenamelist); i++ {
|
||||||
strStart := string([]byte(tablenamelist[i])[:1])
|
strStart := string([]byte(tablenamelist[i])[:1])
|
||||||
@@ -204,9 +204,8 @@ func UpdateSysTable(c *gin.Context) {
|
|||||||
// @Router /api/v1/sys/tables/info/{tableId} [delete]
|
// @Router /api/v1/sys/tables/info/{tableId} [delete]
|
||||||
func DeleteSysTables(c *gin.Context) {
|
func DeleteSysTables(c *gin.Context) {
|
||||||
var data tools.SysTables
|
var data tools.SysTables
|
||||||
id, err := tools2.StringToInt(c.Param("tableId"))
|
IDS := tools2.IdsStrToIdsIntGroup("tableId", c)
|
||||||
data.TableId = id
|
_, err := data.BatchDelete(IDS)
|
||||||
_, err = data.Delete()
|
|
||||||
tools2.HasError(err, "删除失败", 500)
|
tools2.HasError(err, "删除失败", 500)
|
||||||
var res app.Response
|
var res app.Response
|
||||||
res.Msg = "删除成功"
|
res.Msg = "删除成功"
|
||||||
|
|||||||
+22
-10
@@ -6,15 +6,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type SysTables struct {
|
type SysTables struct {
|
||||||
TableId int `gorm:"primary_key;auto_increment" json:"tableId"` //表编码
|
TableId int `gorm:"primary_key;auto_increment" json:"tableId"` //表编码
|
||||||
TableName string `gorm:"type:varchar(255);" json:"tableName"` //表名称
|
TBName string `gorm:"column:table_name;type:varchar(255);" json:"tableName"` //表名称
|
||||||
TableComment string `gorm:"type:varchar(255);" json:"tableComment"` //表备注
|
TableComment string `gorm:"type:varchar(255);" json:"tableComment"` //表备注
|
||||||
ClassName string `gorm:"type:varchar(255);" json:"className"` //类名
|
ClassName string `gorm:"type:varchar(255);" json:"className"` //类名
|
||||||
TplCategory string `gorm:"type:varchar(255);" json:"tplCategory"`
|
TplCategory string `gorm:"type:varchar(255);" json:"tplCategory"`
|
||||||
PackageName string `gorm:"type:varchar(255);" json:"packageName"` //包名
|
PackageName string `gorm:"type:varchar(255);" json:"packageName"` //包名
|
||||||
ModuleName string `gorm:"type:varchar(255);" json:"moduleName"` //模块名
|
ModuleName string `gorm:"type:varchar(255);" json:"moduleName"` //模块名
|
||||||
BusinessName string `gorm:"type:varchar(255);" json:"businessName"`
|
BusinessName string `gorm:"type:varchar(255);" json:"businessName"`
|
||||||
FunctionName string `gorm:"type:varchar(255);" json:"functionName"` //功能名称
|
FunctionName string `gorm:"type:varchar(255);" json:"functionName"` //功能名称
|
||||||
FunctionAuthor string `gorm:"type:varchar(255);" json:"functionAuthor"` //功能作者
|
FunctionAuthor string `gorm:"type:varchar(255);" json:"functionAuthor"` //功能作者
|
||||||
PkColumn string `gorm:"type:varchar(255);" json:"pkColumn"`
|
PkColumn string `gorm:"type:varchar(255);" json:"pkColumn"`
|
||||||
PkGoField string `gorm:"type:varchar(255);" json:"pkGoField"`
|
PkGoField string `gorm:"type:varchar(255);" json:"pkGoField"`
|
||||||
@@ -38,6 +38,10 @@ type SysTables struct {
|
|||||||
models.BaseModel
|
models.BaseModel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (SysTables) TableName() string {
|
||||||
|
return "sys_tables"
|
||||||
|
}
|
||||||
|
|
||||||
type Params struct {
|
type Params struct {
|
||||||
TreeCode string `gorm:"-" json:"treeCode"`
|
TreeCode string `gorm:"-" json:"treeCode"`
|
||||||
TreeParentCode string `gorm:"-" json:"treeParentCode"`
|
TreeParentCode string `gorm:"-" json:"treeParentCode"`
|
||||||
@@ -49,8 +53,8 @@ func (e *SysTables) GetPage(pageSize int, pageIndex int) ([]SysTables, int, erro
|
|||||||
|
|
||||||
table := orm.Eloquent.Select("*").Table("sys_tables")
|
table := orm.Eloquent.Select("*").Table("sys_tables")
|
||||||
|
|
||||||
if e.TableName != "" {
|
if e.TBName != "" {
|
||||||
table = table.Where("table_name = ?", e.TableName)
|
table = table.Where("table_name = ?", e.TBName)
|
||||||
}
|
}
|
||||||
if e.TableComment != "" {
|
if e.TableComment != "" {
|
||||||
table = table.Where("table_comment = ?", e.TableComment)
|
table = table.Where("table_comment = ?", e.TableComment)
|
||||||
@@ -70,8 +74,8 @@ func (e *SysTables) Get() (SysTables, error) {
|
|||||||
var err error
|
var err error
|
||||||
table := orm.Eloquent.Select("*").Table("sys_tables")
|
table := orm.Eloquent.Select("*").Table("sys_tables")
|
||||||
|
|
||||||
if e.TableName != "" {
|
if e.TBName != "" {
|
||||||
table = table.Where("table_name = ?", e.TableName)
|
table = table.Where("table_name = ?", e.TBName)
|
||||||
}
|
}
|
||||||
if e.TableId != 0 {
|
if e.TableId != 0 {
|
||||||
table = table.Where("table_id = ?", e.TableId)
|
table = table.Where("table_id = ?", e.TableId)
|
||||||
@@ -138,3 +142,11 @@ func (e *SysTables) Delete() (success bool, err error) {
|
|||||||
success = true
|
success = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *SysTables) BatchDelete(id []int) (Result bool, err error) {
|
||||||
|
if err = orm.Eloquent.Table(e.TableName()).Where(" table_id in (?)", id).Delete(&SysColumns{}).Error; err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
Result = true
|
||||||
|
return
|
||||||
|
}
|
||||||
Reference in new issue
Block a user