You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.6 KiB
56 lines
1.6 KiB
package service
|
|
|
|
import (
|
|
"fmt"
|
|
"pure/global"
|
|
"pure/model"
|
|
)
|
|
|
|
func GetSysDictDataLabel(typeCode, value string) string {
|
|
var res string
|
|
|
|
cacheKey := "bkb-admin_sys_dict_labels"
|
|
labelKey := fmt.Sprintf("%s_%s", typeCode, value)
|
|
res = RedisHashGet(cacheKey, labelKey)
|
|
if res == "" {
|
|
_ = global.MG_DB.Model(&model.SysDictData{}).Select("label").Where("type_code=? AND `value`=?", typeCode, value).Scan(&res).Error
|
|
go RedisHashSet(cacheKey, labelKey, res)
|
|
}
|
|
return res
|
|
}
|
|
|
|
func GetSysDictDataList(typeCode string) (err error, list interface{}) {
|
|
var lists []model.SysDictDataView
|
|
err = global.MG_DB.Model(&model.SysDictData{}).Where("type_code=? AND `status`='1'", typeCode).Order("sort asc").Find(&lists).Error
|
|
return err, lists
|
|
}
|
|
|
|
func GetSysDictDataListByTypeCode(typeCode string) (list []model.SysDictDataView, err error) {
|
|
var lists []model.SysDictDataView
|
|
err = global.MG_DB.Model(&model.SysDictData{}).Where("type_code=? AND `status`='1'", typeCode).Order("sort asc").Find(&lists).Error
|
|
return lists, err
|
|
}
|
|
|
|
func FormatDictLabels(typeCode string, values []string) (labels []string) {
|
|
for _, vid := range values {
|
|
vLabel := GetSysDictDataLabel(typeCode, vid)
|
|
labels = append(labels, vLabel)
|
|
}
|
|
return labels
|
|
}
|
|
|
|
func getDictMap(typeCode string, values []string) map[string]string {
|
|
var (
|
|
list []model.SysDictData
|
|
result = make(map[string]string)
|
|
)
|
|
db := global.MG_DB.Model(&model.SysDictData{}).Where("type_code = ?", typeCode)
|
|
if len(values) != 0 {
|
|
db = db.Where("values IN (?)", values)
|
|
}
|
|
_ = db.Find(&list).Error
|
|
for _, val := range list {
|
|
result[val.Value] = val.Label
|
|
}
|
|
return result
|
|
}
|
|
|