package models import ( "eta_gn/eta_api/global" "eta_gn/eta_api/utils" "fmt" "github.com/rdlucklib/rdluck_tools/paging" "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-PPT"` IsRemind int `gorm:"column:is_remind" json:"is_remind"` //`description:"是否开启提醒:0-关闭;1-开启"` RemindTime string `gorm:"column:remind_time" json:"remind_time"` //`description:"提醒时间:可选00:00-23:59"` ReportNum int `gorm:"column:report_num" json:"report_num"` //`description:"分类下的报告数"` LevelPath string `gorm:"column:level_path" json:"level_path"` //`description:"分类的层级路径,英文逗号分隔"` } type ClassifyAddReq struct { ClassifyName string `description:"分类名称"` ParentId int `description:"父级分类id,没有父级分类传0"` ChartPermissionIdList []int `description:"权限id数组"` ClassifyType int `description:"分类类型:1-研报;2-PPT"` IsRemind int `description:"是否开启提醒:0-关闭;1-开启"` RemindTime string `description:"提醒时间:可选00:00-23:59"` } func GetClassifyByName(classifyName string, parentId int) (item *Classify, err error) { sql := `SELECT * FROM classify WHERE classify_name=? AND parent_id=? ` err = global.DmSQL["rddp"].Raw(sql, classifyName, parentId).First(&item).Error return } func GetClassifyById(classifyId int) (item *Classify, err error) { sql := `SELECT * FROM classify WHERE id=? ` err = global.DmSQL["rddp"].Raw(sql, classifyId).First(&item).Error return } // 添加分类 func AddClassify(item *Classify) (err error) { err = global.DmSQL["rddp"].Create(item).Error return } func GetReportCountByClassifyId(classifyId int) (count int, err error) { sql := `SELECT COUNT(1) as num FROM report WHERE classify_id_second=? ` err = global.DmSQL["rddp"].Raw(sql, classifyId).First(&count).Error return } func GetClassifySubCountByClassifyId(classifyId int) (count int, err error) { sql := `SELECT COUNT(1) as num FROM classify AS a INNER JOIN report AS b ON a.id=b.classify_id_second WHERE a.parent_id=? ` err = global.DmSQL["rddp"].Raw(sql, classifyId).First(&count).Error return } func GetClassifySubCountByParentId(classifyId int) (count int, err error) { sqlCount := ` SELECT COUNT(1) as num FROM classify AS a WHERE a.parent_id=? ` err = global.DmSQL["rddp"].Raw(sqlCount, classifyId).Scan(&count).Error return } // DeleteClassify 删除分类 func DeleteClassify(classifyIds []int) (err error) { if len(classifyIds) == 0 { return } sql := fmt.Sprintf(`DELETE FROM classify WHERE id IN (%s)`, utils.GetOrmInReplace(len(classifyIds))) err = global.DmSQL["rddp"].Exec(sql, classifyIds).Error if err != nil { return } deleteImgSql := fmt.Sprintf(`DELETE FROM banner WHERE classify_id IN (%s)`, utils.GetOrmInReplace(len(classifyIds))) err = global.DmSQL["rddp"].Exec(deleteImgSql, classifyIds).Error return } // 根据id获取分类详情 func FindByIdClassify(classifyId int) (item *Classify, err error) { sql := `SELECT * FROM classify WHERE id=? ` err = global.DmSQL["rddp"].Raw(sql, classifyId).First(&item).Error return } type ClassifyList struct { Id int `gorm:"column:id"` //`orm:"column(id);pk" gorm:"primaryKey" ` ClassifyName string `gorm:"column:classify_name"` //`description:"分类名称"` Sort int `gorm:"column:sort"` //`description:"排序"` ParentId int `gorm:"column:parent_id"` //`description:"父级分类id"` CreateTime time.Time `gorm:"column:create_time"` //`description:"创建时间"` ModifyTime time.Time `gorm:"column:modify_time"` //`description:"修改时间"` Abstract string `gorm:"column:abstract"` //`description:"简介"` Descript string `gorm:"column:descript"` //`description:"描述"` ClassifyLabel string `gorm:"column:classify_label"` //`description:"分类标签"` ShowType int `gorm:"column:show_type"` //`description:"展示类型:1-列表 2-专栏"` HasTeleconference int `gorm:"column:has_teleconference"` //`description:"是否有电话会:0-否 1-是"` IsShow int `gorm:"column:is_show"` //`description:"是否在小程序显示:1-显示 0-隐藏"` YbFiccSort int `gorm:"column:yb_ficc_sort"` //`description:"小程序FICC页排序"` YbFiccIcon string `gorm:"column:yb_ficc_icon"` //`description:"小程序FICC页icon"` YbFiccPcIcon string `gorm:"column:yb_ficc_pc_icon"` //`description:"小程序PC端FICC页背景图"` YbIconUrl string `gorm:"column:yb_icon_url"` //`description:"小程序已购页icon"` YbBgUrl string `gorm:"column:yb_bg_url"` //`description:"小程序已购详情背景图"` YbListImg string `gorm:"column:yb_list_img"` //`description:"小程序研报列表封面图"` YbShareBgImg string `gorm:"column:yb_share_bg_img"` //`description:"小程序研报详情分享背景图"` YbRightBanner string `gorm:"column:yb_right_banner"` //`description:"Pc端详情页,右侧,报告合集背景图"` RelateTel int `gorm:"column:relate_tel"` //`description:"是否在电话会中可选: 0-否; 1-是"` RelateVideo int `gorm:"column:relate_video"` //`description:"是否在路演视频中可选: 0-否; 1-是"` Enabled int `gorm:"column:enabled"` //`description:"是否可用,1可用,0禁用"` Level int `gorm:"column:level"` //`description:"层级"` HasChild int `gorm:"column:has_child"` //`description:"是否有子级别,0:下面没有子分类,1:下面有子分类;默认:0"` ClassifyType int `gorm:"column:classify_type"` //`description:"分类类型:1-研报;2-PPT"` IsRemind int `gorm:"column:is_remind"` //`description:"是否开启提醒:0-关闭;1-开启"` RemindTime string `gorm:"column:remind_time"` //`description:"提醒时间:可选00:00-23:59"` ReportNum int `gorm:"column:report_num"` //`description:"分类下的报告数"` Child []*ClassifyList `gorm:"-"` ClassifyMenuId int `gorm:"-"` //`description:"二级分类-子目录ID"` ClassifyMenuList []*ClassifyMenu `gorm:"-"` ChartPermissionIdList []int `gorm:"-"` //`description:"绑定的权限ID"` } type ClassifyItem struct { Classify ClassifyMenuId int `description:"二级分类-子目录ID"` ClassifyMenuList []*ClassifyMenu ChartPermissionIdList []int `description:"绑定的权限ID"` Child []*ClassifyItem } type ClassifyListResp struct { List []*ClassifyList } type ClassifyPermissionListResp struct { List []*ClassifyList Paging *paging.PagingItem `description:"分页数据"` } type CheckDeleteClassifyReq struct { ClassifyId int `description:"分类ID"` } type CheckDeleteClassifyResp struct { Code int `description:"编码:0:检测成功,可进行删除,1:分类不存在,2:该分类有关联报告,不允许删除,3:二级分类有关联报告,不允许删除,4:该分类下有关联分类,是否确认全部删除"` Msg string `description:"描述信息"` } type DeleteClassifyReq struct { ClassifyId int `description:"分类ID"` } type EditClassifyReq struct { ClassifyId int `description:"分类ID"` ClassifyAddReq } type FindByIdClassifyReq struct { ClassifyId int `description:"分类ID"` } func GetClassifyChild(parentId int, keyWord string) (items []*Classify, err error) { sql := `` pars := make([]interface{}, 0) if keyWord != "" { sql = `SELECT * FROM classify WHERE classify_name LIKE ? AND parent_id=? ORDER BY create_time ASC ` pars = append(pars, utils.GetLikeKeyword(keyWord)) } else { sql = `SELECT * FROM classify WHERE parent_id=? ORDER BY create_time ASC ` } pars = append(pars, parentId) err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error return } // EditClassifyPermissionReq 编辑分类权限请求 type EditClassifyPermissionReq struct { ClassifyId int `description:"分类ID"` ChartPermissionIdList []int `description:"权限id数组"` } // GetAllClassify 获取所有分类 func GetAllClassify() (list []*Classify, err error) { sql := ` SELECT * FROM classify ` err = global.DmSQL["rddp"].Raw(sql).Find(&list).Error return } // UpdateClassify 更新分类 func (classifyInfo *Classify) UpdateClassify(cols []string) (err error) { err = global.DmSQL["rddp"].Select(cols).Updates(classifyInfo).Error return } // SimpleClassifyList 简版分类列表 type SimpleClassifyList struct { Id int `description:"分类ID"` ClassifyName string `description:"分类名称"` ParentId int `description:"父级ID"` Sort int `description:"排序"` Child []*SimpleClassifyList } // GetClassifyByCondition 获取分类列表 func GetClassifyByCondition(condition, orderRule string, pars []interface{}) (items []*SimpleClassifyList, err error) { sql := `SELECT * FROM classify WHERE 1 = 1 ` if condition != `` { sql += condition } order := `sort ASC, create_time ASC` if orderRule != `` { order = orderRule } sql += ` ORDER BY ` + order err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error return } // RelateTelSecClassifyWithPermissions 关联了电话会的二级分类及权限 type RelateTelSecClassifyWithPermissions struct { Id int `description:"分类ID"` ClassifyName string `description:"分类名称"` ChartPermissionIds string `description:"权限IDs"` } // UpdateClassifySortByParentId 根据父类id更新排序 func UpdateClassifySortByParentId(parentId, permissionId, nowSort int, updateSort string) (err error) { sql := ` update classify set sort = ` + updateSort + ` WHERE parent_id=? AND sort > ? ` if permissionId > 0 { sql += ` or ( id > ` + fmt.Sprint(permissionId) + ` and sort = ` + fmt.Sprint(nowSort) + `)` } err = global.DmSQL["rddp"].Exec(sql, parentId, nowSort).Error return } // GetMaxSortByParentId 获取最大的排序值 func (classifyInfo *Classify) GetMaxSortByParentId(parentId int) (maxSort int, err error) { sql := `SELECT COALESCE(MAX(sort), 0) AS sort FROM classify WHERE parent_id = ? ` err = global.DmSQL["rddp"].Raw(sql, parentId).Scan(&maxSort).Error return } // GetMaxSort 获取最大的排序值 func (classifyInfo *Classify) GetMaxSort() (maxSort int, err error) { sql := `SELECT COALESCE(MAX(sort), 0) AS sort FROM classify` err = global.DmSQL["rddp"].Raw(sql).Scan(&maxSort).Error return } // GetFirstClassifyByParentId 获取当前父级分类下,且排序数相同 的排序第一条的数据 func (classifyInfo *Classify) GetFirstClassifyByParentId(parentId int) (item *Classify, err error) { sql := `SELECT * FROM classify WHERE parent_id = ? order by sort asc, id asc limit 1` err = global.DmSQL["rddp"].Raw(sql, parentId).First(&item).Error return } type ClassifyMoveReq struct { ClassifyId int `description:"分类ID"` PrevClassifyId int `description:"上一个兄弟节点分类id"` NextClassifyId int `description:"下一个兄弟节点分类id"` } type ClassifySetEnabledReq struct { ClassifyId int `description:"分类ID"` Enabled int `description:"是否可用,1可用,0禁用"` } func (classifyInfo *Classify) SetEnabled(id, enabled int) (err error) { to := global.DmSQL["rddp"].Begin() defer func() { if err != nil { _ = to.Rollback() } else { _ = to.Commit() } }() sql := ` UPDATE classify SET enabled =? WHERE id = ?` err = to.Exec(sql, enabled, id).Error if err != nil { return } sql = ` UPDATE classify SET enabled =? WHERE parent_id = ?` err = to.Exec(sql, enabled, id).Error if err != nil { return } return } // GetCountClassifyChildByParentId // @Description: 获取父级分类下子分类数量 // @author: Roc // @datetime 2024-06-17 10:58:46 // @param parentId int // @return total int // @return err error func GetCountClassifyChildByParentId(parentId int) (total int, err error) { sql := `SELECT count(1) AS total FROM classify WHERE parent_id = ? ` err = global.DmSQL["rddp"].Raw(sql, parentId).Scan(&total).Error return } // GetClassifyListByKeyword // @Description: 获取分类列表 // @author: Roc // @datetime 2024-06-19 09:49:33 // @param keyWord string // @param enabled int // @return items []*ClassifyList // @return err error func GetClassifyListByKeyword(keyWord string, enabled, classifyType int) (items []*ClassifyList, err error) { sql := `` pars := make([]interface{}, 0) sql = `SELECT * FROM classify WHERE 1=1 ` if enabled == 1 { sql += ` AND enabled = 1 ` } if classifyType > 0 { sql += fmt.Sprintf(` AND classify_type = %d `, classifyType) } if keyWord != `` { sql += ` AND classify_name LIKE ? ` pars = utils.GetLikeKeywordPars(pars, keyWord, 1) } sql += ` ORDER BY sort ASC, create_time ASC` err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error return } // GetClassifyListByParentIdList // @Description: 获取分类列表 // @author: Roc // @datetime 2024-06-19 09:49:33 // @param keyWord string // @param enabled int // @return items []*ClassifyList // @return err error func GetClassifyListByParentIdList(parentClassifyIdList []int) (items []*ClassifyList, err error) { num := len(parentClassifyIdList) if num <= 0 { return } sql := `SELECT * FROM classify WHERE id in (` + utils.GetOrmInReplace(num) + `) ORDER BY sort ASC, create_time ASC` err = global.DmSQL["rddp"].Raw(sql, parentClassifyIdList).Find(&items).Error return } // GetClassifyListByIdList // @Description: 根据指标ID列表,获取分类列表 // @author: Roc // @datetime 2024-06-27 15:23:57 // @param classifyIdList []int // @return items []*Classify // @return err error func GetClassifyListByIdList(classifyIdList []int) (items []*Classify, err error) { num := len(classifyIdList) if num <= 0 { return } sql := `SELECT * FROM classify WHERE id IN (` + utils.GetOrmInReplace(num) + `) ` err = global.DmSQL["rddp"].Raw(sql, classifyIdList).Find(&items).Error return } func (m *Classify) TableName() string { return "classify" } 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.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error return }