liuxiaolong
2021-03-05 11a04ff41abe8e84925249c7118e7b47150fb0ff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package bhomedbapi
 
import (
    "basic.com/pubsub/protomsg.git"
    "encoding/json"
)
 
type DicApi struct {
 
}
 
func (api DicApi) FindByType(dicType string) (bool,interface{}) {
    url := DATA_URL_PREFIX + "/dictionary/findByType"
    netNode := getNetNode(url2Topic(Topic_System_Service, url))
    if netNode == nil {
        return false,nil
    }
    client := NewClient(WithNodes(netNode))
    paramMap := make(map[string]string)
    paramMap["type"] = dicType
    respBody, err := client.DoGetRequest(url, paramMap, nil)
    if err !=nil {
        return false,nil
    }
    var res Result
    if err = json.Unmarshal(respBody, &res); err != nil {
        logPrint(err)
        return false,nil
    }
    return res.Success,res.Data
}
 
func (api DicApi) FindByParentId(parentId string) (bool,interface{}){
    url := DATA_URL_PREFIX + "/dictionary/findByParentId"
    netNode := getNetNode(url2Topic(Topic_System_Service, url))
    if netNode == nil {
        return false,nil
    }
    client := NewClient(WithNodes(netNode))
    paramMap := make(map[string]string)
    paramMap["parentId"] = parentId
    respBody, err := client.DoGetRequest(url, paramMap, nil)
    if err !=nil {
        return false,nil
    }
    var res Result
    if err = json.Unmarshal(respBody, &res); err != nil {
        logPrint(err)
        return false,nil
    }
    return res.Success,res.Data
}
 
func (api DicApi) ListByType(typ string) (flag bool,list []protomsg.Dic){
    url := DATA_URL_PREFIX + "/dictionary/listByType"
    netNode := getNetNode(url2Topic(Topic_System_Service, url))
    if netNode == nil {
        return false,nil
    }
    client := NewClient(WithNodes(netNode))
    paramMap := make(map[string]string)
    paramMap["type"] = typ
    respBody, err := client.DoGetRequest(url, paramMap, nil)
    if err !=nil {
        return false,nil
    }
    var res Result
    if err = json.Unmarshal(respBody, &res); err != nil {
        logPrint(err)
        return false,nil
    }
    if res.Success {
        dataBytes, _ := json.Marshal(res.Data)
        if err = json.Unmarshal(dataBytes, &list);err !=nil {
            return false,nil
        }
        return true, list
    }
    return false, nil
}