def get_or_create_upgrade_record(self, tenant_id, group_id, group_key, upgrade_group_id, is_from_cloud, market_name): """获取或创建升级记录""" recode_kwargs = { "tenant_id": tenant_id, "group_id": group_id, "group_key": group_key, "create_time": datetime.now(), "is_from_cloud": is_from_cloud, "market_name": market_name, "upgrade_group_id": upgrade_group_id, } try: return upgrade_repo.get_app_not_upgrade_record(status__lt=UpgradeStatus.UPGRADED.value, **recode_kwargs) except AppUpgradeRecord.DoesNotExist: from console.services.group_service import group_service tenant = Tenants.objects.get(tenant_id=tenant_id) service_group_keys = group_service.get_group_service_sources(group_id).values_list('group_key', flat=True) if group_key in set(service_group_keys or []): if not is_from_cloud: app = rainbond_app_repo.get_rainbond_app_qs_by_key(tenant.enterprise_id, group_key) if not app: raise ServiceHandleException( msg="the rainbond app is not in the group", msg_show="该应用中没有这个云市组件", status_code=404) app_name = app.app_name else: market = app_market_service.get_app_market_by_name(tenant.enterprise_id, market_name, raise_exception=True) app = app_market_service.get_market_app_model(market, group_key) app_name = app.app_name app_record = upgrade_repo.create_app_upgrade_record(group_name=app_name, **recode_kwargs) return app_record else: raise AbortRequest(msg="the app model is not in the group", msg_show="该应用中没有这个应用模型", status_code=404)
def get(self, request, team_name, group_id, *args, **kwargs): data = [] market = dict() cloud_app = dict() page = int(request.GET.get("page", 1)) page_size = int(request.GET.get("page_size", 10)) total, share_records = share_repo.get_service_share_records_by_groupid( team_name=team_name, group_id=group_id, page=page, page_size=page_size) if not share_records: result = general_message(200, "success", "获取成功", bean={'total': total}, list=data) return Response(result, status=200) for share_record in share_records: app_model_name = share_record.share_app_model_name app_model_id = share_record.app_id upgrade_time = None store_name = share_record.share_store_name store_id = share_record.share_app_market_name scope = share_record.scope if scope != "goodrain" and not app_model_name: app = rainbond_app_repo.get_rainbond_app_by_app_id(self.tenant.enterprise_id, share_record.app_id) app_model_name = app.app_name if app else "" app_version = rainbond_app_repo.get_rainbond_app_version_by_record_id(share_record.ID) if app_version: upgrade_time = app_version.upgrade_time share_record.share_version_alias = app_version.version_alias share_record.share_app_version_info = app_version.app_version_info share_record.share_app_model_name = app_model_name share_record.save() if scope == "goodrain" and store_id and share_record.app_id and not app_model_name: try: mkt = market.get(share_record.share_app_market_name, None) if not mkt: mkt = app_market_service.get_app_market_by_name( self.tenant.enterprise_id, share_record.share_app_market_name, raise_exception=True) market[share_record.share_app_market_name] = mkt c_app = cloud_app.get(share_record.app_id, None) if not c_app: c_app = app_market_service.get_market_app_model(mkt, share_record.app_id, True) cloud_app[share_record.app_id] = c_app store_name = c_app.market_name app_model_name = c_app.app_name share_record.share_app_model_name = app_model_name share_record.share_store_name = store_name share_record.save() except ServiceHandleException: app_model_id = share_record.app_id data.append({ "app_model_id": app_model_id, "app_model_name": app_model_name, "version": share_record.share_version, "version_alias": share_record.share_version_alias, "scope": scope, "create_time": share_record.create_time, "upgrade_time": upgrade_time, "step": share_record.step, "is_success": share_record.is_success, "status": share_record.status, "scope_target": { "store_name": store_name, "store_id": store_id, }, "record_id": share_record.ID, "app_version_info": share_record.share_app_version_info, }) result = general_message(200, "success", "获取成功", bean={'total': total}, list=data) return Response(result, status=200)
def get(self, request, team_name, group_id, *args, **kwargs): data = [] share_records = share_repo.get_service_share_records_by_groupid( group_id=group_id) if share_records: for share_record in share_records: app_model_name = None app_model_id = None version_alias = None upgrade_time = None # todo get store name store_name = None store_id = share_record.share_app_market_name scope = share_record.scope app = rainbond_app_repo.get_rainbond_app_by_app_id( self.tenant.enterprise_id, share_record.app_id) if app: app_model_id = share_record.app_id app_model_name = app.app_name app_version = rainbond_app_repo.get_rainbond_app_version_by_record_id( share_record.ID) if app_version: version_alias = app_version.version_alias upgrade_time = app_version.upgrade_time else: try: if store_id and share_record.app_id: market = app_market_service.get_app_market_by_name( self.tenant.enterprise_id, share_record.share_app_market_name, raise_exception=True) cloud_app = app_market_service.get_market_app_model( market, share_record.app_id) if cloud_app: app_model_id = share_record.app_id app_model_name = cloud_app.app_name except ServiceHandleException: app_model_id = share_record.app_id data.append({ "app_model_id": app_model_id, "app_model_name": app_model_name, "version": share_record.share_version, "version_alias": (share_record.share_version_alias if share_record.share_version_alias else version_alias), "scope": scope, "create_time": share_record.create_time, "upgrade_time": upgrade_time, "step": share_record.step, "is_success": share_record.is_success, "status": share_record.status, "scope_target": { "store_name": store_name, "store_id": store_id, }, "record_id": share_record.ID, }) result = general_message(200, "success", None, list=data) return Response(result, status=200)