financial_analyst.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. Position string `description:"职位"`
  19. InvestmentCertificate string `description:"投资咨询资格证"`
  20. ProfessionalCertificate string `description:"从业资格证"`
  21. Introduction string `description:"介绍"`
  22. Status AnalystStatus `description:"状态"`
  23. Deleted bool `description:"是否删除"`
  24. CreatedTime time.Time `description:"创建时间"`
  25. UpdatedTime time.Time `description:"更新时间"`
  26. }
  27. func (m *CrmFinancialAnalyst) TableName() string {
  28. return "crm_financial_analysts"
  29. }
  30. type AnalystView struct {
  31. Id int `json:"Id"`
  32. Name string `json:"Name"`
  33. HeadImgURL string `json:"HeadImgURL"`
  34. Position string `json:"Position"`
  35. InvestmentCertificate string `json:"InvestmentCertificate"`
  36. ProfessionalCertificate string `json:"ProfessionalCertificate"`
  37. Introduction string `json:"Introduction"`
  38. CreatedTime string `json:"CreatedTime"`
  39. }
  40. func GetAnalystByName(name string) (analyst CrmFinancialAnalyst, err error) {
  41. o := orm.NewOrm()
  42. sql := `SELECT * FROM crm_financial_analysts where name =?`
  43. err = o.Raw(sql, name).QueryRow(&analyst)
  44. return
  45. }
  46. func (a *CrmFinancialAnalyst) ToView() *AnalystView {
  47. return &AnalystView{
  48. Id: a.Id,
  49. Name: a.Name,
  50. HeadImgURL: a.HeadImgUrl,
  51. Position: a.Position,
  52. InvestmentCertificate: a.InvestmentCertificate,
  53. ProfessionalCertificate: a.ProfessionalCertificate,
  54. Introduction: a.Introduction,
  55. CreatedTime: a.CreatedTime.Format(time.DateTime),
  56. }
  57. }
  58. func GetAnalystCount(condition string) (count int, err error) {
  59. o := orm.NewOrm()
  60. sql := `SELECT COUNT(*) AS count FROM crm_financial_analysts WHERE 1=1 `
  61. if condition != "" {
  62. sql += condition
  63. }
  64. err = o.Raw(sql).QueryRow(&count)
  65. return
  66. }
  67. func GetAnalystList(condition string, startSize int, pageSize int) (item []*CrmFinancialAnalyst, err error) {
  68. o := orm.NewOrm()
  69. sql := `SELECT * FROM crm_financial_analysts WHERE 1=1`
  70. if condition != "" {
  71. sql += condition
  72. }
  73. sql = sql + ` ORDER BY created_time desc LIMIT ?,?`
  74. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&item)
  75. return
  76. }
  77. // GetAnalystById
  78. // @Description: 根据ID获取信息
  79. // @author: Roc
  80. // @datetime 2024-08-09 18:24:58
  81. // @param id int
  82. // @return analyst CrmFinancialAnalyst
  83. // @return err error
  84. func GetAnalystById(id int) (analyst CrmFinancialAnalyst, err error) {
  85. o := orm.NewOrm()
  86. sql := `SELECT * FROM crm_financial_analysts where id =?`
  87. err = o.Raw(sql, id).QueryRow(&analyst)
  88. return
  89. }
  90. func (m *CrmFinancialAnalyst) Update(cols []string) (err error) {
  91. o := orm.NewOrm()
  92. _, err = o.Update(m, cols...)
  93. return
  94. }