Commit 2ce7ed1f by LIDINGDA\ldd

1.修复自动冲正不追加parentorderid问题;2.添加模板自动补齐功能;3.添加数据库支付POS主动发起券冲正

parent 19bc2799
No preview for this file type
...@@ -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;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>libeay32.lib;ssleay32.lib;sqlite3.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
...@@ -96,6 +96,7 @@ ...@@ -96,6 +96,7 @@
<ClCompile Include="strconv.c" /> <ClCompile Include="strconv.c" />
<ClCompile Include="tastdataprocess.cpp" /> <ClCompile Include="tastdataprocess.cpp" />
<ClCompile Include="testlog.cpp" /> <ClCompile Include="testlog.cpp" />
<ClCompile Include="testtool.cpp" />
<ClCompile Include="utf.c" /> <ClCompile Include="utf.c" />
<ClCompile Include="value.c" /> <ClCompile Include="value.c" />
</ItemGroup> </ItemGroup>
...@@ -103,17 +104,21 @@ ...@@ -103,17 +104,21 @@
<ClInclude Include="dataprocess.h" /> <ClInclude Include="dataprocess.h" />
<ClInclude Include="filesystem.h" /> <ClInclude Include="filesystem.h" />
<ClInclude Include="fmcrypt.h" /> <ClInclude Include="fmcrypt.h" />
<ClInclude Include="fmdatabase.h" />
<ClInclude Include="fmerror.h" /> <ClInclude Include="fmerror.h" />
<ClInclude Include="fmglobal.h" /> <ClInclude Include="fmglobal.h" />
<ClInclude Include="fmlog.h" /> <ClInclude Include="fmlog.h" />
<ClInclude Include="fmtool.h" />
<ClInclude Include="hashtable.h" /> <ClInclude Include="hashtable.h" />
<ClInclude Include="jansson.h" /> <ClInclude Include="jansson.h" />
<ClInclude Include="jansson_config.h" /> <ClInclude Include="jansson_config.h" />
<ClInclude Include="jansson_private.h" /> <ClInclude Include="jansson_private.h" />
<ClInclude Include="lookup3.h" /> <ClInclude Include="lookup3.h" />
<ClInclude Include="sqlite3.h" />
<ClInclude Include="strbuffer.h" /> <ClInclude Include="strbuffer.h" />
<ClInclude Include="testdataprocess.h" /> <ClInclude Include="testdataprocess.h" />
<ClInclude Include="testlog.h" /> <ClInclude Include="testlog.h" />
<ClInclude Include="testtool.h" />
<ClInclude Include="utf.h" /> <ClInclude Include="utf.h" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
......
...@@ -63,6 +63,9 @@ ...@@ -63,6 +63,9 @@
<ClCompile Include="value.c"> <ClCompile Include="value.c">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="testtool.cpp">
<Filter>Source Files\TestCase</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="fmcrypt.h"> <ClInclude Include="fmcrypt.h">
...@@ -110,5 +113,17 @@ ...@@ -110,5 +113,17 @@
<ClInclude Include="strbuffer.h"> <ClInclude Include="strbuffer.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="fmtool.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="testtool.h">
<Filter>Header Files\TestCase</Filter>
</ClInclude>
<ClInclude Include="sqlite3.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="fmdatabase.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>
\ No newline at end of file
#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 FM_GLOBAL_H #ifndef FM_GLOBAL_H
#define FM_GLOBAL_H #define FM_GLOBAL_H
#define NUM_SIZE 60
#define KEY_SIZE 24 #define KEY_SIZE 24
#define MAX_LOG_LINE_NUM 1024 #define MAX_LOG_LINE_NUM 1024
#define MAX_RSA_KEY_LEN 2048 #define MAX_RSA_KEY_LEN 2048
...@@ -14,4 +15,10 @@ ...@@ -14,4 +15,10 @@
#define CRET_FILE_NAME "client.p12" #define CRET_FILE_NAME "client.p12"
#define JSON_KEY_ONLY "partnerOrderId" #define JSON_KEY_ONLY "partnerOrderId"
#define CFG_KEY "template"
#define TMP_JSON "json.ini"
#define DB_ORDER "order.db"
#define DB_TABLE_NAME "orderlist"
#define MAX_ORDERID_LEN 200
#endif #endif
\ No newline at end of file
#ifndef FM_TOOL_H_
#define FM_TOOL_H_
#include <jansson.h>
#include <jansson_private.h>
#include <Windows.h>
#include "fmglobal.h"
#include "fmlog.h"
#include "filesystem.h"
class Tool
{
public:
static int ReadTMPForType(char *tplt, int reqType)
{
char tmp[MAX_BUF_LEN] = { 0 };
std::string path;
char type[64] = { 0 };
itoa(reqType, type, 10);
FileSys::GetProcPath(path);
path.append(TMP_JSON);
LOG() << "template cfg file path :" << path;
GetPrivateProfileString(type, CFG_KEY,"",tmp, MAX_BUF_LEN, path.c_str());
strcpy(tplt, tmp);
//LOG() << "get template json : " << tplt;
return (tmp[0] == 0 ? 0 : 1);
}
static void CompareJson(json_t *tplt, json_t *tmpin)
{
if(json_is_object(tplt) && json_is_object(tmpin))
{
const char *key;
json_t *value;
json_object_foreach(tplt, key, value)
{
if(value->type == json_type::JSON_OBJECT)
{
json_t *tmps = json_object_get(tmpin, key);
if(tmps)
{
CompareJson(value, tmps);
}
else
{
json_object_set(tmpin, key, value);
}
}
else if(value->type == json_type::JSON_ARRAY)
{
json_t *tmps = json_object_get(tmpin, key);
if(tmps)
{
CompareJson(value, tmps);
}
else
{
json_object_set(tmpin, key, value);
}
}
else
{
json_t *tmps = json_object_get(tmpin, key);
if(tmps)
continue;
else
{
json_object_set(tmpin, key, value);
}
}
}
}
else if(json_is_array(tplt) && json_is_array(tmpin))
{
int index = 0;
json_t *value, *tmpvalue;
value = json_array_get(tplt, 0);
if(value)
{
json_array_foreach(tmpin, index, tmpvalue)
{
CompareJson(value, tmpvalue);
}
if(index == 0)
json_array_append(tmpin, value);
}
}
}
static int ComplementJson(const char *in, char *out, int reqType)
{
char templatestr[MAX_BUF_LEN] = { 0 };
if(ReadTMPForType(templatestr, reqType) == 0)
{
LOG() << "get temple failed";
return 0;
}
json_t *root, *value, *tmpin;
json_error_t error;
root = json_loads(templatestr, 0, &error);
tmpin = json_loads(in, 0, &error);
LOG() << "get temple success : " << json_dumps(root, JSON_COMPACT | JSON_SORT_KEYS);
if(!root)
{
LOG() << "error temple or injson json(reqType:"<< reqType << "):" << templatestr;
return 0;
}
if( !tmpin )
{
LOG() << "error temple or injson json(reqType:"<< reqType << "):" << in;
return 0;
}
CompareJson(root, tmpin);
char *tmpstr = json_dumps(tmpin, JSON_COMPACT | JSON_SORT_KEYS);
strcpy(out, tmpstr);
LOG() << "complement json success : " << out;
json_decref(root);
json_decref(tmpin);
return 1;
}
};
#endif
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
#include "fmglobal.h"
#include "fmtool.h"
#include "fmlog.h"
void TestComplementJson()
{
//char in[] = "{\"ver\":1,\"statusCode\":0,\"message\":\"\",\"paymentMethod\":\"\",\"paymentMethodCode\":\"\",\"ext\":{\"print\":\"\",\"hint\":\"\"},\"info\":{\"status\":\"\",\"statusDesc\":\"\",\"actId\":\"\",\"actName\":\"\",\"vdata\":\"\",\"code\":\"\",\"authCode\":\"\",\"amount\":8,\"products\":[]}}";
char in[] = "{\"ver\":1,\"message\":\"\",\"products\":[{\"pid\":4,\"name\":\"lcd\"},{\"name\":\"lcd\"},{\"pid\":4},{}]}";
char out[MAX_BUF_LEN] = { 0 };
Tool::ComplementJson(in, out, 95);
LOG() << out ;
}
\ No newline at end of file
#ifdef FM_TEST
void TestComplementJson();
#endif
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