-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcessor.cpp
More file actions
685 lines (624 loc) · 22.4 KB
/
Processor.cpp
File metadata and controls
685 lines (624 loc) · 22.4 KB
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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
#include "Processor.h"
#include "globe.h"
#include "LogComm.h"
#include "DataProxyProto.h"
#include "ServiceDefine.h"
#include "util/tc_hash_fun.h"
#include "uuid.h"
#include "SocialServer.h"
#include "util/tc_base64.h"
//
using namespace std;
using namespace dataproxy;
using namespace dbagent;
//过期时间
#define GIFT_EXPIRED_TIME (24*60*60)
/**
*
*/
Processor::Processor()
{
}
/**
*
*/
Processor::~Processor()
{
}
// CHAT_EXT_INFO = 49, //扩展的聊天数据
//查询
int Processor::selectChatExtInfo(const string &number, TicketInfo &info)
{
TReadDataReq dataReq;
dataReq.resetDefautlt();
dataReq.keyName = I2S(E_REDIS_TYPE_STRING) + ":" + I2S(CHAT_EXT_INFO) + ":" + number;
dataReq.operateType = E_REDIS_READ;
dataReq.clusterInfo.resetDefautlt();
dataReq.clusterInfo.busiType = E_REDIS_PROPERTY;
dataReq.clusterInfo.frageFactorType = E_FRAGE_FACTOR_STRING;
dataReq.clusterInfo.frageFactor = tars::hash<string>()(number);
vector<dbagent::TField> fields;
dbagent::TField tfield;
tfield.colArithType = E_NONE;
tfield.colName = "content";
fields.push_back(tfield);
dataReq.fields = fields;
dataproxy::TReadDataRsp dataRsp;
int iRet = g_app.getOuterFactoryPtr()->getDBAgentServantPrx(number)->redisRead(dataReq, dataRsp);
if (iRet != 0)
{
return -1;
}
ROLLLOG_DEBUG << "read cache, req: " << printTars(dataReq) << ", rsp: " << printTars(dataRsp) << endl;
for (auto it = dataRsp.fields.begin(); it != dataRsp.fields.end(); ++it)
{
for (auto itfield = it->begin(); itfield != it->end(); ++itfield)
{
//门票名称
if (itfield->colName == "content")
{
__TRY__
toObj(TC_Base64::decode(itfield->colValue), info);
__CATCH__
}
}
}
return 0;
}
//添加
int Processor::addChatExtInfo(const string &number, const TicketInfo &info)
{
dataproxy::TWriteDataReq dataReq;
dataReq.resetDefautlt();
dataReq.keyName = I2S(E_REDIS_TYPE_STRING) + ":" + I2S(CHAT_EXT_INFO) + ":" + number;
dataReq.operateType = E_REDIS_INSERT;
dataReq.clusterInfo.resetDefautlt();
dataReq.clusterInfo.busiType = E_REDIS_PROPERTY;
dataReq.clusterInfo.frageFactorType = E_FRAGE_FACTOR_STRING;
dataReq.clusterInfo.frageFactor = tars::hash<string>()(number);
// dataReq.paraExt.resetDefautlt();
// dataReq.paraExt.queryType = E_REPLACE;
vector<dbagent::TField> fields;
dbagent::TField tfield;
tfield.colArithType = E_NONE;
tfield.colName = "transaction_id";
tfield.colType = dbagent::STRING;
tfield.colValue = number;
fields.push_back(tfield);
tfield.colName = "content";
tfield.colType = dbagent::STRING;
tfield.colValue = TC_Base64::encode(tostring(info));
fields.push_back(tfield);
dataReq.fields = fields;
dataproxy::TWriteDataRsp dataRsp;
int iRet = g_app.getOuterFactoryPtr()->getDBAgentServantPrx(number)->redisWrite(dataReq, dataRsp);
ROLLLOG_DEBUG << "addChatExtInfo, iRet: " << iRet << ", dataRsp: " << printTars(dataRsp) << endl;
if (iRet != 0 || dataRsp.iResult != 0)
{
ROLLLOG_ERROR << "addChatExtInfo err, iRet: " << iRet << ", iResult: " << dataRsp.iResult << endl;
return -2;
}
return 0;
}
//更新
int Processor::updateChatExtInfo(const string &number, const TicketInfo &info)
{
dataproxy::TWriteDataReq dataReq;
dataReq.resetDefautlt();
dataReq.keyName = I2S(E_REDIS_TYPE_STRING) + ":" + I2S(CHAT_EXT_INFO) + ":" + number;
dataReq.operateType = E_REDIS_WRITE;
dataReq.clusterInfo.resetDefautlt();
dataReq.clusterInfo.busiType = E_REDIS_PROPERTY;
dataReq.clusterInfo.frageFactorType = E_FRAGE_FACTOR_STRING;
dataReq.clusterInfo.frageFactor = tars::hash<string>()(number);
vector<dbagent::TField> fields;
dbagent::TField tfield;
tfield.colArithType = E_NONE;
tfield.colName = "transaction_id";
tfield.colType = dbagent::STRING;
tfield.colValue = number;
fields.push_back(tfield);
tfield.colName = "content";
tfield.colType = dbagent::STRING;
tfield.colValue = TC_Base64::encode(tostring(info));
fields.push_back(tfield);
dataReq.fields = fields;
dataproxy::TWriteDataRsp dataRsp;
int iRet = g_app.getOuterFactoryPtr()->getDBAgentServantPrx(number)->redisWrite(dataReq, dataRsp);
ROLLLOG_DEBUG << "updateChatExtInfo, iRet: " << iRet << ", dataRsp: " << printTars(dataRsp) << endl;
if (iRet != 0 || dataRsp.iResult != 0)
{
ROLLLOG_ERROR << "updateChatExtInfo err, iRet: " << iRet << ", iResult: " << dataRsp.iResult << endl;
return -2;
}
return 0;
}
int Processor::getGiveChipsTime(tars::Int64 uid, tars::Int64 friend_uid, int &give_time)
{
FUNC_ENTRY("");
int iRet = 0;
__TRY__
if ((uid <= 0) || (friend_uid <= 0))
{
ROLLLOG_ERROR << "uid: " << uid << " or friend_uid: " << friend_uid << " error!" << endl;
return -1;
}
dataproxy::TReadDataReq dataReq;
dataReq.resetDefautlt();
dataReq.keyName = I2S(E_REDIS_TYPE_LIST) + ":" + I2S(FRIEND_INFO) + ":" + L2S(uid);
dataReq.operateType = E_REDIS_READ;
dataReq.clusterInfo.resetDefautlt();
dataReq.clusterInfo.busiType = E_REDIS_PROPERTY;
dataReq.clusterInfo.frageFactorType = E_FRAGE_FACTOR_USER_ID;
dataReq.clusterInfo.frageFactor = uid;
dataReq.paraExt.resetDefautlt();
dataReq.paraExt.subOperateType = E_REDIS_LIST_RANGE;
dataReq.paraExt.start = 0;//起始下标从0开始
dataReq.paraExt.end = -1;//终止最大结束下标为-1
vector<TField> fields;
TField tfield;
tfield.colArithType = E_NONE;
tfield.colName = "friend_uid";
fields.push_back(tfield);
tfield.colName = "give_time";
fields.push_back(tfield);
dataReq.fields = fields;
dataproxy::TReadDataRsp dataRsp;
iRet = g_app.getOuterFactoryPtr()->getDBAgentServantPrx(uid)->redisRead(dataReq, dataRsp);
if (iRet != 0 || dataRsp.iResult != 0)
{
ROLLLOG_ERROR << "get friends give info err, iRet: " << iRet << ", iResult: " << dataRsp.iResult << endl;
return -1;
}
give_time = 0;
for (auto it = dataRsp.fields.begin(); it != dataRsp.fields.end(); ++it)
{
long lFriendUid = 0;
int iGiveTime = 0;
for (auto itTField = it->begin(); itTField != it->end(); ++itTField)
{
if (itTField->colName == "friend_uid")
{
lFriendUid = S2L(itTField->colValue);
}
else if (itTField->colName == "give_time")
{
iGiveTime = g_app.getOuterFactoryPtr()->GetCustomTimeTick(itTField->colValue);
}
}
ROLLLOG_DEBUG << "get friends give info, friend_uid: " << lFriendUid << ", iGiveTime: " << iGiveTime << endl;
if ((lFriendUid > 0) && (iGiveTime > 0) && (lFriendUid == friend_uid))
{
give_time = iGiveTime;
break;
}
}
ROLLLOG_DEBUG << "====================== uid: " << uid << ", friend_uid: " << friend_uid << ", give_time: " << give_time << endl;
__CATCH__
FUNC_EXIT("", iRet);
return iRet;
}
//USER_ACCOUNT = 20, //#tbl_user_account
int Processor::selectUserAccount(const userinfo::GetUserReq &req, userinfo::GetUserResp &resp)
{
if (req.uid <= 0)
{
ROLLLOG_ERROR << "invalid params, uid: " << req.uid << endl;
resp.resultCode = -1;
return -1;
}
TReadDataReq dataReq;
dataReq.resetDefautlt();
dataReq.keyName = I2S(E_REDIS_TYPE_HASH) + ":" + I2S(USER_ACCOUNT) + ":" + L2S(req.uid);
dataReq.operateType = E_REDIS_READ;
dataReq.clusterInfo.resetDefautlt();
dataReq.clusterInfo.busiType = E_REDIS_PROPERTY;
dataReq.clusterInfo.frageFactorType = E_FRAGE_FACTOR_STRING;
dataReq.clusterInfo.frageFactor = tars::hash<string>()(L2S(req.uid));
vector<TField> fields;
TField tfield;
tfield.colArithType = E_NONE;
tfield.colName = "uid";
fields.push_back(tfield);
tfield.colName = "username";
fields.push_back(tfield);
tfield.colName = "password";
fields.push_back(tfield);
tfield.colName = "safes_password";
fields.push_back(tfield);
tfield.colName = "reg_type";
fields.push_back(tfield);
tfield.colName = "reg_time";
fields.push_back(tfield);
tfield.colName = "reg_ip";
fields.push_back(tfield);
tfield.colName = "reg_device_no";
fields.push_back(tfield);
tfield.colName = "is_robot";
fields.push_back(tfield);
tfield.colName = "agcid";
fields.push_back(tfield);
tfield.colName = "disabled";
fields.push_back(tfield);
tfield.colName = "device_id";
fields.push_back(tfield);
tfield.colName = "device_type";
fields.push_back(tfield);
tfield.colName = "platform";
fields.push_back(tfield);
tfield.colName = "channel_id";
fields.push_back(tfield);
tfield.colName = "area_id";
fields.push_back(tfield);
tfield.colName = "is_forbidden";
fields.push_back(tfield);
tfield.colName = "forbidden_time";
fields.push_back(tfield);
tfield.colName = "bindChannelId";
fields.push_back(tfield);
tfield.colName = "bindOpenId";
fields.push_back(tfield);
tfield.colName = "isinwhitelist";
fields.push_back(tfield);
tfield.colName = "whitelisttime";
fields.push_back(tfield);
tfield.colName = "country_id";
fields.push_back(tfield);
dataReq.fields = fields;
dataproxy::TReadDataRsp dataRsp;
int iRet = g_app.getOuterFactoryPtr()->getDBAgentServantPrx(req.uid)->redisRead(dataReq, dataRsp);
if ((iRet != 0) || (dataRsp.iResult != 0))
{
ROLLLOG_ERROR << "get user-account failed, uid: " << req.uid << ", iResult: " << dataRsp.iResult << endl;
resp.resultCode = -1;
return -2;
}
if (dataRsp.fields.empty())
{
ROLLLOG_ERROR << "uid:" << req.uid << " not exist in tb_useraccount!" << endl;
resp.resultCode = -1;
return -3;
}
for (auto it = dataRsp.fields.begin(); it != dataRsp.fields.end(); ++it)
{
for (auto itfields = it->begin(); itfields != it->end(); ++itfields)
{
if (itfields->colName == "username")
{
resp.userName = itfields->colValue;
}
else if (itfields->colName == "device_id")
{
resp.deviceID = itfields->colValue;
}
else if (itfields->colName == "device_type")
{
resp.deviceType = itfields->colValue;
}
else if (itfields->colName == "platform")
{
resp.platform = (userinfo::E_Platform_Type)S2I(itfields->colValue);
}
else if (itfields->colName == "channel_id")
{
resp.channnelID = (userinfo::E_Channel_ID)S2I(itfields->colValue);
}
else if (itfields->colName == "area_id")
{
resp.areaID = S2I(itfields->colValue);
}
else if (itfields->colName == "is_robot")
{
resp.isRobot = S2I(itfields->colValue);
}
else if (itfields->colName == "reg_time")
{
resp.regTime = g_app.getOuterFactoryPtr()->GetCustomTimeTick(itfields->colValue);
}
else if (itfields->colName == "bindChannelId")
{
resp.bindChannelId = S2I(itfields->colValue);
}
else if (itfields->colName == "bindOpenId")
{
resp.bindOpenId = itfields->colValue;
}
else if (itfields->colName == "reg_type")
{
resp.regType = S2I(itfields->colValue);
}
else if (itfields->colName == "isinwhitelist")
{
resp.isinwhitelist = S2I(itfields->colValue);
}
else if (itfields->colName == "whitelisttime")
{
resp.whitelisttime = g_app.getOuterFactoryPtr()->GetCustomTimeTick(itfields->colValue);
}
else if(itfields->colName == "country_id")
{
resp.country_id = itfields->colValue;
}
}
}
ROLLLOG_DEBUG << "get user succ, userinfo::GetUserReq:" << printTars(req) << ", userinfo::GetUserResp:" << printTars(resp) << endl;
resp.resultCode = 0;
return 0;
}
//更改玩家备注
int Processor::ReplaceRemark(const long lUid, tars::Int64 remark_uid, std::string content, int state)
{
FUNC_ENTRY("");
int iRet = 0;
__TRY__
dataproxy::TWriteDataReq dataReq;
dataReq.resetDefautlt();
dataReq.keyName = I2S(E_REDIS_TYPE_LIST) + ":" + I2S(USER_REMARK) + ":" + L2S(lUid);
dataReq.operateType = E_REDIS_WRITE;
dataReq.clusterInfo.resetDefautlt();
dataReq.clusterInfo.busiType = E_REDIS_PROPERTY;
dataReq.clusterInfo.frageFactorType = E_FRAGE_FACTOR_USER_ID;
dataReq.clusterInfo.frageFactor = lUid;
dataReq.paraExt.resetDefautlt();
dataReq.paraExt.queryType = E_REPLACE;
vector<TField> fields;
TField tfield;
tfield.colArithType = E_NONE;
tfield.colName = "uid";
tfield.colType = BIGINT;
tfield.colValue = L2S(lUid);
fields.push_back(tfield);
tfield.colName = "remark_uid";
tfield.colType = BIGINT;
tfield.colValue = L2S(remark_uid);
fields.push_back(tfield);
tfield.colName = "state";
tfield.colType = INT;
tfield.colValue = I2S(state);
fields.push_back(tfield);
tfield.colName = "content";
tfield.colType = STRING;
tfield.colValue = content;
fields.push_back(tfield);
tfield.colName = "log_time";
tfield.colType = BIGINT;
tfield.colValue = L2S(TNOW);
fields.push_back(tfield);
dataReq.fields = fields;
dataproxy::TWriteDataRsp dataRsp;
iRet = g_app.getOuterFactoryPtr()->getDBAgentServantPrx(lUid)->redisWrite(dataReq, dataRsp);
if (iRet != 0 || dataRsp.iResult != 0)
{
ROLLLOG_ERROR << "insert remark err, iRet: " << iRet << ", iResult: " << dataRsp.iResult << endl;
return -2;
}
ROLLLOG_DEBUG << "insert remark, iRet: " << iRet << ", dataRsp: " << printTars(dataRsp) << endl;
__CATCH__
FUNC_EXIT("", iRet);
return iRet;
}
string Processor::getUserRemark(const long lUid, const long remark_uid)
{
FUNC_ENTRY("");
int iRet = 0;
__TRY__
dataproxy::TReadDataReq dataReq;
dataReq.resetDefautlt();
dataReq.keyName = I2S(E_REDIS_TYPE_LIST) + ":" + I2S(USER_REMARK) + ":" + L2S(lUid);
dataReq.operateType = E_REDIS_READ;
dataReq.clusterInfo.resetDefautlt();
dataReq.clusterInfo.busiType = E_REDIS_PROPERTY;
dataReq.clusterInfo.frageFactorType = E_FRAGE_FACTOR_USER_ID;
dataReq.clusterInfo.frageFactor = lUid;
dataReq.paraExt.resetDefautlt();
dataReq.paraExt.subOperateType = E_REDIS_LIST_RANGE;//根据范围取数据
dataReq.paraExt.start = 0;//起始下标从0开始
dataReq.paraExt.end = -1;//终止最大结束下标为-1
vector<TField> fields;
TField tfield;
tfield.colArithType = E_NONE;
tfield.colName = "remark_uid";
fields.push_back(tfield);
tfield.colName = "state";
fields.push_back(tfield);
tfield.colName = "content";
fields.push_back(tfield);
dataReq.fields = fields;
dataproxy::TReadDataRsp dataRsp;
iRet = g_app.getOuterFactoryPtr()->getDBAgentServantPrx(lUid)->redisRead(dataReq, dataRsp);
if (iRet != 0 || dataRsp.iResult != 0)
{
ROLLLOG_ERROR << "get user remark err, iRet: " << iRet << ", iResult: " << dataRsp.iResult << endl;
return "";
}
for (auto it = dataRsp.fields.begin(); it != dataRsp.fields.end(); ++it)
{
map<string, string> mapRow;
for (auto itTField = it->begin(); itTField != it->end(); ++itTField)
{
mapRow.insert(std::make_pair(itTField->colName, itTField->colValue));
}
if(remark_uid == S2L(mapRow["remark_uid"]))
{
return mapRow["content"];
}
}
__CATCH__
FUNC_EXIT("", iRet);
return "";
}
int Processor::addRemark(const long lUid, const FriendsProto::AddRemarkReq &req)
{
return ReplaceRemark(lUid, req.remark_uid(), req.content(), 1);
}
int Processor::deleteRemark(const long lUid, const FriendsProto::DeleteRemarkReq &req)
{
return ReplaceRemark(lUid, req.remark_uid(), "", 0);
}
string Processor::getRemarkContent(const long lUid, const long lRemarkID)
{
FUNC_ENTRY("");
__TRY__
string table_name = "tb_remark";
std::vector<string> col_name = { "remark_uid", "content"};
std::vector<vector<string>> whlist = {
{"uid", "0", L2S(lUid)},
{"remark_uid", "0", L2S(lRemarkID)},
{"state", "0", "1"}
};
dbagent::TDBReadRsp dataRsp;
int iRet = readDataFromDBEx(lUid, table_name, col_name, whlist, "log_time", dataRsp);
if(iRet != 0)
{
LOG_ERROR<<"select tb_remark err!"<< endl;
return "";
}
for (auto it = dataRsp.records.begin(); it != dataRsp.records.end(); ++it)
{
map<string, string> mapRow;
for (auto itfield = it->begin(); itfield != it->end(); ++itfield)
{
mapRow.insert(std::make_pair(itfield->colName, itfield->colValue));
}
return mapRow["content"];
}
__CATCH__
FUNC_EXIT("", 0);
return "";
}
int Processor::readDataFromDBEx(long uid, const string& table_name, const std::vector<string>& col_name, const std::vector<vector<string>>& whlist, const string& order_col, dbagent::TDBReadRsp &dataRsp)
{
int iRet = 0;
dbagent::TDBReadReq rDataReq;
rDataReq.keyIndex = 0;
rDataReq.queryType = dbagent::E_SELECT;
rDataReq.tableName = table_name;
vector<dbagent::TField> fields;
dbagent::TField tfield;
tfield.colArithType = E_NONE;
for(auto item : col_name)
{
tfield.colName = item;
fields.push_back(tfield);
}
rDataReq.fields = fields;
//where条件组
if(!whlist.empty())
{
vector<dbagent::ConditionGroup> conditionGroups;
dbagent::ConditionGroup conditionGroup;
conditionGroup.relation = dbagent::AND;
vector<dbagent::Condition> conditions;
for(auto item : whlist)
{
if(item.size() != 3)
{
continue;
}
dbagent::Condition condition;
condition.condtion = dbagent::Eum_Condition(S2I(item[1]));
condition.colType = dbagent::STRING;
condition.colName = item[0];
condition.colValues = item[2];
conditions.push_back(condition);
}
conditionGroup.condition = conditions;
conditionGroups.push_back(conditionGroup);
rDataReq.conditions = conditionGroups;
}
//order by字段
if(!order_col.empty())
{
vector<dbagent::OrderBy> orderBys;
dbagent::OrderBy orderBy;
orderBy.sort = dbagent::DESC;
orderBy.colName = order_col;
orderBys.push_back(orderBy);
rDataReq.orderbyCol = orderBys;
}
iRet = g_app.getOuterFactoryPtr()->getDBAgentServantPrx(uid)->read(rDataReq, dataRsp);
if (iRet != 0 || dataRsp.iResult != 0)
{
ROLLLOG_ERROR << "read data from dbagent failed, rDataReq:" << printTars(rDataReq) << ",dataRsp: " << printTars(dataRsp) << endl;
return -1;
}
return 0;
}
int Processor::forbitChat(const long lUid, const FriendsProto::ForbitChatReq &req)
{
FUNC_ENTRY("");
int iRet = 0;
__TRY__
dataproxy::TWriteDataReq dataReq;
dataReq.resetDefautlt();
dataReq.keyName = I2S(E_REDIS_TYPE_LIST) + ":" + I2S(USER_FORBIT_CHAT) + ":" + L2S(lUid);
dataReq.operateType = E_REDIS_WRITE;
dataReq.clusterInfo.resetDefautlt();
dataReq.clusterInfo.busiType = E_REDIS_PROPERTY;
dataReq.clusterInfo.frageFactorType = E_FRAGE_FACTOR_USER_ID;
dataReq.clusterInfo.frageFactor = lUid;
dataReq.paraExt.resetDefautlt();
dataReq.paraExt.queryType = E_REPLACE;
vector<TField> fields;
TField tfield;
tfield.colArithType = E_NONE;
tfield.colName = "uid";
tfield.colType = BIGINT;
tfield.colValue = L2S(lUid);
fields.push_back(tfield);
tfield.colName = "forbit_uid";
tfield.colType = BIGINT;
tfield.colValue = L2S(req.forbit_uid());
fields.push_back(tfield);
tfield.colName = "is_forbit";
tfield.colType = INT;
tfield.colValue = I2S(req.is_forbit());
fields.push_back(tfield);
tfield.colName = "log_time";
tfield.colType = BIGINT;
tfield.colValue = L2S(TNOW);
fields.push_back(tfield);
dataReq.fields = fields;
dataproxy::TWriteDataRsp dataRsp;
iRet = g_app.getOuterFactoryPtr()->getDBAgentServantPrx(lUid)->redisWrite(dataReq, dataRsp);
if (iRet != 0 || dataRsp.iResult != 0)
{
ROLLLOG_ERROR << "insert forbit_uid err, iRet: " << iRet << ", iResult: " << dataRsp.iResult << endl;
return -2;
}
ROLLLOG_DEBUG << "insert forbit_uid, iRet: " << iRet << ", dataRsp: " << printTars(dataRsp) << endl;
__CATCH__
FUNC_EXIT("", iRet);
return iRet;
}
int Processor::getForbitChat(const long lUid, const long forbit_uid)
{
FUNC_ENTRY("");
__TRY__
string table_name = "tb_forbitchat";
std::vector<string> col_name = { "forbit_uid", "is_forbit"};
std::vector<vector<string>> whlist = {
{"uid", "0", L2S(lUid)},
{"forbit_uid", "0", L2S(forbit_uid)}
};
dbagent::TDBReadRsp dataRsp;
int iRet = readDataFromDBEx(lUid, table_name, col_name, whlist, "log_time", dataRsp);
if(iRet != 0)
{
LOG_ERROR<<"select tb_forbitchat err!"<< endl;
return 0;
}
for (auto it = dataRsp.records.begin(); it != dataRsp.records.end(); ++it)
{
for (auto itfield = it->begin(); itfield != it->end(); ++itfield)
{
if (itfield->colName == "is_forbit")
{
return S2I(itfield->colValue);
}
}
}
__CATCH__
FUNC_EXIT("", 0);
return 0;
}