sandbox.go 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375
  1. package sandbox
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/controllers"
  5. "eta/eta_api/models"
  6. "eta/eta_api/models/data_manage"
  7. "eta/eta_api/models/sandbox"
  8. "eta/eta_api/models/sandbox/request"
  9. "eta/eta_api/models/sandbox/response"
  10. sandboxService "eta/eta_api/services/sandbox"
  11. "eta/eta_api/utils"
  12. "fmt"
  13. "github.com/rdlucklib/rdluck_tools/paging"
  14. "time"
  15. )
  16. // versionSize 版本列表第一页数据约定是:3条
  17. var versionSize = 3
  18. // SandboxController 逻辑导图
  19. type SandboxController struct {
  20. controllers.BaseAuthController
  21. }
  22. // List
  23. // @Title 逻辑导图列表
  24. // @Description 逻辑导图列表接口
  25. // @Param PageSize query int true "每页数据条数"
  26. // @Param CurrentIndex query int true "当前页页码,从1开始"
  27. // @Param ChartPermissionId query int true "权限编号id"
  28. // @Param Keyword query string false "搜索关键词:沙盘名称/编辑人名称"
  29. // @Success 200 {object} response.SandboxListResp
  30. // @router /list [get]
  31. //func (this *SandboxController) List() {
  32. // br := new(models.BaseResponse).Init()
  33. // defer func() {
  34. // this.Data["json"] = br
  35. // this.ServeJSON()
  36. // }()
  37. //
  38. // chartPermissionId, _ := this.GetInt("ChartPermissionId")
  39. // keyword := this.GetString("Keyword")
  40. //
  41. // pageSize, _ := this.GetInt("PageSize")
  42. // currentIndex, _ := this.GetInt("CurrentIndex")
  43. //
  44. // var startSize int
  45. // if pageSize <= 0 {
  46. // pageSize = utils.PageSize20
  47. // }
  48. // if currentIndex <= 0 {
  49. // currentIndex = 1
  50. // }
  51. // startSize = paging.StartIndex(currentIndex, pageSize)
  52. //
  53. // var condition string
  54. // var pars []interface{}
  55. //
  56. // if chartPermissionId > 0 {
  57. // condition += " AND a.chart_permission_id=? "
  58. // pars = append(pars, chartPermissionId)
  59. // }
  60. //
  61. // if keyword != "" {
  62. // condition += ` AND ( a.name LIKE '%` + keyword + `%' OR b.name LIKE '%` + keyword + `%' )`
  63. // }
  64. //
  65. // //获取指标信息
  66. // total, list, err := sandbox.GetList(condition, pars, startSize, pageSize)
  67. // if err != nil && err.Error() != utils.ErrNoRow() {
  68. // br.Success = true
  69. // br.Msg = "获取沙盘列表失败"
  70. // br.ErrMsg = "获取沙盘列表失败,Err:" + err.Error()
  71. // return
  72. // }
  73. //
  74. // if list == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  75. // list = make([]*sandbox.SandboxListItem, 0)
  76. // }
  77. //
  78. // if len(list) > 0 {
  79. // sandboxIdList := make([]int, 0)
  80. // for _, v := range list {
  81. // sandboxIdList = append(sandboxIdList, v.SandboxId)
  82. // }
  83. //
  84. // sandboxVersionTotalList, err := sandbox.GetTotalSandboxVersionBySandboxIdList(sandboxIdList)
  85. // if err != nil {
  86. // br.Success = true
  87. // br.Msg = "获取沙盘版本数量失败"
  88. // br.ErrMsg = "获取沙盘版本数量失败,Err:" + err.Error()
  89. // return
  90. // }
  91. // sandboxVersionTotalMap := make(map[int]int)
  92. //
  93. // for _, v := range sandboxVersionTotalList {
  94. // sandboxVersionTotalMap[v.SandboxId] = v.Total
  95. // }
  96. //
  97. // for _, item := range list {
  98. // /*key := fmt.Sprint(`crm:sandbox:edit:`, item.SandboxId)
  99. // opUserId, _ := utils.Rc.RedisInt(key)
  100. // //如果当前没有人操作,获取当前操作人是本人,那么编辑按钮可用
  101. // if opUserId <= 0 || (opUserId == this.SysUser.AdminId) {
  102. // item.CanEdit = true
  103. // } else {
  104. // adminInfo, errAdmin := system.GetSysUserById(opUserId)
  105. // if errAdmin != nil {
  106. // br.Msg = "获取失败"
  107. // br.ErrMsg = "获取失败,Err:" + errAdmin.Error()
  108. // return
  109. // }
  110. // item.Editor = adminInfo.RealName
  111. // }*/
  112. // markStatus, err := sandboxService.UpdateSandboxEditMark(item.SandboxId, this.SysUser.AdminId, 2, this.SysUser.RealName)
  113. // if err != nil {
  114. // br.Msg = "查询标记状态失败"
  115. // br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  116. // return
  117. // }
  118. // if markStatus.Status == 0 {
  119. // item.CanEdit = true
  120. // } else {
  121. // item.Editor = markStatus.Editor
  122. // }
  123. //
  124. // // 沙盘版本数量
  125. // versionTotal := sandboxVersionTotalMap[item.SandboxId]
  126. // item.VersionTotal = versionTotal
  127. // }
  128. // }
  129. //
  130. // page := paging.GetPaging(currentIndex, pageSize, total)
  131. // resp := response.SandboxListResp{
  132. // Paging: page,
  133. // List: list,
  134. // }
  135. // br.Ret = 200
  136. // br.Success = true
  137. // br.Msg = "获取成功"
  138. // br.Data = resp
  139. //}
  140. // FirstVersionList
  141. // @Title 逻辑导图版本列表(列表页第一页)
  142. // @Description 逻辑导图版本列表接口(列表页第一页)
  143. // @Param SandboxId query int true "沙盘id"
  144. // @Success 200 {object} response.SandboxVersionListResp
  145. // @router /version/first_list [get]
  146. func (this *SandboxController) FirstVersionList() {
  147. br := new(models.BaseResponse).Init()
  148. defer func() {
  149. this.Data["json"] = br
  150. this.ServeJSON()
  151. }()
  152. sandboxId, _ := this.GetInt("SandboxId")
  153. keyword := this.GetString("Keyword")
  154. currentIndex := 1
  155. pageSize := versionSize
  156. startSize := 0
  157. var condition string
  158. var pars []interface{}
  159. if sandboxId <= 0 {
  160. br.Msg = "参数错误,沙盘编号id必传!"
  161. br.ErrMsg = "参数错误,沙盘编号id必传"
  162. return
  163. }
  164. condition += " AND a.sandbox_id=? "
  165. pars = append(pars, sandboxId)
  166. //不能筛选出当前版本
  167. condition += " AND b.curr_version < a.curr_version "
  168. if keyword != "" {
  169. condition += ` AND ( a.name LIKE ? OR b.name LIKE ? )`
  170. pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  171. }
  172. //获取指标信息
  173. total, list, err := sandbox.GetVersionList(condition, pars, startSize, pageSize)
  174. if err != nil && err.Error() != utils.ErrNoRow() {
  175. br.Success = true
  176. br.Msg = "获取沙盘列表失败"
  177. br.ErrMsg = "获取沙盘列表失败,Err:" + err.Error()
  178. return
  179. }
  180. if list == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  181. list = make([]*sandbox.SandboxVersionListItem, 0)
  182. }
  183. for _, v := range list {
  184. v.ModifyTime = v.CreateTime
  185. }
  186. page := paging.GetPaging(currentIndex, pageSize, total)
  187. resp := response.SandboxVersionListResp{
  188. Paging: page,
  189. List: list,
  190. }
  191. br.Ret = 200
  192. br.Success = true
  193. br.Msg = "获取成功"
  194. br.Data = resp
  195. }
  196. // VersionList
  197. // @Title 逻辑导图版本列表
  198. // @Description 逻辑导图版本列表接口
  199. // @Param PageSize query int true "每页数据条数"
  200. // @Param CurrentIndex query int true "当前页页码,从1开始"
  201. // @Param SandboxId query int true "沙盘id"
  202. // @Success 200 {object} response.SandboxVersionListResp
  203. // @router /version/list [get]
  204. func (this *SandboxController) VersionList() {
  205. br := new(models.BaseResponse).Init()
  206. defer func() {
  207. this.Data["json"] = br
  208. this.ServeJSON()
  209. }()
  210. sandboxId, _ := this.GetInt("SandboxId")
  211. keyWord := this.GetString("Keyword")
  212. pageSize, _ := this.GetInt("PageSize")
  213. currentIndex, _ := this.GetInt("CurrentIndex")
  214. var startSize int
  215. if pageSize <= 0 {
  216. pageSize = utils.PageSize20
  217. }
  218. //第一页需要返回的几条数据(目前是3条)
  219. startSize = paging.StartIndex(currentIndex, pageSize) + versionSize
  220. var condition string
  221. var pars []interface{}
  222. if sandboxId <= 0 {
  223. br.Msg = "参数错误,沙盘编号id必传!"
  224. br.ErrMsg = "参数错误,沙盘编号id必传"
  225. return
  226. }
  227. condition += " AND a.sandbox_id=? "
  228. pars = append(pars, sandboxId)
  229. //不能筛选出当前版本
  230. condition += " AND b.curr_version < a.curr_version "
  231. if keyWord != "" {
  232. condition += ` AND ( a.op_user_name LIKE ? OR a.name LIKE ? or a.op_user_name LIKE ? OR a.name LIKE ? )`
  233. pars = utils.GetLikeKeywordPars(pars, keyWord, 4)
  234. }
  235. //获取指标信息
  236. total, list, err := sandbox.GetVersionList(condition, pars, startSize, pageSize)
  237. if err != nil && err.Error() != utils.ErrNoRow() {
  238. br.Success = true
  239. br.Msg = "获取沙盘列表失败"
  240. br.ErrMsg = "获取沙盘列表失败,Err:" + err.Error()
  241. return
  242. }
  243. if list == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  244. list = make([]*sandbox.SandboxVersionListItem, 0)
  245. }
  246. for _, v := range list {
  247. v.ModifyTime = v.CreateTime
  248. /*key := fmt.Sprint(`crm:sandbox:edit:`, v.SandboxId)
  249. opUserId, _ := utils.Rc.RedisInt(key)
  250. //如果当前没有人操作,获取当前操作人是本人,那么编辑按钮可用
  251. if opUserId <= 0 || (opUserId == this.SysUser.AdminId) {
  252. v.CanEdit = true
  253. }*/
  254. markStatus, err := sandboxService.UpdateSandboxEditMark(v.SandboxId, this.SysUser.AdminId, 2, this.SysUser.RealName)
  255. if err != nil {
  256. br.Msg = "查询标记状态失败"
  257. br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  258. return
  259. }
  260. if markStatus.Status == 0 {
  261. v.CanEdit = true
  262. }
  263. }
  264. //过滤第一页的几条数据(目前是3条)
  265. total = total - versionSize
  266. if total <= 0 {
  267. total = 0
  268. }
  269. page := paging.GetPaging(currentIndex, pageSize, total)
  270. resp := response.SandboxVersionListResp{
  271. Paging: page,
  272. List: list,
  273. }
  274. br.Ret = 200
  275. br.Success = true
  276. br.Msg = "获取成功"
  277. br.Data = resp
  278. }
  279. //// Save
  280. //// @Title 新增/编辑保存沙盘
  281. //// @Description 新增/编辑保存沙盘接口
  282. //// @Param request body request.AddAndEditSandbox true "type json string"
  283. //// @Success 200 {object} sandbox.Sandbox
  284. //// @router /save [post]
  285. //func (this *SandboxController) Save() {
  286. // br := new(models.BaseResponse).Init()
  287. // defer func() {
  288. // this.Data["json"] = br
  289. // this.ServeJSON()
  290. // }()
  291. // sysUser := this.SysUser
  292. // if sysUser == nil {
  293. // br.Msg = "请登录"
  294. // br.ErrMsg = "请登录,SysUser Is Empty"
  295. // br.Ret = 408
  296. // return
  297. // }
  298. // var req request.AddAndEditSandbox
  299. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  300. // if err != nil {
  301. // br.Msg = "参数解析异常!"
  302. // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  303. // return
  304. // }
  305. //
  306. // var sandboxResp *sandbox.SandboxSaveResp
  307. // // 获取系统菜单, 如果没有对应的字段的特殊处理项, 则忽略必填
  308. // menus, e := system.GetSysMenuItemsByCondition(` AND hidden = 0`, make([]interface{}, 0), []string{}, ``)
  309. // if e != nil {
  310. // br.Msg = "保存失败"
  311. // br.ErrMsg = "获取菜单列表失败, Err: " + e.Error()
  312. // return
  313. // }
  314. // menuMap := make(map[string]bool)
  315. // for _, m := range menus {
  316. // if m.ButtonCode != "" {
  317. // menuMap[m.ButtonCode] = true
  318. // }
  319. // }
  320. // ignoreVariety := false
  321. // if !menuMap[system.MenuSpecialHandleSandboxVariety] {
  322. // ignoreVariety = true
  323. // }
  324. //
  325. // var errMsg string
  326. // if req.SandboxVersionCode == `` {
  327. // //新增沙盘
  328. // sandboxResp, err = sandboxService.AddSandbox(req, sysUser.AdminId, sysUser.RealName, ignoreVariety)
  329. // } else {
  330. // ////更新当前编辑中的状态缓存
  331. // //err = sandboxService.UpdateSandboxEditMark(req.SandboxId, sysUser.AdminId, 1)
  332. // //if err != nil {
  333. // // br.Msg = err.Error()
  334. // // return
  335. // //}
  336. //
  337. // //编辑沙盘
  338. // sandboxResp, err, errMsg = sandboxService.UpdateSandbox(req, sysUser.AdminId, sysUser.RealName, ignoreVariety)
  339. // }
  340. // if err != nil {
  341. // br.Msg = "保存失败!"
  342. // if errMsg != `` {
  343. // br.Msg = errMsg
  344. // }
  345. // br.ErrMsg = "保存失败,Err:" + err.Error()
  346. // return
  347. // }
  348. //
  349. // msg := "保存成功"
  350. // br.Ret = 200
  351. // br.Success = true
  352. // br.Msg = msg
  353. // br.Data = sandboxResp
  354. //}
  355. // AddSandboxDraft
  356. // @Title 添加沙盘草稿
  357. // @Description 添加沙盘草稿接口
  358. // @Param request body request.AddAndEditSandbox true "type json string"
  359. // @Success 200 {object} sandbox.SandboxDraft
  360. // @Fail 202 另外的人在操作,不要重复添加草稿;204 错误了,当时不是必要性的错误,不用将错误信息暴露给用户
  361. // @router /draft/add [post]
  362. func (this *SandboxController) AddSandboxDraft() {
  363. br := new(models.BaseResponse).Init()
  364. br.IsSendEmail = false
  365. defer func() {
  366. this.Data["json"] = br
  367. this.ServeJSON()
  368. }()
  369. sysUser := this.SysUser
  370. if sysUser == nil {
  371. br.Msg = "请登录"
  372. br.ErrMsg = "请登录,SysUser Is Empty"
  373. br.Ret = 408
  374. return
  375. }
  376. var req request.AddAndEditSandbox
  377. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  378. if err != nil {
  379. br.Msg = "参数解析异常!"
  380. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  381. return
  382. }
  383. if req.SandboxVersionCode == `` {
  384. br.Msg = "请传入沙盘版本!"
  385. return
  386. }
  387. // 获取沙盘版本信息
  388. sandboxVersion, err := sandbox.GetSandboxVersionBySandboxVersionCode(req.SandboxVersionCode)
  389. if err != nil {
  390. if err.Error() == utils.ErrNoRow() {
  391. br.Msg = "找不到该版本!"
  392. br.ErrMsg = "找不到该版本"
  393. return
  394. }
  395. br.Msg = "找不到该版本!"
  396. br.ErrMsg = "找不到该版本,Err:" + err.Error()
  397. br.IsSendEmail = false
  398. return
  399. }
  400. //更新标记key
  401. markStatus, err := sandboxService.UpdateSandboxEditMark(sandboxVersion.SandboxId, sysUser.AdminId, 1, sysUser.RealName)
  402. if err != nil {
  403. br.Msg = err.Error()
  404. return
  405. }
  406. if markStatus.Status == 1 {
  407. br.Msg = markStatus.Msg
  408. return
  409. }
  410. //新增沙盘草稿
  411. sandboxDraftInfo, err := sandboxService.AddSandboxDraft(sandboxVersion.SandboxId, req, sysUser.AdminId, sysUser.RealName)
  412. if err != nil {
  413. br.Msg = "保存失败!"
  414. br.ErrMsg = "保存失败,Err:" + err.Error()
  415. br.Ret = 204 //204 (无内容) :服务器成功处理了请求,但没有返回任何内容。
  416. return
  417. }
  418. msg := "保存成功"
  419. br.Ret = 200
  420. br.Success = true
  421. br.Msg = msg
  422. br.Data = sandboxDraftInfo
  423. }
  424. // MarkEditStatus
  425. // @Title 标记沙盘编辑状态
  426. // @Description 标记沙盘编辑状态接口
  427. // @Param request body request.MarkEditSandbox true "type json string"
  428. // @Success 200 标记成功 ;202 标记成功
  429. // @router /mark [post]
  430. func (this *SandboxController) MarkEditStatus() {
  431. br := new(models.BaseResponse).Init()
  432. defer func() {
  433. this.Data["json"] = br
  434. this.ServeJSON()
  435. }()
  436. sysUser := this.SysUser
  437. if sysUser == nil {
  438. br.Msg = "请登录"
  439. br.ErrMsg = "请登录,SysUser Is Empty"
  440. br.Ret = 408
  441. return
  442. }
  443. var req request.MarkEditSandbox
  444. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  445. if err != nil {
  446. br.Msg = "参数解析异常!"
  447. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  448. return
  449. }
  450. if req.SandboxId <= 0 {
  451. br.Msg = "缺少沙盘编号"
  452. return
  453. }
  454. if req.Status <= 0 {
  455. br.Msg = "标记状态异常"
  456. return
  457. }
  458. //更新标记key
  459. data, err := sandboxService.UpdateSandboxEditMark(req.SandboxId, sysUser.AdminId, req.Status, sysUser.RealName)
  460. if err != nil {
  461. br.Msg = err.Error()
  462. return
  463. }
  464. msg := "标记成功"
  465. br.Ret = 200
  466. br.Success = true
  467. br.Msg = msg
  468. br.Data = data
  469. }
  470. // GetSandboxVersionDetail
  471. // @Title 获取沙盘版本数据详情(已保存的)
  472. // @Description 获取沙盘版本数据详情接口(已保存的)
  473. // @Param SandboxVersionCode query string true "沙盘版本code"
  474. // @Success 200 {object} sandbox.SandboxVersion
  475. // @router /version/detail [get]
  476. func (this *SandboxController) GetSandboxVersionDetail() {
  477. br := new(models.BaseResponse).Init()
  478. defer func() {
  479. this.Data["json"] = br
  480. this.ServeJSON()
  481. }()
  482. sysUser := this.SysUser
  483. if sysUser == nil {
  484. br.Msg = "请登录"
  485. br.ErrMsg = "请登录,SysUser Is Empty"
  486. br.Ret = 408
  487. return
  488. }
  489. sandboxVersionCode := this.GetString("SandboxVersionCode")
  490. if sandboxVersionCode == "" {
  491. br.Msg = "缺少沙盘版本编号"
  492. return
  493. }
  494. //获取沙盘数据详情(已保存的)
  495. sandboxVersionInfo, err := sandboxService.GetSandboxVersionDetailByCode(sandboxVersionCode)
  496. if err != nil {
  497. br.Msg = "获取失败"
  498. br.ErrMsg = "获取失败,Err:" + err.Error()
  499. return
  500. }
  501. msg := "获取成功"
  502. br.Ret = 200
  503. br.Success = true
  504. br.Msg = msg
  505. br.Data = sandboxVersionInfo
  506. }
  507. // GetLastSandboxInfo
  508. // @Title 获取最后一次编辑的沙盘数据详情
  509. // @Description 获取最后一次编辑的沙盘数据详情接口
  510. // @Param SandboxId query int true "沙盘编号id"
  511. // @Success 200 {object} sandbox.Sandbox
  512. // @router /last_info [get]
  513. func (this *SandboxController) GetLastSandboxInfo() {
  514. br := new(models.BaseResponse).Init()
  515. defer func() {
  516. this.Data["json"] = br
  517. this.ServeJSON()
  518. }()
  519. sysUser := this.SysUser
  520. if sysUser == nil {
  521. br.Msg = "请登录"
  522. br.ErrMsg = "请登录,SysUser Is Empty"
  523. br.Ret = 408
  524. return
  525. }
  526. sandboxId, _ := this.GetInt("SandboxId", 0)
  527. if sandboxId <= 0 {
  528. br.Msg = "缺少沙盘编号"
  529. return
  530. }
  531. //获取最后一次操作的沙盘数据
  532. sandboxInfo, err := sandboxService.GetLastSandboxInfo(sandboxId)
  533. if err != nil {
  534. br.Msg = err.Error()
  535. return
  536. }
  537. msg := "获取成功"
  538. br.Ret = 200
  539. br.Success = true
  540. br.Msg = msg
  541. br.Data = sandboxInfo
  542. }
  543. // Delete
  544. // @Title 删除沙盘
  545. // @Description 删除沙盘接口
  546. // @Param request body request.DeleteSandbox true "type json string"
  547. // @Success 200 标记成功
  548. // @router /delete [post]
  549. func (this *SandboxController) Delete() {
  550. br := new(models.BaseResponse).Init()
  551. defer func() {
  552. this.Data["json"] = br
  553. this.ServeJSON()
  554. }()
  555. sysUser := this.SysUser
  556. if sysUser == nil {
  557. br.Msg = "请登录"
  558. br.ErrMsg = "请登录,SysUser Is Empty"
  559. br.Ret = 408
  560. return
  561. }
  562. var req request.DeleteSandbox
  563. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  564. if err != nil {
  565. br.Msg = "参数解析异常!"
  566. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  567. return
  568. }
  569. if req.SandboxId <= 0 {
  570. br.Msg = "缺少沙盘编号"
  571. return
  572. }
  573. /*key := fmt.Sprint(`crm:sandbox:edit:`, req.SandboxId)
  574. opUserId, _ := utils.Rc.RedisInt(key)
  575. //如果当前有人操作,且获取当前操作人不是本人,那么不允许删除
  576. if opUserId > 0 && opUserId != this.SysUser.AdminId {
  577. br.Msg = "当前有其他人正在编辑,不允许删除该沙盘"
  578. return
  579. }*/
  580. markStatus, err := sandboxService.UpdateSandboxEditMark(req.SandboxId, this.SysUser.AdminId, 2, this.SysUser.RealName)
  581. if err != nil {
  582. br.Msg = "查询标记状态失败"
  583. br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  584. return
  585. }
  586. if markStatus.Status == 1 {
  587. br.Msg = fmt.Sprintf("当前%s正在编辑,不允许删除该沙盘", markStatus.Editor)
  588. return
  589. }
  590. //删除沙盘
  591. err = sandboxService.DeleteSandbox(req.SandboxId)
  592. if err != nil {
  593. br.Msg = err.Error()
  594. return
  595. }
  596. msg := "删除成功"
  597. br.Ret = 200
  598. br.Success = true
  599. br.Msg = msg
  600. }
  601. //// DeleteVersion
  602. //// @Title 删除沙盘版本
  603. //// @Description 删除沙盘版本接口
  604. //// @Param request body request.DeleteSandbox true "type json string"
  605. //// @Success 200 标记成功
  606. //// @router /version/delete [post]
  607. //func (this *SandboxController) DeleteVersion() {
  608. // br := new(models.BaseResponse).Init()
  609. // defer func() {
  610. // this.Data["json"] = br
  611. // this.ServeJSON()
  612. // }()
  613. // sysUser := this.SysUser
  614. // if sysUser == nil {
  615. // br.Msg = "请登录"
  616. // br.ErrMsg = "请登录,SysUser Is Empty"
  617. // br.Ret = 408
  618. // return
  619. // }
  620. // var req request.DeleteSandboxVersion
  621. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  622. // if err != nil {
  623. // br.Msg = "参数解析异常!"
  624. // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  625. // return
  626. // }
  627. //
  628. // if req.SandboxVersionCode == `` {
  629. // br.Msg = "缺少沙盘版本号"
  630. // return
  631. // }
  632. // //删除沙盘
  633. // err, errMsg := sandboxService.DeleteSandboxVersion(req.SandboxVersionCode, this.SysUser.AdminId)
  634. // if err != nil {
  635. // br.Msg = "删除版本失败"
  636. // if errMsg != `` {
  637. // br.Msg = errMsg
  638. // }
  639. // br.ErrMsg = err.Error()
  640. // return
  641. // }
  642. //
  643. // msg := "删除成功"
  644. // br.Ret = 200
  645. // br.Success = true
  646. // br.Msg = msg
  647. //}
  648. //// ResetDraftToLastVersion
  649. //// @Title 重置沙盘草稿至最新版本
  650. //// @Description 重置沙盘草稿至最新版本接口
  651. //// @Param request body request.DeleteSandbox true "type json string"
  652. //// @Success 200 {object} sandbox.SandboxDraft
  653. //// @Fail 202 另外的人在操作,不要重复添加草稿;204 错误了,当时不是必要性的错误,不用将错误信息暴露给用户
  654. //// @router /draft/reset [post]
  655. //func (this *SandboxController) ResetDraftToLastVersion() {
  656. // br := new(models.BaseResponse).Init()
  657. // defer func() {
  658. // this.Data["json"] = br
  659. // this.ServeJSON()
  660. // }()
  661. // sysUser := this.SysUser
  662. // if sysUser == nil {
  663. // br.Msg = "请登录"
  664. // br.ErrMsg = "请登录,SysUser Is Empty"
  665. // br.Ret = 408
  666. // return
  667. // }
  668. // var req request.DeleteSandbox
  669. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  670. // if err != nil {
  671. // br.Msg = "参数解析异常!"
  672. // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  673. // return
  674. // }
  675. //
  676. // if req.SandboxId <= 0 {
  677. // br.Msg = "缺少沙盘编号"
  678. // return
  679. // }
  680. //
  681. // //更新标记key
  682. // markStatus, err := sandboxService.UpdateSandboxEditMark(req.SandboxId, sysUser.AdminId, 0, sysUser.RealName)
  683. // if err != nil {
  684. // br.Msg = err.Error()
  685. // return
  686. // }
  687. // if markStatus.Status == 1 {
  688. // br.Msg = markStatus.Msg
  689. // return
  690. // }
  691. //
  692. // //重置沙盘草稿至最新版本
  693. // sandboxDraftInfo, err := sandboxService.ResetDraftToLastVersion(req.SandboxId, sysUser.AdminId, sysUser.RealName)
  694. // if err != nil {
  695. // br.Msg = "保存失败!"
  696. // br.ErrMsg = "保存失败,Err:" + err.Error()
  697. // return
  698. // }
  699. // msg := "保存成功"
  700. // br.Ret = 200
  701. // br.Success = true
  702. // br.Msg = msg
  703. // br.Data = sandboxDraftInfo
  704. //}
  705. // ListByQuote
  706. // @Title 逻辑导图列表(其他地方引用到的,莫名其妙要根据输入的关键字匹配品种)
  707. // @Description 逻辑导图列表接口(其他地方引用到的,莫名其妙要根据输入的关键字匹配品种)
  708. // @Param PageSize query int true "每页数据条数"
  709. // @Param CurrentIndex query int true "当前页页码,从1开始"
  710. // @Param ChartPermissionId query int true "权限编号id"
  711. // @Param Keyword query string false "搜索关键词:沙盘名称/编辑人名称"
  712. // @Success 200 {object} response.SandboxListResp
  713. // @router /list_by_quote [get]
  714. func (this *SandboxController) ListByQuote() {
  715. br := new(models.BaseResponse).Init()
  716. defer func() {
  717. this.Data["json"] = br
  718. this.ServeJSON()
  719. }()
  720. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  721. keyword := this.GetString("Keyword")
  722. pageSize, _ := this.GetInt("PageSize")
  723. currentIndex, _ := this.GetInt("CurrentIndex")
  724. var startSize int
  725. if pageSize <= 0 {
  726. pageSize = utils.PageSize20
  727. }
  728. if currentIndex <= 0 {
  729. currentIndex = 1
  730. }
  731. startSize = paging.StartIndex(currentIndex, pageSize)
  732. var condition string
  733. var pars []interface{}
  734. if chartPermissionId > 0 {
  735. condition += " AND a.chart_permission_id=? "
  736. pars = append(pars, chartPermissionId)
  737. }
  738. if keyword != "" {
  739. condition += ` AND ( a.name LIKE ? OR a.chart_permission_name LIKE ? )`
  740. pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  741. }
  742. //获取指标信息
  743. total, list, err := sandbox.GetList(condition, pars, startSize, pageSize)
  744. if err != nil && err.Error() != utils.ErrNoRow() {
  745. br.Success = true
  746. br.Msg = "获取沙盘列表失败"
  747. br.ErrMsg = "获取沙盘列表失败,Err:" + err.Error()
  748. return
  749. }
  750. if list == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  751. list = make([]*sandbox.Sandbox, 0)
  752. }
  753. page := paging.GetPaging(currentIndex, pageSize, total)
  754. resp := response.SandboxListResp{
  755. Paging: page,
  756. List: list,
  757. }
  758. br.Ret = 200
  759. br.Success = true
  760. br.Msg = "获取成功"
  761. br.Data = resp
  762. }
  763. // SandboxClassifyItems
  764. // @Title 获取所有沙盘分类接口-包含沙盘
  765. // @Description 获取所有沙盘分类接口-包含沙盘
  766. // @Param IsShowMe query bool true "是否只看我的,true、false"
  767. // @Success 200 {object} data_manage.ChartClassifyListResp
  768. // @router /classify/list [get]
  769. func (this *SandboxController) SandboxClassifyItems() {
  770. br := new(models.BaseResponse).Init()
  771. defer func() {
  772. this.Data["json"] = br
  773. this.ServeJSON()
  774. }()
  775. resp := new(sandbox.SandboxClassifyListResp)
  776. sandboxClassifyId, _ := this.GetInt("SandboxClassifyId")
  777. isShowMe, _ := this.GetBool("IsShowMe")
  778. if isShowMe {
  779. errMsg, err := sandboxService.GetSandboxClassifyListForMe(*this.SysUser, resp, sandboxClassifyId)
  780. if err != nil {
  781. br.Msg = errMsg
  782. br.ErrMsg = err.Error()
  783. return
  784. }
  785. // 移除没有权限的图表
  786. //allNodes := sandboxService.HandleNoPermissionSandbox(resp.AllNodes, nil)
  787. //resp.AllNodes = allNodes
  788. br.Ret = 200
  789. br.Success = true
  790. br.Msg = "获取成功"
  791. br.Data = resp
  792. fmt.Println("source my classify")
  793. return
  794. }
  795. rootList, err := sandbox.GetSandboxClassifyAndInfoByParentId(sandboxClassifyId)
  796. if err != nil && err.Error() != utils.ErrNoRow() {
  797. br.Msg = "获取失败"
  798. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  799. return
  800. }
  801. classifyAll, err := sandbox.GetSandboxClassifyAndInfoByParentId(sandboxClassifyId)
  802. if err != nil && err.Error() != utils.ErrNoRow() {
  803. br.Msg = "获取失败"
  804. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  805. return
  806. }
  807. //sandboxAll, err := sandbox.GetSandboxItemsByClassifyId(sandboxClassifyId)
  808. //if err != nil && err.Error() != utils.ErrNoRow() {
  809. // br.Msg = "获取失败"
  810. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  811. // return
  812. //}
  813. //sandListMap := make(map[int][]*sandbox.SandboxClassifyItems)
  814. //for _, v := range sandboxAll {
  815. // if _, ok := sandListMap[v.SandboxClassifyId]; !ok {
  816. // list := make([]*sandbox.SandboxClassifyItems, 0)
  817. // list = append(list, v)
  818. // sandListMap[v.SandboxClassifyId] = list
  819. // } else {
  820. // sandListMap[v.SandboxClassifyId] = append(sandListMap[v.SandboxClassifyId], v)
  821. // }
  822. //}
  823. nodeAll := make([]*sandbox.SandboxClassifyItems, 0)
  824. for k := range rootList {
  825. rootNode := rootList[k]
  826. sandboxService.SandboxClassifyItemsMakeTreeV2(this.SysUser, classifyAll, rootNode)
  827. nodeAll = append(nodeAll, rootNode)
  828. }
  829. //newAll := sandboxService.SandboxItemsMakeTree(nodeAll, sandListMap, sandboxClassifyId)
  830. resp.AllNodes = nodeAll
  831. br.Ret = 200
  832. br.Success = true
  833. br.Msg = "获取成功"
  834. br.Data = resp
  835. }
  836. // @Title 新增沙盘分类
  837. // @Description 新增沙盘分类接口
  838. // @Param request body data_manage.AddChartClassifyReq true "type json string"
  839. // @Success 200 Ret=200 保存成功
  840. // @router /classify/add [post]
  841. func (this *SandboxController) AddSandboxClassify() {
  842. br := new(models.BaseResponse).Init()
  843. defer func() {
  844. this.Data["json"] = br
  845. this.ServeJSON()
  846. }()
  847. var req sandbox.AddSandboxClassifyReq
  848. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  849. if err != nil {
  850. br.Msg = "参数解析异常!"
  851. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  852. return
  853. }
  854. if req.SandboxClassifyName == "" {
  855. br.Msg = "请输入分类名称"
  856. br.IsSendEmail = false
  857. return
  858. }
  859. if req.ParentId < 0 {
  860. br.Msg = "参数错误"
  861. br.IsSendEmail = false
  862. return
  863. }
  864. count, err := sandbox.GetSandboxClassifyCount(req.SandboxClassifyName, req.ParentId)
  865. if err != nil {
  866. br.Msg = "判断名称是否已存在失败"
  867. br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  868. return
  869. }
  870. if count > 0 {
  871. br.Msg = "分类名称已存在,请重新输入"
  872. br.IsSendEmail = false
  873. return
  874. }
  875. //获取该层级下最大的排序数
  876. maxSort, err := sandbox.GetSandboxClassifyMaxSort(req.ParentId)
  877. classify := new(sandbox.SandboxClassify)
  878. classify.ParentId = req.ParentId
  879. classify.SandboxClassifyName = req.SandboxClassifyName
  880. classify.HasData = 0
  881. classify.CreateTime = time.Now()
  882. classify.ModifyTime = time.Now()
  883. classify.SysUserId = this.SysUser.AdminId
  884. classify.SysUserRealName = this.SysUser.RealName
  885. classify.ChartPermissionId = req.ChartPermissionId
  886. classify.ChartPermissionName = req.ChartPermissionName
  887. classify.Level = req.Level + 1
  888. classify.Sort = maxSort + 1
  889. _, err = sandbox.AddSandboxClassify(classify)
  890. if err != nil {
  891. br.Msg = "保存分类失败"
  892. br.ErrMsg = "保存分类失败,Err:" + err.Error()
  893. return
  894. }
  895. br.Ret = 200
  896. br.Msg = "保存成功"
  897. br.Success = true
  898. }
  899. // @Title 修改沙盘分类
  900. // @Description 修改沙盘分类接口
  901. // @Param request body data_manage.EditChartClassifyReq true "type json string"
  902. // @Success 200 Ret=200 修改成功
  903. // @router /classify/edit [post]
  904. func (this *SandboxController) EditSandboxClassify() {
  905. br := new(models.BaseResponse).Init()
  906. defer func() {
  907. this.Data["json"] = br
  908. this.ServeJSON()
  909. }()
  910. var req sandbox.EditSandboxClassifyReq
  911. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  912. if err != nil {
  913. br.Msg = "参数解析异常!"
  914. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  915. return
  916. }
  917. if req.SandboxClassifyName == "" {
  918. br.Msg = "请输入分类名称"
  919. br.IsSendEmail = false
  920. return
  921. }
  922. if req.SandboxClassifyId <= 0 {
  923. br.Msg = "参数错误"
  924. br.IsSendEmail = false
  925. return
  926. }
  927. //item, err := sandbox.GetSandboxClassifyById(req.SandboxClassifyId)
  928. //if err != nil {
  929. // br.Msg = "保存失败"
  930. // br.Msg = "获取分类信息失败,Err:" + err.Error()
  931. // return
  932. //}
  933. //count, err := sandbox.GetSandboxClassifyCount(req.SandboxClassifyName, item.ParentId)
  934. //if err != nil {
  935. // br.Msg = "判断名称是否已存在失败"
  936. // br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  937. // return
  938. //}
  939. //if count > 0 {
  940. // br.Msg = "分类名称已存在,请重新输入"
  941. // br.IsSendEmail = false
  942. // return
  943. //}
  944. err = sandbox.EditSandboxClassify(req.SandboxClassifyId, req.ChartPermissionId, req.SandboxClassifyName, req.ChartPermissionName)
  945. if err != nil {
  946. br.Msg = "保存失败"
  947. br.ErrMsg = "保存失败,Err:" + err.Error()
  948. return
  949. }
  950. br.Ret = 200
  951. br.Msg = "保存成功"
  952. br.Success = true
  953. br.IsAddLog = true
  954. }
  955. // @Title 删除沙盘检测接口
  956. // @Description 删除沙盘检测接口
  957. // @Param request body data_manage.ChartClassifyDeleteCheckResp true "type json string"
  958. // @Success 200 Ret=200 检测成功
  959. // @router /classify/delete/check [post]
  960. func (this *SandboxController) DeleteSandboxClassifyCheck() {
  961. br := new(models.BaseResponse).Init()
  962. defer func() {
  963. this.Data["json"] = br
  964. this.ServeJSON()
  965. }()
  966. var req sandbox.SandboxClassifyDeleteCheckReq
  967. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  968. if err != nil {
  969. br.Msg = "参数解析异常!"
  970. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  971. return
  972. }
  973. if req.SandboxClassifyId < 0 {
  974. br.Msg = "参数错误"
  975. br.IsSendEmail = false
  976. return
  977. }
  978. var deleteStatus int
  979. var tipsMsg string
  980. //删除分类
  981. if req.SandboxClassifyId > 0 {
  982. //判断沙盘分类下,是否含有沙盘
  983. count, err := sandbox.GetSandboxInfoCountByClassifyId(req.SandboxClassifyId)
  984. if err != nil {
  985. br.Msg = "删除失败"
  986. br.ErrMsg = "分类下是否含有指标失败,Err:" + err.Error()
  987. return
  988. }
  989. if count > 0 {
  990. deleteStatus = 1
  991. tipsMsg = "该分类下关联沙盘不可删除"
  992. }
  993. }
  994. if deleteStatus != 1 {
  995. classifyCount, err := sandbox.GetSandboxInfoCountByClassifyId(req.SandboxClassifyId)
  996. if err != nil && err.Error() != utils.ErrNoRow() {
  997. br.Msg = "删除失败"
  998. br.ErrMsg = "分类下是否含有沙盘失败,Err:" + err.Error()
  999. return
  1000. }
  1001. if classifyCount > 0 {
  1002. deleteStatus = 2
  1003. tipsMsg = "确认删除当前目录及包含的子目录吗"
  1004. }
  1005. }
  1006. if deleteStatus == 0 {
  1007. tipsMsg = "可删除,进行删除操作"
  1008. }
  1009. resp := new(sandbox.SandboxClassifyDeleteCheckResp)
  1010. resp.DeleteStatus = deleteStatus
  1011. resp.TipsMsg = tipsMsg
  1012. br.Ret = 200
  1013. br.Msg = "检测成功"
  1014. br.Success = true
  1015. br.Data = resp
  1016. }
  1017. // @Title 删除沙盘分类/沙盘
  1018. // @Description 删除沙盘分类/沙盘接口
  1019. // @Param request body data_manage.DeleteChartClassifyReq true "type json string"
  1020. // @Success 200 Ret=200 删除成功
  1021. // @router /classify/delete [post]
  1022. func (this *SandboxController) DeleteSandboxClassify() {
  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. var req sandbox.DeleteSandboxClassifyReq
  1036. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1037. if err != nil {
  1038. br.Msg = "参数解析异常!"
  1039. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1040. return
  1041. }
  1042. if req.SandboxClassifyId < 0 && req.SandboxId <= 0 {
  1043. br.Msg = "参数错误"
  1044. br.IsSendEmail = false
  1045. return
  1046. }
  1047. //删除分类
  1048. if req.SandboxClassifyId > 0 && req.SandboxId == 0 {
  1049. //判断是否含有指标
  1050. count, err := sandbox.GetSandboxInfoCountByClassifyId(req.SandboxId)
  1051. if err != nil && err.Error() != utils.ErrNoRow() {
  1052. br.Msg = "删除失败"
  1053. br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  1054. return
  1055. }
  1056. if count > 0 {
  1057. br.Msg = "该目录下存在关联指标,不可删除"
  1058. br.IsSendEmail = false
  1059. return
  1060. }
  1061. err = sandbox.DeleteSandboxClassify(req.SandboxClassifyId)
  1062. if err != nil {
  1063. br.Msg = "删除失败"
  1064. br.ErrMsg = "删除失败,Err:" + err.Error()
  1065. return
  1066. }
  1067. }
  1068. //删除沙盘
  1069. if req.SandboxId > 0 {
  1070. sandboxInfo, err := sandbox.GetSandboxById(req.SandboxId)
  1071. if err != nil {
  1072. if err.Error() == utils.ErrNoRow() {
  1073. br.Msg = "沙盘已删除,请刷新页面"
  1074. br.ErrMsg = "指标不存在,Err:" + err.Error()
  1075. return
  1076. } else {
  1077. br.Msg = "删除失败"
  1078. br.ErrMsg = "删除失败,获取指标信息失败,Err:" + err.Error()
  1079. return
  1080. }
  1081. }
  1082. if sandboxInfo == nil {
  1083. br.Msg = "沙盘已删除,请刷新页面"
  1084. return
  1085. }
  1086. err = sandboxService.DeleteSandbox(req.SandboxId)
  1087. if err != nil {
  1088. br.Msg = err.Error()
  1089. return
  1090. }
  1091. }
  1092. br.Ret = 200
  1093. br.Msg = "删除成功"
  1094. br.Success = true
  1095. br.IsAddLog = true
  1096. }
  1097. // ChartClassifyMove
  1098. // @Title 沙盘分类移动接口
  1099. // @Description 沙盘分类移动接口
  1100. // @Success 200 {object} data_manage.MoveChartClassifyReq
  1101. // @router /classify/move [post]
  1102. func (this *SandboxController) ChartClassifyMove() {
  1103. br := new(models.BaseResponse).Init()
  1104. defer func() {
  1105. this.Data["json"] = br
  1106. this.ServeJSON()
  1107. }()
  1108. sysUser := this.SysUser
  1109. if sysUser == nil {
  1110. br.Msg = "请登录"
  1111. br.ErrMsg = "请登录,SysUser Is Empty"
  1112. br.Ret = 408
  1113. return
  1114. }
  1115. var req sandbox.MoveSandboxClassifyReq
  1116. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1117. if err != nil {
  1118. br.Msg = "参数解析异常!"
  1119. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1120. return
  1121. }
  1122. if req.ClassifyId <= 0 {
  1123. br.Msg = "参数错误"
  1124. br.ErrMsg = "分类id小于等于0"
  1125. return
  1126. }
  1127. //判断分类是否存在
  1128. sandboxClassifyInfo, err := sandbox.GetSandboxClassifyById(req.ClassifyId)
  1129. if err != nil {
  1130. br.Msg = "移动失败"
  1131. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  1132. return
  1133. }
  1134. updateCol := make([]string, 0)
  1135. // 判断移动的是分类还是沙盘
  1136. if req.SandboxId > 0 {
  1137. //判断分类是否存在
  1138. count, _ := sandbox.GetSandboxClassifyCountById(req.ClassifyId)
  1139. if count <= 0 {
  1140. br.Msg = "分类已被删除,不可移动,请刷新页面"
  1141. return
  1142. }
  1143. sandboxInfo, err := sandbox.GetSandboxById(req.SandboxId)
  1144. if err != nil {
  1145. br.Msg = "移动失败"
  1146. br.ErrMsg = "获取沙盘信息失败,Err:" + err.Error()
  1147. return
  1148. }
  1149. //如果改变了分类,那么移动该图表数据
  1150. // 11/22 ETA逻辑优化去除名称重复限制
  1151. if sandboxInfo.SandboxClassifyId != req.ParentClassifyId {
  1152. ////查询需要修改的分类下是否存在同一个图表名称
  1153. //tmpSandboxInfo, tmpErr := sandbox.GetSandboxByClassifyIdAndName(req.ParentClassifyId, sandboxInfo.Name)
  1154. //if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  1155. // br.Msg = "移动失败"
  1156. // br.ErrMsg = "移动失败,Err:" + tmpErr.Error()
  1157. // return
  1158. //}
  1159. //if tmpSandboxInfo != nil {
  1160. // br.Msg = "移动失败,同一个分类下沙盘名称不允许重复"
  1161. // br.ErrMsg = "移动失败,同一个分类下沙盘名称不允许重复"
  1162. // return
  1163. //}
  1164. err = sandbox.MoveSandbox(req.SandboxId, req.ParentClassifyId)
  1165. if err != nil {
  1166. br.Msg = "移动失败"
  1167. br.ErrMsg = "移动失败,Err:" + err.Error()
  1168. return
  1169. }
  1170. }
  1171. //移动排序
  1172. updateCol := make([]string, 0)
  1173. //如果有传入 上一个兄弟节点分类id
  1174. if req.PrevId > 0 {
  1175. if req.PrevType == 1 {
  1176. //上一个兄弟节点
  1177. prevClassify, err := sandbox.GetSandboxClassifyById(req.PrevId)
  1178. if err != nil {
  1179. br.Msg = "移动失败"
  1180. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  1181. return
  1182. }
  1183. //如果是移动在两个兄弟节点之间
  1184. if req.NextId > 0 {
  1185. if req.NextType == 1 {
  1186. //上一个节点是分类 下一个节点是分类的情况
  1187. //下一个兄弟节点
  1188. nextClassify, err := sandbox.GetSandboxClassifyById(req.NextId)
  1189. if err != nil {
  1190. br.Msg = "移动失败"
  1191. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  1192. return
  1193. }
  1194. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  1195. if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == sandboxClassifyInfo.Sort {
  1196. //变更兄弟节点的排序
  1197. updateSortStr := `sort + 2`
  1198. _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, prevClassify.SandboxClassifyId, prevClassify.Sort, updateSortStr)
  1199. _ = sandbox.UpdateSandboxSortByClassifyId(prevClassify.SandboxClassifyId, prevClassify.Sort, 0, updateSortStr)
  1200. } else {
  1201. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  1202. if nextClassify.Sort-prevClassify.Sort == 1 {
  1203. //变更兄弟节点的排序
  1204. updateSortStr := `sort + 1`
  1205. _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr)
  1206. _ = sandbox.UpdateSandboxSortByClassifyId(prevClassify.SandboxClassifyId, prevClassify.Sort, 0, updateSortStr)
  1207. }
  1208. }
  1209. } else {
  1210. //上一个节点是分类 下一个节点是沙盘的情况
  1211. //下一个兄弟节点
  1212. nextChartInfo, err := sandbox.GetSandboxById(req.NextId)
  1213. if err != nil {
  1214. br.Msg = "移动失败"
  1215. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  1216. return
  1217. }
  1218. //如果上一个兄弟(分类)与下一个兄弟(沙盘)的排序权重是一致的,那么需要将下一个兄弟(沙盘)(以及下个兄弟(沙盘)的同样排序权重)的排序权重+2,自己变成上一个兄弟(分类)的排序权重+1
  1219. if prevClassify.Sort == nextChartInfo.Sort || prevClassify.Sort == sandboxInfo.Sort {
  1220. //变更兄弟节点的排序
  1221. updateSortStr := `sort + 2`
  1222. _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, prevClassify.SandboxClassifyId, prevClassify.Sort, updateSortStr)
  1223. _ = sandbox.UpdateSandboxSortByClassifyId(prevClassify.SandboxClassifyId, prevClassify.Sort, 0, updateSortStr)
  1224. } else {
  1225. //如果下一个兄弟(沙盘)的排序权重正好是上个兄弟节点(分类)的下一层,那么需要再加一层了
  1226. if nextChartInfo.Sort-prevClassify.Sort == 1 {
  1227. //变更兄弟节点的排序
  1228. updateSortStr := `sort + 1`
  1229. _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.SandboxClassifyId, updateSortStr)
  1230. _ = sandbox.UpdateSandboxSortByClassifyId(prevClassify.SandboxClassifyId, prevClassify.Sort, 0, updateSortStr)
  1231. }
  1232. }
  1233. }
  1234. }
  1235. sandboxInfo.Sort = prevClassify.Sort + 1
  1236. sandboxInfo.ModifyTime = time.Now()
  1237. updateCol = append(updateCol, "Sort", "ModifyTime")
  1238. } else {
  1239. prevSandbox, err := sandbox.GetSandboxById(req.PrevId)
  1240. if err != nil {
  1241. br.Msg = "移动失败"
  1242. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  1243. return
  1244. }
  1245. //如果是移动在两个兄弟节点之间
  1246. if req.NextId > 0 {
  1247. if req.NextType == 1 {
  1248. //上一个节点是沙盘 下一个节点是分类的情况
  1249. //下一个兄弟节点
  1250. nextClassify, err := sandbox.GetSandboxClassifyById(req.NextId)
  1251. if err != nil {
  1252. br.Msg = "移动失败"
  1253. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  1254. return
  1255. }
  1256. //如果上一个兄弟(沙盘)与下一个兄弟(分类)的排序权重是一致的,那么需要将下一个兄弟(分类)(以及下个兄弟(分类)的同样排序权重)的排序权重+2,自己变成上一个兄弟(沙盘)的排序权重+1
  1257. if prevSandbox.Sort == nextClassify.Sort || prevSandbox.Sort == sandboxClassifyInfo.Sort {
  1258. //变更兄弟节点的排序
  1259. updateSortStr := `sort + 2`
  1260. _ = sandbox.UpdateSandboxClassifySortByParentId(prevSandbox.SandboxClassifyId, 0, prevSandbox.Sort, updateSortStr)
  1261. _ = sandbox.UpdateSandboxSortByClassifyId(prevSandbox.SandboxClassifyId, prevSandbox.Sort, prevSandbox.SandboxId, updateSortStr)
  1262. } else {
  1263. //如果下一个兄弟(分类)的排序权重正好是上个兄弟(沙盘)节点的下一层,那么需要再加一层了
  1264. if nextClassify.Sort-prevSandbox.Sort == 1 {
  1265. //变更兄弟节点的排序
  1266. updateSortStr := `sort + 1`
  1267. _ = sandbox.UpdateSandboxClassifySortByParentId(prevSandbox.SandboxClassifyId, 0, prevSandbox.Sort, updateSortStr)
  1268. _ = sandbox.UpdateSandboxSortByClassifyId(prevSandbox.SandboxClassifyId, prevSandbox.Sort, prevSandbox.SandboxId, updateSortStr)
  1269. }
  1270. }
  1271. } else {
  1272. //上一个节点是沙盘 下一个节点是沙盘的情况
  1273. //下一个兄弟节点
  1274. nextChartInfo, err := sandbox.GetSandboxById(req.NextId)
  1275. if err != nil {
  1276. br.Msg = "移动失败"
  1277. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  1278. return
  1279. }
  1280. //如果上一个兄弟(沙盘)与下一个兄弟(分类)的排序权重是一致的,那么需要将下一个兄弟(分类)(以及下个兄弟(分类)的同样排序权重)的排序权重+2,自己变成上一个兄弟(沙盘)的排序权重+1
  1281. if prevSandbox.Sort == nextChartInfo.Sort || prevSandbox.Sort == sandboxInfo.Sort {
  1282. //变更兄弟节点的排序
  1283. updateSortStr := `sort + 2`
  1284. _ = sandbox.UpdateSandboxClassifySortByParentId(prevSandbox.SandboxClassifyId, 0, prevSandbox.Sort, updateSortStr)
  1285. _ = sandbox.UpdateSandboxSortByClassifyId(prevSandbox.SandboxClassifyId, prevSandbox.Sort, prevSandbox.SandboxId, updateSortStr)
  1286. } else {
  1287. //如果下一个兄弟(分类)的排序权重正好是上个兄弟(沙盘)节点的下一层,那么需要再加一层了
  1288. if nextChartInfo.Sort-prevSandbox.Sort == 1 {
  1289. //变更兄弟节点的排序
  1290. updateSortStr := `sort + 1`
  1291. _ = sandbox.UpdateSandboxClassifySortByParentId(prevSandbox.SandboxClassifyId, 0, prevSandbox.Sort, updateSortStr)
  1292. _ = sandbox.UpdateSandboxSortByClassifyId(prevSandbox.SandboxClassifyId, prevSandbox.Sort, prevSandbox.SandboxId, updateSortStr)
  1293. }
  1294. }
  1295. }
  1296. }
  1297. sandboxInfo.Sort = prevSandbox.Sort + 1
  1298. sandboxInfo.ModifyTime = time.Now()
  1299. updateCol = append(updateCol, "Sort", "ModifyTime")
  1300. }
  1301. } else {
  1302. // prevId为0,也就是沙盘移到最前端
  1303. firstClassify, err := sandbox.GetFirstSandboxByClassifyId(req.ClassifyId)
  1304. if err != nil && err.Error() != utils.ErrNoRow() {
  1305. br.Msg = "移动失败"
  1306. br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  1307. return
  1308. }
  1309. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  1310. if firstClassify != nil && firstClassify.Sort == 0 {
  1311. updateSortStr := ` sort + 1 `
  1312. _ = sandbox.UpdateSandboxSortByClassifyId(firstClassify.SandboxClassifyId, 0, firstClassify.SandboxId-1, updateSortStr)
  1313. }
  1314. sandboxInfo.Sort = 0 //那就是排在第一位
  1315. sandboxInfo.ModifyTime = time.Now()
  1316. updateCol = append(updateCol, "Sort", "ModifyTime")
  1317. }
  1318. //更新
  1319. if len(updateCol) > 0 {
  1320. err = sandboxInfo.Update(updateCol)
  1321. if err != nil {
  1322. br.Msg = "移动失败"
  1323. br.ErrMsg = "修改失败,Err:" + err.Error()
  1324. return
  1325. }
  1326. }
  1327. } else {
  1328. //移动的是分类
  1329. //判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
  1330. if sandboxClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId != 0 {
  1331. parentChartClassifyInfo, err := sandbox.GetSandboxClassifyById(req.ParentClassifyId)
  1332. if err != nil {
  1333. br.Msg = "移动失败"
  1334. br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error()
  1335. return
  1336. }
  1337. sandboxClassifyInfo.ParentId = parentChartClassifyInfo.SandboxClassifyId
  1338. sandboxClassifyInfo.Level = parentChartClassifyInfo.Level + 1
  1339. sandboxClassifyInfo.ModifyTime = time.Now()
  1340. updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  1341. } else if sandboxClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId == 0 {
  1342. //改为一级分类
  1343. sandboxClassifyInfo.ParentId = req.ParentClassifyId
  1344. sandboxClassifyInfo.Level = 1
  1345. sandboxClassifyInfo.ModifyTime = time.Now()
  1346. updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  1347. }
  1348. //如果有传入 上一个兄弟节点分类id
  1349. if req.PrevId > 0 {
  1350. if req.PrevType == 1 {
  1351. //上一个节点是分类
  1352. //上一个兄弟节点
  1353. prevClassify, err := sandbox.GetSandboxClassifyById(req.PrevId)
  1354. if err != nil {
  1355. br.Msg = "移动失败"
  1356. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  1357. return
  1358. }
  1359. //如果是移动在两个兄弟节点之间
  1360. if req.NextId > 0 {
  1361. if req.NextType == 1 {
  1362. //上一个节点是分类 下一个节点是分类的情况
  1363. //下一个兄弟节点
  1364. nextClassify, err := sandbox.GetSandboxClassifyById(req.NextId)
  1365. if err != nil {
  1366. br.Msg = "移动失败"
  1367. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  1368. return
  1369. }
  1370. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  1371. if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == sandboxClassifyInfo.Sort {
  1372. //变更兄弟节点的排序
  1373. updateSortStr := `sort + 2`
  1374. _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, prevClassify.SandboxClassifyId, prevClassify.Sort, updateSortStr)
  1375. _ = sandbox.UpdateSandboxSortByClassifyId(prevClassify.SandboxClassifyId, prevClassify.Sort, 0, updateSortStr)
  1376. } else {
  1377. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  1378. if nextClassify.Sort-prevClassify.Sort == 1 {
  1379. //变更兄弟节点的排序
  1380. updateSortStr := `sort + 1`
  1381. _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr)
  1382. _ = sandbox.UpdateSandboxSortByClassifyId(prevClassify.SandboxClassifyId, prevClassify.Sort, 0, updateSortStr)
  1383. }
  1384. }
  1385. } else {
  1386. //上一个节点是分类 下一个节点是沙盘的情况
  1387. //下一个兄弟节点
  1388. nextChartInfo, err := sandbox.GetSandboxById(req.NextId)
  1389. if err != nil {
  1390. br.Msg = "移动失败"
  1391. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  1392. return
  1393. }
  1394. //如果上一个兄弟(分类)与下一个兄弟(沙盘)的排序权重是一致的,那么需要将下一个兄弟(沙盘)(以及下个兄弟(沙盘)的同样排序权重)的排序权重+2,自己变成上一个兄弟(分类)的排序权重+1
  1395. if prevClassify.Sort == nextChartInfo.Sort || prevClassify.Sort == sandboxClassifyInfo.Sort {
  1396. //变更兄弟节点的排序
  1397. updateSortStr := `sort + 2`
  1398. _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, prevClassify.SandboxClassifyId, prevClassify.Sort, updateSortStr)
  1399. _ = sandbox.UpdateSandboxSortByClassifyId(prevClassify.SandboxClassifyId, prevClassify.Sort, 0, updateSortStr)
  1400. } else {
  1401. //如果下一个兄弟(沙盘)的排序权重正好是上个兄弟节点(分类)的下一层,那么需要再加一层了
  1402. if nextChartInfo.Sort-prevClassify.Sort == 1 {
  1403. //变更兄弟节点的排序
  1404. updateSortStr := `sort + 1`
  1405. _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.SandboxClassifyId, updateSortStr)
  1406. _ = sandbox.UpdateSandboxSortByClassifyId(prevClassify.SandboxClassifyId, prevClassify.Sort, 0, updateSortStr)
  1407. }
  1408. }
  1409. }
  1410. }
  1411. sandboxClassifyInfo.Sort = prevClassify.Sort + 1
  1412. sandboxClassifyInfo.ModifyTime = time.Now()
  1413. updateCol = append(updateCol, "Sort", "ModifyTime")
  1414. } else {
  1415. //上一个节点是沙盘
  1416. prevSandbox, err := sandbox.GetSandboxById(req.PrevId)
  1417. if err != nil {
  1418. br.Msg = "移动失败"
  1419. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  1420. return
  1421. }
  1422. //如果是移动在两个兄弟节点之间
  1423. if req.NextId > 0 {
  1424. if req.NextType == 1 {
  1425. //上一个节点是沙盘 下一个节点是分类的情况
  1426. //下一个兄弟节点
  1427. nextClassify, err := sandbox.GetSandboxClassifyById(req.NextId)
  1428. if err != nil {
  1429. br.Msg = "移动失败"
  1430. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  1431. return
  1432. }
  1433. //如果上一个兄弟(沙盘)与下一个兄弟(分类)的排序权重是一致的,那么需要将下一个兄弟(分类)(以及下个兄弟(分类)的同样排序权重)的排序权重+2,自己变成上一个兄弟(沙盘)的排序权重+1
  1434. if prevSandbox.Sort == nextClassify.Sort || prevSandbox.Sort == sandboxClassifyInfo.Sort {
  1435. //变更兄弟节点的排序
  1436. updateSortStr := `sort + 2`
  1437. _ = sandbox.UpdateSandboxClassifySortByParentId(prevSandbox.SandboxClassifyId, 0, prevSandbox.Sort, updateSortStr)
  1438. _ = sandbox.UpdateSandboxSortByClassifyId(prevSandbox.SandboxClassifyId, prevSandbox.Sort, prevSandbox.SandboxId, updateSortStr)
  1439. } else {
  1440. //如果下一个兄弟(分类)的排序权重正好是上个兄弟(沙盘)节点的下一层,那么需要再加一层了
  1441. if nextClassify.Sort-prevSandbox.Sort == 1 {
  1442. //变更兄弟节点的排序
  1443. updateSortStr := `sort + 1`
  1444. _ = sandbox.UpdateSandboxClassifySortByParentId(prevSandbox.SandboxClassifyId, 0, prevSandbox.Sort, updateSortStr)
  1445. _ = sandbox.UpdateSandboxSortByClassifyId(prevSandbox.SandboxClassifyId, prevSandbox.Sort, prevSandbox.SandboxId, updateSortStr)
  1446. }
  1447. }
  1448. } else {
  1449. //上一个节点是沙盘 下一个节点是沙盘的情况
  1450. //下一个兄弟节点
  1451. nextChartInfo, err := sandbox.GetSandboxById(req.NextId)
  1452. if err != nil {
  1453. br.Msg = "移动失败"
  1454. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  1455. return
  1456. }
  1457. //如果上一个兄弟(沙盘)与下一个兄弟(分类)的排序权重是一致的,那么需要将下一个兄弟(分类)(以及下个兄弟(分类)的同样排序权重)的排序权重+2,自己变成上一个兄弟(沙盘)的排序权重+1
  1458. if prevSandbox.Sort == nextChartInfo.Sort || prevSandbox.Sort == sandboxClassifyInfo.Sort {
  1459. //变更兄弟节点的排序
  1460. updateSortStr := `sort + 2`
  1461. _ = sandbox.UpdateSandboxClassifySortByParentId(prevSandbox.SandboxClassifyId, 0, prevSandbox.Sort, updateSortStr)
  1462. _ = sandbox.UpdateSandboxSortByClassifyId(prevSandbox.SandboxClassifyId, prevSandbox.Sort, prevSandbox.SandboxId, updateSortStr)
  1463. } else {
  1464. //如果下一个兄弟(分类)的排序权重正好是上个兄弟(沙盘)节点的下一层,那么需要再加一层了
  1465. if nextChartInfo.Sort-prevSandbox.Sort == 1 {
  1466. //变更兄弟节点的排序
  1467. updateSortStr := `sort + 1`
  1468. _ = sandbox.UpdateSandboxClassifySortByParentId(prevSandbox.SandboxClassifyId, 0, prevSandbox.Sort, updateSortStr)
  1469. _ = sandbox.UpdateSandboxSortByClassifyId(prevSandbox.SandboxClassifyId, prevSandbox.Sort, prevSandbox.SandboxId, updateSortStr)
  1470. }
  1471. }
  1472. }
  1473. }
  1474. sandboxClassifyInfo.Sort = prevSandbox.Sort + 1
  1475. sandboxClassifyInfo.ModifyTime = time.Now()
  1476. updateCol = append(updateCol, "Sort", "ModifyTime")
  1477. }
  1478. } else {
  1479. firstClassify, err := sandbox.GetFirstSandboxClassifyByParentId(sandboxClassifyInfo.ParentId)
  1480. if err != nil && err.Error() != utils.ErrNoRow() {
  1481. br.Msg = "移动失败"
  1482. br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  1483. return
  1484. }
  1485. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  1486. if firstClassify != nil && firstClassify.Sort == 0 {
  1487. updateSortStr := ` sort + 1 `
  1488. _ = sandbox.UpdateSandboxClassifySortByParentId(firstClassify.ParentId, firstClassify.SandboxClassifyId-1, 0, updateSortStr)
  1489. }
  1490. sandboxClassifyInfo.Sort = 0 //那就是排在第一位
  1491. sandboxClassifyInfo.ModifyTime = time.Now()
  1492. updateCol = append(updateCol, "Sort", "ModifyTime")
  1493. }
  1494. //更新
  1495. if len(updateCol) > 0 {
  1496. err = sandboxClassifyInfo.Update(updateCol)
  1497. if err != nil {
  1498. br.Msg = "移动失败"
  1499. br.ErrMsg = "修改失败,Err:" + err.Error()
  1500. return
  1501. }
  1502. }
  1503. }
  1504. br.Ret = 200
  1505. br.Success = true
  1506. br.Msg = "移动成功"
  1507. }
  1508. // @Title ETA图表列表接口
  1509. // @Description ETA图表列表接口
  1510. // @Param PageSize query int true "每页数据条数"
  1511. // @Param CurrentIndex query int true "当前页页码,从1开始"
  1512. // @Param ChartClassifyId query int true "分类id"
  1513. // @Param KeyWord query string true "搜索关键词"
  1514. // @Param IsShowMe query bool true "是否只看我的,true、false"
  1515. // @Success 200 {object} data_manage.ChartListResp
  1516. // @router /listV2 [get]
  1517. func (this *SandboxController) ListV2() {
  1518. br := new(models.BaseResponse).Init()
  1519. defer func() {
  1520. this.Data["json"] = br
  1521. this.ServeJSON()
  1522. }()
  1523. sysUser := this.SysUser
  1524. if sysUser == nil {
  1525. br.Msg = "请登录"
  1526. br.ErrMsg = "请登录,SysUser Is Empty"
  1527. br.Ret = 408
  1528. return
  1529. }
  1530. sandboxClassifyId, _ := this.GetInt("SandboxClassifyId")
  1531. pageSize, _ := this.GetInt("PageSize")
  1532. currentIndex, _ := this.GetInt("CurrentIndex")
  1533. keyWord := this.GetString("KeyWord")
  1534. var total int
  1535. page := paging.GetPaging(currentIndex, pageSize, total)
  1536. var startSize int
  1537. if pageSize <= 0 {
  1538. pageSize = utils.PageSize20
  1539. }
  1540. if currentIndex <= 0 {
  1541. currentIndex = 1
  1542. }
  1543. startSize = paging.StartIndex(currentIndex, pageSize)
  1544. var condition string
  1545. var pars []interface{}
  1546. if sandboxClassifyId > 0 {
  1547. sandboxClassifyId, err := sandbox.GetSandboxClassify(sandboxClassifyId)
  1548. if err != nil && err.Error() != utils.ErrNoRow() {
  1549. br.Msg = "获取图表信息失败"
  1550. br.ErrMsg = "获取信息失败,GetChartClassify,Err:" + err.Error()
  1551. return
  1552. }
  1553. condition += " AND sandbox_classify_id IN(" + sandboxClassifyId + ") "
  1554. //pars = append(pars, chartClassifyId)
  1555. }
  1556. if keyWord != "" {
  1557. condition += ` AND ( name LIKE '%` + keyWord + `%' )`
  1558. }
  1559. //只看我的
  1560. isShowMe, _ := this.GetBool("IsShowMe")
  1561. if isShowMe {
  1562. condition += ` AND sys_user_id = ? `
  1563. pars = append(pars, sysUser.AdminId)
  1564. }
  1565. //获取图表信息
  1566. condition += ` AND is_delete = 0 `
  1567. list, err := sandbox.GetSandboxListByCondition(condition, pars, startSize, pageSize)
  1568. if err != nil && err.Error() != utils.ErrNoRow() {
  1569. br.Success = true
  1570. br.Msg = "获取沙盘信息失败"
  1571. br.ErrMsg = "获取沙盘信息失败,Err:" + err.Error()
  1572. return
  1573. }
  1574. for i, v := range list {
  1575. ids, err := sandbox.GetSandboxAllParentByClassifyId(v.SandboxClassifyId)
  1576. if err != nil {
  1577. br.Msg = "获取父级信息错误!"
  1578. br.ErrMsg = "获取父级信息错误,Err:" + err.Error()
  1579. return
  1580. }
  1581. list[i].ParentIds = ids
  1582. }
  1583. resp := new(sandbox.SandboxListResp)
  1584. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  1585. items := make([]*sandbox.SandboxListItems, 0)
  1586. resp.Paging = page
  1587. resp.List = items
  1588. br.Ret = 200
  1589. br.Success = true
  1590. br.Msg = "获取成功"
  1591. return
  1592. }
  1593. dataCount, err := sandbox.GetSandboxListCountByCondition(condition, pars)
  1594. if err != nil && err.Error() != utils.ErrNoRow() {
  1595. br.Msg = "获取指标信息失败"
  1596. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  1597. return
  1598. }
  1599. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  1600. resp.Paging = page
  1601. resp.List = list
  1602. br.Ret = 200
  1603. br.Success = true
  1604. br.Msg = "获取成功"
  1605. br.Data = resp
  1606. }
  1607. // Save
  1608. // @Title 新增/编辑保存沙盘
  1609. // @Description 新增/编辑保存沙盘接口
  1610. // @Param request body request.AddAndEditSandbox true "type json string"
  1611. // @Success 200 {object} sandbox.Sandbox
  1612. // @router /saveV2 [post]
  1613. func (this *SandboxController) SaveV2() {
  1614. br := new(models.BaseResponse).Init()
  1615. defer func() {
  1616. this.Data["json"] = br
  1617. this.ServeJSON()
  1618. }()
  1619. sysUser := this.SysUser
  1620. if sysUser == nil {
  1621. br.Msg = "请登录"
  1622. br.ErrMsg = "请登录,SysUser Is Empty"
  1623. br.Ret = 408
  1624. return
  1625. }
  1626. var req request.AddAndEditSandboxV2
  1627. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1628. if err != nil {
  1629. br.Msg = "参数解析异常!"
  1630. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1631. return
  1632. }
  1633. var sandboxResp *sandbox.SandboxSaveResp
  1634. var errMsg string
  1635. if req.SandboxId <= 0 {
  1636. //新增沙盘
  1637. sandboxResp, err = sandboxService.AddSandboxV2(req, sysUser.AdminId, sysUser.RealName)
  1638. if err != nil {
  1639. br.Msg = "保存失败!"
  1640. if errMsg != `` {
  1641. br.Msg = errMsg
  1642. }
  1643. br.ErrMsg = "保存失败,Err:" + err.Error()
  1644. return
  1645. }
  1646. } else {
  1647. //编辑沙盘
  1648. sandboxInfo := &sandbox.Sandbox{
  1649. SandboxId: req.SandboxId,
  1650. Name: utils.TrimStr(req.Name),
  1651. Content: req.Content,
  1652. MindmapData: req.MindmapData,
  1653. PicUrl: utils.TrimStr(req.PicUrl),
  1654. ModifyTime: time.Now(),
  1655. SandboxClassifyId: req.SandboxClassifyId,
  1656. Style: req.Style,
  1657. }
  1658. //缩略图为空时不更新
  1659. var updateSandboxColumn = []string{}
  1660. if req.PicUrl == "" {
  1661. updateSandboxColumn = []string{"Content", "MindmapData", "ModifyTime", "SandboxClassifyId", "Style"}
  1662. } else {
  1663. updateSandboxColumn = []string{"Content", "MindmapData", "PicUrl", "ModifyTime", "SandboxClassifyId", "Style"}
  1664. }
  1665. err = sandboxInfo.Update(updateSandboxColumn)
  1666. if err != nil {
  1667. br.Msg = "保存失败!"
  1668. if errMsg != `` {
  1669. br.Msg = errMsg
  1670. }
  1671. br.ErrMsg = "保存失败,Err:" + err.Error()
  1672. return
  1673. }
  1674. }
  1675. msg := "保存成功"
  1676. br.Ret = 200
  1677. br.Success = true
  1678. br.Msg = msg
  1679. br.Data = sandboxResp
  1680. }
  1681. // Delete
  1682. // @Title 删除沙盘
  1683. // @Description 删除沙盘接口
  1684. // @Param request body request.DeleteSandbox true "type json string"
  1685. // @Success 200 标记成功
  1686. // @router /deleteV2 [post]
  1687. func (this *SandboxController) DeleteV2() {
  1688. br := new(models.BaseResponse).Init()
  1689. defer func() {
  1690. this.Data["json"] = br
  1691. this.ServeJSON()
  1692. }()
  1693. sysUser := this.SysUser
  1694. if sysUser == nil {
  1695. br.Msg = "请登录"
  1696. br.ErrMsg = "请登录,SysUser Is Empty"
  1697. br.Ret = 408
  1698. return
  1699. }
  1700. var req request.DeleteSandbox
  1701. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1702. if err != nil {
  1703. br.Msg = "参数解析异常!"
  1704. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1705. return
  1706. }
  1707. if req.SandboxId <= 0 {
  1708. br.Msg = "缺少沙盘编号"
  1709. return
  1710. }
  1711. //删除沙盘
  1712. err = sandboxService.DeleteSandbox(req.SandboxId)
  1713. if err != nil {
  1714. br.Msg = err.Error()
  1715. return
  1716. }
  1717. msg := "删除成功"
  1718. br.Ret = 200
  1719. br.Success = true
  1720. br.Msg = msg
  1721. }
  1722. // GetSandboxVersionDetail
  1723. // @Title 获取沙盘版本数据详情(已保存的)
  1724. // @Description 获取沙盘版本数据详情接口(已保存的)
  1725. // @Param SandboxVersionCode query string true "沙盘版本code"
  1726. // @Success 200 {object} sandbox.SandboxVersion
  1727. // @router /detail [get]
  1728. func (this *SandboxController) GetSandboxDetail() {
  1729. br := new(models.BaseResponse).Init()
  1730. defer func() {
  1731. this.Data["json"] = br
  1732. this.ServeJSON()
  1733. }()
  1734. sysUser := this.SysUser
  1735. if sysUser == nil {
  1736. br.Msg = "请登录"
  1737. br.ErrMsg = "请登录,SysUser Is Empty"
  1738. br.Ret = 408
  1739. return
  1740. }
  1741. sandboxId, _ := this.GetInt("SandboxId")
  1742. if sandboxId == 0 {
  1743. br.Msg = "缺少沙盘Id"
  1744. return
  1745. }
  1746. //获取沙盘数据详情(已保存的)
  1747. sandboxInfo, err := sandbox.GetSandboxById(sandboxId)
  1748. if err != nil {
  1749. br.Msg = "获取失败"
  1750. br.ErrMsg = "获取失败,Err:" + err.Error()
  1751. return
  1752. }
  1753. msg := "获取成功"
  1754. br.Ret = 200
  1755. br.Success = true
  1756. br.Msg = msg
  1757. br.Data = sandboxInfo
  1758. }
  1759. //// SandboxClassifyItems
  1760. //// @Title 获取所有沙盘分类接口-包含沙盘-先分类后沙盘区分,暂时弃用
  1761. //// @Description 获取所有沙盘分类接口-包含沙盘
  1762. //// @Param IsShowMe query bool true "是否只看我的,true、false"
  1763. //// @Success 200 {object} data_manage.ChartClassifyListResp
  1764. //// @router /classify/list [get]
  1765. //func (this *SandboxController) SandboxClassifyItems() {
  1766. // br := new(models.BaseResponse).Init()
  1767. // defer func() {
  1768. // this.Data["json"] = br
  1769. // this.ServeJSON()
  1770. // }()
  1771. //
  1772. // resp := new(sandbox.SandboxClassifyListResp)
  1773. // sandboxClassifyId, _ := this.GetInt("SandboxClassifyId")
  1774. //
  1775. // isShowMe, _ := this.GetBool("IsShowMe")
  1776. // if isShowMe {
  1777. // errMsg, err := sandboxService.GetSandboxClassifyListForMe(*this.SysUser, resp, sandboxClassifyId)
  1778. // if err != nil {
  1779. // br.Msg = errMsg
  1780. // br.ErrMsg = err.Error()
  1781. // return
  1782. // }
  1783. // // 移除没有权限的图表
  1784. // //allNodes := sandboxService.HandleNoPermissionSandbox(resp.AllNodes, nil)
  1785. // //resp.AllNodes = allNodes
  1786. //
  1787. // br.Ret = 200
  1788. // br.Success = true
  1789. // br.Msg = "获取成功"
  1790. // br.Data = resp
  1791. // fmt.Println("source my classify")
  1792. // return
  1793. // }
  1794. //
  1795. // rootList, err := sandbox.GetSandboxClassifyByParentId(sandboxClassifyId)
  1796. // if err != nil && err.Error() != utils.ErrNoRow() {
  1797. // br.Msg = "获取失败"
  1798. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1799. // return
  1800. // }
  1801. //
  1802. // classifyAll, err := sandbox.GetSandboxClassifyByParentId(sandboxClassifyId)
  1803. // if err != nil && err.Error() != utils.ErrNoRow() {
  1804. // br.Msg = "获取失败"
  1805. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1806. // return
  1807. // }
  1808. //
  1809. // sandboxAll, err := sandbox.GetSandboxItemsByClassifyId(sandboxClassifyId)
  1810. // if err != nil && err.Error() != utils.ErrNoRow() {
  1811. // br.Msg = "获取失败"
  1812. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1813. // return
  1814. // }
  1815. //
  1816. // sandListMap := make(map[int][]*sandbox.SandboxClassifyItems)
  1817. // for _, v := range sandboxAll {
  1818. // if _, ok := sandListMap[v.SandboxClassifyId]; !ok {
  1819. // list := make([]*sandbox.SandboxClassifyItems, 0)
  1820. // list = append(list, v)
  1821. // sandListMap[v.SandboxClassifyId] = list
  1822. // } else {
  1823. // sandListMap[v.SandboxClassifyId] = append(sandListMap[v.SandboxClassifyId], v)
  1824. // }
  1825. // }
  1826. //
  1827. // nodeAll := make([]*sandbox.SandboxClassifyItems, 0)
  1828. // for k := range rootList {
  1829. // rootNode := rootList[k]
  1830. // sandboxService.SandboxClassifyItemsMakeTree(this.SysUser, classifyAll, rootNode)
  1831. // nodeAll = append(nodeAll, rootNode)
  1832. // }
  1833. // //for k := range nodeAll {
  1834. // //
  1835. // //}
  1836. // newAll := sandboxService.SandboxItemsMakeTree(nodeAll, sandListMap, sandboxClassifyId)
  1837. //
  1838. // resp.AllNodes = newAll
  1839. // br.Ret = 200
  1840. // br.Success = true
  1841. // br.Msg = "获取成功"
  1842. // br.Data = resp
  1843. //}
  1844. //// SandboxMove
  1845. //// @Title 移动沙盘接口
  1846. //// @Description 移动图表接口
  1847. //// @Success 200 {object} data_manage.MoveChartInfoReq
  1848. //// @router /move [post]
  1849. //func (this *SandboxController) SandboxMove() {
  1850. // br := new(models.BaseResponse).Init()
  1851. // defer func() {
  1852. // this.Data["json"] = br
  1853. // this.ServeJSON()
  1854. // }()
  1855. //
  1856. // sysUser := this.SysUser
  1857. // if sysUser == nil {
  1858. // br.Msg = "请登录"
  1859. // br.ErrMsg = "请登录,SysUser Is Empty"
  1860. // br.Ret = 408
  1861. // return
  1862. // }
  1863. //
  1864. // var req sandbox.MoveSandboxReq
  1865. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1866. // if err != nil {
  1867. // br.Msg = "参数解析异常!"
  1868. // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1869. // return
  1870. // }
  1871. //
  1872. // if req.SandboxId <= 0 {
  1873. // br.Msg = "参数错误"
  1874. // br.ErrMsg = "沙盘id小于等于0"
  1875. // return
  1876. // }
  1877. //
  1878. // if req.SandboxClassifyId <= 0 {
  1879. // br.Msg = "请选择分类"
  1880. // return
  1881. // }
  1882. // //判断分类是否存在
  1883. // count, _ := sandbox.GetSandboxClassifyCountById(req.SandboxClassifyId)
  1884. // if count <= 0 {
  1885. // br.Msg = "分类已被删除,不可移动,请刷新页面"
  1886. // return
  1887. // }
  1888. //
  1889. // sandboxInfo, err := sandbox.GetSandboxById(req.SandboxId)
  1890. // if err != nil {
  1891. // br.Msg = "移动失败"
  1892. // br.ErrMsg = "获取沙盘信息失败,Err:" + err.Error()
  1893. // return
  1894. // }
  1895. //
  1896. // //如果改变了分类,那么移动该图表数据
  1897. // if sandboxInfo.SandboxClassifyId != req.SandboxClassifyId {
  1898. // //查询需要修改的分类下是否存在同一个图表名称
  1899. // tmpSandboxInfo, tmpErr := sandbox.GetSandboxByClassifyIdAndName(req.SandboxClassifyId, sandboxInfo.Name)
  1900. // if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  1901. // br.Msg = "移动失败"
  1902. // br.ErrMsg = "移动失败,Err:" + tmpErr.Error()
  1903. // return
  1904. // }
  1905. // if tmpSandboxInfo != nil {
  1906. // br.Msg = "移动失败,同一个分类下沙盘名称不允许重复"
  1907. // br.ErrMsg = "移动失败,同一个分类下沙盘名称不允许重复"
  1908. // return
  1909. // }
  1910. // err = sandbox.MoveSandbox(req.SandboxId, req.SandboxClassifyId)
  1911. // if err != nil {
  1912. // br.Msg = "移动失败"
  1913. // br.ErrMsg = "移动失败,Err:" + err.Error()
  1914. // return
  1915. // }
  1916. // }
  1917. //
  1918. // //移动排序
  1919. // updateCol := make([]string, 0)
  1920. // //如果有传入 上一个兄弟节点分类id
  1921. // if req.PrevSandboxId > 0 {
  1922. // prevChartInfo, err := sandbox.GetSandboxById(req.PrevSandboxId)
  1923. // if err != nil {
  1924. // br.Msg = "移动失败"
  1925. // br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  1926. // return
  1927. // }
  1928. //
  1929. // //如果是移动在两个兄弟节点之间
  1930. // if req.NextSandboxId > 0 {
  1931. // //下一个兄弟节点
  1932. // nextChartInfo, err := sandbox.GetSandboxById(req.NextSandboxId)
  1933. // if err != nil {
  1934. // br.Msg = "移动失败"
  1935. // br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  1936. // return
  1937. // }
  1938. // //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  1939. // if prevChartInfo.Sort == nextChartInfo.Sort || prevChartInfo.Sort == sandboxInfo.Sort {
  1940. // //变更兄弟节点的排序
  1941. // updateSortStr := `sort + 2`
  1942. // _ = sandbox.UpdateSandboxSortByClassifyId(prevChartInfo.SandboxClassifyId, prevChartInfo.Sort, prevChartInfo.SandboxId, updateSortStr)
  1943. // } else {
  1944. // //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  1945. // if nextChartInfo.Sort-prevChartInfo.Sort == 1 {
  1946. // //变更兄弟节点的排序
  1947. // updateSortStr := `sort + 1`
  1948. // _ = sandbox.UpdateSandboxSortByClassifyId(prevChartInfo.SandboxClassifyId, prevChartInfo.Sort, prevChartInfo.SandboxId, updateSortStr)
  1949. // }
  1950. // }
  1951. // }
  1952. //
  1953. // sandboxInfo.Sort = prevChartInfo.Sort + 1
  1954. // sandboxInfo.ModifyTime = time.Now()
  1955. // updateCol = append(updateCol, "Sort", "ModifyTime")
  1956. //
  1957. // } else {
  1958. // firstClassify, err := sandbox.GetFirstSandboxByClassifyId(req.SandboxClassifyId)
  1959. // if err != nil && err.Error() != utils.ErrNoRow() {
  1960. // br.Msg = "移动失败"
  1961. // br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  1962. // return
  1963. // }
  1964. //
  1965. // //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  1966. // if firstClassify != nil && firstClassify.Sort == 0 {
  1967. // updateSortStr := ` sort + 1 `
  1968. // _ = sandbox.UpdateSandboxSortByClassifyId(firstClassify.SandboxClassifyId, 0, firstClassify.SandboxId-1, updateSortStr)
  1969. // }
  1970. //
  1971. // sandboxInfo.Sort = 0 //那就是排在第一位
  1972. // sandboxInfo.ModifyTime = time.Now()
  1973. // updateCol = append(updateCol, "Sort", "ModifyTime")
  1974. // }
  1975. //
  1976. // //更新
  1977. // if len(updateCol) > 0 {
  1978. // err = sandboxInfo.Update(updateCol)
  1979. // if err != nil {
  1980. // br.Msg = "移动失败"
  1981. // br.ErrMsg = "修改失败,Err:" + err.Error()
  1982. // return
  1983. // }
  1984. // }
  1985. //
  1986. // if err != nil {
  1987. // br.Msg = "移动失败"
  1988. // br.ErrMsg = "修改失败,Err:" + err.Error()
  1989. // return
  1990. // }
  1991. //
  1992. // br.Ret = 200
  1993. // br.Success = true
  1994. // br.Msg = "移动成功"
  1995. //}
  1996. //// ChartClassifyMove
  1997. //// @Title 沙盘分类移动接口
  1998. //// @Description 沙盘分类移动接口
  1999. //// @Success 200 {object} data_manage.MoveChartClassifyReq
  2000. //// @router /classify/move [post]
  2001. //func (this *SandboxController) ChartClassifyMove() {
  2002. // br := new(models.BaseResponse).Init()
  2003. // defer func() {
  2004. // this.Data["json"] = br
  2005. // this.ServeJSON()
  2006. // }()
  2007. //
  2008. // sysUser := this.SysUser
  2009. // if sysUser == nil {
  2010. // br.Msg = "请登录"
  2011. // br.ErrMsg = "请登录,SysUser Is Empty"
  2012. // br.Ret = 408
  2013. // return
  2014. // }
  2015. //
  2016. // var req sandbox.MoveSandboxClassifyReq
  2017. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2018. // if err != nil {
  2019. // br.Msg = "参数解析异常!"
  2020. // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2021. // return
  2022. // }
  2023. //
  2024. // if req.ClassifyId <= 0 {
  2025. // br.Msg = "参数错误"
  2026. // br.ErrMsg = "分类id小于等于0"
  2027. // return
  2028. // }
  2029. // //判断分类是否存在
  2030. // sandboxClassifyInfo, err := sandbox.GetSandboxClassifyById(req.ClassifyId)
  2031. // if err != nil {
  2032. // br.Msg = "移动失败"
  2033. // br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  2034. // return
  2035. // }
  2036. //
  2037. // updateCol := make([]string, 0)
  2038. //
  2039. // //判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
  2040. // if sandboxClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId != 0 {
  2041. // parentChartClassifyInfo, err := sandbox.GetSandboxClassifyById(req.ParentClassifyId)
  2042. // if err != nil {
  2043. // br.Msg = "移动失败"
  2044. // br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error()
  2045. // return
  2046. // }
  2047. // sandboxClassifyInfo.ParentId = parentChartClassifyInfo.SandboxClassifyId
  2048. // sandboxClassifyInfo.Level = parentChartClassifyInfo.Level + 1
  2049. // sandboxClassifyInfo.ModifyTime = time.Now()
  2050. // updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  2051. // } else if sandboxClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId == 0 {
  2052. // //改为一级分类
  2053. // sandboxClassifyInfo.ParentId = req.ParentClassifyId
  2054. // sandboxClassifyInfo.Level = 1
  2055. // sandboxClassifyInfo.ModifyTime = time.Now()
  2056. // updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  2057. // }
  2058. //
  2059. // //如果有传入 上一个兄弟节点分类id
  2060. // if req.PrevClassifyId > 0 {
  2061. // //上一个兄弟节点
  2062. // prevClassify, err := sandbox.GetSandboxClassifyById(req.PrevClassifyId)
  2063. // if err != nil {
  2064. // br.Msg = "移动失败"
  2065. // br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  2066. // return
  2067. // }
  2068. //
  2069. // //如果是移动在两个兄弟节点之间
  2070. // if req.NextClassifyId > 0 {
  2071. // //下一个兄弟节点
  2072. // nextClassify, err := sandbox.GetSandboxClassifyById(req.NextClassifyId)
  2073. // if err != nil {
  2074. // br.Msg = "移动失败"
  2075. // br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  2076. // return
  2077. // }
  2078. // //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  2079. // if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == sandboxClassifyInfo.Sort {
  2080. // //变更兄弟节点的排序
  2081. // updateSortStr := `sort + 2`
  2082. // _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, prevClassify.SandboxClassifyId, prevClassify.Sort, updateSortStr)
  2083. // } else {
  2084. // //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  2085. // if nextClassify.Sort-prevClassify.Sort == 1 {
  2086. // //变更兄弟节点的排序
  2087. // updateSortStr := `sort + 1`
  2088. // _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr)
  2089. // }
  2090. // }
  2091. // }
  2092. //
  2093. // sandboxClassifyInfo.Sort = prevClassify.Sort + 1
  2094. // sandboxClassifyInfo.ModifyTime = time.Now()
  2095. // updateCol = append(updateCol, "Sort", "ModifyTime")
  2096. //
  2097. // } else {
  2098. // firstClassify, err := sandbox.GetFirstSandboxClassifyByParentId(sandboxClassifyInfo.ParentId)
  2099. // if err != nil && err.Error() != utils.ErrNoRow() {
  2100. // br.Msg = "移动失败"
  2101. // br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  2102. // return
  2103. // }
  2104. //
  2105. // //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  2106. // if firstClassify != nil && firstClassify.Sort == 0 {
  2107. // updateSortStr := ` sort + 1 `
  2108. // _ = sandbox.UpdateSandboxClassifySortByParentId(firstClassify.ParentId, firstClassify.SandboxClassifyId-1, 0, updateSortStr)
  2109. // }
  2110. //
  2111. // sandboxClassifyInfo.Sort = 0 //那就是排在第一位
  2112. // sandboxClassifyInfo.ModifyTime = time.Now()
  2113. // updateCol = append(updateCol, "Sort", "ModifyTime")
  2114. // }
  2115. //
  2116. // //更新
  2117. // if len(updateCol) > 0 {
  2118. // err = sandboxClassifyInfo.Update(updateCol)
  2119. // if err != nil {
  2120. // br.Msg = "移动失败"
  2121. // br.ErrMsg = "修改失败,Err:" + err.Error()
  2122. // return
  2123. // }
  2124. // }
  2125. // br.Ret = 200
  2126. // br.Success = true
  2127. // br.Msg = "移动成功"
  2128. //}
  2129. // SandboxClassifyItems
  2130. // @Title 获取所有沙盘分类接口-不包含沙盘
  2131. // @Description 获取所有沙盘分类接口-不包含沙盘
  2132. // @Param IsShowMe query bool true "是否只看我的,true、false"
  2133. // @Success 200 {object} data_manage.ChartClassifyListResp
  2134. // @router /classifyList [get]
  2135. func (this *SandboxController) SandboxClassifyList() {
  2136. br := new(models.BaseResponse).Init()
  2137. defer func() {
  2138. this.Data["json"] = br
  2139. this.ServeJSON()
  2140. }()
  2141. resp := new(sandbox.SandboxClassifyListResp)
  2142. rootList, err := sandbox.GetSandboxClassifyByParentId(0)
  2143. if err != nil && err.Error() != utils.ErrNoRow() {
  2144. br.Msg = "获取失败"
  2145. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  2146. return
  2147. }
  2148. classifyAll, err := sandbox.GetSandboxClassifyAll()
  2149. if err != nil && err.Error() != utils.ErrNoRow() {
  2150. br.Msg = "获取失败"
  2151. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  2152. return
  2153. }
  2154. nodeAll := make([]*sandbox.SandboxClassifyItems, 0)
  2155. for k := range rootList {
  2156. rootNode := rootList[k]
  2157. sandboxService.SandboxClassifyItemsMakeTree(this.SysUser, classifyAll, rootNode)
  2158. nodeAll = append(nodeAll, rootNode)
  2159. }
  2160. resp.AllNodes = nodeAll
  2161. br.Ret = 200
  2162. br.Success = true
  2163. br.Msg = "获取成功"
  2164. br.Data = resp
  2165. }
  2166. // @Title 链接指标检测
  2167. // @Description 链接指标检测接口
  2168. // @Param request body data_manage.ChartClassifyDeleteCheckResp true "type json string"
  2169. // @Success 200 Ret=200 检测成功
  2170. // @router /link/check [post]
  2171. func (this *SandboxController) LinkEdbInfoCheck() {
  2172. br := new(models.BaseResponse).Init()
  2173. defer func() {
  2174. this.Data["json"] = br
  2175. this.ServeJSON()
  2176. }()
  2177. var req sandbox.SandboxLinkCheckReq
  2178. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2179. if err != nil {
  2180. br.Msg = "参数解析异常!"
  2181. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2182. return
  2183. }
  2184. resp := new(sandbox.SandboxLinkCheckResp)
  2185. edbInfoList, err := data_manage.GetEdbInfoByIdList(req.EdbInfoIdList)
  2186. if err != nil {
  2187. br.Msg = "获取指标信息失败"
  2188. br.ErrMsg = "获取指标信息失败,err:" + err.Error()
  2189. return
  2190. }
  2191. for _, v := range edbInfoList {
  2192. resp.EdbInfoIdList = append(resp.EdbInfoIdList, v.EdbInfoId)
  2193. }
  2194. chartList, err := data_manage.GetChartInfoByIdList(req.ChartInfoIdList)
  2195. if err != nil {
  2196. br.Msg = `获取失败`
  2197. br.ErrMsg = `获取图表列表失败,ERR:` + err.Error()
  2198. return
  2199. }
  2200. for _, v := range chartList {
  2201. resp.ChartInfoIdList = append(resp.ChartInfoIdList, v.ChartInfoId)
  2202. }
  2203. reportList, err := models.GetSimpleReportByIds(req.ReportIdList)
  2204. if err != nil {
  2205. br.Msg = `获取失败`
  2206. br.ErrMsg = `获取报告列表失败,ERR:` + err.Error()
  2207. return
  2208. }
  2209. for _, v := range reportList {
  2210. resp.ReportIdList = append(resp.ReportIdList, v.Id)
  2211. }
  2212. br.Ret = 200
  2213. br.Msg = "检测成功"
  2214. br.Success = true
  2215. br.Data = resp
  2216. }