Quellcode durchsuchen

接口完成,待进行细致的测试和修改完善;

Jeff vor 5 Jahren
Ursprung
Commit
760da4fd8b

+ 44 - 0
scbc.tools/scbc.tools/DataImpl.cpp

@@ -661,6 +661,50 @@ BOOL CDataImpl::UpdateKeyReportStatus(std::string sn)
 	return TRUE;
 }
 
+BOOL CDataImpl::BatchUpdateKeyReportStatus(std::vector<STKeys> &vtKeys)
+{
+	if(m_psqlite3 == NULL)
+		return FALSE;
+
+	char* psqlite_error = NULL;
+	INT nRet = sqlite3_exec(m_psqlite3, "begin;", 0, 0, &psqlite_error);
+	if ( nRet != SQLITE_OK )
+	{
+		FREE_MSG;
+		return FALSE;
+	}
+
+	sqlite3_stmt *stmt;
+	const char* sql = "UPDATE keys set report_date=current_timestamp WHERE sn = '?'";
+	sqlite3_prepare_v2(m_psqlite3, sql, strlen(sql), &stmt, 0);
+
+	std::vector<STKeys>::iterator it = vtKeys.begin();
+	for ( int i = 0; it != vtKeys.end(); it++, i++ )
+	{
+		sqlite3_reset(stmt);  
+		sqlite3_bind_text(stmt, 1, it->sn.c_str(), it->sn.size(), SQLITE_STATIC);    
+		sqlite3_step(stmt);  
+	}
+
+	nRet = sqlite3_finalize(stmt); 
+	if ( nRet != SQLITE_OK )
+	{
+		// »Ø¹öÊÂÎñ;
+		nRet = sqlite3_exec(m_psqlite3, "rollback;", 0, 0, &psqlite_error);
+		FREE_MSG;
+		return FALSE;
+	}
+
+	nRet = sqlite3_exec(m_psqlite3, "commit;", 0, 0, &psqlite_error);
+	if ( nRet != SQLITE_OK )
+	{
+		FREE_MSG;
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
 BOOL CDataImpl::UpdateLogReportStatus(std::string sn, std::string type)
 {
 	if(m_psqlite3 == NULL)

+ 1 - 0
scbc.tools/scbc.tools/DataImpl.h

@@ -105,6 +105,7 @@ public:
 	BOOL UpdateKeyCopyStatus(std::string sn);
 	// 更新上报状态;
 	BOOL UpdateKeyReportStatus(std::string sn);
+	BOOL BatchUpdateKeyReportStatus(std::vector<STKeys> &vtKeys);
 	// 更新日志上报状态;
 	BOOL UpdateLogReportStatus(std::string sn, std::string type);
 

+ 49 - 1
scbc.tools/scbc.tools/SDK.cpp

@@ -228,8 +228,56 @@ int CSDK::ReportKeyCopyResults(std::string sn)
 
 int CSDK::BatchReportKeyCopyResults()
 {
+	CDataImpl db;
+	if ( !db.Open() )
+		return -2;
+
+	std::vector<STKeys> vtkeys;
+	int nRet = db.QueryUnReportKeyInfo(vtkeys);
+	if ( nRet == -1)
+		return -3;
+
+	if ( nRet == 0 )
+		return 0;
+
+	// 上报;
+	std::string result;
+	std::map<std::string, std::string> form;
+	std::vector<STKeys>::iterator it = vtkeys.begin();
+	for (; it != vtkeys.end(); it++)
+	{
+		form.insert(std::pair<std::string,std::string>("sn", it->sn));
+		form.insert(std::pair<std::string,std::string>("date", it->copy_date));
+	}
+
+	CCurlClient curl;
+	curl.Initialize();
+	if ( curl.FormPost("http://test.admin.ota.qhmoka.com/IDManage/reportlist.do?", form, result,3) == CURLE_OK)
+	{
+		cJSON *pJson = cJSON_Parse(result.c_str());
+		if ( pJson == NULL )
+		{
+			return -6;
+		}
+
+		std::string code, des;
+		code = cJSON_GetObjectItem(pJson, "code") ? cJSON_GetObjectItem(pJson, "code")->valuestring: "";
+		des = cJSON_GetObjectItem(pJson, "des") ? cJSON_GetObjectItem(pJson, "des")->valuestring: "";
+		if ( _tcsicmp(code.c_str(), "1000") )
+		{
+			return -7;
+		}
+
+		// 更新上报状态;
+		nRet = db.BatchUpdateKeyReportStatus(vtkeys);
+		if ( nRet == 1 )
+			return 1;
+		else
+			return -8; // 上报成功,更新失败;
+	}
+
+	return -5;
 
-	return 0;
 }
 
 void CSDK::AddDownloadTask(STMid &mid)

+ 6 - 0
scbc.tools/scbc.tools/scbc.tools.cpp

@@ -318,6 +318,12 @@ int ReportKeyCopyResults(const char* lpSN)
 	return g_sdk.ReportKeyCopyResults(lpSN);
 }
 
+int BatchReportKeyCopyResults()
+{
+	return g_sdk.BatchReportKeyCopyResults();
+}
+
+
 int QueryBidInfo(const char* lpOrder, BidInfo& binfo)
 {
 	if ( lpOrder == NULL || lpOrder[0] == '\0' )

+ 21 - 7
scbc.tools/scbc.tools/scbc.tools.h

@@ -85,19 +85,33 @@ extern SCBCTOOLS_API int UpdateKeyReportStatus(const char* lpSN);
 描述:上报抄写结果;
 参数:lpSN 条码;
 返回:
-	0=表示上报抄写结果失败
-	1=表示上报抄写结果成功;
-	上报成功后,需调用UpdateKeyReportStatus更新上报状态;
+	0=表示在数据库中查询不到该sn的抄写信息;
+	1=表示上报抄写结果成功,且更新上报状态成功;
+	-1=表示lpSN参数空;
+	-2=表示打开db失败;
+	-3=表示查询sn出错;
+	-4=表示数据异常;
+	-5=表示https网络请求失败;
+	-6=表示解析https结果异常;
+	-7=表示上报抄写结果失败;
+	-8=表示上报抄写结果成功,但更新上报状态失败;此时,需调用UpdateKeyReportStatus更新上报状态;
 */
 extern SCBCTOOLS_API int ReportKeyCopyResults(const char* lpSN);
 
 /* 7
-描述:批量上报抄写结果。从数据库查询出500条未上报的sn进行上报;
+描述:批量上报抄写结果。从数据库查询出1000条未上报的sn进行上报;
 参数:无;
 返回:
-	0=表示上报抄写结果失败
-	1=表示上报抄写结果成功;
-	上报成功后,会自动更新上报状态;
+	0=表示在数据库中查询不到未上报的sn抄写信息;
+	1=表示上报抄写结果成功,且更新上报状态成功;
+	-1=表示lpSN参数空;
+	-2=表示打开db失败;
+	-3=表示查询sn出错;
+	////-4=表示数据异常;
+	-5=表示https网络请求失败;
+	-6=表示解析https结果异常;
+	-7=表示上报抄写结果失败;
+	-8=表示上报抄写结果成功,但批量更新上报状态失败;
 */
 extern SCBCTOOLS_API int BatchReportKeyCopyResults();
 

+ 23 - 10
scbc.tools/test/test.cpp

@@ -28,18 +28,31 @@ int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
 	}
 	else
 	{
-		// TODO: 在此处为应用程序的行为编写代码。
-		int nRet = QueryMidInfo("10");
+		// 1、查询订单是否已下载成功;
+		int nRet = QueryMidInfo("IDL144240G");
 		printf("QueryMidInfo:%d\n", nRet);
-
-// 		nRet = DownloadMidData("IDL144240G");
-// 		printf("DownloadMidData:%d\n", nRet);
-// 		Sleep(5000);
-
-		//nRet = RemoveBidData("1");
-		//printf("RemoveBidData:%d\n", nRet);
-
+		if ( nRet != 2 )
+		{
+			// 未下载成功,开始后台下载;
+			nRet = DownloadMidData("IDL144240G");
+			printf("DownloadMidData:%d\n", nRet);
+		}
+
+		// 2、等待下载成功;
+		while ( nRet != 2 )
+		{
+			nRet = QueryMidInfo("IDL144240G");
+			printf("QueryMidInfo:%d\n", nRet);
+			Sleep(1000);
+		}
+
+		// 单个sn抄写结果上报;
 		nRet = ReportKeyCopyResults("TEST-3311-8811");
+		printf("ReportKeyCopyResults:%d\n", nRet);
+
+		// 1000个sn抄写结果上报;
+		nRet = BatchReportKeyCopyResults();
+		printf("BatchReportKeyCopyResults:%d\n", nRet);
 	}
 
 	system("pause");