async def update_task(project_id: int = Body(..., embed=True),
                      list_id: int = Body(..., embed=True),
                      title: str = Body(..., embed=True),
                      token_user: TokenUser = Depends(auth_token)) -> BaseRes:
    _, error = verify_project_filed(project_id)
    if error:
        return error
    _, error = verify_project_member(token_user.user_id, project_id)
    if error:
        return error
    try:
        exists_condition = [
            AtpOverviewList.is_delete == 2,
            AtpOverviewList.project_id == project_id,
            AtpOverviewList.title == title, AtpOverviewList.id != list_id
        ]
        count = Db.select_count_by_condition(AtpOverviewList.id,
                                             exists_condition)
        if count != 0:
            return BaseRes(status=0, error='任务栏标题已存在')
        condition = [
            AtpOverviewList.id == list_id,
            AtpOverviewList.is_delete == 2,
        ]
        Db.update_by_condition(
            AtpOverviewList, condition, {
                AtpOverviewList.title: title,
                AtpOverviewList.updator: token_user.user_id,
                AtpOverviewList.update_time: datetime.datetime.now()
            })
        return BaseRes()
    except Exception as e:
        logger.error(traceback.format_exc())
        return BaseRes(status=0, error=str(e))
async def get_project_progress(project_id: int = Query(...)) -> BaseRes:
    _, error = verify_project_deleted(project_id)
    if error:
        return error
    try:
        finish_count = Db.select_count_by_condition(AtpOverviewTask.id, [
            AtpOverviewTask.is_delete == 2, AtpOverviewTask.project_id
            == project_id, AtpOverviewTask.status == 1
        ])
        total_count = Db.select_count_by_condition(AtpOverviewTask.id, [
            AtpOverviewTask.is_delete == 2,
            AtpOverviewTask.project_id == project_id,
        ])
        return BaseRes(data={'total': total_count, 'finish': finish_count})
    except Exception as e:
        logger.error(traceback.format_exc())
        return BaseRes(status=0, error=str(e))
Example #3
0
async def get_workstation_projects(token_user: TokenUser = Depends(
    auth_token)) -> BaseRes:
    try:
        project_list: List[AtpProject] = Db.select_by_condition(
            AtpProject, [AtpProject.type == 1, AtpProject.is_delete == 2],
            AtpProject.create_time.desc())
        parted_project_list = []
        for project in project_list:
            is_part_in = Db.select_by_condition(
                AtpProjectMember,
                [
                    AtpProjectMember.is_delete == 2,
                    AtpProjectMember.project_id == project.id,
                    AtpProjectMember.member_id.in_([token_user.user_id])
                ],
            )
            if is_part_in:
                parted_project_list.append(project)
            if project.img:
                file: AtpFileSystemFile = Db.select_by_primary_key(
                    AtpFileSystemFile, project.img)
                project.img = {
                    'id': file.id,
                    'url': get_settings().archive_host + file.name
                }
            else:
                project.img = {
                    'id':
                    0,
                    'url':
                    'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png'
                }
        session = Db.get_session()
        report_list: List[AtpProjectTestReport] = session.query(
            AtpProjectTestReport).join(
                AtpProject,
                AtpProject.id == AtpProjectTestReport.project_id).filter(
                    AtpProjectTestReport.is_delete == 2,
                    AtpProjectTestReport.creator == token_user.user_id,
                    AtpProject.is_delete == 2).limit(10).all()
        total_projects_num = Db.select_count_by_condition(
            AtpProject.id, [AtpProject.is_delete == 2])
        return BaseRes(
            data={
                'underway_projects': project_list[:6],
                'parted_projects': parted_project_list[:6],
                'my_reports': report_list,
                'total_projects_num': total_projects_num,
                'total_underway_projects_num': len(project_list)
            })
    except Exception as e:
        logger.error(e)
        return BaseRes(status=0, error=str(e))
Example #4
0
async def get_api_case_by_condition(
        project_id: int = Query(...),
        suite_id: int = Query(...),
        page_num: int = Query(...),
        page_size: int = Query(...),
        type: int = Query(...),
        keyword: Optional[str] = Query(None)
) -> BaseRes:
    _, error = verify_project_deleted(project_id)
    if error:
        return error
    try:
        if page_num == 0 and page_size == 0:
            offset = None
            limit = None
        else:
            offset = page_size * (page_num - 1)
            limit = page_size
        condition_list: list = [
            AtpProjectApiCase.is_delete == 2,
            AtpProjectApiCase.project_id == project_id,
            AtpProjectApiCase.suite_id == suite_id
        ]
        if keyword and keyword != '':
            condition_list.append(AtpProjectApiCase.name.like(f'%{keyword}%'))
        if type in [1, 2]:
            condition_list.append(AtpProjectApiCase.method == type)
        api_case_list: List[AtpProjectApiCase] = Db.select_by_condition(
            AtpProjectApiCase,
            condition_list,
            AtpProjectApiCase.id,
            offset,
            limit
        )
        total: int = Db.select_count_by_condition(AtpProjectApiCase.id, condition_list)
        res_list: list = []
        order_id = page_size * (page_num - 1)
        for item in api_case_list:
            item_dict: dict = {}
            order_id += 1
            item_dict.setdefault('id', item.id)
            item_dict.setdefault('order_id', order_id)
            item_dict.setdefault('name', item.name)
            item_dict.setdefault('method', item.method)
            item_dict.setdefault('is_use_env', item.is_use_env)
            item_dict.setdefault('env_host', item.env_host)
            item_dict.setdefault('request_url', item.request_url)
            item_dict.setdefault('request_headers', json.loads(item.request_headers))
            item_dict.setdefault('request_query', json.loads(item.request_query))
            item_dict.setdefault('request_body', item.request_body)
            item_dict.setdefault('suite_id', item.suite_id)
            if item.is_use_env:
                if item.env_host:
                    env: AtpProjectEnv = Db.select_by_primary_key(AtpProjectEnv, item.env_host)
                    item_dict.setdefault('real_host', env.host)
                else:
                    item_dict.setdefault('real_host', None)
            else:
                item_dict.setdefault('real_host', None)
            res_list.append(item_dict)
        return BaseRes(data={'data': res_list, 'total': total})
    except Exception as e:
        logger.error(traceback.format_exc())
        return BaseRes(status=0, error=str(e))