update
This commit is contained in:
1 parent
f25da5f1ee
commit
1df55e75e5
72 files changed
+1401
-1559
No files matched your search
+30
-48
@@ -2,47 +2,34 @@ package models
|
||||
|
||||
import (
|
||||
orm "go-admin/database"
|
||||
"go-admin/utils"
|
||||
"go-admin/pkg/utils"
|
||||
)
|
||||
|
||||
type DictData struct {
|
||||
//字典编码
|
||||
DictCode int64 `gorm:"column:dict_code;primary_key" json:"dictCode" example:"1"`
|
||||
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
|
||||
}
|
||||
|
||||
//显示顺序
|
||||
DictSort int `gorm:"column:dict_sort" json:"dictSort" example:"1"`
|
||||
|
||||
//数据标签
|
||||
DictLabel string `gorm:"column:dict_label" json:"dictLabel"`
|
||||
|
||||
//数据键值
|
||||
DictValue string `gorm:"column:dict_value" json:"dictValue"`
|
||||
|
||||
//字典类型
|
||||
DictType string `gorm:"column:dict_type" json:"dictType"`
|
||||
CssClass string `gorm:"column:css_class" json:"cssClass"`
|
||||
ListClass string `gorm:"column:list_class" json:"listClass"`
|
||||
IsDefault string `gorm:"column:is_default" json:"isDefault"`
|
||||
|
||||
//状态
|
||||
Status string `gorm:"column:status" json:"status"`
|
||||
Default string `gorm:"column:default" json:"default"`
|
||||
CreateBy string `gorm:"column:create_by" json:"createBy"`
|
||||
CreateTime string `gorm:"column:create_time" json:"createTime"`
|
||||
UpdateBy string `gorm:"column:update_by" json:"updateBy"`
|
||||
UpdateTime string `gorm:"column:update_time" json:"updateTime"`
|
||||
|
||||
//备注
|
||||
Remark string `gorm:"column:remark" json:"remark"`
|
||||
Params string `gorm:"column:params" json:"params"`
|
||||
DataScope string `gorm:"column:data_scope" json:"dataScope"`
|
||||
IsDel int `gorm:"column:is_del" json:"isDel"`
|
||||
func (DictData) TableName() string {
|
||||
return "sys_dict_data"
|
||||
}
|
||||
|
||||
func (e *DictData) Create() (DictData, error) {
|
||||
var doc DictData
|
||||
e.CreateTime = utils.GetCurrntTime()
|
||||
e.UpdateTime = utils.GetCurrntTime()
|
||||
result := orm.Eloquent.Table("sys_dict_data").Create(&e)
|
||||
if result.Error != nil {
|
||||
err := result.Error
|
||||
@@ -66,7 +53,7 @@ func (e *DictData) GetByCode() (DictData, error) {
|
||||
table = table.Where("dict_type = ?", e.DictType)
|
||||
}
|
||||
|
||||
if err := table.Where("is_del = 0").First(&doc).Error; err != nil {
|
||||
if err := table.First(&doc).Error; err != nil {
|
||||
return doc, err
|
||||
}
|
||||
return doc, nil
|
||||
@@ -86,13 +73,13 @@ func (e *DictData) Get() ([]DictData, error) {
|
||||
table = table.Where("dict_type = ?", e.DictType)
|
||||
}
|
||||
|
||||
if err := table.Where("is_del = 0").Order("dict_sort").Find(&doc).Error; err != nil {
|
||||
if err := table.Order("dict_sort").Find(&doc).Error; err != nil {
|
||||
return doc, err
|
||||
}
|
||||
return doc, nil
|
||||
}
|
||||
|
||||
func (e *DictData) GetPage(pageSize int, pageIndex int) ([]DictData, int32, error) {
|
||||
func (e *DictData) GetPage(pageSize int, pageIndex int) ([]DictData, int, error) {
|
||||
var doc []DictData
|
||||
|
||||
table := orm.Eloquent.Select("*").Table("sys_dict_data")
|
||||
@@ -111,20 +98,19 @@ func (e *DictData) GetPage(pageSize int, pageIndex int) ([]DictData, int32, erro
|
||||
|
||||
// 数据权限控制
|
||||
dataPermission := new(DataPermission)
|
||||
dataPermission.UserId, _ = utils.StringToInt64(e.DataScope)
|
||||
dataPermission.UserId, _ = utils.StringToInt(e.DataScope)
|
||||
table = dataPermission.GetDataScope("sys_dict_data", table)
|
||||
|
||||
var count int32
|
||||
var count int
|
||||
|
||||
if err := table.Where("is_del = 0").Order("dict_sort").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
||||
if err := table.Order("dict_sort").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
table.Where("is_del = 0").Count(&count)
|
||||
table.Count(&count)
|
||||
return doc, count, nil
|
||||
}
|
||||
|
||||
func (e *DictData) Update(id int64) (update DictData, err error) {
|
||||
e.UpdateTime = utils.GetCurrntTime()
|
||||
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 {
|
||||
return
|
||||
}
|
||||
@@ -137,12 +123,8 @@ func (e *DictData) Update(id int64) (update DictData, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (e *DictData) Delete(id int64) (success bool, err error) {
|
||||
var mp = map[string]string{}
|
||||
mp["is_del"] = "1"
|
||||
mp["update_time"] = utils.GetCurrntTime()
|
||||
mp["update_by"] = e.UpdateBy
|
||||
if err = orm.Eloquent.Table("sys_dict_data").Where("dict_code = ?", id).Update(mp).Error; err != nil {
|
||||
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 {
|
||||
success = false
|
||||
return
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user