123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- package sandbox
- import (
- "github.com/beego/beego/v2/client/orm"
- "github.com/rdlucklib/rdluck_tools/paging"
- "time"
- )
- type Sandbox struct {
- SandboxId int `orm:"column(sandbox_id);pk" description:"沙盘id"`
- Name string `description:"沙盘名称"`
- Code string `description:"沙盘code"`
- Content string `description:"沙盘数据"`
- MindmapData string `description:"思维导图数据"`
- PicUrl string `description:"沙盘图片地址"`
- SysUserId int `description:"作者id"`
- SysUserName string `description:"作者名称"`
- IsDelete int8 `description:"是否删除,0:未删除,1:已删除"`
- ModifyTime time.Time `description:"修改时间"`
- CreateTime time.Time `description:"创建时间"`
- SandboxClassifyId int `description:"分类id"`
- Sort int `description:"排序"`
- Style int `description:"风格"`
- }
- type SandboxItem struct {
- Sandbox
- ModifyTime string `description:"修改时间"`
- CreateTime string `description:"创建时间"`
- }
- // Update 沙盘字段变更
- func (sandbox *Sandbox) Update(cols []string) (err error) {
- o := orm.NewOrmUsingDB("data")
- _, err = o.Update(sandbox, cols...)
- return
- }
- // GetSandboxById 根据沙盘id获取沙盘详情
- func GetSandboxById(sandboxId int) (sandboxInfo *SandboxItem, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `select * from sandbox where sandbox_id = ? and is_delete = 0`
- err = o.Raw(sql, sandboxId).QueryRow(&sandboxInfo)
- return
- }
- // SandboxListItem 沙盘推演列表数据
- type SandboxListItem struct {
- SandboxId int `description:"沙盘id"`
- Name string `description:"沙盘名称"`
- //ChartPermissionId int `description:"品种id"`
- //ChartPermissionName string `description:"品种名称"`
- //CurrVersion int `description:"当前版本"`
- Code string `description:"沙盘code"`
- //VersionCode string `description:"沙盘版本code"`
- //Content string `description:"沙盘数据"`
- PicUrl string `description:"沙盘图片地址"`
- //OpUserId int `description:"最近一次编辑操作的用户id"`
- //OpUserName string `description:"最近一次编辑的用户名称(冗余字段,避免查表)"`
- IsDelete int8 `description:"是否删除,0:未删除,1:已删除" json:"is_delete"`
- // CanEdit bool `description:"是否可编辑"`
- // Editor string `description:"编辑人"`
- // VersionTotal int `description:"历史版本数量"`
- ModifyTime string `description:"修改时间"`
- CreateTime string `description:"创建时间"`
- SysUserId int `description:"作者id"`
- SysUserName string `description:"作者名称"`
- SandboxClassifyId int `description:"分类id"`
- Sort int `description:"排序"`
- Style int `description:"风格"`
- }
- func GetSandboxClassify(sandboxClassifyId int) (sandbox_classify_id string, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `SELECT GROUP_CONCAT(t.sandbox_classify_id) AS sandbox_classify_id FROM (
- SELECT a.sandbox_classify_id FROM sandbox_classify AS a
- WHERE a.sandbox_classify_id=?
- UNION ALL
- SELECT a.sandbox_classify_id FROM sandbox_classify AS a
- WHERE a.parent_id=? UNION ALL
- SELECT
- sandbox_classify_id
- FROM
- sandbox_classify
- WHERE
- parent_id IN ( SELECT sandbox_classify_id FROM sandbox_classify WHERE parent_id = ? )
- )AS t`
- err = o.Raw(sql, sandboxClassifyId, sandboxClassifyId, sandboxClassifyId).QueryRow(&sandbox_classify_id)
- return
- }
- type SandboxListItems struct {
- SandboxListItem
- ParentIds string
- }
- func GetSandboxListByCondition(condition string, pars []interface{}, startSize, pageSize int) (item []*SandboxListItems, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT * FROM sandbox WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- sql += " ORDER BY create_time DESC LIMIT ?,? "
- _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&item)
- return
- }
- func GetSandboxListCountByCondition(condition string, pars []interface{}) (count int, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT COUNT(1) AS count FROM sandbox WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- err = o.Raw(sql, pars).QueryRow(&count)
- return
- }
- type SandboxListResp struct {
- Paging *paging.PagingItem
- List []*SandboxListItems
- }
- func GetSandboxAllParentByClassifyId(sandboxClassifyId int) (ids string, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `SELECT
- GROUP_CONCAT(DISTINCT m.sandbox_classify_id ORDER BY m.level) AS ids
- FROM
- (
- SELECT
- @id AS _id,(
- SELECT
- @id := parent_id
- FROM
- sandbox_classify
- WHERE
- sandbox_classify_id = _id
- )
- FROM
- (
- SELECT
- @id :=(
- SELECT
- parent_id
- FROM
- sandbox_classify
- WHERE
- sandbox_classify_id = ?
- )) vm,
- sandbox_classify m
- WHERE
- @id IS NOT NULL
- ) vm
- INNER JOIN sandbox_classify m
- WHERE
- sandbox_classify_id = vm._id `
- err = o.Raw(sql, sandboxClassifyId).QueryRow(&ids)
- return
- }
- // ContentDataStruct 沙盘内容结构体
- type ContentDataStruct struct {
- Cells []struct {
- Data *NodeData `json:"data,omitempty"`
- } `json:"cells"`
- }
- type NodeData struct {
- LinkData []*LinkData `json:"linkData"`
- LinkFold bool `json:"linkFold"`
- }
- type LinkData struct {
- RId string `json:"RId"`
- Id int `json:"Id"`
- Name string `json:"Name"`
- Type int `json:"Type"`
- Editing bool `json:"editing"`
- DatabaseType int `json:"databaseType"`
- DetailParams DetailParams `json:"detailParams"`
- }
- type DetailParams struct {
- Code string `json:"code"`
- Id int `json:"id"`
- ClassifyId int `json:"classifyId"`
- }
|