From 1e24287327e2ae86deba2c02b81661b2a53e47c7 Mon Sep 17 00:00:00 2001 From: liuxiaoqing Date: Tue, 19 Aug 2025 13:52:25 +0800 Subject: [PATCH] =?UTF-8?q?refactor(webapp):=20=E9=87=8D=E6=9E=84=E5=8F=91?= =?UTF-8?q?=E7=A5=A8=E9=AA=8C=E8=AF=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改基础 URL为本地地址 - 优化发票验证和列表查询逻辑 - 更新数据库结构和查询语句 - 改进前端发票管理页面,增加验证结果展示 - 修复后端发票列表接口,支持 JSON 请求 --- alibabacloud_sample/dataservice.py | 67 +++++------------- alibabacloud_sample/dbservice.py | 1 + alibabacloud_sample/main.py | 4 +- alibabacloud_sample/service.py | 12 ++-- alibabacloud_sample/verify.db | Bin 32768 -> 36864 bytes .../src/components/check/Check.vue | 2 +- .../src/components/check/index.vue | 2 +- .../src/components/check/upload.vue | 3 +- webapp/vite-project/src/pages/manage.vue | 37 ++++++---- webapp/vite-project/src/utils/baseurl.ts | 2 +- 10 files changed, 59 insertions(+), 71 deletions(-) diff --git a/alibabacloud_sample/dataservice.py b/alibabacloud_sample/dataservice.py index 9e2e050..866070f 100644 --- a/alibabacloud_sample/dataservice.py +++ b/alibabacloud_sample/dataservice.py @@ -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 \ No newline at end of file + data = {} + for i in range(len(row)): + data[cursor.description[i][0]] = row[i] + datas.append(data) + return datas \ No newline at end of file diff --git a/alibabacloud_sample/dbservice.py b/alibabacloud_sample/dbservice.py index 67fc093..ec78d8a 100644 --- a/alibabacloud_sample/dbservice.py +++ b/alibabacloud_sample/dbservice.py @@ -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) diff --git a/alibabacloud_sample/main.py b/alibabacloud_sample/main.py index a4926cf..79a198a 100644 --- a/alibabacloud_sample/main.py +++ b/alibabacloud_sample/main.py @@ -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(): diff --git a/alibabacloud_sample/service.py b/alibabacloud_sample/service.py index 1a0f8a7..108f9dd 100644 --- a/alibabacloud_sample/service.py +++ b/alibabacloud_sample/service.py @@ -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: # 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。 diff --git a/alibabacloud_sample/verify.db b/alibabacloud_sample/verify.db index 91be7965989aa209d8a1d325c4b48e463adc5cbe..aea8c57cb9089159ea040128415d121e2db9ee13 100644 GIT binary patch delta 1264 zcmah}L2naB6kgi_#}2EBl?n4dGHI_>h13fYLRFEQI8qQQkz6V+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check/Check.vue index 039e3e4..72c0a55 100644 --- a/webapp/vite-project/src/components/check/Check.vue +++ b/webapp/vite-project/src/components/check/Check.vue @@ -107,7 +107,7 @@ const emit= defineEmits(['update:formState']) const fileType = ref('img') onMounted(() => { - alert(props.filePath) + // alert(props.filePath) if(props.filePath){ fileType.value = props.filePath.split('.').pop() ==='pdf'?'pdf':'img' request.get('/recognize?filePath='+encodeURIComponent(props.filePath)).then((res) => { diff --git a/webapp/vite-project/src/components/check/index.vue b/webapp/vite-project/src/components/check/index.vue index 8567d0b..4a7220f 100644 --- a/webapp/vite-project/src/components/check/index.vue +++ b/webapp/vite-project/src/components/check/index.vue @@ -7,7 +7,7 @@ import { // SmileOutlined, } from '@ant-design/icons-vue' import type {StepProps} from "ant-design-vue" -import Check from './Check.vue' +import Check from './Check.vue' import upload from './upload.vue' import Report from "./report.vue" // 步骤 diff --git a/webapp/vite-project/src/components/check/upload.vue b/webapp/vite-project/src/components/check/upload.vue index 3f1fabb..6aaa55b 100644 --- a/webapp/vite-project/src/components/check/upload.vue +++ b/webapp/vite-project/src/components/check/upload.vue @@ -35,7 +35,8 @@ const handleUpload = (options: any) => { if (xhr.status === 200 || xhr.status === 201) { console.log(xhr.responseText); onSuccess(xhr.responseText, file); - emit('update:filePath', xhr.responseText) + let res = JSON.parse(xhr.responseText) + emit('update:filePath', res.file_path) } else { onError(new Error(`Upload failed with status ${xhr.status}`)); } diff --git a/webapp/vite-project/src/pages/manage.vue b/webapp/vite-project/src/pages/manage.vue index e90ac03..7fc656c 100644 --- a/webapp/vite-project/src/pages/manage.vue +++ b/webapp/vite-project/src/pages/manage.vue @@ -1,10 +1,10 @@ diff --git a/webapp/vite-project/src/utils/baseurl.ts b/webapp/vite-project/src/utils/baseurl.ts index ce5a87f..c01d42a 100644 --- a/webapp/vite-project/src/utils/baseurl.ts +++ b/webapp/vite-project/src/utils/baseurl.ts @@ -1,2 +1,2 @@ -export const baseURL = "http://192.168.1.100:5555" +export const baseURL = "http://127.0.0.1:5555" // export const baseURL = "http://101.200.148.149:8555" \ No newline at end of file