Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
familyMart_takeaway
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guanghui.cui
familyMart_takeaway
Commits
4fe108ec
Commit
4fe108ec
authored
Mar 08, 2018
by
guanghui.cui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1、增加日志打印 2、gb2312转utf8
parent
994a5e3d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
76 additions
and
62 deletions
+76
-62
src/JsonModule.cpp
+6
-5
src/SQLiteModule.cpp
+1
-2
src/main.cpp
+9
-1
utility/utility.cpp
+53
-20
utility/utility.h
+7
-34
No files found.
src/JsonModule.cpp
View file @
4fe108ec
...
@@ -78,7 +78,7 @@ bool JsonModule::getPushOrders(IN const char* json,OUT orderObj &order)
...
@@ -78,7 +78,7 @@ bool JsonModule::getPushOrders(IN const char* json,OUT orderObj &order)
// 注意GetParseError()返回的是一个rapidjson::ParseErrorCode类型的枚举值
// 注意GetParseError()返回的是一个rapidjson::ParseErrorCode类型的枚举值
// 使用函数rapidjson::GetParseError_En()得到错误码的字符串说明,这里的En为English简写
// 使用函数rapidjson::GetParseError_En()得到错误码的字符串说明,这里的En为English简写
// 函数GetErrorOffset()返回出错发生的位置
// 函数GetErrorOffset()返回出错发生的位置
LOG
(
ERROR
)
<<
"JSON parse error:"
<<
document
.
GetParseError
()
<<
":"
<<
document
.
GetErrorOffset
();
LOG
(
ERROR
)
<<
"
getPushOrders
JSON parse error:"
<<
document
.
GetParseError
()
<<
":"
<<
document
.
GetErrorOffset
();
return
false
;
return
false
;
}
}
else
else
...
@@ -470,7 +470,7 @@ bool JsonModule::isInitData(const std::string &data)
...
@@ -470,7 +470,7 @@ bool JsonModule::isInitData(const std::string &data)
document
.
Parse
(
data
.
c_str
());
// 解析,Parse()无返回值,也不会抛异常
document
.
Parse
(
data
.
c_str
());
// 解析,Parse()无返回值,也不会抛异常
if
(
document
.
HasParseError
())
// 通过HasParseError()来判断解析是否成功
if
(
document
.
HasParseError
())
// 通过HasParseError()来判断解析是否成功
{
{
LOG
(
ERROR
)
<<
"JSON parse error:"
<<
document
.
GetParseError
()
<<
":"
<<
document
.
GetErrorOffset
();
LOG
(
ERROR
)
<<
"
isInitData
JSON parse error:"
<<
document
.
GetParseError
()
<<
":"
<<
document
.
GetErrorOffset
();
return
false
;
return
false
;
}
}
return
document
[
"fm_cmd"
].
GetInt
()
==
1000
;
return
document
[
"fm_cmd"
].
GetInt
()
==
1000
;
...
@@ -482,7 +482,7 @@ bool JsonModule::isHeartbeatData(IN const char* data)
...
@@ -482,7 +482,7 @@ bool JsonModule::isHeartbeatData(IN const char* data)
document
.
Parse
(
data
);
// 解析,Parse()无返回值,也不会抛异常
document
.
Parse
(
data
);
// 解析,Parse()无返回值,也不会抛异常
if
(
document
.
HasParseError
())
// 通过HasParseError()来判断解析是否成功
if
(
document
.
HasParseError
())
// 通过HasParseError()来判断解析是否成功
{
{
LOG
(
ERROR
)
<<
"JSON parse error:"
<<
document
.
GetParseError
()
<<
":"
<<
document
.
GetErrorOffset
();
LOG
(
ERROR
)
<<
"
isHeartbeatData
JSON parse error:"
<<
document
.
GetParseError
()
<<
":"
<<
document
.
GetErrorOffset
();
return
false
;
return
false
;
}
}
if
(
document
.
HasMember
(
"fm_cmd"
)){
if
(
document
.
HasMember
(
"fm_cmd"
)){
...
@@ -498,7 +498,7 @@ bool JsonModule::checkInitData(const std::string &data, int &posListenPort)
...
@@ -498,7 +498,7 @@ bool JsonModule::checkInitData(const std::string &data, int &posListenPort)
document
.
Parse
(
data
.
c_str
());
// 解析,Parse()无返回值,也不会抛异常
document
.
Parse
(
data
.
c_str
());
// 解析,Parse()无返回值,也不会抛异常
if
(
document
.
HasParseError
())
// 通过HasParseError()来判断解析是否成功
if
(
document
.
HasParseError
())
// 通过HasParseError()来判断解析是否成功
{
{
LOG
(
ERROR
)
<<
"JSON parse error:"
<<
document
.
GetParseError
()
<<
":"
<<
document
.
GetErrorOffset
();
LOG
(
ERROR
)
<<
"
checkInitData
JSON parse error:"
<<
document
.
GetParseError
()
<<
":"
<<
document
.
GetErrorOffset
();
return
false
;
return
false
;
}
}
...
@@ -596,6 +596,7 @@ bool JsonModule::getOdsResponseData(const std::string &posResponse, const std::s
...
@@ -596,6 +596,7 @@ bool JsonModule::getOdsResponseData(const std::string &posResponse, const std::s
document1
.
Parse
(
orderData
.
c_str
());
document1
.
Parse
(
orderData
.
c_str
());
if
(
document
.
HasParseError
()
||
document1
.
HasParseError
())
if
(
document
.
HasParseError
()
||
document1
.
HasParseError
())
{
{
LOG
(
ERROR
)
<<
"getOdsResponseData posResponse JSON parse error:"
<<
document
.
GetParseError
()
<<
":"
<<
document
.
GetErrorOffset
();
return
false
;
return
false
;
}
}
...
@@ -1358,7 +1359,7 @@ int JsonModule::getPushType(IN const char* data)
...
@@ -1358,7 +1359,7 @@ int JsonModule::getPushType(IN const char* data)
document
.
Parse
(
data
);
// 解析,Parse()无返回值,也不会抛异常
document
.
Parse
(
data
);
// 解析,Parse()无返回值,也不会抛异常
if
(
document
.
HasParseError
())
// 通过HasParseError()来判断解析是否成功
if
(
document
.
HasParseError
())
// 通过HasParseError()来判断解析是否成功
{
{
LOG
(
ERROR
)
<<
"JSON parse error:"
<<
document
.
GetParseError
()
<<
":"
<<
document
.
GetErrorOffset
();
LOG
(
ERROR
)
<<
"
getPushType
JSON parse error:"
<<
document
.
GetParseError
()
<<
":"
<<
document
.
GetErrorOffset
();
return
0
;
return
0
;
}
}
if
(
document
.
HasMember
(
"fm_cmd"
)){
if
(
document
.
HasMember
(
"fm_cmd"
)){
...
...
src/SQLiteModule.cpp
View file @
4fe108ec
...
@@ -99,7 +99,7 @@ bool SQLite::isTableExist(sqlite3 *sqDb, std::string strTableName)
...
@@ -99,7 +99,7 @@ bool SQLite::isTableExist(sqlite3 *sqDb, std::string strTableName)
int
SQLite
::
isRecordExist
(
std
::
string
strTable
,
std
::
string
strKey
)
int
SQLite
::
isRecordExist
(
std
::
string
strTable
,
std
::
string
strKey
)
{
{
char
*
lpSql
=
new
char
[
BUFFER_SIZE
];
char
*
lpSql
=
new
char
[
BUFFER_SIZE
];
sprintf
_s
(
lpSql
,
BUFFER_SIZE
,
"select * from %s where trans_id = '%s'"
,
strTable
.
c_str
(),
strKey
.
c_str
());
sprintf
(
lpSql
,
"select * from %s where trans_id = '%s'"
,
strTable
.
c_str
(),
strKey
.
c_str
());
char
**
pResult
;
char
**
pResult
;
int
nRow
=
0
;
int
nRow
=
0
;
int
nCol
=
0
;
int
nCol
=
0
;
...
@@ -108,7 +108,6 @@ int SQLite::isRecordExist(std::string strTable,std::string strKey)
...
@@ -108,7 +108,6 @@ int SQLite::isRecordExist(std::string strTable,std::string strKey)
if
(
nResult
!=
SQLITE_OK
)
if
(
nResult
!=
SQLITE_OK
)
{
{
LOG
(
ERROR
)
<<
"sqlite3_get_table error:"
<<
errMsg
;
LOG
(
ERROR
)
<<
"sqlite3_get_table error:"
<<
errMsg
;
OutputDebugString
(
errMsg
);
return
-
1
;
return
-
1
;
}
}
return
nRow
;
return
nRow
;
...
...
src/main.cpp
View file @
4fe108ec
...
@@ -74,6 +74,7 @@ void* listen_pos_func(void* arg)
...
@@ -74,6 +74,7 @@ void* listen_pos_func(void* arg)
}
}
}
else
}
else
{
{
LOG
(
INFO
)
<<
"POS send data:"
<<
posRequestData
.
data
();
// 将POS请求数据转换为中台可接受数据格式
// 将POS请求数据转换为中台可接受数据格式
if
(
jsonTool
.
convertDataPos2Ods
(
posRequestData
,
requestOdsData
)
)
if
(
jsonTool
.
convertDataPos2Ods
(
posRequestData
,
requestOdsData
)
)
{
{
...
@@ -238,6 +239,11 @@ int main()
...
@@ -238,6 +239,11 @@ int main()
{
{
LOG
(
INFO
)
<<
"pos response data:"
<<
tmpBuf
;
LOG
(
INFO
)
<<
"pos response data:"
<<
tmpBuf
;
std
::
string
tmp
(
tmpBuf
);
std
::
string
tmp
(
tmpBuf
);
//pos发送过来的数据为gb2312编码,需要转换为utf8
// std::string tmpUtf8= charset_g2u(tmp);
// LOG(INFO)<<"gb2312 to utf8:"<<back.data();
// jsonTool.getOdsResponseData(tmpUtf8, odsPushData, responseData);
jsonTool
.
getOdsResponseData
(
tmp
,
odsPushData
,
responseData
);
jsonTool
.
getOdsResponseData
(
tmp
,
odsPushData
,
responseData
);
}
else
}
else
{
{
...
@@ -259,7 +265,9 @@ int main()
...
@@ -259,7 +265,9 @@ int main()
}
}
// TODO待加入重试机制
// TODO待加入重试机制
ods
.
send
(
responseData
);
LOG
(
INFO
)
<<
"pos response data convert to ODS:"
<<
responseData
;
bool
rlt
=
ods
.
send
(
responseData
);
LOG
(
INFO
)
<<
"send result:"
<<
rlt
;
}
}
}
else
}
else
...
...
utility/utility.cpp
View file @
4fe108ec
#include "utility.h"
#include "utility.h"
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <cstring>
#include <stdarg.h>
#include <stdarg.h>
#include <iostream>
#include <iconv.h>
#include <string.h>
#ifdef WIN32
#ifdef WIN32
#include <Windows.h>
#include <Windows.h>
...
@@ -10,8 +12,8 @@
...
@@ -10,8 +12,8 @@
#include <unistd.h>
#include <unistd.h>
#endif
#endif
//函数名: GetProcDir()
//
函数名
: GetProcDir()
//
功 能: 获
取当前程序的路径
//
功 能: 获取当前程序的路径
std
::
string
GetProcDir
()
std
::
string
GetProcDir
()
{
{
std
::
string
strDir
;
std
::
string
strDir
;
...
@@ -36,25 +38,56 @@ std::string GetProcDir()
...
@@ -36,25 +38,56 @@ std::string GetProcDir()
return
strDir
;
return
strDir
;
}
}
#ifdef _DO_NOT_HAVE_S
int
charset_convert
(
const
char
*
charset_from
,
const
char
*
charset_to
,
const
std
::
string
&
string_from
,
std
::
string
&
string_to
)
int
sprintf_s
(
char
*
buffer
,
size_t
sizeOfBuffer
,
const
char
*
format
,...)
{
{
va_list
ap
;
iconv_t
cd
=
iconv_open
(
charset_to
,
charset_from
);
if
(
!
cd
)
{
return
-
1
;
}
va_start
(
ap
,
format
);
string_to
=
""
;
int
res
=
vsprintf
(
buffer
,
format
,
ap
);
int
ret
=
0
;
va_end
(
ap
);
size_t
inbytes
=
string_from
.
size
();
return
res
;
char
*
inbuf
=
const_cast
<
char
*>
(
string_from
.
c_str
());
while
(
inbytes
>
0
)
{
char
buffer
[
2048
]
=
{
0
};
char
*
outbuf
=
buffer
;
size_t
outbytes
=
sizeof
(
buffer
)
-
1
;
ret
=
iconv
(
cd
,
&
inbuf
,
&
inbytes
,
&
outbuf
,
&
outbytes
);
if
(
ret
==
0
)
{
string_to
.
append
(
buffer
);
}
else
{
break
;
}
}
ret
=
iconv_close
(
cd
);
if
(
inbytes
!=
0
||
ret
!=
0
)
{
return
-
1
;
}
return
0
;
}
}
#endif
#ifdef WIN32
//GB2312码转为UNICODE码
#else
std
::
string
charset_g2u
(
const
std
::
string
&
gb2312
)
void
OutputDebugString
(
const
char
*
lpOutputString
)
{
{
std
::
string
utf8
;
charset_convert
(
"gb2312"
,
"utf-8"
,
gb2312
,
utf8
);
//std::cout<<"convert res:"<<i<<std::endl;
return
utf8
;
}
}
#endif
\ No newline at end of file
//UNICODE码转为GB2312码
std
::
string
charset_u2g
(
const
std
::
string
&
utf8
)
{
std
::
string
gb2312
;
charset_convert
(
"utf-8"
,
"gb2312"
,
utf8
,
gb2312
);
//std::cout<<"convert res:"<<i<<std::endl;
return
gb2312
;
}
\ No newline at end of file
utility/utility.h
View file @
4fe108ec
#include <string>
#include <string>
//函数名: GetProcDir()
//
函数名
: GetProcDir()
//
功 能: 获
取当前程序的路径
//
功 能: 获取当前程序的路径
std
::
string
GetProcDir
();
std
::
string
GetProcDir
();
#ifdef WIN32
//UNICODE码转为GB2312码
#else
std
::
string
charset_u2g
(
const
std
::
string
&
utf8
);
void
OutputDebugString
(
const
char
*
lpOutputString
);
#endif
#ifdef WIN32
//GB2312码转为UNICODE码
#else //LINUX
std
::
string
charset_g2u
(
const
std
::
string
&
gb2312
);
#define _DO_NOT_HAVE_S
\ No newline at end of file
#endif //WIN32
#ifdef _DO_NOT_HAVE_S //如果没有_s版的函数,则启动如下的替换宏
//#define sprintf_s(buffer,size,format, ...) sprintf(buffer,format,__VA_ARGS__)
#include <stdio.h>
#include <stdarg.h>
int
sprintf_s
(
char
*
buffer
,
size_t
sizeOfBuffer
,
const
char
*
format
,...);
//这个比较特殊,需要真的去实现
#define memcpy_s(dest,num,src,count) memcpy(dest,src,count)
#define fprintf_s fprintf
#define _strdate_s(buf,num) _strdate(buf)
#define strcat_s(dest,num,src) strcat(dest,src)
#define fopen_s(pf,name,mode) *pf=fopen(name,mode)
#define strncpy_s(dest,num,src,count) strncpy(dest,src,count)
#define localtime_s(tm,time) *tm=*localtime(time)
#define _strdup strdup
#else
#define mkdir(pathname,mode) _mkdir(pathname)
#endif
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment