sandbox.go 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513
  1. package sandbox
  2. import (
  3. "encoding/json"
  4. "eta_gn/eta_api/controllers"
  5. "eta_gn/eta_api/models"
  6. "eta_gn/eta_api/models/data_manage"
  7. "eta_gn/eta_api/models/sandbox"
  8. "eta_gn/eta_api/models/sandbox/request"
  9. "eta_gn/eta_api/models/sandbox/response"
  10. "eta_gn/eta_api/services/data"
  11. sandboxService "eta_gn/eta_api/services/sandbox"
  12. "eta_gn/eta_api/utils"
  13. "fmt"
  14. "github.com/rdlucklib/rdluck_tools/paging"
  15. "time"
  16. )
  17. var versionSize = 3
  18. type SandboxController struct {
  19. controllers.BaseAuthController
  20. }
  21. // @router /list [get]
  22. // @router /version/first_list [get]
  23. func (this *SandboxController) FirstVersionList() {
  24. br := new(models.BaseResponse).Init()
  25. defer func() {
  26. this.Data["json"] = br
  27. this.ServeJSON()
  28. }()
  29. sandboxId, _ := this.GetInt("SandboxId")
  30. keyword := this.GetString("Keyword")
  31. currentIndex := 1
  32. pageSize := versionSize
  33. startSize := 0
  34. var condition string
  35. var pars []interface{}
  36. if sandboxId <= 0 {
  37. br.Msg = "参数错误,沙盘编号id必传!"
  38. br.ErrMsg = "参数错误,沙盘编号id必传"
  39. return
  40. }
  41. condition += " AND a.sandbox_id=? "
  42. pars = append(pars, sandboxId)
  43. condition += " AND b.curr_version < a.curr_version "
  44. if keyword != "" {
  45. condition += ` AND ( a.name LIKE ? OR b.name LIKE ? )`
  46. pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  47. }
  48. total, list, err := sandbox.GetVersionList(condition, pars, startSize, pageSize)
  49. if err != nil && !utils.IsErrNoRow(err) {
  50. br.Success = true
  51. br.Msg = "获取沙盘列表失败"
  52. br.ErrMsg = "获取沙盘列表失败,Err:" + err.Error()
  53. return
  54. }
  55. if list == nil || (err != nil && utils.IsErrNoRow(err)) {
  56. list = make([]*sandbox.SandboxVersionListItem, 0)
  57. }
  58. for _, v := range list {
  59. v.ModifyTime = v.CreateTime
  60. }
  61. page := paging.GetPaging(currentIndex, pageSize, total)
  62. resp := response.SandboxVersionListResp{
  63. Paging: page,
  64. List: list,
  65. }
  66. br.Ret = 200
  67. br.Success = true
  68. br.Msg = "获取成功"
  69. br.Data = resp
  70. }
  71. // @router /version/list [get]
  72. func (this *SandboxController) VersionList() {
  73. br := new(models.BaseResponse).Init()
  74. defer func() {
  75. this.Data["json"] = br
  76. this.ServeJSON()
  77. }()
  78. sandboxId, _ := this.GetInt("SandboxId")
  79. keyWord := this.GetString("Keyword")
  80. pageSize, _ := this.GetInt("PageSize")
  81. currentIndex, _ := this.GetInt("CurrentIndex")
  82. var startSize int
  83. if pageSize <= 0 {
  84. pageSize = utils.PageSize20
  85. }
  86. startSize = paging.StartIndex(currentIndex, pageSize) + versionSize
  87. var condition string
  88. var pars []interface{}
  89. if sandboxId <= 0 {
  90. br.Msg = "参数错误,沙盘编号id必传!"
  91. br.ErrMsg = "参数错误,沙盘编号id必传"
  92. return
  93. }
  94. condition += " AND a.sandbox_id=? "
  95. pars = append(pars, sandboxId)
  96. condition += " AND b.curr_version < a.curr_version "
  97. if keyWord != "" {
  98. condition += ` AND ( a.op_user_name LIKE ? OR a.name LIKE ? or a.op_user_name LIKE ? OR a.name LIKE ? )`
  99. pars = utils.GetLikeKeywordPars(pars, keyWord, 4)
  100. }
  101. total, list, err := sandbox.GetVersionList(condition, pars, startSize, pageSize)
  102. if err != nil && !utils.IsErrNoRow(err) {
  103. br.Success = true
  104. br.Msg = "获取沙盘列表失败"
  105. br.ErrMsg = "获取沙盘列表失败,Err:" + err.Error()
  106. return
  107. }
  108. if list == nil || (err != nil && utils.IsErrNoRow(err)) {
  109. list = make([]*sandbox.SandboxVersionListItem, 0)
  110. }
  111. for _, v := range list {
  112. v.ModifyTime = v.CreateTime
  113. markStatus, err := sandboxService.UpdateSandboxEditMark(v.SandboxId, this.SysUser.AdminId, 2, this.SysUser.RealName)
  114. if err != nil {
  115. br.Msg = "查询标记状态失败"
  116. br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  117. return
  118. }
  119. if markStatus.Status == 0 {
  120. v.CanEdit = true
  121. }
  122. }
  123. total = total - versionSize
  124. if total <= 0 {
  125. total = 0
  126. }
  127. page := paging.GetPaging(currentIndex, pageSize, total)
  128. resp := response.SandboxVersionListResp{
  129. Paging: page,
  130. List: list,
  131. }
  132. br.Ret = 200
  133. br.Success = true
  134. br.Msg = "获取成功"
  135. br.Data = resp
  136. }
  137. //// @router /save [post]
  138. // @router /draft/add [post]
  139. func (this *SandboxController) AddSandboxDraft() {
  140. br := new(models.BaseResponse).Init()
  141. br.IsSendEmail = false
  142. defer func() {
  143. this.Data["json"] = br
  144. this.ServeJSON()
  145. }()
  146. sysUser := this.SysUser
  147. if sysUser == nil {
  148. br.Msg = "请登录"
  149. br.ErrMsg = "请登录,SysUser Is Empty"
  150. br.Ret = 408
  151. return
  152. }
  153. var req request.AddAndEditSandbox
  154. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  155. if err != nil {
  156. br.Msg = "参数解析异常!"
  157. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  158. return
  159. }
  160. if req.SandboxVersionCode == `` {
  161. br.Msg = "请传入沙盘版本!"
  162. return
  163. }
  164. sandboxVersion, err := sandbox.GetSandboxVersionBySandboxVersionCode(req.SandboxVersionCode)
  165. if err != nil {
  166. if utils.IsErrNoRow(err) {
  167. br.Msg = "找不到该版本!"
  168. br.ErrMsg = "找不到该版本"
  169. return
  170. }
  171. br.Msg = "找不到该版本!"
  172. br.ErrMsg = "找不到该版本,Err:" + err.Error()
  173. br.IsSendEmail = false
  174. return
  175. }
  176. markStatus, err := sandboxService.UpdateSandboxEditMark(sandboxVersion.SandboxId, sysUser.AdminId, 1, sysUser.RealName)
  177. if err != nil {
  178. br.Msg = err.Error()
  179. return
  180. }
  181. if markStatus.Status == 1 {
  182. br.Msg = markStatus.Msg
  183. return
  184. }
  185. sandboxDraftInfo, err := sandboxService.AddSandboxDraft(sandboxVersion.SandboxId, req, sysUser.AdminId, sysUser.RealName)
  186. if err != nil {
  187. br.Msg = "保存失败!"
  188. br.ErrMsg = "保存失败,Err:" + err.Error()
  189. br.Ret = 204 //204 (无内容) :服务器成功处理了请求,但没有返回任何内容。
  190. return
  191. }
  192. msg := "保存成功"
  193. br.Ret = 200
  194. br.Success = true
  195. br.Msg = msg
  196. br.Data = sandboxDraftInfo
  197. }
  198. // @router /mark [post]
  199. func (this *SandboxController) MarkEditStatus() {
  200. br := new(models.BaseResponse).Init()
  201. defer func() {
  202. this.Data["json"] = br
  203. this.ServeJSON()
  204. }()
  205. sysUser := this.SysUser
  206. if sysUser == nil {
  207. br.Msg = "请登录"
  208. br.ErrMsg = "请登录,SysUser Is Empty"
  209. br.Ret = 408
  210. return
  211. }
  212. var req request.MarkEditSandbox
  213. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  214. if err != nil {
  215. br.Msg = "参数解析异常!"
  216. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  217. return
  218. }
  219. if req.SandboxId <= 0 {
  220. br.Msg = "缺少沙盘编号"
  221. return
  222. }
  223. if req.Status <= 0 {
  224. br.Msg = "标记状态异常"
  225. return
  226. }
  227. data, err := sandboxService.UpdateSandboxEditMark(req.SandboxId, sysUser.AdminId, req.Status, sysUser.RealName)
  228. if err != nil {
  229. br.Msg = err.Error()
  230. return
  231. }
  232. msg := "标记成功"
  233. br.Ret = 200
  234. br.Success = true
  235. br.Msg = msg
  236. br.Data = data
  237. }
  238. // @router /version/detail [get]
  239. func (this *SandboxController) GetSandboxVersionDetail() {
  240. br := new(models.BaseResponse).Init()
  241. defer func() {
  242. this.Data["json"] = br
  243. this.ServeJSON()
  244. }()
  245. sysUser := this.SysUser
  246. if sysUser == nil {
  247. br.Msg = "请登录"
  248. br.ErrMsg = "请登录,SysUser Is Empty"
  249. br.Ret = 408
  250. return
  251. }
  252. sandboxVersionCode := this.GetString("SandboxVersionCode")
  253. if sandboxVersionCode == "" {
  254. br.Msg = "缺少沙盘版本编号"
  255. return
  256. }
  257. sandboxVersionInfo, err := sandboxService.GetSandboxVersionDetailByCode(sandboxVersionCode)
  258. if err != nil {
  259. br.Msg = "获取失败"
  260. br.ErrMsg = "获取失败,Err:" + err.Error()
  261. return
  262. }
  263. msg := "获取成功"
  264. br.Ret = 200
  265. br.Success = true
  266. br.Msg = msg
  267. br.Data = sandboxVersionInfo
  268. }
  269. // @router /last_info [get]
  270. func (this *SandboxController) GetLastSandboxInfo() {
  271. br := new(models.BaseResponse).Init()
  272. defer func() {
  273. this.Data["json"] = br
  274. this.ServeJSON()
  275. }()
  276. sysUser := this.SysUser
  277. if sysUser == nil {
  278. br.Msg = "请登录"
  279. br.ErrMsg = "请登录,SysUser Is Empty"
  280. br.Ret = 408
  281. return
  282. }
  283. sandboxId, _ := this.GetInt("SandboxId", 0)
  284. if sandboxId <= 0 {
  285. br.Msg = "缺少沙盘编号"
  286. return
  287. }
  288. sandboxInfo, err := sandboxService.GetLastSandboxInfo(sandboxId)
  289. if err != nil {
  290. br.Msg = err.Error()
  291. return
  292. }
  293. msg := "获取成功"
  294. br.Ret = 200
  295. br.Success = true
  296. br.Msg = msg
  297. br.Data = sandboxInfo
  298. }
  299. // @router /delete [post]
  300. func (this *SandboxController) Delete() {
  301. br := new(models.BaseResponse).Init()
  302. defer func() {
  303. this.Data["json"] = br
  304. this.ServeJSON()
  305. }()
  306. sysUser := this.SysUser
  307. if sysUser == nil {
  308. br.Msg = "请登录"
  309. br.ErrMsg = "请登录,SysUser Is Empty"
  310. br.Ret = 408
  311. return
  312. }
  313. var req request.DeleteSandbox
  314. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  315. if err != nil {
  316. br.Msg = "参数解析异常!"
  317. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  318. return
  319. }
  320. if req.SandboxId <= 0 {
  321. br.Msg = "缺少沙盘编号"
  322. return
  323. }
  324. markStatus, err := sandboxService.UpdateSandboxEditMark(req.SandboxId, this.SysUser.AdminId, 2, this.SysUser.RealName)
  325. if err != nil {
  326. br.Msg = "查询标记状态失败"
  327. br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  328. return
  329. }
  330. if markStatus.Status == 1 {
  331. br.Msg = fmt.Sprintf("当前%s正在编辑,不允许删除该沙盘", markStatus.Editor)
  332. return
  333. }
  334. err = sandboxService.DeleteSandbox(req.SandboxId)
  335. if err != nil {
  336. br.Msg = err.Error()
  337. return
  338. }
  339. _ = data_manage.DeleteEdbRelationByObjectId(req.SandboxId, utils.EDB_RELATION_SANDBOX)
  340. msg := "删除成功"
  341. br.Ret = 200
  342. br.Success = true
  343. br.Msg = msg
  344. }
  345. //// @router /version/delete [post]
  346. //// @router /draft/reset [post]
  347. // @router /list_by_quote [get]
  348. func (this *SandboxController) ListByQuote() {
  349. br := new(models.BaseResponse).Init()
  350. defer func() {
  351. this.Data["json"] = br
  352. this.ServeJSON()
  353. }()
  354. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  355. keyword := this.GetString("Keyword")
  356. pageSize, _ := this.GetInt("PageSize")
  357. currentIndex, _ := this.GetInt("CurrentIndex")
  358. var startSize int
  359. if pageSize <= 0 {
  360. pageSize = utils.PageSize20
  361. }
  362. if currentIndex <= 0 {
  363. currentIndex = 1
  364. }
  365. startSize = paging.StartIndex(currentIndex, pageSize)
  366. var condition string
  367. var pars []interface{}
  368. if chartPermissionId > 0 {
  369. condition += " AND a.chart_permission_id=? "
  370. pars = append(pars, chartPermissionId)
  371. }
  372. if keyword != "" {
  373. condition += ` AND ( a.name LIKE ? OR a.chart_permission_name LIKE ? )`
  374. pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  375. }
  376. total, list, err := sandbox.GetList(condition, pars, startSize, pageSize)
  377. if err != nil && !utils.IsErrNoRow(err) {
  378. br.Success = true
  379. br.Msg = "获取沙盘列表失败"
  380. br.ErrMsg = "获取沙盘列表失败,Err:" + err.Error()
  381. return
  382. }
  383. if list == nil || (err != nil && utils.IsErrNoRow(err)) {
  384. list = make([]*sandbox.Sandbox, 0)
  385. }
  386. page := paging.GetPaging(currentIndex, pageSize, total)
  387. resp := response.SandboxListResp{
  388. Paging: page,
  389. List: list,
  390. }
  391. br.Ret = 200
  392. br.Success = true
  393. br.Msg = "获取成功"
  394. br.Data = resp
  395. }
  396. // @router /classify/list [get]
  397. func (this *SandboxController) SandboxClassifyItems() {
  398. br := new(models.BaseResponse).Init()
  399. defer func() {
  400. this.Data["json"] = br
  401. this.ServeJSON()
  402. }()
  403. resp := new(sandbox.SandboxClassifyListResp)
  404. sandboxClassifyId, _ := this.GetInt("SandboxClassifyId")
  405. isShowMe, _ := this.GetBool("IsShowMe")
  406. if isShowMe {
  407. errMsg, err := sandboxService.GetSandboxClassifyListForMe(*this.SysUser, resp, sandboxClassifyId)
  408. if err != nil {
  409. br.Msg = errMsg
  410. br.ErrMsg = err.Error()
  411. return
  412. }
  413. br.Ret = 200
  414. br.Success = true
  415. br.Msg = "获取成功"
  416. br.Data = resp
  417. fmt.Println("source my classify")
  418. return
  419. }
  420. rootList, err := sandbox.GetSandboxClassifyAndInfoByParentId(sandboxClassifyId)
  421. if err != nil && !utils.IsErrNoRow(err) {
  422. br.Msg = "获取失败"
  423. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  424. return
  425. }
  426. classifyAll, err := sandbox.GetSandboxClassifyAndInfoByParentId(sandboxClassifyId)
  427. if err != nil && !utils.IsErrNoRow(err) {
  428. br.Msg = "获取失败"
  429. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  430. return
  431. }
  432. nodeAll := make([]*sandbox.SandboxClassifyItems, 0)
  433. for k := range rootList {
  434. rootNode := rootList[k]
  435. sandboxService.SandboxClassifyItemsMakeTreeV2(this.SysUser, classifyAll, rootNode)
  436. nodeAll = append(nodeAll, rootNode)
  437. }
  438. resp.AllNodes = nodeAll
  439. br.Ret = 200
  440. br.Success = true
  441. br.Msg = "获取成功"
  442. br.Data = resp
  443. }
  444. // @router /classify/add [post]
  445. func (this *SandboxController) AddSandboxClassify() {
  446. br := new(models.BaseResponse).Init()
  447. defer func() {
  448. this.Data["json"] = br
  449. this.ServeJSON()
  450. }()
  451. var req sandbox.AddSandboxClassifyReq
  452. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  453. if err != nil {
  454. br.Msg = "参数解析异常!"
  455. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  456. return
  457. }
  458. if req.SandboxClassifyName == "" {
  459. br.Msg = "请输入分类名称"
  460. br.IsSendEmail = false
  461. return
  462. }
  463. if req.ParentId < 0 {
  464. br.Msg = "参数错误"
  465. br.IsSendEmail = false
  466. return
  467. }
  468. count, err := sandbox.GetSandboxClassifyCount(req.SandboxClassifyName, req.ParentId)
  469. if err != nil {
  470. br.Msg = "判断名称是否已存在失败"
  471. br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  472. return
  473. }
  474. if count > 0 {
  475. br.Msg = "分类名称已存在,请重新输入"
  476. br.IsSendEmail = false
  477. return
  478. }
  479. maxSort, err := sandbox.GetSandboxClassifyMaxSort(req.ParentId)
  480. classify := new(sandbox.SandboxClassify)
  481. classify.ParentId = req.ParentId
  482. classify.SandboxClassifyName = req.SandboxClassifyName
  483. classify.HasData = 0
  484. classify.CreateTime = time.Now()
  485. classify.ModifyTime = time.Now()
  486. classify.SysUserId = this.SysUser.AdminId
  487. classify.SysUserRealName = this.SysUser.RealName
  488. classify.ChartPermissionId = req.ChartPermissionId
  489. classify.ChartPermissionName = req.ChartPermissionName
  490. classify.Level = req.Level + 1
  491. classify.Sort = maxSort + 1
  492. _, err = sandbox.AddSandboxClassify(classify)
  493. if err != nil {
  494. br.Msg = "保存分类失败"
  495. br.ErrMsg = "保存分类失败,Err:" + err.Error()
  496. return
  497. }
  498. br.Ret = 200
  499. br.Msg = "保存成功"
  500. br.Success = true
  501. }
  502. // @router /classify/edit [post]
  503. func (this *SandboxController) EditSandboxClassify() {
  504. br := new(models.BaseResponse).Init()
  505. defer func() {
  506. this.Data["json"] = br
  507. this.ServeJSON()
  508. }()
  509. var req sandbox.EditSandboxClassifyReq
  510. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  511. if err != nil {
  512. br.Msg = "参数解析异常!"
  513. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  514. return
  515. }
  516. if req.SandboxClassifyName == "" {
  517. br.Msg = "请输入分类名称"
  518. br.IsSendEmail = false
  519. return
  520. }
  521. if req.SandboxClassifyId <= 0 {
  522. br.Msg = "参数错误"
  523. br.IsSendEmail = false
  524. return
  525. }
  526. err = sandbox.EditSandboxClassify(req.SandboxClassifyId, req.ChartPermissionId, req.SandboxClassifyName, req.ChartPermissionName)
  527. if err != nil {
  528. br.Msg = "保存失败"
  529. br.ErrMsg = "保存失败,Err:" + err.Error()
  530. return
  531. }
  532. ids, err := sandbox.GetSandboxClassifySubcategories(req.SandboxClassifyId)
  533. if err != nil {
  534. br.Msg = "查询子级分类id失败"
  535. br.ErrMsg = "查询子级分类id失败,Err:" + err.Error()
  536. return
  537. }
  538. err = sandbox.UpdateSandboxClassifyChartPermissionById(req.ChartPermissionId, req.ChartPermissionName, ids)
  539. if err != nil {
  540. br.Msg = "修改子级分类错误"
  541. br.ErrMsg = "修改子级分类错误,Err:" + err.Error()
  542. return
  543. }
  544. br.Ret = 200
  545. br.Msg = "保存成功"
  546. br.Success = true
  547. br.IsAddLog = true
  548. }
  549. // @router /classify/delete/check [post]
  550. func (this *SandboxController) DeleteSandboxClassifyCheck() {
  551. br := new(models.BaseResponse).Init()
  552. defer func() {
  553. this.Data["json"] = br
  554. this.ServeJSON()
  555. }()
  556. var req sandbox.SandboxClassifyDeleteCheckReq
  557. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  558. if err != nil {
  559. br.Msg = "参数解析异常!"
  560. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  561. return
  562. }
  563. if req.SandboxClassifyId < 0 {
  564. br.Msg = "参数错误"
  565. br.IsSendEmail = false
  566. return
  567. }
  568. var deleteStatus int
  569. var tipsMsg string
  570. if req.SandboxClassifyId > 0 {
  571. count, err := sandbox.GetSandboxInfoCountByClassifyId(req.SandboxClassifyId)
  572. if err != nil {
  573. br.Msg = "删除失败"
  574. br.ErrMsg = "分类下是否含有指标失败,Err:" + err.Error()
  575. return
  576. }
  577. if count > 0 {
  578. deleteStatus = 1
  579. tipsMsg = "该分类下关联沙盘不可删除"
  580. }
  581. }
  582. if deleteStatus != 1 {
  583. classifyCount, err := sandbox.GetSandboxInfoCountByClassifyId(req.SandboxClassifyId)
  584. if err != nil && !utils.IsErrNoRow(err) {
  585. br.Msg = "删除失败"
  586. br.ErrMsg = "分类下是否含有沙盘失败,Err:" + err.Error()
  587. return
  588. }
  589. if classifyCount > 0 {
  590. deleteStatus = 2
  591. tipsMsg = "确认删除当前目录及包含的子目录吗"
  592. }
  593. }
  594. if deleteStatus == 0 {
  595. tipsMsg = "可删除,进行删除操作"
  596. }
  597. resp := new(sandbox.SandboxClassifyDeleteCheckResp)
  598. resp.DeleteStatus = deleteStatus
  599. resp.TipsMsg = tipsMsg
  600. br.Ret = 200
  601. br.Msg = "检测成功"
  602. br.Success = true
  603. br.Data = resp
  604. }
  605. // @router /classify/delete [post]
  606. func (this *SandboxController) DeleteSandboxClassify() {
  607. br := new(models.BaseResponse).Init()
  608. defer func() {
  609. this.Data["json"] = br
  610. this.ServeJSON()
  611. }()
  612. sysUser := this.SysUser
  613. if sysUser == nil {
  614. br.Msg = "请登录"
  615. br.ErrMsg = "请登录,SysUser Is Empty"
  616. br.Ret = 408
  617. return
  618. }
  619. var req sandbox.DeleteSandboxClassifyReq
  620. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  621. if err != nil {
  622. br.Msg = "参数解析异常!"
  623. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  624. return
  625. }
  626. if req.SandboxClassifyId < 0 && req.SandboxId <= 0 {
  627. br.Msg = "参数错误"
  628. br.IsSendEmail = false
  629. return
  630. }
  631. if req.SandboxClassifyId > 0 && req.SandboxId == 0 {
  632. count, err := sandbox.GetSandboxInfoCountByClassifyId(req.SandboxId)
  633. if err != nil && !utils.IsErrNoRow(err) {
  634. br.Msg = "删除失败"
  635. br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  636. return
  637. }
  638. if count > 0 {
  639. br.Msg = "该目录下存在关联指标,不可删除"
  640. br.IsSendEmail = false
  641. return
  642. }
  643. err = sandbox.DeleteSandboxClassify(req.SandboxClassifyId)
  644. if err != nil {
  645. br.Msg = "删除失败"
  646. br.ErrMsg = "删除失败,Err:" + err.Error()
  647. return
  648. }
  649. }
  650. if req.SandboxId > 0 {
  651. sandboxInfo, err := sandbox.GetSandboxById(req.SandboxId)
  652. if err != nil {
  653. if utils.IsErrNoRow(err) {
  654. br.Msg = "沙盘已删除,请刷新页面"
  655. br.ErrMsg = "指标不存在,Err:" + err.Error()
  656. return
  657. } else {
  658. br.Msg = "删除失败"
  659. br.ErrMsg = "删除失败,获取指标信息失败,Err:" + err.Error()
  660. return
  661. }
  662. }
  663. if sandboxInfo == nil {
  664. br.Msg = "沙盘已删除,请刷新页面"
  665. return
  666. }
  667. err = sandboxService.DeleteSandbox(req.SandboxId)
  668. if err != nil {
  669. br.Msg = err.Error()
  670. return
  671. }
  672. }
  673. br.Ret = 200
  674. br.Msg = "删除成功"
  675. br.Success = true
  676. br.IsAddLog = true
  677. }
  678. // @router /classify/move [post]
  679. func (this *SandboxController) ChartClassifyMove() {
  680. br := new(models.BaseResponse).Init()
  681. defer func() {
  682. this.Data["json"] = br
  683. this.ServeJSON()
  684. }()
  685. sysUser := this.SysUser
  686. if sysUser == nil {
  687. br.Msg = "请登录"
  688. br.ErrMsg = "请登录,SysUser Is Empty"
  689. br.Ret = 408
  690. return
  691. }
  692. var req sandbox.MoveSandboxClassifyReq
  693. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  694. if err != nil {
  695. br.Msg = "参数解析异常!"
  696. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  697. return
  698. }
  699. if req.ClassifyId <= 0 {
  700. br.Msg = "参数错误"
  701. br.ErrMsg = "分类id小于等于0"
  702. return
  703. }
  704. sandboxClassifyInfo, err := sandbox.GetSandboxClassifyById(req.ClassifyId)
  705. if err != nil {
  706. br.Msg = "移动失败"
  707. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  708. return
  709. }
  710. updateCol := make([]string, 0)
  711. if req.SandboxId > 0 {
  712. count, _ := sandbox.GetSandboxClassifyCountById(req.ClassifyId)
  713. if count <= 0 {
  714. br.Msg = "分类已被删除,不可移动,请刷新页面"
  715. return
  716. }
  717. sandboxInfo, err := sandbox.GetSandboxById(req.SandboxId)
  718. if err != nil {
  719. br.Msg = "移动失败"
  720. br.ErrMsg = "获取沙盘信息失败,Err:" + err.Error()
  721. return
  722. }
  723. if sandboxInfo.SandboxClassifyId != req.ParentClassifyId {
  724. err = sandbox.MoveSandbox(req.SandboxId, req.ParentClassifyId)
  725. if err != nil {
  726. br.Msg = "移动失败"
  727. br.ErrMsg = "移动失败,Err:" + err.Error()
  728. return
  729. }
  730. }
  731. updateCol := make([]string, 0)
  732. if req.PrevId > 0 {
  733. if req.PrevType == 1 {
  734. prevClassify, err := sandbox.GetSandboxClassifyById(req.PrevId)
  735. if err != nil {
  736. br.Msg = "移动失败"
  737. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  738. return
  739. }
  740. if req.NextId > 0 {
  741. if req.NextType == 1 {
  742. nextClassify, err := sandbox.GetSandboxClassifyById(req.NextId)
  743. if err != nil {
  744. br.Msg = "移动失败"
  745. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  746. return
  747. }
  748. if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == sandboxClassifyInfo.Sort {
  749. updateSortStr := `sort + 2`
  750. _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, prevClassify.SandboxClassifyId, prevClassify.Sort, updateSortStr)
  751. _ = sandbox.UpdateSandboxSortByClassifyId(prevClassify.SandboxClassifyId, prevClassify.Sort, 0, updateSortStr)
  752. } else {
  753. if nextClassify.Sort-prevClassify.Sort == 1 {
  754. updateSortStr := `sort + 1`
  755. _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr)
  756. _ = sandbox.UpdateSandboxSortByClassifyId(prevClassify.SandboxClassifyId, prevClassify.Sort, 0, updateSortStr)
  757. }
  758. }
  759. } else {
  760. nextChartInfo, err := sandbox.GetSandboxById(req.NextId)
  761. if err != nil {
  762. br.Msg = "移动失败"
  763. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  764. return
  765. }
  766. if prevClassify.Sort == nextChartInfo.Sort || prevClassify.Sort == sandboxInfo.Sort {
  767. updateSortStr := `sort + 2`
  768. _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, prevClassify.SandboxClassifyId, prevClassify.Sort, updateSortStr)
  769. _ = sandbox.UpdateSandboxSortByClassifyId(prevClassify.SandboxClassifyId, prevClassify.Sort, 0, updateSortStr)
  770. } else {
  771. if nextChartInfo.Sort-prevClassify.Sort == 1 {
  772. updateSortStr := `sort + 1`
  773. _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.SandboxClassifyId, updateSortStr)
  774. _ = sandbox.UpdateSandboxSortByClassifyId(prevClassify.SandboxClassifyId, prevClassify.Sort, 0, updateSortStr)
  775. }
  776. }
  777. }
  778. }
  779. sandboxInfo.Sort = prevClassify.Sort + 1
  780. sandboxInfo.ModifyTime = time.Now()
  781. updateCol = append(updateCol, "Sort", "ModifyTime")
  782. } else {
  783. prevSandbox, err := sandbox.GetSandboxById(req.PrevId)
  784. if err != nil {
  785. br.Msg = "移动失败"
  786. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  787. return
  788. }
  789. if req.NextId > 0 {
  790. if req.NextType == 1 {
  791. nextClassify, err := sandbox.GetSandboxClassifyById(req.NextId)
  792. if err != nil {
  793. br.Msg = "移动失败"
  794. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  795. return
  796. }
  797. if prevSandbox.Sort == nextClassify.Sort || prevSandbox.Sort == sandboxClassifyInfo.Sort {
  798. updateSortStr := `sort + 2`
  799. _ = sandbox.UpdateSandboxClassifySortByParentId(prevSandbox.SandboxClassifyId, 0, prevSandbox.Sort, updateSortStr)
  800. _ = sandbox.UpdateSandboxSortByClassifyId(prevSandbox.SandboxClassifyId, prevSandbox.Sort, prevSandbox.SandboxId, updateSortStr)
  801. } else {
  802. if nextClassify.Sort-prevSandbox.Sort == 1 {
  803. updateSortStr := `sort + 1`
  804. _ = sandbox.UpdateSandboxClassifySortByParentId(prevSandbox.SandboxClassifyId, 0, prevSandbox.Sort, updateSortStr)
  805. _ = sandbox.UpdateSandboxSortByClassifyId(prevSandbox.SandboxClassifyId, prevSandbox.Sort, prevSandbox.SandboxId, updateSortStr)
  806. }
  807. }
  808. } else {
  809. nextChartInfo, err := sandbox.GetSandboxById(req.NextId)
  810. if err != nil {
  811. br.Msg = "移动失败"
  812. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  813. return
  814. }
  815. if prevSandbox.Sort == nextChartInfo.Sort || prevSandbox.Sort == sandboxInfo.Sort {
  816. updateSortStr := `sort + 2`
  817. _ = sandbox.UpdateSandboxClassifySortByParentId(prevSandbox.SandboxClassifyId, 0, prevSandbox.Sort, updateSortStr)
  818. _ = sandbox.UpdateSandboxSortByClassifyId(prevSandbox.SandboxClassifyId, prevSandbox.Sort, prevSandbox.SandboxId, updateSortStr)
  819. } else {
  820. if nextChartInfo.Sort-prevSandbox.Sort == 1 {
  821. updateSortStr := `sort + 1`
  822. _ = sandbox.UpdateSandboxClassifySortByParentId(prevSandbox.SandboxClassifyId, 0, prevSandbox.Sort, updateSortStr)
  823. _ = sandbox.UpdateSandboxSortByClassifyId(prevSandbox.SandboxClassifyId, prevSandbox.Sort, prevSandbox.SandboxId, updateSortStr)
  824. }
  825. }
  826. }
  827. }
  828. sandboxInfo.Sort = prevSandbox.Sort + 1
  829. sandboxInfo.ModifyTime = time.Now()
  830. updateCol = append(updateCol, "Sort", "ModifyTime")
  831. }
  832. } else {
  833. firstClassify, err := sandbox.GetFirstSandboxByClassifyId(req.ClassifyId)
  834. if err != nil && !utils.IsErrNoRow(err) {
  835. br.Msg = "移动失败"
  836. br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  837. return
  838. }
  839. if firstClassify != nil && firstClassify.SandboxClassifyId > 0 && firstClassify.Sort == 0 {
  840. updateSortStr := ` sort + 1 `
  841. _ = sandbox.UpdateSandboxSortByClassifyId(firstClassify.SandboxClassifyId, 0, firstClassify.SandboxId-1, updateSortStr)
  842. }
  843. sandboxInfo.Sort = 0 //那就是排在第一位
  844. sandboxInfo.ModifyTime = time.Now()
  845. updateCol = append(updateCol, "Sort", "ModifyTime")
  846. }
  847. if len(updateCol) > 0 {
  848. err = sandboxInfo.Update(updateCol)
  849. if err != nil {
  850. br.Msg = "移动失败"
  851. br.ErrMsg = "修改失败,Err:" + err.Error()
  852. return
  853. }
  854. }
  855. } else {
  856. if sandboxClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId != 0 {
  857. parentChartClassifyInfo, err := sandbox.GetSandboxClassifyById(req.ParentClassifyId)
  858. if err != nil {
  859. br.Msg = "移动失败"
  860. br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error()
  861. return
  862. }
  863. sandboxClassifyInfo.ParentId = parentChartClassifyInfo.SandboxClassifyId
  864. sandboxClassifyInfo.Level = parentChartClassifyInfo.Level + 1
  865. sandboxClassifyInfo.ModifyTime = time.Now()
  866. updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  867. } else if sandboxClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId == 0 {
  868. sandboxClassifyInfo.ParentId = req.ParentClassifyId
  869. sandboxClassifyInfo.Level = 1
  870. sandboxClassifyInfo.ModifyTime = time.Now()
  871. updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  872. }
  873. if req.PrevId > 0 {
  874. if req.PrevType == 1 {
  875. prevClassify, err := sandbox.GetSandboxClassifyById(req.PrevId)
  876. if err != nil {
  877. br.Msg = "移动失败"
  878. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  879. return
  880. }
  881. if req.NextId > 0 {
  882. if req.NextType == 1 {
  883. nextClassify, err := sandbox.GetSandboxClassifyById(req.NextId)
  884. if err != nil {
  885. br.Msg = "移动失败"
  886. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  887. return
  888. }
  889. if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == sandboxClassifyInfo.Sort {
  890. updateSortStr := `sort + 2`
  891. _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, prevClassify.SandboxClassifyId, prevClassify.Sort, updateSortStr)
  892. _ = sandbox.UpdateSandboxSortByClassifyId(prevClassify.SandboxClassifyId, prevClassify.Sort, 0, updateSortStr)
  893. } else {
  894. if nextClassify.Sort-prevClassify.Sort == 1 {
  895. updateSortStr := `sort + 1`
  896. _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr)
  897. _ = sandbox.UpdateSandboxSortByClassifyId(prevClassify.SandboxClassifyId, prevClassify.Sort, 0, updateSortStr)
  898. }
  899. }
  900. } else {
  901. nextChartInfo, err := sandbox.GetSandboxById(req.NextId)
  902. if err != nil {
  903. br.Msg = "移动失败"
  904. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  905. return
  906. }
  907. if prevClassify.Sort == nextChartInfo.Sort || prevClassify.Sort == sandboxClassifyInfo.Sort {
  908. updateSortStr := `sort + 2`
  909. _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, prevClassify.SandboxClassifyId, prevClassify.Sort, updateSortStr)
  910. _ = sandbox.UpdateSandboxSortByClassifyId(prevClassify.SandboxClassifyId, prevClassify.Sort, 0, updateSortStr)
  911. } else {
  912. if nextChartInfo.Sort-prevClassify.Sort == 1 {
  913. updateSortStr := `sort + 1`
  914. _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.SandboxClassifyId, updateSortStr)
  915. _ = sandbox.UpdateSandboxSortByClassifyId(prevClassify.SandboxClassifyId, prevClassify.Sort, 0, updateSortStr)
  916. }
  917. }
  918. }
  919. }
  920. sandboxClassifyInfo.Sort = prevClassify.Sort + 1
  921. sandboxClassifyInfo.ModifyTime = time.Now()
  922. updateCol = append(updateCol, "Sort", "ModifyTime")
  923. } else {
  924. prevSandbox, err := sandbox.GetSandboxById(req.PrevId)
  925. if err != nil {
  926. br.Msg = "移动失败"
  927. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  928. return
  929. }
  930. if req.NextId > 0 {
  931. if req.NextType == 1 {
  932. nextClassify, err := sandbox.GetSandboxClassifyById(req.NextId)
  933. if err != nil {
  934. br.Msg = "移动失败"
  935. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  936. return
  937. }
  938. if prevSandbox.Sort == nextClassify.Sort || prevSandbox.Sort == sandboxClassifyInfo.Sort {
  939. updateSortStr := `sort + 2`
  940. _ = sandbox.UpdateSandboxClassifySortByParentId(prevSandbox.SandboxClassifyId, 0, prevSandbox.Sort, updateSortStr)
  941. _ = sandbox.UpdateSandboxSortByClassifyId(prevSandbox.SandboxClassifyId, prevSandbox.Sort, prevSandbox.SandboxId, updateSortStr)
  942. } else {
  943. if nextClassify.Sort-prevSandbox.Sort == 1 {
  944. updateSortStr := `sort + 1`
  945. _ = sandbox.UpdateSandboxClassifySortByParentId(prevSandbox.SandboxClassifyId, 0, prevSandbox.Sort, updateSortStr)
  946. _ = sandbox.UpdateSandboxSortByClassifyId(prevSandbox.SandboxClassifyId, prevSandbox.Sort, prevSandbox.SandboxId, updateSortStr)
  947. }
  948. }
  949. } else {
  950. nextChartInfo, err := sandbox.GetSandboxById(req.NextId)
  951. if err != nil {
  952. br.Msg = "移动失败"
  953. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  954. return
  955. }
  956. if prevSandbox.Sort == nextChartInfo.Sort || prevSandbox.Sort == sandboxClassifyInfo.Sort {
  957. updateSortStr := `sort + 2`
  958. _ = sandbox.UpdateSandboxClassifySortByParentId(prevSandbox.SandboxClassifyId, 0, prevSandbox.Sort, updateSortStr)
  959. _ = sandbox.UpdateSandboxSortByClassifyId(prevSandbox.SandboxClassifyId, prevSandbox.Sort, prevSandbox.SandboxId, updateSortStr)
  960. } else {
  961. if nextChartInfo.Sort-prevSandbox.Sort == 1 {
  962. updateSortStr := `sort + 1`
  963. _ = sandbox.UpdateSandboxClassifySortByParentId(prevSandbox.SandboxClassifyId, 0, prevSandbox.Sort, updateSortStr)
  964. _ = sandbox.UpdateSandboxSortByClassifyId(prevSandbox.SandboxClassifyId, prevSandbox.Sort, prevSandbox.SandboxId, updateSortStr)
  965. }
  966. }
  967. }
  968. }
  969. sandboxClassifyInfo.Sort = prevSandbox.Sort + 1
  970. sandboxClassifyInfo.ModifyTime = time.Now()
  971. updateCol = append(updateCol, "Sort", "ModifyTime")
  972. }
  973. } else {
  974. firstClassify, err := sandbox.GetFirstSandboxClassifyByParentId(sandboxClassifyInfo.ParentId)
  975. if err != nil && !utils.IsErrNoRow(err) {
  976. br.Msg = "移动失败"
  977. br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  978. return
  979. }
  980. if firstClassify != nil && firstClassify.SandboxClassifyId > 0 && firstClassify.Sort == 0 {
  981. updateSortStr := ` sort + 1 `
  982. _ = sandbox.UpdateSandboxClassifySortByParentId(firstClassify.ParentId, firstClassify.SandboxClassifyId-1, 0, updateSortStr)
  983. }
  984. sandboxClassifyInfo.Sort = 0 //那就是排在第一位
  985. sandboxClassifyInfo.ModifyTime = time.Now()
  986. updateCol = append(updateCol, "Sort", "ModifyTime")
  987. }
  988. if len(updateCol) > 0 {
  989. err = sandboxClassifyInfo.Update(updateCol)
  990. if err != nil {
  991. br.Msg = "移动失败"
  992. br.ErrMsg = "修改失败,Err:" + err.Error()
  993. return
  994. }
  995. if req.ParentClassifyId > 0 {
  996. ids, err := sandbox.GetSandboxClassifySubcategories(req.ClassifyId)
  997. if err != nil {
  998. br.Msg = "查询子级分类id失败"
  999. br.ErrMsg = "查询子级分类id失败,Err:" + err.Error()
  1000. return
  1001. }
  1002. parentChartClassifyInfo, err := sandbox.GetSandboxClassifyById(req.ParentClassifyId)
  1003. if err != nil {
  1004. br.Msg = "移动失败"
  1005. br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error()
  1006. return
  1007. }
  1008. err = sandbox.UpdateSandboxClassifyChartPermissionById(parentChartClassifyInfo.ChartPermissionId, parentChartClassifyInfo.ChartPermissionName, ids)
  1009. if err != nil {
  1010. br.Msg = "修改子级分类错误"
  1011. br.ErrMsg = "修改子级分类错误,Err:" + err.Error()
  1012. return
  1013. }
  1014. }
  1015. }
  1016. }
  1017. br.Ret = 200
  1018. br.Success = true
  1019. br.Msg = "移动成功"
  1020. }
  1021. // @router /listV2 [get]
  1022. func (this *SandboxController) ListV2() {
  1023. br := new(models.BaseResponse).Init()
  1024. defer func() {
  1025. this.Data["json"] = br
  1026. this.ServeJSON()
  1027. }()
  1028. sysUser := this.SysUser
  1029. if sysUser == nil {
  1030. br.Msg = "请登录"
  1031. br.ErrMsg = "请登录,SysUser Is Empty"
  1032. br.Ret = 408
  1033. return
  1034. }
  1035. sandboxClassifyId, _ := this.GetInt("SandboxClassifyId")
  1036. pageSize, _ := this.GetInt("PageSize")
  1037. currentIndex, _ := this.GetInt("CurrentIndex")
  1038. keyWord := this.GetString("KeyWord")
  1039. var total int
  1040. page := paging.GetPaging(currentIndex, pageSize, total)
  1041. var startSize int
  1042. if pageSize <= 0 {
  1043. pageSize = utils.PageSize20
  1044. }
  1045. if currentIndex <= 0 {
  1046. currentIndex = 1
  1047. }
  1048. startSize = paging.StartIndex(currentIndex, pageSize)
  1049. classifyList, err := sandbox.GetAllSandboxClassify()
  1050. if err != nil && !utils.IsErrNoRow(err) {
  1051. br.Msg = "获取分类信息失败"
  1052. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  1053. return
  1054. }
  1055. classsifyMap := make(map[int]*sandbox.SandboxClassifyItems)
  1056. for _, v := range classifyList {
  1057. classsifyMap[v.SandboxClassifyId] = v
  1058. }
  1059. var condition string
  1060. var pars []interface{}
  1061. if sandboxClassifyId > 0 {
  1062. childIds := make([]int, 0)
  1063. sandboxService.GetSandBoxClassifyChildIds(sandboxClassifyId, classsifyMap, &childIds)
  1064. if len(childIds) > 0 {
  1065. ids := utils.IntArr2joinString(childIds, ",")
  1066. condition += " AND sandbox_classify_id IN(" + ids + ") "
  1067. } else {
  1068. condition += " AND sandbox_classify_id = ? "
  1069. pars = append(pars, sandboxClassifyId)
  1070. }
  1071. }
  1072. if keyWord != "" {
  1073. condition += ` AND ( name LIKE '%` + keyWord + `%' )`
  1074. }
  1075. isShowMe, _ := this.GetBool("IsShowMe")
  1076. if isShowMe {
  1077. condition += ` AND sys_user_id = ? `
  1078. pars = append(pars, sysUser.AdminId)
  1079. }
  1080. condition += ` AND is_delete = 0 `
  1081. list, err := sandbox.GetSandboxListByCondition(condition, pars, startSize, pageSize)
  1082. if err != nil && !utils.IsErrNoRow(err) {
  1083. br.Success = true
  1084. br.Msg = "获取沙盘信息失败"
  1085. br.ErrMsg = "获取沙盘信息失败,Err:" + err.Error()
  1086. return
  1087. }
  1088. for i, v := range list {
  1089. parentIds := make([]int, 0)
  1090. sandboxService.GetSandBoxParentIds(v.SandboxClassifyId, classsifyMap, &parentIds)
  1091. ids := utils.IntArr2joinString(parentIds, ",")
  1092. list[i].ParentIds = ids
  1093. }
  1094. resp := new(sandbox.SandboxListResp)
  1095. if list == nil || len(list) <= 0 || (err != nil && utils.IsErrNoRow(err)) {
  1096. items := make([]*sandbox.SandboxListItems, 0)
  1097. resp.Paging = page
  1098. resp.List = items
  1099. br.Ret = 200
  1100. br.Success = true
  1101. br.Msg = "获取成功"
  1102. return
  1103. }
  1104. dataCount, err := sandbox.GetSandboxListCountByCondition(condition, pars)
  1105. if err != nil && !utils.IsErrNoRow(err) {
  1106. br.Msg = "获取指标信息失败"
  1107. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  1108. return
  1109. }
  1110. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  1111. resp.Paging = page
  1112. resp.List = list
  1113. br.Ret = 200
  1114. br.Success = true
  1115. br.Msg = "获取成功"
  1116. br.Data = resp
  1117. }
  1118. // @router /saveV2 [post]
  1119. func (this *SandboxController) SaveV2() {
  1120. br := new(models.BaseResponse).Init()
  1121. defer func() {
  1122. this.Data["json"] = br
  1123. this.ServeJSON()
  1124. }()
  1125. sysUser := this.SysUser
  1126. if sysUser == nil {
  1127. br.Msg = "请登录"
  1128. br.ErrMsg = "请登录,SysUser Is Empty"
  1129. br.Ret = 408
  1130. return
  1131. }
  1132. var req request.AddAndEditSandboxV2
  1133. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1134. if err != nil {
  1135. br.Msg = "参数解析异常!"
  1136. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1137. return
  1138. }
  1139. var sandboxResp *sandbox.SandboxSaveResp
  1140. var errMsg string
  1141. var sandBoxData *sandbox.Sandbox
  1142. if req.SandboxId <= 0 {
  1143. sandboxResp, err = sandboxService.AddSandboxV2(req, sysUser.AdminId, sysUser.RealName)
  1144. if err != nil {
  1145. br.Msg = "保存失败!"
  1146. if errMsg != `` {
  1147. br.Msg = errMsg
  1148. }
  1149. br.ErrMsg = "保存失败,Err:" + err.Error()
  1150. return
  1151. }
  1152. sandBoxData = sandboxResp.Sandbox
  1153. } else {
  1154. sandboxInfo := &sandbox.Sandbox{
  1155. SandboxId: req.SandboxId,
  1156. Name: utils.TrimStr(req.Name),
  1157. Content: req.Content,
  1158. MindmapData: req.MindmapData,
  1159. PicUrl: utils.TrimStr(req.PicUrl),
  1160. ModifyTime: time.Now(),
  1161. SandboxClassifyId: req.SandboxClassifyId,
  1162. Style: req.Style,
  1163. }
  1164. var updateSandboxColumn = []string{}
  1165. if req.PicUrl == "" {
  1166. updateSandboxColumn = []string{"Name", "Content", "MindmapData", "ModifyTime", "SandboxClassifyId", "Style"}
  1167. } else {
  1168. updateSandboxColumn = []string{"Name", "Content", "MindmapData", "PicUrl", "ModifyTime", "SandboxClassifyId", "Style"}
  1169. }
  1170. err = sandboxInfo.Update(updateSandboxColumn)
  1171. if err != nil {
  1172. br.Msg = "保存失败!"
  1173. if errMsg != `` {
  1174. br.Msg = errMsg
  1175. }
  1176. br.ErrMsg = "保存失败,Err:" + err.Error()
  1177. return
  1178. }
  1179. sandBoxData = sandboxInfo
  1180. }
  1181. _ = data.SaveSandBoxEdbInfoRelation(sandBoxData.SandboxId, sandBoxData.Content)
  1182. msg := "保存成功"
  1183. br.Ret = 200
  1184. br.Success = true
  1185. br.Msg = msg
  1186. br.Data = sandboxResp
  1187. }
  1188. // @router /deleteV2 [post]
  1189. func (this *SandboxController) DeleteV2() {
  1190. br := new(models.BaseResponse).Init()
  1191. defer func() {
  1192. this.Data["json"] = br
  1193. this.ServeJSON()
  1194. }()
  1195. sysUser := this.SysUser
  1196. if sysUser == nil {
  1197. br.Msg = "请登录"
  1198. br.ErrMsg = "请登录,SysUser Is Empty"
  1199. br.Ret = 408
  1200. return
  1201. }
  1202. var req request.DeleteSandbox
  1203. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1204. if err != nil {
  1205. br.Msg = "参数解析异常!"
  1206. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1207. return
  1208. }
  1209. if req.SandboxId <= 0 {
  1210. br.Msg = "缺少沙盘编号"
  1211. return
  1212. }
  1213. err = sandboxService.DeleteSandbox(req.SandboxId)
  1214. if err != nil {
  1215. br.Msg = err.Error()
  1216. return
  1217. }
  1218. msg := "删除成功"
  1219. br.Ret = 200
  1220. br.Success = true
  1221. br.Msg = msg
  1222. }
  1223. // @router /detail [get]
  1224. func (this *SandboxController) GetSandboxDetail() {
  1225. br := new(models.BaseResponse).Init()
  1226. defer func() {
  1227. this.Data["json"] = br
  1228. this.ServeJSON()
  1229. }()
  1230. sysUser := this.SysUser
  1231. if sysUser == nil {
  1232. br.Msg = "请登录"
  1233. br.ErrMsg = "请登录,SysUser Is Empty"
  1234. br.Ret = 408
  1235. return
  1236. }
  1237. sandboxId, _ := this.GetInt("SandboxId")
  1238. if sandboxId == 0 {
  1239. br.Msg = "缺少沙盘Id"
  1240. return
  1241. }
  1242. sandboxInfo, err := sandbox.GetSandboxById(sandboxId)
  1243. if err != nil {
  1244. br.Msg = "获取失败"
  1245. br.ErrMsg = "获取失败,Err:" + err.Error()
  1246. return
  1247. }
  1248. msg := "获取成功"
  1249. br.Ret = 200
  1250. br.Success = true
  1251. br.Msg = msg
  1252. br.Data = sandboxInfo
  1253. }
  1254. //// @router /classify/list [get]
  1255. //// @router /move [post]
  1256. //// @router /classify/move [post]
  1257. // @router /classifyList [get]
  1258. func (this *SandboxController) SandboxClassifyList() {
  1259. br := new(models.BaseResponse).Init()
  1260. defer func() {
  1261. this.Data["json"] = br
  1262. this.ServeJSON()
  1263. }()
  1264. resp := new(sandbox.SandboxClassifyListResp)
  1265. rootList, err := sandbox.GetSandboxClassifyByParentId(0)
  1266. if err != nil && !utils.IsErrNoRow(err) {
  1267. br.Msg = "获取失败"
  1268. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1269. return
  1270. }
  1271. classifyAll, err := sandbox.GetSandboxClassifyAll()
  1272. if err != nil && !utils.IsErrNoRow(err) {
  1273. br.Msg = "获取失败"
  1274. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1275. return
  1276. }
  1277. nodeAll := make([]*sandbox.SandboxClassifyItems, 0)
  1278. for k := range rootList {
  1279. rootNode := rootList[k]
  1280. sandboxService.SandboxClassifyItemsMakeTree(this.SysUser, classifyAll, rootNode)
  1281. nodeAll = append(nodeAll, rootNode)
  1282. }
  1283. resp.AllNodes = nodeAll
  1284. br.Ret = 200
  1285. br.Success = true
  1286. br.Msg = "获取成功"
  1287. br.Data = resp
  1288. }
  1289. // @router /link/check [post]
  1290. func (this *SandboxController) LinkEdbInfoCheck() {
  1291. br := new(models.BaseResponse).Init()
  1292. defer func() {
  1293. this.Data["json"] = br
  1294. this.ServeJSON()
  1295. }()
  1296. var req sandbox.SandboxLinkCheckReq
  1297. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1298. if err != nil {
  1299. br.Msg = "参数解析异常!"
  1300. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1301. return
  1302. }
  1303. resp := new(sandbox.SandboxLinkCheckResp)
  1304. edbInfoList, err := data_manage.GetEdbInfoByIdList(req.EdbInfoIdList)
  1305. if err != nil {
  1306. br.Msg = "获取指标信息失败"
  1307. br.ErrMsg = "获取指标信息失败,err:" + err.Error()
  1308. return
  1309. }
  1310. edbList := make([]*sandbox.SandboxLinkCheckItem, 0)
  1311. for _, v := range edbInfoList {
  1312. tmp := &sandbox.SandboxLinkCheckItem{
  1313. Id: v.EdbInfoId,
  1314. Name: v.EdbName,
  1315. UniqueCode: v.UniqueCode,
  1316. ClassifyId: v.ClassifyId,
  1317. }
  1318. edbList = append(edbList, tmp)
  1319. }
  1320. chartList, err := data_manage.GetChartInfoByIdList(req.ChartInfoIdList)
  1321. if err != nil {
  1322. br.Msg = `获取失败`
  1323. br.ErrMsg = `获取图表列表失败,ERR:` + err.Error()
  1324. return
  1325. }
  1326. chartListTmp := make([]*sandbox.SandboxLinkCheckItem, 0)
  1327. for _, v := range chartList {
  1328. tmp := &sandbox.SandboxLinkCheckItem{
  1329. Id: v.ChartInfoId,
  1330. Name: v.ChartName,
  1331. UniqueCode: v.UniqueCode,
  1332. ClassifyId: v.ChartClassifyId,
  1333. }
  1334. chartListTmp = append(chartListTmp, tmp)
  1335. }
  1336. reportList, err := models.GetSimpleReportByIds(req.ReportIdList)
  1337. if err != nil {
  1338. br.Msg = `获取失败`
  1339. br.ErrMsg = `获取报告列表失败,ERR:` + err.Error()
  1340. return
  1341. }
  1342. reportListTmp := make([]*sandbox.SandboxLinkCheckItem, 0)
  1343. for _, v := range reportList {
  1344. tmp := &sandbox.SandboxLinkCheckItem{
  1345. Id: v.Id,
  1346. Name: v.Title,
  1347. UniqueCode: v.ReportCode,
  1348. }
  1349. reportListTmp = append(reportListTmp, tmp)
  1350. }
  1351. resp.EdbInfoIdList = edbList
  1352. resp.ChartInfoIdList = chartListTmp
  1353. resp.ReportIdList = reportListTmp
  1354. br.Ret = 200
  1355. br.Msg = "检测成功"
  1356. br.Success = true
  1357. br.Data = resp
  1358. }