#include <libxl.h>
#include <stdexcept>
#include "LoadFromExcel.h"
#include "../../excel/excel.h"

using namespace std;
using namespace libxl;


/************************************************
* \brief 从Excel文件读取车商方案表
* \param filePath Excel文件路径
* \param schemeMap 存放车商方案数据的map
************************************************/
void LoadCarDealerSchemeFromXlsx( const wstring &           filePath,
                                  unsigned int              sheetIndex,
                                  unsigned int              startRowIndex,
                                  vector<CarDealerScheme> & schemeVector )
{
	Book *  pBook  = xlCreateXMLBookW();
	Sheet * pSheet = nullptr;

	if ( pBook == nullptr )
	{
		throw runtime_error( "libxl库加载失败！" );
	}

	setKey( pBook );

	if ( pBook->load( filePath.c_str() ) != true )
	{
		string errorMessage = "打开文件失败！";
		errorMessage.append( pBook->errorMessage() );

		throw runtime_error( errorMessage );
	}

	pSheet = pBook->getSheet( sheetIndex );

	if ( pSheet == nullptr )
	{
		string errorMessage = "读取sheet失败！";
		errorMessage.append( pBook->errorMessage() );

		pBook->release();

		throw runtime_error( errorMessage );
	}

	int lastRowIndex     = pSheet->lastRow();
	int firstRowIndex    = pSheet->firstRow();
	int firstColumnIndex = pSheet->firstCol();
	int rowIndex         = firstRowIndex + startRowIndex;

	while ( rowIndex <= lastRowIndex )
	{
		int colunmIndex = firstRowIndex;

		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 );

		//空行跳过
		if ( carDealerCode.empty() == true )
		{
			rowIndex++;

			continue;
		}

		CarDealerScheme carDealerScheme( theYear,
		                                 theMonth,
		                                 carDealerCode,
		                                 manHourPrice,
		                                 partPrice,
		                                 claimSupport,
		                                 scheme,
		                                 isQualified );

		schemeVector.push_back( carDealerScheme );

		rowIndex++;
	}

	pBook->release();
}

void LoadCarDealerAchievementFromXlsx( const std::wstring &                filePath,
                                       unsigned                            sheetIndex,
                                       unsigned                            startRowIndex,
                                       std::vector<CarDealerAchievement> & achievementVector )
{
	Book *  pBook  = xlCreateXMLBookW();
	Sheet * pSheet = nullptr;

	if ( pBook == nullptr )
	{
		throw runtime_error( "libxl库加载失败！" );
	}

	setKey( pBook );

	if ( pBook->load( filePath.c_str() ) != true )
	{
		string errorMessage = "打开文件失败！";
		errorMessage.append( pBook->errorMessage() );

		throw runtime_error( errorMessage );
	}

	pSheet = pBook->getSheet( sheetIndex );

	if ( pSheet == nullptr )
	{
		string errorMessage = "读取sheet失败！";
		errorMessage.append( pBook->errorMessage() );

		pBook->release();

		throw runtime_error( errorMessage );
	}

	int lastRowIndex     = pSheet->lastRow();
	int firstRowIndex    = pSheet->firstRow();
	int firstColumnIndex = pSheet->firstCol();
	int rowIndex         = firstRowIndex + startRowIndex;

	while ( rowIndex <= lastRowIndex )
	{
		int colunmIndex = firstRowIndex;

		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 );
		long double      checkedAchievement = 0;
		int              policyAmount       = 0;
		int              cpicAmount         = 0;
		int              piccAmount         = 0;
		int              pinganAmount       = 0;
		int              othersAmount       = 0;

		//空行跳过
		if ( carDealerCode.empty() == true )
		{
			rowIndex++;

			continue;
		}

		//每个字段都要先判断数据类型再读写，防止填写表格的人填错内容。
		CellType type = pSheet->cellType( rowIndex, firstColumnIndex + 4 );
		char     errorMessage[1000];

		//产值
		if ( type == CELLTYPE_NUMBER )
		{
			checkedAchievement = pSheet->readNum( rowIndex, firstColumnIndex + 4 );
		}
		else
		{
			pBook->release();

			sprintf( errorMessage, "第%d行第%d列，格式错误，不是数字类型！", rowIndex, firstColumnIndex + 4 );

			throw runtime_error( errorMessage );
		}

		//签单数量
		type = pSheet->cellType( rowIndex, firstColumnIndex + 5 );

		if ( type == CELLTYPE_NUMBER )
		{
			policyAmount = static_cast<int>(pSheet->readNum( rowIndex, firstColumnIndex + 5 ));
		}
		else
		{
			pBook->release();

			sprintf( errorMessage, "第%d行第%d列，格式错误，不是数字类型！", rowIndex, firstColumnIndex + 5 );

			throw runtime_error( errorMessage );
		}

		//太平洋保险新车签单台次
		type = pSheet->cellType( rowIndex, firstColumnIndex + 6 );

		if ( type == CELLTYPE_NUMBER )
		{
			cpicAmount = static_cast<int>(pSheet->readNum( rowIndex, firstColumnIndex + 6 ));
		}
		else
		{
			pBook->release();

			sprintf( errorMessage, "第%d行第%d列，格式错误，不是数字类型！", rowIndex, firstColumnIndex + 6 );

			throw runtime_error( errorMessage );
		}

		//中国人保新车签单台次
		type = pSheet->cellType( rowIndex, firstColumnIndex + 7 );

		if ( type == CELLTYPE_NUMBER )
		{
			piccAmount = static_cast<int>(pSheet->readNum( rowIndex, firstColumnIndex + 7 ));
		}
		else
		{
			pBook->release();

			sprintf( errorMessage, "第%d行第%d列，格式错误，不是数字类型！", rowIndex, firstColumnIndex + 7 );

			throw runtime_error( errorMessage );
		}

		//中国平安新车签单台次
		type = pSheet->cellType( rowIndex, firstColumnIndex + 8 );

		if ( type == CELLTYPE_NUMBER )
		{
			pinganAmount = static_cast<int>(pSheet->readNum( rowIndex, firstColumnIndex + 8 ));
		}
		else
		{
			pBook->release();

			sprintf( errorMessage, "第%d行第%d列，格式错误，不是数字类型！", rowIndex, firstColumnIndex + 8 );

			throw runtime_error( errorMessage );
		}

		//其他保险公司新车签单台次
		type = pSheet->cellType( rowIndex, firstColumnIndex + 9 );

		if ( type == CELLTYPE_NUMBER )
		{
			othersAmount = static_cast<int>(pSheet->readNum( rowIndex, firstColumnIndex + 9 ));
		}
		else
		{
			pBook->release();

			sprintf( errorMessage, "第%d行第%d列，格式错误，不是数字类型！", rowIndex, firstColumnIndex + 9 );

			throw runtime_error( errorMessage );
		}

		CarDealerAchievement achievement( theYear,
		                                  theMonth,
		                                  carDealerCode,
		                                  checkedAchievement,
		                                  policyAmount,
		                                  cpicAmount,
		                                  piccAmount,
		                                  pinganAmount,
		                                  othersAmount );

		achievementVector.push_back( achievement );

		rowIndex++;
	}

	pBook->release();
}

void LoadRepairOrderFromXlsx( const std::wstring &       filePath,
                              unsigned                   sheetIndex,
                              unsigned                   startRowIndex,
                              std::vector<RepairOrder> & orderVector )
{
	Book *  pBook  = xlCreateXMLBookW();
	Sheet * pSheet = nullptr;

	if ( pBook == nullptr )
	{
		throw runtime_error( "libxl库加载失败！" );
	}

	setKey( pBook );

	if ( pBook->load( filePath.c_str() ) != true )
	{
		string errorMessage = "打开文件失败！";
		errorMessage.append( pBook->errorMessage() );

		throw runtime_error( errorMessage );
	}

	pSheet = pBook->getSheet( sheetIndex );

	if ( pSheet == nullptr )
	{
		string errorMessage = "读取sheet失败！";
		errorMessage.append( pBook->errorMessage() );

		pBook->release();

		throw runtime_error( errorMessage );
	}

	int lastRowIndex  = pSheet->lastRow();
	int firstRowIndex = pSheet->firstRow();
	int rowIndex      = firstRowIndex + startRowIndex;

	while ( rowIndex <= lastRowIndex )
	{
		int colunmIndex = pSheet->firstCol();

		//报案推荐车商代码在表格中不存在，但在数据库中存在。
		const wstring && branchName                  = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		const wstring && orderNo                     = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		const wstring && orderType                   = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		const wstring && notifyNo                    = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		const wstring && damageArea                  = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		const wstring && damageDate                  = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		const wstring && generatingDate              = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		const wstring && policyNo                    = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		const wstring && policyNoJQX                 = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		const wstring && plateNumber                 = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		const wstring && brandName                   = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		const wstring && isInsuranceObject           = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		const wstring && isSuccess                   = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		const wstring && recommandDealerCode         = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		const wstring && recommandDealerName         = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		const wstring && recommandDealerCodeInNotify = L""; // ReadCellStringFromXlsx(pBook, sheetIndex, rowIndex, colunmIndex, true);
		const wstring && recommandDealerNameInNotify = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		const wstring && recommandDealerNameInSurvey = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		const wstring && agentName                   = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		const wstring && surveyor                    = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		const wstring && checkDate                   = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		const wstring && repairingStartDate          = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		const wstring && repairingFinishDate         = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		const wstring && status                      = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		const wstring && lostItemID                  = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		const wstring && surveyorRecommandStatus     = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );

		//空行跳过
		if ( orderNo.empty() == true )
		{
			rowIndex++;

			continue;
		}

		RepairOrder order( branchName,
		                   orderNo,
		                   orderType,
		                   notifyNo,
		                   damageArea,
		                   damageDate,
		                   generatingDate,
		                   policyNo,
		                   policyNoJQX,
		                   plateNumber,
		                   brandName,
		                   isInsuranceObject,
		                   isSuccess,
		                   recommandDealerCode,
		                   recommandDealerName,
		                   recommandDealerCodeInNotify,
		                   recommandDealerNameInNotify,
		                   recommandDealerNameInSurvey,
		                   agentName,
		                   surveyor,
		                   checkDate,
		                   repairingStartDate,
		                   repairingFinishDate,
		                   status,
		                   lostItemID,
		                   surveyorRecommandStatus );

		orderVector.push_back( order );

		rowIndex++;
	}

	pBook->release();
}

void LoadRepairSuggestionFromXlsx( const std::wstring &                  filePath,
                                   unsigned                              sheetIndex,
                                   unsigned                              startRowIndex,
                                   std::vector<RepairSuggestionRecord> & recordVector )
{
	Book *  pBook  = xlCreateXMLBookW();
	Sheet * pSheet = nullptr;

	if ( pBook == nullptr )
	{
		throw runtime_error( "libxl库加载失败！" );
	}

	if ( pBook->load( filePath.c_str() ) != true )
	{
		string errorMessage = "打开文件失败！";
		errorMessage.append( pBook->errorMessage() );

		throw runtime_error( errorMessage );
	}

	setKey( pBook );

	pSheet = pBook->getSheet( sheetIndex );

	if ( pSheet == nullptr )
	{
		string errorMessage = "读取sheet失败！";
		errorMessage.append( pBook->errorMessage() );

		pBook->release();

		throw runtime_error( errorMessage );
	}

	int lastRowIndex  = pSheet->lastRow();
	int firstRowIndex = pSheet->firstRow();
	int rowIndex      = firstRowIndex + startRowIndex;

	while ( rowIndex <= lastRowIndex )
	{
		//起始列索引
		int colunmIndex = pSheet->firstCol();

		wstring orderNo                = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		wstring orderType              = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		wstring notifyNo               = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		wstring suggestedCarDealerCode = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		wstring suggestedCarDealerName = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		wstring damageDate             = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		wstring plateNumber            = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		wstring brandName              = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		wstring messageType            = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		wstring messageSendingDate     = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		wstring dataSource             = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );

		RepairSuggestionRecord record( orderNo,
		                               orderType,
		                               notifyNo,
		                               suggestedCarDealerCode,
		                               suggestedCarDealerName,
		                               damageDate,
		                               plateNumber,
		                               brandName,
		                               messageType,
		                               messageSendingDate,
		                               dataSource );

		recordVector.push_back( record );

		rowIndex++;
	}

	pBook->release();
}

void LoadNewRepairMonitorReportFromXlsx( const std::wstring &                        filePath,
                                         unsigned                                    sheetIndex,
                                         unsigned                                    startRowIndex,
                                         std::vector<NewRepairMonitorReportRecord> & recordVector )
{
	Book *  pBook  = xlCreateXMLBookW();
	Sheet * pSheet = nullptr;

	if ( pBook == nullptr )
	{
		throw runtime_error( "libxl库加载失败！" );
	}

	setKey( pBook );

	if ( pBook->load( filePath.c_str() ) != true )
	{
		string errorMessage = "打开文件失败！";
		errorMessage.append( pBook->errorMessage() );

		throw runtime_error( errorMessage );
	}

	pSheet = pBook->getSheet( sheetIndex );

	if ( pSheet == nullptr )
	{
		string errorMessage = "读取sheet失败！";
		errorMessage.append( pBook->errorMessage() );

		pBook->release();

		throw runtime_error( errorMessage );
	}

	int lastRowIndex  = pSheet->lastRow();
	int firstRowIndex = pSheet->firstRow();
	int rowIndex      = firstRowIndex + startRowIndex;

	while ( rowIndex <= lastRowIndex )
	{
		int colunmIndex = pSheet->firstCol();

		NewRepairMonitorReportRecord record;

		record.分公司名称_                 = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.部门组名称_                 = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.报案号_                   = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.报案日期_                  = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.出险日期_                  = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.出险地点_                  = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.事故车目前位置_               = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.车损序号_                  = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.车牌_                    = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.vin码_                  = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.车龄_                    = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.品牌代码_                  = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.品牌名称_                  = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.车系名称_                  = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.使用性质名称_                = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.保单号_                   = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.标的车_三者车_               = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.是否9座以下企业用车_行政用车_家庭自用车_ = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.核价金额_                  = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.核损配件核损金额_              = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.核损工时费核损金额_             = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.核损辅料核损金额_              = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.核损外修费核损金额_             = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.核损施救费核损金额_             = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.结案金额_                  = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.结案配件核损金额_              = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.结案工时费核损金额_             = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.结案辅料核损金额_              = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.结案外修费核损金额_             = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.结案施救费核损金额_             = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.接报案人分公司名称_             = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.接报案人工号_                = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.接报案人名称_                = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第一任务分派时间_              = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第一定损员分公司_              = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第一定损员部门组名称_            = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第一定损员代码_               = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第一定损员名称_               = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第一车商是否已阅读_             = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第一车上是否预约进厂_            = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第一车商是否推荐失败_            = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第一车商是否进厂确认_            = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第一车商是否出场确认_            = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第二任务分派时间_              = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第二定损员分公司_              = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第二定损员部门组名称_            = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第二定损员代码_               = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第二定损员名称_               = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第二车商是否已阅读_             = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第二车上是否预约进厂_            = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第二车商是否推荐失败_            = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第二车商是否进厂确认_            = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第二车商是否出场确认_            = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第三任务分派时间_              = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第三定损员分公司_              = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第三定损员部门组名称_            = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第三定损员代码_               = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第三定损员名称_               = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第三车商是否已阅读_             = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第三车上是否预约进厂_            = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第三车商是否推荐失败_            = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第三车商是否进厂确认_            = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第三车商是否出场确认_            = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.其他查勘员信息_               = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.是否推荐_                  = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.是否存在工单_                = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.工单类型_                  = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.查勘员操作类型_               = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.案件状态名称_                = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.车状_当前状态_               = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.车状_报案环节_               = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.车状_现场推荐环节_             = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.车状_核价通过环节_             = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.车状_结案环节_               = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.承保车商代码_                = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.承保车商名称_                = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.报案车商分公司名称_             = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.报案车商部门组名称_             = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.报案车商代码_                = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.报案车商名称_                = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.现场推荐车商分公司名称_           = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.现场推荐车商代码_              = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.现场推荐车商名称_              = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.核价车商分公司名称_             = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.核价车商部门组名称_             = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.核价车商代码_                = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.核价车商名称_                = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.推荐车商与核价车商是否一致_         = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.核价修理厂归属公司代码_           = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.核价修理厂归属公司名称_           = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.核价修理厂_                 = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.核价修理厂名称_               = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.估损单号_                  = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.核价通过时间_                = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.定损员机构_                 = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.定损员代码_                 = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.定损员名称_                 = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.结案车商分公司_               = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.结案车商部门组名称_             = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.结案车商代码_                = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.结案车商名称_                = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.推荐车商与结案车商是否一致_         = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.结案修理厂归属公司代码_           = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.结案修理厂归属公司名称_           = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.结案修理厂代码_               = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.结案修理厂名称_               = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.车辆进厂时间_                = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.车辆出厂时间_                = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.结案时间_                  = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.事故经过_                  = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.数据更新日期_                = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.备注_                    = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.估损单模板_                 = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.返修开关_报案_               = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.送修开关_报案_               = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.返修开关_核价_               = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.送修开关_核价_               = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.返修开关_结案_               = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.送修开关_结案_               = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.查勘员分公司名称_              = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.查勘员代码_                 = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.查勘员名称_                 = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.核价修理厂归属中支_             = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.结案修理厂归属中支_             = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.是否诉讼_                  = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.座席推荐分公司代码_             = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.座席推荐分公司名称_             = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.座席推荐车商名代码_             = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.座席推荐车商名称_              = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.座席推荐操作类型_              = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.座席推荐排名_                = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第一次推荐分公司代码_            = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第一次推荐分公司名称_            = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第一次推荐车商代码_             = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第一次推荐车商名称_             = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第一次推荐工具_               = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第一次推荐操作类型_             = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第一次推荐排名_其他推荐信息_        = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第二次推荐分公司代码_            = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第二次推荐分公司名称_            = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第二次推荐车商代码_             = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第二次推荐车商名称_             = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第二次推荐工具_               = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第二次推荐操作类型_             = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第二次推荐排名_其他推荐信息_        = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第三次推荐分公司代码_            = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第三次推荐分公司名称_            = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第三次推荐车商代码_             = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第三次推荐车商名称_             = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第三次推荐工具_               = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第三次推荐操作类型_             = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.第三次推荐排名_其他推荐信息_        = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.其他推荐信息_                = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.推荐失败具体原因_              = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.是否现场报案_                = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.报案地点_                  = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		record.是否在厂报案_                = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );

		recordVector.push_back( record );

		rowIndex++;
	}

	pBook->release();
}

void LoadRepairOrderFromXls( const std::wstring &       filePath,
                             unsigned                   sheetIndex,
                             unsigned                   startRowIndex,
                             std::vector<RepairOrder> & orderVector )
{
	Book *  pBook  = xlCreateBookW();
	Sheet * pSheet = nullptr;

	if ( pBook == nullptr )
	{
		throw runtime_error( "libxl库加载失败！" );
	}

	setKey( pBook );

	if ( pBook->load( filePath.c_str() ) != true )
	{
		string errorMessage = "打开文件失败！";
		errorMessage.append( pBook->errorMessage() );

		throw runtime_error( errorMessage );
	}

	pSheet = pBook->getSheet( sheetIndex );

	if ( pSheet == nullptr )
	{
		string errorMessage = "读取sheet失败！";
		errorMessage.append( pBook->errorMessage() );

		pBook->release();

		throw runtime_error( errorMessage );
	}

	int lastRowIndex  = pSheet->lastRow();
	int firstRowIndex = pSheet->firstRow();
	int rowIndex      = firstRowIndex + startRowIndex;

	while ( rowIndex <= lastRowIndex )
	{
		int colunmIndex = pSheet->firstCol();

		// const wstring && branchName                  = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		// const wstring && orderNo                     = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		// const wstring && orderType                   = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		// const wstring && notifyNo                    = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		// const wstring && damageArea                  = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		// const wstring && damageDate                  = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		// const wstring && generatingDate              = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		// const wstring && policyNo                    = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		// const wstring && policyNoJQX                 = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		// const wstring && plateNumber                 = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		// const wstring && brandName                   = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		// const wstring && isInsuranceObject           = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		// const wstring && isSuccess                   = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		// const wstring && recommandDealerCode         = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		// const wstring && recommandDealerName         = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		// const wstring && recommandDealerCodeInNotify = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		// const wstring && recommandDealerNameInNotify = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		// const wstring && recommandDealerNameInSurvey = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		// const wstring && agentName                   = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		// const wstring && surveyor                    = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		// const wstring && checkDate                   = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		// const wstring && repairingStartDate          = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		// const wstring && repairingFinishDate         = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		// const wstring && status                      = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		// const wstring && lostItemID                  = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		// const wstring && surveyorRecommandStatus     = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
		//
		// //空行跳过
		// if ( orderNo.empty() == true )
		// {
		// 	rowIndex++;
		//
		// 	continue;
		// }
		//
		// RepairOrder order( branchName,
		//                    orderNo,
		//                    orderType,
		//                    notifyNo,
		//                    damageArea,
		//                    damageDate,
		//                    generatingDate,
		//                    policyNo,
		//                    policyNoJQX,
		//                    plateNumber,
		//                    brandName,
		//                    isInsuranceObject,
		//                    isSuccess,
		//                    recommandDealerCode,
		//                    recommandDealerName,
		//                    recommandDealerCodeInNotify,
		//                    recommandDealerNameInNotify,
		//                    recommandDealerNameInSurvey,
		//                    agentName,
		//                    surveyor,
		//                    checkDate,
		//                    repairingStartDate,
		//                    repairingFinishDate,
		//                    status,
		//                    lostItemID,
		//                    surveyorRecommandStatus );
		//
		// orderVector.push_back( order );

		rowIndex++;
	}

	pBook->release();
}
