|
@@ -2,6 +2,7 @@
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
from fastapi import APIRouter, Request, Depends, Query, HTTPException
|
|
|
+from fastapi.responses import FileResponse, StreamingResponse
|
|
|
from database import get_db
|
|
|
from sqlalchemy import text, exists, and_, or_, not_
|
|
|
from sqlalchemy.orm import Session
|
|
@@ -12,7 +13,7 @@ import os
|
|
|
from sqlalchemy import create_engine, select
|
|
|
from typing import Optional
|
|
|
from utils.StripTagsHTMLParser import *
|
|
|
-from common.db import db_event_management, db_user, db_area, db_dept
|
|
|
+from common.db import db_user, db_yzy, db_dept
|
|
|
from common.security import valid_access_token
|
|
|
import traceback
|
|
|
from utils import *
|
|
@@ -24,15 +25,14 @@ import base64
|
|
|
from config import settings
|
|
|
from exceptions import AppException
|
|
|
from typing import List, Dict,Set
|
|
|
+import openpyxl
|
|
|
+from io import BytesIO
|
|
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/dept_by_key", response_model=Dict)
|
|
|
def dept_by_key(db: Session = Depends(get_db), area_name: str = Query(None), keyword: str = Query(None)):
|
|
|
|
|
|
- current_date = datetime.now().date()
|
|
|
- current_time = datetime.now().time()
|
|
|
-
|
|
|
def get_dept_tree(db: Session, dept_id: int):
|
|
|
dept = db.query(SysDept).filter(SysDept.dept_id == dept_id).first()
|
|
|
if not dept:
|
|
@@ -44,22 +44,6 @@ def dept_by_key(db: Session = Depends(get_db), area_name: str = Query(None), key
|
|
|
if child is not None:
|
|
|
children.append(child)
|
|
|
|
|
|
- # 获取值班信息
|
|
|
- '''
|
|
|
- q = db.query(DutyShift)
|
|
|
- q = q.filter(DutyShift.shift_date == current_date)
|
|
|
- q = q.filter(DutyShift.shfit_status == 0)
|
|
|
- q = q.filter(DutyShift.start_time < current_time).filter(DutyShift.end_time > current_time)
|
|
|
- shift_row = q.first()
|
|
|
- if shift_row is not None:
|
|
|
- children.append({
|
|
|
- "uuid":str(uuid.uuid4()).replace('-',''),
|
|
|
- "id": shift_row.shift_id,
|
|
|
- "label": str(shift_row.shift_id),
|
|
|
- "deptType": False
|
|
|
- })
|
|
|
- '''
|
|
|
-
|
|
|
dept_info = {
|
|
|
"uuid":str(uuid.uuid4()).replace('-',''),
|
|
|
"id": dept.dept_id,
|
|
@@ -164,6 +148,9 @@ async def create_by_city_to_area(
|
|
|
)
|
|
|
db.add(new_detail)
|
|
|
db.commit()
|
|
|
+ db.refresh(new_detail)
|
|
|
+
|
|
|
+ send_yzy_msg(db, new_detail, user_id)
|
|
|
|
|
|
return {
|
|
|
"code": 200,
|
|
@@ -540,6 +527,26 @@ async def get_event_detail(
|
|
|
traceback.print_exc()
|
|
|
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
|
|
+def send_yzy_msg(db: Session, detail_entity: OnlineRollCallDetail, user_id: int) -> None:
|
|
|
+ to_user_id = detail_entity.leader_id
|
|
|
+ user_info = db_user.get_user_info(db, to_user_id)
|
|
|
+ yzy_account = user_info.yzy_account
|
|
|
+ yzy_userid = db_yzy.get_userid_by_account(db, yzy_account)
|
|
|
+ create_time = get_datetime_str(detail_entity.create_time)
|
|
|
+ detail_url = YzyApi.format_redirect_url(settings.YJXP_WEB_ROOT_PATH, yzy_userid)
|
|
|
+
|
|
|
+ description = f"在线点名提醒\n你有一条在线点名通知,请尽快确认\n点名时间:{create_time}"
|
|
|
+ data = {
|
|
|
+ "yzy_userid": yzy_userid,
|
|
|
+ "mobile": yzy_account,
|
|
|
+ "content": description,
|
|
|
+ "recorded_by": user_id,
|
|
|
+ "detail_url": detail_url,
|
|
|
+ "foreign_key": detail_entity.id,
|
|
|
+ "from_scenario": "online_roll_call_detail",
|
|
|
+ "title": "在线点名提醒"
|
|
|
+ }
|
|
|
+ YzyApi.add_to_msg_queue(db, data)
|
|
|
|
|
|
def get_ack_status_text(ack_status: int) -> str:
|
|
|
if ack_status == 0:
|
|
@@ -707,3 +714,45 @@ async def get_call_summary(request: Request,
|
|
|
traceback.print_exc()
|
|
|
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
|
|
+@router.get("/export", response_class=FileResponse)
|
|
|
+async def get_export_xslx(
|
|
|
+ request: Request,
|
|
|
+ call_id: str,
|
|
|
+ db: Session = Depends(get_db)):
|
|
|
+
|
|
|
+ # 导出excel表
|
|
|
+ wb = openpyxl.Workbook()
|
|
|
+ ws = wb.active
|
|
|
+
|
|
|
+ ws.cell(1, 1).value = "部门名称"
|
|
|
+ ws.cell(1, 2).value = "值班领导"
|
|
|
+ ws.cell(1, 3).value = "值班员"
|
|
|
+ ws.cell(1, 4).value = "点名开始时间"
|
|
|
+ ws.cell(1, 5).value = "应答状态"
|
|
|
+ ws.cell(1, 6).value = "应答时间"
|
|
|
+
|
|
|
+ q = db.query(OnlineRollCallDetail)
|
|
|
+ q = q.filter(and_(OnlineRollCallDetail.pid == call_id, OnlineRollCallDetail.del_flag == '0')).order_by(OnlineRollCallDetail.ack_status.desc(), OnlineRollCallDetail.ack_time.asc())
|
|
|
+ rows = q.all()
|
|
|
+
|
|
|
+ excel_row = 2
|
|
|
+ for row in rows:
|
|
|
+ ws.cell(excel_row, 1).value = row.dept_name
|
|
|
+ ws.cell(excel_row, 2).value = row.onduty_leader
|
|
|
+ ws.cell(excel_row, 3).value = row.onduty_user
|
|
|
+ ws.cell(excel_row, 4).value = get_datetime_str(row.create_time)
|
|
|
+ ws.cell(excel_row, 5).value = get_ack_status_text(row.ack_status)
|
|
|
+ ws.cell(excel_row, 6).value = get_datetime_str(row.ack_time)
|
|
|
+
|
|
|
+ excel_row = excel_row + 1
|
|
|
+
|
|
|
+ upload_path = '/data/download/mergefile'
|
|
|
+ if os.path.exists(upload_path) == False:
|
|
|
+ os.makedirs(upload_path)
|
|
|
+ excel_file_name = new_guid() +".xlsx"
|
|
|
+ save_path = os.path.join(upload_path, excel_file_name)
|
|
|
+
|
|
|
+ wb.save(save_path)
|
|
|
+ wb.close()
|
|
|
+
|
|
|
+ return FileResponse(save_path)
|