sandbox.go 74 KB

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