指定库位效期批次上架

import time
from dingtalkchatbot.chatbot import DingtalkChatbot
import requests

webhook ='https://oapi.dingtalk.com/robot/send?access_token=ca18f6c6fe7f526c5681637a926572c5d8a1b29d2ca2392a974eb87463eb9b7d'
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= '344'
for asn_id in ['743183','743186']:
    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['id']
        lotEnabled = i['lotEnabled']
        standardProductId = i['standardProductTenantMapping']['standardProduct']['id']
        sp = i['standardProductTenantMapping']['standardProduct']['code']
        name= i['standardProductTenantMapping']['standardProduct']['name']
        owner_id = i['owner']['id']
        lotId =''
        if lotEnabled:
            lot_url = 'https://titan-api.xtw-tech.com/v1/lot/create'
            header = {
                'authority': 'titan-api.xtw-tech.com',
                'method': 'POST',
                'path': '/v1/lot/create',
                'scheme': 'https',
                'accept': 'application/json, text/plain, */*',
                'accept-encoding': 'gzip, deflate, br',
                'accept-languagev': 'zh-CN,zh;q=0.9',
                'content-length': '125',
                '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/',
                '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',
            }
            productionTime = '2022-12-05' + 'T09:20:32.404Z'
            pa = {'ownerId': f"{owner_id}", 'productionTime': f"{productionTime}",
                  'standardProductId': f"{standardProductId}", 'tenantId': "344",
                  'warehouseId': "741"}

            mm = session_wms.post(url=lot_url, headers=header, json=pa)
            lotId = mm.json()['lot']['id']

        else:
           pass

        # 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}"}]}

        #记录不同效期 上架库位的信息
            # 上架到过期库位上

        dic[f"{inventoryRelationId}"]={'inventoryRelationId': f"{inventoryRelationId}", 'putawayQuantity': f"{expectedQuantity}",
                   'locationId': "261312", 'lotId': f"{lotId}"}
        kk = session_wms.post(headers=header,url=report_url,json=data)
        print(n, kk.status_code, sp)
        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-12-06T23:58:16+08:00",
            'asnId': f"{asn_id}",
            'pictures': [],
            'tenantId': f"{tenant_id}",
        }
        status = session_wms.post(headers=header,url=url,json=data)
        if int(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=344'
        bot.send_markdown(title=f'完成上架:',
                      text=f"### [岳阳中心仓{n}个sp已完成验收上架,点我跳转至ASN页面]({t})",
                      at_mobiles=['18620332090'])
    else:
        pass

posted @ 2022-12-15 12:30  烦恼1234  阅读(10)  评论(0编辑  收藏  举报