chart_framework.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. package data_manage
  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. "fmt"
  11. "strings"
  12. "time"
  13. )
  14. type ChartFrameworkController struct {
  15. controllers.BaseAuthController
  16. }
  17. // @router /list [get]
  18. func (this *ChartFrameworkController) List() {
  19. br := new(models.BaseResponse).Init()
  20. defer func() {
  21. if br.ErrMsg == "" {
  22. br.IsSendEmail = false
  23. }
  24. this.Data["json"] = br
  25. this.ServeJSON()
  26. }()
  27. sysUser := this.SysUser
  28. if sysUser == nil {
  29. br.Msg = "请登录"
  30. br.ErrMsg = "请登录,SysUser Is Empty"
  31. br.Ret = 408
  32. return
  33. }
  34. adminId, _ := this.GetInt("AdminId")
  35. visibility, _ := this.GetInt("Visibility")
  36. if visibility == 1 && adminId <= 0 {
  37. adminId = sysUser.AdminId
  38. }
  39. keyword := this.GetString("Keyword")
  40. keyword = strings.TrimSpace(keyword)
  41. frameworkOb := new(data_manage.ChartFramework)
  42. cond := ``
  43. pars := make([]interface{}, 0)
  44. if adminId > 0 {
  45. cond += fmt.Sprintf(` AND %s = ?`, data_manage.ChartFrameworkColumns.AdminId)
  46. pars = append(pars, adminId)
  47. }
  48. if keyword != "" {
  49. cond += fmt.Sprintf(` AND %s LIKE ?`, data_manage.ChartFrameworkColumns.FrameworkName)
  50. pars = append(pars, "%"+keyword+"%")
  51. }
  52. if visibility > 0 {
  53. visibilityArr := map[int]int{1: 0, 2: 1}
  54. cond += fmt.Sprintf(` AND %s = ?`, data_manage.ChartFrameworkColumns.IsPublic)
  55. pars = append(pars, visibilityArr[visibility])
  56. }
  57. orderRule := `sort ASC, create_time DESC`
  58. list, e := frameworkOb.GetItemsByCondition(cond, pars, []string{}, orderRule)
  59. if e != nil {
  60. br.Msg = "获取失败"
  61. br.ErrMsg = "获取框架列表失败, Err: " + e.Error()
  62. return
  63. }
  64. resp := make([]*data_manage.ChartFrameworkItem, 0)
  65. for _, v := range list {
  66. t := data_manage.FormatChartFramework2Item(v, make([]*data_manage.ChartFrameworkNodeItem, 0))
  67. resp = append(resp, t)
  68. }
  69. br.Data = resp
  70. br.Ret = 200
  71. br.Success = true
  72. br.Msg = "获取成功"
  73. }
  74. // @router /public_menu [get]
  75. func (this *ChartFrameworkController) PublicMenu() {
  76. br := new(models.BaseResponse).Init()
  77. defer func() {
  78. if br.ErrMsg == "" {
  79. br.IsSendEmail = false
  80. }
  81. this.Data["json"] = br
  82. this.ServeJSON()
  83. }()
  84. sysUser := this.SysUser
  85. if sysUser == nil {
  86. br.Msg = "请登录"
  87. br.ErrMsg = "请登录,SysUser Is Empty"
  88. br.Ret = 408
  89. return
  90. }
  91. frameworkOb := new(data_manage.ChartFramework)
  92. cond := fmt.Sprintf(` AND %s = ?`, data_manage.ChartFrameworkColumns.IsPublic)
  93. pars := make([]interface{}, 0)
  94. pars = append(pars, 1)
  95. orderRule := `public_time ASC, sort ASC, create_time DESC`
  96. list, e := frameworkOb.GetItemsByCondition(cond, pars, []string{}, orderRule)
  97. if e != nil {
  98. br.Msg = "获取失败"
  99. br.ErrMsg = "获取公开框架失败, Err: " + e.Error()
  100. return
  101. }
  102. admins, e := system.GetSysAdminList(``, make([]interface{}, 0), []string{}, "")
  103. if e != nil {
  104. br.Msg = "获取失败"
  105. br.ErrMsg = "获取系统用户列表失败, Err: " + e.Error()
  106. return
  107. }
  108. adminExist := make(map[int]bool)
  109. for _, v := range admins {
  110. adminExist[v.AdminId] = true
  111. }
  112. userExist := make(map[int]bool)
  113. userFrameworks := make(map[int][]*data_manage.ChartFrameworkItem)
  114. resp := make([]*data_manage.ChartFrameworkPublicMenuItem, 0)
  115. for _, v := range list {
  116. if !adminExist[v.AdminId] {
  117. continue
  118. }
  119. if !userExist[v.AdminId] {
  120. u := new(data_manage.ChartFrameworkPublicMenuItem)
  121. u.AdminId = v.AdminId
  122. u.MenuName = fmt.Sprintf("%s的框架", v.AdminName)
  123. resp = append(resp, u)
  124. userExist[v.AdminId] = true
  125. }
  126. t := data_manage.FormatChartFramework2Item(v, make([]*data_manage.ChartFrameworkNodeItem, 0))
  127. if userFrameworks[v.AdminId] == nil {
  128. userFrameworks[v.AdminId] = make([]*data_manage.ChartFrameworkItem, 0)
  129. }
  130. userFrameworks[v.AdminId] = append(userFrameworks[v.AdminId], t)
  131. }
  132. for _, v := range resp {
  133. v.Frameworks = userFrameworks[v.AdminId]
  134. }
  135. br.Data = resp
  136. br.Ret = 200
  137. br.Success = true
  138. br.Msg = "获取成功"
  139. }
  140. // @router /add [post]
  141. func (this *ChartFrameworkController) Add() {
  142. br := new(models.BaseResponse).Init()
  143. defer func() {
  144. if br.ErrMsg == "" {
  145. br.IsSendEmail = false
  146. }
  147. this.Data["json"] = br
  148. this.ServeJSON()
  149. }()
  150. sysUser := this.SysUser
  151. if sysUser == nil {
  152. br.Msg = "请登录"
  153. br.ErrMsg = "请登录,SysUser Is Empty"
  154. br.Ret = 408
  155. return
  156. }
  157. var req data_manage.ChartFrameworkAddReq
  158. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  159. br.Msg = "参数解析异常!"
  160. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  161. return
  162. }
  163. req.FrameworkName = strings.TrimSpace(req.FrameworkName)
  164. if req.FrameworkName == "" {
  165. br.Msg = "框架名称不可为空"
  166. return
  167. }
  168. {
  169. ob := new(data_manage.ChartFramework)
  170. cond := fmt.Sprintf(` AND %s = ? AND %s = ?`, data_manage.ChartFrameworkColumns.FrameworkName, data_manage.ChartFrameworkColumns.AdminId)
  171. pars := make([]interface{}, 0)
  172. pars = append(pars, req.FrameworkName, sysUser.AdminId)
  173. exist, e := ob.GetItemByCondition(cond, pars)
  174. if e != nil && !utils.IsErrNoRow(e) {
  175. br.Msg = "操作失败"
  176. br.ErrMsg = "获取重名框架失败, Err: " + e.Error()
  177. return
  178. }
  179. if exist != nil {
  180. br.Msg = "框架名称已存在"
  181. return
  182. }
  183. }
  184. chartsNumMap, e := data.GetMyChartClassifyIdNumMap(sysUser.AdminId)
  185. if e != nil {
  186. br.Msg = "获取失败"
  187. br.ErrMsg = "获取失败, GetMyChartClassifyIdNumMap Err: " + e.Error()
  188. return
  189. }
  190. now := time.Now().Local()
  191. frameworkCode := utils.MD5(fmt.Sprint(now.UnixMilli()))
  192. item := new(data_manage.ChartFramework)
  193. item.FrameworkName = req.FrameworkName
  194. item.FrameworkCode = frameworkCode
  195. item.FrameworkImg = req.FrameworkImg
  196. item.FrameworkContent = req.FrameworkContent
  197. item.AdminId = sysUser.AdminId
  198. item.AdminName = sysUser.RealName
  199. item.CreateTime = now
  200. item.ModifyTime = now
  201. nodes := make([]*data_manage.ChartFrameworkNode, 0)
  202. itemNodes := make([]*data_manage.ChartFrameworkNodeItem, 0)
  203. if len(req.Nodes) > 0 {
  204. for _, v := range req.Nodes {
  205. if v.MyChartClassifyId <= 0 {
  206. continue
  207. }
  208. t := new(data_manage.ChartFrameworkNode)
  209. t.FrameworkName = req.FrameworkName
  210. t.NodeId = v.NodeId
  211. t.NodeName = v.NodeName
  212. t.MyChartClassifyId = v.MyChartClassifyId
  213. t.CreateTime = now
  214. nodes = append(nodes, t)
  215. num, ok := chartsNumMap[v.MyChartClassifyId]
  216. if !ok {
  217. num = 0
  218. }
  219. td := data_manage.FormatChartFrameworkNode2Item(t, num)
  220. itemNodes = append(itemNodes, td)
  221. }
  222. }
  223. if e := item.CreateFrameworkAndNodes(item, nodes); e != nil {
  224. br.Msg = "操作失败"
  225. br.ErrMsg = "新增框架及节点失败, Err: " + e.Error()
  226. return
  227. }
  228. detail := data_manage.FormatChartFramework2Item(item, itemNodes)
  229. br.Data = detail
  230. br.Ret = 200
  231. br.Success = true
  232. br.Msg = "操作成功"
  233. br.IsAddLog = true
  234. }
  235. // @router /edit [post]
  236. func (this *ChartFrameworkController) Edit() {
  237. br := new(models.BaseResponse).Init()
  238. defer func() {
  239. if br.ErrMsg == "" {
  240. br.IsSendEmail = false
  241. }
  242. this.Data["json"] = br
  243. this.ServeJSON()
  244. }()
  245. sysUser := this.SysUser
  246. if sysUser == nil {
  247. br.Msg = "请登录"
  248. br.ErrMsg = "请登录,SysUser Is Empty"
  249. br.Ret = 408
  250. return
  251. }
  252. var req data_manage.ChartFrameworkEditReq
  253. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  254. br.Msg = "参数解析异常!"
  255. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  256. return
  257. }
  258. if req.ChartFrameworkId <= 0 {
  259. br.Msg = "参数有误"
  260. br.ErrMsg = fmt.Sprintf("参数有误, ChartFrameworkId: %d", req.ChartFrameworkId)
  261. return
  262. }
  263. req.FrameworkName = strings.TrimSpace(req.FrameworkName)
  264. if req.FrameworkName == "" {
  265. br.Msg = "框架名称不可为空"
  266. return
  267. }
  268. frameworkOb := new(data_manage.ChartFramework)
  269. item, e := frameworkOb.GetItemById(req.ChartFrameworkId)
  270. if e != nil {
  271. if utils.IsErrNoRow(e) {
  272. br.Msg = "框架不存在, 请刷新页面"
  273. return
  274. }
  275. br.Msg = "操作失败"
  276. br.ErrMsg = "获取框架失败, Err: " + e.Error()
  277. return
  278. }
  279. {
  280. ob := new(data_manage.ChartFramework)
  281. cond := fmt.Sprintf(` AND %s <> ? AND %s = ? AND %s = ?`, ob.PrimaryId(), data_manage.ChartFrameworkColumns.FrameworkName, data_manage.ChartFrameworkColumns.AdminId)
  282. pars := make([]interface{}, 0)
  283. pars = append(pars, req.ChartFrameworkId, req.FrameworkName, sysUser.AdminId)
  284. exist, e := ob.GetItemByCondition(cond, pars)
  285. if e != nil && !utils.IsErrNoRow(e) {
  286. br.Msg = "操作失败"
  287. br.ErrMsg = "获取重名框架失败, Err: " + e.Error()
  288. return
  289. }
  290. if exist != nil {
  291. br.Msg = "框架名称已存在"
  292. return
  293. }
  294. }
  295. chartsNumMap, e := data.GetMyChartClassifyIdNumMap(sysUser.AdminId)
  296. if e != nil {
  297. br.Msg = "获取失败"
  298. br.ErrMsg = "获取失败, GetMyChartClassifyIdNumMap Err: " + e.Error()
  299. return
  300. }
  301. now := time.Now().Local()
  302. item.FrameworkName = req.FrameworkName
  303. item.FrameworkImg = req.FrameworkImg
  304. item.FrameworkContent = req.FrameworkContent
  305. item.ModifyTime = now
  306. updateCols := []string{"FrameworkName", "FrameworkImg", "FrameworkContent", "ModifyTime"}
  307. nodes := make([]*data_manage.ChartFrameworkNode, 0)
  308. itemNodes := make([]*data_manage.ChartFrameworkNodeItem, 0)
  309. if len(req.Nodes) > 0 {
  310. for _, v := range req.Nodes {
  311. if v.MyChartClassifyId <= 0 {
  312. continue
  313. }
  314. t := new(data_manage.ChartFrameworkNode)
  315. t.ChartFrameworkId = req.ChartFrameworkId
  316. t.FrameworkName = req.FrameworkName
  317. t.NodeId = v.NodeId
  318. t.NodeName = v.NodeName
  319. t.MyChartClassifyId = v.MyChartClassifyId
  320. t.CreateTime = now
  321. nodes = append(nodes, t)
  322. td := data_manage.FormatChartFrameworkNode2Item(t, chartsNumMap[t.MyChartClassifyId])
  323. itemNodes = append(itemNodes, td)
  324. }
  325. }
  326. if e := item.EditFrameworkAndNodes(item, updateCols, nodes); e != nil {
  327. br.Msg = "操作失败"
  328. br.ErrMsg = "编辑框架及节点失败, Err: " + e.Error()
  329. return
  330. }
  331. detail := data_manage.FormatChartFramework2Item(item, itemNodes)
  332. br.Data = detail
  333. br.Ret = 200
  334. br.Success = true
  335. br.Msg = "操作成功"
  336. br.IsAddLog = true
  337. }
  338. // @router /remove [post]
  339. func (this *ChartFrameworkController) Remove() {
  340. br := new(models.BaseResponse).Init()
  341. defer func() {
  342. if br.ErrMsg == "" {
  343. br.IsSendEmail = false
  344. }
  345. this.Data["json"] = br
  346. this.ServeJSON()
  347. }()
  348. sysUser := this.SysUser
  349. if sysUser == nil {
  350. br.Msg = "请登录"
  351. br.ErrMsg = "请登录,SysUser Is Empty"
  352. br.Ret = 408
  353. return
  354. }
  355. var req data_manage.ChartFrameworkRemoveReq
  356. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  357. br.Msg = "参数解析异常!"
  358. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  359. return
  360. }
  361. if req.ChartFrameworkId <= 0 {
  362. br.Msg = "参数有误"
  363. br.ErrMsg = fmt.Sprintf("参数有误, ChartFrameworkId: %d", req.ChartFrameworkId)
  364. return
  365. }
  366. ob := new(data_manage.ChartFramework)
  367. item, e := ob.GetItemById(req.ChartFrameworkId)
  368. if e != nil {
  369. if utils.IsErrNoRow(e) {
  370. br.Ret = 200
  371. br.Success = true
  372. br.Msg = "操作成功"
  373. return
  374. }
  375. br.Msg = "操作失败"
  376. br.ErrMsg = "获取框架失败, Err: " + e.Error()
  377. return
  378. }
  379. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && item.AdminId != sysUser.AdminId {
  380. br.Msg = "无权操作"
  381. return
  382. }
  383. if e := item.RemoveFrameworkAndNodes(req.ChartFrameworkId); e != nil {
  384. br.Msg = "操作失败"
  385. br.ErrMsg = "删除框架失败, Err: " + e.Error()
  386. return
  387. }
  388. br.Ret = 200
  389. br.Success = true
  390. br.Msg = "操作成功"
  391. br.IsAddLog = true
  392. }
  393. // @router /rename [post]
  394. func (this *ChartFrameworkController) Rename() {
  395. br := new(models.BaseResponse).Init()
  396. defer func() {
  397. if br.ErrMsg == "" {
  398. br.IsSendEmail = false
  399. }
  400. this.Data["json"] = br
  401. this.ServeJSON()
  402. }()
  403. sysUser := this.SysUser
  404. if sysUser == nil {
  405. br.Msg = "请登录"
  406. br.ErrMsg = "请登录,SysUser Is Empty"
  407. br.Ret = 408
  408. return
  409. }
  410. var req data_manage.ChartFrameworkRenameReq
  411. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  412. br.Msg = "参数解析异常!"
  413. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  414. return
  415. }
  416. if req.ChartFrameworkId <= 0 {
  417. br.Msg = "参数有误"
  418. br.ErrMsg = fmt.Sprintf("参数有误, ChartFrameworkId: %d", req.ChartFrameworkId)
  419. return
  420. }
  421. req.FrameworkName = strings.TrimSpace(req.FrameworkName)
  422. if req.FrameworkName == "" {
  423. br.Msg = "框架名称不可为空"
  424. return
  425. }
  426. frameworkOb := new(data_manage.ChartFramework)
  427. item, e := frameworkOb.GetItemById(req.ChartFrameworkId)
  428. if e != nil {
  429. if utils.IsErrNoRow(e) {
  430. br.Msg = "框架不存在, 请刷新页面"
  431. return
  432. }
  433. br.Msg = "操作失败"
  434. br.ErrMsg = "获取框架失败, Err: " + e.Error()
  435. return
  436. }
  437. {
  438. ob := new(data_manage.ChartFramework)
  439. cond := fmt.Sprintf(` AND %s <> ? AND %s = ? AND %s = ?`, ob.PrimaryId(), data_manage.ChartFrameworkColumns.FrameworkName, data_manage.ChartFrameworkColumns.AdminId)
  440. pars := make([]interface{}, 0)
  441. pars = append(pars, req.ChartFrameworkId, req.FrameworkName, sysUser.AdminId)
  442. exist, e := ob.GetItemByCondition(cond, pars)
  443. if e != nil && !utils.IsErrNoRow(e) {
  444. br.Msg = "操作失败"
  445. br.ErrMsg = "获取重名框架失败, Err: " + e.Error()
  446. return
  447. }
  448. if exist != nil {
  449. br.Msg = "框架名称已存在"
  450. return
  451. }
  452. }
  453. now := time.Now().Local()
  454. item.FrameworkName = req.FrameworkName
  455. item.ModifyTime = now
  456. updateCols := []string{"FrameworkName", "ModifyTime"}
  457. if e := item.Update(updateCols); e != nil {
  458. br.Msg = "操作失败"
  459. br.ErrMsg = "框架重命名失败, Err: " + e.Error()
  460. return
  461. }
  462. br.Ret = 200
  463. br.Success = true
  464. br.Msg = "操作成功"
  465. }
  466. // @router /edit_public [post]
  467. func (this *ChartFrameworkController) EditPublic() {
  468. br := new(models.BaseResponse).Init()
  469. defer func() {
  470. if br.ErrMsg == "" {
  471. br.IsSendEmail = false
  472. }
  473. this.Data["json"] = br
  474. this.ServeJSON()
  475. }()
  476. sysUser := this.SysUser
  477. if sysUser == nil {
  478. br.Msg = "请登录"
  479. br.ErrMsg = "请登录,SysUser Is Empty"
  480. br.Ret = 408
  481. return
  482. }
  483. var req data_manage.ChartFrameworkEditPublicReq
  484. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  485. br.Msg = "参数解析异常!"
  486. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  487. return
  488. }
  489. if req.ChartFrameworkId <= 0 {
  490. br.Msg = "参数有误"
  491. br.ErrMsg = fmt.Sprintf("参数有误, ChartFrameworkId: %d", req.ChartFrameworkId)
  492. return
  493. }
  494. if req.IsPublic != 0 && req.IsPublic != 1 {
  495. br.Msg = "参数有误"
  496. br.ErrMsg = fmt.Sprintf("参数有误, IsPublic: %d", req.IsPublic)
  497. return
  498. }
  499. frameworkOb := new(data_manage.ChartFramework)
  500. item, e := frameworkOb.GetItemById(req.ChartFrameworkId)
  501. if e != nil {
  502. if utils.IsErrNoRow(e) {
  503. br.Msg = "框架不存在, 请刷新页面"
  504. return
  505. }
  506. br.Msg = "操作失败"
  507. br.ErrMsg = "获取框架失败, Err: " + e.Error()
  508. return
  509. }
  510. now := time.Now().Local()
  511. updateCols := []string{"IsPublic", "PublicTime", "ModifyTime"}
  512. item.IsPublic = req.IsPublic
  513. if req.IsPublic == 1 {
  514. item.PublicTime = time.Now().Local()
  515. } else {
  516. item.PublicTime = time.Time{}
  517. }
  518. item.ModifyTime = now
  519. if e := item.Update(updateCols); e != nil {
  520. br.Msg = "操作失败"
  521. br.ErrMsg = "更新框架是否公开失败, Err: " + e.Error()
  522. return
  523. }
  524. br.Ret = 200
  525. br.Success = true
  526. br.Msg = "操作成功"
  527. }
  528. // @router /move [post]
  529. func (this *ChartFrameworkController) Move() {
  530. br := new(models.BaseResponse).Init()
  531. defer func() {
  532. if br.ErrMsg == "" {
  533. br.IsSendEmail = false
  534. }
  535. this.Data["json"] = br
  536. this.ServeJSON()
  537. }()
  538. sysUser := this.SysUser
  539. if sysUser == nil {
  540. br.Msg = "请登录"
  541. br.ErrMsg = "请登录,SysUser Is Empty"
  542. br.Ret = 408
  543. return
  544. }
  545. var req data_manage.ChartFrameworkMoveReq
  546. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  547. br.Msg = "参数解析异常!"
  548. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  549. return
  550. }
  551. if req.ChartFrameworkId <= 0 {
  552. br.Msg = "参数有误"
  553. br.ErrMsg = fmt.Sprintf("参数有误, ChartFrameworkId: %d", req.ChartFrameworkId)
  554. return
  555. }
  556. frameworkOb := new(data_manage.ChartFramework)
  557. item, e := frameworkOb.GetItemById(req.ChartFrameworkId)
  558. if e != nil {
  559. if utils.IsErrNoRow(e) {
  560. br.Msg = "框架不存在, 请刷新页面"
  561. return
  562. }
  563. br.Msg = "操作失败"
  564. br.ErrMsg = "获取框架失败, Err: " + e.Error()
  565. return
  566. }
  567. updateCols := make([]string, 0)
  568. if req.PrevChartFrameworkId > 0 {
  569. prev, e := frameworkOb.GetItemById(req.PrevChartFrameworkId)
  570. if e != nil {
  571. br.Msg = "操作失败"
  572. br.ErrMsg = "获取上一个兄弟节点失败, Err: " + e.Error()
  573. return
  574. }
  575. if req.NextChartFrameworkId > 0 {
  576. next, e := frameworkOb.GetItemById(req.PrevChartFrameworkId)
  577. if e != nil {
  578. br.Msg = "操作失败"
  579. br.ErrMsg = "获取下一个兄弟节点失败, Err: " + e.Error()
  580. return
  581. }
  582. if prev.Sort == next.Sort || prev.Sort == item.Sort {
  583. strUpdate := `sort + 2`
  584. _ = data_manage.UpdateChartFrameworkSort(sysUser.AdminId, prev.ChartFrameworkId, prev.Sort, strUpdate)
  585. } else {
  586. if next.Sort-prev.Sort == 1 {
  587. strUpdate := `sort + 1`
  588. _ = data_manage.UpdateChartFrameworkSort(sysUser.AdminId, 0, prev.Sort, strUpdate)
  589. }
  590. }
  591. }
  592. item.Sort = prev.Sort + 1
  593. item.ModifyTime = time.Now()
  594. updateCols = append(updateCols, "Sort", "ModifyTime")
  595. } else {
  596. first, err := data_manage.GetFirstChartFramework(sysUser.AdminId)
  597. if err != nil && !utils.IsErrNoRow(err) {
  598. br.Msg = "操作失败"
  599. br.ErrMsg = "获取我的图库框架排首位的数据失败, Err:" + err.Error()
  600. return
  601. }
  602. if first != nil && first.Sort == 0 {
  603. strUpdate := ` sort + 1 `
  604. _ = data_manage.UpdateChartFrameworkSort(sysUser.AdminId, first.ChartFrameworkId-1, 0, strUpdate)
  605. }
  606. item.Sort = 0
  607. item.ModifyTime = time.Now()
  608. updateCols = append(updateCols, "Sort", "ModifyTime")
  609. }
  610. if len(updateCols) > 0 {
  611. if e := item.Update(updateCols); e != nil {
  612. br.Msg = "操作失败"
  613. br.ErrMsg = "更新框架排序失败, Err: " + e.Error()
  614. return
  615. }
  616. }
  617. br.Ret = 200
  618. br.Success = true
  619. br.Msg = "操作成功"
  620. }
  621. // @router /detail [get]
  622. func (this *ChartFrameworkController) Detail() {
  623. br := new(models.BaseResponse).Init()
  624. defer func() {
  625. if br.ErrMsg == "" {
  626. br.IsSendEmail = false
  627. }
  628. this.Data["json"] = br
  629. this.ServeJSON()
  630. }()
  631. sysUser := this.SysUser
  632. if sysUser == nil {
  633. br.Msg = "请登录"
  634. br.ErrMsg = "请登录,SysUser Is Empty"
  635. br.Ret = 408
  636. return
  637. }
  638. frameworkId, _ := this.GetInt("ChartFrameworkId")
  639. if frameworkId <= 0 {
  640. br.Msg = "参数有误"
  641. br.ErrMsg = fmt.Sprintf("参数有误, ChartFrameworkId: %d", frameworkId)
  642. return
  643. }
  644. frameworkOb := new(data_manage.ChartFramework)
  645. item, e := frameworkOb.GetItemById(frameworkId)
  646. if e != nil {
  647. if utils.IsErrNoRow(e) {
  648. br.Msg = "框架不存在, 请刷新页面"
  649. return
  650. }
  651. br.Msg = "获取失败"
  652. br.ErrMsg = "获取框架失败, Err: " + e.Error()
  653. return
  654. }
  655. nodeOb := new(data_manage.ChartFrameworkNode)
  656. nodeCond := ` AND chart_framework_id = ?`
  657. nodePars := make([]interface{}, 0)
  658. nodePars = append(nodePars, frameworkId)
  659. nodes, e := nodeOb.GetItemsByCondition(nodeCond, nodePars, []string{}, "")
  660. if e != nil {
  661. br.Msg = "获取失败"
  662. br.ErrMsg = "获取框架节点失败, Err: " + e.Error()
  663. return
  664. }
  665. chartsNumMap, e := data.GetMyChartClassifyIdNumMap(sysUser.AdminId)
  666. if e != nil {
  667. br.Msg = "获取失败"
  668. br.ErrMsg = "获取失败, GetMyChartClassifyIdNumMap Err: " + e.Error()
  669. return
  670. }
  671. itemNodes := make([]*data_manage.ChartFrameworkNodeItem, 0)
  672. for _, v := range nodes {
  673. if v.NodeId == "" {
  674. continue
  675. }
  676. num, ok := chartsNumMap[v.MyChartClassifyId]
  677. if !ok {
  678. num = 0
  679. }
  680. itemNodes = append(itemNodes, data_manage.FormatChartFrameworkNode2Item(v, num))
  681. }
  682. detail := data_manage.FormatChartFramework2Item(item, itemNodes)
  683. br.Data = detail
  684. br.Ret = 200
  685. br.Success = true
  686. br.Msg = "操作成功"
  687. }