sandbox.go 77 KB

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