This commit is contained in:
zhangwenjian committed 2020-04-13 00:30:58 +08:00
1 parent f25da5f1ee
commit 1df55e75e5
72 files changed
+1401 -1559

No files matched your search

+30 -44
View File
@@ -2,39 +2,30 @@ package models
import (
orm "go-admin/database"
"go-admin/utils"
"go-admin/pkg/utils"
)
type Config struct {
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);"` //备注
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:"-"`
BaseModel
}
//编码
ConfigId int64 `json:"configId" gorm:"column:config_id;primary_key"`
//参数名称
ConfigName string `json:"configName" gorm:"column:config_name"`
//参数键名
ConfigKey string `json:"configKey" gorm:"column:config_key"`
//参数键值
ConfigValue string `json:"configValue" gorm:"column:config_value"`
//是否系统内置
ConfigType string `json:"configType" gorm:"column:config_type"`
//备注
Remark string `json:"remark" gorm:"column:remark"`
CreateBy string `json:"createBy" gorm:"column:create_by"`
CreateTime string `json:"createTime" gorm:"column:create_time"`
UpdateBy string `json:"updateBy" gorm:"column:update_by"`
UpdateTime string `json:"updateTime" gorm:"column:update_time"`
DataScope string `json:"dataScope" gorm:"-"`
Params string `json:"params" gorm:"column:params"`
IsDel int `json:"isDel" gorm:"column:is_del"`
func (SysConfig) TableName() string {
return "sys_config"
}
// Config 创建
func (e *Config) Create() (Config, error) {
var doc Config
doc.IsDel = 0
e.CreateTime = utils.GetCurrntTime()
e.UpdateTime = utils.GetCurrntTime()
func (e *SysConfig) Create() (SysConfig, error) {
var doc SysConfig
result := orm.Eloquent.Table("sys_config").Create(&e)
if result.Error != nil {
err := result.Error
@@ -45,8 +36,8 @@ func (e *Config) Create() (Config, error) {
}
// 获取 Config
func (e *Config) Get() (Config, error) {
var doc Config
func (e *SysConfig) Get() (SysConfig, error) {
var doc SysConfig
table := orm.Eloquent.Table("sys_config")
if e.ConfigId != 0 {
@@ -57,14 +48,14 @@ func (e *Config) Get() (Config, error) {
table = table.Where("config_key = ?", e.ConfigKey)
}
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
}
func (e *Config) GetPage(pageSize int, pageIndex int) ([]Config, int32, error) {
var doc []Config
func (e *SysConfig) GetPage(pageSize int, pageIndex int) ([]SysConfig, int, error) {
var doc []SysConfig
table := orm.Eloquent.Select("*").Table("sys_config")
@@ -80,20 +71,19 @@ func (e *Config) GetPage(pageSize int, pageIndex int) ([]Config, int32, error) {
// 数据权限控制
dataPermission := new(DataPermission)
dataPermission.UserId, _ = utils.StringToInt64(e.DataScope)
dataPermission.UserId, _ = utils.StringToInt(e.DataScope)
table = dataPermission.GetDataScope("sys_config", table)
var count int32
var count int
if err := table.Where("is_del = 0").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
if err := table.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 *Config) Update(id int64) (update Config, err error) {
e.UpdateTime = utils.GetCurrntTime()
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 {
return
}
@@ -106,12 +96,8 @@ func (e *Config) Update(id int64) (update Config, err error) {
return
}
func (e *Config) 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_config").Where("config_id = ?", id).Update(mp).Error; err != nil {
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 {
success = false
return
}