Ver Fonte

250709-5代码。

baoyubo há 4 dias atrás
pai
commit
9d3b087290
1 ficheiros alterados com 56 adições e 0 exclusões
  1. 56 0
      routers/api/dutyManagement/schedule.py

+ 56 - 0
routers/api/dutyManagement/schedule.py

@@ -409,6 +409,62 @@ async def create_dict_data(
         })
 
 
+@router.post('/list_create')
+async def create_dict_data(
+    db: Session = Depends(get_db),
+    body = Depends(remove_xss_json),
+    user_id = Depends(valid_access_token)
+):
+    try:
+        # 创建一个新的 SysDictData 实例
+        if isinstance(body,list) == False:
+            return JSONResponse(status_code=500,content={'msg':"请求体非列表","code":500})
+        for data in body:
+            user_data = data['user_data']
+            if len(user_data)==0:
+                return JSONResponse(status_code=404, content={
+                    'errcode': 404,
+                    'errmsg': '值班人员不能为空'
+                })
+            new_duty_data = DutySchedule(
+                start_time=data['start_time'],
+                end_time=data['end_time'],
+                duty_date=data['duty_date'],
+                shift_type=data['shift_type'],
+                duty_unit=data['duty_unit'],
+                duty_type=data['duty_type'],
+                create_by=user_id
+            )
+
+            # 添加到会话并提交
+            db.add(new_duty_data)
+            db.commit()
+            db.refresh(new_duty_data)
+            user_list = []
+            for user_info in user_data:
+                user_list.append( DutyPersonnelArrangement(
+                    duty_id=new_duty_data.id,
+                    position_id=user_info['position_id'],
+                    personnel_id=user_info['personnel_id'],
+                    create_by=user_id
+                ))
+            db.add_all(user_list)
+            db.commit()
+        # 构建返回结果
+        result = {
+            "code": 200,
+            "msg": "操作成功",
+            "data": None
+        }
+        return result
+    except Exception as e:
+        # 处理异常
+        traceback.print_exc()
+        return JSONResponse(status_code=404, content={
+            'code': 404,
+            'msg': str(e)
+        })
+
 @router.put("/update")
 async def updata_dict_type(
     db: Session = Depends(get_db),