tag.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. package services
  2. import (
  3. "errors"
  4. "hongze/hongze_clpt/models"
  5. "hongze/hongze_clpt/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("43")
  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. //conditionInit += " OR IF ( source IN ('ficcreport') , tag_name IN ('纪要') ,1=1 ) "
  177. case 1: // 热门活动
  178. conf, e := models.GetConfigByCode(utils.CYGX_TAG_HOT_ACTIVITY_ID)
  179. if e != nil {
  180. err = errors.New("GetConfigByCode, Err: " + e.Error())
  181. return
  182. }
  183. //主键ID赋值为0,进行空查询
  184. if conf.ConfigValue == "" {
  185. conditionInit += " AND id = 0 "
  186. return
  187. }
  188. pars = make([]interface{}, 0)
  189. condition = " AND activity_id IN ( " + conf.ConfigValue + ") AND publish_status = 1 AND active_state IN (1,2) "
  190. listActivity, e := models.GetActivityListByCondition(condition, pars)
  191. if e != nil {
  192. err = errors.New("GetActivityListByCondition, Err: " + e.Error())
  193. return
  194. }
  195. if len(listActivity) == 0 {
  196. conditionInit += " AND id = 0 "
  197. return
  198. }
  199. //拼接查询热门活动的SQL、
  200. var activityIds []string
  201. for _, v := range listActivity {
  202. activityIds = append(activityIds, strconv.Itoa(v.ActivityId))
  203. }
  204. conditionInit = " AND source_id IN ( " + strings.Join(activityIds, ",") + ") AND source = '" + utils.CYGX_OBJ_ACTIVITY + "'"
  205. case 2: //海外研究 查询海外研究的文章,以及海外的活动
  206. condition = " AND category_id IN ( SELECT category_id_celue FROM cygx_report_mapping_group WHERE id_cygx IN ( 35,39 ) ) AND publish_status = 1"
  207. pars = make([]interface{}, 0)
  208. articleList, e := models.GetArticleList(condition, pars)
  209. if e != nil {
  210. err = errors.New("GetArticleList, Err: " + e.Error())
  211. return
  212. }
  213. //文章一定会有值,这里就不做为空判断了 。。。
  214. var articleIds []string
  215. for _, v := range articleList {
  216. articleIds = append(articleIds, strconv.Itoa(v.ArticleId))
  217. }
  218. //海外举办的活动查询
  219. condition = " AND area_type = 2 AND publish_status = 1 "
  220. listActivity, e := models.GetActivityListByCondition(condition, pars)
  221. if e != nil {
  222. err = errors.New("GetActivityListByCondition, Err: " + e.Error())
  223. return
  224. }
  225. //判断是否有海外活动,如果有就拼接,报告与活动的查询SQL
  226. if len(listActivity) == 0 {
  227. conditionInit = " AND source_id IN ( " + strings.Join(articleIds, ",") + ") AND source = '" + utils.CYGX_OBJ_ARTICLE + "'"
  228. } else {
  229. var activityIds []string
  230. for _, v := range listActivity {
  231. activityIds = append(activityIds, strconv.Itoa(v.ActivityId))
  232. }
  233. var conditionchartInit string
  234. //行业筛选
  235. if chartPermissionId > 0 {
  236. conditionchartInit += " AND chart_permission_id = " + strconv.Itoa(chartPermissionId)
  237. }
  238. 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 + " ' )"
  239. }
  240. case 3: // 路演回放
  241. conditionInit = " AND source IN('activityvoice','activityvideo') AND search_tag = '路演回放' "
  242. case 4: // 语音问答
  243. conditionInit = " AND source = '" + utils.CYGX_OBJ_ASKSERIEVIDEO + "'"
  244. case 5: //固定标签【跟踪】,包含以下系列:医药-趋势观察 ,科技-产业跟踪 ,智造-产业跟踪 ,消费-月度调研 ,周期-(周度观点,产业跟踪)
  245. condition = ` AND category_name IN ( '医药行业', '智造行业', '消费行业', '科技行业', '周期' )
  246. AND IF ( category_name IN ( '医药行业' ), sub_category_name IN ( '趋势观察' ), 1 = 1 )
  247. AND IF ( category_name IN ( '科技行业' ), sub_category_name IN ( '产业跟踪' ), 1 = 1 )
  248. AND IF ( category_name IN ( '智造行业' ), sub_category_name IN ( '产业跟踪' ), 1 = 1 )
  249. AND IF ( category_name IN ( '消费行业' ), sub_category_name IN ( '月度调研' ), 1 = 1 )
  250. AND IF ( category_name IN ( '周期' ), sub_category_name IN ( '周度观点', '产业跟踪' ), 1 = 1 ) AND publish_status = 1 `
  251. pars = make([]interface{}, 0)
  252. articleList, e := models.GetArticleList(condition, pars)
  253. if e != nil {
  254. err = errors.New("GetArticleList, Err: " + e.Error())
  255. return
  256. }
  257. //文章一定会有值,这里就不做为空判断了 。。。
  258. var articleIds []string
  259. for _, v := range articleList {
  260. articleIds = append(articleIds, strconv.Itoa(v.ArticleId))
  261. }
  262. conditionInit = " AND source IN ('article','ficcreport') AND IF ( source = 'article' , source_id IN ( " + strings.Join(articleIds, ",") + ") ,1=1 ) AND IF ( source = 'ficcreport' , tag_name IN ('跟踪') ,1=1 ) "
  263. }
  264. return
  265. }