251106更新
This commit is contained in:
parent
d5fd39ad55
commit
cc3153637d
Binary file not shown.
|
|
@ -0,0 +1,73 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
就excel工作表进行处理,包括就指定字段解析JSON
|
||||||
|
"""
|
||||||
|
|
||||||
|
from json import loads
|
||||||
|
|
||||||
|
from pandas import DataFrame, read_excel
|
||||||
|
|
||||||
|
from utils.pandas_extension import save_as_workbook
|
||||||
|
|
||||||
|
# 打开并读取指定工作工作表(默认以字符串读取)
|
||||||
|
sheet = read_excel(io="dataset.xlsx", sheet_name="Sheet1", dtype=str)
|
||||||
|
|
||||||
|
dataset = []
|
||||||
|
|
||||||
|
for index, row in sheet.iterrows():
|
||||||
|
# 就指定字段解析为JSON
|
||||||
|
response = loads(row["response"])
|
||||||
|
|
||||||
|
data = {}
|
||||||
|
|
||||||
|
# 根据深圳快瞳票据查验要求解析查验结果
|
||||||
|
# 状态码
|
||||||
|
status = response.get("status", "")
|
||||||
|
# 错误码
|
||||||
|
code = response.get("code", "")
|
||||||
|
# 若状态码为200且错误码为10000,则定义为响应成功
|
||||||
|
if status == 200 and code == 10000:
|
||||||
|
# 查验类型,若查验类型为003081则为医疗收费票据=,003082则为增值税发票
|
||||||
|
match response.get("data").get(
|
||||||
|
"productCode"
|
||||||
|
):
|
||||||
|
# 解析医疗收费票据
|
||||||
|
case "003081":
|
||||||
|
data["发票号"] = response.get("data").get(
|
||||||
|
"billNumber"
|
||||||
|
)
|
||||||
|
# 查验结果
|
||||||
|
match response.get("data").get("flushedRed"):
|
||||||
|
case "true":
|
||||||
|
data["查验结果"] = "正常"
|
||||||
|
case "false":
|
||||||
|
data["查验结果"] = "已红冲"
|
||||||
|
|
||||||
|
# 解析增值税发票
|
||||||
|
case "003082":
|
||||||
|
data["发票号"] = (
|
||||||
|
response.get("data").get("details").get("number")
|
||||||
|
)
|
||||||
|
# 查验结果
|
||||||
|
match response.get("data").get("details").get(
|
||||||
|
"invoiceTypeNo"
|
||||||
|
):
|
||||||
|
case "0":
|
||||||
|
data["查验结果"] = "正常"
|
||||||
|
case "1":
|
||||||
|
data["查验结果"] = "无法查验"
|
||||||
|
case "2" | "3" | "7" | "8":
|
||||||
|
data["查验结果"] = "已红冲"
|
||||||
|
|
||||||
|
# 若状态码为400且错误码为10001或10100,则定义为假票
|
||||||
|
elif status == 400 and (code == 10001 or code == 10100):
|
||||||
|
data["查验结果"] = "假票"
|
||||||
|
|
||||||
|
else:
|
||||||
|
data["查验结果"] = "无法查验"
|
||||||
|
|
||||||
|
dataset.append(data)
|
||||||
|
|
||||||
|
# 本地保存
|
||||||
|
save_as_workbook(worksheets=[("Sheet1", DataFrame(data=dataset, dtype=str))], workbook_name="results.xlsx")
|
||||||
Binary file not shown.
Loading…
Reference in New Issue