123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- 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:"排序字段"`
- UniqueCode string `description:"唯一code"`
- ModifyTime time.Time `description:"修改时间"`
- CreateTime time.Time `description:"创建时间"`
- ClassifyNameEn string `description:"英文分类名称"`
- Children []*BaseFromSciHqClassifyItem `description:"子分类"`
- }
- type BaseFromSciHqClassifyMaxSort struct {
- ClassifyId int `description:"分类id"`
- MaxSort int `description:"最大排序"`
- }
- func (t *BaseFromSciHqClassify) Add() (insertId int64, err error) {
- o := orm.NewOrmUsingDB("data")
- insertId, err = o.Insert(t)
- return
- }
- func (t *BaseFromSciHqClassify) Update(cols []string) (err error) {
- o := orm.NewOrmUsingDB("data")
- _, err = o.Update(t, cols...)
- return
- }
- func BatchAddSciHqClassify(items []*BaseFromSciHqClassify) (err error) {
- o := orm.NewOrmUsingDB("data")
- _, 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 ORDER BY sort ASC, classify_id ASC`
- _, 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
- }
- // GetSciHqChildClassifyById 通过分类id获取子分类
- func GetSciHqChildClassifyIdsById(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
- }
- // GetSciHqClassifyListByIds 通过分类id获取分类列表
- func GetSciHqClassifyListByIds(classifyIds []int) (items []*BaseFromSciHqClassify, err error) {
- if len(classifyIds) == 0 {
- return
- }
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT * FROM base_from_sci_hq_classify WHERE classify_id IN (` + utils.GetOrmInReplace(len(classifyIds)) + `)`
- _, err = o.Raw(sql, classifyIds).QueryRows(&items)
- return
- }
- // GetSciHqClassifyCountByName 通过分类名称获取分类
- func GetSciHqClassifyCountByName(classifyName string, lang string) (count int, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT COUNT(*) AS count FROM base_from_sci_hq_classify WHERE 1=1`
- if lang == utils.EnLangVersion {
- sql += ` AND classify_name_en=? `
- } else {
- sql += ` AND classify_name=? `
- }
- err = o.Raw(sql, classifyName).QueryRow(&count)
- 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_hq_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_hq_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
- }
- // DeleteSciHqClassifyByClassifyId 根据分类id删除对应的指标分类
- func DeleteSciHqClassifyByClassifyId(classifyIdList []int) (err error) {
- o := orm.NewOrmUsingDB("data")
- num := len(classifyIdList)
- if num <= 0 {
- return
- }
- //删除分类
- sql := `DELETE FROM base_from_sci_hq_classify WHERE classify_id IN (` + utils.GetOrmInReplace(num) + `) `
- _, err = o.Raw(sql, classifyIdList).Exec()
- return
- }
- // GetSciHqIndexClassifyMinSort 获取最小不等于0的排序
- func GetSciHqIndexClassifyMinSort(parentId int) (sort int, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `SELECT MIN(sort) FROM base_from_sci_hq_classify WHERE parent_id=? AND sort <> 0 `
- err = o.Raw(sql, parentId).QueryRow(&sort)
- return
- }
- // MoveUpSciHqIndexClassifyBySort 往上移动
- func MoveUpSciHqIndexClassifyBySort(parentId, nextSort, currentSort int) (err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `update base_from_sci_hq_classify set sort = sort + 1 where parent_id=? and sort >= ? and sort< ?`
- _, err = o.Raw(sql, parentId, nextSort, currentSort).Exec()
- return
- }
- // MoveDownSciHqIndexClassifyBySort 往下移动
- func MoveDownSciHqIndexClassifyBySort(parentId, prevSort, currentSort int) (err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `update base_from_sci_hq_classify set sort = sort - 1 where parent_id=? and sort <= ? and sort> ? `
- _, err = o.Raw(sql, parentId, prevSort, currentSort).Exec()
- return
- }
|