You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
173 lines
4.2 KiB
173 lines
4.2 KiB
#pragma once
|
|
|
|
#include <sqlite3.h>
|
|
#include <stdio.h>
|
|
|
|
#include <fstream>
|
|
#include <functional>
|
|
#include <iostream>
|
|
#include <list>
|
|
#include <map>
|
|
#include <memory>
|
|
#include <set>
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "iflytop/core/spdlogfactory/logger.hpp"
|
|
#include "iflytop/core/thread/thread.hpp"
|
|
|
|
#define USER_DB "user.db"
|
|
#define SETTING_DB "setting.db"
|
|
#define DISINFECTION_RECORD_DB "disinfection_record.db"
|
|
/**
|
|
* @brief
|
|
*
|
|
* USER_DB
|
|
* table: user
|
|
* id uid passwd permission_level
|
|
*
|
|
*
|
|
* SETTING_DB
|
|
* table: setting
|
|
* id setting_name setting_name_ch val_upper_limit val_lower_limit permission_level val
|
|
*
|
|
* DISINFECTION_RECORD_DB
|
|
* table: disinfection_record
|
|
* id uuid uid date loglevel duration
|
|
*
|
|
*
|
|
* table: sensor_record
|
|
* id disinfection_id date heating_strip air_compressor sprinkler_pump disinfectant_volume h2o2_1 temp_1 humid_1 saturation_1 h2o2_2 temp_2 humid_2
|
|
* saturation_2 h2o2_3 temp_3 humid_3 saturation_3
|
|
*
|
|
*/
|
|
|
|
namespace iflytop {
|
|
using namespace std;
|
|
using namespace std;
|
|
using namespace core;
|
|
using namespace nlohmann;
|
|
namespace db {
|
|
|
|
struct User {
|
|
public:
|
|
int id;
|
|
string uid;
|
|
string passwd;
|
|
int permission_level;
|
|
int visible;
|
|
};
|
|
|
|
struct Setting {
|
|
public:
|
|
int id;
|
|
string name;
|
|
string name_ch;
|
|
int val_lower_limit;
|
|
int val_upper_limit;
|
|
int permission_level;
|
|
int val;
|
|
};
|
|
|
|
struct PreSetting {
|
|
public:
|
|
int id;
|
|
int group_id;
|
|
int stoped_gs;
|
|
int continued_gs;
|
|
int stoped_satur;
|
|
int continued_satur;
|
|
int stoped_humi;
|
|
int continued_humi;
|
|
int injection_pump_speed;
|
|
};
|
|
|
|
struct DisinfectionRecord {
|
|
public:
|
|
int id;
|
|
string uuid;
|
|
string uid;
|
|
string date;
|
|
string loglevel;
|
|
int duration;
|
|
};
|
|
|
|
struct SensorRecord {
|
|
public:
|
|
int id;
|
|
string disinfection_id;
|
|
string date;
|
|
int heating_strip;
|
|
int air_compressor;
|
|
int sprinkler_pump;
|
|
int disinfectant_volume;
|
|
int h2o2_1;
|
|
int temp_1;
|
|
int humid_1;
|
|
int saturation_1;
|
|
int h2o2_2;
|
|
int temp_2;
|
|
int humid_2;
|
|
int saturation_2;
|
|
int h2o2_3;
|
|
int temp_3;
|
|
int humid_3;
|
|
int saturation_3;
|
|
};
|
|
} // namespace db
|
|
using namespace db;
|
|
class DBService : public enable_shared_from_this<DBService> {
|
|
ENABLE_LOGGER(DBService);
|
|
|
|
public:
|
|
DBService();
|
|
void initialize();
|
|
|
|
public:
|
|
/*******************************************************************************
|
|
* USER_DB *
|
|
*******************************************************************************/
|
|
list<shared_ptr<db::User>> getAllUser();
|
|
json getAllUserJson();
|
|
shared_ptr<db::User> getUser(string uid);
|
|
vector<string> getUserNames();
|
|
|
|
/**
|
|
* @brief 添加用户
|
|
*
|
|
* @param uid 用户名
|
|
* @param passwd 密码
|
|
* @param permission_level 许可等级,0超级管理员 3普通用户
|
|
*/
|
|
void addUser(string uid, string passwd, int permission_level);
|
|
void delUser(int id);
|
|
void updateUserPermissionLevel(int id, int permission_level);
|
|
|
|
public:
|
|
/*******************************************************************************
|
|
* SETTING_DB *
|
|
*******************************************************************************/
|
|
list<shared_ptr<db::Setting>> getAllSetting();
|
|
json getAllSettingJson();
|
|
bool setSettingVal(int id, int val);
|
|
bool setSettingVal(string name, int val);
|
|
int getSettingVal(string name);
|
|
|
|
public:
|
|
/*******************************************************************************
|
|
* SensorRecord_operation *
|
|
*******************************************************************************/
|
|
|
|
json getAllRecords(string disinfection_id);
|
|
void insertSensorRecord(shared_ptr<db::SensorRecord> record);
|
|
void insertDisinfectionRecord(shared_ptr<db::DisinfectionRecord> record);
|
|
void setDisinfectionRecordDuration(string disinfection_id, int duration);
|
|
|
|
private:
|
|
void init_usr_db();
|
|
void init_setting_db();
|
|
void init_disinfection_record_db();
|
|
};
|
|
|
|
}; // namespace iflytop
|