Commit 3ed58533 by 孙龙

init

parents
#!/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 + '/order/track/needupdate'
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:
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'], ))
audit_arr = json.loads(res)
if audit_arr['errcode'] != 0:
raise Exception(audit_arr['errmsg'])
#记录审核数据
post.append({
'rec_id' : body_arr['rec_id'],
'order_id' : body_arr['order_id'],
'order_goods_type' : body_arr['order_goods_type'],
'track_type' : 1,
'track_num' : audit_arr['data']['goods_number'],
'create_name' : audit_arr['data']['sale_name'],
'create_time' : audit_arr['data']['confirm_time'],
'relevance_sn' : audit_arr['data']['order_sn'],
})
#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
++ "a/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.txt"
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