12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- package financial_analyst
- import (
- "errors"
- logger "eta/eta_mini_ht_api/common/component/log"
- "eta/eta_mini_ht_api/models"
- "gorm.io/gorm"
- "gorm.io/gorm/clause"
- "time"
- )
- type AnalystStatus string
- const (
- AnalystStatusEnabled AnalystStatus = "enabled"
- AnalystStatusDisabled AnalystStatus = "disabled"
- columns = "id,eta_id,name,head_img_url,head_origin_img_url,introduction,position,investment_certificate,professional_certificate"
- )
- type CrmFinancialAnalyst struct {
- Id int `gorm:"primaryKey;autoIncrement;column:id;comment:主键"`
- ETAId int `gorm:"column:eta_id"`
- HTId int `gorm:"column:ht_id"`
- Name string `gorm:"column:name"`
- HeadImgURL string `gorm:"column:head_img_url"`
- HeadOriginImgUrl string `gorm:"column:head_origin_img_url"`
- Position string `gorm:"column:position"`
- InvestmentCertificate string `gorm:"column:investment_certificate"`
- ProfessionalCertificate string `gorm:"column:professional_certificate"`
- Introduction string `gorm:"column:introduction"`
- Status AnalystStatus `gorm:"column:status"`
- Deleted bool `gorm:"column:deleted"`
- CreatedTime time.Time `gorm:"column:created_time;type:timestamps;comment:创建时间"`
- UpdatedTime time.Time `gorm:"column:updated_time;type:timestamps;comment:更新时间"`
- }
- func BatchInsertOrUpdate(list []CrmFinancialAnalyst) (err error) {
- db := models.Main()
- OnConflictFunc := clause.OnConflict{
- Columns: []clause.Column{{Name: "eta_id"}},
- DoUpdates: clause.AssignmentColumns([]string{"name", "status", "deleted"}),
- }
- // 执行批量插入或更新操作
- err = db.Clauses(OnConflictFunc).Create(&list).Error
- return
- }
- func (fa *CrmFinancialAnalyst) BeforeCreate(db *gorm.DB) (err error) {
- fa.CreatedTime = time.Now()
- return
- }
- func GetAnalystById(id int) (analyst CrmFinancialAnalyst, err error) {
- db := models.Main()
- err = db.Select(columns).Where("id = ?", id).First(&analyst).Error
- return
- }
- func GetAnalystByName(name string) (analyst CrmFinancialAnalyst, err error) {
- db := models.Main()
- err = db.Select(columns).Where("name = ?", name).First(&analyst).Error
- return
- }
- func GetCount() (total int64, latestId int64) {
- db := models.Main()
- err := db.Model(&CrmFinancialAnalyst{}).Select("count(*) count").Where("deleted = ? and investment_certificate !=''", false).Scan(&total).Error
- if err != nil {
- logger.Error("查询研究员列表失败,%v", err)
- return 0, 0
- }
- err = db.Model(&CrmFinancialAnalyst{}).Select("MAX(id) id").Where("deleted = ? and investment_certificate !=''", false).Scan(&latestId).Error
- if err != nil {
- logger.Error("查询研究员列表失败,%v", err)
- return 0, 0
- }
- return
- }
- func GetAnalystList(latestId int64, offset int, limit int) (analysts []CrmFinancialAnalyst, err error) {
- if latestId < 0 {
- err = errors.New("非法的id参数")
- logger.Error("非法的id参数:%d", latestId)
- return
- }
- if limit <= 0 {
- err = errors.New("非法的limit参数")
- logger.Error("非法的limit参数:%d", limit)
- }
- db := models.Main()
- err = db.Select(columns).Where(" id<= ? ", latestId).Where("deleted = ? and investment_certificate !=''", false).Order("created_time desc").Offset(offset).Limit(limit).Find(&analysts).Error
- return
- }
|