libushang před 4 měsíci
rodič
revize
88f8b27e20
2 změnil soubory, kde provedl 53 přidání a 3 odebrání
  1. 23 1
      models/online_roll_call.py
  2. 30 2
      routers/api/onlineRollCall/call.py

+ 23 - 1
models/online_roll_call.py

@@ -52,4 +52,26 @@ class OnlineRollCallDetail(Base):
     standby_staff_id = Column(Integer, default=0, server_default='0', comment="备班人员ID")
 
     class Config:
-        orm_mode = True
+        orm_mode = True
+
+
+
+class OnlineRollCallFile(Base):
+    __tablename__ = 'online_roll_call_file'
+
+    id = Column(Integer, autoincrement=True, primary_key=True)
+    file_name = Column(String(255), nullable=False, comment='文件名称')
+    storage_file_name = Column(String(255), nullable=False, comment='文件名称原名')
+    file_path = Column(String(255), comment='文件存储路径')
+    file_size = Column(String(50), comment='文件大小')
+    status = Column(String(50), comment='文件状态')
+    foreign_key = Column(String(50), comment='文件外键 --技术字段')
+    from_scenario = Column(String(50), comment='对应标识 --技术字段')
+    create_time = Column(DateTime, default=datetime.now, comment='数据创建时间')
+    update_time = Column(DateTime, default=datetime.now, onupdate=datetime.now, comment='数据更新时间')
+    create_dept = Column(Integer, default=None, comment='创建部门')
+    create_by = Column(Integer, default=None, comment='创建者')
+    del_flag = Column(String(1), default='0', comment='删除标志(0代表存在 2代表删除)')
+
+    class Config:
+        orm_mode = True

+ 30 - 2
routers/api/onlineRollCall/call.py

@@ -27,6 +27,7 @@ from exceptions import AppException
 from typing import List, Dict,Set
 import openpyxl
 from io import BytesIO
+from PIL import Image
 
 router = APIRouter()
 
@@ -420,7 +421,17 @@ async def ack_all(
     body = Depends(remove_xss_json),
     user_id = Depends(valid_access_token)
 ):
-    call_id = body['call_id']
+    call_id = get_req_param(body, 'call_id')
+    base64_data = get_req_param(body, "photo_data")
+
+    file_name = new_guid() + ".png"
+    file_path = f'/data/upload/mergefile/uploads/{file_name}'
+    
+    base64_data = base64_data.replace("data:image/png;base64,", "")
+    binary_data = base64.b64decode(base64_data)
+    bytes_io = BytesIO(binary_data)
+    image = Image.open(bytes_io)
+    image.save(file_path)
 
     base_row = db.query(OnlineRollCallBase).filter(OnlineRollCallBase.id == call_id).first()
     if base_row is None:
@@ -429,13 +440,30 @@ async def ack_all(
             "msg": "点名记录不存在"
         }
     
-    detail_row = db.query(OnlineRollCallDetail).filter(and_(OnlineRollCallDetail.pid == call_id, OnlineRollCallDetail.leader_id == user_id)).first()
+    user_or_where = or_(OnlineRollCallDetail.leader_id == user_id, OnlineRollCallDetail.primary_staff_id == user_id, OnlineRollCallDetail.secondary_staff_id == user_id, OnlineRollCallDetail.standby_staff_id == user_id)
+    detail_row = db.query(OnlineRollCallDetail).filter(and_(OnlineRollCallDetail.pid == call_id, user_or_where)).first()
     if detail_row is None:
         return {
             "code": 500,
             "msg": "点名记录不存在!"
         }
     
+    new_file = OnlineRollCallFile(
+        file_name=f"点名头像{user_id}.png",
+        storage_file_name=file_name,
+        file_path=f'/data/upload/mergefile/uploads/{file_name}',
+        file_size=os.path.getsize(f'/data/upload/mergefile/uploads/{file_name}'),
+        foreign_key=str(detail_row.id),
+        from_scenario="online_call_photo_file",
+        update_time=datetime.now(),
+        create_time=datetime.now(),
+        create_by=user_id,
+        create_dept=0,
+        del_flag='0',
+        status=0,
+    )
+    db.add(new_file)
+
     detail_row.ack_status = 1 # 已应答
     detail_row.ack_time = datetime.now()
     db.commit()