|
@ -3,6 +3,10 @@ package siterpc |
|
|
import ( |
|
|
import ( |
|
|
"encoding/json" |
|
|
"encoding/json" |
|
|
"errors" |
|
|
"errors" |
|
|
|
|
|
"log" |
|
|
|
|
|
"reflect" |
|
|
|
|
|
|
|
|
|
|
|
"git.tetele.net/tgo/helper" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -10,13 +14,14 @@ import ( |
|
|
* 2021/09/04 |
|
|
* 2021/09/04 |
|
|
* GZ |
|
|
* GZ |
|
|
*/ |
|
|
*/ |
|
|
func GetAllConfig(site_id, dbname string, url ...string) ([]map[string]string, error) { |
|
|
|
|
|
|
|
|
func GetAllConfig(site_id, dbname string, url ...string) (map[string]string, error) { |
|
|
|
|
|
|
|
|
if dbname == "" { |
|
|
if dbname == "" { |
|
|
return nil, errors.New("参数错误") |
|
|
return nil, errors.New("参数错误") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
conn, err := rpc_server_conn(url...) |
|
|
conn, err := rpc_server_conn(url...) |
|
|
|
|
|
|
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return nil, err |
|
|
return nil, err |
|
|
} |
|
|
} |
|
@ -50,7 +55,43 @@ func GetAllConfig(site_id, dbname string, url ...string) ([]map[string]string, e |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return nil, err |
|
|
return nil, err |
|
|
} |
|
|
} |
|
|
return res_arr, nil |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var res_map map[string]string = make(map[string]string) |
|
|
|
|
|
if len(res_arr) > 0 { |
|
|
|
|
|
var value string |
|
|
|
|
|
for _, info := range res_arr { |
|
|
|
|
|
value = "" |
|
|
|
|
|
switch info["Type"] { |
|
|
|
|
|
|
|
|
|
|
|
case "select": |
|
|
|
|
|
|
|
|
|
|
|
var content interface{} |
|
|
|
|
|
err = json.Unmarshal([]byte(info["Content"]), &content) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
log.Println(err) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
content_type := reflect.TypeOf(content).String() //数据字典的类型
|
|
|
|
|
|
|
|
|
|
|
|
switch content_type { |
|
|
|
|
|
case "[]interface {}": //数组形式,value字段对应数组的key
|
|
|
|
|
|
list := content.([]interface{}) |
|
|
|
|
|
val_key := helper.ToInt(info["Value"]) |
|
|
|
|
|
value = helper.ToString(list[val_key]) |
|
|
|
|
|
case "map[string]interface {}": //map形式,value字段对应key
|
|
|
|
|
|
list := content.(map[string]interface{}) |
|
|
|
|
|
value = helper.ToString(list[info["Value"]]) |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
default: |
|
|
|
|
|
value = info["Value"] |
|
|
|
|
|
} |
|
|
|
|
|
res_map[info["Name"]] = value |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return res_map, nil |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -59,7 +100,7 @@ func GetAllConfig(site_id, dbname string, url ...string) ([]map[string]string, e |
|
|
* 2021/09/04 |
|
|
* 2021/09/04 |
|
|
* GZ |
|
|
* GZ |
|
|
*/ |
|
|
*/ |
|
|
func GetGroupConfig(site_id, dbname string, groupname string, url ...string) ([]map[string]string, error) { |
|
|
|
|
|
|
|
|
func GetGroupConfig(site_id, dbname string, groupname string, url ...string) (map[string]string, error) { |
|
|
|
|
|
|
|
|
if dbname == "" { |
|
|
if dbname == "" { |
|
|
return nil, errors.New("参数错误") |
|
|
return nil, errors.New("参数错误") |
|
@ -99,6 +140,43 @@ func GetGroupConfig(site_id, dbname string, groupname string, url ...string) ([] |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return nil, err |
|
|
return nil, err |
|
|
} |
|
|
} |
|
|
return res_arr, nil |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var res_map map[string]string = make(map[string]string) |
|
|
|
|
|
|
|
|
|
|
|
if len(res_arr) > 0 { |
|
|
|
|
|
var value string |
|
|
|
|
|
for _, info := range res_arr { |
|
|
|
|
|
value = "" |
|
|
|
|
|
switch info["Type"] { |
|
|
|
|
|
|
|
|
|
|
|
case "select": |
|
|
|
|
|
|
|
|
|
|
|
var content interface{} |
|
|
|
|
|
err = json.Unmarshal([]byte(info["Content"]), &content) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
log.Println(err) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
content_type := reflect.TypeOf(content).String() //数据字典的类型
|
|
|
|
|
|
|
|
|
|
|
|
switch content_type { |
|
|
|
|
|
case "[]interface {}": //数组形式,value字段对应数组的key
|
|
|
|
|
|
list := content.([]interface{}) |
|
|
|
|
|
val_key := helper.ToInt(info["Value"]) |
|
|
|
|
|
value = helper.ToString(list[val_key]) |
|
|
|
|
|
case "map[string]interface {}": //map形式,value字段对应key
|
|
|
|
|
|
list := content.(map[string]interface{}) |
|
|
|
|
|
value = helper.ToString(list[info["Value"]]) |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
default: |
|
|
|
|
|
value = info["Value"] |
|
|
|
|
|
} |
|
|
|
|
|
res_map[info["Name"]] = value |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return res_map, nil |
|
|
|
|
|
|
|
|
} |
|
|
} |