classify.go 22 KB

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