cardStorageIn.py 3.63 KB
#coding=utf-8

# @Time    : 2021/7/16 14:09
# @Author  : Ljq
# @File    : cardStorageIn.py
# @Software: PyCharm


"""
    入库列表相关接口
"""

import requests
import json
from commons.readConf import readConfig

print("cSI")

# rC = readConfig()
# cardHost = rC.returnOptionsItems("host","cardHost")

def getCardType(cardHost,webHeaders):
    """
    获取卡片类型列表
    :param cardHost:
    :param webHeaders:
    :return:
    """
    url = cardHost+"/provider/getLookupList.action"
    webHeaders["Content-Type"] = "application/x-www-form-urlencoded"
    data={"provider":"cardTypeProvider","queryParams":'{"emptyText":"-- 全部 --"}'}
    res = requests.post(url=url,headers=webHeaders,data=data)
    return res

def getCardFace(cardHost,webHeaders):
    """
    获取卡面信息列表
    :param cardHost:
    :param webHeaders:
    :return:
    """
    url = cardHost+"/provider/getLookupList.action"
    webHeaders["Content-Type"] = "application/x-www-form-urlencoded"
    data={"provider":"cardFaceProvider","queryParams":'{emptyText:"-- 请选择 --"}'}
    res = requests.post(url=url,headers=webHeaders,data=data)
    return res

def returnFaceValue(resCardFace,faceNum):
    """
    根据faceNum获取对应卡面的value,目前卡面faceNum值为1-4
    :param resCardFace:
    :param faceNum:
    :return:
    """
    # print("resCardFace",type(resCardFace))
    if resCardFace.json()[0]["text"] == "-- 无--":
        # 业务需求当存在 卡面 “--无--”  时,入库不需要传递cardFace
        cardFace = None
    else:
        cardFace = resCardFace.json()[faceNum]["value"]
    return cardFace


def savaCard(cardHost,webHeaders,startCardNo,endCardNo,cardType=10,cardFace=None):
    """
    卡片入库接口
    :param cardHost:
    :param webHeaders:
    :param startCardNo:
    :param endCardNo:
    :param cardType:
    :param cardFace:
    :return:
    """
    amount = int(endCardNo)-int(startCardNo)+1
    url = cardHost + "/cardStorageIn/save.action"
    if cardFace == None:
        # 当卡面类型为无时,创建入库时,不能传faceNum
        data = {"cardType": str(cardType), "startCardNo": str(startCardNo), "endCardNo": str(endCardNo), "amount": amount}
    else:
        data = {"cardType": str(cardType), "cardFace": cardFace, "startCardNo": str(startCardNo), "endCardNo": str(endCardNo), "amount": amount}
    webHeaders["Content-Type"] = "application/json; charset=UTF-8"
    print("savaCard data ---->  ",data)
    res = requests.post(url=url, headers=webHeaders, data=json.dumps(data))
    return res

def queryList(cardHost=None,webHeaders=None,**searshData):
    """
    入库列表查询
    :param cardHost:
    :param webHeaders:
    :param searshData:
    :return:
    """
    storageInListUrl = cardHost + "/cardStorageIn/queryList.action"
    webHeaders["Content-Type"] = "application/x-www-form-urlencoded"
    storageInSearshData = {"rows": "10", "page": "1", "sort": "create_time", "order": "desc", "startDate": None,
                           "endDate": None}
    storageInSearshData = dict(storageInSearshData,**searshData)
    # print("storageInSearshData[i]---->",storageInSearshData)
    res = requests.post(url=storageInListUrl, headers=webHeaders, data=storageInSearshData)
    return res

def delCard(cardHost=None,webHeaders=None,ids=None):
    """
    删除入库记录
    :param cardHost:
    :param webHeaders:
    :param ids:
    :return:
    """
    storageInListUrl = cardHost + "/cardStorageIn/del.action"
    webHeaders["Content-Type"] = "application/x-www-form-urlencoded"
    delCardData = {"ids":ids}
    res = requests.post(url=storageInListUrl, headers=webHeaders, data=delCardData)
    return res