|
@@ -225,6 +225,7 @@ def create_report_and_table(report: ReportCreate, db: Session = Depends(get_db))
|
|
|
|
|
|
|
|
|
class ReportQuery(BaseModel):
|
|
|
+ creator_id: str # 创建者ID,必须提供
|
|
|
table_name: Optional[str] = None
|
|
|
status: Optional[List[int]] = None
|
|
|
start_time: Optional[datetime] = None
|
|
@@ -237,13 +238,17 @@ class ReportQuery(BaseModel):
|
|
|
@router.get("/select")
|
|
|
async def select_report(
|
|
|
db: Session = Depends(get_db),
|
|
|
- query: ReportQuery = Body(...)
|
|
|
+ query: ReportQuery = Depends()
|
|
|
):
|
|
|
- data_query = db.query(ReportManagement)
|
|
|
+ # 检查 creator_id 是否提供
|
|
|
+ if not query.creator_id:
|
|
|
+ raise HTTPException(status_code=400, detail="创建者ID是必填项")
|
|
|
+
|
|
|
+ data_query = db.query(ReportManagement).filter(ReportManagement.creator_id == query.creator_id)
|
|
|
|
|
|
# 过滤条件
|
|
|
if query.table_name:
|
|
|
- data_query = data_query.filter(ReportManagement.table_name == query.table_name)
|
|
|
+ data_query = data_query.filter(ReportManagement.table_name.ilike(f"%{query.table_name}%"))
|
|
|
|
|
|
if query.start_time and query.end_time:
|
|
|
data_query = data_query.filter(ReportManagement.start_time >= query.start_time,
|
|
@@ -278,7 +283,7 @@ async def select_report(
|
|
|
"creator_name": item.creator_name,
|
|
|
"creator_id": item.creator_id,
|
|
|
"created_at": item.created_at,
|
|
|
- "created_phone": item.creator_phone,
|
|
|
+ "creator_phone": item.creator_phone,
|
|
|
"updated_at": item.updated_at,
|
|
|
"num_reporters": item.num_reporters
|
|
|
}
|
|
@@ -313,6 +318,7 @@ class ReportUpdate(BaseModel):
|
|
|
period_type: str = None
|
|
|
end_time: str = None
|
|
|
comments: dict = None # 字典,键为字段名,值为新的备注
|
|
|
+ creator_id: str = None
|
|
|
|
|
|
#修改
|
|
|
@router.put("/report/{report_id}/")
|
|
@@ -326,6 +332,10 @@ async def update_report(
|
|
|
if not report:
|
|
|
raise HTTPException(status_code=404, detail="Report not found")
|
|
|
|
|
|
+ # 验证请求者ID
|
|
|
+ if report.creator_id != update_data.creator_id:
|
|
|
+ raise HTTPException(status_code=403, detail="没有权限更新此报告")
|
|
|
+
|
|
|
# 更新字段
|
|
|
if update_data.table_name:
|
|
|
report.table_name = update_data.table_name
|
|
@@ -353,7 +363,10 @@ async def update_report(
|
|
|
db.commit()
|
|
|
db.refresh(report)
|
|
|
|
|
|
- return report
|
|
|
+ return {
|
|
|
+ "code":200,
|
|
|
+ "msg":"操作成功"
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
@@ -402,7 +415,11 @@ async def get_user_tasks(
|
|
|
}
|
|
|
result_items.append(result_item)
|
|
|
|
|
|
- return {"data": result_items}
|
|
|
+ return {
|
|
|
+ "code":200,
|
|
|
+ "msg":"查询成功",
|
|
|
+ "data": result_items
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
@@ -450,6 +467,8 @@ async def get_report_fields(
|
|
|
|
|
|
# 返回用户ID、填报ID和字段信息
|
|
|
return {
|
|
|
+ "code":200,
|
|
|
+ "msg":"查询成功",
|
|
|
"user_id": user_id,
|
|
|
"report_id": report_id,
|
|
|
"fields": result_fields
|
|
@@ -514,7 +533,10 @@ async def submit_data(
|
|
|
# 提交事务
|
|
|
db.commit()
|
|
|
|
|
|
- return {"message": "数据提交成功"}
|
|
|
+ return {
|
|
|
+ "code":200,
|
|
|
+ "msg": "数据提交成功"
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
@@ -525,7 +547,7 @@ class SubmissionQuery(BaseModel):
|
|
|
report_id: str # 填报ID,必须是字符串
|
|
|
|
|
|
|
|
|
-@router.post("/submission-status")
|
|
|
+@router.post("/submission_status")
|
|
|
async def get_submission_status(
|
|
|
db: Session = Depends(get_db),
|
|
|
query: SubmissionQuery = Body(...)
|
|
@@ -612,7 +634,7 @@ def has_matching_column_comments(
|
|
|
return bool(get_columns_with_comment_like(inspector, table_name, comment_like))
|
|
|
|
|
|
|
|
|
-@router.post("/reports-by-creator/")
|
|
|
+@router.post("/reports_by_creator/")
|
|
|
async def get_reports_by_creator(
|
|
|
creator_id: str, # 精确匹配的必选参数
|
|
|
field_comment: Optional[str] = Query(None, description="Optional comment of the field to match"),
|
|
@@ -652,7 +674,7 @@ async def get_reports_by_creator(
|
|
|
return {"data": results}
|
|
|
|
|
|
|
|
|
-@router.put("/update-collection-status/")
|
|
|
+@router.put("/update_collection_status/")
|
|
|
async def update_collection_status(
|
|
|
creator_id: str,
|
|
|
report_id: str,
|
|
@@ -679,7 +701,11 @@ async def update_collection_status(
|
|
|
db.commit()
|
|
|
db.refresh(report)
|
|
|
|
|
|
- return {"message": "Collection status updated successfully", "new_status": new_status}
|
|
|
+ return {
|
|
|
+ "code":200,
|
|
|
+ "msg": "更新成功",
|
|
|
+ "new_status": new_status
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
@@ -688,7 +714,7 @@ class ReportQuery(BaseModel):
|
|
|
creator_id: str # 创建人ID,必须是字符串
|
|
|
report_id: str # 填报ID,必须是字符串
|
|
|
|
|
|
-@router.get("/get-records-by-creator-and-report/")
|
|
|
+@router.get("/dataArchiveDetails/")
|
|
|
async def get_records_by_creator_and_report(
|
|
|
query: ReportQuery = Depends(),
|
|
|
db: Session = Depends(get_db)
|
|
@@ -709,7 +735,7 @@ async def get_records_by_creator_and_report(
|
|
|
|
|
|
# 查询工单表所有信息,并关联用户表匹配到用户名字
|
|
|
query_sql = text(f"""
|
|
|
- SELECT w.*, u.nick_name AS user_name
|
|
|
+ SELECT w.*, u.user_name
|
|
|
FROM {report.data_table_name} w
|
|
|
LEFT JOIN sys_user u ON w.user_id = u.user_id
|
|
|
""")
|
|
@@ -717,7 +743,7 @@ async def get_records_by_creator_and_report(
|
|
|
rows = result.fetchall()
|
|
|
|
|
|
# 使用SQLAlchemy的inspect功能来获取表的列信息
|
|
|
- inspector = Inspector.from_engine(db.bind)
|
|
|
+ inspector = inspect(db.bind)
|
|
|
columns = inspector.get_columns(report.data_table_name)
|
|
|
|
|
|
# 提取列名和列注释
|
|
@@ -730,11 +756,13 @@ async def get_records_by_creator_and_report(
|
|
|
|
|
|
# 添加字段名和字段注释作为第一行
|
|
|
first_row = {column: column_comments.get(column, '') for column in column_names if column not in excluded_columns}
|
|
|
+ first_row['user_name'] = column_comments.get('user_name', '用户昵称') # 添加用户昵称的注释
|
|
|
results.append(first_row)
|
|
|
|
|
|
for row in rows:
|
|
|
# 过滤掉不需要的列,并添加到结果中
|
|
|
filtered_row = {column: row[idx] for idx, column in enumerate(column_names) if column not in excluded_columns}
|
|
|
+ filtered_row['user_name'] = row[-1] # 添加用户昵称
|
|
|
results.append(filtered_row)
|
|
|
|
|
|
# 获取报告的开始和结束时间,并格式化为字符串
|