article_history_record_all.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CygxArticleHistoryRecordAll struct {
  7. Id int `orm:"column(id);pk"`
  8. ArticleId int
  9. UserId int
  10. CreateTime string
  11. ModifyTime time.Time
  12. Mobile string `description:"手机号"`
  13. Email string `description:"邮箱"`
  14. CompanyId int `description:"公司id"`
  15. CompanyName string `description:"公司名称"`
  16. StopTime int `description:"停留时间"`
  17. OutType int `description:"退出方式,1正常退出,2强制关闭"`
  18. Source string `description:"来源,MOBILE:手机端,PC:电脑端"`
  19. RealName string `description:"用户实际名称"`
  20. CreateDateApi time.Time `description:"同步创建时间"`
  21. CelueHistoryId int `description:"策略平台记录的ID"`
  22. Platfor int `description:"PV阅读记录来源,1:查研观向,2:策略平台"`
  23. IsDel int `description:"是否删除"`
  24. RegisterPlatform int `description:"来源"`
  25. CompanyStatus string `description:"公司状态"`
  26. SellerName string `description:"所属销售"`
  27. }
  28. // 获取数量
  29. func GetCygxArticleHistoryRecordAllCountBycondition(condition string, pars []interface{}) (count int, err error) {
  30. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_article_history_record_all as art WHERE 1= 1 `
  31. if condition != "" {
  32. sqlCount += condition
  33. }
  34. o := orm.NewOrm()
  35. err = o.Raw(sqlCount, pars).QueryRow(&count)
  36. return
  37. }
  38. // 列表
  39. func GetCygxArticleHistoryRecordAllList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxArticleHistoryRecordAll, err error) {
  40. o := orm.NewOrm()
  41. sql := `SELECT * FROM cygx_article_history_record_all as art WHERE 1= 1 `
  42. if condition != "" {
  43. sql += condition
  44. }
  45. sql += ` LIMIT ?,? `
  46. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  47. return
  48. }
  49. type CygxArticleHistoryRecordAllResp struct {
  50. Id int `orm:"column(id);pk"`
  51. ArticleId int
  52. UserId int
  53. CreateTime string
  54. ModifyTime time.Time
  55. Mobile string `description:"手机号"`
  56. Email string `description:"邮箱"`
  57. CompanyId int `description:"公司id"`
  58. CompanyName string `description:"公司名称"`
  59. StopTime int `description:"停留时间"`
  60. OutType int `description:"退出方式,1正常退出,2强制关闭"`
  61. Source string `description:"来源,MOBILE:手机端,PC:电脑端"`
  62. RealName string `description:"用户实际名称"`
  63. CreateDateApi time.Time `description:"同步创建时间"`
  64. CelueHistoryId int `description:"策略平台记录的ID"`
  65. Platfor int `description:"PV阅读记录来源,1:查研观向,2:策略平台"`
  66. IsDel int `description:"是否删除"`
  67. RegisterPlatform int `description:"来源"`
  68. Title string `description:"标题"`
  69. CategoryName string `description:"一级分类"`
  70. }
  71. // 列表
  72. func GetCygxArticleHistoryRecordAllListNoLimit(condition string, pars []interface{}) (items []*CygxArticleHistoryRecordAllResp, err error) {
  73. o := orm.NewOrm()
  74. sql := `SELECT art.* ,a.title,a.category_name FROM cygx_article_history_record_all as art INNER JOIN cygx_article AS a ON a.article_id = art.article_id WHERE 1= 1 `
  75. if condition != "" {
  76. sql += condition
  77. }
  78. _, err = o.Raw(sql, pars).QueryRows(&items)
  79. return
  80. }
  81. // AddCygxArticleHistoryRecordAllMulti 批量添加
  82. func AddCygxArticleHistoryRecordAllMulti(itemsCelue []*CygxCelueArticleHistoryRecord, items []*CygxArticleHistoryRecordAll) (err error) {
  83. o, err := orm.NewOrm().Begin()
  84. if err != nil {
  85. return
  86. }
  87. defer func() {
  88. if err == nil {
  89. o.Commit()
  90. } else {
  91. o.Rollback()
  92. }
  93. }()
  94. //批量插入新的关联数据
  95. if len(itemsCelue) > 0 {
  96. //批量添加流水信息
  97. _, err = o.InsertMulti(len(itemsCelue), itemsCelue)
  98. }
  99. //批量插入新的关联数据
  100. if len(items) > 0 {
  101. //批量添加流水信息
  102. _, err = o.InsertMulti(len(items), items)
  103. }
  104. return
  105. }