tag.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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, chartPermissionId int) (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("GetCygxTagListCondition, Err: " + e.Error())
  58. return
  59. }
  60. var tagType int // 定义特殊标签的类型,判断传过来的参数是否有固定标签的搜索
  61. for _, tagInfo := range listTag {
  62. //ActivityTypes 与 ArticleTypes 进行合并
  63. if tagInfo.ActivityTypes != "" {
  64. sliceObj := strings.Split(tagInfo.ActivityTypes, ",")
  65. for _, v := range sliceObj {
  66. searchTag = append(searchTag, v)
  67. }
  68. }
  69. if tagInfo.ArticleTypes != "" {
  70. sliceObj := strings.Split(tagInfo.ArticleTypes, ",")
  71. for _, v := range sliceObj {
  72. searchTag = append(searchTag, v)
  73. }
  74. }
  75. if tagInfo.Industries != "" {
  76. sliceObj := strings.Split(tagInfo.Industries, ",")
  77. for _, v := range sliceObj {
  78. industries = append(industries, v)
  79. }
  80. //industries = append(industries, tagInfo.Industries)
  81. }
  82. if tagInfo.SubjectNames != "" {
  83. sliceObj := strings.Split(tagInfo.SubjectNames, ",")
  84. for _, v := range sliceObj {
  85. subjectNames = append(subjectNames, v)
  86. }
  87. //subjectNames = append(subjectNames, tagInfo.SubjectNames)
  88. }
  89. if tagType == 0 && tagInfo.TagType > 0 {
  90. tagType = tagInfo.TagType
  91. }
  92. }
  93. switch tagType {
  94. case 0: // 无固定标签
  95. //拼接search_tag 搜索内容
  96. if len(searchTag) > 0 {
  97. //search_tag_two 兼容报告类型一对多的这种,时间不够,产品也有可能变先这么做
  98. conditionInit += " AND ( search_tag IN ('" + strings.Join(searchTag, "','") + "') OR search_tag_two IN( '" + strings.Join(searchTag, "','") + "' ) )"
  99. }
  100. var resourceDataIds []int //cygx_resource_data 主键ID
  101. //如果产业有组合,那么就去捞产业相关的内容
  102. if len(industries) > 0 {
  103. var conditionIndustry string
  104. var parsIndustry []interface{}
  105. conditionIndustry += " AND industry_name IN ('" + strings.Join(industries, "','") + "')"
  106. listIndustry, e := models.GetTopOneMonthArtReadNumIndustryAll(conditionIndustry, parsIndustry)
  107. if e != nil {
  108. err = errors.New("GetTopOneMonthArtReadNumIndustryAll, Err: " + e.Error())
  109. return
  110. }
  111. var industrialManagementIds []int // 产业ID合集
  112. for _, v := range listIndustry {
  113. industrialManagementIds = append(industrialManagementIds, v.IndustrialManagementId)
  114. }
  115. var conditionIndustryResource string
  116. var parsIndustryResource []interface{}
  117. lenArrindustrial := len(industrialManagementIds)
  118. conditionIndustryResource = ` AND industrial_management_id IN (` + utils.GetOrmInReplace(lenArrindustrial) + `)`
  119. parsIndustryResource = append(parsIndustryResource, industrialManagementIds)
  120. if lenArrindustrial > 0 {
  121. listResourceDataIndustrial, e := models.GetCygxResourceDataIndustrialGroupManagementList(conditionIndustryResource, parsIndustryResource, 0, 0)
  122. //return
  123. if e != nil {
  124. err = errors.New("GetCygxResourceDataIndustrialGroupManagementList, Err: " + e.Error())
  125. return
  126. }
  127. for _, v := range listResourceDataIndustrial {
  128. resourceDataIds = append(resourceDataIds, v.ResourceDataId)
  129. }
  130. }
  131. }
  132. //return
  133. //如果标的有组合,那么就去捞标的相关的内容
  134. if len(subjectNames) > 0 {
  135. var conditionsubject string
  136. var parssubject []interface{}
  137. conditionsubject += " AND subject_name IN ('" + strings.Join(subjectNames, "','") + "')"
  138. listsubject, e := models.GetCygxIndustrialSubjectListCondition(conditionsubject, parssubject)
  139. if e != nil {
  140. err = errors.New("GetTopOneMonthArtReadNumIndustry, Err: " + e.Error())
  141. return
  142. }
  143. var industrialsubjectIds []int // 标的ID集合
  144. for _, v := range listsubject {
  145. industrialsubjectIds = append(industrialsubjectIds, v.IndustrialSubjectId)
  146. }
  147. var conditionsubjectResource string
  148. var parssubjectResource []interface{}
  149. lenArrsubject := len(industrialsubjectIds)
  150. conditionsubjectResource = ` AND industrial_subject_id IN (` + utils.GetOrmInReplace(lenArrsubject) + `)`
  151. parssubjectResource = append(parssubjectResource, industrialsubjectIds)
  152. if lenArrsubject > 0 {
  153. listResourceDatasubject, e := models.GetCygxResourceDataIndustrialGroupSubjectList(conditionsubjectResource, parssubjectResource, 0, 0)
  154. if e != nil {
  155. err = errors.New("GetCygxResourceDataIndustrialGroupSubjectList, Err: " + e.Error())
  156. return
  157. }
  158. for _, v := range listResourceDatasubject {
  159. resourceDataIds = append(resourceDataIds, v.ResourceDataId)
  160. }
  161. }
  162. }
  163. //拼接 cygx_resource_data 表主键查询ID
  164. if len(resourceDataIds) > 0 {
  165. var resourceDataIdStrs []string
  166. resourceDataIdMap := make(map[int]bool)
  167. for _, v := range resourceDataIds {
  168. if resourceDataIdMap[v] {
  169. continue
  170. }
  171. resourceDataIdStrs = append(resourceDataIdStrs, strconv.Itoa(v))
  172. resourceDataIdMap[v] = true
  173. }
  174. conditionInit += " AND id IN (" + strings.Join(resourceDataIdStrs, ",") + ") "
  175. }
  176. case 1: // 热门活动
  177. conf, e := models.GetConfigByCode(utils.CYGX_TAG_HOT_ACTIVITY_ID)
  178. if e != nil {
  179. err = errors.New("GetConfigByCode, Err: " + e.Error())
  180. return
  181. }
  182. //主键ID赋值为0,进行空查询
  183. if conf.ConfigValue == "" {
  184. conditionInit += " AND id = 0 "
  185. return
  186. }
  187. pars = make([]interface{}, 0)
  188. condition = " AND activity_id IN ( " + conf.ConfigValue + ") AND publish_status = 1 AND active_state IN (1,2) "
  189. listActivity, e := models.GetActivityListByCondition(condition, pars)
  190. if e != nil {
  191. err = errors.New("GetActivityListByCondition, Err: " + e.Error())
  192. return
  193. }
  194. if len(listActivity) == 0 {
  195. conditionInit += " AND id = 0 "
  196. return
  197. }
  198. //拼接查询热门活动的SQL、
  199. var activityIds []string
  200. for _, v := range listActivity {
  201. activityIds = append(activityIds, strconv.Itoa(v.ActivityId))
  202. }
  203. conditionInit = " AND source_id IN ( " + strings.Join(activityIds, ",") + ") AND source = '" + utils.CYGX_OBJ_ACTIVITY + "'"
  204. case 2: //海外研究 查询海外研究的文章,以及海外的活动
  205. condition = " AND category_id IN ( SELECT category_id_celue FROM cygx_report_mapping_group WHERE id_cygx IN ( 35,39 ) ) AND publish_status = 1"
  206. pars = make([]interface{}, 0)
  207. articleList, e := models.GetArticleList(condition, pars)
  208. if e != nil {
  209. err = errors.New("GetArticleList, Err: " + e.Error())
  210. return
  211. }
  212. //文章一定会有值,这里就不做为空判断了 。。。
  213. var articleIds []string
  214. for _, v := range articleList {
  215. articleIds = append(articleIds, strconv.Itoa(v.ArticleId))
  216. }
  217. //海外举办的活动查询
  218. condition = " AND area_type = 2 AND publish_status = 1 "
  219. listActivity, e := models.GetActivityListByCondition(condition, pars)
  220. if e != nil {
  221. err = errors.New("GetActivityListByCondition, Err: " + e.Error())
  222. return
  223. }
  224. //判断是否有海外活动,如果有就拼接,报告与活动的查询SQL
  225. if len(listActivity) == 0 {
  226. conditionInit = " AND source_id IN ( " + strings.Join(articleIds, ",") + ") AND source = '" + utils.CYGX_OBJ_ARTICLE + "'"
  227. } else {
  228. var activityIds []string
  229. for _, v := range listActivity {
  230. activityIds = append(activityIds, strconv.Itoa(v.ActivityId))
  231. }
  232. var conditionchartInit string
  233. //行业筛选
  234. if chartPermissionId > 0 {
  235. conditionchartInit += " AND chart_permission_id = " + strconv.Itoa(chartPermissionId)
  236. }
  237. conditionInit = " AND ( source_id IN ( " + strings.Join(articleIds, ",") + ") " + conditionchartInit + " AND source = '" + utils.CYGX_OBJ_ARTICLE + "') OR (source_id IN ( " + strings.Join(activityIds, ",") + ") " + conditionchartInit + " AND source = '" + utils.CYGX_OBJ_ACTIVITY + " ' )"
  238. }
  239. case 3: // 路演回放
  240. conditionInit = " AND source IN('activityvoice','activityvideo') AND search_tag = '路演回放' "
  241. case 4: // 语音问答
  242. conditionInit = " AND source = '" + utils.CYGX_OBJ_ASKSERIEVIDEO + "'"
  243. case 5: //固定标签【跟踪】,包含以下系列:医药-趋势观察 ,科技-产业跟踪 ,智造-产业跟踪 ,消费-月度调研 ,周期-(周度观点,产业跟踪)
  244. condition = " AND sub_category_name IN ('趋势观察','产业跟踪','月度调研') AND category_name IN ('医药行业','智造行业','消费行业','科技行业') OR ( sub_category_name IN ('周度观点','产业跟踪') AND category_name = '周期' ) AND publish_status = 1 "
  245. pars = make([]interface{}, 0)
  246. articleList, e := models.GetArticleList(condition, pars)
  247. if e != nil {
  248. err = errors.New("GetArticleList, Err: " + e.Error())
  249. return
  250. }
  251. //文章一定会有值,这里就不做为空判断了 。。。
  252. var articleIds []string
  253. for _, v := range articleList {
  254. articleIds = append(articleIds, strconv.Itoa(v.ArticleId))
  255. }
  256. conditionInit = " AND source_id IN ( " + strings.Join(articleIds, ",") + ") AND source = '" + utils.CYGX_OBJ_ARTICLE + "'"
  257. }
  258. return
  259. }