12 changed files with 176 additions and 295 deletions
-
4appsrc/baseservice/db/base/dbbase.hpp
-
8appsrc/baseservice/db/base/keyvaldb.cpp
-
3appsrc/baseservice/db/base/keyvaldb.hpp
-
189appsrc/baseservice/db/db_service.cpp
-
31appsrc/baseservice/db/db_service.hpp
-
0appsrc/baseservice/db/doc/README.md
-
53appsrc/baseservice/db/formula_db_dao.cpp
-
61appsrc/baseservice/db/formula_db_dao.hpp
-
51appsrc/baseservice/db/setting_db_dao.cpp
-
6appsrc/baseservice/db/setting_db_dao.hpp
-
63appsrc/service/setting_mgr_service.cpp
@ -0,0 +1,53 @@ |
|||
#include "formula_db_dao.hpp"
|
|||
|
|||
#include "setting_db_dao.hpp"
|
|||
|
|||
/*******************************************************************************
|
|||
* BASIC * |
|||
*******************************************************************************/ |
|||
#define DB_VERSION "1.0.1" // 更新这个参数,会自动重置数据库
|
|||
|
|||
namespace iflytop { |
|||
namespace db {} |
|||
} // namespace iflytop
|
|||
using namespace iflytop; |
|||
using namespace db; |
|||
|
|||
void FormulaDBDao::initialize() { |
|||
inited = true; |
|||
keyvaldb.initialize("formula.db", "formula"); |
|||
} |
|||
|
|||
json FormulaDBDao::getAllFormula() { |
|||
json allFormula; |
|||
auto all = keyvaldb.getAll(); |
|||
for (auto& formula : all) { |
|||
allFormula.push_back(formula->val); |
|||
} |
|||
return allFormula; |
|||
} |
|||
void FormulaDBDao::updateFormula(string formulaid, json formula) { |
|||
formula["formula_id"] = formulaid; |
|||
keyvaldb.set(formulaid, formula); |
|||
} |
|||
void FormulaDBDao::updateFormula(string formulaid, string key, string val) { |
|||
json formula = keyvaldb.get(formulaid); |
|||
formula[key] = val; |
|||
keyvaldb.set(formulaid, formula); |
|||
} |
|||
void FormulaDBDao::deleteFormula(string formulaid) { keyvaldb.del(formulaid); } |
|||
|
|||
json FormulaDBDao::newFormula() { |
|||
// 根据设置中setting是否支持formula
|
|||
auto allSettings = SettingDBDao::ins()->getAllSetting(); |
|||
json formula; |
|||
formula["formula_id"] = UUID().toString(); |
|||
formula["name"] = "新公式"; |
|||
for (auto& setting : allSettings) { |
|||
if (setting->is_visible_in_formula_page) { |
|||
formula[string(setting->setting_id)] = setting->default_val; |
|||
} |
|||
} |
|||
keyvaldb.set(formula["formula_id"], formula); |
|||
return formula; |
|||
} |
@ -0,0 +1,61 @@ |
|||
#pragma once
|
|||
|
|||
#include <sqlite3.h>
|
|||
#include <stdio.h>
|
|||
|
|||
#include <fstream>
|
|||
#include <functional>
|
|||
#include <iostream>
|
|||
#include <list>
|
|||
#include <map>
|
|||
#include <memory>
|
|||
#include <mutex>
|
|||
#include <set>
|
|||
#include <sstream>
|
|||
#include <string>
|
|||
#include <vector>
|
|||
|
|||
#include "appbase/dep.hpp"
|
|||
#include "base/dbbase.hpp"
|
|||
#include "base/keyvaldb.hpp"
|
|||
#include "user_behavior_des.hpp"
|
|||
|
|||
namespace iflytop { |
|||
using namespace std; |
|||
using namespace std; |
|||
using namespace core; |
|||
using namespace nlohmann; |
|||
namespace db { |
|||
|
|||
/*******************************************************************************
|
|||
* DAO * |
|||
*******************************************************************************/ |
|||
class FormulaDBDao : public enable_shared_from_this<FormulaDBDao> { |
|||
THISCLASS(FormulaDBDao); |
|||
recursive_mutex lock_; |
|||
|
|||
KeyvalDBDao keyvaldb; |
|||
bool inited = false; |
|||
|
|||
public: |
|||
void initialize(); |
|||
|
|||
static FormulaDBDao* ins() { |
|||
static FormulaDBDao instance; |
|||
if (!instance.inited) instance.initialize(); |
|||
instance.inited = true; |
|||
return &instance; |
|||
} |
|||
|
|||
public: |
|||
json getAllFormula(); |
|||
void updateFormula(string formulaid, json formula); |
|||
void updateFormula(string formulaid, string key, string val); |
|||
void deleteFormula(string formulaid); |
|||
json newFormula(); |
|||
|
|||
public: |
|||
}; |
|||
|
|||
} // namespace db
|
|||
}; // namespace iflytop
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue