123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- package models
- import (
- "eta_gn/eta_report/global"
- "fmt"
- "strings"
- "time"
- )
- type Classify struct {
- Id int `gorm:"column:id;primaryKey" json:"id"` //`orm:"column(id);pk" gorm:"primaryKey" `
- ClassifyName string `gorm:"column:classify_name" json:"classify_name"` //`description:"分类名称"`
- Sort int `gorm:"column:sort" json:"sort"` //`json:"-"`
- ParentId int `gorm:"column:parent_id" json:"parent_id"` //`description:"父级分类id"`
- CreateTime time.Time `gorm:"column:create_time" json:"create_time"` //`description:"创建时间"`
- ModifyTime time.Time `gorm:"column:modify_time" json:"modify_time"` //`description:"修改时间"`
- Abstract string `gorm:"column:abstract" json:"abstract"` //`description:"栏目简介"`
- Descript string `gorm:"column:descript" json:"descript"` //`description:"分享描述"`
- ReportAuthor string `gorm:"column:report_author" json:"report_author"` //`description:"栏目作者"`
- AuthorDescript string `gorm:"column:author_descript" json:"author_descript"` //`description:"作者简介"`
- ColumnImgUrl string `gorm:"column:column_img_url" json:"column_img_url"` //`description:"栏目配图"`
- HeadImgUrl string `gorm:"column:head_img_url" json:"head_img_url"` //`description:"头部banner"`
- AvatarImgUrl string `gorm:"column:avatar_img_url" json:"avatar_img_url"` //`description:"头像"`
- ReportImgUrl string `gorm:"column:report_img_url" json:"report_img_url"` //`description:"报告配图"`
- HomeImgUrl string `gorm:"column:home_img_url" json:"home_img_url"` //`description:"首页配图"`
- ClassifyLabel string `gorm:"column:classify_label" json:"classify_label"` //`description:"分类标签"`
- ShowType int `gorm:"column:show_type" json:"show_type"` //`description:"展示类型:1-列表 2-专栏"`
- HasTeleconference int `gorm:"column:has_teleconference" json:"has_teleconference"` //`description:"是否有电话会:0-否 1-是"`
- VipTitle string `gorm:"column:vip_title" json:"vip_title"` //`description:"研究员头衔"`
- IsShow int `gorm:"column:is_show" json:"is_show"` //`description:"是否在小程序显示:1-显示 0-隐藏"`
- YbFiccSort int `gorm:"column:yb_ficc_sort" json:"yb_ficc_sort"` //`description:"小程序FICC页排序"`
- YbFiccIcon string `gorm:"column:yb_ficc_icon" json:"yb_ficc_icon"` // `description:"小程序FICC页icon"`
- YbFiccPcIcon string `gorm:"column:yb_ficc_pc_icon" json:"yb_ficc_pc_icon"` //`description:"小程序PC端FICC页背景图"`
- YbIconUrl string `gorm:"column:yb_icon_url" json:"yb_icon_url"` //`description:"小程序已购页icon"`
- YbBgUrl string `gorm:"column:yb_bg_url" json:"yb_bg_url"` //`description:"小程序已购详情背景图"`
- YbListImg string `gorm:"column:yb_list_img" json:"yb_list_img"` //`description:"小程序研报列表封面图"`
- YbShareBgImg string `gorm:"column:yb_share_bg_img" json:"yb_share_bg_img"` //`description:"小程序研报详情分享背景图"`
- YbRightBanner string `gorm:"column:yb_right_banner" json:"yb_right_banner"` //`description:"Pc端详情页,右侧,报告合集背景图"`
- RelateTel int `gorm:"column:relate_tel" json:"relate_tel"` //`description:"是否在电话会中可选: 0-否; 1-是"`
- RelateVideo int `gorm:"column:relate_video" json:"relate_video"` //`description:"是否在路演视频中可选: 0-否; 1-是"`
- IsMassSend int `gorm:"column:is_mass_send" json:"is_mass_send"` //`description:"1:群发,0:非群发"`
- Enabled int `gorm:"column:enabled" json:"enabled"` //`description:"是否可用,1可用,0禁用"`
- Level int `gorm:"column:level" json:"level"` //`description:"层级"`
- HasChild int `gorm:"column:has_child" json:"has_child"` //`description:"是否有子级别,0:下面没有子分类,1:下面有子分类;默认:0"`
- ReportDetailShowType int `gorm:"column:report_detail_show_type" json:"report_detail_show_type"` //`description:"报告详情的展示类型:1-拼接;2:目录"`
- ClassifyType int `gorm:"column:classify_type" json:"classify_type"` //`description:"报告详情的展示类型:1-拼接;2:目录"`
- IsRemind int `gorm:"column:is_remind" json:"is_remind"` //`description:"报告详情的展示类型:1-拼接;2:目录"`
- RemindTime string `gorm:"column:remind_time" json:"remind_time"` //`description:"报告详情的展示类型:1-拼接;2:目录"`
- ReportNum int `gorm:"column:report_num" json:"report_num"` //`description:"分类下的报告数"`
- LevelPath string `gorm:"column:level_path" json:"level_path"` //`description:"分类的层级路径,英文逗号分隔"`
- }
- func (m *Classify) TableName() string {
- return "classify"
- }
- func (m *Classify) GetItemById(id int) (item *Classify, err error) {
- sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), "id")
- err = global.DEFAULT_DmSQL.Raw(sql, id).First(&item).Error
- return
- }
- func (m *Classify) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*Classify, err error) {
- fields := strings.Join(fieldArr, ",")
- if len(fieldArr) == 0 {
- fields = `*`
- }
- order := `ORDER BY create_time DESC`
- if orderRule != "" {
- order = ` ORDER BY ` + orderRule
- }
- sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
- err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error
- return
- }
- type ClassifyTreeItem struct {
- ClassifyId int `description:"分类ID"`
- ClassifyName string `description:"分类名称"`
- ParentId int `description:"父级ID"`
- Sort int `description:"排序"`
- Level int `description:"层级"`
- ClassifyType int `description:"分类类型:1-研报;2-PPT"`
- HasChild int `json:"-" description:"是否有子级别,0:下面没有子分类,1:下面有子分类;默认:0"` //`description:"是否有子级别,0:下面没有子分类,1:下面有子分类;默认:0"`
- Children []*ClassifyTreeItem `description:"子目录"`
- }
- func (m *Classify) Format2TreeItem(origin *Classify) (item *ClassifyTreeItem) {
- if origin == nil {
- return
- }
- item = new(ClassifyTreeItem)
- item.ClassifyId = origin.Id
- item.ClassifyName = origin.ClassifyName
- item.ParentId = origin.ParentId
- item.Sort = origin.Sort
- item.Level = origin.Level
- item.ClassifyType = origin.ClassifyType
- item.Children = make([]*ClassifyTreeItem, 0)
- return
- }
- func GetClassifyById(classifyId int) (item *Classify, err error) {
- sql := `SELECT * FROM classify WHERE id=? `
- err = global.DEFAULT_DmSQL.Raw(sql, classifyId).First(&item).Error
- return
- }
- // UpdateClassify 更新分类
- func (classifyInfo *Classify) UpdateClassify(cols []string) (err error) {
- err = global.DEFAULT_DmSQL.Select(cols).Updates(classifyInfo).Error
- return
- }
|