Browse Source

修改文件名

ziwen 1 year ago
parent
commit
8cb7103d05
2 changed files with 151 additions and 244 deletions
  1. 0 234
      models/sandbox/sand_box_classify.go
  2. 151 10
      models/sandbox/sandbox_classify.go

+ 0 - 234
models/sandbox/sand_box_classify.go

@@ -1,234 +0,0 @@
-package sandbox
-
-import (
-	"fmt"
-	"github.com/beego/beego/v2/client/orm"
-	"time"
-)
-
-type SandboxClassify struct {
-	SandboxClassifyId   int       `orm:"column(sandbox_classify_id);pk"`
-	SandboxClassifyName string    `description:"分类名称"`
-	ParentId            int       `description:"父级id"`
-	HasData             int       `description:"是否含有指标数据"`
-	CreateTime          time.Time `description:"创建时间"`
-	ModifyTime          time.Time `description:"修改时间"`
-	SysUserId           int       `description:"创建人id"`
-	SysUserRealName     string    `description:"创建人姓名"`
-	Level               int       `description:"层级"`
-	ChartPermissionId   int       `description:"品种id"`
-	ChartPermissionName string    `description:"品种名称"`
-	Sort                int       `description:"排序字段,越小越靠前,默认值:10"`
-}
-
-func AddSandboxClassify(item *SandboxClassify) (lastId int64, err error) {
-	o := orm.NewOrmUsingDB("data")
-	lastId, err = o.Insert(item)
-	return
-}
-
-// GetSandboxClassifyByParentId
-func GetSandboxClassifyByParentId(parentId int) (items []*SandboxClassifyItems, err error) {
-	o := orm.NewOrmUsingDB("data")
-	sql := ` SELECT * FROM sandbox_classify WHERE parent_id=? order by sort asc,sandbox_classify_id asc`
-	_, err = o.Raw(sql, parentId).QueryRows(&items)
-	return
-}
-
-// GetSandboxClassifyAll
-func GetSandboxClassifyAll() (items []*SandboxClassifyItems, err error) {
-	o := orm.NewOrmUsingDB("data")
-	sql := ` SELECT * FROM sandbox_classify WHERE parent_id<>0 order by sort asc,sandbox_classify_id asc`
-	_, err = o.Raw(sql).QueryRows(&items)
-	return
-}
-
-type SandboxClassifyItems struct {
-	SandboxClassifyId   int       `orm:"column(sandbox_classify_id);pk"`
-	SandboxClassifyName string    `description:"分类名称"`
-	ParentId            int       `description:"父级id"`
-	HasData             int       `description:"是否含有指标数据"`
-	CreateTime          time.Time `description:"创建时间"`
-	ModifyTime          time.Time `description:"修改时间"`
-	SysUserId           int       `description:"创建人id"`
-	SysUserName         string    `description:"创建人姓名"`
-	Level               int       `description:"层级"`
-	Sort                int       `description:"排序字段,越小越靠前,默认值:10"`
-	SandboxId           int       `description:"沙盘id"`
-	Children            []*SandboxClassifyItems
-}
-
-type SandboxClassifyListResp struct {
-	AllNodes []*SandboxClassifyItems
-}
-
-type AddSandboxClassifyReq struct {
-	SandboxClassifyName string `description:"分类名称"`
-	ParentId            int    `description:"父级id,第一级传0"`
-	Level               int    `description:"层级,第一级传0,其余传上一级的层级"`
-	ChartPermissionId   int    `description:"品种id"`
-	ChartPermissionName string `description:"品种名称"`
-}
-
-func GetSandboxClassifyCount(sandboxClassifyName string, parentId int) (count int, err error) {
-	o := orm.NewOrmUsingDB("data")
-	sql := `SELECT COUNT(1) AS count FROM sandbox_classify WHERE parent_id=? AND sandbox_classify_name=? `
-	err = o.Raw(sql, parentId, sandboxClassifyName).QueryRow(&count)
-	return
-}
-
-// GetSandboxClassifyMaxSort 获取沙盘分类下最大的排序数
-func GetSandboxClassifyMaxSort(parentId int) (sort int, err error) {
-	o := orm.NewOrmUsingDB("data")
-	sql := `SELECT Max(sort) AS sort FROM sandbox_classify WHERE parent_id=? `
-	err = o.Raw(sql, parentId).QueryRow(&sort)
-	return
-}
-
-type EditSandboxClassifyReq struct {
-	SandboxClassifyName string `description:"分类名称"`
-	SandboxClassifyId   int    `description:"分类id"`
-}
-
-func GetSandboxClassifyById(classifyId int) (item *SandboxClassify, err error) {
-	o := orm.NewOrmUsingDB("data")
-	sql := `SELECT * FROM sandbox_classify WHERE sandbox_classify_id=? `
-	err = o.Raw(sql, classifyId).QueryRow(&item)
-	return
-}
-
-func EditSandboxClassify(classifyId int, sandboxClassifyName string) (err error) {
-	o := orm.NewOrmUsingDB("data")
-	sql := `UPDATE sandbox_classify SET sandbox_classify_name=?,modify_time=NOW() WHERE sandbox_classify_id=? `
-	_, err = o.Raw(sql, sandboxClassifyName, classifyId).Exec()
-	return
-}
-
-type SandboxClassifyDeleteCheckReq struct {
-	SandboxClassifyId int `description:"分类id"`
-}
-
-func GetSandboxInfoCountByClassifyId(classifyId int) (count int, err error) {
-	o := orm.NewOrmUsingDB("data")
-	sql := ` SELECT COUNT(1) AS count FROM sandbox AS a
-				WHERE a.sandbox_classify_id IN(
-				SELECT t.sandbox_classify_id FROM 
-				(
-				SELECT rd.*
-				FROM (SELECT * FROM sandbox_classify WHERE parent_id IS NOT NULL) rd,
-					 (SELECT @pid := ?) pd 
-				WHERE FIND_IN_SET(parent_id, @pid) > 0 
-				  AND @pid := CONCAT(@pid, ',', sandbox_classify_id) 
-				UNION SELECT * FROM sandbox_classify WHERE sandbox_classify_id = @pid
-				)AS t
-				) `
-	err = o.Raw(sql, classifyId).QueryRow(&count)
-	return
-}
-
-type SandboxClassifyDeleteCheckResp struct {
-	DeleteStatus int    `description:"检测状态:0:默认值,如果为0,继续走其他校验,1:该分类下关联图表不可删除,2:确认删除当前目录及包含的子目录吗"`
-	TipsMsg      string `description:"提示信息"`
-}
-
-type DeleteSandboxClassifyReq struct {
-	SandboxClassifyId int `description:"分类id"`
-	SandboxId         int `description:"指标id"`
-}
-
-func DeleteSandboxClassify(classifyId int) (err error) {
-	o := orm.NewOrmUsingDB("data")
-	sql := ` DELETE FROM sandbox_classify
-				WHERE sandbox_classify_id IN(
-				SELECT t.sandbox_classify_id FROM
-				(
-				SELECT rd.*
-				FROM (SELECT * FROM sandbox_classify WHERE parent_id IS NOT NULL) rd,
-				(SELECT @pid := ?) pd
-				WHERE FIND_IN_SET(parent_id, @pid) > 0
-				AND @pid := CONCAT(@pid, ',', sandbox_classify_id)
-				UNION SELECT * FROM sandbox_classify WHERE sandbox_classify_id = @pid
-				)AS t
-				) `
-	_, err = o.Raw(sql, classifyId).Exec()
-	return
-}
-
-// MoveSandboxClassifyReq 移动沙盘分类请求参数
-type MoveSandboxClassifyReq struct {
-	ClassifyId       int `description:"分类id"`
-	SandboxId        int `description:"沙盘ID"`
-	ParentClassifyId int `description:"父级分类id 移动沙盘时为目标分类id"`
-	PrevId           int `description:"上一个兄弟节点分类id"`
-	NextId           int `description:"下一个兄弟节点分类id"`
-	PrevType         int `description:"上一个兄弟节点类型 1分类 2沙盘 "`
-	NextType         int `description:"上一个兄弟节点类型 1分类 2沙盘 "`
-}
-
-// UpdateSandboxClassifySortByParentId 根据沙盘父类id更新排序
-func UpdateSandboxClassifySortByParentId(parentId, classifyId, nowSort int, updateSort string) (err error) {
-	o := orm.NewOrmUsingDB("data")
-	sql := ` update sandbox_classify set sort = ` + updateSort + ` WHERE parent_id=? and sort > ? `
-	if classifyId > 0 {
-		sql += ` or ( sandbox_classify_id > ` + fmt.Sprint(classifyId) + ` and sort= ` + fmt.Sprint(nowSort) + `)`
-	}
-	_, err = o.Raw(sql, parentId, nowSort).Exec()
-	return
-}
-
-// GetFirstSandboxClassifyByParentId 获取当前父级沙盘分类下的排序第一条的数据
-func GetFirstSandboxClassifyByParentId(parentId int) (item *SandboxClassify, err error) {
-	o := orm.NewOrmUsingDB("data")
-	sql := ` SELECT * FROM sandbox_classify WHERE parent_id=? order by sort asc,sandbox_classify_id asc limit 1`
-	err = o.Raw(sql, parentId).QueryRow(&item)
-	return
-}
-
-// Update 更新沙盘分类基础信息
-func (sandboxClassify *SandboxClassify) Update(cols []string) (err error) {
-	o := orm.NewOrmUsingDB("data")
-	_, err = o.Update(sandboxClassify, cols...)
-	return
-}
-
-// GetSandboxClassifyAndInfoByParentId
-func GetSandboxClassifyAndInfoByParentId(parentId int) (items []*SandboxClassifyItems, err error) {
-	o := orm.NewOrmUsingDB("data")
-	sql := ` SELECT
-	0 AS sandbox_id,
-	sandbox_classify_id,
-	sandbox_classify_name,
-	parent_id,
-	create_time,
-	modify_time,
-	sys_user_id,
-	sys_user_real_name AS sys_user_name,
-	sort,
-	level,
-	0 AS is_delete
-FROM
-	sandbox_classify 
-WHERE
-	parent_id = ? UNION ALL
-SELECT
-	sandbox_id,
-	sandbox_classify_id,
-	name AS sandbox_classify_name,
-	0 AS parent_id,
-	create_time,
-	modify_time,
-	sys_user_id,
-	sys_user_name,
-	sort,
-	0 AS level,
-	is_delete 
-FROM
-	sandbox 
-WHERE
-	sandbox_classify_id = ? AND is_delete = 0
-ORDER BY
-	sort ASC,
-	sandbox_classify_id ASC`
-	_, err = o.Raw(sql, parentId, parentId).QueryRows(&items)
-	return
-}

+ 151 - 10
models/sandbox/sandbox_classify.go

@@ -1,6 +1,7 @@
 package sandbox
 
 import (
+	"fmt"
 	"github.com/beego/beego/v2/client/orm"
 	"time"
 )
@@ -8,14 +9,16 @@ import (
 type SandboxClassify struct {
 	SandboxClassifyId   int       `orm:"column(sandbox_classify_id);pk"`
 	SandboxClassifyName string    `description:"分类名称"`
-	ParentId          int       `description:"父级id"`
-	HasData           int       `description:"是否含有指标数据"`
-	CreateTime        time.Time `description:"创建时间"`
-	ModifyTime        time.Time `description:"修改时间"`
-	SysUserId         int       `description:"创建人id"`
-	SysUserRealName   string    `description:"创建人姓名"`
-	Level             int       `description:"层级"`
-	Sort              int       `description:"排序字段,越小越靠前,默认值:10"`
+	ParentId            int       `description:"父级id"`
+	HasData             int       `description:"是否含有指标数据"`
+	CreateTime          time.Time `description:"创建时间"`
+	ModifyTime          time.Time `description:"修改时间"`
+	SysUserId           int       `description:"创建人id"`
+	SysUserRealName     string    `description:"创建人姓名"`
+	Level               int       `description:"层级"`
+	ChartPermissionId   int       `description:"品种id"`
+	ChartPermissionName string    `description:"品种名称"`
+	Sort                int       `description:"排序字段,越小越靠前,默认值:10"`
 }
 
 func AddSandboxClassify(item *SandboxClassify) (lastId int64, err error) {
@@ -48,7 +51,7 @@ type SandboxClassifyItems struct {
 	CreateTime          time.Time `description:"创建时间"`
 	ModifyTime          time.Time `description:"修改时间"`
 	SysUserId           int       `description:"创建人id"`
-	SysUserRealName     string    `description:"创建人姓名"`
+	SysUserName         string    `description:"创建人姓名"`
 	Level               int       `description:"层级"`
 	Sort                int       `description:"排序字段,越小越靠前,默认值:10"`
 	SandboxId           int       `description:"沙盘id"`
@@ -63,6 +66,8 @@ type AddSandboxClassifyReq struct {
 	SandboxClassifyName string `description:"分类名称"`
 	ParentId            int    `description:"父级id,第一级传0"`
 	Level               int    `description:"层级,第一级传0,其余传上一级的层级"`
+	ChartPermissionId   int    `description:"品种id"`
+	ChartPermissionName string `description:"品种名称"`
 }
 
 func GetSandboxClassifyCount(sandboxClassifyName string, parentId int) (count int, err error) {
@@ -90,4 +95,140 @@ func GetSandboxClassifyById(classifyId int) (item *SandboxClassify, err error) {
 	sql := `SELECT * FROM sandbox_classify WHERE sandbox_classify_id=? `
 	err = o.Raw(sql, classifyId).QueryRow(&item)
 	return
-}
+}
+
+func EditSandboxClassify(classifyId int, sandboxClassifyName string) (err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := `UPDATE sandbox_classify SET sandbox_classify_name=?,modify_time=NOW() WHERE sandbox_classify_id=? `
+	_, err = o.Raw(sql, sandboxClassifyName, classifyId).Exec()
+	return
+}
+
+type SandboxClassifyDeleteCheckReq struct {
+	SandboxClassifyId int `description:"分类id"`
+}
+
+func GetSandboxInfoCountByClassifyId(classifyId int) (count int, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := ` SELECT COUNT(1) AS count FROM sandbox AS a
+				WHERE a.sandbox_classify_id IN(
+				SELECT t.sandbox_classify_id FROM 
+				(
+				SELECT rd.*
+				FROM (SELECT * FROM sandbox_classify WHERE parent_id IS NOT NULL) rd,
+					 (SELECT @pid := ?) pd 
+				WHERE FIND_IN_SET(parent_id, @pid) > 0 
+				  AND @pid := CONCAT(@pid, ',', sandbox_classify_id) 
+				UNION SELECT * FROM sandbox_classify WHERE sandbox_classify_id = @pid
+				)AS t
+				) `
+	err = o.Raw(sql, classifyId).QueryRow(&count)
+	return
+}
+
+type SandboxClassifyDeleteCheckResp struct {
+	DeleteStatus int    `description:"检测状态:0:默认值,如果为0,继续走其他校验,1:该分类下关联图表不可删除,2:确认删除当前目录及包含的子目录吗"`
+	TipsMsg      string `description:"提示信息"`
+}
+
+type DeleteSandboxClassifyReq struct {
+	SandboxClassifyId int `description:"分类id"`
+	SandboxId         int `description:"指标id"`
+}
+
+func DeleteSandboxClassify(classifyId int) (err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := ` DELETE FROM sandbox_classify
+				WHERE sandbox_classify_id IN(
+				SELECT t.sandbox_classify_id FROM
+				(
+				SELECT rd.*
+				FROM (SELECT * FROM sandbox_classify WHERE parent_id IS NOT NULL) rd,
+				(SELECT @pid := ?) pd
+				WHERE FIND_IN_SET(parent_id, @pid) > 0
+				AND @pid := CONCAT(@pid, ',', sandbox_classify_id)
+				UNION SELECT * FROM sandbox_classify WHERE sandbox_classify_id = @pid
+				)AS t
+				) `
+	_, err = o.Raw(sql, classifyId).Exec()
+	return
+}
+
+// MoveSandboxClassifyReq 移动沙盘分类请求参数
+type MoveSandboxClassifyReq struct {
+	ClassifyId       int `description:"分类id"`
+	SandboxId        int `description:"沙盘ID"`
+	ParentClassifyId int `description:"父级分类id 移动沙盘时为目标分类id"`
+	PrevId           int `description:"上一个兄弟节点分类id"`
+	NextId           int `description:"下一个兄弟节点分类id"`
+	PrevType         int `description:"上一个兄弟节点类型 1分类 2沙盘 "`
+	NextType         int `description:"上一个兄弟节点类型 1分类 2沙盘 "`
+}
+
+// UpdateSandboxClassifySortByParentId 根据沙盘父类id更新排序
+func UpdateSandboxClassifySortByParentId(parentId, classifyId, nowSort int, updateSort string) (err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := ` update sandbox_classify set sort = ` + updateSort + ` WHERE parent_id=? and sort > ? `
+	if classifyId > 0 {
+		sql += ` or ( sandbox_classify_id > ` + fmt.Sprint(classifyId) + ` and sort= ` + fmt.Sprint(nowSort) + `)`
+	}
+	_, err = o.Raw(sql, parentId, nowSort).Exec()
+	return
+}
+
+// GetFirstSandboxClassifyByParentId 获取当前父级沙盘分类下的排序第一条的数据
+func GetFirstSandboxClassifyByParentId(parentId int) (item *SandboxClassify, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := ` SELECT * FROM sandbox_classify WHERE parent_id=? order by sort asc,sandbox_classify_id asc limit 1`
+	err = o.Raw(sql, parentId).QueryRow(&item)
+	return
+}
+
+// Update 更新沙盘分类基础信息
+func (sandboxClassify *SandboxClassify) Update(cols []string) (err error) {
+	o := orm.NewOrmUsingDB("data")
+	_, err = o.Update(sandboxClassify, cols...)
+	return
+}
+
+// GetSandboxClassifyAndInfoByParentId
+func GetSandboxClassifyAndInfoByParentId(parentId int) (items []*SandboxClassifyItems, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := ` SELECT
+	0 AS sandbox_id,
+	sandbox_classify_id,
+	sandbox_classify_name,
+	parent_id,
+	create_time,
+	modify_time,
+	sys_user_id,
+	sys_user_real_name AS sys_user_name,
+	sort,
+	level,
+	0 AS is_delete
+FROM
+	sandbox_classify 
+WHERE
+	parent_id = ? UNION ALL
+SELECT
+	sandbox_id,
+	sandbox_classify_id,
+	name AS sandbox_classify_name,
+	0 AS parent_id,
+	create_time,
+	modify_time,
+	sys_user_id,
+	sys_user_name,
+	sort,
+	0 AS level,
+	is_delete 
+FROM
+	sandbox 
+WHERE
+	sandbox_classify_id = ? AND is_delete = 0
+ORDER BY
+	sort ASC,
+	sandbox_classify_id ASC`
+	_, err = o.Raw(sql, parentId, parentId).QueryRows(&items)
+	return
+}