yesterday_btl_rank.cpp 2.3 KB

#include "yesterday_btl_rank.h"
#include "func_rount.h"

yesterday_btl_rank_t::yesterday_btl_rank_t( el::lib_mysql_if* db )
	: el::lib_mysql_table_route1x1(db, g_gen_db_name("USER"), "t_yesterday_btl_rank")
{
}

int yesterday_btl_rank_t::load(db_msg::load_yesterday_btl_rank_msg_res* out, role_t* role)
{
	GEN_SQLSTR(this->sqlstr, "select type, uid, win_cnt, exp, 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_win_cnt = 0;
	uint32_t t_exp = 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_win_cnt);
	member->set_win_cnt(t_win_cnt);

	GET_FIELD_UINT64(t_exp);
	member->set_exp(t_exp);

	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_yesterday_btl_rank_msg(USER_ID uid, google::protobuf::Message* msg)
{
	db_msg::load_yesterday_btl_rank_msg_res res;

	this->ret = this->yesterday_btl_rank.load(&res, &this->role);
	if (SUCC == this->ret) {
		this->encode_msg2sendbuf(&res);
	}

	return this->ret;
}

int yesterday_btl_rank_t::update(uint32_t type, USER_ID uid, uint32_t win_cnt, uint32_t exp, uint32_t tim)
{
	GEN_SQLSTR(this->sqlstr, "insert into %s (type,uid,win_cnt,exp,tim)"
		"values(%u, %" PRIu64 ", %u, %u, %u) on duplicate key update win_cnt=%u, exp=%u, tim=%u",
		this->get_table_name(),
		type, uid, win_cnt, exp, tim,
		win_cnt, exp, tim);
	return this->exec_update_sqls(this->sqlstr);
}

int Cfunc_route::on_update_yesterday_btl_rank_msg(USER_ID uid, google::protobuf::Message* msg)
{
	auto in = (db_msg::update_yesterday_btl_rank_msg*)msg;

	auto ptr_rank = in->mutable_rank_user();

	return this->yesterday_btl_rank.update(ptr_rank->type(), ptr_rank->user_show().uid(), ptr_rank->win_cnt(), ptr_rank->exp(), ptr_rank->tim());

}

int yesterday_btl_rank_t::del_all()
{
	GEN_SQLSTR(this->sqlstr, "delete from %s", this->get_table_name());

	return this->exec_update_sqls(this->sqlstr);
}

int Cfunc_route::on_delete_yesterday_btl_rank_msg(USER_ID uid, google::protobuf::Message* msg)
{
	return this->yesterday_btl_rank.del_all();
}