Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
孙龙
/
test-long
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a4dcbb61
authored
Oct 08, 2019
by
孙龙
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
init
parent
edae56e2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
118 additions
and
118 deletions
web2erp_track.py
web2erp_track.py
View file @
a4dcbb61
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date : 2018-01-03 17:40:18
# @Author : yc ()
# @Link :
# @Version : Id
from
core.base
import
*
from
core.lib.rbmq
import
Rbmq
from
core.lib.request
import
Request
from
core.lib.exceptions
import
EmptyException
from
core.func.common
import
*
from
sync.conf.base
import
BaseConf
from
suds.client
import
Client
import
time
,
json
,
traceback
class
web2erp_track
(
base
):
'''跟踪订单明细的采购轨迹'''
def
__init__
(
self
,
data
=
None
):
super
()
.
__init__
(
data
)
self
.
needupdate_url
=
self
.
CommonConf
.
order_api_url
+
'/ag/bdfdf/cdd
'
self
.
create_url
=
self
.
CommonConf
.
order_api_url
+
'/order/track/create'
self
.
audit_url
=
self
.
CommonConf
.
order_api_url
+
'/order/getrecaudit'
self
.
request
=
Request
()
self
.
rbmq
=
Rbmq
(
self
.
RbmqConf
.
business
)
self
.
client
=
Client
(
self
.
CommonConf
.
erp_wsdl_order
)
self
.
start
()
def
start
(
self
):
'''开启轮询'''
while
True
:
if
self
.
_global
.
extend
==
'publish'
:
#生产
try
:
self
.
publish
()
except
EmptyException
as
e
:
self
.
needupdate_url
=
self
.
CommonConf
.
order_api_url
+
'/order/track/needupdate'
pass
except
Exception
as
e
:
self
.
elkReport
(
'订单明细轨迹推送任务失败'
)
else
:
#消费
#队列监听为即时
self
.
rbmq
.
listen
(
BaseConf
.
erp_follow_queue
,
self
.
consume
,
self
.
consume_fail
)
time
.
sleep
(
60
)
def
publish
(
self
):
'''生产'''
if
self
.
rbmq
.
queue
(
BaseConf
.
erp_follow_queue
)
.
len
()
<=
0
:
datas
=
self
.
request
.
postUrl
(
self
.
needupdate_url
,
{
'order_goods_type'
:
1
})
if
None
==
datas
:
raise
EmptyException
()
arr
=
json
.
loads
(
datas
)
for
data
in
arr
[
'data'
]:
self
.
rbmq
.
queue
(
BaseConf
.
erp_follow_queue
)
.
publish
(
data
)
print
(
len
(
arr
[
'data'
]))
def
consume
(
self
,
body
):
'''消费 eg:{"rec_id": 3052, "erp_rec_id": "0", "order_id": 2492, "order_goods_type": 1, "max_type": null}'''
print
(
body
)
body_arr
=
json
.
loads
(
body
)
post
=
[]
#读取最新的路径
max_type
=
1
if
None
==
body_arr
[
'max_type'
]
else
int
(
body_arr
[
'max_type'
])
+
1
if
max_type
==
1
:
#查订单审核数据
res
=
self
.
request
.
postUrl
(
self
.
audit_url
,
{
'rec_id'
:
body_arr
[
'rec_id'
]})
if
None
==
res
:
raise
Exception
(
'rec_id
%
s,请求查询审核接口失败'
%
(
body_arr
[
'rec_id'
],
))
#ERP查询轨迹
data
=
{
'ORDERENTRYID'
:
body_arr
[
'erp_rec_id'
]
}
# arr = eval("[{'NUMBER': 'LQJ-SZ201907290001', 'BIZDATE': '2019-07-29 00:00:00', 'SEQ': '2', 'CREATOR': '龙桥均', 'QTY': '10000'}, {'NUMBER': 'PUI2019019507', 'BIZDATE': '2019-07-29 13:21:16', 'SEQ': '10', 'CREATOR': '龙桥均', 'QTY': '10000', 'LOGISTICSNUMBER':'x2222222', 'CARRIER':'顺丰'}]")
try
:
res
=
self
.
client
.
service
.
getPTorderStatus
(
json
.
dumps
(
data
))
except
Exception
as
e
:
res
=
None
if
res
==
None
:
raise
Exception
(
'rec_id
%
s,获取ERP轨迹失败:请求失败'
%
(
body_arr
[
'rec_id'
],
))
arr
=
json
.
loads
(
res
)
for
items
in
arr
:
#只更新接下来的轨迹
if
max_type
<=
int
(
items
[
'SEQ'
]):
post
.
append
({
'rec_id'
:
body_arr
[
'rec_id'
],
'order_id'
:
body_arr
[
'order_id'
],
'order_goods_type'
:
body_arr
[
'order_goods_type'
],
'track_type'
:
items
[
'SEQ'
],
'track_num'
:
items
[
'QTY'
]
if
'QTY'
in
items
.
keys
()
else
0
,
'create_name'
:
items
[
'CREATOR'
]
if
'CREATOR'
in
items
.
keys
()
else
''
,
'create_time'
:
int
(
time
.
mktime
(
time
.
strptime
(
items
[
'BIZDATE'
],
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
)))
if
'BIZDATE'
in
items
.
keys
()
and
items
[
'BIZDATE'
]
not
in
[
''
,
None
]
else
0
,
'relevance_sn'
:
items
[
'NUMBER'
]
if
'NUMBER'
in
items
.
keys
()
else
''
,
'shipping_name'
:
items
[
'CARRIER'
]
if
'CARRIER'
in
items
.
keys
()
else
''
,
'shipping_no'
:
items
[
'LOGISTICSNUMBER'
]
if
'LOGISTICSNUMBER'
in
items
.
keys
()
else
''
,
})
if
post
==
[]:
#没有可添加数据
return
res
=
self
.
request
.
postUrl
(
self
.
create_url
,
{
'data'
:
post
})
if
None
==
res
:
raise
Exception
(
'rec_id
%
s,创建轨迹失败:请求失败
%
s'
%
(
body_arr
[
'rec_id'
],
self
.
request
.
_error
))
arr
=
json
.
loads
(
res
)
if
arr
[
'errcode'
]
not
in
[
0
,
102029
]:
#相同类型
raise
Exception
(
'rec_id
%
s,创建轨迹失败:code=
%
s msg=
%
s'
%
(
body_arr
[
'rec_id'
],
arr
[
'errcode'
],
arr
[
'errmsg'
]))
def
consume_fail
(
self
,
body
,
res
,
msg
):
'''消费失败通知'''
self
.
elkReport
(
'订单明细轨迹消费任务失败'
,
False
)
if
__name__
==
'__main__'
:
pass
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date : 2018-01-03 17:40:18
# @Author : yc ()
# @Link :
# @Version : Id
from
core.base
import
*
from
core.lib.rbmq
import
Rbmq
from
core.lib.request
import
Request
from
core.lib.exceptions
import
EmptyException
from
core.func.common
import
*
from
sync.conf.base
import
BaseConf
from
suds.client
import
Client
import
time
,
json
,
traceback
class
web2erp_track
(
base
):
'''跟踪订单明细的采购轨迹'''
def
__init__
(
self
,
data
=
None
):
super
()
.
__init__
(
data
)
self
.
needupdate_url
=
self
.
CommonConf
.
order_api_url
+
'/ag/bdfdf/cdd
/hhh'
self
.
create_url
=
self
.
CommonConf
.
order_api_url
+
'/order/track/create'
self
.
audit_url
=
self
.
CommonConf
.
order_api_url
+
'/order/getrecaudit'
self
.
request
=
Request
()
self
.
rbmq
=
Rbmq
(
self
.
RbmqConf
.
business
)
self
.
client
=
Client
(
self
.
CommonConf
.
erp_wsdl_order
)
self
.
start
()
def
start
(
self
):
'''开启轮询'''
while
True
:
if
self
.
_global
.
extend
==
'publish'
:
#生产
try
:
self
.
publish
()
except
EmptyException
as
e
:
self
.
needupdate_url
=
self
.
CommonConf
.
order_api_url
+
'/order/track/needupdate'
pass
except
Exception
as
e
:
self
.
elkReport
(
'订单明细轨迹推送任务失败'
)
else
:
#消费
#队列监听为即时
self
.
rbmq
.
listen
(
BaseConf
.
erp_follow_queue
,
self
.
consume
,
self
.
consume_fail
)
time
.
sleep
(
60
)
def
publish
(
self
):
'''生产'''
if
self
.
rbmq
.
queue
(
BaseConf
.
erp_follow_queue
)
.
len
()
<=
0
:
datas
=
self
.
request
.
postUrl
(
self
.
needupdate_url
,
{
'order_goods_type'
:
1
})
if
None
==
datas
:
raise
EmptyException
()
arr
=
json
.
loads
(
datas
)
for
data
in
arr
[
'data'
]:
self
.
rbmq
.
queue
(
BaseConf
.
erp_follow_queue
)
.
publish
(
data
)
print
(
len
(
arr
[
'data'
]))
def
consume
(
self
,
body
):
'''消费 eg:{"rec_id": 3052, "erp_rec_id": "0", "order_id": 2492, "order_goods_type": 1, "max_type": null}'''
print
(
body
)
body_arr
=
json
.
loads
(
body
)
post
=
[]
#读取最新的路径
max_type
=
1
if
None
==
body_arr
[
'max_type'
]
else
int
(
body_arr
[
'max_type'
])
+
1
if
max_type
==
1
:
#查订单审核数据
res
=
self
.
request
.
postUrl
(
self
.
audit_url
,
{
'rec_id'
:
body_arr
[
'rec_id'
]})
if
None
==
res
:
raise
Exception
(
'rec_id
%
s,请求查询审核接口失败'
%
(
body_arr
[
'rec_id'
],
))
#ERP查询轨迹
data
=
{
'ORDERENTRYID'
:
body_arr
[
'erp_rec_id'
]
}
# arr = eval("[{'NUMBER': 'LQJ-SZ201907290001', 'BIZDATE': '2019-07-29 00:00:00', 'SEQ': '2', 'CREATOR': '龙桥均', 'QTY': '10000'}, {'NUMBER': 'PUI2019019507', 'BIZDATE': '2019-07-29 13:21:16', 'SEQ': '10', 'CREATOR': '龙桥均', 'QTY': '10000', 'LOGISTICSNUMBER':'x2222222', 'CARRIER':'顺丰'}]")
try
:
res
=
self
.
client
.
service
.
getPTorderStatus
(
json
.
dumps
(
data
))
except
Exception
as
e
:
res
=
None
if
res
==
None
:
raise
Exception
(
'rec_id
%
s,获取ERP轨迹失败:请求失败'
%
(
body_arr
[
'rec_id'
],
))
arr
=
json
.
loads
(
res
)
for
items
in
arr
:
#只更新接下来的轨迹
if
max_type
<=
int
(
items
[
'SEQ'
]):
post
.
append
({
'rec_id'
:
body_arr
[
'rec_id'
],
'order_id'
:
body_arr
[
'order_id'
],
'order_goods_type'
:
body_arr
[
'order_goods_type'
],
'track_type'
:
items
[
'SEQ'
],
'track_num'
:
items
[
'QTY'
]
if
'QTY'
in
items
.
keys
()
else
0
,
'create_name'
:
items
[
'CREATOR'
]
if
'CREATOR'
in
items
.
keys
()
else
''
,
'create_time'
:
int
(
time
.
mktime
(
time
.
strptime
(
items
[
'BIZDATE'
],
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
)))
if
'BIZDATE'
in
items
.
keys
()
and
items
[
'BIZDATE'
]
not
in
[
''
,
None
]
else
0
,
'relevance_sn'
:
items
[
'NUMBER'
]
if
'NUMBER'
in
items
.
keys
()
else
''
,
'shipping_name'
:
items
[
'CARRIER'
]
if
'CARRIER'
in
items
.
keys
()
else
''
,
'shipping_no'
:
items
[
'LOGISTICSNUMBER'
]
if
'LOGISTICSNUMBER'
in
items
.
keys
()
else
''
,
})
if
post
==
[]:
#没有可添加数据
return
res
=
self
.
request
.
postUrl
(
self
.
create_url
,
{
'data'
:
post
})
if
None
==
res
:
raise
Exception
(
'rec_id
%
s,创建轨迹失败:请求失败
%
s'
%
(
body_arr
[
'rec_id'
],
self
.
request
.
_error
))
arr
=
json
.
loads
(
res
)
if
arr
[
'errcode'
]
not
in
[
0
,
102029
]:
#相同类型
raise
Exception
(
'rec_id
%
s,创建轨迹失败:code=
%
s msg=
%
s'
%
(
body_arr
[
'rec_id'
],
arr
[
'errcode'
],
arr
[
'errmsg'
]))
def
consume_fail
(
self
,
body
,
res
,
msg
):
'''消费失败通知'''
self
.
elkReport
(
'订单明细轨迹消费任务失败'
,
False
)
if
__name__
==
'__main__'
:
pass
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