Commit c12728a6 by xiaoqing.gu

添加数据库,增加pos主动发起冲正场景,兼容pos主动发partnerOrderId的情况

parent 253d5ac2
...@@ -63,7 +63,7 @@ ...@@ -63,7 +63,7 @@
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>C:\openssl\openssl-1.0.1s\out32dll;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>C:\openssl\openssl-1.0.1s\out32dll;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>libeay32.lib;ssleay32.lib;gtestd.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>libeay32.lib;ssleay32.lib;gtestd.lib;sqlite3.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
...@@ -97,6 +97,7 @@ ...@@ -97,6 +97,7 @@
<ClInclude Include="fmlog.h" /> <ClInclude Include="fmlog.h" />
<ClInclude Include="fmtool.h" /> <ClInclude Include="fmtool.h" />
<ClInclude Include="resource.h" /> <ClInclude Include="resource.h" />
<ClInclude Include="sqlite3.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ResourceCompile Include="fmclient.rc" /> <ResourceCompile Include="fmclient.rc" />
......
...@@ -50,6 +50,9 @@ ...@@ -50,6 +50,9 @@
<ClInclude Include="resource.h"> <ClInclude Include="resource.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="sqlite3.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ResourceCompile Include="fmclient.rc"> <ResourceCompile Include="fmclient.rc">
......
//#ifndef DATABASE_H_ #ifndef DATABASE_H_
//#define DATABASE_H_ #define DATABASE_H_
//
//#include <iostream> #include <iostream>
//
//#include "sqlite3.h" #include "sqlite3.h"
//#include "filesystem.h" #include "filesystem.h"
//#include "fmglobal.h" #include "fmglobal.h"
//#include "fmlog.h" #include "fmlog.h"
//
//using std::string; using std::string;
//
//class DataBase class DataBase
//{ {
//public: public:
// static int update(const string& sql) static int update(const string& sql)
// { {
// string path; string path;
// sqlite3 *dbhend = NULL; sqlite3 *dbhend = NULL;
// char *err = NULL; char *err = NULL;
//
// FileSys::GetProcPath(path); FileSys::GetProcPath(path);
// path.append(DB_ORDER); path.append(DB_ORDER);
//
// int rlt = sqlite3_open(path.c_str(), &dbhend); int rlt = sqlite3_open(path.c_str(), &dbhend);
//
// if(rlt) if(rlt)
// { {
// LOG() << "open " << path << " failed"; LOG() << "open " << path << " failed";
// return 0; return 0;
// } }
//
// int res = sqlite3_exec(dbhend, sql.c_str(), 0, 0, &err); int res = sqlite3_exec(dbhend, sql.c_str(), 0, 0, &err);
//
// if(res != SQLITE_OK) if(res != SQLITE_OK)
// { {
// LOG() << "update table failed error : " << err; LOG() << "update table failed error : " << err;
// sqlite3_close(dbhend); sqlite3_close(dbhend);
// return 0; return 0;
// } }
//
// sqlite3_close(dbhend); sqlite3_close(dbhend);
// return 1; return 1;
// } }
//
// static int creat(const string& sql) static int creat(const string& sql)
// { {
// string path; string path;
// sqlite3 *dbhend = NULL; sqlite3 *dbhend = NULL;
// char *err = NULL; char *err = NULL;
//
// FileSys::GetProcPath(path); FileSys::GetProcPath(path);
// path.append(DB_ORDER); path.append(DB_ORDER);
//
// int rlt = sqlite3_open(path.c_str(), &dbhend); int rlt = sqlite3_open(path.c_str(), &dbhend);
//
// if(rlt) if(rlt)
// { {
// LOG() << "open " << path << " failed"; LOG() << "open " << path << " failed";
// return 0; return 0;
// } }
//
// int res = sqlite3_exec(dbhend, sql.c_str(), 0, 0, &err); int res = sqlite3_exec(dbhend, sql.c_str(), 0, 0, &err);
//
// if(res != SQLITE_OK) if(res != SQLITE_OK)
// { {
// LOG() << "creat table failed error : " << err; LOG() << "creat table failed error : " << err;
// sqlite3_close(dbhend); sqlite3_close(dbhend);
// return 0; return 0;
// } }
//
// sqlite3_close(dbhend); sqlite3_close(dbhend);
// return 1; return 1;
// } }
//
// static int insert(const string& sql) static int insert(const string& sql)
// { {
// string path; string path;
// sqlite3 *dbhend = NULL; sqlite3 *dbhend = NULL;
// char *err = NULL; char *err = NULL;
//
// FileSys::GetProcPath(path); FileSys::GetProcPath(path);
// path.append(DB_ORDER); path.append(DB_ORDER);
//
// int rlt = sqlite3_open(path.c_str(), &dbhend); int rlt = sqlite3_open(path.c_str(), &dbhend);
//
// if(rlt) if(rlt)
// { {
// LOG() << "open " << path << " failed"; LOG() << "open " << path << " failed";
// return 0; return 0;
// } }
//
// int res = sqlite3_exec(dbhend, sql.c_str(), 0, 0, &err); int res = sqlite3_exec(dbhend, sql.c_str(), 0, 0, &err);
//
// if(res != SQLITE_OK) if(res != SQLITE_OK)
// { {
// LOG() << "creat table failed error : " << err; LOG() << "creat table failed error : " << err;
// sqlite3_close(dbhend); sqlite3_close(dbhend);
// return 0; return 0;
// } }
//
// sqlite3_close(dbhend); sqlite3_close(dbhend);
// return 1; return 1;
// } }
//
// static int callback(void* dst ,int nCount,char** pValue,char** pName) static int callback(void* dst ,int nCount,char** pValue,char** pName)
// { {
// strcpy_s((char *)dst, MAX_ORDERID_LEN - 1, pValue[0]); strcpy_s((char *)dst, MAX_ORDERID_LEN - 1, pValue[0]);
// return 0; return 0;
// } }
//
// static int select(const string& sql, string &result) static int select(const string& sql, string &result)
// { {
// string path; string path;
// sqlite3 *dbhend = NULL; sqlite3 *dbhend = NULL;
// char *err = NULL; char *err = NULL;
//
// FileSys::GetProcPath(path); FileSys::GetProcPath(path);
// path.append(DB_ORDER); path.append(DB_ORDER);
//
// int rlt = sqlite3_open(path.c_str(), &dbhend); int rlt = sqlite3_open(path.c_str(), &dbhend);
//
// if(rlt) if(rlt)
// { {
// LOG() << "open " << path << " failed"; LOG() << "open " << path << " failed";
// return 0; return 0;
// } }
//
// char parentOrederID[MAX_ORDERID_LEN] = { 0 }; char parentOrederID[MAX_ORDERID_LEN] = { 0 };
//
// int res = sqlite3_exec(dbhend, sql.c_str(), callback, parentOrederID, &err); int res = sqlite3_exec(dbhend, sql.c_str(), callback, parentOrederID, &err);
//
// if(res != SQLITE_OK) if(res != SQLITE_OK)
// { {
// LOG() << "slelct table failed error : " << err; LOG() << "slelct table failed error : " << err;
// sqlite3_close(dbhend); sqlite3_close(dbhend);
// return 0; return 0;
// } }
//
// result = string(parentOrederID); result = string(parentOrederID);
// sqlite3_close(dbhend); sqlite3_close(dbhend);
// return 1; return 1;
// } }
//
// static int delt(const string &sql) static int delt(const string &sql)
// { {
// string path; string path;
// sqlite3 *dbhend = NULL; sqlite3 *dbhend = NULL;
// char *err = NULL; char *err = NULL;
//
// FileSys::GetProcPath(path); FileSys::GetProcPath(path);
// path.append(DB_ORDER); path.append(DB_ORDER);
//
// int rlt = sqlite3_open(path.c_str(), &dbhend); int rlt = sqlite3_open(path.c_str(), &dbhend);
//
// if(rlt) if(rlt)
// { {
// LOG() << "open " << path << " failed"; LOG() << "open " << path << " failed";
// return 0; return 0;
// } }
//
// int res = sqlite3_exec(dbhend, sql.c_str(), 0, 0, &err); int res = sqlite3_exec(dbhend, sql.c_str(), 0, 0, &err);
//
// if(res != SQLITE_OK) if(res != SQLITE_OK)
// { {
// LOG() << "delete table failed error : " << err; LOG() << "delete table failed error : " << err;
// sqlite3_close(dbhend); sqlite3_close(dbhend);
// return 0; return 0;
// } }
//
// sqlite3_close(dbhend); sqlite3_close(dbhend);
// return 1; return 1;
// } }
//}; };
//
//#endif #endif
//
//
...@@ -565,13 +565,14 @@ int ProcessPosReqData(const char *indata, int /**needrbk*/*needcheck, int *reqTy ...@@ -565,13 +565,14 @@ int ProcessPosReqData(const char *indata, int /**needrbk*/*needcheck, int *reqTy
//json_object_set(root, JSON_KEY_ONLY, json_string(tmps.str().c_str())); //json_object_set(root, JSON_KEY_ONLY, json_string(tmps.str().c_str()));
tmproot.AddMember(JSON_KEY_ONLY, Value().SetString(tmps.str().c_str(), strlen(tmps.str().c_str()), root.GetAllocator()), tmproot.GetAllocator()); tmproot.AddMember(JSON_KEY_ONLY, Value().SetString(tmps.str().c_str(), strlen(tmps.str().c_str()), root.GetAllocator()), tmproot.GetAllocator());
in = Tool::DocumentToString(tmproot);
LOG() << "*****:" << in;
/*
if(type == 71) if(type == 71)
{ {
tmpkey << codestr << transIdstr << json_integer_value(partnerId) << json_string_value(storeId) << json_string_value(stationId); //tmpkey << codestr << transIdstr << json_integer_value(partnerId) << json_string_value(storeId) << json_string_value(stationId);
tmpkey << codestr <<transIdstr << int(partnerId.GetInt()) << string(storeId.GetString()) << string(stationId.GetString());
std::stringstream creatsql, insetsql, updatesql; std::stringstream creatsql, insetsql, updatesql;
creatsql << "create table IF NOT EXISTS " << DB_TABLE_NAME << "(orderID varchar(200) NOT NULL,parentID varchar(60),businessDate date,PRIMARY KEY (orderID))"; creatsql << "create table IF NOT EXISTS " << DB_TABLE_NAME << "(orderID varchar(200) NOT NULL,parentID varchar(60),businessDate date,PRIMARY KEY (orderID))";
...@@ -590,7 +591,8 @@ int ProcessPosReqData(const char *indata, int /**needrbk*/*needcheck, int *reqTy ...@@ -590,7 +591,8 @@ int ProcessPosReqData(const char *indata, int /**needrbk*/*needcheck, int *reqTy
if(type == 3) if(type == 3)
{ {
tmpkey << codestr << transIdstr << (int)json_integer_value(partnerId) << (char *)json_string_value(storeId) << (char *)json_string_value(stationId); //tmpkey << codestr << transIdstr << (int)json_integer_value(partnerId) << (char *)json_string_value(storeId) << (char *)json_string_value(stationId);
tmpkey << codestr <<transIdstr << int(partnerId.GetInt()) << string(storeId.GetString()) << string(stationId.GetString());
std::stringstream selectsql; std::stringstream selectsql;
selectsql << "select parentID from " << DB_TABLE_NAME << " where orderID='" << tmpkey.str().c_str() << "'" ; selectsql << "select parentID from " << DB_TABLE_NAME << " where orderID='" << tmpkey.str().c_str() << "'" ;
...@@ -601,18 +603,22 @@ int ProcessPosReqData(const char *indata, int /**needrbk*/*needcheck, int *reqTy ...@@ -601,18 +603,22 @@ int ProcessPosReqData(const char *indata, int /**needrbk*/*needcheck, int *reqTy
if(DataBase::select(string(selectsql.str().c_str()), prid) == 1) if(DataBase::select(string(selectsql.str().c_str()), prid) == 1)
{ {
LOG() << "get partnerOrderId : " << prid; LOG() << "get partnerOrderId : " << prid;
json_object_set(root, JSON_KEY_ONLY, json_string(prid.c_str())); //json_object_set(root, JSON_KEY_ONLY, json_string(prid.c_str()));
}else if(!tmproot.HasMember(JSON_KEY_ONLY))
{ tmproot.AddMember(JSON_KEY_ONLY, Value().SetString(prid.c_str(), strlen(prid.c_str()), root.GetAllocator()), tmproot.GetAllocator());
goto freeJson;
} }
} }
in = Tool::DocumentToString(tmproot);
LOG() << "*****:" << in;
//in = string(json_dumps(root, JSON_COMPACT | JSON_SORT_KEYS)); //in = string(json_dumps(root, JSON_COMPACT | JSON_SORT_KEYS));
//rlt = 1; //rlt = 1;
*/
return 1; return 1;
//freeJson: //freeJson:
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment