提交
This commit is contained in:
55
app/blueprints/bag_data/routes.py
Normal file
55
app/blueprints/bag_data/routes.py
Normal file
@@ -0,0 +1,55 @@
|
||||
from collections import defaultdict
|
||||
from datetime import datetime
|
||||
from flask import Blueprint, current_app, request, jsonify
|
||||
from flask_jwt_extended import create_access_token, get_jwt, get_jwt_identity, jwt_required
|
||||
from sqlalchemy import and_, asc, desc, exists, func, or_
|
||||
from app.models import BagFile, Fst, Role, User, UserRole
|
||||
from app.utils.fst_tree import build_tree,build_sub_tree
|
||||
from app import db
|
||||
from app.utils.log_record import log_operation
|
||||
from sqlalchemy.orm import aliased
|
||||
|
||||
# 1.创建蓝图实例,指定名称和导入名称
|
||||
data_bp = Blueprint('bag', __name__)
|
||||
|
||||
@data_bp.route('/fstlist',methods=['GET'])
|
||||
@jwt_required()
|
||||
def get_fstlist():
|
||||
res=Fst.query.with_entities(Fst.id,Fst.name,Fst.parent_id).all()
|
||||
response=build_tree(res)
|
||||
return jsonify(response), 200
|
||||
|
||||
|
||||
|
||||
@data_bp.route('/fstlevel1', methods=['GET'])
|
||||
def get_level1_fst():
|
||||
# 查询 level=1 的记录,仅返回 id, name, level 字段
|
||||
results = Fst.query.with_entities(
|
||||
Fst.id,
|
||||
Fst.name,
|
||||
Fst.level
|
||||
).filter_by(level=1).all()
|
||||
|
||||
# 转换为字典列表(方便 JSON 序列化)
|
||||
data = [{
|
||||
"id": r.id,
|
||||
"name": r.name,
|
||||
"level": r.level
|
||||
} for r in results]
|
||||
|
||||
return jsonify(data),200
|
||||
|
||||
# 跨表查询所有的bag
|
||||
|
||||
@data_bp.route('/getnode', methods=['GET'])
|
||||
@jwt_required()
|
||||
def query_sub_node():
|
||||
'''
|
||||
根据一级标签查询对应的所有子标签
|
||||
'''
|
||||
tagid=request.args.get('tagid')
|
||||
res=Fst.query.with_entities(Fst.id,Fst.name,Fst.parent_id).all()
|
||||
response=build_sub_tree(res,tagid)
|
||||
return jsonify(response), 200
|
||||
|
||||
|
||||
Reference in New Issue
Block a user