classify.go 18 KB

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