line_chart_classify.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. package line_equation
  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/system"
  8. "eta/eta_api/services/data"
  9. "eta/eta_api/utils"
  10. "time"
  11. )
  12. // LineEquationChartClassifyController 拟合方程图表分类
  13. type LineEquationChartClassifyController struct {
  14. controllers.BaseAuthController
  15. }
  16. // ChartClassifyList
  17. // @Title 拟合方程图表分类列表
  18. // @Description 拟合方程图表分类列表接口
  19. // @Param IsShowMe query bool true "是否只看我的,true、false"
  20. // @Param Source query int true "图表类型,3:拟合方程,4:滚动拟合方程"
  21. // @Success 200 {object} data_manage.ChartClassifyListResp
  22. // @router /chart_classify/list [get]
  23. func (this *LineEquationChartClassifyController) ChartClassifyList() {
  24. br := new(models.BaseResponse).Init()
  25. defer func() {
  26. this.Data["json"] = br
  27. this.ServeJSON()
  28. }()
  29. resp := new(data_manage.ChartClassifyListResp)
  30. // 获取当前账号的不可见指标
  31. noPermissionChartIdMap := make(map[int]bool)
  32. {
  33. obj := data_manage.EdbInfoNoPermissionAdmin{}
  34. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  35. if err != nil && err.Error() != utils.ErrNoRow() {
  36. br.Msg = "获取失败"
  37. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  38. return
  39. }
  40. for _, v := range confList {
  41. noPermissionChartIdMap[v.ChartInfoId] = true
  42. }
  43. }
  44. isShowMe, _ := this.GetBool("IsShowMe")
  45. if isShowMe {
  46. errMsg, err := getChartClassifyListForMe(*this.SysUser, resp)
  47. if err != nil {
  48. br.Msg = errMsg
  49. br.ErrMsg = err.Error()
  50. return
  51. }
  52. br.Ret = 200
  53. br.Success = true
  54. br.Msg = "获取成功"
  55. br.Data = resp
  56. return
  57. }
  58. source := utils.CHART_SOURCE_LINE_EQUATION
  59. rootList, err := data_manage.GetChartClassifyByParentId(0, source)
  60. if err != nil && err.Error() != utils.ErrNoRow() {
  61. br.Msg = "获取失败"
  62. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  63. return
  64. }
  65. allChartInfo, err := data_manage.GetChartInfoAll([]int{source})
  66. if err != nil && err.Error() != utils.ErrNoRow() {
  67. br.Msg = "获取失败"
  68. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  69. return
  70. }
  71. chartInfoMap := make(map[int][]*data_manage.ChartClassifyItems)
  72. for _, v := range allChartInfo {
  73. if !isShowMe {
  74. chartInfoMap[v.ChartClassifyId] = append(chartInfoMap[v.ChartClassifyId], v)
  75. continue
  76. }
  77. if v.SysUserId != this.SysUser.AdminId {
  78. continue
  79. }
  80. chartInfoMap[v.ChartClassifyId] = append(chartInfoMap[v.ChartClassifyId], v)
  81. }
  82. rootChildMap := make(map[int][]*data_manage.ChartClassifyItems)
  83. for _, v := range rootList {
  84. rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
  85. if existItems, ok := chartInfoMap[v.ChartClassifyId]; ok {
  86. v.Children = existItems
  87. } else {
  88. items := make([]*data_manage.ChartClassifyItems, 0)
  89. v.Children = items
  90. }
  91. }
  92. // 移除没有权限的图表
  93. allNodes := data.HandleNoPermissionChart(rootList, noPermissionChartIdMap, this.SysUser.AdminId)
  94. resp.AllNodes = allNodes
  95. br.Ret = 200
  96. br.Success = true
  97. br.Msg = "获取成功"
  98. br.Data = resp
  99. }
  100. // getChartClassifyListForMe 获取我创建的图表
  101. func getChartClassifyListForMe(adminInfo system.Admin, resp *data_manage.ChartClassifyListResp) (errMsg string, err error) {
  102. // 获取所有的分类
  103. rootList, err := data_manage.GetChartClassifyByParentId(0, utils.CHART_SOURCE_LINE_EQUATION)
  104. if err != nil && err.Error() != utils.ErrNoRow() {
  105. errMsg = "获取失败"
  106. return
  107. }
  108. // /获取所有的图表
  109. allChartInfo, err := data_manage.GetChartInfoByAdminId([]int{utils.CHART_SOURCE_LINE_EQUATION}, adminInfo.AdminId)
  110. if err != nil && err.Error() != utils.ErrNoRow() {
  111. errMsg = "获取失败"
  112. return
  113. }
  114. chartInfoMap := make(map[int][]*data_manage.ChartClassifyItems)
  115. for _, v := range allChartInfo {
  116. chartInfoMap[v.ChartClassifyId] = append(chartInfoMap[v.ChartClassifyId], v)
  117. }
  118. for k, v := range rootList {
  119. if existItems, ok := chartInfoMap[v.ChartClassifyId]; ok {
  120. v.Children = existItems
  121. } else {
  122. items := make([]*data_manage.ChartClassifyItems, 0)
  123. v.Children = items
  124. }
  125. rootList[k] = v
  126. }
  127. resp.AllNodes = rootList
  128. return
  129. }
  130. // ChartClassifyItems
  131. // @Title 获取所有拟合方程图表分类接口-不包含图表
  132. // @Description 获取所有拟合方程图表分类接口-不包含图表
  133. // @Success 200 {object} data_manage.ChartClassifyListResp
  134. // @router /chart_classify/items [get]
  135. func (this *LineEquationChartClassifyController) ChartClassifyItems() {
  136. br := new(models.BaseResponse).Init()
  137. defer func() {
  138. this.Data["json"] = br
  139. this.ServeJSON()
  140. }()
  141. rootList, err := data_manage.GetChartClassifyByParentId(0, utils.CHART_SOURCE_LINE_EQUATION)
  142. if err != nil {
  143. br.Msg = "获取失败"
  144. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  145. return
  146. }
  147. nodeAll := make([]*data_manage.ChartClassifyItems, 0)
  148. for k := range rootList {
  149. rootNode := rootList[k]
  150. nodeAll = append(nodeAll, rootNode)
  151. }
  152. resp := new(data_manage.ChartClassifyListResp)
  153. resp.AllNodes = nodeAll
  154. br.Ret = 200
  155. br.Success = true
  156. br.Msg = "获取成功"
  157. br.Data = resp
  158. }
  159. // AddChartClassify
  160. // @Title 新增拟合方程图表分类
  161. // @Description 新增拟合方程图表分类接口
  162. // @Param request body data_manage.AddChartClassifyReq true "type json string"
  163. // @Success 200 Ret=200 保存成功
  164. // @router /chart_classify/add [post]
  165. func (this *LineEquationChartClassifyController) AddChartClassify() {
  166. br := new(models.BaseResponse).Init()
  167. defer func() {
  168. this.Data["json"] = br
  169. this.ServeJSON()
  170. }()
  171. var req data_manage.AddChartClassifyReq
  172. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  173. if err != nil {
  174. br.Msg = "参数解析异常!"
  175. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  176. return
  177. }
  178. if req.ChartClassifyName == "" {
  179. br.Msg = "请输入分类名称"
  180. br.IsSendEmail = false
  181. return
  182. }
  183. if req.ParentId < 0 {
  184. br.Msg = "参数错误"
  185. br.IsSendEmail = false
  186. return
  187. }
  188. // 新增图表分类
  189. _, err, errMsg, isSendEmail := data.AddChartClassify(req.ChartClassifyName, req.ParentId, req.Level, utils.CHART_SOURCE_LINE_EQUATION, this.Lang, this.SysUser)
  190. if err != nil {
  191. br.Msg = errMsg
  192. br.ErrMsg = "添加分类失败,Err:" + err.Error()
  193. br.IsSendEmail = isSendEmail
  194. return
  195. }
  196. br.Ret = 200
  197. br.Msg = "添加成功"
  198. br.Success = true
  199. }
  200. // EditChartClassify
  201. // @Title 修改拟合方程图表分类
  202. // @Description 修改拟合方程图表分类接口
  203. // @Param request body data_manage.EditChartClassifyReq true "type json string"
  204. // @Success 200 Ret=200 修改成功
  205. // @router /chart_classify/edit [post]
  206. func (this *LineEquationChartClassifyController) EditChartClassify() {
  207. br := new(models.BaseResponse).Init()
  208. defer func() {
  209. this.Data["json"] = br
  210. this.ServeJSON()
  211. }()
  212. var req data_manage.EditChartClassifyReq
  213. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  214. if err != nil {
  215. br.Msg = "参数解析异常!"
  216. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  217. return
  218. }
  219. if req.ChartClassifyName == "" {
  220. br.Msg = "请输入分类名称"
  221. br.IsSendEmail = false
  222. return
  223. }
  224. if req.ChartClassifyId <= 0 {
  225. br.Msg = "参数错误"
  226. br.IsSendEmail = false
  227. return
  228. }
  229. // 编辑图表分类
  230. _, err, errMsg, isSendEmail := data.EditChartClassify(req.ChartClassifyId, utils.CHART_SOURCE_LINE_EQUATION, req.ChartClassifyName, this.Lang, this.SysUser)
  231. if err != nil {
  232. br.Msg = errMsg
  233. br.ErrMsg = "保存分类失败,Err:" + err.Error()
  234. br.IsSendEmail = isSendEmail
  235. return
  236. }
  237. br.Ret = 200
  238. br.Msg = "修改成功"
  239. br.Success = true
  240. br.IsAddLog = true
  241. }
  242. // DeleteChartClassifyCheck
  243. // @Title 删除图表检测接口
  244. // @Description 删除图表检测接口
  245. // @Param request body data_manage.ChartClassifyDeleteCheckResp true "type json string"
  246. // @Success 200 Ret=200 检测成功
  247. // @router /chart_classify/delete/check [post]
  248. func (this *LineEquationChartClassifyController) DeleteChartClassifyCheck() {
  249. br := new(models.BaseResponse).Init()
  250. defer func() {
  251. this.Data["json"] = br
  252. this.ServeJSON()
  253. }()
  254. var req data_manage.ChartClassifyDeleteCheckReq
  255. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  256. if err != nil {
  257. br.Msg = "参数解析异常!"
  258. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  259. return
  260. }
  261. if req.ChartClassifyId < 0 && req.ChartInfoId <= 0 {
  262. br.Msg = "参数错误"
  263. br.IsSendEmail = false
  264. return
  265. }
  266. var deleteStatus int
  267. var tipsMsg string
  268. //删除分类
  269. if req.ChartClassifyId > 0 && req.ChartInfoId == 0 {
  270. //判断拟合方程图表分类下,是否含有图表
  271. count, err := data_manage.GetChartInfoCountByClassifyId(req.ChartClassifyId)
  272. if err != nil {
  273. br.Msg = "删除失败"
  274. br.ErrMsg = "分类下是否含有图表失败,Err:" + err.Error()
  275. return
  276. }
  277. if count > 0 {
  278. deleteStatus = 1
  279. tipsMsg = "该分类下关联图表不可删除"
  280. }
  281. }
  282. if deleteStatus != 1 && req.ChartInfoId == 0 {
  283. classifyCount, err := data_manage.GetChartClassifyCountByClassifyId(req.ChartClassifyId)
  284. if err != nil && err.Error() != utils.ErrNoRow() {
  285. br.Msg = "删除失败"
  286. br.ErrMsg = "分类下是否含有图表失败,Err:" + err.Error()
  287. return
  288. }
  289. if classifyCount > 0 {
  290. deleteStatus = 2
  291. tipsMsg = "确认删除当前目录及包含的子目录吗"
  292. }
  293. }
  294. if deleteStatus == 0 {
  295. tipsMsg = "可删除,进行删除操作"
  296. }
  297. resp := new(data_manage.ChartClassifyDeleteCheckResp)
  298. resp.DeleteStatus = deleteStatus
  299. resp.TipsMsg = tipsMsg
  300. br.Ret = 200
  301. br.Msg = "检测成功"
  302. br.Success = true
  303. br.Data = resp
  304. }
  305. // DeleteChartClassify
  306. // @Title 删除拟合方程图表分类/图表
  307. // @Description 删除拟合方程图表分类/图表接口
  308. // @Param request body data_manage.DeleteChartClassifyReq true "type json string"
  309. // @Success 200 Ret=200 删除成功
  310. // @router /chart_classify/delete [post]
  311. func (this *LineEquationChartClassifyController) DeleteChartClassify() {
  312. br := new(models.BaseResponse).Init()
  313. defer func() {
  314. this.Data["json"] = br
  315. this.ServeJSON()
  316. }()
  317. sysUser := this.SysUser
  318. if sysUser == nil {
  319. br.Msg = "请登录"
  320. br.ErrMsg = "请登录,SysUser Is Empty"
  321. br.Ret = 408
  322. return
  323. }
  324. var req data_manage.DeleteChartClassifyReq
  325. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  326. if err != nil {
  327. br.Msg = "参数解析异常!"
  328. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  329. return
  330. }
  331. if req.ChartClassifyId < 0 && req.ChartInfoId <= 0 {
  332. br.Msg = "参数错误"
  333. br.IsSendEmail = false
  334. return
  335. }
  336. //删除分类
  337. if req.ChartClassifyId > 0 && req.ChartInfoId == 0 {
  338. //判断是否含有指标
  339. count, err := data_manage.GetChartInfoCountByClassifyId(req.ChartClassifyId)
  340. if err != nil && err.Error() != utils.ErrNoRow() {
  341. br.Msg = "删除失败"
  342. br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  343. return
  344. }
  345. if count > 0 {
  346. br.Msg = "该目录下存在关联指标,不可删除"
  347. br.IsSendEmail = false
  348. return
  349. }
  350. err = data_manage.DeleteChartClassify(req.ChartClassifyId)
  351. if err != nil {
  352. br.Msg = "删除失败"
  353. br.ErrMsg = "删除失败,Err:" + err.Error()
  354. return
  355. }
  356. }
  357. resp := new(data_manage.AddChartInfoResp)
  358. //删除图表
  359. if req.ChartInfoId > 0 {
  360. chartInfo, err := data_manage.GetChartInfoById(req.ChartInfoId)
  361. if err != nil {
  362. if err.Error() == utils.ErrNoRow() {
  363. br.Msg = "图表已删除,请刷新页面"
  364. br.ErrMsg = "指标不存在,Err:" + err.Error()
  365. return
  366. } else {
  367. br.Msg = "删除失败"
  368. br.ErrMsg = "删除失败,获取指标信息失败,Err:" + err.Error()
  369. return
  370. }
  371. }
  372. if chartInfo == nil {
  373. br.Msg = "图表已删除,请刷新页面"
  374. return
  375. }
  376. //图表操作权限
  377. ok := data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, true)
  378. if !ok {
  379. br.Msg = "没有该图表的操作权限"
  380. br.ErrMsg = "没有该图表的操作权限"
  381. return
  382. }
  383. myIds := make([]int, 0)
  384. {
  385. // 获取引用该图表的MyCharts, 用于ES删除
  386. var myCond string
  387. var myPars []interface{}
  388. myCond += ` AND a.chart_info_id = ? `
  389. myPars = append(myPars, req.ChartInfoId)
  390. myCharts, e := data_manage.GetMyChartListGroupByCharyInfoIdAndAdminIdByCondition(myCond, myPars)
  391. if e != nil {
  392. br.Msg = "删除失败"
  393. br.ErrMsg = "获取引用图表的MyChats失败, Err: " + e.Error()
  394. return
  395. }
  396. for _, m := range myCharts {
  397. myIds = append(myIds, m.MyChartId)
  398. }
  399. }
  400. //删除图表及关联指标
  401. err = data_manage.DeleteChartInfoAndData(chartInfo.ChartInfoId)
  402. if err != nil {
  403. br.Msg = "删除失败"
  404. br.ErrMsg = "删除失败,Err:" + err.Error()
  405. return
  406. }
  407. //删除ES
  408. {
  409. go data.EsDeleteChartInfo(chartInfo.ChartInfoId)
  410. // 删除MY ETA 图表 es数据
  411. go data.EsDeleteMyChartInfoByMyChartIds(myIds)
  412. }
  413. source := chartInfo.Source // 拟合方程图表
  414. var condition string
  415. var pars []interface{}
  416. condition += " AND chart_classify_id=? AND source = ? "
  417. pars = append(pars, chartInfo.ChartClassifyId, source)
  418. condition += " AND chart_info_id>? ORDER BY create_time ASC LIMIT 1 "
  419. pars = append(pars, req.ChartInfoId)
  420. nextItem, err := data_manage.GetChartInfoByCondition(condition, pars)
  421. if err != nil && err.Error() != utils.ErrNoRow() {
  422. br.Msg = "删除失败"
  423. br.ErrMsg = "获取下一级图库信息失败,Err:" + err.Error()
  424. return
  425. }
  426. if nextItem != nil {
  427. resp.UniqueCode = nextItem.UniqueCode
  428. resp.ChartInfoId = nextItem.ChartInfoId
  429. } else {
  430. var condition string
  431. var pars []interface{}
  432. condition += " AND level=1 "
  433. //pars = append(pars, chartInfo.ChartClassifyId)
  434. condition += " AND chart_classify_id>? ORDER BY chart_classify_id ASC LIMIT 1 "
  435. pars = append(pars, chartInfo.ChartClassifyId)
  436. classifyItem, err := data_manage.GetChartClassifyByCondition(condition, pars)
  437. if err != nil && err.Error() != utils.ErrNoRow() {
  438. br.Msg = "删除失败"
  439. br.ErrMsg = "获取下一级图库分类信息失败,Err:" + err.Error()
  440. return
  441. }
  442. if classifyItem != nil {
  443. nextItem, err = data_manage.GetNextChartInfo(chartInfo.ChartClassifyId)
  444. if err != nil && err.Error() != utils.ErrNoRow() {
  445. br.Msg = "删除失败"
  446. br.ErrMsg = "获取下一级图库信息失败,Err:" + err.Error()
  447. return
  448. }
  449. if nextItem != nil {
  450. resp.UniqueCode = nextItem.UniqueCode
  451. resp.ChartInfoId = nextItem.ChartInfoId
  452. }
  453. }
  454. }
  455. //新增操作日志
  456. {
  457. chartLog := new(data_manage.ChartInfoLog)
  458. chartLog.ChartName = chartInfo.ChartName
  459. chartLog.ChartInfoId = req.ChartInfoId
  460. chartLog.ChartClassifyId = chartInfo.ChartClassifyId
  461. chartLog.SysUserId = sysUser.AdminId
  462. chartLog.SysUserRealName = sysUser.RealName
  463. chartLog.UniqueCode = chartInfo.UniqueCode
  464. chartLog.CreateTime = time.Now()
  465. chartLog.Content = string(this.Ctx.Input.RequestBody)
  466. chartLog.Status = "删除图表"
  467. chartLog.Method = this.Ctx.Input.URI()
  468. go data_manage.AddChartInfoLog(chartLog)
  469. }
  470. }
  471. br.Ret = 200
  472. br.Msg = "删除成功"
  473. br.Success = true
  474. br.Data = resp
  475. br.IsAddLog = true
  476. }
  477. // ChartClassifyMove
  478. // @Title 拟合方程图表分类移动接口
  479. // @Description 拟合方程图表分类移动接口
  480. // @Success 200 {object} data_manage.MoveChartClassifyReq
  481. // @router /chart_classify/move [post]
  482. func (this *LineEquationChartClassifyController) ChartClassifyMove() {
  483. br := new(models.BaseResponse).Init()
  484. defer func() {
  485. this.Data["json"] = br
  486. this.ServeJSON()
  487. }()
  488. sysUser := this.SysUser
  489. if sysUser == nil {
  490. br.Msg = "请登录"
  491. br.ErrMsg = "请登录,SysUser Is Empty"
  492. br.Ret = 408
  493. return
  494. }
  495. var req data_manage.MoveChartClassifyReq
  496. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  497. if err != nil {
  498. br.Msg = "参数解析异常!"
  499. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  500. return
  501. }
  502. if req.ClassifyId <= 0 {
  503. br.Msg = "参数错误"
  504. br.ErrMsg = "分类id小于等于0"
  505. return
  506. }
  507. //判断分类是否存在
  508. chartClassifyInfo, err := data_manage.GetChartClassifyById(req.ClassifyId)
  509. if err != nil {
  510. br.Msg = "移动失败"
  511. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  512. return
  513. }
  514. if chartClassifyInfo.Source != utils.CHART_SOURCE_LINE_EQUATION {
  515. br.Msg = "分类异常"
  516. br.ErrMsg = "分类异常,不是拟合方程图表的分类"
  517. return
  518. }
  519. updateCol := make([]string, 0)
  520. //判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
  521. if chartClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId != 0 {
  522. parentChartClassifyInfo, err := data_manage.GetChartClassifyById(req.ParentClassifyId)
  523. if err != nil {
  524. br.Msg = "移动失败"
  525. br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error()
  526. return
  527. }
  528. chartClassifyInfo.ParentId = parentChartClassifyInfo.ChartClassifyId
  529. chartClassifyInfo.Level = parentChartClassifyInfo.Level + 1
  530. chartClassifyInfo.ModifyTime = time.Now()
  531. updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  532. }
  533. //如果有传入 上一个兄弟节点分类id
  534. if req.PrevClassifyId > 0 {
  535. //上一个兄弟节点
  536. prevClassify, err := data_manage.GetChartClassifyById(req.PrevClassifyId)
  537. if err != nil {
  538. br.Msg = "移动失败"
  539. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  540. return
  541. }
  542. //如果是移动在两个兄弟节点之间
  543. if req.NextClassifyId > 0 {
  544. //下一个兄弟节点
  545. nextClassify, err := data_manage.GetChartClassifyById(req.NextClassifyId)
  546. if err != nil {
  547. br.Msg = "移动失败"
  548. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  549. return
  550. }
  551. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  552. if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == chartClassifyInfo.Sort {
  553. //变更兄弟节点的排序
  554. updateSortStr := `sort + 2`
  555. _ = data_manage.UpdateChartClassifySortByParentId(prevClassify.ParentId, prevClassify.ChartClassifyId, prevClassify.Sort, updateSortStr)
  556. } else {
  557. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  558. if nextClassify.Sort-prevClassify.Sort == 1 {
  559. //变更兄弟节点的排序
  560. updateSortStr := `sort + 1`
  561. _ = data_manage.UpdateChartClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr)
  562. }
  563. }
  564. }
  565. chartClassifyInfo.Sort = prevClassify.Sort + 1
  566. chartClassifyInfo.ModifyTime = time.Now()
  567. updateCol = append(updateCol, "Sort", "ModifyTime")
  568. } else {
  569. firstClassify, err := data_manage.GetFirstChartClassifyByParentId(chartClassifyInfo.ParentId)
  570. if err != nil && err.Error() != utils.ErrNoRow() {
  571. br.Msg = "移动失败"
  572. br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  573. return
  574. }
  575. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  576. if firstClassify != nil && firstClassify.Sort == 0 {
  577. updateSortStr := ` sort + 1 `
  578. _ = data_manage.UpdateChartClassifySortByParentId(firstClassify.ParentId, firstClassify.ChartClassifyId-1, 0, updateSortStr)
  579. }
  580. chartClassifyInfo.Sort = 0 //那就是排在第一位
  581. chartClassifyInfo.ModifyTime = time.Now()
  582. updateCol = append(updateCol, "Sort", "ModifyTime")
  583. }
  584. //更新
  585. if len(updateCol) > 0 {
  586. err = chartClassifyInfo.Update(updateCol)
  587. if err != nil {
  588. br.Msg = "移动失败"
  589. br.ErrMsg = "修改失败,Err:" + err.Error()
  590. return
  591. }
  592. }
  593. br.Ret = 200
  594. br.Success = true
  595. br.Msg = "移动成功"
  596. }