from fastapi import APIRouter, Depends from sqlalchemy.orm import Session from app.common.security.auth import verify_users from app.services.jm_homework import create_jm_homework_services, update_jm_homework_service from app.services.jm_job import red_dag_and_format from utils.sx_time import sxtimeit from utils.sx_web import web_try import app.crud as crud from app import schemas, get_db router = APIRouter( prefix="/jpt/jm_homework", tags=["jm_homework-作业管理"], ) @router.post("/") @web_try() @sxtimeit def create_jm_homework(item: schemas.JmHomeworkCreate, token_data: schemas.TokenData = Depends(verify_users), db: Session = Depends(get_db)): return create_jm_homework_services(db, item) @router.get("/") @web_try() @sxtimeit def get_jm_homeworks(token_data: schemas.TokenData = Depends(verify_users), db: Session = Depends(get_db)): return crud.get_jm_homeworks(db, token_data.project_id) @router.get("/info") @web_try() @sxtimeit def get_jm_homework_info(homework_id: str, token_data: schemas.TokenData = Depends(verify_users), db: Session = Depends(get_db)): return crud.get_jm_homework_info(db, homework_id) @router.put("/") @web_try() @sxtimeit def update_jm_homework(jm_id: int, update_item: schemas.JmHomeworkUpdate, token_data: schemas.TokenData = Depends(verify_users), db: Session = Depends(get_db)): return update_jm_homework_service(db, jm_id, update_item) @router.delete("/") @web_try() @sxtimeit def delete_jm_homework(jm_id: int, token_data: schemas.TokenData = Depends(verify_users), db: Session = Depends(get_db)): jm_log_infos = crud.get_jm_job_infos(db) jm_job_ids = [jm_job.id for jm_job in jm_log_infos] res = crud.find_by_homework_and_job(db, jm_job_ids,jm_id) if len(res) > 0: raise Exception("该作业正在被定时任务使用,不可删除") return crud.delete_jm_homework(db, jm_id)