jm_homework.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from fastapi import APIRouter, Depends
  2. from sqlalchemy.orm import Session
  3. from app.common.security.auth import verify_users
  4. from app.services.jm_homework import create_jm_homework_services, update_jm_homework_service
  5. from app.services.jm_job import red_dag_and_format
  6. from utils.sx_time import sxtimeit
  7. from utils.sx_web import web_try
  8. import app.crud as crud
  9. from app import schemas, get_db
  10. router = APIRouter(
  11. prefix="/jpt/jm_homework",
  12. tags=["jm_homework-作业管理"],
  13. )
  14. @router.post("/")
  15. @web_try()
  16. @sxtimeit
  17. def create_jm_homework(item: schemas.JmHomeworkCreate, token_data: schemas.TokenData = Depends(verify_users), db: Session = Depends(get_db)):
  18. return create_jm_homework_services(db, item)
  19. @router.get("/")
  20. @web_try()
  21. @sxtimeit
  22. def get_jm_homeworks(token_data: schemas.TokenData = Depends(verify_users), db: Session = Depends(get_db)):
  23. return crud.get_jm_homeworks(db, token_data.project_id)
  24. @router.get("/info")
  25. @web_try()
  26. @sxtimeit
  27. def get_jm_homework_info(homework_id: str, token_data: schemas.TokenData = Depends(verify_users), db: Session = Depends(get_db)):
  28. return crud.get_jm_homework_info(db, homework_id)
  29. @router.put("/")
  30. @web_try()
  31. @sxtimeit
  32. def update_jm_homework(jm_id: int, update_item: schemas.JmHomeworkUpdate, token_data: schemas.TokenData = Depends(verify_users), db: Session = Depends(get_db)):
  33. return update_jm_homework_service(db, jm_id, update_item)
  34. @router.delete("/")
  35. @web_try()
  36. @sxtimeit
  37. def delete_jm_homework(jm_id: int, token_data: schemas.TokenData = Depends(verify_users), db: Session = Depends(get_db)):
  38. jm_log_infos = crud.get_jm_job_infos(db)
  39. jm_job_ids = [jm_job.id for jm_job in jm_log_infos]
  40. res = crud.find_by_homework_and_job(db, jm_job_ids,jm_id)
  41. if len(res) > 0:
  42. raise Exception("该作业正在被定时任务使用,不可删除")
  43. return crud.delete_jm_homework(db, jm_id)