完成字典模块改造
This commit is contained in:
1 parent
e04b5559bd
commit
4979fd659f
21 files changed
+1176
-635
No files matched your search
@@ -32,8 +32,8 @@ func _1599190683659Tables(db *gorm.DB, version string) error {
|
||||
new(models.SysUser),
|
||||
new(system.SysRole),
|
||||
new(models.Post),
|
||||
new(models.DictData),
|
||||
new(models.DictType),
|
||||
new(DictData),
|
||||
new(DictType),
|
||||
new(models.SysJob),
|
||||
new(system.SysConfig),
|
||||
new(models.SysSetting),
|
||||
|
||||
@@ -44,7 +44,7 @@ func _1599190683670Test(db *gorm.DB, version string) error {
|
||||
{1, "系统管理员", "2", "admin", 1, "", "1", "", "", true, "", models.BaseModel{CreatedAt: time.Now(), UpdatedAt: time.Now()}, "", []int{}, []int{}},
|
||||
}
|
||||
|
||||
list7 := []models.DictType{
|
||||
list7 := []DictType{
|
||||
{DictId: 1, DictName: "系统开关", DictType: "sys_normal_disable", Status: "2", CreateBy: "1", UpdateBy: "1", Remark: "系统开关列表", BaseModel: models.BaseModel{CreatedAt: time.Now(), UpdatedAt: time.Now()}},
|
||||
{DictId: 2, DictName: "用户性别", DictType: "sys_user_sex", Status: "2", CreateBy: "1", UpdateBy: "", Remark: "用户性别列表", BaseModel: models.BaseModel{CreatedAt: time.Now(), UpdatedAt: time.Now()}},
|
||||
{DictId: 3, DictName: "菜单状态", DictType: "sys_show_hide", Status: "2", CreateBy: "1", UpdateBy: "", Remark: "菜单状态列表", BaseModel: models.BaseModel{CreatedAt: time.Now(), UpdatedAt: time.Now()}},
|
||||
@@ -61,7 +61,7 @@ func _1599190683670Test(db *gorm.DB, version string) error {
|
||||
{models.SysUserId{1}, models.LoginM{models.UserName{"admin"}, models.PassWord{"$2a$10$cKFFTCzGOvaIHHJY2K45Zuwt8TD6oPzYi4s5MzYIBAWCLL6ZhouP2"}}, models.SysUserB{"zhangwj", "13818888888", 1, "", "", "0", "1@qq.com", 1, 1, "1", "1", "", "2", models.BaseModel{CreatedAt: time.Now(), UpdatedAt: time.Now()}, "", ""}},
|
||||
}
|
||||
|
||||
list9 := []models.DictData{
|
||||
list9 := []DictData{
|
||||
{DictCode: 1, DictSort: 0, DictLabel: "正常", DictValue: "2", DictType: "sys_normal_disable", CssClass: "", ListClass: "", IsDefault: "", Status: "2", Default: "", CreateBy: "1", UpdateBy: "", Remark: "系统正常", BaseModel: models.BaseModel{CreatedAt: time.Now(), UpdatedAt: time.Now()}},
|
||||
{DictCode: 2, DictSort: 0, DictLabel: "停用", DictValue: "1", DictType: "sys_normal_disable", CssClass: "", ListClass: "", IsDefault: "", Status: "2", Default: "", CreateBy: "1", UpdateBy: "", Remark: "系统停用", BaseModel: models.BaseModel{CreatedAt: time.Now(), UpdatedAt: time.Now()}},
|
||||
{DictCode: 3, DictSort: 0, DictLabel: "男", DictValue: "0", DictType: "sys_user_sex", CssClass: "", ListClass: "", IsDefault: "", Status: "2", Default: "", CreateBy: "1", UpdateBy: "", Remark: "性别男", BaseModel: models.BaseModel{CreatedAt: time.Now(), UpdatedAt: time.Now()}},
|
||||
|
||||
@@ -18,13 +18,13 @@ func init() {
|
||||
func _1606579402398Test(db *gorm.DB, version string) error {
|
||||
return db.Transaction(func(tx *gorm.DB) error {
|
||||
|
||||
dicData := models.DictData{}
|
||||
dicData := DictData{}
|
||||
err := tx.Model(&dicData).Where("dict_code = ?", 1).Update("dict_value", 2).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dicType := models.DictType{}
|
||||
dicType := DictType{}
|
||||
err = tx.Model(&dicType).Where("status = ?", 0).Update("status", 2).Error
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -24,7 +24,7 @@ func _1606582844753Test(db *gorm.DB, version string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
dictData := models.DictData{}
|
||||
dictData := DictData{}
|
||||
err = tx.Model(&dictData).Where("status = ?", 0).Update("status", 2).Error
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package version
|
||||
|
||||
import (
|
||||
"go-admin/app/admin/models"
|
||||
//"go-admin/app/admin/models"
|
||||
"gorm.io/gorm"
|
||||
"runtime"
|
||||
@@ -19,7 +18,7 @@ func _1613720892819Test(db *gorm.DB, version string) error {
|
||||
return db.Transaction(func(tx *gorm.DB) error {
|
||||
|
||||
// TODO: 这里开始写入要变更的内容
|
||||
t := &models.DictType{
|
||||
t := &DictType{
|
||||
DictName: "内容状态",
|
||||
DictType: "sys_content_status",
|
||||
Status: "2",
|
||||
@@ -31,8 +30,8 @@ func _1613720892819Test(db *gorm.DB, version string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
data := make([]models.DictData, 2)
|
||||
data[0] = models.DictData{
|
||||
data := make([]DictData, 2)
|
||||
data[0] = DictData{
|
||||
DictSort: 0,
|
||||
DictLabel: "正常",
|
||||
DictValue: "1",
|
||||
@@ -41,7 +40,7 @@ func _1613720892819Test(db *gorm.DB, version string) error {
|
||||
CreateBy: "1",
|
||||
UpdateBy: "1",
|
||||
}
|
||||
data[1] = models.DictData{
|
||||
data[1] = DictData{
|
||||
DictSort: 1,
|
||||
DictLabel: "禁用",
|
||||
DictValue: "2",
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package version
|
||||
|
||||
import (
|
||||
"go-admin/app/admin/models/system"
|
||||
|
||||
//"go-admin/app/admin/models"
|
||||
"gorm.io/gorm"
|
||||
"runtime"
|
||||
|
||||
"go-admin/cmd/migrate/migration"
|
||||
common "go-admin/common/models"
|
||||
)
|
||||
|
||||
func init() {
|
||||
_, fileName, _, _ := runtime.Caller(0)
|
||||
migration.Migrate.SetVersion(migration.GetFilename(fileName), _1613783303115Test)
|
||||
}
|
||||
|
||||
func _1613783303115Test(db *gorm.DB, version string) error {
|
||||
return db.Transaction(func(tx *gorm.DB) error {
|
||||
|
||||
//修改字段类型
|
||||
err := tx.Migrator().AlterColumn(&system.SysDictType{}, "create_by")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = tx.Migrator().AlterColumn(&system.SysDictType{}, "update_by")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = tx.Migrator().AlterColumn(&system.SysDictData{}, "create_by")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = tx.Migrator().AlterColumn(&system.SysDictData{}, "update_by")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.Create(&common.Migration{
|
||||
Version: version,
|
||||
}).Error
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package version
|
||||
|
||||
import (
|
||||
"go-admin/app/admin/models"
|
||||
)
|
||||
|
||||
type DictData struct {
|
||||
DictCode int `gorm:"primary_key;auto_increment;" json:"dictCode" example:"1"` //字典编码
|
||||
DictSort int `gorm:"" json:"dictSort"` //显示顺序
|
||||
DictLabel string `gorm:"size:128;" json:"dictLabel"` //数据标签
|
||||
DictValue string `gorm:"size:255;" json:"dictValue"` //数据键值
|
||||
DictType string `gorm:"size:64;" json:"dictType"` //字典类型
|
||||
CssClass string `gorm:"size:128;" json:"cssClass"` //
|
||||
ListClass string `gorm:"size:128;" json:"listClass"` //
|
||||
IsDefault string `gorm:"size:8;" json:"isDefault"` //
|
||||
Status string `gorm:"size:4;" json:"status"` //状态
|
||||
Default string `gorm:"size:8;" json:"default"` //
|
||||
CreateBy string `gorm:"size:64;" json:"createBy"` //
|
||||
UpdateBy string `gorm:"size:64;" json:"updateBy"` //
|
||||
Remark string `gorm:"size:255;" json:"remark"` //备注
|
||||
models.BaseModel
|
||||
}
|
||||
|
||||
func (DictData) TableName() string {
|
||||
return "sys_dict_data"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package version
|
||||
|
||||
import (
|
||||
"go-admin/app/admin/models"
|
||||
)
|
||||
|
||||
type DictType struct {
|
||||
DictId int `gorm:"primary_key;auto_increment;" json:"dictId"`
|
||||
DictName string `gorm:"size:128;" json:"dictName"` //字典名称
|
||||
DictType string `gorm:"size:128;" json:"dictType"` //字典类型
|
||||
Status string `gorm:"size:4;" json:"status"` //状态
|
||||
CreateBy string `gorm:"size:11;" json:"createBy"` //创建者
|
||||
UpdateBy string `gorm:"size:11;" json:"updateBy"` //更新者
|
||||
Remark string `gorm:"size:255;" json:"remark"` //备注
|
||||
models.BaseModel
|
||||
}
|
||||
|
||||
func (DictType) TableName() string {
|
||||
return "sys_dict_type"
|
||||
}
|
||||
Reference in new issue
Block a user