//如果文件是utf-8编码存放，要注意sql语句编码和ocilib库版本的问题。
#include <ocilib.hpp>
#include <stdexcept>
#include <QString>
#include "ImportToOracle.h"
#include "../../../db/ocilib/db_oper.h"

using namespace std;
using namespace ocilib;


/************************************************
* \brief 向oracle数据库写入车商业绩表,C++实现。
* \param userName oracle数据库用户名
* \param password oracle数据库密码
* \param tnsName oracle TNS名称
* \param orderVector 车商业绩表数据
************************************************/
void ImportCarDealerAchievementToOracleCpp( const std::string &                       userName,
                                            const std::string &                       password,
                                            const std::string &                       tnsName,
                                            const std::vector<CarDealerAchievement> & achievementVector )
{
	ostring sqlImport =
			"BEGIN \n"
			"  car_dealer.data_import_util_pkg.import_cardealer_achvmnt( :a_the_year, \n"
			"                                                            :a_the_month, \n"
			"                                                            :a_car_dealer_code, \n"
			"                                                            :a_checked_achievement, \n"
			"                                                            :a_policy_amount, \n"
			"                                                            :a_cpic_amount, \n"
			"                                                            :a_picc_amount , \n"
			"                                                            :a_pingan_amount, \n"
			"                                                            :a_others_amount ); \n"
			"END; ";

	//初始化
	try
	{
		Environment::Initialize();
	}
	catch ( exception & error )
	{
		string errorMessage = "ocilib初始化失败！";
		errorMessage.append( error.what() );

		throw runtime_error( errorMessage );
	}

	Connection * pConn = nullptr;
	Statement *  pStmt = nullptr;

	try
	{
		pConn = new Connection( tnsName, userName, password );
	}
	catch ( exception & error )
	{
		string errorMessage = "连接oracle失败！";
		errorMessage.append( error.what() );

		Environment::Cleanup();

		throw runtime_error( errorMessage );
	}

	try
	{
		pStmt = new Statement( *pConn );

		pStmt->Prepare( sqlImport );
		pStmt->AllowRebinding( true );

		for ( auto iter = achievementVector.begin();
		      iter != achievementVector.end();
		      ++iter )
		{
			string theYear            = QString::fromStdWString( iter->getTheYear() ).toStdString().c_str();
			string theMonth           = QString::fromStdWString( iter->getTheMonth() ).toStdString().c_str();
			string carDealerCode      = QString::fromStdWString( iter->getCarDealerCode() ).toStdString().c_str();
			string checkedAchievement = QString( "%1" ).arg( static_cast<double>(iter->getCheckedAchievement()) ).toStdString();
			string policyAmount       = QString( "%1" ).arg( iter->getPolicyAmount() ).toStdString();
			string cpicAmount         = QString( "%1" ).arg( iter->getCpicAmount() ).toStdString();
			string piccAmount         = QString( "%1" ).arg( iter->getPiccAmount() ).toStdString();
			string pinganAmount       = QString( "%1" ).arg( iter->getPinganAmount() ).toStdString();
			string othersAmount       = QString( "%1" ).arg( iter->getOthersAmount() ).toStdString();

			pStmt->Bind<ostring, int>( ostring( ":a_the_year" ), theYear, 0, BindInfo::BindDirectionValues::In );
			pStmt->Bind<ostring, int>( ostring( ":a_the_month" ), theMonth, 0, BindInfo::BindDirectionValues::In );
			pStmt->Bind<ostring, int>( ostring( ":a_car_dealer_code" ), carDealerCode, 0, BindInfo::BindDirectionValues::In );
			pStmt->Bind<ostring, int>( ostring( ":a_checked_achievement" ), checkedAchievement, 0, BindInfo::BindDirectionValues::In );
			pStmt->Bind<ostring, int>( ostring( ":a_policy_amount" ), policyAmount, 0, BindInfo::BindDirectionValues::In );
			pStmt->Bind<ostring, int>( ostring( ":a_cpic_amount" ), cpicAmount, 0, BindInfo::BindDirectionValues::In );
			pStmt->Bind<ostring, int>( ostring( ":a_picc_amount" ), piccAmount, 0, BindInfo::BindDirectionValues::In );
			pStmt->Bind<ostring, int>( ostring( ":a_pingan_amount" ), pinganAmount, 0, BindInfo::BindDirectionValues::In );
			pStmt->Bind<ostring, int>( ostring( ":a_others_amount" ), othersAmount, 0, BindInfo::BindDirectionValues::In );

			pStmt->ExecutePrepared();
		}
	}
	catch ( exception & error )
	{
		string errorMessage = "语句执行失败！";
		errorMessage.append( error.what() );

		Environment::Cleanup();

		throw runtime_error( errorMessage );
	}

	Environment::Cleanup();
}


/************************************************
* \brief 向oracle数据库写入车商业绩表
* \param userName oracle数据库用户名
* \param password oracle数据库密码
* \param tnsName oracle TNS名称
* \param orderVector 车商业绩表数据
************************************************/
void ImportCarDealerAchievementToOracle( std::string                         userName,
                                         std::string                         password,
                                         std::string                         tnsName,
                                         std::vector<CarDealerAchievement> & achievementVector )
{
	OCI_Connection * pConnection = nullptr;
	OCI_Statement *  pStatement  = nullptr;
	int              returnCode  = 0;

	const otext * szSqlImport =
			"BEGIN "
			"  car_dealer.data_import_util_pkg.import_cardealer_achvmnt( :a_the_year, "
			"                                                            :a_the_month, "
			"                                                            :a_car_dealer_code, "
			"                                                            :a_checked_achievement, "
			"                                                            :a_policy_amount, "
			"                                                            :a_cpic_amount, "
			"                                                            :a_picc_amount , "
			"                                                            :a_pingan_amount, "
			"                                                            :a_others_amount ); "
			"END; ";

	//初始化
	returnCode = OCI_Initialize( l_error_handler, nullptr, OCI_ENV_DEFAULT );

	if ( static_cast<bool>(returnCode) == false )
	{
		string errorMessage( "ocilib初始化错误:" );
		errorMessage.append( get_last_error_message() );

		throw runtime_error( errorMessage );
	}

	pConnection = OCI_ConnectionCreate( tnsName.c_str(),
	                                    userName.c_str(),
	                                    password.c_str(),
	                                    OCI_SESSION_DEFAULT );

	pStatement = OCI_StatementCreate( pConnection );

	OCI_AllowRebinding( pStatement, true );
	OCI_Prepare( pStatement, szSqlImport );

	for ( auto iterAchievement = achievementVector.begin();
	      iterAchievement != achievementVector.end();
	      ++iterAchievement )
	{
		string checkedAchievement = QString( "%1" ).arg( static_cast<double>(iterAchievement->getCheckedAchievement()) ).toStdString();
		string policyAmount       = QString( "%1" ).arg( iterAchievement->getPolicyAmount() ).toStdString();
		string cpicAmount         = QString( "%1" ).arg( iterAchievement->getCpicAmount() ).toStdString();
		string piccAmount         = QString( "%1" ).arg( iterAchievement->getPiccAmount() ).toStdString();
		string pinganAmount       = QString( "%1" ).arg( iterAchievement->getPinganAmount() ).toStdString();
		string othersAmount       = QString( "%1" ).arg( iterAchievement->getOthersAmount() ).toStdString();
	}
}

/************************************************
* \brief 向oracle数据库写入车商方案表
* \param userName oracle数据库用户名
* \param password oracle数据库密码
* \param tnsName oracle TNS名称
* \param orderVector 车商方案表数据
************************************************/
void ImportCarDealerSchemeToOracle( const std::string &            userName,
                                    const std::string &            password,
                                    const std::string &            tnsName,
                                    std::vector<CarDealerScheme> & schemeVector )
{
	//防御性验证
	if ( userName.empty() == true ||
	     password.empty() == true ||
	     tnsName.empty() == true ||
	     schemeVector.empty() == true )
	{
		return;
	}

	Connection * pConnection = nullptr;
	Statement *  pStatement  = nullptr;

	ostring sqlInsertScheme =
			"begin \n"
			"  car_dealer.data_import_util_pkg.import_cardealer_scheme( :the_year, \n"
			"                                                        :the_month, \n"
			"                                                        :car_dealer_code, \n"
			"                                                        :man_hour_price, \n"
			"                                                        :part_price, \n"
			"                                                        :claim_support, \n"
			"                                                        :scheme, \n"
			"                                                        :is_qualified ); \n"
			"end; ";

	//初始化
	try
	{
		Environment::Initialize();
	}
	catch ( exception & error )
	{
		QString errorMessage = "初始化ocilib失败！";
		errorMessage.append( QString::fromLocal8Bit( error.what() ) );

		throw runtime_error( errorMessage.toLocal8Bit() );
	}

	//
	try
	{
		pConnection = new Connection( tnsName, userName, password );
	}
	catch ( exception & error )
	{
	}

	//准备语句
	try
	{
		pStatement = new Statement( *pConnection );

		pStatement->Prepare( sqlInsertScheme );
		pStatement->AllowRebinding( true );

		for ( auto iterScheme = schemeVector.begin();
		      iterScheme != schemeVector.end();
		      ++iterScheme )
		{
			string theYear       = QString::fromStdWString( iterScheme->getTheYear() ).toLocal8Bit();
			string theMonth      = QString::fromStdWString( iterScheme->getTheMonth() ).toLocal8Bit();
			string carDealerCode = QString::fromStdWString( iterScheme->getCarDealerCode() ).toLocal8Bit();
			string manHourPrice  = QString::fromStdWString( iterScheme->getManHourPrice() ).toLocal8Bit();
			string partPrice     = QString::fromStdWString( iterScheme->getPartPrice() ).toLocal8Bit();
			string claimSupport  = QString::fromStdWString( iterScheme->getCarDealerCode() ).toLocal8Bit();
			string scheme        = QString::fromStdWString( iterScheme->getScheme() ).toLocal8Bit();
			string isQualified   = QString::fromStdWString( iterScheme->getIsQualified() ).toLocal8Bit();

			try
			{
				pStatement->Bind<ostring, int>( ostring( ":the_year" ), theYear, theYear.size(), BindInfo::BindDirectionValues::In );
				pStatement->Bind<ostring, int>( ostring( ":the_month" ), theMonth, theMonth.size(), BindInfo::BindDirectionValues::In );
				pStatement->Bind<ostring, int>( ostring( ":car_dealer_code" ), carDealerCode, carDealerCode.size(), BindInfo::BindDirectionValues::In );
				pStatement->Bind<ostring, int>( ostring( ":man_hour_price" ), manHourPrice, manHourPrice.size(), BindInfo::BindDirectionValues::In );
				pStatement->Bind<ostring, int>( ostring( ":claim_support" ), claimSupport, claimSupport.size(), BindInfo::BindDirectionValues::In );
				pStatement->Bind<ostring, int>( ostring( ":part_price" ), partPrice, partPrice.size(), BindInfo::BindDirectionValues::In );
				pStatement->Bind<ostring, int>( ostring( ":scheme" ), scheme, scheme.size(), BindInfo::BindDirectionValues::In );
				pStatement->Bind<ostring, int>( ostring( ":is_qualified" ), isQualified, isQualified.size(), BindInfo::BindDirectionValues::In );

				pStatement->ExecutePrepared();
			}
			catch ( exception & error )
			{
			}
		}
	}
	catch ( exception & error )
	{
		Environment::Cleanup();

		throw runtime_error( error.what() );
	}

	Environment::Cleanup();
}


/************************************************
* \brief 向oracle数据库写入送返修工单信息
* \param userName oracle数据库用户名
* \param password oracle数据库密码
* \param tnsName oracle TNS名称
* \param orderVector 送返修工单数据
************************************************/
void ImportRepairOrderToOracle( const std::string &              userName,
                                const std::string &              password,
                                const std::string &              tnsName,
                                const std::vector<RepairOrder> & orderVector )
{
	OCI_Connection * pConn = nullptr;
	OCI_Statement *  pStmt = nullptr;

	int           returnCode  = 0;
	const otext * szSqlImport =
			"BEGIN"
			"  car_dealer.data_import_util_pkg.import_repairing_order(:a_branch_name, \n"
			"                                                          :a_order_no,\n"
			"                                                          :a_order_type,\n"
			"                                                          :a_notify_no,\n"
			"                                                          :a_damage_area,\n"
			"                                                          :a_damage_date,\n"
			"                                                          :a_generating_date,\n\n"
			"                                                          :a_policy_no,"
			"                                                          :a_policy_no_jqx,\n"
			"                                                          :a_plate_number,\n"
			"                                                          :a_brand_name,\n"
			"                                                          :a_is_insurance_object,\n"
			"                                                          :a_is_success,\n"
			"                                                          :a_recommend_dealer_code,\n"
			"                                                          :a_recommend_dealer_name,\n"
			"                                                          :a_recomm_dealer_name_in_notify,\n"
			"                                                          :a_recomm_dealer_name_in_survey,\n"
			"                                                          :a_agent_name,\n"
			"                                                          :a_surveyor,\n"
			"                                                          :a_check_date,\n"
			"                                                          :a_repairing_start_date,\n"
			"                                                          :a_repairing_finish_date,\n"
			"                                                          :a_status,\n"
			"                                                          :a_lost_item_id,\n"
			"                                                          :a_surveyor_recomm_status );\n"
			"END;";

	//初始化
	returnCode = OCI_Initialize( l_error_handler, nullptr, OCI_ENV_DEFAULT );

	if ( static_cast<bool>(returnCode) == false )
	{
		string errorMessage( "ocilib初始化错误:" );
		errorMessage.append( get_last_error_message() );

		throw runtime_error( errorMessage );
	}

	pConn = OCI_ConnectionCreate( tnsName.c_str(),
	                              userName.c_str(),
	                              password.c_str(),
	                              OCI_SESSION_DEFAULT );
	pStmt = OCI_StatementCreate( pConn );

	try
	{
		OCI_AllowRebinding( pStmt, true );
		OCI_Prepare( pStmt, szSqlImport );
	}
	catch ( runtime_error & error )
	{
		OCI_ConnectionFree( pConn );
		OCI_Cleanup();

		throw error;
	}

	for ( auto iterOrder = orderVector.begin();
	      iterOrder != orderVector.end();
	      ++iterOrder )
	{
		try
		{
			string branchName                        = QString::fromStdWString( iterOrder->getBranchName() ).toLocal8Bit();
			string orderNo                           = QString::fromStdWString( iterOrder->getOrderNo() ).toLocal8Bit();
			string orderType                         = QString::fromStdWString( iterOrder->getOrderType() ).toLocal8Bit();
			string notifyNo                          = QString::fromStdWString( iterOrder->getNotifyNo() ).toLocal8Bit();
			string damageArea                        = QString::fromStdWString( iterOrder->getDamageArea() ).toLocal8Bit();
			string damageDate                        = QString::fromStdWString( iterOrder->getDamageDate() ).toLocal8Bit();
			string genDate                           = QString::fromStdWString( iterOrder->getGeneratingDate() ).toLocal8Bit();
			string policyNo                          = QString::fromStdWString( iterOrder->getPolicyNo() ).toLocal8Bit();
			string policyNoJQX                       = QString::fromStdWString( iterOrder->getPolicyNoJqx() ).toLocal8Bit();
			string plateNumber                       = QString::fromStdWString( iterOrder->getPlateNumber() ).toLocal8Bit();;
			string brandName                         = QString::fromStdWString( iterOrder->getBrandName() ).toLocal8Bit();;
			string isInsuranceObject                 = QString::fromStdWString( iterOrder->getIsInsuranceObject() ).toLocal8Bit();
			string isSuccess                         = QString::fromStdWString( iterOrder->getIsSuccess() ).toLocal8Bit();
			string recommandDealerCode               = QString::fromStdWString( iterOrder->getRecommandDealerCode() ).toLocal8Bit();
			string recommandDealerName               = QString::fromStdWString( iterOrder->getRecommandDealerName() ).toLocal8Bit();
			string recommandDealerCodeInNameInNotify = QString::fromStdWString( iterOrder->getRecommandDealerNameInNotify() ).toLocal8Bit();
			string recommandDealerCodeInSurvy        = QString::fromStdWString( iterOrder->getRecommandDealerNameInSurvey() ).toLocal8Bit();
			string agentName                         = QString::fromStdWString( iterOrder->getAgentName() ).toLocal8Bit();
			string surveyor                          = QString::fromStdWString( iterOrder->getSurveyor() ).toLocal8Bit();
			string repairingStartDate                = QString::fromStdWString( iterOrder->getRepairingStartDate() ).toLocal8Bit();
			string repairingEndDate                  = QString::fromStdWString( iterOrder->getRepairingFinishDate() ).toLocal8Bit();
			string checkDate                         = QString::fromStdWString( iterOrder->getCheckDate() ).toLocal8Bit();
			string status                            = QString::fromStdWString( iterOrder->getStatus() ).toLocal8Bit();
			string lostItemID                        = QString::fromStdWString( iterOrder->getLostItemId() ).toLocal8Bit();
			string surveyorRecommandStatus           = QString::fromStdWString( iterOrder->getSurveyorRecommandStatus() ).toLocal8Bit();

			OCI_BindString( pStmt, ":a_branch_name", const_cast<otext*>(branchName.c_str()), 0 );
			OCI_BindString( pStmt, ":a_order_no", const_cast<otext*>(orderNo.c_str()), 0 );
			OCI_BindString( pStmt, ":a_order_type", const_cast<otext*>(orderType.c_str()), 0 );
			OCI_BindString( pStmt, ":a_notify_no", const_cast<otext*>(notifyNo.c_str()), 0 );
			OCI_BindString( pStmt, ":a_damage_area", const_cast<otext*>(damageArea.c_str()), 0 );
			OCI_BindString( pStmt, ":a_policy_no", const_cast<otext*>(policyNo.c_str()), 0 );
			OCI_BindString( pStmt, ":a_policy_no_jqx", const_cast<otext*>(policyNoJQX.c_str()), 0 );
			OCI_BindString( pStmt, ":a_plate_number", const_cast<otext*>(plateNumber.c_str()), 0 );
			OCI_BindString( pStmt, ":a_brand_name", const_cast<otext*>(brandName.c_str()), 0 );
			OCI_BindString( pStmt, ":a_is_insurance_object", const_cast<otext*>(isInsuranceObject.c_str()), 0 );
			OCI_BindString( pStmt, ":a_is_success", const_cast<otext*>(isSuccess.c_str()), 0 );
			OCI_BindString( pStmt, ":a_recommend_dealer_code", const_cast<otext*>(recommandDealerCode.c_str()), 0 );
			OCI_BindString( pStmt, ":a_recommend_dealer_name", const_cast<otext*>(recommandDealerName.c_str()), 0 );
			OCI_BindString( pStmt, ":a_recomm_dealer_name_in_notify", const_cast<otext*>(recommandDealerCodeInNameInNotify.c_str()), 0 );
			OCI_BindString( pStmt, ":a_recomm_dealer_name_in_survey", const_cast<otext*>(recommandDealerCodeInSurvy.c_str()), 0 );
			OCI_BindString( pStmt, ":a_agent_name", const_cast<otext*>(agentName.c_str()), 0 );
			OCI_BindString( pStmt, ":a_surveyor", const_cast<otext*>(surveyor.c_str()), 0 );
			OCI_BindString( pStmt, ":a_status", const_cast<otext*>(status.c_str()), 0 );
			OCI_BindString( pStmt, ":a_lost_item_id", const_cast<otext*>(lostItemID.c_str()), 0 );
			OCI_BindString( pStmt, ":a_surveyor_recomm_status", const_cast<otext*>(surveyorRecommandStatus.c_str()), 0 );

			OCI_BindString( pStmt, ":a_damage_date", const_cast<otext*>(damageDate.c_str()), 0 );
			OCI_BindString( pStmt, ":a_generating_date", const_cast<otext*>(genDate.c_str()), 0 );
			OCI_BindString( pStmt, ":a_check_date", const_cast<otext*>(checkDate.c_str()), 0 );
			OCI_BindString( pStmt, ":a_repairing_start_date", const_cast<otext*>(repairingStartDate.c_str()), 0 );
			OCI_BindString( pStmt, ":a_repairing_finish_date", const_cast<otext*>(repairingEndDate.c_str()), 0 );

			OCI_Execute( pStmt );
		}
		catch ( runtime_error & error )
		{
			//输出日志，让过程继续
			string errorMessage = "送返修工单编号";

			errorMessage.append( QString::fromStdWString( iterOrder->getOrderNo() ).toLocal8Bit() );
			errorMessage.append( "保存失败，提示信息:" );
			errorMessage.append( error.what() );

			output_error_message( errorMessage );
		}
	}

	OCI_Commit( pConn );
	OCI_ConnectionFree( pConn );
	OCI_Cleanup();
}

void ImportRepairSuggestionToOracle( const std::string &                         userName,
                                     const std::string &                         password,
                                     const std::string &                         tnsName,
                                     const std::vector<RepairSuggestionRecord> & recordVector )
{
	OCI_Connection * pConn      = nullptr;
	OCI_Statement *  pStmt      = nullptr;
	int              returnCode = 0;

	const otext * szSql =
			"BEGIN \n"
			"    car_dealer.data_import_util_pkg.import_repairing_suggestion(:a_order_no, \n"
			"                                                                :a_order_type, \n"
			"                                                                :a_notify_no, \n"
			"                                                                :a_sug_cardealer_code, \n"
			"                                                                :a_sug_cardealer_name, \n"
			"                                                                :a_damage_date, \n"
			"                                                                :a_plateNo, \n"
			"                                                                :a_brand_name, \n"
			"                                                                :a_message_type, \n"
			"                                                                :a_sending_date, \n"
			"                                                                :a_data_source); \n"
			"END;";

	returnCode = OCI_Initialize( error_handler, nullptr, OCI_ENV_CONTEXT );

	if ( static_cast<bool>(returnCode) == false )
	{
		string errorMessage( "ocilib初始化错误:" );
		errorMessage.append( get_last_error_message() );

		throw runtime_error( errorMessage );
	}

	pConn = OCI_ConnectionCreate( tnsName.c_str(),
	                              userName.c_str(),
	                              password.c_str(),
	                              OCI_SESSION_DEFAULT );
	pStmt = OCI_StatementCreate( pConn );

	try
	{
		OCI_AllowRebinding( pStmt, true );
		OCI_Prepare( pStmt, szSql );
	}
	catch ( runtime_error & error )
	{
		OCI_ConnectionFree( pConn );
		OCI_Cleanup();

		throw error;
	}

	for ( auto iterOrder = recordVector.begin();
	      iterOrder != recordVector.end();
	      ++iterOrder )
	{
		try
		{
			//绑定数据
			string 工单号    = QString::fromStdWString( iterOrder->getOrderNo() ).toLocal8Bit();
			string 工单类型   = QString::fromStdWString( iterOrder->getOrderType() ).toLocal8Bit();
			string 报案号    = QString::fromStdWString( iterOrder->getNotifyNo() ).toLocal8Bit();
			string 推荐车商代码 = QString::fromStdWString( iterOrder->getSuggestedCarDealerCode() ).toLocal8Bit();
			string 推荐车商名称 = QString::fromStdWString( iterOrder->getSuggestedCarDealerName() ).toLocal8Bit();
			string 出险日期   = QString::fromStdWString( iterOrder->getDamageDate() ).toLocal8Bit();
			string 短信类型   = QString::fromStdWString( iterOrder->getMessageType() ).toLocal8Bit();
			string 短信日期   = QString::fromStdWString( iterOrder->getMessageSendingDate() ).toLocal8Bit();
			string 数据来源   = QString::fromStdWString( iterOrder->getDataSource() ).toLocal8Bit();
			string 车牌号    = QString::fromStdWString( iterOrder->getPlateNumber() ).toLocal8Bit();
			string 厂牌型号   = QString::fromStdWString( iterOrder->getBrandName() ).toLocal8Bit();

			if ( 工单号.empty() == true )
			{
				continue;
			}

			//执行语句
			OCI_BindString( pStmt, ":a_order_no", (otext*)工单号.c_str(), 工单号.size() );
			OCI_BindString( pStmt, ":a_order_type", (otext*)工单类型.c_str(), 工单类型.size() );
			OCI_BindString( pStmt, ":a_notify_no", (otext*)报案号.c_str(), 报案号.size() );
			OCI_BindString( pStmt, ":a_sug_cardealer_code", (otext*)推荐车商代码.c_str(), 推荐车商代码.size() );
			OCI_BindString( pStmt, ":a_sug_cardealer_name", (otext*)推荐车商名称.c_str(), 推荐车商名称.size() );
			OCI_BindString( pStmt, ":a_damage_date", (otext*)出险日期.c_str(), 出险日期.size() );
			OCI_BindString( pStmt, ":a_plateNo", (otext*)车牌号.c_str(), 车牌号.size() );
			OCI_BindString( pStmt, ":a_message_type", (otext*)短信类型.c_str(), 短信类型.size() );
			OCI_BindString( pStmt, ":a_sending_date", (otext*)短信日期.c_str(), 短信日期.size() );
			OCI_BindString( pStmt, ":a_data_source", (otext*)数据来源.c_str(), 数据来源.size() );
			OCI_BindString( pStmt, ":a_brand_name", (otext*)厂牌型号.c_str(), 厂牌型号.size() );

			returnCode = OCI_Execute( pStmt );
		}
		catch ( runtime_error & error )
		{
			//rollback，停止保存
			string errorMessage = "送返修工单编号";

			errorMessage.append( QString::fromStdWString( iterOrder->getOrderNo() ).toLocal8Bit() );
			errorMessage.append( "保存失败，提示信息:" );
			errorMessage.append( error.what() );

			//output_error_message( errorMessage );

			OCI_Rollback( pConn );
			OCI_ConnectionFree( pConn );
			OCI_Cleanup();

			throw runtime_error( errorMessage );
		}
	}

	OCI_Commit( pConn );
	OCI_ConnectionFree( pConn );
	OCI_Cleanup();
}

void ImportNewRepairMonitorToOracle( const std::string &                               userName,
                                     const std::string &                               password,
                                     const std::string &                               tnsName,
                                     const std::vector<NewRepairMonitorReportRecord> & recordVector )
{
	OCI_Connection * pConnection = nullptr;
	OCI_Statement *  pStatement  = nullptr;
	int              returnCode  = -1;

	QString sql = QString::fromUtf8( 
		"BEGIN   " \
		"    car_dealer.data_import_util_pkg.导入新送返修监控报表(:1,   " \
		"                                               :2,   " \
		"                                               :3,   " \
		"                                               :4,   " \
		"                                               :5,   " \
		"                                               :6,   " \
		"                                               :7,   " \
		"                                               :8,   " \
		"                                               :9,   " \
		"                                               :10,   " \
		"                                               :11,   " \
		"                                               :12,   " \
		"                                               :13,   " \
		"                                               :14,   " \
		"                                               :15,   " \
		"                                               :16,   " \
		"                                               :17,   " \
		"                                               :18,   " \
		"                                               :19,   " \
		"                                               :20,   " \
		"                                               :21,   " \
		"                                               :22,   " \
		"                                               :23,   " \
		"                                               :24,   " \
		"                                               :25,   " \
		"                                               :26,   " \
		"                                               :27,   " \
		"                                               :28,   " \
		"                                               :29,   " \
		"                                               :30,   " \
		"                                               :31,   " \
		"                                               :32,   " \
		"                                               :33,   " \
		"                                               :34,   " \
		"                                               :35,   " \
		"                                               :36,   " \
		"                                               :37,   " \
		"                                               :38,   " \
		"                                               :39,   " \
		"                                               :40,   " \
		"                                               :41,   " \
		"                                               :42,   " \
		"                                               :43,   " \
		"                                               :44,   " \
		"                                               :45,   " \
		"                                               :46,   " \
		"                                               :47,   " \
		"                                               :48,   " \
		"                                               :49,   " \
		"                                               :50,   " \
		"                                               :51,   " \
		"                                               :52,   " \
		"                                               :53,   " \
		"                                               :54,   " \
		"                                               :55,   " \
		"                                               :56,   " \
		"                                               :57,   " \
		"                                               :58,   " \
		"                                               :59,   " \
		"                                               :60,   " \
		"                                               :61,   " \
		"                                               :62,   " \
		"                                               :63,   " \
		"                                               :64,   " \
		"                                               :65,   " \
		"                                               :66,   " \
		"                                               :67,   " \
		"                                               :68,   " \
		"                                               :69,   " \
		"                                               :70,   " \
		"                                               :71,   " \
		"                                               :72,   " \
		"                                               :73,   " \
		"                                               :74,   " \
		"                                               :75,   " \
		"                                               :76,   " \
		"                                               :77,   " \
		"                                               :78,   " \
		"                                               :79,   " \
		"                                               :80,   " \
		"                                               :81,   " \
		"                                               :82,   " \
		"                                               :83,   " \
		"                                               :84,   " \
		"                                               :85,   " \
		"                                               :86,   " \
		"                                               :87,   " \
		"                                               :88,   " \
		"                                               :89,   " \
		"                                               :90,   " \
		"                                               :91,   " \
		"                                               :92,   " \
		"                                               :93,   " \
		"                                               :94,   " \
		"                                               :95,   " \
		"                                               :96,   " \
		"                                               :97,   " \
		"                                               :98,   " \
		"                                               :99,   " \
		"                                               :100,   " \
		"                                               :101,   " \
		"                                               :102,   " \
		"                                               :103,   " \
		"                                               :104,   " \
		"                                               :105,   " \
		"                                               :106,   " \
		"                                               :107,   " \
		"                                               :108,   " \
		"                                               :109,   " \
		"                                               :110,   " \
		"                                               :111,   " \
		"                                               :112,   " \
		"                                               :113,   " \
		"                                               :114,   " \
		"                                               :115,   " \
		"                                               :116,   " \
		"                                               :117,   " \
		"                                               :118,   " \
		"                                               :119,   " \
		"                                               :120,   " \
		"                                               :121,   " \
		"                                               :122,   " \
		"                                               :123,   " \
		"                                               :124,   " \
		"                                               :125,   " \
		"                                               :126,   " \
		"                                               :127,   " \
		"                                               :128,   " \
		"                                               :129,   " \
		"                                               :130,   " \
		"                                               :131,   " \
		"                                               :132,   " \
		"                                               :133,   " \
		"                                               :134,   " \
		"                                               :135,   " \
		"                                               :136,   " \
		"                                               :137,   " \
		"                                               :138,   " \
		"                                               :139,   " \
		"                                               :140,   " \
		"                                               :141,   " \
		"                                               :142,   " \
		"                                               :143,   " \
		"                                               :144,   " \
		"                                               :145,   " \
		"                                               :146,   " \
		"                                               :147,   " \
		"                                               :148,   " \
		"                                               :149,   " \
		"                                               :150,   " \
		"                                               :151,   " \
		"                                               :152,   " \
		"                                               :153,   " \
		"                                               :154,   " \
		"                                               :155,   " \
		"                                               :156,   " \
		"                                               :157 );   " \
	    "END;" );

	//初始化
	returnCode = OCI_Initialize( error_handler, nullptr, OCI_ENV_CONTEXT );

	if ( static_cast<bool>(returnCode) == false )
	{
		//ocilib加载错误
		throw runtime_error( "" );
	}

	//连接
	pConnection = OCI_ConnectionCreate( tnsName.c_str(),
	                                    userName.c_str(),
	                                    password.c_str(),
	                                    OCI_SESSION_DEFAULT );

	if ( pConnection == nullptr )
	{
		throw runtime_error( "" );
	}

	pStatement = OCI_StatementCreate( pConnection );

	if ( pStatement == nullptr )
	{
	}

	try
	{
		OCI_AllowRebinding( pStatement, true );
		OCI_Prepare( pStatement, sql.toLocal8Bit() );
	}
	catch ( runtime_error & error )
	{
		//绑定语句失败
	}

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

			if ( 报案号.empty() == true )
			{
				continue;
			}
			
			OCI_BindString(pStatement, (const otext*)(":1"), (otext*)(分公司名称.c_str()), 分公司名称.size());
			OCI_BindString(pStatement, (const otext*)(":2"), (otext*)(部门组名称.c_str()), 部门组名称.size());
			OCI_BindString(pStatement, (const otext*)(":3"), (otext*)(报案号.c_str()), 报案号.size());
			OCI_BindString(pStatement, (const otext*)(":4"), (otext*)(报案日期.c_str()), 报案日期.size());
			OCI_BindString(pStatement, (const otext*)(":5"), (otext*)(出险日期.c_str()), 出险日期.size());
			OCI_BindString(pStatement, (const otext*)(":6"), (otext*)(出险地点.c_str()), 出险地点.size());
			OCI_BindString(pStatement, (const otext*)(":7"), (otext*)(事故车目前位置.c_str()), 事故车目前位置.size());
			OCI_BindString(pStatement, (const otext*)(":8"), (otext*)(车损序号.c_str()), 车损序号.size());
			OCI_BindString(pStatement, (const otext*)(":9"), (otext*)(车牌.c_str()), 车牌.size());
			OCI_BindString(pStatement, (const otext*)(":10"), (otext*)(vin码.c_str()), vin码.size());
			OCI_BindString(pStatement, (const otext*)(":11"), (otext*)(车龄.c_str()), 车龄.size());
			OCI_BindString(pStatement, (const otext*)(":12"), (otext*)(品牌代码.c_str()), 品牌代码.size());
			OCI_BindString(pStatement, (const otext*)(":13"), (otext*)(品牌名称.c_str()), 品牌名称.size());
			OCI_BindString(pStatement, (const otext*)(":14"), (otext*)(车系名称.c_str()), 车系名称.size());
			OCI_BindString(pStatement, (const otext*)(":15"), (otext*)(使用性质名称.c_str()), 使用性质名称.size());
			OCI_BindString(pStatement, (const otext*)(":16"), (otext*)(保单号.c_str()), 保单号.size());
			OCI_BindString(pStatement, (const otext*)(":17"), (otext*)(标的车三者车.c_str()), 标的车三者车.size());
			OCI_BindString(pStatement, (const otext*)(":18"), (otext*)(是否9座以下企业用车行政用车家庭自用车.c_str()), 是否9座以下企业用车行政用车家庭自用车.size());
			OCI_BindString(pStatement, (const otext*)(":19"), (otext*)(核价金额.c_str()), 核价金额.size());
			OCI_BindString(pStatement, (const otext*)(":20"), (otext*)(核损配件核损金额.c_str()), 核损配件核损金额.size());
			OCI_BindString(pStatement, (const otext*)(":21"), (otext*)(核损工时费核损金额.c_str()), 核损工时费核损金额.size());
			OCI_BindString(pStatement, (const otext*)(":22"), (otext*)(核损辅料核损金额.c_str()), 核损辅料核损金额.size());
			OCI_BindString(pStatement, (const otext*)(":23"), (otext*)(核损外修费核损金额.c_str()), 核损外修费核损金额.size());
			OCI_BindString(pStatement, (const otext*)(":24"), (otext*)(核损施救费核损金额.c_str()), 核损施救费核损金额.size());
			OCI_BindString(pStatement, (const otext*)(":25"), (otext*)(结案金额.c_str()), 结案金额.size());
			OCI_BindString(pStatement, (const otext*)(":26"), (otext*)(结案配件核损金额.c_str()), 结案配件核损金额.size());
			OCI_BindString(pStatement, (const otext*)(":27"), (otext*)(结案工时费核损金额.c_str()), 结案工时费核损金额.size());
			OCI_BindString(pStatement, (const otext*)(":28"), (otext*)(结案辅料核损金额.c_str()), 结案辅料核损金额.size());
			OCI_BindString(pStatement, (const otext*)(":29"), (otext*)(结案外修费核损金额.c_str()), 结案外修费核损金额.size());
			OCI_BindString(pStatement, (const otext*)(":30"), (otext*)(结案施救费核损金额.c_str()), 结案施救费核损金额.size());
			OCI_BindString(pStatement, (const otext*)(":31"), (otext*)(接报案人分公司名称.c_str()), 接报案人分公司名称.size());
			OCI_BindString(pStatement, (const otext*)(":32"), (otext*)(接报案人工号.c_str()), 接报案人工号.size());
			OCI_BindString(pStatement, (const otext*)(":33"), (otext*)(接报案人名称.c_str()), 接报案人名称.size());
			OCI_BindString(pStatement, (const otext*)(":34"), (otext*)(第一任务分派时间.c_str()), 第一任务分派时间.size());
			OCI_BindString(pStatement, (const otext*)(":35"), (otext*)(第一定损员分公司.c_str()), 第一定损员分公司.size());
			OCI_BindString(pStatement, (const otext*)(":36"), (otext*)(第一定损员部门组名称.c_str()), 第一定损员部门组名称.size());
			OCI_BindString(pStatement, (const otext*)(":37"), (otext*)(第一定损员代码.c_str()), 第一定损员代码.size());
			OCI_BindString(pStatement, (const otext*)(":38"), (otext*)(第一定损员名称.c_str()), 第一定损员名称.size());
			OCI_BindString(pStatement, (const otext*)(":39"), (otext*)(第一车商是否已阅读.c_str()), 第一车商是否已阅读.size());
			OCI_BindString(pStatement, (const otext*)(":40"), (otext*)(第一车上是否预约进厂.c_str()), 第一车上是否预约进厂.size());
			OCI_BindString(pStatement, (const otext*)(":41"), (otext*)(第一车商是否推荐失败.c_str()), 第一车商是否推荐失败.size());
			OCI_BindString(pStatement, (const otext*)(":42"), (otext*)(第一车商是否进厂确认.c_str()), 第一车商是否进厂确认.size());
			OCI_BindString(pStatement, (const otext*)(":43"), (otext*)(第一车商是否出场确认.c_str()), 第一车商是否出场确认.size());
			OCI_BindString(pStatement, (const otext*)(":44"), (otext*)(第二任务分派时间.c_str()), 第二任务分派时间.size());
			OCI_BindString(pStatement, (const otext*)(":45"), (otext*)(第二定损员分公司.c_str()), 第二定损员分公司.size());
			OCI_BindString(pStatement, (const otext*)(":46"), (otext*)(第二定损员部门组名称.c_str()), 第二定损员部门组名称.size());
			OCI_BindString(pStatement, (const otext*)(":47"), (otext*)(第二定损员代码.c_str()), 第二定损员代码.size());
			OCI_BindString(pStatement, (const otext*)(":48"), (otext*)(第二定损员名称.c_str()), 第二定损员名称.size());
			OCI_BindString(pStatement, (const otext*)(":49"), (otext*)(第二车商是否已阅读.c_str()), 第二车商是否已阅读.size());
			OCI_BindString(pStatement, (const otext*)(":50"), (otext*)(第二车上是否预约进厂.c_str()), 第二车上是否预约进厂.size());
			OCI_BindString(pStatement, (const otext*)(":51"), (otext*)(第二车商是否推荐失败.c_str()), 第二车商是否推荐失败.size());
			OCI_BindString(pStatement, (const otext*)(":52"), (otext*)(第二车商是否进厂确认.c_str()), 第二车商是否进厂确认.size());
			OCI_BindString(pStatement, (const otext*)(":53"), (otext*)(第二车商是否出场确认.c_str()), 第二车商是否出场确认.size());
			OCI_BindString(pStatement, (const otext*)(":54"), (otext*)(第三任务分派时间.c_str()), 第三任务分派时间.size());
			OCI_BindString(pStatement, (const otext*)(":55"), (otext*)(第三定损员分公司.c_str()), 第三定损员分公司.size());
			OCI_BindString(pStatement, (const otext*)(":56"), (otext*)(第三定损员部门组名称.c_str()), 第三定损员部门组名称.size());
			OCI_BindString(pStatement, (const otext*)(":57"), (otext*)(第三定损员代码.c_str()), 第三定损员代码.size());
			OCI_BindString(pStatement, (const otext*)(":58"), (otext*)(第三定损员名称.c_str()), 第三定损员名称.size());
			OCI_BindString(pStatement, (const otext*)(":59"), (otext*)(第三车商是否已阅读.c_str()), 第三车商是否已阅读.size());
			OCI_BindString(pStatement, (const otext*)(":60"), (otext*)(第三车上是否预约进厂.c_str()), 第三车上是否预约进厂.size());
			OCI_BindString(pStatement, (const otext*)(":61"), (otext*)(第三车商是否推荐失败.c_str()), 第三车商是否推荐失败.size());
			OCI_BindString(pStatement, (const otext*)(":62"), (otext*)(第三车商是否进厂确认.c_str()), 第三车商是否进厂确认.size());
			OCI_BindString(pStatement, (const otext*)(":63"), (otext*)(第三车商是否出场确认.c_str()), 第三车商是否出场确认.size());
			OCI_BindString(pStatement, (const otext*)(":64"), (otext*)(其他查勘员信息.c_str()), 其他查勘员信息.size());
			OCI_BindString(pStatement, (const otext*)(":65"), (otext*)(是否推荐.c_str()), 是否推荐.size());
			OCI_BindString(pStatement, (const otext*)(":66"), (otext*)(是否存在工单.c_str()), 是否存在工单.size());
			OCI_BindString(pStatement, (const otext*)(":67"), (otext*)(工单类型.c_str()), 工单类型.size());
			OCI_BindString(pStatement, (const otext*)(":68"), (otext*)(查勘员操作类型.c_str()), 查勘员操作类型.size());
			OCI_BindString(pStatement, (const otext*)(":69"), (otext*)(案件状态名称.c_str()), 案件状态名称.size());
			OCI_BindString(pStatement, (const otext*)(":70"), (otext*)(车状当前状态.c_str()), 车状当前状态.size());
			OCI_BindString(pStatement, (const otext*)(":71"), (otext*)(车状报案环节.c_str()), 车状报案环节.size());
			OCI_BindString(pStatement, (const otext*)(":72"), (otext*)(车状现场推荐环节.c_str()), 车状现场推荐环节.size());
			OCI_BindString(pStatement, (const otext*)(":73"), (otext*)(车状核价通过环节.c_str()), 车状核价通过环节.size());
			OCI_BindString(pStatement, (const otext*)(":74"), (otext*)(车状结案环节.c_str()), 车状结案环节.size());
			OCI_BindString(pStatement, (const otext*)(":75"), (otext*)(承保车商代码.c_str()), 承保车商代码.size());
			OCI_BindString(pStatement, (const otext*)(":76"), (otext*)(承保车商名称.c_str()), 承保车商名称.size());
			OCI_BindString(pStatement, (const otext*)(":77"), (otext*)(报案车商分公司名称.c_str()), 报案车商分公司名称.size());
			OCI_BindString(pStatement, (const otext*)(":78"), (otext*)(报案车商部门组名称.c_str()), 报案车商部门组名称.size());
			OCI_BindString(pStatement, (const otext*)(":79"), (otext*)(报案车商代码.c_str()), 报案车商代码.size());
			OCI_BindString(pStatement, (const otext*)(":80"), (otext*)(报案车商名称.c_str()), 报案车商名称.size());
			OCI_BindString(pStatement, (const otext*)(":81"), (otext*)(现场推荐车商分公司名称.c_str()), 现场推荐车商分公司名称.size());
			OCI_BindString(pStatement, (const otext*)(":82"), (otext*)(现场推荐车商代码.c_str()), 现场推荐车商代码.size());
			OCI_BindString(pStatement, (const otext*)(":83"), (otext*)(现场推荐车商名称.c_str()), 现场推荐车商名称.size());
			OCI_BindString(pStatement, (const otext*)(":84"), (otext*)(核价车商分公司名称.c_str()), 核价车商分公司名称.size());
			OCI_BindString(pStatement, (const otext*)(":85"), (otext*)(核价车商部门组名称.c_str()), 核价车商部门组名称.size());
			OCI_BindString(pStatement, (const otext*)(":86"), (otext*)(核价车商代码.c_str()), 核价车商代码.size());
			OCI_BindString(pStatement, (const otext*)(":87"), (otext*)(核价车商名称.c_str()), 核价车商名称.size());
			OCI_BindString(pStatement, (const otext*)(":88"), (otext*)(推荐车商与核价车商是否一致.c_str()), 推荐车商与核价车商是否一致.size());
			OCI_BindString(pStatement, (const otext*)(":89"), (otext*)(核价修理厂归属公司代码.c_str()), 核价修理厂归属公司代码.size());
			OCI_BindString(pStatement, (const otext*)(":90"), (otext*)(核价修理厂归属公司名称.c_str()), 核价修理厂归属公司名称.size());
			OCI_BindString(pStatement, (const otext*)(":91"), (otext*)(核价修理厂.c_str()), 核价修理厂.size());
			OCI_BindString(pStatement, (const otext*)(":92"), (otext*)(核价修理厂名称.c_str()), 核价修理厂名称.size());
			OCI_BindString(pStatement, (const otext*)(":93"), (otext*)(估损单号.c_str()), 估损单号.size());
			OCI_BindString(pStatement, (const otext*)(":94"), (otext*)(核价通过时间.c_str()), 核价通过时间.size());
			OCI_BindString(pStatement, (const otext*)(":95"), (otext*)(定损员机构.c_str()), 定损员机构.size());
			OCI_BindString(pStatement, (const otext*)(":96"), (otext*)(定损员代码.c_str()), 定损员代码.size());
			OCI_BindString(pStatement, (const otext*)(":97"), (otext*)(定损员名称.c_str()), 定损员名称.size());
			OCI_BindString(pStatement, (const otext*)(":98"), (otext*)(结案车商分公司.c_str()), 结案车商分公司.size());
			OCI_BindString(pStatement, (const otext*)(":99"), (otext*)(结案车商部门组名称.c_str()), 结案车商部门组名称.size());
			OCI_BindString(pStatement, (const otext*)(":100"), (otext*)(结案车商代码.c_str()), 结案车商代码.size());
			OCI_BindString(pStatement, (const otext*)(":101"), (otext*)(结案车商名称.c_str()), 结案车商名称.size());
			OCI_BindString(pStatement, (const otext*)(":102"), (otext*)(推荐车商与结案车商是否一致.c_str()), 推荐车商与结案车商是否一致.size());
			OCI_BindString(pStatement, (const otext*)(":103"), (otext*)(结案修理厂归属公司代码.c_str()), 结案修理厂归属公司代码.size());
			OCI_BindString(pStatement, (const otext*)(":104"), (otext*)(结案修理厂归属公司名称.c_str()), 结案修理厂归属公司名称.size());
			OCI_BindString(pStatement, (const otext*)(":105"), (otext*)(结案修理厂代码.c_str()), 结案修理厂代码.size());
			OCI_BindString(pStatement, (const otext*)(":106"), (otext*)(结案修理厂名称.c_str()), 结案修理厂名称.size());
			OCI_BindString(pStatement, (const otext*)(":107"), (otext*)(车辆进厂时间.c_str()), 车辆进厂时间.size());
			OCI_BindString(pStatement, (const otext*)(":108"), (otext*)(车辆出厂时间.c_str()), 车辆出厂时间.size());
			OCI_BindString(pStatement, (const otext*)(":109"), (otext*)(结案时间.c_str()), 结案时间.size());
			OCI_BindString(pStatement, (const otext*)(":110"), (otext*)(事故经过.c_str()), 事故经过.size());
			OCI_BindString(pStatement, (const otext*)(":111"), (otext*)(数据更新日期.c_str()), 数据更新日期.size());
			OCI_BindString(pStatement, (const otext*)(":112"), (otext*)(备注.c_str()), 备注.size());
			OCI_BindString(pStatement, (const otext*)(":113"), (otext*)(估损单模板.c_str()), 估损单模板.size());
			OCI_BindString(pStatement, (const otext*)(":114"), (otext*)(返修开关报案.c_str()), 返修开关报案.size());
			OCI_BindString(pStatement, (const otext*)(":115"), (otext*)(送修开关报案.c_str()), 送修开关报案.size());
			OCI_BindString(pStatement, (const otext*)(":116"), (otext*)(返修开关核价.c_str()), 返修开关核价.size());
			OCI_BindString(pStatement, (const otext*)(":117"), (otext*)(送修开关核价.c_str()), 送修开关核价.size());
			OCI_BindString(pStatement, (const otext*)(":118"), (otext*)(返修开关结案.c_str()), 返修开关结案.size());
			OCI_BindString(pStatement, (const otext*)(":119"), (otext*)(送修开关结案.c_str()), 送修开关结案.size());
			OCI_BindString(pStatement, (const otext*)(":120"), (otext*)(查勘员分公司名称.c_str()), 查勘员分公司名称.size());
			OCI_BindString(pStatement, (const otext*)(":121"), (otext*)(查勘员代码.c_str()), 查勘员代码.size());
			OCI_BindString(pStatement, (const otext*)(":122"), (otext*)(查勘员名称.c_str()), 查勘员名称.size());
			OCI_BindString(pStatement, (const otext*)(":123"), (otext*)(核价修理厂归属中支.c_str()), 核价修理厂归属中支.size());
			OCI_BindString(pStatement, (const otext*)(":124"), (otext*)(结案修理厂归属中支.c_str()), 结案修理厂归属中支.size());
			OCI_BindString(pStatement, (const otext*)(":125"), (otext*)(是否诉讼.c_str()), 是否诉讼.size());
			OCI_BindString(pStatement, (const otext*)(":126"), (otext*)(座席推荐分公司代码.c_str()), 座席推荐分公司代码.size());
			OCI_BindString(pStatement, (const otext*)(":127"), (otext*)(座席推荐分公司名称.c_str()), 座席推荐分公司名称.size());
			OCI_BindString(pStatement, (const otext*)(":128"), (otext*)(座席推荐车商名代码.c_str()), 座席推荐车商名代码.size());
			OCI_BindString(pStatement, (const otext*)(":129"), (otext*)(座席推荐车商名称.c_str()), 座席推荐车商名称.size());
			OCI_BindString(pStatement, (const otext*)(":130"), (otext*)(座席推荐操作类型.c_str()), 座席推荐操作类型.size());
			OCI_BindString(pStatement, (const otext*)(":131"), (otext*)(座席推荐排名.c_str()), 座席推荐排名.size());
			OCI_BindString(pStatement, (const otext*)(":132"), (otext*)(第一次推荐分公司代码.c_str()), 第一次推荐分公司代码.size());
			OCI_BindString(pStatement, (const otext*)(":133"), (otext*)(第一次推荐分公司名称.c_str()), 第一次推荐分公司名称.size());
			OCI_BindString(pStatement, (const otext*)(":134"), (otext*)(第一次推荐车商代码.c_str()), 第一次推荐车商代码.size());
			OCI_BindString(pStatement, (const otext*)(":135"), (otext*)(第一次推荐车商名称.c_str()), 第一次推荐车商名称.size());
			OCI_BindString(pStatement, (const otext*)(":136"), (otext*)(第一次推荐工具.c_str()), 第一次推荐工具.size());
			OCI_BindString(pStatement, (const otext*)(":137"), (otext*)(第一次推荐操作类型.c_str()), 第一次推荐操作类型.size());
			OCI_BindString(pStatement, (const otext*)(":138"), (otext*)(第一次推荐排名其他推荐信息.c_str()), 第一次推荐排名其他推荐信息.size());
			OCI_BindString(pStatement, (const otext*)(":139"), (otext*)(第二次推荐分公司代码.c_str()), 第二次推荐分公司代码.size());
			OCI_BindString(pStatement, (const otext*)(":140"), (otext*)(第二次推荐分公司名称.c_str()), 第二次推荐分公司名称.size());
			OCI_BindString(pStatement, (const otext*)(":141"), (otext*)(第二次推荐车商代码.c_str()), 第二次推荐车商代码.size());
			OCI_BindString(pStatement, (const otext*)(":142"), (otext*)(第二次推荐车商名称.c_str()), 第二次推荐车商名称.size());
			OCI_BindString(pStatement, (const otext*)(":143"), (otext*)(第二次推荐工具.c_str()), 第二次推荐工具.size());
			OCI_BindString(pStatement, (const otext*)(":144"), (otext*)(第二次推荐操作类型.c_str()), 第二次推荐操作类型.size());
			OCI_BindString(pStatement, (const otext*)(":145"), (otext*)(第二次推荐排名其他推荐信息.c_str()), 第二次推荐排名其他推荐信息.size());
			OCI_BindString(pStatement, (const otext*)(":146"), (otext*)(第三次推荐分公司代码.c_str()), 第三次推荐分公司代码.size());
			OCI_BindString(pStatement, (const otext*)(":147"), (otext*)(第三次推荐分公司名称.c_str()), 第三次推荐分公司名称.size());
			OCI_BindString(pStatement, (const otext*)(":148"), (otext*)(第三次推荐车商代码.c_str()), 第三次推荐车商代码.size());
			OCI_BindString(pStatement, (const otext*)(":149"), (otext*)(第三次推荐车商名称.c_str()), 第三次推荐车商名称.size());
			OCI_BindString(pStatement, (const otext*)(":150"), (otext*)(第三次推荐工具.c_str()), 第三次推荐工具.size());
			OCI_BindString(pStatement, (const otext*)(":151"), (otext*)(第三次推荐操作类型.c_str()), 第三次推荐操作类型.size());
			OCI_BindString(pStatement, (const otext*)(":152"), (otext*)(第三次推荐排名其他推荐信息.c_str()), 第三次推荐排名其他推荐信息.size());
			OCI_BindString(pStatement, (const otext*)(":153"), (otext*)(其他推荐信息.c_str()), 其他推荐信息.size());
			OCI_BindString(pStatement, (const otext*)(":154"), (otext*)(推荐失败具体原因.c_str()), 推荐失败具体原因.size());
			OCI_BindString(pStatement, (const otext*)(":155"), (otext*)(是否现场报案.c_str()), 是否现场报案.size());
			OCI_BindString(pStatement, (const otext*)(":156"), (otext*)(报案地点.c_str()), 报案地点.size());
			OCI_BindString(pStatement, (const otext*)(":157"), (otext*)(是否在厂报案.c_str()), 是否在厂报案.size());


			OCI_Execute( pStatement );
		}
		catch ( runtime_error & error )
		{
			//rollback，停止保存
			string errorMessage = "报案号";

			errorMessage.append( QString::fromStdWString( iter->报案号_ ).toLocal8Bit() );
			errorMessage.append( "保存失败，提示信息:" );
			errorMessage.append( error.what() );

			OCI_Rollback( pConnection );
			OCI_ConnectionFree( pConnection );
			OCI_Cleanup();

			throw runtime_error( errorMessage );
		}
	}

	OCI_Commit( pConnection );
	OCI_ConnectionFree( pConnection );
	OCI_Cleanup();
}
