tag.go 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. package services
  2. import (
  3. "errors"
  4. "hongze/hongze_cygx/models"
  5. "hongze/hongze_cygx/utils"
  6. "strconv"
  7. "strings"
  8. "time"
  9. )
  10. func AddCygxTagHistory(user *models.WxUserItem, tagId int) (err error) {
  11. if user.UserId == 0 {
  12. return
  13. }
  14. defer func() {
  15. if err != nil {
  16. go utils.SendAlarmMsg("tag点击信息记录失败"+err.Error()+"tagId"+strconv.Itoa(tagId)+"userId:"+strconv.Itoa(user.UserId), 2)
  17. }
  18. }()
  19. historyRecord := new(models.CygxTagHistory)
  20. historyRecord.UserId = user.UserId
  21. historyRecord.TagId = tagId
  22. historyRecord.CreateTime = time.Now()
  23. historyRecord.Mobile = user.Mobile
  24. historyRecord.Email = user.Email
  25. historyRecord.CompanyId = user.CompanyId
  26. historyRecord.CompanyName = user.CompanyName
  27. historyRecord.RegisterPlatform = utils.REGISTER_PLATFORM
  28. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  29. if err != nil && err.Error() != utils.ErrNoRow() {
  30. return
  31. }
  32. historyRecord.RealName = user.RealName
  33. if sellerItem != nil {
  34. historyRecord.SellerName = sellerItem.RealName
  35. }
  36. _, err = models.AddCygxTagHistory(historyRecord)
  37. return
  38. }
  39. //func init() {
  40. // conditionInit, err := GetConditionInitByTagIds("20,21,26")
  41. // fmt.Println(err)
  42. // fmt.Println()
  43. // fmt.Println(conditionInit)
  44. //}
  45. func GetConditionInitByTagIds(tagIds string) (conditionInit string, err error) {
  46. if tagIds == "" {
  47. return
  48. }
  49. var condition string
  50. var pars []interface{}
  51. var searchTag, industries, subjectNames []string
  52. tagslice := strings.Split(tagIds, ",")
  53. condition = ` AND tag_id IN (` + utils.GetOrmInReplace(len(tagslice)) + `)`
  54. pars = append(pars, tagslice)
  55. listTag, e := models.GetCygxTagListCondition(condition, pars, 0, 0)
  56. if e != nil {
  57. err = errors.New("GetActivityListByCondition, Err: " + e.Error())
  58. return
  59. }
  60. for _, tagInfo := range listTag {
  61. //ActivityTypes 与 ArticleTypes 进行合并
  62. if tagInfo.ActivityTypes != "" {
  63. sliceObj := strings.Split(tagInfo.ActivityTypes, ",")
  64. for _, v := range sliceObj {
  65. searchTag = append(searchTag, v)
  66. }
  67. }
  68. if tagInfo.ArticleTypes != "" {
  69. sliceObj := strings.Split(tagInfo.ArticleTypes, ",")
  70. for _, v := range sliceObj {
  71. searchTag = append(searchTag, v)
  72. }
  73. }
  74. if tagInfo.Industries != "" {
  75. sliceObj := strings.Split(tagInfo.Industries, ",")
  76. for _, v := range sliceObj {
  77. industries = append(industries, v)
  78. }
  79. //industries = append(industries, tagInfo.Industries)
  80. }
  81. if tagInfo.SubjectNames != "" {
  82. sliceObj := strings.Split(tagInfo.SubjectNames, ",")
  83. for _, v := range sliceObj {
  84. subjectNames = append(subjectNames, v)
  85. }
  86. //subjectNames = append(subjectNames, tagInfo.SubjectNames)
  87. }
  88. }
  89. //拼接search_tag 搜索内容
  90. if len(searchTag) > 0 {
  91. //search_tag_two 兼容报告类型一对多的这种,时间不够,产品也有可能变先这么做
  92. conditionInit += " AND ( search_tag IN ('" + strings.Join(searchTag, "','") + "') OR search_tag_two IN( '" + strings.Join(searchTag, "','") + "' ) )"
  93. }
  94. var resourceDataIds []int //cygx_resource_data 主键ID
  95. //如果产业有组合,那么就去捞产业相关的内容
  96. if len(industries) > 0 {
  97. // 获取近一个月产业报告阅读次数最多的产业
  98. var conditionIndustry string
  99. var parsIndustry []interface{}
  100. conditionIndustry += " AND industry_name IN ('" + strings.Join(industries, "','") + "')"
  101. listIndustry, e := models.GetTopOneMonthArtReadNumIndustryAll(conditionIndustry, parsIndustry)
  102. if e != nil {
  103. err = errors.New("GetTopOneMonthArtReadNumIndustryAll, Err: " + e.Error())
  104. return
  105. }
  106. var industrialManagementIds []int // 产业ID合集
  107. for _, v := range listIndustry {
  108. industrialManagementIds = append(industrialManagementIds, v.IndustrialManagementId)
  109. }
  110. var conditionIndustryResource string
  111. var parsIndustryResource []interface{}
  112. lenArrindustrial := len(industrialManagementIds)
  113. conditionIndustryResource = ` AND industrial_management_id IN (` + utils.GetOrmInReplace(lenArrindustrial) + `)`
  114. parsIndustryResource = append(parsIndustryResource, industrialManagementIds)
  115. if lenArrindustrial > 0 {
  116. listResourceDataIndustrial, e := models.GetCygxResourceDataIndustrialGroupManagementList(conditionIndustryResource, parsIndustryResource, 0, 0)
  117. //return
  118. if e != nil {
  119. err = errors.New("GetCygxResourceDataIndustrialGroupManagementList, Err: " + e.Error())
  120. return
  121. }
  122. for _, v := range listResourceDataIndustrial {
  123. resourceDataIds = append(resourceDataIds, v.ResourceDataId)
  124. }
  125. }
  126. }
  127. //return
  128. //如果标的有组合,那么就去捞标的相关的内容
  129. if len(subjectNames) > 0 {
  130. // 获取近一个月产业报告阅读次数最多的产业
  131. var conditionsubject string
  132. var parssubject []interface{}
  133. conditionsubject += " AND subject_name IN ('" + strings.Join(subjectNames, "','") + "')"
  134. listsubject, e := models.GetCygxIndustrialSubjectListCondition(conditionsubject, parssubject)
  135. if e != nil {
  136. err = errors.New("GetTopOneMonthArtReadNumIndustry, Err: " + e.Error())
  137. return
  138. }
  139. var industrialsubjectIds []int // 标的ID集合
  140. for _, v := range listsubject {
  141. industrialsubjectIds = append(industrialsubjectIds, v.IndustrialSubjectId)
  142. }
  143. var conditionsubjectResource string
  144. var parssubjectResource []interface{}
  145. lenArrsubject := len(industrialsubjectIds)
  146. conditionsubjectResource = ` AND industrial_subject_id IN (` + utils.GetOrmInReplace(lenArrsubject) + `)`
  147. parssubjectResource = append(parssubjectResource, industrialsubjectIds)
  148. if lenArrsubject > 0 {
  149. listResourceDatasubject, e := models.GetCygxResourceDataIndustrialGroupSubjectList(conditionsubjectResource, parssubjectResource, 0, 0)
  150. if e != nil {
  151. err = errors.New("GetCygxResourceDataIndustrialGroupSubjectList, Err: " + e.Error())
  152. return
  153. }
  154. for _, v := range listResourceDatasubject {
  155. resourceDataIds = append(resourceDataIds, v.ResourceDataId)
  156. }
  157. }
  158. }
  159. //拼接 cygx_resource_data 表主键查询ID
  160. if len(resourceDataIds) > 0 {
  161. var resourceDataIdStrs []string
  162. resourceDataIdMap := make(map[int]bool)
  163. for _, v := range resourceDataIds {
  164. if resourceDataIdMap[v] {
  165. continue
  166. }
  167. resourceDataIdStrs = append(resourceDataIdStrs, strconv.Itoa(v))
  168. resourceDataIdMap[v] = true
  169. }
  170. conditionInit += " AND id IN (" + strings.Join(resourceDataIdStrs, ",") + ") "
  171. }
  172. return
  173. }