package data_manage import ( "eta/eta_api/utils" "time" "github.com/beego/beego/v2/client/orm" ) // BaseFromSciHqClassify 卓创红期原始数据分类表 type BaseFromSciHqClassify struct { ClassifyId int `orm:"column(classify_id);pk"` ClassifyName string `description:"分类名称"` ParentId int `description:"父级id"` Level int `description:"层级"` Sort int `description:"排序字段"` ModifyTime time.Time `description:"修改时间"` CreateTime time.Time `description:"创建时间"` ClassifyNameEn string `description:"英文分类名称"` } type BaseFromSciHqClassifyItem struct { ClassifyId int `orm:"column(classify_id);pk"` ClassifyName string `description:"分类名称"` ParentId int `description:"父级id"` Level int `description:"层级"` Sort int `description:"排序字段"` ModifyTime time.Time `description:"修改时间"` CreateTime time.Time `description:"创建时间"` ClassifyNameEn string `description:"英文分类名称"` Children []*BaseFromSciHqClassifyItem `description:"子分类"` } func (t *BaseFromSciHqClassify) Add() (insertId int64, err error) { o := orm.NewOrm() insertId, err = o.Insert(t) return } func BatchAddSciHqClassify(items []*BaseFromSciHqClassify) (err error) { o := orm.NewOrm() _, err = o.InsertMulti(len(items), items) return } // 获取所有分类 func GetSciHqClassifyAll() (items []*BaseFromSciHqClassifyItem, err error) { o := orm.NewOrmUsingDB("data") sql := ` SELECT * FROM base_from_sci_hq_classify ` _, err = o.Raw(sql).QueryRows(&items) return } // GetChildSciHqClassifyListById 获取子分类列表 func GetChildSciHqClassifyListById(classifyId int) (items []*BaseFromSciHqClassifyItem, err error) { o := orm.NewOrmUsingDB("data") sql := ` SELECT * FROM base_from_sci_hq_classify WHERE parent_id=? ` _, err = o.Raw(sql, classifyId).QueryRows(&items) return } // GetChildSciHqClassifyIdsById 获取子分类的id集合 func GetChildSciHqClassifyIdsById(classifyId int) (items []int, err error) { o := orm.NewOrmUsingDB("data") sql := ` SELECT classify_id FROM base_from_sci_hq_classify WHERE parent_id=? ` _, err = o.Raw(sql, classifyId).QueryRows(&items) return } // GetChildSciHqClassifyMaxSortById 获取子分类最大排序 func GetChildSciHqClassifyMaxSortById(classifyId int) (sort int, err error) { o := orm.NewOrmUsingDB("data") sql := ` SELECT MAX(sort) AS sort FROM base_from_sci_hq_classify WHERE parent_id=? ` err = o.Raw(sql, classifyId).QueryRow(&sort) return } // GetSciHqClassifyCountById 获取分类数量 func GetSciHqClassifyCountById(classifyId int) (count int, err error) { o := orm.NewOrmUsingDB("data") sql := ` SELECT COUNT(*) AS count FROM base_from_sci_hq_classify WHERE classify_id=? ` err = o.Raw(sql, classifyId).QueryRow(&count) return } // GetSciHqClassifyById 通过分类id获取分类 func GetSciHqClassifyById(classifyId int) (item *BaseFromSciHqClassify, err error) { o := orm.NewOrmUsingDB("data") sql := ` SELECT * FROM base_from_sci_hq_classify WHERE classify_id=? ` err = o.Raw(sql, classifyId).QueryRow(&item) return } func GetBaseFromSciHqClassifyEnCount(classifyNameEn string, parentId int) (count int, err error) { o := orm.NewOrmUsingDB("data") sql := `SELECT COUNT(1) AS count FROM base_from_sci_classify WHERE classify_name_en=? AND parent_id=? ` err = o.Raw(sql, classifyNameEn, parentId).QueryRow(&count) return } func GetBaseFromSciHqClassifyCount(classifyName string, parentId int) (count int, err error) { o := orm.NewOrmUsingDB("data") sql := `SELECT COUNT(1) AS count FROM base_from_sci_classify WHERE classify_name=? AND parent_id=? ` err = o.Raw(sql, classifyName, parentId).QueryRow(&count) return } func DeleteSciHqClassifyById(classifyId int) (err error) { o := orm.NewOrmUsingDB("data") sql := ` DELETE FROM base_from_sci_hq_classify WHERE classify_id=? ` _, err = o.Raw(sql, classifyId).Exec() return } // BatchDeleteSciHqClassifyById 批量删除分类 func BatchDeleteSciHqClassifyById(classifyId []int) (err error) { if len(classifyId) == 0 { return } o := orm.NewOrmUsingDB("data") to, err := o.Begin() if err != nil { return } defer func() { if err != nil { _ = to.Rollback() } else { _ = to.Commit() } }() sql := ` DELETE FROM base_from_sci_hq_classify WHERE classify_id IN (` + utils.GetOrmInReplace(len(classifyId)) + `) ` _, err = o.Raw(sql, classifyId).Exec() return }