celue_article_history_record.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package models
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "strconv"
  6. "time"
  7. )
  8. type CeLueArticleResultApi struct {
  9. Data []CeLueArticleResultApidate `json:"data"`
  10. Code int `json:"code"`
  11. Msg string `json:"msg"`
  12. Pagination *Pagination `json:"pagination"`
  13. }
  14. type CeLueArticleResultApidate struct {
  15. CelueHistoryId int `json:"id"`
  16. Mobile string `json:"phone_number"`
  17. ArticleId string `json:"entity_info"`
  18. CreateDate string `json:"access_time"`
  19. CrmUser *CrmUser `json:"user"`
  20. CompanyName *CrmUser `json:"crm_company"`
  21. }
  22. type CrmUser struct {
  23. RealName string `json:"name"`
  24. }
  25. type CrmCompany struct {
  26. CompanyName string `json:"name"`
  27. }
  28. func GetCeLueArticleCountById(celueHistoryId int) (count int, err error) {
  29. o := orm.NewOrm()
  30. sql := `SELECT COUNT(1) AS count FROM cygx_celue_article_history_record WHERE celue_history_id = ? `
  31. err = o.Raw(sql, celueHistoryId).QueryRow(&count)
  32. return
  33. }
  34. type CygxCelueArticleHistoryRecord struct {
  35. Id int `orm:"column(id);pk"`
  36. ArticleId string `description:"文章ID"`
  37. CelueHistoryId int `description:"策略平台记录的ID"`
  38. CreateTime string `description:"本地创建时间"`
  39. CreateDateApi time.Time `description:"图表创建时间"`
  40. Mobile string `description:"手机号"`
  41. CompanyName string `description:"公司名称"`
  42. RealName string `description:"用户姓名"`
  43. }
  44. //新增
  45. func AddCeLueArticle(item *CygxCelueArticleHistoryRecord, mapMobileArticleId map[string]int) (lastId int64, err error) {
  46. o, err := orm.NewOrm().Begin()
  47. if err != nil {
  48. return
  49. }
  50. defer func() {
  51. if err == nil {
  52. o.Commit()
  53. } else {
  54. o.Rollback()
  55. }
  56. }()
  57. lastId, err = o.Insert(item)
  58. //写入记录到总的统计表
  59. record := new(CygxArticleHistoryRecordAll)
  60. articleId, _ := strconv.Atoi(item.ArticleId)
  61. record.ArticleId = articleId
  62. record.CelueHistoryId = item.CelueHistoryId
  63. record.CreateTime = item.CreateTime
  64. record.ModifyTime = time.Now()
  65. record.CreateDateApi = time.Now()
  66. record.Mobile = item.Mobile
  67. record.CompanyName = item.CompanyName
  68. record.RealName = item.RealName
  69. record.Platfor = 2
  70. record.Source = "CELUE"
  71. if mapMobileArticleId[fmt.Sprint(item.Mobile, "_", item.ArticleId)] == articleId {
  72. record.IsDel = 1
  73. }
  74. lastId, err = o.Insert(record)
  75. return
  76. }