2026-04-07 17:23:00 +08:00
|
|
|
|
from flask import Blueprint, request, jsonify, send_file # .material -> .base refactor checked
|
2026-02-05 14:30:11 +08:00
|
|
|
|
from app.services.inbound.inbound_summary_service import InboundSummaryService
|
|
|
|
|
|
|
|
|
|
|
|
# 定义蓝图
|
|
|
|
|
|
bp = Blueprint('inbound_summary', __name__)
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route('/list', methods=['GET'])
|
|
|
|
|
|
def get_list():
|
|
|
|
|
|
try:
|
|
|
|
|
|
# 获取参数
|
|
|
|
|
|
page = request.args.get('page', 1, type=int)
|
|
|
|
|
|
per_page = request.args.get('per_page', 20, type=int) # 默认每页20
|
|
|
|
|
|
keyword = request.args.get('keyword', '')
|
|
|
|
|
|
start_date = request.args.get('start_date')
|
|
|
|
|
|
end_date = request.args.get('end_date')
|
|
|
|
|
|
source_type = request.args.get('source_type') # 可选:筛选 specific table
|
2026-07-15 11:11:40 +08:00
|
|
|
|
company = request.args.get('company', '')
|
2026-02-05 14:30:11 +08:00
|
|
|
|
|
|
|
|
|
|
result = InboundSummaryService.get_list(
|
|
|
|
|
|
page=page,
|
|
|
|
|
|
per_page=per_page,
|
|
|
|
|
|
keyword=keyword,
|
|
|
|
|
|
start_date=start_date,
|
|
|
|
|
|
end_date=end_date,
|
2026-07-15 11:11:40 +08:00
|
|
|
|
source_type=source_type,
|
|
|
|
|
|
company=company
|
2026-02-05 14:30:11 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
return jsonify({
|
|
|
|
|
|
'code': 200,
|
|
|
|
|
|
'msg': 'success',
|
|
|
|
|
|
'data': result
|
|
|
|
|
|
})
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
# 生产环境建议记录详细日志
|
|
|
|
|
|
print(f"Inbound Summary Error: {str(e)}")
|
2026-02-10 11:34:50 +08:00
|
|
|
|
return jsonify({'code': 500, 'msg': str(e)}), 500
|
2026-04-07 17:23:00 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route('/export', methods=['GET'])
|
|
|
|
|
|
def export_data():
|
|
|
|
|
|
"""
|
|
|
|
|
|
导出入库记录 Excel
|
|
|
|
|
|
支持筛选条件:keyword, start_date, end_date, source_type
|
|
|
|
|
|
"""
|
|
|
|
|
|
try:
|
|
|
|
|
|
# 获取参数
|
|
|
|
|
|
keyword = request.args.get('keyword', '')
|
|
|
|
|
|
start_date = request.args.get('start_date')
|
|
|
|
|
|
end_date = request.args.get('end_date')
|
|
|
|
|
|
source_type = request.args.get('source_type')
|
2026-07-15 11:11:40 +08:00
|
|
|
|
company = request.args.get('company', '')
|
2026-04-07 17:23:00 +08:00
|
|
|
|
|
|
|
|
|
|
# 调用导出服务
|
|
|
|
|
|
file_stream = InboundSummaryService.export_excel(
|
|
|
|
|
|
keyword=keyword,
|
|
|
|
|
|
start_date=start_date,
|
|
|
|
|
|
end_date=end_date,
|
2026-07-15 11:11:40 +08:00
|
|
|
|
source_type=source_type,
|
|
|
|
|
|
company=company
|
2026-04-07 17:23:00 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
now = datetime.now().strftime('%Y%m%d_%H%M%S')
|
|
|
|
|
|
filename = f"入库记录_{now}.xlsx"
|
|
|
|
|
|
|
|
|
|
|
|
return send_file(
|
|
|
|
|
|
file_stream,
|
|
|
|
|
|
mimetype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
|
|
|
|
as_attachment=True,
|
|
|
|
|
|
download_name=filename
|
|
|
|
|
|
)
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
print(f"Inbound Summary Export Error: {str(e)}")
|
|
|
|
|
|
return jsonify({'code': 500, 'msg': str(e)}), 500
|