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
31862199
Commit
31862199
authored
Mar 25, 2018
by
guanghui.cui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
设置pos优先级
parent
151657fa
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
89 additions
and
18 deletions
+89
-18
base/CommonStruct.h
+2
-1
src/JsonModule.cpp
+22
-7
src/JsonModule.h
+12
-0
src/main.cpp
+53
-10
No files found.
base/CommonStruct.h
View file @
31862199
...
...
@@ -122,7 +122,8 @@ struct customer
struct
orderObj
{
int
fm_cmd
=
0
;
//请求类型
std
::
string
channel
;
//订单渠道
std
::
string
channel
;
//订单渠道
bool
offline_bonus
=
false
;
//是否需要线下累分
int
order_no
=
0
;
//订单序号
std
::
string
order_id
;
//订单标识号
std
::
string
create_time
;
//订单创建时间
...
...
src/JsonModule.cpp
View file @
31862199
...
...
@@ -87,6 +87,12 @@ bool JsonModule::getPushOrders(IN const char* json,OUT orderObj &order)
rapidjson
::
Value
&
channel
=
document
[
"channel"
];
order
.
channel
=
channel
.
GetString
();
if
(
document
.
HasMember
(
"offlinePoints"
)){
rapidjson
::
Value
&
offlinePoints
=
document
[
"offlinePoints"
];
order
.
offline_bonus
=
offlinePoints
.
GetBool
();
}
rapidjson
::
Value
&
token
=
document
[
"token"
];
token
.
GetString
();
...
...
@@ -582,7 +588,7 @@ bool JsonModule::convertInitDataPos2Ods(IN const std::string& data, OUT std::str
writer
.
EndObject
();
re
turn
buffer
.
GetString
();
re
sult
=
buffer
.
GetString
();
return
true
;
...
...
@@ -693,9 +699,6 @@ bool JsonModule::getPosResponseData(const std::string &odsResponse,IN const std:
result
=
_convertToOrderOperationReponseJson
(
odsResponse
.
data
());
rlt
=
true
;
}
else
if
(
fm_cmd
==
REQUEST_TYPE_POS_PRIORITY
){
}
// serverResponseOperationObj obj;
// if(_getServerResponseData(odsResponse.data(),obj)){
...
...
@@ -872,9 +875,6 @@ bool JsonModule::convertDataPos2Ods(const std::string &data, std::string &result
else
if
(
fm_cmd
==
REQUEST_TYPE_GOODS_CHANGE
){
}
else
if
(
fm_cmd
==
REQUEST_TYPE_POS_PRIORITY
){
rlt
=
_convertPOSReqPriorityJson
(
data
,
result
);
}
return
rlt
;
...
...
@@ -920,6 +920,9 @@ std::string JsonModule::_convertToNewOrderJson(orderObj &obj)
writer
.
Key
(
"channel"
);
writer
.
String
(
obj
.
channel
.
c_str
());
writer
.
Key
(
"offline_bonus"
);
writer
.
Bool
(
obj
.
offline_bonus
);
writer
.
Key
(
"order_no"
);
writer
.
Int
(
obj
.
order_no
);
...
...
@@ -1913,4 +1916,15 @@ bool JsonModule::_convertPOSReqPriorityJson(IN const std::string& posReq,OUT con
//odsJson = buffer.GetString();
return
true
;
}
bool
JsonModule
::
convertSetPosPriorityDataPos2Ods
(
IN
const
std
::
string
&
data
,
OUT
std
::
string
&
result
)
{
return
_convertPOSReqPriorityJson
(
data
,
result
);
}
bool
JsonModule
::
getSetPosPriorityBackData
(
IN
const
char
*
inJson
,
OUT
std
::
string
&
outJson
)
{
//缺接口
return
true
;
}
\ No newline at end of file
src/JsonModule.h
View file @
31862199
...
...
@@ -46,6 +46,18 @@ public:
* */
bool
convertInitDataPos2Ods
(
IN
const
std
::
string
&
data
,
OUT
std
::
string
&
result
);
/* 功能:转换POS设置POS优先级数据格式到中台数据格式
* 参数:[1]POS数据格式[2]转换后数据
* 返回:是否转换成功
* */
bool
convertSetPosPriorityDataPos2Ods
(
IN
const
std
::
string
&
data
,
OUT
std
::
string
&
result
);
/* 功能:获取POS设置优先级,ODS返回数据
* 参数:[1]返回json数据 [2]pos需要的json数据
* 返回:是否正确格式
* */
bool
getSetPosPriorityBackData
(
IN
const
char
*
inJson
,
OUT
std
::
string
&
outJson
);
/* 功能:获取POS请求的返回数据
* 参数:[1]状态码[2]消息[3]转换后数据
* 重载:[1]ODS返回数据[2]转换后数据
...
...
src/main.cpp
View file @
31862199
...
...
@@ -15,6 +15,9 @@ INITIALIZE_EASYLOGGINGPP
std
::
string
g_init_data
;
std
::
string
g_init_data_ods_back
;
std
::
string
g_set_pos_priority
;
//设置pos优先级
std
::
string
g_set_pos_priority_ods_back
;
std
::
string
ods_ip
;
std
::
string
pos_ip
=
"127.0.0.1"
;
int
ods_push_port
;
...
...
@@ -23,7 +26,8 @@ int client_listen_port;
int
pos_listen_port
;
std
::
vector
<
orderSendFailedObj
>
vecFailedOrders
;
bool
bRetryThreadRunning
=
false
;
//retry线程是否正在运行
bool
bInitDone
=
false
;
//初始化完成
bool
bInitDone
=
false
;
//初始化完成
bool
bPriorityDone
=
true
;
//设置POS优先级
SQLite
sqlite
;
//函数,订单信息发送给pos
...
...
@@ -71,20 +75,24 @@ void* listen_pos_func(void* arg)
{
posRequestData
=
tmpBuf
;
// 如果为初始化请求则通过长连接socket发送
bool
isInit
=
jsonTool
.
isInitData
(
posRequestData
);
if
(
isInit
)
//bool isInit=jsonTool.isInitData(posRequestData);
int
reqType
=
jsonTool
.
getPushType
(
posRequestData
.
data
());
LOG
(
INFO
)
<<
"reqType.:"
<<
reqType
;
if
(
reqType
==
REQUEST_TYPE_INIT
)
{
bInitDone
=
false
;
if
(
jsonTool
.
checkInitData
(
posRequestData
,
pos_listen_port
)
)
{
g_init_data_ods_back
.
clear
();
//g_init_data = posRequestData;
jsonTool
.
convertInitDataPos2Ods
(
posRequestData
,
g_init_data
);
//jsonTool.getPosResponseData(100, "successful!", responseData);
LOG
(
INFO
)
<<
"POS init data:"
<<
g_init_data
.
c_str
();
LOG
(
INFO
)
<<
"POS init data
.
:"
<<
g_init_data
.
c_str
();
//等待ods返回初始化结果
while
(
true
){
if
(
!
g_init_data_ods_back
.
empty
()){
jsonTool
.
getInitBackData
(
g_init_data_ods_back
.
data
(),
responseData
);
LOG
(
INFO
)
<<
"responseData:"
<<
responseData
.
c_str
();
break
;
}
else
{
...
...
@@ -97,7 +105,29 @@ void* listen_pos_func(void* arg)
{
jsonTool
.
getPosResponseData
(
101
,
"invalid initdata!"
,
responseData
);
}
}
else
}
else
if
(
reqType
==
REQUEST_TYPE_POS_PRIORITY
){
if
(
bInitDone
){
//未完成,缺接口
bPriorityDone
=
false
;
LOG
(
INFO
)
<<
"POS send priority data:"
<<
posRequestData
.
data
();
g_set_pos_priority_ods_back
.
clear
();
jsonTool
.
convertSetPosPriorityDataPos2Ods
(
posRequestData
,
g_set_pos_priority
);
//等待ods返回初始化结果
while
(
true
){
if
(
!
g_set_pos_priority_ods_back
.
empty
()){
jsonTool
.
getSetPosPriorityBackData
(
g_set_pos_priority_ods_back
.
data
(),
responseData
);
break
;
}
else
{
LOG
(
INFO
)
<<
"wait for ods priority back data"
;
sleep
(
1
);
}
}
}
}
else
{
LOG
(
INFO
)
<<
"POS send data:"
<<
posRequestData
.
data
();
// 将POS请求数据转换为中台可接受数据格式
...
...
@@ -137,9 +167,13 @@ void* listen_pos_func(void* arg)
LOG
(
INFO
)
<<
"ODS response data:"
<<
responseData
.
data
();
pos
.
write
(
responseData
.
c_str
());
pos
.
close
();
if
(
isInit
){
if
(
reqType
==
REQUEST_TYPE_INIT
){
bInitDone
=
true
;
//初始化完成,可以接收订单
}
if
(
reqType
==
REQUEST_TYPE_POS_PRIORITY
){
bPriorityDone
=
true
;
//设置pos优先级完成
}
LOG
(
INFO
)
<<
"pos.close"
;
}
else
{
LOG
(
INFO
)
<<
"recv pos pushDate failed"
;
...
...
@@ -204,7 +238,7 @@ int main()
/// 注册回调函数
el
::
Helpers
::
installPreRollOutCallback
(
logRolloutHandler
);
LOG
(
INFO
)
<<
"---------software start---------
.
"
;
LOG
(
INFO
)
<<
"---------software start---------"
;
//sqlite初始化
if
(
!
sqlite
.
initSQLite
()){
...
...
@@ -262,11 +296,10 @@ 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,\"ver\":1
}";
if
(
!
g_init_data
.
empty
())
{
g_init_data_ods_back
.
clear
();
{
if
(
ods
.
send
(
g_init_data
)
)
{
ods
.
receive
(
odsPushData
);
...
...
@@ -302,6 +335,16 @@ int main()
}
}
if
(
!
bPriorityDone
){
LOG
(
INFO
)
<<
"ODS set priority send:"
<<
g_set_pos_priority
.
data
();
if
(
ods
.
send
(
g_set_pos_priority
)
)
{
ods
.
receive
(
odsPushData
);
g_set_pos_priority_ods_back
=
odsPushData
;
LOG
(
INFO
)
<<
"ODS set priority back:"
<<
odsPushData
.
data
();
}
}
if
(
ods
.
receive
(
odsPushData
)
)
{
LOG
(
INFO
)
<<
"----------------recved ODS data------------------."
;
...
...
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