wx_user_rai_label.go 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556
  1. package services
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "hongze/hongze_cygx/models"
  7. "hongze/hongze_cygx/models/roadshow"
  8. "hongze/hongze_cygx/utils"
  9. "strconv"
  10. "time"
  11. )
  12. // 添加用户搜索标签到Redis
  13. func KeyWordsWxUserRaiLabelRedisAdd(sourceId, uid int, label string) (err error) {
  14. defer func() {
  15. if err != nil {
  16. fmt.Println(err)
  17. msg := fmt.Sprint("sourceId:", sourceId, "userId:", uid)
  18. go utils.SendAlarmMsg("用户关注产业更新相关标签,写入Redis队列消息失败:"+err.Error()+msg, 2)
  19. }
  20. }()
  21. log := &models.WxUserRaiLabelRedis{UserId: uid, SourceId: sourceId, SourceType: 1, Label: label, CreateTime: time.Now(), RegisterPlatform: utils.REGISTER_PLATFORM}
  22. if utils.Re == nil {
  23. err := utils.Rc.LPush(utils.WX_USER_RAI_LABEL_KEY, log)
  24. if err != nil {
  25. fmt.Println("WxUserRaiLabelRedis LPush Err:" + err.Error())
  26. }
  27. }
  28. return
  29. }
  30. // 添加用户阅读文章标签到Redis
  31. func ArticleWxUserRaiLabelRedisAdd(sourceId, uid int, createTime time.Time) (err error) {
  32. defer func() {
  33. if err != nil {
  34. fmt.Println(err)
  35. msg := fmt.Sprint("sourceId:", sourceId, "userId:", uid)
  36. go utils.SendAlarmMsg("用户关注产业更新相关标签,写入Redis队列消息失败:"+err.Error()+msg, 2)
  37. }
  38. }()
  39. log := &models.WxUserRaiLabelRedis{UserId: uid, SourceId: sourceId, SourceType: 1, TableName: utils.CYGX_OBJ_ARTICLE, CreateTime: createTime, RegisterPlatform: utils.REGISTER_PLATFORM}
  40. if utils.Re == nil {
  41. err := utils.Rc.LPush(utils.WX_USER_RAI_LABEL_KEY, log)
  42. if err != nil {
  43. fmt.Println("WxUserRaiLabelRedis LPush Err:" + err.Error())
  44. }
  45. }
  46. return
  47. }
  48. // 添加用户阅读本周研究汇总,与重点公司标签到Redis
  49. func ReportSelectionWxUserRaiLabelRedisAdd(sourceId, uid int, createTime time.Time, tableName, label string) (err error) {
  50. defer func() {
  51. if err != nil {
  52. fmt.Println(err)
  53. msg := fmt.Sprint("sourceId:", sourceId, "userId:", uid)
  54. go utils.SendAlarmMsg("用户关注产业更新相关标签,写入Redis队列消息失败:"+err.Error()+msg, 2)
  55. }
  56. }()
  57. log := &models.WxUserRaiLabelRedis{UserId: uid, SourceId: sourceId, SourceType: 1, TableName: tableName, Label: label, CreateTime: createTime, RegisterPlatform: utils.REGISTER_PLATFORM}
  58. if utils.Re == nil {
  59. err := utils.Rc.LPush(utils.WX_USER_RAI_LABEL_KEY, log)
  60. if err != nil {
  61. fmt.Println("ReportSelectionWxUserRaiLabelRedisAdd LPush Err:" + err.Error())
  62. }
  63. }
  64. return
  65. }
  66. // 添加用户参加活动标签到Redis
  67. func ActivityWxUserRaiLabelRedisAdd(sourceId, uid int, createTime time.Time) (err error) {
  68. defer func() {
  69. if err != nil {
  70. fmt.Println(err)
  71. msg := fmt.Sprint("sourceId:", sourceId, "userId:", uid)
  72. go utils.SendAlarmMsg("添加用户参加活动标签,写入Redis队列消息失败:"+err.Error()+msg, 2)
  73. }
  74. }()
  75. log := &models.WxUserRaiLabelRedis{UserId: uid, SourceId: sourceId, SourceType: 2, CreateTime: createTime, RegisterPlatform: utils.REGISTER_PLATFORM}
  76. if utils.Re == nil {
  77. err := utils.Rc.LPush(utils.WX_USER_RAI_LABEL_KEY, log)
  78. if err != nil {
  79. fmt.Println("ActivityWxUserRaiLabelRedisAdd LPush Err:" + err.Error())
  80. }
  81. }
  82. return
  83. }
  84. func UpdateWxUserRaiLabelRedis() (err error) {
  85. for {
  86. // SourceType int `description:"来源1:搜索关键字标签、2:产业/个股标签(线下活动)、3:产业/个股标签(线下路演)、4:产业/个股标签(线上活动)、5:产业/个股标签(线上路演)、6:销售输入标签、7:产业/个股标签(报告)、8:报告类型标签"`
  87. utils.Rc.Brpop(utils.WX_USER_RAI_LABEL_KEY, func(b []byte) {
  88. var log models.WxUserRaiLabelRedis
  89. if err := json.Unmarshal(b, &log); err != nil {
  90. fmt.Println("json unmarshal wrong!")
  91. go utils.SendAlarmMsg("用户更新相关标签处理Redis队列消息失败:"+err.Error()+string(b), 2)
  92. }
  93. if log.TableName == "" {
  94. switch log.SourceType {
  95. case 1:
  96. go KeyWordsWxUserRaiLabelRedisAddReduce(log)
  97. fmt.Println("搜索关键词")
  98. break
  99. case 2, 4:
  100. go ActivityWxUserRaiLabelRedisAddReduce(log)
  101. fmt.Println("活动到会")
  102. break
  103. case 3, 5:
  104. go RoadshowWxUserRaiLabelRedisAddReduce(log)
  105. fmt.Println("活动到会")
  106. break
  107. default:
  108. fmt.Println(string(b))
  109. go utils.SendAlarmMsg("用户更新相关标签处理Redis队列消息失败:"+string(b), 2)
  110. }
  111. } else {
  112. switch log.TableName {
  113. case utils.CYGX_OBJ_ARTICLE:
  114. go ArticleWxUserRaiLabelRedisAddReduce(log)
  115. fmt.Println("阅读文章")
  116. case "cygx_research_summary":
  117. go ReportSelectionWxUserRaiLabelRedisAddReduce(log)
  118. fmt.Println("阅读本周研究汇总")
  119. case "cygx_report_selection":
  120. go ReportSelectionWxUserRaiLabelRedisAddReduce(log)
  121. fmt.Println("阅读报告精选(重点公司)")
  122. }
  123. }
  124. })
  125. }
  126. }
  127. // 1:搜索关键词
  128. func KeyWordsWxUserRaiLabelRedisAddReduce(log models.WxUserRaiLabelRedis) (err error) {
  129. defer func() {
  130. if err != nil {
  131. fmt.Println(err)
  132. go utils.SendAlarmMsg("用户文章阅读更新相关标签,处理Redis队列消息失败:"+err.Error()+fmt.Sprint("articleId", log.SourceId, "userId", log.UserId), 2)
  133. }
  134. }()
  135. userId := log.UserId
  136. label := log.Label
  137. if userId == 0 {
  138. return
  139. }
  140. wxUser, e := models.GetWxUserItemByUserId(userId)
  141. if e != nil {
  142. err = errors.New("GetWxUserItemByUserId" + e.Error())
  143. return
  144. }
  145. item := new(models.WxUserRaiLabel)
  146. item.UserId = wxUser.UserId
  147. item.RealName = wxUser.RealName
  148. item.Mobile = wxUser.Mobile
  149. item.Email = wxUser.Email
  150. item.CompanyId = wxUser.CompanyId
  151. item.CompanyName = wxUser.CompanyName
  152. item.Label = label
  153. item.SourceType = log.SourceType
  154. item.CreateTime = log.CreateTime
  155. item.ModifyTime = time.Now()
  156. item.RegisterPlatform = log.RegisterPlatform
  157. err = models.AddWxUserRaiLabel(item)
  158. if e != nil {
  159. err = errors.New("AddWxUserRaiLabel" + e.Error())
  160. return
  161. }
  162. return
  163. }
  164. //func init() {
  165. // log := models.WxUserRaiLabelRedis{UserId: 53840, SourceId: 1753, SourceType: 3, TableName: "", Label: "", CreateTime: time.Now(), RegisterPlatform: utils.REGISTER_PLATFORM}
  166. // RoadshowWxUserRaiLabelRedisAddReduce(log)
  167. //}
  168. // 2:产业/个股标签(线下活动)、 4:产业/个股标签(线上活动)
  169. // 用户参加活动,相关标签
  170. func ActivityWxUserRaiLabelRedisAddReduce(log models.WxUserRaiLabelRedis) (err error) {
  171. defer func() {
  172. if err != nil {
  173. fmt.Println(err)
  174. go utils.SendAlarmMsg("用户参加活动,相关标签,处理Redis队列消息失败:ActivityWxUserRaiLabelRedisAddReduce"+err.Error()+fmt.Sprint("SourceId", log.SourceId, "userId", log.UserId), 2)
  175. }
  176. }()
  177. userId := log.UserId
  178. sourceId := log.SourceId
  179. wxUser, e := models.GetWxUserItemByUserId(userId)
  180. if e != nil {
  181. err = errors.New("GetWxUserItemByUserId" + e.Error())
  182. return
  183. }
  184. activityDetail, e := models.GetAddActivityDetailByActivityId(sourceId)
  185. if e != nil {
  186. err = errors.New("GetArticleDetailTestById" + e.Error())
  187. return
  188. }
  189. var sourceType int
  190. if activityDetail.ActivityType == 1 {
  191. sourceType = 4
  192. } else {
  193. sourceType = 2
  194. }
  195. //正常的有产业报告
  196. var labelArr []string
  197. //建立首页资源表,与产业的关系
  198. industrialList, e := models.GetIndustrialActivityGroupManagementListByArticleId(sourceId)
  199. if e != nil && e.Error() != utils.ErrNoRow() {
  200. err = errors.New("GetIndustrialArticleGroupManagementListByArticleId, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  201. return
  202. }
  203. var items []*models.WxUserRaiLabel
  204. for _, v := range industrialList {
  205. item := new(models.WxUserRaiLabel)
  206. item.UserId = wxUser.UserId
  207. item.RealName = wxUser.RealName
  208. item.Mobile = wxUser.Mobile
  209. item.Email = wxUser.Email
  210. item.CompanyId = wxUser.CompanyId
  211. item.CompanyName = wxUser.CompanyName
  212. item.Label = v.IndustryName
  213. item.SourceType = sourceType
  214. item.SourceId = sourceId
  215. item.CreateTime = log.CreateTime
  216. item.ModifyTime = time.Now()
  217. item.RegisterPlatform = log.RegisterPlatform
  218. item.TableName = ""
  219. items = append(items, item)
  220. labelArr = append(labelArr, v.IndustryName)
  221. }
  222. //建立首页资源表,与标的 的关系
  223. subjectList, e := models.GetSubjectActivityGroupManagementListByActivityId(sourceId)
  224. if e != nil && e.Error() != utils.ErrNoRow() {
  225. err = errors.New("GetSubjectArticleGroupManagementListByArtcileId, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  226. return
  227. }
  228. //fmt.Println("subjectList", subjectList)
  229. for _, v := range subjectList {
  230. item := new(models.WxUserRaiLabel)
  231. item.UserId = wxUser.UserId
  232. item.RealName = wxUser.RealName
  233. item.Mobile = wxUser.Mobile
  234. item.Email = wxUser.Email
  235. item.CompanyId = wxUser.CompanyId
  236. item.CompanyName = wxUser.CompanyName
  237. item.Label = v.SubjectName
  238. item.SourceType = sourceType
  239. item.SourceId = sourceId
  240. item.CreateTime = log.CreateTime
  241. item.ModifyTime = time.Now()
  242. item.RegisterPlatform = log.RegisterPlatform
  243. item.TableName = ""
  244. items = append(items, item)
  245. labelArr = append(labelArr, v.SubjectName)
  246. }
  247. //如果两个标签都没有,就添加临时标签
  248. if len(labelArr) == 0 {
  249. item := new(models.WxUserRaiLabel)
  250. item.UserId = wxUser.UserId
  251. item.RealName = wxUser.RealName
  252. item.Mobile = wxUser.Mobile
  253. item.Email = wxUser.Email
  254. item.CompanyId = wxUser.CompanyId
  255. item.CompanyName = wxUser.CompanyName
  256. item.Label = activityDetail.Label
  257. item.SourceType = sourceType
  258. item.SourceId = sourceId
  259. item.CreateTime = log.CreateTime
  260. item.ModifyTime = time.Now()
  261. item.RegisterPlatform = log.RegisterPlatform
  262. item.TableName = ""
  263. items = append(items, item)
  264. labelArr = append(labelArr, activityDetail.Label)
  265. }
  266. e = models.AddWxUserRaiLabelMulti(items, labelArr, userId)
  267. if e != nil {
  268. err = errors.New("AddWxUserRaiLabelMulti" + e.Error())
  269. return
  270. }
  271. return
  272. }
  273. // 3:产业/个股标签(路演线下活动)、 5:产业/个股标签(路演线上活动)
  274. // 用户参加路演,相关标签
  275. func RoadshowWxUserRaiLabelRedisAddReduce(log models.WxUserRaiLabelRedis) (err error) {
  276. defer func() {
  277. if err != nil {
  278. fmt.Println(err)
  279. go utils.SendAlarmMsg("用户参加路演,相关标签,处理Redis队列消息失败:RoadshowWxUserRaiLabelRedisAddReduce"+err.Error()+fmt.Sprint("SourceId", log.SourceId, "userId", log.UserId), 2)
  280. }
  281. }()
  282. userId := log.UserId
  283. sourceId := log.SourceId
  284. wxUser, e := models.GetWxUserItemByUserId(userId)
  285. if e != nil {
  286. err = errors.New("GetWxUserItemByUserId" + e.Error())
  287. return
  288. }
  289. rsCalendar, e := roadshow.GetRsCalendarById(sourceId)
  290. if e != nil {
  291. err = errors.New("GetRsCalendarById" + e.Error())
  292. return
  293. }
  294. var sourceType int
  295. if rsCalendar.RoadshowType == "线下" {
  296. sourceType = 3
  297. } else {
  298. sourceType = 5
  299. }
  300. totalGroup, e := roadshow.GetRsCalendarMeetingLabelGroupByRsCalendarId(sourceId)
  301. if e != nil {
  302. err = errors.New("GetRsCalendarMeetingLabelGroupByRsCalendarId" + e.Error())
  303. return
  304. }
  305. //var lebelDetail []*cygx.RaiServeTagResp
  306. var label string
  307. var labelArr []string
  308. var items []*models.WxUserRaiLabel
  309. if totalGroup > 0 {
  310. listGroup, e := roadshow.GetRsCalendarMeetingLabelGroupListByRsCalendarId(sourceId)
  311. if e != nil {
  312. err = errors.New("GetRsCalendarMeetingLabelGroupByRsCalendarId" + e.Error())
  313. return
  314. }
  315. var industrialManagementIds []int
  316. var industrialSubjectIds []int
  317. mapindustrialManagementName := make(map[int]string)
  318. mapindustrialSubjectName := make(map[int]string)
  319. mapCelueName := make(map[int]string)
  320. for _, v := range listGroup {
  321. switch v.TagType {
  322. case 1:
  323. industrialManagementIds = append(industrialManagementIds, v.TagId)
  324. case 2:
  325. industrialSubjectIds = append(industrialSubjectIds, v.TagId)
  326. case 3:
  327. mapCelueName[v.TagId] = "策略"
  328. }
  329. }
  330. if len(industrialManagementIds) > 0 {
  331. IndustryList, e := models.GetIndustryListByConditionByIds(industrialManagementIds)
  332. if e != nil {
  333. err = errors.New("GetRsCalendarMeetingLabelGroupByRsCalendarId" + e.Error())
  334. return
  335. }
  336. for _, v := range IndustryList {
  337. mapindustrialManagementName[v.IndustrialManagementId] = v.IndustryName
  338. }
  339. }
  340. if len(industrialSubjectIds) > 0 {
  341. SubjectList, e := models.GetIndustrialSubjectDetailByIds(industrialSubjectIds)
  342. if e != nil {
  343. err = errors.New("GetIndustrialSubjectDetailByIds" + e.Error())
  344. return
  345. }
  346. for _, v := range SubjectList {
  347. mapindustrialSubjectName[v.IndustrialSubjectId] = v.SubjectName
  348. }
  349. }
  350. for _, v := range listGroup {
  351. switch v.TagType {
  352. case 1:
  353. label = mapindustrialManagementName[v.TagId]
  354. case 2:
  355. label = mapindustrialSubjectName[v.TagId]
  356. case 3:
  357. label = mapCelueName[v.TagId]
  358. }
  359. item := new(models.WxUserRaiLabel)
  360. item.UserId = wxUser.UserId
  361. item.RealName = wxUser.RealName
  362. item.Mobile = wxUser.Mobile
  363. item.Email = wxUser.Email
  364. item.CompanyId = wxUser.CompanyId
  365. item.CompanyName = wxUser.CompanyName
  366. item.Label = label
  367. item.SourceType = sourceType
  368. item.SourceId = sourceId
  369. item.CreateTime = log.CreateTime
  370. item.ModifyTime = time.Now()
  371. item.RegisterPlatform = log.RegisterPlatform
  372. item.TableName = ""
  373. items = append(items, item)
  374. labelArr = append(labelArr, label)
  375. }
  376. }
  377. e = models.AddWxUserRaiLabelMulti(items, labelArr, userId)
  378. if e != nil {
  379. err = errors.New("AddWxUserRaiLabelMulti" + e.Error())
  380. return
  381. }
  382. return
  383. }
  384. // 7:产业/个股标签(报告)、8:报告类型标签
  385. func ArticleWxUserRaiLabelRedisAddReduce(log models.WxUserRaiLabelRedis) (err error) {
  386. defer func() {
  387. if err != nil {
  388. fmt.Println(err)
  389. go utils.SendAlarmMsg("用户文章阅读更新相关标签,处理Redis队列消息失败:"+err.Error()+fmt.Sprint("articleId", log.SourceId, "userId", log.UserId), 2)
  390. }
  391. }()
  392. userId := log.UserId
  393. sourceId := log.SourceId
  394. wxUser, e := models.GetWxUserItemByUserId(userId)
  395. if e != nil {
  396. err = errors.New("GetWxUserItemByUserId" + e.Error())
  397. return
  398. }
  399. //articleDetail, e := models.GetArticleDetailTestById(sourceId)
  400. //if e != nil {
  401. // err = errors.New("GetArticleDetailTestById" + e.Error())
  402. // return
  403. //}
  404. labelArr, sourceType := GetArticlelabelArrByArticleId(sourceId)
  405. if len(labelArr) == 0 {
  406. return
  407. }
  408. var items []*models.WxUserRaiLabel
  409. for _, v := range labelArr {
  410. item := new(models.WxUserRaiLabel)
  411. item.UserId = wxUser.UserId
  412. item.RealName = wxUser.RealName
  413. item.Mobile = wxUser.Mobile
  414. item.Email = wxUser.Email
  415. item.CompanyId = wxUser.CompanyId
  416. item.CompanyName = wxUser.CompanyName
  417. item.Label = v
  418. item.SourceType = sourceType
  419. item.SourceId = sourceId
  420. item.CreateTime = log.CreateTime
  421. item.ModifyTime = time.Now()
  422. item.RegisterPlatform = log.RegisterPlatform
  423. item.TableName = "cygx_article"
  424. items = append(items, item)
  425. //labelArr = append(labelArr, v.IndustryName)
  426. }
  427. //articlePermission, e := models.GetArticlePermission(articleDetail.CategoryId)
  428. //if e != nil {
  429. // err = errors.New("GetArticlePermission" + e.Error())
  430. // return
  431. //}
  432. //if articlePermission == nil {
  433. // err = errors.New("报告权限不存在" + e.Error())
  434. // return
  435. //}
  436. //articlePermissionName := articlePermission.PermissionName
  437. //matchTypeName := articlePermission.MatchTypeName
  438. //matchTypeNameArr := []string{"季度策略", "科技前沿(周报)", "本周荟", "智造精粹"}
  439. //
  440. ////1;四大行业汇总类报告:季度策略、科技前沿(周报)、本周荟、智造精粹以报告类型做标签
  441. ////2:策略、固收的所有报告,以报告类型做标签
  442. //if articlePermissionName == utils.CE_LUE_NAME || articlePermissionName == utils.GU_SHOU_NAME || utils.InArrayByStr(matchTypeNameArr, matchTypeName) { // 策略、固收的所有报告,以报告类型做标签
  443. // if matchTypeName == "季度策略" {
  444. // matchTypeName = articlePermissionName + matchTypeName //其中季度策略以:xx行业季度策略 呈现
  445. // }
  446. // item := new(models.WxUserRaiLabel)
  447. // item.UserId = wxUser.UserId
  448. // item.RealName = wxUser.RealName
  449. // item.Mobile = wxUser.Mobile
  450. // item.Email = wxUser.Email
  451. // item.CompanyId = wxUser.CompanyId
  452. // item.CompanyName = wxUser.CompanyName
  453. // item.Label = matchTypeName
  454. // item.SourceType = 8
  455. // item.SourceId = sourceId
  456. // item.CreateTime = log.CreateTime
  457. // item.ModifyTime = time.Now()
  458. // item.RegisterPlatform = log.RegisterPlatform
  459. // item.TableName = "cygx_article"
  460. // err = models.AddWxUserRaiLabel(item)
  461. // if e != nil {
  462. // err = errors.New("AddWxUserRaiLabel" + e.Error())
  463. // return
  464. // }
  465. //} else if articlePermissionName == utils.ZHOU_QI_NAME {
  466. // //周期的行业深度、调研纪要、产业跟踪这些系列的报告用领域做标签,其余的周期报告,都用报告类型(也就是ficc定义的类型)做标签
  467. // //其中周期的周度观点,以 周期周度观点 呈现
  468. // matchTypeNameArrZhouqi := []string{"行业深度", "调研纪要", "产业跟踪"}
  469. // if utils.InArrayByStr(matchTypeNameArrZhouqi, matchTypeName) {
  470. // matchTypeName = articleDetail.FieldName
  471. // }
  472. // item := new(models.WxUserRaiLabel)
  473. // item.UserId = wxUser.UserId
  474. // item.RealName = wxUser.RealName
  475. // item.Mobile = wxUser.Mobile
  476. // item.Email = wxUser.Email
  477. // item.CompanyId = wxUser.CompanyId
  478. // item.CompanyName = wxUser.CompanyName
  479. // item.Label = matchTypeName
  480. // item.SourceType = 8
  481. // item.SourceId = sourceId
  482. // item.CreateTime = log.CreateTime
  483. // item.ModifyTime = time.Now()
  484. // item.RegisterPlatform = log.RegisterPlatform
  485. // item.TableName = "cygx_article"
  486. // e = models.AddWxUserRaiLabel(item)
  487. // if e != nil {
  488. // err = errors.New("AddWxUserRaiLabel" + e.Error())
  489. // return
  490. // }
  491. //} else {
  492. // //正常的有产业报告
  493. // var labelArr []string
  494. // //建立首页资源表,与产业的关系
  495. // industrialList, e := models.GetIndustrialArticleGroupManagementListByArticleId(sourceId)
  496. // if e != nil && e.Error() != utils.ErrNoRow() {
  497. // err = errors.New("GetIndustrialArticleGroupManagementListByArticleId, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  498. // return
  499. // }
  500. //
  501. // var items []*models.WxUserRaiLabel
  502. // for _, v := range industrialList {
  503. // item := new(models.WxUserRaiLabel)
  504. // item.UserId = wxUser.UserId
  505. // item.RealName = wxUser.RealName
  506. // item.Mobile = wxUser.Mobile
  507. // item.Email = wxUser.Email
  508. // item.CompanyId = wxUser.CompanyId
  509. // item.CompanyName = wxUser.CompanyName
  510. // item.Label = v.IndustryName
  511. // item.SourceType = 7
  512. // item.SourceId = sourceId
  513. // item.CreateTime = log.CreateTime
  514. // item.ModifyTime = time.Now()
  515. // item.RegisterPlatform = log.RegisterPlatform
  516. // item.TableName = "cygx_article"
  517. // items = append(items, item)
  518. // labelArr = append(labelArr, v.IndustryName)
  519. // }
  520. //
  521. // //建立首页资源表,与标的 的关系
  522. // subjectList, e := models.GetSubjectArticleGroupManagementListByArtcileId(sourceId)
  523. // if e != nil && e.Error() != utils.ErrNoRow() {
  524. // err = errors.New("GetSubjectArticleGroupManagementListByArtcileId, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  525. // return
  526. // }
  527. //
  528. // for _, v := range subjectList {
  529. // item := new(models.WxUserRaiLabel)
  530. // item.UserId = wxUser.UserId
  531. // item.RealName = wxUser.RealName
  532. // item.Mobile = wxUser.Mobile
  533. // item.Email = wxUser.Email
  534. // item.CompanyId = wxUser.CompanyId
  535. // item.CompanyName = wxUser.CompanyName
  536. // item.Label = v.SubjectName
  537. // item.SourceType = 7
  538. // item.SourceId = sourceId
  539. // item.CreateTime = log.CreateTime
  540. // item.ModifyTime = time.Now()
  541. // item.RegisterPlatform = log.RegisterPlatform
  542. // item.TableName = "cygx_article"
  543. // items = append(items, item)
  544. // labelArr = append(labelArr, v.SubjectName)
  545. // }
  546. // e = models.AddWxUserRaiLabelMulti(items, labelArr, userId)
  547. // if e != nil {
  548. // err = errors.New("AddWxUserRaiLabelMulti" + e.Error())
  549. // return
  550. // }
  551. //}
  552. e = models.AddWxUserRaiLabelMulti(items, labelArr, userId)
  553. if e != nil {
  554. err = errors.New("AddWxUserRaiLabelMulti" + e.Error())
  555. return
  556. }
  557. return
  558. }
  559. // 8:报告类型标签 (本周研究汇总,与重点公司)
  560. func ReportSelectionWxUserRaiLabelRedisAddReduce(log models.WxUserRaiLabelRedis) (err error) {
  561. defer func() {
  562. if err != nil {
  563. fmt.Println(err)
  564. go utils.SendAlarmMsg("报告类型标签 (本周研究汇总,与重点公司),处理Redis队列消息失败:ReportSelectionWxUserRaiLabelRedisAddReduce"+err.Error()+fmt.Sprint("SourceId", log.SourceId, "userId", log.UserId), 2)
  565. }
  566. }()
  567. userId := log.UserId
  568. sourceId := log.SourceId
  569. wxUser, e := models.GetWxUserItemByUserId(userId)
  570. if e != nil {
  571. err = errors.New("GetWxUserItemByUserId" + e.Error())
  572. return
  573. }
  574. item := new(models.WxUserRaiLabel)
  575. item.UserId = wxUser.UserId
  576. item.RealName = wxUser.RealName
  577. item.Mobile = wxUser.Mobile
  578. item.Email = wxUser.Email
  579. item.CompanyId = wxUser.CompanyId
  580. item.CompanyName = wxUser.CompanyName
  581. item.Label = log.Label
  582. item.SourceType = 8
  583. item.SourceId = sourceId
  584. item.CreateTime = log.CreateTime
  585. item.ModifyTime = time.Now()
  586. item.RegisterPlatform = log.RegisterPlatform
  587. item.TableName = log.TableName
  588. err = models.AddWxUserRaiLabel(item)
  589. if e != nil {
  590. err = errors.New("AddWxUserRaiLabel" + e.Error())
  591. return
  592. }
  593. return
  594. }
  595. func GetArticlelabelArrByArticleId(articleId int) (labelArr []string, sourceType int) {
  596. articleDetail, e := models.GetArticleDetailTestById(articleId)
  597. if e != nil {
  598. fmt.Println(e)
  599. return
  600. }
  601. if articleDetail.ArticleTypeId > 0 {
  602. //正常的有产业报告
  603. //建立首页资源表,与产业的关系
  604. industrialList, e := models.GetIndustrialArticleGroupManagementListByArticleId(articleId)
  605. if e != nil && e.Error() != utils.ErrNoRow() {
  606. fmt.Println(e)
  607. return
  608. }
  609. for _, v := range industrialList {
  610. labelArr = append(labelArr, v.IndustryName)
  611. }
  612. //建立首页资源表,与标的 的关系
  613. subjectList, e := models.GetSubjectArticleGroupManagementListByArtcileId(articleId)
  614. if e != nil && e.Error() != utils.ErrNoRow() {
  615. fmt.Println(e)
  616. return
  617. }
  618. for _, v := range subjectList {
  619. labelArr = append(labelArr, v.SubjectName)
  620. }
  621. sourceType = 7
  622. return
  623. }
  624. articlePermission, e := models.GetArticlePermission(articleDetail.CategoryId)
  625. if e != nil {
  626. fmt.Println(e)
  627. return
  628. }
  629. if articlePermission == nil {
  630. fmt.Println(e)
  631. return
  632. }
  633. articlePermissionName := articlePermission.PermissionName
  634. matchTypeName := articlePermission.MatchTypeName
  635. matchTypeNameArr := []string{"季度策略", "科技前沿(周报)", "本周荟", "智造精粹"}
  636. //1;四大行业汇总类报告:季度策略、科技前沿(周报)、本周荟、智造精粹以报告类型做标签
  637. //2:策略、固收的所有报告,以报告类型做标签
  638. //var labelArr []string
  639. if articlePermissionName == utils.CE_LUE_NAME || articlePermissionName == utils.GU_SHOU_NAME || utils.InArrayByStr(matchTypeNameArr, matchTypeName) { // 策略、固收的所有报告,以报告类型做标签
  640. if matchTypeName == "季度策略" {
  641. matchTypeName = articlePermissionName + matchTypeName //其中季度策略以:xx行业季度策略 呈现
  642. }
  643. labelArr = append(labelArr, matchTypeName)
  644. sourceType = 8
  645. } else if articlePermissionName == utils.ZHOU_QI_NAME {
  646. //周期的行业深度、调研纪要、产业跟踪这些系列的报告用领域做标签,其余的周期报告,都用报告类型(也就是ficc定义的类型)做标签
  647. //其中周期的周度观点,以 周期周度观点 呈现
  648. matchTypeNameArrZhouqi := []string{"行业深度", "调研纪要", "产业跟踪"}
  649. if utils.InArrayByStr(matchTypeNameArrZhouqi, matchTypeName) {
  650. matchTypeName = articleDetail.FieldName
  651. }
  652. labelArr = append(labelArr, matchTypeName)
  653. sourceType = 8
  654. } else {
  655. //正常的有产业报告
  656. //建立首页资源表,与产业的关系
  657. industrialList, e := models.GetIndustrialArticleGroupManagementListByArticleId(articleId)
  658. if e != nil && e.Error() != utils.ErrNoRow() {
  659. fmt.Println(e)
  660. return
  661. }
  662. for _, v := range industrialList {
  663. labelArr = append(labelArr, v.IndustryName)
  664. }
  665. //建立首页资源表,与标的 的关系
  666. subjectList, e := models.GetSubjectArticleGroupManagementListByArtcileId(articleId)
  667. if e != nil && e.Error() != utils.ErrNoRow() {
  668. fmt.Println(e)
  669. return
  670. }
  671. for _, v := range subjectList {
  672. labelArr = append(labelArr, v.SubjectName)
  673. }
  674. sourceType = 7
  675. }
  676. return
  677. }
  678. //func init() {
  679. // //fmt.Println(GetArticlelabelArrByArticleId(11037))
  680. // //initCrm16_5Article2()
  681. //}
  682. func initCrm16_5keyWord() {
  683. listKeyWords, err := models.GetSearchKeyWordinitCrm16_5()
  684. if err != nil {
  685. fmt.Println(err)
  686. return
  687. }
  688. var mobiles []string
  689. mapMobile := make(map[string]bool)
  690. for _, v := range listKeyWords {
  691. if mapMobile[v.Mobile] || v.Mobile == "" {
  692. continue
  693. }
  694. mapMobile[v.Mobile] = true
  695. mobiles = append(mobiles, v.Mobile)
  696. }
  697. listUser, err := models.GetWxUserListByMobileArr(mobiles)
  698. if err != nil {
  699. fmt.Println(err)
  700. return
  701. }
  702. mapUser := make(map[string]*models.WxUserItem)
  703. for _, v := range listUser {
  704. mapUser[v.Mobile] = v
  705. }
  706. var items []*models.WxUserRaiLabelLog
  707. for _, v := range listKeyWords {
  708. if mapUser[v.Mobile] == nil || v.Mobile == "" {
  709. continue
  710. }
  711. wxUser := mapUser[v.Mobile]
  712. item := new(models.WxUserRaiLabelLog)
  713. item.UserId = wxUser.UserId
  714. item.RealName = wxUser.RealName
  715. item.Mobile = wxUser.Mobile
  716. item.Email = wxUser.Email
  717. item.CompanyId = wxUser.CompanyId
  718. item.CompanyName = wxUser.CompanyName
  719. item.Label = v.KeyWord
  720. item.SourceType = 1
  721. item.CreateTime = v.CreateTime
  722. item.ModifyTime = time.Now()
  723. item.RegisterPlatform = v.RegisterPlatform
  724. items = append(items, item)
  725. }
  726. fmt.Println(len(items))
  727. var itemsAdd []*models.WxUserRaiLabelLog
  728. if len(items) > 0 {
  729. for _, v := range items {
  730. itemsAdd = append(itemsAdd, v)
  731. if len(items)%2000 == 0 {
  732. err = models.AddWxUserRaiLabelLogMultiInit(itemsAdd)
  733. if err != nil {
  734. return
  735. }
  736. itemsAdd = make([]*models.WxUserRaiLabelLog, 0)
  737. }
  738. }
  739. }
  740. if len(itemsAdd) > 0 {
  741. err = models.AddWxUserRaiLabelLogMultiInit(itemsAdd)
  742. if err != nil {
  743. return
  744. }
  745. }
  746. fmt.Println("endAddWxUserRaiLabelLogMultiInit")
  747. }
  748. func initCrm16_5Activity() {
  749. var condition string
  750. var pars []interface{}
  751. condition += ` AND create_time > '2024-09-01' AND (is_meeting =1 OR duration != '') `
  752. pars = append(pars)
  753. //获取提交到会的人员信息
  754. signUpDetailList, err := models.GetSignupDetailList(condition, pars)
  755. if err != nil {
  756. fmt.Println(err)
  757. return
  758. }
  759. var mobiles []string
  760. mapMobile := make(map[string]bool)
  761. for _, v := range signUpDetailList {
  762. if mapMobile[v.Mobile] || v.Mobile == "" {
  763. continue
  764. }
  765. mapMobile[v.Mobile] = true
  766. mobiles = append(mobiles, v.Mobile)
  767. }
  768. var activityIds []int
  769. mapactivityId := make(map[int]bool)
  770. for _, v := range signUpDetailList {
  771. if mapactivityId[v.ActivityId] {
  772. continue
  773. }
  774. mapactivityId[v.ActivityId] = true
  775. activityIds = append(activityIds, v.ActivityId)
  776. }
  777. listUser, err := models.GetWxUserListByMobileArr(mobiles)
  778. if err != nil {
  779. fmt.Println(err)
  780. return
  781. }
  782. mapUser := make(map[string]*models.WxUserItem)
  783. for _, v := range listUser {
  784. mapUser[v.Mobile] = v
  785. }
  786. activityDetailList, e := models.GetAddActivityDetailByActivityIdinitCrm16_5(activityIds)
  787. if e != nil {
  788. fmt.Println(e)
  789. return
  790. }
  791. sourceTypemap := make(map[int]int)
  792. mapLabel := make(map[int]string)
  793. for _, v := range activityDetailList {
  794. if v.ActivityType == 1 {
  795. sourceTypemap[v.ActivityId] = 4
  796. } else {
  797. sourceTypemap[v.ActivityId] = 2
  798. }
  799. mapLabel[v.ActivityId] = v.Label
  800. }
  801. //正常的有产业报告
  802. //建立首页资源表,与产业的关系
  803. industrialList, e := models.GetIndustrialActivityGroupManagementListByArticleIds(activityIds)
  804. if e != nil && e.Error() != utils.ErrNoRow() {
  805. fmt.Println(e)
  806. return
  807. }
  808. //建立首页资源表,与标的 的关系
  809. subjectList, e := models.GetSubjectActivityGroupManagementListByActivityIds(activityIds)
  810. if e != nil && e.Error() != utils.ErrNoRow() {
  811. fmt.Println(e)
  812. return
  813. }
  814. var items []*models.WxUserRaiLabelLog
  815. for _, v := range signUpDetailList {
  816. if mapUser[v.Mobile] == nil || v.Mobile == "" {
  817. continue
  818. }
  819. var haseName bool
  820. wxUser := mapUser[v.Mobile]
  821. for _, vI := range industrialList {
  822. if vI.ActivityId != v.ActivityId {
  823. continue
  824. }
  825. haseName = true
  826. item := new(models.WxUserRaiLabelLog)
  827. item.UserId = wxUser.UserId
  828. item.RealName = wxUser.RealName
  829. item.Mobile = wxUser.Mobile
  830. item.Email = wxUser.Email
  831. item.CompanyId = wxUser.CompanyId
  832. item.CompanyName = wxUser.CompanyName
  833. item.Label = vI.IndustryName
  834. item.SourceType = sourceTypemap[v.ActivityId]
  835. item.SourceId = v.ActivityId
  836. item.CreateTime = v.CreateTime
  837. item.ModifyTime = time.Now()
  838. item.TableName = ""
  839. //item.RegisterPlatform = v.RegisterPlatform
  840. items = append(items, item)
  841. }
  842. for _, vs := range subjectList {
  843. if vs.ActivityId != v.ActivityId {
  844. continue
  845. }
  846. haseName = true
  847. item := new(models.WxUserRaiLabelLog)
  848. item.UserId = wxUser.UserId
  849. item.RealName = wxUser.RealName
  850. item.Mobile = wxUser.Mobile
  851. item.Email = wxUser.Email
  852. item.CompanyId = wxUser.CompanyId
  853. item.CompanyName = wxUser.CompanyName
  854. item.Label = vs.SubjectName
  855. item.SourceType = sourceTypemap[v.ActivityId]
  856. item.SourceId = v.ActivityId
  857. item.CreateTime = v.CreateTime
  858. item.ModifyTime = time.Now()
  859. //item.RegisterPlatform = v.RegisterPlatform
  860. items = append(items, item)
  861. }
  862. //如果两个标签都没有,就添加临时标签
  863. if !haseName {
  864. item := new(models.WxUserRaiLabelLog)
  865. item.UserId = wxUser.UserId
  866. item.RealName = wxUser.RealName
  867. item.Mobile = wxUser.Mobile
  868. item.Email = wxUser.Email
  869. item.CompanyId = wxUser.CompanyId
  870. item.CompanyName = wxUser.CompanyName
  871. item.Label = mapLabel[v.ActivityId]
  872. item.SourceType = sourceTypemap[v.ActivityId]
  873. item.SourceId = v.ActivityId
  874. item.CreateTime = v.CreateTime
  875. item.ModifyTime = time.Now()
  876. //item.RegisterPlatform = v.RegisterPlatform
  877. item.TableName = ""
  878. items = append(items, item)
  879. }
  880. }
  881. //fmt.Println("initCrm16_5Activity", len(items))
  882. //return
  883. var itemsAdd []*models.WxUserRaiLabelLog
  884. if len(items) > 0 {
  885. for _, v := range items {
  886. itemsAdd = append(itemsAdd, v)
  887. if len(itemsAdd)%2000 == 0 {
  888. err = models.AddWxUserRaiLabelLogMultiInit(itemsAdd)
  889. if err != nil {
  890. return
  891. }
  892. itemsAdd = make([]*models.WxUserRaiLabelLog, 0)
  893. }
  894. }
  895. }
  896. if len(itemsAdd) > 0 {
  897. err = models.AddWxUserRaiLabelLogMultiInit(itemsAdd)
  898. if err != nil {
  899. return
  900. }
  901. }
  902. fmt.Println("endAddWxUserRaiLabelLogMultiInit")
  903. }
  904. func initCrm16_5Article() {
  905. var condition string
  906. var pars []interface{}
  907. condition += ` `
  908. pars = append(pars)
  909. listArticleIds, err := models.GetCygxArticleHistoryRecordAllListArticleIdCrm16_5()
  910. if err != nil {
  911. fmt.Println(err)
  912. return
  913. }
  914. fmt.Println("listArticleIds", len(listArticleIds))
  915. listHave, err := models.GetWxUserRaiArticleLabelCrm16_5()
  916. if err != nil {
  917. fmt.Println(err)
  918. return
  919. }
  920. mapArticleId := make(map[int]bool)
  921. for _, v := range listHave {
  922. mapArticleId[v.ArticleId] = true
  923. }
  924. for k, v := range listArticleIds {
  925. fmt.Println(k)
  926. labelArr, sourceType := GetArticlelabelArrByArticleId(v.ArticleId)
  927. if len(labelArr) == 0 {
  928. continue
  929. }
  930. var items []*models.WxUserRaiArticleLabel
  931. for _, v2 := range labelArr {
  932. item := new(models.WxUserRaiArticleLabel)
  933. item.ArticleId = v.ArticleId
  934. item.Label = v2
  935. item.SourceType = sourceType
  936. item.CreateTime = time.Now()
  937. items = append(items, item)
  938. }
  939. err = models.AddWxUserRaiArticleLabelMultiInit(items)
  940. time.Sleep(time.Millisecond * 100)
  941. fmt.Println(err)
  942. }
  943. }
  944. func initCrm16_5Article2() {
  945. var condition string
  946. var pars []interface{}
  947. condition += ` `
  948. pars = append(pars)
  949. //获取提交到会的人员信息
  950. listArticleIds, err := models.GetCygxArticleHistoryRecordAllListUserIdCrm16_5()
  951. if err != nil {
  952. fmt.Println(err)
  953. return
  954. }
  955. fmt.Println("listArticleIds", len(listArticleIds))
  956. mapUserId := make(map[string]bool)
  957. var mobiles []string
  958. for _, v := range listArticleIds {
  959. if mapUserId[v.Mobile] {
  960. continue
  961. }
  962. mobiles = append(mobiles, v.Mobile)
  963. mapUserId[v.Mobile] = true
  964. }
  965. listUser, err := models.GetWxUserListByMobileArr(mobiles)
  966. if err != nil {
  967. fmt.Println(err)
  968. return
  969. }
  970. mapUser := make(map[string]*models.WxUserItem)
  971. for _, v := range listUser {
  972. mapUser[v.Mobile] = v
  973. }
  974. listArticleLabel, err := models.GetWxUserRaiArticleLabelAllCrm16_5()
  975. if err != nil {
  976. fmt.Println(err)
  977. return
  978. }
  979. mapArticleLabel := make(map[int][]string)
  980. mapArticleType := make(map[int]int)
  981. for _, v := range listArticleLabel {
  982. mapArticleLabel[v.ArticleId] = append(mapArticleLabel[v.ArticleId], v.Label)
  983. mapArticleType[v.ArticleId] = v.SourceType
  984. }
  985. var items []*models.WxUserRaiLabelLog
  986. for _, v := range listArticleIds {
  987. if mapUser[v.Mobile] == nil || v.Mobile == "" {
  988. continue
  989. }
  990. if len(mapArticleLabel[v.ArticleId]) == 0 {
  991. continue
  992. }
  993. wxUser := mapUser[v.Mobile]
  994. for _, vI := range mapArticleLabel[v.ArticleId] {
  995. item := new(models.WxUserRaiLabelLog)
  996. item.UserId = wxUser.UserId
  997. item.RealName = wxUser.RealName
  998. item.Mobile = wxUser.Mobile
  999. item.Email = wxUser.Email
  1000. item.CompanyId = wxUser.CompanyId
  1001. item.CompanyName = wxUser.CompanyName
  1002. item.Label = vI
  1003. item.SourceType = mapArticleType[v.ArticleId]
  1004. item.SourceId = v.ArticleId
  1005. item.CreateTime = utils.StrTimeToTime(v.CreateTime)
  1006. item.ModifyTime = time.Now()
  1007. item.TableName = "cygx_article"
  1008. //item.RegisterPlatform = v.RegisterPlatform
  1009. items = append(items, item)
  1010. }
  1011. }
  1012. fmt.Println("items", len(items))
  1013. var itemsAdd []*models.WxUserRaiLabelLog
  1014. if len(items) > 0 {
  1015. for _, v := range items {
  1016. itemsAdd = append(itemsAdd, v)
  1017. if len(itemsAdd)%2000 == 0 {
  1018. err = models.AddWxUserRaiLabelLogMultiInit(itemsAdd)
  1019. if err != nil {
  1020. fmt.Println(err)
  1021. return
  1022. }
  1023. itemsAdd = make([]*models.WxUserRaiLabelLog, 0)
  1024. }
  1025. }
  1026. }
  1027. if len(itemsAdd) > 0 {
  1028. err = models.AddWxUserRaiLabelLogMultiInit(itemsAdd)
  1029. if err != nil {
  1030. fmt.Println(err)
  1031. return
  1032. }
  1033. }
  1034. fmt.Println("endAddWxUserRaiLabelLogMultiInit")
  1035. }
  1036. ////func init() {
  1037. // //initCrm16_5keyWord()
  1038. // //initCrm16_5Activity()
  1039. // //initCrm16_5Article2()
  1040. // //initCrm16_5ReportHistory()
  1041. // //initCrm16_5ReportHistory_2()
  1042. // //initCrm16_5Roadshow()
  1043. //
  1044. // fmt.Println("end RO")
  1045. //
  1046. // initCrm16_5wx_user_rai_label()
  1047. //
  1048. // fmt.Println("end RO2")
  1049. //}
  1050. // 记录用户在重点公司单独点了某一个标签
  1051. func initCrm16_5ReportHistory_0() {
  1052. var err error
  1053. defer func() {
  1054. if err != nil {
  1055. go utils.SendAlarmMsg("SendCygxReportSelectionLogApplyTemplateMsg Err"+err.Error(), 2)
  1056. }
  1057. }()
  1058. var condition string
  1059. var pars []interface{}
  1060. listhistory, err := models.GetCygxReportSelectionSubjectHistory()
  1061. if err != nil {
  1062. fmt.Println(err)
  1063. return
  1064. }
  1065. for kH, vH := range listhistory {
  1066. fmt.Println(kH)
  1067. pars = make([]interface{}, 0)
  1068. condition = ` AND article_id = ? AND industrial_subject_id = ? AND industrial_management_id = ? AND third_id = ? `
  1069. pars = append(pars, vH.ArticleId, vH.IndustrialSubjectId, vH.IndustrialManagementId, vH.ThirdId)
  1070. listLog, e := models.GetCygxReportSelectionLog(condition, pars, 0, 9999)
  1071. if e != nil {
  1072. err = errors.New("GetCygxReportSelectionLog, Err: " + e.Error())
  1073. fmt.Println(err)
  1074. return
  1075. }
  1076. var labelName string
  1077. for _, v2 := range listLog {
  1078. if v2.ThirdId > 0 {
  1079. labelName = v2.ThirdName
  1080. } else if v2.IndustrialSubjectId == 0 && v2.IndustrialManagementId != "" {
  1081. labelName = v2.IndustrialManagementNames
  1082. } else {
  1083. labelName = v2.SubjectName
  1084. }
  1085. }
  1086. err = models.UpdateCygxReportSelectionSubjectHistoryName(labelName, vH.Id)
  1087. if err != nil {
  1088. fmt.Println(err)
  1089. return
  1090. }
  1091. }
  1092. fmt.Println("end")
  1093. return
  1094. }
  1095. func initCrm16_5ReportHistory() {
  1096. listReportHistory, err := models.GetWxUserRaiCygxReportHistoryRecordCrm16_5()
  1097. if err != nil {
  1098. fmt.Println(err)
  1099. return
  1100. }
  1101. var mobiles []string
  1102. mapMobile := make(map[string]bool)
  1103. for _, v := range listReportHistory {
  1104. if mapMobile[v.Mobile] || v.Mobile == "" {
  1105. continue
  1106. }
  1107. mapMobile[v.Mobile] = true
  1108. mobiles = append(mobiles, v.Mobile)
  1109. }
  1110. listUser, err := models.GetWxUserListByMobileArr(mobiles)
  1111. if err != nil {
  1112. fmt.Println(err)
  1113. return
  1114. }
  1115. mapUser := make(map[string]*models.WxUserItem)
  1116. for _, v := range listUser {
  1117. mapUser[v.Mobile] = v
  1118. }
  1119. var items []*models.WxUserRaiLabelLog
  1120. for _, v := range listReportHistory {
  1121. if mapUser[v.Mobile] == nil || v.Mobile == "" {
  1122. continue
  1123. }
  1124. wxUser := mapUser[v.Mobile]
  1125. item := new(models.WxUserRaiLabelLog)
  1126. item.UserId = wxUser.UserId
  1127. item.RealName = wxUser.RealName
  1128. item.Mobile = wxUser.Mobile
  1129. item.Email = wxUser.Email
  1130. item.CompanyId = wxUser.CompanyId
  1131. item.CompanyName = wxUser.CompanyName
  1132. if v.ReportType == "bgjx" {
  1133. item.Label = "重点推荐"
  1134. item.TableName = "cygx_report_selection"
  1135. } else {
  1136. item.Label = "本周研究汇总"
  1137. item.TableName = "cygx_research_summary"
  1138. }
  1139. item.SourceId = v.ArticleId
  1140. item.SourceType = 8
  1141. item.CreateTime = v.CreateTime
  1142. item.ModifyTime = time.Now()
  1143. item.RegisterPlatform = v.RegisterPlatform
  1144. items = append(items, item)
  1145. }
  1146. fmt.Println("items", len(items))
  1147. var itemsAdd []*models.WxUserRaiLabelLog
  1148. if len(items) > 0 {
  1149. for _, v := range items {
  1150. itemsAdd = append(itemsAdd, v)
  1151. if len(items)%2000 == 0 {
  1152. err = models.AddWxUserRaiLabelLogMultiInit(itemsAdd)
  1153. if err != nil {
  1154. return
  1155. }
  1156. itemsAdd = make([]*models.WxUserRaiLabelLog, 0)
  1157. }
  1158. }
  1159. }
  1160. if len(itemsAdd) > 0 {
  1161. err = models.AddWxUserRaiLabelLogMultiInit(itemsAdd)
  1162. if err != nil {
  1163. return
  1164. }
  1165. }
  1166. fmt.Println("endAddWxUserRaiLabelLogMultiInit")
  1167. }
  1168. func initCrm16_5ReportHistory_2() {
  1169. listReportHistory, err := models.GetCygxReportSelectionSubjectHistory()
  1170. if err != nil {
  1171. fmt.Println(err)
  1172. return
  1173. }
  1174. var mobiles []string
  1175. mapMobile := make(map[string]bool)
  1176. for _, v := range listReportHistory {
  1177. if mapMobile[v.Mobile] || v.Mobile == "" {
  1178. continue
  1179. }
  1180. mapMobile[v.Mobile] = true
  1181. mobiles = append(mobiles, v.Mobile)
  1182. }
  1183. listUser, err := models.GetWxUserListByMobileArr(mobiles)
  1184. if err != nil {
  1185. fmt.Println(err)
  1186. return
  1187. }
  1188. mapUser := make(map[string]*models.WxUserItem)
  1189. for _, v := range listUser {
  1190. mapUser[v.Mobile] = v
  1191. }
  1192. var items []*models.WxUserRaiLabelLog
  1193. for _, v := range listReportHistory {
  1194. if mapUser[v.Mobile] == nil || v.Mobile == "" || v.LableName == "" {
  1195. continue
  1196. }
  1197. wxUser := mapUser[v.Mobile]
  1198. item := new(models.WxUserRaiLabelLog)
  1199. item.UserId = wxUser.UserId
  1200. item.RealName = wxUser.RealName
  1201. item.Mobile = wxUser.Mobile
  1202. item.Email = wxUser.Email
  1203. item.CompanyId = wxUser.CompanyId
  1204. item.CompanyName = wxUser.CompanyName
  1205. item.Label = v.LableName
  1206. item.SourceType = 8
  1207. item.CreateTime = v.CreateTime
  1208. item.ModifyTime = time.Now()
  1209. item.RegisterPlatform = v.RegisterPlatform
  1210. items = append(items, item)
  1211. }
  1212. fmt.Println("items", len(items))
  1213. var itemsAdd []*models.WxUserRaiLabelLog
  1214. if len(items) > 0 {
  1215. for _, v := range items {
  1216. itemsAdd = append(itemsAdd, v)
  1217. if len(items)%2000 == 0 {
  1218. err = models.AddWxUserRaiLabelLogMultiInit(items)
  1219. if err != nil {
  1220. return
  1221. }
  1222. itemsAdd = make([]*models.WxUserRaiLabelLog, 0)
  1223. }
  1224. }
  1225. }
  1226. if len(itemsAdd) > 0 {
  1227. err = models.AddWxUserRaiLabelLogMultiInit(itemsAdd)
  1228. if err != nil {
  1229. return
  1230. }
  1231. }
  1232. fmt.Println("endAddWxUserRaiLabelLogMultiInit")
  1233. }
  1234. func initCrm16_5Roadshow() {
  1235. var condition string
  1236. var pars []interface{}
  1237. condition = " "
  1238. calendarMeetingUserList, e := roadshow.GetRsCalendarMeetingUserList(condition+" ORDER BY rs.start_date ASC ", pars)
  1239. if e != nil {
  1240. fmt.Println(e)
  1241. return
  1242. }
  1243. var rsCalendarIds []int
  1244. for _, v := range calendarMeetingUserList {
  1245. rsCalendarIds = append(rsCalendarIds, v.RsCalendarId)
  1246. }
  1247. var mobiles []string
  1248. mapMobile := make(map[string]bool)
  1249. for _, v := range calendarMeetingUserList {
  1250. if mapMobile[v.Mobile] || v.Mobile == "" {
  1251. continue
  1252. }
  1253. mapMobile[v.Mobile] = true
  1254. mobiles = append(mobiles, v.Mobile)
  1255. }
  1256. RsCalendarListInit, e := roadshow.GetRsCalendarListInit(rsCalendarIds)
  1257. if e != nil {
  1258. fmt.Println(e)
  1259. return
  1260. }
  1261. mapRoadshowType := make(map[int]int)
  1262. for _, v := range RsCalendarListInit {
  1263. if v.RoadshowType == "线下" {
  1264. mapRoadshowType[v.RsCalendarId] = 3
  1265. } else {
  1266. mapRoadshowType[v.RsCalendarId] = 5
  1267. }
  1268. }
  1269. listUser, err := models.GetWxUserListByMobileArr(mobiles)
  1270. if err != nil {
  1271. fmt.Println(err)
  1272. return
  1273. }
  1274. mapUser := make(map[string]*models.WxUserItem)
  1275. for _, v := range listUser {
  1276. mapUser[v.Mobile] = v
  1277. }
  1278. var items []*models.WxUserRaiLabelLog
  1279. for _, v := range calendarMeetingUserList {
  1280. if mapUser[v.Mobile] == nil || v.Mobile == "" {
  1281. continue
  1282. }
  1283. wxUser := mapUser[v.Mobile]
  1284. var sourceType int
  1285. sourceType = mapRoadshowType[v.RsCalendarId]
  1286. totalGroup, e := roadshow.GetRsCalendarMeetingLabelGroupByRsCalendarId(v.RsCalendarId)
  1287. if e != nil {
  1288. err = errors.New("GetRsCalendarMeetingLabelGroupByRsCalendarId" + e.Error())
  1289. return
  1290. }
  1291. //var lebelDetail []*cygx.RaiServeTagResp
  1292. var label string
  1293. var labelArr []string
  1294. if totalGroup > 0 {
  1295. listGroup, e := roadshow.GetRsCalendarMeetingLabelGroupListByRsCalendarId(v.RsCalendarId)
  1296. if e != nil {
  1297. err = errors.New("GetRsCalendarMeetingLabelGroupByRsCalendarId" + e.Error())
  1298. return
  1299. }
  1300. var industrialManagementIds []int
  1301. var industrialSubjectIds []int
  1302. mapindustrialManagementName := make(map[int]string)
  1303. mapindustrialSubjectName := make(map[int]string)
  1304. mapCelueName := make(map[int]string)
  1305. for _, vG := range listGroup {
  1306. switch vG.TagType {
  1307. case 1:
  1308. industrialManagementIds = append(industrialManagementIds, vG.TagId)
  1309. case 2:
  1310. industrialSubjectIds = append(industrialSubjectIds, vG.TagId)
  1311. case 3:
  1312. mapCelueName[vG.TagId] = "策略"
  1313. }
  1314. }
  1315. if len(industrialManagementIds) > 0 {
  1316. IndustryList, e := models.GetIndustryListByConditionByIds(industrialManagementIds)
  1317. if e != nil {
  1318. err = errors.New("GetRsCalendarMeetingLabelGroupByRsCalendarId" + e.Error())
  1319. return
  1320. }
  1321. for _, vI := range IndustryList {
  1322. mapindustrialManagementName[vI.IndustrialManagementId] = vI.IndustryName
  1323. }
  1324. }
  1325. if len(industrialSubjectIds) > 0 {
  1326. SubjectList, e := models.GetIndustrialSubjectDetailByIds(industrialSubjectIds)
  1327. if e != nil {
  1328. err = errors.New("GetIndustrialSubjectDetailByIds" + e.Error())
  1329. return
  1330. }
  1331. for _, vS := range SubjectList {
  1332. mapindustrialSubjectName[vS.IndustrialSubjectId] = vS.SubjectName
  1333. }
  1334. }
  1335. for _, vG := range listGroup {
  1336. switch vG.TagType {
  1337. case 1:
  1338. label = mapindustrialManagementName[vG.TagId]
  1339. case 2:
  1340. label = mapindustrialSubjectName[vG.TagId]
  1341. case 3:
  1342. label = mapCelueName[vG.TagId]
  1343. }
  1344. item := new(models.WxUserRaiLabelLog)
  1345. item.UserId = wxUser.UserId
  1346. item.RealName = wxUser.RealName
  1347. item.Mobile = wxUser.Mobile
  1348. item.Email = wxUser.Email
  1349. item.CompanyId = wxUser.CompanyId
  1350. item.CompanyName = wxUser.CompanyName
  1351. item.Label = label
  1352. item.SourceType = sourceType
  1353. item.SourceId = v.RsCalendarId
  1354. item.CreateTime = v.CreateTime
  1355. item.ModifyTime = time.Now()
  1356. //item.RegisterPlatform = log.RegisterPlatform
  1357. item.TableName = ""
  1358. items = append(items, item)
  1359. labelArr = append(labelArr, label)
  1360. }
  1361. }
  1362. }
  1363. fmt.Println("items", len(items))
  1364. var itemsAdd []*models.WxUserRaiLabelLog
  1365. if len(items) > 0 {
  1366. for _, v := range items {
  1367. itemsAdd = append(itemsAdd, v)
  1368. if len(items)%2000 == 0 {
  1369. err = models.AddWxUserRaiLabelLogMultiInit(items)
  1370. if err != nil {
  1371. return
  1372. }
  1373. itemsAdd = make([]*models.WxUserRaiLabelLog, 0)
  1374. }
  1375. }
  1376. }
  1377. if len(itemsAdd) > 0 {
  1378. err = models.AddWxUserRaiLabelLogMultiInit(itemsAdd)
  1379. if err != nil {
  1380. return
  1381. }
  1382. }
  1383. fmt.Println("endAddWxUserRaiLabelLogMultiInit")
  1384. }
  1385. func initCrm16_5wx_user_rai_label() {
  1386. listAll, err := models.GetWxUserRaiLabelLogAll()
  1387. if err != nil {
  1388. fmt.Println(err)
  1389. return
  1390. }
  1391. mapMobileLabel := make(map[string]bool)
  1392. var items []*models.WxUserRaiLabel
  1393. for _, v := range listAll {
  1394. if mapMobileLabel[fmt.Sprint(v.Mobile, "__", v.Label)] {
  1395. continue
  1396. }
  1397. item := new(models.WxUserRaiLabel)
  1398. item.UserId = v.UserId
  1399. item.RealName = v.RealName
  1400. item.Mobile = v.Mobile
  1401. item.Email = v.Email
  1402. item.CompanyId = v.CompanyId
  1403. item.CompanyName = v.CompanyName
  1404. item.Label = v.Label
  1405. item.SourceId = v.SourceId
  1406. item.SourceType = v.SourceType
  1407. item.CreateTime = v.CreateTime
  1408. item.ModifyTime = v.ModifyTime
  1409. item.RegisterPlatform = v.RegisterPlatform
  1410. item.TableName = v.TableName
  1411. items = append(items, item)
  1412. mapMobileLabel[fmt.Sprint(v.Mobile, "__", v.Label)] = true
  1413. }
  1414. var itemsAdd []*models.WxUserRaiLabel
  1415. if len(items) > 0 {
  1416. for _, v := range items {
  1417. itemsAdd = append(itemsAdd, v)
  1418. if len(items)%2000 == 0 {
  1419. err = models.AddWxUserRaiLabelMultiInit(items)
  1420. if err != nil {
  1421. return
  1422. }
  1423. itemsAdd = make([]*models.WxUserRaiLabel, 0)
  1424. }
  1425. }
  1426. }
  1427. if len(itemsAdd) > 0 {
  1428. err = models.AddWxUserRaiLabelMultiInit(itemsAdd)
  1429. if err != nil {
  1430. return
  1431. }
  1432. }
  1433. fmt.Println("endAddWxUserRaiLabelLogMultiInit")
  1434. }