Commit c12728a6 by xiaoqing.gu

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

parent 253d5ac2
......@@ -63,7 +63,7 @@
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<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>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
......@@ -97,6 +97,7 @@
<ClInclude Include="fmlog.h" />
<ClInclude Include="fmtool.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="sqlite3.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="fmclient.rc" />
......
......@@ -50,6 +50,9 @@
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="sqlite3.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="fmclient.rc">
......
//#ifndef DATABASE_H_
//#define DATABASE_H_
//
//#include <iostream>
//
//#include "sqlite3.h"
//#include "filesystem.h"
//#include "fmglobal.h"
//#include "fmlog.h"
//
//using std::string;
//
//class DataBase
//{
//public:
// static int update(const string& sql)
// {
// string path;
// sqlite3 *dbhend = NULL;
// char *err = NULL;
//
// FileSys::GetProcPath(path);
// path.append(DB_ORDER);
//
// int rlt = sqlite3_open(path.c_str(), &dbhend);
//
// if(rlt)
// {
// LOG() << "open " << path << " failed";
// return 0;
// }
//
// int res = sqlite3_exec(dbhend, sql.c_str(), 0, 0, &err);
//
// if(res != SQLITE_OK)
// {
// LOG() << "update table failed error : " << err;
// sqlite3_close(dbhend);
// return 0;
// }
//
// sqlite3_close(dbhend);
// return 1;
// }
//
// static int creat(const string& sql)
// {
// string path;
// sqlite3 *dbhend = NULL;
// char *err = NULL;
//
// FileSys::GetProcPath(path);
// path.append(DB_ORDER);
//
// int rlt = sqlite3_open(path.c_str(), &dbhend);
//
// if(rlt)
// {
// LOG() << "open " << path << " failed";
// return 0;
// }
//
// int res = sqlite3_exec(dbhend, sql.c_str(), 0, 0, &err);
//
// if(res != SQLITE_OK)
// {
// LOG() << "creat table failed error : " << err;
// sqlite3_close(dbhend);
// return 0;
// }
//
// sqlite3_close(dbhend);
// return 1;
// }
//
// static int insert(const string& sql)
// {
// string path;
// sqlite3 *dbhend = NULL;
// char *err = NULL;
//
// FileSys::GetProcPath(path);
// path.append(DB_ORDER);
//
// int rlt = sqlite3_open(path.c_str(), &dbhend);
//
// if(rlt)
// {
// LOG() << "open " << path << " failed";
// return 0;
// }
//
// int res = sqlite3_exec(dbhend, sql.c_str(), 0, 0, &err);
//
// if(res != SQLITE_OK)
// {
// LOG() << "creat table failed error : " << err;
// sqlite3_close(dbhend);
// return 0;
// }
//
// sqlite3_close(dbhend);
// return 1;
// }
//
// static int callback(void* dst ,int nCount,char** pValue,char** pName)
// {
// strcpy_s((char *)dst, MAX_ORDERID_LEN - 1, pValue[0]);
// return 0;
// }
//
// static int select(const string& sql, string &result)
// {
// string path;
// sqlite3 *dbhend = NULL;
// char *err = NULL;
//
// FileSys::GetProcPath(path);
// path.append(DB_ORDER);
//
// int rlt = sqlite3_open(path.c_str(), &dbhend);
//
// if(rlt)
// {
// LOG() << "open " << path << " failed";
// return 0;
// }
//
// char parentOrederID[MAX_ORDERID_LEN] = { 0 };
//
// int res = sqlite3_exec(dbhend, sql.c_str(), callback, parentOrederID, &err);
//
// if(res != SQLITE_OK)
// {
// LOG() << "slelct table failed error : " << err;
// sqlite3_close(dbhend);
// return 0;
// }
//
// result = string(parentOrederID);
// sqlite3_close(dbhend);
// return 1;
// }
//
// static int delt(const string &sql)
// {
// string path;
// sqlite3 *dbhend = NULL;
// char *err = NULL;
//
// FileSys::GetProcPath(path);
// path.append(DB_ORDER);
//
// int rlt = sqlite3_open(path.c_str(), &dbhend);
//
// if(rlt)
// {
// LOG() << "open " << path << " failed";
// return 0;
// }
//
// int res = sqlite3_exec(dbhend, sql.c_str(), 0, 0, &err);
//
// if(res != SQLITE_OK)
// {
// LOG() << "delete table failed error : " << err;
// sqlite3_close(dbhend);
// return 0;
// }
//
// sqlite3_close(dbhend);
// return 1;
// }
//};
//
//#endif
//
//
#ifndef DATABASE_H_
#define DATABASE_H_
#include <iostream>
#include "sqlite3.h"
#include "filesystem.h"
#include "fmglobal.h"
#include "fmlog.h"
using std::string;
class DataBase
{
public:
static int update(const string& sql)
{
string path;
sqlite3 *dbhend = NULL;
char *err = NULL;
FileSys::GetProcPath(path);
path.append(DB_ORDER);
int rlt = sqlite3_open(path.c_str(), &dbhend);
if(rlt)
{
LOG() << "open " << path << " failed";
return 0;
}
int res = sqlite3_exec(dbhend, sql.c_str(), 0, 0, &err);
if(res != SQLITE_OK)
{
LOG() << "update table failed error : " << err;
sqlite3_close(dbhend);
return 0;
}
sqlite3_close(dbhend);
return 1;
}
static int creat(const string& sql)
{
string path;
sqlite3 *dbhend = NULL;
char *err = NULL;
FileSys::GetProcPath(path);
path.append(DB_ORDER);
int rlt = sqlite3_open(path.c_str(), &dbhend);
if(rlt)
{
LOG() << "open " << path << " failed";
return 0;
}
int res = sqlite3_exec(dbhend, sql.c_str(), 0, 0, &err);
if(res != SQLITE_OK)
{
LOG() << "creat table failed error : " << err;
sqlite3_close(dbhend);
return 0;
}
sqlite3_close(dbhend);
return 1;
}
static int insert(const string& sql)
{
string path;
sqlite3 *dbhend = NULL;
char *err = NULL;
FileSys::GetProcPath(path);
path.append(DB_ORDER);
int rlt = sqlite3_open(path.c_str(), &dbhend);
if(rlt)
{
LOG() << "open " << path << " failed";
return 0;
}
int res = sqlite3_exec(dbhend, sql.c_str(), 0, 0, &err);
if(res != SQLITE_OK)
{
LOG() << "creat table failed error : " << err;
sqlite3_close(dbhend);
return 0;
}
sqlite3_close(dbhend);
return 1;
}
static int callback(void* dst ,int nCount,char** pValue,char** pName)
{
strcpy_s((char *)dst, MAX_ORDERID_LEN - 1, pValue[0]);
return 0;
}
static int select(const string& sql, string &result)
{
string path;
sqlite3 *dbhend = NULL;
char *err = NULL;
FileSys::GetProcPath(path);
path.append(DB_ORDER);
int rlt = sqlite3_open(path.c_str(), &dbhend);
if(rlt)
{
LOG() << "open " << path << " failed";
return 0;
}
char parentOrederID[MAX_ORDERID_LEN] = { 0 };
int res = sqlite3_exec(dbhend, sql.c_str(), callback, parentOrederID, &err);
if(res != SQLITE_OK)
{
LOG() << "slelct table failed error : " << err;
sqlite3_close(dbhend);
return 0;
}
result = string(parentOrederID);
sqlite3_close(dbhend);
return 1;
}
static int delt(const string &sql)
{
string path;
sqlite3 *dbhend = NULL;
char *err = NULL;
FileSys::GetProcPath(path);
path.append(DB_ORDER);
int rlt = sqlite3_open(path.c_str(), &dbhend);
if(rlt)
{
LOG() << "open " << path << " failed";
return 0;
}
int res = sqlite3_exec(dbhend, sql.c_str(), 0, 0, &err);
if(res != SQLITE_OK)
{
LOG() << "delete table failed error : " << err;
sqlite3_close(dbhend);
return 0;
}
sqlite3_close(dbhend);
return 1;
}
};
#endif
......@@ -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()));
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)
{
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;
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
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;
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
if(DataBase::select(string(selectsql.str().c_str()), prid) == 1)
{
LOG() << "get partnerOrderId : " << prid;
json_object_set(root, JSON_KEY_ONLY, json_string(prid.c_str()));
}else
{
goto freeJson;
//json_object_set(root, JSON_KEY_ONLY, json_string(prid.c_str()));
if(!tmproot.HasMember(JSON_KEY_ONLY))
tmproot.AddMember(JSON_KEY_ONLY, Value().SetString(prid.c_str(), strlen(prid.c_str()), root.GetAllocator()), tmproot.GetAllocator());
}
}
in = Tool::DocumentToString(tmproot);
LOG() << "*****:" << in;
//in = string(json_dumps(root, JSON_COMPACT | JSON_SORT_KEYS));
//rlt = 1;
*/
return 1;
//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