system_setting.go 2.5 KB
package domain

// 系统参数设置
type SystemSetting struct {
	// 公司id
	CompanyId int64 `json:"companyId"`
	// 管控层级
	ControlLevel string `json:"controlLevel"`
	// 描述
	Description string `json:"description"`
	// 设置对应的编码
	SettingCode string `json:"settingCode"`
	// 设置对应的名称
	SettingName string `json:"settingName"`
	// 数据id
	SystemSettingId int64 `json:"systemSettingId"`
	// 设定的值
	Value string `json:"value"`
	// 值类型
	ValueType string `json:"valueType"`
}

type SystemSettingRepository interface {
	Save(systemSetting *SystemSetting) (*SystemSetting, error)
	Remove(systemSetting *SystemSetting) (*SystemSetting, error)
	FindOne(queryOptions map[string]interface{}) (*SystemSetting, error)
	Find(queryOptions map[string]interface{}) (int64, []*SystemSetting, error)
}

func (systemSetting *SystemSetting) Identify() interface{} {
	if systemSetting.SystemSettingId == 0 {
		return nil
	}
	return systemSetting.SystemSettingId
}

func (systemSetting *SystemSetting) Update(data map[string]interface{}) error {
	if companyId, ok := data["companyId"]; ok {
		systemSetting.CompanyId = companyId.(int64)
	}
	if controlLevel, ok := data["controlLevel"]; ok {
		systemSetting.ControlLevel = controlLevel.(string)
	}
	if description, ok := data["description"]; ok {
		systemSetting.Description = description.(string)
	}
	if settingCode, ok := data["settingCode"]; ok {
		systemSetting.SettingCode = settingCode.(string)
	}
	if settingName, ok := data["settingName"]; ok {
		systemSetting.SettingName = settingName.(string)
	}
	if systemSettingId, ok := data["systemSettingId"]; ok {
		systemSetting.SystemSettingId = systemSettingId.(int64)
	}
	if value, ok := data["value"]; ok {
		systemSetting.Value = value.(string)
	}
	if valueType, ok := data["valueType"]; ok {
		systemSetting.ValueType = valueType.(string)
	}
	return nil
}

var defaultsysSettingList = []SystemSetting{
	{
		ControlLevel: "系统级",
		ValueType:    "字符",
		Value:        "TL123456!",
		SettingName:  "用户初始化密码",
		SettingCode:  "XT001",
		Description:  "用于用户初始化设置初始化密码",
	},
}

func (systemSetting *SystemSetting) GetDefaultSetting(settingCode string) []SystemSetting {
	var list []SystemSetting
	if len(settingCode) > 0 {
		for i := range defaultsysSettingList {
			if defaultsysSettingList[i].SettingCode == settingCode {
				list = append(list, defaultsysSettingList[i])
			}
		}
	} else {
		list = make([]SystemSetting, len(defaultsysSettingList))
		copy(list, defaultsysSettingList)
	}
	return list
}