user_label.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. package cygx
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hz_crm_api/models"
  6. "hongze/hz_crm_api/models/cygx"
  7. "hongze/hz_crm_api/models/roadshow"
  8. "hongze/hz_crm_api/services/alarm_msg"
  9. "hongze/hz_crm_api/utils"
  10. "strconv"
  11. "strings"
  12. "time"
  13. )
  14. // 添加用户活动到会标签到Redis
  15. func ActivityUserLabelLogAdd(activityId int, userIdArr []int) (err error) {
  16. if len(userIdArr) == 0 {
  17. return
  18. }
  19. defer func() {
  20. if err != nil {
  21. fmt.Println(err)
  22. msg := fmt.Sprint("activityId:", activityId, "mobile:", userIdArr)
  23. go alarm_msg.SendAlarmMsg("添加用户活动到会标签到Redis,写入Redis队列消息失败:"+err.Error()+msg, 2)
  24. }
  25. }()
  26. var condition string
  27. var pars []interface{}
  28. condition = ` AND activity_id = ? `
  29. pars = append(pars, activityId)
  30. total, e := cygx.GetCygxIndustrialActivityGroupManagementCount(condition+" AND source = 1 ", pars)
  31. if e != nil {
  32. err = errors.New("GetCygxIndustrialActivityGroupManagementCount" + e.Error())
  33. return
  34. }
  35. if total == 0 {
  36. //没有关联产业的活动不做标签处理
  37. return
  38. }
  39. industrialList, e := cygx.GetCygxIndustrialActivityGroupManagementList(condition+" AND source = 1 ", pars)
  40. if e != nil {
  41. err = errors.New("GetCygxIndustrialActivityGroupManagementList, Err: " + e.Error())
  42. return
  43. }
  44. //如果有行产业归类就按照产业报告处理
  45. var topCond string
  46. var topPars []interface{}
  47. var industrialManagementIds []int
  48. for _, v := range industrialList {
  49. industrialManagementIds = append(industrialManagementIds, v.IndustrialManagementId)
  50. }
  51. idsLen := len(industrialManagementIds)
  52. if idsLen > 0 {
  53. topCond = ` AND industrial_management_id IN (` + utils.GetOrmInReplace(idsLen) + `)`
  54. topPars = append(topPars, industrialManagementIds)
  55. } else {
  56. return
  57. }
  58. industrNamelist, e := cygx.GetTopOneMonthArtReadNumIndustryAll(topCond, topPars)
  59. if e != nil {
  60. err = errors.New("GetTopOneMonthArtReadNumIndustryAll, Err: " + e.Error())
  61. return
  62. }
  63. userList, e := models.GetWxUserByUserIds(userIdArr)
  64. if e != nil {
  65. err = errors.New("GetWxUserByOutboundMobiles" + e.Error())
  66. return
  67. }
  68. listActivityHistory, e := cygx.GetCygxUserLabelActivity(condition, pars, 0, 9999)
  69. if e != nil {
  70. err = errors.New("GetCygxUserLabelActivity" + e.Error())
  71. return
  72. }
  73. activityHistoryMap := make(map[int]bool)
  74. for _, v := range listActivityHistory {
  75. activityHistoryMap[v.UserId] = true
  76. }
  77. var items []*cygx.CygxUserLabelActivity
  78. for _, user := range userList {
  79. //已经提交到会的活动写入标签的不做二次添加处理
  80. if activityHistoryMap[int(user.UserId)] {
  81. continue
  82. }
  83. // SourceType 1:文章阅读、 2产业关注、3:活动到会、4系列关注、5专项调研活动到会。
  84. log := &cygx.CygxUserLabelLogRedis{UserId: int(user.UserId), SourceId: activityId, SourceType: 3, CreateTime: time.Now()}
  85. if utils.Re == nil {
  86. err := utils.Rc.LPush(utils.CYGX_USER_KEY_LABEL, log)
  87. if err != nil {
  88. fmt.Println("CygxUserLabelLogRedis LPush Err:" + err.Error())
  89. }
  90. }
  91. for _, industr := range industrNamelist {
  92. item := new(cygx.CygxUserLabelActivity)
  93. item.UserId = int(user.UserId)
  94. item.CompanyId = user.CompanyId
  95. item.RealName = user.RealName
  96. item.Mobile = user.Mobile
  97. item.Email = user.Email
  98. item.ActivityId = activityId
  99. item.IndustrialManagementId = industr.IndustrialManagementId
  100. item.Label = industr.IndustryName
  101. item.CreateTime = time.Now()
  102. item.ModifyTime = time.Now()
  103. items = append(items, item)
  104. }
  105. }
  106. if len(items) > 0 {
  107. _, err = cygx.AddCygxUserLabelActivityList(items)
  108. }
  109. return
  110. }
  111. // 添加用户活动到会标签到Redis
  112. func ActivitySpecialUserLabelLogAdd(activityId int, userIdArr []int) (err error) {
  113. if len(userIdArr) == 0 {
  114. return
  115. }
  116. defer func() {
  117. if err != nil {
  118. fmt.Println(err)
  119. msg := fmt.Sprint("activityId:", activityId, "mobile:", userIdArr)
  120. go alarm_msg.SendAlarmMsg("添加用户专项调研活动到会标签到Redis,写入Redis队列消息失败:"+err.Error()+msg, 2)
  121. }
  122. }()
  123. var condition string
  124. var pars []interface{}
  125. condition = ` AND activity_id = ? `
  126. pars = append(pars, activityId)
  127. total, e := cygx.GetCygxIndustrialActivityGroupManagementCount(condition+" AND source = 2 ", pars)
  128. if e != nil {
  129. err = errors.New("GetCygxIndustrialActivityGroupManagementCount" + e.Error())
  130. return
  131. }
  132. if total == 0 {
  133. //没有关联产业的活动不做标签处理
  134. return
  135. }
  136. industrialList, e := cygx.GetCygxIndustrialActivityGroupManagementList(condition+" AND source = 2 ", pars)
  137. if e != nil {
  138. err = errors.New("GetCygxIndustrialActivityGroupManagementList, Err: " + e.Error())
  139. return
  140. }
  141. //如果有行产业归类就按照产业报告处理
  142. var topCond string
  143. var topPars []interface{}
  144. var industrialManagementIds []int
  145. for _, v := range industrialList {
  146. industrialManagementIds = append(industrialManagementIds, v.IndustrialManagementId)
  147. }
  148. idsLen := len(industrialManagementIds)
  149. if idsLen > 0 {
  150. topCond = ` AND industrial_management_id IN (` + utils.GetOrmInReplace(idsLen) + `)`
  151. topPars = append(topPars, industrialManagementIds)
  152. } else {
  153. return
  154. }
  155. industrNamelist, e := cygx.GetTopOneMonthArtReadNumIndustryAll(topCond, topPars)
  156. if e != nil {
  157. err = errors.New("GetTopOneMonthArtReadNumIndustryAll, Err: " + e.Error())
  158. return
  159. }
  160. userList, e := models.GetWxUserByUserIds(userIdArr)
  161. if e != nil {
  162. err = errors.New("GetWxUserByOutboundMobiles" + e.Error())
  163. return
  164. }
  165. listActivityHistory, e := cygx.GetCygxUserLabelActivitySpecial(condition, pars, 0, 9999)
  166. if e != nil {
  167. err = errors.New("GetCygxUserLabelActivity" + e.Error())
  168. return
  169. }
  170. activityHistoryMap := make(map[int]bool)
  171. for _, v := range listActivityHistory {
  172. activityHistoryMap[v.UserId] = true
  173. }
  174. var items []*cygx.CygxUserLabelActivitySpecial
  175. for _, user := range userList {
  176. //已经提交到会的活动写入标签的不做二次添加处理
  177. if activityHistoryMap[int(user.UserId)] {
  178. continue
  179. }
  180. // SourceType 1:文章阅读、 2产业关注、3:活动到会、4系列关注、5专项调研活动到会。
  181. log := &cygx.CygxUserLabelLogRedis{UserId: int(user.UserId), SourceId: activityId, SourceType: 5, CreateTime: time.Now()}
  182. if utils.Re == nil {
  183. err := utils.Rc.LPush(utils.CYGX_USER_KEY_LABEL, log)
  184. if err != nil {
  185. fmt.Println("CygxUserLabelLogRedis LPush Err:" + err.Error())
  186. }
  187. }
  188. for _, industr := range industrNamelist {
  189. item := new(cygx.CygxUserLabelActivitySpecial)
  190. item.UserId = int(user.UserId)
  191. item.CompanyId = user.CompanyId
  192. item.RealName = user.RealName
  193. item.Mobile = user.Mobile
  194. item.Email = user.Email
  195. item.ActivityId = activityId
  196. item.IndustrialManagementId = industr.IndustrialManagementId
  197. item.Label = industr.IndustryName
  198. item.CreateTime = time.Now()
  199. item.ModifyTime = time.Now()
  200. items = append(items, item)
  201. }
  202. }
  203. if len(items) > 0 {
  204. _, err = cygx.AddCygxUserLabelActivitySpecialList(items)
  205. }
  206. return
  207. }
  208. // 用户关注产业更新相关标签到Redis
  209. func IndustryFllowUserLabelLogAdd(industrialManagementId, count, uid int) (err error) {
  210. var isFllow int
  211. if count == 0 {
  212. isFllow = 1
  213. } else {
  214. isFllow = 0
  215. }
  216. defer func() {
  217. if err != nil {
  218. fmt.Println(err)
  219. msg := fmt.Sprint("industrialManagementId:", industrialManagementId, "isFllow:", isFllow, "userId:", uid)
  220. go alarm_msg.SendAlarmMsg("用户关注产业更新相关标签,写入Redis队列消息失败:"+err.Error()+msg, 2)
  221. }
  222. }()
  223. log := &cygx.CygxUserLabelLogRedis{UserId: uid, SourceId: industrialManagementId, SourceType: 2, IsFllow: isFllow, CreateTime: time.Now()}
  224. if utils.Re == nil {
  225. err := utils.Rc.LPush(utils.CYGX_USER_KEY_LABEL, log)
  226. if err != nil {
  227. fmt.Println("RecordNewLogs LPush Err:" + err.Error())
  228. }
  229. }
  230. return
  231. }
  232. // GetUserInteractionNumMap 根据用户ID 获取对应的用户互动量
  233. func GetUserInteractionNumMap(userIds []int) (mapResp map[int]int) {
  234. lenArr := len(userIds)
  235. if lenArr == 0 {
  236. return
  237. }
  238. var err error
  239. defer func() {
  240. if err != nil {
  241. fmt.Println(err)
  242. go alarm_msg.SendAlarmMsg(fmt.Sprint("GetUserInteractionNumMap 根据用户ID 获取对应的用户互动量 失败 userIds", userIds, err.Error()), 2)
  243. }
  244. }()
  245. var userIdsArr []string
  246. for _, v := range userIds {
  247. userIdsArr = append(userIdsArr, strconv.Itoa(v))
  248. }
  249. userIdstr := strings.Join(userIdsArr, ",")
  250. list, e := cygx.GetCygxCompanyUserListSplit(userIdstr)
  251. if e != nil {
  252. err = errors.New("GetCygxCompanyUserListSplit, Err: " + e.Error())
  253. return
  254. }
  255. mapResp = make(map[int]int, 0)
  256. for k, v := range list {
  257. mapResp[int(v.UserId)] = list[k].HistoryNum + list[k].CountNum + list[k].IndustryFllowNum + list[k].DepartmentFollowNum + list[k].KeyWordNum + list[k].OnLineNum + list[k].OfficeNum + list[k].ChartNum + list[k].TripNum + list[k].RoadshowVideoNum + list[k].ActivityVideoNum + list[k].ActivityVoiceNum + list[k].YanxuanspecialNum + list[k].FeedbackNum + list[k].RsCalendarNum
  258. }
  259. return
  260. }
  261. // 预处理1v1路演的参会人员信息
  262. func HandleListRsCalendar(list []*roadshow.RsCalendarMeetingUserByRai) (items []*cygx.UserInteraction, err error) {
  263. if len(list) == 0 {
  264. return
  265. }
  266. var rsCalendarIds []int
  267. for _, v := range list {
  268. rsCalendarIds = append(rsCalendarIds, v.RsCalendarId)
  269. }
  270. mapRsCalendarLabel := make(map[int][]string) //1v1 路演标签
  271. mapRsCalendarLabel = GetRsCalendarLabelByRsCalendarIds(rsCalendarIds)
  272. //获取研究员信息
  273. researchers, err := roadshow.GetRsCalendarResearcherListByIds(rsCalendarIds)
  274. if err != nil && err.Error() != utils.ErrNoRow() {
  275. return
  276. }
  277. mapResearcherName := make(map[int][]string)
  278. for _, v := range researchers {
  279. mapResearcherName[v.RsCalendarId] = append(mapResearcherName[v.RsCalendarId], v.ResearcherName)
  280. }
  281. //listGroup, err := roadshow.GetRsCalendarMeetingLabelGroupDetailByRsCalendarIds(rsCalendarIds)
  282. //if err != nil && err.Error() != utils.ErrNoRow() {
  283. // return
  284. //}
  285. //
  286. //var industrialManagementIds []int
  287. //var industrialSubjectIds []int
  288. //
  289. //mapindustrialManagementName := make(map[int]string)
  290. //mapindustrialSubjectName := make(map[int]string)
  291. //mapCelueName := make(map[int]string)
  292. //for _, v := range listGroup {
  293. // fmt.Println(v)
  294. // switch v.TagType {
  295. // case 1:
  296. // industrialManagementIds = append(industrialManagementIds, v.TagId)
  297. // case 2:
  298. // industrialSubjectIds = append(industrialSubjectIds, v.TagId)
  299. // case 3:
  300. // mapCelueName[v.RsCalendarId] = "策略"
  301. // }
  302. //}
  303. //if len(industrialManagementIds) > 0 {
  304. // IndustryList, e := cygx.GetIndustryListByConditionByIds(industrialManagementIds)
  305. // if e != nil {
  306. // err = errors.New("GetIndustryListByConditionByIds" + e.Error())
  307. // return
  308. // }
  309. //
  310. // for _, v := range IndustryList {
  311. // mapindustrialManagementName[v.IndustrialManagementId] = v.IndustryName
  312. // }
  313. //}
  314. //if len(industrialSubjectIds) > 0 {
  315. // SubjectList, e := cygx.GetIndustrialSubjectDetailByIds(industrialSubjectIds)
  316. // if e != nil {
  317. // err = errors.New("GetIndustryListByConditionByIds" + e.Error())
  318. // return
  319. // }
  320. // for _, v := range SubjectList {
  321. // mapindustrialSubjectName[v.IndustrialSubjectId] = v.SubjectName
  322. // }
  323. //}
  324. //mapGroupindustrialManagementName := make(map[int][]string)
  325. //mapGroupindustrialSubjectName := make(map[int][]string)
  326. //for _, v := range listGroup {
  327. // switch v.TagType {
  328. // case 1:
  329. // mapGroupindustrialManagementName[v.RsCalendarId] = append(mapGroupindustrialManagementName[v.RsCalendarId], mapindustrialManagementName[v.TagId])
  330. // case 2:
  331. // mapGroupindustrialSubjectName[v.RsCalendarId] = append(mapGroupindustrialSubjectName[v.RsCalendarId], mapindustrialSubjectName[v.TagId])
  332. // }
  333. //}
  334. for _, v := range list {
  335. item := new(cygx.UserInteraction)
  336. item.UserId = v.UserId
  337. item.RealName = v.RealName
  338. item.Mobile = v.Mobile
  339. item.CompanyId = v.CompanyId
  340. item.CompanyName = v.CompanyName
  341. item.RoadShowTheme = v.RoadShowTheme
  342. //switch v.TagType {
  343. //case 1:
  344. // item.LabelKeyWord = strings.Join(mapGroupindustrialManagementName[v.RsCalendarId], ",")
  345. //case 2:
  346. // item.LabelKeyWord = strings.Join(mapGroupindustrialSubjectName[v.RsCalendarId], ",")
  347. //case 3:
  348. // item.LabelKeyWord = mapCelueName[v.RsCalendarId]
  349. //}
  350. item.LabelKeyWord = strings.Join(mapRsCalendarLabel[v.RsCalendarId], ",")
  351. item.ActivityTimeText = v.StartDate + "(" + v.StartWeek + ")" + v.StartTime + "-" + v.EndTime
  352. item.ResearcherName = strings.Join(mapResearcherName[v.RsCalendarId], ",")
  353. items = append(items, item)
  354. }
  355. return
  356. }
  357. // 获取1V1路演标签信息
  358. func GetRsCalendarLabelByRsCalendarIds(rsCalendarIds []int) (respMap map[int][]string) {
  359. if len(rsCalendarIds) == 0 {
  360. return
  361. }
  362. var err error
  363. defer func() {
  364. if err != nil {
  365. fmt.Println(err)
  366. go alarm_msg.SendAlarmMsg(fmt.Sprint("获取1V1路演标签信息 失败 GetRsCalendarLabelByRsCalendarIds rsCalendarIds: ", rsCalendarIds, err.Error()), 2)
  367. }
  368. }()
  369. listEmail, err := cygx.GetAskEmail()
  370. if err != nil && err.Error() != utils.ErrNoRow() {
  371. return
  372. }
  373. var ceLueResearcherName []string
  374. var guShouResearcherName []string
  375. for _, v := range listEmail {
  376. if v.ChartPermissionName == utils.CE_LUE_NAME {
  377. ceLueResearcherName = append(ceLueResearcherName, v.Name)
  378. }
  379. if v.ChartPermissionName == utils.GU_SHOU_NAME {
  380. guShouResearcherName = append(guShouResearcherName, v.Name)
  381. }
  382. }
  383. //获取研究员信息
  384. researchers, err := roadshow.GetRsCalendarResearcherListByIds(rsCalendarIds)
  385. if err != nil && err.Error() != utils.ErrNoRow() {
  386. return
  387. }
  388. mapResearcherName := make(map[int][]string)
  389. for _, v := range researchers {
  390. if utils.InArrayByStr(ceLueResearcherName, v.ResearcherName) {
  391. mapResearcherName[v.RsCalendarId] = append(mapResearcherName[v.RsCalendarId], "策略")
  392. }
  393. if utils.InArrayByStr(guShouResearcherName, v.ResearcherName) {
  394. mapResearcherName[v.RsCalendarId] = append(mapResearcherName[v.RsCalendarId], "固收")
  395. }
  396. }
  397. listGroup, err := roadshow.GetRsCalendarMeetingLabelGroupDetailByRsCalendarIds(rsCalendarIds)
  398. if err != nil && err.Error() != utils.ErrNoRow() {
  399. return
  400. }
  401. var industrialManagementIds []int
  402. var industrialSubjectIds []int
  403. mapindustrialManagementName := make(map[int]string)
  404. mapindustrialSubjectName := make(map[int]string)
  405. mapCelueName := make(map[int]string)
  406. for _, v := range listGroup {
  407. switch v.TagType {
  408. case 1:
  409. industrialManagementIds = append(industrialManagementIds, v.TagId)
  410. case 2:
  411. industrialSubjectIds = append(industrialSubjectIds, v.TagId)
  412. case 3:
  413. mapCelueName[v.RsCalendarId] = strings.Join(mapResearcherName[v.RsCalendarId], ",")
  414. }
  415. }
  416. if len(industrialManagementIds) > 0 {
  417. IndustryList, e := cygx.GetIndustryListByConditionByIds(industrialManagementIds)
  418. if e != nil {
  419. err = errors.New("GetIndustryListByConditionByIds" + e.Error())
  420. return
  421. }
  422. for _, v := range IndustryList {
  423. mapindustrialManagementName[v.IndustrialManagementId] = v.IndustryName
  424. }
  425. }
  426. if len(industrialSubjectIds) > 0 {
  427. SubjectList, e := cygx.GetIndustrialSubjectDetailByIds(industrialSubjectIds)
  428. if e != nil {
  429. err = errors.New("GetIndustryListByConditionByIds" + e.Error())
  430. return
  431. }
  432. for _, v := range SubjectList {
  433. mapindustrialSubjectName[v.IndustrialSubjectId] = v.SubjectName
  434. }
  435. }
  436. respMap = make(map[int][]string, 0)
  437. for _, v := range listGroup {
  438. switch v.TagType {
  439. case 1:
  440. respMap[v.RsCalendarId] = append(respMap[v.RsCalendarId], mapindustrialManagementName[v.TagId])
  441. case 2:
  442. respMap[v.RsCalendarId] = append(respMap[v.RsCalendarId], mapindustrialSubjectName[v.TagId])
  443. case 3:
  444. respMap[v.RsCalendarId] = append(respMap[v.RsCalendarId], mapCelueName[v.RsCalendarId])
  445. }
  446. }
  447. for _, v := range rsCalendarIds {
  448. if len(respMap[v]) == 0 && len(mapResearcherName[v]) > 0 {
  449. respMap[v] = mapResearcherName[v]
  450. }
  451. }
  452. return
  453. }