refactor(webapp): 重构发票验证功能

- 修改基础 URL为本地地址
- 优化发票验证和列表查询逻辑
- 更新数据库结构和查询语句
- 改进前端发票管理页面,增加验证结果展示
- 修复后端发票列表接口,支持 JSON 请求
This commit is contained in:
liuxiaoqing
2025-08-19 13:52:25 +08:00
parent c22a509633
commit 1e24287327
10 changed files with 59 additions and 71 deletions
+19 -48
View File
@@ -38,7 +38,7 @@ class DataService:
purchaserBankAccountInfo, purchaserContactInfo, purchaserName,
purchaserTaxNumber, recipient, remarks, reviewer,
sellerBankAccountInfo, sellerContactInfo, sellerName, sellerTaxNumber,
specialTag, title, totalAmount, totalAmountInWords,file_path,verify_time,cyjgxx,
specialTag, title, totalAmount, totalAmountInWords,file_path,verify_time,
verify_time,verify_status,desc,desc_files,status
from invoice
"""
@@ -124,14 +124,15 @@ class DataService:
invoice_id = cursor.lastrowid
return invoice_id
# 更新发票状态
def update_invoice_status(self, invoice_id: int, verify_status: str):
def update_invoice_status(self, invoice_id: int, verify_status: str,inspectionAmount :str ):
conn = DBService().get_conn()
cursor = conn.cursor()
cursor.execute(
"UPDATE invoice SET verify_time = ?,"
"verify_status = ?"
"inspectionAmount = ?"
"WHERE id = ?",
(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), verify_status, invoice_id))
(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), verify_status,inspectionAmount, invoice_id))
conn.commit()
def update_invoice_desc(self, invoice_id: int|str, desc: str, desc_file: str,status: str):
conn = DBService().get_conn()
@@ -145,20 +146,20 @@ class DataService:
(desc, desc_file,status, invoice_id))
conn.commit()
# 查询验证记录
def get_verify_log(self, file_path: str) -> dict[Any, Any]:
def get_verify_log(self, file_path: str) -> dict[Any, Any]|None:
conn = DBService().get_conn()
cursor = conn.cursor()
cursor.execute("""
select inspectionAmount,cyjgxx,verify_time,file_path from verify_log where file_path = ? order verify_time desc limit 1
select inspectionAmount,cyjgxx,verify_time,file_path from verify_log where file_path = ? order by verify_time desc limit 1
"""
, (file_path,))
rows = cursor.fetchall()
data = {}
if len(rows) > 0:
data = {}
for i in range(len(rows[0])):
data[cursor.description[i][0]] = rows[0][i]
return data
return data
return None
# 插入验证记录
def insert_verify_log(self, inspection_amount: str, cyjgxx: str, file_path: str):
conn = DBService().get_conn()
@@ -196,18 +197,18 @@ class DataService:
purchaserBankAccountInfo, purchaserContactInfo, purchaserName,
purchaserTaxNumber, recipient, remarks, reviewer,
sellerBankAccountInfo, sellerContactInfo, sellerName, sellerTaxNumber,
specialTag, title, totalAmount, totalAmountInWords,file_path,verify_time,verify_status,desc,desc_files,status
specialTag, title, totalAmount, totalAmountInWords,file_path,verify_time,verify_status,inspectionAmount,desc,desc_files,status
from invoice where
"""
if time_out != 'all':
sql += " date('now', '-"+time_out+" day') >= date(verify_time) and verify_status == 'success' "
else:
sql += " verify_status = " + verify_status
sql += " verify_status = '" + verify_status+"'"
if start_date is not None:
sql += " and verify_time >= '" + start_date.strftime("%Y-%m-%d") + "'"
if end_date is not None:
sql += " and verify_time <= '" + end_date.strftime("%Y-%m-%d") + "'"
if value != '':
if value is not None and value != '':
sql += " and ( "
sql += "file_path like '%" + value + "%' or "
sql += "checkCode like '%" + value + "%' or "
@@ -242,43 +243,13 @@ class DataService:
sql += "desc_files like '%" + value + "%' "
sql += ")"
sql += " order by verify_time desc"
print(sql)
cursor.execute(sql)
rows = cursor.fetchall()
data = []
datas = []
for row in rows:
data.append({
'checkCode': row[0],
'drawer': row[1],
'formType': row[2],
'invoiceAmountPreTax': row[3],
'invoiceCode': row[4],
'invoiceDate': row[5],
'invoiceNumber': row[6],
'invoiceTax': row[7],
'invoiceType': row[8],
'machineCode': row[9],
'passwordArea': row[10],
'printedInvoiceCode': row[11],
'printedInvoiceNumber': row[12],
'purchaserBankAccountInfo': row[13],
'purchaserContactInfo': row[14],
'purchaserName': row[15],
'purchaserTaxNumber': row[16],
'recipient': row[17],
'remarks': row[18],
'reviewer': row[19],
'sellerBankAccountInfo': row[20],
'sellerContactInfo': row[21],
'sellerName': row[22],
'sellerTaxNumber': row[23],
'specialTag': row[24],
'title': row[25],
'totalAmount': row[26],
'totalAmountInWords': row[27],
'file_path': row[28],
'verify_time': row[29],
'verify_status': row[30],
'desc': row[31],
'desc_files': row[32]
})
return data
data = {}
for i in range(len(row)):
data[cursor.description[i][0]] = row[i]
datas.append(data)
return datas
+1
View File
@@ -117,6 +117,7 @@ class DBService:
file_path TEXT, -- 文件哈希
verify_time TEXT, -- 验证时间
verify_status TEXT, -- 验证结果
inspectionAmount TEXT, -- 验证次数
desc TEXT, -- 备注
desc_files TEXT, -- 备注附件
status TEXT, -- 是否报销(yes,no
+2 -2
View File
@@ -65,8 +65,8 @@ def reverify():
# 发票列表
@app.route('/listInvoice',methods=['POST'])
def list_invoice():
value = request.form.get('value')
verify_status = request.form.get('verifyStatus')
value = request.json.get('value')
verify_status = request.json.get('verify_status')
return dataservice.get_invoice_list(value=value,verify_status=verify_status)
@app.route('/listInvoiceTimeOut',methods=['POST'])
def list_invoice_time_out():
+8 -4
View File
@@ -71,8 +71,8 @@ class Service:
# 复验
if not reverify:
data1 = dataservice.get_verify_log(file_path=file_path)
print(data)
if data1 is not None and data1.get('inspectionAmount') > 0:
print(data1)
if data1 is not None and int(data1.get('inspectionAmount')) > 0:
return data1
client = Service.create_client()
type = Service.typeDict.get(data.get('invoiceType'))
@@ -96,13 +96,17 @@ class Service:
try:
resp = client.verify_vatinvoice_with_options(verify_vatinvoice_request, runtime)
ConsoleClient.log(UtilClient.to_jsonstring(resp))
resdata = json.loads(UtilClient.to_jsonstring(resp.body.data)).get('data')
respjson = json.loads(UtilClient.to_jsonstring(resp.body.data))
code = respjson.get('code')
if code != '001':
return {'cyjgxx': respjson.get('msg'), 'inspectionAmount': -1,'status': 'fail'}
resdata = respjson.get('data')
if resdata is None:
resdata = {'cyjgxx': "未查询到发票信息", 'inspectionAmount': -1,'status': 'fail'}
else:
resdata.update({'status': 'success'})
dataservice.insert_verify_log(resdata.get('inspectionAmount'), resdata.get('cyjgxx'), file_path)
dataservice.update_invoice_status(data.get('id'), resdata.get('status'))
dataservice.update_invoice_status(data.get('id'), resdata.get('status'), resdata.get('inspectionAmount'))
return resdata
except Exception as error:
# 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
Binary file not shown.