|
@@ -20,6 +20,80 @@ router = APIRouter()
|
|
|
|
|
|
####巡查人员####
|
|
####巡查人员####
|
|
|
|
|
|
|
|
+
|
|
|
|
+@router.get('/system/user/list')
|
|
|
|
+async def userlist( userId: int = Query(None ,description='用户id'),
|
|
|
|
+ nickName: 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: int = Depends(valid_access_token)):
|
|
|
|
+ try:
|
|
|
|
+ def dept_id_get_dept_info( dept_id):
|
|
|
|
+ query = db.query(SysDept)
|
|
|
|
+ query = query.filter(SysDept.del_flag != '2')
|
|
|
|
+ query = query.filter(SysDept.dept_id == dept_id)
|
|
|
|
+ return query.first()
|
|
|
|
+ def dept_id_get_ancestors_names(dept,ancestors_name=''):
|
|
|
|
+ ancestors_name = '/' + dept.dept_name + ancestors_name
|
|
|
|
+ if dept.parent_id==0:
|
|
|
|
+ return ancestors_name
|
|
|
|
+ else:
|
|
|
|
+ return dept_id_get_ancestors_names(dept_id_get_dept_info(dept.parent_id),ancestors_name)
|
|
|
|
+ # 构建查询
|
|
|
|
+ query = db.query(SysUser)
|
|
|
|
+ query = query.filter(SysUser.del_flag != '2')
|
|
|
|
+ # 应用查询条件
|
|
|
|
+
|
|
|
|
+ if nickName:
|
|
|
|
+ query =query.filter(SysUser.nick_name.like(f'%{nickName}%'))
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if userId:
|
|
|
|
+ query = query.filter(SysUser.user_id == userId)
|
|
|
|
+
|
|
|
|
+ # 计算总条目数
|
|
|
|
+ total_items = query.count()
|
|
|
|
+
|
|
|
|
+ # 排序
|
|
|
|
+
|
|
|
|
+ query = query.order_by(SysUser.create_time.desc())
|
|
|
|
+ # 执行分页查询
|
|
|
|
+ users = query.offset((page - 1) * pageSize).limit(pageSize).all()
|
|
|
|
+
|
|
|
|
+ # 将查询结果转换为列表形式的字典
|
|
|
|
+ user_list = []
|
|
|
|
+ for user in users:
|
|
|
|
+ # roleIds = user_id_get_user_roleIds(db, user.user_id)
|
|
|
|
+ dept = dept_id_get_dept_info(user.dept_id)
|
|
|
|
+ ancestors_names = dept_id_get_ancestors_names(dept)
|
|
|
|
+ user_info = {
|
|
|
|
+ "user_id": user.user_id,
|
|
|
|
+ "dept_id": user.dept_id,
|
|
|
|
+ "dept_name":dept.dept_name,
|
|
|
|
+ "ancestors_names":ancestors_names,
|
|
|
|
+ "user_name": user.user_name,
|
|
|
|
+ "nick_name": user.nick_name,
|
|
|
|
+ "phonenumber": user.phonenumber
|
|
|
|
+ }
|
|
|
|
+ user_list.append(user_info)
|
|
|
|
+
|
|
|
|
+ # 返回结果
|
|
|
|
+ return {
|
|
|
|
+ "code": 200,
|
|
|
|
+ "msg": "成功用户列表",
|
|
|
|
+ "rows": user_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=f"Internal server error: {str(e)}")
|
|
|
|
+
|
|
@router.get('/inspection/user/list')
|
|
@router.get('/inspection/user/list')
|
|
async def get_inspection_user_list(
|
|
async def get_inspection_user_list(
|
|
nickName: str = Query(None, description='姓名'),
|
|
nickName: str = Query(None, description='姓名'),
|
|
@@ -382,6 +456,8 @@ async def get_inspection_task_list(
|
|
task_status = '1' #'进行中'
|
|
task_status = '1' #'进行中'
|
|
else:
|
|
else:
|
|
task_status = '2' #'未完成'
|
|
task_status = '2' #'未完成'
|
|
|
|
+ create_by = task.create_by
|
|
|
|
+ create_by = db.query(SysUser).filter(SysUser.user_id==create_by).first()
|
|
task_info = {
|
|
task_info = {
|
|
"id": task.id,
|
|
"id": task.id,
|
|
"task_number": task.task_number,
|
|
"task_number": task.task_number,
|
|
@@ -390,6 +466,7 @@ async def get_inspection_task_list(
|
|
"cycle": task.inspection_cycle,
|
|
"cycle": task.inspection_cycle,
|
|
"inspection_range": task.inspection_range,
|
|
"inspection_range": task.inspection_range,
|
|
"task_status": task_status,
|
|
"task_status": task_status,
|
|
|
|
+ "create_by":create_by.nick_name,
|
|
"create_time": task.create_time.strftime('%Y-%m-%d')
|
|
"create_time": task.create_time.strftime('%Y-%m-%d')
|
|
}
|
|
}
|
|
InspectionTasks_list.append(task_info)
|
|
InspectionTasks_list.append(task_info)
|