ziwen 2 jaren geleden
bovenliggende
commit
16ee4998e3
6 gewijzigde bestanden met toevoegingen van 467 en 0 verwijderingen
  1. 261 0
      controllers/user.go
  2. 78 0
      models/activity_help_ask.go
  3. 70 0
      models/article_comment.go
  4. 16 0
      models/user.go
  5. 27 0
      routers/commentsRouter.go
  6. 15 0
      utils/common.go

+ 261 - 0
controllers/user.go

@@ -816,4 +816,265 @@ func (this *UserController) CollectList() {
 	br.Ret = 200
 	br.Success = true
 	br.Data = resp
+}
+
+
+// @Title 获取我的留言
+// @Description 获取我的留言列表
+// @Success 200 {object} models.CygxCommentListResp
+// @router /comment/list [get]
+func (this *UserController) CommnetList() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,用户信息为空"
+		br.Ret = 408
+		return
+	}
+
+	userId := this.User.UserId
+	commentlist, err := models.GetCommentList(userId)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取我的留言列表失败,Err:" + err.Error()
+		return
+	}
+
+	resp := new(models.CygxCommentListResp)
+
+	for _, comment := range commentlist {
+		item := models.CygxArticleCommentResp{
+			Id:          comment.Id,
+			UserId:      comment.UserId,
+			ArticleId:   comment.ArticleId,
+			IndustryId:  comment.IndustryId,
+			ActivityId:  comment.ActivityId,
+			CreateTime:  comment.CreateTime,
+			Mobile:      comment.Mobile,
+			Email:       comment.Email,
+			CompanyId:   comment.CompanyId,
+			CompanyName: comment.CompanyName,
+			Content:     comment.Content,
+			Title:       comment.Title,
+		}
+		if comment.ArticleId > 0 {
+			item.RedirectType = 1
+		} else if comment.IndustryId > 0 {
+			item.RedirectType = 3
+		} else if comment.ActivityId > 0 {
+			item.RedirectType = 2
+		}
+		resp.List = append(resp.List, &item)
+	}
+
+	br.Msg = "获取成功!"
+	br.Ret = 200
+	br.Success = true
+	br.Data = resp
+}
+
+// @Title 获取浏览历史列表
+// @Description 获取浏览历史列表
+// @Param   PageSize    query   int true       "PageSize"
+// @Param   CurrentIndex    query   int true       "CurrentIndex"
+// @Success 200 {object} models.ArticleBrowseHistoryListResp
+// @router /browse/history/list [get]
+func (this *UserController) BrowseHistoryList() {
+	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)
+
+	endDate := time.Now().AddDate(0, -1, 0).Format(utils.FormatDate)
+	total, err := models.GetArticleUserBrowseHistoryCount(userId, endDate)
+	if err != nil {
+		br.Msg = "获取数据失败"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+	list, err := models.GetArticleUserBrowseHistoryList(startSize, pageSize, userId, endDate)
+	if err != nil {
+		br.Msg = "获取数据失败"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+	resp := new(models.ArticleReportBillboardLIstPageResp)
+	if len(list) == 0 {
+		page := paging.GetPaging(currentIndex, pageSize, total)
+		resp.List = list
+		resp.Paging = page
+		br.Msg = "获取成功!"
+		br.Ret = 200
+		br.Success = true
+		br.Data = resp
+		return
+	}
+
+	var articleIds []string
+	var condition string
+	var pars []interface{}
+	for _, v := range list {
+		articleIds = append(articleIds, strconv.Itoa(v.ArticleId))
+	}
+	articleIdStr := strings.Join(articleIds, ",")
+
+	//获取文章关联的产业
+	pars = make([]interface{}, 0)
+	condition = ` AND mg.article_id IN (  ` + utils.GetOrmInReplace(len(articleIds)) + ` )  `
+	pars = append(pars, articleIds)
+	industrialList, err := models.GetIndustrialListByarticleId(pars, condition)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,GetSubjectList Err:" + err.Error()
+		return
+	}
+	industrialMap := make(map[int][]*models.IndustrialManagementIdInt)
+	if len(industrialList) > 0 {
+		for _, v := range industrialList {
+			item := new(models.IndustrialManagementIdInt)
+			item.ArticleId = v.ArticleId
+			if v.ArticleId > utils.SummaryArticleId {
+				item.IsResearch = true
+			}
+			item.IndustrialManagementId = v.IndustrialManagementId
+			item.IndustryName = v.IndustryName
+			industrialMap[v.ArticleId] = append(industrialMap[v.ArticleId], item)
+		}
+	}
+	for k, v := range list {
+		if len(industrialMap[v.ArticleId]) > 0 {
+			list[k].List = industrialMap[v.ArticleId]
+		} else {
+			list[k].List = make([]*models.IndustrialManagementIdInt, 0)
+		}
+	}
+
+	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
+			}
+		}
+	}
+
+	//处理文章PV收藏等数量
+	mapArticleCollectNum := make(map[int]*models.CygxArticleNum)
+	if len(articleIds) > 0 {
+		articleCollectNumList, err := models.GetArticleCollectNum(articleIds, userId)
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取失败,GetArticleCollectNum Err:" + err.Error()
+			return
+		}
+		for _, v := range articleCollectNumList {
+			mapArticleCollectNum[v.ArticleId] = v
+		}
+	}
+
+	lenList := len(list)
+	for i := 0; i < lenList; i++ {
+		item := list[i]
+		article := articleMap[item.ArticleId]
+		if article != nil {
+			list[i].Title = article.Title
+			list[i].PublishDate = utils.TimeRemoveHms2(article.PublishDate)
+			list[i].DepartmentId = article.DepartmentId
+			list[i].NickName = article.NickName
+			if article.ArticleId < utils.SummaryArticleId {
+				list[i].Source = 1
+			} else {
+				list[i].Source = 2
+			}
+
+			if mapArticleCollectNum[article.ArticleId] != nil {
+				list[i].CollectNum = mapArticleCollectNum[article.ArticleId].CollectNum
+				list[i].Pv = mapArticleCollectNum[article.ArticleId].Pv
+				list[i].IsCollect = mapArticleCollectNum[article.ArticleId].IsCollect
+			}
+			//list[i].TitleEn = article.TitleEn
+			//list[i].UpdateFrequency = article.UpdateFrequency
+			//list[i].CreateDate = article.CreateDate
+			//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.List = list
+	resp.Paging = page
+	br.Msg = "获取成功!"
+	br.Ret = 200
+	br.Success = true
+	br.Data = resp
+}
+
+// @Title 获取我的提问
+// @Description 获取我的提问列表
+// @Success 200 {object} models.CygxAskListResp
+// @router /ask/list [get]
+func (this *UserController) AskList() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,用户信息为空"
+		br.Ret = 408
+		return
+	}
+	userId := this.User.UserId
+	listActcivity, err := models.GetActivityAskList(userId)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取活动问题失败,Err:" + err.Error()
+		return
+	}
+	for _, v := range listActcivity {
+		v.AskType = "Activity"
+	}
+	listArticle, err := models.GetArticleAskList(userId)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取文章问题失败,Err:" + err.Error()
+		return
+	}
+	for _, v := range listArticle {
+		v.AskType = "Report"
+		listActcivity = append(listActcivity, v)
+	}
+	resp := new(models.CygxAskListResp)
+	resp.List = listActcivity
+	br.Msg = "获取成功!"
+	br.Ret = 200
+	br.Success = true
+	br.Data = resp
 }

+ 78 - 0
models/activity_help_ask.go

@@ -0,0 +1,78 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxActivityHelpAsk struct {
+	AskId       int       `orm:"column(ask_id);pk" description:"带问id"`
+	UserId      int       `description:"用户id"`
+	ActivityId  int       `description:"活动id"`
+	CreateTime  time.Time `description:"创建时间"`
+	Mobile      string    `description:"手机号"`
+	Email       string    `description:"邮箱"`
+	CompanyId   int       `description:"公司id"`
+	CompanyName string    `description:"公司名称"`
+	Content     string    `description:"内容"`
+}
+
+//添加优化建议
+func AddActivityHelpAsk(item *CygxActivityHelpAsk) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}
+
+type AddCygxActivityHelpAsk struct {
+	ActivityId int    `description:"活动id"`
+	Content    string `description:"内容"`
+}
+
+type CygxAskList struct {
+	ReportOrActivityId int    ` description:"对应的文章或者活动Id"`
+	Title              string `description:"标题"`
+	Content            string `description:"内容"`
+	AskType            string `description:"类型 Activity 活动 、Report 文章报告"`
+	CreateTime         string `description:"创建时间"`
+}
+
+type CygxAskListResp struct {
+	List []*CygxAskList
+}
+
+//report_or_activity_id
+
+//主题列表
+func GetActivityAskList(userId int) (items []*CygxAskList, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			k.activity_id as report_or_activity_id,
+			k.content,
+			k.create_time,
+			a.activity_name as title
+		FROM
+			cygx_activity_help_ask AS k
+			INNER JOIN cygx_activity AS a ON a.activity_id = k.activity_id 
+		WHERE
+			user_id = ? AND a.publish_status = 1 ORDER BY k.ask_id DESC`
+	_, err = o.Raw(sql, userId).QueryRows(&items)
+	return
+}
+
+//列表
+func GetArticleAskList(userId int) (items []*CygxAskList, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			k.article_id as report_or_activity_id,
+			k.content,
+			k.create_time,
+			a.title as title
+		FROM
+			cygx_article_ask AS k
+			INNER JOIN cygx_article AS a ON a.article_id = k.article_id 
+		WHERE
+			user_id = ? AND a.publish_status = 1 ORDER BY k.ask_id DESC`
+	_, err = o.Raw(sql, userId).QueryRows(&items)
+	return
+}

+ 70 - 0
models/article_comment.go

@@ -0,0 +1,70 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxArticleComment struct {
+	Id              int       `orm:"column(id);pk" description:"留言id"`
+	UserId          int       `description:"用户id"`
+	RealName        string    `description:"用户姓名"`
+	ArticleId       int       `description:"文章id"`
+	ActivityId      int       `description:"活动id"`
+	VideoId         int       `description:"视频id"`
+	ActivityVoiceId int       `description:"活动音频ID"`
+	IndustryId      int       `description:"产业id"`
+	CreateTime      time.Time `description:"创建时间"`
+	Mobile          string    `description:"手机号"`
+	Email           string    `description:"邮箱"`
+	CompanyId       int       `description:"公司id"`
+	CompanyName     string    `description:"公司名称"`
+	Content         string    `description:"内容"`
+	Title           string    `description:"标题"`
+}
+
+//添加留言
+func AddArticleComment(item *CygxArticleComment) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}
+
+type AddCygxArticleCommentReq struct {
+	ArticleId int    `description:"文章id"`
+	Content   string `description:"内容"`
+}
+
+//我的留言列表
+func GetCommentList(userId int) (items []*CygxArticleComment, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			* 
+		FROM
+			cygx_article_comment AS c
+		WHERE
+			user_id = ? ORDER BY c.create_time DESC`
+
+	_, err = o.Raw(sql, userId).QueryRows(&items)
+	return
+}
+
+type CygxArticleCommentResp struct {
+	Id           int       `orm:"column(id);pk" description:"留言id"`
+	UserId       int       `description:"用户id"`
+	ArticleId    int       `description:"文章id"`
+	IndustryId   int       `description:"产业id"`
+	ActivityId   int       `description:"活动id"`
+	CreateTime   time.Time `description:"创建时间"`
+	Mobile       string    `description:"手机号"`
+	Email        string    `description:"邮箱"`
+	CompanyId    int       `description:"公司id"`
+	CompanyName  string    `description:"公司名称"`
+	Content      string    `description:"内容"`
+	Title        string    `description:"标题"`
+	RedirectType int       `description:"跳转类型 1文章 2活动 3产业资源包"`
+}
+
+type CygxCommentListResp struct {
+	List []*CygxArticleCommentResp
+}

+ 16 - 0
models/user.go

@@ -302,3 +302,19 @@ func GetArticleUserCollectList(startSize, pageSize, userId int) (items []*Articl
 	_, err = orm.NewOrm().Raw(sql, userId, startSize, pageSize).QueryRows(&items)
 	return
 }
+
+func GetArticleUserBrowseHistoryCount(userId int, endDate string) (count int, err error) {
+	sql := `SELECT COUNT( 1 ) as count
+			FROM
+			( SELECT count(*) FROM cygx_article_history_record AS a WHERE a.user_id = ? AND a.create_time >= ? GROUP BY a.article_id ) b  `
+	err = orm.NewOrm().Raw(sql, userId, endDate).QueryRow(&count)
+	return
+}
+
+func GetArticleUserBrowseHistoryList(startSize, pageSize, userId int, endDate string) (items []*ArticleReportBillboardResp, err error) {
+	sql := `SELECT a.* ,	MAX( a.id ) AS mid   FROM cygx_article_history_record AS a
+			WHERE a.user_id=? AND a.create_time>=?  GROUP BY a.article_id
+           ORDER BY mid  DESC LIMIT ?,? `
+	_, err = orm.NewOrm().Raw(sql, userId, endDate, startSize, pageSize).QueryRows(&items)
+	return
+}

+ 27 - 0
routers/commentsRouter.go

@@ -286,6 +286,24 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:UserController"] = append(beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:UserController"],
+        beego.ControllerComments{
+            Method: "AskList",
+            Router: `/ask/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:UserController"] = append(beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:UserController"],
+        beego.ControllerComments{
+            Method: "BrowseHistoryList",
+            Router: `/browse/history/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:UserController"] = append(beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:UserController"],
         beego.ControllerComments{
             Method: "CheckLogin",
@@ -304,6 +322,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:UserController"] = append(beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:UserController"],
+        beego.ControllerComments{
+            Method: "CommnetList",
+            Router: `/comment/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:UserController"] = append(beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:UserController"],
         beego.ControllerComments{
             Method: "AddOutboundMobile",

+ 15 - 0
utils/common.go

@@ -673,3 +673,18 @@ func InArrayByInt(idIntList []int, searchId int) (has bool) {
 	}
 	return
 }
+
+//时间格式去掉时分秒
+func TimeRemoveHms2(strTime string) string {
+	var Ymd string
+	var resultTime = StrTimeToTime(strTime)
+	year := resultTime.Year()
+	month := resultTime.Format("01")
+	day1 := resultTime.Day()
+	if day1 < 10 {
+		Ymd = strconv.Itoa(year) + "-" + month + "-0" + strconv.Itoa(day1)
+	} else {
+		Ymd = strconv.Itoa(year) + "-" + month + "-" + strconv.Itoa(day1)
+	}
+	return Ymd
+}