1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- package models
- import (
- sql2 "database/sql"
- "eta/eta_api/global"
- "eta/eta_api/utils"
- "fmt"
- )
- // UpdateEnglishClassifySortByParentId 根据父类id更新排序
- func UpdateEnglishClassifySortByParentId(parentId, permissionId, nowSort int, updateSort string) (err error) {
- sql := ` update english_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.DbMap[utils.DbNameReport].Exec(sql, parentId, nowSort).Error
- return
- }
- // GetMaxSortByParentId 获取最大的排序值
- func (classifyInfo *EnglishClassify) GetMaxSortByParentId(parentId int) (maxSort int, err error) {
- var maxNull sql2.NullInt64
- sql := `SELECT max(sort) AS sort FROM english_classify WHERE parent_id = ? `
- err = global.DbMap[utils.DbNameReport].Raw(sql, parentId).Scan(&maxNull).Error
- if maxNull.Valid {
- maxSort = int(maxNull.Int64)
- }
- return
- }
- // GetMaxSort 获取最大的排序值
- func (classifyInfo *EnglishClassify) GetMaxSort() (maxSort int, err error) {
- var maxNull sql2.NullInt64
- sql := `SELECT max(sort) AS sort FROM english_classify`
- err = global.DbMap[utils.DbNameReport].Raw(sql).Scan(&maxNull).Error
- if maxNull.Valid {
- maxSort = int(maxNull.Int64)
- }
- return
- }
- // GetFirstClassifyByParentId 获取当前父级分类下,且排序数相同 的排序第一条的数据
- func (classifyInfo *EnglishClassify) GetFirstClassifyByParentId(parentId int) (item *Classify, err error) {
- sql := `SELECT * FROM english_classify WHERE parent_id = ? order by sort asc, id asc limit 1`
- err = global.DbMap[utils.DbNameReport].Raw(sql, parentId).First(&item).Error
- return
- }
- type EnglishClassifyMoveReq struct {
- ClassifyId int `description:"分类ID"`
- PrevClassifyId int `description:"上一个兄弟节点分类id"`
- NextClassifyId int `description:"下一个兄弟节点分类id"`
- }
- type EnClassifyAddReq struct {
- EnPermissions []int `description:"权限IDs"`
- ClassifyName string `description:"分类名称"`
- ParentId int `description:"父级分类id"`
- }
- type EnClassifyEditReq struct {
- ClassifyId int `description:"分类ID"`
- EnClassifyAddReq
- }
- // GetClassifyListByParentId 获取当前父级分类下的素有分类
- func (classifyInfo *EnglishClassify) GetClassifyListByParentId(childId []int) (items []*Classify, err error) {
- if len(childId) <= 0 {
- return
- }
- sql := `SELECT b.* FROM english_classify as a
- join english_classify b on a.parent_id = b.id
- WHERE a.id in (?) order b.id asc`
- err = global.DbMap[utils.DbNameReport].Raw(sql, childId).Find(&items).Error
- return
- }
- // GetClassifyListByParentId 获取当前父级分类下的素有分类
- func (classifyInfo *EnglishClassify) GetClassifyListByIdList(idList []int) (items []*Classify, err error) {
- if len(idList) <= 0 {
- return
- }
- sql := `SELECT a.* FROM english_classify as a
- WHERE a.id in (?) order by a.id asc`
- err = global.DbMap[utils.DbNameReport].Raw(sql, idList).Find(&items).Error
- return
- }
|