sandbox.go 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825
  1. package sandbox
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/controllers"
  5. "eta/eta_api/models"
  6. "eta/eta_api/models/sandbox"
  7. "eta/eta_api/models/sandbox/request"
  8. "eta/eta_api/models/sandbox/response"
  9. sandboxService "eta/eta_api/services/sandbox"
  10. "eta/eta_api/utils"
  11. "fmt"
  12. "github.com/rdlucklib/rdluck_tools/paging"
  13. "time"
  14. )
  15. // versionSize 版本列表第一页数据约定是:3条
  16. var versionSize = 3
  17. // SandboxController 逻辑导图
  18. type SandboxController struct {
  19. controllers.BaseAuthController
  20. }
  21. // List
  22. // @Title 逻辑导图列表
  23. // @Description 逻辑导图列表接口
  24. // @Param PageSize query int true "每页数据条数"
  25. // @Param CurrentIndex query int true "当前页页码,从1开始"
  26. // @Param ChartPermissionId query int true "权限编号id"
  27. // @Param Keyword query string false "搜索关键词:沙盘名称/编辑人名称"
  28. // @Success 200 {object} response.SandboxListResp
  29. // @router /list [get]
  30. func (this *SandboxController) List() {
  31. br := new(models.BaseResponse).Init()
  32. defer func() {
  33. this.Data["json"] = br
  34. this.ServeJSON()
  35. }()
  36. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  37. keyword := this.GetString("Keyword")
  38. pageSize, _ := this.GetInt("PageSize")
  39. currentIndex, _ := this.GetInt("CurrentIndex")
  40. var startSize int
  41. if pageSize <= 0 {
  42. pageSize = utils.PageSize20
  43. }
  44. if currentIndex <= 0 {
  45. currentIndex = 1
  46. }
  47. startSize = paging.StartIndex(currentIndex, pageSize)
  48. var condition string
  49. var pars []interface{}
  50. if chartPermissionId > 0 {
  51. condition += " AND a.chart_permission_id=? "
  52. pars = append(pars, chartPermissionId)
  53. }
  54. if keyword != "" {
  55. condition += ` AND ( a.name LIKE ? OR b.name LIKE ? )`
  56. pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  57. }
  58. //获取指标信息
  59. total, list, err := sandbox.GetList(condition, pars, startSize, pageSize)
  60. if err != nil && err.Error() != utils.ErrNoRow() {
  61. br.Success = true
  62. br.Msg = "获取沙盘列表失败"
  63. br.ErrMsg = "获取沙盘列表失败,Err:" + err.Error()
  64. return
  65. }
  66. if list == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  67. list = make([]*sandbox.SandboxListItem, 0)
  68. }
  69. if len(list) > 0 {
  70. sandboxIdList := make([]int, 0)
  71. for _, v := range list {
  72. sandboxIdList = append(sandboxIdList, v.SandboxId)
  73. }
  74. sandboxVersionTotalList, err := sandbox.GetTotalSandboxVersionBySandboxIdList(sandboxIdList)
  75. if err != nil {
  76. br.Success = true
  77. br.Msg = "获取沙盘版本数量失败"
  78. br.ErrMsg = "获取沙盘版本数量失败,Err:" + err.Error()
  79. return
  80. }
  81. sandboxVersionTotalMap := make(map[int]int)
  82. for _, v := range sandboxVersionTotalList {
  83. sandboxVersionTotalMap[v.SandboxId] = v.Total
  84. }
  85. for _, item := range list {
  86. /*key := fmt.Sprint(`crm:sandbox:edit:`, item.SandboxId)
  87. opUserId, _ := utils.Rc.RedisInt(key)
  88. //如果当前没有人操作,获取当前操作人是本人,那么编辑按钮可用
  89. if opUserId <= 0 || (opUserId == this.SysUser.AdminId) {
  90. item.CanEdit = true
  91. } else {
  92. adminInfo, errAdmin := system.GetSysUserById(opUserId)
  93. if errAdmin != nil {
  94. br.Msg = "获取失败"
  95. br.ErrMsg = "获取失败,Err:" + errAdmin.Error()
  96. return
  97. }
  98. item.Editor = adminInfo.RealName
  99. }*/
  100. markStatus, err := sandboxService.UpdateSandboxEditMark(item.SandboxId, this.SysUser.AdminId, 2, this.SysUser.RealName)
  101. if err != nil {
  102. br.Msg = "查询标记状态失败"
  103. br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  104. return
  105. }
  106. if markStatus.Status == 0 {
  107. item.CanEdit = true
  108. } else {
  109. item.Editor = markStatus.Editor
  110. }
  111. // 沙盘版本数量
  112. versionTotal := sandboxVersionTotalMap[item.SandboxId]
  113. item.VersionTotal = versionTotal
  114. }
  115. }
  116. page := paging.GetPaging(currentIndex, pageSize, total)
  117. resp := response.SandboxListResp{
  118. Paging: page,
  119. List: list,
  120. }
  121. br.Ret = 200
  122. br.Success = true
  123. br.Msg = "获取成功"
  124. br.Data = resp
  125. }
  126. // FirstVersionList
  127. // @Title 逻辑导图版本列表(列表页第一页)
  128. // @Description 逻辑导图版本列表接口(列表页第一页)
  129. // @Param SandboxId query int true "沙盘id"
  130. // @Success 200 {object} response.SandboxVersionListResp
  131. // @router /version/first_list [get]
  132. func (this *SandboxController) FirstVersionList() {
  133. br := new(models.BaseResponse).Init()
  134. defer func() {
  135. this.Data["json"] = br
  136. this.ServeJSON()
  137. }()
  138. sandboxId, _ := this.GetInt("SandboxId")
  139. keyword := this.GetString("Keyword")
  140. currentIndex := 1
  141. pageSize := versionSize
  142. startSize := 0
  143. var condition string
  144. var pars []interface{}
  145. if sandboxId <= 0 {
  146. br.Msg = "参数错误,沙盘编号id必传!"
  147. br.ErrMsg = "参数错误,沙盘编号id必传"
  148. return
  149. }
  150. condition += " AND a.sandbox_id=? "
  151. pars = append(pars, sandboxId)
  152. //不能筛选出当前版本
  153. condition += " AND b.curr_version < a.curr_version "
  154. if keyword != "" {
  155. condition += ` AND ( a.name LIKE ? OR b.name LIKE ? )`
  156. pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  157. }
  158. //获取指标信息
  159. total, list, err := sandbox.GetVersionList(condition, pars, startSize, pageSize)
  160. if err != nil && err.Error() != utils.ErrNoRow() {
  161. br.Success = true
  162. br.Msg = "获取沙盘列表失败"
  163. br.ErrMsg = "获取沙盘列表失败,Err:" + err.Error()
  164. return
  165. }
  166. if list == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  167. list = make([]*sandbox.SandboxVersionListItem, 0)
  168. }
  169. for _, v := range list {
  170. v.ModifyTime = v.CreateTime
  171. }
  172. page := paging.GetPaging(currentIndex, pageSize, total)
  173. resp := response.SandboxVersionListResp{
  174. Paging: page,
  175. List: list,
  176. }
  177. br.Ret = 200
  178. br.Success = true
  179. br.Msg = "获取成功"
  180. br.Data = resp
  181. }
  182. // VersionList
  183. // @Title 逻辑导图版本列表
  184. // @Description 逻辑导图版本列表接口
  185. // @Param PageSize query int true "每页数据条数"
  186. // @Param CurrentIndex query int true "当前页页码,从1开始"
  187. // @Param SandboxId query int true "沙盘id"
  188. // @Success 200 {object} response.SandboxVersionListResp
  189. // @router /version/list [get]
  190. func (this *SandboxController) VersionList() {
  191. br := new(models.BaseResponse).Init()
  192. defer func() {
  193. this.Data["json"] = br
  194. this.ServeJSON()
  195. }()
  196. sandboxId, _ := this.GetInt("SandboxId")
  197. keyWord := this.GetString("Keyword")
  198. pageSize, _ := this.GetInt("PageSize")
  199. currentIndex, _ := this.GetInt("CurrentIndex")
  200. var startSize int
  201. if pageSize <= 0 {
  202. pageSize = utils.PageSize20
  203. }
  204. //第一页需要返回的几条数据(目前是3条)
  205. startSize = paging.StartIndex(currentIndex, pageSize) + versionSize
  206. var condition string
  207. var pars []interface{}
  208. if sandboxId <= 0 {
  209. br.Msg = "参数错误,沙盘编号id必传!"
  210. br.ErrMsg = "参数错误,沙盘编号id必传"
  211. return
  212. }
  213. condition += " AND a.sandbox_id=? "
  214. pars = append(pars, sandboxId)
  215. //不能筛选出当前版本
  216. condition += " AND b.curr_version < a.curr_version "
  217. if keyWord != "" {
  218. condition += ` AND ( a.op_user_name LIKE ? OR a.name LIKE ? or a.op_user_name LIKE ? OR a.name LIKE ? )`
  219. pars = utils.GetLikeKeywordPars(pars, keyWord, 4)
  220. }
  221. //获取指标信息
  222. total, list, err := sandbox.GetVersionList(condition, pars, startSize, pageSize)
  223. if err != nil && err.Error() != utils.ErrNoRow() {
  224. br.Success = true
  225. br.Msg = "获取沙盘列表失败"
  226. br.ErrMsg = "获取沙盘列表失败,Err:" + err.Error()
  227. return
  228. }
  229. if list == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  230. list = make([]*sandbox.SandboxVersionListItem, 0)
  231. }
  232. for _, v := range list {
  233. v.ModifyTime = v.CreateTime
  234. /*key := fmt.Sprint(`crm:sandbox:edit:`, v.SandboxId)
  235. opUserId, _ := utils.Rc.RedisInt(key)
  236. //如果当前没有人操作,获取当前操作人是本人,那么编辑按钮可用
  237. if opUserId <= 0 || (opUserId == this.SysUser.AdminId) {
  238. v.CanEdit = true
  239. }*/
  240. markStatus, err := sandboxService.UpdateSandboxEditMark(v.SandboxId, this.SysUser.AdminId, 2, this.SysUser.RealName)
  241. if err != nil {
  242. br.Msg = "查询标记状态失败"
  243. br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  244. return
  245. }
  246. if markStatus.Status == 0 {
  247. v.CanEdit = true
  248. }
  249. }
  250. //过滤第一页的几条数据(目前是3条)
  251. total = total - versionSize
  252. if total <= 0 {
  253. total = 0
  254. }
  255. page := paging.GetPaging(currentIndex, pageSize, total)
  256. resp := response.SandboxVersionListResp{
  257. Paging: page,
  258. List: list,
  259. }
  260. br.Ret = 200
  261. br.Success = true
  262. br.Msg = "获取成功"
  263. br.Data = resp
  264. }
  265. //// Save
  266. //// @Title 新增/编辑保存沙盘
  267. //// @Description 新增/编辑保存沙盘接口
  268. //// @Param request body request.AddAndEditSandbox true "type json string"
  269. //// @Success 200 {object} sandbox.Sandbox
  270. //// @router /save [post]
  271. //func (this *SandboxController) Save() {
  272. // br := new(models.BaseResponse).Init()
  273. // defer func() {
  274. // this.Data["json"] = br
  275. // this.ServeJSON()
  276. // }()
  277. // sysUser := this.SysUser
  278. // if sysUser == nil {
  279. // br.Msg = "请登录"
  280. // br.ErrMsg = "请登录,SysUser Is Empty"
  281. // br.Ret = 408
  282. // return
  283. // }
  284. // var req request.AddAndEditSandbox
  285. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  286. // if err != nil {
  287. // br.Msg = "参数解析异常!"
  288. // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  289. // return
  290. // }
  291. //
  292. // var sandboxResp *sandbox.SandboxSaveResp
  293. // // 获取系统菜单, 如果没有对应的字段的特殊处理项, 则忽略必填
  294. // menus, e := system.GetSysMenuItemsByCondition(` AND hidden = 0`, make([]interface{}, 0), []string{}, ``)
  295. // if e != nil {
  296. // br.Msg = "保存失败"
  297. // br.ErrMsg = "获取菜单列表失败, Err: " + e.Error()
  298. // return
  299. // }
  300. // menuMap := make(map[string]bool)
  301. // for _, m := range menus {
  302. // if m.ButtonCode != "" {
  303. // menuMap[m.ButtonCode] = true
  304. // }
  305. // }
  306. // ignoreVariety := false
  307. // if !menuMap[system.MenuSpecialHandleSandboxVariety] {
  308. // ignoreVariety = true
  309. // }
  310. //
  311. // var errMsg string
  312. // if req.SandboxVersionCode == `` {
  313. // //新增沙盘
  314. // sandboxResp, err = sandboxService.AddSandbox(req, sysUser.AdminId, sysUser.RealName, ignoreVariety)
  315. // } else {
  316. // ////更新当前编辑中的状态缓存
  317. // //err = sandboxService.UpdateSandboxEditMark(req.SandboxId, sysUser.AdminId, 1)
  318. // //if err != nil {
  319. // // br.Msg = err.Error()
  320. // // return
  321. // //}
  322. //
  323. // //编辑沙盘
  324. // sandboxResp, err, errMsg = sandboxService.UpdateSandbox(req, sysUser.AdminId, sysUser.RealName, ignoreVariety)
  325. // }
  326. // if err != nil {
  327. // br.Msg = "保存失败!"
  328. // if errMsg != `` {
  329. // br.Msg = errMsg
  330. // }
  331. // br.ErrMsg = "保存失败,Err:" + err.Error()
  332. // return
  333. // }
  334. //
  335. // msg := "保存成功"
  336. // br.Ret = 200
  337. // br.Success = true
  338. // br.Msg = msg
  339. // br.Data = sandboxResp
  340. //}
  341. // AddSandboxDraft
  342. // @Title 添加沙盘草稿
  343. // @Description 添加沙盘草稿接口
  344. // @Param request body request.AddAndEditSandbox true "type json string"
  345. // @Success 200 {object} sandbox.SandboxDraft
  346. // @Fail 202 另外的人在操作,不要重复添加草稿;204 错误了,当时不是必要性的错误,不用将错误信息暴露给用户
  347. // @router /draft/add [post]
  348. func (this *SandboxController) AddSandboxDraft() {
  349. br := new(models.BaseResponse).Init()
  350. br.IsSendEmail = false
  351. defer func() {
  352. this.Data["json"] = br
  353. this.ServeJSON()
  354. }()
  355. sysUser := this.SysUser
  356. if sysUser == nil {
  357. br.Msg = "请登录"
  358. br.ErrMsg = "请登录,SysUser Is Empty"
  359. br.Ret = 408
  360. return
  361. }
  362. var req request.AddAndEditSandbox
  363. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  364. if err != nil {
  365. br.Msg = "参数解析异常!"
  366. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  367. return
  368. }
  369. if req.SandboxVersionCode == `` {
  370. br.Msg = "请传入沙盘版本!"
  371. return
  372. }
  373. // 获取沙盘版本信息
  374. sandboxVersion, err := sandbox.GetSandboxVersionBySandboxVersionCode(req.SandboxVersionCode)
  375. if err != nil {
  376. if err.Error() == utils.ErrNoRow() {
  377. br.Msg = "找不到该版本!"
  378. br.ErrMsg = "找不到该版本"
  379. return
  380. }
  381. br.Msg = "找不到该版本!"
  382. br.ErrMsg = "找不到该版本,Err:" + err.Error()
  383. br.IsSendEmail = false
  384. return
  385. }
  386. //更新标记key
  387. markStatus, err := sandboxService.UpdateSandboxEditMark(sandboxVersion.SandboxId, sysUser.AdminId, 1, sysUser.RealName)
  388. if err != nil {
  389. br.Msg = err.Error()
  390. return
  391. }
  392. if markStatus.Status == 1 {
  393. br.Msg = markStatus.Msg
  394. return
  395. }
  396. //新增沙盘草稿
  397. sandboxDraftInfo, err := sandboxService.AddSandboxDraft(sandboxVersion.SandboxId, req, sysUser.AdminId, sysUser.RealName)
  398. if err != nil {
  399. br.Msg = "保存失败!"
  400. br.ErrMsg = "保存失败,Err:" + err.Error()
  401. br.Ret = 204 //204 (无内容) :服务器成功处理了请求,但没有返回任何内容。
  402. return
  403. }
  404. msg := "保存成功"
  405. br.Ret = 200
  406. br.Success = true
  407. br.Msg = msg
  408. br.Data = sandboxDraftInfo
  409. }
  410. // MarkEditStatus
  411. // @Title 标记沙盘编辑状态
  412. // @Description 标记沙盘编辑状态接口
  413. // @Param request body request.MarkEditSandbox true "type json string"
  414. // @Success 200 标记成功 ;202 标记成功
  415. // @router /mark [post]
  416. func (this *SandboxController) MarkEditStatus() {
  417. br := new(models.BaseResponse).Init()
  418. defer func() {
  419. this.Data["json"] = br
  420. this.ServeJSON()
  421. }()
  422. sysUser := this.SysUser
  423. if sysUser == nil {
  424. br.Msg = "请登录"
  425. br.ErrMsg = "请登录,SysUser Is Empty"
  426. br.Ret = 408
  427. return
  428. }
  429. var req request.MarkEditSandbox
  430. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  431. if err != nil {
  432. br.Msg = "参数解析异常!"
  433. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  434. return
  435. }
  436. if req.SandboxId <= 0 {
  437. br.Msg = "缺少沙盘编号"
  438. return
  439. }
  440. if req.Status <= 0 {
  441. br.Msg = "标记状态异常"
  442. return
  443. }
  444. //更新标记key
  445. data, err := sandboxService.UpdateSandboxEditMark(req.SandboxId, sysUser.AdminId, req.Status, sysUser.RealName)
  446. if err != nil {
  447. br.Msg = err.Error()
  448. return
  449. }
  450. msg := "标记成功"
  451. br.Ret = 200
  452. br.Success = true
  453. br.Msg = msg
  454. br.Data = data
  455. }
  456. // GetSandboxVersionDetail
  457. // @Title 获取沙盘版本数据详情(已保存的)
  458. // @Description 获取沙盘版本数据详情接口(已保存的)
  459. // @Param SandboxVersionCode query string true "沙盘版本code"
  460. // @Success 200 {object} sandbox.SandboxVersion
  461. // @router /version/detail [get]
  462. func (this *SandboxController) GetSandboxVersionDetail() {
  463. br := new(models.BaseResponse).Init()
  464. defer func() {
  465. this.Data["json"] = br
  466. this.ServeJSON()
  467. }()
  468. sysUser := this.SysUser
  469. if sysUser == nil {
  470. br.Msg = "请登录"
  471. br.ErrMsg = "请登录,SysUser Is Empty"
  472. br.Ret = 408
  473. return
  474. }
  475. sandboxVersionCode := this.GetString("SandboxVersionCode")
  476. if sandboxVersionCode == "" {
  477. br.Msg = "缺少沙盘版本编号"
  478. return
  479. }
  480. //获取沙盘数据详情(已保存的)
  481. sandboxVersionInfo, err := sandboxService.GetSandboxVersionDetailByCode(sandboxVersionCode)
  482. if err != nil {
  483. br.Msg = "获取失败"
  484. br.ErrMsg = "获取失败,Err:" + err.Error()
  485. return
  486. }
  487. msg := "获取成功"
  488. br.Ret = 200
  489. br.Success = true
  490. br.Msg = msg
  491. br.Data = sandboxVersionInfo
  492. }
  493. // GetLastSandboxInfo
  494. // @Title 获取最后一次编辑的沙盘数据详情
  495. // @Description 获取最后一次编辑的沙盘数据详情接口
  496. // @Param SandboxId query int true "沙盘编号id"
  497. // @Success 200 {object} sandbox.Sandbox
  498. // @router /last_info [get]
  499. func (this *SandboxController) GetLastSandboxInfo() {
  500. br := new(models.BaseResponse).Init()
  501. defer func() {
  502. this.Data["json"] = br
  503. this.ServeJSON()
  504. }()
  505. sysUser := this.SysUser
  506. if sysUser == nil {
  507. br.Msg = "请登录"
  508. br.ErrMsg = "请登录,SysUser Is Empty"
  509. br.Ret = 408
  510. return
  511. }
  512. sandboxId, _ := this.GetInt("SandboxId", 0)
  513. if sandboxId <= 0 {
  514. br.Msg = "缺少沙盘编号"
  515. return
  516. }
  517. //获取最后一次操作的沙盘数据
  518. sandboxInfo, err := sandboxService.GetLastSandboxInfo(sandboxId)
  519. if err != nil {
  520. br.Msg = err.Error()
  521. return
  522. }
  523. msg := "获取成功"
  524. br.Ret = 200
  525. br.Success = true
  526. br.Msg = msg
  527. br.Data = sandboxInfo
  528. }
  529. // Delete
  530. // @Title 删除沙盘
  531. // @Description 删除沙盘接口
  532. // @Param request body request.DeleteSandbox true "type json string"
  533. // @Success 200 标记成功
  534. // @router /delete [post]
  535. func (this *SandboxController) Delete() {
  536. br := new(models.BaseResponse).Init()
  537. defer func() {
  538. this.Data["json"] = br
  539. this.ServeJSON()
  540. }()
  541. sysUser := this.SysUser
  542. if sysUser == nil {
  543. br.Msg = "请登录"
  544. br.ErrMsg = "请登录,SysUser Is Empty"
  545. br.Ret = 408
  546. return
  547. }
  548. var req request.DeleteSandbox
  549. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  550. if err != nil {
  551. br.Msg = "参数解析异常!"
  552. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  553. return
  554. }
  555. if req.SandboxId <= 0 {
  556. br.Msg = "缺少沙盘编号"
  557. return
  558. }
  559. /*key := fmt.Sprint(`crm:sandbox:edit:`, req.SandboxId)
  560. opUserId, _ := utils.Rc.RedisInt(key)
  561. //如果当前有人操作,且获取当前操作人不是本人,那么不允许删除
  562. if opUserId > 0 && opUserId != this.SysUser.AdminId {
  563. br.Msg = "当前有其他人正在编辑,不允许删除该沙盘"
  564. return
  565. }*/
  566. markStatus, err := sandboxService.UpdateSandboxEditMark(req.SandboxId, this.SysUser.AdminId, 2, this.SysUser.RealName)
  567. if err != nil {
  568. br.Msg = "查询标记状态失败"
  569. br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  570. return
  571. }
  572. if markStatus.Status == 1 {
  573. br.Msg = fmt.Sprintf("当前%s正在编辑,不允许删除该沙盘", markStatus.Editor)
  574. return
  575. }
  576. //删除沙盘
  577. err = sandboxService.DeleteSandbox(req.SandboxId)
  578. if err != nil {
  579. br.Msg = err.Error()
  580. return
  581. }
  582. msg := "删除成功"
  583. br.Ret = 200
  584. br.Success = true
  585. br.Msg = msg
  586. }
  587. //// DeleteVersion
  588. //// @Title 删除沙盘版本
  589. //// @Description 删除沙盘版本接口
  590. //// @Param request body request.DeleteSandbox true "type json string"
  591. //// @Success 200 标记成功
  592. //// @router /version/delete [post]
  593. //func (this *SandboxController) DeleteVersion() {
  594. // br := new(models.BaseResponse).Init()
  595. // defer func() {
  596. // this.Data["json"] = br
  597. // this.ServeJSON()
  598. // }()
  599. // sysUser := this.SysUser
  600. // if sysUser == nil {
  601. // br.Msg = "请登录"
  602. // br.ErrMsg = "请登录,SysUser Is Empty"
  603. // br.Ret = 408
  604. // return
  605. // }
  606. // var req request.DeleteSandboxVersion
  607. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  608. // if err != nil {
  609. // br.Msg = "参数解析异常!"
  610. // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  611. // return
  612. // }
  613. //
  614. // if req.SandboxVersionCode == `` {
  615. // br.Msg = "缺少沙盘版本号"
  616. // return
  617. // }
  618. // //删除沙盘
  619. // err, errMsg := sandboxService.DeleteSandboxVersion(req.SandboxVersionCode, this.SysUser.AdminId)
  620. // if err != nil {
  621. // br.Msg = "删除版本失败"
  622. // if errMsg != `` {
  623. // br.Msg = errMsg
  624. // }
  625. // br.ErrMsg = err.Error()
  626. // return
  627. // }
  628. //
  629. // msg := "删除成功"
  630. // br.Ret = 200
  631. // br.Success = true
  632. // br.Msg = msg
  633. //}
  634. //// ResetDraftToLastVersion
  635. //// @Title 重置沙盘草稿至最新版本
  636. //// @Description 重置沙盘草稿至最新版本接口
  637. //// @Param request body request.DeleteSandbox true "type json string"
  638. //// @Success 200 {object} sandbox.SandboxDraft
  639. //// @Fail 202 另外的人在操作,不要重复添加草稿;204 错误了,当时不是必要性的错误,不用将错误信息暴露给用户
  640. //// @router /draft/reset [post]
  641. //func (this *SandboxController) ResetDraftToLastVersion() {
  642. // br := new(models.BaseResponse).Init()
  643. // defer func() {
  644. // this.Data["json"] = br
  645. // this.ServeJSON()
  646. // }()
  647. // sysUser := this.SysUser
  648. // if sysUser == nil {
  649. // br.Msg = "请登录"
  650. // br.ErrMsg = "请登录,SysUser Is Empty"
  651. // br.Ret = 408
  652. // return
  653. // }
  654. // var req request.DeleteSandbox
  655. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  656. // if err != nil {
  657. // br.Msg = "参数解析异常!"
  658. // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  659. // return
  660. // }
  661. //
  662. // if req.SandboxId <= 0 {
  663. // br.Msg = "缺少沙盘编号"
  664. // return
  665. // }
  666. //
  667. // //更新标记key
  668. // markStatus, err := sandboxService.UpdateSandboxEditMark(req.SandboxId, sysUser.AdminId, 0, sysUser.RealName)
  669. // if err != nil {
  670. // br.Msg = err.Error()
  671. // return
  672. // }
  673. // if markStatus.Status == 1 {
  674. // br.Msg = markStatus.Msg
  675. // return
  676. // }
  677. //
  678. // //重置沙盘草稿至最新版本
  679. // sandboxDraftInfo, err := sandboxService.ResetDraftToLastVersion(req.SandboxId, sysUser.AdminId, sysUser.RealName)
  680. // if err != nil {
  681. // br.Msg = "保存失败!"
  682. // br.ErrMsg = "保存失败,Err:" + err.Error()
  683. // return
  684. // }
  685. // msg := "保存成功"
  686. // br.Ret = 200
  687. // br.Success = true
  688. // br.Msg = msg
  689. // br.Data = sandboxDraftInfo
  690. //}
  691. // ListByQuote
  692. // @Title 逻辑导图列表(其他地方引用到的,莫名其妙要根据输入的关键字匹配品种)
  693. // @Description 逻辑导图列表接口(其他地方引用到的,莫名其妙要根据输入的关键字匹配品种)
  694. // @Param PageSize query int true "每页数据条数"
  695. // @Param CurrentIndex query int true "当前页页码,从1开始"
  696. // @Param ChartPermissionId query int true "权限编号id"
  697. // @Param Keyword query string false "搜索关键词:沙盘名称/编辑人名称"
  698. // @Success 200 {object} response.SandboxListResp
  699. // @router /list_by_quote [get]
  700. func (this *SandboxController) ListByQuote() {
  701. br := new(models.BaseResponse).Init()
  702. defer func() {
  703. this.Data["json"] = br
  704. this.ServeJSON()
  705. }()
  706. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  707. keyword := this.GetString("Keyword")
  708. pageSize, _ := this.GetInt("PageSize")
  709. currentIndex, _ := this.GetInt("CurrentIndex")
  710. var startSize int
  711. if pageSize <= 0 {
  712. pageSize = utils.PageSize20
  713. }
  714. if currentIndex <= 0 {
  715. currentIndex = 1
  716. }
  717. startSize = paging.StartIndex(currentIndex, pageSize)
  718. var condition string
  719. var pars []interface{}
  720. if chartPermissionId > 0 {
  721. condition += " AND a.chart_permission_id=? "
  722. pars = append(pars, chartPermissionId)
  723. }
  724. if keyword != "" {
  725. condition += ` AND ( a.name LIKE ? OR b.name LIKE ? OR a.chart_permission_name LIKE ? )`
  726. pars = utils.GetLikeKeywordPars(pars, keyword, 3)
  727. }
  728. //获取指标信息
  729. total, list, err := sandbox.GetList(condition, pars, startSize, pageSize)
  730. if err != nil && err.Error() != utils.ErrNoRow() {
  731. br.Success = true
  732. br.Msg = "获取沙盘列表失败"
  733. br.ErrMsg = "获取沙盘列表失败,Err:" + err.Error()
  734. return
  735. }
  736. if list == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  737. list = make([]*sandbox.SandboxListItem, 0)
  738. }
  739. page := paging.GetPaging(currentIndex, pageSize, total)
  740. resp := response.SandboxListResp{
  741. Paging: page,
  742. List: list,
  743. }
  744. br.Ret = 200
  745. br.Success = true
  746. br.Msg = "获取成功"
  747. br.Data = resp
  748. }
  749. // SandboxClassifyItems
  750. // @Title 获取所有沙盘分类接口-包含沙盘
  751. // @Description 获取所有沙盘分类接口-包含沙盘
  752. // @Param IsShowMe query bool true "是否只看我的,true、false"
  753. // @Success 200 {object} data_manage.ChartClassifyListResp
  754. // @router /classify/list [get]
  755. func (this *SandboxController) SandboxClassifyItems() {
  756. br := new(models.BaseResponse).Init()
  757. defer func() {
  758. this.Data["json"] = br
  759. this.ServeJSON()
  760. }()
  761. resp := new(sandbox.SandboxClassifyListResp)
  762. sandboxClassifyId, _ := this.GetInt("SandboxClassifyId")
  763. isShowMe, _ := this.GetBool("IsShowMe")
  764. if isShowMe {
  765. errMsg, err := sandboxService.GetSandboxClassifyListForMe(*this.SysUser, resp, sandboxClassifyId)
  766. if err != nil {
  767. br.Msg = errMsg
  768. br.ErrMsg = err.Error()
  769. return
  770. }
  771. // 移除没有权限的图表
  772. //allNodes := sandboxService.HandleNoPermissionSandbox(resp.AllNodes, nil)
  773. //resp.AllNodes = allNodes
  774. br.Ret = 200
  775. br.Success = true
  776. br.Msg = "获取成功"
  777. br.Data = resp
  778. fmt.Println("source my classify")
  779. return
  780. }
  781. rootList, err := sandbox.GetSandboxClassifyAndInfoByParentId(sandboxClassifyId)
  782. if err != nil && err.Error() != utils.ErrNoRow() {
  783. br.Msg = "获取失败"
  784. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  785. return
  786. }
  787. classifyAll, err := sandbox.GetSandboxClassifyAndInfoByParentId(sandboxClassifyId)
  788. if err != nil && err.Error() != utils.ErrNoRow() {
  789. br.Msg = "获取失败"
  790. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  791. return
  792. }
  793. //sandboxAll, err := sandbox.GetSandboxItemsByClassifyId(sandboxClassifyId)
  794. //if err != nil && err.Error() != utils.ErrNoRow() {
  795. // br.Msg = "获取失败"
  796. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  797. // return
  798. //}
  799. //sandListMap := make(map[int][]*sandbox.SandboxClassifyItems)
  800. //for _, v := range sandboxAll {
  801. // if _, ok := sandListMap[v.SandboxClassifyId]; !ok {
  802. // list := make([]*sandbox.SandboxClassifyItems, 0)
  803. // list = append(list, v)
  804. // sandListMap[v.SandboxClassifyId] = list
  805. // } else {
  806. // sandListMap[v.SandboxClassifyId] = append(sandListMap[v.SandboxClassifyId], v)
  807. // }
  808. //}
  809. nodeAll := make([]*sandbox.SandboxClassifyItems, 0)
  810. for k := range rootList {
  811. rootNode := rootList[k]
  812. sandboxService.SandboxClassifyItemsMakeTreeV2(this.SysUser, classifyAll, rootNode)
  813. nodeAll = append(nodeAll, rootNode)
  814. }
  815. //newAll := sandboxService.SandboxItemsMakeTree(nodeAll, sandListMap, sandboxClassifyId)
  816. resp.AllNodes = nodeAll
  817. br.Ret = 200
  818. br.Success = true
  819. br.Msg = "获取成功"
  820. br.Data = resp
  821. }
  822. // @Title 新增沙盘分类
  823. // @Description 新增沙盘分类接口
  824. // @Param request body data_manage.AddChartClassifyReq true "type json string"
  825. // @Success 200 Ret=200 保存成功
  826. // @router /classify/add [post]
  827. func (this *SandboxController) AddSandboxClassify() {
  828. br := new(models.BaseResponse).Init()
  829. defer func() {
  830. this.Data["json"] = br
  831. this.ServeJSON()
  832. }()
  833. var req sandbox.AddSandboxClassifyReq
  834. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  835. if err != nil {
  836. br.Msg = "参数解析异常!"
  837. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  838. return
  839. }
  840. if req.SandboxClassifyName == "" {
  841. br.Msg = "请输入分类名称"
  842. br.IsSendEmail = false
  843. return
  844. }
  845. if req.ParentId < 0 {
  846. br.Msg = "参数错误"
  847. br.IsSendEmail = false
  848. return
  849. }
  850. count, err := sandbox.GetSandboxClassifyCount(req.SandboxClassifyName, req.ParentId)
  851. if err != nil {
  852. br.Msg = "判断名称是否已存在失败"
  853. br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  854. return
  855. }
  856. if count > 0 {
  857. br.Msg = "分类名称已存在,请重新输入"
  858. br.IsSendEmail = false
  859. return
  860. }
  861. //获取该层级下最大的排序数
  862. maxSort, err := sandbox.GetSandboxClassifyMaxSort(req.ParentId)
  863. classify := new(sandbox.SandboxClassify)
  864. classify.ParentId = req.ParentId
  865. classify.SandboxClassifyName = req.SandboxClassifyName
  866. classify.HasData = 0
  867. classify.CreateTime = time.Now()
  868. classify.ModifyTime = time.Now()
  869. classify.SysUserId = this.SysUser.AdminId
  870. classify.SysUserRealName = this.SysUser.RealName
  871. classify.ChartPermissionId = req.ChartPermissionId
  872. classify.ChartPermissionName = req.ChartPermissionName
  873. classify.Level = req.Level + 1
  874. classify.Sort = maxSort + 1
  875. _, err = sandbox.AddSandboxClassify(classify)
  876. if err != nil {
  877. br.Msg = "保存分类失败"
  878. br.ErrMsg = "保存分类失败,Err:" + err.Error()
  879. return
  880. }
  881. br.Ret = 200
  882. br.Msg = "保存成功"
  883. br.Success = true
  884. }
  885. // @Title 修改沙盘分类
  886. // @Description 修改沙盘分类接口
  887. // @Param request body data_manage.EditChartClassifyReq true "type json string"
  888. // @Success 200 Ret=200 修改成功
  889. // @router /classify/edit [post]
  890. func (this *SandboxController) EditSandboxClassify() {
  891. br := new(models.BaseResponse).Init()
  892. defer func() {
  893. this.Data["json"] = br
  894. this.ServeJSON()
  895. }()
  896. var req sandbox.EditSandboxClassifyReq
  897. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  898. if err != nil {
  899. br.Msg = "参数解析异常!"
  900. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  901. return
  902. }
  903. if req.SandboxClassifyName == "" {
  904. br.Msg = "请输入分类名称"
  905. br.IsSendEmail = false
  906. return
  907. }
  908. if req.SandboxClassifyId <= 0 {
  909. br.Msg = "参数错误"
  910. br.IsSendEmail = false
  911. return
  912. }
  913. item, err := sandbox.GetSandboxClassifyById(req.SandboxClassifyId)
  914. if err != nil {
  915. br.Msg = "保存失败"
  916. br.Msg = "获取分类信息失败,Err:" + err.Error()
  917. return
  918. }
  919. if item.SandboxClassifyName != req.SandboxClassifyName {
  920. count, err := sandbox.GetSandboxClassifyCount(req.SandboxClassifyName, item.ParentId)
  921. if err != nil {
  922. br.Msg = "判断名称是否已存在失败"
  923. br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  924. return
  925. }
  926. if count > 0 {
  927. br.Msg = "分类名称已存在,请重新输入"
  928. br.IsSendEmail = false
  929. return
  930. }
  931. err = sandbox.EditSandboxClassify(req.SandboxClassifyId, req.SandboxClassifyName)
  932. if err != nil {
  933. br.Msg = "保存失败"
  934. br.ErrMsg = "保存失败,Err:" + err.Error()
  935. return
  936. }
  937. }
  938. br.Ret = 200
  939. br.Msg = "保存成功"
  940. br.Success = true
  941. br.IsAddLog = true
  942. }
  943. // @Title 删除沙盘检测接口
  944. // @Description 删除沙盘检测接口
  945. // @Param request body data_manage.ChartClassifyDeleteCheckResp true "type json string"
  946. // @Success 200 Ret=200 检测成功
  947. // @router /classify/delete/check [post]
  948. func (this *SandboxController) DeleteSandboxClassifyCheck() {
  949. br := new(models.BaseResponse).Init()
  950. defer func() {
  951. this.Data["json"] = br
  952. this.ServeJSON()
  953. }()
  954. var req sandbox.SandboxClassifyDeleteCheckReq
  955. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  956. if err != nil {
  957. br.Msg = "参数解析异常!"
  958. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  959. return
  960. }
  961. if req.SandboxClassifyId < 0 {
  962. br.Msg = "参数错误"
  963. br.IsSendEmail = false
  964. return
  965. }
  966. var deleteStatus int
  967. var tipsMsg string
  968. //删除分类
  969. if req.SandboxClassifyId > 0 {
  970. //判断沙盘分类下,是否含有沙盘
  971. count, err := sandbox.GetSandboxInfoCountByClassifyId(req.SandboxClassifyId)
  972. if err != nil {
  973. br.Msg = "删除失败"
  974. br.ErrMsg = "分类下是否含有指标失败,Err:" + err.Error()
  975. return
  976. }
  977. if count > 0 {
  978. deleteStatus = 1
  979. tipsMsg = "该分类下关联沙盘不可删除"
  980. }
  981. }
  982. if deleteStatus != 1 {
  983. classifyCount, err := sandbox.GetSandboxInfoCountByClassifyId(req.SandboxClassifyId)
  984. if err != nil && err.Error() != utils.ErrNoRow() {
  985. br.Msg = "删除失败"
  986. br.ErrMsg = "分类下是否含有沙盘失败,Err:" + err.Error()
  987. return
  988. }
  989. if classifyCount > 0 {
  990. deleteStatus = 2
  991. tipsMsg = "确认删除当前目录及包含的子目录吗"
  992. }
  993. }
  994. if deleteStatus == 0 {
  995. tipsMsg = "可删除,进行删除操作"
  996. }
  997. resp := new(sandbox.SandboxClassifyDeleteCheckResp)
  998. resp.DeleteStatus = deleteStatus
  999. resp.TipsMsg = tipsMsg
  1000. br.Ret = 200
  1001. br.Msg = "检测成功"
  1002. br.Success = true
  1003. br.Data = resp
  1004. }
  1005. // @Title 删除沙盘分类/沙盘
  1006. // @Description 删除沙盘分类/沙盘接口
  1007. // @Param request body data_manage.DeleteChartClassifyReq true "type json string"
  1008. // @Success 200 Ret=200 删除成功
  1009. // @router /classify/delete [post]
  1010. func (this *SandboxController) DeleteSandboxClassify() {
  1011. br := new(models.BaseResponse).Init()
  1012. defer func() {
  1013. this.Data["json"] = br
  1014. this.ServeJSON()
  1015. }()
  1016. sysUser := this.SysUser
  1017. if sysUser == nil {
  1018. br.Msg = "请登录"
  1019. br.ErrMsg = "请登录,SysUser Is Empty"
  1020. br.Ret = 408
  1021. return
  1022. }
  1023. var req sandbox.DeleteSandboxClassifyReq
  1024. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1025. if err != nil {
  1026. br.Msg = "参数解析异常!"
  1027. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1028. return
  1029. }
  1030. if req.SandboxClassifyId < 0 && req.SandboxId <= 0 {
  1031. br.Msg = "参数错误"
  1032. br.IsSendEmail = false
  1033. return
  1034. }
  1035. //删除分类
  1036. if req.SandboxClassifyId > 0 && req.SandboxId == 0 {
  1037. //判断是否含有指标
  1038. count, err := sandbox.GetSandboxInfoCountByClassifyId(req.SandboxId)
  1039. if err != nil && err.Error() != utils.ErrNoRow() {
  1040. br.Msg = "删除失败"
  1041. br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  1042. return
  1043. }
  1044. if count > 0 {
  1045. br.Msg = "该目录下存在关联指标,不可删除"
  1046. br.IsSendEmail = false
  1047. return
  1048. }
  1049. err = sandbox.DeleteSandboxClassify(req.SandboxClassifyId)
  1050. if err != nil {
  1051. br.Msg = "删除失败"
  1052. br.ErrMsg = "删除失败,Err:" + err.Error()
  1053. return
  1054. }
  1055. }
  1056. //删除沙盘
  1057. if req.SandboxId > 0 {
  1058. sandboxInfo, err := sandbox.GetSandboxById(req.SandboxId)
  1059. if err != nil {
  1060. if err.Error() == utils.ErrNoRow() {
  1061. br.Msg = "沙盘已删除,请刷新页面"
  1062. br.ErrMsg = "指标不存在,Err:" + err.Error()
  1063. return
  1064. } else {
  1065. br.Msg = "删除失败"
  1066. br.ErrMsg = "删除失败,获取指标信息失败,Err:" + err.Error()
  1067. return
  1068. }
  1069. }
  1070. if sandboxInfo == nil {
  1071. br.Msg = "沙盘已删除,请刷新页面"
  1072. return
  1073. }
  1074. err = sandboxService.DeleteSandbox(req.SandboxId)
  1075. if err != nil {
  1076. br.Msg = err.Error()
  1077. return
  1078. }
  1079. }
  1080. br.Ret = 200
  1081. br.Msg = "删除成功"
  1082. br.Success = true
  1083. br.IsAddLog = true
  1084. }
  1085. // ChartClassifyMove
  1086. // @Title 沙盘分类移动接口
  1087. // @Description 沙盘分类移动接口
  1088. // @Success 200 {object} data_manage.MoveChartClassifyReq
  1089. // @router /classify/move [post]
  1090. func (this *SandboxController) ChartClassifyMove() {
  1091. br := new(models.BaseResponse).Init()
  1092. defer func() {
  1093. this.Data["json"] = br
  1094. this.ServeJSON()
  1095. }()
  1096. sysUser := this.SysUser
  1097. if sysUser == nil {
  1098. br.Msg = "请登录"
  1099. br.ErrMsg = "请登录,SysUser Is Empty"
  1100. br.Ret = 408
  1101. return
  1102. }
  1103. var req sandbox.MoveSandboxClassifyReq
  1104. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1105. if err != nil {
  1106. br.Msg = "参数解析异常!"
  1107. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1108. return
  1109. }
  1110. if req.ClassifyId <= 0 {
  1111. br.Msg = "参数错误"
  1112. br.ErrMsg = "分类id小于等于0"
  1113. return
  1114. }
  1115. //判断分类是否存在
  1116. sandboxClassifyInfo, err := sandbox.GetSandboxClassifyById(req.ClassifyId)
  1117. if err != nil {
  1118. br.Msg = "移动失败"
  1119. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  1120. return
  1121. }
  1122. updateCol := make([]string, 0)
  1123. //判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
  1124. if sandboxClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId != 0 {
  1125. parentChartClassifyInfo, err := sandbox.GetSandboxClassifyById(req.ParentClassifyId)
  1126. if err != nil {
  1127. br.Msg = "移动失败"
  1128. br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error()
  1129. return
  1130. }
  1131. sandboxClassifyInfo.ParentId = parentChartClassifyInfo.SandboxClassifyId
  1132. sandboxClassifyInfo.Level = parentChartClassifyInfo.Level + 1
  1133. sandboxClassifyInfo.ModifyTime = time.Now()
  1134. updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  1135. } else if sandboxClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId == 0 {
  1136. //改为一级分类
  1137. sandboxClassifyInfo.ParentId = req.ParentClassifyId
  1138. sandboxClassifyInfo.Level = 1
  1139. sandboxClassifyInfo.ModifyTime = time.Now()
  1140. updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  1141. }
  1142. //如果有传入 上一个兄弟节点分类id
  1143. if req.PrevClassifyId > 0 {
  1144. //上一个兄弟节点
  1145. prevClassify, err := sandbox.GetSandboxClassifyById(req.PrevClassifyId)
  1146. if err != nil {
  1147. br.Msg = "移动失败"
  1148. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  1149. return
  1150. }
  1151. //如果是移动在两个兄弟节点之间
  1152. if req.NextClassifyId > 0 {
  1153. //下一个兄弟节点
  1154. nextClassify, err := sandbox.GetSandboxClassifyById(req.NextClassifyId)
  1155. if err != nil {
  1156. br.Msg = "移动失败"
  1157. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  1158. return
  1159. }
  1160. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  1161. if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == sandboxClassifyInfo.Sort {
  1162. //变更兄弟节点的排序
  1163. updateSortStr := `sort + 2`
  1164. _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, prevClassify.SandboxClassifyId, prevClassify.Sort, updateSortStr)
  1165. } else {
  1166. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  1167. if nextClassify.Sort-prevClassify.Sort == 1 {
  1168. //变更兄弟节点的排序
  1169. updateSortStr := `sort + 1`
  1170. _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr)
  1171. }
  1172. }
  1173. }
  1174. sandboxClassifyInfo.Sort = prevClassify.Sort + 1
  1175. sandboxClassifyInfo.ModifyTime = time.Now()
  1176. updateCol = append(updateCol, "Sort", "ModifyTime")
  1177. } else {
  1178. firstClassify, err := sandbox.GetFirstSandboxClassifyByParentId(sandboxClassifyInfo.ParentId)
  1179. if err != nil && err.Error() != utils.ErrNoRow() {
  1180. br.Msg = "移动失败"
  1181. br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  1182. return
  1183. }
  1184. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  1185. if firstClassify != nil && firstClassify.Sort == 0 {
  1186. updateSortStr := ` sort + 1 `
  1187. _ = sandbox.UpdateSandboxClassifySortByParentId(firstClassify.ParentId, firstClassify.SandboxClassifyId-1, 0, updateSortStr)
  1188. }
  1189. sandboxClassifyInfo.Sort = 0 //那就是排在第一位
  1190. sandboxClassifyInfo.ModifyTime = time.Now()
  1191. updateCol = append(updateCol, "Sort", "ModifyTime")
  1192. }
  1193. //更新
  1194. if len(updateCol) > 0 {
  1195. err = sandboxClassifyInfo.Update(updateCol)
  1196. if err != nil {
  1197. br.Msg = "移动失败"
  1198. br.ErrMsg = "修改失败,Err:" + err.Error()
  1199. return
  1200. }
  1201. }
  1202. br.Ret = 200
  1203. br.Success = true
  1204. br.Msg = "移动成功"
  1205. }
  1206. // @Title ETA图表列表接口
  1207. // @Description ETA图表列表接口
  1208. // @Param PageSize query int true "每页数据条数"
  1209. // @Param CurrentIndex query int true "当前页页码,从1开始"
  1210. // @Param ChartClassifyId query int true "分类id"
  1211. // @Param KeyWord query string true "搜索关键词"
  1212. // @Param IsShowMe query bool true "是否只看我的,true、false"
  1213. // @Success 200 {object} data_manage.ChartListResp
  1214. // @router /listV2 [get]
  1215. func (this *SandboxController) ListV2() {
  1216. br := new(models.BaseResponse).Init()
  1217. defer func() {
  1218. this.Data["json"] = br
  1219. this.ServeJSON()
  1220. }()
  1221. sysUser := this.SysUser
  1222. if sysUser == nil {
  1223. br.Msg = "请登录"
  1224. br.ErrMsg = "请登录,SysUser Is Empty"
  1225. br.Ret = 408
  1226. return
  1227. }
  1228. sandboxClassifyId, _ := this.GetInt("SandboxClassifyId")
  1229. pageSize, _ := this.GetInt("PageSize")
  1230. currentIndex, _ := this.GetInt("CurrentIndex")
  1231. keyWord := this.GetString("KeyWord")
  1232. var total int
  1233. page := paging.GetPaging(currentIndex, pageSize, total)
  1234. var startSize int
  1235. if pageSize <= 0 {
  1236. pageSize = utils.PageSize20
  1237. }
  1238. if currentIndex <= 0 {
  1239. currentIndex = 1
  1240. }
  1241. startSize = paging.StartIndex(currentIndex, pageSize)
  1242. var condition string
  1243. var pars []interface{}
  1244. if sandboxClassifyId > 0 {
  1245. sandboxClassifyId, err := sandbox.GetSandboxClassify(sandboxClassifyId)
  1246. if err != nil && err.Error() != utils.ErrNoRow() {
  1247. br.Msg = "获取图表信息失败"
  1248. br.ErrMsg = "获取信息失败,GetChartClassify,Err:" + err.Error()
  1249. return
  1250. }
  1251. condition += " AND sandbox_classify_id IN(" + sandboxClassifyId + ") "
  1252. //pars = append(pars, chartClassifyId)
  1253. }
  1254. if keyWord != "" {
  1255. condition += ` AND ( name LIKE '%` + keyWord + `%' )`
  1256. }
  1257. //只看我的
  1258. isShowMe, _ := this.GetBool("IsShowMe")
  1259. if isShowMe {
  1260. condition += ` AND sys_user_id = ? `
  1261. pars = append(pars, sysUser.AdminId)
  1262. }
  1263. //获取图表信息
  1264. condition += ` AND is_delete = 0 `
  1265. list, err := sandbox.GetSandboxListByCondition(condition, pars, startSize, pageSize)
  1266. if err != nil && err.Error() != utils.ErrNoRow() {
  1267. br.Success = true
  1268. br.Msg = "获取沙盘信息失败"
  1269. br.ErrMsg = "获取沙盘信息失败,Err:" + err.Error()
  1270. return
  1271. }
  1272. for i, v := range list {
  1273. ids, err := sandbox.GetSandboxAllParentByClassifyId(v.SandboxClassifyId)
  1274. if err != nil {
  1275. br.Msg = "获取父级信息错误!"
  1276. br.ErrMsg = "获取父级信息错误,Err:" + err.Error()
  1277. return
  1278. }
  1279. list[i].ParentIds = ids
  1280. }
  1281. resp := new(sandbox.SandboxListResp)
  1282. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  1283. items := make([]*sandbox.SandboxListItems, 0)
  1284. resp.Paging = page
  1285. resp.List = items
  1286. br.Ret = 200
  1287. br.Success = true
  1288. br.Msg = "获取成功"
  1289. return
  1290. }
  1291. dataCount, err := sandbox.GetSandboxListCountByCondition(condition, pars)
  1292. if err != nil && err.Error() != utils.ErrNoRow() {
  1293. br.Msg = "获取指标信息失败"
  1294. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  1295. return
  1296. }
  1297. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  1298. resp.Paging = page
  1299. resp.List = list
  1300. br.Ret = 200
  1301. br.Success = true
  1302. br.Msg = "获取成功"
  1303. br.Data = resp
  1304. }
  1305. // Save
  1306. // @Title 新增/编辑保存沙盘
  1307. // @Description 新增/编辑保存沙盘接口
  1308. // @Param request body request.AddAndEditSandbox true "type json string"
  1309. // @Success 200 {object} sandbox.Sandbox
  1310. // @router /saveV2 [post]
  1311. func (this *SandboxController) SaveV2() {
  1312. br := new(models.BaseResponse).Init()
  1313. defer func() {
  1314. this.Data["json"] = br
  1315. this.ServeJSON()
  1316. }()
  1317. sysUser := this.SysUser
  1318. if sysUser == nil {
  1319. br.Msg = "请登录"
  1320. br.ErrMsg = "请登录,SysUser Is Empty"
  1321. br.Ret = 408
  1322. return
  1323. }
  1324. var req request.AddAndEditSandboxV2
  1325. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1326. if err != nil {
  1327. br.Msg = "参数解析异常!"
  1328. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1329. return
  1330. }
  1331. var sandboxResp *sandbox.SandboxSaveResp
  1332. var errMsg string
  1333. if req.SandboxId == 0 {
  1334. //新增沙盘
  1335. sandboxResp, err = sandboxService.AddSandboxV2(req, sysUser.AdminId, sysUser.RealName)
  1336. if err != nil {
  1337. br.Msg = "保存失败!"
  1338. if errMsg != `` {
  1339. br.Msg = errMsg
  1340. }
  1341. br.ErrMsg = "保存失败,Err:" + err.Error()
  1342. return
  1343. }
  1344. } else {
  1345. //编辑沙盘
  1346. sandboxInfo := &sandbox.Sandbox{
  1347. Name: utils.TrimStr(req.Name),
  1348. Content: req.Content,
  1349. PicUrl: utils.TrimStr(req.PicUrl),
  1350. ModifyTime: time.Now(),
  1351. SandboxClassifyId: req.SandboxClassifyId,
  1352. }
  1353. var updateSandboxColumn = []string{"Content","PicUrl","ModifyTime","SandboxClassifyId"}
  1354. err = sandboxInfo.Update(updateSandboxColumn)
  1355. if err != nil {
  1356. br.Msg = "保存失败!"
  1357. if errMsg != `` {
  1358. br.Msg = errMsg
  1359. }
  1360. br.ErrMsg = "保存失败,Err:" + err.Error()
  1361. return
  1362. }
  1363. }
  1364. msg := "保存成功"
  1365. br.Ret = 200
  1366. br.Success = true
  1367. br.Msg = msg
  1368. br.Data = sandboxResp
  1369. }
  1370. // Delete
  1371. // @Title 删除沙盘
  1372. // @Description 删除沙盘接口
  1373. // @Param request body request.DeleteSandbox true "type json string"
  1374. // @Success 200 标记成功
  1375. // @router /deleteV2 [post]
  1376. func (this *SandboxController) DeleteV2() {
  1377. br := new(models.BaseResponse).Init()
  1378. defer func() {
  1379. this.Data["json"] = br
  1380. this.ServeJSON()
  1381. }()
  1382. sysUser := this.SysUser
  1383. if sysUser == nil {
  1384. br.Msg = "请登录"
  1385. br.ErrMsg = "请登录,SysUser Is Empty"
  1386. br.Ret = 408
  1387. return
  1388. }
  1389. var req request.DeleteSandbox
  1390. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1391. if err != nil {
  1392. br.Msg = "参数解析异常!"
  1393. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1394. return
  1395. }
  1396. if req.SandboxId <= 0 {
  1397. br.Msg = "缺少沙盘编号"
  1398. return
  1399. }
  1400. //删除沙盘
  1401. err = sandboxService.DeleteSandbox(req.SandboxId)
  1402. if err != nil {
  1403. br.Msg = err.Error()
  1404. return
  1405. }
  1406. msg := "删除成功"
  1407. br.Ret = 200
  1408. br.Success = true
  1409. br.Msg = msg
  1410. }
  1411. // GetSandboxVersionDetail
  1412. // @Title 获取沙盘版本数据详情(已保存的)
  1413. // @Description 获取沙盘版本数据详情接口(已保存的)
  1414. // @Param SandboxVersionCode query string true "沙盘版本code"
  1415. // @Success 200 {object} sandbox.SandboxVersion
  1416. // @router /detail [get]
  1417. func (this *SandboxController) GetSandboxDetail() {
  1418. br := new(models.BaseResponse).Init()
  1419. defer func() {
  1420. this.Data["json"] = br
  1421. this.ServeJSON()
  1422. }()
  1423. sysUser := this.SysUser
  1424. if sysUser == nil {
  1425. br.Msg = "请登录"
  1426. br.ErrMsg = "请登录,SysUser Is Empty"
  1427. br.Ret = 408
  1428. return
  1429. }
  1430. sandboxId, _ := this.GetInt("SandboxId")
  1431. if sandboxId == 0 {
  1432. br.Msg = "缺少沙盘Id"
  1433. return
  1434. }
  1435. //获取沙盘数据详情(已保存的)
  1436. sandboxVersionInfo, err := sandbox.GetSandboxById(sandboxId)
  1437. if err != nil {
  1438. br.Msg = "获取失败"
  1439. br.ErrMsg = "获取失败,Err:" + err.Error()
  1440. return
  1441. }
  1442. msg := "获取成功"
  1443. br.Ret = 200
  1444. br.Success = true
  1445. br.Msg = msg
  1446. br.Data = sandboxVersionInfo
  1447. }
  1448. // SandboxMove
  1449. // @Title 移动沙盘接口
  1450. // @Description 移动图表接口
  1451. // @Success 200 {object} data_manage.MoveChartInfoReq
  1452. // @router /move [post]
  1453. func (this *SandboxController) SandboxMove() {
  1454. br := new(models.BaseResponse).Init()
  1455. defer func() {
  1456. this.Data["json"] = br
  1457. this.ServeJSON()
  1458. }()
  1459. sysUser := this.SysUser
  1460. if sysUser == nil {
  1461. br.Msg = "请登录"
  1462. br.ErrMsg = "请登录,SysUser Is Empty"
  1463. br.Ret = 408
  1464. return
  1465. }
  1466. var req sandbox.MoveSandboxReq
  1467. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1468. if err != nil {
  1469. br.Msg = "参数解析异常!"
  1470. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1471. return
  1472. }
  1473. if req.SandboxId <= 0 {
  1474. br.Msg = "参数错误"
  1475. br.ErrMsg = "沙盘id小于等于0"
  1476. return
  1477. }
  1478. if req.SandboxClassifyId <= 0 {
  1479. br.Msg = "请选择分类"
  1480. return
  1481. }
  1482. //判断分类是否存在
  1483. count, _ := sandbox.GetSandboxClassifyCountById(req.SandboxClassifyId)
  1484. if count <= 0 {
  1485. br.Msg = "分类已被删除,不可移动,请刷新页面"
  1486. return
  1487. }
  1488. sandboxInfo, err := sandbox.GetSandboxById(req.SandboxId)
  1489. if err != nil {
  1490. br.Msg = "移动失败"
  1491. br.ErrMsg = "获取沙盘信息失败,Err:" + err.Error()
  1492. return
  1493. }
  1494. //如果改变了分类,那么移动该图表数据
  1495. if sandboxInfo.SandboxClassifyId != req.SandboxClassifyId {
  1496. //查询需要修改的分类下是否存在同一个图表名称
  1497. tmpSandboxInfo, tmpErr := sandbox.GetSandboxByClassifyIdAndName(req.SandboxClassifyId, sandboxInfo.Name)
  1498. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  1499. br.Msg = "移动失败"
  1500. br.ErrMsg = "移动失败,Err:" + tmpErr.Error()
  1501. return
  1502. }
  1503. if tmpSandboxInfo != nil {
  1504. br.Msg = "移动失败,同一个分类下沙盘名称不允许重复"
  1505. br.ErrMsg = "移动失败,同一个分类下沙盘名称不允许重复"
  1506. return
  1507. }
  1508. err = sandbox.MoveSandbox(req.SandboxId, req.SandboxClassifyId)
  1509. if err != nil {
  1510. br.Msg = "移动失败"
  1511. br.ErrMsg = "移动失败,Err:" + err.Error()
  1512. return
  1513. }
  1514. }
  1515. //移动排序
  1516. updateCol := make([]string, 0)
  1517. //如果有传入 上一个兄弟节点分类id
  1518. if req.PrevSandboxId > 0 {
  1519. prevChartInfo, err := sandbox.GetSandboxById(req.PrevSandboxId)
  1520. if err != nil {
  1521. br.Msg = "移动失败"
  1522. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  1523. return
  1524. }
  1525. //如果是移动在两个兄弟节点之间
  1526. if req.NextSandboxId > 0 {
  1527. //下一个兄弟节点
  1528. nextChartInfo, err := sandbox.GetSandboxById(req.NextSandboxId)
  1529. if err != nil {
  1530. br.Msg = "移动失败"
  1531. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  1532. return
  1533. }
  1534. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  1535. if prevChartInfo.Sort == nextChartInfo.Sort || prevChartInfo.Sort == sandboxInfo.Sort {
  1536. //变更兄弟节点的排序
  1537. updateSortStr := `sort + 2`
  1538. _ = sandbox.UpdateSandboxSortByClassifyId(prevChartInfo.SandboxClassifyId, prevChartInfo.Sort, prevChartInfo.SandboxId, updateSortStr)
  1539. } else {
  1540. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  1541. if nextChartInfo.Sort-prevChartInfo.Sort == 1 {
  1542. //变更兄弟节点的排序
  1543. updateSortStr := `sort + 1`
  1544. _ = sandbox.UpdateSandboxSortByClassifyId(prevChartInfo.SandboxClassifyId, prevChartInfo.Sort, prevChartInfo.SandboxId, updateSortStr)
  1545. }
  1546. }
  1547. }
  1548. sandboxInfo.Sort = prevChartInfo.Sort + 1
  1549. sandboxInfo.ModifyTime = time.Now()
  1550. updateCol = append(updateCol, "Sort", "ModifyTime")
  1551. } else {
  1552. firstClassify, err := sandbox.GetFirstSandboxByClassifyId(req.SandboxClassifyId)
  1553. if err != nil && err.Error() != utils.ErrNoRow() {
  1554. br.Msg = "移动失败"
  1555. br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  1556. return
  1557. }
  1558. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  1559. if firstClassify != nil && firstClassify.Sort == 0 {
  1560. updateSortStr := ` sort + 1 `
  1561. _ = sandbox.UpdateSandboxSortByClassifyId(firstClassify.SandboxClassifyId, 0, firstClassify.SandboxId-1, updateSortStr)
  1562. }
  1563. sandboxInfo.Sort = 0 //那就是排在第一位
  1564. sandboxInfo.ModifyTime = time.Now()
  1565. updateCol = append(updateCol, "Sort", "ModifyTime")
  1566. }
  1567. //更新
  1568. if len(updateCol) > 0 {
  1569. err = sandboxInfo.Update(updateCol)
  1570. if err != nil {
  1571. br.Msg = "移动失败"
  1572. br.ErrMsg = "修改失败,Err:" + err.Error()
  1573. return
  1574. }
  1575. }
  1576. if err != nil {
  1577. br.Msg = "移动失败"
  1578. br.ErrMsg = "修改失败,Err:" + err.Error()
  1579. return
  1580. }
  1581. br.Ret = 200
  1582. br.Success = true
  1583. br.Msg = "移动成功"
  1584. }
  1585. //// SandboxClassifyItems
  1586. //// @Title 获取所有沙盘分类接口-包含沙盘-先分类后沙盘区分,暂时弃用
  1587. //// @Description 获取所有沙盘分类接口-包含沙盘
  1588. //// @Param IsShowMe query bool true "是否只看我的,true、false"
  1589. //// @Success 200 {object} data_manage.ChartClassifyListResp
  1590. //// @router /classify/list [get]
  1591. //func (this *SandboxController) SandboxClassifyItems() {
  1592. // br := new(models.BaseResponse).Init()
  1593. // defer func() {
  1594. // this.Data["json"] = br
  1595. // this.ServeJSON()
  1596. // }()
  1597. //
  1598. // resp := new(sandbox.SandboxClassifyListResp)
  1599. // sandboxClassifyId, _ := this.GetInt("SandboxClassifyId")
  1600. //
  1601. // isShowMe, _ := this.GetBool("IsShowMe")
  1602. // if isShowMe {
  1603. // errMsg, err := sandboxService.GetSandboxClassifyListForMe(*this.SysUser, resp, sandboxClassifyId)
  1604. // if err != nil {
  1605. // br.Msg = errMsg
  1606. // br.ErrMsg = err.Error()
  1607. // return
  1608. // }
  1609. // // 移除没有权限的图表
  1610. // //allNodes := sandboxService.HandleNoPermissionSandbox(resp.AllNodes, nil)
  1611. // //resp.AllNodes = allNodes
  1612. //
  1613. // br.Ret = 200
  1614. // br.Success = true
  1615. // br.Msg = "获取成功"
  1616. // br.Data = resp
  1617. // fmt.Println("source my classify")
  1618. // return
  1619. // }
  1620. //
  1621. // rootList, err := sandbox.GetSandboxClassifyByParentId(sandboxClassifyId)
  1622. // if err != nil && err.Error() != utils.ErrNoRow() {
  1623. // br.Msg = "获取失败"
  1624. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1625. // return
  1626. // }
  1627. //
  1628. // classifyAll, err := sandbox.GetSandboxClassifyByParentId(sandboxClassifyId)
  1629. // if err != nil && err.Error() != utils.ErrNoRow() {
  1630. // br.Msg = "获取失败"
  1631. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1632. // return
  1633. // }
  1634. //
  1635. // sandboxAll, err := sandbox.GetSandboxItemsByClassifyId(sandboxClassifyId)
  1636. // if err != nil && err.Error() != utils.ErrNoRow() {
  1637. // br.Msg = "获取失败"
  1638. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1639. // return
  1640. // }
  1641. //
  1642. // sandListMap := make(map[int][]*sandbox.SandboxClassifyItems)
  1643. // for _, v := range sandboxAll {
  1644. // if _, ok := sandListMap[v.SandboxClassifyId]; !ok {
  1645. // list := make([]*sandbox.SandboxClassifyItems, 0)
  1646. // list = append(list, v)
  1647. // sandListMap[v.SandboxClassifyId] = list
  1648. // } else {
  1649. // sandListMap[v.SandboxClassifyId] = append(sandListMap[v.SandboxClassifyId], v)
  1650. // }
  1651. // }
  1652. //
  1653. // nodeAll := make([]*sandbox.SandboxClassifyItems, 0)
  1654. // for k := range rootList {
  1655. // rootNode := rootList[k]
  1656. // sandboxService.SandboxClassifyItemsMakeTree(this.SysUser, classifyAll, rootNode)
  1657. // nodeAll = append(nodeAll, rootNode)
  1658. // }
  1659. // //for k := range nodeAll {
  1660. // //
  1661. // //}
  1662. // newAll := sandboxService.SandboxItemsMakeTree(nodeAll, sandListMap, sandboxClassifyId)
  1663. //
  1664. // resp.AllNodes = newAll
  1665. // br.Ret = 200
  1666. // br.Success = true
  1667. // br.Msg = "获取成功"
  1668. // br.Data = resp
  1669. //}