124 lines
3.7 KiB
C++
124 lines
3.7 KiB
C++
//
|
||
// Created by dongl on 23-5-4.
|
||
//
|
||
|
||
#include "UserFriendsDB.h"
|
||
#include "linkDB.h"
|
||
|
||
|
||
// 查询好友添加权限类型
|
||
char UserFriendsDB::select_add_type(uint64_t account) {
|
||
conn = LinkDB::safe_grab();
|
||
auto query = conn->query("select restrictions from im_user_friends where account=%0:account");
|
||
query.parse();
|
||
|
||
// 查看添加授权类型 0 直接添加 1 验证问题 2 账户审核
|
||
return query.store(account)[0][0][0]; // 因为 account 唯一 所以结果 至多一个
|
||
}
|
||
|
||
// 修改好友列表数据 添加好友
|
||
/// friends :{
|
||
/// uid :info { }
|
||
/// }
|
||
bool UserFriendsDB::add_friends(uint64_t account, uint64_t friends) {
|
||
conn = LinkDB::safe_grab();
|
||
auto query = conn->query("update im_user_friends set friends="
|
||
"JSON_SET(friends, '$.\"%2:friends\"', "
|
||
"JSON_OBJECT('belong_grouping', 1, 'add_time', 10000, 'add_source', 1)"
|
||
")"
|
||
"where account=%1:account");
|
||
|
||
query.template_defaults[1] = account;
|
||
query.template_defaults[2] = friends;
|
||
query.parse();
|
||
return query.exec();
|
||
}
|
||
|
||
std::vector<uint64_t> UserFriendsDB::select_friends_all(uint64_t account) {
|
||
conn = LinkDB::safe_grab();
|
||
|
||
auto q = conn->query("select friends from im_user_friends where account=783556037");
|
||
|
||
auto ret = q.store();
|
||
std::vector<uint64_t> v;
|
||
return v;
|
||
}
|
||
|
||
rapidjson::Document UserFriendsDB::select_friends_info(uint64_t account, uint64_t friends) {
|
||
conn = LinkDB::safe_grab();
|
||
rapidjson::Document document;
|
||
|
||
auto q = conn->query("select JSON_EXTRACT(friends, '$.\"%2:friends\"') as friend_info "
|
||
"from im_user_friends where account=%1:account");
|
||
q.template_defaults[1] = account;
|
||
q.template_defaults[2] = friends;
|
||
q.parse();
|
||
|
||
// 查库
|
||
auto ret = q.store();
|
||
|
||
printf("%zu\n", ret.num_rows());
|
||
|
||
if (ret.num_rows() < 1) {
|
||
return document;
|
||
}
|
||
|
||
// 取json字符串
|
||
std::string friend_info;
|
||
ret[0][0].to_string(friend_info);
|
||
|
||
// 解析json
|
||
document.Parse(friend_info.c_str());
|
||
|
||
printf("%d\n", document["add_time"].GetInt());
|
||
printf("user[%ld] friend_info-> %ld : %s", account, friends, friend_info.c_str());
|
||
// printf("%u\n", document.Size());
|
||
return document;
|
||
}
|
||
|
||
|
||
//std::tuple<mp::MP_SRI, mp::MP_SRI, std::string> UserFriendsDB::update_add_info(char type, mp::body *body) {
|
||
// // 如果是0 直接添加
|
||
// if (type == '0') {
|
||
// auto temp_query = conn->query("update im_user_friends set friends=%1q:groups where account=%0:account");
|
||
// temp_query.parse();
|
||
//
|
||
// std::vector<uint64_t> friends;
|
||
// friends.push_back(body->source());
|
||
// auto ret1 = temp_query.execute(body->target(), vectorSerialization(friends));
|
||
//
|
||
// friends.clear();
|
||
// friends.push_back(body->target());
|
||
// auto ret2 = temp_query.execute(body->source(), vectorSerialization(friends));
|
||
//
|
||
// if (ret1.rows() < 1 || ret2.rows() < 1) {
|
||
// return std::make_tuple(mp::MP_ADD_FRIENDS_ERR, mp::MP_ADD_FRIENDS_SQL_ERR, "定位之于此 sql可能执行结果出错");
|
||
// }
|
||
// return std::make_tuple(mp::MP_ADD_FRIENDS, mp::MP_ADD_FRIENDS_0, "添加成功");
|
||
// }
|
||
//
|
||
// // 1 回答问题
|
||
// else if (type == '1') {
|
||
//
|
||
// return std::make_tuple(mp::MP_ADD_FRIENDS, mp::MP_ADD_FRIENDS, "添加成功");
|
||
// }
|
||
// // 2 被添加账户审核
|
||
// else if (type == '2') {
|
||
//// auto temp_query = conn->query("select");
|
||
//
|
||
// return std::make_tuple(mp::MP_ADD_FRIENDS, mp::MP_ADD_FRIENDS_2, "待同意");
|
||
// }
|
||
//
|
||
// return std::make_tuple(mp::MP_ADD_FRIENDS_ERR, mp::MP_ADD_FRIENDS_NOT_TYPE, "找不到此类型的添加决策");
|
||
//}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|