mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-21 10:13:01 +00:00
update 修改表名的硬编码问题
This commit is contained in:
+6
-6
@@ -26,7 +26,7 @@ func (SysConfig) TableName() string {
|
||||
// Config 创建
|
||||
func (e *SysConfig) Create() (SysConfig, error) {
|
||||
var doc SysConfig
|
||||
result := orm.Eloquent.Table("sys_config").Create(&e)
|
||||
result := orm.Eloquent.Table(e.TableName()).Create(&e)
|
||||
if result.Error != nil {
|
||||
err := result.Error
|
||||
return doc, err
|
||||
@@ -39,7 +39,7 @@ func (e *SysConfig) Create() (SysConfig, error) {
|
||||
func (e *SysConfig) Get() (SysConfig, error) {
|
||||
var doc SysConfig
|
||||
|
||||
table := orm.Eloquent.Table("sys_config")
|
||||
table := orm.Eloquent.Table(e.TableName())
|
||||
if e.ConfigId != 0 {
|
||||
table = table.Where("config_id = ?", e.ConfigId)
|
||||
}
|
||||
@@ -57,7 +57,7 @@ func (e *SysConfig) Get() (SysConfig, error) {
|
||||
func (e *SysConfig) GetPage(pageSize int, pageIndex int) ([]SysConfig, int, error) {
|
||||
var doc []SysConfig
|
||||
|
||||
table := orm.Eloquent.Select("*").Table("sys_config")
|
||||
table := orm.Eloquent.Select("*").Table(e.TableName())
|
||||
|
||||
if e.ConfigName != "" {
|
||||
table = table.Where("config_name = ?", e.ConfigName)
|
||||
@@ -84,20 +84,20 @@ func (e *SysConfig) GetPage(pageSize int, pageIndex int) ([]SysConfig, int, erro
|
||||
}
|
||||
|
||||
func (e *SysConfig) Update(id int) (update SysConfig, err error) {
|
||||
if err = orm.Eloquent.Table("sys_config").Where("config_id = ?", id).First(&update).Error; err != nil {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Where("config_id = ?", id).First(&update).Error; err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
//参数1:是要修改的数据
|
||||
//参数2:是修改的数据
|
||||
if err = orm.Eloquent.Table("sys_config").Model(&update).Updates(&e).Error; err != nil {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Model(&update).Updates(&e).Error; err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (e *SysConfig) Delete() (success bool, err error) {
|
||||
if err = orm.Eloquent.Table("sys_config").Where("config_id = ?", e.ConfigId).Delete(&SysConfig{}).Error; err != nil {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Where("config_id = ?", e.ConfigId).Delete(&SysConfig{}).Error; err != nil {
|
||||
success = false
|
||||
return
|
||||
}
|
||||
|
||||
+10
-10
@@ -35,7 +35,7 @@ type DeptLable struct {
|
||||
|
||||
func (e *Dept) Create() (Dept, error) {
|
||||
var doc Dept
|
||||
result := orm.Eloquent.Table("sys_dept").Create(&e)
|
||||
result := orm.Eloquent.Table(e.TableName()).Create(&e)
|
||||
if result.Error != nil {
|
||||
err := result.Error
|
||||
return doc, err
|
||||
@@ -43,14 +43,14 @@ func (e *Dept) Create() (Dept, error) {
|
||||
deptPath := "/" + utils.IntToString(e.DeptId)
|
||||
if int(e.ParentId) != 0 {
|
||||
var deptP Dept
|
||||
orm.Eloquent.Table("sys_dept").Where("dept_id = ?", e.ParentId).First(&deptP)
|
||||
orm.Eloquent.Table(e.TableName()).Where("dept_id = ?", e.ParentId).First(&deptP)
|
||||
deptPath = deptP.DeptPath + deptPath
|
||||
} else {
|
||||
deptPath = "/0" + deptPath
|
||||
}
|
||||
var mp = map[string]string{}
|
||||
mp["deptPath"] = deptPath
|
||||
if err := orm.Eloquent.Table("sys_dept").Where("dept_id = ?", e.DeptId).Update(mp).Error; err != nil {
|
||||
if err := orm.Eloquent.Table(e.TableName()).Where("dept_id = ?", e.DeptId).Update(mp).Error; err != nil {
|
||||
err := result.Error
|
||||
return doc, err
|
||||
}
|
||||
@@ -62,7 +62,7 @@ func (e *Dept) Create() (Dept, error) {
|
||||
func (e *Dept) Get() (Dept, error) {
|
||||
var doc Dept
|
||||
|
||||
table := orm.Eloquent.Table("sys_dept")
|
||||
table := orm.Eloquent.Table(e.TableName())
|
||||
if e.DeptId != 0 {
|
||||
table = table.Where("dept_id = ?", e.DeptId)
|
||||
}
|
||||
@@ -79,7 +79,7 @@ func (e *Dept) Get() (Dept, error) {
|
||||
func (e *Dept) GetList() ([]Dept, error) {
|
||||
var doc []Dept
|
||||
|
||||
table := orm.Eloquent.Table("sys_dept")
|
||||
table := orm.Eloquent.Table(e.TableName())
|
||||
if e.DeptId != 0 {
|
||||
table = table.Where("dept_id = ?", e.DeptId)
|
||||
}
|
||||
@@ -99,7 +99,7 @@ func (e *Dept) GetList() ([]Dept, error) {
|
||||
func (e *Dept) GetPage(bl bool) ([]Dept, error) {
|
||||
var doc []Dept
|
||||
|
||||
table := orm.Eloquent.Select("*").Table("sys_dept")
|
||||
table := orm.Eloquent.Select("*").Table(e.TableName())
|
||||
if e.DeptId != 0 {
|
||||
table = table.Where("dept_id = ?", e.DeptId)
|
||||
}
|
||||
@@ -169,14 +169,14 @@ func Digui(deptlist *[]Dept, menu Dept) Dept {
|
||||
}
|
||||
|
||||
func (e *Dept) Update(id int) (update Dept, err error) {
|
||||
if err = orm.Eloquent.Table("sys_dept").Where("dept_id = ?", id).First(&update).Error; err != nil {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Where("dept_id = ?", id).First(&update).Error; err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
deptPath := "/" + utils.IntToString(e.DeptId)
|
||||
if int(e.ParentId) != 0 {
|
||||
var deptP Dept
|
||||
orm.Eloquent.Table("sys_dept").Where("dept_id = ?", e.ParentId).First(&deptP)
|
||||
orm.Eloquent.Table(e.TableName()).Where("dept_id = ?", e.ParentId).First(&deptP)
|
||||
deptPath = deptP.DeptPath + deptPath
|
||||
} else {
|
||||
deptPath = "/0" + deptPath
|
||||
@@ -185,14 +185,14 @@ func (e *Dept) Update(id int) (update Dept, err error) {
|
||||
|
||||
//参数1:是要修改的数据
|
||||
//参数2:是修改的数据
|
||||
if err = orm.Eloquent.Table("sys_dept").Model(&update).Updates(&e).Error; err != nil {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Model(&update).Updates(&e).Error; err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (e *Dept) Delete(id int) (success bool, err error) {
|
||||
if err = orm.Eloquent.Table("sys_dept").Where("dept_id = ?", e.DeptId).Delete(&Dept{}).Error; err != nil {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Where("dept_id = ?", e.DeptId).Delete(&Dept{}).Error; err != nil {
|
||||
success = false
|
||||
return
|
||||
}
|
||||
|
||||
+7
-7
@@ -30,7 +30,7 @@ func (DictData) TableName() string {
|
||||
|
||||
func (e *DictData) Create() (DictData, error) {
|
||||
var doc DictData
|
||||
result := orm.Eloquent.Table("sys_dict_data").Create(&e)
|
||||
result := orm.Eloquent.Table(e.TableName()).Create(&e)
|
||||
if result.Error != nil {
|
||||
err := result.Error
|
||||
return doc, err
|
||||
@@ -42,7 +42,7 @@ func (e *DictData) Create() (DictData, error) {
|
||||
func (e *DictData) GetByCode() (DictData, error) {
|
||||
var doc DictData
|
||||
|
||||
table := orm.Eloquent.Table("sys_dict_data")
|
||||
table := orm.Eloquent.Table(e.TableName())
|
||||
if e.DictCode != 0 {
|
||||
table = table.Where("dict_code = ?", e.DictCode)
|
||||
}
|
||||
@@ -62,7 +62,7 @@ func (e *DictData) GetByCode() (DictData, error) {
|
||||
func (e *DictData) Get() ([]DictData, error) {
|
||||
var doc []DictData
|
||||
|
||||
table := orm.Eloquent.Table("sys_dict_data")
|
||||
table := orm.Eloquent.Table(e.TableName())
|
||||
if e.DictCode != 0 {
|
||||
table = table.Where("dict_code = ?", e.DictCode)
|
||||
}
|
||||
@@ -82,7 +82,7 @@ func (e *DictData) Get() ([]DictData, error) {
|
||||
func (e *DictData) GetPage(pageSize int, pageIndex int) ([]DictData, int, error) {
|
||||
var doc []DictData
|
||||
|
||||
table := orm.Eloquent.Select("*").Table("sys_dict_data")
|
||||
table := orm.Eloquent.Select("*").Table(e.TableName())
|
||||
if e.DictCode != 0 {
|
||||
table = table.Where("dict_code = ?", e.DictCode)
|
||||
}
|
||||
@@ -111,20 +111,20 @@ func (e *DictData) GetPage(pageSize int, pageIndex int) ([]DictData, int, error)
|
||||
}
|
||||
|
||||
func (e *DictData) Update(id int) (update DictData, err error) {
|
||||
if err = orm.Eloquent.Table("sys_dict_data").Where("dict_code = ?", id).First(&update).Error; err != nil {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Where("dict_code = ?", id).First(&update).Error; err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
//参数1:是要修改的数据
|
||||
//参数2:是修改的数据
|
||||
if err = orm.Eloquent.Table("sys_dict_data").Model(&update).Updates(&e).Error; err != nil {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Model(&update).Updates(&e).Error; err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (e *DictData) Delete(id int) (success bool, err error) {
|
||||
if err = orm.Eloquent.Table("sys_dict_data").Where("dict_code = ?", id).Delete(&DictData{}).Error; err != nil {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Where("dict_code = ?", id).Delete(&DictData{}).Error; err != nil {
|
||||
success = false
|
||||
return
|
||||
}
|
||||
|
||||
+7
-7
@@ -24,7 +24,7 @@ func (DictType) TableName() string {
|
||||
|
||||
func (e *DictType) Create() (DictType, error) {
|
||||
var doc DictType
|
||||
result := orm.Eloquent.Table("sys_dict_type").Create(&e)
|
||||
result := orm.Eloquent.Table(e.TableName()).Create(&e)
|
||||
if result.Error != nil {
|
||||
err := result.Error
|
||||
return doc, err
|
||||
@@ -36,7 +36,7 @@ func (e *DictType) Create() (DictType, error) {
|
||||
func (e *DictType) Get() (DictType, error) {
|
||||
var doc DictType
|
||||
|
||||
table := orm.Eloquent.Table("sys_dict_type")
|
||||
table := orm.Eloquent.Table(e.TableName())
|
||||
if e.DictId != 0 {
|
||||
table = table.Where("dict_id = ?", e.DictId)
|
||||
}
|
||||
@@ -56,7 +56,7 @@ func (e *DictType) Get() (DictType, error) {
|
||||
func (e *DictType) GetList() ([]DictType, error) {
|
||||
var doc []DictType
|
||||
|
||||
table := orm.Eloquent.Table("sys_dict_type")
|
||||
table := orm.Eloquent.Table(e.TableName())
|
||||
if e.DictId != 0 {
|
||||
table = table.Where("dict_id = ?", e.DictId)
|
||||
}
|
||||
@@ -76,7 +76,7 @@ func (e *DictType) GetList() ([]DictType, error) {
|
||||
func (e *DictType) GetPage(pageSize int, pageIndex int) ([]DictType, int, error) {
|
||||
var doc []DictType
|
||||
|
||||
table := orm.Eloquent.Select("*").Table("sys_dict_type")
|
||||
table := orm.Eloquent.Select("*").Table(e.TableName())
|
||||
if e.DictId != 0 {
|
||||
table = table.Where("dict_id = ?", e.DictId)
|
||||
}
|
||||
@@ -99,20 +99,20 @@ func (e *DictType) GetPage(pageSize int, pageIndex int) ([]DictType, int, error)
|
||||
}
|
||||
|
||||
func (e *DictType) Update(id int) (update DictType, err error) {
|
||||
if err = orm.Eloquent.Table("sys_dict_type").First(&update, id).Error; err != nil {
|
||||
if err = orm.Eloquent.Table(e.TableName()).First(&update, id).Error; err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
//参数1:是要修改的数据
|
||||
//参数2:是修改的数据
|
||||
if err = orm.Eloquent.Table("sys_dict_type").Model(&update).Updates(&e).Error; err != nil {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Model(&update).Updates(&e).Error; err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (e *DictType) Delete(id int) (success bool, err error) {
|
||||
if err = orm.Eloquent.Table("sys_dict_type").Where("dict_id = ?", id).Delete(&DictData{}).Error; err != nil {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Where("dict_id = ?", id).Delete(&DictData{}).Error; err != nil {
|
||||
success = false
|
||||
return
|
||||
}
|
||||
|
||||
+6
-6
@@ -31,7 +31,7 @@ func (LoginLog) TableName() string {
|
||||
func (e *LoginLog) Get() (LoginLog, error) {
|
||||
var doc LoginLog
|
||||
|
||||
table := orm.Eloquent.Table("sys_loginlog")
|
||||
table := orm.Eloquent.Table(e.TableName())
|
||||
if e.Ipaddr != "" {
|
||||
table = table.Where("ipaddr = ?", e.Ipaddr)
|
||||
}
|
||||
@@ -48,7 +48,7 @@ func (e *LoginLog) Get() (LoginLog, error) {
|
||||
func (e *LoginLog) GetPage(pageSize int, pageIndex int) ([]LoginLog, int, error) {
|
||||
var doc []LoginLog
|
||||
|
||||
table := orm.Eloquent.Select("*").Table("sys_loginlog")
|
||||
table := orm.Eloquent.Select("*").Table(e.TableName())
|
||||
if e.Ipaddr != "" {
|
||||
table = table.Where("ipaddr = ?", e.Ipaddr)
|
||||
}
|
||||
@@ -72,7 +72,7 @@ func (e *LoginLog) Create() (LoginLog, error) {
|
||||
var doc LoginLog
|
||||
e.CreateBy = "0"
|
||||
e.UpdateBy = "0"
|
||||
result := orm.Eloquent.Table("sys_loginlog").Create(&e)
|
||||
result := orm.Eloquent.Table(e.TableName()).Create(&e)
|
||||
if result.Error != nil {
|
||||
err := result.Error
|
||||
return doc, err
|
||||
@@ -83,20 +83,20 @@ func (e *LoginLog) Create() (LoginLog, error) {
|
||||
|
||||
func (e *LoginLog) Update(id int) (update LoginLog, err error) {
|
||||
|
||||
if err = orm.Eloquent.Table("sys_loginlog").First(&update, id).Error; err != nil {
|
||||
if err = orm.Eloquent.Table(e.TableName()).First(&update, id).Error; err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
//参数1:是要修改的数据
|
||||
//参数2:是修改的数据
|
||||
if err = orm.Eloquent.Table("sys_loginlog").Model(&update).Updates(&e).Error; err != nil {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Model(&update).Updates(&e).Error; err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (e *LoginLog) BatchDelete(id []int) (Result bool, err error) {
|
||||
if err = orm.Eloquent.Table("sys_loginlog").Where("info_id in (?)", id).Delete(&LoginLog{}).Error; err != nil {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Where("info_id in (?)", id).Delete(&LoginLog{}).Error; err != nil {
|
||||
return
|
||||
}
|
||||
Result = true
|
||||
|
||||
+16
-12
@@ -68,6 +68,10 @@ type Menus struct {
|
||||
BaseModel
|
||||
}
|
||||
|
||||
func (Menus) TableName() string {
|
||||
return "sys_menu"
|
||||
}
|
||||
|
||||
type MenuRole struct {
|
||||
Menus
|
||||
IsSelect bool `json:"is_select" gorm:"-"`
|
||||
@@ -77,7 +81,7 @@ type MS []Menu
|
||||
|
||||
func (e *Menu) GetByMenuId() (Menu Menu, err error) {
|
||||
|
||||
table := orm.Eloquent.Table("sys_menu")
|
||||
table := orm.Eloquent.Table(e.TableName())
|
||||
table = table.Where("menu_id = ?", e.MenuId)
|
||||
if err = table.Find(&Menu).Error; err != nil {
|
||||
return
|
||||
@@ -198,10 +202,10 @@ func (e *Menu) SetMenuRole(rolename string) (m []Menu, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (menu *MenuRole) Get() (Menus []MenuRole, err error) {
|
||||
table := orm.Eloquent.Table("sys_menu")
|
||||
if menu.MenuName != "" {
|
||||
table = table.Where("menu_name = ?", menu.MenuName)
|
||||
func (e *MenuRole) Get() (Menus []MenuRole, err error) {
|
||||
table := orm.Eloquent.Table(e.TableName())
|
||||
if e.MenuName != "" {
|
||||
table = table.Where("menu_name = ?", e.MenuName)
|
||||
}
|
||||
if err = table.Order("sort").Find(&Menus).Error; err != nil {
|
||||
return
|
||||
@@ -210,7 +214,7 @@ func (menu *MenuRole) Get() (Menus []MenuRole, err error) {
|
||||
}
|
||||
|
||||
func (e *Menu) GetByRoleName(rolename string) (Menus []Menu, err error) {
|
||||
table := orm.Eloquent.Table("sys_menu").Select("sys_menu.*").Joins("left join sys_role_menu on sys_role_menu.menu_id=sys_menu.menu_id")
|
||||
table := orm.Eloquent.Table(e.TableName()).Select("sys_menu.*").Joins("left join sys_role_menu on sys_role_menu.menu_id=sys_menu.menu_id")
|
||||
table = table.Where("sys_role_menu.role_name=? and menu_type in ('M','C')", rolename)
|
||||
if err = table.Order("sort").Find(&Menus).Error; err != nil {
|
||||
return
|
||||
@@ -219,7 +223,7 @@ func (e *Menu) GetByRoleName(rolename string) (Menus []Menu, err error) {
|
||||
}
|
||||
|
||||
func (e *Menu) Get() (Menus []Menu, err error) {
|
||||
table := orm.Eloquent.Table("sys_menu")
|
||||
table := orm.Eloquent.Table(e.TableName())
|
||||
if e.MenuName != "" {
|
||||
table = table.Where("menu_name = ?", e.MenuName)
|
||||
}
|
||||
@@ -240,7 +244,7 @@ func (e *Menu) Get() (Menus []Menu, err error) {
|
||||
}
|
||||
|
||||
func (e *Menu) GetPage() (Menus []Menu, err error) {
|
||||
table := orm.Eloquent.Table("sys_menu")
|
||||
table := orm.Eloquent.Table(e.TableName())
|
||||
if e.MenuName != "" {
|
||||
table = table.Where("menu_name = ?", e.MenuName)
|
||||
}
|
||||
@@ -260,7 +264,7 @@ func (e *Menu) GetPage() (Menus []Menu, err error) {
|
||||
}
|
||||
|
||||
func (e *Menu) Create() (id int, err error) {
|
||||
result := orm.Eloquent.Table("sys_menu").Create(&e)
|
||||
result := orm.Eloquent.Table(e.TableName()).Create(&e)
|
||||
if result.Error != nil {
|
||||
err = result.Error
|
||||
return
|
||||
@@ -290,13 +294,13 @@ func InitPaths(menu *Menu) (err error) {
|
||||
}
|
||||
|
||||
func (e *Menu) Update(id int) (update Menu, err error) {
|
||||
if err = orm.Eloquent.Table("sys_menu").First(&update, id).Error; err != nil {
|
||||
if err = orm.Eloquent.Table(e.TableName()).First(&update, id).Error; err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
//参数1:是要修改的数据
|
||||
//参数2:是修改的数据
|
||||
if err = orm.Eloquent.Table("sys_menu").Model(&update).Updates(&e).Error; err != nil {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Model(&update).Updates(&e).Error; err != nil {
|
||||
return
|
||||
}
|
||||
err = InitPaths(e)
|
||||
@@ -307,7 +311,7 @@ func (e *Menu) Update(id int) (update Menu, err error) {
|
||||
}
|
||||
|
||||
func (e *Menu) Delete(id int) (success bool, err error) {
|
||||
if err = orm.Eloquent.Table("sys_menu").Where("menu_id = ?", id).Delete(&Menu{}).Error; err != nil {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Where("menu_id = ?", id).Delete(&Menu{}).Error; err != nil {
|
||||
success = false
|
||||
return
|
||||
}
|
||||
|
||||
+6
-6
@@ -40,7 +40,7 @@ func (SysOperLog) TableName() string {
|
||||
func (e *SysOperLog) Get() (SysOperLog, error) {
|
||||
var doc SysOperLog
|
||||
|
||||
table := orm.Eloquent.Table("sys_operlog")
|
||||
table := orm.Eloquent.Table(e.TableName())
|
||||
if e.OperIp != "" {
|
||||
table = table.Where("oper_ip = ?", e.OperIp)
|
||||
}
|
||||
@@ -57,7 +57,7 @@ func (e *SysOperLog) Get() (SysOperLog, error) {
|
||||
func (e *SysOperLog) GetPage(pageSize int, pageIndex int) ([]SysOperLog, int, error) {
|
||||
var doc []SysOperLog
|
||||
|
||||
table := orm.Eloquent.Select("*").Table("sys_operlog")
|
||||
table := orm.Eloquent.Select("*").Table(e.TableName())
|
||||
if e.OperIp != "" {
|
||||
table = table.Where("oper_ip = ?", e.OperIp)
|
||||
}
|
||||
@@ -84,7 +84,7 @@ func (e *SysOperLog) Create() (SysOperLog, error) {
|
||||
var doc SysOperLog
|
||||
e.CreateBy = "0"
|
||||
e.UpdateBy = "0"
|
||||
result := orm.Eloquent.Table("sys_operlog").Create(&e)
|
||||
result := orm.Eloquent.Table(e.TableName()).Create(&e)
|
||||
if result.Error != nil {
|
||||
err := result.Error
|
||||
return doc, err
|
||||
@@ -94,20 +94,20 @@ func (e *SysOperLog) Create() (SysOperLog, error) {
|
||||
}
|
||||
|
||||
func (e *SysOperLog) Update(id int) (update SysOperLog, err error) {
|
||||
if err = orm.Eloquent.Table("sys_operlog").First(&update, id).Error; err != nil {
|
||||
if err = orm.Eloquent.Table(e.TableName()).First(&update, id).Error; err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
//参数1:是要修改的数据
|
||||
//参数2:是修改的数据
|
||||
if err = orm.Eloquent.Table("sys_operlog").Model(&update).Updates(&e).Error; err != nil {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Model(&update).Updates(&e).Error; err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (e *SysOperLog) BatchDelete(id []int) (Result bool, err error) {
|
||||
if err = orm.Eloquent.Table("sys_operlog").Where(" oper_id in (?)", id).Delete(&SysOperLog{}).Error; err != nil {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Where(" oper_id in (?)", id).Delete(&SysOperLog{}).Error; err != nil {
|
||||
return
|
||||
}
|
||||
Result = true
|
||||
|
||||
+7
-7
@@ -25,7 +25,7 @@ func (Post) TableName() string {
|
||||
|
||||
func (e *Post) Create() (Post, error) {
|
||||
var doc Post
|
||||
result := orm.Eloquent.Table("sys_post").Create(&e)
|
||||
result := orm.Eloquent.Table(e.TableName()).Create(&e)
|
||||
if result.Error != nil {
|
||||
err := result.Error
|
||||
return doc, err
|
||||
@@ -37,7 +37,7 @@ func (e *Post) Create() (Post, error) {
|
||||
func (e *Post) Get() (Post, error) {
|
||||
var doc Post
|
||||
|
||||
table := orm.Eloquent.Table("sys_post")
|
||||
table := orm.Eloquent.Table(e.TableName())
|
||||
if e.PostId != 0 {
|
||||
table = table.Where("post_id = ?", e.PostId)
|
||||
}
|
||||
@@ -60,7 +60,7 @@ func (e *Post) Get() (Post, error) {
|
||||
func (e *Post) GetList() ([]Post, error) {
|
||||
var doc []Post
|
||||
|
||||
table := orm.Eloquent.Table("sys_post")
|
||||
table := orm.Eloquent.Table(e.TableName())
|
||||
if e.PostId != 0 {
|
||||
table = table.Where("post_id = ?", e.PostId)
|
||||
}
|
||||
@@ -83,7 +83,7 @@ func (e *Post) GetList() ([]Post, error) {
|
||||
func (e *Post) GetPage(pageSize int, pageIndex int) ([]Post, int, error) {
|
||||
var doc []Post
|
||||
|
||||
table := orm.Eloquent.Select("*").Table("sys_post")
|
||||
table := orm.Eloquent.Select("*").Table(e.TableName())
|
||||
if e.PostId != 0 {
|
||||
table = table.Where("post_id = ?", e.PostId)
|
||||
}
|
||||
@@ -109,20 +109,20 @@ func (e *Post) GetPage(pageSize int, pageIndex int) ([]Post, int, error) {
|
||||
}
|
||||
|
||||
func (e *Post) Update(id int) (update Post, err error) {
|
||||
if err = orm.Eloquent.Table("sys_post").First(&update, id).Error; err != nil {
|
||||
if err = orm.Eloquent.Table(e.TableName()).First(&update, id).Error; err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
//参数1:是要修改的数据
|
||||
//参数2:是修改的数据
|
||||
if err = orm.Eloquent.Table("sys_post").Model(&update).Updates(&e).Error; err != nil {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Model(&update).Updates(&e).Error; err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (e *Post) Delete(id int) (success bool, err error) {
|
||||
if err = orm.Eloquent.Table("sys_post").Where("post_id = ?", id).Delete(&Post{}).Error; err != nil {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Where("post_id = ?", id).Delete(&Post{}).Error; err != nil {
|
||||
success = false
|
||||
return
|
||||
}
|
||||
|
||||
+9
-8
@@ -5,9 +5,10 @@ import (
|
||||
orm "go-admin/database"
|
||||
"go-admin/pkg"
|
||||
"go-admin/pkg/utils"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
// User
|
||||
@@ -92,7 +93,7 @@ type SysUserView struct {
|
||||
// 获取用户数据
|
||||
func (e *SysUser) Get() (SysUserView SysUserView, err error) {
|
||||
|
||||
table := orm.Eloquent.Table("sys_user").Select([]string{"sys_user.*", "sys_role.role_name"})
|
||||
table := orm.Eloquent.Table(e.TableName()).Select([]string{"sys_user.*", "sys_role.role_name"})
|
||||
table = table.Joins("left join sys_role on sys_user.role_id=sys_role.role_id")
|
||||
if e.UserId != 0 {
|
||||
table = table.Where("user_id = ?", e.UserId)
|
||||
@@ -127,7 +128,7 @@ func (e *SysUser) Get() (SysUserView SysUserView, err error) {
|
||||
func (e *SysUser) GetPage(pageSize int, pageIndex int) ([]SysUserPage, int, error) {
|
||||
var doc []SysUserPage
|
||||
|
||||
table := orm.Eloquent.Select("sys_user.*,sys_dept.dept_name").Table("sys_user")
|
||||
table := orm.Eloquent.Select("sys_user.*,sys_dept.dept_name").Table(e.TableName())
|
||||
table = table.Joins("left join sys_dept on sys_dept.dept_id = sys_user.dept_id")
|
||||
|
||||
if e.Username != "" {
|
||||
@@ -175,14 +176,14 @@ func (e SysUser) Insert() (id int, err error) {
|
||||
|
||||
// check 用户名
|
||||
var count int
|
||||
orm.Eloquent.Table("sys_user").Where("username = ?", e.Username).Count(&count)
|
||||
orm.Eloquent.Table(e.TableName()).Where("username = ?", e.Username).Count(&count)
|
||||
if count > 0 {
|
||||
err = errors.New("账户已存在!")
|
||||
return
|
||||
}
|
||||
|
||||
//添加数据
|
||||
if err = orm.Eloquent.Table("sys_user").Create(&e).Error; err != nil {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Create(&e).Error; err != nil {
|
||||
return
|
||||
}
|
||||
id = e.UserId
|
||||
@@ -195,7 +196,7 @@ func (e *SysUser) Update(id int) (update SysUser, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
if err = orm.Eloquent.Table("sys_user").First(&update, id).Error; err != nil {
|
||||
if err = orm.Eloquent.Table(e.TableName()).First(&update, id).Error; err != nil {
|
||||
return
|
||||
}
|
||||
if e.RoleId == 0 {
|
||||
@@ -204,14 +205,14 @@ func (e *SysUser) Update(id int) (update SysUser, err error) {
|
||||
|
||||
//参数1:是要修改的数据
|
||||
//参数2:是修改的数据
|
||||
if err = orm.Eloquent.Table("sys_user").Model(&update).Updates(&e).Error; err != nil {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Model(&update).Updates(&e).Error; err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (e *SysUser) BatchDelete(id []int) (Result bool, err error) {
|
||||
if err = orm.Eloquent.Table("sys_user").Where("user_id in (?)", id).Delete(&SysUser{}).Error; err != nil {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Where("user_id in (?)", id).Delete(&SysUser{}).Error; err != nil {
|
||||
return
|
||||
}
|
||||
Result = true
|
||||
|
||||
Reference in New Issue
Block a user