123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- from re import S
- from typing import Optional
- from fastapi import APIRouter
- from fastapi import Depends
- from sqlalchemy.orm import Session
- from app import schemas
- from app.common.decorators import verify_all
- from app.common.hive import hiveDs
- from app.crud import jm_homework
- 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
- from fastapi_pagination import Page, add_pagination, paginate, Params
- import app.crud as crud
- from app import get_db
- from configs.globals import g
- from configs.settings import DefaultOption, config
- DATABASE_NAME = config.get('HIVE', 'DATABASE_NAME')
- router = APIRouter(
- prefix="/jpt/jm_homework",
- tags=["jm_homework-作业管理"],
- )
- @router.post("/", dependencies=[Depends(verify_all)])
- @web_try()
- @sxtimeit
- def create_jm_homework(item: schemas.JmHomeworkCreate, db: Session = Depends(get_db)):
- return create_jm_homework_services(db, item)
- @router.get("/", dependencies=[Depends(verify_all)])
- @web_try()
- @sxtimeit
- def get_jm_homeworks(db: Session = Depends(get_db)):
- return crud.get_jm_homeworks(db, g.project_id)
- @router.get("/info", dependencies=[Depends(verify_all)])
- @web_try()
- @sxtimeit
- def get_jm_homework_info(homework_id: str, db: Session = Depends(get_db)):
- return crud.get_jm_homework_info(db, homework_id)
- @router.put("/", dependencies=[Depends(verify_all)])
- @web_try()
- @sxtimeit
- def update_jm_homework(jm_id: int, update_item: schemas.JmHomeworkUpdate, db: Session = Depends(get_db)):
- return update_jm_homework_service(db, jm_id, update_item)
- @router.delete("/", dependencies=[Depends(verify_all)])
- @web_try()
- @sxtimeit
- def delete_jm_homework(jm_id: int, 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)
|