package dao // Dict 字典 type Dict struct { ID int64 `gorm:"primary_key" json:"id"` //主键 ParentId int64 `gorm:"type:bigint;default 0" json:"parentId"` //父主键 Code string `gorm:"type:varchar(255)" json:"code"` //字典码 DictKey string `gorm:"type:varchar(255)" json:"dictKey"` //字典值 DictValue string `gorm:"type:varchar(255)" json:"dictValue"` //字典名称 Sort int `gorm:"type:int" json:"sort"` //排序 Remark string `gorm:"type:varchar(255)" json:"remark"` //字典备注 IsSealed int `gorm:"type:int;default 0" json:"isSealed"` //是否已封存 IsDeleted int `gorm:"type:int;default 0" json:"isDeleted"` //是否已删除 } func (Dict) TableName() string { return "dict" } func (c *Dict) GetByCodeAndKey() error { return Db.Model(&c).Where("code = ? and dict_key = ?", c.Code, c.DictKey).Find(&c).Error } func (c *Dict) GetByCode() ([]Dict, error) { var dict []Dict err := Db.Model(&c).Select("code, dict_key, dict_value"). Where("code = ? and parent_id > 0 and is_sealed = 0 and is_deleted = 0", c.Code). Find(&dict).Error return dict, err }