Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fmtakeout
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
李定达
fmtakeout
Commits
b096f645
Commit
b096f645
authored
Sep 27, 2018
by
李定达
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.添加token7天过期重新登陆;2.调整退单工作流为非阻塞放行事件循环
parent
4b517863
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
154 additions
and
20 deletions
+154
-20
takeout/control/ordergetwork.cpp
+12
-0
takeout/control/ordergetwork.h
+3
-0
takeout/control/orderpushwork.cpp
+128
-19
takeout/control/orderpushwork.h
+10
-0
takeout/main.cpp
+1
-1
No files found.
takeout/control/ordergetwork.cpp
View file @
b096f645
...
...
@@ -21,12 +21,24 @@ OrderGetWork::OrderGetWork(QObject *parent) : QObject(parent)
_islogin
=
false
;
_timestamp
=
"0"
;
connect
(
&
_timer
,
&
QTimer
::
timeout
,
[
this
]
()
{
QLOG_INFO
()
<<
"Timeout Start login again ..."
;
QLOG_DEBUG
()
<<
"StoreInfo : "
<<
_storeinfo
;
if
(
!
_storeinfo
.
isEmpty
())
{
_islogin
=
false
;
loginStart
();
}
});
//订阅需要拉单的事件
FMApplication
::
subscibeEvent
(
this
,
PosEvent
::
s_need_get_order
);
//订阅操作订单的事件
FMApplication
::
subscibeEvent
(
this
,
PosEvent
::
s_opt_order
);
//
FMApplication
::
subscibeEvent
(
this
,
PosEvent
::
s_login_storeinfo
);
_timer
.
start
(
7
*
24
*
60
*
60
*
1000
);
}
void
OrderGetWork
::
workStart
()
...
...
takeout/control/ordergetwork.h
View file @
b096f645
...
...
@@ -3,6 +3,7 @@
#include <QObject>
#include <QFile>
#include <QTimer>
#include <QJsonObject>
#include <QJsonArray>
#include <QVariantMap>
...
...
@@ -98,6 +99,8 @@ private:
QString
_token
;
//是否自动接单
QString
_autoconfirm
;
//自动重新登录
QTimer
_timer
;
};
class
OrderGetDataProcess
...
...
takeout/control/orderpushwork.cpp
View file @
b096f645
...
...
@@ -16,11 +16,28 @@
OrderPushWork
::
OrderPushWork
(
QObject
*
parent
)
:
QObject
(
parent
)
{
_socket
=
NULL
;
_socket
=
new
QSslSocket
;
_stopflag
=
1
;
_needlogin
=
1
;
_server_index
=
-
1
;
_token
=
QString
(
""
);
_serurl
.
clear
();
_istimeout
=
true
;
connect
(
_socket
,
&
QSslSocket
::
connected
,
[
this
]
()
{
_istimeout
=
false
;
emit
connected
();
});
connect
(
_socket
,
&
QSslSocket
::
readyRead
,
[
this
]
()
{
_istimeout
=
false
;
emit
readready
();
});
connect
(
_socket
,
&
QSslSocket
::
bytesWritten
,
[
this
]
(
quint64
writebyte
)
{
_istimeout
=
false
;
emit
writeready
();
});
FMApplication
::
subscibeEvent
(
this
,
PosEvent
::
s_token_change
);
FMApplication
::
subscibeEvent
(
this
,
PosEvent
::
s_login_storeinfo
);
...
...
@@ -32,6 +49,7 @@ OrderPushWork::~OrderPushWork()
{
if
(
_socket
->
isOpen
())
_socket
->
close
();
delete
_socket
;
_socket
=
NULL
;
}
}
...
...
@@ -41,11 +59,6 @@ void OrderPushWork::setStoreinfo(const QVariantMap &storeinfo)
_storeinfo
=
storeinfo
;
}
//void OrderPushWork::setServicelist(const QStringList &servicelist)
//{
// _servicelist = servicelist;
//}
QStringList
OrderPushWork
::
servicelist
()
const
{
return
_servicelist
;
...
...
@@ -73,7 +86,10 @@ bool OrderPushWork::event(QEvent *e)
GETEVENTINFO
(
token
,
e
,
QString
);
_token_lock
.
unlock
();
QLOG_DEBUG
()
<<
"$$$:"
<<
token
;
_token
=
token
;
_needlogin
=
1
;
emit
quit
();
return
true
;
...
...
@@ -107,7 +123,7 @@ bool OrderPushWork::connectTcpServer()
QLOG_INFO
()
<<
"ip:"
<<
ip
<<
"; port:"
<<
port
;
_socket
=
new
QSslSocket
();
//
_socket = new QSslSocket();
_socket
->
addCaCertificates
(
qApp
->
applicationDirPath
()
+
"/"
+
"microwstest.sandload.cn.pem"
);
...
...
@@ -122,14 +138,27 @@ bool OrderPushWork::connectTcpServer()
QLOG_INFO
()
<<
_socket
->
errorString
();
_istimeout
=
true
;
_socket
->
connectToHostEncrypted
(
ip
,
port
);
bool
flag
=
_socket
->
waitForConnected
(
10
*
1000
);
//bool flag = _socket->waitForConnected(10*1000);
{
QEventLoop
loop
;
QTimer
timer
;
connect
(
this
,
&
OrderPushWork
::
quit
,
&
loop
,
&
QEventLoop
::
quit
);
connect
(
&
timer
,
&
QTimer
::
timeout
,
&
loop
,
&
QEventLoop
::
quit
);
connect
(
this
,
&
OrderPushWork
::
connected
,
&
loop
,
&
QEventLoop
::
quit
);
QLOG_INFO
()
<<
_socket
->
errorString
()
<<
flag
;
timer
.
start
(
10
*
1000
)
;
return
flag
;
loop
.
exec
();
}
QLOG_INFO
()
<<
_socket
->
errorString
()
<<
_istimeout
;
return
!
_istimeout
;
}
bool
OrderPushWork
::
loginTcpServer
()
...
...
@@ -146,15 +175,47 @@ bool OrderPushWork::loginTcpServer()
QLOG_INFO
()
<<
"tcp login request : "
<<
requestdata
.
toHex
();
_istimeout
=
true
;
_socket
->
write
(
requestdata
);
if
(
!
_socket
->
waitForBytesWritten
(
10
*
1000
))
{
QEventLoop
loop
;
QTimer
timer
;
connect
(
this
,
&
OrderPushWork
::
quit
,
&
loop
,
&
QEventLoop
::
quit
);
connect
(
&
timer
,
&
QTimer
::
timeout
,
&
loop
,
&
QEventLoop
::
quit
);
connect
(
this
,
&
OrderPushWork
::
writeready
,
&
loop
,
&
QEventLoop
::
quit
);
timer
.
start
(
10
*
1000
);
loop
.
exec
();
}
//if(!_socket->waitForBytesWritten(10*1000))
if
(
_istimeout
)
{
QLOG_ERROR
()
<<
"send msg to service failed"
<<
_socket
->
errorString
();
return
false
;
}
if
(
!
_socket
->
waitForReadyRead
(
30
*
1000
))
_istimeout
=
true
;
{
QEventLoop
loop
;
QTimer
timer
;
connect
(
this
,
&
OrderPushWork
::
quit
,
&
loop
,
&
QEventLoop
::
quit
);
connect
(
&
timer
,
&
QTimer
::
timeout
,
&
loop
,
&
QEventLoop
::
quit
);
connect
(
this
,
&
OrderPushWork
::
readready
,
&
loop
,
&
QEventLoop
::
quit
);
timer
.
start
(
30
*
1000
);
loop
.
exec
();
}
//if(!_socket->waitForReadyRead(30*1000))
if
(
_istimeout
)
{
QLOG_ERROR
()
<<
"receive msg from service failed"
<<
_socket
->
errorString
();
return
false
;
...
...
@@ -190,11 +251,27 @@ bool OrderPushWork::loginTcpServer()
void
OrderPushWork
::
heartBeatTcpService
()
{
while
(
_stopflag
)
while
(
_stopflag
&&
!
_needlogin
)
{
QLOG_INFO
()
<<
"wait recv json ..."
;
if
(
!
_socket
->
waitForReadyRead
(
4
*
60
*
1000
))
_istimeout
=
true
;
{
QEventLoop
loop
;
QTimer
timer
;
connect
(
this
,
&
OrderPushWork
::
quit
,
&
loop
,
&
QEventLoop
::
quit
);
connect
(
&
timer
,
&
QTimer
::
timeout
,
&
loop
,
&
QEventLoop
::
quit
);
connect
(
this
,
&
OrderPushWork
::
readready
,
&
loop
,
&
QEventLoop
::
quit
);
timer
.
start
(
4
*
60
*
1000
);
loop
.
exec
();
}
//if(!_socket->waitForReadyRead(4*60*1000))
if
(
_istimeout
)
break
;
quint32
tmplenandsynSeq
=
0
;
...
...
@@ -232,9 +309,24 @@ void OrderPushWork::heartBeatTcpService()
QLOG_INFO
()
<<
"write len : "
<<
len
;
bool
fl
=
_socket
->
waitForBytesWritten
();
//bool fl = _socket->waitForBytesWritten();
_istimeout
=
true
;
{
QEventLoop
loop
;
QTimer
timer
;
QLOG_INFO
()
<<
"waitForBytesWritten : "
<<
fl
;
connect
(
this
,
&
OrderPushWork
::
quit
,
&
loop
,
&
QEventLoop
::
quit
);
connect
(
&
timer
,
&
QTimer
::
timeout
,
&
loop
,
&
QEventLoop
::
quit
);
connect
(
this
,
&
OrderPushWork
::
writeready
,
&
loop
,
&
QEventLoop
::
quit
);
timer
.
start
(
30
*
1000
);
loop
.
exec
();
}
QLOG_INFO
()
<<
"waitForBytesWritten : "
<<
_istimeout
;
continue
;
}
...
...
@@ -259,7 +351,22 @@ void OrderPushWork::heartBeatTcpService()
_socket
->
write
(
data
);
_socket
->
waitForBytesWritten
();
//_socket->waitForBytesWritten();
_istimeout
=
true
;
{
QEventLoop
loop
;
QTimer
timer
;
connect
(
this
,
&
OrderPushWork
::
quit
,
&
loop
,
&
QEventLoop
::
quit
);
connect
(
&
timer
,
&
QTimer
::
timeout
,
&
loop
,
&
QEventLoop
::
quit
);
connect
(
this
,
&
OrderPushWork
::
writeready
,
&
loop
,
&
QEventLoop
::
quit
);
timer
.
start
(
30
*
1000
);
loop
.
exec
();
}
continue
;
...
...
@@ -400,14 +507,16 @@ void OrderPushWork::workStart()
break
;
}
_needlogin
=
0
;
heartBeatTcpService
();
}
while
(
0
);
//网络异常断开重连
CLOSESOCKES
(
_socket
);
delete
_socket
;
_socket
=
NULL
;
//
delete _socket;
//
_socket = NULL;
EVENTWAIT
(
60000
);
}
...
...
takeout/control/orderpushwork.h
View file @
b096f645
...
...
@@ -153,6 +153,12 @@ public slots:
signals
:
void
quit
();
void
connected
();
void
writeready
();
void
readready
();
private
:
//门店信息
QVariantMap
_storeinfo
;
...
...
@@ -162,6 +168,10 @@ private:
int
_server_index
;
//停止标志位置
qint8
_stopflag
;
//重新登录标识
qint8
_needlogin
;
//超时标识
bool
_istimeout
;
//长连接套接字
//QTcpSocket *_socket;
QSslSocket
*
_socket
;
...
...
takeout/main.cpp
View file @
b096f645
...
...
@@ -151,7 +151,7 @@ int main(int argc, char *argv[])
QDir
().
mkdir
(
logDir
);
QsLogging
::
Logger
&
logger
=
QsLogging
::
Logger
::
instance
();
logger
.
setLoggingLevel
(
QsLogging
::
Info
Level
);
logger
.
setLoggingLevel
(
QsLogging
::
Debug
Level
);
QString
logPath
=
QString
(
"%1/%2"
).
arg
(
logDir
,
"takeout.log"
);
QsLogging
::
DestinationPtr
fileDst
(
QsLogging
::
DestinationFactory
::
MakeFileDestination
(
logPath
,
QsLogging
::
EnableLogRotation
,
QsLogging
::
MaxSizeBytes
(
2
*
1024
*
1024
),
QsLogging
::
MaxOldLogCount
(
6
)));
...
...
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