classify.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta_gn/eta_api/models"
  5. "eta_gn/eta_api/models/report_approve"
  6. "eta_gn/eta_api/services"
  7. "eta_gn/eta_api/utils"
  8. "fmt"
  9. )
  10. type ClassifyController struct {
  11. BaseAuthController
  12. }
  13. // @router /add [post]
  14. func (this *ClassifyController) Add() {
  15. br := new(models.BaseResponse).Init()
  16. defer func() {
  17. this.Data["json"] = br
  18. this.ServeJSON()
  19. }()
  20. var req models.ClassifyAddReq
  21. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  22. if err != nil {
  23. br.Msg = "参数解析异常!"
  24. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  25. return
  26. }
  27. if req.ClassifyName == "" {
  28. br.Msg = "分类名称不可为空"
  29. return
  30. }
  31. err, errMsg, isSentEmail := services.AddReportClassify(req.ClassifyName, req.ParentId, req.ChartPermissionIdList)
  32. if err != nil {
  33. br.Msg = "添加失败"
  34. if errMsg != "" {
  35. br.Msg = errMsg
  36. }
  37. br.ErrMsg = "添加失败,Err:" + err.Error()
  38. br.IsSendEmail = isSentEmail
  39. return
  40. }
  41. br.Ret = 200
  42. br.Success = true
  43. br.Msg = "新增成功"
  44. }
  45. // @router /checkDeleteClassify [get]
  46. func (this *ClassifyController) CheckDeleteClassify() {
  47. br := new(models.BaseResponse).Init()
  48. defer func() {
  49. this.Data["json"] = br
  50. this.ServeJSON()
  51. }()
  52. classifyId, err := this.GetInt("ClassifyId")
  53. if classifyId <= 0 {
  54. br.Msg = "参数错误"
  55. return
  56. }
  57. classify, err := models.GetClassifyById(classifyId)
  58. if err != nil {
  59. br.Msg = "获取信息失败"
  60. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  61. return
  62. }
  63. resp := new(models.CheckDeleteClassifyResp)
  64. if classify == nil {
  65. br.Msg = "分类不存在"
  66. resp.Code = 1
  67. resp.Msg = "分类不存在"
  68. br.Data = resp
  69. br.Ret = 200
  70. br.Success = true
  71. return
  72. }
  73. if classify.ParentId > 0 {
  74. count, err := models.GetReportCountByClassifyId(classifyId)
  75. if err != nil {
  76. br.Msg = "获取信息失败"
  77. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  78. return
  79. }
  80. if count > 0 {
  81. resp.Code = 2
  82. resp.Msg = "该分类有关联报告,不允许删除"
  83. br.Data = resp
  84. br.Ret = 200
  85. br.Msg = "该分类有关联报告,不允许删除"
  86. br.Success = true
  87. return
  88. }
  89. } else {
  90. subCount, err := models.GetClassifySubCountByClassifyId(classifyId)
  91. if err != nil {
  92. br.Msg = "获取信息失败"
  93. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  94. return
  95. }
  96. if subCount > 0 {
  97. resp.Code = 3
  98. resp.Msg = "二级分类有关联报告,不允许删除"
  99. br.Data = resp
  100. br.Ret = 200
  101. br.Msg = "二级分类有关联报告,不允许删除"
  102. br.Success = true
  103. return
  104. }
  105. subTotal, err := models.GetClassifySubCountByParentId(classifyId)
  106. if err != nil {
  107. br.Msg = "获取信息失败"
  108. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  109. return
  110. }
  111. if subTotal > 0 {
  112. resp.Code = 4
  113. resp.Msg = "请先删除该分类下关联分类"
  114. br.Data = resp
  115. br.Ret = 200
  116. br.Msg = "请先删除该分类下关联分类"
  117. br.Success = true
  118. return
  119. }
  120. }
  121. flowOb := new(report_approve.ReportApproveFlow)
  122. flowCond := fmt.Sprintf(` AND %s = ? AND (%s = ? OR %s = ?)`, report_approve.ReportApproveFlowCols.ReportType, report_approve.ReportApproveFlowCols.ClassifyFirstId, report_approve.ReportApproveFlowCols.ClassifySecondId)
  123. flowPars := make([]interface{}, 0)
  124. flowPars = append(flowPars, report_approve.FlowReportTypeChinese, classifyId, classifyId)
  125. flowCount, e := flowOb.GetCountByCondition(flowCond, flowPars)
  126. if e != nil {
  127. br.Msg = "检测失败"
  128. br.ErrMsg = "获取关联审批流失败, Err: " + e.Error()
  129. return
  130. }
  131. if flowCount > 0 {
  132. resp.Code = 5
  133. resp.Msg = "该分类关联审批流,不允许删除"
  134. br.Data = resp
  135. br.Ret = 200
  136. br.Msg = resp.Msg
  137. br.Success = true
  138. return
  139. }
  140. resp.Code = 0
  141. resp.Msg = "检测完成,可进行删除操作"
  142. br.Ret = 200
  143. br.Data = resp
  144. br.Success = true
  145. br.Msg = "检测成功"
  146. }
  147. // @router /delete [post]
  148. func (this *ClassifyController) Delete() {
  149. br := new(models.BaseResponse).Init()
  150. defer func() {
  151. this.Data["json"] = br
  152. this.ServeJSON()
  153. }()
  154. var req models.DeleteClassifyReq
  155. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  156. if err != nil {
  157. br.Msg = "参数解析异常!"
  158. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  159. return
  160. }
  161. if req.ClassifyId <= 0 {
  162. br.Msg = "参数错误"
  163. return
  164. }
  165. br.Msg = "报告分类不允许删除"
  166. br.IsSendEmail = false
  167. return
  168. item, err := models.GetClassifyById(req.ClassifyId)
  169. if err != nil {
  170. br.Msg = "获取信息失败"
  171. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  172. return
  173. }
  174. if item == nil {
  175. br.Msg = "分类不存在"
  176. return
  177. }
  178. err = models.DeleteClassify(req.ClassifyId)
  179. if err != nil {
  180. br.Msg = "删除失败"
  181. br.ErrMsg = "删除失败,Err:" + err.Error()
  182. return
  183. }
  184. br.Ret = 200
  185. br.Success = true
  186. br.Msg = "删除成功"
  187. }
  188. // @router /edit [post]
  189. func (this *ClassifyController) Edit() {
  190. br := new(models.BaseResponse).Init()
  191. defer func() {
  192. this.Data["json"] = br
  193. this.ServeJSON()
  194. }()
  195. var req models.EditClassifyReq
  196. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  197. if err != nil {
  198. br.Msg = "参数解析异常!"
  199. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  200. return
  201. }
  202. if req.ClassifyId <= 0 {
  203. br.Msg = "参数错误"
  204. return
  205. }
  206. if req.ClassifyName == "" {
  207. br.Msg = "分类名称不可为空"
  208. return
  209. }
  210. err, errMsg, isSentEmail := services.EditReportClassify(req.ClassifyId, req.ClassifyName, req.ChartPermissionIdList)
  211. if err != nil {
  212. br.Msg = "修改失败"
  213. if errMsg != "" {
  214. br.Msg = errMsg
  215. }
  216. br.ErrMsg = "修改失败,Err:" + err.Error()
  217. br.IsSendEmail = isSentEmail
  218. return
  219. }
  220. br.Ret = 200
  221. br.Success = true
  222. br.Msg = "修改成功"
  223. }
  224. // @router /parent [get]
  225. func (this *ClassifyController) ParentClassify() {
  226. br := new(models.BaseResponse).Init()
  227. defer func() {
  228. this.Data["json"] = br
  229. this.ServeJSON()
  230. }()
  231. items, err := models.GetAllClassify()
  232. if err != nil {
  233. br.Msg = "获取失败"
  234. br.ErrMsg = "获取失败,Err:" + err.Error()
  235. return
  236. }
  237. classifyIds := make([]int, 0)
  238. for i := range items {
  239. classifyIds = append(classifyIds, items[i].Id)
  240. }
  241. classifyLen := len(classifyIds)
  242. if classifyLen == 0 {
  243. br.Ret = 200
  244. br.Success = true
  245. br.Msg = "获取成功"
  246. return
  247. }
  248. menuListMap := make(map[int][]*models.ClassifyMenu, 0)
  249. var menuCond string
  250. var menuPars []interface{}
  251. menuCond += ` AND classify_id IN (` + utils.GetOrmInReplace(classifyLen) + `)`
  252. menuPars = append(menuPars, classifyIds)
  253. parentMenus, e := models.GetClassifyMenuList(menuCond, menuPars)
  254. if e != nil {
  255. br.Msg = "获取失败"
  256. br.ErrMsg = "获取一级分类子目录列表失败"
  257. return
  258. }
  259. for i := range parentMenus {
  260. if menuListMap[parentMenus[i].ClassifyId] == nil {
  261. menuListMap[parentMenus[i].ClassifyId] = make([]*models.ClassifyMenu, 0)
  262. }
  263. menuListMap[parentMenus[i].ClassifyId] = append(menuListMap[parentMenus[i].ClassifyId], parentMenus[i])
  264. }
  265. resp := make([]*models.ClassifyItem, 0)
  266. for i := range items {
  267. resp = append(resp, &models.ClassifyItem{
  268. Classify: *items[i],
  269. ClassifyMenuList: menuListMap[items[i].Id],
  270. })
  271. }
  272. resp = services.GetClassifyTreeRecursive(resp, 0)
  273. br.Data = resp
  274. br.Ret = 200
  275. br.Success = true
  276. br.Msg = "获取成功"
  277. }
  278. // @router /findById [get]
  279. func (this *ClassifyController) FindByIdClassify() {
  280. br := new(models.BaseResponse).Init()
  281. defer func() {
  282. this.Data["json"] = br
  283. this.ServeJSON()
  284. }()
  285. var req models.FindByIdClassifyReq
  286. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  287. if err != nil {
  288. br.Msg = "参数解析异常!"
  289. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  290. return
  291. }
  292. items, err := models.FindByIdClassify(req.ClassifyId)
  293. if err != nil {
  294. br.Msg = "获取失败"
  295. br.ErrMsg = "获取失败,Err:" + err.Error()
  296. return
  297. }
  298. br.Data = items
  299. br.Ret = 200
  300. br.Success = true
  301. br.Msg = "获取成功"
  302. }
  303. // @router /list [get]
  304. func (this *ClassifyController) ListClassify() {
  305. br := new(models.BaseResponse).Init()
  306. defer func() {
  307. this.Data["json"] = br
  308. this.ServeJSON()
  309. }()
  310. keyWord := this.GetString("KeyWord")
  311. reqEnabled, _ := this.GetInt("Enabled", -1)
  312. enabled := -1
  313. if reqEnabled == 1 {
  314. enabled = reqEnabled
  315. }
  316. list, err := models.GetClassifyListByKeyword(keyWord, enabled)
  317. if err != nil {
  318. br.Msg = "获取失败"
  319. br.ErrMsg = "获取失败,Err:" + err.Error()
  320. return
  321. }
  322. if keyWord != `` {
  323. idMap := make(map[int]bool)
  324. currParentClassifyIdList := make([]int, 0)
  325. for _, v := range list {
  326. idMap[v.Id] = true
  327. if v.ParentId > 0 {
  328. currParentClassifyIdList = append(currParentClassifyIdList, v.ParentId)
  329. }
  330. }
  331. findList := list
  332. list = make([]*models.ClassifyList, 0)
  333. tmpList, tmpErr := services.GetParentClassifyListByParentIdList(currParentClassifyIdList)
  334. if tmpErr != nil {
  335. br.Msg = "获取失败"
  336. br.ErrMsg = "获取上级分类信息失败,Err:" + tmpErr.Error()
  337. return
  338. }
  339. for _, v := range tmpList {
  340. if _, ok := idMap[v.Id]; !ok {
  341. list = append(list, v)
  342. }
  343. }
  344. list = append(list, findList...)
  345. }
  346. classifyIdList := make([]int, 0)
  347. for i := range list {
  348. classifyIdList = append(classifyIdList, list[i].Id)
  349. }
  350. parentIdLen := len(classifyIdList)
  351. if parentIdLen == 0 {
  352. resp := &models.ClassifyListResp{
  353. List: list,
  354. }
  355. br.Data = resp
  356. br.Ret = 200
  357. br.Success = true
  358. br.Msg = "获取成功"
  359. return
  360. }
  361. menuListMap := make(map[int][]*models.ClassifyMenu, 0)
  362. var menuCond string
  363. var menuPars []interface{}
  364. menuCond += ` AND classify_id IN (` + utils.GetOrmInReplace(parentIdLen) + `)`
  365. menuPars = append(menuPars, classifyIdList)
  366. parentMenus, e := models.GetClassifyMenuList(menuCond, menuPars)
  367. if e != nil {
  368. br.Msg = "获取失败"
  369. br.ErrMsg = "获取一级分类子目录列表失败"
  370. return
  371. }
  372. for i := range parentMenus {
  373. if menuListMap[parentMenus[i].ClassifyId] == nil {
  374. menuListMap[parentMenus[i].ClassifyId] = make([]*models.ClassifyMenu, 0)
  375. }
  376. menuListMap[parentMenus[i].ClassifyId] = append(menuListMap[parentMenus[i].ClassifyId], parentMenus[i])
  377. }
  378. relateMap := make(map[int]int, 0)
  379. {
  380. var relateCond string
  381. var relatePars []interface{}
  382. relateCond += ` AND classify_id IN (` + utils.GetOrmInReplace(parentIdLen) + `)`
  383. relatePars = append(relatePars, classifyIdList)
  384. relates, e := models.GetClassifyMenuRelationList(relateCond, relatePars)
  385. if e != nil {
  386. br.Msg = "获取失败"
  387. br.ErrMsg = "获取二级分类子目录关联失败, Err: " + e.Error()
  388. return
  389. }
  390. for i := range relates {
  391. relateMap[relates[i].ClassifyId] = relates[i].MenuId
  392. }
  393. }
  394. permissionList, _ := models.GetAllPermissionMapping()
  395. classifyPermissionMap := make(map[int][]int)
  396. if len(permissionList) > 0 {
  397. for _, v := range permissionList {
  398. classifyPermissionMap[v.ClassifyId] = append(classifyPermissionMap[v.ClassifyId], v.ChartPermissionId)
  399. }
  400. }
  401. for i, v := range list {
  402. list[i].ClassifyMenuList = menuListMap[v.Id]
  403. list[i].ClassifyMenuId = relateMap[v.Id]
  404. if permissionIds, ok := classifyPermissionMap[v.Id]; ok {
  405. list[i].ChartPermissionIdList = permissionIds
  406. }
  407. }
  408. services.SortClassifyListBySortAndCreateTime(list)
  409. list = services.GetClassifyListTreeRecursive(list, 0)
  410. resp := new(models.ClassifyListResp)
  411. resp.List = list
  412. br.Data = resp
  413. br.Ret = 200
  414. br.Success = true
  415. br.Msg = "获取成功"
  416. }
  417. // @router /permission_list [get]
  418. func (this *ClassifyController) ClassifyPermission() {
  419. br := new(models.BaseResponse).Init()
  420. defer func() {
  421. this.Data["json"] = br
  422. this.ServeJSON()
  423. }()
  424. classifyId, _ := this.GetInt("ClassifyId")
  425. if classifyId <= 0 {
  426. br.Msg = "参数错误"
  427. return
  428. }
  429. classifyInfo, err := models.GetClassifyById(classifyId)
  430. if err != nil {
  431. br.Msg = "获取分类信息失败"
  432. br.ErrMsg = "获取失败,Err:" + err.Error()
  433. return
  434. }
  435. list, err := models.GetPermissionByClassifyId(classifyInfo.Id)
  436. if err != nil {
  437. br.Msg = "获取分类信息失败"
  438. br.ErrMsg = "获取失败,Err:" + err.Error()
  439. return
  440. }
  441. br.Data = list
  442. br.Ret = 200
  443. br.Success = true
  444. br.Msg = "获取成功"
  445. }
  446. // @router /permission/edit [post]
  447. func (this *ClassifyController) EditClassifyPermission() {
  448. br := new(models.BaseResponse).Init()
  449. defer func() {
  450. this.Data["json"] = br
  451. this.ServeJSON()
  452. }()
  453. var req models.EditClassifyPermissionReq
  454. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  455. if err != nil {
  456. br.Msg = "参数解析异常!"
  457. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  458. return
  459. }
  460. if req.ClassifyId <= 0 {
  461. br.Msg = "参数错误"
  462. return
  463. }
  464. if len(req.ChartPermissionIdList) <= 0 {
  465. br.Msg = "请选择权限"
  466. return
  467. }
  468. classifyInfo, err := models.GetClassifyById(req.ClassifyId)
  469. if err != nil {
  470. br.Msg = "获取分类信息失败"
  471. br.ErrMsg = "获取失败,Err:" + err.Error()
  472. return
  473. }
  474. err = models.EditChartPermissionSearchKeyWordMappingMulti(classifyInfo.ClassifyName, req.ChartPermissionIdList, req.ClassifyId)
  475. if err != nil {
  476. br.Msg = "修改分类权限失败"
  477. br.ErrMsg = "修改分类权限失败,Err:" + err.Error()
  478. return
  479. }
  480. go func() {
  481. _ = services.EditClassifyChartPermissionSync(classifyInfo.ClassifyName, req.ClassifyId)
  482. }()
  483. br.Ret = 200
  484. br.Success = true
  485. br.Msg = "修改成功"
  486. }
  487. // @router /tel_list [get]
  488. func (this *ClassifyController) TelListClassify() {
  489. br := new(models.BaseResponse).Init()
  490. defer func() {
  491. this.Data["json"] = br
  492. this.ServeJSON()
  493. }()
  494. resp := make([]*models.SimpleClassifyList, 0)
  495. var condition, orderRule string
  496. var pars []interface{}
  497. telList, e := models.GetClassifyByCondition(condition, orderRule, pars)
  498. if e != nil {
  499. return
  500. }
  501. firstList := make([]*models.SimpleClassifyList, 0)
  502. secondList := make([]*models.SimpleClassifyList, 0)
  503. secondMap := make(map[int][]*models.SimpleClassifyList, 0)
  504. for i := range telList {
  505. if telList[i].ParentId == 0 {
  506. firstList = append(firstList, telList[i])
  507. } else {
  508. secondList = append(secondList, telList[i])
  509. secondMap[telList[i].ParentId] = append(secondMap[telList[i].ParentId], telList[i])
  510. }
  511. }
  512. for i := range firstList {
  513. firstList[i].Child = secondMap[firstList[i].Id]
  514. }
  515. resp = firstList
  516. br.Data = resp
  517. br.Ret = 200
  518. br.Success = true
  519. br.Msg = "获取成功"
  520. }
  521. // @router /move [post]
  522. func (this *ClassifyController) Move() {
  523. br := new(models.BaseResponse).Init()
  524. defer func() {
  525. this.Data["json"] = br
  526. this.ServeJSON()
  527. }()
  528. var req models.ClassifyMoveReq
  529. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  530. if err != nil {
  531. br.Msg = "参数解析异常!"
  532. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  533. return
  534. }
  535. if req.ClassifyId <= 0 {
  536. br.Msg = "请选择分类"
  537. return
  538. }
  539. e, msg := services.MoveReportClassify(req)
  540. if e != nil {
  541. br.Msg = msg
  542. br.ErrMsg = "移动分类失败, Err: " + e.Error()
  543. return
  544. }
  545. br.Ret = 200
  546. br.Success = true
  547. br.Msg = "操作成功"
  548. }
  549. // @router /enabled/set [post]
  550. func (this *ClassifyController) SetEnabled() {
  551. br := new(models.BaseResponse).Init()
  552. defer func() {
  553. this.Data["json"] = br
  554. this.ServeJSON()
  555. }()
  556. var req models.ClassifySetEnabledReq
  557. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  558. if err != nil {
  559. br.Msg = "参数解析异常!"
  560. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  561. return
  562. }
  563. if req.ClassifyId <= 0 {
  564. br.Msg = "请选择分类"
  565. return
  566. }
  567. if req.Enabled != 0 && req.Enabled != 1 {
  568. br.Msg = "请选择正确的启用禁用状态"
  569. return
  570. }
  571. item, err := models.GetClassifyById(req.ClassifyId)
  572. if err != nil {
  573. if utils.IsErrNoRow(err) {
  574. br.Msg = "分类不存在"
  575. return
  576. }
  577. br.Msg = "获取信息失败"
  578. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  579. return
  580. }
  581. if item == nil {
  582. br.Msg = "分类不存在"
  583. return
  584. }
  585. ob := new(models.Classify)
  586. err = ob.SetEnabled(req.ClassifyId, req.Enabled)
  587. if err != nil {
  588. br.Msg = "操作失败"
  589. br.ErrMsg = "操作失败,Err:" + err.Error()
  590. return
  591. }
  592. br.Ret = 200
  593. br.Success = true
  594. br.Msg = "操作成功"
  595. }
  596. // @router /permission/list [get]
  597. func (this *ClassifyController) ClassifyPermissionV2() {
  598. br := new(models.BaseResponse).Init()
  599. defer func() {
  600. this.Data["json"] = br
  601. this.ServeJSON()
  602. }()
  603. sysUser := this.SysUser
  604. if sysUser == nil {
  605. br.Msg = "请登录"
  606. br.ErrMsg = "请登录,SysUser Is Empty"
  607. br.Ret = 408
  608. return
  609. }
  610. classifyId, _ := this.GetInt("ClassifyId")
  611. if classifyId <= 0 {
  612. br.Msg = "参数错误"
  613. return
  614. }
  615. resp := make([]*models.ChartPermissionItem, 0)
  616. permissionIdMap := make(map[int]bool)
  617. {
  618. classifyInfo, err := models.GetClassifyById(classifyId)
  619. if err != nil {
  620. br.Msg = "获取分类信息失败"
  621. br.ErrMsg = "获取失败,Err:" + err.Error()
  622. return
  623. }
  624. list, err := models.GetPermission(classifyInfo.Id)
  625. if err != nil {
  626. br.Msg = "获取分类信息失败"
  627. br.ErrMsg = "获取失败,Err:" + err.Error()
  628. return
  629. }
  630. for _, v := range list {
  631. permissionIdMap[v.ChartPermissionId] = true
  632. }
  633. }
  634. num := len(permissionIdMap)
  635. if num <= 0 {
  636. br.Ret = 200
  637. br.Success = true
  638. br.Msg = "获取成功"
  639. br.Data = resp
  640. return
  641. }
  642. cond := ` and product_id = ?`
  643. pars := make([]interface{}, 0)
  644. pars = append(pars, 1)
  645. list, e := services.GetChartPermissionList(cond, pars)
  646. if e != nil {
  647. br.Msg = "获取失败"
  648. br.ErrMsg = "获取品种列表失败, Err: " + e.Error()
  649. return
  650. }
  651. childMap := make(map[int][]*models.ChartPermissionItem)
  652. tmpResp := make([]*models.ChartPermissionItem, 0)
  653. for _, v := range list {
  654. t := new(models.ChartPermissionItem)
  655. t.PermissionId = v.ChartPermissionId
  656. t.PermissionName = v.PermissionName
  657. t.ParentId = v.ParentId
  658. t.IsPublic = v.IsPublic
  659. t.Enabled = v.Enabled
  660. t.Sort = v.Sort
  661. t.CreateTime = v.CreatedTime.Format(utils.FormatDateTime)
  662. t.Child = make([]*models.ChartPermissionItem, 0)
  663. if v.ParentId == 0 {
  664. tmpResp = append(tmpResp, t)
  665. continue
  666. }
  667. if v.ParentId > 0 {
  668. if _, ok := permissionIdMap[v.ChartPermissionId]; ok {
  669. if childMap[v.ParentId] == nil {
  670. childMap[v.ParentId] = make([]*models.ChartPermissionItem, 0)
  671. }
  672. childMap[v.ParentId] = append(childMap[v.ParentId], t)
  673. }
  674. }
  675. }
  676. for _, r := range tmpResp {
  677. childList, ok := childMap[r.PermissionId]
  678. if !ok {
  679. continue
  680. }
  681. r.Child = childList
  682. resp = append(resp, r)
  683. }
  684. br.Ret = 200
  685. br.Success = true
  686. br.Msg = "获取成功"
  687. br.Data = resp
  688. }