Reviewed-on: https://openi.pcl.ac.cn/OpenI/aiforge/pulls/3362 Reviewed-by: ychao_1983 <ychao_1983@sina.com>tags/v1.22.12.1^2
| @@ -221,6 +221,19 @@ func SaveModelToDb(model *AiModelManage) error { | |||||
| return nil | return nil | ||||
| } | } | ||||
| func QueryModelConvertByName(name string, repoId int64) ([]*AiModelConvert, error) { | |||||
| sess := x.NewSession() | |||||
| defer sess.Close() | |||||
| sess.Select("*").Table(new(AiModelConvert)). | |||||
| Where("name='" + name + "' and repo_id=" + fmt.Sprint(repoId)).OrderBy("created_unix desc") | |||||
| aiModelManageConvertList := make([]*AiModelConvert, 0) | |||||
| err := sess.Find(&aiModelManageConvertList) | |||||
| if err == nil { | |||||
| return aiModelManageConvertList, nil | |||||
| } | |||||
| return nil, err | |||||
| } | |||||
| func QueryModelConvertById(id string) (*AiModelConvert, error) { | func QueryModelConvertById(id string) (*AiModelConvert, error) { | ||||
| sess := x.NewSession() | sess := x.NewSession() | ||||
| defer sess.Close() | defer sess.Close() | ||||
| @@ -1021,6 +1021,7 @@ func RegisterRoutes(m *macaron.Macaron) { | |||||
| m.Delete("/delete_model", repo.DeleteModel) | m.Delete("/delete_model", repo.DeleteModel) | ||||
| m.Get("/downloadall", repo.DownloadModel) | m.Get("/downloadall", repo.DownloadModel) | ||||
| m.Get("/query_model_byId", repo.QueryModelById) | m.Get("/query_model_byId", repo.QueryModelById) | ||||
| m.Get("/query_model_byName", repo.QueryModelByName) | |||||
| m.Get("/query_model_for_predict", repo.QueryModelListForPredict) | m.Get("/query_model_for_predict", repo.QueryModelListForPredict) | ||||
| m.Get("/query_modelfile_for_predict", repo.QueryModelFileForPredict) | m.Get("/query_modelfile_for_predict", repo.QueryModelFileForPredict) | ||||
| m.Get("/query_train_model", repo.QueryTrainModelList) | m.Get("/query_train_model", repo.QueryTrainModelList) | ||||
| @@ -1028,6 +1029,7 @@ func RegisterRoutes(m *macaron.Macaron) { | |||||
| m.Post("/convert_stop", repo.StopModelConvert) | m.Post("/convert_stop", repo.StopModelConvert) | ||||
| m.Get("/show_model_convert_page", repo.ShowModelConvertPage) | m.Get("/show_model_convert_page", repo.ShowModelConvertPage) | ||||
| m.Get("/query_model_convert_byId", repo.QueryModelConvertById) | m.Get("/query_model_convert_byId", repo.QueryModelConvertById) | ||||
| m.Get("/query_model_convert_byName", repo.QueryModelConvertByName) | |||||
| m.Get("/:id", repo.GetCloudbrainModelConvertTask) | m.Get("/:id", repo.GetCloudbrainModelConvertTask) | ||||
| m.Get("/:id/log", repo.CloudbrainForModelConvertGetLog) | m.Get("/:id/log", repo.CloudbrainForModelConvertGetLog) | ||||
| @@ -43,6 +43,11 @@ func QueryModelById(ctx *context.APIContext) { | |||||
| routerRepo.QueryModelById(ctx.Context) | routerRepo.QueryModelById(ctx.Context) | ||||
| } | } | ||||
| func QueryModelByName(ctx *context.APIContext) { | |||||
| log.Info("QueryModelByName by api.") | |||||
| routerRepo.ShowSingleModel(ctx.Context) | |||||
| } | |||||
| func QueryModelListForPredict(ctx *context.APIContext) { | func QueryModelListForPredict(ctx *context.APIContext) { | ||||
| log.Info("QueryModelListForPredict by api.") | log.Info("QueryModelListForPredict by api.") | ||||
| ctx.Context.SetParams("isOnlyThisRepo", "true") | ctx.Context.SetParams("isOnlyThisRepo", "true") | ||||
| @@ -119,3 +124,12 @@ func QueryModelConvertById(ctx *context.APIContext) { | |||||
| ctx.JSON(http.StatusOK, nil) | ctx.JSON(http.StatusOK, nil) | ||||
| } | } | ||||
| } | } | ||||
| func QueryModelConvertByName(ctx *context.APIContext) { | |||||
| modelResult, err := routerRepo.GetModelConvertByName(ctx.Context) | |||||
| if err == nil { | |||||
| ctx.JSON(http.StatusOK, modelResult) | |||||
| } else { | |||||
| ctx.JSON(http.StatusOK, nil) | |||||
| } | |||||
| } | |||||
| @@ -758,6 +758,11 @@ func GetModelConvertById(ctx *context.Context) (*models.AiModelConvert, error) { | |||||
| return models.QueryModelConvertById(id) | return models.QueryModelConvertById(id) | ||||
| } | } | ||||
| func GetModelConvertByName(ctx *context.Context) ([]*models.AiModelConvert, error) { | |||||
| name := ctx.Query("name") | |||||
| return models.QueryModelConvertByName(name, ctx.Repo.Repository.ID) | |||||
| } | |||||
| func GetModelConvertPageData(ctx *context.Context) ([]*models.AiModelConvert, int64, error) { | func GetModelConvertPageData(ctx *context.Context) ([]*models.AiModelConvert, int64, error) { | ||||
| page := ctx.QueryInt("page") | page := ctx.QueryInt("page") | ||||
| if page <= 0 { | if page <= 0 { | ||||