def post(self, request): """ 新增接口 :param request: :return: """ data=request.data result = self.parameter_check(data) if result: return result data["userUpdate"] = request.user.pk data["params"]="{}" if not "params" in data or not data["params"] else data["params"] api_name = ApiInfo.objects.filter(name=data["name"], project=data["project_id"]) if len(api_name): return JsonResponse(code="999997", msg="存在相同名称!") else: result=ApiService.addApi(data) if result: record_dynamic(project=data["project_id"], _type="新增", operationObject="接口", user=request.user.pk, data="新增接口“%s”" % data["name"]) api_record = ApiOperationHistory(api=ApiInfo.objects.get(id=result["id"]), user=User.objects.get(id=request.user.pk), description="新增接口“%s”" % data["name"]) api_record.save() return JsonResponse(code="999999", msg="执行成功!", data={"api_id": result["id"]}) else: return JsonResponse(code="999996", msg="执行失败!")
def run(self): try: start = time.clock() for apiInfo in self.apiInfoList: if "id" in apiInfo: ApiService.updateApi(apiInfo) else: ApiService.addApi(apiInfo) duration = int(time.clock() - start) print("导入%s分组共%s个接口,耗时%s秒!" % (self.toGroupName, len(self.apiInfoList), duration)) record_dynamic(project=self.projectId, _type="导入", operationObject="接口", user=self.userId, data="导入%s分组共%s个接口,耗时%s秒!" % (self.toGroupName, len(self.apiInfoList), duration)) except: logging.error(traceback.format_exc())