master
IoTcat 5 years ago
parent 3a3f18e42e
commit 1f3f1a2a89
  1. 3
      src/feeTable.h
  2. 49
      src/main.cpp
  3. 123
      src/park.h

@ -56,6 +56,7 @@ public:
void set(std::map<string, std::vector<int>>& m){
for(auto& i : m){
if(this->_table.count(i.first)){
this->_table[i.first].erase(this->_table[i.first].begin(), this->_table[i.first].end());
@ -90,7 +91,7 @@ public:
int fee = 0;
for(int i = 0; i < hours; i ++){
for(int i = 0; i <= hours; i ++){
fee += this->_table[type][i];
}

@ -12,29 +12,32 @@ int main(int argc, char const *argv[])
{
FeeTable t;
/*
std::vector<string> v;
v.push_back("car");
v.push_back("Cars");
v.push_back("rac");
//t.setTypes(v);
std::map<string, std::vector<int>> m;
t.setTypes(v);
*/
std::map<string, std::vector<int>> mm;
std::vector<int> vv;
vv.push_back(2);
vv.push_back(3);
m["car"] = vv;
mm["Cars"] = vv;
t.set(mm);
cout << t.showAll();
//t.set(m);
cout << t.getFee("car", "0", "10000");
//cout << t.getFee("car", "0", "10000");
cout << t.showAll();
//cout << t.showAll();
/*
@ -48,11 +51,11 @@ int main(int argc, char const *argv[])
*/
/*
Park p;
cout << p.isExist();
//cout << p.isExist();
std::vector<map<string, int>> v;
@ -66,23 +69,33 @@ int main(int argc, char const *argv[])
m["Carsss"] = 99;
v.push_back(m);
//p.ini(v);
p.ini(v);
//p.updateFeeTable(mm);
//cout << p.checkType("Cadrs");
p.join();
cout << p._d.showAll();
p.checkIn("2333", "Cars");
cout << p.checkOut("2333");
//cout << p._feeTable.showAll();
//cout << p._d.showAll();
//
/*
string kk = "";
if(!p.newCar("110", "Cars", p.getPlotsID("Cars", false)[0], kk))cout << kk;
int t = time(NULL);
int t = time(NULL);*/
string s = "Cars";
cout << endl<<p.getPlotsID("Cars", false).size();
for(auto i : p.getPlotsID("Cars", false)){
//cout << endl<<p.getPlotsID("Cars", false).size();
for(auto i : p.getPlotsID(s)){
cout << p.getPlot(i).showAll();
}
}/*
for(auto i : p.getCarsID(0)){
cout << i;
@ -91,5 +104,9 @@ int main(int argc, char const *argv[])
//p.delCar("110");
cout << p.getPlotByCar("110").showAll();
*/
for(auto i : p.getLogByDate("2019-05-23")){
cout << i.showAll();
}
return 0;
}

@ -25,6 +25,7 @@ public:
Park(){
this->_threadFinished = true;
this->_threadPointer = false;
this->_d = db.getData(g_ParkID);
if(!this->isExist()) return ;
@ -33,13 +34,15 @@ public:
this->_t = new std::thread([&]{
this->_threadPointer = true;
this->_plotsList = db.getData(this->_d["plotsList"]);
this->_carsList = db.getData(this->_d["carsList"]);
this->_recoverTypes();
this->_feeTable.setTypes(this->_types);
this->_levels = atoi(this->_d["levels"].c_str());
this->_threadFinished = true;
});
@ -63,9 +66,17 @@ public:
if(!this->_threadFinished)
{
this->_t->join();
delete this->_t;
this->_threadPointer = false;
this->_threadFinished = true;
}
if(this->_threadPointer){
delete this->_t;
this->_threadPointer = false;
}
}
bool isExist(){
@ -262,6 +273,7 @@ public:
this->_d["carsList"] = m.randStr();
this->_d["plotsList"] = m.randStr();
this->_d["feeTable"] = m.randStr();
this->_d["log"] = m.randStr();
this->_d["levels"] = to_string(this->_levels);
this->_d["types"] = "";
for(string i : this->_types){
@ -271,6 +283,19 @@ public:
this->_setupPlots(v);
this->_feeTable.setTypes(this->_types);
std::vector<string> vv;
vv.push_back("uid");
vv.push_back("licenseNum");
vv.push_back("type");
vv.push_back("level");
vv.push_back("plot");
vv.push_back("LastInTime");
vv.push_back("LastOutTime");
vv.push_back("fee");
vv.push_back("date");
db.createTable(this->_d["log"], vv);
};
void updateFeeTable(std::map<string, std::vector<int>>& m){
@ -640,12 +665,89 @@ public:
Car c(this->_carsList[licenseNum]);
this->delCar(licenseNum);
int fee = this->_feeTable.getFee(c.getType(), c.getLastInTime(), c.getLastOutTime());
//this->_threadFinished = false;
//this->_t = new std::thread([&]{
return this->_feeTable.getFee(c.getType(), c.getLastInTime(), c.getLastOutTime());
//this->_threadPointer = true;
ovo::data d;
d["uid"] = m.randStr();
d["licenseNum"] = licenseNum;
d["type"] = c.getType();
d["plot"] = c.getPlot();
d["level"] = this->_simpleGet(this->_plotsList[c.getPlot()], "level");
d["LastInTime"] = c.getLastInTime();
d["LastOutTime"] = c.getLastOutTime();
d["fee"] = to_string(fee);
d["date"] = this->_getDate();
db.insertSQL(this->_d["log"], d);
this->delCar(licenseNum);
//this->_threadFinished = true;
//});
return fee;
}
std::vector<ovo::data> getLog(ovo::data FilterData){
return db.getSQL(this->_d["log"], FilterData);
}
std::vector<ovo::data> getLog(){
return db.getSQL(this->_d["log"]);
}
std::vector<ovo::data> getLogByCarID(const string& licenseNum){
ovo::data d;
d["licenseNum"] = licenseNum;
return db.getSQL(this->_d["log"], d);
}
std::vector<ovo::data> getLogByType(const string& type){
ovo::data d;
d["type"] = type;
return db.getSQL(this->_d["log"], d);
}
std::vector<ovo::data> getLogByLevel(const int& level){
ovo::data d;
d["level"] = to_string(level);
return db.getSQL(this->_d["log"], d);
}
std::vector<ovo::data> getLogByFee(const int& fee){
ovo::data d;
d["fee"] = to_string(fee);
return db.getSQL(this->_d["log"], d);
}
std::vector<ovo::data> getLogByPlotID(const string& plot){
ovo::data d;
d["plot"] = plot;
return db.getSQL(this->_d["log"], d);
}
std::vector<ovo::data> getLogByDate(const string& date){ //2019-05-24
ovo::data d;
d["date"] = date;
return db.getSQL(this->_d["log"], d);
}
//private:
ovo::data _d, _carsList, _plotsList;
@ -656,7 +758,7 @@ public:
ovo::String S;
ovo::db db;
std::thread *_t;
bool _threadFinished;
bool _threadFinished, _threadPointer;
FeeTable _feeTable;
void _getTypes(std::vector<std::map<string, int>>& v){
@ -738,6 +840,19 @@ public:
return (bool)(find(this->_types.begin(), this->_types.end(), type) == this->_types.end());
}
string _getDate(){
char now[64];
time_t tt;
struct tm *ttime;
//tt = atol(argv[1]);
//tt = 1212132599; //uint
time(&tt);
ttime = localtime(&tt);
strftime(now,64,"%Y-%m-%d",ttime);
string s = now;
return s;
}
};

Loading…
Cancel
Save