提交信息!

This commit is contained in:
2020-11-23 15:48:50 +08:00
parent 6572379132
commit 1e628ccc30
5 changed files with 102 additions and 48 deletions

View File

@@ -2,6 +2,7 @@
#include <stdexcept>
#include "LoadFromExcel.h"
#include "../../excel/excel.h"
#include "../../Data/Datastructure/CarDealer/CarDealerMap.h"
using namespace std;
using namespace libxl;
@@ -52,6 +53,9 @@ void LoadCarDealerSchemeFromXlsx( const wstring & filePath,
int firstColumnIndex = pSheet->firstCol();
int rowIndex = firstRowIndex + startRowIndex;
//车商名称表
auto * pCarDealerMap = getCarDealerMap();
while ( rowIndex <= lastRowIndex )
{
int colunmIndex = firstRowIndex;
@@ -59,12 +63,12 @@ void LoadCarDealerSchemeFromXlsx( const wstring & filePath,
const wstring && theYear = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex, true );
const wstring && theMonth = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex + 1, true );
const wstring && carDealerCode = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex + 2, true );
const wstring && carDealerName = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex + 3, true );
const wstring && manHourPrice = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex + 4, true );
const wstring && partPrice = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex + 5, true );
const wstring && claimSupport = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex + 6, true );
const wstring && scheme = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex + 7, true );
const wstring && isQualified = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex + 8, true );
//const wstring && carDealerName = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex + 3, true );
const wstring && manHourPrice = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex + 4, true );
const wstring && partPrice = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex + 5, true );
const wstring && claimSupport = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex + 6, true );
const wstring && scheme = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex + 7, true );
const wstring && isQualified = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex + 8, true );
//空行跳过
if ( carDealerCode.empty() == true )
@@ -74,6 +78,19 @@ void LoadCarDealerSchemeFromXlsx( const wstring & filePath,
continue;
}
//核对车商代码
auto iterCarDealer = pCarDealerMap->find(carDealerCode);
if ( iterCarDealer == pCarDealerMap->end() )
{
//没查到这个车商,清除掉已经读取的数据
schemeVector.clear();
QString rowIndexString = QString::number(rowIndex, 'g', -1);
QString errorMessage = QString("") + rowIndexString + QString("行车商代码错误!");
throw runtime_error(errorMessage.toStdString());
}
CarDealerScheme carDealerScheme( theYear,
theMonth,
carDealerCode,
@@ -131,6 +148,8 @@ void LoadCarDealerAchievementFromXlsx( const std::wstring & fileP
int firstColumnIndex = pSheet->firstCol();
int rowIndex = firstRowIndex + startRowIndex;
unordered_map<wstring, CarDealer>* pCarDealerMap = getCarDealerMap();
while ( rowIndex <= lastRowIndex )
{
int colunmIndex = firstRowIndex;
@@ -154,6 +173,19 @@ void LoadCarDealerAchievementFromXlsx( const std::wstring & fileP
continue;
}
//核对车商代码
auto iterCarDealer = pCarDealerMap->find(carDealerCode);
if (iterCarDealer == pCarDealerMap->end())
{
//没查到这个车商,清除掉已经读取的数据
achievementVector.clear();
QString rowIndexString = QString::number(rowIndex, 'g', -1);
QString errorMessage = QString("") + rowIndexString + QString("行车商代码错误!");
throw runtime_error(errorMessage.toStdString());
}
//每个字段都要先判断数据类型再读写,防止填写表格的人填错内容。
CellType type = pSheet->cellType( rowIndex, firstColumnIndex + 4 );
char errorMessage[1000];
@@ -309,6 +341,8 @@ void LoadRepairOrderFromXlsx( const std::wstring & filePath,
int firstRowIndex = pSheet->firstRow();
int rowIndex = firstRowIndex + startRowIndex;
auto* pCarDealerMap = getCarDealerMap();
while ( rowIndex <= lastRowIndex )
{
int colunmIndex = pSheet->firstCol();

View File

@@ -18,7 +18,7 @@
using namespace std;
using namespace ocilib;
unordered_map<string, CarDealer> * pCarDealerMap = nullptr;
unordered_map<wstring, CarDealer> * pCarDealerMap = nullptr;
void initCarDealerMap()
{
@@ -63,11 +63,11 @@ void initCarDealerMap()
//连接数据库失败
string errorMessage = "连接数据库失败!";
errorMessage.append(error.what());
errorMessage.append( error.what() );
OCI_Cleanup();
throw runtime_error(errorMessage.c_str());
throw runtime_error( errorMessage.c_str() );
}
//查询
@@ -78,28 +78,28 @@ void initCarDealerMap()
OCI_ExecuteStmt( pStatement, sql.c_str() );
pResult = OCI_GetResultset( pStatement );
pCarDealerMap = new unordered_map<string, CarDealer>;
pCarDealerMap = new unordered_map<wstring, CarDealer>;
while ( OCI_FetchNext( pResult ) == true )
{
string carDealerCodeIndex = OCI_GetString( pResult, 1 );
wstring carDealerCodeIndex = QString::fromLocal8Bit( OCI_GetString( pResult, 1 ) ).toStdWString();
QString carDealerCode = QString::fromLocal8Bit( OCI_GetString( pResult, 1 ) );
QString carDealerName = QString::fromLocal8Bit( OCI_GetString( pResult, 2 ) );
CarDealer dealer( carDealerCode, carDealerName );
pCarDealerMap->insert( pair<string, CarDealer>( carDealerCodeIndex, dealer ) );
pCarDealerMap->insert( pair<wstring, CarDealer>( carDealerCodeIndex, dealer ) );
}
}
catch ( runtime_error & error )
{
string errorMessage = "执行查询失败!";
errorMessage.append(error.what());
errorMessage.append( error.what() );
OCI_Cleanup();
throw runtime_error(errorMessage.c_str());
throw runtime_error( errorMessage.c_str() );
}
OCI_Cleanup();
@@ -187,7 +187,12 @@ void initCarDealerMapCpp()
Environment::Cleanup();
}
std::unordered_map<string, CarDealer> * getCarDealerMap()
std::unordered_map<wstring, CarDealer> * getCarDealerMap()
{
if ( pCarDealerMap != nullptr )
{
initCarDealerMap();
}
return pCarDealerMap;
}

View File

@@ -22,4 +22,4 @@ void initCarDealerMap();
* \brief
* \return
************************************************/
std::unordered_map<std::string, CarDealer> * getCarDealerMap();
std::unordered_map<std::wstring, CarDealer> * getCarDealerMap();