2025-08-17 13:24:36 +08:00
|
|
|
from flask import Flask, request, render_template, send_from_directory
|
|
|
|
|
from flask_cors import CORS
|
|
|
|
|
from alibabacloud_sample.dataservice import DataService
|
|
|
|
|
from alibabacloud_sample.fileservice import FileService
|
|
|
|
|
from alibabacloud_sample.service import Service
|
2025-08-18 17:54:29 +08:00
|
|
|
|
2025-08-17 13:24:36 +08:00
|
|
|
app = Flask(__name__)
|
|
|
|
|
CORS(app)
|
|
|
|
|
app.config['UPLOAD_FOLDER'] = 'uploads' # 指定上传文件夹
|
|
|
|
|
app.config['WEBAPP'] = 'templates'
|
2025-08-18 17:45:36 +08:00
|
|
|
dataservice = DataService()
|
2025-08-17 13:24:36 +08:00
|
|
|
@app.route('/index')
|
|
|
|
|
def index():
|
|
|
|
|
return render_template('index.html')
|
|
|
|
|
@app.route('/assets/<path:filename>')
|
|
|
|
|
def return_js(filename):
|
|
|
|
|
return send_from_directory(app.config.get('WEBAPP')+'/assets', str(filename))
|
|
|
|
|
@app.route('/uploads/<path:filename>')
|
|
|
|
|
def return_file(filename):
|
|
|
|
|
return send_from_directory(app.config.get('UPLOAD_FOLDER'), str(filename))
|
|
|
|
|
# 上传文件
|
|
|
|
|
@app.route('/upload', methods=['POST'])
|
|
|
|
|
def upload_file():
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
file_service = FileService()
|
|
|
|
|
msg = file_service.upload(request,app.config['UPLOAD_FOLDER'])
|
|
|
|
|
if msg == "No file part" or msg == "No selected file":
|
|
|
|
|
return "请选择文件"
|
|
|
|
|
else:
|
|
|
|
|
return msg
|
|
|
|
|
return None
|
|
|
|
|
# 发票识别
|
|
|
|
|
@app.route('/recognize', methods=['GET'])
|
|
|
|
|
def recognize():
|
|
|
|
|
file_path = request.args.get('filePath')
|
|
|
|
|
service = Service()
|
|
|
|
|
data = dataservice.get_invoice(file_path=file_path)
|
2025-08-17 22:39:59 +08:00
|
|
|
if data is not None and data.get('file_path') is not None:
|
2025-08-17 13:24:36 +08:00
|
|
|
return data
|
|
|
|
|
return service.recognize(file_path=file_path)
|
|
|
|
|
# 发票验证
|
|
|
|
|
@app.route('/verify', methods=['GET'])
|
|
|
|
|
def verify():
|
2025-08-18 17:45:36 +08:00
|
|
|
file_path = request.args.get('filePath')
|
|
|
|
|
invoice_id = request.args.get('invoiceId')
|
|
|
|
|
if file_path is None:
|
|
|
|
|
return "请选择文件"
|
|
|
|
|
service = Service()
|
|
|
|
|
data = dataservice.get_invoice(file_path=file_path,invice_id=invoice_id)
|
|
|
|
|
if data is not None:
|
|
|
|
|
if data.get('status') == 'yes':
|
|
|
|
|
return "已报销发票!!"
|
|
|
|
|
return service.verify(data=data,file_path=file_path)
|
|
|
|
|
else:
|
|
|
|
|
return "请选择文件"
|
|
|
|
|
# 发票复验
|
|
|
|
|
@app.route('/reverify', methods=['GET'])
|
|
|
|
|
def reverify():
|
2025-08-17 13:24:36 +08:00
|
|
|
file_path = request.args.get('filePath')
|
|
|
|
|
if file_path is None:
|
|
|
|
|
return "请选择文件"
|
|
|
|
|
service = Service()
|
|
|
|
|
data = dataservice.get_invoice(file_path=file_path)
|
2025-08-18 17:45:36 +08:00
|
|
|
return service.verify(data=data,file_path=file_path,reverify=True)
|
|
|
|
|
# 发票列表
|
|
|
|
|
@app.route('/listInvoice',methods=['POST'])
|
2025-08-18 17:54:29 +08:00
|
|
|
def list_invoice():
|
2025-08-19 13:52:25 +08:00
|
|
|
value = request.json.get('value')
|
|
|
|
|
verify_status = request.json.get('verify_status')
|
2025-08-19 22:22:44 +08:00
|
|
|
verify_time = request.json.get('verify_time')
|
|
|
|
|
start_date = None
|
|
|
|
|
end_date = None
|
|
|
|
|
if verify_time is not None:
|
|
|
|
|
start_date = verify_time[0].split(' ')[0]
|
|
|
|
|
end_date = verify_time[1].split(' ')[0]
|
|
|
|
|
return dataservice.get_invoice_list(value=value,verify_status=verify_status,start_date=start_date,end_date=end_date)
|
2025-08-18 17:45:36 +08:00
|
|
|
@app.route('/listInvoiceTimeOut',methods=['POST'])
|
2025-08-18 17:54:29 +08:00
|
|
|
def list_invoice_time_out():
|
2025-08-18 17:45:36 +08:00
|
|
|
time_out = request.form.get('timeOut')
|
|
|
|
|
return dataservice.get_invoice_list(value='',verify_status='',time_out=time_out)
|
|
|
|
|
# 发票日志列表
|
|
|
|
|
@app.route('/listLogs',methods=['GET'])
|
2025-08-18 17:54:29 +08:00
|
|
|
def list_logs():
|
2025-08-18 17:45:36 +08:00
|
|
|
file_path = request.args.get('filePath')
|
|
|
|
|
return dataservice.get_verify_log_list(file_path=file_path)
|
|
|
|
|
# 更新发票标注
|
|
|
|
|
@app.route('/updateInvoice',methods=['POST'])
|
2025-08-18 17:54:29 +08:00
|
|
|
def update_invoice():
|
2025-08-19 17:35:34 +08:00
|
|
|
invoice_id = request.json.get('invoiceId')
|
|
|
|
|
status = request.json.get('status')
|
|
|
|
|
desc = request.json.get('desc')
|
|
|
|
|
desc_files = request.json.get('desc_files')
|
2025-08-18 17:45:36 +08:00
|
|
|
return dataservice.update_invoice_desc(invoice_id=invoice_id,desc=desc,desc_file=desc_files,status=status)
|
2025-08-17 13:24:36 +08:00
|
|
|
if __name__ == '__main__':
|
|
|
|
|
# Service.verify(sys.argv[1:])
|
|
|
|
|
# Service.recognize(file_path="/home/jayus/图片/wechat_2025-07-31_131911_822.png")
|
2025-08-17 22:39:59 +08:00
|
|
|
app.run(host='0.0.0.0', port=5555, debug=True)
|