wx_user_rai_label.go 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560
  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 init() {
  596. // GetArticlelabelArrByArticleId(11796)
  597. //}
  598. func GetArticlelabelArrByArticleId(articleId int) (labelArr []string, sourceType int) {
  599. articleDetail, e := models.GetArticleDetailTestById(articleId)
  600. if e != nil {
  601. fmt.Println(e)
  602. return
  603. }
  604. if articleDetail.ArticleTypeId > 0 {
  605. //正常的有产业报告
  606. //建立首页资源表,与产业的关系
  607. industrialList, e := models.GetIndustrialArticleGroupManagementListByArticleId(articleId)
  608. if e != nil && e.Error() != utils.ErrNoRow() {
  609. fmt.Println(e)
  610. return
  611. }
  612. for _, v := range industrialList {
  613. labelArr = append(labelArr, v.IndustryName)
  614. }
  615. //建立首页资源表,与标的 的关系
  616. subjectList, e := models.GetSubjectArticleGroupManagementListByArtcileId(articleId)
  617. if e != nil && e.Error() != utils.ErrNoRow() {
  618. fmt.Println(e)
  619. return
  620. }
  621. for _, v := range subjectList {
  622. labelArr = append(labelArr, v.SubjectName)
  623. }
  624. sourceType = 7
  625. return
  626. }
  627. articlePermission, e := models.GetArticlePermission(articleDetail.CategoryId)
  628. if e != nil {
  629. fmt.Println(e)
  630. return
  631. }
  632. if articlePermission == nil {
  633. fmt.Println(e)
  634. return
  635. }
  636. articlePermissionName := articlePermission.PermissionName
  637. subCategoryName := articleDetail.SubCategoryName
  638. matchTypeNameArr := []string{"季度策略", "科技前沿(周报)", "本周荟", "智造精粹"}
  639. //1;四大行业汇总类报告:季度策略、科技前沿(周报)、本周荟、智造精粹以报告类型做标签
  640. //2:策略、固收的所有报告,以报告类型做标签
  641. //var labelArr []string
  642. if articlePermissionName == utils.CE_LUE_NAME || articlePermissionName == utils.GU_SHOU_NAME || utils.InArrayByStr(matchTypeNameArr, subCategoryName) { // 策略、固收的所有报告,以报告类型做标签
  643. if subCategoryName == "季度策略" {
  644. subCategoryName = articlePermissionName + subCategoryName //其中季度策略以:xx行业季度策略 呈现
  645. }
  646. labelArr = append(labelArr, subCategoryName)
  647. sourceType = 8
  648. } else if articlePermissionName == utils.ZHOU_QI_NAME {
  649. //周期的行业深度、调研纪要、产业跟踪这些系列的报告用领域做标签,其余的周期报告,都用报告类型(也就是ficc定义的类型)做标签
  650. //其中周期的周度观点,以 周期周度观点 呈现
  651. matchTypeNameArrZhouqi := []string{"行业深度", "调研纪要", "产业跟踪"}
  652. if utils.InArrayByStr(matchTypeNameArrZhouqi, subCategoryName) {
  653. subCategoryName = articleDetail.FieldName
  654. }
  655. labelArr = append(labelArr, subCategoryName)
  656. sourceType = 8
  657. } else {
  658. //正常的有产业报告
  659. //建立首页资源表,与产业的关系
  660. industrialList, e := models.GetIndustrialArticleGroupManagementListByArticleId(articleId)
  661. if e != nil && e.Error() != utils.ErrNoRow() {
  662. fmt.Println(e)
  663. return
  664. }
  665. for _, v := range industrialList {
  666. labelArr = append(labelArr, v.IndustryName)
  667. }
  668. //建立首页资源表,与标的 的关系
  669. subjectList, e := models.GetSubjectArticleGroupManagementListByArtcileId(articleId)
  670. if e != nil && e.Error() != utils.ErrNoRow() {
  671. fmt.Println(e)
  672. return
  673. }
  674. for _, v := range subjectList {
  675. labelArr = append(labelArr, v.SubjectName)
  676. }
  677. sourceType = 7
  678. }
  679. return
  680. }
  681. //func init() {
  682. // //fmt.Println(GetArticlelabelArrByArticleId(11037))
  683. // //initCrm16_5Article2()
  684. //}
  685. func initCrm16_5keyWord() {
  686. listKeyWords, err := models.GetSearchKeyWordinitCrm16_5()
  687. if err != nil {
  688. fmt.Println(err)
  689. return
  690. }
  691. var mobiles []string
  692. mapMobile := make(map[string]bool)
  693. for _, v := range listKeyWords {
  694. if mapMobile[v.Mobile] || v.Mobile == "" {
  695. continue
  696. }
  697. mapMobile[v.Mobile] = true
  698. mobiles = append(mobiles, v.Mobile)
  699. }
  700. listUser, err := models.GetWxUserListByMobileArr(mobiles)
  701. if err != nil {
  702. fmt.Println(err)
  703. return
  704. }
  705. mapUser := make(map[string]*models.WxUserItem)
  706. for _, v := range listUser {
  707. mapUser[v.Mobile] = v
  708. }
  709. var items []*models.WxUserRaiLabelLog
  710. for _, v := range listKeyWords {
  711. if mapUser[v.Mobile] == nil || v.Mobile == "" {
  712. continue
  713. }
  714. wxUser := mapUser[v.Mobile]
  715. item := new(models.WxUserRaiLabelLog)
  716. item.UserId = wxUser.UserId
  717. item.RealName = wxUser.RealName
  718. item.Mobile = wxUser.Mobile
  719. item.Email = wxUser.Email
  720. item.CompanyId = wxUser.CompanyId
  721. item.CompanyName = wxUser.CompanyName
  722. item.Label = v.KeyWord
  723. item.SourceType = 1
  724. item.CreateTime = v.CreateTime
  725. item.ModifyTime = time.Now()
  726. item.RegisterPlatform = v.RegisterPlatform
  727. items = append(items, item)
  728. }
  729. fmt.Println(len(items))
  730. var itemsAdd []*models.WxUserRaiLabelLog
  731. if len(items) > 0 {
  732. for _, v := range items {
  733. itemsAdd = append(itemsAdd, v)
  734. if len(items)%2000 == 0 {
  735. err = models.AddWxUserRaiLabelLogMultiInit(itemsAdd)
  736. if err != nil {
  737. return
  738. }
  739. itemsAdd = make([]*models.WxUserRaiLabelLog, 0)
  740. }
  741. }
  742. }
  743. if len(itemsAdd) > 0 {
  744. err = models.AddWxUserRaiLabelLogMultiInit(itemsAdd)
  745. if err != nil {
  746. return
  747. }
  748. }
  749. fmt.Println("endAddWxUserRaiLabelLogMultiInit")
  750. }
  751. func initCrm16_5Activity() {
  752. var condition string
  753. var pars []interface{}
  754. condition += ` AND create_time > '2024-09-01' AND (is_meeting =1 OR duration != '') `
  755. pars = append(pars)
  756. //获取提交到会的人员信息
  757. signUpDetailList, err := models.GetSignupDetailList(condition, pars)
  758. if err != nil {
  759. fmt.Println(err)
  760. return
  761. }
  762. var mobiles []string
  763. mapMobile := make(map[string]bool)
  764. for _, v := range signUpDetailList {
  765. if mapMobile[v.Mobile] || v.Mobile == "" {
  766. continue
  767. }
  768. mapMobile[v.Mobile] = true
  769. mobiles = append(mobiles, v.Mobile)
  770. }
  771. var activityIds []int
  772. mapactivityId := make(map[int]bool)
  773. for _, v := range signUpDetailList {
  774. if mapactivityId[v.ActivityId] {
  775. continue
  776. }
  777. mapactivityId[v.ActivityId] = true
  778. activityIds = append(activityIds, v.ActivityId)
  779. }
  780. listUser, err := models.GetWxUserListByMobileArr(mobiles)
  781. if err != nil {
  782. fmt.Println(err)
  783. return
  784. }
  785. mapUser := make(map[string]*models.WxUserItem)
  786. for _, v := range listUser {
  787. mapUser[v.Mobile] = v
  788. }
  789. activityDetailList, e := models.GetAddActivityDetailByActivityIdinitCrm16_5(activityIds)
  790. if e != nil {
  791. fmt.Println(e)
  792. return
  793. }
  794. sourceTypemap := make(map[int]int)
  795. mapLabel := make(map[int]string)
  796. for _, v := range activityDetailList {
  797. if v.ActivityType == 1 {
  798. sourceTypemap[v.ActivityId] = 4
  799. } else {
  800. sourceTypemap[v.ActivityId] = 2
  801. }
  802. mapLabel[v.ActivityId] = v.Label
  803. }
  804. //正常的有产业报告
  805. //建立首页资源表,与产业的关系
  806. industrialList, e := models.GetIndustrialActivityGroupManagementListByArticleIds(activityIds)
  807. if e != nil && e.Error() != utils.ErrNoRow() {
  808. fmt.Println(e)
  809. return
  810. }
  811. //建立首页资源表,与标的 的关系
  812. subjectList, e := models.GetSubjectActivityGroupManagementListByActivityIds(activityIds)
  813. if e != nil && e.Error() != utils.ErrNoRow() {
  814. fmt.Println(e)
  815. return
  816. }
  817. var items []*models.WxUserRaiLabelLog
  818. for _, v := range signUpDetailList {
  819. if mapUser[v.Mobile] == nil || v.Mobile == "" {
  820. continue
  821. }
  822. var haseName bool
  823. wxUser := mapUser[v.Mobile]
  824. for _, vI := range industrialList {
  825. if vI.ActivityId != v.ActivityId {
  826. continue
  827. }
  828. haseName = true
  829. item := new(models.WxUserRaiLabelLog)
  830. item.UserId = wxUser.UserId
  831. item.RealName = wxUser.RealName
  832. item.Mobile = wxUser.Mobile
  833. item.Email = wxUser.Email
  834. item.CompanyId = wxUser.CompanyId
  835. item.CompanyName = wxUser.CompanyName
  836. item.Label = vI.IndustryName
  837. item.SourceType = sourceTypemap[v.ActivityId]
  838. item.SourceId = v.ActivityId
  839. item.CreateTime = v.CreateTime
  840. item.ModifyTime = time.Now()
  841. item.TableName = ""
  842. //item.RegisterPlatform = v.RegisterPlatform
  843. items = append(items, item)
  844. }
  845. for _, vs := range subjectList {
  846. if vs.ActivityId != v.ActivityId {
  847. continue
  848. }
  849. haseName = true
  850. item := new(models.WxUserRaiLabelLog)
  851. item.UserId = wxUser.UserId
  852. item.RealName = wxUser.RealName
  853. item.Mobile = wxUser.Mobile
  854. item.Email = wxUser.Email
  855. item.CompanyId = wxUser.CompanyId
  856. item.CompanyName = wxUser.CompanyName
  857. item.Label = vs.SubjectName
  858. item.SourceType = sourceTypemap[v.ActivityId]
  859. item.SourceId = v.ActivityId
  860. item.CreateTime = v.CreateTime
  861. item.ModifyTime = time.Now()
  862. //item.RegisterPlatform = v.RegisterPlatform
  863. items = append(items, item)
  864. }
  865. //如果两个标签都没有,就添加临时标签
  866. if !haseName {
  867. item := new(models.WxUserRaiLabelLog)
  868. item.UserId = wxUser.UserId
  869. item.RealName = wxUser.RealName
  870. item.Mobile = wxUser.Mobile
  871. item.Email = wxUser.Email
  872. item.CompanyId = wxUser.CompanyId
  873. item.CompanyName = wxUser.CompanyName
  874. item.Label = mapLabel[v.ActivityId]
  875. item.SourceType = sourceTypemap[v.ActivityId]
  876. item.SourceId = v.ActivityId
  877. item.CreateTime = v.CreateTime
  878. item.ModifyTime = time.Now()
  879. //item.RegisterPlatform = v.RegisterPlatform
  880. item.TableName = ""
  881. items = append(items, item)
  882. }
  883. }
  884. //fmt.Println("initCrm16_5Activity", len(items))
  885. //return
  886. var itemsAdd []*models.WxUserRaiLabelLog
  887. if len(items) > 0 {
  888. for _, v := range items {
  889. itemsAdd = append(itemsAdd, v)
  890. if len(itemsAdd)%2000 == 0 {
  891. err = models.AddWxUserRaiLabelLogMultiInit(itemsAdd)
  892. if err != nil {
  893. return
  894. }
  895. itemsAdd = make([]*models.WxUserRaiLabelLog, 0)
  896. }
  897. }
  898. }
  899. if len(itemsAdd) > 0 {
  900. err = models.AddWxUserRaiLabelLogMultiInit(itemsAdd)
  901. if err != nil {
  902. return
  903. }
  904. }
  905. fmt.Println("endAddWxUserRaiLabelLogMultiInit")
  906. }
  907. func initCrm16_5Article() {
  908. var condition string
  909. var pars []interface{}
  910. condition += ` `
  911. pars = append(pars)
  912. listArticleIds, err := models.GetCygxArticleHistoryRecordAllListArticleIdCrm16_5()
  913. if err != nil {
  914. fmt.Println(err)
  915. return
  916. }
  917. fmt.Println("listArticleIds", len(listArticleIds))
  918. listHave, err := models.GetWxUserRaiArticleLabelCrm16_5()
  919. if err != nil {
  920. fmt.Println(err)
  921. return
  922. }
  923. mapArticleId := make(map[int]bool)
  924. for _, v := range listHave {
  925. mapArticleId[v.ArticleId] = true
  926. }
  927. for k, v := range listArticleIds {
  928. fmt.Println(k)
  929. labelArr, sourceType := GetArticlelabelArrByArticleId(v.ArticleId)
  930. if len(labelArr) == 0 {
  931. continue
  932. }
  933. var items []*models.WxUserRaiArticleLabel
  934. for _, v2 := range labelArr {
  935. item := new(models.WxUserRaiArticleLabel)
  936. item.ArticleId = v.ArticleId
  937. item.Label = v2
  938. item.SourceType = sourceType
  939. item.CreateTime = time.Now()
  940. items = append(items, item)
  941. }
  942. err = models.AddWxUserRaiArticleLabelMultiInit(items)
  943. time.Sleep(time.Millisecond * 100)
  944. fmt.Println(err)
  945. }
  946. }
  947. func initCrm16_5Article2() {
  948. var condition string
  949. var pars []interface{}
  950. condition += ` `
  951. pars = append(pars)
  952. //获取提交到会的人员信息
  953. listArticleIds, err := models.GetCygxArticleHistoryRecordAllListUserIdCrm16_5()
  954. if err != nil {
  955. fmt.Println(err)
  956. return
  957. }
  958. fmt.Println("listArticleIds", len(listArticleIds))
  959. mapUserId := make(map[string]bool)
  960. var mobiles []string
  961. for _, v := range listArticleIds {
  962. if mapUserId[v.Mobile] {
  963. continue
  964. }
  965. mobiles = append(mobiles, v.Mobile)
  966. mapUserId[v.Mobile] = true
  967. }
  968. listUser, err := models.GetWxUserListByMobileArr(mobiles)
  969. if err != nil {
  970. fmt.Println(err)
  971. return
  972. }
  973. mapUser := make(map[string]*models.WxUserItem)
  974. for _, v := range listUser {
  975. mapUser[v.Mobile] = v
  976. }
  977. listArticleLabel, err := models.GetWxUserRaiArticleLabelAllCrm16_5()
  978. if err != nil {
  979. fmt.Println(err)
  980. return
  981. }
  982. mapArticleLabel := make(map[int][]string)
  983. mapArticleType := make(map[int]int)
  984. for _, v := range listArticleLabel {
  985. mapArticleLabel[v.ArticleId] = append(mapArticleLabel[v.ArticleId], v.Label)
  986. mapArticleType[v.ArticleId] = v.SourceType
  987. }
  988. var items []*models.WxUserRaiLabelLog
  989. for _, v := range listArticleIds {
  990. if mapUser[v.Mobile] == nil || v.Mobile == "" {
  991. continue
  992. }
  993. if len(mapArticleLabel[v.ArticleId]) == 0 {
  994. continue
  995. }
  996. wxUser := mapUser[v.Mobile]
  997. for _, vI := range mapArticleLabel[v.ArticleId] {
  998. item := new(models.WxUserRaiLabelLog)
  999. item.UserId = wxUser.UserId
  1000. item.RealName = wxUser.RealName
  1001. item.Mobile = wxUser.Mobile
  1002. item.Email = wxUser.Email
  1003. item.CompanyId = wxUser.CompanyId
  1004. item.CompanyName = wxUser.CompanyName
  1005. item.Label = vI
  1006. item.SourceType = mapArticleType[v.ArticleId]
  1007. item.SourceId = v.ArticleId
  1008. item.CreateTime = utils.StrTimeToTime(v.CreateTime)
  1009. item.ModifyTime = time.Now()
  1010. item.TableName = "cygx_article"
  1011. //item.RegisterPlatform = v.RegisterPlatform
  1012. items = append(items, item)
  1013. }
  1014. }
  1015. fmt.Println("items", len(items))
  1016. var itemsAdd []*models.WxUserRaiLabelLog
  1017. if len(items) > 0 {
  1018. for _, v := range items {
  1019. itemsAdd = append(itemsAdd, v)
  1020. if len(itemsAdd)%2000 == 0 {
  1021. err = models.AddWxUserRaiLabelLogMultiInit(itemsAdd)
  1022. if err != nil {
  1023. fmt.Println(err)
  1024. return
  1025. }
  1026. itemsAdd = make([]*models.WxUserRaiLabelLog, 0)
  1027. }
  1028. }
  1029. }
  1030. if len(itemsAdd) > 0 {
  1031. err = models.AddWxUserRaiLabelLogMultiInit(itemsAdd)
  1032. if err != nil {
  1033. fmt.Println(err)
  1034. return
  1035. }
  1036. }
  1037. fmt.Println("endAddWxUserRaiLabelLogMultiInit")
  1038. }
  1039. ////func init() {
  1040. // //initCrm16_5keyWord()
  1041. // //initCrm16_5Activity()
  1042. // //initCrm16_5Article2()
  1043. // //initCrm16_5ReportHistory()
  1044. // //initCrm16_5ReportHistory_2()
  1045. // //initCrm16_5Roadshow()
  1046. //
  1047. // fmt.Println("end RO")
  1048. //
  1049. // initCrm16_5wx_user_rai_label()
  1050. //
  1051. // fmt.Println("end RO2")
  1052. //}
  1053. // 记录用户在重点公司单独点了某一个标签
  1054. func initCrm16_5ReportHistory_0() {
  1055. var err error
  1056. defer func() {
  1057. if err != nil {
  1058. go utils.SendAlarmMsg("SendCygxReportSelectionLogApplyTemplateMsg Err"+err.Error(), 2)
  1059. }
  1060. }()
  1061. var condition string
  1062. var pars []interface{}
  1063. listhistory, err := models.GetCygxReportSelectionSubjectHistory()
  1064. if err != nil {
  1065. fmt.Println(err)
  1066. return
  1067. }
  1068. for kH, vH := range listhistory {
  1069. fmt.Println(kH)
  1070. pars = make([]interface{}, 0)
  1071. condition = ` AND article_id = ? AND industrial_subject_id = ? AND industrial_management_id = ? AND third_id = ? `
  1072. pars = append(pars, vH.ArticleId, vH.IndustrialSubjectId, vH.IndustrialManagementId, vH.ThirdId)
  1073. listLog, e := models.GetCygxReportSelectionLog(condition, pars, 0, 9999)
  1074. if e != nil {
  1075. err = errors.New("GetCygxReportSelectionLog, Err: " + e.Error())
  1076. fmt.Println(err)
  1077. return
  1078. }
  1079. var labelName string
  1080. for _, v2 := range listLog {
  1081. if v2.ThirdId > 0 {
  1082. labelName = v2.ThirdName
  1083. } else if v2.IndustrialSubjectId == 0 && v2.IndustrialManagementId != "" {
  1084. labelName = v2.IndustrialManagementNames
  1085. } else {
  1086. labelName = v2.SubjectName
  1087. }
  1088. }
  1089. err = models.UpdateCygxReportSelectionSubjectHistoryName(labelName, vH.Id)
  1090. if err != nil {
  1091. fmt.Println(err)
  1092. return
  1093. }
  1094. }
  1095. fmt.Println("end")
  1096. return
  1097. }
  1098. func initCrm16_5ReportHistory() {
  1099. listReportHistory, err := models.GetWxUserRaiCygxReportHistoryRecordCrm16_5()
  1100. if err != nil {
  1101. fmt.Println(err)
  1102. return
  1103. }
  1104. var mobiles []string
  1105. mapMobile := make(map[string]bool)
  1106. for _, v := range listReportHistory {
  1107. if mapMobile[v.Mobile] || v.Mobile == "" {
  1108. continue
  1109. }
  1110. mapMobile[v.Mobile] = true
  1111. mobiles = append(mobiles, v.Mobile)
  1112. }
  1113. listUser, err := models.GetWxUserListByMobileArr(mobiles)
  1114. if err != nil {
  1115. fmt.Println(err)
  1116. return
  1117. }
  1118. mapUser := make(map[string]*models.WxUserItem)
  1119. for _, v := range listUser {
  1120. mapUser[v.Mobile] = v
  1121. }
  1122. var items []*models.WxUserRaiLabelLog
  1123. for _, v := range listReportHistory {
  1124. if mapUser[v.Mobile] == nil || v.Mobile == "" {
  1125. continue
  1126. }
  1127. wxUser := mapUser[v.Mobile]
  1128. item := new(models.WxUserRaiLabelLog)
  1129. item.UserId = wxUser.UserId
  1130. item.RealName = wxUser.RealName
  1131. item.Mobile = wxUser.Mobile
  1132. item.Email = wxUser.Email
  1133. item.CompanyId = wxUser.CompanyId
  1134. item.CompanyName = wxUser.CompanyName
  1135. if v.ReportType == "bgjx" {
  1136. item.Label = "重点推荐"
  1137. item.TableName = "cygx_report_selection"
  1138. } else {
  1139. item.Label = "本周研究汇总"
  1140. item.TableName = "cygx_research_summary"
  1141. }
  1142. item.SourceId = v.ArticleId
  1143. item.SourceType = 8
  1144. item.CreateTime = v.CreateTime
  1145. item.ModifyTime = time.Now()
  1146. item.RegisterPlatform = v.RegisterPlatform
  1147. items = append(items, item)
  1148. }
  1149. fmt.Println("items", len(items))
  1150. var itemsAdd []*models.WxUserRaiLabelLog
  1151. if len(items) > 0 {
  1152. for _, v := range items {
  1153. itemsAdd = append(itemsAdd, v)
  1154. if len(items)%2000 == 0 {
  1155. err = models.AddWxUserRaiLabelLogMultiInit(itemsAdd)
  1156. if err != nil {
  1157. return
  1158. }
  1159. itemsAdd = make([]*models.WxUserRaiLabelLog, 0)
  1160. }
  1161. }
  1162. }
  1163. if len(itemsAdd) > 0 {
  1164. err = models.AddWxUserRaiLabelLogMultiInit(itemsAdd)
  1165. if err != nil {
  1166. return
  1167. }
  1168. }
  1169. fmt.Println("endAddWxUserRaiLabelLogMultiInit")
  1170. }
  1171. func initCrm16_5ReportHistory_2() {
  1172. listReportHistory, err := models.GetCygxReportSelectionSubjectHistory()
  1173. if err != nil {
  1174. fmt.Println(err)
  1175. return
  1176. }
  1177. var mobiles []string
  1178. mapMobile := make(map[string]bool)
  1179. for _, v := range listReportHistory {
  1180. if mapMobile[v.Mobile] || v.Mobile == "" {
  1181. continue
  1182. }
  1183. mapMobile[v.Mobile] = true
  1184. mobiles = append(mobiles, v.Mobile)
  1185. }
  1186. listUser, err := models.GetWxUserListByMobileArr(mobiles)
  1187. if err != nil {
  1188. fmt.Println(err)
  1189. return
  1190. }
  1191. mapUser := make(map[string]*models.WxUserItem)
  1192. for _, v := range listUser {
  1193. mapUser[v.Mobile] = v
  1194. }
  1195. var items []*models.WxUserRaiLabelLog
  1196. for _, v := range listReportHistory {
  1197. if mapUser[v.Mobile] == nil || v.Mobile == "" || v.LableName == "" {
  1198. continue
  1199. }
  1200. wxUser := mapUser[v.Mobile]
  1201. item := new(models.WxUserRaiLabelLog)
  1202. item.UserId = wxUser.UserId
  1203. item.RealName = wxUser.RealName
  1204. item.Mobile = wxUser.Mobile
  1205. item.Email = wxUser.Email
  1206. item.CompanyId = wxUser.CompanyId
  1207. item.CompanyName = wxUser.CompanyName
  1208. item.Label = v.LableName
  1209. item.SourceType = 8
  1210. item.CreateTime = v.CreateTime
  1211. item.ModifyTime = time.Now()
  1212. item.RegisterPlatform = v.RegisterPlatform
  1213. items = append(items, item)
  1214. }
  1215. fmt.Println("items", len(items))
  1216. var itemsAdd []*models.WxUserRaiLabelLog
  1217. if len(items) > 0 {
  1218. for _, v := range items {
  1219. itemsAdd = append(itemsAdd, v)
  1220. if len(items)%2000 == 0 {
  1221. err = models.AddWxUserRaiLabelLogMultiInit(items)
  1222. if err != nil {
  1223. return
  1224. }
  1225. itemsAdd = make([]*models.WxUserRaiLabelLog, 0)
  1226. }
  1227. }
  1228. }
  1229. if len(itemsAdd) > 0 {
  1230. err = models.AddWxUserRaiLabelLogMultiInit(itemsAdd)
  1231. if err != nil {
  1232. return
  1233. }
  1234. }
  1235. fmt.Println("endAddWxUserRaiLabelLogMultiInit")
  1236. }
  1237. func initCrm16_5Roadshow() {
  1238. var condition string
  1239. var pars []interface{}
  1240. condition = " "
  1241. calendarMeetingUserList, e := roadshow.GetRsCalendarMeetingUserList(condition+" ORDER BY rs.start_date ASC ", pars)
  1242. if e != nil {
  1243. fmt.Println(e)
  1244. return
  1245. }
  1246. var rsCalendarIds []int
  1247. for _, v := range calendarMeetingUserList {
  1248. rsCalendarIds = append(rsCalendarIds, v.RsCalendarId)
  1249. }
  1250. var mobiles []string
  1251. mapMobile := make(map[string]bool)
  1252. for _, v := range calendarMeetingUserList {
  1253. if mapMobile[v.Mobile] || v.Mobile == "" {
  1254. continue
  1255. }
  1256. mapMobile[v.Mobile] = true
  1257. mobiles = append(mobiles, v.Mobile)
  1258. }
  1259. RsCalendarListInit, e := roadshow.GetRsCalendarListInit(rsCalendarIds)
  1260. if e != nil {
  1261. fmt.Println(e)
  1262. return
  1263. }
  1264. mapRoadshowType := make(map[int]int)
  1265. for _, v := range RsCalendarListInit {
  1266. if v.RoadshowType == "线下" {
  1267. mapRoadshowType[v.RsCalendarId] = 3
  1268. } else {
  1269. mapRoadshowType[v.RsCalendarId] = 5
  1270. }
  1271. }
  1272. listUser, err := models.GetWxUserListByMobileArr(mobiles)
  1273. if err != nil {
  1274. fmt.Println(err)
  1275. return
  1276. }
  1277. mapUser := make(map[string]*models.WxUserItem)
  1278. for _, v := range listUser {
  1279. mapUser[v.Mobile] = v
  1280. }
  1281. var items []*models.WxUserRaiLabelLog
  1282. for _, v := range calendarMeetingUserList {
  1283. if mapUser[v.Mobile] == nil || v.Mobile == "" {
  1284. continue
  1285. }
  1286. wxUser := mapUser[v.Mobile]
  1287. var sourceType int
  1288. sourceType = mapRoadshowType[v.RsCalendarId]
  1289. totalGroup, e := roadshow.GetRsCalendarMeetingLabelGroupByRsCalendarId(v.RsCalendarId)
  1290. if e != nil {
  1291. err = errors.New("GetRsCalendarMeetingLabelGroupByRsCalendarId" + e.Error())
  1292. return
  1293. }
  1294. //var lebelDetail []*cygx.RaiServeTagResp
  1295. var label string
  1296. var labelArr []string
  1297. if totalGroup > 0 {
  1298. listGroup, e := roadshow.GetRsCalendarMeetingLabelGroupListByRsCalendarId(v.RsCalendarId)
  1299. if e != nil {
  1300. err = errors.New("GetRsCalendarMeetingLabelGroupByRsCalendarId" + e.Error())
  1301. return
  1302. }
  1303. var industrialManagementIds []int
  1304. var industrialSubjectIds []int
  1305. mapindustrialManagementName := make(map[int]string)
  1306. mapindustrialSubjectName := make(map[int]string)
  1307. mapCelueName := make(map[int]string)
  1308. for _, vG := range listGroup {
  1309. switch vG.TagType {
  1310. case 1:
  1311. industrialManagementIds = append(industrialManagementIds, vG.TagId)
  1312. case 2:
  1313. industrialSubjectIds = append(industrialSubjectIds, vG.TagId)
  1314. case 3:
  1315. mapCelueName[vG.TagId] = "策略"
  1316. }
  1317. }
  1318. if len(industrialManagementIds) > 0 {
  1319. IndustryList, e := models.GetIndustryListByConditionByIds(industrialManagementIds)
  1320. if e != nil {
  1321. err = errors.New("GetRsCalendarMeetingLabelGroupByRsCalendarId" + e.Error())
  1322. return
  1323. }
  1324. for _, vI := range IndustryList {
  1325. mapindustrialManagementName[vI.IndustrialManagementId] = vI.IndustryName
  1326. }
  1327. }
  1328. if len(industrialSubjectIds) > 0 {
  1329. SubjectList, e := models.GetIndustrialSubjectDetailByIds(industrialSubjectIds)
  1330. if e != nil {
  1331. err = errors.New("GetIndustrialSubjectDetailByIds" + e.Error())
  1332. return
  1333. }
  1334. for _, vS := range SubjectList {
  1335. mapindustrialSubjectName[vS.IndustrialSubjectId] = vS.SubjectName
  1336. }
  1337. }
  1338. for _, vG := range listGroup {
  1339. switch vG.TagType {
  1340. case 1:
  1341. label = mapindustrialManagementName[vG.TagId]
  1342. case 2:
  1343. label = mapindustrialSubjectName[vG.TagId]
  1344. case 3:
  1345. label = mapCelueName[vG.TagId]
  1346. }
  1347. item := new(models.WxUserRaiLabelLog)
  1348. item.UserId = wxUser.UserId
  1349. item.RealName = wxUser.RealName
  1350. item.Mobile = wxUser.Mobile
  1351. item.Email = wxUser.Email
  1352. item.CompanyId = wxUser.CompanyId
  1353. item.CompanyName = wxUser.CompanyName
  1354. item.Label = label
  1355. item.SourceType = sourceType
  1356. item.SourceId = v.RsCalendarId
  1357. item.CreateTime = v.CreateTime
  1358. item.ModifyTime = time.Now()
  1359. //item.RegisterPlatform = log.RegisterPlatform
  1360. item.TableName = ""
  1361. items = append(items, item)
  1362. labelArr = append(labelArr, label)
  1363. }
  1364. }
  1365. }
  1366. fmt.Println("items", len(items))
  1367. var itemsAdd []*models.WxUserRaiLabelLog
  1368. if len(items) > 0 {
  1369. for _, v := range items {
  1370. itemsAdd = append(itemsAdd, v)
  1371. if len(items)%2000 == 0 {
  1372. err = models.AddWxUserRaiLabelLogMultiInit(items)
  1373. if err != nil {
  1374. return
  1375. }
  1376. itemsAdd = make([]*models.WxUserRaiLabelLog, 0)
  1377. }
  1378. }
  1379. }
  1380. if len(itemsAdd) > 0 {
  1381. err = models.AddWxUserRaiLabelLogMultiInit(itemsAdd)
  1382. if err != nil {
  1383. return
  1384. }
  1385. }
  1386. fmt.Println("endAddWxUserRaiLabelLogMultiInit")
  1387. }
  1388. func initCrm16_5wx_user_rai_label() {
  1389. listAll, err := models.GetWxUserRaiLabelLogAll()
  1390. if err != nil {
  1391. fmt.Println(err)
  1392. return
  1393. }
  1394. mapMobileLabel := make(map[string]bool)
  1395. var items []*models.WxUserRaiLabel
  1396. for _, v := range listAll {
  1397. if mapMobileLabel[fmt.Sprint(v.Mobile, "__", v.Label)] {
  1398. continue
  1399. }
  1400. item := new(models.WxUserRaiLabel)
  1401. item.UserId = v.UserId
  1402. item.RealName = v.RealName
  1403. item.Mobile = v.Mobile
  1404. item.Email = v.Email
  1405. item.CompanyId = v.CompanyId
  1406. item.CompanyName = v.CompanyName
  1407. item.Label = v.Label
  1408. item.SourceId = v.SourceId
  1409. item.SourceType = v.SourceType
  1410. item.CreateTime = v.CreateTime
  1411. item.ModifyTime = v.ModifyTime
  1412. item.RegisterPlatform = v.RegisterPlatform
  1413. item.TableName = v.TableName
  1414. items = append(items, item)
  1415. mapMobileLabel[fmt.Sprint(v.Mobile, "__", v.Label)] = true
  1416. }
  1417. var itemsAdd []*models.WxUserRaiLabel
  1418. if len(items) > 0 {
  1419. for _, v := range items {
  1420. itemsAdd = append(itemsAdd, v)
  1421. if len(items)%2000 == 0 {
  1422. err = models.AddWxUserRaiLabelMultiInit(items)
  1423. if err != nil {
  1424. return
  1425. }
  1426. itemsAdd = make([]*models.WxUserRaiLabel, 0)
  1427. }
  1428. }
  1429. }
  1430. if len(itemsAdd) > 0 {
  1431. err = models.AddWxUserRaiLabelMultiInit(itemsAdd)
  1432. if err != nil {
  1433. return
  1434. }
  1435. }
  1436. fmt.Println("endAddWxUserRaiLabelLogMultiInit")
  1437. }