financial_analyst.go 2.5 KB

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