libushang hai 6 meses
pai
achega
99c2084063
Modificáronse 2 ficheiros con 105 adicións e 14 borrados
  1. 1 1
      models/online_roll_call.py
  2. 104 13
      routers/api/onlineRollCall/call.py

+ 1 - 1
models/online_roll_call.py

@@ -41,7 +41,7 @@ class OnlineRollCallDetail(Base):
     video_url = Column(String, default='', server_default='', comment='视频URL')
     call_url = Column(String, default='', server_default='', comment='电话URL')
     ack_status = Column(Integer, default=0, server_default='0', comment='应答状态 0 未应答 1 已接通 2 呼叫中')
-    act_time = Column(DateTime, comment='应答时间')
+    ack_time = Column(DateTime, comment='应答时间')
     create_time = Column(DateTime, default=datetime.now, comment='数据创建时间')
     del_flag = Column(String(1), default='0', comment='删除标志(0代表存在 2代表删除)')
     ack_type = Column(Integer, default=0, server_default='0', comment='应答方式 1 视频  2 电话')

+ 104 - 13
routers/api/onlineRollCall/call.py

@@ -149,7 +149,7 @@ async def create_by_city_to_area(
                 video_url = video_url,
                 call_url = call_url,
                 ack_status = 0,
-                act_time = None,
+                ack_time = None,
                 create_time = datetime.now(),
                 del_flag = '0',
                 ack_type = 0
@@ -238,7 +238,7 @@ async def create_by_city_to_district(
                 video_url = video_url,
                 call_url = call_url,
                 ack_status = 0,
-                act_time = None,
+                ack_time = None,
                 create_time = datetime.now(),
                 del_flag = '0',
                 ack_type = 0
@@ -324,7 +324,7 @@ async def create_by_dept_ids(
                     video_url = video_url,
                     call_url = call_url,
                     ack_status = 0,
-                    act_time = None,
+                    ack_time = None,
                     create_time = datetime.now(),
                     del_flag = '0',
                     ack_type = 0
@@ -420,7 +420,7 @@ async def ack_all(
         }
     
     detail_row.ack_type = ack_type
-    detail_row.act_time = datetime.now()
+    detail_row.ack_time = datetime.now()
     db.commit()
 
     # 统计应答数
@@ -482,8 +482,8 @@ async def get_event_detail(
         data['update_time'] = get_datetime_str(data['update_time'])
         data['duration_time'] = ''
 
-        # 已结束
-        if data['call_status'] == 2:
+        # 已应答
+        if data['call_status'] == 1:
             time_diff = base_row.end_time - base_row.create_time
             # hours,minutes,seconds = str(time_diff).split(':')
             data['duration_time'] = str(time_diff)
@@ -493,7 +493,7 @@ async def get_event_detail(
         for row in detail_rows:
             detail_info = get_model_dict(row)
             detail_info['begin_time'] = get_datetime_str(detail_info['create_time'])
-            detail_info['act_time'] = get_datetime_str(detail_info['act_time'])
+            detail_info['ack_time'] = get_datetime_str(detail_info['ack_time'])
             detail_info['ack_status_text'] = get_ack_status_text(detail_info['ack_status'])
             items.append(detail_info)
 
@@ -511,15 +511,15 @@ async def get_event_detail(
         raise HTTPException(status_code=500, detail=str(e))
     
 
-def get_ack_status_text(act_status: int) -> str:
-    if act_status == 0:
+def get_ack_status_text(ack_status: int) -> str:
+    if ack_status == 0:
         return '未应答'
-    elif act_status == 1:
+    elif ack_status == 1:
         return '已接通'
-    elif act_status == 2:
+    elif ack_status == 2:
         return '呼叫中'
     else:
-        return str(act_status)
+        return str(ack_status)
     
 #应答详情
 @router.get('/list')
@@ -585,4 +585,95 @@ async def get_event_list(
         # 处理异常
         traceback.print_exc()
         raise HTTPException(status_code=500, detail=str(e))
-    
+    
+
+#应答列表
+@router.get('/ack_list')
+async def get_event_list(
+    request: Request,
+    begin_date: str = Query('', description='开始时间'),
+    end_date: str = Query('', description='结束时间'), 
+    page: int = Query(1, gt=0, description='页码'),
+    page_size: int = Query(10, gt=0, description='pageSize'),
+    db: Session = Depends(get_db)):
+
+    try:
+        where = and_(OnlineRollCallDetail.del_flag == '0')
+
+        if begin_date is not None and begin_date != '':
+            begin_date = datetime.strptime(begin_date, "%Y-%m-%d")
+            where = and_(where, OnlineRollCallDetail.create_time > begin_date)
+
+        if end_date is not None and end_date != '':
+            end_date = datetime.strptime(end_date, "%Y-%m-%d") + timedelta(days=1)
+            where = and_(where, OnlineRollCallDetail.create_time < end_date)
+
+        print(where)
+        
+        # 计算总条目数
+        q = db.query(func.count(OnlineRollCallDetail.id))
+        q = q.filter(where)
+        total = q.scalar()
+        
+        # 执行分页查询
+        q = db.query(OnlineRollCallDetail)
+        q = q.filter(where)
+        rows = q.order_by(OnlineRollCallDetail.id.desc()).offset((page - 1) * page_size).limit(page_size).all()
+        data = []
+
+        for row in rows:
+            duration_time = ""
+            # 已应答
+            if row.ack_status == 1:
+                time_diff = row.ack_time - row.create_time
+                # hours,minutes,seconds = str(time_diff).split(':')
+                duration_time = str(time_diff)
+                
+            data.append({
+                "id": row.id,
+                "create_time": get_datetime_str(row.create_time),
+                "duration_time": duration_time,
+                "ack_status": row.ack_status
+            })
+
+        # 返回结果
+        return {
+            "code": 200,
+            "msg": "查询成功",
+            "data": data,
+            "total": total
+        }
+
+    except Exception as e:
+        # 处理异常
+        traceback.print_exc()
+        raise HTTPException(status_code=500, detail=str(e))
+    
+
+# 点名统计
+@router.get("/summary")
+async def get_call_summary(request: Request,
+    db: Session = Depends(get_db)):
+
+    try:
+        call_count = db.query(OnlineRollCallBase).filter(OnlineRollCallBase.del_flag == '0').count()
+        ack_count = db.query(OnlineRollCallDetail).filter(and_(OnlineRollCallDetail.del_flag == '0', OnlineRollCallDetail.ack_status == 1)).count()
+        unack_count = db.query(OnlineRollCallDetail).filter(and_(OnlineRollCallDetail.del_flag == '0', OnlineRollCallDetail.ack_status == 0)).count()
+
+        data = {
+            "call_count": call_count,
+            "ack_count": ack_count,
+            "unack_count": unack_count
+        }
+
+        return {
+            "code": 200,
+            "msg": "查询成功",
+            "data": data
+        }
+
+    except Exception as e:
+        # 处理异常
+        traceback.print_exc()
+        raise HTTPException(status_code=500, detail=str(e))
+