Compare commits
2 commits
e494762c3a
...
56931c2e27
Author | SHA1 | Date | |
---|---|---|---|
56931c2e27 | |||
8f5797bbfb |
2 changed files with 26 additions and 28 deletions
|
@ -608,6 +608,7 @@ unsigned int Database::loadSales(std::vector<std::unique_ptr<Sale>>& sales,
|
|||
|
||||
sales.clear();
|
||||
|
||||
std::map<std::string, Sale*> saleMap;
|
||||
while (retCode != SQLITE_DONE) {
|
||||
++count;
|
||||
auto sale = std::make_unique<Sale>();
|
||||
|
@ -615,6 +616,7 @@ unsigned int Database::loadSales(std::vector<std::unique_ptr<Sale>>& sales,
|
|||
sale->setSourceNo(sqlite3_column_int(stmt, 1));
|
||||
sale->setTimestamp(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 2)));
|
||||
sale->setState(Sale::State::OK);
|
||||
saleMap.insert(std::make_pair(sale->getUuidAsString(), sale.get()));
|
||||
sales.push_back(std::move(sale));
|
||||
|
||||
retCode = sqlite3_step(stmt);
|
||||
|
@ -622,35 +624,31 @@ unsigned int Database::loadSales(std::vector<std::unique_ptr<Sale>>& sales,
|
|||
|
||||
sqlite3_finalize(stmt);
|
||||
|
||||
for (auto& sale : sales) {
|
||||
std::map<std::string, Article*> artMap;
|
||||
for (const auto& seller : sellers) {
|
||||
for (const auto article : seller->getArticles(false)) {
|
||||
artMap.insert(std::make_pair(article->getUuidAsString(), article));
|
||||
}
|
||||
}
|
||||
|
||||
retCode = sqlite3_prepare_v2(db_,
|
||||
"SELECT sale_id, article_id"
|
||||
" FROM sales_items"
|
||||
" WHERE sale_id = :sale_uuid",
|
||||
" FROM sales_items",
|
||||
-1, &stmt, nullptr);
|
||||
if (retCode != SQLITE_OK)
|
||||
throw std::runtime_error(sqlite3_errmsg(db_));
|
||||
|
||||
sqlite3_bind_text(stmt, sqlite3_bind_parameter_index(stmt, ":sale_uuid"),
|
||||
sale->getUuidAsString().c_str(), -1, SQLITE_TRANSIENT);
|
||||
|
||||
retCode = sqlite3_step(stmt);
|
||||
|
||||
while (retCode != SQLITE_DONE) {
|
||||
for (auto& seller : sellers) {
|
||||
auto article = seller->getArticleByUuid(
|
||||
reinterpret_cast<const char*>(sqlite3_column_text(stmt, 1)));
|
||||
if (article != nullptr) {
|
||||
sale->addArticle(article);
|
||||
break;
|
||||
}
|
||||
}
|
||||
saleMap[reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0))]->addArticle(
|
||||
artMap[reinterpret_cast<const char*>(sqlite3_column_text(stmt, 1))]);
|
||||
|
||||
retCode = sqlite3_step(stmt);
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
//}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
|
|
@ -56,9 +56,9 @@ class Marketplace
|
|||
friend class ExcelReader;
|
||||
|
||||
private:
|
||||
SellersVec sellers_{500};
|
||||
SalesVec sales_{50000};
|
||||
BasketVec basket_{50};
|
||||
SellersVec sellers_;
|
||||
SalesVec sales_;
|
||||
BasketVec basket_;
|
||||
};
|
||||
|
||||
double marketFee(int sumInCent, int percent, int maxFeeInCent);
|
||||
|
|
Loading…
Reference in a new issue