financial_analyst.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. Status AnalystStatus `description:"状态"`
  42. }
  43. func GetAnalystByName(name string) (analyst CrmFinancialAnalyst, err error) {
  44. o := orm.NewOrm()
  45. sql := `SELECT * FROM crm_financial_analysts where name =?`
  46. err = o.Raw(sql, name).QueryRow(&analyst)
  47. return
  48. }
  49. func (a *CrmFinancialAnalyst) ToView() *AnalystView {
  50. return &AnalystView{
  51. Id: a.Id,
  52. Name: a.Name,
  53. HeadImgURL: a.HeadImgUrl,
  54. HeadOriginImgUrl: a.HeadOriginImgUrl,
  55. Position: a.Position,
  56. InvestmentCertificate: a.InvestmentCertificate,
  57. ProfessionalCertificate: a.ProfessionalCertificate,
  58. Introduction: a.Introduction,
  59. CreatedTime: a.CreatedTime.Format(time.DateTime),
  60. }
  61. }
  62. func GetAnalystCount(condition string) (count int, err error) {
  63. o := orm.NewOrm()
  64. sql := `SELECT COUNT(*) AS count FROM crm_financial_analysts WHERE 1=1 `
  65. if condition != "" {
  66. sql += condition
  67. }
  68. err = o.Raw(sql).QueryRow(&count)
  69. return
  70. }
  71. func GetAnalystList(condition string, startSize int, pageSize int) (item []*CrmFinancialAnalyst, err error) {
  72. o := orm.NewOrm()
  73. sql := `SELECT * FROM crm_financial_analysts WHERE 1=1`
  74. if condition != "" {
  75. sql += condition
  76. }
  77. sql = sql + ` ORDER BY created_time desc LIMIT ?,?`
  78. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&item)
  79. return
  80. }
  81. // GetAnalystById
  82. // @Description: 根据ID获取信息
  83. // @author: Roc
  84. // @datetime 2024-08-09 18:24:58
  85. // @param id int
  86. // @return analyst CrmFinancialAnalyst
  87. // @return err error
  88. func GetAnalystById(id int) (analyst CrmFinancialAnalyst, err error) {
  89. o := orm.NewOrm()
  90. sql := `SELECT * FROM crm_financial_analysts where id =?`
  91. err = o.Raw(sql, id).QueryRow(&analyst)
  92. return
  93. }
  94. func (m *CrmFinancialAnalyst) Update(cols []string) (err error) {
  95. o := orm.NewOrm()
  96. _, err = o.Update(m, cols...)
  97. return
  98. }