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