|
@@ -484,9 +484,133 @@ async def get_children_task_records_list(
|
|
|
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
|
|
|
|
|
+@router.get('/children/task/result/{children_task_id}')
|
|
|
+async def get_children_task_result(
|
|
|
+ children_task_id: str ,
|
|
|
+ db: Session = Depends(get_db),
|
|
|
+ page: int = Query(1, gt=0, description='页码'),
|
|
|
+ pageSize: int = Query(10, gt=0, description='每页条目数量'),
|
|
|
+ user_id = Depends(valid_access_token)
|
|
|
+):
|
|
|
+ try:
|
|
|
+ # 构建查询
|
|
|
+ query = db.query(RiskManagementInspectionTaskChildrenTaskResult)
|
|
|
+ query = query.filter(RiskManagementInspectionTaskChildrenTaskResult.del_flag != '2')
|
|
|
+ # 应用查询条件
|
|
|
+ query = query.filter(RiskManagementInspectionTaskChildrenTaskResult.children_task_id == children_task_id)
|
|
|
+ # 计算总条目数
|
|
|
+ total_items = query.count()
|
|
|
+
|
|
|
+ # 排序
|
|
|
+
|
|
|
+ query = query.order_by(RiskManagementInspectionTaskChildrenTaskResult.create_time.desc())
|
|
|
+ # 执行分页查询
|
|
|
+ InspectionTasks = query.offset((page - 1) * pageSize).limit(pageSize).all()
|
|
|
|
|
|
|
|
|
|
|
|
+ InspectionTasks_list = []
|
|
|
+ for task in InspectionTasks:
|
|
|
+ area_code = task.area_code
|
|
|
+ area = area_code_get_area_info(db, area_code)
|
|
|
+ area = area_code_get_ancestors_names(db, area)
|
|
|
+ task_info = {
|
|
|
+ "id": task.id,
|
|
|
+ # "children_task_id": task.children_task_id,
|
|
|
+ "type":inspection_task_children_task_id_get_inspection_task_children_task_info(db,task.children_task_id).type,
|
|
|
+ "inspection_point_name": task.inspection_point_name,
|
|
|
+ # "area": area,
|
|
|
+ # "create_time": task.create_time.strftime('%Y-%m-%d'),
|
|
|
+ # "nick_name": task.nick_name,
|
|
|
+ "inspection_result": task.inspection_result,
|
|
|
+ "remark": task.remark,
|
|
|
+ "fileList": get_file_query_fun(db=db, from_scenario='RiskManagementInspectionTaskChildrenTaskResult',
|
|
|
+ foreign_key=task.id)
|
|
|
+ }
|
|
|
+ InspectionTasks_list.append(task_info)
|
|
|
+ # 返回结果
|
|
|
+ return {
|
|
|
+ "code": 200,
|
|
|
+ "msg": "成功",
|
|
|
+ "data": InspectionTasks_list,
|
|
|
+ "total": total_items,
|
|
|
+ "page": page,
|
|
|
+ "pageSize": pageSize,
|
|
|
+ "totalPages": (total_items + pageSize - 1) // pageSize
|
|
|
+ }
|
|
|
+ except Exception as e:
|
|
|
+ # 处理异常
|
|
|
+ traceback.print_exc()
|
|
|
+ raise HTTPException(status_code=500, detail=str(e))
|
|
|
+
|
|
|
+@router.post('/children/task/result/create')
|
|
|
+async def create_inspection_task(
|
|
|
+ db: Session = Depends(get_db),
|
|
|
+ body = Depends(remove_xss_json),
|
|
|
+ user_id = Depends(valid_access_token)
|
|
|
+):
|
|
|
+ try:
|
|
|
+ children_task_id = body['children_task_id']
|
|
|
+ result = body['result']
|
|
|
+ area_code = body['area_code']
|
|
|
+ area =area_code_get_ancestors_names(db, area_code_get_area_info(db, area_code))
|
|
|
+ # task_time = body['task_time']
|
|
|
+ # 创建新的
|
|
|
+ new_task_log = RiskManagementInspectionTaskChildrenTaskLog(
|
|
|
+ id=new_guid(),
|
|
|
+ children_task_id=children_task_id,
|
|
|
+ area_code = area_code,
|
|
|
+ area = area,
|
|
|
+ task_status = '1',
|
|
|
+ user_id = user_id,
|
|
|
+ nick_name = user_id_get_user_info(db,user_id).nick_name,
|
|
|
+ create_by = user_id
|
|
|
+ )
|
|
|
+ for info in result:
|
|
|
+ new_file_list = info['fileList']
|
|
|
+ inspection_point_name= info['inspection_point_name']
|
|
|
+ inspection_result = info['inspection_result']
|
|
|
+ remark = info['remark']
|
|
|
+ new_task_result = RiskManagementInspectionTaskChildrenTaskResult(
|
|
|
+ id=new_guid(),
|
|
|
+ children_task_id=children_task_id,
|
|
|
+ inspection_point_name=inspection_point_name,
|
|
|
+ area_code=area_code,
|
|
|
+ inspection_result=inspection_result,
|
|
|
+ remark = remark,
|
|
|
+ user_id = user_id,
|
|
|
+ nick_name = user_id_get_user_info(db,user_id).nick_name,
|
|
|
+ create_by = user_id
|
|
|
+ )
|
|
|
+ db.add(new_task_result)
|
|
|
+ for file in new_file_list:
|
|
|
+ file_name = file['file_name']
|
|
|
+ file_name_desc = file['file_name_desc']
|
|
|
+ status = file['status']
|
|
|
+ new_file = RiskManagementFile(
|
|
|
+ file_id=new_guid(),
|
|
|
+ foreign_key=new_task_result.id,
|
|
|
+ from_scenario='RiskManagementInspectionTaskChildrenTaskResult',
|
|
|
+ file_name=file_name,
|
|
|
+ file_name_desc=file_name_desc,
|
|
|
+ status=status
|
|
|
+ )
|
|
|
+ db.add(new_file)
|
|
|
+ # 添加到数据库会话并提交
|
|
|
+ db.add(new_task_log)
|
|
|
+
|
|
|
+ db.commit()
|
|
|
+ # 返回创建成功的响应
|
|
|
+ return {
|
|
|
+ "code": 200,
|
|
|
+ "msg": "成功",
|
|
|
+ "data": None
|
|
|
+ }
|
|
|
+ except Exception as e:
|
|
|
+ # 处理异常
|
|
|
+ traceback.print_exc()
|
|
|
+ raise HTTPException(status_code=500, detail=str(e))
|
|
|
+
|
|
|
|
|
|
####中屏子任务
|
|
|
@router.get('/children/task/{task_id}/list')
|