package models import ( "github.com/beego/beego/v2/client/orm" "time" ) type AnalystStatus string const ( AnalystStatusEnabled AnalystStatus = "enabled" AnalystStatusDisabled AnalystStatus = "disabled" columns = "id,eta_id,name,head_img_url,introduction" ) type CrmFinancialAnalyst struct { Id int `description:"主键"` ETAId int `description:"eta_id"` HTId int `description:"ht_id"` Name string `description:"姓名"` HeadImgUrl string `description:"头像"` Position string `description:"职位"` InvestmentCertificate string `description:"投资咨询资格证"` ProfessionalCertificate string `description:"从业资格证"` Introduction string `description:"介绍"` Status AnalystStatus `description:"状态"` Deleted bool `description:"是否删除"` CreatedTime time.Time `description:"创建时间"` UpdatedTime time.Time `description:"更新时间"` } func (m *CrmFinancialAnalyst) TableName() string { return "crm_financial_analysts" } type AnalystView struct { Id int `json:"Id"` Name string `json:"Name"` HeadImgURL string `json:"HeadImgURL"` Position string `json:"Position"` InvestmentCertificate string `json:"InvestmentCertificate"` ProfessionalCertificate string `json:"ProfessionalCertificate"` Introduction string `json:"Introduction"` CreatedTime string `json:"CreatedTime"` } func GetAnalystByName(name string) (analyst CrmFinancialAnalyst, err error) { o := orm.NewOrm() sql := `SELECT * FROM crm_financial_analysts where name =?` err = o.Raw(sql, name).QueryRow(&analyst) return } func (a *CrmFinancialAnalyst) ToView() *AnalystView { return &AnalystView{ Id: a.Id, Name: a.Name, HeadImgURL: a.HeadImgUrl, Position: a.Position, InvestmentCertificate: a.InvestmentCertificate, ProfessionalCertificate: a.ProfessionalCertificate, Introduction: a.Introduction, CreatedTime: a.CreatedTime.Format(time.DateTime), } } func GetAnalystCount(condition string) (count int, err error) { o := orm.NewOrm() sql := `SELECT COUNT(*) AS count FROM crm_financial_analysts WHERE 1=1 ` if condition != "" { sql += condition } err = o.Raw(sql).QueryRow(&count) return } func GetAnalystList(condition string, startSize int, pageSize int) (item []*CrmFinancialAnalyst, err error) { o := orm.NewOrm() sql := `SELECT * FROM crm_financial_analysts WHERE 1=1` if condition != "" { sql += condition } sql = sql + ` ORDER BY created_time desc LIMIT ?,?` _, err = o.Raw(sql, startSize, pageSize).QueryRows(&item) return } // GetAnalystById // @Description: 根据ID获取信息 // @author: Roc // @datetime 2024-08-09 18:24:58 // @param id int // @return analyst CrmFinancialAnalyst // @return err error func GetAnalystById(id int) (analyst CrmFinancialAnalyst, err error) { o := orm.NewOrm() sql := `SELECT * FROM crm_financial_analysts where id =?` err = o.Raw(sql, id).QueryRow(&analyst) return } func (m *CrmFinancialAnalyst) Update(cols []string) (err error) { o := orm.NewOrm() _, err = o.Update(m, cols...) return }