sandbox.go 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461
  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. "eta/eta_api/services/data"
  11. sandboxService "eta/eta_api/services/sandbox"
  12. "eta/eta_api/utils"
  13. "fmt"
  14. "time"
  15. "github.com/rdlucklib/rdluck_tools/paging"
  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 && err.Error() != utils.ErrNoRow() {
  69. // br.Success = true
  70. // br.Msg = "获取沙盘列表失败"
  71. // br.ErrMsg = "获取沙盘列表失败,Err:" + err.Error()
  72. // return
  73. // }
  74. //
  75. // if list == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  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 && err.Error() != utils.ErrNoRow() {
  176. br.Success = true
  177. br.Msg = "获取沙盘列表失败"
  178. br.ErrMsg = "获取沙盘列表失败,Err:" + err.Error()
  179. return
  180. }
  181. if list == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  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 && err.Error() != utils.ErrNoRow() {
  239. br.Success = true
  240. br.Msg = "获取沙盘列表失败"
  241. br.ErrMsg = "获取沙盘列表失败,Err:" + err.Error()
  242. return
  243. }
  244. if list == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  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 err.Error() == utils.ErrNoRow() {
  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 && err.Error() != utils.ErrNoRow() {
  748. br.Success = true
  749. br.Msg = "获取沙盘列表失败"
  750. br.ErrMsg = "获取沙盘列表失败,Err:" + err.Error()
  751. return
  752. }
  753. if list == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  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. nodeAll, err := sandboxService.GetSandboxClassifyByIsShowMe(resp.AllNodes, sandboxClassifyId, this.SysUser.AdminId)
  792. if err != nil {
  793. br.Msg = "获取失败"
  794. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  795. return
  796. }
  797. resp.AllNodes = nodeAll
  798. br.Ret = 200
  799. br.Success = true
  800. br.Msg = "获取成功"
  801. br.Data = resp
  802. fmt.Println("source my classify")
  803. return
  804. }
  805. rootList, err := sandbox.GetSandboxClassifyAndInfoByParentId(sandboxClassifyId)
  806. if err != nil && err.Error() != utils.ErrNoRow() {
  807. br.Msg = "获取失败"
  808. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  809. return
  810. }
  811. classifyAll, err := sandbox.GetSandboxClassifyAndInfoByParentId(sandboxClassifyId)
  812. if err != nil && err.Error() != utils.ErrNoRow() {
  813. br.Msg = "获取失败"
  814. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  815. return
  816. }
  817. //sandboxAll, err := sandbox.GetSandboxItemsByClassifyId(sandboxClassifyId)
  818. //if err != nil && err.Error() != utils.ErrNoRow() {
  819. // br.Msg = "获取失败"
  820. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  821. // return
  822. //}
  823. //sandListMap := make(map[int][]*sandbox.SandboxClassifyItems)
  824. //for _, v := range sandboxAll {
  825. // if _, ok := sandListMap[v.SandboxClassifyId]; !ok {
  826. // list := make([]*sandbox.SandboxClassifyItems, 0)
  827. // list = append(list, v)
  828. // sandListMap[v.SandboxClassifyId] = list
  829. // } else {
  830. // sandListMap[v.SandboxClassifyId] = append(sandListMap[v.SandboxClassifyId], v)
  831. // }
  832. //}
  833. nodeAll := make([]*sandbox.SandboxClassifyItems, 0)
  834. for k := range rootList {
  835. rootNode := rootList[k]
  836. sandboxService.SandboxClassifyItemsMakeTreeV2(this.SysUser, classifyAll, rootNode)
  837. nodeAll = append(nodeAll, rootNode)
  838. }
  839. //newAll := sandboxService.SandboxItemsMakeTree(nodeAll, sandListMap, sandboxClassifyId)
  840. resp.AllNodes = nodeAll
  841. br.Ret = 200
  842. br.Success = true
  843. br.Msg = "获取成功"
  844. br.Data = resp
  845. }
  846. // @Title 新增沙盘分类
  847. // @Description 新增沙盘分类接口
  848. // @Param request body data_manage.AddChartClassifyReq true "type json string"
  849. // @Success 200 Ret=200 保存成功
  850. // @router /classify/add [post]
  851. func (this *SandboxController) AddSandboxClassify() {
  852. br := new(models.BaseResponse).Init()
  853. defer func() {
  854. this.Data["json"] = br
  855. this.ServeJSON()
  856. }()
  857. var req sandbox.AddSandboxClassifyReq
  858. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  859. if err != nil {
  860. br.Msg = "参数解析异常!"
  861. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  862. return
  863. }
  864. if req.SandboxClassifyName == "" {
  865. br.Msg = "请输入分类名称"
  866. br.IsSendEmail = false
  867. return
  868. }
  869. if req.ParentId < 0 {
  870. br.Msg = "参数错误"
  871. br.IsSendEmail = false
  872. return
  873. }
  874. count, err := sandbox.GetSandboxClassifyCount(req.SandboxClassifyName, req.ParentId)
  875. if err != nil {
  876. br.Msg = "判断名称是否已存在失败"
  877. br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  878. return
  879. }
  880. if count > 0 {
  881. br.Msg = "分类名称已存在,请重新输入"
  882. br.IsSendEmail = false
  883. return
  884. }
  885. //获取该层级下最大的排序数
  886. maxSort, err := sandbox.GetSandboxClassifyMaxSort(req.ParentId)
  887. classify := new(sandbox.SandboxClassify)
  888. classify.ParentId = req.ParentId
  889. classify.SandboxClassifyName = req.SandboxClassifyName
  890. classify.HasData = 0
  891. classify.CreateTime = time.Now()
  892. classify.ModifyTime = time.Now()
  893. classify.SysUserId = this.SysUser.AdminId
  894. classify.SysUserRealName = this.SysUser.RealName
  895. classify.ChartPermissionId = req.ChartPermissionId
  896. classify.ChartPermissionName = req.ChartPermissionName
  897. classify.Level = req.Level + 1
  898. classify.Sort = maxSort + 1
  899. _, err = sandbox.AddSandboxClassify(classify)
  900. if err != nil {
  901. br.Msg = "保存分类失败"
  902. br.ErrMsg = "保存分类失败,Err:" + err.Error()
  903. return
  904. }
  905. br.Ret = 200
  906. br.Msg = "保存成功"
  907. br.Success = true
  908. }
  909. // @Title 修改沙盘分类
  910. // @Description 修改沙盘分类接口
  911. // @Param request body data_manage.EditChartClassifyReq true "type json string"
  912. // @Success 200 Ret=200 修改成功
  913. // @router /classify/edit [post]
  914. func (this *SandboxController) EditSandboxClassify() {
  915. br := new(models.BaseResponse).Init()
  916. defer func() {
  917. this.Data["json"] = br
  918. this.ServeJSON()
  919. }()
  920. var req sandbox.EditSandboxClassifyReq
  921. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  922. if err != nil {
  923. br.Msg = "参数解析异常!"
  924. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  925. return
  926. }
  927. if req.SandboxClassifyName == "" {
  928. br.Msg = "请输入分类名称"
  929. br.IsSendEmail = false
  930. return
  931. }
  932. if req.SandboxClassifyId <= 0 {
  933. br.Msg = "参数错误"
  934. br.IsSendEmail = false
  935. return
  936. }
  937. //item, err := sandbox.GetSandboxClassifyById(req.SandboxClassifyId)
  938. //if err != nil {
  939. // br.Msg = "保存失败"
  940. // br.Msg = "获取分类信息失败,Err:" + err.Error()
  941. // return
  942. //}
  943. //count, err := sandbox.GetSandboxClassifyCount(req.SandboxClassifyName, item.ParentId)
  944. //if err != nil {
  945. // br.Msg = "判断名称是否已存在失败"
  946. // br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  947. // return
  948. //}
  949. //if count > 0 {
  950. // br.Msg = "分类名称已存在,请重新输入"
  951. // br.IsSendEmail = false
  952. // return
  953. //}
  954. err = sandbox.EditSandboxClassify(req.SandboxClassifyId, req.ChartPermissionId, req.SandboxClassifyName, req.ChartPermissionName)
  955. if err != nil {
  956. br.Msg = "保存失败"
  957. br.ErrMsg = "保存失败,Err:" + err.Error()
  958. return
  959. }
  960. ids, err := sandbox.GetSandboxClassifySubcategories(req.SandboxClassifyId)
  961. if err != nil {
  962. br.Msg = "查询子级分类id失败"
  963. br.ErrMsg = "查询子级分类id失败,Err:" + err.Error()
  964. return
  965. }
  966. err = sandbox.UpdateSandboxClassifyChartPermissionById(req.ChartPermissionId, req.ChartPermissionName, ids)
  967. if err != nil {
  968. br.Msg = "修改子级分类错误"
  969. br.ErrMsg = "修改子级分类错误,Err:" + err.Error()
  970. return
  971. }
  972. br.Ret = 200
  973. br.Msg = "保存成功"
  974. br.Success = true
  975. br.IsAddLog = true
  976. }
  977. // @Title 删除沙盘检测接口
  978. // @Description 删除沙盘检测接口
  979. // @Param request body data_manage.ChartClassifyDeleteCheckResp true "type json string"
  980. // @Success 200 Ret=200 检测成功
  981. // @router /classify/delete/check [post]
  982. func (this *SandboxController) DeleteSandboxClassifyCheck() {
  983. br := new(models.BaseResponse).Init()
  984. defer func() {
  985. this.Data["json"] = br
  986. this.ServeJSON()
  987. }()
  988. var req sandbox.SandboxClassifyDeleteCheckReq
  989. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  990. if err != nil {
  991. br.Msg = "参数解析异常!"
  992. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  993. return
  994. }
  995. if req.SandboxClassifyId < 0 {
  996. br.Msg = "参数错误"
  997. br.IsSendEmail = false
  998. return
  999. }
  1000. var deleteStatus int
  1001. var tipsMsg string
  1002. //删除分类
  1003. if req.SandboxClassifyId > 0 {
  1004. //判断沙盘分类下,是否含有沙盘
  1005. count, err := sandbox.GetSandboxInfoCountByClassifyId(req.SandboxClassifyId)
  1006. if err != nil {
  1007. br.Msg = "删除失败"
  1008. br.ErrMsg = "分类下是否含有指标失败,Err:" + err.Error()
  1009. return
  1010. }
  1011. if count > 0 {
  1012. deleteStatus = 1
  1013. tipsMsg = "该分类下关联沙盘不可删除"
  1014. }
  1015. }
  1016. if deleteStatus != 1 {
  1017. classifyCount, err := sandbox.GetSandboxInfoCountByClassifyId(req.SandboxClassifyId)
  1018. if err != nil && err.Error() != utils.ErrNoRow() {
  1019. br.Msg = "删除失败"
  1020. br.ErrMsg = "分类下是否含有沙盘失败,Err:" + err.Error()
  1021. return
  1022. }
  1023. if classifyCount > 0 {
  1024. deleteStatus = 2
  1025. tipsMsg = "确认删除当前目录及包含的子目录吗"
  1026. }
  1027. }
  1028. if deleteStatus == 0 {
  1029. tipsMsg = "可删除,进行删除操作"
  1030. }
  1031. resp := new(sandbox.SandboxClassifyDeleteCheckResp)
  1032. resp.DeleteStatus = deleteStatus
  1033. resp.TipsMsg = tipsMsg
  1034. br.Ret = 200
  1035. br.Msg = "检测成功"
  1036. br.Success = true
  1037. br.Data = resp
  1038. }
  1039. // @Title 删除沙盘分类/沙盘
  1040. // @Description 删除沙盘分类/沙盘接口
  1041. // @Param request body data_manage.DeleteChartClassifyReq true "type json string"
  1042. // @Success 200 Ret=200 删除成功
  1043. // @router /classify/delete [post]
  1044. func (this *SandboxController) DeleteSandboxClassify() {
  1045. br := new(models.BaseResponse).Init()
  1046. defer func() {
  1047. this.Data["json"] = br
  1048. this.ServeJSON()
  1049. }()
  1050. sysUser := this.SysUser
  1051. if sysUser == nil {
  1052. br.Msg = "请登录"
  1053. br.ErrMsg = "请登录,SysUser Is Empty"
  1054. br.Ret = 408
  1055. return
  1056. }
  1057. var req sandbox.DeleteSandboxClassifyReq
  1058. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1059. if err != nil {
  1060. br.Msg = "参数解析异常!"
  1061. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1062. return
  1063. }
  1064. if req.SandboxClassifyId < 0 && req.SandboxId <= 0 {
  1065. br.Msg = "参数错误"
  1066. br.IsSendEmail = false
  1067. return
  1068. }
  1069. //删除分类
  1070. if req.SandboxClassifyId > 0 && req.SandboxId == 0 {
  1071. //判断是否含有指标
  1072. count, err := sandbox.GetSandboxInfoCountByClassifyId(req.SandboxId)
  1073. if err != nil && err.Error() != utils.ErrNoRow() {
  1074. br.Msg = "删除失败"
  1075. br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  1076. return
  1077. }
  1078. if count > 0 {
  1079. br.Msg = "该目录下存在关联指标,不可删除"
  1080. br.IsSendEmail = false
  1081. return
  1082. }
  1083. err = sandbox.DeleteSandboxClassify(req.SandboxClassifyId)
  1084. if err != nil {
  1085. br.Msg = "删除失败"
  1086. br.ErrMsg = "删除失败,Err:" + err.Error()
  1087. return
  1088. }
  1089. }
  1090. //删除沙盘
  1091. if req.SandboxId > 0 {
  1092. sandboxInfo, err := sandbox.GetSandboxById(req.SandboxId)
  1093. if err != nil {
  1094. if err.Error() == utils.ErrNoRow() {
  1095. br.Msg = "沙盘已删除,请刷新页面"
  1096. br.ErrMsg = "指标不存在,Err:" + err.Error()
  1097. return
  1098. } else {
  1099. br.Msg = "删除失败"
  1100. br.ErrMsg = "删除失败,获取指标信息失败,Err:" + err.Error()
  1101. return
  1102. }
  1103. }
  1104. if sandboxInfo == nil {
  1105. br.Msg = "沙盘已删除,请刷新页面"
  1106. return
  1107. }
  1108. err = sandboxService.DeleteSandbox(req.SandboxId)
  1109. if err != nil {
  1110. br.Msg = err.Error()
  1111. return
  1112. }
  1113. }
  1114. br.Ret = 200
  1115. br.Msg = "删除成功"
  1116. br.Success = true
  1117. br.IsAddLog = true
  1118. }
  1119. // ChartClassifyMove
  1120. // @Title 沙盘分类移动接口
  1121. // @Description 沙盘分类移动接口
  1122. // @Success 200 {object} data_manage.MoveChartClassifyReq
  1123. // @router /classify/move [post]
  1124. func (this *SandboxController) ChartClassifyMove() {
  1125. br := new(models.BaseResponse).Init()
  1126. defer func() {
  1127. this.Data["json"] = br
  1128. this.ServeJSON()
  1129. }()
  1130. sysUser := this.SysUser
  1131. if sysUser == nil {
  1132. br.Msg = "请登录"
  1133. br.ErrMsg = "请登录,SysUser Is Empty"
  1134. br.Ret = 408
  1135. return
  1136. }
  1137. var req sandbox.MoveSandboxClassifyReq
  1138. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1139. if err != nil {
  1140. br.Msg = "参数解析异常!"
  1141. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1142. return
  1143. }
  1144. if req.ClassifyId <= 0 {
  1145. br.Msg = "参数错误"
  1146. br.ErrMsg = "分类id小于等于0"
  1147. return
  1148. }
  1149. //判断分类是否存在
  1150. sandboxClassifyInfo, err := sandbox.GetSandboxClassifyById(req.ClassifyId)
  1151. if err != nil {
  1152. br.Msg = "移动失败"
  1153. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  1154. return
  1155. }
  1156. updateCol := make([]string, 0)
  1157. // 判断移动的是分类还是沙盘
  1158. if req.SandboxId > 0 {
  1159. //判断分类是否存在
  1160. count, _ := sandbox.GetSandboxClassifyCountById(req.ClassifyId)
  1161. if count <= 0 {
  1162. br.Msg = "分类已被删除,不可移动,请刷新页面"
  1163. return
  1164. }
  1165. sandboxInfo, err := sandbox.GetSandboxById(req.SandboxId)
  1166. if err != nil {
  1167. br.Msg = "移动失败"
  1168. br.ErrMsg = "获取沙盘信息失败,Err:" + err.Error()
  1169. return
  1170. }
  1171. //如果改变了分类,那么移动该图表数据
  1172. // 11/22 ETA逻辑优化去除名称重复限制
  1173. if sandboxInfo.SandboxClassifyId != req.ParentClassifyId {
  1174. ////查询需要修改的分类下是否存在同一个图表名称
  1175. //tmpSandboxInfo, tmpErr := sandbox.GetSandboxByClassifyIdAndName(req.ParentClassifyId, sandboxInfo.Name)
  1176. //if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  1177. // br.Msg = "移动失败"
  1178. // br.ErrMsg = "移动失败,Err:" + tmpErr.Error()
  1179. // return
  1180. //}
  1181. //if tmpSandboxInfo != nil {
  1182. // br.Msg = "移动失败,同一个分类下沙盘名称不允许重复"
  1183. // br.ErrMsg = "移动失败,同一个分类下沙盘名称不允许重复"
  1184. // return
  1185. //}
  1186. err = sandbox.MoveSandbox(req.SandboxId, req.ParentClassifyId)
  1187. if err != nil {
  1188. br.Msg = "移动失败"
  1189. br.ErrMsg = "移动失败,Err:" + err.Error()
  1190. return
  1191. }
  1192. }
  1193. //移动排序
  1194. updateCol := make([]string, 0)
  1195. //如果有传入 上一个兄弟节点分类id
  1196. if req.PrevId > 0 {
  1197. if req.PrevType == 1 {
  1198. //上一个兄弟节点
  1199. prevClassify, err := sandbox.GetSandboxClassifyById(req.PrevId)
  1200. if err != nil {
  1201. br.Msg = "移动失败"
  1202. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  1203. return
  1204. }
  1205. //如果是移动在两个兄弟节点之间
  1206. if req.NextId > 0 {
  1207. if req.NextType == 1 {
  1208. //上一个节点是分类 下一个节点是分类的情况
  1209. //下一个兄弟节点
  1210. nextClassify, err := sandbox.GetSandboxClassifyById(req.NextId)
  1211. if err != nil {
  1212. br.Msg = "移动失败"
  1213. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  1214. return
  1215. }
  1216. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  1217. if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == sandboxClassifyInfo.Sort {
  1218. //变更兄弟节点的排序
  1219. updateSortStr := `sort + 2`
  1220. _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, prevClassify.SandboxClassifyId, prevClassify.Sort, updateSortStr)
  1221. _ = sandbox.UpdateSandboxSortByClassifyId(prevClassify.SandboxClassifyId, prevClassify.Sort, 0, updateSortStr)
  1222. } else {
  1223. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  1224. if nextClassify.Sort-prevClassify.Sort == 1 {
  1225. //变更兄弟节点的排序
  1226. updateSortStr := `sort + 1`
  1227. _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr)
  1228. _ = sandbox.UpdateSandboxSortByClassifyId(prevClassify.SandboxClassifyId, prevClassify.Sort, 0, updateSortStr)
  1229. }
  1230. }
  1231. } else {
  1232. //上一个节点是分类 下一个节点是沙盘的情况
  1233. //下一个兄弟节点
  1234. nextChartInfo, err := sandbox.GetSandboxById(req.NextId)
  1235. if err != nil {
  1236. br.Msg = "移动失败"
  1237. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  1238. return
  1239. }
  1240. //如果上一个兄弟(分类)与下一个兄弟(沙盘)的排序权重是一致的,那么需要将下一个兄弟(沙盘)(以及下个兄弟(沙盘)的同样排序权重)的排序权重+2,自己变成上一个兄弟(分类)的排序权重+1
  1241. if prevClassify.Sort == nextChartInfo.Sort || prevClassify.Sort == sandboxInfo.Sort {
  1242. //变更兄弟节点的排序
  1243. updateSortStr := `sort + 2`
  1244. _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, prevClassify.SandboxClassifyId, prevClassify.Sort, updateSortStr)
  1245. _ = sandbox.UpdateSandboxSortByClassifyId(prevClassify.SandboxClassifyId, prevClassify.Sort, 0, updateSortStr)
  1246. } else {
  1247. //如果下一个兄弟(沙盘)的排序权重正好是上个兄弟节点(分类)的下一层,那么需要再加一层了
  1248. if nextChartInfo.Sort-prevClassify.Sort == 1 {
  1249. //变更兄弟节点的排序
  1250. updateSortStr := `sort + 1`
  1251. _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.SandboxClassifyId, updateSortStr)
  1252. _ = sandbox.UpdateSandboxSortByClassifyId(prevClassify.SandboxClassifyId, prevClassify.Sort, 0, updateSortStr)
  1253. }
  1254. }
  1255. }
  1256. }
  1257. sandboxInfo.Sort = prevClassify.Sort + 1
  1258. sandboxInfo.ModifyTime = time.Now()
  1259. updateCol = append(updateCol, "Sort", "ModifyTime")
  1260. } else {
  1261. prevSandbox, err := sandbox.GetSandboxById(req.PrevId)
  1262. if err != nil {
  1263. br.Msg = "移动失败"
  1264. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  1265. return
  1266. }
  1267. //如果是移动在两个兄弟节点之间
  1268. if req.NextId > 0 {
  1269. if req.NextType == 1 {
  1270. //上一个节点是沙盘 下一个节点是分类的情况
  1271. //下一个兄弟节点
  1272. nextClassify, err := sandbox.GetSandboxClassifyById(req.NextId)
  1273. if err != nil {
  1274. br.Msg = "移动失败"
  1275. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  1276. return
  1277. }
  1278. //如果上一个兄弟(沙盘)与下一个兄弟(分类)的排序权重是一致的,那么需要将下一个兄弟(分类)(以及下个兄弟(分类)的同样排序权重)的排序权重+2,自己变成上一个兄弟(沙盘)的排序权重+1
  1279. if prevSandbox.Sort == nextClassify.Sort || prevSandbox.Sort == sandboxClassifyInfo.Sort {
  1280. //变更兄弟节点的排序
  1281. updateSortStr := `sort + 2`
  1282. _ = sandbox.UpdateSandboxClassifySortByParentId(prevSandbox.SandboxClassifyId, 0, prevSandbox.Sort, updateSortStr)
  1283. _ = sandbox.UpdateSandboxSortByClassifyId(prevSandbox.SandboxClassifyId, prevSandbox.Sort, prevSandbox.SandboxId, updateSortStr)
  1284. } else {
  1285. //如果下一个兄弟(分类)的排序权重正好是上个兄弟(沙盘)节点的下一层,那么需要再加一层了
  1286. if nextClassify.Sort-prevSandbox.Sort == 1 {
  1287. //变更兄弟节点的排序
  1288. updateSortStr := `sort + 1`
  1289. _ = sandbox.UpdateSandboxClassifySortByParentId(prevSandbox.SandboxClassifyId, 0, prevSandbox.Sort, updateSortStr)
  1290. _ = sandbox.UpdateSandboxSortByClassifyId(prevSandbox.SandboxClassifyId, prevSandbox.Sort, prevSandbox.SandboxId, updateSortStr)
  1291. }
  1292. }
  1293. } else {
  1294. //上一个节点是沙盘 下一个节点是沙盘的情况
  1295. //下一个兄弟节点
  1296. nextChartInfo, err := sandbox.GetSandboxById(req.NextId)
  1297. if err != nil {
  1298. br.Msg = "移动失败"
  1299. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  1300. return
  1301. }
  1302. //如果上一个兄弟(沙盘)与下一个兄弟(分类)的排序权重是一致的,那么需要将下一个兄弟(分类)(以及下个兄弟(分类)的同样排序权重)的排序权重+2,自己变成上一个兄弟(沙盘)的排序权重+1
  1303. if prevSandbox.Sort == nextChartInfo.Sort || prevSandbox.Sort == sandboxInfo.Sort {
  1304. //变更兄弟节点的排序
  1305. updateSortStr := `sort + 2`
  1306. _ = sandbox.UpdateSandboxClassifySortByParentId(prevSandbox.SandboxClassifyId, 0, prevSandbox.Sort, updateSortStr)
  1307. _ = sandbox.UpdateSandboxSortByClassifyId(prevSandbox.SandboxClassifyId, prevSandbox.Sort, prevSandbox.SandboxId, updateSortStr)
  1308. } else {
  1309. //如果下一个兄弟(分类)的排序权重正好是上个兄弟(沙盘)节点的下一层,那么需要再加一层了
  1310. if nextChartInfo.Sort-prevSandbox.Sort == 1 {
  1311. //变更兄弟节点的排序
  1312. updateSortStr := `sort + 1`
  1313. _ = sandbox.UpdateSandboxClassifySortByParentId(prevSandbox.SandboxClassifyId, 0, prevSandbox.Sort, updateSortStr)
  1314. _ = sandbox.UpdateSandboxSortByClassifyId(prevSandbox.SandboxClassifyId, prevSandbox.Sort, prevSandbox.SandboxId, updateSortStr)
  1315. }
  1316. }
  1317. }
  1318. }
  1319. sandboxInfo.Sort = prevSandbox.Sort + 1
  1320. sandboxInfo.ModifyTime = time.Now()
  1321. updateCol = append(updateCol, "Sort", "ModifyTime")
  1322. }
  1323. } else {
  1324. // prevId为0,也就是沙盘移到最前端
  1325. firstClassify, err := sandbox.GetFirstSandboxByClassifyId(req.ClassifyId)
  1326. if err != nil && err.Error() != utils.ErrNoRow() {
  1327. br.Msg = "移动失败"
  1328. br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  1329. return
  1330. }
  1331. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  1332. if firstClassify != nil && firstClassify.Sort == 0 {
  1333. updateSortStr := ` sort + 1 `
  1334. _ = sandbox.UpdateSandboxSortByClassifyId(firstClassify.SandboxClassifyId, 0, firstClassify.SandboxId-1, updateSortStr)
  1335. }
  1336. sandboxInfo.Sort = 0 //那就是排在第一位
  1337. sandboxInfo.ModifyTime = time.Now()
  1338. updateCol = append(updateCol, "Sort", "ModifyTime")
  1339. }
  1340. //更新
  1341. if len(updateCol) > 0 {
  1342. err = sandboxInfo.Update(updateCol)
  1343. if err != nil {
  1344. br.Msg = "移动失败"
  1345. br.ErrMsg = "修改失败,Err:" + err.Error()
  1346. return
  1347. }
  1348. }
  1349. } else {
  1350. //移动的是分类
  1351. //判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
  1352. if sandboxClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId != 0 {
  1353. parentChartClassifyInfo, err := sandbox.GetSandboxClassifyById(req.ParentClassifyId)
  1354. if err != nil {
  1355. br.Msg = "移动失败"
  1356. br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error()
  1357. return
  1358. }
  1359. sandboxClassifyInfo.ParentId = parentChartClassifyInfo.SandboxClassifyId
  1360. sandboxClassifyInfo.Level = parentChartClassifyInfo.Level + 1
  1361. sandboxClassifyInfo.ModifyTime = time.Now()
  1362. updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  1363. } else if sandboxClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId == 0 {
  1364. //改为一级分类
  1365. sandboxClassifyInfo.ParentId = req.ParentClassifyId
  1366. sandboxClassifyInfo.Level = 1
  1367. sandboxClassifyInfo.ModifyTime = time.Now()
  1368. updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  1369. }
  1370. //如果有传入 上一个兄弟节点分类id
  1371. if req.PrevId > 0 {
  1372. if req.PrevType == 1 {
  1373. //上一个节点是分类
  1374. //上一个兄弟节点
  1375. prevClassify, err := sandbox.GetSandboxClassifyById(req.PrevId)
  1376. if err != nil {
  1377. br.Msg = "移动失败"
  1378. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  1379. return
  1380. }
  1381. //如果是移动在两个兄弟节点之间
  1382. if req.NextId > 0 {
  1383. if req.NextType == 1 {
  1384. //上一个节点是分类 下一个节点是分类的情况
  1385. //下一个兄弟节点
  1386. nextClassify, err := sandbox.GetSandboxClassifyById(req.NextId)
  1387. if err != nil {
  1388. br.Msg = "移动失败"
  1389. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  1390. return
  1391. }
  1392. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  1393. if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == sandboxClassifyInfo.Sort {
  1394. //变更兄弟节点的排序
  1395. updateSortStr := `sort + 2`
  1396. _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, prevClassify.SandboxClassifyId, prevClassify.Sort, updateSortStr)
  1397. _ = sandbox.UpdateSandboxSortByClassifyId(prevClassify.SandboxClassifyId, prevClassify.Sort, 0, updateSortStr)
  1398. } else {
  1399. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  1400. if nextClassify.Sort-prevClassify.Sort == 1 {
  1401. //变更兄弟节点的排序
  1402. updateSortStr := `sort + 1`
  1403. _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr)
  1404. _ = sandbox.UpdateSandboxSortByClassifyId(prevClassify.SandboxClassifyId, prevClassify.Sort, 0, updateSortStr)
  1405. }
  1406. }
  1407. } else {
  1408. //上一个节点是分类 下一个节点是沙盘的情况
  1409. //下一个兄弟节点
  1410. nextChartInfo, err := sandbox.GetSandboxById(req.NextId)
  1411. if err != nil {
  1412. br.Msg = "移动失败"
  1413. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  1414. return
  1415. }
  1416. //如果上一个兄弟(分类)与下一个兄弟(沙盘)的排序权重是一致的,那么需要将下一个兄弟(沙盘)(以及下个兄弟(沙盘)的同样排序权重)的排序权重+2,自己变成上一个兄弟(分类)的排序权重+1
  1417. if prevClassify.Sort == nextChartInfo.Sort || prevClassify.Sort == sandboxClassifyInfo.Sort {
  1418. //变更兄弟节点的排序
  1419. updateSortStr := `sort + 2`
  1420. _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, prevClassify.SandboxClassifyId, prevClassify.Sort, updateSortStr)
  1421. _ = sandbox.UpdateSandboxSortByClassifyId(prevClassify.SandboxClassifyId, prevClassify.Sort, 0, updateSortStr)
  1422. } else {
  1423. //如果下一个兄弟(沙盘)的排序权重正好是上个兄弟节点(分类)的下一层,那么需要再加一层了
  1424. if nextChartInfo.Sort-prevClassify.Sort == 1 {
  1425. //变更兄弟节点的排序
  1426. updateSortStr := `sort + 1`
  1427. _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.SandboxClassifyId, updateSortStr)
  1428. _ = sandbox.UpdateSandboxSortByClassifyId(prevClassify.SandboxClassifyId, prevClassify.Sort, 0, updateSortStr)
  1429. }
  1430. }
  1431. }
  1432. }
  1433. sandboxClassifyInfo.Sort = prevClassify.Sort + 1
  1434. sandboxClassifyInfo.ModifyTime = time.Now()
  1435. updateCol = append(updateCol, "Sort", "ModifyTime")
  1436. } else {
  1437. //上一个节点是沙盘
  1438. prevSandbox, err := sandbox.GetSandboxById(req.PrevId)
  1439. if err != nil {
  1440. br.Msg = "移动失败"
  1441. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  1442. return
  1443. }
  1444. //如果是移动在两个兄弟节点之间
  1445. if req.NextId > 0 {
  1446. if req.NextType == 1 {
  1447. //上一个节点是沙盘 下一个节点是分类的情况
  1448. //下一个兄弟节点
  1449. nextClassify, err := sandbox.GetSandboxClassifyById(req.NextId)
  1450. if err != nil {
  1451. br.Msg = "移动失败"
  1452. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  1453. return
  1454. }
  1455. //如果上一个兄弟(沙盘)与下一个兄弟(分类)的排序权重是一致的,那么需要将下一个兄弟(分类)(以及下个兄弟(分类)的同样排序权重)的排序权重+2,自己变成上一个兄弟(沙盘)的排序权重+1
  1456. if prevSandbox.Sort == nextClassify.Sort || prevSandbox.Sort == sandboxClassifyInfo.Sort {
  1457. //变更兄弟节点的排序
  1458. updateSortStr := `sort + 2`
  1459. _ = sandbox.UpdateSandboxClassifySortByParentId(prevSandbox.SandboxClassifyId, 0, prevSandbox.Sort, updateSortStr)
  1460. _ = sandbox.UpdateSandboxSortByClassifyId(prevSandbox.SandboxClassifyId, prevSandbox.Sort, prevSandbox.SandboxId, updateSortStr)
  1461. } else {
  1462. //如果下一个兄弟(分类)的排序权重正好是上个兄弟(沙盘)节点的下一层,那么需要再加一层了
  1463. if nextClassify.Sort-prevSandbox.Sort == 1 {
  1464. //变更兄弟节点的排序
  1465. updateSortStr := `sort + 1`
  1466. _ = sandbox.UpdateSandboxClassifySortByParentId(prevSandbox.SandboxClassifyId, 0, prevSandbox.Sort, updateSortStr)
  1467. _ = sandbox.UpdateSandboxSortByClassifyId(prevSandbox.SandboxClassifyId, prevSandbox.Sort, prevSandbox.SandboxId, updateSortStr)
  1468. }
  1469. }
  1470. } else {
  1471. //上一个节点是沙盘 下一个节点是沙盘的情况
  1472. //下一个兄弟节点
  1473. nextChartInfo, err := sandbox.GetSandboxById(req.NextId)
  1474. if err != nil {
  1475. br.Msg = "移动失败"
  1476. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  1477. return
  1478. }
  1479. //如果上一个兄弟(沙盘)与下一个兄弟(分类)的排序权重是一致的,那么需要将下一个兄弟(分类)(以及下个兄弟(分类)的同样排序权重)的排序权重+2,自己变成上一个兄弟(沙盘)的排序权重+1
  1480. if prevSandbox.Sort == nextChartInfo.Sort || prevSandbox.Sort == sandboxClassifyInfo.Sort {
  1481. //变更兄弟节点的排序
  1482. updateSortStr := `sort + 2`
  1483. _ = sandbox.UpdateSandboxClassifySortByParentId(prevSandbox.SandboxClassifyId, 0, prevSandbox.Sort, updateSortStr)
  1484. _ = sandbox.UpdateSandboxSortByClassifyId(prevSandbox.SandboxClassifyId, prevSandbox.Sort, prevSandbox.SandboxId, updateSortStr)
  1485. } else {
  1486. //如果下一个兄弟(分类)的排序权重正好是上个兄弟(沙盘)节点的下一层,那么需要再加一层了
  1487. if nextChartInfo.Sort-prevSandbox.Sort == 1 {
  1488. //变更兄弟节点的排序
  1489. updateSortStr := `sort + 1`
  1490. _ = sandbox.UpdateSandboxClassifySortByParentId(prevSandbox.SandboxClassifyId, 0, prevSandbox.Sort, updateSortStr)
  1491. _ = sandbox.UpdateSandboxSortByClassifyId(prevSandbox.SandboxClassifyId, prevSandbox.Sort, prevSandbox.SandboxId, updateSortStr)
  1492. }
  1493. }
  1494. }
  1495. }
  1496. sandboxClassifyInfo.Sort = prevSandbox.Sort + 1
  1497. sandboxClassifyInfo.ModifyTime = time.Now()
  1498. updateCol = append(updateCol, "Sort", "ModifyTime")
  1499. }
  1500. } else {
  1501. firstClassify, err := sandbox.GetFirstSandboxClassifyByParentId(sandboxClassifyInfo.ParentId)
  1502. if err != nil && err.Error() != utils.ErrNoRow() {
  1503. br.Msg = "移动失败"
  1504. br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  1505. return
  1506. }
  1507. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  1508. if firstClassify != nil && firstClassify.Sort == 0 {
  1509. updateSortStr := ` sort + 1 `
  1510. _ = sandbox.UpdateSandboxClassifySortByParentId(firstClassify.ParentId, firstClassify.SandboxClassifyId-1, 0, updateSortStr)
  1511. }
  1512. sandboxClassifyInfo.Sort = 0 //那就是排在第一位
  1513. sandboxClassifyInfo.ModifyTime = time.Now()
  1514. updateCol = append(updateCol, "Sort", "ModifyTime")
  1515. }
  1516. //更新
  1517. if len(updateCol) > 0 {
  1518. err = sandboxClassifyInfo.Update(updateCol)
  1519. if err != nil {
  1520. br.Msg = "移动失败"
  1521. br.ErrMsg = "修改失败,Err:" + err.Error()
  1522. return
  1523. }
  1524. if req.ParentClassifyId > 0 {
  1525. ids, err := sandbox.GetSandboxClassifySubcategories(req.ClassifyId)
  1526. if err != nil {
  1527. br.Msg = "查询子级分类id失败"
  1528. br.ErrMsg = "查询子级分类id失败,Err:" + err.Error()
  1529. return
  1530. }
  1531. parentChartClassifyInfo, err := sandbox.GetSandboxClassifyById(req.ParentClassifyId)
  1532. if err != nil {
  1533. br.Msg = "移动失败"
  1534. br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error()
  1535. return
  1536. }
  1537. err = sandbox.UpdateSandboxClassifyChartPermissionById(parentChartClassifyInfo.ChartPermissionId, parentChartClassifyInfo.ChartPermissionName, ids)
  1538. if err != nil {
  1539. br.Msg = "修改子级分类错误"
  1540. br.ErrMsg = "修改子级分类错误,Err:" + err.Error()
  1541. return
  1542. }
  1543. }
  1544. }
  1545. }
  1546. br.Ret = 200
  1547. br.Success = true
  1548. br.Msg = "移动成功"
  1549. }
  1550. // @Title ETA图表列表接口
  1551. // @Description ETA图表列表接口
  1552. // @Param PageSize query int true "每页数据条数"
  1553. // @Param CurrentIndex query int true "当前页页码,从1开始"
  1554. // @Param ChartClassifyId query int true "分类id"
  1555. // @Param KeyWord query string true "搜索关键词"
  1556. // @Param IsShowMe query bool true "是否只看我的,true、false"
  1557. // @Success 200 {object} data_manage.ChartListResp
  1558. // @router /listV2 [get]
  1559. func (this *SandboxController) ListV2() {
  1560. br := new(models.BaseResponse).Init()
  1561. defer func() {
  1562. this.Data["json"] = br
  1563. this.ServeJSON()
  1564. }()
  1565. sysUser := this.SysUser
  1566. if sysUser == nil {
  1567. br.Msg = "请登录"
  1568. br.ErrMsg = "请登录,SysUser Is Empty"
  1569. br.Ret = 408
  1570. return
  1571. }
  1572. sandboxClassifyId, _ := this.GetInt("SandboxClassifyId")
  1573. pageSize, _ := this.GetInt("PageSize")
  1574. currentIndex, _ := this.GetInt("CurrentIndex")
  1575. keyWord := this.GetString("KeyWord")
  1576. var total int
  1577. page := paging.GetPaging(currentIndex, pageSize, total)
  1578. var startSize int
  1579. if pageSize <= 0 {
  1580. pageSize = utils.PageSize20
  1581. }
  1582. if currentIndex <= 0 {
  1583. currentIndex = 1
  1584. }
  1585. startSize = paging.StartIndex(currentIndex, pageSize)
  1586. var condition string
  1587. var pars []interface{}
  1588. if sandboxClassifyId > 0 {
  1589. sandboxClassifyId, err := sandbox.GetSandboxClassify(sandboxClassifyId)
  1590. if err != nil && err.Error() != utils.ErrNoRow() {
  1591. br.Msg = "获取图表信息失败"
  1592. br.ErrMsg = "获取信息失败,GetChartClassify,Err:" + err.Error()
  1593. return
  1594. }
  1595. condition += " AND sandbox_classify_id IN(" + sandboxClassifyId + ") "
  1596. //pars = append(pars, chartClassifyId)
  1597. }
  1598. if keyWord != "" {
  1599. condition += ` AND ( name LIKE '%` + keyWord + `%' )`
  1600. }
  1601. //只看我的
  1602. isShowMe, _ := this.GetBool("IsShowMe")
  1603. if isShowMe {
  1604. condition += ` AND sys_user_id = ? `
  1605. pars = append(pars, sysUser.AdminId)
  1606. }
  1607. //获取图表信息
  1608. condition += ` AND is_delete = 0 `
  1609. list, err := sandbox.GetSandboxListByCondition(condition, pars, startSize, pageSize)
  1610. if err != nil && err.Error() != utils.ErrNoRow() {
  1611. br.Success = true
  1612. br.Msg = "获取沙盘信息失败"
  1613. br.ErrMsg = "获取沙盘信息失败,Err:" + err.Error()
  1614. return
  1615. }
  1616. for i, v := range list {
  1617. ids, err := sandbox.GetSandboxAllParentByClassifyId(v.SandboxClassifyId)
  1618. if err != nil {
  1619. br.Msg = "获取父级信息错误!"
  1620. br.ErrMsg = "获取父级信息错误,Err:" + err.Error()
  1621. return
  1622. }
  1623. list[i].ParentIds = ids
  1624. }
  1625. resp := new(sandbox.SandboxListResp)
  1626. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  1627. items := make([]*sandbox.SandboxListItems, 0)
  1628. resp.Paging = page
  1629. resp.List = items
  1630. br.Ret = 200
  1631. br.Success = true
  1632. br.Msg = "获取成功"
  1633. return
  1634. }
  1635. dataCount, err := sandbox.GetSandboxListCountByCondition(condition, pars)
  1636. if err != nil && err.Error() != utils.ErrNoRow() {
  1637. br.Msg = "获取指标信息失败"
  1638. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  1639. return
  1640. }
  1641. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  1642. resp.Paging = page
  1643. resp.List = list
  1644. br.Ret = 200
  1645. br.Success = true
  1646. br.Msg = "获取成功"
  1647. br.Data = resp
  1648. }
  1649. // Save
  1650. // @Title 新增/编辑保存沙盘
  1651. // @Description 新增/编辑保存沙盘接口
  1652. // @Param request body request.AddAndEditSandbox true "type json string"
  1653. // @Success 200 {object} sandbox.Sandbox
  1654. // @router /saveV2 [post]
  1655. func (this *SandboxController) SaveV2() {
  1656. br := new(models.BaseResponse).Init()
  1657. defer func() {
  1658. this.Data["json"] = br
  1659. this.ServeJSON()
  1660. }()
  1661. sysUser := this.SysUser
  1662. if sysUser == nil {
  1663. br.Msg = "请登录"
  1664. br.ErrMsg = "请登录,SysUser Is Empty"
  1665. br.Ret = 408
  1666. return
  1667. }
  1668. var req request.AddAndEditSandboxV2
  1669. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1670. if err != nil {
  1671. br.Msg = "参数解析异常!"
  1672. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1673. return
  1674. }
  1675. var sandboxResp *sandbox.SandboxSaveResp
  1676. var errMsg string
  1677. var sandBoxData *sandbox.Sandbox
  1678. if req.SandboxId <= 0 {
  1679. //新增沙盘
  1680. sandboxResp, err = sandboxService.AddSandboxV2(req, sysUser.AdminId, sysUser.RealName)
  1681. if err != nil {
  1682. br.Msg = "保存失败!"
  1683. if errMsg != `` {
  1684. br.Msg = errMsg
  1685. }
  1686. br.ErrMsg = "保存失败,Err:" + err.Error()
  1687. return
  1688. }
  1689. sandBoxData = sandboxResp.Sandbox
  1690. } else {
  1691. //编辑沙盘
  1692. sandboxInfo := &sandbox.Sandbox{
  1693. SandboxId: req.SandboxId,
  1694. Name: utils.TrimStr(req.Name),
  1695. Content: req.Content,
  1696. MindmapData: req.MindmapData,
  1697. PicUrl: utils.TrimStr(req.PicUrl),
  1698. ModifyTime: time.Now(),
  1699. SandboxClassifyId: req.SandboxClassifyId,
  1700. Style: req.Style,
  1701. }
  1702. //缩略图为空时不更新
  1703. var updateSandboxColumn = []string{}
  1704. if req.PicUrl == "" {
  1705. updateSandboxColumn = []string{"Name", "Content", "MindmapData", "ModifyTime", "SandboxClassifyId", "Style"}
  1706. } else {
  1707. updateSandboxColumn = []string{"Name", "Content", "MindmapData", "PicUrl", "ModifyTime", "SandboxClassifyId", "Style"}
  1708. }
  1709. err = sandboxInfo.Update(updateSandboxColumn)
  1710. if err != nil {
  1711. br.Msg = "保存失败!"
  1712. if errMsg != `` {
  1713. br.Msg = errMsg
  1714. }
  1715. br.ErrMsg = "保存失败,Err:" + err.Error()
  1716. return
  1717. }
  1718. sandBoxData = sandboxInfo
  1719. }
  1720. //解析逻辑图的指标
  1721. _ = data.SaveSandBoxEdbInfoRelation(sandBoxData.SandboxId, sandBoxData.Content)
  1722. msg := "保存成功"
  1723. br.Ret = 200
  1724. br.Success = true
  1725. br.Msg = msg
  1726. br.Data = sandboxResp
  1727. }
  1728. // Delete
  1729. // @Title 删除沙盘
  1730. // @Description 删除沙盘接口
  1731. // @Param request body request.DeleteSandbox true "type json string"
  1732. // @Success 200 标记成功
  1733. // @router /deleteV2 [post]
  1734. func (this *SandboxController) DeleteV2() {
  1735. br := new(models.BaseResponse).Init()
  1736. defer func() {
  1737. this.Data["json"] = br
  1738. this.ServeJSON()
  1739. }()
  1740. sysUser := this.SysUser
  1741. if sysUser == nil {
  1742. br.Msg = "请登录"
  1743. br.ErrMsg = "请登录,SysUser Is Empty"
  1744. br.Ret = 408
  1745. return
  1746. }
  1747. var req request.DeleteSandbox
  1748. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1749. if err != nil {
  1750. br.Msg = "参数解析异常!"
  1751. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1752. return
  1753. }
  1754. if req.SandboxId <= 0 {
  1755. br.Msg = "缺少沙盘编号"
  1756. return
  1757. }
  1758. //删除沙盘
  1759. err = sandboxService.DeleteSandbox(req.SandboxId)
  1760. if err != nil {
  1761. br.Msg = err.Error()
  1762. return
  1763. }
  1764. msg := "删除成功"
  1765. br.Ret = 200
  1766. br.Success = true
  1767. br.Msg = msg
  1768. }
  1769. // GetSandboxVersionDetail
  1770. // @Title 获取沙盘版本数据详情(已保存的)
  1771. // @Description 获取沙盘版本数据详情接口(已保存的)
  1772. // @Param SandboxVersionCode query string true "沙盘版本code"
  1773. // @Success 200 {object} sandbox.SandboxVersion
  1774. // @router /detail [get]
  1775. func (this *SandboxController) GetSandboxDetail() {
  1776. br := new(models.BaseResponse).Init()
  1777. defer func() {
  1778. this.Data["json"] = br
  1779. this.ServeJSON()
  1780. }()
  1781. sysUser := this.SysUser
  1782. if sysUser == nil {
  1783. br.Msg = "请登录"
  1784. br.ErrMsg = "请登录,SysUser Is Empty"
  1785. br.Ret = 408
  1786. return
  1787. }
  1788. sandboxId, _ := this.GetInt("SandboxId")
  1789. if sandboxId == 0 {
  1790. br.Msg = "缺少沙盘Id"
  1791. return
  1792. }
  1793. //获取沙盘数据详情(已保存的)
  1794. sandboxInfo, err := sandbox.GetSandboxById(sandboxId)
  1795. if err != nil {
  1796. br.Msg = "获取失败"
  1797. br.ErrMsg = "获取失败,Err:" + err.Error()
  1798. return
  1799. }
  1800. msg := "获取成功"
  1801. br.Ret = 200
  1802. br.Success = true
  1803. br.Msg = msg
  1804. br.Data = sandboxInfo
  1805. }
  1806. //// SandboxClassifyItems
  1807. //// @Title 获取所有沙盘分类接口-包含沙盘-先分类后沙盘区分,暂时弃用
  1808. //// @Description 获取所有沙盘分类接口-包含沙盘
  1809. //// @Param IsShowMe query bool true "是否只看我的,true、false"
  1810. //// @Success 200 {object} data_manage.ChartClassifyListResp
  1811. //// @router /classify/list [get]
  1812. //func (this *SandboxController) SandboxClassifyItems() {
  1813. // br := new(models.BaseResponse).Init()
  1814. // defer func() {
  1815. // this.Data["json"] = br
  1816. // this.ServeJSON()
  1817. // }()
  1818. //
  1819. // resp := new(sandbox.SandboxClassifyListResp)
  1820. // sandboxClassifyId, _ := this.GetInt("SandboxClassifyId")
  1821. //
  1822. // isShowMe, _ := this.GetBool("IsShowMe")
  1823. // if isShowMe {
  1824. // errMsg, err := sandboxService.GetSandboxClassifyListForMe(*this.SysUser, resp, sandboxClassifyId)
  1825. // if err != nil {
  1826. // br.Msg = errMsg
  1827. // br.ErrMsg = err.Error()
  1828. // return
  1829. // }
  1830. // // 移除没有权限的图表
  1831. // //allNodes := sandboxService.HandleNoPermissionSandbox(resp.AllNodes, nil)
  1832. // //resp.AllNodes = allNodes
  1833. //
  1834. // br.Ret = 200
  1835. // br.Success = true
  1836. // br.Msg = "获取成功"
  1837. // br.Data = resp
  1838. // fmt.Println("source my classify")
  1839. // return
  1840. // }
  1841. //
  1842. // rootList, err := sandbox.GetSandboxClassifyByParentId(sandboxClassifyId)
  1843. // if err != nil && err.Error() != utils.ErrNoRow() {
  1844. // br.Msg = "获取失败"
  1845. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1846. // return
  1847. // }
  1848. //
  1849. // classifyAll, err := sandbox.GetSandboxClassifyByParentId(sandboxClassifyId)
  1850. // if err != nil && err.Error() != utils.ErrNoRow() {
  1851. // br.Msg = "获取失败"
  1852. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1853. // return
  1854. // }
  1855. //
  1856. // sandboxAll, err := sandbox.GetSandboxItemsByClassifyId(sandboxClassifyId)
  1857. // if err != nil && err.Error() != utils.ErrNoRow() {
  1858. // br.Msg = "获取失败"
  1859. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1860. // return
  1861. // }
  1862. //
  1863. // sandListMap := make(map[int][]*sandbox.SandboxClassifyItems)
  1864. // for _, v := range sandboxAll {
  1865. // if _, ok := sandListMap[v.SandboxClassifyId]; !ok {
  1866. // list := make([]*sandbox.SandboxClassifyItems, 0)
  1867. // list = append(list, v)
  1868. // sandListMap[v.SandboxClassifyId] = list
  1869. // } else {
  1870. // sandListMap[v.SandboxClassifyId] = append(sandListMap[v.SandboxClassifyId], v)
  1871. // }
  1872. // }
  1873. //
  1874. // nodeAll := make([]*sandbox.SandboxClassifyItems, 0)
  1875. // for k := range rootList {
  1876. // rootNode := rootList[k]
  1877. // sandboxService.SandboxClassifyItemsMakeTree(this.SysUser, classifyAll, rootNode)
  1878. // nodeAll = append(nodeAll, rootNode)
  1879. // }
  1880. // //for k := range nodeAll {
  1881. // //
  1882. // //}
  1883. // newAll := sandboxService.SandboxItemsMakeTree(nodeAll, sandListMap, sandboxClassifyId)
  1884. //
  1885. // resp.AllNodes = newAll
  1886. // br.Ret = 200
  1887. // br.Success = true
  1888. // br.Msg = "获取成功"
  1889. // br.Data = resp
  1890. //}
  1891. //// SandboxMove
  1892. //// @Title 移动沙盘接口
  1893. //// @Description 移动图表接口
  1894. //// @Success 200 {object} data_manage.MoveChartInfoReq
  1895. //// @router /move [post]
  1896. //func (this *SandboxController) SandboxMove() {
  1897. // br := new(models.BaseResponse).Init()
  1898. // defer func() {
  1899. // this.Data["json"] = br
  1900. // this.ServeJSON()
  1901. // }()
  1902. //
  1903. // sysUser := this.SysUser
  1904. // if sysUser == nil {
  1905. // br.Msg = "请登录"
  1906. // br.ErrMsg = "请登录,SysUser Is Empty"
  1907. // br.Ret = 408
  1908. // return
  1909. // }
  1910. //
  1911. // var req sandbox.MoveSandboxReq
  1912. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1913. // if err != nil {
  1914. // br.Msg = "参数解析异常!"
  1915. // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1916. // return
  1917. // }
  1918. //
  1919. // if req.SandboxId <= 0 {
  1920. // br.Msg = "参数错误"
  1921. // br.ErrMsg = "沙盘id小于等于0"
  1922. // return
  1923. // }
  1924. //
  1925. // if req.SandboxClassifyId <= 0 {
  1926. // br.Msg = "请选择分类"
  1927. // return
  1928. // }
  1929. // //判断分类是否存在
  1930. // count, _ := sandbox.GetSandboxClassifyCountById(req.SandboxClassifyId)
  1931. // if count <= 0 {
  1932. // br.Msg = "分类已被删除,不可移动,请刷新页面"
  1933. // return
  1934. // }
  1935. //
  1936. // sandboxInfo, err := sandbox.GetSandboxById(req.SandboxId)
  1937. // if err != nil {
  1938. // br.Msg = "移动失败"
  1939. // br.ErrMsg = "获取沙盘信息失败,Err:" + err.Error()
  1940. // return
  1941. // }
  1942. //
  1943. // //如果改变了分类,那么移动该图表数据
  1944. // if sandboxInfo.SandboxClassifyId != req.SandboxClassifyId {
  1945. // //查询需要修改的分类下是否存在同一个图表名称
  1946. // tmpSandboxInfo, tmpErr := sandbox.GetSandboxByClassifyIdAndName(req.SandboxClassifyId, sandboxInfo.Name)
  1947. // if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  1948. // br.Msg = "移动失败"
  1949. // br.ErrMsg = "移动失败,Err:" + tmpErr.Error()
  1950. // return
  1951. // }
  1952. // if tmpSandboxInfo != nil {
  1953. // br.Msg = "移动失败,同一个分类下沙盘名称不允许重复"
  1954. // br.ErrMsg = "移动失败,同一个分类下沙盘名称不允许重复"
  1955. // return
  1956. // }
  1957. // err = sandbox.MoveSandbox(req.SandboxId, req.SandboxClassifyId)
  1958. // if err != nil {
  1959. // br.Msg = "移动失败"
  1960. // br.ErrMsg = "移动失败,Err:" + err.Error()
  1961. // return
  1962. // }
  1963. // }
  1964. //
  1965. // //移动排序
  1966. // updateCol := make([]string, 0)
  1967. // //如果有传入 上一个兄弟节点分类id
  1968. // if req.PrevSandboxId > 0 {
  1969. // prevChartInfo, err := sandbox.GetSandboxById(req.PrevSandboxId)
  1970. // if err != nil {
  1971. // br.Msg = "移动失败"
  1972. // br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  1973. // return
  1974. // }
  1975. //
  1976. // //如果是移动在两个兄弟节点之间
  1977. // if req.NextSandboxId > 0 {
  1978. // //下一个兄弟节点
  1979. // nextChartInfo, err := sandbox.GetSandboxById(req.NextSandboxId)
  1980. // if err != nil {
  1981. // br.Msg = "移动失败"
  1982. // br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  1983. // return
  1984. // }
  1985. // //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  1986. // if prevChartInfo.Sort == nextChartInfo.Sort || prevChartInfo.Sort == sandboxInfo.Sort {
  1987. // //变更兄弟节点的排序
  1988. // updateSortStr := `sort + 2`
  1989. // _ = sandbox.UpdateSandboxSortByClassifyId(prevChartInfo.SandboxClassifyId, prevChartInfo.Sort, prevChartInfo.SandboxId, updateSortStr)
  1990. // } else {
  1991. // //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  1992. // if nextChartInfo.Sort-prevChartInfo.Sort == 1 {
  1993. // //变更兄弟节点的排序
  1994. // updateSortStr := `sort + 1`
  1995. // _ = sandbox.UpdateSandboxSortByClassifyId(prevChartInfo.SandboxClassifyId, prevChartInfo.Sort, prevChartInfo.SandboxId, updateSortStr)
  1996. // }
  1997. // }
  1998. // }
  1999. //
  2000. // sandboxInfo.Sort = prevChartInfo.Sort + 1
  2001. // sandboxInfo.ModifyTime = time.Now()
  2002. // updateCol = append(updateCol, "Sort", "ModifyTime")
  2003. //
  2004. // } else {
  2005. // firstClassify, err := sandbox.GetFirstSandboxByClassifyId(req.SandboxClassifyId)
  2006. // if err != nil && err.Error() != utils.ErrNoRow() {
  2007. // br.Msg = "移动失败"
  2008. // br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  2009. // return
  2010. // }
  2011. //
  2012. // //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  2013. // if firstClassify != nil && firstClassify.Sort == 0 {
  2014. // updateSortStr := ` sort + 1 `
  2015. // _ = sandbox.UpdateSandboxSortByClassifyId(firstClassify.SandboxClassifyId, 0, firstClassify.SandboxId-1, updateSortStr)
  2016. // }
  2017. //
  2018. // sandboxInfo.Sort = 0 //那就是排在第一位
  2019. // sandboxInfo.ModifyTime = time.Now()
  2020. // updateCol = append(updateCol, "Sort", "ModifyTime")
  2021. // }
  2022. //
  2023. // //更新
  2024. // if len(updateCol) > 0 {
  2025. // err = sandboxInfo.Update(updateCol)
  2026. // if err != nil {
  2027. // br.Msg = "移动失败"
  2028. // br.ErrMsg = "修改失败,Err:" + err.Error()
  2029. // return
  2030. // }
  2031. // }
  2032. //
  2033. // if err != nil {
  2034. // br.Msg = "移动失败"
  2035. // br.ErrMsg = "修改失败,Err:" + err.Error()
  2036. // return
  2037. // }
  2038. //
  2039. // br.Ret = 200
  2040. // br.Success = true
  2041. // br.Msg = "移动成功"
  2042. //}
  2043. //// ChartClassifyMove
  2044. //// @Title 沙盘分类移动接口
  2045. //// @Description 沙盘分类移动接口
  2046. //// @Success 200 {object} data_manage.MoveChartClassifyReq
  2047. //// @router /classify/move [post]
  2048. //func (this *SandboxController) ChartClassifyMove() {
  2049. // br := new(models.BaseResponse).Init()
  2050. // defer func() {
  2051. // this.Data["json"] = br
  2052. // this.ServeJSON()
  2053. // }()
  2054. //
  2055. // sysUser := this.SysUser
  2056. // if sysUser == nil {
  2057. // br.Msg = "请登录"
  2058. // br.ErrMsg = "请登录,SysUser Is Empty"
  2059. // br.Ret = 408
  2060. // return
  2061. // }
  2062. //
  2063. // var req sandbox.MoveSandboxClassifyReq
  2064. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2065. // if err != nil {
  2066. // br.Msg = "参数解析异常!"
  2067. // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2068. // return
  2069. // }
  2070. //
  2071. // if req.ClassifyId <= 0 {
  2072. // br.Msg = "参数错误"
  2073. // br.ErrMsg = "分类id小于等于0"
  2074. // return
  2075. // }
  2076. // //判断分类是否存在
  2077. // sandboxClassifyInfo, err := sandbox.GetSandboxClassifyById(req.ClassifyId)
  2078. // if err != nil {
  2079. // br.Msg = "移动失败"
  2080. // br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  2081. // return
  2082. // }
  2083. //
  2084. // updateCol := make([]string, 0)
  2085. //
  2086. // //判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
  2087. // if sandboxClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId != 0 {
  2088. // parentChartClassifyInfo, err := sandbox.GetSandboxClassifyById(req.ParentClassifyId)
  2089. // if err != nil {
  2090. // br.Msg = "移动失败"
  2091. // br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error()
  2092. // return
  2093. // }
  2094. // sandboxClassifyInfo.ParentId = parentChartClassifyInfo.SandboxClassifyId
  2095. // sandboxClassifyInfo.Level = parentChartClassifyInfo.Level + 1
  2096. // sandboxClassifyInfo.ModifyTime = time.Now()
  2097. // updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  2098. // } else if sandboxClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId == 0 {
  2099. // //改为一级分类
  2100. // sandboxClassifyInfo.ParentId = req.ParentClassifyId
  2101. // sandboxClassifyInfo.Level = 1
  2102. // sandboxClassifyInfo.ModifyTime = time.Now()
  2103. // updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  2104. // }
  2105. //
  2106. // //如果有传入 上一个兄弟节点分类id
  2107. // if req.PrevClassifyId > 0 {
  2108. // //上一个兄弟节点
  2109. // prevClassify, err := sandbox.GetSandboxClassifyById(req.PrevClassifyId)
  2110. // if err != nil {
  2111. // br.Msg = "移动失败"
  2112. // br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  2113. // return
  2114. // }
  2115. //
  2116. // //如果是移动在两个兄弟节点之间
  2117. // if req.NextClassifyId > 0 {
  2118. // //下一个兄弟节点
  2119. // nextClassify, err := sandbox.GetSandboxClassifyById(req.NextClassifyId)
  2120. // if err != nil {
  2121. // br.Msg = "移动失败"
  2122. // br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  2123. // return
  2124. // }
  2125. // //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  2126. // if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == sandboxClassifyInfo.Sort {
  2127. // //变更兄弟节点的排序
  2128. // updateSortStr := `sort + 2`
  2129. // _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, prevClassify.SandboxClassifyId, prevClassify.Sort, updateSortStr)
  2130. // } else {
  2131. // //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  2132. // if nextClassify.Sort-prevClassify.Sort == 1 {
  2133. // //变更兄弟节点的排序
  2134. // updateSortStr := `sort + 1`
  2135. // _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr)
  2136. // }
  2137. // }
  2138. // }
  2139. //
  2140. // sandboxClassifyInfo.Sort = prevClassify.Sort + 1
  2141. // sandboxClassifyInfo.ModifyTime = time.Now()
  2142. // updateCol = append(updateCol, "Sort", "ModifyTime")
  2143. //
  2144. // } else {
  2145. // firstClassify, err := sandbox.GetFirstSandboxClassifyByParentId(sandboxClassifyInfo.ParentId)
  2146. // if err != nil && err.Error() != utils.ErrNoRow() {
  2147. // br.Msg = "移动失败"
  2148. // br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  2149. // return
  2150. // }
  2151. //
  2152. // //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  2153. // if firstClassify != nil && firstClassify.Sort == 0 {
  2154. // updateSortStr := ` sort + 1 `
  2155. // _ = sandbox.UpdateSandboxClassifySortByParentId(firstClassify.ParentId, firstClassify.SandboxClassifyId-1, 0, updateSortStr)
  2156. // }
  2157. //
  2158. // sandboxClassifyInfo.Sort = 0 //那就是排在第一位
  2159. // sandboxClassifyInfo.ModifyTime = time.Now()
  2160. // updateCol = append(updateCol, "Sort", "ModifyTime")
  2161. // }
  2162. //
  2163. // //更新
  2164. // if len(updateCol) > 0 {
  2165. // err = sandboxClassifyInfo.Update(updateCol)
  2166. // if err != nil {
  2167. // br.Msg = "移动失败"
  2168. // br.ErrMsg = "修改失败,Err:" + err.Error()
  2169. // return
  2170. // }
  2171. // }
  2172. // br.Ret = 200
  2173. // br.Success = true
  2174. // br.Msg = "移动成功"
  2175. //}
  2176. // SandboxClassifyItems
  2177. // @Title 获取所有沙盘分类接口-不包含沙盘
  2178. // @Description 获取所有沙盘分类接口-不包含沙盘
  2179. // @Param IsShowMe query bool true "是否只看我的,true、false"
  2180. // @Success 200 {object} data_manage.ChartClassifyListResp
  2181. // @router /classifyList [get]
  2182. func (this *SandboxController) SandboxClassifyList() {
  2183. br := new(models.BaseResponse).Init()
  2184. defer func() {
  2185. this.Data["json"] = br
  2186. this.ServeJSON()
  2187. }()
  2188. resp := new(sandbox.SandboxClassifyListResp)
  2189. rootList, err := sandbox.GetSandboxClassifyByParentId(0)
  2190. if err != nil && err.Error() != utils.ErrNoRow() {
  2191. br.Msg = "获取失败"
  2192. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  2193. return
  2194. }
  2195. classifyAll, err := sandbox.GetSandboxClassifyAll()
  2196. if err != nil && err.Error() != utils.ErrNoRow() {
  2197. br.Msg = "获取失败"
  2198. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  2199. return
  2200. }
  2201. nodeAll := make([]*sandbox.SandboxClassifyItems, 0)
  2202. for k := range rootList {
  2203. rootNode := rootList[k]
  2204. sandboxService.SandboxClassifyItemsMakeTree(this.SysUser, classifyAll, rootNode)
  2205. nodeAll = append(nodeAll, rootNode)
  2206. }
  2207. resp.AllNodes = nodeAll
  2208. br.Ret = 200
  2209. br.Success = true
  2210. br.Msg = "获取成功"
  2211. br.Data = resp
  2212. }
  2213. // @Title 链接指标检测
  2214. // @Description 链接指标检测接口
  2215. // @Param request body data_manage.ChartClassifyDeleteCheckResp true "type json string"
  2216. // @Success 200 Ret=200 检测成功
  2217. // @router /link/check [post]
  2218. func (this *SandboxController) LinkEdbInfoCheck() {
  2219. br := new(models.BaseResponse).Init()
  2220. defer func() {
  2221. this.Data["json"] = br
  2222. this.ServeJSON()
  2223. }()
  2224. var req sandbox.SandboxLinkCheckReq
  2225. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2226. if err != nil {
  2227. br.Msg = "参数解析异常!"
  2228. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2229. return
  2230. }
  2231. resp := new(sandbox.SandboxLinkCheckResp)
  2232. edbInfoList, err := data_manage.GetEdbInfoByIdList(req.EdbInfoIdList)
  2233. if err != nil {
  2234. br.Msg = "获取指标信息失败"
  2235. br.ErrMsg = "获取指标信息失败,err:" + err.Error()
  2236. return
  2237. }
  2238. edbList := make([]*sandbox.SandboxLinkCheckItem, 0)
  2239. for _, id := range req.EdbInfoIdList {
  2240. for _, v := range edbInfoList {
  2241. if v.EdbInfoId == id {
  2242. tmp := &sandbox.SandboxLinkCheckItem{
  2243. Id: v.EdbInfoId,
  2244. Name: v.EdbName,
  2245. UniqueCode: v.UniqueCode,
  2246. ClassifyId: v.ClassifyId,
  2247. }
  2248. edbList = append(edbList, tmp)
  2249. }
  2250. }
  2251. }
  2252. chartList, err := data_manage.GetChartInfoByIdList(req.ChartInfoIdList)
  2253. if err != nil {
  2254. br.Msg = `获取失败`
  2255. br.ErrMsg = `获取图表列表失败,ERR:` + err.Error()
  2256. return
  2257. }
  2258. chartListTmp := make([]*sandbox.SandboxLinkCheckItem, 0)
  2259. for _, id := range req.ChartInfoIdList {
  2260. for _, v := range chartList {
  2261. if v.ChartInfoId == id {
  2262. tmp := &sandbox.SandboxLinkCheckItem{
  2263. Id: v.ChartInfoId,
  2264. Name: v.ChartName,
  2265. UniqueCode: v.UniqueCode,
  2266. ClassifyId: v.ChartClassifyId,
  2267. }
  2268. chartListTmp = append(chartListTmp, tmp)
  2269. }
  2270. }
  2271. }
  2272. reportList, err := models.GetSimpleReportByIds(req.ReportIdList)
  2273. if err != nil {
  2274. br.Msg = `获取失败`
  2275. br.ErrMsg = `获取报告列表失败,ERR:` + err.Error()
  2276. return
  2277. }
  2278. reportListTmp := make([]*sandbox.SandboxLinkCheckItem, 0)
  2279. for _, id := range req.ReportIdList {
  2280. for _, v := range reportList {
  2281. if v.Id == id {
  2282. tmp := &sandbox.SandboxLinkCheckItem{
  2283. Id: v.Id,
  2284. Name: v.Title,
  2285. UniqueCode: v.ReportCode,
  2286. }
  2287. reportListTmp = append(reportListTmp, tmp)
  2288. }
  2289. }
  2290. }
  2291. resp.EdbInfoIdList = edbList
  2292. resp.ChartInfoIdList = chartListTmp
  2293. resp.ReportIdList = reportListTmp
  2294. br.Ret = 200
  2295. br.Msg = "检测成功"
  2296. br.Success = true
  2297. br.Data = resp
  2298. }