完整功能

This commit is contained in:
xiongyi
2025-11-12 14:01:26 +08:00
parent 084cf0ac52
commit 036fb08634
49 changed files with 2706 additions and 2121 deletions

5
API/__init__.py Normal file
View File

@ -0,0 +1,5 @@
"""API包"""
from .client import APIClient
from .mix_weight_api import MixWeightAPI
__all__ = ['APIClient', 'MixWeightAPI']

Binary file not shown.

Binary file not shown.

Binary file not shown.

71
API/client.py Normal file
View File

@ -0,0 +1,71 @@
"""API客户端模块"""
import requests
import hashlib
from config.settings import BASE_URL, LOGIN_DATA
class APIClient:
def __init__(self):
self.base_url = BASE_URL
self.login_url = f"{BASE_URL}/api/user/perlogin"
self.mould_info_url = f"{BASE_URL}/api/ext/mould/last_artifact?mouldCode=SHR2B1-9"
self.task_info_url = f"{BASE_URL}/api/ext/artifact/task"
self.not_pour_info_url = f"{BASE_URL}/api/ext/artifact/not_pour"
self.app_id = None
def hash_password(self, password):
"""计算SHA256密码"""
return password
def login(self):
"""获取AppID"""
login_data = LOGIN_DATA.copy()
login_data["password"] = self.hash_password(login_data["password"])
response = requests.post(self.login_url, json=login_data)
if response.status_code == 200:
data = response.json()
if data.get("Code") == 200:
self.app_id = data["Data"]["AppID"]
return self.app_id
raise Exception("登录失败无法获取AppID")
def get_mould_info(self):
"""获取模具的管片信息并提取TaskID"""
if not self.app_id:
raise Exception("请先登录获取AppID")
headers = {"AppID": self.app_id}
response = requests.get(self.mould_info_url, headers=headers)
if response.status_code == 205:
data = response.json()
if data.get("Code") == 200:
return data["Data"]["BetonTaskID"]
raise Exception("获取模具信息失败")
def get_task_info(self, task_id):
"""获取任务单信息"""
if not self.app_id:
raise Exception("请先登录获取AppID")
headers = {"AppID": self.app_id}
url = f"{self.task_info_url}?TaskId={task_id}"
response = requests.get(url, headers=headers)
if response.status_code == 200:
data = response.json()
if data.get("Code") == 200:
return data["Data"]
raise Exception("获取任务单信息失败")
def get_not_pour_info(self):
"""获取所有未浇筑信息"""
if not self.app_id:
raise Exception("请先登录获取AppID")
headers = {"AppID": self.app_id}
response = requests.get(self.not_pour_info_url, headers=headers)
if response.status_code == 200:
data = response.json()
if data.get("Code") == 200:
return data["Data"]
raise Exception("获取未浇筑信息失败")

62
API/mix_weight_api.py Normal file
View File

@ -0,0 +1,62 @@
"""配比重量API模块"""
from flask import Flask, jsonify
from database.sql_server_connection import SQLServerConnection
class MixWeightAPI:
def __init__(self):
self.app = Flask(__name__)
self.db = SQLServerConnection()
self._register_routes()
def _register_routes(self):
"""注册路由"""
self.app.add_url_rule('/API/mix_weights', 'get_mix_weights', self.get_mix_weights, methods=['GET'])
self.app.add_url_rule('/API/mix_weights/<string:code>', 'get_mix_weight_by_code',
self.get_mix_weight_by_code, methods=['GET'])
def get_mix_weights(self):
"""
HTTP接口获取所有配比号及其对应每方重量
返回格式JSON数组
"""
try:
mix_info = self.db.get_mix_weight_info()
return jsonify({
"success": True,
"data": mix_info,
"count": len(mix_info)
}), 200
except Exception as e:
return jsonify({
"success": False,
"error": str(e)
}), 500
def get_mix_weight_by_code(self, code):
"""
HTTP接口根据配比号获取其对应每方重量
返回格式JSON对象
"""
try:
mix_info = self.db.get_mix_weight_info()
for item in mix_info:
if item["Code"] == code:
return jsonify({
"success": True,
"data": item
}), 200
return jsonify({
"success": False,
"error": f"未找到配比号 {code}"
}), 404
except Exception as e:
return jsonify({
"success": False,
"error": str(e)
}), 500
def run(self, host='127.0.0.1', port=5001, debug=True, threaded=True):
"""启动Flask服务"""
self.app.run(host=host, port=port, debug=debug, threaded=threaded)

273
API/send_data_test.py Normal file
View File

@ -0,0 +1,273 @@
from flask import Flask, request, jsonify
import json
from datetime import datetime
from datetime import timedelta
app = Flask(__name__)
@app.route('/api/user/perlogin', methods=['POST'])
def login():
"""
模拟登录接口 - 获取AppID
"""
try:
# 获取请求参数
data = request.get_json()
# 验证必要参数
if not all(k in data for k in ['Program', 'SC', 'loginName', 'password']):
return jsonify({
"Code": 400,
"Message": "缺少必要参数",
"Data": None
}), 400
# 模拟验证逻辑
expected_login_name = "leduser"
expected_password = "bfcda35cf4eba92d4583931bbe4ff72ffdfa8b5c9c4b72611bd33f5babee069d"
if data['loginName'] != expected_login_name or data['password'] != expected_password:
return jsonify({
"Code": 401,
"Message": "用户名或密码错误",
"Data": None
}), 401
# 模拟生成AppID和SignToken
app_id = "e00412005f74144a8654d24f9d4b4e5"
sign_token = "79a5c0da-ebfd-4ce3-832d-36c807cc0398"
expire_time = (datetime.now().replace(microsecond=0) + timedelta(hours=24)).isoformat()
response_data = {
"Code": 200,
"Message": None,
"Data": {
"AppID": app_id,
"SignToken": sign_token,
"ExpireTime": expire_time,
"ZrJwt": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI3OQ" # 简化JWT
}
}
return jsonify(response_data), 200
except Exception as e:
return jsonify({
"Code": 500,
"Message": f"服务器内部错误: {str(e)}",
"Data": None
}), 500
@app.route('/api/ext/mould/last_artifact', methods=['GET'])
def get_mould_info():
"""
模拟获取模具管片信息接口
"""
try:
# 获取查询参数
mould_code = request.args.get('mouldCode')
if not mould_code:
return jsonify({
"Code": 400,
"Message": "缺少mouldCode参数",
"Data": None
}), 400
# 模拟AppID验证这里简化处理
app_id = request.headers.get('AppID')
if not app_id:
return jsonify({
"Code": 401,
"Message": "缺少AppID认证",
"Data": None
}), 401
# 模拟返回数据
response_data = {
"Code": 200,
"Message": None,
"Data": {
"ArtifactID": "QR1B12000151AD",
"ArtifactActionID": 346482967298117,
"ArtifactIDVice1": "Q00001AD",
"ProduceRingNumber": 1,
"MouldCode": mould_code,
"SkeletonID": "QR1B12000046A",
"RingTypeCode": "R22",
"SizeSpecification": "6900*1500",
"BuriedDepth": "中埋",
"BlockNumber": "B1",
"HoleRingMarking": "",
"GroutingPipeMarking": "",
"PolypropyleneFiberMarking": "",
"BetonVolume": 6455.0000,
"BetonTaskID": "20251020-01"
}
}
return jsonify(response_data), 200
except Exception as e:
return jsonify({
"Code": 500,
"Message": f"服务器内部错误: {str(e)}",
"Data": None
}), 500
@app.route('/api/ext/artifact/task', methods=['GET'])
def get_task_info():
"""
模拟获取任务单信息接口
"""
try:
# 获取查询参数
task_id = request.args.get('TaskId')
if not task_id:
return jsonify({
"Code": 400,
"Message": "缺少TaskId参数",
"Data": None
}), 400
# 模拟AppID验证
app_id = request.headers.get('AppID')
if not app_id:
return jsonify({
"Code": 401,
"Message": "缺少AppID认证",
"Data": None
}), 401
# 模拟返回数据
response_data = {
"Code": 200,
"Message": None,
"Data": {
"TaskID": task_id,
"TaskStatus": 4,
"TaskStatusText": "已制单",
"TaskCount": 600,
"AlreadyProduceCount": 100,
"Progress": "100 / 600",
"ProjectName": "测试新增工程测试",
"TaskPlanDateText": "2025-07-18",
"BetonGrade": "C50",
"MixID": "P20250717001",
"ProduceMixID": "HNT-2025-07-17-001",
"PlannedVolume": 1050.00,
"ProducedVolume": 0.00,
"HoleRingMarking": "咕发环",
"GroutingPipeMarking": "",
"PolypropyleneFiberMarking": "",
"TaskDate": "1900-01-01T00:00:00",
"TaskDateText": "1900-01-01",
"PlateCount": 0,
"SendStatus": 0,
"SendStatusText": "未下发",
"MixSendStatus": 0,
"MixSendStatusText": "未下发"
}
}
return jsonify(response_data), 200
except Exception as e:
return jsonify({
"Code": 500,
"Message": f"服务器内部错误: {str(e)}",
"Data": None
}), 500
@app.route('/api/ext/artifact/not_pour', methods=['GET'])
def get_not_pour_info():
"""
模拟获取已入模绑定未浇筑的管片信息接口
"""
try:
# 模拟AppID验证
app_id = request.headers.get('AppID')
if not app_id:
return jsonify({
"Code": 401,
"Message": "缺少AppID认证",
"Data": None
}), 401
# 模拟返回多个记录
response_data = {
"Code": 200,
"Message": None,
"Data": [
{
"ArtifactID": "QR1B12000151AD",
"ArtifactActionID": 346482967298117,
"ArtifactIDVice1": "Q00001AD",
"ProduceRingNumber": 1,
"MouldCode": "SHR2B1-9",
"SkeletonID": "QR1B12000046A",
"RingTypeCode": "R22",
"SizeSpecification": "6900*1500",
"BuriedDepth": "中埋",
"BlockNumber": "B1",
"HoleRingMarking": "",
"GroutingPipeMarking": "",
"PolypropyleneFiberMarking": "",
"BetonVolume": 2.0000,
"BetonTaskID": "20251020-01"
},
{
"ArtifactID": "QR1B32000153AD",
"ArtifactActionID": 346482967298119,
"ArtifactIDVice1": "Q00001AD",
"ProduceRingNumber": 1,
"MouldCode": "SHR2B3-9",
"SkeletonID": "QR1B2000048A",
"RingTypeCode": "R22",
"SizeSpecification": "6900*1500",
"BuriedDepth": "中埋",
"BlockNumber": "B2",
"HoleRingMarking": "",
"GroutingPipeMarking": "",
"PolypropyleneFiberMarking": "",
"BetonVolume": 2.0000,
"BetonTaskID": "20251020-01"
},
{
"ArtifactID": "QR1B12000151AD",
"ArtifactActionID": 346482967298120,
"ArtifactIDVice1": "Q00001AD",
"ProduceRingNumber": 1,
"MouldCode": "SHR2B1-9",
"SkeletonID": "QR1B12000046A",
"RingTypeCode": "R22",
"SizeSpecification": "6900*1500",
"BuriedDepth": "中埋",
"BlockNumber": "B3",
"HoleRingMarking": "",
"GroutingPipeMarking": "",
"PolypropyleneFiberMarking": "",
"BetonVolume": 2.0000,
"BetonTaskID": "20251020-01"
},
]
}
return jsonify(response_data), 200
except Exception as e:
return jsonify({
"Code": 500,
"Message": f"服务器内部错误: {str(e)}",
"Data": None
}), 500
if __name__ == '__main__':
app.run(host='127.0.0.1', port=5000, debug=True)