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
5985d6e1
Commit
5985d6e1
authored
Mar 09, 2018
by
guanghui.cui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
代码重构
parent
4fe108ec
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
130 additions
and
46 deletions
+130
-46
src/JsonModule.cpp
+118
-40
src/JsonModule.h
+3
-0
src/main.cpp
+8
-5
utility/utility.cpp
+1
-1
No files found.
src/JsonModule.cpp
View file @
5985d6e1
...
...
@@ -582,60 +582,36 @@ bool JsonModule::getOdsResponseData(int status_code, const std::string &msg, std
bool
JsonModule
::
getOdsResponseData
(
const
std
::
string
&
posResponse
,
const
std
::
string
&
orderData
,
std
::
string
&
result
)
{
int
status_code
;
std
::
string
msg
;
std
::
string
order_id
;
int
status
;
if
(
posResponse
.
empty
()
||
orderData
.
empty
()
)
if
(
posResponse
.
empty
()
||
orderData
.
empty
()
){
LOG
(
INFO
)
<<
"getOdsResponseData empty input"
;
return
false
;
}
rapidjson
::
Document
document
,
document1
;
document
.
Parse
(
posResponse
.
c_str
());
document1
.
Parse
(
orderData
.
c_str
());
if
(
document
.
HasParseError
()
||
document1
.
HasParseError
())
{
LOG
(
ERROR
)
<<
"getOdsResponseData posResponse JSON parse error:"
<<
document
.
GetParseError
()
<<
":"
<<
document
.
GetErrorOffset
();
LOG
(
INFO
)
<<
"getOdsResponseData posResponse JSON parse error:"
<<
document
.
GetParseError
()
<<
":"
<<
document
.
GetErrorOffset
();
return
false
;
}
if
(
!
document
.
HasMember
(
"status_code"
)
||
!
document1
.
HasMember
(
"order_id"
)
||
!
document1
.
HasMember
(
"status"
)
)
if
(
!
document
.
HasMember
(
"fm_cmd"
)
)
{
LOG
(
INFO
)
<<
"Don't have needed parames"
;
return
false
;
}
status_code
=
document
[
"status_code"
].
GetInt
();
msg
=
document
[
"msg"
].
GetString
();
order_id
=
document1
[
"order_id"
].
GetString
();
status
=
document1
[
"status"
].
GetInt
();
rapidjson
::
StringBuffer
buffer
;
rapidjson
::
Writer
<
rapidjson
::
StringBuffer
>
writer
(
buffer
);
writer
.
StartObject
();
writer
.
Key
(
"fm_cmd"
);
writer
.
Int
(
2
);
writer
.
Key
(
"order_id"
);
writer
.
String
(
order_id
.
c_str
());
writer
.
Key
(
"status"
);
writer
.
Int
(
status
);
writer
.
Key
(
"status_code"
);
writer
.
Int
(
status_code
);
writer
.
Key
(
"msg"
);
writer
.
String
(
msg
.
c_str
());
writer
.
EndObject
();
result
=
buffer
.
GetString
();
return
true
;
int
fm_cmd
=
document
[
"fm_cmd"
].
GetInt
();
bool
rlt
=
false
;
if
(
fm_cmd
==
REQUEST_TYPE_NEWORDER_PUSH
){
rlt
=
_getOrderResponseJson
(
posResponse
,
orderData
,
result
);
}
else
if
(
fm_cmd
==
REQUEST_TYPE_STOCK_WARN
){
rlt
=
_getStockWarnResponseJson
(
posResponse
,
orderData
,
result
);
}
return
rlt
;
}
bool
JsonModule
::
convertDataPos2Ods
(
const
std
::
string
&
data
,
std
::
string
&
result
)
...
...
@@ -1366,4 +1342,105 @@ int JsonModule::getPushType(IN const char* data)
return
document
[
"fm_cmd"
].
GetInt
();
}
return
0
;
}
bool
JsonModule
::
_getOrderResponseJson
(
IN
const
std
::
string
&
posResponse
,
IN
const
std
::
string
&
orderData
,
OUT
std
::
string
&
result
)
{
rapidjson
::
Document
document
,
document1
;
document
.
Parse
(
posResponse
.
c_str
());
document1
.
Parse
(
orderData
.
c_str
());
if
(
!
document
.
HasMember
(
"status_code"
)
||
!
document1
.
HasMember
(
"order_id"
)
||
!
document1
.
HasMember
(
"status"
)
||
!
document1
.
HasMember
(
"channel"
)
)
{
LOG
(
INFO
)
<<
"Don't have needed parames"
;
return
false
;
}
int
status_code
=
document
[
"status_code"
].
GetInt
();
std
::
string
msg
=
document
[
"msg"
].
GetString
();
std
::
string
order_id
=
document1
[
"order_id"
].
GetString
();
int
status
=
document1
[
"status"
].
GetInt
();
std
::
string
channel
=
document1
[
"channel"
].
GetString
();
rapidjson
::
StringBuffer
buffer
;
rapidjson
::
Writer
<
rapidjson
::
StringBuffer
>
writer
(
buffer
);
writer
.
StartObject
();
writer
.
Key
(
"fm_cmd"
);
writer
.
Int
(
2
);
writer
.
Key
(
"order_id"
);
writer
.
String
(
order_id
.
c_str
());
writer
.
Key
(
"channel"
);
writer
.
String
(
channel
.
c_str
());
writer
.
Key
(
"status"
);
writer
.
Int
(
status
);
writer
.
Key
(
"status_code"
);
writer
.
Int
(
status_code
);
writer
.
Key
(
"msg"
);
writer
.
String
(
msg
.
c_str
());
writer
.
EndObject
();
result
=
buffer
.
GetString
();
return
true
;
}
bool
JsonModule
::
_getStockWarnResponseJson
(
IN
const
std
::
string
&
posResponse
,
IN
const
std
::
string
&
orderData
,
OUT
std
::
string
&
result
)
{
//待接口确定
rapidjson
::
Document
document
,
document1
;
document
.
Parse
(
posResponse
.
c_str
());
document1
.
Parse
(
orderData
.
c_str
());
if
(
!
document
.
HasMember
(
"status_code"
)
||
!
document1
.
HasMember
(
"order_id"
)
||
!
document1
.
HasMember
(
"status"
)
||
!
document1
.
HasMember
(
"channel"
)
)
{
LOG
(
INFO
)
<<
"Don't have needed parames"
;
return
false
;
}
int
status_code
=
document
[
"status_code"
].
GetInt
();
std
::
string
msg
=
document
[
"msg"
].
GetString
();
std
::
string
order_id
=
document1
[
"order_id"
].
GetString
();
int
status
=
document1
[
"status"
].
GetInt
();
std
::
string
channel
=
document1
[
"channel"
].
GetString
();
rapidjson
::
StringBuffer
buffer
;
rapidjson
::
Writer
<
rapidjson
::
StringBuffer
>
writer
(
buffer
);
writer
.
StartObject
();
writer
.
Key
(
"fm_cmd"
);
writer
.
Int
(
1016
);
writer
.
Key
(
"order_id"
);
writer
.
String
(
order_id
.
c_str
());
writer
.
Key
(
"channel"
);
writer
.
String
(
channel
.
c_str
());
writer
.
Key
(
"status"
);
writer
.
Int
(
status
);
writer
.
Key
(
"status_code"
);
writer
.
Int
(
status_code
);
writer
.
Key
(
"msg"
);
writer
.
String
(
msg
.
c_str
());
writer
.
EndObject
();
result
=
buffer
.
GetString
();
return
true
;
}
\ No newline at end of file
src/JsonModule.h
View file @
5985d6e1
...
...
@@ -89,6 +89,9 @@ private:
std
::
string
_convertToOrderStatusJson
(
orderStatusObj
&
obj
);
std
::
string
_convertToRefundJson
(
refundObj
&
obj
);
std
::
string
_convertToStockWarnJson
(
stockWarnObj
&
obj
);
bool
_getOrderResponseJson
(
IN
const
std
::
string
&
posResponse
,
IN
const
std
::
string
&
orderData
,
OUT
std
::
string
&
result
);
bool
_getStockWarnResponseJson
(
IN
const
std
::
string
&
posResponse
,
IN
const
std
::
string
&
orderData
,
OUT
std
::
string
&
result
);
};
#endif
src/main.cpp
View file @
5985d6e1
...
...
@@ -240,11 +240,11 @@ int main()
LOG
(
INFO
)
<<
"pos response data:"
<<
tmpBuf
;
std
::
string
tmp
(
tmpBuf
);
//pos发送过来的数据为gb2312编码,需要转换为utf8
//
std::string tmpUtf8= charset_g2u(tmp);
// LOG(INFO)<<"gb2312 to utf8:"<<back
.data();
// jsonTool.getOdsResponseData(tmpUtf8, odsPush
Data, responseData);
std
::
string
tmpUtf8
=
charset_g2u
(
tmp
);
LOG
(
INFO
)
<<
"gb2312 to utf8:"
<<
tmpUtf8
.
data
();
jsonTool
.
getOdsResponseData
(
tmpUtf8
,
pushPos
Data
,
responseData
);
jsonTool
.
getOdsResponseData
(
tmp
,
odsPushData
,
responseData
);
//
jsonTool.getOdsResponseData(tmp, odsPushData, responseData);
}
else
{
jsonTool
.
getOdsResponseData
(
101
,
"receive data from [POS] failed!"
,
responseData
);
...
...
@@ -265,7 +265,10 @@ int main()
}
// TODO待加入重试机制
LOG
(
INFO
)
<<
"pos response data convert to ODS:"
<<
responseData
;
LOG
(
INFO
)
<<
"pos response data convert to ODS:"
<<
responseData
.
data
();
//test
//responseData="{\"fm_cmd\": 2,\"order_id\" : \"1234\",\"status\" : 1,\"channel\" : \"1234\",\"status_code\" : 100,\"msg\" : \"\"}";
bool
rlt
=
ods
.
send
(
responseData
);
LOG
(
INFO
)
<<
"send result:"
<<
rlt
;
}
...
...
utility/utility.cpp
View file @
5985d6e1
...
...
@@ -56,7 +56,7 @@ int charset_convert(const char* charset_from, const char* charset_to, const std:
char
*
outbuf
=
buffer
;
size_t
outbytes
=
sizeof
(
buffer
)
-
1
;
ret
=
iconv
(
cd
,
&
inbuf
,
&
inbytes
,
&
outbuf
,
&
outbytes
);
if
(
ret
==
0
)
if
(
ret
==
0
||
errno
==
E2BIG
)
{
string_to
.
append
(
buffer
);
}
...
...
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