chart_classify.go 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_forum_admin/models"
  5. "eta/eta_forum_admin/models/system"
  6. "eta/eta_forum_admin/services"
  7. "eta/eta_forum_admin/utils"
  8. "fmt"
  9. "github.com/rdlucklib/rdluck_tools/paging"
  10. "sort"
  11. "strconv"
  12. "strings"
  13. "time"
  14. )
  15. // 数据管理-分类模块
  16. type ChartClassifyController struct {
  17. BaseAuthController
  18. }
  19. // ChartClassifyListV2
  20. // @Title 图表分类列表
  21. // @Description 图表分类列表接口
  22. // @Param IsShowMe query bool true "是否只看我的,true、false"
  23. // @Success 200 {object} models.ChartClassifyListResp
  24. // @router /chart_classify/list [get]
  25. func (this *ChartClassifyController) ChartClassifyListV2() {
  26. br := new(models.BaseResponse).Init()
  27. defer func() {
  28. this.Data["json"] = br
  29. this.ServeJSON()
  30. }()
  31. resp := new(models.ChartClassifyListResp)
  32. //判断是否存在缓存,如果存在缓存,那么直接从缓存中获取
  33. key := utils.CACHE_CHART_CLASSIFY
  34. if utils.Re == nil {
  35. if utils.Re == nil && utils.Rc.IsExist(key) {
  36. if redisData, err1 := utils.Rc.RedisBytes(key); err1 == nil {
  37. err := json.Unmarshal(redisData, &resp)
  38. if err == nil && resp != nil {
  39. br.Ret = 200
  40. br.Success = true
  41. br.Msg = "获取成功"
  42. br.Data = resp
  43. fmt.Println("source redis")
  44. return
  45. }
  46. }
  47. }
  48. }
  49. rootList, err := models.GetChartClassifyByParentId(0, utils.CHART_SOURCE_DEFAULT)
  50. if err != nil && err.Error() != utils.ErrNoRow() {
  51. br.Msg = "获取失败"
  52. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  53. return
  54. }
  55. classifyAll, err := models.GetChartClassifyAll(utils.CHART_SOURCE_DEFAULT)
  56. if err != nil && err.Error() != utils.ErrNoRow() {
  57. br.Msg = "获取失败"
  58. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  59. return
  60. }
  61. allChartInfo, err := models.GetChartInfoAll([]int{utils.CHART_SOURCE_DEFAULT})
  62. if err != nil && err.Error() != utils.ErrNoRow() {
  63. br.Msg = "获取失败"
  64. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  65. return
  66. }
  67. chartInfoMap := make(map[int][]*models.ChartClassifyItems)
  68. for _, v := range allChartInfo {
  69. chartInfoMap[v.ChartClassifyId] = append(chartInfoMap[v.ChartClassifyId], v)
  70. }
  71. rootChildMap := make(map[int][]*models.ChartClassifyItems)
  72. for _, v := range classifyAll {
  73. rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
  74. if existItems, ok := chartInfoMap[v.ChartClassifyId]; ok {
  75. v.Children = existItems
  76. } else {
  77. items := make([]*models.ChartClassifyItems, 0)
  78. v.Children = items
  79. }
  80. }
  81. nodeAll := make([]*models.ChartClassifyItems, 0)
  82. for _, v := range rootList {
  83. if existItems, ok := rootChildMap[v.ChartClassifyId]; ok {
  84. v.Children = existItems
  85. } else {
  86. items := make([]*models.ChartClassifyItems, 0)
  87. v.Children = items
  88. }
  89. nodeAll = append(nodeAll, v)
  90. }
  91. //
  92. //
  93. //nodeAll := make([]*models.ChartClassifyItems, 0)
  94. //for k := range rootList {
  95. // rootNode := rootList[k]
  96. // services.ChartClassifyListMakeTree(classifyAll, rootNode)
  97. // nodeAll = append(nodeAll, rootNode)
  98. //}
  99. resp.AllNodes = nodeAll
  100. // 将数据加入缓存
  101. if utils.Re == nil {
  102. redisData, _ := json.Marshal(resp)
  103. utils.Rc.Put(key, redisData, 2*time.Hour)
  104. }
  105. br.Ret = 200
  106. br.Success = true
  107. br.Msg = "获取成功"
  108. br.Data = resp
  109. }
  110. // getChartClassifyListForMe 获取我创建的图表
  111. func getChartClassifyListForMe(adminInfo system.Admin, resp *models.ChartClassifyListResp) (errMsg string, err error) {
  112. rootList, err := models.GetChartClassifyByParentId(0, utils.CHART_SOURCE_DEFAULT)
  113. if err != nil && err.Error() != utils.ErrNoRow() {
  114. errMsg = "获取失败"
  115. return
  116. }
  117. classifyAll, err := models.GetChartClassifyAll(utils.CHART_SOURCE_DEFAULT)
  118. if err != nil && err.Error() != utils.ErrNoRow() {
  119. errMsg = "获取失败"
  120. return
  121. }
  122. allChartInfo, err := models.GetChartInfoByAdminId([]int{utils.CHART_SOURCE_DEFAULT}, adminInfo.AdminId)
  123. if err != nil && err.Error() != utils.ErrNoRow() {
  124. errMsg = "获取失败"
  125. return
  126. }
  127. chartInfoMap := make(map[int][]*models.ChartClassifyItems)
  128. for _, v := range allChartInfo {
  129. chartInfoMap[v.ChartClassifyId] = append(chartInfoMap[v.ChartClassifyId], v)
  130. }
  131. rootChildMap := make(map[int][]*models.ChartClassifyItems)
  132. for _, v := range classifyAll {
  133. rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
  134. if existItems, ok := chartInfoMap[v.ChartClassifyId]; ok {
  135. v.Children = existItems
  136. } else {
  137. items := make([]*models.ChartClassifyItems, 0)
  138. v.Children = items
  139. }
  140. }
  141. nodeAll := make([]*models.ChartClassifyItems, 0)
  142. for _, v := range rootList {
  143. if existItems, ok := rootChildMap[v.ChartClassifyId]; ok {
  144. v.Children = existItems
  145. } else {
  146. items := make([]*models.ChartClassifyItems, 0)
  147. v.Children = items
  148. }
  149. nodeAll = append(nodeAll, v)
  150. }
  151. resp.AllNodes = nodeAll
  152. return
  153. }
  154. // SimpleList
  155. // @Title 单层分类列表
  156. // @Description 单层分类列表
  157. // @Success 200 {object} data_manage.EdbClassifyListResp
  158. // @router /classify/simple [get]
  159. func (this *ChartClassifyController) SimpleList() {
  160. br := new(models.BaseResponse).Init()
  161. defer func() {
  162. this.Data["json"] = br
  163. this.ServeJSON()
  164. }()
  165. // 默认查一级分类和一级分类下的指标信息,
  166. // 如果是 子级分类,查询该子级分类的下一级分类和指标信息
  167. // 增加标识判断是文件夹还是指标列表
  168. reqParentId, _ := this.GetInt("ParentId")
  169. parentId := 0
  170. nodeAll := make([]*models.ChartClassifyItems, 0)
  171. // 处理未分类
  172. //查询未分类的指标列表
  173. if reqParentId == -1 {
  174. initClassify := &models.ChartClassifyItems{
  175. ChartClassifyId: 0,
  176. ChartInfoId: 0,
  177. ChartClassifyName: "未分类",
  178. ChartClassifyNameEn: "",
  179. ParentId: 0,
  180. Level: 1,
  181. Sort: 0,
  182. }
  183. nodeAll = append(nodeAll, initClassify)
  184. } else {
  185. parentId = reqParentId
  186. }
  187. rootList := make([]*models.ChartClassifyItems, 0)
  188. var err error
  189. if reqParentId == -1 {
  190. rootList, err = models.GetChartClassifyByParentId(parentId, utils.CHART_SOURCE_DEFAULT)
  191. if err != nil && err.Error() != utils.ErrNoRow() {
  192. br.Msg = "获取失败"
  193. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  194. return
  195. }
  196. }
  197. var sortList models.ChartClassifyItemList
  198. if reqParentId >= 0 {
  199. // 查询挂在当前分类上的图表列表
  200. allChartInfo, e := models.GetChartInfoAllByClassifyId(utils.CHART_SOURCE_DEFAULT, parentId)
  201. if e != nil && e.Error() != utils.ErrNoRow() {
  202. br.Msg = "获取失败"
  203. br.ErrMsg = "获取图表信息失败,Err:" + e.Error()
  204. return
  205. }
  206. if len(allChartInfo) > 0 {
  207. for _, v := range allChartInfo {
  208. v.Children = make([]*models.ChartClassifyItems, 0)
  209. v.Company = "弘则研究"
  210. nodeAll = append(nodeAll, v)
  211. }
  212. }
  213. }
  214. if len(rootList) > 0 {
  215. for _, v := range rootList {
  216. v.Children = make([]*models.ChartClassifyItems, 0)
  217. nodeAll = append(nodeAll, v)
  218. }
  219. }
  220. if len(nodeAll) > 0 {
  221. //根据sort值排序
  222. sortList = nodeAll
  223. sort.Sort(sortList)
  224. }
  225. language := `CN`
  226. // 指标显示的语言
  227. {
  228. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.EdbLanguageVar)
  229. if configDetail != nil {
  230. language = configDetail.ConfigValue
  231. } else {
  232. configDetail, _ = system.GetDefaultConfigDetailByCode(system.EdbLanguageVar)
  233. if configDetail != nil {
  234. language = configDetail.ConfigValue
  235. }
  236. }
  237. }
  238. resp := new(models.ChartClassifyListResp)
  239. if len(nodeAll) > 0 {
  240. resp.AllNodes = sortList
  241. } else {
  242. resp.AllNodes = nodeAll
  243. }
  244. resp.Language = language
  245. br.Ret = 200
  246. br.Success = true
  247. br.Msg = "获取成功"
  248. br.Data = resp
  249. }
  250. // ChartClassifyItems
  251. // @Title 获取所有图表分类接口-不包含图表
  252. // @Description 获取所有图表分类接口-不包含图表
  253. // @Success 200 {object} models.ChartClassifyListResp
  254. // @router /chart_classify/items [get]
  255. func (this *ChartClassifyController) ChartClassifyItems() {
  256. br := new(models.BaseResponse).Init()
  257. defer func() {
  258. this.Data["json"] = br
  259. this.ServeJSON()
  260. }()
  261. rootList, err := models.GetChartClassifyByParentId(0, utils.CHART_SOURCE_DEFAULT)
  262. if err != nil {
  263. br.Msg = "获取失败"
  264. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  265. return
  266. }
  267. classifyAll, err := models.GetChartClassifyAll(utils.CHART_SOURCE_DEFAULT)
  268. if err != nil {
  269. br.Msg = "获取失败"
  270. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  271. return
  272. }
  273. nodeAll := make([]*models.ChartClassifyItems, 0)
  274. for k := range rootList {
  275. rootNode := rootList[k]
  276. services.ChartClassifyItemsMakeTree(this.SysUser, classifyAll, rootNode)
  277. nodeAll = append(nodeAll, rootNode)
  278. }
  279. language := `CN`
  280. // 指标显示的语言
  281. {
  282. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.ChartLanguageVar)
  283. if configDetail != nil {
  284. language = configDetail.ConfigValue
  285. } else {
  286. configDetail, _ = system.GetDefaultConfigDetailByCode(system.ChartLanguageVar)
  287. if configDetail != nil {
  288. language = configDetail.ConfigValue
  289. }
  290. }
  291. }
  292. // 是否允许添加分类
  293. canOpClassify := true
  294. // 如果不是 超管 或者 ficc管理员 或者 ficc研究员,那么就没有权限
  295. //if !utils.InArrayByStr([]string{utils.ROLE_TYPE_CODE_ADMIN, utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_RESEARCHR, utils.ROLE_TYPE_CODE_FICC_RESEARCHR}, this.SysUser.RoleTypeCode) {
  296. // canOpClassify = false
  297. //}
  298. resp := models.ChartClassifyListResp{
  299. AllNodes: nodeAll,
  300. Language: language,
  301. CanOpClassify: canOpClassify,
  302. }
  303. br.Ret = 200
  304. br.Success = true
  305. br.Msg = "获取成功"
  306. br.Data = resp
  307. }
  308. // @Title 新增图表分类
  309. // @Description 新增图表分类接口
  310. // @Param request body models.AddChartClassifyReq true "type json string"
  311. // @Success 200 Ret=200 保存成功
  312. // @router /classify/add [post]
  313. func (this *ChartClassifyController) AddChartClassify() {
  314. br := new(models.BaseResponse).Init()
  315. defer func() {
  316. this.Data["json"] = br
  317. this.ServeJSON()
  318. }()
  319. var req models.AddChartClassifyReq
  320. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  321. if err != nil {
  322. br.Msg = "参数解析异常!"
  323. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  324. return
  325. }
  326. if req.ChartClassifyName == "" {
  327. br.Msg = "请输入分类名称"
  328. br.IsSendEmail = false
  329. return
  330. }
  331. if req.ParentId < 0 {
  332. br.Msg = "参数错误"
  333. br.IsSendEmail = false
  334. return
  335. }
  336. // 新增图表分类
  337. _, err, errMsg, isSendEmail := services.AddChartClassify(req.ChartClassifyName, req.ParentId, utils.CHART_SOURCE_DEFAULT, this.Lang, this.SysUser)
  338. if err != nil {
  339. br.Msg = errMsg
  340. br.ErrMsg = "添加分类失败,Err:" + err.Error()
  341. br.IsSendEmail = isSendEmail
  342. return
  343. }
  344. br.Ret = 200
  345. br.Msg = "保存成功"
  346. br.Success = true
  347. }
  348. // EditChartClassify
  349. // @Title 修改图表分类
  350. // @Description 修改图表分类接口
  351. // @Param request body models.EditChartClassifyReq true "type json string"
  352. // @Success 200 Ret=200 修改成功
  353. // @router /classify/edit [post]
  354. func (this *ChartClassifyController) EditChartClassify() {
  355. br := new(models.BaseResponse).Init()
  356. defer func() {
  357. this.Data["json"] = br
  358. this.ServeJSON()
  359. }()
  360. var req models.EditChartClassifyReq
  361. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  362. if err != nil {
  363. br.Msg = "参数解析异常!"
  364. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  365. return
  366. }
  367. if req.ChartClassifyName == "" {
  368. br.Msg = "请输入分类名称"
  369. br.IsSendEmail = false
  370. return
  371. }
  372. if req.ChartClassifyId <= 0 {
  373. br.Msg = "参数错误"
  374. br.IsSendEmail = false
  375. return
  376. }
  377. // 编辑图表分类
  378. _, err, errMsg, isSendEmail := services.EditChartClassify(req.ChartClassifyId, utils.CHART_SOURCE_DEFAULT, req.ChartClassifyName, this.Lang, this.SysUser)
  379. if err != nil {
  380. br.Msg = errMsg
  381. br.ErrMsg = "保存分类失败,Err:" + err.Error()
  382. br.IsSendEmail = isSendEmail
  383. return
  384. }
  385. br.Ret = 200
  386. br.Msg = "保存成功"
  387. br.Success = true
  388. br.IsAddLog = true
  389. }
  390. // @Title 删除图表检测接口
  391. // @Description 删除图表检测接口
  392. // @Param request body models.ChartClassifyDeleteCheckResp true "type json string"
  393. // @Success 200 Ret=200 检测成功
  394. // @router /chart_classify/delete/check [post]
  395. func (this *ChartClassifyController) DeleteChartClassifyCheck() {
  396. br := new(models.BaseResponse).Init()
  397. defer func() {
  398. this.Data["json"] = br
  399. this.ServeJSON()
  400. }()
  401. var req models.ChartClassifyDeleteCheckReq
  402. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  403. if err != nil {
  404. br.Msg = "参数解析异常!"
  405. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  406. return
  407. }
  408. if req.ChartClassifyId < 0 && req.ChartInfoId <= 0 {
  409. br.Msg = "参数错误"
  410. br.IsSendEmail = false
  411. return
  412. }
  413. var deleteStatus int
  414. var tipsMsg string
  415. //删除分类
  416. if req.ChartClassifyId > 0 && req.ChartInfoId == 0 {
  417. // 查找分类
  418. /*item, err := models.GetChartClassifyById(req.ChartClassifyId)
  419. if err != nil {
  420. br.Msg = "保存失败"
  421. br.Msg = "获取分类信息失败,Err:" + err.Error()
  422. return
  423. }
  424. // 已授权分类id
  425. permissionClassifyIdList, err := data_manage_permission.GetUserChartClassifyPermissionList(this.SysUser.AdminId, item.ChartClassifyId)
  426. if err != nil {
  427. br.Msg = "获取失败"
  428. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  429. return
  430. }
  431. // todo 删除是否需要加权限校验
  432. {
  433. haveOperaAuth := data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(item.IsJoinPermission, item.ChartClassifyId, permissionClassifyIdList)
  434. button := services.GetChartClassifyOpButton(this.SysUser, item.SysUserId, haveOperaAuth)
  435. if !button.OpButton {
  436. br.Msg = "无操作权限"
  437. br.IsSendEmail = false
  438. return
  439. }
  440. }*/
  441. //判断图表分类下,是否含有图表
  442. count, err := models.GetChartInfoCountByClassifyId(req.ChartClassifyId)
  443. if err != nil {
  444. br.Msg = "删除失败"
  445. br.ErrMsg = "分类下是否含有指标失败,Err:" + err.Error()
  446. return
  447. }
  448. if count > 0 {
  449. deleteStatus = 1
  450. tipsMsg = "该分类下关联图表不可删除"
  451. }
  452. }
  453. if deleteStatus != 1 && req.ChartInfoId == 0 {
  454. classifyCount, err := models.GetChartClassifyCountByClassifyId(req.ChartClassifyId)
  455. if err != nil && err.Error() != utils.ErrNoRow() {
  456. br.Msg = "删除失败"
  457. br.ErrMsg = "分类下是否含有图表失败,Err:" + err.Error()
  458. return
  459. }
  460. if classifyCount > 0 {
  461. deleteStatus = 2
  462. tipsMsg = "确认删除当前目录及包含的子目录吗"
  463. }
  464. }
  465. if deleteStatus == 0 {
  466. tipsMsg = "可删除,进行删除操作"
  467. }
  468. resp := new(models.ChartClassifyDeleteCheckResp)
  469. resp.DeleteStatus = deleteStatus
  470. resp.TipsMsg = tipsMsg
  471. br.Ret = 200
  472. br.Msg = "检测成功"
  473. br.Success = true
  474. br.Data = resp
  475. }
  476. // @Title 删除图表分类/图表
  477. // @Description 删除图表分类/图表接口
  478. // @Param request body models.DeleteChartClassifyReq true "type json string"
  479. // @Success 200 Ret=200 删除成功
  480. // @router /classify/delete [post]
  481. func (this *ChartClassifyController) DeleteChartClassify() {
  482. br := new(models.BaseResponse).Init()
  483. defer func() {
  484. this.Data["json"] = br
  485. this.ServeJSON()
  486. }()
  487. sysUser := this.SysUser
  488. if sysUser == nil {
  489. br.Msg = "请登录"
  490. br.ErrMsg = "请登录,SysUser Is Empty"
  491. br.Ret = 408
  492. return
  493. }
  494. var req models.DeleteChartClassifyReq
  495. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  496. if err != nil {
  497. br.Msg = "参数解析异常!"
  498. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  499. return
  500. }
  501. if req.ChartClassifyId < 0 {
  502. br.Msg = "参数错误"
  503. br.IsSendEmail = false
  504. return
  505. }
  506. //删除分类
  507. _, err = models.GetChartClassifyById(req.ChartClassifyId)
  508. if err != nil {
  509. if err.Error() == utils.ErrNoRow() {
  510. br.Msg = "分类不存在,请刷新"
  511. return
  512. }
  513. br.Msg = "操作失败"
  514. br.Msg = "获取分类信息失败,Err:" + err.Error()
  515. return
  516. }
  517. //判断是否含有指标
  518. count, err := models.GetChartInfoCountByClassifyId(req.ChartClassifyId)
  519. if err != nil && err.Error() != utils.ErrNoRow() {
  520. br.Msg = "删除失败"
  521. br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  522. return
  523. }
  524. if count > 0 {
  525. br.Msg = "该目录下存在关联指标,不可删除"
  526. br.IsSendEmail = false
  527. return
  528. }
  529. err = models.DeleteChartClassify(req.ChartClassifyId)
  530. if err != nil {
  531. br.Msg = "删除失败"
  532. br.ErrMsg = "删除失败,Err:" + err.Error()
  533. return
  534. }
  535. resp := new(models.AddChartInfoResp)
  536. br.Ret = 200
  537. br.Msg = "删除成功"
  538. br.Success = true
  539. br.Data = resp
  540. br.IsAddLog = true
  541. }
  542. // ChartClassifyMove
  543. // @Title 图表分类移动接口
  544. // @Description 图表分类移动接口
  545. // @Success 200 {object} models.MoveChartClassifyReq
  546. // @router /classify/move [post]
  547. func (this *ChartClassifyController) ChartClassifyMove() {
  548. br := new(models.BaseResponse).Init()
  549. defer func() {
  550. if br.ErrMsg == "" {
  551. br.IsSendEmail = false
  552. }
  553. this.Data["json"] = br
  554. this.ServeJSON()
  555. }()
  556. sysUser := this.SysUser
  557. if sysUser == nil {
  558. br.Msg = "请登录"
  559. br.ErrMsg = "请登录,SysUser Is Empty"
  560. br.Ret = 408
  561. return
  562. }
  563. var req models.MoveChartClassifyReq
  564. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  565. if err != nil {
  566. br.Msg = "参数解析异常!"
  567. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  568. return
  569. }
  570. if req.ClassifyId <= 0 {
  571. br.Msg = "参数错误"
  572. br.ErrMsg = "分类id小于等于0"
  573. return
  574. }
  575. //判断分类是否存在
  576. /*chartClassifyInfo, err := models.GetChartClassifyById(req.ClassifyId)
  577. if err != nil {
  578. if err.Error() == utils.ErrNoRow() {
  579. br.Msg = "分类不存在,请刷新页面"
  580. return
  581. }
  582. br.Msg = "移动失败"
  583. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  584. return
  585. }
  586. // 校验移动的父级目录下是否有重名分类
  587. exists, e := models.GetChartClassifyByParentIdAndName(req.ParentClassifyId, chartClassifyInfo.ChartClassifyName, req.ClassifyId)
  588. if e != nil && e.Error() != utils.ErrNoRow() {
  589. br.Msg = "移动失败"
  590. br.ErrMsg = "获取父级目录下的同名分类失败, Err: " + e.Error()
  591. return
  592. }
  593. if exists != nil {
  594. br.Msg = "移动失败,分类名称已存在"
  595. return
  596. }
  597. if chartClassifyInfo.Source != utils.CHART_SOURCE_DEFAULT {
  598. br.Msg = "分类异常"
  599. br.ErrMsg = "分类异常,不是ETA图库的分类"
  600. return
  601. }
  602. updateCol := make([]string, 0)
  603. //判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
  604. if chartClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId != 0 {
  605. parentChartClassifyInfo, err := models.GetChartClassifyById(req.ParentClassifyId)
  606. if err != nil {
  607. br.Msg = "移动失败"
  608. br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error()
  609. return
  610. }
  611. chartClassifyInfo.ParentId = parentChartClassifyInfo.ChartClassifyId
  612. chartClassifyInfo.Level = parentChartClassifyInfo.Level + 1
  613. chartClassifyInfo.ModifyTime = time.Now()
  614. updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  615. }
  616. //如果有传入 上一个兄弟节点分类id
  617. if req.PrevClassifyId > 0 {
  618. //上一个兄弟节点
  619. prevClassify, err := models.GetChartClassifyById(req.PrevClassifyId)
  620. if err != nil {
  621. br.Msg = "移动失败"
  622. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  623. return
  624. }
  625. //如果是移动在两个兄弟节点之间
  626. if req.NextClassifyId > 0 {
  627. //下一个兄弟节点
  628. nextClassify, err := models.GetChartClassifyById(req.NextClassifyId)
  629. if err != nil {
  630. br.Msg = "移动失败"
  631. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  632. return
  633. }
  634. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  635. if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == chartClassifyInfo.Sort {
  636. //变更兄弟节点的排序
  637. updateSortStr := `sort + 2`
  638. _ = models.UpdateChartClassifySortByParentId(prevClassify.ParentId, prevClassify.ChartClassifyId, prevClassify.Sort, updateSortStr)
  639. } else {
  640. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  641. if nextClassify.Sort-prevClassify.Sort == 1 {
  642. //变更兄弟节点的排序
  643. updateSortStr := `sort + 1`
  644. _ = models.UpdateChartClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr)
  645. }
  646. }
  647. }
  648. chartClassifyInfo.Sort = prevClassify.Sort + 1
  649. chartClassifyInfo.ModifyTime = time.Now()
  650. updateCol = append(updateCol, "Sort", "ModifyTime")
  651. } else {
  652. firstClassify, err := models.GetFirstChartClassifyByParentId(chartClassifyInfo.ParentId)
  653. if err != nil && err.Error() != utils.ErrNoRow() {
  654. br.Msg = "移动失败"
  655. br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  656. return
  657. }
  658. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  659. if firstClassify != nil && firstClassify.Sort == 0 {
  660. updateSortStr := ` sort + 1 `
  661. _ = models.UpdateChartClassifySortByParentId(firstClassify.ParentId, firstClassify.ChartClassifyId-1, 0, updateSortStr)
  662. }
  663. chartClassifyInfo.Sort = 0 //那就是排在第一位
  664. chartClassifyInfo.ModifyTime = time.Now()
  665. updateCol = append(updateCol, "Sort", "ModifyTime")
  666. }
  667. //更新
  668. if len(updateCol) > 0 {
  669. err = chartClassifyInfo.Update(updateCol)
  670. if err != nil {
  671. br.Msg = "移动失败"
  672. br.ErrMsg = "修改失败,Err:" + err.Error()
  673. return
  674. }
  675. }*/
  676. err, errMsg := services.MoveChartClassify(req, sysUser, 0)
  677. if errMsg != `` {
  678. br.Msg = errMsg
  679. br.ErrMsg = errMsg
  680. if err != nil {
  681. br.ErrMsg = err.Error()
  682. } else {
  683. br.IsSendEmail = false
  684. }
  685. return
  686. }
  687. br.Ret = 200
  688. br.Success = true
  689. br.Msg = "移动成功"
  690. }
  691. // getChartClassifyListForMe 获取我创建的图表分类
  692. func getChartClassifyListForMeV2(adminInfo system.Admin, resp *models.ChartClassifyListResp) (errMsg string, err error) {
  693. rootList, err := models.GetChartClassifyByParentId(0, utils.CHART_SOURCE_DEFAULT)
  694. if err != nil && err.Error() != utils.ErrNoRow() {
  695. errMsg = "获取失败"
  696. return
  697. }
  698. classifyAll, err := models.GetChartClassifyAll(utils.CHART_SOURCE_DEFAULT)
  699. if err != nil && err.Error() != utils.ErrNoRow() {
  700. errMsg = "获取失败"
  701. return
  702. }
  703. rootChildMap := make(map[int][]*models.ChartClassifyItems)
  704. for _, v := range classifyAll {
  705. rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
  706. }
  707. nodeAll := make([]*models.ChartClassifyItems, 0)
  708. for _, v := range rootList {
  709. if existItems, ok := rootChildMap[v.ChartClassifyId]; ok {
  710. v.Children = existItems
  711. } else {
  712. items := make([]*models.ChartClassifyItems, 0)
  713. v.Children = items
  714. }
  715. nodeAll = append(nodeAll, v)
  716. }
  717. resp.AllNodes = nodeAll
  718. return
  719. }
  720. // ChartClassifyChartListV2
  721. // @Title 根据图表分类获取图表列表
  722. // @Description 根据图表分类获取图表列表接口
  723. // @Param SysUserIds query string true "根据创建人查询"
  724. // @Param ChartClassifyId query bool true "图片分类id"
  725. // @Success 200 {object} models.ChartClassifyListResp
  726. // @router /classify/chart_list [get]
  727. func (this *ChartClassifyController) ChartClassifyChartListV2() {
  728. br := new(models.BaseResponse).Init()
  729. defer func() {
  730. this.Data["json"] = br
  731. this.ServeJSON()
  732. }()
  733. sysUser := this.SysUser
  734. if sysUser == nil {
  735. br.Msg = "请登录"
  736. br.ErrMsg = "请登录,SysUser Is Empty"
  737. br.Ret = 408
  738. return
  739. }
  740. resp := new(models.ChartClassifyListResp)
  741. chartClassifyId, _ := this.GetInt("ChartClassifyId")
  742. if chartClassifyId < 0 && chartClassifyId != -1 {
  743. br.Msg = "参数错误"
  744. return
  745. }
  746. pageSize, _ := this.GetInt("PageSize")
  747. currentIndex, _ := this.GetInt("CurrentIndex")
  748. var startSize int
  749. if pageSize <= 0 {
  750. pageSize = utils.PageSize20
  751. }
  752. if currentIndex <= 0 {
  753. currentIndex = 1
  754. }
  755. startSize = utils.StartIndex(currentIndex, pageSize)
  756. sysUserIds := this.GetString("SysUserIds")
  757. allChartInfo := make([]*models.ChartClassifyItems, 0)
  758. var err error
  759. var total int64
  760. if sysUserIds != "" {
  761. adminIds := strings.Split(sysUserIds, ",")
  762. if len(adminIds) == 0 {
  763. br.Msg = "请选择正确的创建人"
  764. return
  765. }
  766. adminIdsSlice := make([]int, 0)
  767. for _, adminId := range adminIds {
  768. adminIdInt, e := strconv.Atoi(adminId)
  769. if e != nil {
  770. br.Msg = "请选择正确的创建人"
  771. return
  772. }
  773. adminIdsSlice = append(adminIdsSlice, adminIdInt)
  774. }
  775. allChartInfo, err = models.GetChartInfoByAdminIdAndClassify([]int{utils.CHART_SOURCE_DEFAULT}, adminIdsSlice, chartClassifyId, startSize, pageSize)
  776. if err != nil && err.Error() != utils.ErrNoRow() {
  777. br.Msg = "获取失败"
  778. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  779. return
  780. }
  781. total, err = models.GetChartInfoTotalByAdminIdAndClassify([]int{utils.CHART_SOURCE_DEFAULT}, adminIdsSlice, chartClassifyId)
  782. if err != nil {
  783. br.Msg = "获取失败"
  784. br.ErrMsg = "获取图表总数失败,Err:" + err.Error()
  785. return
  786. }
  787. } else {
  788. allChartInfo, err = models.GetChartInfoByClassifyId(utils.CHART_SOURCE_DEFAULT, chartClassifyId, startSize, pageSize)
  789. if err != nil && err.Error() != utils.ErrNoRow() {
  790. br.Msg = "获取失败"
  791. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  792. return
  793. }
  794. total, err = models.GetChartInfoTotalByClassifyId(utils.CHART_SOURCE_DEFAULT, chartClassifyId)
  795. if err != nil {
  796. br.Msg = "获取失败"
  797. br.ErrMsg = "获取图表总数失败,Err:" + err.Error()
  798. return
  799. }
  800. }
  801. if len(allChartInfo) > 0 {
  802. for k, _ := range allChartInfo {
  803. allChartInfo[k].Company = "弘则研究"
  804. }
  805. }
  806. page := paging.GetPaging(currentIndex, pageSize, int(total))
  807. resp.AllNodes = allChartInfo
  808. resp.Paging = page
  809. br.Ret = 200
  810. br.Success = true
  811. br.Msg = "获取成功"
  812. br.Data = resp
  813. }