package sandbox import ( "encoding/json" "eta_gn/eta_api/controllers" "eta_gn/eta_api/models" "eta_gn/eta_api/models/data_manage" "eta_gn/eta_api/models/sandbox" "eta_gn/eta_api/models/sandbox/request" "eta_gn/eta_api/models/sandbox/response" "eta_gn/eta_api/services/data" sandboxService "eta_gn/eta_api/services/sandbox" "eta_gn/eta_api/utils" "fmt" "github.com/rdlucklib/rdluck_tools/paging" "time" ) var versionSize = 3 type SandboxController struct { controllers.BaseAuthController } // @router /list [get] // @router /version/first_list [get] func (this *SandboxController) FirstVersionList() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sandboxId, _ := this.GetInt("SandboxId") keyword := this.GetString("Keyword") currentIndex := 1 pageSize := versionSize startSize := 0 var condition string var pars []interface{} if sandboxId <= 0 { br.Msg = "参数错误,沙盘编号id必传!" br.ErrMsg = "参数错误,沙盘编号id必传" return } condition += " AND a.sandbox_id=? " pars = append(pars, sandboxId) condition += " AND b.curr_version < a.curr_version " if keyword != "" { condition += ` AND ( a.name LIKE ? OR b.name LIKE ? )` pars = utils.GetLikeKeywordPars(pars, keyword, 2) } total, list, err := sandbox.GetVersionList(condition, pars, startSize, pageSize) if err != nil && !utils.IsErrNoRow(err) { br.Success = true br.Msg = "获取沙盘列表失败" br.ErrMsg = "获取沙盘列表失败,Err:" + err.Error() return } if list == nil || (err != nil && utils.IsErrNoRow(err)) { list = make([]*sandbox.SandboxVersionListItem, 0) } for _, v := range list { v.ModifyTime = v.CreateTime } page := paging.GetPaging(currentIndex, pageSize, total) resp := response.SandboxVersionListResp{ Paging: page, List: list, } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // @router /version/list [get] func (this *SandboxController) VersionList() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sandboxId, _ := this.GetInt("SandboxId") keyWord := this.GetString("Keyword") pageSize, _ := this.GetInt("PageSize") currentIndex, _ := this.GetInt("CurrentIndex") var startSize int if pageSize <= 0 { pageSize = utils.PageSize20 } startSize = paging.StartIndex(currentIndex, pageSize) + versionSize var condition string var pars []interface{} if sandboxId <= 0 { br.Msg = "参数错误,沙盘编号id必传!" br.ErrMsg = "参数错误,沙盘编号id必传" return } condition += " AND a.sandbox_id=? " pars = append(pars, sandboxId) condition += " AND b.curr_version < a.curr_version " if keyWord != "" { condition += ` AND ( a.op_user_name LIKE ? OR a.name LIKE ? or a.op_user_name LIKE ? OR a.name LIKE ? )` pars = utils.GetLikeKeywordPars(pars, keyWord, 4) } total, list, err := sandbox.GetVersionList(condition, pars, startSize, pageSize) if err != nil && !utils.IsErrNoRow(err) { br.Success = true br.Msg = "获取沙盘列表失败" br.ErrMsg = "获取沙盘列表失败,Err:" + err.Error() return } if list == nil || (err != nil && utils.IsErrNoRow(err)) { list = make([]*sandbox.SandboxVersionListItem, 0) } for _, v := range list { v.ModifyTime = v.CreateTime markStatus, err := sandboxService.UpdateSandboxEditMark(v.SandboxId, this.SysUser.AdminId, 2, this.SysUser.RealName) if err != nil { br.Msg = "查询标记状态失败" br.ErrMsg = "查询标记状态失败,Err:" + err.Error() return } if markStatus.Status == 0 { v.CanEdit = true } } total = total - versionSize if total <= 0 { total = 0 } page := paging.GetPaging(currentIndex, pageSize, total) resp := response.SandboxVersionListResp{ Paging: page, List: list, } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } //// @router /save [post] // @router /draft/add [post] func (this *SandboxController) AddSandboxDraft() { br := new(models.BaseResponse).Init() br.IsSendEmail = false defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } var req request.AddAndEditSandbox err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.SandboxVersionCode == `` { br.Msg = "请传入沙盘版本!" return } sandboxVersion, err := sandbox.GetSandboxVersionBySandboxVersionCode(req.SandboxVersionCode) if err != nil { if utils.IsErrNoRow(err) { br.Msg = "找不到该版本!" br.ErrMsg = "找不到该版本" return } br.Msg = "找不到该版本!" br.ErrMsg = "找不到该版本,Err:" + err.Error() br.IsSendEmail = false return } markStatus, err := sandboxService.UpdateSandboxEditMark(sandboxVersion.SandboxId, sysUser.AdminId, 1, sysUser.RealName) if err != nil { br.Msg = err.Error() return } if markStatus.Status == 1 { br.Msg = markStatus.Msg return } sandboxDraftInfo, err := sandboxService.AddSandboxDraft(sandboxVersion.SandboxId, req, sysUser.AdminId, sysUser.RealName) if err != nil { br.Msg = "保存失败!" br.ErrMsg = "保存失败,Err:" + err.Error() br.Ret = 204 //204 (无内容) :服务器成功处理了请求,但没有返回任何内容。 return } msg := "保存成功" br.Ret = 200 br.Success = true br.Msg = msg br.Data = sandboxDraftInfo } // @router /mark [post] func (this *SandboxController) MarkEditStatus() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } var req request.MarkEditSandbox err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.SandboxId <= 0 { br.Msg = "缺少沙盘编号" return } if req.Status <= 0 { br.Msg = "标记状态异常" return } data, err := sandboxService.UpdateSandboxEditMark(req.SandboxId, sysUser.AdminId, req.Status, sysUser.RealName) if err != nil { br.Msg = err.Error() return } msg := "标记成功" br.Ret = 200 br.Success = true br.Msg = msg br.Data = data } // @router /version/detail [get] func (this *SandboxController) GetSandboxVersionDetail() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } sandboxVersionCode := this.GetString("SandboxVersionCode") if sandboxVersionCode == "" { br.Msg = "缺少沙盘版本编号" return } sandboxVersionInfo, err := sandboxService.GetSandboxVersionDetailByCode(sandboxVersionCode) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } msg := "获取成功" br.Ret = 200 br.Success = true br.Msg = msg br.Data = sandboxVersionInfo } // @router /last_info [get] func (this *SandboxController) GetLastSandboxInfo() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } sandboxId, _ := this.GetInt("SandboxId", 0) if sandboxId <= 0 { br.Msg = "缺少沙盘编号" return } sandboxInfo, err := sandboxService.GetLastSandboxInfo(sandboxId) if err != nil { br.Msg = err.Error() return } msg := "获取成功" br.Ret = 200 br.Success = true br.Msg = msg br.Data = sandboxInfo } // @router /delete [post] func (this *SandboxController) Delete() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } var req request.DeleteSandbox err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.SandboxId <= 0 { br.Msg = "缺少沙盘编号" return } markStatus, err := sandboxService.UpdateSandboxEditMark(req.SandboxId, this.SysUser.AdminId, 2, this.SysUser.RealName) if err != nil { br.Msg = "查询标记状态失败" br.ErrMsg = "查询标记状态失败,Err:" + err.Error() return } if markStatus.Status == 1 { br.Msg = fmt.Sprintf("当前%s正在编辑,不允许删除该沙盘", markStatus.Editor) return } err = sandboxService.DeleteSandbox(req.SandboxId) if err != nil { br.Msg = err.Error() return } _ = data_manage.DeleteEdbRelationByObjectId(req.SandboxId, utils.EDB_RELATION_SANDBOX) msg := "删除成功" br.Ret = 200 br.Success = true br.Msg = msg } //// @router /version/delete [post] //// @router /draft/reset [post] // @router /list_by_quote [get] func (this *SandboxController) ListByQuote() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() chartPermissionId, _ := this.GetInt("ChartPermissionId") keyword := this.GetString("Keyword") pageSize, _ := this.GetInt("PageSize") currentIndex, _ := this.GetInt("CurrentIndex") var startSize int if pageSize <= 0 { pageSize = utils.PageSize20 } if currentIndex <= 0 { currentIndex = 1 } startSize = paging.StartIndex(currentIndex, pageSize) var condition string var pars []interface{} if chartPermissionId > 0 { condition += " AND a.chart_permission_id=? " pars = append(pars, chartPermissionId) } if keyword != "" { condition += ` AND ( a.name LIKE ? OR a.chart_permission_name LIKE ? )` pars = utils.GetLikeKeywordPars(pars, keyword, 2) } total, list, err := sandbox.GetList(condition, pars, startSize, pageSize) if err != nil && !utils.IsErrNoRow(err) { br.Success = true br.Msg = "获取沙盘列表失败" br.ErrMsg = "获取沙盘列表失败,Err:" + err.Error() return } if list == nil || (err != nil && utils.IsErrNoRow(err)) { list = make([]*sandbox.Sandbox, 0) } page := paging.GetPaging(currentIndex, pageSize, total) resp := response.SandboxListResp{ Paging: page, List: list, } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // @router /classify/list [get] func (this *SandboxController) SandboxClassifyItems() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() resp := new(sandbox.SandboxClassifyListResp) sandboxClassifyId, _ := this.GetInt("SandboxClassifyId") isShowMe, _ := this.GetBool("IsShowMe") if isShowMe { errMsg, err := sandboxService.GetSandboxClassifyListForMe(*this.SysUser, resp, sandboxClassifyId) if err != nil { br.Msg = errMsg br.ErrMsg = err.Error() return } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp fmt.Println("source my classify") return } rootList, err := sandbox.GetSandboxClassifyAndInfoByParentId(sandboxClassifyId) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } classifyAll, err := sandbox.GetSandboxClassifyAndInfoByParentId(sandboxClassifyId) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } nodeAll := make([]*sandbox.SandboxClassifyItems, 0) for k := range rootList { rootNode := rootList[k] sandboxService.SandboxClassifyItemsMakeTreeV2(this.SysUser, classifyAll, rootNode) nodeAll = append(nodeAll, rootNode) } resp.AllNodes = nodeAll br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // @router /classify/add [post] func (this *SandboxController) AddSandboxClassify() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() var req sandbox.AddSandboxClassifyReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.SandboxClassifyName == "" { br.Msg = "请输入分类名称" br.IsSendEmail = false return } if req.ParentId < 0 { br.Msg = "参数错误" br.IsSendEmail = false return } count, err := sandbox.GetSandboxClassifyCount(req.SandboxClassifyName, req.ParentId) if err != nil { br.Msg = "判断名称是否已存在失败" br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error() return } if count > 0 { br.Msg = "分类名称已存在,请重新输入" br.IsSendEmail = false return } maxSort, err := sandbox.GetSandboxClassifyMaxSort(req.ParentId) classify := new(sandbox.SandboxClassify) classify.ParentId = req.ParentId classify.SandboxClassifyName = req.SandboxClassifyName classify.HasData = 0 classify.CreateTime = time.Now() classify.ModifyTime = time.Now() classify.SysUserId = this.SysUser.AdminId classify.SysUserRealName = this.SysUser.RealName classify.ChartPermissionId = req.ChartPermissionId classify.ChartPermissionName = req.ChartPermissionName classify.Level = req.Level + 1 classify.Sort = maxSort + 1 _, err = sandbox.AddSandboxClassify(classify) if err != nil { br.Msg = "保存分类失败" br.ErrMsg = "保存分类失败,Err:" + err.Error() return } br.Ret = 200 br.Msg = "保存成功" br.Success = true } // @router /classify/edit [post] func (this *SandboxController) EditSandboxClassify() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() var req sandbox.EditSandboxClassifyReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.SandboxClassifyName == "" { br.Msg = "请输入分类名称" br.IsSendEmail = false return } if req.SandboxClassifyId <= 0 { br.Msg = "参数错误" br.IsSendEmail = false return } err = sandbox.EditSandboxClassify(req.SandboxClassifyId, req.ChartPermissionId, req.SandboxClassifyName, req.ChartPermissionName) if err != nil { br.Msg = "保存失败" br.ErrMsg = "保存失败,Err:" + err.Error() return } ids, err := sandbox.GetSandboxClassifySubcategories(req.SandboxClassifyId) if err != nil { br.Msg = "查询子级分类id失败" br.ErrMsg = "查询子级分类id失败,Err:" + err.Error() return } err = sandbox.UpdateSandboxClassifyChartPermissionById(req.ChartPermissionId, req.ChartPermissionName, ids) if err != nil { br.Msg = "修改子级分类错误" br.ErrMsg = "修改子级分类错误,Err:" + err.Error() return } br.Ret = 200 br.Msg = "保存成功" br.Success = true br.IsAddLog = true } // @router /classify/delete/check [post] func (this *SandboxController) DeleteSandboxClassifyCheck() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() var req sandbox.SandboxClassifyDeleteCheckReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.SandboxClassifyId < 0 { br.Msg = "参数错误" br.IsSendEmail = false return } var deleteStatus int var tipsMsg string if req.SandboxClassifyId > 0 { count, err := sandbox.GetSandboxInfoCountByClassifyId(req.SandboxClassifyId) if err != nil { br.Msg = "删除失败" br.ErrMsg = "分类下是否含有指标失败,Err:" + err.Error() return } if count > 0 { deleteStatus = 1 tipsMsg = "该分类下关联沙盘不可删除" } } if deleteStatus != 1 { classifyCount, err := sandbox.GetSandboxInfoCountByClassifyId(req.SandboxClassifyId) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "删除失败" br.ErrMsg = "分类下是否含有沙盘失败,Err:" + err.Error() return } if classifyCount > 0 { deleteStatus = 2 tipsMsg = "确认删除当前目录及包含的子目录吗" } } if deleteStatus == 0 { tipsMsg = "可删除,进行删除操作" } resp := new(sandbox.SandboxClassifyDeleteCheckResp) resp.DeleteStatus = deleteStatus resp.TipsMsg = tipsMsg br.Ret = 200 br.Msg = "检测成功" br.Success = true br.Data = resp } // @router /classify/delete [post] func (this *SandboxController) DeleteSandboxClassify() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } var req sandbox.DeleteSandboxClassifyReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.SandboxClassifyId < 0 && req.SandboxId <= 0 { br.Msg = "参数错误" br.IsSendEmail = false return } if req.SandboxClassifyId > 0 && req.SandboxId == 0 { count, err := sandbox.GetSandboxInfoCountByClassifyId(req.SandboxId) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "删除失败" br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error() return } if count > 0 { br.Msg = "该目录下存在关联指标,不可删除" br.IsSendEmail = false return } err = sandbox.DeleteSandboxClassify(req.SandboxClassifyId) if err != nil { br.Msg = "删除失败" br.ErrMsg = "删除失败,Err:" + err.Error() return } } if req.SandboxId > 0 { sandboxInfo, err := sandbox.GetSandboxById(req.SandboxId) if err != nil { if utils.IsErrNoRow(err) { br.Msg = "沙盘已删除,请刷新页面" br.ErrMsg = "指标不存在,Err:" + err.Error() return } else { br.Msg = "删除失败" br.ErrMsg = "删除失败,获取指标信息失败,Err:" + err.Error() return } } if sandboxInfo == nil { br.Msg = "沙盘已删除,请刷新页面" return } err = sandboxService.DeleteSandbox(req.SandboxId) if err != nil { br.Msg = err.Error() return } } br.Ret = 200 br.Msg = "删除成功" br.Success = true br.IsAddLog = true } // @router /classify/move [post] func (this *SandboxController) ChartClassifyMove() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } var req sandbox.MoveSandboxClassifyReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.ClassifyId <= 0 { br.Msg = "参数错误" br.ErrMsg = "分类id小于等于0" return } sandboxClassifyInfo, err := sandbox.GetSandboxClassifyById(req.ClassifyId) if err != nil { br.Msg = "移动失败" br.ErrMsg = "获取分类信息失败,Err:" + err.Error() return } updateCol := make([]string, 0) if req.SandboxId > 0 { count, _ := sandbox.GetSandboxClassifyCountById(req.ClassifyId) if count <= 0 { br.Msg = "分类已被删除,不可移动,请刷新页面" return } sandboxInfo, err := sandbox.GetSandboxById(req.SandboxId) if err != nil { br.Msg = "移动失败" br.ErrMsg = "获取沙盘信息失败,Err:" + err.Error() return } if sandboxInfo.SandboxClassifyId != req.ParentClassifyId { err = sandbox.MoveSandbox(req.SandboxId, req.ParentClassifyId) if err != nil { br.Msg = "移动失败" br.ErrMsg = "移动失败,Err:" + err.Error() return } } updateCol := make([]string, 0) if req.PrevId > 0 { if req.PrevType == 1 { prevClassify, err := sandbox.GetSandboxClassifyById(req.PrevId) if err != nil { br.Msg = "移动失败" br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error() return } if req.NextId > 0 { if req.NextType == 1 { nextClassify, err := sandbox.GetSandboxClassifyById(req.NextId) if err != nil { br.Msg = "移动失败" br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error() return } if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == sandboxClassifyInfo.Sort { updateSortStr := `sort + 2` _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, prevClassify.SandboxClassifyId, prevClassify.Sort, updateSortStr) _ = sandbox.UpdateSandboxSortByClassifyId(prevClassify.SandboxClassifyId, prevClassify.Sort, 0, updateSortStr) } else { if nextClassify.Sort-prevClassify.Sort == 1 { updateSortStr := `sort + 1` _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr) _ = sandbox.UpdateSandboxSortByClassifyId(prevClassify.SandboxClassifyId, prevClassify.Sort, 0, updateSortStr) } } } else { nextChartInfo, err := sandbox.GetSandboxById(req.NextId) if err != nil { br.Msg = "移动失败" br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error() return } if prevClassify.Sort == nextChartInfo.Sort || prevClassify.Sort == sandboxInfo.Sort { updateSortStr := `sort + 2` _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, prevClassify.SandboxClassifyId, prevClassify.Sort, updateSortStr) _ = sandbox.UpdateSandboxSortByClassifyId(prevClassify.SandboxClassifyId, prevClassify.Sort, 0, updateSortStr) } else { if nextChartInfo.Sort-prevClassify.Sort == 1 { updateSortStr := `sort + 1` _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.SandboxClassifyId, updateSortStr) _ = sandbox.UpdateSandboxSortByClassifyId(prevClassify.SandboxClassifyId, prevClassify.Sort, 0, updateSortStr) } } } } sandboxInfo.Sort = prevClassify.Sort + 1 sandboxInfo.ModifyTime = time.Now() updateCol = append(updateCol, "Sort", "ModifyTime") } else { prevSandbox, err := sandbox.GetSandboxById(req.PrevId) if err != nil { br.Msg = "移动失败" br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error() return } if req.NextId > 0 { if req.NextType == 1 { nextClassify, err := sandbox.GetSandboxClassifyById(req.NextId) if err != nil { br.Msg = "移动失败" br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error() return } if prevSandbox.Sort == nextClassify.Sort || prevSandbox.Sort == sandboxClassifyInfo.Sort { updateSortStr := `sort + 2` _ = sandbox.UpdateSandboxClassifySortByParentId(prevSandbox.SandboxClassifyId, 0, prevSandbox.Sort, updateSortStr) _ = sandbox.UpdateSandboxSortByClassifyId(prevSandbox.SandboxClassifyId, prevSandbox.Sort, prevSandbox.SandboxId, updateSortStr) } else { if nextClassify.Sort-prevSandbox.Sort == 1 { updateSortStr := `sort + 1` _ = sandbox.UpdateSandboxClassifySortByParentId(prevSandbox.SandboxClassifyId, 0, prevSandbox.Sort, updateSortStr) _ = sandbox.UpdateSandboxSortByClassifyId(prevSandbox.SandboxClassifyId, prevSandbox.Sort, prevSandbox.SandboxId, updateSortStr) } } } else { nextChartInfo, err := sandbox.GetSandboxById(req.NextId) if err != nil { br.Msg = "移动失败" br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error() return } if prevSandbox.Sort == nextChartInfo.Sort || prevSandbox.Sort == sandboxInfo.Sort { updateSortStr := `sort + 2` _ = sandbox.UpdateSandboxClassifySortByParentId(prevSandbox.SandboxClassifyId, 0, prevSandbox.Sort, updateSortStr) _ = sandbox.UpdateSandboxSortByClassifyId(prevSandbox.SandboxClassifyId, prevSandbox.Sort, prevSandbox.SandboxId, updateSortStr) } else { if nextChartInfo.Sort-prevSandbox.Sort == 1 { updateSortStr := `sort + 1` _ = sandbox.UpdateSandboxClassifySortByParentId(prevSandbox.SandboxClassifyId, 0, prevSandbox.Sort, updateSortStr) _ = sandbox.UpdateSandboxSortByClassifyId(prevSandbox.SandboxClassifyId, prevSandbox.Sort, prevSandbox.SandboxId, updateSortStr) } } } } sandboxInfo.Sort = prevSandbox.Sort + 1 sandboxInfo.ModifyTime = time.Now() updateCol = append(updateCol, "Sort", "ModifyTime") } } else { firstClassify, err := sandbox.GetFirstSandboxByClassifyId(req.ClassifyId) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "移动失败" br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error() return } if firstClassify != nil && firstClassify.SandboxClassifyId > 0 && firstClassify.Sort == 0 { updateSortStr := ` sort + 1 ` _ = sandbox.UpdateSandboxSortByClassifyId(firstClassify.SandboxClassifyId, 0, firstClassify.SandboxId-1, updateSortStr) } sandboxInfo.Sort = 0 //那就是排在第一位 sandboxInfo.ModifyTime = time.Now() updateCol = append(updateCol, "Sort", "ModifyTime") } if len(updateCol) > 0 { err = sandboxInfo.Update(updateCol) if err != nil { br.Msg = "移动失败" br.ErrMsg = "修改失败,Err:" + err.Error() return } } } else { if sandboxClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId != 0 { parentChartClassifyInfo, err := sandbox.GetSandboxClassifyById(req.ParentClassifyId) if err != nil { br.Msg = "移动失败" br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error() return } sandboxClassifyInfo.ParentId = parentChartClassifyInfo.SandboxClassifyId sandboxClassifyInfo.Level = parentChartClassifyInfo.Level + 1 sandboxClassifyInfo.ModifyTime = time.Now() updateCol = append(updateCol, "ParentId", "Level", "ModifyTime") } else if sandboxClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId == 0 { sandboxClassifyInfo.ParentId = req.ParentClassifyId sandboxClassifyInfo.Level = 1 sandboxClassifyInfo.ModifyTime = time.Now() updateCol = append(updateCol, "ParentId", "Level", "ModifyTime") } if req.PrevId > 0 { if req.PrevType == 1 { prevClassify, err := sandbox.GetSandboxClassifyById(req.PrevId) if err != nil { br.Msg = "移动失败" br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error() return } if req.NextId > 0 { if req.NextType == 1 { nextClassify, err := sandbox.GetSandboxClassifyById(req.NextId) if err != nil { br.Msg = "移动失败" br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error() return } if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == sandboxClassifyInfo.Sort { updateSortStr := `sort + 2` _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, prevClassify.SandboxClassifyId, prevClassify.Sort, updateSortStr) _ = sandbox.UpdateSandboxSortByClassifyId(prevClassify.SandboxClassifyId, prevClassify.Sort, 0, updateSortStr) } else { if nextClassify.Sort-prevClassify.Sort == 1 { updateSortStr := `sort + 1` _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr) _ = sandbox.UpdateSandboxSortByClassifyId(prevClassify.SandboxClassifyId, prevClassify.Sort, 0, updateSortStr) } } } else { nextChartInfo, err := sandbox.GetSandboxById(req.NextId) if err != nil { br.Msg = "移动失败" br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error() return } if prevClassify.Sort == nextChartInfo.Sort || prevClassify.Sort == sandboxClassifyInfo.Sort { updateSortStr := `sort + 2` _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, prevClassify.SandboxClassifyId, prevClassify.Sort, updateSortStr) _ = sandbox.UpdateSandboxSortByClassifyId(prevClassify.SandboxClassifyId, prevClassify.Sort, 0, updateSortStr) } else { if nextChartInfo.Sort-prevClassify.Sort == 1 { updateSortStr := `sort + 1` _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.SandboxClassifyId, updateSortStr) _ = sandbox.UpdateSandboxSortByClassifyId(prevClassify.SandboxClassifyId, prevClassify.Sort, 0, updateSortStr) } } } } sandboxClassifyInfo.Sort = prevClassify.Sort + 1 sandboxClassifyInfo.ModifyTime = time.Now() updateCol = append(updateCol, "Sort", "ModifyTime") } else { prevSandbox, err := sandbox.GetSandboxById(req.PrevId) if err != nil { br.Msg = "移动失败" br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error() return } if req.NextId > 0 { if req.NextType == 1 { nextClassify, err := sandbox.GetSandboxClassifyById(req.NextId) if err != nil { br.Msg = "移动失败" br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error() return } if prevSandbox.Sort == nextClassify.Sort || prevSandbox.Sort == sandboxClassifyInfo.Sort { updateSortStr := `sort + 2` _ = sandbox.UpdateSandboxClassifySortByParentId(prevSandbox.SandboxClassifyId, 0, prevSandbox.Sort, updateSortStr) _ = sandbox.UpdateSandboxSortByClassifyId(prevSandbox.SandboxClassifyId, prevSandbox.Sort, prevSandbox.SandboxId, updateSortStr) } else { if nextClassify.Sort-prevSandbox.Sort == 1 { updateSortStr := `sort + 1` _ = sandbox.UpdateSandboxClassifySortByParentId(prevSandbox.SandboxClassifyId, 0, prevSandbox.Sort, updateSortStr) _ = sandbox.UpdateSandboxSortByClassifyId(prevSandbox.SandboxClassifyId, prevSandbox.Sort, prevSandbox.SandboxId, updateSortStr) } } } else { nextChartInfo, err := sandbox.GetSandboxById(req.NextId) if err != nil { br.Msg = "移动失败" br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error() return } if prevSandbox.Sort == nextChartInfo.Sort || prevSandbox.Sort == sandboxClassifyInfo.Sort { updateSortStr := `sort + 2` _ = sandbox.UpdateSandboxClassifySortByParentId(prevSandbox.SandboxClassifyId, 0, prevSandbox.Sort, updateSortStr) _ = sandbox.UpdateSandboxSortByClassifyId(prevSandbox.SandboxClassifyId, prevSandbox.Sort, prevSandbox.SandboxId, updateSortStr) } else { if nextChartInfo.Sort-prevSandbox.Sort == 1 { updateSortStr := `sort + 1` _ = sandbox.UpdateSandboxClassifySortByParentId(prevSandbox.SandboxClassifyId, 0, prevSandbox.Sort, updateSortStr) _ = sandbox.UpdateSandboxSortByClassifyId(prevSandbox.SandboxClassifyId, prevSandbox.Sort, prevSandbox.SandboxId, updateSortStr) } } } } sandboxClassifyInfo.Sort = prevSandbox.Sort + 1 sandboxClassifyInfo.ModifyTime = time.Now() updateCol = append(updateCol, "Sort", "ModifyTime") } } else { firstClassify, err := sandbox.GetFirstSandboxClassifyByParentId(sandboxClassifyInfo.ParentId) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "移动失败" br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error() return } if firstClassify != nil && firstClassify.SandboxClassifyId > 0 && firstClassify.Sort == 0 { updateSortStr := ` sort + 1 ` _ = sandbox.UpdateSandboxClassifySortByParentId(firstClassify.ParentId, firstClassify.SandboxClassifyId-1, 0, updateSortStr) } sandboxClassifyInfo.Sort = 0 //那就是排在第一位 sandboxClassifyInfo.ModifyTime = time.Now() updateCol = append(updateCol, "Sort", "ModifyTime") } if len(updateCol) > 0 { err = sandboxClassifyInfo.Update(updateCol) if err != nil { br.Msg = "移动失败" br.ErrMsg = "修改失败,Err:" + err.Error() return } if req.ParentClassifyId > 0 { ids, err := sandbox.GetSandboxClassifySubcategories(req.ClassifyId) if err != nil { br.Msg = "查询子级分类id失败" br.ErrMsg = "查询子级分类id失败,Err:" + err.Error() return } parentChartClassifyInfo, err := sandbox.GetSandboxClassifyById(req.ParentClassifyId) if err != nil { br.Msg = "移动失败" br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error() return } err = sandbox.UpdateSandboxClassifyChartPermissionById(parentChartClassifyInfo.ChartPermissionId, parentChartClassifyInfo.ChartPermissionName, ids) if err != nil { br.Msg = "修改子级分类错误" br.ErrMsg = "修改子级分类错误,Err:" + err.Error() return } } } } br.Ret = 200 br.Success = true br.Msg = "移动成功" } // @router /listV2 [get] func (this *SandboxController) ListV2() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } sandboxClassifyId, _ := this.GetInt("SandboxClassifyId") pageSize, _ := this.GetInt("PageSize") currentIndex, _ := this.GetInt("CurrentIndex") keyWord := this.GetString("KeyWord") var total int page := paging.GetPaging(currentIndex, pageSize, total) var startSize int if pageSize <= 0 { pageSize = utils.PageSize20 } if currentIndex <= 0 { currentIndex = 1 } startSize = paging.StartIndex(currentIndex, pageSize) classifyList, err := sandbox.GetAllSandboxClassify() if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取分类信息失败" br.ErrMsg = "获取分类信息失败,Err:" + err.Error() return } classsifyMap := make(map[int]*sandbox.SandboxClassifyItems) for _, v := range classifyList { classsifyMap[v.SandboxClassifyId] = v } var condition string var pars []interface{} if sandboxClassifyId > 0 { childIds := make([]int, 0) sandboxService.GetSandBoxClassifyChildIds(sandboxClassifyId, classsifyMap, &childIds) if len(childIds) > 0 { ids := utils.IntArr2joinString(childIds, ",") condition += " AND sandbox_classify_id IN(" + ids + ") " } else { condition += " AND sandbox_classify_id = ? " pars = append(pars, sandboxClassifyId) } } if keyWord != "" { condition += ` AND ( name LIKE '%` + keyWord + `%' )` } isShowMe, _ := this.GetBool("IsShowMe") if isShowMe { condition += ` AND sys_user_id = ? ` pars = append(pars, sysUser.AdminId) } condition += ` AND is_delete = 0 ` list, err := sandbox.GetSandboxListByCondition(condition, pars, startSize, pageSize) if err != nil && !utils.IsErrNoRow(err) { br.Success = true br.Msg = "获取沙盘信息失败" br.ErrMsg = "获取沙盘信息失败,Err:" + err.Error() return } for i, v := range list { parentIds := make([]int, 0) sandboxService.GetSandBoxParentIds(v.SandboxClassifyId, classsifyMap, &parentIds) ids := utils.IntArr2joinString(parentIds, ",") list[i].ParentIds = ids } resp := new(sandbox.SandboxListResp) if list == nil || len(list) <= 0 || (err != nil && utils.IsErrNoRow(err)) { items := make([]*sandbox.SandboxListItems, 0) resp.Paging = page resp.List = items br.Ret = 200 br.Success = true br.Msg = "获取成功" return } dataCount, err := sandbox.GetSandboxListCountByCondition(condition, pars) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取指标信息失败" br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error() return } page = paging.GetPaging(currentIndex, pageSize, dataCount) resp.Paging = page resp.List = list br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // @router /saveV2 [post] func (this *SandboxController) SaveV2() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } var req request.AddAndEditSandboxV2 err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } var sandboxResp *sandbox.SandboxSaveResp var errMsg string var sandBoxData *sandbox.Sandbox if req.SandboxId <= 0 { sandboxResp, err = sandboxService.AddSandboxV2(req, sysUser.AdminId, sysUser.RealName) if err != nil { br.Msg = "保存失败!" if errMsg != `` { br.Msg = errMsg } br.ErrMsg = "保存失败,Err:" + err.Error() return } sandBoxData = sandboxResp.Sandbox } else { sandboxInfo := &sandbox.Sandbox{ SandboxId: req.SandboxId, Name: utils.TrimStr(req.Name), Content: req.Content, MindmapData: req.MindmapData, PicUrl: utils.TrimStr(req.PicUrl), ModifyTime: time.Now(), SandboxClassifyId: req.SandboxClassifyId, Style: req.Style, } var updateSandboxColumn = []string{} if req.PicUrl == "" { updateSandboxColumn = []string{"Name", "Content", "MindmapData", "ModifyTime", "SandboxClassifyId", "Style"} } else { updateSandboxColumn = []string{"Name", "Content", "MindmapData", "PicUrl", "ModifyTime", "SandboxClassifyId", "Style"} } err = sandboxInfo.Update(updateSandboxColumn) if err != nil { br.Msg = "保存失败!" if errMsg != `` { br.Msg = errMsg } br.ErrMsg = "保存失败,Err:" + err.Error() return } sandBoxData = sandboxInfo } _ = data.SaveSandBoxEdbInfoRelation(sandBoxData.SandboxId, sandBoxData.Content) msg := "保存成功" br.Ret = 200 br.Success = true br.Msg = msg br.Data = sandboxResp } // @router /deleteV2 [post] func (this *SandboxController) DeleteV2() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } var req request.DeleteSandbox err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.SandboxId <= 0 { br.Msg = "缺少沙盘编号" return } err = sandboxService.DeleteSandbox(req.SandboxId) if err != nil { br.Msg = err.Error() return } msg := "删除成功" br.Ret = 200 br.Success = true br.Msg = msg } // @router /detail [get] func (this *SandboxController) GetSandboxDetail() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } sandboxId, _ := this.GetInt("SandboxId") if sandboxId == 0 { br.Msg = "缺少沙盘Id" return } sandboxInfo, err := sandbox.GetSandboxById(sandboxId) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } msg := "获取成功" br.Ret = 200 br.Success = true br.Msg = msg br.Data = sandboxInfo } //// @router /classify/list [get] //// @router /move [post] //// @router /classify/move [post] // @router /classifyList [get] func (this *SandboxController) SandboxClassifyList() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() resp := new(sandbox.SandboxClassifyListResp) rootList, err := sandbox.GetSandboxClassifyByParentId(0) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } classifyAll, err := sandbox.GetSandboxClassifyAll() if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } nodeAll := make([]*sandbox.SandboxClassifyItems, 0) for k := range rootList { rootNode := rootList[k] sandboxService.SandboxClassifyItemsMakeTree(this.SysUser, classifyAll, rootNode) nodeAll = append(nodeAll, rootNode) } resp.AllNodes = nodeAll br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // @router /link/check [post] func (this *SandboxController) LinkEdbInfoCheck() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() var req sandbox.SandboxLinkCheckReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } resp := new(sandbox.SandboxLinkCheckResp) edbInfoList, err := data_manage.GetEdbInfoByIdList(req.EdbInfoIdList) if err != nil { br.Msg = "获取指标信息失败" br.ErrMsg = "获取指标信息失败,err:" + err.Error() return } edbList := make([]*sandbox.SandboxLinkCheckItem, 0) for _, v := range edbInfoList { tmp := &sandbox.SandboxLinkCheckItem{ Id: v.EdbInfoId, Name: v.EdbName, UniqueCode: v.UniqueCode, ClassifyId: v.ClassifyId, } edbList = append(edbList, tmp) } chartList, err := data_manage.GetChartInfoByIdList(req.ChartInfoIdList) if err != nil { br.Msg = `获取失败` br.ErrMsg = `获取图表列表失败,ERR:` + err.Error() return } chartListTmp := make([]*sandbox.SandboxLinkCheckItem, 0) for _, v := range chartList { tmp := &sandbox.SandboxLinkCheckItem{ Id: v.ChartInfoId, Name: v.ChartName, UniqueCode: v.UniqueCode, ClassifyId: v.ChartClassifyId, } chartListTmp = append(chartListTmp, tmp) } reportList, err := models.GetSimpleReportByIds(req.ReportIdList) if err != nil { br.Msg = `获取失败` br.ErrMsg = `获取报告列表失败,ERR:` + err.Error() return } reportListTmp := make([]*sandbox.SandboxLinkCheckItem, 0) for _, v := range reportList { tmp := &sandbox.SandboxLinkCheckItem{ Id: v.Id, Name: v.Title, UniqueCode: v.ReportCode, } reportListTmp = append(reportListTmp, tmp) } resp.EdbInfoIdList = edbList resp.ChartInfoIdList = chartListTmp resp.ReportIdList = reportListTmp br.Ret = 200 br.Msg = "检测成功" br.Success = true br.Data = resp }