my_chart.go 21 KB

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