sandbox.go 76 KB

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