package service

import (
	"gin-vue-admin/global"
	"gin-vue-admin/model"
)

func GetSysConf(confName string) string {
	data := new(model.SysConf)
	table := " sys_conf "
	field := " conf_val "

	sqlStr := "SELECT " + field +
		" FROM " + table +
		" WHERE conf_name =?"

	global.GVA_DB.Raw(sqlStr, confName).Find(&data)
	if global.GVA_DB.Error != nil {
		return ""
	}
	return data.ConfVal
}

func SetSysConf(confName string, confVal string) error {
	table := " sys_conf "

	sqlStr := "UPDATE " + table +
		" SET conf_val = '" + confVal + "'" +
		" WHERE conf_name =?"

	global.GVA_DB.Exec(sqlStr, confName)
	if global.GVA_DB.Error != nil {
		return global.GVA_DB.Error
	}
	return nil
}
