fix data store

master
IoTcat 5 years ago
parent 0ef6f6ac99
commit 813ba0a8eb
  1. 2
      lib/ovo.h
  2. 2
      src/feeTable.h
  3. 17
      src/main.cpp
  4. 47
      src/park.cpp
  5. 7
      src/park.h

@ -221,7 +221,7 @@ namespace ovo{
/*** AES ***/
public:
aes_ini(std::string key, std::string iv = ""){
void aes_ini(std::string key, std::string iv = ""){
key = (this->md5(key)).substr(0, 16);
_aes_key = key;
if(iv == "") this->_aes_iv = this->_aes_key;

@ -40,6 +40,8 @@ class FeeTable {
return std::vector<int>();
};
friend class Park;
private:
ovo::data _d, _tableData;
ovo::db db;

@ -10,8 +10,8 @@ using namespace std;
int main(int argc, char const *argv[]) {
Park p;
if (!p.isExist()) {
int t = time(NULL);
if (!p.isExist()) {cout << "exist";
ovo::math m;
std::vector<std::map<string, int>> ParkIniInfo;
std::map<string, int> t_map;
@ -53,12 +53,19 @@ int main(int argc, char const *argv[]) {
feeTable["Ship"] = fee;
p.updateFeeTable(feeTable);
//p._storeData();
}
ovo::data d;
d["date"] = "2019-05-24";
p.join();
cout << p._d.showAll();
cout << "Cost" << time(NULL) - t;
p.checkIn("2222", "Ship");
p.checkOut("2222");
//ovo::data d;
//d["date"] = "2019-05-24";
cout << p.getLog(d)[0].showAll();
//cout << p.getLog(d)[0].showAll();
// cout << p.getLog()
while (1) {

@ -13,6 +13,7 @@ Park::Park() {
this->_threadPointer = false;
this->_d = db.getData(g_ParkID);
cout << _d.showAll();
if (!this->isExist()) return;
this->_threadFinished = false;
@ -29,14 +30,7 @@ Park::Park() {
};
Park::~Park() {
if (!this->_threadFinished) this->_t->join();
this->_d.classify();
this->_plotsList.classify();
this->_carsList.classify();
db.pushData(g_ParkID, this->_d);
db.pushData(this->_d["plotsList"], this->_plotsList);
db.pushData(this->_d["carsList"], this->_carsList);
this->_storeData();
};
void Park::join() {
@ -87,6 +81,8 @@ void Park::ini(std::vector<std::map<string, int>>& v) {
vv.push_back("date");
db.createTable(this->_d["log"], vv);
this->_storeData();
};
const vector<string> Park::getPlotsID() {
@ -249,6 +245,8 @@ const bool Park::newCar(const string& licenseNum, const string& type,
this->_plotsList[plotID] =
this->_simpleUpdate(this->_plotsList[plotID], "car", licenseNum);
this->_storeData();
return true;
};
@ -265,6 +263,9 @@ const bool Park::delCar(const string& licenseNum, string& msg) {
this->_plotsList[c.getPlot()] =
this->_simpleUpdate(this->_plotsList[c.getPlot()], "car", "null");
this->_carsList.clear(licenseNum);
this->_storeData();
return true;
}
@ -332,6 +333,8 @@ const bool Park::updatePlot(Plot& plot, const int& level) {
plot.updateLevel(level);
this->_storeData();
return true;
}
@ -347,6 +350,8 @@ const bool Park::updatePlot(Plot& plot, const string& type) {
plot.updateType(type);
this->_storeData();
return true;
}
@ -423,12 +428,38 @@ int Park::checkOut(const string& licenseNum) {
this->delCar(licenseNum);
// this->_threadFinished = true;
//});
return fee;
}
void Park::_storeData(){
if (!this->_threadFinished) this->_t->join();
this->_threadFinished = false;
this->_t = new std::thread([&]{
this->_threadPointer = true;
this->_needStoreData = false;
this->_d.classify();
this->_plotsList.classify();
this->_carsList.classify();
db.pushData(g_ParkID, this->_d);
db.pushData(this->_d["plotsList"], this->_plotsList);
db.pushData(this->_d["carsList"], this->_carsList);
this->_threadFinished = true;
});
}
void Park::_getTypes(std::vector<std::map<string, int>>& v) {
this->_types.clear(); //清空vec
for (auto i : v) {

@ -82,6 +82,7 @@ class Park {
inline void updateFeeTable(std::map<string, std::vector<int>>& m) {
this->_feeTable.set(m);
this->_feeTable._pushTable();
};
inline const std::vector<string> getPlotsID(const string& type,
@ -210,7 +211,7 @@ class Park {
return db.getSQL(this->_d["log"], d);
};
private:
//private:
ovo::data _d, _carsList, _plotsList;
// ovo::index _isOccupiedIndex, _typeIndex, _levelIndex;
std::vector<string> _types;
@ -219,11 +220,13 @@ class Park {
ovo::String S;
ovo::db db;
std::thread* _t;
bool _threadFinished, _threadPointer;
bool _threadFinished, _threadPointer, _needStoreData;
FeeTable _feeTable;
void _storeData();
void _getTypes(std::vector<std::map<string, int>>& v);
void _setupPlots(std::vector<std::map<string, int>>& v);
const string _simpleGet(const string& s, const string& what);
const string _simpleUpdate(const string& s, const string& what,
const string& to);

Loading…
Cancel
Save