wx_user.go 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498
  1. package services
  2. import (
  3. "context"
  4. "errors"
  5. "fmt"
  6. "hongze/hongze_cygx/models"
  7. "hongze/hongze_cygx/utils"
  8. "strconv"
  9. "strings"
  10. "time"
  11. )
  12. func UpdateWxUserLabelOLd(cont context.Context) (err error) {
  13. defer func() {
  14. if err != nil {
  15. go utils.SendAlarmMsg("更新用户标签失败;Err:"+err.Error(), 2)
  16. }
  17. }()
  18. //获取需要处理的权益客户
  19. listUser, err := models.GetUserRegisterList()
  20. if err != nil {
  21. fmt.Println("GetUserRegisterList Err", err)
  22. return err
  23. }
  24. mapChartCollect := make(map[string]int)
  25. //获取已经处理记录的用户并记录切片
  26. listChartCollectL, err := models.GetCygxChartCollectList()
  27. if err != nil && err.Error() != utils.ErrNoRow() {
  28. fmt.Println("GetCygxUserInteractionNumList Err", err)
  29. return err
  30. }
  31. for _, v := range listChartCollectL {
  32. mapChartCollect[fmt.Sprint("m:", v.Mobile, "u:", v.ChartId)] = v.UserId
  33. }
  34. var interactionNum int // 互动量
  35. mapComapnyInteractionNum := make(map[int]int)
  36. //拉取策略平台用户同步的图表信息
  37. {
  38. var chartMobile string
  39. var chartItems []*models.CygxChartCollect
  40. if utils.RunMode == "release" {
  41. for k, vUser := range listUser {
  42. if vUser.Mobile != "" {
  43. mobile := vUser.Mobile
  44. fmt.Println(vUser.Mobile, "_", k)
  45. chartMobile += mobile + ","
  46. listChart, _, _ := GetChartCollectionByApi(mobile, 9999, 0)
  47. if len(listChart) > 0 {
  48. for _, vChart := range listChart {
  49. if mapChartCollect[fmt.Sprint("m:", mobile, "u:", vChart.ChartId)] == 0 {
  50. item := new(models.CygxChartCollect)
  51. item.ChartId = vChart.ChartId
  52. t1, _ := time.Parse("2006-01-02T15:04:05Z", vChart.CreateDate)
  53. item.CreateTime = t1
  54. item.Mobile = mobile
  55. chartItems = append(chartItems, item)
  56. }
  57. }
  58. }
  59. }
  60. }
  61. }
  62. //如果有数据就添加
  63. if len(chartItems) > 0 {
  64. _, err = models.AddCygxChartCollectList(chartItems)
  65. if err != nil {
  66. fmt.Println(" RemoveChartCollectByMobile Err", err)
  67. }
  68. }
  69. //处理图表关注后的用户
  70. {
  71. if utils.RunMode == "release" {
  72. listChartCollect, err := models.GetCygxChartCollectByMobileList()
  73. if err != nil {
  74. fmt.Println("GetCygxChartCollectByMobileList ,Err" + err.Error())
  75. }
  76. for k, v := range listChartCollect {
  77. if v.Mobile != "" {
  78. user, err := models.GetWxUserItemByMobile(v.Mobile)
  79. if err != nil && err.Error() != utils.ErrNoRow() {
  80. fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
  81. }
  82. if user != nil {
  83. fmt.Println(user.RealName, k)
  84. err = models.UpdateCygxChartCollect(user)
  85. if err != nil {
  86. fmt.Println("UpdateCygxChartCollect ,Err" + err.Error())
  87. }
  88. }
  89. }
  90. }
  91. }
  92. }
  93. }
  94. //处理 前一天移动之后的用户的公司记录信息
  95. //{
  96. // startDate := time.Now().AddDate(0, 0, -1).Format(utils.FormatDate)
  97. // endDate := time.Now().Format(utils.FormatDate)
  98. // listUpdateUser, err := models.GetWxUserOpLogList(startDate, endDate)
  99. // if err != nil && err.Error() != utils.ErrNoRow() {
  100. // return err
  101. // }
  102. // var userIds string
  103. // var mobiles string
  104. // if len(listUpdateUser) > 0 {
  105. // for _, v := range listUpdateUser {
  106. // userIds += strconv.Itoa(v.UserId) + ","
  107. // mobiles += "'" + v.Mobile + "',"
  108. // }
  109. // }
  110. // userIds = strings.TrimRight(userIds, ",")
  111. // mobiles = strings.TrimRight(mobiles, ",")
  112. //
  113. // //如果用户ID不为空那么就处理这些用户的记录信息
  114. // if userIds != "" {
  115. // var condition string
  116. // //condition = ` AND user_id IN (` + userIds + `)`
  117. // condition = ` AND mobile IN (` + mobiles + `)`
  118. // //处理用户的文章收藏
  119. // listCollect, err := models.GetCygxArticleCollectList(condition)
  120. // if err != nil && err.Error() != utils.ErrNoRow() {
  121. // fmt.Println("GetAddCygxArticleCollectList ,Err" + err.Error())
  122. // }
  123. // if len(listCollect) > 0 {
  124. // for _, v := range listCollect {
  125. // user, err := models.GetWxUserItemByUserId(v.UserId)
  126. // if err != nil && err.Error() != utils.ErrNoRow() {
  127. // fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
  128. // }
  129. // if user != nil {
  130. // fmt.Println(user.RealName)
  131. // err = models.UpdateCygxArticleCollect(user)
  132. // if err != nil {
  133. // fmt.Println("UpdateCygxArticleCollect ,Err" + err.Error())
  134. // }
  135. // }
  136. // }
  137. // }
  138. // //处理用户的文章收藏 end
  139. //
  140. // //修改用户关注的产业
  141. // listIndustryFllow, err := models.GetCygxIndustryFllowList(condition)
  142. // if err != nil {
  143. // fmt.Println("GetCygxIndustryFllowList ,Err" + err.Error())
  144. // }
  145. // for k, v := range listIndustryFllow {
  146. // if v.Mobile != "" {
  147. // user, err := models.GetWxUserItemByUserId(v.UserId)
  148. // if err != nil && err.Error() != utils.ErrNoRow() {
  149. // fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
  150. // }
  151. // if user != nil {
  152. // fmt.Println(user.RealName, k)
  153. // err = models.UpdateCygxIndustryFllow(user)
  154. // if err != nil {
  155. // fmt.Println("UpdateCygxIndustryFllow ,Err" + err.Error())
  156. // }
  157. // }
  158. // }
  159. // }
  160. //
  161. // //修改用户产业关注的产业end
  162. //
  163. // //修改用户的阅读记录
  164. // listArticlePv, err := models.GetArticleHistoryRecordAllByMobileList(condition)
  165. // if err != nil {
  166. // fmt.Println("GetArticleHistoryRecordAllByMobileList ,Err" + err.Error())
  167. // }
  168. // for k, v := range listArticlePv {
  169. // if v.Mobile != "" {
  170. // user, err := models.GetWxUserItemByMobile(v.Mobile)
  171. // if err != nil && err.Error() != utils.ErrNoRow() {
  172. // fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
  173. // }
  174. // if user != nil {
  175. // fmt.Println(user.RealName, k)
  176. // err = models.UpdateCygxArticleHistoryRecordAll(user)
  177. // if err != nil {
  178. // fmt.Println("UpdateCygxArticleCollect ,Err" + err.Error())
  179. // }
  180. // }
  181. // }
  182. // }
  183. // //修改用户的阅读记录end
  184. //
  185. // //处理用户的搜索记录
  186. // listSearch, err := models.GetCygxSearchKeyWordList(condition)
  187. // if err != nil {
  188. // fmt.Println("GetArticleHistoryRecordAllByMobileList ,Err" + err.Error())
  189. // }
  190. //
  191. // for k, v := range listSearch {
  192. // if v.Mobile != "" {
  193. // user, err := models.GetWxUserItemByUserId(v.UserId)
  194. // if err != nil && err.Error() != utils.ErrNoRow() {
  195. // fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
  196. // }
  197. // if user != nil {
  198. // fmt.Println(user.RealName, k)
  199. // err = models.UpdateCygxSearchKeyWord(user)
  200. // if err != nil {
  201. // fmt.Println("UpdateCygxSearchKeyWord ,Err" + err.Error())
  202. // }
  203. // }
  204. // }
  205. // }
  206. //
  207. // // 处理用户的作者关注
  208. // lisDepartmentF, err := models.GetArticleDepartmentFollowByMobileList(condition)
  209. // if err != nil {
  210. // fmt.Println("GetArticleDepartmentFollowByMobileList ,Err" + err.Error())
  211. // return err
  212. // }
  213. // for k, v := range lisDepartmentF {
  214. // if v.Mobile != "" {
  215. // user, err := models.GetWxUserItemByUserId(v.UserId)
  216. // if err != nil && err.Error() != utils.ErrNoRow() {
  217. // fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
  218. // }
  219. // if user != nil {
  220. // fmt.Println(user.RealName, k)
  221. // err = models.UpdateCygxArticleDepartmentFollow(user)
  222. // if err != nil {
  223. // fmt.Println("UpdateCygxArticleDepartmentFollow ,Err" + err.Error())
  224. // }
  225. // }
  226. // }
  227. // }
  228. // // 处理用户的作者关注end
  229. //
  230. // // 处理用户的活动视频播放
  231. // listActivityVideo, err := models.GetActivityVideoHistoryByMobileList(condition)
  232. // if err != nil {
  233. // fmt.Println("GetArticleDepartmentFollowByMobileList ,Err" + err.Error())
  234. // return err
  235. // }
  236. // for k, v := range listActivityVideo {
  237. // if v.Mobile != "" {
  238. // user, err := models.GetWxUserItemByUserId(v.UserId)
  239. // if err != nil && err.Error() != utils.ErrNoRow() {
  240. // fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
  241. // }
  242. // if user != nil {
  243. // fmt.Println(user.RealName, k)
  244. // err = models.UpdateCygxActivityVideoHistory(user)
  245. // if err != nil {
  246. // fmt.Println("UpdateCygxActivityVideoHistory ,Err" + err.Error())
  247. // }
  248. // }
  249. // }
  250. // }
  251. // // 处理用户的活动视频播放end
  252. //
  253. // // 处理用户的活动音频播放
  254. // listActivityVoice, err := models.GetActivityVoiceHistoryByMobileList(condition)
  255. // if err != nil {
  256. // fmt.Println("GetActivityVoiceHistoryByMobileList ,Err" + err.Error())
  257. // return err
  258. // }
  259. // for k, v := range listActivityVoice {
  260. // if v.Mobile != "" {
  261. // user, err := models.GetWxUserItemByUserId(v.UserId)
  262. // if err != nil && err.Error() != utils.ErrNoRow() {
  263. // fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
  264. // }
  265. // if user != nil {
  266. // fmt.Println(user.RealName, k)
  267. // err = models.UpdateCygxActivityVoiceHistory(user)
  268. // if err != nil {
  269. // fmt.Println("UpdateCygxActivityVoiceHistory ,Err" + err.Error())
  270. // }
  271. // }
  272. // }
  273. // }
  274. // // 处理用户的活动音频播放end
  275. //
  276. // // 处理用户产业视频的播放记录
  277. // listMicroRoadshow, err := models.GetMicroRoadshowVideoHistoryByMobileList(condition)
  278. // if err != nil {
  279. // fmt.Println("GetMicroRoadshowVideoHistoryByMobileList ,Err" + err.Error())
  280. // return err
  281. // }
  282. // for k, v := range listMicroRoadshow {
  283. // if v.Mobile != "" {
  284. // user, err := models.GetWxUserItemByUserId(v.UserId)
  285. // if err != nil && err.Error() != utils.ErrNoRow() {
  286. // fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
  287. // }
  288. // if user != nil {
  289. // fmt.Println(user.RealName, k)
  290. // err = models.UpdateCygxMicroRoadshowVideoHistory(user)
  291. // if err != nil {
  292. // fmt.Println("UpdateCygxMicroRoadshowVideoHistory ,Err" + err.Error())
  293. // }
  294. // }
  295. // }
  296. // }
  297. // // 处理用户产业视频的播放记录 end
  298. //
  299. // //如果手机号不为空,则更新用户的报名信息
  300. // if mobiles != "" {
  301. // condition = ` AND mobile IN (` + mobiles + `)`
  302. // listSingUp, err := models.GetCygxActivitySignupByMobileList(condition)
  303. // if err != nil {
  304. // fmt.Println("GetCygxChartCollectByMobileList ,Err" + err.Error())
  305. // }
  306. // //fmt.Println("更新用户的报名信息长度", len(listSingUp))
  307. // for _, v := range listSingUp {
  308. // if v.Mobile != "" {
  309. // user, err := models.GetWxUserItemByMobile(v.Mobile)
  310. // if err != nil && err.Error() != utils.ErrNoRow() {
  311. // fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
  312. // }
  313. // if user != nil {
  314. // err = models.UpdateCygxActivitySignup(user)
  315. // if err != nil {
  316. // fmt.Println("UpdateCygxActivitySignup ,Err" + err.Error())
  317. // //return err
  318. // }
  319. // }
  320. // }
  321. // }
  322. // }
  323. //
  324. // }
  325. //}
  326. //处理用户标签
  327. //for _, vUser := range listUser {
  328. // labels, err := models.GetCygxCompanyUserListSplit(strconv.Itoa(vUser.UserId))
  329. // if err != nil {
  330. // fmt.Println("GetCygxCompanyUserListSplit Err", err)
  331. // return err
  332. // }
  333. // mapLabels := make(map[string]string)
  334. // var labelsListStr []*models.UserLabel
  335. // mapActivityLabels := make(map[string]string)
  336. // labelsList := strings.Split(labels, ",")
  337. // for _, vL := range labelsList {
  338. // if mapLabels[vL] == "" && vL != "" {
  339. // mapLabels[vL] = vL
  340. // item := new(models.UserLabel)
  341. // item.Label = vL
  342. // labelsListStr = append(labelsListStr, item)
  343. // }
  344. // }
  345. // dateTime := time.Now().AddDate(0, -3, 0).Format(utils.FormatDate)
  346. // listArticlePv, err := models.GetArticlePvCount(vUser.Mobile, vUser.Email, dateTime)
  347. // if err != nil && err.Error() != utils.ErrNoRow() {
  348. // fmt.Println("GetArticlePvCount Err", err)
  349. // return err
  350. // }
  351. // var articleIds string
  352. // mapArticleIdLabelTotal := make(map[string]int)
  353. // mapArticleIdPv := make(map[int]int)
  354. // if len(listArticlePv) > 0 {
  355. // for _, v := range listArticlePv {
  356. // articleIds += strconv.Itoa(v.ArticleId) + ","
  357. // mapArticleIdPv[v.ArticleId] = v.Pv
  358. // }
  359. // articleIds = strings.TrimRight(articleIds, ",")
  360. // //产业、标的标签
  361. // listLabelName, err := models.GetArticleGroupyIndustryName(articleIds)
  362. // if err != nil && err.Error() != utils.ErrNoRow() {
  363. // fmt.Println("GetArticleGroupyIndustryName Err", err)
  364. // return err
  365. // }
  366. // if len(listLabelName) > 0 {
  367. // for _, v := range listLabelName {
  368. // labelsIndustryList := strings.Split(v.IndustryName, "/")
  369. // labelsSubjectList := strings.Split(v.SubjectName, "/")
  370. // //添加产业统计
  371. // if len(labelsIndustryList) > 0 {
  372. // for _, vIn := range labelsIndustryList {
  373. // if mapActivityLabels[vIn] != "" {
  374. // mapArticleIdLabelTotal[vIn] += mapArticleIdPv[v.ArticleId]
  375. // } else {
  376. // mapArticleIdLabelTotal[vIn] = mapArticleIdPv[v.ArticleId]
  377. // mapActivityLabels[vIn] = vIn
  378. // }
  379. // }
  380. // }
  381. // if len(labelsSubjectList) > 0 {
  382. // //添加标的统计
  383. // for _, vIn := range labelsSubjectList {
  384. // if mapActivityLabels[vIn] != "" {
  385. // mapArticleIdLabelTotal[vIn] += mapArticleIdPv[v.ArticleId]
  386. // } else {
  387. // mapArticleIdLabelTotal[vIn] = mapArticleIdPv[v.ArticleId]
  388. // mapActivityLabels[vIn] = vIn
  389. // }
  390. // }
  391. // }
  392. // }
  393. // }
  394. // }
  395. // articleIds, err = models.GetCygxArticleCollectId(vUser.UserId, dateTime)
  396. // if err != nil && err.Error() != utils.ErrNoRow() {
  397. // fmt.Println("GetCygxArticleCollectId Err", err)
  398. // return err
  399. // }
  400. // if articleIds != "" {
  401. // //产业、标的标签
  402. // listLabelName, err := models.GetArticleGroupyIndustryName(articleIds)
  403. // if err != nil && err.Error() != utils.ErrNoRow() {
  404. // fmt.Println("GetArticleGroupyIndustryName Err", err)
  405. // return err
  406. // }
  407. // if len(listLabelName) > 0 {
  408. // for _, v := range listLabelName {
  409. // labelsIndustryList := strings.Split(v.IndustryName, "/")
  410. // labelsSubjectList := strings.Split(v.SubjectName, "/")
  411. // //添加产业统计
  412. // if len(labelsIndustryList) > 0 {
  413. // for _, vIn := range labelsIndustryList {
  414. // if mapActivityLabels[vIn] != "" {
  415. // mapArticleIdLabelTotal[vIn] += 1
  416. // } else {
  417. // mapArticleIdLabelTotal[vIn] = 1
  418. // mapActivityLabels[vIn] = vIn
  419. // }
  420. // }
  421. // }
  422. // if len(labelsSubjectList) > 0 {
  423. // //添加标的统计
  424. // for _, vIn := range labelsSubjectList {
  425. // if mapActivityLabels[vIn] != "" {
  426. // mapArticleIdLabelTotal[vIn] += 1
  427. // } else {
  428. // mapArticleIdLabelTotal[vIn] = 1
  429. // mapActivityLabels[vIn] = vIn
  430. // }
  431. // }
  432. // }
  433. // }
  434. // }
  435. // }
  436. // //活动标签计算
  437. // listActivityPv, err := models.GetActivitySignCount(vUser.Mobile, dateTime)
  438. // if err != nil && err.Error() != utils.ErrNoRow() {
  439. // fmt.Println("GetActivitySignCount Err", err)
  440. // return err
  441. // }
  442. // if len(listActivityPv) > 0 {
  443. // for _, v := range listActivityPv {
  444. // labelsList := strings.Split(v.Label, "-")
  445. // for _, v2 := range labelsList {
  446. // labelsListSon := strings.Split(v2, "/")
  447. // for _, v3 := range labelsListSon {
  448. // if mapActivityLabels[v3] != "" {
  449. // mapArticleIdLabelTotal[v3] += 1
  450. // } else {
  451. // mapArticleIdLabelTotal[v3] = 1
  452. // mapActivityLabels[v3] = v3
  453. // }
  454. // }
  455. // }
  456. // }
  457. // }
  458. // //对标签数量进行排序
  459. // type KvPair struct {
  460. // Key string
  461. // Val int
  462. // }
  463. // tmpList := make([]KvPair, 0)
  464. // for k, v := range mapArticleIdLabelTotal {
  465. // tmpList = append(tmpList, KvPair{Key: k, Val: v})
  466. // }
  467. // sort.Slice(tmpList, func(i, j int) bool {
  468. // return tmpList[i].Val > tmpList[j].Val // 降序
  469. // })
  470. // for _, v := range tmpList {
  471. // if v.Key != "" {
  472. // mapLabels[v.Key] = v.Key
  473. // item := new(models.UserLabel)
  474. // item.Label = v.Key
  475. // labelsListStr = append(labelsListStr, item)
  476. // }
  477. // }
  478. // var labelNew string
  479. // for _, v := range labelsListStr {
  480. // labelNew += v.Label + ","
  481. // }
  482. // labelNew = strings.TrimRight(labelNew, ",")
  483. // if labelNew != "" {
  484. // err = models.UpdateUserLabel(labelNew, vUser.UserId)
  485. // if err != nil {
  486. // fmt.Println("UpdateUserLabel Err", err)
  487. // return err
  488. // }
  489. // }
  490. //}
  491. //处理用户、机构互动量数据
  492. {
  493. var userIds string
  494. var itemsInteraction []*models.CygxUserInteractionNum
  495. mapUserInteraction := make(map[int]int)
  496. mapCompanyInteraction := make(map[int]int)
  497. mapCompanyInteractionItem := make(map[int]*models.CygxCompanyInteractionNum)
  498. mapComapnyInteractionSeller := make(map[int]int)
  499. mapComapnyInteractionNumSeller := make(map[int]int) // 销售可查看的互动量
  500. //获取已经处理记录的用户并记录切片
  501. listUserInteractionNum, err := models.GetCygxUserInteractionNumList()
  502. if err != nil && err.Error() != utils.ErrNoRow() {
  503. fmt.Println("GetCygxUserInteractionNumList Err", err)
  504. return err
  505. }
  506. for _, v := range listUserInteractionNum {
  507. mapUserInteraction[v.UserId] = v.UserId
  508. }
  509. //获取跟销售建立绑定关系的用户并记录切片
  510. listUserSeller, err := models.GetUserSellerRelationUserList()
  511. if err != nil && err.Error() != utils.ErrNoRow() {
  512. fmt.Println("GetUserSellerRelationUserList Err", err)
  513. return err
  514. }
  515. for _, v := range listUserSeller {
  516. mapComapnyInteractionSeller[v.UserId] = v.UserId
  517. }
  518. listCompanyInteractionNum, err := models.GetCygxCompanyInteractionNumList()
  519. if err != nil && err.Error() != utils.ErrNoRow() {
  520. fmt.Println("GetCygxUserInteractionNumList Err", err)
  521. return err
  522. }
  523. for _, v := range listCompanyInteractionNum {
  524. mapCompanyInteraction[v.CompanyId] = v.CompanyId
  525. }
  526. //处理用户互动量数据
  527. for kUser, vUser := range listUser {
  528. userIds += strconv.Itoa(vUser.UserId) + ","
  529. //一次查询一百个避免用户过多
  530. if kUser%100 == 0 {
  531. userIds = strings.TrimRight(userIds, ",")
  532. userUserInteractionList, err := models.GetCygxCompanyUserUserInteraction(userIds)
  533. if err != nil {
  534. fmt.Println("GetCygxCompanyUserUserInteraction Err", err)
  535. return err
  536. }
  537. //处理用户的互动量
  538. if len(userUserInteractionList) > 0 {
  539. for _, vsplit := range userUserInteractionList {
  540. interactionNum = vsplit.HistoryNum + vsplit.CountNum + vsplit.IndustryFllowNum + vsplit.DepartmentFollowNum + vsplit.KeyWordNum + vsplit.OnLineNum + vsplit.OfficeNum + vsplit.ChartCountNum + vsplit.TripNum + vsplit.RoadshowVideoNum + vsplit.ActivityVideoNum + vsplit.ActivityVoiceNum + vsplit.TagNum
  541. if interactionNum > 0 {
  542. //更改用户的互动量
  543. err = models.UpdateUserInteractionNum(interactionNum, int(vsplit.UserId))
  544. if err != nil {
  545. fmt.Println("UpdateUserInteractionNum Err", err)
  546. return err
  547. }
  548. mapComapnyInteractionNum[vsplit.CompanyId] += interactionNum
  549. itemInteraction := new(models.CygxUserInteractionNum)
  550. itemInteraction.UserId = int(vsplit.UserId)
  551. itemInteraction.ArticleHistoryNum = vsplit.HistoryNum
  552. itemInteraction.ArticleCountNum = vsplit.CountNum
  553. itemInteraction.ChartCountNum = vsplit.ChartCountNum
  554. itemInteraction.IndustryFllowNum = vsplit.IndustryFllowNum
  555. itemInteraction.DepartmentFollowNum = vsplit.DepartmentFollowNum
  556. itemInteraction.KeyWordNum = vsplit.KeyWordNum
  557. itemInteraction.ActivityOnLineNum = vsplit.OnLineNum
  558. itemInteraction.ActivityOfficeNum = vsplit.OfficeNum
  559. itemInteraction.ActivityNum = vsplit.OnLineNum + vsplit.OfficeNum
  560. itemInteraction.TripNum = vsplit.TripNum
  561. itemInteraction.RoadshowVideoNum = vsplit.RoadshowVideoNum
  562. itemInteraction.ActivityVideoNum = vsplit.ActivityVideoNum
  563. itemInteraction.ActivityVoiceNum = vsplit.ActivityVoiceNum
  564. itemInteraction.TagNum = vsplit.TagNum
  565. itemInteraction.RoadshowNum = vsplit.RoadshowVideoNum + vsplit.ActivityVideoNum + vsplit.ActivityVoiceNum
  566. itemInteraction.CreateTime = time.Now()
  567. itemInteraction.ModifyTime = time.Now()
  568. //如果这个切片下的结构体没有值就给他初始值,如果有就跟后面的相加
  569. if mapCompanyInteractionItem[vsplit.CompanyId] == nil {
  570. itemCompanyInteraction := new(models.CygxCompanyInteractionNum)
  571. itemCompanyInteraction.CompanyId = vsplit.CompanyId
  572. itemCompanyInteraction.ArticleHistoryNum = vsplit.HistoryNum
  573. itemCompanyInteraction.ArticleCountNum = vsplit.CountNum
  574. itemCompanyInteraction.ChartCountNum = vsplit.ChartCountNum
  575. itemCompanyInteraction.IndustryFllowNum = vsplit.IndustryFllowNum
  576. itemCompanyInteraction.DepartmentFollowNum = vsplit.DepartmentFollowNum
  577. itemCompanyInteraction.KeyWordNum = vsplit.KeyWordNum
  578. itemCompanyInteraction.ActivityOnLineNum = vsplit.OnLineNum
  579. itemCompanyInteraction.ActivityOfficeNum = vsplit.OfficeNum
  580. itemCompanyInteraction.ActivityNum = vsplit.OnLineNum + vsplit.OfficeNum
  581. itemCompanyInteraction.TripNum = vsplit.TripNum
  582. itemCompanyInteraction.RoadshowVideoNum = vsplit.RoadshowVideoNum
  583. itemCompanyInteraction.ActivityVideoNum = vsplit.ActivityVideoNum
  584. itemCompanyInteraction.ActivityVoiceNum = vsplit.ActivityVoiceNum
  585. itemCompanyInteraction.TagNum = vsplit.TagNum
  586. itemCompanyInteraction.RoadshowNum = vsplit.RoadshowVideoNum + vsplit.ActivityVideoNum + vsplit.ActivityVoiceNum
  587. mapCompanyInteractionItem[vsplit.CompanyId] = itemCompanyInteraction
  588. mapCompanyInteractionItem[vsplit.CompanyId].CreateTime = time.Now()
  589. mapCompanyInteractionItem[vsplit.CompanyId].ModifyTime = time.Now()
  590. } else {
  591. fmt.Println("公司ID", vsplit.CompanyId)
  592. mapCompanyInteractionItem[vsplit.CompanyId].CompanyId = vsplit.CompanyId
  593. mapCompanyInteractionItem[vsplit.CompanyId].ArticleHistoryNum += vsplit.HistoryNum
  594. mapCompanyInteractionItem[vsplit.CompanyId].ArticleCountNum += vsplit.CountNum
  595. mapCompanyInteractionItem[vsplit.CompanyId].ChartCountNum += vsplit.ChartCountNum
  596. mapCompanyInteractionItem[vsplit.CompanyId].IndustryFllowNum += vsplit.IndustryFllowNum
  597. mapCompanyInteractionItem[vsplit.CompanyId].DepartmentFollowNum += vsplit.DepartmentFollowNum
  598. mapCompanyInteractionItem[vsplit.CompanyId].KeyWordNum += vsplit.KeyWordNum
  599. mapCompanyInteractionItem[vsplit.CompanyId].ActivityOnLineNum += vsplit.OnLineNum
  600. mapCompanyInteractionItem[vsplit.CompanyId].ActivityOfficeNum += vsplit.OfficeNum
  601. mapCompanyInteractionItem[vsplit.CompanyId].ActivityNum += vsplit.OnLineNum + vsplit.OfficeNum
  602. mapCompanyInteractionItem[vsplit.CompanyId].TripNum += vsplit.TripNum
  603. mapCompanyInteractionItem[vsplit.CompanyId].RoadshowVideoNum += vsplit.RoadshowVideoNum
  604. mapCompanyInteractionItem[vsplit.CompanyId].ActivityVideoNum += vsplit.ActivityVideoNum
  605. mapCompanyInteractionItem[vsplit.CompanyId].ActivityVoiceNum += vsplit.ActivityVoiceNum
  606. mapCompanyInteractionItem[vsplit.CompanyId].TagNum += vsplit.TagNum
  607. mapCompanyInteractionItem[vsplit.CompanyId].RoadshowNum += vsplit.RoadshowVideoNum + vsplit.ActivityVideoNum + vsplit.ActivityVoiceNum
  608. }
  609. //如果存在就修改不存在就新增
  610. if mapUserInteraction[int(vsplit.UserId)] == 0 {
  611. itemsInteraction = append(itemsInteraction, itemInteraction)
  612. } else {
  613. err = models.UpdateCygxUserInteractionNum(itemInteraction)
  614. if err != nil {
  615. fmt.Println("UpdateCygxUserInteractionNum Err", err)
  616. return err
  617. }
  618. }
  619. }
  620. }
  621. }
  622. userIds = ""
  623. }
  624. }
  625. userIds = strings.TrimRight(userIds, ",")
  626. if userIds != "" {
  627. userUserInteractionList, err := models.GetCygxCompanyUserUserInteraction(userIds)
  628. if err != nil {
  629. fmt.Println("GetCygxCompanyUserUserInteraction Err", err)
  630. return err
  631. }
  632. //fmt.Println("处理用户剩余的")
  633. //处理用户的互动量
  634. if len(userUserInteractionList) > 0 {
  635. for _, vsplit := range userUserInteractionList {
  636. interactionNum = vsplit.HistoryNum + vsplit.CountNum + vsplit.IndustryFllowNum + vsplit.DepartmentFollowNum + vsplit.KeyWordNum + vsplit.OnLineNum + vsplit.OfficeNum + vsplit.ChartCountNum + vsplit.TripNum + vsplit.RoadshowVideoNum + vsplit.ActivityVideoNum + vsplit.ActivityVoiceNum + vsplit.TagNum
  637. if interactionNum > 0 {
  638. err = models.UpdateUserInteractionNum(interactionNum, int(vsplit.UserId))
  639. if err != nil {
  640. fmt.Println("UpdateUserInteractionNum Err", err)
  641. return err
  642. }
  643. mapComapnyInteractionNum[vsplit.CompanyId] += interactionNum
  644. if mapComapnyInteractionSeller[int(vsplit.UserId)] > 0 {
  645. mapComapnyInteractionNumSeller[vsplit.CompanyId] += interactionNum //如果销售可以看到这个人,那么就对销售可见的数量进行添加
  646. }
  647. itemInteraction := new(models.CygxUserInteractionNum)
  648. itemInteraction.UserId = int(vsplit.UserId)
  649. itemInteraction.ArticleHistoryNum = vsplit.HistoryNum
  650. itemInteraction.ArticleCountNum = vsplit.CountNum
  651. itemInteraction.ChartCountNum = vsplit.ChartCountNum
  652. itemInteraction.IndustryFllowNum = vsplit.IndustryFllowNum
  653. itemInteraction.DepartmentFollowNum = vsplit.DepartmentFollowNum
  654. itemInteraction.KeyWordNum = vsplit.KeyWordNum
  655. itemInteraction.ActivityOnLineNum = vsplit.OnLineNum
  656. itemInteraction.ActivityOfficeNum = vsplit.OfficeNum
  657. itemInteraction.ActivityNum = vsplit.OnLineNum + vsplit.OfficeNum
  658. itemInteraction.TripNum = vsplit.TripNum
  659. itemInteraction.RoadshowVideoNum = vsplit.RoadshowVideoNum
  660. itemInteraction.ActivityVideoNum = vsplit.ActivityVideoNum
  661. itemInteraction.ActivityVoiceNum = vsplit.ActivityVoiceNum
  662. itemInteraction.TagNum = vsplit.TagNum
  663. itemInteraction.RoadshowNum = vsplit.RoadshowVideoNum + vsplit.ActivityVideoNum + vsplit.ActivityVoiceNum
  664. //如果这个切片下的结构体没有值就给他初始值,如果有就跟后面的相加
  665. if mapCompanyInteractionItem[vsplit.CompanyId] == nil {
  666. itemCompanyInteraction := new(models.CygxCompanyInteractionNum)
  667. itemCompanyInteraction.CompanyId = vsplit.CompanyId
  668. itemCompanyInteraction.ArticleHistoryNum = vsplit.HistoryNum
  669. itemCompanyInteraction.ArticleCountNum = vsplit.CountNum
  670. itemCompanyInteraction.ChartCountNum = vsplit.ChartCountNum
  671. itemCompanyInteraction.IndustryFllowNum = vsplit.IndustryFllowNum
  672. itemCompanyInteraction.DepartmentFollowNum = vsplit.DepartmentFollowNum
  673. itemCompanyInteraction.KeyWordNum = vsplit.KeyWordNum
  674. itemCompanyInteraction.ActivityOnLineNum = vsplit.OnLineNum
  675. itemCompanyInteraction.ActivityOfficeNum = vsplit.OfficeNum
  676. itemCompanyInteraction.ActivityNum = vsplit.OnLineNum + vsplit.OfficeNum
  677. itemCompanyInteraction.TripNum = vsplit.TripNum
  678. itemCompanyInteraction.RoadshowVideoNum = vsplit.RoadshowVideoNum
  679. itemCompanyInteraction.ActivityVideoNum = vsplit.ActivityVideoNum
  680. itemCompanyInteraction.ActivityVoiceNum = vsplit.ActivityVoiceNum
  681. itemCompanyInteraction.TagNum = vsplit.TagNum
  682. itemCompanyInteraction.RoadshowNum = vsplit.RoadshowVideoNum + vsplit.ActivityVideoNum + vsplit.ActivityVoiceNum
  683. mapCompanyInteractionItem[vsplit.CompanyId] = itemCompanyInteraction
  684. mapCompanyInteractionItem[vsplit.CompanyId].CreateTime = time.Now()
  685. mapCompanyInteractionItem[vsplit.CompanyId].ModifyTime = time.Now()
  686. } else {
  687. mapCompanyInteractionItem[vsplit.CompanyId].CompanyId = vsplit.CompanyId
  688. mapCompanyInteractionItem[vsplit.CompanyId].ArticleHistoryNum += vsplit.HistoryNum
  689. mapCompanyInteractionItem[vsplit.CompanyId].ArticleCountNum += vsplit.CountNum
  690. mapCompanyInteractionItem[vsplit.CompanyId].ChartCountNum += vsplit.ChartCountNum
  691. mapCompanyInteractionItem[vsplit.CompanyId].IndustryFllowNum += vsplit.IndustryFllowNum
  692. mapCompanyInteractionItem[vsplit.CompanyId].DepartmentFollowNum += vsplit.DepartmentFollowNum
  693. mapCompanyInteractionItem[vsplit.CompanyId].KeyWordNum += vsplit.KeyWordNum
  694. mapCompanyInteractionItem[vsplit.CompanyId].ActivityOnLineNum += vsplit.OnLineNum
  695. mapCompanyInteractionItem[vsplit.CompanyId].ActivityOfficeNum += vsplit.OfficeNum
  696. mapCompanyInteractionItem[vsplit.CompanyId].ActivityNum += vsplit.OnLineNum + vsplit.OfficeNum
  697. mapCompanyInteractionItem[vsplit.CompanyId].TripNum += vsplit.TripNum
  698. mapCompanyInteractionItem[vsplit.CompanyId].RoadshowVideoNum += vsplit.RoadshowVideoNum
  699. mapCompanyInteractionItem[vsplit.CompanyId].ActivityVideoNum += vsplit.ActivityVideoNum
  700. mapCompanyInteractionItem[vsplit.CompanyId].ActivityVoiceNum += vsplit.ActivityVoiceNum
  701. mapCompanyInteractionItem[vsplit.CompanyId].TagNum += vsplit.TagNum
  702. mapCompanyInteractionItem[vsplit.CompanyId].RoadshowNum += vsplit.RoadshowVideoNum + vsplit.ActivityVideoNum + vsplit.ActivityVoiceNum
  703. }
  704. //如果存在就修改不存在就新增
  705. if mapUserInteraction[int(vsplit.UserId)] == 0 {
  706. itemsInteraction = append(itemsInteraction, itemInteraction)
  707. } else {
  708. err = models.UpdateCygxUserInteractionNum(itemInteraction)
  709. if err != nil {
  710. fmt.Println("UpdateCygxUserInteractionNum Err", err)
  711. return err
  712. }
  713. //fmt.Println(itemInteraction.UserId)
  714. //err = models.UpdateCygxUserInteractionNum(itemInteraction)
  715. }
  716. }
  717. }
  718. }
  719. }
  720. fmt.Println("修改机构互动量信息")
  721. ////修改机构互动量信息
  722. if len(mapComapnyInteractionNum) > 0 {
  723. for k, v := range mapComapnyInteractionNum {
  724. companyId := k
  725. err = models.UpdateComapanyInteractionNum(v, mapComapnyInteractionNumSeller[companyId], companyId)
  726. if err != nil {
  727. fmt.Println(" AddCygxUserInteractionNumList Err", err)
  728. }
  729. }
  730. }
  731. // 批量添加用户互动量信息
  732. if len(itemsInteraction) > 0 {
  733. _, err = models.AddCygxUserInteractionNumList(itemsInteraction)
  734. if err != nil {
  735. fmt.Println(" AddCygxUserInteractionNumList Err", err)
  736. }
  737. }
  738. // 批量添加用户互动量信息
  739. if len(mapCompanyInteractionItem) > 0 {
  740. fmt.Println("添加机构互动信息")
  741. for _, v := range mapCompanyInteractionItem {
  742. fmt.Println(v.CompanyId)
  743. if mapCompanyInteraction[v.CompanyId] > 0 {
  744. err = models.UpdateCygxCompanyInteractionNum(v)
  745. if err != nil {
  746. fmt.Println(" UpdateCygxCompanyInteractionNum Err", err)
  747. }
  748. } else {
  749. _, err = models.AddCygxCompanyInteractionNum(v)
  750. if err != nil {
  751. fmt.Println(" AddCygxCompanyInteractionNum Err", err)
  752. }
  753. }
  754. }
  755. }
  756. }
  757. //更新用户标签以及权重
  758. //go UpdateUserLabelWeight()
  759. return
  760. }
  761. func init123123() {
  762. var err error
  763. defer func() {
  764. if err != nil {
  765. go utils.SendAlarmMsg("更新用户标签失败;Err:"+err.Error(), 2)
  766. }
  767. }()
  768. var interactionNum int
  769. mapComapnyInteractionNum := make(map[int]int)
  770. listUser, err := models.GetUserRegisterListinit()
  771. if err != nil && err.Error() != utils.ErrNoRow() {
  772. fmt.Println("GetUserSellerRelationUserList Err", err)
  773. return
  774. }
  775. fmt.Println(len(listUser))
  776. //return
  777. //处理用户、机构互动量数据
  778. {
  779. var userIds string
  780. var itemsInteraction []*models.CygxUserInteractionNum
  781. mapUserInteraction := make(map[int]int)
  782. mapCompanyInteraction := make(map[int]int)
  783. mapCompanyInteractionItem := make(map[int]*models.CygxCompanyInteractionNum)
  784. mapComapnyInteractionSeller := make(map[int]int)
  785. mapComapnyInteractionNumSeller := make(map[int]int) // 销售可查看的互动量
  786. //获取已经处理记录的用户并记录切片
  787. listUserInteractionNum, err := models.GetCygxUserInteractionNumList()
  788. if err != nil && err.Error() != utils.ErrNoRow() {
  789. fmt.Println("GetCygxUserInteractionNumList Err", err)
  790. return
  791. }
  792. for _, v := range listUserInteractionNum {
  793. mapUserInteraction[v.UserId] = v.UserId
  794. }
  795. //获取跟销售建立绑定关系的用户并记录切片
  796. listUserSeller, err := models.GetUserSellerRelationUserList()
  797. if err != nil && err.Error() != utils.ErrNoRow() {
  798. fmt.Println("GetUserSellerRelationUserList Err", err)
  799. return
  800. }
  801. for _, v := range listUserSeller {
  802. mapComapnyInteractionSeller[v.UserId] = v.UserId
  803. }
  804. listCompanyInteractionNum, err := models.GetCygxCompanyInteractionNumList()
  805. if err != nil && err.Error() != utils.ErrNoRow() {
  806. fmt.Println("GetCygxUserInteractionNumList Err", err)
  807. return
  808. }
  809. for _, v := range listCompanyInteractionNum {
  810. mapCompanyInteraction[v.CompanyId] = v.CompanyId
  811. }
  812. //处理用户互动量数据
  813. for kUser, vUser := range listUser {
  814. userIds += strconv.Itoa(vUser.UserId) + ","
  815. //一次查询一百个避免用户过多
  816. if kUser%100 == 0 {
  817. userIds = strings.TrimRight(userIds, ",")
  818. userUserInteractionList, err := models.GetCygxCompanyUserUserInteraction(userIds)
  819. if err != nil {
  820. fmt.Println("GetCygxCompanyUserUserInteraction Err", err)
  821. return
  822. }
  823. //处理用户的互动量
  824. if len(userUserInteractionList) > 0 {
  825. for _, vsplit := range userUserInteractionList {
  826. interactionNum = vsplit.HistoryNum + vsplit.CountNum + vsplit.IndustryFllowNum + vsplit.DepartmentFollowNum + vsplit.KeyWordNum + vsplit.OnLineNum + vsplit.OfficeNum + vsplit.ChartCountNum + vsplit.TripNum + vsplit.RoadshowVideoNum + vsplit.ActivityVideoNum + vsplit.ActivityVoiceNum + vsplit.TagNum
  827. if interactionNum > 0 {
  828. //更改用户的互动量
  829. err = models.UpdateUserInteractionNum(interactionNum, int(vsplit.UserId))
  830. if err != nil {
  831. fmt.Println("UpdateUserInteractionNum Err", err)
  832. return
  833. }
  834. mapComapnyInteractionNum[vsplit.CompanyId] += interactionNum
  835. itemInteraction := new(models.CygxUserInteractionNum)
  836. itemInteraction.UserId = int(vsplit.UserId)
  837. itemInteraction.ArticleHistoryNum = vsplit.HistoryNum
  838. itemInteraction.ArticleCountNum = vsplit.CountNum
  839. itemInteraction.ChartCountNum = vsplit.ChartCountNum
  840. itemInteraction.IndustryFllowNum = vsplit.IndustryFllowNum
  841. itemInteraction.DepartmentFollowNum = vsplit.DepartmentFollowNum
  842. itemInteraction.KeyWordNum = vsplit.KeyWordNum
  843. itemInteraction.ActivityOnLineNum = vsplit.OnLineNum
  844. itemInteraction.ActivityOfficeNum = vsplit.OfficeNum
  845. itemInteraction.ActivityNum = vsplit.OnLineNum + vsplit.OfficeNum
  846. itemInteraction.TripNum = vsplit.TripNum
  847. itemInteraction.RoadshowVideoNum = vsplit.RoadshowVideoNum
  848. itemInteraction.ActivityVideoNum = vsplit.ActivityVideoNum
  849. itemInteraction.ActivityVoiceNum = vsplit.ActivityVoiceNum
  850. itemInteraction.TagNum = vsplit.TagNum
  851. itemInteraction.RoadshowNum = vsplit.RoadshowVideoNum + vsplit.ActivityVideoNum + vsplit.ActivityVoiceNum
  852. itemInteraction.CreateTime = time.Now()
  853. itemInteraction.ModifyTime = time.Now()
  854. //如果这个切片下的结构体没有值就给他初始值,如果有就跟后面的相加
  855. if mapCompanyInteractionItem[vsplit.CompanyId] == nil {
  856. itemCompanyInteraction := new(models.CygxCompanyInteractionNum)
  857. itemCompanyInteraction.CompanyId = vsplit.CompanyId
  858. itemCompanyInteraction.ArticleHistoryNum = vsplit.HistoryNum
  859. itemCompanyInteraction.ArticleCountNum = vsplit.CountNum
  860. itemCompanyInteraction.ChartCountNum = vsplit.ChartCountNum
  861. itemCompanyInteraction.IndustryFllowNum = vsplit.IndustryFllowNum
  862. itemCompanyInteraction.DepartmentFollowNum = vsplit.DepartmentFollowNum
  863. itemCompanyInteraction.KeyWordNum = vsplit.KeyWordNum
  864. itemCompanyInteraction.ActivityOnLineNum = vsplit.OnLineNum
  865. itemCompanyInteraction.ActivityOfficeNum = vsplit.OfficeNum
  866. itemCompanyInteraction.ActivityNum = vsplit.OnLineNum + vsplit.OfficeNum
  867. itemCompanyInteraction.TripNum = vsplit.TripNum
  868. itemCompanyInteraction.RoadshowVideoNum = vsplit.RoadshowVideoNum
  869. itemCompanyInteraction.ActivityVideoNum = vsplit.ActivityVideoNum
  870. itemCompanyInteraction.ActivityVoiceNum = vsplit.ActivityVoiceNum
  871. itemCompanyInteraction.TagNum = vsplit.TagNum
  872. itemCompanyInteraction.RoadshowNum = vsplit.RoadshowVideoNum + vsplit.ActivityVideoNum + vsplit.ActivityVoiceNum
  873. mapCompanyInteractionItem[vsplit.CompanyId] = itemCompanyInteraction
  874. mapCompanyInteractionItem[vsplit.CompanyId].CreateTime = time.Now()
  875. mapCompanyInteractionItem[vsplit.CompanyId].ModifyTime = time.Now()
  876. } else {
  877. fmt.Println("公司ID", vsplit.CompanyId)
  878. mapCompanyInteractionItem[vsplit.CompanyId].CompanyId = vsplit.CompanyId
  879. mapCompanyInteractionItem[vsplit.CompanyId].ArticleHistoryNum += vsplit.HistoryNum
  880. mapCompanyInteractionItem[vsplit.CompanyId].ArticleCountNum += vsplit.CountNum
  881. mapCompanyInteractionItem[vsplit.CompanyId].ChartCountNum += vsplit.ChartCountNum
  882. mapCompanyInteractionItem[vsplit.CompanyId].IndustryFllowNum += vsplit.IndustryFllowNum
  883. mapCompanyInteractionItem[vsplit.CompanyId].DepartmentFollowNum += vsplit.DepartmentFollowNum
  884. mapCompanyInteractionItem[vsplit.CompanyId].KeyWordNum += vsplit.KeyWordNum
  885. mapCompanyInteractionItem[vsplit.CompanyId].ActivityOnLineNum += vsplit.OnLineNum
  886. mapCompanyInteractionItem[vsplit.CompanyId].ActivityOfficeNum += vsplit.OfficeNum
  887. mapCompanyInteractionItem[vsplit.CompanyId].ActivityNum += vsplit.OnLineNum + vsplit.OfficeNum
  888. mapCompanyInteractionItem[vsplit.CompanyId].TripNum += vsplit.TripNum
  889. mapCompanyInteractionItem[vsplit.CompanyId].RoadshowVideoNum += vsplit.RoadshowVideoNum
  890. mapCompanyInteractionItem[vsplit.CompanyId].ActivityVideoNum += vsplit.ActivityVideoNum
  891. mapCompanyInteractionItem[vsplit.CompanyId].ActivityVoiceNum += vsplit.ActivityVoiceNum
  892. mapCompanyInteractionItem[vsplit.CompanyId].TagNum += vsplit.TagNum
  893. mapCompanyInteractionItem[vsplit.CompanyId].RoadshowNum += vsplit.RoadshowVideoNum + vsplit.ActivityVideoNum + vsplit.ActivityVoiceNum
  894. }
  895. //如果存在就修改不存在就新增
  896. if mapUserInteraction[int(vsplit.UserId)] == 0 {
  897. itemsInteraction = append(itemsInteraction, itemInteraction)
  898. } else {
  899. err = models.UpdateCygxUserInteractionNum(itemInteraction)
  900. if err != nil {
  901. fmt.Println("UpdateCygxUserInteractionNum Err", err)
  902. return
  903. }
  904. fmt.Println(itemInteraction.UserId)
  905. }
  906. }
  907. }
  908. }
  909. userIds = ""
  910. }
  911. }
  912. userIds = strings.TrimRight(userIds, ",")
  913. if userIds != "" {
  914. userUserInteractionList, err := models.GetCygxCompanyUserUserInteraction(userIds)
  915. if err != nil {
  916. fmt.Println("GetCygxCompanyUserUserInteraction Err", err)
  917. return
  918. }
  919. //fmt.Println("处理用户剩余的")
  920. //处理用户的互动量
  921. if len(userUserInteractionList) > 0 {
  922. for _, vsplit := range userUserInteractionList {
  923. interactionNum = vsplit.HistoryNum + vsplit.CountNum + vsplit.IndustryFllowNum + vsplit.DepartmentFollowNum + vsplit.KeyWordNum + vsplit.OnLineNum + vsplit.OfficeNum + vsplit.ChartCountNum + vsplit.TripNum + vsplit.RoadshowVideoNum + vsplit.ActivityVideoNum + vsplit.ActivityVoiceNum + vsplit.TagNum
  924. if interactionNum > 0 {
  925. err = models.UpdateUserInteractionNum(interactionNum, int(vsplit.UserId))
  926. if err != nil {
  927. fmt.Println("UpdateUserInteractionNum Err", err)
  928. return
  929. }
  930. mapComapnyInteractionNum[vsplit.CompanyId] += interactionNum
  931. if mapComapnyInteractionSeller[int(vsplit.UserId)] > 0 {
  932. mapComapnyInteractionNumSeller[vsplit.CompanyId] += interactionNum //如果销售可以看到这个人,那么就对销售可见的数量进行添加
  933. }
  934. itemInteraction := new(models.CygxUserInteractionNum)
  935. itemInteraction.UserId = int(vsplit.UserId)
  936. itemInteraction.ArticleHistoryNum = vsplit.HistoryNum
  937. itemInteraction.ArticleCountNum = vsplit.CountNum
  938. itemInteraction.ChartCountNum = vsplit.ChartCountNum
  939. itemInteraction.IndustryFllowNum = vsplit.IndustryFllowNum
  940. itemInteraction.DepartmentFollowNum = vsplit.DepartmentFollowNum
  941. itemInteraction.KeyWordNum = vsplit.KeyWordNum
  942. itemInteraction.ActivityOnLineNum = vsplit.OnLineNum
  943. itemInteraction.ActivityOfficeNum = vsplit.OfficeNum
  944. itemInteraction.ActivityNum = vsplit.OnLineNum + vsplit.OfficeNum
  945. itemInteraction.TripNum = vsplit.TripNum
  946. itemInteraction.RoadshowVideoNum = vsplit.RoadshowVideoNum
  947. itemInteraction.ActivityVideoNum = vsplit.ActivityVideoNum
  948. itemInteraction.ActivityVoiceNum = vsplit.ActivityVoiceNum
  949. itemInteraction.TagNum = vsplit.TagNum
  950. itemInteraction.RoadshowNum = vsplit.RoadshowVideoNum + vsplit.ActivityVideoNum + vsplit.ActivityVoiceNum
  951. //如果这个切片下的结构体没有值就给他初始值,如果有就跟后面的相加
  952. if mapCompanyInteractionItem[vsplit.CompanyId] == nil {
  953. itemCompanyInteraction := new(models.CygxCompanyInteractionNum)
  954. itemCompanyInteraction.CompanyId = vsplit.CompanyId
  955. itemCompanyInteraction.ArticleHistoryNum = vsplit.HistoryNum
  956. itemCompanyInteraction.ArticleCountNum = vsplit.CountNum
  957. itemCompanyInteraction.ChartCountNum = vsplit.ChartCountNum
  958. itemCompanyInteraction.IndustryFllowNum = vsplit.IndustryFllowNum
  959. itemCompanyInteraction.DepartmentFollowNum = vsplit.DepartmentFollowNum
  960. itemCompanyInteraction.KeyWordNum = vsplit.KeyWordNum
  961. itemCompanyInteraction.ActivityOnLineNum = vsplit.OnLineNum
  962. itemCompanyInteraction.ActivityOfficeNum = vsplit.OfficeNum
  963. itemCompanyInteraction.ActivityNum = vsplit.OnLineNum + vsplit.OfficeNum
  964. itemCompanyInteraction.TripNum = vsplit.TripNum
  965. itemCompanyInteraction.RoadshowVideoNum = vsplit.RoadshowVideoNum
  966. itemCompanyInteraction.ActivityVideoNum = vsplit.ActivityVideoNum
  967. itemCompanyInteraction.ActivityVoiceNum = vsplit.ActivityVoiceNum
  968. itemCompanyInteraction.TagNum = vsplit.TagNum
  969. itemCompanyInteraction.RoadshowNum = vsplit.RoadshowVideoNum + vsplit.ActivityVideoNum + vsplit.ActivityVoiceNum
  970. mapCompanyInteractionItem[vsplit.CompanyId] = itemCompanyInteraction
  971. mapCompanyInteractionItem[vsplit.CompanyId].CreateTime = time.Now()
  972. mapCompanyInteractionItem[vsplit.CompanyId].ModifyTime = time.Now()
  973. } else {
  974. mapCompanyInteractionItem[vsplit.CompanyId].CompanyId = vsplit.CompanyId
  975. mapCompanyInteractionItem[vsplit.CompanyId].ArticleHistoryNum += vsplit.HistoryNum
  976. mapCompanyInteractionItem[vsplit.CompanyId].ArticleCountNum += vsplit.CountNum
  977. mapCompanyInteractionItem[vsplit.CompanyId].ChartCountNum += vsplit.ChartCountNum
  978. mapCompanyInteractionItem[vsplit.CompanyId].IndustryFllowNum += vsplit.IndustryFllowNum
  979. mapCompanyInteractionItem[vsplit.CompanyId].DepartmentFollowNum += vsplit.DepartmentFollowNum
  980. mapCompanyInteractionItem[vsplit.CompanyId].KeyWordNum += vsplit.KeyWordNum
  981. mapCompanyInteractionItem[vsplit.CompanyId].ActivityOnLineNum += vsplit.OnLineNum
  982. mapCompanyInteractionItem[vsplit.CompanyId].ActivityOfficeNum += vsplit.OfficeNum
  983. mapCompanyInteractionItem[vsplit.CompanyId].ActivityNum += vsplit.OnLineNum + vsplit.OfficeNum
  984. mapCompanyInteractionItem[vsplit.CompanyId].TripNum += vsplit.TripNum
  985. mapCompanyInteractionItem[vsplit.CompanyId].RoadshowVideoNum += vsplit.RoadshowVideoNum
  986. mapCompanyInteractionItem[vsplit.CompanyId].ActivityVideoNum += vsplit.ActivityVideoNum
  987. mapCompanyInteractionItem[vsplit.CompanyId].ActivityVoiceNum += vsplit.ActivityVoiceNum
  988. mapCompanyInteractionItem[vsplit.CompanyId].TagNum += vsplit.TagNum
  989. mapCompanyInteractionItem[vsplit.CompanyId].RoadshowNum += vsplit.RoadshowVideoNum + vsplit.ActivityVideoNum + vsplit.ActivityVoiceNum
  990. }
  991. ////如果存在就修改不存在就新增
  992. //if mapUserInteraction[int(vsplit.UserId)] == 0 {
  993. // itemsInteraction = append(itemsInteraction, itemInteraction)
  994. //} else {
  995. // err = models.UpdateCygxUserInteractionNum(itemInteraction)
  996. // if err != nil {
  997. // fmt.Println("UpdateCygxUserInteractionNum Err", err)
  998. // return
  999. // }
  1000. // fmt.Println(itemInteraction.UserId)
  1001. // err = models.UpdateCygxUserInteractionNum(itemInteraction)
  1002. //}
  1003. }
  1004. }
  1005. }
  1006. }
  1007. fmt.Println("修改机构互动量信息")
  1008. ////修改机构互动量信息
  1009. if len(mapComapnyInteractionNum) > 0 {
  1010. for k, v := range mapComapnyInteractionNum {
  1011. companyId := k
  1012. err = models.UpdateComapanyInteractionNum(v, mapComapnyInteractionNumSeller[companyId], companyId)
  1013. if err != nil {
  1014. fmt.Println(" AddCygxUserInteractionNumList Err", err)
  1015. }
  1016. }
  1017. }
  1018. }
  1019. }
  1020. //func init() {
  1021. // UpdateWxUserLabelNew()
  1022. //}
  1023. func UpdateWxUserLabel(cont context.Context) (err error) {
  1024. //func UpdateWxUserLabel() (err error) {
  1025. defer func() {
  1026. if err != nil {
  1027. fmt.Println(err)
  1028. go utils.SendAlarmMsg(fmt.Sprint("更新用户标签失败UpdateWxUserLabel, err:", err.Error()), 2)
  1029. }
  1030. }()
  1031. mapComapnyInteractionNum := make(map[int]int) // 机构互动数量
  1032. mapComapnyInteractionNumSeller := make(map[int]int) // 销售可查看的机构互动数量
  1033. mapComapnyInteractionSeller := make(map[int]bool) // 跟销售建立绑定关系的用户
  1034. mapComapnyInteractionNumItem := make(map[int]*models.CygxCompanyInteractionNum) // 公司互动详情结构体
  1035. var comapnyInteractionNumItemAdd []*models.CygxCompanyInteractionNum // 公司互动详情结构体新增
  1036. var comapnyInteractionNumItemUpdate []*models.CygxCompanyInteractionNum // 公司互动详情结构体修改
  1037. //获取跟销售建立绑定关系的用户并记录切片
  1038. listUserSeller, e := models.GetUserSellerRelationUserList()
  1039. if e != nil && e.Error() != utils.ErrNoRow() {
  1040. err = errors.New("GetUserSellerRelationUserList, Err: " + e.Error())
  1041. return
  1042. }
  1043. for _, v := range listUserSeller {
  1044. mapComapnyInteractionSeller[v.UserId] = true
  1045. }
  1046. var condition string
  1047. //condition = ` AND h.create_time < '%s' AND h.company_id IN ( 398,17773) `
  1048. condition = ` AND h.create_time < '%s' `
  1049. condition = fmt.Sprintf(condition, time.Now().Format(utils.FormatDate)) // 截止昨天的所有数据
  1050. //fmt.Println(condition)
  1051. //报告阅读记录1
  1052. {
  1053. listArticleHistoryRecord, e := models.GetCygxArticleHistoryRecordInteractionNum(condition)
  1054. if e != nil {
  1055. err = errors.New("GetCygxArticleHistoryRecordInteractionNum, Err: " + e.Error())
  1056. return
  1057. }
  1058. for _, v := range listArticleHistoryRecord {
  1059. mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
  1060. if mapComapnyInteractionSeller[v.UserId] { //如果用户跟销售建立绑定关系,就对互动量进行累加
  1061. mapComapnyInteractionNumSeller[v.CompanyId] += v.InteractionNum
  1062. }
  1063. if mapComapnyInteractionNumItem[v.CompanyId] == nil {
  1064. mapComapnyInteractionNumItem[v.CompanyId] = new(models.CygxCompanyInteractionNum)
  1065. }
  1066. mapComapnyInteractionNumItem[v.CompanyId].ArticleHistoryNum += v.InteractionNum
  1067. }
  1068. }
  1069. //报告收藏记录2
  1070. {
  1071. listArticleCollect, e := models.GetCygxArticleCollectInteractionNum(condition)
  1072. if e != nil {
  1073. err = errors.New("GetCygxArticleCollectInteractionNum, Err: " + e.Error())
  1074. return
  1075. }
  1076. for _, v := range listArticleCollect {
  1077. mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
  1078. if mapComapnyInteractionSeller[v.UserId] { //如果用户跟销售建立绑定关系,就对互动量进行累加
  1079. mapComapnyInteractionNumSeller[v.CompanyId] += v.InteractionNum
  1080. }
  1081. if mapComapnyInteractionNumItem[v.CompanyId] == nil {
  1082. mapComapnyInteractionNumItem[v.CompanyId] = new(models.CygxCompanyInteractionNum)
  1083. }
  1084. mapComapnyInteractionNumItem[v.CompanyId].ArticleCountNum += v.InteractionNum
  1085. }
  1086. }
  1087. //图表收藏记录3
  1088. {
  1089. listChartCollect, e := models.GetCygxChartCollectInteractionNum(condition)
  1090. if e != nil {
  1091. err = errors.New("GetCygxChartCollectInteractionNum, Err: " + e.Error())
  1092. return
  1093. }
  1094. for _, v := range listChartCollect {
  1095. mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
  1096. if mapComapnyInteractionSeller[v.UserId] { //如果用户跟销售建立绑定关系,就对互动量进行累加
  1097. mapComapnyInteractionNumSeller[v.CompanyId] += v.InteractionNum
  1098. }
  1099. if mapComapnyInteractionNumItem[v.CompanyId] == nil {
  1100. mapComapnyInteractionNumItem[v.CompanyId] = new(models.CygxCompanyInteractionNum)
  1101. }
  1102. mapComapnyInteractionNumItem[v.CompanyId].ChartCountNum += v.InteractionNum
  1103. }
  1104. }
  1105. //用户关注产业数量4
  1106. {
  1107. listIndustryFllow, e := models.GetCygxIndustryFllowInteractionNum(condition)
  1108. if e != nil {
  1109. err = errors.New("GetCygxIndustryFllowInteractionNum, Err: " + e.Error())
  1110. return
  1111. }
  1112. for _, v := range listIndustryFllow {
  1113. mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
  1114. if mapComapnyInteractionSeller[v.UserId] { //如果用户跟销售建立绑定关系,就对互动量进行累加
  1115. mapComapnyInteractionNumSeller[v.CompanyId] += v.InteractionNum
  1116. }
  1117. if mapComapnyInteractionNumItem[v.CompanyId] == nil {
  1118. mapComapnyInteractionNumItem[v.CompanyId] = new(models.CygxCompanyInteractionNum)
  1119. }
  1120. mapComapnyInteractionNumItem[v.CompanyId].IndustryFllowNum += v.InteractionNum
  1121. }
  1122. }
  1123. //用户搜索关键词数量5
  1124. {
  1125. listSearchKeyWord, e := models.GetCygxSearchKeyWordInteractionNum(condition)
  1126. if e != nil {
  1127. err = errors.New("GetCygxSearchKeyWordInteractionNum, Err: " + e.Error())
  1128. return
  1129. }
  1130. for _, v := range listSearchKeyWord {
  1131. mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
  1132. if mapComapnyInteractionSeller[v.UserId] { //如果用户跟销售建立绑定关系,就对互动量进行累加
  1133. mapComapnyInteractionNumSeller[v.CompanyId] += v.InteractionNum
  1134. }
  1135. if mapComapnyInteractionNumItem[v.CompanyId] == nil {
  1136. mapComapnyInteractionNumItem[v.CompanyId] = new(models.CygxCompanyInteractionNum)
  1137. }
  1138. mapComapnyInteractionNumItem[v.CompanyId].KeyWordNum += v.InteractionNum
  1139. }
  1140. }
  1141. //用户活动报名参会数量6
  1142. {
  1143. listActivitySignup, e := models.GetCygxActivitySignupInteractionNum(condition)
  1144. if e != nil {
  1145. err = errors.New("GetCygxActivitySignupInteractionNum, Err: " + e.Error())
  1146. return
  1147. }
  1148. for _, v := range listActivitySignup {
  1149. mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
  1150. if mapComapnyInteractionSeller[v.UserId] { //如果用户跟销售建立绑定关系,就对互动量进行累加
  1151. mapComapnyInteractionNumSeller[v.CompanyId] += v.InteractionNum
  1152. }
  1153. if mapComapnyInteractionNumItem[v.CompanyId] == nil {
  1154. mapComapnyInteractionNumItem[v.CompanyId] = new(models.CygxCompanyInteractionNum)
  1155. }
  1156. mapComapnyInteractionNumItem[v.CompanyId].ActivityNum += v.InteractionNum
  1157. }
  1158. }
  1159. //用户专项调研活动报名参会数量7
  1160. {
  1161. listActivitySpecialSignup, e := models.GetCygxActivitySpecialSignupInteractionNum(condition)
  1162. if e != nil {
  1163. err = errors.New("GetCygxActivitySpecialSignupInteractionNum, Err: " + e.Error())
  1164. return
  1165. }
  1166. for _, v := range listActivitySpecialSignup {
  1167. mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
  1168. if mapComapnyInteractionSeller[v.UserId] { //如果用户跟销售建立绑定关系,就对互动量进行累加
  1169. mapComapnyInteractionNumSeller[v.CompanyId] += v.InteractionNum
  1170. }
  1171. if mapComapnyInteractionNumItem[v.CompanyId] == nil {
  1172. mapComapnyInteractionNumItem[v.CompanyId] = new(models.CygxCompanyInteractionNum)
  1173. }
  1174. mapComapnyInteractionNumItem[v.CompanyId].TripNum += v.InteractionNum
  1175. }
  1176. }
  1177. //用户路演精华播放数量8
  1178. {
  1179. listMicroRoadshowVideoHistory, e := models.GetCygxMicroRoadshowVideoHistoryInteractionNum(condition)
  1180. if e != nil {
  1181. err = errors.New("GetCygxMicroRoadshowVideoHistoryInteractionNum, Err: " + e.Error())
  1182. return
  1183. }
  1184. for _, v := range listMicroRoadshowVideoHistory {
  1185. mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
  1186. if mapComapnyInteractionSeller[v.UserId] { //如果用户跟销售建立绑定关系,就对互动量进行累加
  1187. mapComapnyInteractionNumSeller[v.CompanyId] += v.InteractionNum
  1188. }
  1189. if mapComapnyInteractionNumItem[v.CompanyId] == nil {
  1190. mapComapnyInteractionNumItem[v.CompanyId] = new(models.CygxCompanyInteractionNum)
  1191. }
  1192. mapComapnyInteractionNumItem[v.CompanyId].RoadshowNum += v.InteractionNum
  1193. }
  1194. }
  1195. //用户活动视频播放数量9
  1196. {
  1197. listActivityVideoHistory, e := models.GetCygxActivityVideoHistoryInteractionNum(condition)
  1198. if e != nil {
  1199. err = errors.New("GetCygxActivityVideoHistoryInteractionNum, Err: " + e.Error())
  1200. return
  1201. }
  1202. for _, v := range listActivityVideoHistory {
  1203. mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
  1204. if mapComapnyInteractionSeller[v.UserId] { //如果用户跟销售建立绑定关系,就对互动量进行累加
  1205. mapComapnyInteractionNumSeller[v.CompanyId] += v.InteractionNum
  1206. }
  1207. if mapComapnyInteractionNumItem[v.CompanyId] == nil {
  1208. mapComapnyInteractionNumItem[v.CompanyId] = new(models.CygxCompanyInteractionNum)
  1209. }
  1210. mapComapnyInteractionNumItem[v.CompanyId].ActivityVideoNum += v.InteractionNum
  1211. }
  1212. }
  1213. //用户活动音频播放数量10
  1214. {
  1215. listActivityVoiceHistory, e := models.GetCygxActivityVoiceHistoryInteractionNum(condition)
  1216. if e != nil {
  1217. err = errors.New("GetCygxActivityVoiceHistoryInteractionNum, Err: " + e.Error())
  1218. return
  1219. }
  1220. for _, v := range listActivityVoiceHistory {
  1221. mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
  1222. if mapComapnyInteractionSeller[v.UserId] { //如果用户跟销售建立绑定关系,就对互动量进行累加
  1223. mapComapnyInteractionNumSeller[v.CompanyId] += v.InteractionNum
  1224. }
  1225. if mapComapnyInteractionNumItem[v.CompanyId] == nil {
  1226. mapComapnyInteractionNumItem[v.CompanyId] = new(models.CygxCompanyInteractionNum)
  1227. }
  1228. mapComapnyInteractionNumItem[v.CompanyId].ActivityVoiceNum += v.InteractionNum
  1229. }
  1230. }
  1231. //用户首页标签点击量数量11
  1232. {
  1233. listTagHistory, e := models.GetCygxTagHistoryInteractionNum(condition)
  1234. if e != nil {
  1235. err = errors.New("GetCygxTagHistoryInteractionNum, Err: " + e.Error())
  1236. return
  1237. }
  1238. for _, v := range listTagHistory {
  1239. mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
  1240. if mapComapnyInteractionSeller[v.UserId] { //如果用户跟销售建立绑定关系,就对互动量进行累加
  1241. mapComapnyInteractionNumSeller[v.CompanyId] += v.InteractionNum
  1242. }
  1243. if mapComapnyInteractionNumItem[v.CompanyId] == nil {
  1244. mapComapnyInteractionNumItem[v.CompanyId] = new(models.CygxCompanyInteractionNum)
  1245. }
  1246. mapComapnyInteractionNumItem[v.CompanyId].TagNum += v.InteractionNum
  1247. }
  1248. }
  1249. //用户关注文章作者数量12
  1250. {
  1251. listArticleDepartmentFollow, e := models.GetCygxArticleDepartmentFollowInteractionNum(condition)
  1252. if e != nil {
  1253. err = errors.New("GetCygxArticleDepartmentFollowInteractionNum, Err: " + e.Error())
  1254. return
  1255. }
  1256. for _, v := range listArticleDepartmentFollow {
  1257. mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
  1258. if mapComapnyInteractionSeller[v.UserId] { //如果用户跟销售建立绑定关系,就对互动量进行累加
  1259. mapComapnyInteractionNumSeller[v.CompanyId] += v.InteractionNum
  1260. }
  1261. if mapComapnyInteractionNumItem[v.CompanyId] == nil {
  1262. mapComapnyInteractionNumItem[v.CompanyId] = new(models.CygxCompanyInteractionNum)
  1263. }
  1264. mapComapnyInteractionNumItem[v.CompanyId].DepartmentFollowNum += v.InteractionNum
  1265. }
  1266. }
  1267. //用户收藏研选专栏数量13
  1268. //{
  1269. // listYanxuanSpecialCollect, e := models.GetCygxYanxuanSpecialCollectInteractionNum(condition)
  1270. // if e != nil {
  1271. // err = errors.New("GetCygxYanxuanSpecialCollectInteractionNum, Err: " + e.Error())
  1272. // return
  1273. // }
  1274. // for _, v := range listYanxuanSpecialCollect {
  1275. // mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
  1276. // if mapComapnyInteractionSeller[v.UserId] { //如果用户跟销售建立绑定关系,就对互动量进行累加
  1277. // mapComapnyInteractionNumSeller[v.CompanyId] += v.InteractionNum
  1278. // }
  1279. //
  1280. // if mapComapnyInteractionNumItem[v.CompanyId] == nil {
  1281. // mapComapnyInteractionNumItem[v.CompanyId] = new(models.CygxCompanyInteractionNum)
  1282. // }
  1283. // mapComapnyInteractionNumItem[v.CompanyId].YanxuanSpecialCollectNum += v.InteractionNum
  1284. // }
  1285. //}
  1286. //用户关注研选专栏作者数量统计14
  1287. //{
  1288. // listYanxuanSpecialFollow, e := models.GetCygxYanxuanSpecialFollowInteractionNum(condition)
  1289. // if e != nil {
  1290. // err = errors.New("GetCygxYanxuanSpecialFollowInteractionNum, Err: " + e.Error())
  1291. // return
  1292. // }
  1293. // for _, v := range listYanxuanSpecialFollow {
  1294. // mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
  1295. // if mapComapnyInteractionSeller[v.UserId] { //如果用户跟销售建立绑定关系,就对互动量进行累加
  1296. // mapComapnyInteractionNumSeller[v.CompanyId] += v.InteractionNum
  1297. // }
  1298. // if mapComapnyInteractionNumItem[v.CompanyId] == nil {
  1299. // mapComapnyInteractionNumItem[v.CompanyId] = new(models.CygxCompanyInteractionNum)
  1300. // }
  1301. // mapComapnyInteractionNumItem[v.CompanyId].YanxuanSpecialFollowNum += v.InteractionNum
  1302. // }
  1303. //}
  1304. //用户研选专栏阅读数量数量15
  1305. {
  1306. listYanxuanSpecialFollow, e := models.GetCygxYanxuanSpecialRecordInteractionNum(condition)
  1307. if e != nil {
  1308. err = errors.New("GetCygxYanxuanSpecialRecordInteractionNum, Err: " + e.Error())
  1309. return
  1310. }
  1311. for _, v := range listYanxuanSpecialFollow {
  1312. mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
  1313. if mapComapnyInteractionSeller[v.UserId] { //如果用户跟销售建立绑定关系,就对互动量进行累加
  1314. mapComapnyInteractionNumSeller[v.CompanyId] += v.InteractionNum
  1315. }
  1316. if mapComapnyInteractionNumItem[v.CompanyId] == nil {
  1317. mapComapnyInteractionNumItem[v.CompanyId] = new(models.CygxCompanyInteractionNum)
  1318. }
  1319. mapComapnyInteractionNumItem[v.CompanyId].YanxuanSpecialNum += v.InteractionNum
  1320. }
  1321. }
  1322. mapCompanyInteraction := make(map[int]bool)
  1323. mapCompanyInteractionItem := make(map[int]*models.CygxCompanyInteractionNum)
  1324. listCompanyInteractionNum, e := models.GetCygxCompanyInteractionNumList() // 有过互动记录的公司
  1325. if e != nil && e.Error() != utils.ErrNoRow() {
  1326. err = errors.New("GetCygxCompanyInteractionNumList, Err: " + e.Error())
  1327. return
  1328. }
  1329. for _, v := range listCompanyInteractionNum {
  1330. mapCompanyInteraction[v.CompanyId] = true
  1331. mapCompanyInteractionItem[v.CompanyId] = v
  1332. }
  1333. var itemsCompanyInteractionNums []*models.CompanyInteractionNumReq // 公司总的互动量结构体
  1334. companyInteractionNumList, e := models.GetCompanyInteractionNumList() // 获取有机构互动的公司
  1335. mapInteractionNumOld := make(map[int]int) //历史公司总的互动量
  1336. mapInteractionNumSellerOld := make(map[int]int) //历史公司关联销售所能查看的互动量
  1337. for _, v := range companyInteractionNumList {
  1338. mapInteractionNumOld[v.CompanyId] = v.InteractionNum
  1339. mapInteractionNumSellerOld[v.CompanyId] = v.InteractionNumSeller
  1340. }
  1341. for k, v := range mapComapnyInteractionNumItem {
  1342. v.CompanyId = k
  1343. if mapCompanyInteraction[k] {
  1344. itemOld := mapCompanyInteractionItem[v.CompanyId]
  1345. //ArticleHistoryNum int `description:"文章浏览数量"`
  1346. //ArticleCountNum int `description:"文章收藏数量"`
  1347. //ChartCountNum int `description:"图表收藏"`
  1348. //IndustryFllowNum int `description:"产业关注数量"`
  1349. //DepartmentFollowNum int `description:"作者关注数量"`
  1350. //KeyWordNum int `description:"关键词搜索次数"`
  1351. //ActivityOnLineNum int `description:"线上活动报名次数"`
  1352. //ActivityOfficeNum int `description:"线下活动报名次数"`
  1353. //ActivityNum int `description:"活动报名次数"`
  1354. //TripNum int `description:"专项产业调研数量"`
  1355. //RoadshowVideoNum int `description:"产业视频播放量"`
  1356. //ActivityVideoNum int `description:"活动视频播放量"`
  1357. //ActivityVoiceNum int `description:"活动音频播放量"`
  1358. //RoadshowNum int `description:"路演播放总数量"`
  1359. //TagNum int `description:"标签点击次数"`
  1360. //YanxuanSpecialNum int `description:"研选专栏阅读数量"`
  1361. //YanxuanSpecialCollectNum int `description:"研选专栏收藏数量"`
  1362. //YanxuanSpecialFollowNum int `description:"研选专栏作者关注数量"`
  1363. //如果这些数据对比不一样,那么就对这条数据进行更新
  1364. //if itemOld != nil && (itemOld.ArticleHistoryNum != v.ArticleHistoryNum || itemOld.ArticleCountNum != v.ArticleCountNum || itemOld.ChartCountNum != v.ChartCountNum || itemOld.IndustryFllowNum != v.IndustryFllowNum || itemOld.DepartmentFollowNum != v.DepartmentFollowNum || itemOld.KeyWordNum != v.KeyWordNum || itemOld.ActivityNum != v.ActivityNum || itemOld.TripNum != v.TripNum || itemOld.RoadshowVideoNum != v.RoadshowVideoNum || itemOld.ActivityVideoNum != v.ActivityVideoNum || itemOld.ActivityVoiceNum != v.ActivityVoiceNum || itemOld.RoadshowNum != v.RoadshowNum || itemOld.TagNum != v.TagNum || itemOld.YanxuanSpecialNum != v.YanxuanSpecialNum || itemOld.YanxuanSpecialCollectNum != v.YanxuanSpecialCollectNum || itemOld.YanxuanSpecialFollowNum != v.YanxuanSpecialFollowNum) {
  1365. if itemOld != nil && (itemOld.ArticleHistoryNum != v.ArticleHistoryNum || itemOld.ArticleCountNum != v.ArticleCountNum || itemOld.ChartCountNum != v.ChartCountNum || itemOld.IndustryFllowNum != v.IndustryFllowNum || itemOld.DepartmentFollowNum != v.DepartmentFollowNum || itemOld.KeyWordNum != v.KeyWordNum || itemOld.ActivityNum != v.ActivityNum || itemOld.TripNum != v.TripNum || itemOld.RoadshowVideoNum != v.RoadshowVideoNum || itemOld.ActivityVideoNum != v.ActivityVideoNum || itemOld.ActivityVoiceNum != v.ActivityVoiceNum || itemOld.RoadshowNum != v.RoadshowNum || itemOld.TagNum != v.TagNum) {
  1366. comapnyInteractionNumItemUpdate = append(comapnyInteractionNumItemUpdate, v)
  1367. }
  1368. } else {
  1369. v.CreateTime = time.Now()
  1370. v.ModifyTime = time.Now()
  1371. comapnyInteractionNumItemAdd = append(comapnyInteractionNumItemAdd, v)
  1372. }
  1373. //对比历史数据如果不一样就进行修改
  1374. if mapInteractionNumOld[v.CompanyId] != mapComapnyInteractionNum[v.CompanyId] || mapInteractionNumSellerOld[v.CompanyId] != mapComapnyInteractionNumSeller[v.CompanyId] {
  1375. itemCompanyInteractionNums := new(models.CompanyInteractionNumReq)
  1376. itemCompanyInteractionNums.CompanyId = k
  1377. itemCompanyInteractionNums.InteractionNum = mapComapnyInteractionNum[v.CompanyId]
  1378. itemCompanyInteractionNums.InteractionNumSeller = mapComapnyInteractionNumSeller[v.CompanyId]
  1379. itemsCompanyInteractionNums = append(itemsCompanyInteractionNums, itemCompanyInteractionNums)
  1380. }
  1381. }
  1382. //for _, v := range comapnyInteractionNumItemUpdate {
  1383. // fmt.Println(v)
  1384. //}
  1385. //return
  1386. //批量插入公司互动详情
  1387. if len(comapnyInteractionNumItemAdd) > 0 {
  1388. _, e = models.AddCygxCompanyInteractionNumList(comapnyInteractionNumItemAdd)
  1389. if e != nil {
  1390. err = errors.New("AddCygxCompanyInteractionNumList, Err: " + e.Error())
  1391. return
  1392. }
  1393. }
  1394. // 批量修改公司互动详情
  1395. if len(comapnyInteractionNumItemUpdate) > 0 {
  1396. e = models.UpdateCygxCompanyInteractionNumMulti(comapnyInteractionNumItemUpdate)
  1397. if e != nil {
  1398. err = errors.New("UpdateCygxCompanyInteractionNumMulti, Err: " + e.Error())
  1399. return
  1400. }
  1401. }
  1402. // 批量修改公司互动总量
  1403. if len(itemsCompanyInteractionNums) > 0 {
  1404. e = models.UpdateCompanyInteractionNumMulti(itemsCompanyInteractionNums)
  1405. if e != nil {
  1406. err = errors.New("UpdateCompanyInteractionNumMulti, Err: " + e.Error())
  1407. return
  1408. }
  1409. }
  1410. //CompanyInteractionNumReq
  1411. fmt.Println("add", len(comapnyInteractionNumItemAdd))
  1412. fmt.Println("edit", len(comapnyInteractionNumItemUpdate))
  1413. fmt.Println("Update", len(itemsCompanyInteractionNums))
  1414. //fmt.Println(mapComapnyInteractionNum)
  1415. return
  1416. }