industry.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "hongze/hongze_mfyx/models"
  5. "hongze/hongze_mfyx/services"
  6. "hongze/hongze_mfyx/utils"
  7. "strconv"
  8. "time"
  9. )
  10. // 报告
  11. type IndustryController struct {
  12. BaseAuthController
  13. }
  14. // @Title 关注/取消关注产业
  15. // @Description 关注/取消关注 接口
  16. // @Param request body models.CygxIndustryFllowRep true "type json string"
  17. // @Success 200
  18. // @router /follow [post]
  19. func (this *IndustryController) Fllow() {
  20. br := new(models.BaseResponse).Init()
  21. defer func() {
  22. this.Data["json"] = br
  23. this.ServeJSON()
  24. }()
  25. user := this.User
  26. if user == nil {
  27. br.Msg = "请重新登录"
  28. br.Ret = 408
  29. return
  30. }
  31. uid := user.UserId
  32. var req models.IndustryFllowArryReq
  33. resp := new(models.CygxIndustryFllowResp)
  34. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  35. if err != nil {
  36. br.Msg = "参数解析异常!"
  37. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  38. return
  39. }
  40. sourceId := req.SourceId
  41. source := req.Source
  42. doType := req.DoType
  43. var status int
  44. var condition string
  45. var pars []interface{}
  46. var industrialIds []int
  47. if source == "article" {
  48. articleDetail, err := models.GetArticleDetailById(sourceId)
  49. if err != nil {
  50. br.Msg = "获取信息失败"
  51. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  52. return
  53. }
  54. //判读是否属于策略的文章类型
  55. reportMappingMap, _ := services.GetReportMappingMap()
  56. if reportMappingMap[articleDetail.CategoryId] {
  57. chooseCategoryMap, _ := services.GetChooseCategoryMap(user)
  58. //判断用户是否关注策略对应分类
  59. if !chooseCategoryMap[articleDetail.CategoryId] {
  60. item := new(models.CygxXzsChooseCategory)
  61. item.CategoryId = articleDetail.CategoryId
  62. item.UserId = uid
  63. item.Email = user.Email
  64. item.Mobile = user.Mobile
  65. item.RealName = user.RealName
  66. item.CompanyId = user.CompanyId
  67. item.CompanyName = user.CompanyName
  68. item.CreateTime = time.Now()
  69. item.ModifyTime = time.Now()
  70. _, err = models.AddCygxCategoryFllow(item)
  71. if err != nil {
  72. br.Msg = "操作失败"
  73. br.ErrMsg = "操作失败,Err:" + err.Error()
  74. return
  75. }
  76. resp.Status = 1
  77. } else {
  78. err = models.RemoveCygxCategoryFllow(user.Mobile, articleDetail.CategoryId)
  79. if err != nil {
  80. br.Msg = "操作失败"
  81. br.ErrMsg = "取消关注失败,Err:" + err.Error()
  82. return
  83. }
  84. resp.Status = 2
  85. }
  86. br.Msg = "操作成功"
  87. br.Ret = 200
  88. br.Success = true
  89. br.Data = resp
  90. return
  91. } else {
  92. pars = make([]interface{}, 0)
  93. condition = ` AND article_id = ? `
  94. pars = append(pars, sourceId)
  95. industrialList, err := models.GetIndustrialArticleGroupManagementList(condition, pars)
  96. if err != nil && err.Error() != utils.ErrNoRow() {
  97. br.Msg = "获取信息失败"
  98. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  99. return
  100. }
  101. if len(industrialList) > 0 {
  102. for _, v := range industrialList {
  103. industrialIds = append(industrialIds, v.IndustrialManagementId)
  104. }
  105. }
  106. }
  107. } else if source == "activity" {
  108. //处理活动关联的产业
  109. industrialList, err := models.GetIndustrialActivityGroupManagementList(sourceId)
  110. if err != nil && err.Error() != utils.ErrNoRow() {
  111. br.Msg = "获取信息失败"
  112. br.ErrMsg = "获取活动关联的产业列表信息失败,Err:" + err.Error() + "activityId:" + strconv.Itoa(sourceId)
  113. return
  114. }
  115. if len(industrialList) > 0 {
  116. for _, v := range industrialList {
  117. industrialIds = append(industrialIds, v.IndustrialManagementId)
  118. }
  119. }
  120. } else {
  121. br.Msg = "参数解析异常!"
  122. br.ErrMsg = "资源类型有误:" + source
  123. return
  124. }
  125. lenindustrialIds := len(industrialIds)
  126. if lenindustrialIds == 0 {
  127. br.Msg = "操作失败!"
  128. br.ErrMsg = "对应的产业不存在:" + source + "ID:" + strconv.Itoa(sourceId)
  129. return
  130. }
  131. //批量取关与关注
  132. if doType == "add" {
  133. status = 1
  134. var industryFllowItems []*models.CygxIndustryFllow
  135. for _, v := range industrialIds {
  136. item := new(models.CygxIndustryFllow)
  137. item.IndustrialManagementId = v
  138. item.UserId = uid
  139. item.Email = user.Email
  140. item.Mobile = user.Mobile
  141. item.RealName = user.RealName
  142. item.CompanyId = user.CompanyId
  143. item.CompanyName = user.CompanyName
  144. item.Type = 1
  145. item.CreateTime = time.Now()
  146. item.ModifyTime = time.Now()
  147. industryFllowItems = append(industryFllowItems, item)
  148. }
  149. err = models.AddCygxIndustryFllowMulti(industryFllowItems)
  150. } else if doType == "cancel" {
  151. status = 2
  152. pars = make([]interface{}, 0)
  153. condition = ` AND industrial_management_id IN (` + utils.GetOrmInReplace(lenindustrialIds) + `)`
  154. pars = append(pars, industrialIds)
  155. err = models.RemoveCygxIndustryFllowArry(uid, condition, pars)
  156. } else {
  157. br.Msg = "参数解析异常!"
  158. br.ErrMsg = "操作方式有误:" + doType
  159. return
  160. }
  161. if err != nil {
  162. br.Msg = "操作失败"
  163. br.ErrMsg = "取消关注失败,Err:" + err.Error()
  164. return
  165. }
  166. resp.Status = status
  167. //处理是否关注全部赛道字段
  168. //go services.IndustryFllowWithTrack(industrialManagementId, count, uid)
  169. br.Msg = "操作成功"
  170. br.Ret = 200
  171. br.Success = true
  172. br.Data = resp
  173. }