warehouse_classify.go 19 KB

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