rank.cpp
2.09 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
#include "rank.h"
#include "func_rount.h"
rank_t::rank_t( el::lib_mysql_if* db )
: el::lib_mysql_table_route1x1(db, g_gen_db_name("USER"), "t_rank")
{
}
int rank_t::load(db_msg::load_rank_msg_res* out, role_t* role)
{
GEN_SQLSTR(this->sqlstr, "select type, uid, val, tim from %s",
this->get_table_name());
PB_STD_QUERY_WHILE_BEGIN(this->sqlstr, out, add_rank_user);
uint32_t t_type = 0;
USER_ID t_uid = 0;
uint32_t t_val = 0;
uint32_t t_tim = 0;
GET_FIELD_UINT64(t_type);
member->set_type(t_type);
GET_FIELD_UINT64(t_uid);
member->mutable_user_show()->set_uid(t_uid);
GET_FIELD_UINT64(t_val);
member->set_val(t_val);
GET_FIELD_UINT64(t_tim);
member->set_tim(t_tim);
std::string nick;
USER_HEAD_ID head;
role->load(t_uid, nick, head);
member->mutable_user_show()->set_nick(nick);
PB_STD_QUERY_WHILE_END();
}
int Cfunc_route::on_load_rank_msg(USER_ID uid, google::protobuf::Message* msg)
{
db_msg::load_rank_msg_res res;
this->ret = this->rank.load(&res, &this->role);
if (SUCC == this->ret) {
this->encode_msg2sendbuf(&res);
}
return this->ret;
}
int rank_t::update(uint32_t type, USER_ID uid, uint32_t val, uint32_t tim)
{
GEN_SQLSTR(this->sqlstr, "insert into %s (type,uid,val,tim)"
"values(%u, %" PRIu64 ", %u, %u) on duplicate key update val=%u, tim=%u",
this->get_table_name(),
type, uid, val, tim,
val, tim);
return this->exec_update_sqls(this->sqlstr);
}
int Cfunc_route::on_update_user_rank_msg(USER_ID uid, google::protobuf::Message* msg)
{
auto in = (db_msg::update_user_rank_msg*)msg;
auto ptr_rank = in->mutable_rank_user();
this->ret = this->rank.update(ptr_rank->type(), ptr_rank->user_show().uid(), ptr_rank->val(), ptr_rank->tim());
return this->ret;
}
int rank_t::del(uint32_t type, USER_ID uid)
{
GEN_SQLSTR(this->sqlstr, "delete from %s where type=%u and uid=%" PRIu64,
this->get_table_name(),
type,
uid);
return this->exec_update_sqls(this->sqlstr);
}
int Cfunc_route::on_delete_user_rank_msg(USER_ID uid, google::protobuf::Message* msg)
{
auto in = (db_msg::delete_user_rank_msg*)msg;
this->rank.del(in->type(), in->uid());
return this->ret;
}