@@ -120,6 +120,12 @@ func GetTechConvergeBaseInfoByProjectNumber(projectNumber string) (*TechConverge | |||
tb := &TechConvergeBaseInfo{ProjectNumber: projectNumber} | |||
return getTechConvergeBaseInfo(tb) | |||
} | |||
func GetTechConvergeBaseInfoById(id int64) (*TechConvergeBaseInfo, error) { | |||
tb := &TechConvergeBaseInfo{ID: id} | |||
return getTechConvergeBaseInfo(tb) | |||
} | |||
func (baseInfo *TechConvergeBaseInfo) InsertOrUpdate() error { | |||
if baseInfo.ID != 0 { | |||
_, err := x.ID(baseInfo.ID).Update(baseInfo) | |||
@@ -313,6 +319,61 @@ type SearchRepoOpt struct { | |||
ListOptions | |||
} | |||
type SearchUserRepoOpt struct { | |||
User *User | |||
ListOptions | |||
} | |||
type TechRepoInfoUser struct { | |||
ID int64 `json:"id"` | |||
ProjectNumber string `json:"no"` | |||
ProjectName string `json:"name"` | |||
Institution string `json:"institution"` | |||
AllInstitution string `json:"all_institution"` | |||
Url string `json:"url"` | |||
RepoName string `json:"repo_name"` | |||
RepoOwnerName string `json:"repo_owner_name"` | |||
ContributionInstitution string `json:"contribution_institution"` | |||
UserName string `json:"user_name"` | |||
Status int `json:"status"` | |||
CreatedUnix timeutil.TimeStamp `json:"created_unix"` | |||
UpdatedUnix timeutil.TimeStamp `json:"updated_unix"` | |||
} | |||
type TechRepoInfoAdmin struct { | |||
ID int64 `json:"id"` | |||
Url string `json:"url"` | |||
ContributionInstitution string `json:"contribution_institution"` | |||
Status int `json:"status"` | |||
ProjectNumber string `json:"no"` | |||
ProjectName string `json:"name"` | |||
Institution string `json:"institution"` | |||
Province string `json:"province"` | |||
Category string `json:"category"` | |||
Recommend string `json:"recommend"` | |||
Owner string `json:"owner"` | |||
Phone string `json:"phone"` | |||
Email string `json:"email"` | |||
Contact string `json:"contact"` | |||
ContactPhone string `json:"contact_phone"` | |||
ContactEmail string `json:"contact_email"` | |||
ExecuteMonth int `json:"execute_month"` | |||
ExecutePeriod string `json:"execute_period"` | |||
Type string `json:"type"` | |||
StartUp string `json:"start_up"` | |||
NumberTopic int `json:"number_topic"` | |||
Topic1 string `json:"topic1"` | |||
Topic2 string `json:"topic2"` | |||
Topic3 string `json:"topic3"` | |||
Topic4 string `json:"topic4"` | |||
Topic5 string `json:"topic5"` | |||
AllInstitution string `json:"all_institution"` | |||
RepoName string `json:"repo_name"` | |||
RepoOwnerName string `json:"repo_owner_name"` | |||
UserName string `json:"user_name"` | |||
CreatedUnix timeutil.TimeStamp `json:"created_unix"` | |||
UpdatedUnix timeutil.TimeStamp `json:"updated_unix"` | |||
} | |||
type RepoWithInstitution struct { | |||
ID int64 `json:"id"` | |||
OwnerID int64 `json:"owner_id"` | |||
@@ -338,6 +399,64 @@ type TechRepoInfo struct { | |||
Repos []*RepoWithInstitution | |||
} | |||
func ShowTechRepo(ids []int64, show bool) error { | |||
status := TechShow | |||
if !show { | |||
status = TechHide | |||
} | |||
idStrs := make([]string, 0, len(ids)) | |||
for _, id := range ids { | |||
idStrs = append(idStrs, strconv.FormatInt(id, 10)) | |||
} | |||
sql := "update repo_converge_info set status=? where id in (" + strings.Join(idStrs, ",") + ")" | |||
_, err := x.Exec(sql, status) | |||
return err | |||
} | |||
func GetTechRepoInfoForUser(opts *SearchUserRepoOpt) ([]*RepoConvergeInfo, int64, error) { | |||
cond := buildTechRepoForUserCondition(opts) | |||
total, err := x.Where(cond).Count(new(RepoConvergeInfo)) | |||
if err != nil { | |||
return nil, 0, err | |||
} | |||
repoConvergeInfos := make([]*RepoConvergeInfo, 0) | |||
err = x.Where(cond).Limit(opts.PageSize, (opts.Page-1)*opts.PageSize).Desc("status").Find(&repoConvergeInfos) | |||
if err != nil { | |||
return nil, 0, err | |||
} | |||
loadAttributes(repoConvergeInfos) | |||
return repoConvergeInfos, total, nil | |||
} | |||
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.BaseInfo, _ = GetTechConvergeBaseInfoById(info.BaseInfoID) | |||
} | |||
} | |||
func buildTechRepoForUserCondition(opts *SearchUserRepoOpt) builder.Cond { | |||
var cond = builder.NewCond() | |||
if opts.User != nil { | |||
cond = cond.And(builder.Eq{"uid": opts.User.ID}) | |||
} | |||
return cond | |||
} | |||
func GetAvailableRepoConvergeInfo(opt *SearchRepoOpt) ([]*RepoConvergeInfo, error) { | |||
repos := make([]*RepoConvergeInfo, 0) | |||
@@ -358,7 +477,7 @@ func buildRepoFilterCond(opt *SearchRepoOpt) string { | |||
baseInfoIds := GetIdByProjectName(opt.ProjectName) | |||
if len(baseInfoIds) > 0 { | |||
sql += getPrefixWithoutWhere(sql) + " id in (" + strings.Join(baseInfoIds, ",") + ")" | |||
sql += getPrefixWithoutWhere(sql) + " base_info_id in (" + strings.Join(baseInfoIds, ",") + ")" | |||
} | |||
} | |||
@@ -3362,8 +3362,7 @@ process_image_fail=Fail to process image, please try again later. | |||
get_file_fail= Can not get the file content, please try again later. | |||
content_type_unsupported=The format of the file or file content is wrong. | |||
sql_err=Fail to process data, please try again later. | |||
[tech] | |||
show_or_hide_fail=Failed to %s the repo(s). | |||
incorrect_openi_format = The OpenI address format is incorrect | |||
openi_repo_not_exist = OpenI repository is not exists | |||
tech_not_exist = The project approval number does not exist | |||
@@ -3382,8 +3382,7 @@ process_image_fail=图片处理失败,请稍后再试。 | |||
get_file_fail= 获取上传文件失败。 | |||
content_type_unsupported=上传文件的格式有误。 | |||
sql_err=数据处理错误,请稍后再试。 | |||
[tech] | |||
show_or_hide_fail=%s失败。 | |||
incorrect_openi_format = 启智项目地址格式错误 | |||
openi_repo_not_exist = 启智项目不存在 | |||
tech_not_exist = 项目立项编号不存在 | |||
@@ -554,6 +554,9 @@ func RegisterRoutes(m *macaron.Macaron) { | |||
m.Get("/filter", tech.GetFilterInfo) | |||
m.Get("/search", tech.SearchTechProjectInfo) | |||
m.Get("/repo_search", tech.SearchRepoInfo) | |||
m.Get("/admin", tech.GetAdminRepoInfo) | |||
m.Get("/my", tech.GetMyRepoInfo) | |||
m.Post("/admin/:action", bind(tech.ActionIDs{}), tech.Action) | |||
m.Post("/openi", bind(api.OpenITechRepo{}), tech.CommitOpenIRepo) | |||
m.Post("/no_openi", bind(api.NotOpenITechRepo{}), tech.CommitNotOpenIRepo) | |||
m.Get("/is_admin", tech.IsAdmin) | |||
@@ -46,6 +46,79 @@ func GetFilterInfo(ctx *context.APIContext) { | |||
} | |||
func GetAdminRepoInfo(ctx *context.APIContext) { | |||
opts := &models.SearchUserRepoOpt{} | |||
page := ctx.QueryInt("page") | |||
if page <= 0 { | |||
page = 1 | |||
} | |||
opts.Page = page | |||
pageSize := ctx.QueryInt("pageSize") | |||
if pageSize <= 0 { | |||
pageSize = 15 | |||
} | |||
opts.PageSize = pageSize | |||
infos, total, err := techService.GetAdminRepoInfo(opts) | |||
if err != nil { | |||
log.Error("search has error", err) | |||
ctx.JSON(http.StatusOK, map[string]interface { | |||
}{"total": 0, "data": []*models.TechRepoInfoAdmin{}}) | |||
} else { | |||
ctx.JSON(http.StatusOK, map[string]interface { | |||
}{"total": total, "data": infos}) | |||
} | |||
} | |||
func Action(ctx *context.APIContext, ids ActionIDs) { | |||
if len(ids.ID) == 0 { | |||
ctx.JSON(http.StatusOK, models.BaseOKMessageApi) | |||
} | |||
var err error | |||
switch ctx.Params(":action") { | |||
case "show": | |||
err = models.ShowTechRepo(ids.ID, true) | |||
case "hide": | |||
err = models.ShowTechRepo(ids.ID, false) | |||
} | |||
if err != nil { | |||
ctx.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr("tech.show_or_hide_fail", ctx.Params(":action")))) | |||
} else { | |||
ctx.JSON(http.StatusOK, models.BaseOKMessage) | |||
} | |||
} | |||
type ActionIDs struct { | |||
ID []int64 `json:"id"` | |||
} | |||
func GetMyRepoInfo(ctx *context.APIContext) { | |||
opts := &models.SearchUserRepoOpt{} | |||
page := ctx.QueryInt("page") | |||
if page <= 0 { | |||
page = 1 | |||
} | |||
opts.Page = page | |||
pageSize := ctx.QueryInt("pageSize") | |||
if pageSize <= 0 { | |||
pageSize = 15 | |||
} | |||
opts.PageSize = pageSize | |||
opts.User = ctx.User | |||
infos, total, err := techService.GetMyRepoInfo(opts) | |||
if err != nil { | |||
log.Error("search has error", err) | |||
ctx.JSON(http.StatusOK, map[string]interface { | |||
}{"total": 0, "data": []*models.TechRepoInfoUser{}}) | |||
} else { | |||
ctx.JSON(http.StatusOK, map[string]interface { | |||
}{"total": total, "data": infos}) | |||
} | |||
} | |||
func SearchRepoInfo(ctx *context.APIContext) { | |||
opts := &models.SearchRepoOpt{} | |||
@@ -16,6 +16,98 @@ func FindTech(opt models.FindTechOpt) ([]*models.TechConvergeBrief, error) { | |||
} | |||
return r, nil | |||
} | |||
func GetMyRepoInfo(opts *models.SearchUserRepoOpt) ([]*models.TechRepoInfoUser, int64, error) { | |||
infos, total, err := models.GetTechRepoInfoForUser(opts) | |||
if err != nil { | |||
return nil, total, err | |||
} | |||
result := make([]*models.TechRepoInfoUser, 0, total) | |||
for _, info := range infos { | |||
techRepoInfoUser := &models.TechRepoInfoUser{ | |||
ID: info.ID, | |||
Url: info.Url, | |||
Status: info.Status, | |||
ContributionInstitution: info.Institution, | |||
CreatedUnix: info.CreatedUnix, | |||
UpdatedUnix: info.UpdatedUnix, | |||
} | |||
if info.User != nil { | |||
techRepoInfoUser.UserName = info.User.Name | |||
} | |||
if info.BaseInfo != nil { | |||
baseInfo := info.BaseInfo | |||
techRepoInfoUser.ProjectNumber = baseInfo.ProjectNumber | |||
techRepoInfoUser.ProjectName = baseInfo.ProjectName | |||
techRepoInfoUser.Institution = baseInfo.Institution | |||
techRepoInfoUser.AllInstitution = baseInfo.AllInstitution | |||
} | |||
if info.Repo != nil { | |||
techRepoInfoUser.RepoName = info.Repo.Name | |||
techRepoInfoUser.RepoOwnerName = info.Repo.OwnerName | |||
} | |||
result = append(result, techRepoInfoUser) | |||
} | |||
return result, total, nil | |||
} | |||
func GetAdminRepoInfo(opts *models.SearchUserRepoOpt) ([]*models.TechRepoInfoAdmin, int64, error) { | |||
infos, total, err := models.GetTechRepoInfoForUser(opts) | |||
if err != nil { | |||
return nil, total, err | |||
} | |||
result := make([]*models.TechRepoInfoAdmin, 0, total) | |||
for _, info := range infos { | |||
techRepoInfoAdmin := &models.TechRepoInfoAdmin{ | |||
ID: info.ID, | |||
Url: info.Url, | |||
Status: info.Status, | |||
ContributionInstitution: info.Institution, | |||
CreatedUnix: info.CreatedUnix, | |||
UpdatedUnix: info.UpdatedUnix, | |||
} | |||
if info.User != nil { | |||
techRepoInfoAdmin.UserName = info.User.Name | |||
} | |||
if info.BaseInfo != nil { | |||
baseInfo := info.BaseInfo | |||
techRepoInfoAdmin.ProjectNumber = baseInfo.ProjectNumber | |||
techRepoInfoAdmin.ProjectName = baseInfo.ProjectName | |||
techRepoInfoAdmin.Institution = baseInfo.Institution | |||
techRepoInfoAdmin.Province = baseInfo.Province | |||
techRepoInfoAdmin.Category = baseInfo.Category | |||
techRepoInfoAdmin.Owner = baseInfo.Owner | |||
techRepoInfoAdmin.Recommend = baseInfo.Recommend | |||
techRepoInfoAdmin.Phone = baseInfo.Phone | |||
techRepoInfoAdmin.Email = baseInfo.Email | |||
techRepoInfoAdmin.Contact = baseInfo.Contact | |||
techRepoInfoAdmin.ContactPhone = baseInfo.ContactPhone | |||
techRepoInfoAdmin.ContactEmail = baseInfo.ContactEmail | |||
techRepoInfoAdmin.ExecuteMonth = baseInfo.ExecuteMonth | |||
techRepoInfoAdmin.ExecutePeriod = baseInfo.ExecutePeriod | |||
techRepoInfoAdmin.Type = baseInfo.Type | |||
techRepoInfoAdmin.StartUp = baseInfo.StartUp | |||
techRepoInfoAdmin.NumberTopic = baseInfo.NumberTopic | |||
techRepoInfoAdmin.Topic1 = baseInfo.Topic1 | |||
techRepoInfoAdmin.Topic2 = baseInfo.Topic2 | |||
techRepoInfoAdmin.Topic3 = baseInfo.Topic3 | |||
techRepoInfoAdmin.Topic4 = baseInfo.Topic4 | |||
techRepoInfoAdmin.Topic5 = baseInfo.Topic5 | |||
techRepoInfoAdmin.AllInstitution = baseInfo.AllInstitution | |||
} | |||
if info.Repo != nil { | |||
techRepoInfoAdmin.RepoName = info.Repo.Name | |||
techRepoInfoAdmin.RepoOwnerName = info.Repo.OwnerName | |||
} | |||
result = append(result, techRepoInfoAdmin) | |||
} | |||
return result, total, nil | |||
} | |||
func SearchRepoInfoWithInstitution(opt *models.SearchRepoOpt) ([]*models.RepoWithInstitution, int64, error) { | |||
infos, err := models.GetAvailableRepoConvergeInfo(opt) | |||
@@ -43,6 +135,7 @@ func SearchRepoInfoWithInstitution(opt *models.SearchRepoOpt) ([]*models.RepoWit | |||
OwnerID: repo.OwnerID, | |||
OwnerName: repo.OwnerName, | |||
Name: repo.Name, | |||
Alias: repo.Alias, | |||
Topics: repo.Topics, | |||
Description: repo.Description, | |||
Institution: institutionMap[repo.ID], | |||