financial_analyst.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type AnalystStatus string
  7. const (
  8. AnalystStatusEnabled AnalystStatus = "enabled"
  9. AnalystStatusDisabled AnalystStatus = "disabled"
  10. columns = "id,eta_id,name,head_img_url,introduction"
  11. )
  12. type CrmFinancialAnalyst struct {
  13. Id int `description:"主键"`
  14. ETAId int `description:"eta_id"`
  15. HTId int `description:"ht_id"`
  16. Name string `description:"姓名"`
  17. HeadImgUrl string `description:"头像"`
  18. HeadOriginImgUrl string `description:"原始头像"`
  19. Position string `description:"职位"`
  20. InvestmentCertificate string `description:"投资咨询资格证"`
  21. ProfessionalCertificate string `description:"从业资格证"`
  22. Introduction string `description:"介绍"`
  23. Status AnalystStatus `description:"状态"`
  24. Deleted bool `description:"是否删除"`
  25. CreatedTime time.Time `description:"创建时间"`
  26. UpdatedTime time.Time `description:"更新时间"`
  27. }
  28. func (m *CrmFinancialAnalyst) TableName() string {
  29. return "crm_financial_analysts"
  30. }
  31. type AnalystView struct {
  32. Id int `json:"Id"`
  33. Name string `json:"Name"`
  34. HeadImgURL string `json:"HeadImgURL"`
  35. HeadOriginImgUrl string `json:"HeadOriginImgUrl"`
  36. Position string `json:"Position"`
  37. InvestmentCertificate string `json:"InvestmentCertificate"`
  38. ProfessionalCertificate string `json:"ProfessionalCertificate"`
  39. Introduction string `json:"Introduction"`
  40. CreatedTime string `json:"CreatedTime"`
  41. }
  42. func GetAnalystByName(name string) (analyst CrmFinancialAnalyst, err error) {
  43. o := orm.NewOrm()
  44. sql := `SELECT * FROM crm_financial_analysts where name =?`
  45. err = o.Raw(sql, name).QueryRow(&analyst)
  46. return
  47. }
  48. func (a *CrmFinancialAnalyst) ToView() *AnalystView {
  49. return &AnalystView{
  50. Id: a.Id,
  51. Name: a.Name,
  52. HeadImgURL: a.HeadImgUrl,
  53. HeadOriginImgUrl: a.HeadOriginImgUrl,
  54. Position: a.Position,
  55. InvestmentCertificate: a.InvestmentCertificate,
  56. ProfessionalCertificate: a.ProfessionalCertificate,
  57. Introduction: a.Introduction,
  58. CreatedTime: a.CreatedTime.Format(time.DateTime),
  59. }
  60. }
  61. func GetAnalystCount(condition string) (count int, err error) {
  62. o := orm.NewOrm()
  63. sql := `SELECT COUNT(*) AS count FROM crm_financial_analysts WHERE 1=1 `
  64. if condition != "" {
  65. sql += condition
  66. }
  67. err = o.Raw(sql).QueryRow(&count)
  68. return
  69. }
  70. func GetAnalystList(condition string, startSize int, pageSize int) (item []*CrmFinancialAnalyst, err error) {
  71. o := orm.NewOrm()
  72. sql := `SELECT * FROM crm_financial_analysts WHERE 1=1`
  73. if condition != "" {
  74. sql += condition
  75. }
  76. sql = sql + ` ORDER BY created_time desc LIMIT ?,?`
  77. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&item)
  78. return
  79. }
  80. // GetAnalystById
  81. // @Description: 根据ID获取信息
  82. // @author: Roc
  83. // @datetime 2024-08-09 18:24:58
  84. // @param id int
  85. // @return analyst CrmFinancialAnalyst
  86. // @return err error
  87. func GetAnalystById(id int) (analyst CrmFinancialAnalyst, err error) {
  88. o := orm.NewOrm()
  89. sql := `SELECT * FROM crm_financial_analysts where id =?`
  90. err = o.Raw(sql, id).QueryRow(&analyst)
  91. return
  92. }
  93. func (m *CrmFinancialAnalyst) Update(cols []string) (err error) {
  94. o := orm.NewOrm()
  95. _, err = o.Update(m, cols...)
  96. return
  97. }