sandbox.go 77 KB

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