自动验收上架coding

import time
from dingtalkchatbot.chatbot import DingtalkChatbot
import requests

webhook ='https://oapi.dingtalk.com/robot/send?access_token=b7527b37d578d1e244b9b08609e61d209b4170a7acc1d95f2da75e22c62728e9'
bot = DingtalkChatbot(webhook)

session_wms = requests.Session()

这个url是登陆入口

login_url = "https://apollo-api.xtw-tech.com/v1/auth/token"

请求头文件Request Headers

headers = {
# 'accept': 'application/json, text/plain, /',
# 'accept-encoding': 'gzip, deflate, br',
# 'accept-language': 'zh-CN,zh;q=0.9',
# 'content-length': '46',
# 'content-type': 'application/json',
'grpc-metadata-application-code': 'VENUS',
# 'grpc-metadata-user-auth-token': 'null',
# 'origin': 'https://mercury.xtw-tech.com',
# 'referer': 'https://mercury.xtw-tech.com/',
# 'sec-fetch-mode': 'cors',
# 'sec-fetch-site': 'same-site',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36'
}

登陆wms

data = {

}

登录wms

response_wms = session_wms.post(url=login_url, headers=headers, json=data)
tenant_id= '3'
for asn_id in ['743021']:
asn_url = f'https://titan-api.xtw-tech.com/v1/asn/by_id/{asn_id}?tenant_id={tenant_id}'
headers = {
'authority': 'titan-api.xtw-tech.com',
'method': 'GET',
'path': f'/v1/asn/by_id/{asn_id}?tenant_id={tenant_id}',
'scheme': 'https',
'accept': 'application/json, text/plain, /',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'zh-CN,zh;q=0.9',
'grpc-metadata-application-code': 'MERCURY',
'grpc-metadata-user-auth-token': f'{response_wms.cookies.values()[0]}',
'origin': 'https://mercury.xtw-tech.com',
'referer': 'https://mercury.xtw-tech.com/',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': "macOS",
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-site',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36',
}
response_asn = session_wms.get(headers=headers, url=asn_url)
respon = response_asn.json()['asnWithDetails']

url_start =f'https://titan-api.xtw-tech.com/v1/asn/by_id/{asn_id}/inspection/start' header = { 'authority': 'titan-api.xtw-tech.com', 'method': 'POST', 'path': f'/v1/asn/by_id/{asn_id}/inspection/start', 'scheme': 'https', 'accept': 'application/json, text/plain, */*', 'accept-encoding': 'gzip, deflate, br', 'accept-language': 'zh-CN,zh;q=0.9', 'content-length': '35', 'content-type': 'application/json', 'grpc-metadata-application-code': 'MERCURY', 'grpc-metadata-user-auth-token': f'{response_wms.cookies.values()[0]}', 'origin': 'https://mercury.xtw-tech.com', 'referer': 'https://mercury.xtw-tech.com/', 'sec-ch-ua-platform': "Windows", 'sec-fetch-dest': 'empty', 'sec-fetch-mode': 'cors', 'sec-fetch-site': 'same-site', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36', } data ={'asnId': f"{asn_id}", 'tenantId': f"{tenant_id}"} re_start = session_wms.post(headers=header,url=url_start,json=data) k = re_start.json()['asnWithDetails']['inventories'] n =0 dic = {} for i in k: expectedQuantity = i['expectedQuantity'] inventoryRelationId = i['reportItem'][0]['inventoryRelationId'] try: productionTime = i['reportItem'][0]['lot']['productionTime'] lotId = i['reportItem'][0]['lot']['id'] status= i['reportItem'][0]['lot']["status"] # LOT_STATUS_CLOSE_TO_EXPIRY(临期) # LOT_STATUS_EXPIRED(过期) except: productionTime = '' lotId ='' status ='' sp = i['standardProductTenantMapping']['standardProduct']['code'] name= i['standardProductTenantMapping']['standardProduct']['name'] # print(sp,name,expectedQuantity,inventoryRelationId,productionTime,lotId) # 开始进行确认验收 report_url = f'https://titan-api.xtw-tech.com/v1/asn/by_id/{asn_id}/inspection/report/temp_item_record/create_or_update' header ={ 'authority': 'titan-api.xtw-tech.com', 'method': 'POST', 'path': f'/v1/asn/by_id/{asn_id}/inspection/report/temp_item_record/create_or_update', 'scheme': 'https', 'accept': 'application/json, text/plain, */*', 'accept-encoding': 'gzip, deflate, br', 'accept-language': 'zh-CN,zh;q=0.9', 'content-length': '177', 'content-type': 'application/json', 'grpc-metadata-application-code': 'MERCURY', 'grpc-metadata-user-auth-token': f'{response_wms.cookies.values()[0]}', 'origin': 'https://mercury.xtw-tech.com', 'referer': 'https://mercury.xtw-tech.com/', 'sec-ch-ua-platform': "Windows", 'sec-fetch-dest': 'empty', 'sec-fetch-mode': 'cors', 'sec-fetch-site': 'same-site', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36', } if lotId !="": data = {'inventoryRelationId': f"{inventoryRelationId}",'tenantId': f"{tenant_id}",'reportItem':[{'actualQuantity': f"{expectedQuantity}",'inventoryRelationId': f"{inventoryRelationId}",'lotId': f"{lotId}",'productionTime': f"{productionTime}"}]} else: data = {'inventoryRelationId': f"{inventoryRelationId}",'tenantId': f"{tenant_id}",'reportItem':[{'actualQuantity': f"{expectedQuantity}",'inventoryRelationId': f"{inventoryRelationId}"}]} #记录不同效期 上架库位的信息 # 上架到过期库位上 if status =='LOT_STATUS_EXPIRED': dic[f"{inventoryRelationId}"]={'inventoryRelationId': f"{inventoryRelationId}",'putawayQuantity':f"{expectedQuantity}", 'locationId': "205548",'lotId': f"{lotId}"} # 上架到临期库位上 elif status =='LOT_STATUS_CLOSE_TO_EXPIRY': dic[f"{inventoryRelationId}"]= {'inventoryRelationId': f"{inventoryRelationId}", 'putawayQuantity': f"{expectedQuantity}", 'locationId': "2434", 'lotId': f"{lotId}"} # 上架到正常库位上 else: dic[f"{inventoryRelationId}"]={'inventoryRelationId': f"{inventoryRelationId}", 'putawayQuantity': f"{expectedQuantity}", 'locationId': "260835", 'lotId': f"{lotId}"} kk = session_wms.post(headers=header,url=report_url,json=data) print(n, kk.status_code, asn_id, sp, status) n +=1 time.sleep(0.1) try: # 确认收货 url = f'https://titan-api.xtw-tech.com/v1/asn/by_id/{asn_id}/inspection/report' header = { 'authority': 'titan-api.xtw-tech.com', 'method': 'POST', 'path': f'/v1/asn/by_id/{asn_id}/inspection/report', 'scheme': 'https', 'accept': 'application/json, text/plain, */*', 'accept-encoding': 'gzip, deflate, br', 'accept-language': 'zh-CN,zh;q=0.9', 'content-length': '177', 'content-type': 'application/json', 'grpc-metadata-application-code': 'MERCURY', 'grpc-metadata-user-auth-token': f'{response_wms.cookies.values()[0]}', 'origin': 'https://mercury.xtw-tech.com', 'referer': 'https://mercury.xtw-tech.com/', 'sec-ch-ua-platform': "Windows", 'sec-fetch-dest': 'empty', 'sec-fetch-mode': 'cors', 'sec-fetch-site': 'same-site', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36', } data ={ 'actualArrivalTime': "2022-11-01T23:58:16+08:00", 'asnId': f"{asn_id}", 'pictures': [], 'tenantId': f"{tenant_id}", } status = session_wms.post(headers=header,url=url,json=data) if status.status_code==400: str = status.json()['message'] f =bot.send_markdown(title=f'验收上架异常:', text=f"### {str}&{asn_id}", at_mobiles=['18620332090']) print('检测到异常了') break else: pass except: bot.send_markdown(title=f'验收上架异常:', text=f"### 验收,请及时核查。。", at_mobiles=['18620332090']) # 还需要获取 putaway_url = f'https://titan-api.xtw-tech.com/v1/asn/by_id/{asn_id}/putaway/start' header ={ 'authority': 'titan-api.xtw-tech.com', 'method': 'POST', 'path': f'/v1/asn/by_id/{asn_id}/putaway/start', 'scheme': 'https', 'accept': 'application/json, text/plain, */*', 'accept-encoding': 'gzip, deflate, br', 'accept-language': 'zh-CN,zh;q=0.9', 'content-length': '35', 'content-type': 'application/json', 'grpc-metadata-application-code': 'MERCURY', 'grpc-metadata-user-auth-token': f'{response_wms.cookies.values()[0]}', 'origin': 'https://mercury.xtw-tech.com', 'referer': 'https://mercury.xtw-tech.com/', 'sec-ch-ua-platform': "Windows", 'sec-fetch-dest': 'empty', 'sec-fetch-mode': 'cors', 'sec-fetch-site': 'same-site', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36', } data = {'asnId': f"{asn_id}", 'tenantId': f"{tenant_id}"} session_wms.post(url=putaway_url,headers=header,json=data) location_url = f'https://titan-api.xtw-tech.com/v1/asn/by_id/{asn_id}/putaway/location' header ={ 'authority': 'titan-api.xtw-tech.com', 'method': 'POST', 'path': f'/v1/asn/by_id/{asn_id}/putaway/location', 'scheme': 'https', 'accept': 'application/json, text/plain, */*', 'accept-encoding': 'gzip, deflate, br', 'accept-language': 'zh-CN,zh;q=0.9', 'content-length': '35', 'content-type': 'application/json', 'grpc-metadata-application-code': 'MERCURY', 'grpc-metadata-user-auth-token': f'{response_wms.cookies.values()[0]}', 'origin': 'https://mercury.xtw-tech.com', 'referer': 'https://mercury.xtw-tech.com/', 'sec-ch-ua-platform': "Windows", 'sec-fetch-dest': 'empty', 'sec-fetch-mode': 'cors', 'sec-fetch-site': 'same-site', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36', } for key,value in dic.items(): try: if value['lotId'] =='': data ={'tenantId': f"{tenant_id}",'inventoryPutawayLocationRelation': [{'inventoryRelationId': f"{key}", 'putawayQuantity': f"{value['putawayQuantity']}", 'locationId': f"{value['locationId']}"}]} s1 = session_wms.post(url=location_url,headers=header,json=data) else: data ={'tenantId': f"{tenant_id}",'inventoryPutawayLocationRelation': [{'inventoryRelationId': f"{key}", 'putawayQuantity': f"{value['putawayQuantity']}", 'locationId': f"{value['locationId']}",'lotId': f"{value['lotId']}"}]} s2 = session_wms.post(url=location_url,headers=header,json=data) except: print('出现异常了') finish =f'https://titan-api.xtw-tech.com/v1/asn/by_id/{asn_id}/putaway/finish' header ={ 'authority': 'titan-api.xtw-tech.com', 'method': 'POST', 'path': f'/v1/asn/by_id/{asn_id}/putaway/finish', 'scheme': 'https', 'accept': 'application/json, text/plain, */*', 'accept-encoding': 'gzip, deflate, br', 'accept-language': 'zh-CN,zh;q=0.9', 'content-length': '35', 'content-type': 'application/json', 'grpc-metadata-application-code': 'MERCURY', 'grpc-metadata-user-auth-token': f'{response_wms.cookies.values()[0]}', 'origin': 'https://mercury.xtw-tech.com', 'referer': 'https://mercury.xtw-tech.com/', 'sec-ch-ua-platform': "Windows", 'sec-fetch-dest': 'empty', 'sec-fetch-mode': 'cors', 'sec-fetch-site': 'same-site', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36', } data = {'tenantId': f"{tenant_id}"} code = session_wms.post(url=finish,headers=header,json=data) if code.status_code == 200: t = f'https://mercury.xtw-tech.com/asn/{asn_id}/?tenant_id=3' bot.send_markdown(title=f'完成上架:', text=f"### [深圳中心仓{n}个sp已完成验收上架,点我跳转至ASN页面]({t})", at_mobiles=['18620332090']) else: pass

__EOF__

本文作者ivan09
本文链接https://www.cnblogs.com/ivan09/p/16853976.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   烦恼1234  阅读(28)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示