xingzai 3 жил өмнө
parent
commit
aae2cd65b6

+ 173 - 2
controllers/report.go

@@ -450,7 +450,6 @@ func (this *ReportController) ArticleCollect() {
 		return
 	}
 	industrialManagementId := req.IndustrialManagementId
-	fmt.Println(industrialManagementId)
 	countIndustrial, err := models.GetIndustrialManagementCount(industrialManagementId)
 	if err != nil {
 		br.Msg = "获取数据失败!"
@@ -559,7 +558,7 @@ func (this *ReportController) Fllow() {
 			br.ErrMsg = "操作失败,Err:" + err.Error()
 			return
 		}
-		resp.GoFllow = true
+		resp.GoFollow = true
 		resp.Status = 1
 	} else {
 		var doType int
@@ -643,6 +642,9 @@ func (this *ReportController) IndustryListByDepartment() {
 			br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
 			return
 		}
+		if v.FollowNum > 0 {
+			list[k].IsMyFollow = true
+		}
 	}
 	resp := new(models.CygxArticleDepartmentList)
 	resp.ListnNew, err = models.GetIndustrialSubjectByDepartmentNew(chartPermissionId)
@@ -658,3 +660,172 @@ func (this *ReportController) IndustryListByDepartment() {
 	br.Msg = "获取成功"
 	br.Data = resp
 }
+
+// @Title 关注作者/取消关注作者
+// @Description 关注作者/取消关注作者 接口
+// @Param	request	body models.CygxArticleDepartmentId true "type json string"
+// @Success 200
+// @router /fllowDepartment [post]
+func (this *ReportController) FllowDepartment() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请重新登录"
+		br.Ret = 408
+		return
+	}
+	uid := user.UserId
+	var req models.CygxArticleDepartmentId
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	departmentId := req.DepartmentId
+	var condition string
+	countDepartment, err := models.GetDepartmentCount(departmentId)
+	if err != nil {
+		br.Msg = "获取数据失败!"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+	if countDepartment == 0 {
+		br.Msg = "作者不存在!"
+		br.ErrMsg = "作者ID不存在:" + strconv.Itoa(departmentId)
+		return
+	}
+	count, err := models.GetArticleDepartmentFollow(uid, departmentId, condition)
+	if err != nil {
+		br.Msg = "获取数据失败!"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+	resp := new(models.CygxArticleDepartmentFollowResp)
+	if count == 0 {
+		item := new(models.CygxArticleDepartmentFollow)
+		item.DepartmentId = departmentId
+		item.UserId = uid
+		item.Email = user.Email
+		item.Mobile = user.Mobile
+		item.CompanyId = user.CompanyId
+		item.CompanyName = user.CompanyName
+		item.Type = 1
+		item.CreateTime = time.Now()
+		item.ModifyTime = time.Now()
+		_, err = models.AddArticleDepartmentFollow(item)
+		if err != nil {
+			br.Msg = "操作失败"
+			br.ErrMsg = "操作失败,Err:" + err.Error()
+			return
+		}
+		resp.Status = 1
+		resp.GoFollow = true
+	} else {
+		var doType int
+		condition = ` AND type = 1`
+		count, err = models.GetArticleDepartmentFollow(uid, departmentId, condition)
+		if err != nil {
+			br.Msg = "操作失败!"
+			br.ErrMsg = "获取数据失败,Err:" + err.Error()
+			return
+		}
+		if count == 1 {
+			resp.Status = 2
+			doType = 2
+		} else {
+			resp.Status = 1
+			doType = 1
+		}
+		err = models.RemoveArticleDepartmentFollow(uid, departmentId, doType)
+		if err != nil {
+			br.Msg = "操作失败"
+			br.ErrMsg = "取消关注失败,Err:" + err.Error()
+			return
+		}
+	}
+	br.Msg = "操作成功"
+	br.Ret = 200
+	br.Success = true
+	br.Data = resp
+}
+
+// @Title 研选文章列表接口
+// @Description 获取研选文章列表接口
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Param   DepartmentId   query   int  true       "作者ID"
+// @Param   IndustrialManagementId   query   int  true       "产业ID"
+// @Success 200 {object} models.ReportArticleWhichIndustrialRepList
+// @router /industry/reportList [get]
+func (this *ReportController) ReportList() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请重新登录"
+		br.Ret = 408
+		return
+	}
+	uid := user.UserId
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+	departmentId, _ := this.GetInt("DepartmentId")
+	industrialManagementId, _ := this.GetInt("IndustrialManagementId")
+
+	var condition string
+	var startSize int
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	startSize = paging.StartIndex(currentIndex, pageSize)
+	var pars []interface{}
+	var total int
+	resp := new(models.ReportArticleWhichIndustrialRepList)
+	page := paging.GetPaging(currentIndex, pageSize, total)
+
+	if departmentId > 0 {
+		condition += ` AND art.department_id = ` + strconv.Itoa(departmentId)
+	}
+
+	if industrialManagementId > 0 {
+		condition += ` AND m.industrial_management_id = ` + strconv.Itoa(industrialManagementId)
+	}
+	total, err := models.GetWhichDepartmentCount(condition)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取帖子总数失败,Err:" + err.Error()
+		return
+	}
+	page = paging.GetPaging(currentIndex, pageSize, total)
+	condition += ` ORDER BY art.publish_date DESC`
+	list, err := models.IndustrialToArticleWhichDepartment(condition, pars, uid, startSize, pageSize)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
+	}
+	for k, v := range list {
+		if v.Readnum == 0 {
+			list[k].IsRed = true
+		}
+		resp.NickName = v.NickName
+		resp.IndustryName = v.IndustryName
+	}
+	resp.List = list
+	resp.Paging = page
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}

+ 21 - 4
models/article_department.go

@@ -19,14 +19,19 @@ type CygxArticleDepartmentRep struct {
 	DepartmentId int    `description:"主键ID"`
 	CreateTime   string `description:"创建时间"`
 	NickName     string `description:"昵称"`
-	IsFollow     int    `description:"是否关注 1是 ,0 否"`
+	FollowNum    int    `description:"是否关注 1是 ,0 否"`
+	IsMyFollow   bool   `description:"是否关注"`
 	List         []*IndustrialManagementIdInt
 }
 
+type CygxArticleDepartmentId struct {
+	DepartmentId int `description:"作者ID"`
+}
+
 type CygxArticleDepartmentList struct {
 	Paging   *paging.PagingItem `description:"分页数据"`
-	List     []*CygxArticleDepartmentRep
 	ListnNew []*IndustrialManagementIdInt
+	List     []*CygxArticleDepartmentRep
 }
 
 //详情
@@ -40,13 +45,16 @@ func GetArticleDepartmentDateil(nickName, remarks string) (item *CygxArticleDepa
 //数量
 func GetArticleDepartmentCount(condition string) (count int, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT COUNT(1)  FROM cygx_article_department AS d
+	sql := ` SELECT COUNT(*) count
+		FROM
+		( SELECT COUNT(1)  FROM cygx_article_department AS d
 		INNER JOIN cygx_article AS a ON a.department_id = d.department_id
 		INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
 		INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id WHERE 1= 1  `
 	if condition != "" {
 		sql += condition
 	}
+	sql += ` GROUP BY d.department_id ) AS num `
 
 	err = o.Raw(sql).QueryRow(&count)
 	return
@@ -56,7 +64,8 @@ func GetArticleDepartmentCount(condition string) (count int, err error) {
 func GetCygxArticleDepartmentList(startSize, pageSize int, condition string) (items []*CygxArticleDepartmentRep, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT d.*,
-		( SELECT COUNT( 1 ) FROM cygx_article AS a INNER JOIN cygx_article_history_record as h ON h.article_id = a.article_id WHERE  a.department_id = d.department_id  ) AS art_num 
+		( SELECT COUNT( 1 ) FROM cygx_article AS a INNER JOIN cygx_article_history_record as h ON h.article_id = a.article_id WHERE  a.department_id = d.department_id  ) AS art_num,
+		( SELECT COUNT( 1 ) FROM cygx_article_department_follow AS f  WHERE f.department_id = d.department_id AND f.user_id = 51561 ) AS follow_num
 		FROM
 		cygx_article_department AS d
 		INNER JOIN cygx_article AS a ON a.department_id = d.department_id
@@ -108,3 +117,11 @@ func GetIndustrialSubjectByDepartmentNew(industrialManagementId int) (items []*I
 	_, err = o.Raw(sql, industrialManagementId).QueryRows(&items)
 	return
 }
+
+//获取作者数量
+func GetDepartmentCount(departmentId int) (count int, err error) {
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_article_department WHERE department_id=? `
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, departmentId).QueryRow(&count)
+	return
+}

+ 49 - 0
models/article_department_follow.go

@@ -0,0 +1,49 @@
+package models
+
+import (
+	"rdluck_tools/orm"
+	"time"
+)
+
+type CygxArticleDepartmentFollow struct {
+	Id           int       `orm:"column(id);pk"`
+	DepartmentId int       `description:"作者ID"`
+	UserId       int       `description:"用户ID"`
+	Mobile       string    `description:"手机号"`
+	Email        string    `description:"邮箱"`
+	CompanyId    int       `description:"公司id"`
+	CompanyName  string    `description:"公司名称"`
+	Type         int       `description:"操作方式,1报名,2取消报名"`
+	CreateTime   time.Time `description:"创建时间"`
+	ModifyTime   time.Time `description:"更新时间"`
+}
+
+type ArticleDepartmentIdRep struct {
+	DepartmentId int `description:"作者ID"`
+}
+
+//添加
+func AddArticleDepartmentFollow(item *CygxArticleDepartmentFollow) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}
+
+type CygxArticleDepartmentFollowResp struct {
+	Status   int  `description:"1:关注,2:取消关注"`
+	GoFollow bool `description:"是否去关注"`
+}
+
+func RemoveArticleDepartmentFollow(userId, industrialManagementId, doType int) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE cygx_article_department_follow SET type = ? ,modify_time=? WHERE user_id=? AND department_id=? `
+	_, err = o.Raw(sql, doType, time.Now(), userId, industrialManagementId).Exec()
+	return
+}
+
+//获取数量
+func GetArticleDepartmentFollow(userId, departmentId int, condition string) (count int, err error) {
+	sql := `SELECT COUNT(1) AS count FROM cygx_article_department_follow WHERE user_id=? AND department_id=? ` + condition
+	err = orm.NewOrm().Raw(sql, userId, departmentId).QueryRow(&count)
+	return
+}

+ 1 - 0
models/db.go

@@ -58,5 +58,6 @@ func init() {
 		new(WxUserWhite),
 		new(CygxActivityHelpAsk),
 		new(CygxIndustryFllow),
+		new(CygxArticleDepartmentFollow),
 	)
 }

+ 2 - 2
models/industry_fllow.go

@@ -30,8 +30,8 @@ func AddCygxIndustryFllow(item *CygxIndustryFllow) (lastId int64, err error) {
 }
 
 type CygxIndustryFllowResp struct {
-	Status  int  `description:"1:关注,2:取消关注"`
-	GoFllow bool `description:"是否去关注"`
+	Status   int  `description:"1:关注,2:取消关注"`
+	GoFollow bool `description:"是否去关注"`
 }
 
 func RemoveCygxIndustryFllow(userId, industrialManagementId, doType int) (err error) {

+ 55 - 0
models/report.go

@@ -135,3 +135,58 @@ func GetIndustrialManagementIdsBykeyWord(condition string) (industrialManagement
 	err = o.Raw(sql).QueryRow(&industrialManagementIds)
 	return
 }
+
+type ReportArticleWhichIndustrial struct {
+	ArticleId    int    `description:"文章id"`
+	Title        string `description:"标题"`
+	PublishDate  string `description:"发布时间"`
+	IndustryName string `description:"产业名称"`
+	NickName     string `description:"作者昵称"`
+	IsRed        bool   `description:"是否标记红点"`
+	Readnum      int    `description:"阅读数量"`
+}
+
+type ReportArticleWhichIndustrialRepList struct {
+	Paging       *paging.PagingItem `description:"分页数据"`
+	NickName     string             `description:"作者昵称"`
+	IndustryName string             `description:"产业名称"`
+	List         []*ReportArticleWhichIndustrial
+}
+
+//列表
+func IndustrialToArticleWhichDepartment(condition string, pars []interface{}, uid, startSize, pageSize int) (items []*ReportArticleWhichIndustrial, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+	art.* ,m.industry_name,d.nick_name,
+	( SELECT COUNT( 1 ) FROM cygx_article_history_record AS rec WHERE rec.user_id =  ` + strconv.Itoa(uid) + ` AND rec.article_id = art.article_id ) AS readnum 
+FROM
+	cygx_article AS art
+	INNER JOIN cygx_industrial_article_group_management as mg ON mg.article_id = art.article_id 
+	INNER JOIN cygx_industrial_management as m ON m.industrial_management_id = mg.industrial_management_id
+	INNER JOIN cygx_article_department as d ON d.department_id = art.department_id
+	WHERE 1 = 1 
+	AND art.publish_status = 1`
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` LIMIT ?,?`
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	return
+}
+
+func GetWhichDepartmentCount(condition string) (count int, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT COUNT(1) count 
+FROM
+	cygx_article AS art
+	INNER JOIN cygx_industrial_article_group_management as mg ON mg.article_id = art.article_id 
+	INNER JOIN cygx_industrial_management as m ON m.industrial_management_id = mg.industrial_management_id
+	INNER JOIN cygx_article_department as d ON d.department_id = art.department_id
+	WHERE 1 = 1 
+	AND art.publish_status = 1`
+	if condition != "" {
+		sql += condition
+	}
+	err = o.Raw(sql).QueryRow(&count)
+	return
+}