|
@@ -393,7 +393,11 @@ async def handover(
|
|
|
where = and_(DutyShift.shift_id == shift_id)
|
|
|
row = db.query(DutyShift).filter(where).first()
|
|
|
if row is None:
|
|
|
- raise AppException(1, "班次不存在")
|
|
|
+ new_duty = DutyShift(shift_id = shift_id, shift_status = 0)
|
|
|
+ db.add(new_duty)
|
|
|
+ db.commit()
|
|
|
+
|
|
|
+ row = db.query(DutyShift).filter(where).first()
|
|
|
|
|
|
if row.shift_status == 1:
|
|
|
raise AppException(1, "班次已交班,不用重复操作")
|
|
@@ -419,6 +423,47 @@ async def handover(
|
|
|
traceback.print_exc()
|
|
|
# 处理异常
|
|
|
raise HTTPException(status_code=500, detail=str(e))
|
|
|
+
|
|
|
+
|
|
|
+# 接班
|
|
|
+@router.post("/takeover")
|
|
|
+async def takeover(
|
|
|
+ db: Session = Depends(get_db),
|
|
|
+ body = Depends(remove_xss_json),
|
|
|
+ user_id = Depends(valid_access_token)
|
|
|
+):
|
|
|
+ try:
|
|
|
+ shift_id = body['shift_id']
|
|
|
+
|
|
|
+ where = and_(DutyShift.shift_id == shift_id)
|
|
|
+ row = db.query(DutyShift).filter(where).first()
|
|
|
+ if row is None:
|
|
|
+ raise AppException(1, "班次不存在")
|
|
|
+
|
|
|
+ if row.shift_status == 2:
|
|
|
+ raise AppException(1, "班次已接班,不用重复操作")
|
|
|
+
|
|
|
+ row.shift_status = 2
|
|
|
+ row.takeover_time = datetime.now()
|
|
|
+ row.takeover_user_id = user_id
|
|
|
+ db.commit()
|
|
|
+
|
|
|
+ return {
|
|
|
+ "code": 200,
|
|
|
+ "msg": "接班成功",
|
|
|
+ "data": shift_id
|
|
|
+ }
|
|
|
+
|
|
|
+ except AppException as e:
|
|
|
+ return {
|
|
|
+ "code": e.code,
|
|
|
+ "msg": e.msg
|
|
|
+ }
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ traceback.print_exc()
|
|
|
+ # 处理异常
|
|
|
+ raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
|
|
# 值班表查询
|
|
|
@router.get("/duty_book_by_area")
|