sandbox.go 51 KB

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