Преглед изворни кода

新增我的申请访谈接口

rdluck пре 4 година
родитељ
комит
ac6c31bbc9
2 измењених фајлова са 101 додато и 0 уклоњено
  1. 80 0
      controllers/user.go
  2. 21 0
      models/user.go

+ 80 - 0
controllers/user.go

@@ -350,3 +350,83 @@ func (this *UserController) CollectList() {
 	br.Success = true
 	br.Data = resp
 }
+
+
+// @Title 获取申请访谈列表
+// @Description 获取申请访谈列表
+// @Param   PageSize    query   int true       "PageSize"
+// @Param   CurrentIndex    query   int true       "CurrentIndex"
+// @Success 200 {object} models.ArticleInterviewApplyListResp
+// @router /interview/apply/list [get]
+func (this *UserController) InterviewApplyList() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	userId := this.User.UserId
+	var pageSize, currentIndex, startSize int
+	pageSize, _ = this.GetInt("PageSize")
+	currentIndex, _ = this.GetInt("CurrentIndex")
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	startSize = utils.StartIndex(currentIndex, pageSize)
+
+	total, err := models.GetArticleUserInterviewApplyCount(userId)
+	if err != nil {
+		br.Msg = "获取数据失败"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+	list, err := models.GetArticleUserInterviewApplyList(startSize, pageSize, userId)
+	if err != nil {
+		br.Msg = "获取数据失败"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+	var articleIds []string
+	for _, v := range list {
+		articleIds = append(articleIds, strconv.Itoa(v.ArticleId))
+	}
+	articleIdStr := strings.Join(articleIds, ",")
+	articleMap := make(map[int]*models.ArticleDetail)
+	if articleIdStr != "" {
+		articleList, err := models.GetArticleDetailByIdStr(articleIdStr)
+		if err != nil {
+			br.Msg = "获取数据失败"
+			br.ErrMsg = "获取报告详情信息失败,Err:" + err.Error()
+			return
+		}
+		for _, v := range articleList {
+			if _, ok := articleMap[v.ArticleId]; !ok {
+				articleMap[v.ArticleId] = v
+			}
+		}
+	}
+	lenList := len(list)
+	for i := 0; i < lenList; i++ {
+		item := list[i]
+		article := articleMap[item.ArticleId]
+		list[i].Title = article.Title
+		list[i].TitleEn = article.TitleEn
+		list[i].UpdateFrequency = article.UpdateFrequency
+		list[i].CreateDate = article.CreateDate
+		list[i].PublishDate = article.PublishDate
+		list[i].Body, _ = services.GetReportContentTextSub(article.Body)
+		list[i].Abstract = article.Abstract
+		list[i].CategoryName = article.CategoryName
+		list[i].SubCategoryName = article.SubCategoryName
+	}
+	page := paging.GetPaging(currentIndex, pageSize, total)
+	resp := new(models.ArticleInterviewApplyListResp)
+	resp.List = list
+	resp.Paging = page
+	br.Msg = "获取成功!"
+	br.Ret = 200
+	br.Success = true
+	br.Data = resp
+}

+ 21 - 0
models/user.go

@@ -162,4 +162,25 @@ func GetArticleUserCollectList(startSize, pageSize, userId int) (items []*Articl
 type ArticleCollectListResp struct {
 	List   []*ArticleCollectList
 	Paging *paging.PagingItem
+}
+
+
+
+func GetArticleUserInterviewApplyCount(userId int) (count int, err error) {
+	sql := `SELECT COUNT(1) AS count FROM cygx_interview_apply AS a WHERE a.user_id=? `
+	err = orm.NewOrm().Raw(sql,userId).QueryRow(&count)
+	return
+}
+
+func GetArticleUserInterviewApplyList(startSize, pageSize, userId int) (items []*ArticleInterviewApplyList, err error) {
+	sql := `SELECT a.* FROM cygx_interview_apply AS a
+			WHERE a.user_id=? 
+           ORDER BY a.sort ASC LIMIT ?,? `
+	_, err = orm.NewOrm().Raw(sql, userId, startSize, pageSize).QueryRows(&items)
+	return
+}
+
+type ArticleInterviewApplyListResp struct {
+	List   []*ArticleInterviewApplyList
+	Paging *paging.PagingItem
 }