update 修改表名的硬编码问题

This commit is contained in:
kikiyou
2020-04-14 18:16:54 +08:00
parent f091f8c24d
commit 7ee48cf4a9
9 changed files with 144 additions and 139 deletions
+12 -12
View File
@@ -6,12 +6,12 @@ import (
)
type SysConfig struct {
ConfigId int `json:"configId" gorm:"primary_key;auto_increment;"` //编码
ConfigName string `json:"configName" gorm:"type:varchar(128);"` //参数名称
ConfigKey string `json:"configKey" gorm:"type:varchar(128);"` //参数键名
ConfigValue string `json:"configValue" gorm:"type:varchar(255);"` //参数键值
ConfigType string `json:"configType" gorm:"type:varchar(64);"` //是否系统内置
Remark string `json:"remark" gorm:"type:varchar(128);"` //备注
ConfigId int `json:"configId" gorm:"primary_key;auto_increment;"` //编码
ConfigName string `json:"configName" gorm:"type:varchar(128);"` //参数名称
ConfigKey string `json:"configKey" gorm:"type:varchar(128);"` //参数键名
ConfigValue string `json:"configValue" gorm:"type:varchar(255);"` //参数键值
ConfigType string `json:"configType" gorm:"type:varchar(64);"` //是否系统内置
Remark string `json:"remark" gorm:"type:varchar(128);"` //备注
CreateBy string `json:"createBy" gorm:"type:varchar(128);"`
UpdateBy string `json:"updateBy" gorm:"type:varchar(128);"`
DataScope string `json:"dataScope" gorm:"-"`
@@ -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
}
+20 -20
View File
@@ -6,15 +6,15 @@ import (
)
type Dept struct {
DeptId int `json:"deptId" gorm:"primary_key;AUTO_INCREMENT"` //部门编码
ParentId int `json:"parentId" gorm:"type:int(11);"` //上级部门
DeptPath string `json:"deptPath" gorm:"type:varchar(255);"` //
DeptName string `json:"deptName" gorm:"type:varchar(128);"` //部门名称
Sort int `json:"sort" gorm:"type:int(4);"` //排序
Leader string `json:"leader" gorm:"type:varchar(128);"` //负责人
Phone string `json:"phone" gorm:"type:varchar(11);"` //手机
Email string `json:"email" gorm:"type:varchar(64);"` //邮箱
Status string `json:"status" gorm:"type:int(1);"` //状态
DeptId int `json:"deptId" gorm:"primary_key;AUTO_INCREMENT"` //部门编码
ParentId int `json:"parentId" gorm:"type:int(11);"` //上级部门
DeptPath string `json:"deptPath" gorm:"type:varchar(255);"` //
DeptName string `json:"deptName" gorm:"type:varchar(128);"` //部门名称
Sort int `json:"sort" gorm:"type:int(4);"` //排序
Leader string `json:"leader" gorm:"type:varchar(128);"` //负责人
Phone string `json:"phone" gorm:"type:varchar(11);"` //手机
Email string `json:"email" gorm:"type:varchar(64);"` //邮箱
Status string `json:"status" gorm:"type:int(1);"` //状态
CreateBy string `json:"createBy" gorm:"type:varchar(64);"`
UpdateBy string `json:"updateBy" gorm:"type:varchar(64);"`
DataScope string `json:"dataScope" gorm:"-"`
@@ -28,14 +28,14 @@ func (Dept) TableName() string {
}
type DeptLable struct {
Id int `gorm:"-" json:"id"`
Id int `gorm:"-" json:"id"`
Label string `gorm:"-" json:"label"`
Children []DeptLable `gorm:"-" json:"children"`
}
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
}
+20 -20
View File
@@ -6,19 +6,19 @@ import (
)
type DictData struct {
DictCode int `gorm:"primary_key;AUTO_INCREMENT" json:"dictCode" example:"1"` //字典编码
DictSort int `gorm:"type:int(4);" json:"dictSort"` //显示顺序
DictLabel string `gorm:"type:varchar(128);" json:"dictLabel"` //数据标签
DictValue string `gorm:"type:varchar(255);" json:"dictValue"` //数据键值
DictType string `gorm:"type:varchar(64);" json:"dictType"` //字典类型
CssClass string `gorm:"type:varchar(128);" json:"cssClass"` //
ListClass string `gorm:"type:varchar(128);" json:"listClass"` //
IsDefault string `gorm:"type:varchar(8);" json:"isDefault"` //
Status string `gorm:"type:int(1);" json:"status"` //状态
Default string `gorm:"type:varchar(8);" json:"default"` //
CreateBy string `gorm:"type:varchar(64);" json:"createBy"` //
UpdateBy string `gorm:"type:varchar(64);" json:"updateBy"` //
Remark string `gorm:"type:varchar(255);" json:"remark"` //备注
DictCode int `gorm:"primary_key;AUTO_INCREMENT" json:"dictCode" example:"1"` //字典编码
DictSort int `gorm:"type:int(4);" json:"dictSort"` //显示顺序
DictLabel string `gorm:"type:varchar(128);" json:"dictLabel"` //数据标签
DictValue string `gorm:"type:varchar(255);" json:"dictValue"` //数据键值
DictType string `gorm:"type:varchar(64);" json:"dictType"` //字典类型
CssClass string `gorm:"type:varchar(128);" json:"cssClass"` //
ListClass string `gorm:"type:varchar(128);" json:"listClass"` //
IsDefault string `gorm:"type:varchar(8);" json:"isDefault"` //
Status string `gorm:"type:int(1);" json:"status"` //状态
Default string `gorm:"type:varchar(8);" json:"default"` //
CreateBy string `gorm:"type:varchar(64);" json:"createBy"` //
UpdateBy string `gorm:"type:varchar(64);" json:"updateBy"` //
Remark string `gorm:"type:varchar(255);" json:"remark"` //备注
Params string `gorm:"-" json:"params"`
DataScope string `gorm:"-" json:"dataScope"`
BaseModel
@@ -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
}
+14 -14
View File
@@ -6,15 +6,15 @@ import (
)
type DictType struct {
DictId int `gorm:"primary_key;AUTO_INCREMENT" json:"dictId"`
DictId int `gorm:"primary_key;AUTO_INCREMENT" json:"dictId"`
DictName string `gorm:"type:varchar(128);" json:"dictName"` //字典名称
DictType string `gorm:"type:varchar(128);" json:"dictType"` //字典类型
Status string `gorm:"type:int(1);" json:"status"` //状态
DataScope string `gorm:"-" json:"dataScope"` //
Params string `gorm:"-" json:"params"` //
CreateBy string `gorm:"type:varchar(11);" json:"createBy"` //创建者
UpdateBy string `gorm:"type:varchar(11);" json:"updateBy"` //更新者
Remark string `gorm:"type:varchar(255);" json:"remark"` //备注
Status string `gorm:"type:int(1);" json:"status"` //状态
DataScope string `gorm:"-" json:"dataScope"` //
Params string `gorm:"-" json:"params"` //
CreateBy string `gorm:"type:varchar(11);" json:"createBy"` //创建者
UpdateBy string `gorm:"type:varchar(11);" json:"updateBy"` //更新者
Remark string `gorm:"type:varchar(255);" json:"remark"` //备注
BaseModel
}
@@ -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
}
+20 -20
View File
@@ -6,20 +6,20 @@ import (
)
type LoginLog struct {
InfoId int `json:"infoId" gorm:"primary_key;AUTO_INCREMENT"` //主键
Username string `json:"username" gorm:"type:varchar(128);"` //用户名
Status string `json:"status" gorm:"type:int(1);"` //状态
Ipaddr string `json:"ipaddr" gorm:"type:varchar(255);"` //ip地址
LoginLocation string `json:"loginLocation" gorm:"type:varchar(255);"` //归属地
Browser string `json:"browser" gorm:"type:varchar(255);"` //浏览器
Os string `json:"os" gorm:"type:varchar(255);"` //系统
Platform string `json:"platform" gorm:"type:varchar(255);"` // 固件
LoginTime time.Time `json:"loginTime" gorm:"type:timestamp;"` //登录时间
CreateBy string `json:"createBy" gorm:"type:varchar(128);"` //创建人
UpdateBy string `json:"updateBy" gorm:"type:varchar(128);"` //更新者
DataScope string `json:"dataScope" gorm:"-"` //数据
Params string `json:"params" gorm:"-"` //
Remark string `json:"remark" gorm:"type:varchar(255);"` //备注
InfoId int `json:"infoId" gorm:"primary_key;AUTO_INCREMENT"` //主键
Username string `json:"username" gorm:"type:varchar(128);"` //用户名
Status string `json:"status" gorm:"type:int(1);"` //状态
Ipaddr string `json:"ipaddr" gorm:"type:varchar(255);"` //ip地址
LoginLocation string `json:"loginLocation" gorm:"type:varchar(255);"` //归属地
Browser string `json:"browser" gorm:"type:varchar(255);"` //浏览器
Os string `json:"os" gorm:"type:varchar(255);"` //系统
Platform string `json:"platform" gorm:"type:varchar(255);"` // 固件
LoginTime time.Time `json:"loginTime" gorm:"type:timestamp;"` //登录时间
CreateBy string `json:"createBy" gorm:"type:varchar(128);"` //创建人
UpdateBy string `json:"updateBy" gorm:"type:varchar(128);"` //更新者
DataScope string `json:"dataScope" gorm:"-"` //数据
Params string `json:"params" gorm:"-"` //
Remark string `json:"remark" gorm:"type:varchar(255);"` //备注
Msg string `json:"msg" gorm:"type:varchar(255);"`
BaseModel
}
@@ -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
+22 -18
View File
@@ -7,7 +7,7 @@ import (
)
type Menu struct {
MenuId int `json:"menuId" gorm:"primary_key;AUTO_INCREMENT"`
MenuId int `json:"menuId" gorm:"primary_key;AUTO_INCREMENT"`
MenuName string `json:"menuName" gorm:"type:varchar(11);"`
Title string `json:"title" gorm:"type:varchar(64);"`
Icon string `json:"icon" gorm:"type:varchar(128);"`
@@ -16,7 +16,7 @@ type Menu struct {
MenuType string `json:"menuType" gorm:"type:varchar(1);"`
Action string `json:"action" gorm:"type:varchar(16);"`
Permission string `json:"permission" gorm:"type:varchar(32);"`
ParentId int `json:"parentId" gorm:"type:int(11);"`
ParentId int `json:"parentId" gorm:"type:int(11);"`
NoCache bool `json:"noCache" gorm:"type:char(1);"`
Breadcrumb string `json:"breadcrumb" gorm:"type:varchar(255);"`
Component string `json:"component" gorm:"type:varchar(255);"`
@@ -27,7 +27,7 @@ type Menu struct {
IsFrame string `json:"isFrame" gorm:"type:int(1);DEFAULT:0;"`
DataScope string `json:"dataScope" gorm:"-"`
Params string `json:"params" gorm:"-"`
RoleId int `gorm:"-"`
RoleId int `gorm:"-"`
Children []Menu `json:"children" gorm:"-"`
IsSelect bool `json:"is_select" gorm:"-"`
BaseModel
@@ -38,13 +38,13 @@ func (Menu) TableName() string {
}
type MenuLable struct {
Id int `json:"id" gorm:"-"`
Id int `json:"id" gorm:"-"`
Label string `json:"label" gorm:"-"`
Children []MenuLable `json:"children" gorm:"-"`
}
type Menus struct {
MenuId int `json:"menuId" gorm:"column:menu_id;primary_key"`
MenuId int `json:"menuId" gorm:"column:menu_id;primary_key"`
MenuName string `json:"menuName" gorm:"column:menu_name"`
Title string `json:"title" gorm:"column:title"`
Icon string `json:"icon" gorm:"column:icon"`
@@ -52,7 +52,7 @@ type Menus struct {
MenuType string `json:"menuType" gorm:"column:menu_type"`
Action string `json:"action" gorm:"column:action"`
Permission string `json:"permission" gorm:"column:permission"`
ParentId int `json:"parentId" gorm:"column:parent_id"`
ParentId int `json:"parentId" gorm:"column:parent_id"`
NoCache bool `json:"noCache" gorm:"column:no_cache"`
Breadcrumb string `json:"breadcrumb" gorm:"column:breadcrumb"`
Component string `json:"component" gorm:"column:component"`
@@ -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
}
+10 -10
View File
@@ -7,9 +7,9 @@ import (
//sys_operlog
type SysOperLog struct {
OperId int `json:"operId" gorm:"primary_key;AUTO_INCREMENT"` //日志编码
Title string `json:"title" gorm:"size(255);"` //操作模块
BusinessType string `json:"businessType" gorm:"type:varchar(128);"` //操作类型
OperId int `json:"operId" gorm:"primary_key;AUTO_INCREMENT"` //日志编码
Title string `json:"title" gorm:"size(255);"` //操作模块
BusinessType string `json:"businessType" gorm:"type:varchar(128);"` //操作类型
BusinessTypes string `json:"businessTypes" gorm:"type:varchar(128);"`
Method string `json:"method" gorm:"type:varchar(128);"` //函数
RequestMethod string `json:"requestMethod" gorm:"type:varchar(128);"` //请求方式
@@ -20,7 +20,7 @@ type SysOperLog struct {
OperIp string `json:"operIp" gorm:"type:varchar(128);"` //客户端ip
OperLocation string `json:"operLocation" gorm:"type:varchar(128);"` //访问位置
OperParam string `json:"operParam" gorm:"type:varchar(255);"` //请求参数
Status string `json:"status" gorm:"type:int(1);"` //操作状态
Status string `json:"status" gorm:"type:int(1);"` //操作状态
OperTime time.Time `json:"operTime" gorm:"type:timestamp;"` //操作时间
JsonResult string `json:"jsonResult" gorm:"type:varchar(255);"` //返回数据
CreateBy string `json:"createBy" gorm:"type:varchar(128);"` //创建人
@@ -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
+13 -13
View File
@@ -6,12 +6,12 @@ import (
)
type Post struct {
PostId int `gorm:"primary_key;AUTO_INCREMENT" json:"postId"` //岗位编号
PostName string `gorm:"type:varchar(128);" json:"postName"` //岗位名称
PostCode string `gorm:"type:varchar(128);" json:"postCode"` //岗位代码
Sort int `gorm:"type:int(4);" json:"sort"` //岗位排序
Status string `gorm:"type:int(1);" json:"status"` //状态
Remark string `gorm:"type:varchar(255);" json:"remark"` //描述
PostId int `gorm:"primary_key;AUTO_INCREMENT" json:"postId"` //岗位编号
PostName string `gorm:"type:varchar(128);" json:"postName"` //岗位名称
PostCode string `gorm:"type:varchar(128);" json:"postCode"` //岗位代码
Sort int `gorm:"type:int(4);" json:"sort"` //岗位排序
Status string `gorm:"type:int(1);" json:"status"` //状态
Remark string `gorm:"type:varchar(255);" json:"remark"` //描述
CreateBy string `gorm:"type:varchar(128);" json:"createBy"`
UpdateBy string `gorm:"type:varchar(128);" json:"updateBy"`
DataScope string `gorm:"-" json:"dataScope"`
@@ -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
}
+13 -12
View File
@@ -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
@@ -43,17 +44,17 @@ type SysUserId struct {
type SysUserB struct {
NickName string `gorm:"type:varchar(128)" json:"nickName"` // 昵称
Phone string `gorm:"type:varchar(11)" json:"phone"` // 手机号
RoleId int `gorm:"type:int(11)" json:"roleId"` // 角色编码
RoleId int `gorm:"type:int(11)" json:"roleId"` // 角色编码
Salt string `gorm:"type:varchar(255)" json:"salt"` //盐
Avatar string `gorm:"type:varchar(255)" json:"avatar"` //头像
Sex string `gorm:"type:varchar(255)" json:"sex"` //性别
Email string `gorm:"type:varchar(128)" json:"email"` //邮箱
DeptId int `gorm:"type:int(11)" json:"deptId"` //部门编码
PostId int `gorm:"type:int(11)" json:"postId"` //职位编码
DeptId int `gorm:"type:int(11)" json:"deptId"` //部门编码
PostId int `gorm:"type:int(11)" json:"postId"` //职位编码
CreateBy string `gorm:"type:varchar(128)" json:"createBy"` //
UpdateBy string `gorm:"type:varchar(128)" json:"updateBy"` //
Remark string `gorm:"type:varchar(255)" json:"remark"` //备注
Status string `gorm:"type:int(1);" json:"status"`
Status string `gorm:"type:int(1);" json:"status"`
DataScope string `gorm:"-" json:"dataScope"`
Params string `gorm:"-" json:"params"`
@@ -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