|
@@ -13,95 +13,14 @@ from database import get_db
|
|
|
from typing import List
|
|
|
from models import *
|
|
|
from utils import *
|
|
|
+from utils.ry_system_util import *
|
|
|
+from utils.riskManagement_uitl import *
|
|
|
import json
|
|
|
import traceback
|
|
|
|
|
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
-def get_area_num(db,rang):
|
|
|
- query = db.query(GovdataArea)
|
|
|
- if rang=='0':
|
|
|
- return 1
|
|
|
- elif rang=='1':
|
|
|
- query = query.filter(and_(GovdataArea.area_code.like('%000000'),GovdataArea.area_code.notlike('%00000000')))
|
|
|
- return query.count()
|
|
|
- elif rang=='2':
|
|
|
- query = query.filter(and_(GovdataArea.area_code.like('%000'),GovdataArea.area_code.notlike('%000000')))
|
|
|
- return query.count()
|
|
|
- elif rang=='3':
|
|
|
- query = query.filter(GovdataArea.area_code.notlike('%000'))
|
|
|
- return query.count()
|
|
|
- else:
|
|
|
- return 0
|
|
|
-def get_task_date_list(cycle,start_date,end_date,corn_query):
|
|
|
- # 生成日期列表
|
|
|
- date_list = []
|
|
|
- if cycle=='4': #仅一次,返回当天
|
|
|
- date_list.append(datetime.today())
|
|
|
- return date_list
|
|
|
- elif cycle=='3': #每天
|
|
|
- current_date = start_date
|
|
|
- while current_date <= end_date:
|
|
|
- # 将日期添加到列表中
|
|
|
- date_list.append(current_date)
|
|
|
- # 增加一天
|
|
|
- current_date += timedelta(days=1)
|
|
|
- return date_list
|
|
|
- elif cycle=='2': #每周
|
|
|
- days_ahead = (7+int(corn_query) - start_date.weekday()) % 7
|
|
|
- current_date = start_date + timedelta(days=days_ahead)
|
|
|
- while current_date <= end_date:
|
|
|
- # 将日期添加到列表中
|
|
|
- date_list.append(current_date)
|
|
|
- # 增加七天
|
|
|
- current_date += timedelta(days=7)
|
|
|
- return date_list
|
|
|
- elif cycle=='1': #每月
|
|
|
- days_ahead = datetime.strptime(start_date.strftime("%Y-%m-")+corn_query, "%Y-%m-%d")
|
|
|
- if days_ahead>start_date:
|
|
|
- current_date = days_ahead
|
|
|
- else:
|
|
|
- current_date = days_ahead+relativedelta(months=1)
|
|
|
-
|
|
|
- while current_date <= end_date:
|
|
|
- # 将日期添加到列表中
|
|
|
- date_list.append(current_date)
|
|
|
- # 增加七天
|
|
|
- current_date += relativedelta(months=1)
|
|
|
- return date_list
|
|
|
- elif cycle=='0': #每月
|
|
|
- d,m = corn_query.split()
|
|
|
- days_ahead = datetime.strptime(start_date.strftime("%Y-")+m+'-'+d, "%Y-%m-%d")
|
|
|
- if days_ahead>start_date:
|
|
|
- current_date = days_ahead
|
|
|
- else:
|
|
|
- current_date = days_ahead+relativedelta(years=1)
|
|
|
-
|
|
|
- while current_date <= end_date:
|
|
|
- # 将日期添加到列表中
|
|
|
- date_list.append(current_date)
|
|
|
- # 增加七天
|
|
|
- current_date += relativedelta(years=1)
|
|
|
- return date_list
|
|
|
-def create_children_task(db,task_info,corn_query):
|
|
|
- cycle = task_info.inspection_cycle
|
|
|
- task_range = task_info.inspection_range
|
|
|
- for t in get_task_date_list(cycle,task_info.start_time,task_info.end_time,corn_query):
|
|
|
- new_children_task = RiskManagementInspectionTaskChildrenTask(
|
|
|
- id = new_guid(),
|
|
|
- task_id= task_info.id,
|
|
|
- task_number= task_info.task_number,
|
|
|
- type = task_info.inspection_business,
|
|
|
- tsak_time = t,
|
|
|
- cycle=cycle,
|
|
|
- task_range = task_range,
|
|
|
- task_num=get_area_num(db,task_range),
|
|
|
- create_by=task_info.create_by
|
|
|
- )
|
|
|
- db.add(new_children_task)
|
|
|
- db.commit()
|
|
|
-
|
|
|
@router.get('/list')
|
|
|
async def get_inspection_task_list(
|
|
|
business: str = Query(None, description='巡查业务'),
|
|
@@ -482,9 +401,10 @@ async def get_inspection_task_list(
|
|
|
|
|
|
|
|
|
|
|
|
-@router.get('/children/task/log/{children_task_id}/list')
|
|
|
+@router.get('/children/task/log/{children_task_id}/{status}/list')
|
|
|
async def get_inspection_task_list(
|
|
|
children_task_id: str ,
|
|
|
+ status:str,
|
|
|
area_code: str = Query(None, description='区划编码'),
|
|
|
page: int = Query(1, gt=0, description='页码'),
|
|
|
pageSize: int = Query(10, gt=0, description='每页条目数量'),
|
|
@@ -493,36 +413,122 @@ async def get_inspection_task_list(
|
|
|
):
|
|
|
try:
|
|
|
# 构建查询
|
|
|
- query = db.query(RiskManagementInspectionTaskChildrenTaskLog)
|
|
|
- query = query.filter(RiskManagementInspectionTaskChildrenTaskLog.del_flag != '2')
|
|
|
- # 应用查询条件
|
|
|
+ total_items= 0
|
|
|
+ InspectionTasks_list = []
|
|
|
+ if status=='completed':
|
|
|
+ query = db.query(RiskManagementInspectionTaskChildrenTaskLog)
|
|
|
+ query = query.filter(RiskManagementInspectionTaskChildrenTaskLog.del_flag != '2')
|
|
|
+ # 应用查询条件
|
|
|
+
|
|
|
+ query = query.filter(RiskManagementInspectionTaskChildrenTaskLog.children_task_id == children_task_id)
|
|
|
+
|
|
|
+ if area_code:
|
|
|
+ query = query.filter(RiskManagementInspectionTaskChildrenTaskLog.area_code == area_code)
|
|
|
+ # 计算总条目数
|
|
|
+ total_items = query.count()
|
|
|
+
|
|
|
+ # 排序
|
|
|
+ query = query.order_by(RiskManagementInspectionTaskChildrenTaskLog.create_time.desc())
|
|
|
+ # 执行分页查询
|
|
|
+ InspectionTasks = query.offset((page - 1) * pageSize).limit(pageSize).all()
|
|
|
+
|
|
|
+ # 将查询结果转换为列表形式的字典
|
|
|
+ for task in InspectionTasks:
|
|
|
+ task_info = {
|
|
|
+ "id": task.id,
|
|
|
+ "children_task_id":children_task_id,
|
|
|
+ "area_code": task.area_code,
|
|
|
+ "area": task.area,
|
|
|
+ "task_status": task.task_status,
|
|
|
+ "user_id": task.user_id,
|
|
|
+ "nick_name": task.nick_name,
|
|
|
+ "create_time": task.create_time.strftime('%Y-%m-%d')
|
|
|
+ }
|
|
|
+ InspectionTasks_list.append(task_info)
|
|
|
+ # 返回结果
|
|
|
+ elif status == 'incomplete':
|
|
|
+ children_task = inspection_task_children_task_id_get_inspection_task_children_task_info(db,children_task_id)
|
|
|
+ task = inspection_task_id_get_inspection_task_info(db,children_task.task_id)
|
|
|
+ complete_area_code_list =[i.area_code for i in inspection_task_children_task_id_get_inspection_task_children_task_log_info(db,children_task_id)]
|
|
|
+ area_code_list = get_area_code_exclude_list(db,task.inspection_range,complete_area_code_list)
|
|
|
+ if area_code and area_code in area_code_list:
|
|
|
+ area_code_list = [area_code_list]
|
|
|
+ for area_code in area_code_list:
|
|
|
+ task_info = {
|
|
|
+ "id": new_guid(),
|
|
|
+ "children_task_id": children_task_id,
|
|
|
+ "area_code": area_code,
|
|
|
+ "area": area_code_get_ancestors_names(db,area_code_get_area_info(db,area_code)),
|
|
|
+ "task_status": '0',
|
|
|
+ "user_id": '',
|
|
|
+ "nick_name": '',
|
|
|
+ "create_time": children_task.tsak_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))
|
|
|
|
|
|
- query = query.filter(RiskManagementInspectionTaskChildrenTaskLog.children_task_id == children_task_id)
|
|
|
|
|
|
+@router.get('/children/task/result/{children_task_id}/list')
|
|
|
+async def get_inspection_task_list(
|
|
|
+ children_task_id: str ,
|
|
|
+ area_code: str = Query(None, description='区划编码'),
|
|
|
+ inspection_result: str = Query(None, description='巡查结果'),
|
|
|
+ nick_name: 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:
|
|
|
+ # 构建查询
|
|
|
+ query = db.query(RiskManagementInspectionTaskChildrenTaskResult)
|
|
|
+ query = query.filter(RiskManagementInspectionTaskChildrenTaskResult.del_flag != '2')
|
|
|
+ query = query.filter(RiskManagementInspectionTaskChildrenTaskResult.children_task_id == children_task_id)
|
|
|
+ # 应用查询条件
|
|
|
if area_code:
|
|
|
- query = query.filter(RiskManagementInspectionTaskChildrenTaskLog.area_code == area_code)
|
|
|
+ query = query.filter(RiskManagementInspectionTaskChildrenTaskResult.area_code == area_code)
|
|
|
+ if inspection_result:
|
|
|
+ query = query.filter(RiskManagementInspectionTaskChildrenTaskResult.inspection_result == inspection_result)
|
|
|
+ if nick_name:
|
|
|
+ query = query.filter(RiskManagementInspectionTaskChildrenTaskResult.nick_name.like(f'%{nick_name}%') )
|
|
|
+
|
|
|
# 计算总条目数
|
|
|
total_items = query.count()
|
|
|
|
|
|
# 排序
|
|
|
|
|
|
- query = query.order_by(RiskManagementInspectionTaskChildrenTaskLog.create_time.desc())
|
|
|
+ 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,
|
|
|
- "area_code": task.area_code,
|
|
|
- "area": task.area,
|
|
|
- "task_status": task.task_status,
|
|
|
- "user_id": task.user_id,
|
|
|
+ "children_task_id": task.children_task_id,
|
|
|
+ "inspection_point_name":task.inspection_point_name,
|
|
|
+ "area": area,
|
|
|
+ "create_time": task.create_time.strftime('%Y-%m-%d'),
|
|
|
"nick_name": task.nick_name,
|
|
|
- "create_time": task.create_time.strftime('%Y-%m-%d')
|
|
|
+ "inspection_result": task.inspection_result,
|
|
|
+ "fileList": get_file_query_fun(db=db,from_scenario='RiskManagementInspectionTaskChildrenTaskResult', foreign_key=task.id),
|
|
|
+ "remark":task.remark
|
|
|
}
|
|
|
InspectionTasks_list.append(task_info)
|
|
|
# 返回结果
|