123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- package classify
- import (
- "errors"
- "hongze/hongze_yb/global"
- "hongze/hongze_yb/utils"
- )
- func GetSimpleAll() (list []*Classify, err error) {
- err = global.MYSQL["rddp"].Select("id, classify_name, yb_icon_url, yb_bg_url, parent_id").Model(Classify{}).Where("is_show = 1 AND parent_id != 56 AND id != 56").Scan(&list).Error
- return
- }
- func GetByClassifyName(classifyName string) (item *Classify, err error) {
- err = global.MYSQL["rddp"].Model(Classify{}).Where("classify_name = ?", classifyName).First(&item).Error
- if err == utils.ErrNoRow {
- err = nil
- }
- return
- }
- func GetByClassifyNameFirst(classifyName string) (item *Classify, err error) {
- err = global.MYSQL["rddp"].Model(Classify{}).Where("classify_name = ? and parent_id = 0", classifyName).First(&item).Error
- if err == utils.ErrNoRow {
- err = nil
- }
- return
- }
- func GetSecondIdsByClassifyNames(names []string) (ids []int, err error) {
- var list []*Classify
- err = global.MYSQL["rddp"].Model(Classify{}).Select("id").Where("classify_name in (?) and parent_id >0 AND is_show = 1 AND enabled = 1 AND parent_id != 56", names).Scan(&list).Error
- if err != nil {
- if err == utils.ErrNoRow {
- err = nil
- }
- return
- }
- for _, v := range list {
- ids = append(ids, v.Id)
- }
- return
- }
- func GetParentList() (list []*Classify, err error) {
- err = global.MYSQL["rddp"].Model(Classify{}).
- Select("id, classify_name, show_type, yb_ficc_icon, yb_ficc_pc_icon, yb_ficc_sort").
- Where("parent_id = 0 and classify_name != '权益研报' AND is_show = 1 AND enabled = 1").
- Order("sort asc, id asc").Scan(&list).Error
- if err == utils.ErrNoRow {
- err = nil
- }
- return
- }
- func GetByClassifyId(id int) (item *Classify, err error) {
- err = global.MYSQL["rddp"].Model(Classify{}).Where("id = ? AND is_show = 1 AND enabled = 1", id).First(&item).Error
- if err == utils.ErrNoRow {
- err = nil
- }
- return
- }
- func GetListByPid(pid int) (list []*Classify, err error) {
- err = global.MYSQL["rddp"].Model(Classify{}).
- Select("id, classify_name, parent_id, abstract, report_author, author_descript, home_img_url, vip_title, avatar_img_url").
- Where("parent_id = ? AND is_show = 1 AND enabled = 1", pid).Order("sort asc, id asc").Scan(&list).Error
- if err == utils.ErrNoRow {
- err = nil
- }
- return
- }
- func GetIdsByClassifyNameAndParentId(names []string, parentId int) (ids []int, err error) {
- var list []*Classify
- err = global.MYSQL["rddp"].Model(Classify{}).Select("id").Where("classify_name in (?) and parent_id = ? AND is_show = 1 AND enabled = 1", names, parentId).Scan(&list).Error
- if err != nil {
- return
- }
- for _, v := range list {
- ids = append(ids, v.Id)
- }
- return
- }
- func GetOtherIdsByClassifyNames(names []string) (ids []int, err error) {
- var list []*Classify
- err = global.MYSQL["rddp"].Model(Classify{}).Select("id").Where("classify_name in (?) and parent_id > 0 AND is_show = 1 AND enabled = 1", names).Scan(&list).Error
- if err != nil {
- return
- }
- for _, v := range list {
- ids = append(ids, v.Id)
- }
- return
- }
- func GetOtherSecondIds(names []string) (ids []int, err error) {
- var list []*Classify
- err = global.MYSQL["rddp"].Model(Classify{}).Select("id").Where("parent_id IN (SELECT id FROM classify WHERE classify_name IN (?) AND parent_id = 0 AND is_show = 1 AND enabled = 1)", names).Scan(&list).Error
- if err != nil {
- return
- }
- for _, v := range list {
- ids = append(ids, v.Id)
- }
- return
- }
- func GetChildByPid(pid int) (list []*Classify, err error) {
- err = global.MYSQL["rddp"].Model(Classify{}).Where("parent_id = ? AND is_show = 1 AND enabled = 1", pid).Scan(&list).Error
- if err == utils.ErrNoRow {
- err = nil
- }
- return
- }
- func GetClassifyList() (list []*Classify, err error) {
- err = global.MYSQL["rddp"].Model(Classify{}).Scan(&list).Error
- return
- }
- func GetByClassifyIdFirst(classifyId int) (item *Classify, err error) {
- err = global.MYSQL["rddp"].Model(Classify{}).Where("id = ? and parent_id = 0", classifyId).First(&item).Error
- if errors.Is(err, utils.ErrNoRow) {
- err = nil
- }
- return
- }
- func GetListByClassifyIdList(idList []int) (list []*Classify, err error) {
- err = global.MYSQL["rddp"].Model(Classify{}).Where("id in (?) AND is_show = 1 AND enabled = 1", idList).Find(&list).Error
- return
- }
|