派生自 development/c++

chenshijun
2019-03-15 684b55231257011c11caacc5ae72b0f0977c6114
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#ifndef VSSDOMAINUNITTBL_CONTROLLER_H
#define VSSDOMAINUNITTBL_CONTROLLER_H
 
#include <string>
#include <DataManagerServer/http_configserver.h>
#include "vss/dao/VssDomainUnitTblDao.h"
#include "vss/model/VssDomainUnitTblBuilder.h"
#include "vss/model/VssDomainUnitTbl.h"
#include "VssBaseController.h"
#include <mysql++.h>
 
using namespace std;
 
/**
 * 创建一级设备表
 */
class VssDomainUnitTblController : public VssBaseController {
private:
    /** 创建一级设备表构造函数 */
    VssDomainUnitTblController() {}
public:
    /** 创建一级设备表单例模式 */
    static VssDomainUnitTblController* instance() {
        static VssDomainUnitTblController instance;
        return &instance;
    }
public:
    /** 注册{label}http服务 */
    void registerHttpServices(HttpSrvRetRecieve& _HttpSrvRetRecieve) {
 
        _HttpSrvRetRecieve.setInfo("^/addVssDomainUnitTbl$", "POST",
                                   std::bind(&VssDomainUnitTblController::addVssDomainUnitTbl, this,
                                             std::placeholders::_1, std::placeholders::_2,
                                             std::placeholders::_3, std::placeholders::_4));
 
        _HttpSrvRetRecieve.setInfo("^/delVssDomainUnitTbl$", "POST",
                                   std::bind(&VssDomainUnitTblController::delVssDomainUnitTbl, this,
                                             std::placeholders::_1, std::placeholders::_2,
                                             std::placeholders::_3, std::placeholders::_4));
 
        _HttpSrvRetRecieve.setInfo("^/updateVssDomainUnitTbl$", "POST",
                                   std::bind(&VssDomainUnitTblController::updateVssDomainUnitTbl, this,
                                             std::placeholders::_1, std::placeholders::_2,
                                             std::placeholders::_3, std::placeholders::_4));
 
        _HttpSrvRetRecieve.setInfo("^/findVssDomainUnitTbl$", "POST",
                                   std::bind(&VssDomainUnitTblController::findVssDomainUnitTbl, this,
                                             std::placeholders::_1, std::placeholders::_2,
                                             std::placeholders::_3, std::placeholders::_4));
 
        _HttpSrvRetRecieve.setInfo("^/findVssDomainUnitTblList$", "POST",
                                   std::bind(&VssDomainUnitTblController::findVssDomainUnitTblList, this,
                                             std::placeholders::_1, std::placeholders::_2,
                                             std::placeholders::_3, std::placeholders::_4));
 
    }
public:
    /** 添加创建一级设备表 */
    std::string addVssDomainUnitTbl(std::string ip, unsigned int port, std::string content, PResponse &response) {
        Json::Reader requestJsonReader;
        Json::Value requestJsonValue;
        Json::Value responseJsonValue;
        responseJsonValue["message"] = "添加失败!";
        responseJsonValue["success"] = "false";
        if (requestJsonReader.parse(content, requestJsonValue)) {
            VssDomainUnitTblBuilder vssDomainUnitTblBuilder;
 
            Json::Value iDJsonValue = requestJsonValue[VssDomainUnitTbl_ID];
            if (iDJsonValue.type() != Json::ValueType::nullValue) {
                vssDomainUnitTblBuilder.addID(std::stoi((iDJsonValue.asString())));
            }
 
            Json::Value devPubIDJsonValue = requestJsonValue[VssDomainUnitTbl_DevPubID];
            if (devPubIDJsonValue.type() != Json::ValueType::nullValue) {
                vssDomainUnitTblBuilder.addDevPubID((devPubIDJsonValue.asString()));
            }
 
            Json::Value domainPubIDJsonValue = requestJsonValue[VssDomainUnitTbl_DomainPubID];
            if (domainPubIDJsonValue.type() != Json::ValueType::nullValue) {
                vssDomainUnitTblBuilder.addDomainPubID((domainPubIDJsonValue.asString()));
            }
 
            Json::Value nameJsonValue = requestJsonValue[VssDomainUnitTbl_Name];
            if (nameJsonValue.type() != Json::ValueType::nullValue) {
                vssDomainUnitTblBuilder.addName((nameJsonValue.asString()));
            }
 
            Json::Value businessGroupIDJsonValue = requestJsonValue[VssDomainUnitTbl_BusinessGroupID];
            if (businessGroupIDJsonValue.type() != Json::ValueType::nullValue) {
                vssDomainUnitTblBuilder.addBusinessGroupID((businessGroupIDJsonValue.asString()));
            }
 
            Json::Value parentIdJsonValue = requestJsonValue[VssDomainUnitTbl_ParentId];
            if (parentIdJsonValue.type() != Json::ValueType::nullValue) {
                vssDomainUnitTblBuilder.addParentId((parentIdJsonValue.asString()));
            }
 
            Json::Value domainTypeJsonValue = requestJsonValue[VssDomainUnitTbl_DomainType];
            if (domainTypeJsonValue.type() != Json::ValueType::nullValue) {
                vssDomainUnitTblBuilder.addDomainType(std::stoi((domainTypeJsonValue.asString())));
            }
 
            Json::Value updateTimeJsonValue = requestJsonValue[VssDomainUnitTbl_UpdateTime];
            if (updateTimeJsonValue.type() != Json::ValueType::nullValue) {
                vssDomainUnitTblBuilder.addUpdateTime((updateTimeJsonValue.asString()));
            }
            auto keyValuesToAdd = vssDomainUnitTblBuilder.buildVssDomainUnitTblMap();
            if (keyValuesToAdd.size() > 0) {
                mysqlpp::SimpleResult addVssDomainUnitTblResult = VssDomainUnitTblDao::instance()->addVssDomainUnitTbl(keyValuesToAdd);
                if (addVssDomainUnitTblResult.rows() > 0) {
                    responseJsonValue["success"] = "true";
                    responseJsonValue["message"] = "添加成功!";
                }
            }
        }
        return responseJsonValue.toStyledString();
    }
 
    /** 删除创建一级设备表 */
    std::string delVssDomainUnitTbl(std::string ip, unsigned int port, std::string content, PResponse &response) {
        Json::Reader requestJsonReader;
        Json::Value requestJsonValue;
        Json::Value responseJsonValue;
        responseJsonValue["message"] = "删除失败!";
        responseJsonValue["success"] = "false";
        if (requestJsonReader.parse(content, requestJsonValue)) {
            Json::Value iDJsonValue = requestJsonValue[VssDomainUnitTbl_ID];
            if (iDJsonValue.type() != Json::ValueType::nullValue) {
                string iDValue = iDJsonValue.asString();
                if (iDValue.size() > 0 && VssDomainUnitTblDao::instance()->deleteByColumn("ID", iDValue)) {
                    responseJsonValue["success"] = "true";
                    responseJsonValue["message"] = "删除成功!";
                }
            }
 
        }
        return responseJsonValue.toStyledString();
    }
 
    /** 更新创建一级设备表 */
    std::string updateVssDomainUnitTbl(std::string ip, unsigned int port, std::string content, PResponse &response) {
        Json::Reader requestJsonReader;
        Json::Value requestJsonValue;
        Json::Value responseJsonValue;
        responseJsonValue["message"] = "更新失败!";
        responseJsonValue["success"] = "false";
        if (requestJsonReader.parse(content, requestJsonValue)) {
            VssDomainUnitTblBuilder vssDomainUnitTblBuilder;
 
            Json::Value iDJsonValue = requestJsonValue[VssDomainUnitTbl_ID];
            if (iDJsonValue.type() != Json::ValueType::nullValue) {
                vssDomainUnitTblBuilder.addID(std::stoi((iDJsonValue.asString())));
            }
 
            Json::Value devPubIDJsonValue = requestJsonValue[VssDomainUnitTbl_DevPubID];
            if (devPubIDJsonValue.type() != Json::ValueType::nullValue) {
                vssDomainUnitTblBuilder.addDevPubID((devPubIDJsonValue.asString()));
            }
 
            Json::Value domainPubIDJsonValue = requestJsonValue[VssDomainUnitTbl_DomainPubID];
            if (domainPubIDJsonValue.type() != Json::ValueType::nullValue) {
                vssDomainUnitTblBuilder.addDomainPubID((domainPubIDJsonValue.asString()));
            }
 
            Json::Value nameJsonValue = requestJsonValue[VssDomainUnitTbl_Name];
            if (nameJsonValue.type() != Json::ValueType::nullValue) {
                vssDomainUnitTblBuilder.addName((nameJsonValue.asString()));
            }
 
            Json::Value businessGroupIDJsonValue = requestJsonValue[VssDomainUnitTbl_BusinessGroupID];
            if (businessGroupIDJsonValue.type() != Json::ValueType::nullValue) {
                vssDomainUnitTblBuilder.addBusinessGroupID((businessGroupIDJsonValue.asString()));
            }
 
            Json::Value parentIdJsonValue = requestJsonValue[VssDomainUnitTbl_ParentId];
            if (parentIdJsonValue.type() != Json::ValueType::nullValue) {
                vssDomainUnitTblBuilder.addParentId((parentIdJsonValue.asString()));
            }
 
            Json::Value domainTypeJsonValue = requestJsonValue[VssDomainUnitTbl_DomainType];
            if (domainTypeJsonValue.type() != Json::ValueType::nullValue) {
                vssDomainUnitTblBuilder.addDomainType(std::stoi((domainTypeJsonValue.asString())));
            }
 
            Json::Value updateTimeJsonValue = requestJsonValue[VssDomainUnitTbl_UpdateTime];
            if (updateTimeJsonValue.type() != Json::ValueType::nullValue) {
                vssDomainUnitTblBuilder.addUpdateTime((updateTimeJsonValue.asString()));
            }
            if (iDJsonValue.type() != Json::ValueType::nullValue) {
                string iDValue = iDJsonValue.asString();
                if (iDValue.size() > 0 && VssDomainUnitTblDao::instance()->updateVssDomainUnitTbl(vssDomainUnitTblBuilder.buildVssDomainUnitTblMap(), "ID", iDValue)) {
                    responseJsonValue["success"] = "true";
                    responseJsonValue["message"] = "更新成功!";
                }
            }
        }
        return responseJsonValue.toStyledString();
    }
 
    /** 查找单个创建一级设备表 */
    std::string findVssDomainUnitTbl(std::string ip, unsigned int port, std::string content, PResponse &response) {
        Json::Reader requestJsonReader;
        Json::Value requestJsonValue;
        Json::Value responseJsonValue;
        responseJsonValue["message"] = "查询失败!";
        responseJsonValue["success"] = "false";
        if (requestJsonReader.parse(content, requestJsonValue)) {
            VssDomainUnitTblBuilder vssDomainUnitTblBuilder;
 
            Json::Value iDJsonValue = requestJsonValue[VssDomainUnitTbl_ID];
            if (iDJsonValue.type() != Json::ValueType::nullValue) {
                vssDomainUnitTblBuilder.addID(std::stoi((iDJsonValue.asString())));
            }
 
            Json::Value devPubIDJsonValue = requestJsonValue[VssDomainUnitTbl_DevPubID];
            if (devPubIDJsonValue.type() != Json::ValueType::nullValue) {
                vssDomainUnitTblBuilder.addDevPubID((devPubIDJsonValue.asString()));
            }
 
            Json::Value domainPubIDJsonValue = requestJsonValue[VssDomainUnitTbl_DomainPubID];
            if (domainPubIDJsonValue.type() != Json::ValueType::nullValue) {
                vssDomainUnitTblBuilder.addDomainPubID((domainPubIDJsonValue.asString()));
            }
 
            Json::Value nameJsonValue = requestJsonValue[VssDomainUnitTbl_Name];
            if (nameJsonValue.type() != Json::ValueType::nullValue) {
                vssDomainUnitTblBuilder.addName((nameJsonValue.asString()));
            }
 
            Json::Value businessGroupIDJsonValue = requestJsonValue[VssDomainUnitTbl_BusinessGroupID];
            if (businessGroupIDJsonValue.type() != Json::ValueType::nullValue) {
                vssDomainUnitTblBuilder.addBusinessGroupID((businessGroupIDJsonValue.asString()));
            }
 
            Json::Value parentIdJsonValue = requestJsonValue[VssDomainUnitTbl_ParentId];
            if (parentIdJsonValue.type() != Json::ValueType::nullValue) {
                vssDomainUnitTblBuilder.addParentId((parentIdJsonValue.asString()));
            }
 
            Json::Value domainTypeJsonValue = requestJsonValue[VssDomainUnitTbl_DomainType];
            if (domainTypeJsonValue.type() != Json::ValueType::nullValue) {
                vssDomainUnitTblBuilder.addDomainType(std::stoi((domainTypeJsonValue.asString())));
            }
 
            Json::Value updateTimeJsonValue = requestJsonValue[VssDomainUnitTbl_UpdateTime];
            if (updateTimeJsonValue.type() != Json::ValueType::nullValue) {
                vssDomainUnitTblBuilder.addUpdateTime((updateTimeJsonValue.asString()));
            }
            responseJsonValue["message"] = "查询成功!";
            responseJsonValue["success"] = "true";
            responseJsonValue["data"] = VssDomainUnitTblDao::instance()->findJsonArray(string("select * from ") + VSSDomainUnitTbl_TABLE_NAME + " where 1 = 1 limit 1", vssDomainUnitTblBuilder.buildVssDomainUnitTblMap());
        }
        return responseJsonValue.toStyledString();
    }
 
    /** 查找创建一级设备表列表 */
    std::string findVssDomainUnitTblList(std::string ip, unsigned int port, std::string content, PResponse &response) {
        Json::Reader requestJsonReader;
        Json::Value requestJsonValue;
        Json::Value responseJsonValue;
        responseJsonValue["message"] = "查询失败!";
        responseJsonValue["success"] = "false";
        if (content == "" || requestJsonReader.parse(content, requestJsonValue)) {
            VssDomainUnitTblBuilder vssDomainUnitTblBuilder;
 
            Json::Value iDJsonValue = requestJsonValue[VssDomainUnitTbl_ID];
            if (iDJsonValue.type() != Json::ValueType::nullValue) {
                vssDomainUnitTblBuilder.addID(std::stoi((iDJsonValue.asString())));
            }
 
            Json::Value devPubIDJsonValue = requestJsonValue[VssDomainUnitTbl_DevPubID];
            if (devPubIDJsonValue.type() != Json::ValueType::nullValue) {
                vssDomainUnitTblBuilder.addDevPubID((devPubIDJsonValue.asString()));
            }
 
            Json::Value domainPubIDJsonValue = requestJsonValue[VssDomainUnitTbl_DomainPubID];
            if (domainPubIDJsonValue.type() != Json::ValueType::nullValue) {
                vssDomainUnitTblBuilder.addDomainPubID((domainPubIDJsonValue.asString()));
            }
 
            Json::Value nameJsonValue = requestJsonValue[VssDomainUnitTbl_Name];
            if (nameJsonValue.type() != Json::ValueType::nullValue) {
                vssDomainUnitTblBuilder.addName((nameJsonValue.asString()));
            }
 
            Json::Value businessGroupIDJsonValue = requestJsonValue[VssDomainUnitTbl_BusinessGroupID];
            if (businessGroupIDJsonValue.type() != Json::ValueType::nullValue) {
                vssDomainUnitTblBuilder.addBusinessGroupID((businessGroupIDJsonValue.asString()));
            }
 
            Json::Value parentIdJsonValue = requestJsonValue[VssDomainUnitTbl_ParentId];
            if (parentIdJsonValue.type() != Json::ValueType::nullValue) {
                vssDomainUnitTblBuilder.addParentId((parentIdJsonValue.asString()));
            }
 
            Json::Value domainTypeJsonValue = requestJsonValue[VssDomainUnitTbl_DomainType];
            if (domainTypeJsonValue.type() != Json::ValueType::nullValue) {
                vssDomainUnitTblBuilder.addDomainType(std::stoi((domainTypeJsonValue.asString())));
            }
 
            Json::Value updateTimeJsonValue = requestJsonValue[VssDomainUnitTbl_UpdateTime];
            if (updateTimeJsonValue.type() != Json::ValueType::nullValue) {
                vssDomainUnitTblBuilder.addUpdateTime((updateTimeJsonValue.asString()));
            }
            responseJsonValue["message"] = "查询成功!";
            responseJsonValue["success"] = "true";
            responseJsonValue["data"] = VssDomainUnitTblDao::instance()->findJsonArray(string("select * from ") + VSSDomainUnitTbl_TABLE_NAME + " where 1 = 1", vssDomainUnitTblBuilder.buildVssDomainUnitTblMap());
 
        }
        return responseJsonValue.toStyledString();
    }
};
 
 
 
 
 
 
#endif //VSSDOMAINUNITTBL_CONTROLLER_H