dictionary.go 1.3 KB
package domain

// 字典
type Dictionary struct {
	// 字典编号 主键
	DictionaryId int64 `json:"dictionaryId"`
	// 字典编码
	DictCode string `json:"dictCode"`
	// 字典名称
	DictName string `json:"dictName"`
	// 备注信息
	Describe string `json:"describe"`
	// 字典值列表
	DictItems []DictionaryItem `json:"dictItems"`
}

type DictionaryRepository interface {
	Save(dictionary *Dictionary) (*Dictionary, error)
	Remove(dictionary *Dictionary) (*Dictionary, error)
	FindOne(queryOptions map[string]interface{}) (*Dictionary, error)
	Find(queryOptions map[string]interface{}) (int64, []*Dictionary, error)
}

func (dictionary *Dictionary) Identify() interface{} {
	if dictionary.DictionaryId == 0 {
		return nil
	}
	return dictionary.DictionaryId
}

func (dictionary *Dictionary) Update(data map[string]interface{}) error {
	if dictionaryId, ok := data["dictionaryId"]; ok {
		dictionary.DictionaryId = dictionaryId.(int64)
	}
	if dictCode, ok := data["dictCode"]; ok {
		dictionary.DictCode = dictCode.(string)
	}
	if dictName, ok := data["dictName"]; ok {
		dictionary.DictName = dictName.(string)
	}
	if desc, ok := data["describe"]; ok {
		dictionary.Describe = desc.(string)
	}
	if dictItems, ok := data["dictItems"]; ok {
		dictionary.DictItems = dictItems.([]DictionaryItem)
	}
	return nil
}