|
@@ -335,9 +335,160 @@ async def delete_inspection_task(
|
|
|
e = detail
|
|
|
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
|
|
+####小屏子任务查询
|
|
|
|
|
|
+@router.get('/children/task/list')
|
|
|
+async def get_inspection_task_list(
|
|
|
+ type: str =Query(None, description='类型'),
|
|
|
+ page: int = Query(1, gt=0, description='页码'),
|
|
|
+ pageSize: int = Query(10, gt=0, description='每页条目数量'),
|
|
|
+ db: Session = Depends(get_db),
|
|
|
+ user_id = Depends(valid_access_token)
|
|
|
+):
|
|
|
+ try:
|
|
|
+ # 构建查询
|
|
|
+ task_range = user_id_get_task_range(db,user_id)
|
|
|
+ Task_list = db.query(RiskManagementInspectionTask).filter(RiskManagementInspectionTask.del_flag!='2').filter(RiskManagementInspectionTask.inspection_range.in_(task_range)).filter(RiskManagementInspectionTask.task_status!='3').all()
|
|
|
+ task_ids = [i.id for i in Task_list]
|
|
|
+ user_area_code_list = db.query(RiskManagementInspectionUser).filter(RiskManagementInspectionUser.del_flag!='2').filter(RiskManagementInspectionUser.user_id==user_id).all()
|
|
|
+ user_area_codes = [i.area_code for i in user_area_code_list]
|
|
|
+ query = db.query(RiskManagementInspectionTaskChildrenTask)
|
|
|
+ query = query.filter(RiskManagementInspectionTaskChildrenTask.del_flag != '2')
|
|
|
+ # 应用查询条件
|
|
|
+
|
|
|
+ query = query.filter(RiskManagementInspectionTaskChildrenTask.tsak_time <=datetime.now())
|
|
|
+ query = query.filter(RiskManagementInspectionTaskChildrenTask.task_range.in_(task_range))
|
|
|
+ query = query.filter(RiskManagementInspectionTaskChildrenTask.task_id.in_(task_ids))
|
|
|
+ # 计算总条目数
|
|
|
+ if type:
|
|
|
+ query = query.filter(RiskManagementInspectionTaskChildrenTask.type==type)
|
|
|
+ total_items = query.count()
|
|
|
+
|
|
|
+ # 排序
|
|
|
+
|
|
|
+ query = query.order_by(RiskManagementInspectionTaskChildrenTask.tsak_time.asc())
|
|
|
+ # 执行分页查询
|
|
|
+ InspectionTasks = query.offset((page - 1) * pageSize).limit(pageSize).all()
|
|
|
|
|
|
+ # 将查询结果转换为列表形式的字典
|
|
|
+ InspectionTasks_list = []
|
|
|
+ for task in InspectionTasks:
|
|
|
+ # 判断这个任务该user_id完成了没
|
|
|
+ tasklog = db.query(RiskManagementInspectionTaskChildrenTaskLog).\
|
|
|
+ filter(RiskManagementInspectionTaskChildrenTaskLog.del_flag!='2').\
|
|
|
+ filter(RiskManagementInspectionTaskChildrenTaskLog.children_task_id==task.id).\
|
|
|
+ filter(RiskManagementInspectionTaskChildrenTaskLog.area_code.in_(user_area_codes)).all()
|
|
|
+ task_area_code_list = [i.area_code for i in tasklog]
|
|
|
+ query = db.query(RiskManagementInspectionUser).filter(RiskManagementInspectionUser.user_id==user_id)
|
|
|
+ if task.task_range == '0':
|
|
|
+ user_range_area_codes= ['440900000000']
|
|
|
+ elif task.task_range == '1':
|
|
|
+ query = query.filter(
|
|
|
+ and_(RiskManagementInspectionUser.area_code.like('%000000'), RiskManagementInspectionUser.area_code.notlike('%00000000')))
|
|
|
+ user_range_area_codes= [i.area_code for i in query.all()]
|
|
|
+ elif task.task_range == '2':
|
|
|
+ query = query.filter(and_(RiskManagementInspectionUser.area_code.like('%000'), RiskManagementInspectionUser.area_code.notlike('%000000')))
|
|
|
+ user_range_area_codes= [i.area_code for i in query.all()]
|
|
|
+ elif task.task_range == '3':
|
|
|
+ query = query.filter(RiskManagementInspectionUser.area_code.notlike('%000'))
|
|
|
+ user_range_area_codes= [i.area_code for i in query.all()]
|
|
|
+ else:
|
|
|
+ user_range_area_codes= []
|
|
|
|
|
|
+ for area_code in user_range_area_codes:
|
|
|
+ task_info = {
|
|
|
+ "id": task.id,
|
|
|
+ "business": task.type,
|
|
|
+ "cycle": task.cycle,
|
|
|
+ "area_code":area_code,
|
|
|
+ "area": area_code_get_ancestors_names(db,area_code_get_area_info(db,area_code)),
|
|
|
+ "task_time": task.tsak_time.strftime('%Y-%m-%d'),
|
|
|
+ "create_time": task.create_time.strftime('%Y-%m-%d')
|
|
|
+ }
|
|
|
+ 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.get('/children/task/records')
|
|
|
+async def get_children_task_records_list(
|
|
|
+ type: str =Query(None, description='类型'),
|
|
|
+ page: int = Query(1, gt=0, description='页码'),
|
|
|
+ pageSize: int = Query(10, gt=0, description='每页条目数量'),
|
|
|
+ db: Session = Depends(get_db),
|
|
|
+ user_id = Depends(valid_access_token)
|
|
|
+):
|
|
|
+ try:
|
|
|
+
|
|
|
+ # 获取子任务id
|
|
|
+ query = db.query(RiskManagementInspectionTaskChildrenTask)
|
|
|
+ query = query.filter(RiskManagementInspectionTaskChildrenTask.del_flag != '2')
|
|
|
+
|
|
|
+ if type:
|
|
|
+ query = query.filter(RiskManagementInspectionTaskChildrenTask.type==type)
|
|
|
+ children_ids = [i.id for i in query.all()]
|
|
|
+ print(children_ids)
|
|
|
+ # 构建查询
|
|
|
+ query = db.query(RiskManagementInspectionTaskChildrenTaskLog)
|
|
|
+ query = query.filter(RiskManagementInspectionTaskChildrenTaskLog.del_flag != '2')
|
|
|
+
|
|
|
+ query = query.filter(RiskManagementInspectionTaskChildrenTaskLog.user_id == user_id)
|
|
|
+ query = query.filter(RiskManagementInspectionTaskChildrenTaskLog.children_task_id.in_(children_ids))
|
|
|
+ total_items = query.count()
|
|
|
+
|
|
|
+ # 排序
|
|
|
+
|
|
|
+ query = query.order_by(RiskManagementInspectionTaskChildrenTaskLog.create_time.desc())
|
|
|
+ # 执行分页查询
|
|
|
+ InspectionTasks = query.offset((page - 1) * pageSize).limit(pageSize).all()
|
|
|
+
|
|
|
+ # 将查询结果转换为列表形式的字典
|
|
|
+ InspectionTasks_list = []
|
|
|
+ for task in InspectionTasks:
|
|
|
+ children_task = inspection_task_children_task_id_get_inspection_task_children_task_info(db,task.children_task_id)
|
|
|
+ task_info = {
|
|
|
+ "id": task.id,
|
|
|
+ "business": children_task.type,
|
|
|
+ "cycle": children_task.cycle,
|
|
|
+ "area_code": task.area_code,
|
|
|
+ "area": area_code_get_ancestors_names(db, area_code_get_area_info(db, task.area_code)),
|
|
|
+ "task_time": children_task.tsak_time.strftime('%Y-%m-%d'),
|
|
|
+ "create_time": task.create_time.strftime('%Y-%m-%d %H:%M')
|
|
|
+ }
|
|
|
+ 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.get('/children/task/{task_id}/list')
|
|
|
async def get_inspection_task_list(
|
|
|
task_id: str ,
|
|
@@ -546,4 +697,5 @@ async def get_inspection_task_list(
|
|
|
except Exception as e:
|
|
|
# 处理异常
|
|
|
traceback.print_exc()
|
|
|
- raise HTTPException(status_code=500, detail=str(e))
|
|
|
+ raise HTTPException(status_code=500, detail=str(e))
|
|
|
+
|