tag.go 6.0 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. conditionInit += " AND search_tag IN ('" + strings.Join(searchTag, "','") + "')"
  92. }
  93. var resourceDataIds []int //cygx_resource_data 主键ID
  94. //如果产业有组合,那么就去捞产业相关的内容
  95. if len(industries) > 0 {
  96. // 获取近一个月产业报告阅读次数最多的产业
  97. var conditionIndustry string
  98. var parsIndustry []interface{}
  99. conditionIndustry += " AND industry_name IN ('" + strings.Join(industries, "','") + "')"
  100. listIndustry, e := models.GetTopOneMonthArtReadNumIndustryAll(conditionIndustry, parsIndustry)
  101. if e != nil {
  102. err = errors.New("GetTopOneMonthArtReadNumIndustryAll, Err: " + e.Error())
  103. return
  104. }
  105. var industrialManagementIds []int // 产业ID合集
  106. for _, v := range listIndustry {
  107. industrialManagementIds = append(industrialManagementIds, v.IndustrialManagementId)
  108. }
  109. var conditionIndustryResource string
  110. var parsIndustryResource []interface{}
  111. lenArrindustrial := len(industrialManagementIds)
  112. conditionIndustryResource = ` AND industrial_management_id IN (` + utils.GetOrmInReplace(lenArrindustrial) + `)`
  113. parsIndustryResource = append(parsIndustryResource, industrialManagementIds)
  114. if lenArrindustrial > 0 {
  115. listResourceDataIndustrial, e := models.GetCygxResourceDataIndustrialGroupManagementList(conditionIndustryResource, parsIndustryResource, 0, 0)
  116. //return
  117. if e != nil {
  118. err = errors.New("GetCygxResourceDataIndustrialGroupManagementList, Err: " + e.Error())
  119. return
  120. }
  121. for _, v := range listResourceDataIndustrial {
  122. resourceDataIds = append(resourceDataIds, v.ResourceDataId)
  123. }
  124. }
  125. }
  126. //return
  127. //如果标的有组合,那么就去捞标的相关的内容
  128. if len(subjectNames) > 0 {
  129. // 获取近一个月产业报告阅读次数最多的产业
  130. var conditionsubject string
  131. var parssubject []interface{}
  132. conditionsubject += " AND subject_name IN ('" + strings.Join(subjectNames, "','") + "')"
  133. listsubject, e := models.GetCygxIndustrialSubjectListCondition(conditionsubject, parssubject)
  134. if e != nil {
  135. err = errors.New("GetTopOneMonthArtReadNumIndustry, Err: " + e.Error())
  136. return
  137. }
  138. var industrialsubjectIds []int // 标的ID集合
  139. for _, v := range listsubject {
  140. industrialsubjectIds = append(industrialsubjectIds, v.IndustrialSubjectId)
  141. }
  142. var conditionsubjectResource string
  143. var parssubjectResource []interface{}
  144. lenArrsubject := len(industrialsubjectIds)
  145. conditionsubjectResource = ` AND industrial_subject_id IN (` + utils.GetOrmInReplace(lenArrsubject) + `)`
  146. parssubjectResource = append(parssubjectResource, industrialsubjectIds)
  147. if lenArrsubject > 0 {
  148. listResourceDatasubject, e := models.GetCygxResourceDataIndustrialGroupSubjectList(conditionsubjectResource, parssubjectResource, 0, 0)
  149. if e != nil {
  150. err = errors.New("GetCygxResourceDataIndustrialGroupSubjectList, Err: " + e.Error())
  151. return
  152. }
  153. for _, v := range listResourceDatasubject {
  154. resourceDataIds = append(resourceDataIds, v.ResourceDataId)
  155. }
  156. }
  157. }
  158. //拼接 cygx_resource_data 表主键查询ID
  159. if len(resourceDataIds) > 0 {
  160. var resourceDataIdStrs []string
  161. resourceDataIdMap := make(map[int]bool)
  162. for _, v := range resourceDataIds {
  163. if resourceDataIdMap[v] {
  164. continue
  165. }
  166. resourceDataIdStrs = append(resourceDataIdStrs, strconv.Itoa(v))
  167. resourceDataIdMap[v] = true
  168. }
  169. conditionInit += " AND id IN (" + strings.Join(resourceDataIdStrs, ",") + ") "
  170. }
  171. return
  172. }