export sellers as json file
This commit is contained in:
parent
b2d696ccb5
commit
045bc8dd20
8 changed files with 80 additions and 11 deletions
|
@ -3,7 +3,8 @@ set(Boost_USE_STATIC_LIBS ON)
|
|||
find_package(Boost 1.62 COMPONENTS date_time REQUIRED)
|
||||
find_package(SQLite3 REQUIRED)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(XLNT REQUIRED xlnt)
|
||||
pkg_check_modules(XLNT REQUIRED xlnt>=1.3)
|
||||
pkg_check_modules(JSONCPP REQUIRED jsoncpp)
|
||||
|
||||
set(CORE_SOURCES
|
||||
database.cpp
|
||||
|
@ -13,10 +14,11 @@ set(CORE_SOURCES
|
|||
sale.cpp
|
||||
marketplace.cpp
|
||||
excelreader.cpp
|
||||
jsonutil
|
||||
)
|
||||
|
||||
add_library(core STATIC ${CORE_SOURCES})
|
||||
target_link_libraries(core Boost::boost Boost::date_time sqlite3 ${XLNT_LIBRARIES})
|
||||
target_link_libraries(core Boost::boost Boost::date_time sqlite3 ${XLNT_LIBRARIES} ${JSONCPP_LIBRARIES})
|
||||
if (WIN32)
|
||||
target_link_libraries(core bcrypt)
|
||||
endif()
|
||||
|
|
|
@ -8,15 +8,19 @@ void ExcelReader::readSellersFromFile(const std::string& filename, Marketplace*
|
|||
wb.load(filename);
|
||||
auto ws = wb.sheet_by_index(0);
|
||||
|
||||
const int START_ROW = 6;
|
||||
const int END_ROW = 349;
|
||||
const int START_ROW = 5;
|
||||
const int END_ROW = 350;
|
||||
|
||||
int rowCount{};
|
||||
for (const auto& row : ws.rows(false)) {
|
||||
// auto test = row[0].value<int>();
|
||||
if (rowCount < START_ROW)
|
||||
if (rowCount < START_ROW) {
|
||||
rowCount++;
|
||||
continue;
|
||||
std::cout << row[0].to_string() << "\n";
|
||||
} else if (rowCount > END_ROW) {
|
||||
break;
|
||||
}
|
||||
std::cout << row[0].value<int>() << "\n";
|
||||
rowCount++;
|
||||
}
|
||||
}
|
||||
|
|
31
src/core/jsonutil.cpp
Normal file
31
src/core/jsonutil.cpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
#include "jsonutil.h"
|
||||
|
||||
#include <json/json.h>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
void JsonUtil::exportSellers(const std::string& filename, Marketplace* market)
|
||||
{
|
||||
Json::Value root;
|
||||
std::ofstream file(filename);
|
||||
|
||||
Json::StreamWriterBuilder builder;
|
||||
builder["commentStyle"] = "None";
|
||||
builder["indentation"] = " ";
|
||||
|
||||
std::unique_ptr<Json::StreamWriter> writer(builder.newStreamWriter());
|
||||
|
||||
root["encoding"] = "UTF-8";
|
||||
|
||||
for (const auto& seller : market->getSellers()) {
|
||||
Json::Value newEntry;
|
||||
newEntry["uuid"] = seller->getUuidAsString();
|
||||
newEntry["seller_no"] = seller->getSellerNo();
|
||||
newEntry["last_name"] = seller->getLastName();
|
||||
newEntry["first_name"] = seller->getFirstName();
|
||||
newEntry["num_offered_articles"] = seller->getFirstName();
|
||||
root["sellers"].append(newEntry);
|
||||
}
|
||||
|
||||
writer->write(root, &file);
|
||||
}
|
14
src/core/jsonutil.h
Normal file
14
src/core/jsonutil.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
#ifndef JSON_H
|
||||
#define JSON_H
|
||||
|
||||
#include "marketplace.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
class JsonUtil
|
||||
{
|
||||
public:
|
||||
static void exportSellers(const std::string& filename, Marketplace* market);
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue