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
5f2c1796
Commit
5f2c1796
authored
Aug 30, 2018
by
guanghui.cui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1、增加判断预警类型,用于处理非法请求 2、ods长连接socket对象定义为全局,解决设置pos优先级的问题
parent
13eea5e2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
20 deletions
+28
-20
src/JsonModule.cpp
+4
-2
src/main.cpp
+24
-18
No files found.
src/JsonModule.cpp
View file @
5f2c1796
...
...
@@ -919,7 +919,9 @@ bool JsonModule::convertDataOds2Pos(const std::string &data, std::string &result
result
=
_convertToNewOrderJson
(
order
);
}
}
else
{
rlt
=
false
;
//如果推送报文不是以上类型,则返回失败
}
return
rlt
;
}
...
...
@@ -1717,7 +1719,7 @@ void JsonModule::_getStockWarnObj(IN const char* json,OUT stockWarnObj &warn_obj
GetJsonStringSafe
(
document
,
"barCounter"
);
detail
.
source
=
GetJsonStringSafe
(
document
,
"channel"
);
GetJson
Int
Safe
(
document
,
"id"
);
GetJson
String
Safe
(
document
,
"id"
);
GetJsonStringSafe
(
document
,
"memo"
);
GetJsonStringSafe
(
document
,
"pcId"
);
GetJsonStringSafe
(
document
,
"posId"
);
...
...
src/main.cpp
View file @
5f2c1796
...
...
@@ -19,7 +19,7 @@
INITIALIZE_EASYLOGGINGPP
#define VERSION "1.0.6 beta
3
" //版本号
#define VERSION "1.0.6 beta
5
" //版本号
std
::
string
g_init_data
;
std
::
string
g_init_data_ods_back
;
...
...
@@ -36,6 +36,7 @@ int pos_listen_port;
bool
bInitDone
=
false
;
//初始化完成
bool
bPriorityDone
=
true
;
//设置POS优先级
TCPClient
longConnectionOds
;
//长连接tcp对象
//函数,订单信息发送给pos
bool
order_send_to_pos
(
IN
std
::
string
&
order_json
,
IN
std
::
string
&
ods_json
,
OUT
std
::
string
&
back_json
);
...
...
@@ -90,7 +91,7 @@ void* listen_pos_func(void* arg)
int
reqType
=
jsonTool
.
getPushType
(
posRequestData
.
data
());
LOG
(
INFO
)
<<
"pos reqType:"
<<
reqType
;
if
(
reqType
==
REQUEST_TYPE_INIT
)
{
{
bInitDone
=
false
;
if
(
jsonTool
.
checkInitData
(
posRequestData
,
pos_listen_port
)
)
{
...
...
@@ -100,6 +101,7 @@ void* listen_pos_func(void* arg)
jsonTool
.
convertInitDataPos2Ods
(
posRequestData
,
g_init_data
);
//jsonTool.getPosResponseData(100, "successful!", responseData);
LOG
(
INFO
)
<<
"INIT PLUGIN ===>> ODS:"
<<
g_init_data
.
c_str
();
longConnectionOds
.
close
();
//关闭长连接,等待重连
//等待ods返回初始化结果
while
(
true
){
if
(
!
g_init_data_ods_back
.
empty
()){
...
...
@@ -236,8 +238,9 @@ int main(int argc,char *argv[])
////--------test------------
//JsonModule jsonTest;
//std::string json = "{\"alertTime\":1534416551000,\"channel\":\"201\",\"id\":117049102732151083,\"pcId\":\"10\",\"qty\":0,\"saftQty\":1,\"selfMacId\":\"2027490121\",\"shelfNo\":\"20274901210405\",\"sku\":\"20627836\",\"storeId\":\"202749\",\"pk_id\":1}";
//std::string json = "{\"key\":\"网络故障\",\"notifyDate\":1535240399875,\"notifyDesc\":\"网络故障\",\"notifyType\":0,\"storeId\":\"403219\",\"pk_id\":415,\"fm_cmd\":1018,\"fm_cmd\":1018,\"fm_cmd\":1018,\"fm_cmd\":1018,\"fm_cmd\":1018,\"fm_cmd\":1018,\"fm_cmd\":1018,\"fm_cmd\":1018,\"fm_cmd\":1018,\"fm_cmd\":1018,\"fm_cmd\":1018,\"fm_cmd\":1018,\"fm_cmd\":1018,\"fm_cmd\":1018,\"fm_cmd\":1018}";
//std::string rltTest;
//jsonTest.convertDataOds2Pos(json, rltTest);
//
bool bTest =
jsonTest.convertDataOds2Pos(json, rltTest);
////-------------------------
if
(
2
==
argc
&&
0
==
strcmp
(
"-v"
,
argv
[
1
]))
{
printf
(
"version:%s
\n
"
,
VERSION
);
...
...
@@ -307,7 +310,7 @@ int main(int argc,char *argv[])
#endif // WIN32
TCPClient
ods
;
//
TCPClient ods;
JsonModule
jsonTool
;
while
(
true
)
...
...
@@ -317,12 +320,12 @@ int main(int argc,char *argv[])
std
::
string
responseData
;
// 判断是否成功连接ODS
if
(
!
o
ds
.
isValid
()
)
if
(
!
longConnectionO
ds
.
isValid
()
)
{
if
(
o
ds
.
doConnect
(
ods_push_port
,
ods_ip
.
c_str
())
)
if
(
longConnectionO
ds
.
doConnect
(
ods_push_port
,
ods_ip
.
c_str
())
)
{
LOG
(
INFO
)
<<
"connect ODS successful"
;
o
ds
.
setSocketTimeout
(
ods_socket_timeout
);
//设置超时时间10s
longConnectionO
ds
.
setSocketTimeout
(
ods_socket_timeout
);
//设置超时时间10s
// 注册socket信息
while
(
true
)
{
...
...
@@ -330,20 +333,20 @@ int main(int argc,char *argv[])
//g_init_data = "{\"fm_cmd\":1000,\"listen_port\":24445,\"storeId\":\"202557\",\"pos_id\":\"1\",\"operator_id\":\"17076352\",\"is_master\":true,\"ver\":1}";
if
(
!
g_init_data
.
empty
())
{
if
(
o
ds
.
send
(
g_init_data
)
)
if
(
longConnectionO
ds
.
send
(
g_init_data
)
)
{
o
ds
.
receive
(
odsPushData
);
longConnectionO
ds
.
receive
(
odsPushData
);
g_init_data_ods_back
=
odsPushData
;
LOG
(
INFO
)
<<
"INIT ODS ===>> PLUGIN:"
<<
odsPushData
.
data
();
if
(
odsPushData
.
empty
()
||
!
jsonTool
.
isInitBackValid
(
odsPushData
.
data
()))
{
LOG
(
INFO
)
<<
"invalid data,close connect"
;
o
ds
.
close
();
//当连接到负载均衡,并没有和ods建立连接的时候。返回值为空,所以应该关闭重新连接
longConnectionO
ds
.
close
();
//当连接到负载均衡,并没有和ods建立连接的时候。返回值为空,所以应该关闭重新连接
os_sleep
(
10
);
}
int
count
=
0
;
while
(
!
bInitDone
){
LOG
(
INFO
)
<<
"wait for init done"
;
if
(
!
o
ds
.
isValid
()
){
if
(
!
longConnectionO
ds
.
isValid
()
){
LOG
(
INFO
)
<<
"ods is not valid"
;
os_sleep
(
1
);
//防止在ods挂掉后狂刷日志
break
;
...
...
@@ -352,7 +355,7 @@ int main(int argc,char *argv[])
count
++
;
//如果10s没有初始化完成,则跳出循环,重新连接
if
(
10
==
count
){
o
ds
.
close
();
longConnectionO
ds
.
close
();
break
;
}
}
...
...
@@ -375,15 +378,15 @@ int main(int argc,char *argv[])
if
(
!
bPriorityDone
){
LOG
(
INFO
)
<<
"ODS set priority send:"
<<
g_set_pos_priority
.
data
();
if
(
o
ds
.
send
(
g_set_pos_priority
)
)
if
(
longConnectionO
ds
.
send
(
g_set_pos_priority
)
)
{
o
ds
.
receive
(
odsPushData
);
longConnectionO
ds
.
receive
(
odsPushData
);
g_set_pos_priority_ods_back
=
odsPushData
;
LOG
(
INFO
)
<<
"ODS set priority back:"
<<
odsPushData
.
data
();
}
}
if
(
o
ds
.
receive
(
odsPushData
)
)
if
(
longConnectionO
ds
.
receive
(
odsPushData
)
)
{
LOG
(
INFO
)
<<
"---------------- ODS ===>> PLUGIN ---------------"
;
LOG
(
INFO
)
<<
odsPushData
;
...
...
@@ -398,6 +401,9 @@ int main(int argc,char *argv[])
jsonTool
.
getOdsResponseData
(
101
,
"send to pos failed or receive data illegal!"
,
odsPushData
,
responseData
);
}
}
else
{
jsonTool
.
getOdsResponseData
(
101
,
"convert data to [POS] format failed,empty json!"
,
odsPushData
,
responseData
);
}
}
else
{
...
...
@@ -407,12 +413,12 @@ int main(int argc,char *argv[])
//test
//responseData="{\"fm_cmd\": 2,\"order_id\" : \"1234\",\"status\" : 1,\"channel\" : \"1234\",\"status_code\" : 100,\"msg\" : \"\"}";
bool
rlt
=
o
ds
.
send
(
responseData
);
bool
rlt
=
longConnectionO
ds
.
send
(
responseData
);
LOG
(
INFO
)
<<
"send to ods result:"
<<
rlt
;
}
else
if
(
1
==
dataType
){
if
(
!
bInitDone
){
o
ds
.
setValid
(
false
);
longConnectionO
ds
.
setValid
(
false
);
LOG
(
INFO
)
<<
"maybe pos restart,reconnect!!!"
;
}
}
...
...
@@ -422,7 +428,7 @@ int main(int argc,char *argv[])
}
else
{
o
ds
.
close
();
longConnectionO
ds
.
close
();
os_sleep
(
2
);
//防止在ods挂掉后狂刷日志
LOG
(
INFO
)
<<
"recv ODS pushData failed or timeout"
;
}
...
...
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