classify.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/models"
  5. "eta/eta_api/models/report_approve"
  6. "eta/eta_api/services"
  7. "eta/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 = ? OR %s = ?) AND (%s = ? OR %s = ?)`, report_approve.ReportApproveFlowCols.ReportType, report_approve.ReportApproveFlowCols.ReportType, report_approve.ReportApproveFlowCols.ClassifyFirstId, report_approve.ReportApproveFlowCols.ClassifySecondId)
  148. flowPars := make([]interface{}, 0)
  149. flowPars = append(flowPars, report_approve.FlowReportTypeChinese, report_approve.FlowReportTypeSmart, 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. if utils.BusinessCode == utils.BusinessCodeRelease || utils.BusinessCode == utils.BusinessCodeSandbox {
  582. condition += ` AND classify_name <> '晨报' AND classify_name <> '周报' `
  583. }
  584. telList, e := models.GetClassifyByCondition(condition, orderRule, pars)
  585. if e != nil {
  586. return
  587. }
  588. firstList := make([]*models.SimpleClassifyList, 0)
  589. secondList := make([]*models.SimpleClassifyList, 0)
  590. secondMap := make(map[int][]*models.SimpleClassifyList, 0)
  591. for i := range telList {
  592. if telList[i].ParentId == 0 {
  593. firstList = append(firstList, telList[i])
  594. } else {
  595. secondList = append(secondList, telList[i])
  596. secondMap[telList[i].ParentId] = append(secondMap[telList[i].ParentId], telList[i])
  597. }
  598. }
  599. for i := range firstList {
  600. firstList[i].Child = secondMap[firstList[i].Id]
  601. }
  602. resp = firstList
  603. br.Data = resp
  604. br.Ret = 200
  605. br.Success = true
  606. br.Msg = "获取成功"
  607. }
  608. // Move
  609. // @Title 移动分类接口
  610. // @Description 移动分类
  611. // @Param request body models.ClassifyMoveReq true "type json string"
  612. // @Success 200 新增成功
  613. // @router /move [post]
  614. func (this *ClassifyController) Move() {
  615. br := new(models.BaseResponse).Init()
  616. defer func() {
  617. this.Data["json"] = br
  618. this.ServeJSON()
  619. }()
  620. var req models.ClassifyMoveReq
  621. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  622. if err != nil {
  623. br.Msg = "参数解析异常!"
  624. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  625. return
  626. }
  627. if req.ClassifyId <= 0 {
  628. br.Msg = "请选择分类"
  629. return
  630. }
  631. e, msg := services.MoveReportClassify(req)
  632. if e != nil {
  633. br.Msg = msg
  634. br.ErrMsg = "移动分类失败, Err: " + e.Error()
  635. return
  636. }
  637. br.Ret = 200
  638. br.Success = true
  639. br.Msg = "操作成功"
  640. }
  641. // SetEnabled
  642. // @Title 启用/禁用分类接口
  643. // @Description 启用/禁用分类
  644. // @Param request body models.ClassifyMoveReq true "type json string"
  645. // @Success 200 新增成功
  646. // @router /enabled/set [post]
  647. func (this *ClassifyController) SetEnabled() {
  648. br := new(models.BaseResponse).Init()
  649. defer func() {
  650. this.Data["json"] = br
  651. this.ServeJSON()
  652. }()
  653. var req models.ClassifySetEnabledReq
  654. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  655. if err != nil {
  656. br.Msg = "参数解析异常!"
  657. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  658. return
  659. }
  660. if req.ClassifyId <= 0 {
  661. br.Msg = "请选择分类"
  662. return
  663. }
  664. if req.Enabled != 0 && req.Enabled != 1 {
  665. br.Msg = "请选择正确的启用禁用状态"
  666. return
  667. }
  668. item, err := models.GetClassifyById(req.ClassifyId)
  669. if err != nil {
  670. if err.Error() == utils.ErrNoRow() {
  671. br.Msg = "分类不存在"
  672. return
  673. }
  674. br.Msg = "获取信息失败"
  675. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  676. return
  677. }
  678. if item == nil {
  679. br.Msg = "分类不存在"
  680. return
  681. }
  682. ob := new(models.Classify)
  683. //设置分类启用、禁用状态
  684. err = ob.SetEnabled(req.ClassifyId, req.Enabled)
  685. if err != nil {
  686. br.Msg = "操作失败"
  687. br.ErrMsg = "操作失败,Err:" + err.Error()
  688. return
  689. }
  690. br.Ret = 200
  691. br.Success = true
  692. br.Msg = "操作成功"
  693. }
  694. // ClassifyPermissionV2
  695. // @Title 获取权限设置基础信息
  696. // @Description 获取权限设置基础信息接口
  697. // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
  698. // @Param NoUpgrade query bool false "是否不展示升级权限,默认为 false"
  699. // @Success 200 {object} company.PermissionSetResp
  700. // @router /permission/list [get]
  701. func (this *ClassifyController) ClassifyPermissionV2() {
  702. br := new(models.BaseResponse).Init()
  703. defer func() {
  704. this.Data["json"] = br
  705. this.ServeJSON()
  706. }()
  707. sysUser := this.SysUser
  708. if sysUser == nil {
  709. br.Msg = "请登录"
  710. br.ErrMsg = "请登录,SysUser Is Empty"
  711. br.Ret = 408
  712. return
  713. }
  714. classifyId, _ := this.GetInt("ClassifyId")
  715. if classifyId <= 0 {
  716. br.Msg = "参数错误"
  717. return
  718. }
  719. resp := make([]*models.ChartPermissionItem, 0)
  720. // 拥有的品种ID列表
  721. permissionIdMap := make(map[int]bool)
  722. {
  723. //获取报告分类详情
  724. classifyInfo, err := models.GetClassifyById(classifyId)
  725. if err != nil {
  726. br.Msg = "获取分类信息失败"
  727. br.ErrMsg = "获取失败,Err:" + err.Error()
  728. return
  729. }
  730. //获取报告分类权限列表
  731. list, err := models.GetPermission(classifyInfo.Id)
  732. if err != nil {
  733. br.Msg = "获取分类信息失败"
  734. br.ErrMsg = "获取失败,Err:" + err.Error()
  735. return
  736. }
  737. for _, v := range list {
  738. permissionIdMap[v.ChartPermissionId] = true
  739. }
  740. }
  741. // 没有关联品种时,直接返回
  742. num := len(permissionIdMap)
  743. if num <= 0 {
  744. br.Ret = 200
  745. br.Success = true
  746. br.Msg = "获取成功"
  747. br.Data = resp
  748. return
  749. }
  750. cond := ` and product_id = ?`
  751. pars := make([]interface{}, 0)
  752. pars = append(pars, 1)
  753. list, e := services.GetChartPermissionList(cond, pars)
  754. if e != nil {
  755. br.Msg = "获取失败"
  756. br.ErrMsg = "获取品种列表失败, Err: " + e.Error()
  757. return
  758. }
  759. // 品种树
  760. childMap := make(map[int][]*models.ChartPermissionItem)
  761. tmpResp := make([]*models.ChartPermissionItem, 0)
  762. for _, v := range list {
  763. t := new(models.ChartPermissionItem)
  764. t.PermissionId = v.ChartPermissionId
  765. t.PermissionName = v.PermissionName
  766. t.ParentId = v.ParentId
  767. t.IsPublic = v.IsPublic
  768. t.Enabled = v.Enabled
  769. t.Sort = v.Sort
  770. t.CreateTime = v.CreatedTime.Format(utils.FormatDateTime)
  771. t.Child = make([]*models.ChartPermissionItem, 0)
  772. if v.ParentId == 0 {
  773. tmpResp = append(tmpResp, t)
  774. continue
  775. }
  776. if v.ParentId > 0 {
  777. if _, ok := permissionIdMap[v.ChartPermissionId]; ok {
  778. if childMap[v.ParentId] == nil {
  779. childMap[v.ParentId] = make([]*models.ChartPermissionItem, 0)
  780. }
  781. childMap[v.ParentId] = append(childMap[v.ParentId], t)
  782. }
  783. }
  784. }
  785. for _, r := range tmpResp {
  786. childList, ok := childMap[r.PermissionId]
  787. if !ok {
  788. continue
  789. }
  790. r.Child = childList
  791. resp = append(resp, r)
  792. }
  793. br.Ret = 200
  794. br.Success = true
  795. br.Msg = "获取成功"
  796. br.Data = resp
  797. }
  798. // 处理禅道bug6445,对数据进行补偿刷新
  799. /*func init() {
  800. err := services.DealBug6445()
  801. if err != nil {
  802. return
  803. }
  804. }
  805. */