warehouse_classify.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. package trade_analysis
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/controllers"
  5. "eta/eta_api/models"
  6. "eta/eta_api/models/data_manage"
  7. "eta/eta_api/models/system"
  8. "eta/eta_api/services/data"
  9. correlationServ "eta/eta_api/services/data/correlation"
  10. "eta/eta_api/services/data/data_manage_permission"
  11. "eta/eta_api/utils"
  12. "fmt"
  13. "sort"
  14. "time"
  15. )
  16. // WarehouseClassifyController 建仓过程-分类
  17. type WarehouseClassifyController struct {
  18. controllers.BaseAuthController
  19. }
  20. //func (c *WarehouseClassifyController) ClassifyMove() {
  21. // br := new(models.BaseResponse).Init()
  22. // defer func() {
  23. // if br.ErrMsg == "" {
  24. // br.IsSendEmail = false
  25. // }
  26. // c.Data["json"] = br
  27. // c.ServeJSON()
  28. // }()
  29. // var pars models.CommonClassifyMoveReq
  30. //
  31. // classifyOb := new(trade_analysis.WareHouseProcessClassify)
  32. // ctx := data.NewCommonClassifyCtx(classifyOb)
  33. //
  34. // tips, e := data.CommonClassifyMove(pars, ctx)
  35. // if tips != "" {
  36. // br.Msg = tips
  37. // return
  38. // }
  39. // if e != nil {
  40. // br.Msg = "操作失败"
  41. // br.ErrMsg = fmt.Sprintf("移动失败, %v", e)
  42. // return
  43. // }
  44. //
  45. // br.Ret = 200
  46. // br.Success = true
  47. // br.Msg = "操作成功"
  48. //}
  49. // ChartClassifyList
  50. // @Title 分类列表
  51. // @Description 分类列表接口
  52. // @Param IsShowMe query bool false "是否只看我的,true、false"
  53. // @Param ParentId query bool false "父级ID"
  54. // @Param Source query int false "图表类型,3:相关性,4:滚动相关性"
  55. // @Success 200 {object} data_manage.ChartClassifyListResp
  56. // @router /warehouse/classify/list [get]
  57. func (this *WarehouseClassifyController) ChartClassifyList() {
  58. br := new(models.BaseResponse).Init()
  59. defer func() {
  60. if br.ErrMsg == "" {
  61. br.IsSendEmail = false
  62. }
  63. this.Data["json"] = br
  64. this.ServeJSON()
  65. }()
  66. resp := new(data_manage.ChartClassifyListResp)
  67. isShowMe, _ := this.GetBool("IsShowMe")
  68. parentId, _ := this.GetInt("ParentId")
  69. source, _ := this.GetInt("Source", utils.CHART_SOURCE_TRADE_ANALYSIS_PROCESS)
  70. nodeAll := make([]*data_manage.ChartClassifyItems, 0)
  71. // 查询分类节点
  72. rootList, err := data_manage.GetChartClassifyByParentId(parentId, utils.CHART_SOURCE_TRADE_ANALYSIS_PROCESS)
  73. if err != nil && err.Error() != utils.ErrNoRow() {
  74. br.Msg = "获取失败"
  75. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  76. return
  77. }
  78. if len(rootList) > 0 {
  79. permissionClassifyIdList, e := data_manage_permission.GetUserChartClassifyPermissionList(this.SysUser.AdminId, 0)
  80. if e != nil {
  81. br.Msg = "获取失败"
  82. br.ErrMsg = "获取已授权分类id数据失败,Err:" + e.Error()
  83. return
  84. }
  85. for _, v := range rootList {
  86. // 操作按钮权限
  87. v.HaveOperaAuth = data_manage_permission.CheckChartClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ChartClassifyId, permissionClassifyIdList)
  88. button := data.GetChartClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  89. v.Button = button
  90. v.ParentId = parentId
  91. v.Children = make([]*data_manage.ChartClassifyItems, 0)
  92. nodeAll = append(nodeAll, v)
  93. }
  94. }
  95. // 查询图表节点, ParentId=0时说明仅查询一级目录节点
  96. if parentId > 0 {
  97. // 查询当前分类信息
  98. currClassify, e := data_manage.GetChartClassifyById(parentId)
  99. if e != nil {
  100. br.Msg = "获取失败"
  101. br.ErrMsg = "获取当前分类信息失败,Err:" + e.Error()
  102. return
  103. }
  104. // 获取所有有权限的指标和分类
  105. permissionEdbIdList, permissionClassifyIdList, e := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  106. if e != nil {
  107. br.Msg = "获取失败"
  108. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + e.Error()
  109. return
  110. }
  111. var adminId int
  112. if isShowMe {
  113. adminId = this.SysUser.AdminId
  114. }
  115. charts, e := data_manage.GetChartInfoBySourceAndParentId(source, parentId, adminId)
  116. if e != nil {
  117. br.Msg = "获取失败"
  118. br.ErrMsg = fmt.Sprintf("获取图表信息失败, Err: %v", e)
  119. return
  120. }
  121. for _, v := range charts {
  122. // 操作按钮权限
  123. v.HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.ChartInfoId, v.ChartClassifyId, permissionEdbIdList, permissionClassifyIdList)
  124. button := data.GetChartOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  125. button.AddButton = false //不管有没有权限,图表都是没有添加按钮的
  126. v.Button = button
  127. v.ParentId = parentId
  128. v.Children = make([]*data_manage.ChartClassifyItems, 0)
  129. nodeAll = append(nodeAll, v)
  130. }
  131. }
  132. // 整体排序
  133. if len(nodeAll) > 0 {
  134. sort.Slice(nodeAll, func(i, j int) bool {
  135. return nodeAll[i].Sort < nodeAll[j].Sort
  136. })
  137. }
  138. resp.AllNodes = nodeAll
  139. br.Ret = 200
  140. br.Success = true
  141. br.Msg = "获取成功"
  142. br.Data = resp
  143. }
  144. // ChartClassifyItems
  145. // @Title 获取所有分类接口-不包含图表
  146. // @Description 获取所有分类接口-不包含图表
  147. // @Success 200 {object} data_manage.ChartClassifyListResp
  148. // @router /warehouse/classify/items [get]
  149. func (this *WarehouseClassifyController) ChartClassifyItems() {
  150. br := new(models.BaseResponse).Init()
  151. defer func() {
  152. this.Data["json"] = br
  153. this.ServeJSON()
  154. }()
  155. rootList, err := data_manage.GetChartClassifyByParentId(0, utils.CHART_SOURCE_TRADE_ANALYSIS_PROCESS)
  156. if err != nil {
  157. br.Msg = "获取失败"
  158. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  159. return
  160. }
  161. nodeAll := make([]*data_manage.ChartClassifyItems, 0)
  162. for k := range rootList {
  163. rootNode := rootList[k]
  164. nodeAll = append(nodeAll, rootNode)
  165. }
  166. resp := new(data_manage.ChartClassifyListResp)
  167. resp.AllNodes = nodeAll
  168. br.Ret = 200
  169. br.Success = true
  170. br.Msg = "获取成功"
  171. br.Data = resp
  172. }
  173. // AddChartClassify
  174. // @Title 新增分类
  175. // @Description 新增分类接口
  176. // @Param request body data_manage.AddChartClassifyReq true "type json string"
  177. // @Success 200 Ret=200 保存成功
  178. // @router /warehouse/classify/add [post]
  179. func (this *WarehouseClassifyController) AddChartClassify() {
  180. br := new(models.BaseResponse).Init()
  181. defer func() {
  182. this.Data["json"] = br
  183. this.ServeJSON()
  184. }()
  185. var req data_manage.AddChartClassifyReq
  186. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  187. if err != nil {
  188. br.Msg = "参数解析异常!"
  189. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  190. return
  191. }
  192. if req.ChartClassifyName == "" {
  193. br.Msg = "请输入分类名称"
  194. br.IsSendEmail = false
  195. return
  196. }
  197. if req.ParentId < 0 {
  198. br.Msg = "参数错误"
  199. br.IsSendEmail = false
  200. return
  201. }
  202. // 新增图表分类
  203. _, err, errMsg, isSendEmail := data.AddChartClassify(req.ChartClassifyName, req.ParentId, req.Level, utils.CHART_SOURCE_TRADE_ANALYSIS_PROCESS, this.Lang, this.SysUser)
  204. if err != nil {
  205. br.Msg = errMsg
  206. br.ErrMsg = "添加分类失败,Err:" + err.Error()
  207. br.IsSendEmail = isSendEmail
  208. return
  209. }
  210. br.Ret = 200
  211. br.Msg = "添加成功"
  212. br.Success = true
  213. }
  214. // EditChartClassify
  215. // @Title 修改分类
  216. // @Description 修改分类接口
  217. // @Param request body data_manage.EditChartClassifyReq true "type json string"
  218. // @Success 200 Ret=200 修改成功
  219. // @router /warehouse/classify/edit [post]
  220. func (this *WarehouseClassifyController) EditChartClassify() {
  221. br := new(models.BaseResponse).Init()
  222. defer func() {
  223. this.Data["json"] = br
  224. this.ServeJSON()
  225. }()
  226. var req data_manage.EditChartClassifyReq
  227. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  228. if err != nil {
  229. br.Msg = "参数解析异常!"
  230. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  231. return
  232. }
  233. if req.ChartClassifyName == "" {
  234. br.Msg = "请输入分类名称"
  235. br.IsSendEmail = false
  236. return
  237. }
  238. if req.ChartClassifyId <= 0 {
  239. br.Msg = "参数错误"
  240. br.IsSendEmail = false
  241. return
  242. }
  243. // 编辑图表分类
  244. _, err, errMsg, isSendEmail := data.EditChartClassify(req.ChartClassifyId, utils.CHART_SOURCE_TRADE_ANALYSIS_PROCESS, req.ChartClassifyName, this.Lang, this.SysUser)
  245. if err != nil {
  246. br.Msg = errMsg
  247. br.ErrMsg = "保存分类失败,Err:" + err.Error()
  248. br.IsSendEmail = isSendEmail
  249. return
  250. }
  251. br.Ret = 200
  252. br.Msg = "修改成功"
  253. br.Success = true
  254. br.IsAddLog = true
  255. }
  256. // DeleteChartClassifyCheck
  257. // @Title 删除图表检测接口
  258. // @Description 删除图表检测接口
  259. // @Param request body data_manage.ChartClassifyDeleteCheckResp true "type json string"
  260. // @Success 200 Ret=200 检测成功
  261. // @router /warehouse/classify/delete/check [post]
  262. func (this *WarehouseClassifyController) DeleteChartClassifyCheck() {
  263. br := new(models.BaseResponse).Init()
  264. defer func() {
  265. this.Data["json"] = br
  266. this.ServeJSON()
  267. }()
  268. var req data_manage.ChartClassifyDeleteCheckReq
  269. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  270. if err != nil {
  271. br.Msg = "参数解析异常!"
  272. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  273. return
  274. }
  275. if req.ChartClassifyId < 0 && req.ChartInfoId <= 0 {
  276. br.Msg = "参数错误"
  277. br.IsSendEmail = false
  278. return
  279. }
  280. var deleteStatus int
  281. var tipsMsg string
  282. //删除分类
  283. if req.ChartClassifyId > 0 && req.ChartInfoId == 0 {
  284. //判断分类下,是否含有图表
  285. count, err := data_manage.GetChartInfoCountByClassifyId(req.ChartClassifyId)
  286. if err != nil {
  287. br.Msg = "删除失败"
  288. br.ErrMsg = "分类下是否含有图表失败,Err:" + err.Error()
  289. return
  290. }
  291. if count > 0 {
  292. deleteStatus = 1
  293. tipsMsg = "该分类下关联图表不可删除"
  294. }
  295. }
  296. if deleteStatus != 1 && req.ChartInfoId == 0 {
  297. classifyCount, err := data_manage.GetChartClassifyCountByClassifyId(req.ChartClassifyId)
  298. if err != nil && err.Error() != utils.ErrNoRow() {
  299. br.Msg = "删除失败"
  300. br.ErrMsg = "分类下是否含有图表失败,Err:" + err.Error()
  301. return
  302. }
  303. if classifyCount > 0 {
  304. deleteStatus = 2
  305. tipsMsg = "确认删除当前目录及包含的子目录吗"
  306. }
  307. }
  308. if deleteStatus == 0 {
  309. tipsMsg = "可删除,进行删除操作"
  310. }
  311. resp := new(data_manage.ChartClassifyDeleteCheckResp)
  312. resp.DeleteStatus = deleteStatus
  313. resp.TipsMsg = tipsMsg
  314. br.Ret = 200
  315. br.Msg = "检测成功"
  316. br.Success = true
  317. br.Data = resp
  318. }
  319. // DeleteChartClassify
  320. // @Title 删除分类/图表
  321. // @Description 删除分类/图表接口
  322. // @Param request body data_manage.DeleteChartClassifyReq true "type json string"
  323. // @Success 200 Ret=200 删除成功
  324. // @router /warehouse/classify/delete [post]
  325. func (this *WarehouseClassifyController) DeleteChartClassify() {
  326. br := new(models.BaseResponse).Init()
  327. defer func() {
  328. this.Data["json"] = br
  329. this.ServeJSON()
  330. }()
  331. sysUser := this.SysUser
  332. if sysUser == nil {
  333. br.Msg = "请登录"
  334. br.ErrMsg = "请登录,SysUser Is Empty"
  335. br.Ret = 408
  336. return
  337. }
  338. var req data_manage.DeleteChartClassifyReq
  339. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  340. if err != nil {
  341. br.Msg = "参数解析异常!"
  342. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  343. return
  344. }
  345. if req.ChartClassifyId < 0 && req.ChartInfoId <= 0 {
  346. br.Msg = "参数错误"
  347. br.IsSendEmail = false
  348. return
  349. }
  350. //删除分类
  351. if req.ChartClassifyId > 0 && req.ChartInfoId == 0 {
  352. //判断是否含有指标
  353. count, err := data_manage.GetChartInfoCountByClassifyId(req.ChartClassifyId)
  354. if err != nil && err.Error() != utils.ErrNoRow() {
  355. br.Msg = "删除失败"
  356. br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  357. return
  358. }
  359. if count > 0 {
  360. br.Msg = "该目录下存在关联指标,不可删除"
  361. br.IsSendEmail = false
  362. return
  363. }
  364. err = data_manage.DeleteChartClassify(req.ChartClassifyId)
  365. if err != nil {
  366. br.Msg = "删除失败"
  367. br.ErrMsg = "删除失败,Err:" + err.Error()
  368. return
  369. }
  370. }
  371. resp := new(data_manage.AddChartInfoResp)
  372. //删除图表
  373. if req.ChartInfoId > 0 {
  374. chartInfo, err := data_manage.GetChartInfoById(req.ChartInfoId)
  375. if err != nil {
  376. if err.Error() == utils.ErrNoRow() {
  377. br.Msg = "图表已删除,请刷新页面"
  378. br.ErrMsg = "指标不存在,Err:" + err.Error()
  379. return
  380. } else {
  381. br.Msg = "删除失败"
  382. br.ErrMsg = "删除失败,获取指标信息失败,Err:" + err.Error()
  383. return
  384. }
  385. }
  386. if chartInfo == nil {
  387. br.Msg = "图表已删除,请刷新页面"
  388. return
  389. }
  390. //图表操作权限
  391. ok := data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, true)
  392. if !ok {
  393. br.Msg = "没有该图表的操作权限"
  394. br.ErrMsg = "没有该图表的操作权限"
  395. return
  396. }
  397. // 获取引用该图表的MyCharts, 用于ES删除
  398. var myCond string
  399. var myPars []interface{}
  400. myCond += ` AND a.chart_info_id = ? `
  401. myPars = append(myPars, chartInfo.ChartInfoId)
  402. myCharts, e := data_manage.GetMyChartListGroupByCharyInfoIdAndAdminIdByCondition(myCond, myPars)
  403. if e != nil {
  404. br.Msg = "删除失败"
  405. br.ErrMsg = "获取引用图表的MyChats失败, Err: " + e.Error()
  406. return
  407. }
  408. myIds := make([]int, 0)
  409. for _, m := range myCharts {
  410. myIds = append(myIds, m.MyChartId)
  411. }
  412. source := chartInfo.Source
  413. //删除图表及关联指标
  414. err = data_manage.DeleteChartInfoAndData(chartInfo.ChartInfoId)
  415. if err != nil {
  416. br.Msg = "删除失败"
  417. br.ErrMsg = "删除失败,Err:" + err.Error()
  418. return
  419. }
  420. //删除ES
  421. {
  422. go data.EsDeleteChartInfo(chartInfo.ChartInfoId)
  423. // 删除MY ETA 图表 es数据
  424. //go data.EsDeleteMyChartInfoByChartInfoId(chartInfo.ChartInfoId)
  425. go data.EsDeleteMyChartInfoByMyChartIds(myIds)
  426. }
  427. var condition string
  428. var pars []interface{}
  429. condition += " AND chart_classify_id=? AND source = ? "
  430. pars = append(pars, chartInfo.ChartClassifyId, source)
  431. condition += " AND chart_info_id>? ORDER BY create_time ASC LIMIT 1 "
  432. pars = append(pars, req.ChartInfoId)
  433. nextItem, err := data_manage.GetChartInfoByCondition(condition, pars)
  434. if err != nil && err.Error() != utils.ErrNoRow() {
  435. br.Msg = "删除失败"
  436. br.ErrMsg = "获取下一级图库信息失败,Err:" + err.Error()
  437. return
  438. }
  439. if nextItem != nil {
  440. resp.UniqueCode = nextItem.UniqueCode
  441. resp.ChartInfoId = nextItem.ChartInfoId
  442. } else {
  443. var condition string
  444. var pars []interface{}
  445. condition += " AND level=1 "
  446. //pars = append(pars, chartInfo.ChartClassifyId)
  447. condition += " AND chart_classify_id>? ORDER BY chart_classify_id ASC LIMIT 1 "
  448. pars = append(pars, chartInfo.ChartClassifyId)
  449. classifyItem, err := data_manage.GetChartClassifyByCondition(condition, pars)
  450. if err != nil && err.Error() != utils.ErrNoRow() {
  451. br.Msg = "删除失败"
  452. br.ErrMsg = "获取下一级图库分类信息失败,Err:" + err.Error()
  453. return
  454. }
  455. if classifyItem != nil {
  456. nextItem, err = data_manage.GetNextChartInfo(chartInfo.ChartClassifyId)
  457. if err != nil && err.Error() != utils.ErrNoRow() {
  458. br.Msg = "删除失败"
  459. br.ErrMsg = "获取下一级图库信息失败,Err:" + err.Error()
  460. return
  461. }
  462. if nextItem != nil {
  463. resp.UniqueCode = nextItem.UniqueCode
  464. resp.ChartInfoId = nextItem.ChartInfoId
  465. }
  466. }
  467. }
  468. // 删除图表关联
  469. e = correlationServ.RemoveCorrelationRelate(chartInfo.ChartInfoId)
  470. if e != nil {
  471. br.Msg = "删除失败"
  472. br.ErrMsg = fmt.Sprintf("删除关联失败, %v", e)
  473. return
  474. }
  475. //新增操作日志
  476. {
  477. chartLog := new(data_manage.ChartInfoLog)
  478. chartLog.ChartName = chartInfo.ChartName
  479. chartLog.ChartInfoId = req.ChartInfoId
  480. chartLog.ChartClassifyId = chartInfo.ChartClassifyId
  481. chartLog.SysUserId = sysUser.AdminId
  482. chartLog.SysUserRealName = sysUser.RealName
  483. chartLog.UniqueCode = chartInfo.UniqueCode
  484. chartLog.CreateTime = time.Now()
  485. chartLog.Content = string(this.Ctx.Input.RequestBody)
  486. chartLog.Status = "删除图表"
  487. chartLog.Method = this.Ctx.Input.URI()
  488. go data_manage.AddChartInfoLog(chartLog)
  489. }
  490. }
  491. br.Ret = 200
  492. br.Msg = "删除成功"
  493. br.Success = true
  494. br.Data = resp
  495. br.IsAddLog = true
  496. }
  497. // ChartClassifyMove
  498. // @Title 分类移动接口
  499. // @Description 分类移动接口
  500. // @Success 200 {object} data_manage.MoveChartClassifyReq
  501. // @router /warehouse/classify/move [post]
  502. func (this *WarehouseClassifyController) ChartClassifyMove() {
  503. br := new(models.BaseResponse).Init()
  504. defer func() {
  505. if br.ErrMsg == "" {
  506. br.IsSendEmail = false
  507. }
  508. this.Data["json"] = br
  509. this.ServeJSON()
  510. }()
  511. sysUser := this.SysUser
  512. if sysUser == nil {
  513. br.Msg = "请登录"
  514. br.ErrMsg = "请登录,SysUser Is Empty"
  515. br.Ret = 408
  516. return
  517. }
  518. var req data_manage.MoveChartClassifyReq
  519. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  520. if err != nil {
  521. br.Msg = "参数解析异常!"
  522. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  523. return
  524. }
  525. if req.ClassifyId <= 0 && req.ChartInfoId <= 0 {
  526. br.Msg = "参数错误"
  527. br.ErrMsg = "请选择拖动目标,分类目录或者指标"
  528. return
  529. }
  530. err, errMsg := data.MoveChartClassify(req, sysUser, utils.CHART_SOURCE_TRADE_ANALYSIS_PROCESS)
  531. if errMsg != `` {
  532. br.Msg = errMsg
  533. br.ErrMsg = errMsg
  534. if err != nil {
  535. br.ErrMsg = err.Error()
  536. } else {
  537. br.IsSendEmail = false
  538. }
  539. return
  540. }
  541. br.Ret = 200
  542. br.Success = true
  543. br.Msg = "移动成功"
  544. }
  545. // ClassifyTree
  546. // @Title 多层分类列表树
  547. // @Description 多层分类列表树
  548. // @Success 200 {object} data_manage.ChartClassifyListResp
  549. // @router /warehouse/classify/tree [get]
  550. func (this *WarehouseClassifyController) ClassifyTree() {
  551. br := new(models.BaseResponse).Init()
  552. defer func() {
  553. if br.ErrMsg == "" {
  554. br.IsSendEmail = false
  555. }
  556. this.Data["json"] = br
  557. this.ServeJSON()
  558. }()
  559. allList, err := data_manage.GetChartClassifyAllBySource(utils.CHART_SOURCE_TRADE_ANALYSIS_PROCESS)
  560. if err != nil {
  561. br.Msg = "获取失败"
  562. br.ErrMsg = "获取所有分类失败, Err:" + err.Error()
  563. return
  564. }
  565. nodeAll := make([]*data_manage.ChartClassifyItems, 0)
  566. if len(allList) > 0 {
  567. // 已授权分类id
  568. permissionClassifyIdList, e := data_manage_permission.GetUserChartClassifyPermissionList(this.SysUser.AdminId, 0)
  569. if e != nil {
  570. br.Msg = "获取失败"
  571. br.ErrMsg = "获取已授权分类id数据失败,Err:" + e.Error()
  572. return
  573. }
  574. for k, v := range allList {
  575. // 数据权限
  576. v.HaveOperaAuth = data_manage_permission.CheckChartClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ChartClassifyId, permissionClassifyIdList)
  577. // 按钮权限
  578. button := data.GetChartClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  579. allList[k].Button = button
  580. }
  581. nodeAll = data.GetChartClassifyTreeRecursive(allList, 0)
  582. //根据sort值排序
  583. sort.Slice(nodeAll, func(i, j int) bool {
  584. return nodeAll[i].Sort < nodeAll[j].Sort
  585. })
  586. }
  587. language := `CN`
  588. // 显示的语言
  589. {
  590. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.ChartLanguageVar)
  591. if configDetail != nil {
  592. language = configDetail.ConfigValue
  593. } else {
  594. configDetail, _ = system.GetDefaultConfigDetailByCode(system.ChartLanguageVar)
  595. if configDetail != nil {
  596. language = configDetail.ConfigValue
  597. }
  598. }
  599. }
  600. // 是否允许添加一级分类
  601. canOpClassify := true
  602. button := data.GetChartClassifyOpButton(this.SysUser, 0, true)
  603. if !button.AddButton {
  604. canOpClassify = false
  605. }
  606. resp := new(data_manage.ChartClassifyListResp)
  607. resp.AllNodes = nodeAll
  608. resp.Language = language
  609. resp.CanOpClassify = canOpClassify
  610. br.Ret = 200
  611. br.Success = true
  612. br.Msg = "获取成功"
  613. br.Data = resp
  614. }