admin
2022-07-22 9adb473067a993b4e0eacf3675baf14b29da3eca
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#pragma once
#include <string>
#include <list>
#include "json/json.h"
#include <THSActionUtil.h>
#include "LimitUpCapture.h"
#include "TradeSuccessCapture.h"
#include "IndustryCapture.h"
 
class JsonUtil {
 
public:
 
    static  Json::Value toJson(std::list<TradeData> dataList) {
        Json::Value root;
 
        std::list<TradeData>::iterator ele;
        int index = 0;
        for (ele = dataList.begin();ele != dataList.end();ele++) {
            Json::Value  item;
            item["time"] = (*ele).time;
            item["price"] = (*ele).price;
            item["num"] = (*ele).num;
            item["limitPrice"] = (*ele).limitPrice;
            item["operateType"] = (*ele).operateType;
            item["cancelTime"] = (*ele).cancelTime;
            item["cancelTimeUnit"] = (*ele).cancelTimeUnit;
            root[index++] = item;
        }
        return root;
    }
 
 
 
    static  Json::Value toJson(set<string> dataList) {
        Json::Value root;
 
        set<string>::iterator ele;
        int index = 0;
        for (ele = dataList.begin();ele != dataList.end();ele++) {
            root[index++] = *ele;
        }
        return root;
    }
 
    //json¶ÔÏóתΪ×Ö·û´®
    static  std::string toJsonStr(Json::Value json) {
        Json::StreamWriterBuilder writerBuilder;
        //²»×Ô¶¯»»ÐÐ
        writerBuilder.settings_["indentation"] = "";
        std::ostringstream os;
        std::unique_ptr<Json::StreamWriter> jsonWriter(writerBuilder.newStreamWriter());
        jsonWriter->write(json, &os);
        string jsonStr = os.str();
        return jsonStr;
    }
 
    static  std::string loadL2Data(int clientID, int channel, string code, std::list<TradeData> dataList) {
        Json::Value data;
        data["channel"] = channel;
        data["code"] = code;
        data["data"] = toJson(dataList);
        Json::Value root;
        root["type"] = 0;
        root["client"] = clientID;
        root["data"] = data;
        return toJsonStr(root);
    }
 
 
    static  std::string loadTradeQueueData(int clientID, int channel, string code, std::list<int> numList) {
        Json::Value data;
        data["channel"] = channel;
        data["code"] = code;
 
        Json::Value _data;
 
        std::list<int>::iterator ele;
        int index = 0;
        for (ele = numList.begin();ele != numList.end();ele++) {
            _data[index++] = *ele;
        }
        data["data"] = _data;
        Json::Value root;
        root["type"] = 10;
        root["client"] = clientID;
        root["data"] = data;
        return toJsonStr(root);
    }
 
    static  std::string loadLimitUpData(list<LimitUpData>  dataList) {
        Json::Value root;
        root["type"] = 2;
        
 
        Json::Value data;
 
        std::list<LimitUpData>::iterator ele;
        int index = 0;
        for (ele = dataList.begin();ele != dataList.end();ele++) {
            Json::Value  item;
            item["time"] = (*ele).time;
            item["price"] = (*ele).price;
            item["limitMoney"] = (*ele).limitMoney;
            item["limitMoneyUnit"] = (*ele).limitMoneyUnit;
            item["code"] = (*ele).code;
            data[index++] = item;
        }
 
        root["data"] = data;
 
 
        return toJsonStr(root);
    }
 
 
    static  std::string loadTradeSuccessData(list<TradeSuccessData>  dataList) {
        Json::Value root;
        root["type"] = 3;
 
 
        Json::Value data;
 
        std::list<TradeSuccessData>::iterator ele;
        int index = 0;
        for (ele = dataList.begin();ele != dataList.end();ele++) {
            Json::Value  item;
            item["date"] = (*ele).date;
            item["code"] = (*ele).code;
            item["time"] = (*ele).time;
            item["num"] = (*ele).num;
            item["money"] = (*ele).money;
            item["trade_num"] = (*ele).trade_num;
            item["type"] = (*ele).type;
            data[index++] = item;
        }
 
        root["data"] = data;
 
 
        return toJsonStr(root);
    }
 
    static  std::string loadIndustryData(list<list<IndustryData>>  dataList) {
        Json::Value root;
        root["type"] = 4;
 
 
        Json::Value data;
 
        std::list<list<IndustryData>>::iterator ele;
        int index = 0;
        for (ele = dataList.begin();ele != dataList.end();ele++) {
            Json::Value  item;
 
            int cindex = 0;
            for (list<IndustryData >::iterator e = (*ele).begin();e != (*ele).end();e++) {
                Json::Value item_c;
                item_c["code"] = (*e).code;
                item_c["zyltgb"] = (*e).zyltMoney;
                item_c["zyltgb_unit"] = (*e).zyltMoneyUnit;
                item[cindex++] = item_c;
            }
            data[index++] = item;
        }
 
        root["data"] = data;
 
 
        return toJsonStr(root);
    }
 
 
    static  std::string loadGPCodeData(std::list<string> codeList) {
        Json::Value root;
        root["type"] = 1;
        Json::Value data;
 
        std::list<string>::iterator ele;
        int index = 0;
        for (ele = codeList.begin();ele != codeList.end();ele++) {
            data[index++] = *ele;
        }
        root["data"] = data;
        return toJsonStr(root);
    }
 
    static  Json::Value parseJson(string data) {
        Json::Value root;
        Json::Reader reader;
        reader.parse(data, root);
        return root;
    }
 
 
 
 
};