classify.go 24 KB

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