sjApi.py 12.8 KB
# -*- coding: utf-8 -*-

# @Time    : 2021/8/11 15:59
# @Author  : Ljq
# @File    : sjApi.py
# @Software: PyCharm

"""
散件
"""

import json,time,random
from commons.scripts import dealContentType as dct
from commons.MySession import my
from commons.api import zcApi
from commons.api import entranceFeeBillList as eFBL
from commons.basic import getLookupList as gLL


def create_sparePartsWeighSave(host="",duplicateToken=None,**kwargs):
    """查询证明类型
    :param host:
    :param **kwargs:
    		        {
                    "driverTel": "",
                    "inGreeterId": 223,
                    "inGreeterName": "测试沈阳",
                    "itemWeight": 11,
                    "productId": 14158,
                    "productName": "雪莲果",
                    "proveTypeCode": 665,
                    "proveTypeName": "食品安全",
                    "qty": 33,
                    "weighRemark": null,
                    "weight": 363,
                    "weighmanRecord": {
                        "grossWeight": null,
                        "grossWeightDate": null,
                        "newWeight": null,
                        "tareWeight": null,
                        "tareWeightDate": null,
                        "weighImgs": []
                    },
                    "productCode": null,
                    "plate": "ASD",
                    "carTypeId": 53,
                    "carTypeCode": "003",
                    "carTypeName": "板车",
                    "pathAddress": "A4-BB-6D-0A-F4-13",
                    "entryPlateInputType": 1,
                    "feeDepId": 0,
                    "feeDepName": null,
                    "dep": 58,
                    "depName": "水果部",
                    "notice": 0,
                    "backSkinTwo": -1,
                    "recordOriginId": 0,
                    "recordOriginName": null,
                    "recordProductId": 0,
                    "recordProductName": null,
                    "recordWeight": null,
                    "codeIc": null,
                    "codeId": 0,
                    "difference": 0,
                    "bindRecordSign": 0,
                    "recordDesc": null,
                    "hasCodeItems": false,
                    "type": 2,
                    "tradeTypeId": 70,
                    "tradeType": "9001",
                    "tradeTypeName": "沈阳1号",
                    "goodsTagId": 663,
                    "originId": 500101,
                    "origin": "万州区",
                    "originCode": "023"l
                }
    :return:"""
    url = host + "/jmsf-web/api/entrace/sparePartsWeighSave"
    # data = {"driverTel":"","inGreeterId":223,"inGreeterName":"测试沈阳","itemWeight":11,"productId":14158,"productName":"雪莲果","proveTypeCode":665,"proveTypeName":"食品安全","qty":33,"weighRemark":None,"weight":363,"weighmanRecord":{"grossWeight":None,"grossWeightDate":None,"newWeight":None,"tareWeight":None,"tareWeightDate":None,"weighImgs":[]},"productCode":None,"plate":"ASD","carTypeId":53,"carTypeCode":"003","carTypeName":"板车","pathAddress":"A4-BB-6D-0A-F4-13","entryPlateInputType":1,"feeDepId":0,"feeDepName":None,"dep":58,"depName":"水果部","notice":0,"backSkinTwo":-1,"recordOriginId":0,"recordOriginName":None,"recordProductId":0,"recordProductName":None,"recordWeight":None,"codeIc":None,"codeId":0,"difference":0,"bindRecordSign":0,"recordDesc":None,"hasCodeItems":False,"type":2,"tradeTypeId":70,"tradeType":"9001","tradeTypeName":"沈阳1号","goodsTagId":663,"originId":500101,"origin":"万州区","originCode":"023"}
    data = {"driverTel": "", "inGreeterId": 223, "inGreeterName": "测试沈阳", "itemWeight": 11, "productId": 14158,
            "productName": "雪莲果", "proveTypeCode": 665, "proveTypeName": "食品安全", "qty": 33, "weighRemark": None,
            "weight": 363,
            "weighmanRecord": {"grossWeight": None, "grossWeightDate": None, "newWeight": None, "tareWeight": None,
                               "tareWeightDate": None, "weighImgs": []}, "productCode": None, "plate": "ASD",
            "carTypeId": 53, "carTypeCode": "003", "carTypeName": "板车", "pathAddress": "A4-BB-6D-0A-F4-13",
            "entryPlateInputType": 1, "feeDepId": 0, "feeDepName": None, "dep": 58, "depName": "水果部", "notice": 0,
            "backSkinTwo": -1, "recordOriginId": 0, "recordOriginName": None, "recordProductId": 0,
            "recordProductName": None, "recordWeight": None, "codeIc": None, "codeId": 0, "difference": 0,
            "bindRecordSign": 0, "recordDesc": None, "hasCodeItems": False, "type": 2, "tradeTypeId": 70,
            "tradeType": "9001", "tradeTypeName": "沈阳1号", "goodsTagId": 663, "originId": 500101, "origin": "万州区",
            "originCode": "023"}
    headers = dct.jsonCode()
    headers["jmsf_duplicate_commit_token"] = duplicateToken
    data = dict(data, **kwargs)
    res = my.useHeadersRequests(method="POST", url=url, data=json.dumps(data), headers=headers)
    return res

def create_sj(host=None,carTypeName=None,keyword="蔬菜",userName=None,transactionName=None,
                plate="川A12345",goodsTagName=None,depName=None,proveName=None,itemWeight="10",qty="22"):
    """

    """
    # 模板获取
    templateAttr_list = gLL.get_templateAttr(host=host,moduleCode="SJ")
    print(templateAttr_list)

    # 获取车型
    if "车型" in templateAttr_list:
        carType = zcApi.get_carType(host=host)
        print(carType.text)
        if carTypeName == None:
            carTypeIndex = 0
        else:
            carTypeIndex = carType.json()["data"].index(
                [i for i in carType.json()["data"] if i["carTypeName"] == carTypeName][0])
        carTypeCode = carType.json()["data"][carTypeIndex]["code"]
        carTypeId = carType.json()["data"][carTypeIndex]["id"]
        carTypeName = carType.json()["data"][carTypeIndex]["carTypeName"]
        carTypeWeight = carType.json()["data"][carTypeIndex]["weight"]
    else:
        carTypeCode = ""
        carTypeId = ""
        carTypeName = ""
        carTypeWeight = ""


    # 获取商品
    if "商品" in templateAttr_list or "商品(末级)" in templateAttr_list:
        categoryByCondition = zcApi.get_listCategoryByCondition(host=host, keyword=keyword)
        cateId = categoryByCondition.json()["data"][0]["id"]
        productId = categoryByCondition.json()["data"][0]["id"]
        productName = categoryByCondition.json()["data"][0]["name"]
        # productCode = categoryByCondition.json()["data"][0]["keycode"]
    else:
        cateId = ""
        productId = ""
        productName = ""


    # 获取接车员信息
    if "进门接车员" in templateAttr_list:
        firmCode = my.userInfo["data"]["user"]["firmCode"]
        firmId = my.userInfo["data"]["user"]["firmId"]

        try:
            res_config = gLL.get_config(host=host, marketId=firmId)
            departmentId = [i["value"] for i in res_config.json()["rows"] if i["name"] == "DepartmentId"][0]
        except:
            departmentId = None
        # print("==========1============")
        # print(my.userInfo["data"]["user"])
        # print(firmCode)
        # print(departmentId)
        # print("==========1============")
        listByExample =  zcApi.get_listByExample(host=host,firmCode=firmCode,departmentId=departmentId)
        print("listByExample",listByExample.json())
        if userName == None:
            listByExampleIndex = 0
        else:
            listByExampleIndex = listByExample.json()["data"].index(
                [i for i in listByExample.json()["data"] if i["userName"] == userName][0])
        inGreeterId = listByExample.json()["data"][listByExampleIndex]["id"]
        inGreeterName = listByExample.json()["data"][listByExampleIndex]["realName"]
    else:
        inGreeterId=""
        inGreeterName = ""

    # if "进门接车员" in templateAttr_list:
    #     listByExample = zcApi.get_listByExample(host=host)
    #     print(listByExample.json())
    #     if userName == None:
    #         listByExampleIndex = 0
    #     else:
    #         listByExampleIndex = listByExample.json()["data"].index(
    #             [i for i in listByExample.json()["data"] if i["userName"] == userName][0])
    #     inGreeterId = listByExample.json()["data"][listByExampleIndex]["id"]
    #     inGreeterName = listByExample.json()["data"][listByExampleIndex]["realName"]
    # else:
    #     inGreeterId = ""
    #     inGreeterName = ""

    # 获取交易类型
    if "交易类型" in templateAttr_list:
        transactionType = zcApi.query_transactionType(host=host)
        print(transactionType.json())
        print("交易类型")
        if transactionName == None:
            transactionTypeIndex = 0
        else:
            transactionTypeIndex = transactionType.json()["rows"].index(
                [i for i in transactionType.json()["rows"] if i["name"] == transactionName][0])
        tradeType = transactionType.json()["rows"][transactionTypeIndex]["code"]
        tradeTypeId = transactionType.json()["rows"][transactionTypeIndex]["id"]
        tradeTypeName = transactionType.json()["rows"][transactionTypeIndex]["name"]
    else:
        tradeType = ""
        tradeTypeId = ""
        tradeTypeName = ""

    # 获取货物标签
    if "货物标签" in templateAttr_list:
        goodsTag = zcApi.get_goodsTag(host=host)
        print(goodsTag.json())
        if goodsTagName == None:
            transactionTypeIndex = 0
        else:
            transactionTypeIndex = goodsTag.json()["data"].index(
                [i for i in goodsTag.json()["data"] if i["name"] == goodsTagName][0])
        goodsTagId = goodsTag.json()["data"][transactionTypeIndex]["id"]
    else:
        goodsTagId = ""

    # 产地信息获取
    if "产地" in templateAttr_list:
        address = zcApi.get_address(host=host)
        print(address.json())
        originId = address.json()["data"][0]["id"]
        origin = address.json()["data"][0]["name"]
        originCode = address.json()["data"][0]["cityCode"]
    else:
        originId = ""
        origin = ""
        originCode = ""

    # 查询部门信息
    # 查询部门信息
    if "接车部门" in templateAttr_list or "收费部门" in templateAttr_list:
        depRes = zcApi.get_dep(host=host)
        print(depRes.json())
        if depName == None:
            depResIndex = 0
        else:
            depResIndex = depRes.json()["data"].index(
                [i for i in depRes.json()["data"] if i["name"] == depName][0])
        feeDepId = depRes.json()["data"][depResIndex]["id"]
        feeDepName = depRes.json()["data"][depResIndex]["name"]
    else:
        feeDepId = ""
        feeDepName = ""

    # 获取证明类型
    if "证明类型" in templateAttr_list:
        proveType = zcApi.get_proveType(host=host)
        print(proveType.json())
        # print("proveName",proveName)
        if proveName == None:
            proveTypeIndex = 0
        else:
            proveTypeIndex = proveType.json()["data"].index(
                [i for i in proveType.json()["data"] if i["name"] == proveName][0])
        proveTypeCode = proveType.json()["data"][proveTypeIndex]["id"]
        proveTypeName = proveType.json()["data"][proveTypeIndex]["name"]
    else:
        proveTypeCode = ""
        proveTypeName = ""
    print("proveTypeCode", proveTypeCode)
    print("proveTypeName", proveTypeName)

    # 获取防重token
    duplicateTokenRes = zcApi.get_duplicateToken(host=host)
    print(duplicateTokenRes.json())
    duplicateToken = duplicateTokenRes.json()["data"]

    # 创建生成进门单
    plate = plate
    productState = "1"
    trailerNumber = plate

    # 重量信息准备
    weight = int(itemWeight)*int(qty)

    # 创建进门单
    cre_res = create_sparePartsWeighSave(host=host, duplicateToken=duplicateToken,
                                           carTypeCode=carTypeCode, carTypeId=carTypeId,
                                           carTypeName=carTypeName, plate=plate,weight=weight,
                                           productId=productId, productName=productName, proveTypeCode=proveTypeCode,
                                           proveTypeName=proveTypeName, trailerNumber=trailerNumber, depName=feeDepName,
                                           cateId=cateId, originId=originId, origin=origin, originCode=originCode,
                                           tradeType=tradeType, tradeTypeName=tradeTypeName, productState=productState,
                                           tradeTypeId=tradeTypeId, goodsTagId=goodsTagId, inGreeterId=inGreeterId,
                                           inGreeterName=inGreeterName, dep=feeDepId)
    return cre_res

# host="http://test.gateway.diligrp.com:8285"
# cre_res = create_sj(host=host,keyword="雪莲果")
# print(cre_res.json())
# number = cre_res.json()["data"]["number"]
# aa = eFBL.do_payOrder(attrValue=number)