Commit a4dcbb61 by 孙龙

init

parent edae56e2
Showing with 118 additions and 118 deletions
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# @Date : 2018-01-03 17:40:18 # @Date : 2018-01-03 17:40:18
# @Author : yc () # @Author : yc ()
# @Link : # @Link :
# @Version : Id # @Version : Id
from core.base import * from core.base import *
from core.lib.rbmq import Rbmq from core.lib.rbmq import Rbmq
from core.lib.request import Request from core.lib.request import Request
from core.lib.exceptions import EmptyException from core.lib.exceptions import EmptyException
from core.func.common import * from core.func.common import *
from sync.conf.base import BaseConf from sync.conf.base import BaseConf
from suds.client import Client from suds.client import Client
import time, json, traceback import time, json, traceback
class web2erp_track(base): class web2erp_track(base):
'''跟踪订单明细的采购轨迹''' '''跟踪订单明细的采购轨迹'''
def __init__(self, data=None): def __init__(self, data=None):
super().__init__(data) super().__init__(data)
self.needupdate_url = self.CommonConf.order_api_url + '/ag/bdfdf/cdd' self.needupdate_url = self.CommonConf.order_api_url + '/ag/bdfdf/cdd/hhh'
self.create_url = self.CommonConf.order_api_url + '/order/track/create' self.create_url = self.CommonConf.order_api_url + '/order/track/create'
self.audit_url = self.CommonConf.order_api_url + '/order/getrecaudit' self.audit_url = self.CommonConf.order_api_url + '/order/getrecaudit'
self.request = Request() self.request = Request()
self.rbmq = Rbmq(self.RbmqConf.business) self.rbmq = Rbmq(self.RbmqConf.business)
self.client = Client(self.CommonConf.erp_wsdl_order) self.client = Client(self.CommonConf.erp_wsdl_order)
self.start() self.start()
def start(self): def start(self):
'''开启轮询''' '''开启轮询'''
while True: while True:
if self._global.extend == 'publish': if self._global.extend == 'publish':
#生产 #生产
try: try:
self.publish() self.publish()
except EmptyException as e: except EmptyException as e:
self.needupdate_url = self.CommonConf.order_api_url + '/order/track/needupdate' self.needupdate_url = self.CommonConf.order_api_url + '/order/track/needupdate'
pass pass
except Exception as e: except Exception as e:
self.elkReport('订单明细轨迹推送任务失败') self.elkReport('订单明细轨迹推送任务失败')
else: else:
#消费 #消费
#队列监听为即时 #队列监听为即时
self.rbmq.listen(BaseConf.erp_follow_queue, self.consume, self.consume_fail) self.rbmq.listen(BaseConf.erp_follow_queue, self.consume, self.consume_fail)
time.sleep(60) time.sleep(60)
def publish(self): def publish(self):
'''生产''' '''生产'''
if self.rbmq.queue(BaseConf.erp_follow_queue).len() <= 0: if self.rbmq.queue(BaseConf.erp_follow_queue).len() <= 0:
datas = self.request.postUrl(self.needupdate_url, {'order_goods_type' : 1}) datas = self.request.postUrl(self.needupdate_url, {'order_goods_type' : 1})
if None == datas: if None == datas:
raise EmptyException() raise EmptyException()
arr = json.loads(datas) arr = json.loads(datas)
for data in arr['data']: for data in arr['data']:
self.rbmq.queue(BaseConf.erp_follow_queue).publish(data) self.rbmq.queue(BaseConf.erp_follow_queue).publish(data)
print(len(arr['data'])) print(len(arr['data']))
def consume(self, body): def consume(self, body):
'''消费 eg:{"rec_id": 3052, "erp_rec_id": "0", "order_id": 2492, "order_goods_type": 1, "max_type": null}''' '''消费 eg:{"rec_id": 3052, "erp_rec_id": "0", "order_id": 2492, "order_goods_type": 1, "max_type": null}'''
print(body) print(body)
body_arr = json.loads(body) body_arr = json.loads(body)
post = [] post = []
#读取最新的路径 #读取最新的路径
max_type = 1 if None == body_arr['max_type'] else int(body_arr['max_type']) + 1 max_type = 1 if None == body_arr['max_type'] else int(body_arr['max_type']) + 1
if max_type == 1: if max_type == 1:
#查订单审核数据 #查订单审核数据
res = self.request.postUrl(self.audit_url, {'rec_id' : body_arr['rec_id']}) res = self.request.postUrl(self.audit_url, {'rec_id' : body_arr['rec_id']})
if None == res: if None == res:
raise Exception('rec_id %s,请求查询审核接口失败' % (body_arr['rec_id'], )) raise Exception('rec_id %s,请求查询审核接口失败' % (body_arr['rec_id'], ))
#ERP查询轨迹 #ERP查询轨迹
data = { data = {
'ORDERENTRYID' : body_arr['erp_rec_id'] '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':'顺丰'}]") # 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: try:
res = self.client.service.getPTorderStatus(json.dumps(data)) res = self.client.service.getPTorderStatus(json.dumps(data))
except Exception as e: except Exception as e:
res = None res = None
if res == None: if res == None:
raise Exception('rec_id %s,获取ERP轨迹失败:请求失败' % (body_arr['rec_id'], )) raise Exception('rec_id %s,获取ERP轨迹失败:请求失败' % (body_arr['rec_id'], ))
arr = json.loads(res) arr = json.loads(res)
for items in arr: for items in arr:
#只更新接下来的轨迹 #只更新接下来的轨迹
if max_type <= int(items['SEQ']): if max_type <= int(items['SEQ']):
post.append({ post.append({
'rec_id' : body_arr['rec_id'], 'rec_id' : body_arr['rec_id'],
'order_id' : body_arr['order_id'], 'order_id' : body_arr['order_id'],
'order_goods_type' : body_arr['order_goods_type'], 'order_goods_type' : body_arr['order_goods_type'],
'track_type' : items['SEQ'], 'track_type' : items['SEQ'],
'track_num' : items['QTY'] if 'QTY' in items.keys() else 0, 'track_num' : items['QTY'] if 'QTY' in items.keys() else 0,
'create_name' : items['CREATOR'] if 'CREATOR' in items.keys() else '', '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, '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 '', 'relevance_sn' : items['NUMBER'] if 'NUMBER' in items.keys() else '',
'shipping_name' : items['CARRIER'] if 'CARRIER' in items.keys() else '', 'shipping_name' : items['CARRIER'] if 'CARRIER' in items.keys() else '',
'shipping_no' : items['LOGISTICSNUMBER'] if 'LOGISTICSNUMBER' in items.keys() else '', 'shipping_no' : items['LOGISTICSNUMBER'] if 'LOGISTICSNUMBER' in items.keys() else '',
}) })
if post == []:#没有可添加数据 if post == []:#没有可添加数据
return return
res = self.request.postUrl(self.create_url, {'data': post}) res = self.request.postUrl(self.create_url, {'data': post})
if None == res: if None == res:
raise Exception('rec_id %s,创建轨迹失败:请求失败%s' % (body_arr['rec_id'], self.request._error)) raise Exception('rec_id %s,创建轨迹失败:请求失败%s' % (body_arr['rec_id'], self.request._error))
arr = json.loads(res) arr = json.loads(res)
if arr['errcode'] not in [0, 102029]:#相同类型 if arr['errcode'] not in [0, 102029]:#相同类型
raise Exception('rec_id %s,创建轨迹失败:code=%s msg=%s' % (body_arr['rec_id'], arr['errcode'], arr['errmsg'])) raise Exception('rec_id %s,创建轨迹失败:code=%s msg=%s' % (body_arr['rec_id'], arr['errcode'], arr['errmsg']))
def consume_fail(self, body, res, msg): def consume_fail(self, body, res, msg):
'''消费失败通知''' '''消费失败通知'''
self.elkReport('订单明细轨迹消费任务失败', False) self.elkReport('订单明细轨迹消费任务失败', False)
if __name__ == '__main__': if __name__ == '__main__':
pass pass
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment