| @@ -437,14 +437,7 @@ func GetTechRepoInfoForUser(opts *SearchUserRepoOpt) ([]*RepoConvergeInfo, int64 | |||
| func loadAttributes(infos []*RepoConvergeInfo) { | |||
| for _, info := range infos { | |||
| info.User, _ = GetUserByID(info.UID) | |||
| var err error | |||
| info.Repo, err = GetRepositoryByID(info.RepoID) | |||
| if err != nil && IsErrRepoNotExist(err) { | |||
| //不存在的项目更新状态为不存在 | |||
| info.Status = TechNotExist | |||
| x.ID(info.ID).Cols("status").Update(info) | |||
| } | |||
| info.Repo, _ = GetRepositoryByID(info.RepoID) | |||
| info.BaseInfo, _ = GetTechConvergeBaseInfoById(info.BaseInfoID) | |||
| } | |||
| } | |||
| @@ -467,17 +460,17 @@ func GetAvailableRepoConvergeInfo(opt *SearchRepoOpt) ([]*RepoConvergeInfo, erro | |||
| func buildRepoFilterCond(opt *SearchRepoOpt) string { | |||
| sql := "" | |||
| sql := "status=" + strconv.Itoa(TechShow) | |||
| if opt.Institution != "" { | |||
| sql += getPrefixWithoutWhere(sql) + " (institution like '%" + opt.Institution + ",%'" + " or institution like '%," + opt.Institution + "%'" + " or institution = '" + opt.Institution + "')" | |||
| sql += " and (institution like '%" + opt.Institution + ",%'" + " or institution like '%," + opt.Institution + "%'" + " or institution = '" + opt.Institution + "')" | |||
| } | |||
| if opt.ProjectName != "" { | |||
| baseInfoIds := GetIdByProjectName(opt.ProjectName) | |||
| if len(baseInfoIds) > 0 { | |||
| sql += getPrefixWithoutWhere(sql) + " base_info_id in (" + strings.Join(baseInfoIds, ",") + ")" | |||
| sql += " and base_info_id in (" + strings.Join(baseInfoIds, ",") + ")" | |||
| } | |||
| } | |||
| @@ -552,13 +545,6 @@ func getWherePrefix(sql string) string { | |||
| return " and " | |||
| } | |||
| func getPrefixWithoutWhere(sql string) string { | |||
| if sql == "" { | |||
| return "" | |||
| } | |||
| return " and " | |||
| } | |||
| func loadRepoInfoForTech(list []*TechRepoInfo) { | |||
| for _, techRepo := range list { | |||
| @@ -47,6 +47,7 @@ func GetFilterInfo(ctx *context.APIContext) { | |||
| } | |||
| func GetAdminRepoInfo(ctx *context.APIContext) { | |||
| go techService.UpdateTechStatus() | |||
| opts := &models.SearchUserRepoOpt{} | |||
| page := ctx.QueryInt("page") | |||
| if page <= 0 { | |||
| @@ -95,6 +96,7 @@ type ActionIDs struct { | |||
| } | |||
| func GetMyRepoInfo(ctx *context.APIContext) { | |||
| go techService.UpdateTechStatus() | |||
| opts := &models.SearchUserRepoOpt{} | |||
| page := ctx.QueryInt("page") | |||
| if page <= 0 { | |||
| @@ -120,7 +122,7 @@ func GetMyRepoInfo(ctx *context.APIContext) { | |||
| } | |||
| func SearchRepoInfo(ctx *context.APIContext) { | |||
| go techService.UpdateTechStatus() | |||
| opts := &models.SearchRepoOpt{} | |||
| opts.Q = ctx.Query("name") | |||
| opts.ProjectName = ctx.Query("tech_name") | |||
| @@ -151,7 +153,7 @@ func SearchRepoInfo(ctx *context.APIContext) { | |||
| } | |||
| func SearchTechProjectInfo(ctx *context.APIContext) { | |||
| go techService.UpdateTechStatus() | |||
| opts := &models.SearchTechOpt{} | |||
| opts.Q = ctx.Query("name") | |||
| opts.ApplyYear = ctx.QueryInt("apply_year") | |||
| @@ -2,6 +2,7 @@ package tech | |||
| import ( | |||
| "code.gitea.io/gitea/models" | |||
| "code.gitea.io/gitea/modules/log" | |||
| "code.gitea.io/gitea/services/repository" | |||
| ) | |||
| @@ -114,6 +115,9 @@ func SearchRepoInfoWithInstitution(opt *models.SearchRepoOpt) ([]*models.RepoWit | |||
| if err != nil { | |||
| return nil, 0, err | |||
| } | |||
| if len(infos) == 0 { | |||
| return []*models.RepoWithInstitution{}, 0, nil | |||
| } | |||
| repoIds, institutionMap := getRepoIdAndInstitutionMap(infos) | |||
| result, err := repository.FindRepos(repository.FindReposOptions{ | |||
| @@ -172,6 +176,38 @@ func IsValidRepoConvergeExists(repoId, baseInfoId int64) (bool, error) { | |||
| return len(list) > 0, nil | |||
| } | |||
| func UpdateTechStatus() { | |||
| err := UpdateTechRepoDeleteStatus() | |||
| if err != nil { | |||
| log.Error("update delete status fail", err) | |||
| } | |||
| err = UpdateTechMigrateStatus() | |||
| if err != nil { | |||
| log.Error("update migrate status fail", err) | |||
| } | |||
| } | |||
| func UpdateTechRepoDeleteStatus() error { | |||
| needDeleteCheckRepos, err := models.GetRepoConverge(models.GetRepoConvergeOpts{ | |||
| Status: []int{models.TechShow, models.TechHide}, | |||
| }) | |||
| if err != nil { | |||
| return err | |||
| } | |||
| for _, r := range needDeleteCheckRepos { | |||
| _, err := models.GetRepositoryByID(r.RepoID) | |||
| if err != nil && models.IsErrRepoNotExist(err) { | |||
| models.UpdateRepoConvergeStatus(r.ID, models.TechNotExist) | |||
| continue | |||
| } | |||
| } | |||
| return nil | |||
| } | |||
| func UpdateTechMigrateStatus() error { | |||
| migratingRepos, err := models.GetRepoConverge(models.GetRepoConvergeOpts{ | |||
| Status: []int{models.TechMigrating}, | |||