123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- package data_manage
- import (
- "eta_gn/eta_api/global"
- "time"
- )
- type EdbdataClassify struct {
- ClassifyId int `gorm:"primaryKey" description:"分类id"`
- ClassifyName string `description:"分类名称"`
- ParentId int `description:"父级id"`
- CreateTime time.Time `description:"创建时间"`
- Sort int `description:"排序"`
- IsShow int `description:"是否显示"`
- }
- type EdbdataClassifyList struct {
- ClassifyId int `description:"分类id"`
- ClassifyName string `description:"分类名称"`
- ParentId int `description:"父级id"`
- CreateTime time.Time `description:"创建时间"`
- Sort int `description:"排序"`
- IsShow int `description:"是否显示"`
- Total int `description:"指标总数"`
- }
- func AddEdbdataClassify(item *EdbdataClassify) (lastId int64, err error) {
- err = global.DmSQL["edb"].Create(item).Error
- return
- }
- type ManualClassifyList struct {
- ClassifyId int
- ClassifyName string
- ParentId int
- CheckList []int
- Child []*ManualClassifyList
- }
- func GetManualClassifyAll(adminId int) (items []*ManualClassifyList, err error) {
- var newItems []*ManualClassifyList
- sql := ` SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE parent_id=0 AND is_show=1 ORDER BY sort ASC ,classify_id ASC `
- err = global.DmSQL["edb"].Raw(sql).Find(&newItems).Error
- if err != nil {
- return
- }
- classifyLen := len(newItems)
- for i := 0; i < classifyLen; i++ {
- var childItems []*ManualClassifyList
- parentId := newItems[i].ClassifyId
- childSql := ``
- childSql = "SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE parent_id=? AND is_show=1 ORDER BY sort ASC ,classify_id ASC "
- err = global.DmSQL["edb"].Raw(childSql, parentId).Find(&childItems).Error
- if err != nil {
- return
- }
- checkList := make([]int, 0)
- for _, v := range childItems {
- if v.ParentId > 0 {
- count, err := GetManualUserClassifyCount(adminId, v.ClassifyId)
- if err != nil {
- return items, err
- }
- if count > 0 {
- checkList = append(checkList, v.ClassifyId)
- }
- }
- }
- newItems[i].CheckList = checkList
- newItems[i].Child = childItems
- }
- for _, v := range newItems {
- if v.ParentId > 0 {
- count, err := GetManualUserClassifyCount(adminId, v.ClassifyId)
- if err != nil {
- return items, err
- }
- if count > 0 {
- v.CheckList = append(v.CheckList, v.ClassifyId)
- }
- }
- childLen := len(v.Child)
- if childLen > 0 {
- items = append(items, v)
- }
- }
- return
- }
- func GetManualClassifyAllV2() (items []*ManualClassifyList, err error) {
- var newItems []*ManualClassifyList
- sql := ` SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE parent_id=0 AND is_show=1 ORDER BY sort ASC ,classify_id ASC `
- err = global.DmSQL["edb"].Raw(sql).Find(&newItems).Error
- if err != nil {
- return
- }
- classifyLen := len(newItems)
- for i := 0; i < classifyLen; i++ {
- var childItems []*ManualClassifyList
- parentId := newItems[i].ClassifyId
- childSql := ``
- childSql = "SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE parent_id=? AND is_show=1 ORDER BY sort ASC ,classify_id ASC "
- err = global.DmSQL["edb"].Raw(childSql, parentId).Find(&childItems).Error
- if err != nil {
- return
- }
- newItems[i].Child = childItems
- }
- for _, v := range newItems {
- items = append(items, v)
- }
- return
- }
- type AddManualClassifyReq struct {
- ClassifyName string `description:"分类名称"`
- ParentId int `description:"父级id,第一级传0"`
- }
- func GetManualClassifyByClassifyName(classifyName string) (item *EdbdataClassify, err error) {
- sql := `SELECT * FROM edbdata_classify WHERE classify_name=? `
- err = global.DmSQL["edb"].Raw(sql, classifyName).First(&item).Error
- return
- }
- func ModifyManualClassifyIsShow(isShow, classifyId, parentId int) (err error) {
- sql := `UPDATE edbdata_classify SET is_show=?,parent_id=? WHERE classify_id=? `
- err = global.DmSQL["edb"].Exec(sql, isShow, parentId, classifyId).Error
- return
- }
- type EditManualClassifyReq struct {
- ClassifyName string `description:"分类名称"`
- ClassifyId int `orm:"column(classify_id);pk" gorm:"primaryKey" description:"分类id"`
- ParentId int `description:"上级id"`
- }
- // DelManualClassifyReq 删除手工指标分类请求
- type DelManualClassifyReq struct {
- ClassifyId int `description:"分类id"`
- }
- func GetManualClassifyById(classifyId int) (item *EdbdataClassify, err error) {
- sql := ` SELECT * FROM edbdata_classify WHERE classify_id=? `
- err = global.DmSQL["edb"].Raw(sql, classifyId).First(&item).Error
- return
- }
- func ModifyManualClassifyName(classifyName string, classifyId, parentId int) (err error) {
- updateStr := ` classify_name=? `
- pars := []interface{}{classifyName}
- if parentId > 0 {
- updateStr += ` , parent_id=? `
- pars = append(pars, parentId)
- }
- sql := `UPDATE edbdata_classify SET ` + updateStr + ` WHERE classify_id=? `
- pars = append(pars, classifyId)
- err = global.DmSQL["edb"].Exec(sql, pars).Error
- return
- }
- func GetManualClassifyAllByCondition(condition string) (items []*EdbdataClassifyList, err error) {
- sql := ` SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE is_show=1 `
- if condition != "" {
- sql += condition
- }
- sql += ` ORDER BY sort ASC `
- err = global.DmSQL["edb"].Raw(sql).Find(&items).Error
- return
- }
- // GetChildManualClassifyCount 根据分类id获取下面存在的子分类数量(展示的)
- func GetChildManualClassifyCount(parentId int) (count int, err error) {
- sql := `SELECT COUNT(1) AS count FROM edbdata_classify WHERE parent_id=? AND is_show = 1`
- err = global.DmSQL["edb"].Raw(sql, parentId).Scan(&count).Error
- return
- }
|