my_chart.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. package chart
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "hongze/hongze_yb/controller/response"
  5. "hongze/hongze_yb/models/response/my_chart"
  6. chartInfoModel "hongze/hongze_yb/models/tables/chart_info"
  7. myChartModel "hongze/hongze_yb/models/tables/my_chart"
  8. "hongze/hongze_yb/models/tables/my_chart_classify"
  9. myChartClassifyMappingModel "hongze/hongze_yb/models/tables/my_chart_classify_mapping"
  10. myChartLogModel "hongze/hongze_yb/models/tables/my_chart_log"
  11. "hongze/hongze_yb/services/chart"
  12. "hongze/hongze_yb/services/user"
  13. "hongze/hongze_yb/utils"
  14. "io/ioutil"
  15. "strconv"
  16. "time"
  17. )
  18. // GetMyChartChassify 获取图表分类列表
  19. // @Tags 图库模块
  20. // @Summary 获取图表分类
  21. // @Description 获取图表分类列表
  22. // @Security ApiKeyAuth
  23. // @Param Authorization header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
  24. // @Accept json
  25. // @Product json
  26. // @Param Keywords query string false "分类名称关键词"
  27. // @Success 200 {object} my_chart.MyChartClassifyListResp
  28. // @failure 400 {string} string "分类列表获取失败"
  29. // @Router /chart/getChartChassify [get]
  30. func GetMyChartChassify(c *gin.Context) {
  31. userInfo := user.GetInfoByClaims(c)
  32. publicCondition := make(map[string]interface{})
  33. privateCondition := make(map[string]interface{})
  34. reqKeywords := c.DefaultQuery("Keywords", "")
  35. if reqKeywords != "" {
  36. publicCondition["my_chart_classify_name like"] = "%" + reqKeywords + "%"
  37. privateCondition["my_chart_classify_name like"] = "%" + reqKeywords + "%"
  38. }
  39. publicClassify, privateClassify, err := chart.GetUserChartClassifyListByCondition(userInfo, publicCondition, privateCondition)
  40. if err != nil {
  41. response.Fail("获取图表分类失败, Err:"+err.Error(), c)
  42. return
  43. }
  44. respData := &my_chart.MyChartClassifyListResp{
  45. PublicClassify: publicClassify,
  46. PrivateClassify: privateClassify,
  47. }
  48. response.OkData("获取成功", respData, c)
  49. }
  50. // GetMyChartList 获取图表列表
  51. // @Tags 图库模块
  52. // @Summary 获取图表列表
  53. // @Description 获取图表列表
  54. // @Security ApiKeyAuth
  55. // @Param Authorization header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
  56. // @Accept json
  57. // @Product json
  58. // @Param Keywords query string false "图表名称关键词"
  59. // @Param ClassifyId query string false "图表分类ID"
  60. // @Param Page query int false "当前页页码,从1开始"
  61. // @Param Limit query int false "每页数据量"
  62. // @Success 200 {object} []my_chart.MyChartList
  63. // @failure 400 {string} string "图库列表获取失败"
  64. // @Router /chart/getChartList [get]
  65. func GetMyChartList(c *gin.Context) {
  66. userInfo := user.GetInfoByClaims(c)
  67. // 筛选
  68. var condition string
  69. var pars []interface{}
  70. reqKeywords := c.DefaultQuery("Keywords", "")
  71. reqClassifyId := c.DefaultQuery("ClassifyId", "")
  72. // 获取用户图表分类权限
  73. publicCondition := make(map[string]interface{})
  74. privateCondition := make(map[string]interface{})
  75. publicClassify, privateClassify, err := chart.GetUserChartClassifyListByCondition(userInfo, publicCondition, privateCondition)
  76. if err != nil {
  77. response.FailMsg("获取失败", "获取图表分类信息失败, Err:"+err.Error(), c)
  78. return
  79. }
  80. if reqClassifyId == "" && reqKeywords == "" {
  81. // 内部员工默认取自己的第一个分类
  82. classifyId := 0
  83. if len(privateClassify) > 0 {
  84. classifyId = privateClassify[0].MyChartClassifyId
  85. } else {
  86. if len(publicClassify) > 0 {
  87. classifyId = publicClassify[0].MyChartClassifyId
  88. }
  89. }
  90. condition += " AND d.my_chart_classify_id = ?"
  91. pars = append(pars, classifyId)
  92. } else if reqKeywords != "" {
  93. // 关键词
  94. condition += " AND b.chart_name LIKE ?"
  95. pars = append(pars, "%"+reqKeywords+"%")
  96. // 搜索自己权限内的图表
  97. classifyIds := make([]int, 0)
  98. for i := 0; i < len(publicClassify); i++ {
  99. classifyIds = append(classifyIds, publicClassify[i].MyChartClassifyId)
  100. }
  101. for i := 0; i < len(privateClassify); i++ {
  102. classifyIds = append(classifyIds, privateClassify[i].MyChartClassifyId)
  103. }
  104. condition += " AND d.my_chart_classify_id IN (?)"
  105. pars = append(pars, classifyIds)
  106. } else {
  107. // 指定分类
  108. condition += " AND d.my_chart_classify_id = ?"
  109. pars = append(pars, reqClassifyId)
  110. }
  111. // 分页
  112. page, _ := strconv.Atoi(c.Query("Page"))
  113. limit, _ := strconv.Atoi(c.Query("Limit"))
  114. if page == 0 {
  115. page = 1
  116. }
  117. if limit == 0 {
  118. limit = 10
  119. }
  120. list, err := myChartModel.GetMyChartListByCondition(condition, pars, page, limit)
  121. if err != nil {
  122. response.FailMsg("获取失败", "获取图库列表失败, Err:"+err.Error(), c)
  123. return
  124. }
  125. response.OkData("获取成功", list, c)
  126. }
  127. // MoveMyChart 移动我的图表
  128. // @Tags 图库模块
  129. // @Summary 移动我的图表
  130. // @Description 移动我的图表
  131. // @Security ApiKeyAuth
  132. // @Param Authorization header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
  133. // @Accept json
  134. // @Product json
  135. // @Param data body myChartModel.MoveMyChartReq true "请求参数"
  136. // @Success 200 {string} string "操作成功"
  137. // @failure 400 {string} string "操作失败"
  138. // @Router /my_chart/moveMyChart [post]
  139. func MoveMyChart(c *gin.Context) {
  140. // 参数校验
  141. var req myChartModel.MoveMyChartReq
  142. if c.ShouldBind(&req) != nil {
  143. response.Fail("参数异常", c)
  144. return
  145. }
  146. if req.MyChartId == 0 {
  147. response.Fail("图表ID有误", c)
  148. return
  149. }
  150. if req.MyChartClassifyId == 0 {
  151. response.Fail("图表分类ID有误", c)
  152. return
  153. }
  154. // 操作权限校验
  155. userInfo := user.GetInfoByClaims(c)
  156. ok, adminInfo, err := user.GetAdminByUserInfo(userInfo)
  157. if err != nil {
  158. response.Fail("操作人信息有误", c)
  159. return
  160. }
  161. if !ok {
  162. response.Fail("非内部人员无权进行操作", c)
  163. return
  164. }
  165. adminId := int(adminInfo.AdminID)
  166. myChassify, err := my_chart_classify.GetClassifyById(req.MyChartClassifyId)
  167. if err != nil {
  168. if err == utils.ErrNoRow {
  169. response.FailMsg("操作失败", "图表分类信息有误, Err:"+err.Error(), c)
  170. return
  171. }
  172. response.FailMsg("操作失败", "获取图表分类信息失败, Err:"+err.Error(), c)
  173. return
  174. }
  175. if myChassify.AdminID != adminId {
  176. response.Fail("无权移动该图表", c)
  177. return
  178. }
  179. // 图表排序
  180. step := float64(65536)
  181. var newSort float64
  182. if req.PrevMyChartId <= 0 {
  183. firstMapItem, err := myChartClassifyMappingModel.GetMyChartSort(adminId, req.MyChartClassifyId, 0)
  184. if err != nil {
  185. response.FailMsg("操作失败", "获取图表排序失败4001, Err:"+err.Error(), c)
  186. return
  187. }
  188. if firstMapItem.Sort <= 0 {
  189. firstSort := step / float64(2)
  190. err = myChartClassifyMappingModel.MyChartMove(firstSort, adminId, firstMapItem.MyChartId, firstMapItem.MyChartClassifyId)
  191. if err != nil {
  192. response.FailMsg("操作失败", "移动失败4001, Err:"+err.Error(), c)
  193. return
  194. }
  195. newSort = step / float64(4)
  196. } else {
  197. newSort = firstMapItem.Sort / float64(2)
  198. }
  199. } else if req.NextMyChartId <= 0 {
  200. latestMapItem, err := myChartClassifyMappingModel.GetMyChartSort(adminId, req.MyChartClassifyId, 1)
  201. if err != nil {
  202. response.FailMsg("操作失败", "获取图表排序失败4002, Err:"+err.Error(), c)
  203. return
  204. }
  205. if latestMapItem.Sort <= 0 {
  206. latestSort := step / float64(2)
  207. err = myChartClassifyMappingModel.MyChartMove(latestSort, adminId, latestMapItem.MyChartId, latestMapItem.MyChartClassifyId)
  208. if err != nil {
  209. response.FailMsg("操作失败", "移动失败4002, Err:"+err.Error(), c)
  210. return
  211. }
  212. newSort = step / float64(4)
  213. } else {
  214. newSort = latestMapItem.Sort + (step / float64(2)) - 1
  215. }
  216. } else {
  217. preMapItem, err := myChartClassifyMappingModel.GetMyChartClassifyMapping(adminId, req.PrevMyChartId, req.MyChartClassifyId)
  218. if err != nil {
  219. response.FailMsg("操作失败", "获取上级图表关联信息失败, Err:"+err.Error(), c)
  220. return
  221. }
  222. nextMapItem, err := myChartClassifyMappingModel.GetMyChartClassifyMapping(adminId, req.NextMyChartId, req.MyChartClassifyId)
  223. if err != nil {
  224. response.FailMsg("操作失败", "获取下级图表关联信息失败, Err:"+err.Error(), c)
  225. return
  226. }
  227. newSort = (preMapItem.Sort + nextMapItem.Sort) / 2
  228. }
  229. if newSort >= 0 {
  230. err = myChartClassifyMappingModel.MyChartMove(newSort, adminId, req.MyChartId, req.MyChartClassifyId)
  231. if err != nil {
  232. response.FailMsg("操作失败", "移动失败4003, Err:"+err.Error(), c)
  233. return
  234. }
  235. }
  236. // 新增操作日志
  237. {
  238. bodyBytes, _ := ioutil.ReadAll(c.Request.Body)
  239. requestBodyStr := string(bodyBytes)
  240. edbLog := new(myChartLogModel.MyChartLog)
  241. edbLog.MyChartId = 0
  242. edbLog.ChartInfoId = 0
  243. edbLog.SysUserId = adminId
  244. edbLog.SysUserRealName = adminInfo.RealName
  245. edbLog.CreateTime = time.Now()
  246. edbLog.Content = requestBodyStr
  247. edbLog.Status = "移动我的图表"
  248. edbLog.Method = c.Request.URL.String()
  249. go edbLog.Create()
  250. }
  251. response.Ok("操作成功", c)
  252. }
  253. // MoveMyChart 移动我的图表分类
  254. // @Tags 图库模块
  255. // @Summary 移动我的图表分类
  256. // @Description 移动我的图表分类
  257. // @Security ApiKeyAuth
  258. // @Param Authorization header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
  259. // @Accept json
  260. // @Product json
  261. // @Param data body myChartModel.MoveMyChartClassifyReq true "请求参数"
  262. // @Success 200 {string} string "操作成功"
  263. // @failure 400 {string} string "操作失败"
  264. // @Router /my_chart/moveMyChartClassify [post]
  265. func MoveMyChartClassify(c *gin.Context) {
  266. // 参数校验
  267. var req myChartModel.MoveMyChartClassifyReq
  268. if c.ShouldBind(&req) != nil {
  269. response.Fail("参数异常", c)
  270. return
  271. }
  272. if req.MyChartClassifyId == 0 {
  273. response.Fail("图表分类ID有误", c)
  274. return
  275. }
  276. // 操作权限校验
  277. userInfo := user.GetInfoByClaims(c)
  278. ok, adminInfo, err := user.GetAdminByUserInfo(userInfo)
  279. if err != nil {
  280. response.Fail("操作人信息有误", c)
  281. return
  282. }
  283. if !ok {
  284. response.Fail("非内部人员无权进行操作", c)
  285. return
  286. }
  287. adminId := int(adminInfo.AdminID)
  288. myChassify, err := my_chart_classify.GetClassifyById(req.MyChartClassifyId)
  289. if err != nil {
  290. if err == utils.ErrNoRow {
  291. response.FailMsg("操作失败", "该图表分类信息有误, Err:", c)
  292. return
  293. }
  294. response.FailMsg("操作失败", "获取图表信息失败"+err.Error(), c)
  295. return
  296. }
  297. if myChassify.AdminID != adminId {
  298. response.Fail("无权移动该图表", c)
  299. return
  300. }
  301. // 移动分类
  302. updateCol := make([]string, 0)
  303. if req.PrevClassifyId > 0 {
  304. prevClassify, err := my_chart_classify.GetClassifyByIdAndAdminId(adminId, req.PrevClassifyId)
  305. if err != nil {
  306. response.FailMsg("操作失败", "移动失败, 获取上一个兄弟节点分类信息失败, Err:"+err.Error(), c)
  307. return
  308. }
  309. // 如果是移动在两个兄弟节点之间
  310. if req.NextClassifyId > 0 {
  311. // 下一个兄弟节点
  312. nextClassify, err := my_chart_classify.GetClassifyByIdAndAdminId(adminId, req.NextClassifyId)
  313. if err != nil {
  314. response.FailMsg("操作失败", "移动失败, 获取下一个兄弟节点分类信息失败, Err:"+err.Error(), c)
  315. return
  316. }
  317. // 如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  318. if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == myChassify.Sort {
  319. // 变更兄弟节点的排序
  320. updateSortStr := `sort + 2`
  321. _ = my_chart_classify.UpdateMyChartClassifySortByClassifyId(adminId, prevClassify.MyChartClassifyId, prevClassify.Sort, updateSortStr)
  322. } else {
  323. // 如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  324. if nextClassify.Sort-prevClassify.Sort == 1 {
  325. // 变更兄弟节点的排序
  326. updateSortStr := `sort + 1`
  327. _ = my_chart_classify.UpdateMyChartClassifySortByClassifyId(adminId, 0, prevClassify.Sort, updateSortStr)
  328. }
  329. }
  330. }
  331. myChassify.Sort = prevClassify.Sort + 1
  332. myChassify.ModifyTime = time.Now()
  333. updateCol = append(updateCol, "Sort", "ModifyTime")
  334. } else {
  335. firstClassify, err := my_chart_classify.GetFirstClassifyByAdminId(adminId)
  336. if err != nil && err != utils.ErrNoRow {
  337. response.FailMsg("操作失败", "移动失败, 获取获取当前账号下的排序第一条的分类信息失败, Err:"+err.Error(), c)
  338. return
  339. }
  340. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  341. if firstClassify != nil && firstClassify.Sort == 0 {
  342. updateSortStr := ` sort + 1 `
  343. _ = my_chart_classify.UpdateMyChartClassifySortByClassifyId(adminId, firstClassify.MyChartClassifyId-1, 0, updateSortStr)
  344. }
  345. myChassify.Sort = 0 //那就是排在第一位
  346. myChassify.ModifyTime = time.Now()
  347. updateCol = append(updateCol, "Sort", "ModifyTime")
  348. }
  349. // 更新
  350. if len(updateCol) > 0 {
  351. err = my_chart_classify.UpdateClassifySort(adminId, myChassify.MyChartClassifyId, myChassify.Sort, myChassify.ModifyTime)
  352. if err != nil {
  353. response.FailMsg("操作失败", "更新图表分类排序失败, Err:"+err.Error(), c)
  354. return
  355. }
  356. }
  357. //新增操作日志
  358. {
  359. bodyBytes, _ := ioutil.ReadAll(c.Request.Body)
  360. requestBodyStr := string(bodyBytes)
  361. edbLog := new(myChartLogModel.MyChartLog)
  362. edbLog.MyChartId = 0
  363. edbLog.ChartInfoId = 0
  364. edbLog.SysUserId = adminId
  365. edbLog.SysUserRealName = adminInfo.RealName
  366. edbLog.CreateTime = time.Now()
  367. edbLog.Content = requestBodyStr
  368. edbLog.Status = "移动分类"
  369. edbLog.Method = c.Request.URL.String()
  370. go edbLog.Create()
  371. }
  372. response.Ok("操作成功", c)
  373. }
  374. // GetChartBeforeAndNext 获取当前图表上一张及下一张信息
  375. // @Tags 图库模块
  376. // @Summary 获取当前图表上一张及下一张信息
  377. // @Description 获取当前图表上一张及下一张信息
  378. // @Security ApiKeyAuth
  379. // @Param Authorization header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
  380. // @Accept json
  381. // @Product json
  382. // @Param MyChartId query string false "我的图表ID"
  383. // @Param MyChartClassifyId query string false "我的图表分类ID"
  384. // @Success 200 {object} chartInfoModel.ChartBeforeNext
  385. // @failure 400 {string} string "获取失败"
  386. // @Router /my_chart/getChartBeforeAndNext [get]
  387. func GetChartBeforeAndNext(c *gin.Context) {
  388. // 参数校验
  389. reqMyChartId := c.DefaultQuery("MyChartId", "")
  390. if reqMyChartId == "" {
  391. response.Fail("参数有误:图表ID", c)
  392. return
  393. }
  394. myChartId, _ := strconv.Atoi(reqMyChartId)
  395. myChartClassifyId := c.DefaultQuery("MyChartClassifyId", "")
  396. if myChartClassifyId == "" {
  397. response.Fail("参数有误:图表分类ID", c)
  398. return
  399. }
  400. // 当前图表
  401. myChartInfo, err := myChartModel.GetMyChartById(myChartId, myChartClassifyId)
  402. if err != nil {
  403. if err == utils.ErrNoRow {
  404. response.Fail("图表已被删除,请刷新当前页面", c)
  405. return
  406. }
  407. response.FailMsg("获取失败", "获取我的图表信息失败, Err:"+err.Error(), c)
  408. return
  409. }
  410. // 获取当前图表所在分类的所有图表信息
  411. myChartList, err := myChartClassifyMappingModel.GetMyChartSortInfoList(myChartClassifyId, 2)
  412. // 找出当前图表前一张及后一张,当前图为最前一张或最后一张时需要取其他分类的图
  413. var currentIndex int
  414. lastIndex := len(myChartList) - 1
  415. for index, item := range myChartList {
  416. if myChartInfo.MyChartId == item.MyChartId {
  417. currentIndex = index
  418. break
  419. }
  420. }
  421. var beforeChart, afterChart *myChartClassifyMappingModel.MyChartSortInfo
  422. beforeIndex := currentIndex - 1
  423. if beforeIndex >= 0 {
  424. // 存在同分类上一张
  425. beforeChart = myChartList[beforeIndex]
  426. }
  427. afterIndex := currentIndex + 1
  428. if afterIndex <= lastIndex {
  429. // 存在同分类下一张
  430. afterChart = myChartList[afterIndex]
  431. }
  432. // 检索其他分类
  433. if beforeIndex < 0 || afterIndex > lastIndex {
  434. // 获取当前用户有权限查看的图表分类
  435. userInfo := user.GetInfoByClaims(c)
  436. publicCondition := make(map[string]interface{})
  437. privateCondition := make(map[string]interface{})
  438. publicClassify, privateClassify, err := chart.GetUserChartClassifyListByCondition(userInfo, publicCondition, privateCondition)
  439. if err != nil {
  440. response.FailMsg("获取失败", "获取图表分类失败, Err:"+err.Error(), c)
  441. return
  442. }
  443. // 合并公共及私有分类
  444. var classifyList []*my_chart_classify.MyChartClassify
  445. for i := 0; i < len(publicClassify); i++ {
  446. classifyList = append(classifyList, publicClassify[i])
  447. }
  448. for i := 0; i < len(privateClassify); i++ {
  449. classifyList = append(classifyList, privateClassify[i])
  450. }
  451. // 获取当前图表分类在所有分类中的位置
  452. var currentClassifyIndex int
  453. for indexClassify, itemClassify := range classifyList {
  454. itemClassifyId := strconv.Itoa(itemClassify.MyChartClassifyId)
  455. if myChartClassifyId == itemClassifyId {
  456. currentClassifyIndex = indexClassify
  457. break
  458. }
  459. }
  460. lastClassifyIndex := len(classifyList) - 1
  461. // 若图表为分类第一张,则取上一个分类最后一张作为上一张返回
  462. beforeClassifyIndex := currentClassifyIndex - 1
  463. if beforeIndex < 0 && len(classifyList) > 0 && beforeClassifyIndex >= 0 {
  464. beforeClassifyIdStr := strconv.Itoa(classifyList[beforeClassifyIndex].MyChartClassifyId)
  465. beforeClassifyChartList, tempErr := myChartClassifyMappingModel.GetMyChartSortInfoList(beforeClassifyIdStr, 1)
  466. if tempErr != nil {
  467. response.FailMsg("获取失败", "获取上一个分类图表信息失败4101, Err:"+tempErr.Error(), c)
  468. return
  469. }
  470. // 上一个分类没有图则继续向上取最后一张直到所取的分类为第一个分类,依旧无图则到顶
  471. SearchPrevChart:
  472. if len(beforeClassifyChartList) > 0 {
  473. beforeChart = beforeClassifyChartList[0]
  474. } else {
  475. beforeClassifyIndex -= 1
  476. if beforeClassifyIndex >= 0 {
  477. beforeClassifyIdStr = strconv.Itoa(classifyList[beforeClassifyIndex].MyChartClassifyId)
  478. beforeClassifyChartList, tempErr = myChartClassifyMappingModel.GetMyChartSortInfoList(beforeClassifyIdStr, 1)
  479. if tempErr != nil {
  480. response.FailMsg("获取失败", "获取上一个分类图表信息失败4102, Err:"+tempErr.Error(), c)
  481. return
  482. }
  483. goto SearchPrevChart
  484. }
  485. }
  486. }
  487. // 若图表为分类最后一张,则取下一个分类第一张作为下一张返回
  488. afterClassifyIndex := currentClassifyIndex + 1
  489. if afterIndex > lastIndex && len(classifyList) > 0 && afterClassifyIndex <= lastClassifyIndex {
  490. afterClassifyIdStr := strconv.Itoa(classifyList[afterClassifyIndex].MyChartClassifyId)
  491. afterClassifyChartList, tempErr := myChartClassifyMappingModel.GetMyChartSortInfoList(afterClassifyIdStr, 2)
  492. if tempErr != nil {
  493. response.FailMsg("获取失败", "获取下一个分类图表信息失败4103, Err:"+tempErr.Error(), c)
  494. return
  495. }
  496. // 下一个分类没有图则继续向下取第一张直到所取的分类为最后一个分类,依旧无图则到底
  497. SearchNextChart:
  498. if len(afterClassifyChartList) > 0 {
  499. afterChart = afterClassifyChartList[0]
  500. } else {
  501. afterClassifyIndex += 1
  502. if afterClassifyIndex <= lastClassifyIndex {
  503. afterClassifyIdStr = strconv.Itoa(classifyList[afterClassifyIndex].MyChartClassifyId)
  504. afterClassifyChartList, tempErr = myChartClassifyMappingModel.GetMyChartSortInfoList(afterClassifyIdStr, 2)
  505. if tempErr != nil {
  506. response.FailMsg("获取失败", "获取下一个分类图表信息失败4104, Err:"+tempErr.Error(), c)
  507. return
  508. }
  509. goto SearchNextChart
  510. }
  511. }
  512. }
  513. }
  514. var beforeResp, afterResp chartInfoModel.ChartSortInfo
  515. if beforeChart != nil {
  516. beforeResp.MyChartId = beforeChart.MyChartId
  517. beforeResp.MyChartClassifyId = beforeChart.MyChartClassifyId
  518. beforeResp.MyChartClassifyName = beforeChart.MyChartClassifyName
  519. beforeResp.Sort = int(beforeChart.Sort)
  520. beforeResp.UniqueCode = beforeChart.UniqueCode
  521. beforeResp.ChartInfoId = beforeChart.ChartInfoId
  522. beforeResp.ChartInfoSource = beforeChart.ChartInfoSource
  523. if beforeIndex < 0 {
  524. beforeResp.Switch = 1
  525. }
  526. }
  527. if afterChart != nil {
  528. afterResp.MyChartId = afterChart.MyChartId
  529. afterResp.MyChartClassifyId = afterChart.MyChartClassifyId
  530. afterResp.MyChartClassifyName = afterChart.MyChartClassifyName
  531. afterResp.Sort = int(afterChart.Sort)
  532. afterResp.UniqueCode = afterChart.UniqueCode
  533. afterResp.ChartInfoId = afterChart.ChartInfoId
  534. afterResp.ChartInfoSource = afterChart.ChartInfoSource
  535. if afterIndex > lastIndex {
  536. afterResp.Switch = 1
  537. }
  538. }
  539. resp := chartInfoModel.ChartBeforeNext{
  540. PrevChart: beforeResp,
  541. NextChart: afterResp,
  542. }
  543. response.OkData("获取成功", resp, c)
  544. }