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
97499271
Commit
97499271
authored
Mar 22, 2018
by
guanghui.cui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
通用预警
parent
27811ff8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
134 additions
and
0 deletions
+134
-0
base/BaseDefine.h
+1
-0
src/JsonModule.cpp
+131
-0
src/JsonModule.h
+2
-0
No files found.
base/BaseDefine.h
View file @
97499271
...
...
@@ -27,6 +27,7 @@
#define REQUEST_TYPE_GOODS_CHANGE 1004 //商品更换
#define REQUEST_TYPE_POS_PRIORITY 1005 //设置POS优先级
#define REQUEST_TYPE_STOCK_WARN 1006 //库存预警通知
#define REQUEST_TYPE_COMMON_WARN 1007 //通用预警通知
//配送类型对照表
#define DELIVERY_TYPE_SELF "self" //自配送
...
...
src/JsonModule.cpp
View file @
97499271
...
...
@@ -696,6 +696,9 @@ bool JsonModule::getOdsResponseData(int status_code, const std::string &msg, std
else
if
(
fm_cmd
==
REQUEST_TYPE_STOCK_WARN
){
rlt
=
_getStockWarnResponseJson
(
posResponse
,
orderData
,
odsData
,
result
);
}
else
if
(
fm_cmd
==
REQUEST_TYPE_COMMON_WARN
){
rlt
=
_getCommonWarnResponseJson
(
posResponse
,
orderData
,
odsData
,
result
);
}
return
rlt
;
}
...
...
@@ -722,6 +725,9 @@ bool JsonModule::convertDataOds2Pos(const std::string &data, std::string &result
result
=
_convertToStockWarnJson
(
warn_obj
);
}
else
if
(
pushType
==
ODS_PUSH_TYPE_COMMON
){
result
=
_convertToCommonWarnJson
(
data
.
c_str
());
}
else
{
orderObj
order
;
rlt
=
getPushOrders
(
data
.
c_str
(),
order
);
...
...
@@ -1544,4 +1550,128 @@ bool JsonModule::_getStockWarnResponseJson(IN const std::string& posResponse, IN
result
=
buffer
.
GetString
();
return
true
;
}
std
::
string
JsonModule
::
_convertToCommonWarnJson
(
IN
const
char
*
json
)
{
std
::
string
notifyDate
,
notifyDesc
,
rackNo
,
storeId
,
terminalNo
;
int
notifyType
=
0
;
rapidjson
::
Document
document
;
// 定义一个Document对象
document
.
Parse
(
json
);
// 解析,Parse()无返回值,也不会抛异常
if
(
document
.
HasParseError
())
// 通过HasParseError()来判断解析是否成功
{
LOG
(
ERROR
)
<<
"JSON parse error:"
<<
document
.
GetParseError
()
<<
":"
<<
document
.
GetErrorOffset
();
return
""
;
}
else
{
rapidjson
::
Value
&
vNotifyDate
=
document
[
"notifyDate"
];
rapidjson
::
Value
&
vNotifyDesc
=
document
[
"notifyDesc"
];
rapidjson
::
Value
&
vNotifyType
=
document
[
"notifyType"
];
rapidjson
::
Value
&
vRackNo
=
document
[
"rackNo"
];
rapidjson
::
Value
&
vStoreId
=
document
[
"storeId"
];
rapidjson
::
Value
&
vTerminalNo
=
document
[
"terminalNo"
];
int64_t
iDate
=
vNotifyDate
.
GetInt64
();
notifyDate
=
getdatetime
(
iDate
);
if
(
!
vNotifyDesc
.
IsNull
()){
notifyDesc
=
vNotifyDesc
.
GetString
();
}
notifyType
=
vNotifyType
.
GetInt
();
rackNo
=
vRackNo
.
GetString
();
storeId
=
vStoreId
.
GetString
();
terminalNo
=
vTerminalNo
.
GetString
();
}
rapidjson
::
StringBuffer
buffer
;
rapidjson
::
Writer
<
rapidjson
::
StringBuffer
>
writer
(
buffer
);
writer
.
StartObject
();
writer
.
Key
(
"fm_cmd"
);
writer
.
Int
(
REQUEST_TYPE_COMMON_WARN
);
writer
.
Key
(
"notifyDate"
);
writer
.
String
(
notifyDate
.
c_str
());
writer
.
Key
(
"notifyDesc"
);
writer
.
String
(
notifyDesc
.
c_str
());
writer
.
Key
(
"notifyType"
);
writer
.
Int
(
notifyType
);
writer
.
Key
(
"rackNo"
);
writer
.
String
(
rackNo
.
c_str
());
writer
.
Key
(
"storeId"
);
writer
.
String
(
storeId
.
c_str
());
writer
.
Key
(
"terminalNo"
);
writer
.
String
(
terminalNo
.
c_str
());
writer
.
EndObject
();
return
buffer
.
GetString
();
}
bool
JsonModule
::
_getCommonWarnResponseJson
(
IN
const
std
::
string
&
posResponse
,
IN
const
std
::
string
&
orderData
,
IN
const
std
::
string
&
odsData
,
OUT
std
::
string
&
result
)
{
std
::
string
notifyDate
,
rackNo
,
storeId
,
terminalNo
;
int64_t
iDatetime
=
0
;
rapidjson
::
Document
document
,
document1
;
// 定义一个Document对象
document1
.
Parse
(
odsData
.
data
());
// 解析,Parse()无返回值,也不会抛异常
if
(
document1
.
HasParseError
())
// 通过HasParseError()来判断解析是否成功
{
LOG
(
ERROR
)
<<
"JSON odsData _getCommonWarnResponseJson parse error:"
<<
document1
.
GetParseError
()
<<
":"
<<
document1
.
GetErrorOffset
();
return
false
;
}
else
{
rapidjson
::
Value
&
vNotifyDate
=
document1
[
"notifyDate"
];
rapidjson
::
Value
&
vRackNo
=
document1
[
"rackNo"
];
rapidjson
::
Value
&
vStoreId
=
document1
[
"storeId"
];
rapidjson
::
Value
&
vTerminalNo
=
document1
[
"terminalNo"
];
iDatetime
=
vNotifyDate
.
GetInt64
();
rackNo
=
vRackNo
.
GetString
();
storeId
=
vStoreId
.
GetString
();
terminalNo
=
vTerminalNo
.
GetString
();
}
document
.
Parse
(
posResponse
.
c_str
());
if
(
document
.
HasParseError
())
// 通过HasParseError()来判断解析是否成功
{
LOG
(
ERROR
)
<<
"JSON posResponse _getCommonWarnResponseJson parse error:"
<<
document1
.
GetParseError
()
<<
":"
<<
document1
.
GetErrorOffset
();
return
false
;
}
int
status_code
=
document
[
"status_code"
].
GetInt
();
rapidjson
::
StringBuffer
buffer
;
rapidjson
::
Writer
<
rapidjson
::
StringBuffer
>
writer
(
buffer
);
writer
.
StartObject
();
writer
.
Key
(
"fm_cmd"
);
writer
.
Int
(
ODS_PUSH_TYPE_COMMON_BACK
);
writer
.
Key
(
"store_id"
);
writer
.
String
(
storeId
.
c_str
());
writer
.
Key
(
"rack_no"
);
writer
.
String
(
rackNo
.
c_str
());
writer
.
Key
(
"terminal_no"
);
writer
.
String
(
terminalNo
.
c_str
());
writer
.
Key
(
"alert_time"
);
writer
.
Int64
(
iDatetime
);
writer
.
Key
(
"status_code"
);
writer
.
Int
(
status_code
);
writer
.
EndObject
();
result
=
buffer
.
GetString
();
return
true
;
}
\ No newline at end of file
src/JsonModule.h
View file @
97499271
...
...
@@ -96,9 +96,11 @@ private:
std
::
string
_convertToOrderStatusJson
(
orderStatusObj
&
obj
);
std
::
string
_convertToRefundJson
(
refundObj
&
obj
);
std
::
string
_convertToStockWarnJson
(
stockWarnObj
&
obj
);
std
::
string
_convertToCommonWarnJson
(
IN
const
char
*
json
);
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
,
IN
const
std
::
string
&
odsData
,
OUT
std
::
string
&
result
);
bool
_getCommonWarnResponseJson
(
IN
const
std
::
string
&
posResponse
,
IN
const
std
::
string
&
orderData
,
IN
const
std
::
string
&
odsData
,
OUT
std
::
string
&
result
);
};
#endif
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