tag.go 11 KB

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