|
@@ -14,12 +14,16 @@ from models import *
|
|
|
from utils import *
|
|
|
import json
|
|
|
import traceback
|
|
|
-
|
|
|
+from . import user
|
|
|
+from . import task
|
|
|
+from routers.api.riskManagement import risk_router
|
|
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
-####巡查人员####
|
|
|
-
|
|
|
+router.include_router(user.router, prefix="/inspection/user", tags=["巡查人员"])
|
|
|
+router.include_router(task.router, prefix="/inspection/task", tags=["巡查任务"])
|
|
|
+router.include_router(risk_router.router, prefix="/risk", tags=["风险防控"])
|
|
|
+####巡查人员--用户查询####
|
|
|
|
|
|
@router.get('/system/user/list')
|
|
|
async def userlist( userId: int = Query(None ,description='用户id'),
|
|
@@ -94,278 +98,6 @@ async def userlist( userId: int = Query(None ,description='用户id'),
|
|
|
traceback.print_exc()
|
|
|
raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
|
|
|
|
|
|
-@router.get('/inspection/user/list')
|
|
|
-async def get_inspection_user_list(
|
|
|
- nickName: str = Query(None, description='姓名'),
|
|
|
- deptId :str = Query(None, description='部门id'),
|
|
|
- page: int = Query(1, gt=0, description='页码'),
|
|
|
- pageSize: int = Query(5, gt=0, description='每页条目数量'),
|
|
|
- db: Session = Depends(get_db),
|
|
|
- user_id = Depends(valid_access_token)
|
|
|
-):
|
|
|
- try:
|
|
|
- # 构建查询
|
|
|
- query = db.query(RiskManagementInspectionUser)
|
|
|
- query = query.filter(RiskManagementInspectionUser.del_flag != '2')
|
|
|
- # 应用查询条件
|
|
|
- if nickName:
|
|
|
- query = query.filter(RiskManagementInspectionUser.nick_name.like(f'%{nickName}%'))
|
|
|
- if deptId:
|
|
|
- query = query.filter(RiskManagementInspectionUser.dept_id == deptId)
|
|
|
-
|
|
|
- # 计算总条目数
|
|
|
- total_items = query.count()
|
|
|
-
|
|
|
- # 排序
|
|
|
-
|
|
|
- query = query.order_by(RiskManagementInspectionUser.create_time.desc())
|
|
|
- # 执行分页查询
|
|
|
- InspectionUsers = query.offset((page - 1) * pageSize).limit(pageSize).all()
|
|
|
-
|
|
|
- # 将查询结果转换为列表形式的字典
|
|
|
- InspectionUsers_list = [
|
|
|
- {
|
|
|
- "id": user.id,
|
|
|
- "user_id": user.user_id,
|
|
|
- "dept_id": user.dept_id,
|
|
|
- "dept_name": user.dept_name,
|
|
|
- "ancestors_names": user.ancestors_names,
|
|
|
- "user_name": user.user_name,
|
|
|
- "create_time": user.create_time.strftime('%Y-%m-%d'),
|
|
|
- "phonenumber": user.phonenumber,
|
|
|
- "nick_name": user.nick_name,
|
|
|
- "area_code": user.area_code,
|
|
|
- "area": user.area,
|
|
|
- "yzy_account":user.yzy_account
|
|
|
- }
|
|
|
- for user in InspectionUsers
|
|
|
- ]
|
|
|
-
|
|
|
- # 返回结果
|
|
|
- return {
|
|
|
- "code": 200,
|
|
|
- "msg": "成功",
|
|
|
- "data": InspectionUsers_list,
|
|
|
- "total": total_items,
|
|
|
- "page": page,
|
|
|
- "pageSize": pageSize,
|
|
|
- "totalPages": (total_items + pageSize - 1) // pageSize
|
|
|
- }
|
|
|
- except Exception as e:
|
|
|
- # 处理异常
|
|
|
- raise HTTPException(status_code=500, detail=str(e))
|
|
|
-
|
|
|
-
|
|
|
-@router.get('/inspection/user/{id}')
|
|
|
-async def get_inspection_user(
|
|
|
- id: str ,
|
|
|
- db: Session = Depends(get_db),
|
|
|
- user_id = Depends(valid_access_token)
|
|
|
-):
|
|
|
- try:
|
|
|
- # 构建查询
|
|
|
- query = db.query(RiskManagementInspectionUser)
|
|
|
- query = query.filter(RiskManagementInspectionUser.del_flag != '2')
|
|
|
- # 应用查询条件
|
|
|
- if id:
|
|
|
- query = query.filter(RiskManagementInspectionUser.id == id)
|
|
|
-
|
|
|
- # 执行查询
|
|
|
- user = query.first()
|
|
|
- if not user:
|
|
|
- detail = "用户不存在"
|
|
|
- raise HTTPException(status_code=404, detail="用户不存在")
|
|
|
- # 将查询结果转换为列表形式的字典
|
|
|
- inspection_user_result = {
|
|
|
- "id": user.id,
|
|
|
- "user_id": user.user_id,
|
|
|
- "dept_id": user.dept_id,
|
|
|
- "dept_name": user.dept_name,
|
|
|
- "ancestors_names": user.ancestors_names,
|
|
|
- "user_name": user.user_name,
|
|
|
- "create_time": user.create_time.strftime('%Y-%m-%d'),
|
|
|
- "phonenumber": user.phonenumber,
|
|
|
- "nick_name": user.nick_name,
|
|
|
- "area_code": user.area_code,
|
|
|
- "area": user.area,
|
|
|
- "yzy_account":user.yzy_account
|
|
|
- }
|
|
|
-
|
|
|
- # 返回结果
|
|
|
- return {
|
|
|
- "code": 200,
|
|
|
- "msg": "成功",
|
|
|
- "data": inspection_user_result
|
|
|
- }
|
|
|
- except Exception as e:
|
|
|
- # 处理异常
|
|
|
- if str(e)=='':
|
|
|
- e = detail
|
|
|
- raise HTTPException(status_code=500, detail=str(e))
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-@router.post('/inspection/user/create')
|
|
|
-async def create_inspection_user(
|
|
|
- db: Session = Depends(get_db),
|
|
|
- body = Depends(remove_xss_json),
|
|
|
- user_id = Depends(valid_access_token)
|
|
|
-):
|
|
|
- try:
|
|
|
-
|
|
|
- # 创建新的预案记录
|
|
|
- new_user = RiskManagementInspectionUser(
|
|
|
- user_id=body['user_id'],
|
|
|
- dept_id = body['dept_id'],
|
|
|
- dept_name = body['dept_name'],
|
|
|
- ancestors_names = body['ancestors_names'],
|
|
|
- user_name = body['user_name'],
|
|
|
- nick_name = body['nick_name'],
|
|
|
- phonenumber = body['phonenumber'],
|
|
|
- area_code = body['area_code'],
|
|
|
- area = body['area'],
|
|
|
- yzy_account = body['yzy_account'],
|
|
|
- create_by = user_id
|
|
|
- )
|
|
|
- # 添加到数据库会话并提交
|
|
|
- db.add(new_user)
|
|
|
- db.commit()
|
|
|
- db.refresh(new_user) # 可选,如果需要刷新实例状态
|
|
|
- # 返回创建成功的响应
|
|
|
- return {
|
|
|
- "code": 200,
|
|
|
- "msg": "成功",
|
|
|
- "data": None
|
|
|
- }
|
|
|
- except Exception as e:
|
|
|
- # 处理异常
|
|
|
- raise HTTPException(status_code=500, detail=str(e))
|
|
|
-
|
|
|
-
|
|
|
-@router.put('/inspection/user/update')
|
|
|
-async def update_inspection_user(
|
|
|
- db: Session = Depends(get_db),
|
|
|
- body = Depends(remove_xss_json),
|
|
|
- user_id = Depends(valid_access_token)
|
|
|
-):
|
|
|
- try:
|
|
|
- # 提取请求数据
|
|
|
- query = db.query(RiskManagementInspectionUser)
|
|
|
- query = query.filter(RiskManagementInspectionUser.id == body['id'])
|
|
|
- query = query.filter(RiskManagementInspectionUser.del_flag != '2')
|
|
|
- user = query.first()
|
|
|
-
|
|
|
- if not user:
|
|
|
- detail = "用户不存在"
|
|
|
- raise HTTPException(status_code=404, detail="用户不存在")
|
|
|
-
|
|
|
- if 'user_id' in body:
|
|
|
- user.user_id = body['user_id']
|
|
|
- if 'dept_id' in body:
|
|
|
- user.dept_id = body['dept_id']
|
|
|
- if 'dept_name' in body:
|
|
|
- user.dept_name = body['dept_name']
|
|
|
- if 'ancestors_names' in body:
|
|
|
- user.ancestors_names = body['ancestors_names']
|
|
|
- if 'user_name' in body:
|
|
|
- user.user_name = body['user_name']
|
|
|
- if 'nick_name' in body:
|
|
|
- user.nick_name = body['nick_name']
|
|
|
- if 'phonenumber' in body:
|
|
|
- user.phonenumber = body['phonenumber']
|
|
|
- if 'area_code' in body:
|
|
|
- user.area_code = body['area_code']
|
|
|
- if 'area' in body:
|
|
|
- user.area = body['area']
|
|
|
-
|
|
|
- if user_id:
|
|
|
- user.update_by = user_id
|
|
|
-
|
|
|
- # 更新到数据库会话并提交
|
|
|
- db.commit()
|
|
|
- db.refresh(user) # 可选,如果需要刷新实例状态
|
|
|
-
|
|
|
- # 返回创建成功的响应
|
|
|
- return {
|
|
|
- "code": 200,
|
|
|
- "msg": "成功",
|
|
|
- "data": None
|
|
|
- }
|
|
|
- except Exception as e:
|
|
|
- # 处理异常
|
|
|
- if str(e)=='':
|
|
|
- e = detail
|
|
|
- raise HTTPException(status_code=500, detail=str(e))
|
|
|
-
|
|
|
-@router.delete('/inspection/user/delete')
|
|
|
-async def delete_inspection_users(
|
|
|
- userIds: list,
|
|
|
- db: Session = Depends(get_db),
|
|
|
- body = Depends(remove_xss_json),
|
|
|
- user_id = Depends(valid_access_token)
|
|
|
-):
|
|
|
- try:
|
|
|
- # 提取请求数据
|
|
|
- query = db.query(RiskManagementInspectionUser)
|
|
|
- query = query.filter(RiskManagementInspectionUser.del_flag != '2')
|
|
|
- query = query.filter(RiskManagementInspectionUser.id.in_(userIds))
|
|
|
- users = query.all()
|
|
|
- if not users:
|
|
|
- detail = "用户不存在"
|
|
|
- raise HTTPException(status_code=404, detail="用户不存在")
|
|
|
- for user in users:
|
|
|
- user.del_flag = '2'
|
|
|
- user.update_by=user_id
|
|
|
- # 更新到数据库会话并提交
|
|
|
- db.commit()
|
|
|
-
|
|
|
- # 返回创建成功的响应
|
|
|
- return {
|
|
|
- "code": 200,
|
|
|
- "msg": "删除成功",
|
|
|
- "data": None
|
|
|
- }
|
|
|
- except Exception as e:
|
|
|
- # 处理异常
|
|
|
- if str(e) == '':
|
|
|
- e = detail
|
|
|
- raise HTTPException(status_code=500, detail=str(e))
|
|
|
-
|
|
|
-@router.delete('/inspection/user/delete/{userId}')
|
|
|
-async def delete_inspection_user(
|
|
|
- userId: str,
|
|
|
- db: Session = Depends(get_db),
|
|
|
- body = Depends(remove_xss_json),
|
|
|
- user_id = Depends(valid_access_token)
|
|
|
-):
|
|
|
- try:
|
|
|
- # 提取请求数据
|
|
|
- query = db.query(RiskManagementInspectionUser)
|
|
|
- query = query.filter(RiskManagementInspectionUser.del_flag != '2')
|
|
|
- query = query.filter(RiskManagementInspectionUser.id==userId)
|
|
|
- user = query.first()
|
|
|
- if not user:
|
|
|
- detail = "用户不存在"
|
|
|
- raise HTTPException(status_code=404, detail="用户不存在")
|
|
|
-
|
|
|
- user.del_flag = '2'
|
|
|
- user.update_by = user_id
|
|
|
- # 更新到数据库会话并提交
|
|
|
- db.commit()
|
|
|
- db.refresh(user) # 可选,如果需要刷新实例状态
|
|
|
-
|
|
|
- # 返回创建成功的响应
|
|
|
- return {
|
|
|
- "code": 200,
|
|
|
- "msg": "删除成功",
|
|
|
- "data": None
|
|
|
- }
|
|
|
- except Exception as e:
|
|
|
- # 处理异常
|
|
|
- if str(e) == '':
|
|
|
- e = detail
|
|
|
- raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
|
|
@router.get("/allAreas")
|
|
|
def read_all_areas(db: Session = Depends(get_db)):
|
|
@@ -414,308 +146,3 @@ def read_all_areas(db: Session = Depends(get_db)):
|
|
|
"data": data
|
|
|
}
|
|
|
|
|
|
-####巡查任务####
|
|
|
-
|
|
|
-@router.get('/inspection/task/list')
|
|
|
-async def get_inspection_task_list(
|
|
|
- business: str = Query(None, description='巡查业务'),
|
|
|
- cycle :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(RiskManagementInspectionTask)
|
|
|
- query = query.filter(RiskManagementInspectionTask.del_flag != '2')
|
|
|
- # 应用查询条件
|
|
|
- if business:
|
|
|
- query = query.filter(RiskManagementInspectionTask.inspection_business == business)
|
|
|
- if cycle:
|
|
|
- query = query.filter(RiskManagementInspectionTask.inspection_cycle == cycle)
|
|
|
-
|
|
|
- # 计算总条目数
|
|
|
- total_items = query.count()
|
|
|
-
|
|
|
- # 排序
|
|
|
-
|
|
|
- query = query.order_by(RiskManagementInspectionTask.create_time.desc())
|
|
|
- # 执行分页查询
|
|
|
- InspectionTasks = query.offset((page - 1) * pageSize).limit(pageSize).all()
|
|
|
-
|
|
|
- # 将查询结果转换为列表形式的字典
|
|
|
- InspectionTasks_list = []
|
|
|
- for task in InspectionTasks:
|
|
|
- if task.task_status=='3':
|
|
|
- task_status = '3' #'已完结'
|
|
|
- else:
|
|
|
- if datetime.now()<task.start_time:
|
|
|
- task_status = '0' #'未开始'
|
|
|
- elif task.start_time<=datetime.now()<=task.end_time:
|
|
|
- task_status = '1' #'进行中'
|
|
|
- else:
|
|
|
- task_status = '2' #'未完成'
|
|
|
- create_by = task.create_by
|
|
|
- create_by = db.query(SysUser).filter(SysUser.user_id==create_by).first()
|
|
|
- task_info = {
|
|
|
- "id": task.id,
|
|
|
- "task_number": task.task_number,
|
|
|
- "business": task.inspection_business,
|
|
|
- "task_time": '%s-%s'%(task.start_time.strftime('%Y/%m/%d'),task.end_time.strftime('%Y/%m/%d')),
|
|
|
- "cycle": task.inspection_cycle,
|
|
|
- "inspection_range": task.inspection_range,
|
|
|
- "task_status": task_status,
|
|
|
- "create_by":create_by.nick_name,
|
|
|
- "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:
|
|
|
- # 处理异常
|
|
|
- raise HTTPException(status_code=500, detail=str(e))
|
|
|
-
|
|
|
-
|
|
|
-@router.get('/inspection/task/{id}')
|
|
|
-async def get_inspection_task(
|
|
|
- id: str ,
|
|
|
- db: Session = Depends(get_db),
|
|
|
- user_id = Depends(valid_access_token)
|
|
|
-):
|
|
|
- try:
|
|
|
- # 构建查询
|
|
|
- query = db.query(RiskManagementInspectionTask)
|
|
|
- query = query.filter(RiskManagementInspectionTask.del_flag != '2')
|
|
|
- # 应用查询条件
|
|
|
- if id:
|
|
|
- query = query.filter(RiskManagementInspectionTask.id == id)
|
|
|
-
|
|
|
- # 执行查询
|
|
|
- task = query.first()
|
|
|
- if not task:
|
|
|
- detail = "巡查任务不存在"
|
|
|
- raise HTTPException(status_code=404, detail="用户不存在")
|
|
|
- # 将查询结果转换为列表形式的字典
|
|
|
- if task.task_status == '3':
|
|
|
- task_status = '3' # '已完结'
|
|
|
- else:
|
|
|
- if datetime.now() < task.start_time:
|
|
|
- task_status = '0' # '未开始'
|
|
|
- elif task.start_time <= datetime.now() <= task.end_time:
|
|
|
- task_status = '1' # '进行中'
|
|
|
- else:
|
|
|
- task_status = '2' # '未完成'
|
|
|
- inspection_task_result = {
|
|
|
- "id": task.id,
|
|
|
- "task_number": task.task_number,
|
|
|
- "business": task.inspection_business,
|
|
|
- "task_time": '%s-%s'%(task.start_time.strftime('%Y/%m/%d'),task.end_time.strftime('%Y/%m/%d')),
|
|
|
- "cycle": task.inspection_cycle,
|
|
|
- "inspection_range": task.inspection_range,
|
|
|
- "task_status": task_status,
|
|
|
- "create_time": task.create_time.strftime('%Y-%m-%d')
|
|
|
- }
|
|
|
-
|
|
|
- # 返回结果
|
|
|
- return {
|
|
|
- "code": 200,
|
|
|
- "msg": "成功",
|
|
|
- "data": inspection_task_result
|
|
|
- }
|
|
|
- except Exception as e:
|
|
|
- # 处理异常
|
|
|
- if str(e)=='':
|
|
|
- e = detail
|
|
|
- raise HTTPException(status_code=500, detail=str(e))
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-@router.post('/inspection/task/create')
|
|
|
-async def create_inspection_task(
|
|
|
- db: Session = Depends(get_db),
|
|
|
- body = Depends(remove_xss_json),
|
|
|
- user_id = Depends(valid_access_token)
|
|
|
-):
|
|
|
- try:
|
|
|
- cycle = body['cycle']
|
|
|
- # 0每年、1每月、2每周、3每日、4一次
|
|
|
- corn_query = body['corn_query']
|
|
|
- if cycle=='0':
|
|
|
- corn=f'0 0 {corn_query} *'
|
|
|
- elif cycle=='1':
|
|
|
- corn=f'0 0 {corn_query} * *'
|
|
|
- elif cycle == '2':
|
|
|
- corn = f'0 0 * * {corn_query}'
|
|
|
- elif cycle == '3':
|
|
|
- corn = f'0 0 * * *'
|
|
|
- else:
|
|
|
- corn=''
|
|
|
- # 创建新的预案记录
|
|
|
- new_task = RiskManagementInspectionTask(
|
|
|
- inspection_business=body['business'],
|
|
|
- start_time = body['start_time'],
|
|
|
- end_time = body['end_time'],
|
|
|
- inspection_cycle = cycle,
|
|
|
- corn_expression = corn,
|
|
|
- inspection_range = body['inspection_range'],
|
|
|
- task_status = '-1',
|
|
|
- create_by = user_id
|
|
|
- )
|
|
|
- # 添加到数据库会话并提交
|
|
|
- db.add(new_task)
|
|
|
- db.commit()
|
|
|
- db.refresh(new_task) # 可选,如果需要刷新实例状态
|
|
|
- new_task.task_number = f'YJXC{str(new_task.id).zfill(10)}'
|
|
|
- db.commit()
|
|
|
- # 返回创建成功的响应
|
|
|
- return {
|
|
|
- "code": 200,
|
|
|
- "msg": "成功",
|
|
|
- "data": None
|
|
|
- }
|
|
|
- except Exception as e:
|
|
|
- # 处理异常
|
|
|
- raise HTTPException(status_code=500, detail=str(e))
|
|
|
-
|
|
|
-
|
|
|
-@router.put('/inspection/task/update')
|
|
|
-async def update_inspection_task(
|
|
|
- db: Session = Depends(get_db),
|
|
|
- body = Depends(remove_xss_json),
|
|
|
- user_id = Depends(valid_access_token)
|
|
|
-):
|
|
|
- try:
|
|
|
- # 提取请求数据
|
|
|
- query = db.query(RiskManagementInspectionTask)
|
|
|
- query = query.filter(RiskManagementInspectionTask.id == body['id'])
|
|
|
- query = query.filter(RiskManagementInspectionTask.del_flag != '2')
|
|
|
- task = query.first()
|
|
|
-
|
|
|
- if not task:
|
|
|
- detail = "任务不存在"
|
|
|
- raise HTTPException(status_code=404, detail="任务不存在")
|
|
|
-
|
|
|
- if 'cycle' in body:
|
|
|
- cycle = body['cycle']
|
|
|
- # 0每年、1每月、2每周、3每日、4一次
|
|
|
- corn_query = body['corn_query']
|
|
|
- if cycle == '0':
|
|
|
- corn = f'0 0 {corn_query} *'
|
|
|
- elif cycle == '1':
|
|
|
- corn = f'0 0 {corn_query} * *'
|
|
|
- elif cycle == '2':
|
|
|
- corn = f'0 0 * * {corn_query}'
|
|
|
- elif cycle == '3':
|
|
|
- corn = f'0 0 * * *'
|
|
|
- else:
|
|
|
- corn = ''
|
|
|
- task.inspection_cycle = cycle
|
|
|
- task.corn_expression = corn
|
|
|
- if 'business' in body:
|
|
|
- task.inspection_business = body['business']
|
|
|
- if 'start_time' in body:
|
|
|
- task.start_time = body['start_time']
|
|
|
- if 'end_time' in body:
|
|
|
- task.end_time = body['end_time']
|
|
|
- if 'inspection_range' in body:
|
|
|
- task.inspection_range = body['inspection_range']
|
|
|
- if 'task_status' in body:
|
|
|
- task.task_status = body['task_status']
|
|
|
-
|
|
|
- if user_id:
|
|
|
- task.update_by = user_id
|
|
|
-
|
|
|
- # 更新到数据库会话并提交
|
|
|
- db.commit()
|
|
|
- db.refresh(task) # 可选,如果需要刷新实例状态
|
|
|
-
|
|
|
- # 返回创建成功的响应
|
|
|
- return {
|
|
|
- "code": 200,
|
|
|
- "msg": "成功",
|
|
|
- "data": None
|
|
|
- }
|
|
|
- except Exception as e:
|
|
|
- # 处理异常
|
|
|
- if str(e)=='':
|
|
|
- e = detail
|
|
|
- raise HTTPException(status_code=500, detail=str(e))
|
|
|
-
|
|
|
-@router.delete('/inspection/task/delete')
|
|
|
-async def delete_inspection_tasks(
|
|
|
- taskIds: list,
|
|
|
- db: Session = Depends(get_db),
|
|
|
- body = Depends(remove_xss_json),
|
|
|
- user_id = Depends(valid_access_token)
|
|
|
-):
|
|
|
- try:
|
|
|
- # 提取请求数据
|
|
|
- query = db.query(RiskManagementInspectionTask)
|
|
|
- query = query.filter(RiskManagementInspectionTask.del_flag != '2')
|
|
|
- query = query.filter(RiskManagementInspectionTask.id.in_(taskIds))
|
|
|
- tasks = query.all()
|
|
|
- if not tasks:
|
|
|
- detail = "任务不存在"
|
|
|
- raise HTTPException(status_code=404, detail="任务不存在")
|
|
|
- for task in tasks:
|
|
|
- task.del_flag = '2'
|
|
|
- task.update_by=user_id
|
|
|
- # 更新到数据库会话并提交
|
|
|
- db.commit()
|
|
|
-
|
|
|
- # 返回创建成功的响应
|
|
|
- return {
|
|
|
- "code": 200,
|
|
|
- "msg": "删除成功",
|
|
|
- "data": None
|
|
|
- }
|
|
|
- except Exception as e:
|
|
|
- # 处理异常
|
|
|
- if str(e) == '':
|
|
|
- e = detail
|
|
|
- raise HTTPException(status_code=500, detail=str(e))
|
|
|
-
|
|
|
-@router.delete('/inspection/task/delete/{userId}')
|
|
|
-async def delete_inspection_task(
|
|
|
- userId: str,
|
|
|
- db: Session = Depends(get_db),
|
|
|
- body = Depends(remove_xss_json),
|
|
|
- user_id = Depends(valid_access_token)
|
|
|
-):
|
|
|
- try:
|
|
|
- # 提取请求数据
|
|
|
- query = db.query(RiskManagementInspectionTask)
|
|
|
- query = query.filter(RiskManagementInspectionTask.del_flag != '2')
|
|
|
- query = query.filter(RiskManagementInspectionTask.id==userId)
|
|
|
- task = query.first()
|
|
|
- if not task:
|
|
|
- detail = "用户不存在"
|
|
|
- raise HTTPException(status_code=404, detail="用户不存在")
|
|
|
-
|
|
|
- task.del_flag = '2'
|
|
|
- task.update_by = user_id
|
|
|
- # 更新到数据库会话并提交
|
|
|
- db.commit()
|
|
|
- db.refresh(task) # 可选,如果需要刷新实例状态
|
|
|
-
|
|
|
- # 返回创建成功的响应
|
|
|
- return {
|
|
|
- "code": 200,
|
|
|
- "msg": "删除成功",
|
|
|
- "data": None
|
|
|
- }
|
|
|
- except Exception as e:
|
|
|
- # 处理异常
|
|
|
- if str(e) == '':
|
|
|
- e = detail
|
|
|
- raise HTTPException(status_code=500, detail=str(e))
|