sandbox.go 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437
  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. "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 && 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. 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 && err.Error() != utils.ErrNoRow() {
  800. br.Msg = "获取失败"
  801. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  802. return
  803. }
  804. classifyAll, err := sandbox.GetSandboxClassifyAndInfoByParentId(sandboxClassifyId)
  805. if err != nil && err.Error() != utils.ErrNoRow() {
  806. br.Msg = "获取失败"
  807. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  808. return
  809. }
  810. //sandboxAll, err := sandbox.GetSandboxItemsByClassifyId(sandboxClassifyId)
  811. //if err != nil && err.Error() != utils.ErrNoRow() {
  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 && err.Error() != utils.ErrNoRow() {
  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 && err.Error() != utils.ErrNoRow() {
  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 err.Error() == utils.ErrNoRow() {
  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 && tmpErr.Error() != utils.ErrNoRow() {
  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 && err.Error() != utils.ErrNoRow() {
  1320. br.Msg = "移动失败"
  1321. br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  1322. return
  1323. }
  1324. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  1325. if firstClassify != nil && 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 && err.Error() != utils.ErrNoRow() {
  1496. br.Msg = "移动失败"
  1497. br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  1498. return
  1499. }
  1500. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  1501. if firstClassify != nil && 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. var condition string
  1580. var pars []interface{}
  1581. if sandboxClassifyId > 0 {
  1582. sandboxClassifyId, err := sandbox.GetSandboxClassify(sandboxClassifyId)
  1583. if err != nil && err.Error() != utils.ErrNoRow() {
  1584. br.Msg = "获取图表信息失败"
  1585. br.ErrMsg = "获取信息失败,GetChartClassify,Err:" + err.Error()
  1586. return
  1587. }
  1588. condition += " AND sandbox_classify_id IN(" + sandboxClassifyId + ") "
  1589. //pars = append(pars, chartClassifyId)
  1590. }
  1591. if keyWord != "" {
  1592. condition += ` AND ( name LIKE '%` + keyWord + `%' )`
  1593. }
  1594. //只看我的
  1595. isShowMe, _ := this.GetBool("IsShowMe")
  1596. if isShowMe {
  1597. condition += ` AND sys_user_id = ? `
  1598. pars = append(pars, sysUser.AdminId)
  1599. }
  1600. //获取图表信息
  1601. condition += ` AND is_delete = 0 `
  1602. list, err := sandbox.GetSandboxListByCondition(condition, pars, startSize, pageSize)
  1603. if err != nil && err.Error() != utils.ErrNoRow() {
  1604. br.Success = true
  1605. br.Msg = "获取沙盘信息失败"
  1606. br.ErrMsg = "获取沙盘信息失败,Err:" + err.Error()
  1607. return
  1608. }
  1609. for i, v := range list {
  1610. ids, err := sandbox.GetSandboxAllParentByClassifyId(v.SandboxClassifyId)
  1611. if err != nil {
  1612. br.Msg = "获取父级信息错误!"
  1613. br.ErrMsg = "获取父级信息错误,Err:" + err.Error()
  1614. return
  1615. }
  1616. list[i].ParentIds = ids
  1617. }
  1618. resp := new(sandbox.SandboxListResp)
  1619. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  1620. items := make([]*sandbox.SandboxListItems, 0)
  1621. resp.Paging = page
  1622. resp.List = items
  1623. br.Ret = 200
  1624. br.Success = true
  1625. br.Msg = "获取成功"
  1626. return
  1627. }
  1628. dataCount, err := sandbox.GetSandboxListCountByCondition(condition, pars)
  1629. if err != nil && err.Error() != utils.ErrNoRow() {
  1630. br.Msg = "获取指标信息失败"
  1631. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  1632. return
  1633. }
  1634. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  1635. resp.Paging = page
  1636. resp.List = list
  1637. br.Ret = 200
  1638. br.Success = true
  1639. br.Msg = "获取成功"
  1640. br.Data = resp
  1641. }
  1642. // Save
  1643. // @Title 新增/编辑保存沙盘
  1644. // @Description 新增/编辑保存沙盘接口
  1645. // @Param request body request.AddAndEditSandbox true "type json string"
  1646. // @Success 200 {object} sandbox.Sandbox
  1647. // @router /saveV2 [post]
  1648. func (this *SandboxController) SaveV2() {
  1649. br := new(models.BaseResponse).Init()
  1650. defer func() {
  1651. this.Data["json"] = br
  1652. this.ServeJSON()
  1653. }()
  1654. sysUser := this.SysUser
  1655. if sysUser == nil {
  1656. br.Msg = "请登录"
  1657. br.ErrMsg = "请登录,SysUser Is Empty"
  1658. br.Ret = 408
  1659. return
  1660. }
  1661. var req request.AddAndEditSandboxV2
  1662. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1663. if err != nil {
  1664. br.Msg = "参数解析异常!"
  1665. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1666. return
  1667. }
  1668. var sandboxResp *sandbox.SandboxSaveResp
  1669. var errMsg string
  1670. var sandBoxData *sandbox.Sandbox
  1671. if req.SandboxId <= 0 {
  1672. //新增沙盘
  1673. sandboxResp, err = sandboxService.AddSandboxV2(req, sysUser.AdminId, sysUser.RealName)
  1674. if err != nil {
  1675. br.Msg = "保存失败!"
  1676. if errMsg != `` {
  1677. br.Msg = errMsg
  1678. }
  1679. br.ErrMsg = "保存失败,Err:" + err.Error()
  1680. return
  1681. }
  1682. sandBoxData = sandboxResp.Sandbox
  1683. } else {
  1684. //编辑沙盘
  1685. sandboxInfo := &sandbox.Sandbox{
  1686. SandboxId: req.SandboxId,
  1687. Name: utils.TrimStr(req.Name),
  1688. Content: req.Content,
  1689. MindmapData: req.MindmapData,
  1690. PicUrl: utils.TrimStr(req.PicUrl),
  1691. ModifyTime: time.Now(),
  1692. SandboxClassifyId: req.SandboxClassifyId,
  1693. Style: req.Style,
  1694. }
  1695. //缩略图为空时不更新
  1696. var updateSandboxColumn = []string{}
  1697. if req.PicUrl == "" {
  1698. updateSandboxColumn = []string{"Name", "Content", "MindmapData", "ModifyTime", "SandboxClassifyId", "Style"}
  1699. } else {
  1700. updateSandboxColumn = []string{"Name", "Content", "MindmapData", "PicUrl", "ModifyTime", "SandboxClassifyId", "Style"}
  1701. }
  1702. err = sandboxInfo.Update(updateSandboxColumn)
  1703. if err != nil {
  1704. br.Msg = "保存失败!"
  1705. if errMsg != `` {
  1706. br.Msg = errMsg
  1707. }
  1708. br.ErrMsg = "保存失败,Err:" + err.Error()
  1709. return
  1710. }
  1711. sandBoxData = sandboxInfo
  1712. }
  1713. //解析逻辑图的指标
  1714. _ = data.SaveSandBoxEdbInfoRelation(sandBoxData.SandboxId, sandBoxData.Content)
  1715. msg := "保存成功"
  1716. br.Ret = 200
  1717. br.Success = true
  1718. br.Msg = msg
  1719. br.Data = sandboxResp
  1720. }
  1721. // Delete
  1722. // @Title 删除沙盘
  1723. // @Description 删除沙盘接口
  1724. // @Param request body request.DeleteSandbox true "type json string"
  1725. // @Success 200 标记成功
  1726. // @router /deleteV2 [post]
  1727. func (this *SandboxController) DeleteV2() {
  1728. br := new(models.BaseResponse).Init()
  1729. defer func() {
  1730. this.Data["json"] = br
  1731. this.ServeJSON()
  1732. }()
  1733. sysUser := this.SysUser
  1734. if sysUser == nil {
  1735. br.Msg = "请登录"
  1736. br.ErrMsg = "请登录,SysUser Is Empty"
  1737. br.Ret = 408
  1738. return
  1739. }
  1740. var req request.DeleteSandbox
  1741. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1742. if err != nil {
  1743. br.Msg = "参数解析异常!"
  1744. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1745. return
  1746. }
  1747. if req.SandboxId <= 0 {
  1748. br.Msg = "缺少沙盘编号"
  1749. return
  1750. }
  1751. //删除沙盘
  1752. err = sandboxService.DeleteSandbox(req.SandboxId)
  1753. if err != nil {
  1754. br.Msg = err.Error()
  1755. return
  1756. }
  1757. msg := "删除成功"
  1758. br.Ret = 200
  1759. br.Success = true
  1760. br.Msg = msg
  1761. }
  1762. // GetSandboxVersionDetail
  1763. // @Title 获取沙盘版本数据详情(已保存的)
  1764. // @Description 获取沙盘版本数据详情接口(已保存的)
  1765. // @Param SandboxVersionCode query string true "沙盘版本code"
  1766. // @Success 200 {object} sandbox.SandboxVersion
  1767. // @router /detail [get]
  1768. func (this *SandboxController) GetSandboxDetail() {
  1769. br := new(models.BaseResponse).Init()
  1770. defer func() {
  1771. this.Data["json"] = br
  1772. this.ServeJSON()
  1773. }()
  1774. sysUser := this.SysUser
  1775. if sysUser == nil {
  1776. br.Msg = "请登录"
  1777. br.ErrMsg = "请登录,SysUser Is Empty"
  1778. br.Ret = 408
  1779. return
  1780. }
  1781. sandboxId, _ := this.GetInt("SandboxId")
  1782. if sandboxId == 0 {
  1783. br.Msg = "缺少沙盘Id"
  1784. return
  1785. }
  1786. //获取沙盘数据详情(已保存的)
  1787. sandboxInfo, err := sandbox.GetSandboxById(sandboxId)
  1788. if err != nil {
  1789. br.Msg = "获取失败"
  1790. br.ErrMsg = "获取失败,Err:" + err.Error()
  1791. return
  1792. }
  1793. msg := "获取成功"
  1794. br.Ret = 200
  1795. br.Success = true
  1796. br.Msg = msg
  1797. br.Data = sandboxInfo
  1798. }
  1799. //// SandboxClassifyItems
  1800. //// @Title 获取所有沙盘分类接口-包含沙盘-先分类后沙盘区分,暂时弃用
  1801. //// @Description 获取所有沙盘分类接口-包含沙盘
  1802. //// @Param IsShowMe query bool true "是否只看我的,true、false"
  1803. //// @Success 200 {object} data_manage.ChartClassifyListResp
  1804. //// @router /classify/list [get]
  1805. //func (this *SandboxController) SandboxClassifyItems() {
  1806. // br := new(models.BaseResponse).Init()
  1807. // defer func() {
  1808. // this.Data["json"] = br
  1809. // this.ServeJSON()
  1810. // }()
  1811. //
  1812. // resp := new(sandbox.SandboxClassifyListResp)
  1813. // sandboxClassifyId, _ := this.GetInt("SandboxClassifyId")
  1814. //
  1815. // isShowMe, _ := this.GetBool("IsShowMe")
  1816. // if isShowMe {
  1817. // errMsg, err := sandboxService.GetSandboxClassifyListForMe(*this.SysUser, resp, sandboxClassifyId)
  1818. // if err != nil {
  1819. // br.Msg = errMsg
  1820. // br.ErrMsg = err.Error()
  1821. // return
  1822. // }
  1823. // // 移除没有权限的图表
  1824. // //allNodes := sandboxService.HandleNoPermissionSandbox(resp.AllNodes, nil)
  1825. // //resp.AllNodes = allNodes
  1826. //
  1827. // br.Ret = 200
  1828. // br.Success = true
  1829. // br.Msg = "获取成功"
  1830. // br.Data = resp
  1831. // fmt.Println("source my classify")
  1832. // return
  1833. // }
  1834. //
  1835. // rootList, err := sandbox.GetSandboxClassifyByParentId(sandboxClassifyId)
  1836. // if err != nil && err.Error() != utils.ErrNoRow() {
  1837. // br.Msg = "获取失败"
  1838. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1839. // return
  1840. // }
  1841. //
  1842. // classifyAll, 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. // sandboxAll, err := sandbox.GetSandboxItemsByClassifyId(sandboxClassifyId)
  1850. // if err != nil && err.Error() != utils.ErrNoRow() {
  1851. // br.Msg = "获取失败"
  1852. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1853. // return
  1854. // }
  1855. //
  1856. // sandListMap := make(map[int][]*sandbox.SandboxClassifyItems)
  1857. // for _, v := range sandboxAll {
  1858. // if _, ok := sandListMap[v.SandboxClassifyId]; !ok {
  1859. // list := make([]*sandbox.SandboxClassifyItems, 0)
  1860. // list = append(list, v)
  1861. // sandListMap[v.SandboxClassifyId] = list
  1862. // } else {
  1863. // sandListMap[v.SandboxClassifyId] = append(sandListMap[v.SandboxClassifyId], v)
  1864. // }
  1865. // }
  1866. //
  1867. // nodeAll := make([]*sandbox.SandboxClassifyItems, 0)
  1868. // for k := range rootList {
  1869. // rootNode := rootList[k]
  1870. // sandboxService.SandboxClassifyItemsMakeTree(this.SysUser, classifyAll, rootNode)
  1871. // nodeAll = append(nodeAll, rootNode)
  1872. // }
  1873. // //for k := range nodeAll {
  1874. // //
  1875. // //}
  1876. // newAll := sandboxService.SandboxItemsMakeTree(nodeAll, sandListMap, sandboxClassifyId)
  1877. //
  1878. // resp.AllNodes = newAll
  1879. // br.Ret = 200
  1880. // br.Success = true
  1881. // br.Msg = "获取成功"
  1882. // br.Data = resp
  1883. //}
  1884. //// SandboxMove
  1885. //// @Title 移动沙盘接口
  1886. //// @Description 移动图表接口
  1887. //// @Success 200 {object} data_manage.MoveChartInfoReq
  1888. //// @router /move [post]
  1889. //func (this *SandboxController) SandboxMove() {
  1890. // br := new(models.BaseResponse).Init()
  1891. // defer func() {
  1892. // this.Data["json"] = br
  1893. // this.ServeJSON()
  1894. // }()
  1895. //
  1896. // sysUser := this.SysUser
  1897. // if sysUser == nil {
  1898. // br.Msg = "请登录"
  1899. // br.ErrMsg = "请登录,SysUser Is Empty"
  1900. // br.Ret = 408
  1901. // return
  1902. // }
  1903. //
  1904. // var req sandbox.MoveSandboxReq
  1905. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1906. // if err != nil {
  1907. // br.Msg = "参数解析异常!"
  1908. // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1909. // return
  1910. // }
  1911. //
  1912. // if req.SandboxId <= 0 {
  1913. // br.Msg = "参数错误"
  1914. // br.ErrMsg = "沙盘id小于等于0"
  1915. // return
  1916. // }
  1917. //
  1918. // if req.SandboxClassifyId <= 0 {
  1919. // br.Msg = "请选择分类"
  1920. // return
  1921. // }
  1922. // //判断分类是否存在
  1923. // count, _ := sandbox.GetSandboxClassifyCountById(req.SandboxClassifyId)
  1924. // if count <= 0 {
  1925. // br.Msg = "分类已被删除,不可移动,请刷新页面"
  1926. // return
  1927. // }
  1928. //
  1929. // sandboxInfo, err := sandbox.GetSandboxById(req.SandboxId)
  1930. // if err != nil {
  1931. // br.Msg = "移动失败"
  1932. // br.ErrMsg = "获取沙盘信息失败,Err:" + err.Error()
  1933. // return
  1934. // }
  1935. //
  1936. // //如果改变了分类,那么移动该图表数据
  1937. // if sandboxInfo.SandboxClassifyId != req.SandboxClassifyId {
  1938. // //查询需要修改的分类下是否存在同一个图表名称
  1939. // tmpSandboxInfo, tmpErr := sandbox.GetSandboxByClassifyIdAndName(req.SandboxClassifyId, sandboxInfo.Name)
  1940. // if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  1941. // br.Msg = "移动失败"
  1942. // br.ErrMsg = "移动失败,Err:" + tmpErr.Error()
  1943. // return
  1944. // }
  1945. // if tmpSandboxInfo != nil {
  1946. // br.Msg = "移动失败,同一个分类下沙盘名称不允许重复"
  1947. // br.ErrMsg = "移动失败,同一个分类下沙盘名称不允许重复"
  1948. // return
  1949. // }
  1950. // err = sandbox.MoveSandbox(req.SandboxId, req.SandboxClassifyId)
  1951. // if err != nil {
  1952. // br.Msg = "移动失败"
  1953. // br.ErrMsg = "移动失败,Err:" + err.Error()
  1954. // return
  1955. // }
  1956. // }
  1957. //
  1958. // //移动排序
  1959. // updateCol := make([]string, 0)
  1960. // //如果有传入 上一个兄弟节点分类id
  1961. // if req.PrevSandboxId > 0 {
  1962. // prevChartInfo, err := sandbox.GetSandboxById(req.PrevSandboxId)
  1963. // if err != nil {
  1964. // br.Msg = "移动失败"
  1965. // br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  1966. // return
  1967. // }
  1968. //
  1969. // //如果是移动在两个兄弟节点之间
  1970. // if req.NextSandboxId > 0 {
  1971. // //下一个兄弟节点
  1972. // nextChartInfo, err := sandbox.GetSandboxById(req.NextSandboxId)
  1973. // if err != nil {
  1974. // br.Msg = "移动失败"
  1975. // br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  1976. // return
  1977. // }
  1978. // //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  1979. // if prevChartInfo.Sort == nextChartInfo.Sort || prevChartInfo.Sort == sandboxInfo.Sort {
  1980. // //变更兄弟节点的排序
  1981. // updateSortStr := `sort + 2`
  1982. // _ = sandbox.UpdateSandboxSortByClassifyId(prevChartInfo.SandboxClassifyId, prevChartInfo.Sort, prevChartInfo.SandboxId, updateSortStr)
  1983. // } else {
  1984. // //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  1985. // if nextChartInfo.Sort-prevChartInfo.Sort == 1 {
  1986. // //变更兄弟节点的排序
  1987. // updateSortStr := `sort + 1`
  1988. // _ = sandbox.UpdateSandboxSortByClassifyId(prevChartInfo.SandboxClassifyId, prevChartInfo.Sort, prevChartInfo.SandboxId, updateSortStr)
  1989. // }
  1990. // }
  1991. // }
  1992. //
  1993. // sandboxInfo.Sort = prevChartInfo.Sort + 1
  1994. // sandboxInfo.ModifyTime = time.Now()
  1995. // updateCol = append(updateCol, "Sort", "ModifyTime")
  1996. //
  1997. // } else {
  1998. // firstClassify, err := sandbox.GetFirstSandboxByClassifyId(req.SandboxClassifyId)
  1999. // if err != nil && err.Error() != utils.ErrNoRow() {
  2000. // br.Msg = "移动失败"
  2001. // br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  2002. // return
  2003. // }
  2004. //
  2005. // //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  2006. // if firstClassify != nil && firstClassify.Sort == 0 {
  2007. // updateSortStr := ` sort + 1 `
  2008. // _ = sandbox.UpdateSandboxSortByClassifyId(firstClassify.SandboxClassifyId, 0, firstClassify.SandboxId-1, updateSortStr)
  2009. // }
  2010. //
  2011. // sandboxInfo.Sort = 0 //那就是排在第一位
  2012. // sandboxInfo.ModifyTime = time.Now()
  2013. // updateCol = append(updateCol, "Sort", "ModifyTime")
  2014. // }
  2015. //
  2016. // //更新
  2017. // if len(updateCol) > 0 {
  2018. // err = sandboxInfo.Update(updateCol)
  2019. // if err != nil {
  2020. // br.Msg = "移动失败"
  2021. // br.ErrMsg = "修改失败,Err:" + err.Error()
  2022. // return
  2023. // }
  2024. // }
  2025. //
  2026. // if err != nil {
  2027. // br.Msg = "移动失败"
  2028. // br.ErrMsg = "修改失败,Err:" + err.Error()
  2029. // return
  2030. // }
  2031. //
  2032. // br.Ret = 200
  2033. // br.Success = true
  2034. // br.Msg = "移动成功"
  2035. //}
  2036. //// ChartClassifyMove
  2037. //// @Title 沙盘分类移动接口
  2038. //// @Description 沙盘分类移动接口
  2039. //// @Success 200 {object} data_manage.MoveChartClassifyReq
  2040. //// @router /classify/move [post]
  2041. //func (this *SandboxController) ChartClassifyMove() {
  2042. // br := new(models.BaseResponse).Init()
  2043. // defer func() {
  2044. // this.Data["json"] = br
  2045. // this.ServeJSON()
  2046. // }()
  2047. //
  2048. // sysUser := this.SysUser
  2049. // if sysUser == nil {
  2050. // br.Msg = "请登录"
  2051. // br.ErrMsg = "请登录,SysUser Is Empty"
  2052. // br.Ret = 408
  2053. // return
  2054. // }
  2055. //
  2056. // var req sandbox.MoveSandboxClassifyReq
  2057. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2058. // if err != nil {
  2059. // br.Msg = "参数解析异常!"
  2060. // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2061. // return
  2062. // }
  2063. //
  2064. // if req.ClassifyId <= 0 {
  2065. // br.Msg = "参数错误"
  2066. // br.ErrMsg = "分类id小于等于0"
  2067. // return
  2068. // }
  2069. // //判断分类是否存在
  2070. // sandboxClassifyInfo, err := sandbox.GetSandboxClassifyById(req.ClassifyId)
  2071. // if err != nil {
  2072. // br.Msg = "移动失败"
  2073. // br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  2074. // return
  2075. // }
  2076. //
  2077. // updateCol := make([]string, 0)
  2078. //
  2079. // //判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
  2080. // if sandboxClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId != 0 {
  2081. // parentChartClassifyInfo, err := sandbox.GetSandboxClassifyById(req.ParentClassifyId)
  2082. // if err != nil {
  2083. // br.Msg = "移动失败"
  2084. // br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error()
  2085. // return
  2086. // }
  2087. // sandboxClassifyInfo.ParentId = parentChartClassifyInfo.SandboxClassifyId
  2088. // sandboxClassifyInfo.Level = parentChartClassifyInfo.Level + 1
  2089. // sandboxClassifyInfo.ModifyTime = time.Now()
  2090. // updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  2091. // } else if sandboxClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId == 0 {
  2092. // //改为一级分类
  2093. // sandboxClassifyInfo.ParentId = req.ParentClassifyId
  2094. // sandboxClassifyInfo.Level = 1
  2095. // sandboxClassifyInfo.ModifyTime = time.Now()
  2096. // updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  2097. // }
  2098. //
  2099. // //如果有传入 上一个兄弟节点分类id
  2100. // if req.PrevClassifyId > 0 {
  2101. // //上一个兄弟节点
  2102. // prevClassify, err := sandbox.GetSandboxClassifyById(req.PrevClassifyId)
  2103. // if err != nil {
  2104. // br.Msg = "移动失败"
  2105. // br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  2106. // return
  2107. // }
  2108. //
  2109. // //如果是移动在两个兄弟节点之间
  2110. // if req.NextClassifyId > 0 {
  2111. // //下一个兄弟节点
  2112. // nextClassify, err := sandbox.GetSandboxClassifyById(req.NextClassifyId)
  2113. // if err != nil {
  2114. // br.Msg = "移动失败"
  2115. // br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  2116. // return
  2117. // }
  2118. // //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  2119. // if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == sandboxClassifyInfo.Sort {
  2120. // //变更兄弟节点的排序
  2121. // updateSortStr := `sort + 2`
  2122. // _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, prevClassify.SandboxClassifyId, prevClassify.Sort, updateSortStr)
  2123. // } else {
  2124. // //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  2125. // if nextClassify.Sort-prevClassify.Sort == 1 {
  2126. // //变更兄弟节点的排序
  2127. // updateSortStr := `sort + 1`
  2128. // _ = sandbox.UpdateSandboxClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr)
  2129. // }
  2130. // }
  2131. // }
  2132. //
  2133. // sandboxClassifyInfo.Sort = prevClassify.Sort + 1
  2134. // sandboxClassifyInfo.ModifyTime = time.Now()
  2135. // updateCol = append(updateCol, "Sort", "ModifyTime")
  2136. //
  2137. // } else {
  2138. // firstClassify, err := sandbox.GetFirstSandboxClassifyByParentId(sandboxClassifyInfo.ParentId)
  2139. // if err != nil && err.Error() != utils.ErrNoRow() {
  2140. // br.Msg = "移动失败"
  2141. // br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  2142. // return
  2143. // }
  2144. //
  2145. // //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  2146. // if firstClassify != nil && firstClassify.Sort == 0 {
  2147. // updateSortStr := ` sort + 1 `
  2148. // _ = sandbox.UpdateSandboxClassifySortByParentId(firstClassify.ParentId, firstClassify.SandboxClassifyId-1, 0, updateSortStr)
  2149. // }
  2150. //
  2151. // sandboxClassifyInfo.Sort = 0 //那就是排在第一位
  2152. // sandboxClassifyInfo.ModifyTime = time.Now()
  2153. // updateCol = append(updateCol, "Sort", "ModifyTime")
  2154. // }
  2155. //
  2156. // //更新
  2157. // if len(updateCol) > 0 {
  2158. // err = sandboxClassifyInfo.Update(updateCol)
  2159. // if err != nil {
  2160. // br.Msg = "移动失败"
  2161. // br.ErrMsg = "修改失败,Err:" + err.Error()
  2162. // return
  2163. // }
  2164. // }
  2165. // br.Ret = 200
  2166. // br.Success = true
  2167. // br.Msg = "移动成功"
  2168. //}
  2169. // SandboxClassifyItems
  2170. // @Title 获取所有沙盘分类接口-不包含沙盘
  2171. // @Description 获取所有沙盘分类接口-不包含沙盘
  2172. // @Param IsShowMe query bool true "是否只看我的,true、false"
  2173. // @Success 200 {object} data_manage.ChartClassifyListResp
  2174. // @router /classifyList [get]
  2175. func (this *SandboxController) SandboxClassifyList() {
  2176. br := new(models.BaseResponse).Init()
  2177. defer func() {
  2178. this.Data["json"] = br
  2179. this.ServeJSON()
  2180. }()
  2181. resp := new(sandbox.SandboxClassifyListResp)
  2182. rootList, err := sandbox.GetSandboxClassifyByParentId(0)
  2183. if err != nil && err.Error() != utils.ErrNoRow() {
  2184. br.Msg = "获取失败"
  2185. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  2186. return
  2187. }
  2188. classifyAll, err := sandbox.GetSandboxClassifyAll()
  2189. if err != nil && err.Error() != utils.ErrNoRow() {
  2190. br.Msg = "获取失败"
  2191. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  2192. return
  2193. }
  2194. nodeAll := make([]*sandbox.SandboxClassifyItems, 0)
  2195. for k := range rootList {
  2196. rootNode := rootList[k]
  2197. sandboxService.SandboxClassifyItemsMakeTree(this.SysUser, classifyAll, rootNode)
  2198. nodeAll = append(nodeAll, rootNode)
  2199. }
  2200. resp.AllNodes = nodeAll
  2201. br.Ret = 200
  2202. br.Success = true
  2203. br.Msg = "获取成功"
  2204. br.Data = resp
  2205. }
  2206. // @Title 链接指标检测
  2207. // @Description 链接指标检测接口
  2208. // @Param request body data_manage.ChartClassifyDeleteCheckResp true "type json string"
  2209. // @Success 200 Ret=200 检测成功
  2210. // @router /link/check [post]
  2211. func (this *SandboxController) LinkEdbInfoCheck() {
  2212. br := new(models.BaseResponse).Init()
  2213. defer func() {
  2214. this.Data["json"] = br
  2215. this.ServeJSON()
  2216. }()
  2217. var req sandbox.SandboxLinkCheckReq
  2218. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2219. if err != nil {
  2220. br.Msg = "参数解析异常!"
  2221. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2222. return
  2223. }
  2224. resp := new(sandbox.SandboxLinkCheckResp)
  2225. edbInfoList, err := data_manage.GetEdbInfoByIdList(req.EdbInfoIdList)
  2226. if err != nil {
  2227. br.Msg = "获取指标信息失败"
  2228. br.ErrMsg = "获取指标信息失败,err:" + err.Error()
  2229. return
  2230. }
  2231. edbList := make([]*sandbox.SandboxLinkCheckItem, 0)
  2232. for _, v := range edbInfoList {
  2233. tmp := &sandbox.SandboxLinkCheckItem{
  2234. Id: v.EdbInfoId,
  2235. Name: v.EdbName,
  2236. UniqueCode: v.UniqueCode,
  2237. ClassifyId: v.ClassifyId,
  2238. }
  2239. edbList = append(edbList, tmp)
  2240. }
  2241. chartList, err := data_manage.GetChartInfoByIdList(req.ChartInfoIdList)
  2242. if err != nil {
  2243. br.Msg = `获取失败`
  2244. br.ErrMsg = `获取图表列表失败,ERR:` + err.Error()
  2245. return
  2246. }
  2247. chartListTmp := make([]*sandbox.SandboxLinkCheckItem, 0)
  2248. for _, v := range chartList {
  2249. tmp := &sandbox.SandboxLinkCheckItem{
  2250. Id: v.ChartInfoId,
  2251. Name: v.ChartName,
  2252. UniqueCode: v.UniqueCode,
  2253. ClassifyId: v.ChartClassifyId,
  2254. }
  2255. chartListTmp = append(chartListTmp, tmp)
  2256. }
  2257. reportList, err := models.GetSimpleReportByIds(req.ReportIdList)
  2258. if err != nil {
  2259. br.Msg = `获取失败`
  2260. br.ErrMsg = `获取报告列表失败,ERR:` + err.Error()
  2261. return
  2262. }
  2263. reportListTmp := make([]*sandbox.SandboxLinkCheckItem, 0)
  2264. for _, v := range reportList {
  2265. tmp := &sandbox.SandboxLinkCheckItem{
  2266. Id: v.Id,
  2267. Name: v.Title,
  2268. UniqueCode: v.ReportCode,
  2269. }
  2270. reportListTmp = append(reportListTmp, tmp)
  2271. }
  2272. resp.EdbInfoIdList = edbList
  2273. resp.ChartInfoIdList = chartListTmp
  2274. resp.ReportIdList = reportListTmp
  2275. br.Ret = 200
  2276. br.Msg = "检测成功"
  2277. br.Success = true
  2278. br.Data = resp
  2279. }