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
994a5e3d
Commit
994a5e3d
authored
Mar 07, 2018
by
guanghui.cui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
库存预警接口
parent
e40833f5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
116 additions
and
11 deletions
+116
-11
base/BaseDefine.h
+5
-0
base/CommonStruct.h
+27
-4
src/JsonModule.cpp
+75
-6
src/JsonModule.h
+6
-0
src/main.cpp
+3
-1
No files found.
base/BaseDefine.h
View file @
994a5e3d
...
...
@@ -79,4 +79,8 @@
#define ODS_ORDERSTATUS_REFUND_DISAGREE 40 //不同意退款
#define ODS_ORDERSTATUS_REFUND_COMPLETE 100 //退款完成
//推送类型
#define ODS_PUSH_TYPE_HEARTBEAT 3 //心跳
#define ODS_PUSH_TYPE_STOCKWARN 1015 //库存预警
#endif
\ No newline at end of file
base/CommonStruct.h
View file @
994a5e3d
...
...
@@ -13,9 +13,8 @@ struct product
std
::
string
bag_id
;
//商品口袋ID
std
::
string
name
;
//商品名称
int
price
=
0
;
//商品价格
int
qty
=
0
;
//商品数量
(商品使用)
int
qty
=
0
;
//商品数量
std
::
string
sku
;
//商品SKU
int
stock
=
0
;
//商品当前库存(库存预警使用)
};
//商品规格
...
...
@@ -163,11 +162,27 @@ struct refundObj
std
::
vector
<
productAttr
>
vecProducts
;
//商品数组
};
//预警商品
struct
productWarn
{
std
::
string
source
;
//商品来源
std
::
string
attributes
;
//商品属性
std
::
string
combo_id
;
//商品组合ID
std
::
string
bom_id
;
//商品分组组合ID
std
::
string
bag_id
;
//商品口袋ID
std
::
string
name
;
//商品名称
int
price
=
0
;
//商品价格
std
::
string
sku
;
//商品SKU
int
stock
=
0
;
//商品当前库存
int
safeQty
=
0
;
//商品安全库存
std
::
string
alertTime
;
//预警时间
};
//库存预警
struct
stockWarnObj
{
int
fm_cmd
=
0
;
//请求类型(1006)
std
::
vector
<
product
>
vecProducts
;
//商品数组
int
fm_cmd
=
0
;
//请求类型(1006)
std
::
vector
<
product
Warn
>
vecProducts
;
//商品数组
};
//POS订单处理请求
...
...
@@ -186,4 +201,11 @@ struct serverResponseOperationObj
std
::
string
ver
;
};
//订单发送给pos失败结构体
struct
orderSendFailedObj
{
std
::
string
order_json
;
//订单json字符串
unsigned
int
timestamp
=
0
;
//接收到订单时候的时间戳
};
#endif
\ No newline at end of file
src/JsonModule.cpp
View file @
994a5e3d
...
...
@@ -651,13 +651,24 @@ bool JsonModule::convertDataPos2Ods(const std::string &data, std::string &result
bool
JsonModule
::
convertDataOds2Pos
(
const
std
::
string
&
data
,
std
::
string
&
result
)
{
bool
rlt
=
true
;
orderObj
order
;
rlt
=
getPushOrders
(
data
.
c_str
(),
order
);
if
(
rlt
)
{
result
=
_convertToNewOrderJson
(
order
);
int
pushType
=
getPushType
(
data
.
c_str
());
if
(
pushType
==
ODS_PUSH_TYPE_STOCKWARN
){
//库存预警
stockWarnObj
warn_obj
;
_getStockWarnObj
(
data
.
c_str
(),
warn_obj
);
result
=
_convertToStockWarnJson
(
warn_obj
);
}
else
{
orderObj
order
;
rlt
=
getPushOrders
(
data
.
c_str
(),
order
);
if
(
rlt
)
{
result
=
_convertToNewOrderJson
(
order
);
}
}
return
rlt
;
}
...
...
@@ -1105,6 +1116,12 @@ std::string JsonModule::_convertToStockWarnJson(stockWarnObj &obj)
writer
.
Key
(
"sku"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
sku
.
c_str
());
writer
.
Key
(
"safeQty"
);
writer
.
Int
(
obj
.
vecProducts
[
i
].
safeQty
);
writer
.
Key
(
"alertTime"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
alertTime
.
c_str
());
writer
.
EndObject
();
//-----------------end 单个商品------------------
}
...
...
@@ -1297,4 +1314,55 @@ std::string JsonModule::_convertServerResponseToJson(serverResponseOperationObj
writer
.
EndObject
();
return
buffer
.
GetString
();
}
void
JsonModule
::
_getStockWarnObj
(
IN
const
char
*
json
,
OUT
stockWarnObj
&
warn_obj
)
{
rapidjson
::
Document
document
;
// 定义一个Document对象
document
.
Parse
(
json
);
// 解析,Parse()无返回值,也不会抛异常
if
(
document
.
HasParseError
())
// 通过HasParseError()来判断解析是否成功
{
LOG
(
ERROR
)
<<
"_getStockWarnObj JSON parse error:"
<<
document
.
GetParseError
()
<<
":"
<<
document
.
GetErrorOffset
();
}
else
{
rapidjson
::
Value
&
products_array
=
document
[
"products"
];
if
(
products_array
.
IsArray
())
{
for
(
unsigned
int
i
=
0
;
i
<
products_array
.
Size
();
i
++
){
rapidjson
::
Value
&
product_obj
=
products_array
[
i
];
productWarn
detail
;
rapidjson
::
Value
&
qty
=
product_obj
[
"qty"
];
detail
.
stock
=
qty
.
GetInt
();
rapidjson
::
Value
&
sku
=
product_obj
[
"sku"
];
detail
.
sku
=
sku
.
GetString
();
rapidjson
::
Value
&
safeQty
=
product_obj
[
"safeQty"
];
detail
.
safeQty
=
safeQty
.
GetInt
();
rapidjson
::
Value
&
alertTime
=
product_obj
[
"alertTime"
];
detail
.
alertTime
=
alertTime
.
GetString
();
warn_obj
.
vecProducts
.
push_back
(
detail
);
}
}
}
}
int
JsonModule
::
getPushType
(
IN
const
char
*
data
)
{
rapidjson
::
Document
document
;
// 定义一个Document对象
document
.
Parse
(
data
);
// 解析,Parse()无返回值,也不会抛异常
if
(
document
.
HasParseError
())
// 通过HasParseError()来判断解析是否成功
{
LOG
(
ERROR
)
<<
"JSON parse error:"
<<
document
.
GetParseError
()
<<
":"
<<
document
.
GetErrorOffset
();
return
0
;
}
if
(
document
.
HasMember
(
"fm_cmd"
)){
return
document
[
"fm_cmd"
].
GetInt
();
}
return
0
;
}
\ No newline at end of file
src/JsonModule.h
View file @
994a5e3d
...
...
@@ -62,6 +62,11 @@ public:
* */
bool
convertDataOds2Pos
(
IN
const
std
::
string
&
data
,
OUT
std
::
string
&
result
);
/* 功能:获取推送类型
* 参数:[1]待判断数据
* 返回:...
* */
int
getPushType
(
IN
const
char
*
data
);
private
:
std
::
string
_getDeliveryTypeString
(
int
type
);
...
...
@@ -70,6 +75,7 @@ private:
void
_getStatusObj
(
IN
orderObj
&
order_obj
,
OUT
orderStatusObj
&
status_obj
);
void
_getRefundObj
(
IN
orderObj
&
order_obj
,
OUT
refundObj
&
refund_obj
);
void
_getStockWarnObj
(
IN
const
char
*
json
,
OUT
stockWarnObj
&
warn_obj
);
//pos操作请求json转换为结构体
bool
_getPOSOperationObj
(
IN
const
char
*
data
,
OUT
orderOperationObj
&
operation_obj
);
...
...
src/main.cpp
View file @
994a5e3d
...
...
@@ -87,6 +87,7 @@ void* listen_pos_func(void* arg)
if
(
ods
.
receive
(
tmp
)
)
{
jsonTool
.
getPosResponseData
(
tmp
,
responseData
);
LOG
(
INFO
)
<<
"ODS response data:"
<<
responseData
.
data
();
}
else
{
jsonTool
.
getPosResponseData
(
101
,
"receive data from [ODS] failed!"
,
responseData
);
...
...
@@ -194,7 +195,7 @@ int main()
// 注册socket信息
while
(
true
)
{
g_init_data
=
"{
\"
fm_cmd
\"
: 1000,
\"
store_id
\"
:
\"
208888
\"
,
\"
pos_id
\"
:
\"
0001
\"
,
\"
operator_id
\"
:
\"
00001
\"
,
\"
business_date
\"
:
\"
20171225
\"
,
\"
is_master
\"
: true,
\"
listen_port
\"
: 3289}"
;
//
g_init_data = "{\"fm_cmd\": 1000,\"store_id\": \"208888\",\"pos_id\": \"0001\",\"operator_id\": \"00001\",\"business_date\": \"20171225\",\"is_master\": true,\"listen_port\": 3289}";
if
(
!
g_init_data
.
empty
())
{
...
...
@@ -235,6 +236,7 @@ int main()
char
tmpBuf
[
BUF_SIZE
]
=
{
0
};
if
(
pos
.
read
(
tmpBuf
,
sizeof
(
tmpBuf
))
)
{
LOG
(
INFO
)
<<
"pos response data:"
<<
tmpBuf
;
std
::
string
tmp
(
tmpBuf
);
jsonTool
.
getOdsResponseData
(
tmp
,
odsPushData
,
responseData
);
}
else
...
...
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