init_10.5.1.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. package services
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "hongze/hongze_cygx/models"
  6. "hongze/hongze_cygx/utils"
  7. "time"
  8. )
  9. //10.5.1版本上线需要更新的数据
  10. //func init1111() {
  11. // var condition string
  12. // var pars []interface{}
  13. // var err error
  14. // fmt.Print()
  15. //
  16. // var topCond string
  17. // var topPars []interface{}
  18. // toplist, err := models.GetTopOneMonthArtReadNumIndustryAll(topCond, topPars)
  19. // if err != nil {
  20. // return
  21. // }
  22. //
  23. // mapIndustryName := make(map[int]string)
  24. // for _, v := range toplist {
  25. // mapIndustryName[v.IndustrialManagementId] = v.IndustryName
  26. // }
  27. // fmt.Println(mapIndustryName)
  28. // //处理上周纪要汇总
  29. // condition = ` AND type = 1 `
  30. // list, err := models.GetCygxIndustryFllowListByCon(condition, pars, 0, 100000)
  31. // if err != nil {
  32. // fmt.Println(err)
  33. // }
  34. // var items []*models.CygxUserLabel
  35. // for _, user := range list {
  36. // item := new(models.CygxUserLabel)
  37. // item.UserId = user.UserId
  38. // item.CompanyId = user.CompanyId
  39. // item.RealName = user.RealName
  40. // item.Mobile = user.Mobile
  41. // item.Email = user.Email
  42. // item.Label = mapIndustryName[user.IndustrialManagementId]
  43. // item.SourceId = user.IndustrialManagementId
  44. // item.Source = 1
  45. // item.IsFollow = 1
  46. // item.CreateTime = time.Now()
  47. // item.ModifyTime = time.Now()
  48. // items = append(items, item)
  49. // if len(items)%5000 == 0 {
  50. // err = models.CygxUserLabelMulti(items)
  51. // fmt.Println(err)
  52. // items = make([]*models.CygxUserLabel, 0)
  53. // }
  54. // }
  55. // if len(items) > 0 {
  56. // err = models.CygxUserLabelMulti(items)
  57. // fmt.Println(err, "555")
  58. // }
  59. //}
  60. func init123() {
  61. var condition string
  62. var pars []interface{}
  63. var err error
  64. fmt.Print()
  65. var topCond string
  66. var topPars []interface{}
  67. toplist, err := models.GetCygxReportMappingCygxByCon(topCond, topPars)
  68. if err != nil {
  69. return
  70. }
  71. mapIndustryName := make(map[int]string)
  72. for _, v := range toplist {
  73. mapIndustryName[v.Id] = v.MatchTypeName
  74. }
  75. fmt.Println(mapIndustryName)
  76. condition = ` `
  77. list, err := models.GetCygxXzsChooseCategoryListByCon(condition, pars, 0, 100000)
  78. if err != nil {
  79. fmt.Println(err)
  80. }
  81. var items []*models.CygxUserLabel
  82. for _, user := range list {
  83. if user.IdCygx == 0 {
  84. continue
  85. }
  86. item := new(models.CygxUserLabel)
  87. item.UserId = user.UserId
  88. item.CompanyId = user.CompanyId
  89. item.RealName = user.RealName
  90. item.Mobile = user.Mobile
  91. item.Email = user.Email
  92. item.Label = mapIndustryName[user.IdCygx]
  93. item.SourceId = user.IdCygx
  94. item.Source = 2
  95. item.IsFollow = 1
  96. item.CreateTime = time.Now()
  97. item.ModifyTime = time.Now()
  98. fmt.Println(item.SourceId)
  99. items = append(items, item)
  100. if len(items)%5000 == 0 {
  101. err = models.CygxUserLabelMulti(items)
  102. fmt.Println(err)
  103. items = make([]*models.CygxUserLabel, 0)
  104. }
  105. }
  106. if len(items) > 0 {
  107. err = models.CygxUserLabelMulti(items)
  108. fmt.Println(err, "555")
  109. }
  110. }
  111. func init5333() {
  112. var condition string
  113. var pars []interface{}
  114. var err error
  115. fmt.Print()
  116. var topCond string
  117. var topPars []interface{}
  118. toplist, err := models.GetTopOneMonthArtReadNumIndustryAll(topCond, topPars)
  119. if err != nil {
  120. return
  121. }
  122. mapIndustryName := make(map[int]string)
  123. for _, v := range toplist {
  124. mapIndustryName[v.IndustrialManagementId] = v.IndustryName
  125. }
  126. fmt.Println(mapIndustryName)
  127. condition = ` AND activity_time > '2022-11-25 00:00:00' AND publish_status = 1 `
  128. listAct, err := models.GetCygxActivityList(condition, pars, 0, 100000)
  129. if err != nil {
  130. fmt.Println(err)
  131. }
  132. var items []*models.CygxUserLabelActivity
  133. for _, v := range listAct {
  134. fmt.Println(v.ActivityTime)
  135. var condition1 string
  136. var pars1 []interface{}
  137. condition1 = ` AND activity_id = ? `
  138. pars1 = append(pars1, v.ActivityId)
  139. total, e := models.GetCygxIndustrialActivityGroupManagementCount(condition1+" AND source = 1 ", pars1)
  140. if e != nil {
  141. fmt.Println(e)
  142. return
  143. }
  144. if total == 0 {
  145. continue
  146. }
  147. industrialList, e := models.GetCygxIndustrialActivityGroupManagementList(condition1+" AND source = 1 ", pars1)
  148. if e != nil {
  149. fmt.Println(e)
  150. return
  151. }
  152. pars = make([]interface{}, 0)
  153. condition = ` AND activity_id = ? AND is_meeting = 1 `
  154. pars = append(pars, v.ActivityId)
  155. signUpList, err := models.GetSignupDetailBySignup(condition, pars)
  156. if err != nil && err.Error() != utils.ErrNoRow() {
  157. return
  158. }
  159. for _, vi := range industrialList {
  160. for _, user := range signUpList {
  161. item := new(models.CygxUserLabelActivity)
  162. item.UserId = user.UserId
  163. item.CompanyId = user.CompanyId
  164. item.RealName = user.RealName
  165. item.Mobile = user.Mobile
  166. item.Email = user.Email
  167. item.ActivityId = v.ActivityId
  168. item.IndustrialManagementId = vi.IndustrialManagementId
  169. item.Label = mapIndustryName[vi.IndustrialManagementId]
  170. item.CreateTime = utils.StrTimeToTime(v.ActivityTime)
  171. item.ModifyTime = time.Now()
  172. items = append(items, item)
  173. if len(items)%5000 == 0 {
  174. _, err = models.AddCygxUserLabelActivityList(items)
  175. fmt.Println(err)
  176. items = make([]*models.CygxUserLabelActivity, 0)
  177. }
  178. }
  179. }
  180. }
  181. fmt.Println(len(items))
  182. if len(items) > 0 {
  183. _, err = models.AddCygxUserLabelActivityList(items)
  184. fmt.Println(err, "555")
  185. }
  186. }
  187. func init5444() {
  188. var condition string
  189. var pars []interface{}
  190. var err error
  191. fmt.Print()
  192. var topCond string
  193. var topPars []interface{}
  194. toplist, err := models.GetTopOneMonthArtReadNumIndustryAll(topCond, topPars)
  195. if err != nil {
  196. return
  197. }
  198. mapIndustryName := make(map[int]string)
  199. for _, v := range toplist {
  200. mapIndustryName[v.IndustrialManagementId] = v.IndustryName
  201. }
  202. fmt.Println(mapIndustryName)
  203. condition = ` AND is_meeting = 1 `
  204. listAct, err := models.GetCygxActivitySpecialmeetingDetailList(condition, pars)
  205. if err != nil {
  206. fmt.Println(err)
  207. }
  208. var items []*models.CygxUserLabelActivitySpecial
  209. for _, user := range listAct {
  210. var condition1 string
  211. var pars1 []interface{}
  212. condition1 = ` AND activity_id = ? `
  213. pars1 = append(pars1, user.ActivityId)
  214. total, e := models.GetCygxIndustrialActivityGroupManagementCount(condition1+" AND source = 2 ", pars1)
  215. if e != nil {
  216. fmt.Println(e)
  217. return
  218. }
  219. if total == 0 {
  220. continue
  221. }
  222. industrialList, e := models.GetCygxIndustrialActivityGroupManagementList(condition1+" AND source = 2 ", pars1)
  223. if e != nil {
  224. fmt.Println(e)
  225. return
  226. }
  227. for _, vi := range industrialList {
  228. item := new(models.CygxUserLabelActivitySpecial)
  229. item.UserId = user.UserId
  230. item.CompanyId = user.CompanyId
  231. item.RealName = user.RealName
  232. item.Mobile = user.Mobile
  233. item.Email = user.Email
  234. item.ActivityId = user.ActivityId
  235. item.IndustrialManagementId = vi.IndustrialManagementId
  236. item.Label = mapIndustryName[vi.IndustrialManagementId]
  237. item.CreateTime = utils.StrTimeToTime(user.CreateTime)
  238. item.ModifyTime = time.Now()
  239. items = append(items, item)
  240. if len(items)%5000 == 0 {
  241. _, err = models.AddCygxUserLabelActivitySpecialList(items)
  242. fmt.Println(err)
  243. items = make([]*models.CygxUserLabelActivitySpecial, 0)
  244. }
  245. }
  246. }
  247. fmt.Println(len(items))
  248. if len(items) > 0 {
  249. _, err = models.AddCygxUserLabelActivitySpecialList(items)
  250. fmt.Println(err, "555")
  251. }
  252. }
  253. func init5555() {
  254. var condition string
  255. var pars []interface{}
  256. var err error
  257. fmt.Print()
  258. var topCond string
  259. var topPars []interface{}
  260. toplist, err := models.GetTopOneMonthArtReadNumIndustryAll(topCond, topPars)
  261. if err != nil {
  262. return
  263. }
  264. mapIndustryName := make(map[int]string)
  265. for _, v := range toplist {
  266. mapIndustryName[v.IndustrialManagementId] = v.IndustryName
  267. }
  268. //fmt.Println(mapIndustryName)
  269. condition = ` AND stop_time > 3 AND create_time > '2022-11-25 00:00:00' GROUP BY article_id `
  270. //condition = ` AND stop_time > 4 AND create_time > '2023-04-25 00:00:00' GROUP BY article_id `
  271. listArtGroup, err := models.GetCygxArticleHistoryRecordNewpvList(condition, pars)
  272. if err != nil {
  273. fmt.Println(err)
  274. }
  275. fmt.Println(len(listArtGroup))
  276. var source int
  277. itemsMap := make(map[int][]*models.CygxUserLabel)
  278. for _, v := range listArtGroup {
  279. fmt.Println(v.ArticleId)
  280. var items []*models.CygxUserLabel
  281. articleId := v.ArticleId
  282. var condition string
  283. var pars []interface{}
  284. condition = ` AND article_id = ? `
  285. pars = append(pars, v.ArticleId)
  286. industrialList, e := models.GetIndustrialArticleGroupManagementList(condition, pars)
  287. if e != nil && e.Error() != utils.ErrNoRow() {
  288. fmt.Println(e)
  289. continue
  290. //return
  291. }
  292. if len(industrialList) == 0 {
  293. //如果没有行产业归类就按照行业报告处理
  294. source = 2
  295. detailArticle, e := models.GetArticleDetailById(articleId)
  296. if e != nil {
  297. fmt.Println(e)
  298. continue
  299. //return
  300. }
  301. labelDetail, e := models.GetdetailByCategoryIdLabel(detailArticle.CategoryId)
  302. if e != nil {
  303. fmt.Println(e)
  304. continue
  305. //return
  306. }
  307. label := labelDetail.MatchTypeName
  308. industrialManagementId := labelDetail.Id
  309. item := new(models.CygxUserLabel)
  310. item.Label = label
  311. item.SourceId = industrialManagementId
  312. item.Source = source
  313. item.Weight = 1
  314. item.CreateTime = time.Now()
  315. item.ModifyTime = time.Now()
  316. items = append(items, item)
  317. } else {
  318. //如果有行产业归类就按照产业报告处理
  319. var topCond string
  320. var topPars []interface{}
  321. var industrialManagementIds []int
  322. for _, v := range industrialList {
  323. industrialManagementIds = append(industrialManagementIds, v.IndustrialManagementId)
  324. }
  325. idsLen := len(industrialManagementIds)
  326. if idsLen > 0 {
  327. topCond = ` AND industrial_management_id IN (` + utils.GetOrmInReplace(idsLen) + `)`
  328. topPars = append(topPars, industrialManagementIds)
  329. } else {
  330. continue
  331. }
  332. industrNamelist, e := models.GetTopOneMonthArtReadNumIndustryAll(topCond, topPars)
  333. if e != nil {
  334. fmt.Println(e)
  335. continue
  336. }
  337. source = 1
  338. for _, v := range industrNamelist {
  339. label := v.IndustryName
  340. industrialManagementId := v.IndustrialManagementId
  341. item := new(models.CygxUserLabel)
  342. item.Label = label
  343. item.SourceId = industrialManagementId
  344. item.Source = source
  345. item.Weight = 1
  346. item.CreateTime = time.Now()
  347. item.ModifyTime = time.Now()
  348. items = append(items, item)
  349. }
  350. //for _, vi := range industrialList {
  351. // for _, user := range signUpList {
  352. // item := new(models.CygxUserLabelActivity)
  353. // item.UserId = user.UserId
  354. // item.CompanyId = user.CompanyId
  355. // item.RealName = user.RealName
  356. // item.Mobile = user.Mobile
  357. // item.Email = user.Email
  358. // item.ActivityId = v.ActivityId
  359. // item.IndustrialManagementId = vi.IndustrialManagementId
  360. // item.Label = mapIndustryName[vi.IndustrialManagementId]
  361. // item.CreateTime = utils.StrTimeToTime(v.ActivityTime)
  362. // item.ModifyTime = time.Now()
  363. // items = append(items, item)
  364. // if len(items)%50 == 0 {
  365. // _, err = models.AddCygxUserLabelActivityList(items)
  366. // fmt.Println(err)
  367. // items = make([]*models.CygxUserLabelActivity, 0)
  368. // }
  369. // }
  370. //}
  371. itemsMap[articleId] = items
  372. }
  373. }
  374. condition = ` AND stop_time > 3 AND create_time > '2022-11-25 00:00:00' `
  375. //condition = ` AND stop_time > 4 AND create_time > '2023-4-25 00:00:00' `
  376. listArt, err := models.GetCygxArticleHistoryRecordNewpvList(condition, pars)
  377. if err != nil {
  378. fmt.Println(err)
  379. }
  380. var items []*models.CygxUserLabelArticle
  381. fmt.Println(len(listArt))
  382. for _, user := range listArt {
  383. if len(itemsMap[user.ArticleId]) > 0 {
  384. for k2, vlsit := range itemsMap {
  385. if k2 != user.ArticleId {
  386. continue
  387. }
  388. for _, vm := range vlsit {
  389. //if user.ArticleId == 8365 {
  390. // fmt.Println("k", k, "_k2:", k2, "_k3:", k3)
  391. // fmt.Println(vm.Label)
  392. //}
  393. item := new(models.CygxUserLabelArticle)
  394. item.UserId = user.UserId
  395. item.ArticleId = user.ArticleId
  396. item.CompanyId = user.CompanyId
  397. //item.RealName = user.R
  398. item.Mobile = user.Mobile
  399. item.Email = user.Email
  400. item.Label = vm.Label
  401. item.SourceId = vm.SourceId
  402. item.Source = vm.Source
  403. item.CreateTime = user.CreateTime
  404. item.ModifyTime = time.Now()
  405. items = append(items, item)
  406. if len(items)%5000 == 0 {
  407. _, err = models.AddCygxUserLabelArticleList(items)
  408. fmt.Println(err)
  409. items = make([]*models.CygxUserLabelArticle, 0)
  410. }
  411. }
  412. }
  413. }
  414. }
  415. //for k, vlsit := range itemsMap[8365] {
  416. // fmt.Println(k)
  417. // fmt.Println(vlsit)
  418. // //for _, vm := range vlsit {
  419. // // fmt.Println(vm)
  420. // //}
  421. //}
  422. fmt.Println(len(items))
  423. fmt.Println(len(itemsMap))
  424. fmt.Println((itemsMap))
  425. fmt.Println(len(items))
  426. if len(items) > 0 {
  427. _, err = models.AddCygxUserLabelArticleList(items)
  428. fmt.Println(err, "555")
  429. }
  430. }
  431. func init10_12() {
  432. var condition string
  433. var pars []interface{}
  434. condition = " AND active_state = 1 "
  435. listAct, err := models.GetCygxActivityList(condition, pars, 0, 100000)
  436. fmt.Println(err)
  437. for _, v := range listAct {
  438. resultTime := utils.StrTimeToTime(v.ActivityTime) //时间字符串格式转时间格式
  439. cancelDeadline := resultTime.Add(-time.Hour * 1).Format(utils.FormatDateTime) //默认一小时
  440. o := orm.NewOrm()
  441. sql := `UPDATE cygx_activity SET cancel_deadline = ? WHERE activity_id = ? `
  442. _, err = o.Raw(sql, cancelDeadline, v.ActivityId).Exec()
  443. fmt.Println(err)
  444. }
  445. }