提交 df894bd2 authored 作者: ”name“'s avatar ”name“

补充代码

上级 58edc1c3
"""
@-*- coding: utf-8 -*-
@ python:python 3.9
@ 创建人员:libaofeng
@ 创建时间:2025/09/16
煤价分析工具上报端app用户数据上报流程
"""
\ No newline at end of file
...@@ -1005,7 +1005,6 @@ class Coal_price_reporting_app(object): ...@@ -1005,7 +1005,6 @@ class Coal_price_reporting_app(object):
wu = None wu = None
return wu return wu
# """--------------------------------------------------循环执行上报----------------------------------------------------""" # """--------------------------------------------------循环执行上报----------------------------------------------------"""
def execute_method_repeatedly(self, user, reporting_type, times): def execute_method_repeatedly(self, user, reporting_type, times):
""" """
......
"""
@-*- coding: utf-8 -*-
@ python:python 3.9
@ 创建人员:libaofeng
@ 创建时间:2025/09/16
煤价分析工具上报端app用户数据上报流程
flask_receive_parameters/__init__.py
Flask应用工厂
"""
from flask import Flask
from .routes import bp # 导入路由蓝图
from flask_cors import CORS
def create_app():
"""
创建Flask应用实例
"""
app = Flask(__name__)
CORS(app)
# 注册蓝图
app.register_blueprint(bp)
print("✅ Flask应用创建成功")
print(f"✅ 注册蓝图: {bp.name}")
return app
# 测试代码
if __name__ == '__main__':
app = create_app()
app.run(debug=True, host='0.0.0.0', port=5000)
\ No newline at end of file
"""
@-*- coding: utf-8 -*-
@ python:python 3.9
@ 创建人员:libaofeng
@ 创建时间:2025/09/16
煤价分析工具上报端app用户数据上报流程
flask_receive_parameters/routes.py
API路由定义 - 使用类封装
"""
from data_center.coal_price_analysis_app import Coal_price_reporting_app
from flask import Blueprint, request, jsonify
import sys
import os
class APIHandler:
"""API请求处理器类"""
def __init__(self):
"""初始化API处理器"""
# 添加项目根目录到Python路径
project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(project_root)
self.Coal_reporting_user = Coal_price_reporting_app() # 煤价分析上报端用户user
self.Coal_price_reporting_app = Coal_price_reporting_app # 导入业务模块
def handle_test(self):
"""处理测试接口请求"""
return jsonify({
"message": "后端服务连接成功!",
"status": "success"
})
def handle_run(self):
"""
处理运行接口请求
接收前端参数,调用execute_method_repeatedly方法
"""
print("=" * 50)
print("🚀 /api/run 接口被调用")
print("=" * 50)
try:
# 1. 接收前端JSON数据
data = request.get_json()
if not data:
return jsonify({"status": "error", "message": "未接收到有效数据"}), 400
# 2. 提取参数
param1 = data.get('param1')
param2 = data.get('param2')
print(f"📥 接收到的参数: param1={param1}, param2={param2}")
print(f"📥 参数类型: param1={type(param1)}, param2={type(param2)}")
# 3. 验证参数
if param1 is None or param2 is None:
return jsonify({
"status": "error",
"message": "缺少必要参数: param1 和 param2 是必填的"
}), 400
# 4. 检查模块导入是否成功
if self.Coal_price_reporting_app is None:
return jsonify({
"status": "error",
"message": "业务模块导入失败,请检查 data_center.coal_price_analysis_app 模块"
}), 500
# 5. 创建实例并调用方法
coal_app = self.Coal_price_reporting_app()
result = coal_app.execute_method_repeatedly(self.Coal_reporting_user.reporting_end_user, param1, param2)
print(f"✅ 方法执行结果: {result}")
print("=" * 50)
# 6. 返回结果
return jsonify({
"status": "success",
"received_params": {
"param1": param1, # 前端传的第一个参数
"param2": param2, # 前端传的第二个参数
},
"method_result": result if result is not None else "方法已执行(无返回值)",
"message": f"执行成功"
})
except TypeError as error:
# 专门处理参数错误
if "missing 1 required positional argument" in str(error):
return jsonify({
"status": "error",
"message": f"参数错误: 您的方法需要2个参数(param1, param2),但只收到了{data.keys()}。"
}), 400
raise error
except Exception as error:
print(f"❌ 执行过程中发生错误: {str(error)}")
import traceback
traceback.print_exc()
return jsonify({
"status": "error",
"message": f"执行错误: {str(error)}"
}), 500
# 创建API处理器实例
api_handler = APIHandler()
# 创建蓝图
bp = Blueprint('receive_params', __name__)
# 注册路由
@bp.route('/api/test', methods=['GET'])
def test():
"""测试接口"""
return api_handler.handle_test()
@bp.route('/api/run', methods=['POST'])
def run_code():
"""运行接口"""
return api_handler.handle_run()
# 测试代码
if __name__ == '__main__':
# 测试API处理器
handler = APIHandler()
print("🚨 这是路由文件,请通过 run.py 启动应用")
\ No newline at end of file
"""
@-*- coding: utf-8 -*-
@ python:python 3.9
@ 创建人员:libaofeng
@ 创建时间:2025/09/16
煤价分析工具上报端app用户数据上报流程
flask_receive_parameters/run.py
应用启动文件
"""
from flask_receive_parameters import create_app
# 创建应用实例
app = create_app()
if __name__ == '__main__':
print("=" * 50)
print("🚀 启动 Flask 应用")
print("📡 本地访问: http://127.0.0.1:5000")
print("📡 局域网访问: http://<您的IP>:5000")
print("📡 接口列表:")
print(" GET http://127.0.0.1:5000/api/test")
print(" POST http://127.0.0.1:5000/api/run")
print("=" * 50)
# 启动应用
app.run(
debug=True, # 调试模式,生产环境设为 False
host='0.0.0.0', # 监听所有网络接口
port=5000, # 端口号
threaded=True # 启用多线程
)
\ No newline at end of file
2025-12-18 17:31:50 _internal.py [line:97] INFO: WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on all addresses (0.0.0.0)
* Running on http://127.0.0.1:5000
* Running on http://192.168.1.22:5000
2025-12-18 17:31:50 _internal.py [line:97] INFO: Press CTRL+C to quit
2025-12-18 17:31:50 _internal.py [line:97] INFO: * Restarting with stat
2025-12-18 17:31:51 _internal.py [line:97] WARNING: * Debugger is active!
2025-12-18 17:31:51 _internal.py [line:97] INFO: * Debugger PIN: 969-433-717
2025-12-18 17:32:34 _internal.py [line:97] INFO: 127.0.0.1 - - [18/Dec/2025 17:32:34] "POST /api/run HTTP/1.1" 500 -
2025-12-18 17:35:48 _internal.py [line:97] INFO: * Detected change in 'D:\\Tool\\Jenkins\\Py_Data_Center\\flask_receive_parameters\\routes.py', reloading
2025-12-18 17:35:48 _internal.py [line:97] INFO: * Restarting with stat
2025-12-18 17:35:50 _internal.py [line:97] WARNING: * Debugger is active!
2025-12-18 17:35:50 _internal.py [line:97] INFO: * Debugger PIN: 969-433-717
2025-12-18 17:43:18 _internal.py [line:97] INFO: * Detected change in 'D:\\Tool\\Jenkins\\Py_Data_Center\\flask_receive_parameters\\routes.py', reloading
2025-12-18 17:43:18 _internal.py [line:97] INFO: * Restarting with stat
2025-12-18 17:43:20 _internal.py [line:97] WARNING: * Debugger is active!
2025-12-18 17:43:20 _internal.py [line:97] INFO: * Debugger PIN: 969-433-717
2025-12-18 17:45:33 _internal.py [line:97] INFO: * Detected change in 'D:\\Tool\\Jenkins\\Py_Data_Center\\flask_receive_parameters\\routes.py', reloading
2025-12-18 17:45:33 _internal.py [line:97] INFO: * Restarting with stat
2025-12-18 17:45:35 _internal.py [line:97] WARNING: * Debugger is active!
2025-12-18 17:45:35 _internal.py [line:97] INFO: * Debugger PIN: 969-433-717
2025-12-18 17:48:14 _internal.py [line:97] INFO: * Detected change in 'D:\\Tool\\Jenkins\\Py_Data_Center\\flask_receive_parameters\\routes.py', reloading
2025-12-18 17:48:14 _internal.py [line:97] INFO: * Restarting with stat
2025-12-18 17:48:20 _internal.py [line:97] WARNING: * Debugger is active!
2025-12-18 17:48:20 _internal.py [line:97] INFO: * Debugger PIN: 969-433-717
2025-12-18 17:48:27 _internal.py [line:97] INFO: WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on all addresses (0.0.0.0)
* Running on http://127.0.0.1:5000
* Running on http://192.168.1.22:5000
2025-12-18 17:48:27 _internal.py [line:97] INFO: Press CTRL+C to quit
2025-12-18 17:48:27 _internal.py [line:97] INFO: * Restarting with stat
2025-12-18 17:48:33 _internal.py [line:97] WARNING: * Debugger is active!
2025-12-18 17:48:33 _internal.py [line:97] INFO: * Debugger PIN: 969-433-717
2025-12-18 17:48:33 coal_price_analysis_app.py [line:1025] INFO: 正在执行第 1/2 次...
2025-12-18 17:48:35 coal_price_analysis_app.py [line:151] INFO: 产地信息主动上报成功:
2025-12-18 17:48:35 coal_price_analysis_app.py [line:152] INFO: 产地名称为:电影博物馆
2025-12-18 17:48:35 coal_price_analysis_app.py [line:154] INFO: 煤种:渣渣煤 热值: 5900 Kcal/kg 本期价格: 591.49 元/吨
2025-12-18 17:48:35 coal_price_analysis_app.py [line:154] INFO: 煤种:水洗煤 热值: 3500 Kcal/kg 本期价格: 340.47 元/吨
2025-12-18 17:48:35 coal_price_analysis_app.py [line:154] INFO: 煤种:面煤 热值: 7800 Kcal/kg 本期价格: 772.41 元/吨
2025-12-18 17:48:35 coal_price_analysis_app.py [line:154] INFO: 煤种:渣煤 热值: 7500 Kcal/kg 本期价格: 741.41 元/吨
2025-12-18 17:48:35 coal_price_analysis_app.py [line:154] INFO: 煤种:新煤 热值: 8200 Kcal/kg 本期价格: 819.39 元/吨
2025-12-18 17:48:35 coal_price_analysis_app.py [line:154] INFO: 煤种:面煤 热值: 5700 Kcal/kg 本期价格: 566.49 元/吨
2025-12-18 17:48:35 coal_price_analysis_app.py [line:154] INFO: 煤种:化工煤 热值: 7900 Kcal/kg 本期价格: 786.23 元/吨
2025-12-18 17:48:35 coal_price_analysis_app.py [line:154] INFO: 煤种:天隆精块 热值: 8300 Kcal/kg 本期价格: 838.91 元/吨
2025-12-18 17:48:35 coal_price_analysis_app.py [line:154] INFO: 煤种:渣渣煤 热值: 7500 Kcal/kg 本期价格: 745.24 元/吨
2025-12-18 17:48:35 coal_price_analysis_app.py [line:154] INFO: 煤种:化工煤 热值: 4200 Kcal/kg 本期价格: 417.4 元/吨
2025-12-18 17:48:35 coal_price_analysis_app.py [line:154] INFO: 煤种:渣渣煤 热值: 5300 Kcal/kg 本期价格: 522.9 元/吨
2025-12-18 17:48:35 coal_price_analysis_app.py [line:154] INFO: 煤种:新煤 热值: 6600 Kcal/kg 本期价格: 669.06 元/吨
2025-12-18 17:48:35 coal_price_analysis_app.py [line:154] INFO: 煤种:2-5籽 热值: 5300 Kcal/kg 本期价格: 524.37 元/吨
2025-12-18 17:48:35 coal_price_analysis_app.py [line:154] INFO: 煤种:新煤 热值: 7000 Kcal/kg 本期价格: 691.13 元/吨
2025-12-18 17:48:35 coal_price_analysis_app.py [line:1025] INFO: 正在执行第 2/2 次...
2025-12-18 17:48:35 coal_price_analysis_app.py [line:151] INFO: 产地信息主动上报成功:
2025-12-18 17:48:35 coal_price_analysis_app.py [line:152] INFO: 产地名称为:淖尔豪煤矿
2025-12-18 17:48:35 coal_price_analysis_app.py [line:154] INFO: 煤种:焦炭 热值: 6700 Kcal/kg 本期价格: 672.56 元/吨
2025-12-18 17:48:35 coal_price_analysis_app.py [line:154] INFO: 煤种:化工煤 热值: 3500 Kcal/kg 本期价格: 356.45 元/吨
2025-12-18 17:48:35 coal_price_analysis_app.py [line:154] INFO: 煤种:渣渣煤 热值: 3200 Kcal/kg 本期价格: 312.25 元/吨
2025-12-18 17:48:35 coal_price_analysis_app.py [line:154] INFO: 煤种:水洗煤 热值: 3800 Kcal/kg 本期价格: 389.73 元/吨
2025-12-18 17:48:35 coal_price_analysis_app.py [line:154] INFO: 煤种:化工煤 热值: 4600 Kcal/kg 本期价格: 455.96 元/吨
2025-12-18 17:48:35 coal_price_analysis_app.py [line:154] INFO: 煤种:渣煤 热值: 6900 Kcal/kg 本期价格: 692.46 元/吨
2025-12-18 17:48:35 coal_price_analysis_app.py [line:154] INFO: 煤种:洗面 热值: 7200 Kcal/kg 本期价格: 715.86 元/吨
2025-12-18 17:48:35 coal_price_analysis_app.py [line:154] INFO: 煤种:洗小籽 热值: 5800 Kcal/kg 本期价格: 581.19 元/吨
2025-12-18 17:48:35 _internal.py [line:97] INFO: 127.0.0.1 - - [18/Dec/2025 17:48:35] "POST /api/run HTTP/1.1" 200 -
2025-12-18 18:05:24 _internal.py [line:97] INFO: 127.0.0.1 - - [18/Dec/2025 18:05:24] "OPTIONS /api/run HTTP/1.1" 200 -
2025-12-18 18:05:26 _internal.py [line:97] INFO: 127.0.0.1 - - [18/Dec/2025 18:05:26] "OPTIONS /api/run HTTP/1.1" 200 -
2025-12-18 18:05:31 _internal.py [line:97] INFO: 127.0.0.1 - - [18/Dec/2025 18:05:31] "OPTIONS /api/run HTTP/1.1" 200 -
2025-12-18 18:06:31 _internal.py [line:97] INFO: 127.0.0.1 - - [18/Dec/2025 18:06:31] "OPTIONS /api/run HTTP/1.1" 200 -
2025-12-18 18:06:36 _internal.py [line:97] INFO: 127.0.0.1 - - [18/Dec/2025 18:06:36] "OPTIONS /api/run HTTP/1.1" 200 -
2025-12-18 18:06:49 _internal.py [line:97] INFO: 127.0.0.1 - - [18/Dec/2025 18:06:49] "OPTIONS /api/run HTTP/1.1" 200 -
2025-12-18 18:08:48 _internal.py [line:97] INFO: 127.0.0.1 - - [18/Dec/2025 18:08:48] "OPTIONS /api/run HTTP/1.1" 200 -
2025-12-18 18:08:58 _internal.py [line:97] INFO: 127.0.0.1 - - [18/Dec/2025 18:08:58] "OPTIONS /api/run HTTP/1.1" 200 -
2025-12-18 18:08:58 _internal.py [line:97] INFO: 127.0.0.1 - - [18/Dec/2025 18:08:58] "OPTIONS /api/run HTTP/1.1" 200 -
2025-12-18 18:08:59 _internal.py [line:97] INFO: 127.0.0.1 - - [18/Dec/2025 18:08:59] "OPTIONS /api/run HTTP/1.1" 200 -
2025-12-18 18:08:59 _internal.py [line:97] INFO: 127.0.0.1 - - [18/Dec/2025 18:08:59] "OPTIONS /api/run HTTP/1.1" 200 -
2025-12-18 18:08:59 _internal.py [line:97] INFO: 127.0.0.1 - - [18/Dec/2025 18:08:59] "OPTIONS /api/run HTTP/1.1" 200 -
2025-12-18 18:09:05 _internal.py [line:97] INFO: 127.0.0.1 - - [18/Dec/2025 18:09:05] "OPTIONS /api/run HTTP/1.1" 200 -
2025-12-18 18:09:05 _internal.py [line:97] INFO: 127.0.0.1 - - [18/Dec/2025 18:09:05] "OPTIONS /api/run HTTP/1.1" 200 -
2025-12-18 18:09:05 _internal.py [line:97] INFO: 127.0.0.1 - - [18/Dec/2025 18:09:05] "OPTIONS /api/run HTTP/1.1" 200 -
2025-12-18 18:09:05 _internal.py [line:97] INFO: 127.0.0.1 - - [18/Dec/2025 18:09:05] "OPTIONS /api/run HTTP/1.1" 200 -
2025-12-18 18:09:05 _internal.py [line:97] INFO: 127.0.0.1 - - [18/Dec/2025 18:09:05] "OPTIONS /api/run HTTP/1.1" 200 -
2025-12-18 18:09:06 _internal.py [line:97] INFO: 127.0.0.1 - - [18/Dec/2025 18:09:06] "OPTIONS /api/run HTTP/1.1" 200 -
2025-12-18 18:09:06 _internal.py [line:97] INFO: 127.0.0.1 - - [18/Dec/2025 18:09:06] "OPTIONS /api/run HTTP/1.1" 200 -
2025-12-18 18:09:06 _internal.py [line:97] INFO: 127.0.0.1 - - [18/Dec/2025 18:09:06] "OPTIONS /api/run HTTP/1.1" 200 -
2025-12-18 18:09:06 _internal.py [line:97] INFO: 127.0.0.1 - - [18/Dec/2025 18:09:06] "OPTIONS /api/run HTTP/1.1" 200 -
2025-12-18 18:09:06 _internal.py [line:97] INFO: 127.0.0.1 - - [18/Dec/2025 18:09:06] "OPTIONS /api/run HTTP/1.1" 200 -
2025-12-18 18:09:06 _internal.py [line:97] INFO: 127.0.0.1 - - [18/Dec/2025 18:09:06] "OPTIONS /api/run HTTP/1.1" 200 -
2025-12-18 18:09:07 _internal.py [line:97] INFO: 127.0.0.1 - - [18/Dec/2025 18:09:07] "OPTIONS /api/run HTTP/1.1" 200 -
2025-12-18 18:09:07 _internal.py [line:97] INFO: 127.0.0.1 - - [18/Dec/2025 18:09:07] "OPTIONS /api/run HTTP/1.1" 200 -
2025-12-18 18:09:07 _internal.py [line:97] INFO: 127.0.0.1 - - [18/Dec/2025 18:09:07] "OPTIONS /api/run HTTP/1.1" 200 -
差异被折叠。
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论