classify.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915
  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. item, err := models.GetClassifyById(req.ClassifyId)
  195. if err != nil {
  196. br.Msg = "获取信息失败"
  197. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  198. return
  199. }
  200. if item == nil {
  201. br.Msg = "分类不存在"
  202. return
  203. }
  204. classifyList := &models.ClassifyList{Id: item.Id}
  205. err = services.MarkEnableDeleteClassify([]*models.ClassifyList{classifyList})
  206. if err != nil {
  207. br.Msg = "删除失败"
  208. br.ErrMsg = "标记失败,Err:" + err.Error()
  209. return
  210. }
  211. if classifyList.IsEnableDelete == 0 {
  212. br.Msg = "该分类有关联报告或审批流,不允许删除"
  213. return
  214. }
  215. var childClassifyIds []int
  216. if item.HasChild == 1 {
  217. // 获取所有子分类
  218. subClassifyMap := make(map[int][]int)
  219. allClassify, err := models.GetAllClassifyWithDesc()
  220. if err != nil {
  221. br.Msg = "删除失败"
  222. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  223. return
  224. }
  225. for _, classify := range allClassify {
  226. v, ok := subClassifyMap[classify.Id]
  227. if !ok {
  228. subClassifyMap[classify.Id] = []int{}
  229. }
  230. pv, pok := subClassifyMap[classify.ParentId]
  231. if pok {
  232. subClassifyMap[classify.ParentId] = append(pv, classify.Id)
  233. } else {
  234. subClassifyMap[classify.ParentId] = []int{classify.Id}
  235. }
  236. if ok {
  237. subClassifyMap[classify.ParentId] = append(subClassifyMap[classify.ParentId], v...)
  238. }
  239. }
  240. childClassifyIds = subClassifyMap[item.Id]
  241. }
  242. err = item.Delete(childClassifyIds)
  243. if err != nil {
  244. br.Msg = "删除失败"
  245. br.ErrMsg = "删除失败,Err:" + err.Error()
  246. return
  247. }
  248. // 被删除是二级分类且关联电话会时, 同步FICC活动分类
  249. //if item.ParentId > 0 && item.RelateTel == 1 {
  250. // go func() {
  251. // _ = yb.SyncClassifyAndFiccActivityType()
  252. // }()
  253. //}
  254. br.Ret = 200
  255. br.Success = true
  256. br.Msg = "删除成功"
  257. }
  258. // @Title 修改分类接口
  259. // @Description 修改分类
  260. // @Param request body models.EditClassifyReq true "type json string"
  261. // @Success 200 Ret=200,修改成功
  262. // @router /edit [post]
  263. func (this *ClassifyController) Edit() {
  264. br := new(models.BaseResponse).Init()
  265. defer func() {
  266. this.Data["json"] = br
  267. this.ServeJSON()
  268. }()
  269. var req models.EditClassifyReq
  270. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  271. if err != nil {
  272. br.Msg = "参数解析异常!"
  273. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  274. return
  275. }
  276. if req.ClassifyId <= 0 {
  277. br.Msg = "参数错误"
  278. return
  279. }
  280. if req.ClassifyName == "" {
  281. br.Msg = "分类名称不可为空"
  282. return
  283. }
  284. // 修改分类
  285. err, errMsg, isSentEmail := services.EditReportClassify(req.ClassifyId, req.ClassifyName, req.ChartPermissionIdList)
  286. if err != nil {
  287. br.Msg = "修改失败"
  288. if errMsg != "" {
  289. br.Msg = errMsg
  290. }
  291. br.ErrMsg = "修改失败,Err:" + err.Error()
  292. br.IsSendEmail = isSentEmail
  293. return
  294. }
  295. br.Ret = 200
  296. br.Success = true
  297. br.Msg = "修改成功"
  298. }
  299. // ParentClassify
  300. // @Title 获取父级分类接口
  301. // @Description 获取父级分类
  302. // @Success 200 {object} models.Classify
  303. // @router /parent [get]
  304. func (this *ClassifyController) ParentClassify() {
  305. br := new(models.BaseResponse).Init()
  306. defer func() {
  307. this.Data["json"] = br
  308. this.ServeJSON()
  309. }()
  310. items, err := models.GetAllClassify()
  311. if err != nil {
  312. br.Msg = "获取失败"
  313. br.ErrMsg = "获取失败,Err:" + err.Error()
  314. return
  315. }
  316. classifyIds := make([]int, 0)
  317. for i := range items {
  318. classifyIds = append(classifyIds, items[i].Id)
  319. }
  320. classifyLen := len(classifyIds)
  321. if classifyLen == 0 {
  322. br.Ret = 200
  323. br.Success = true
  324. br.Msg = "获取成功"
  325. return
  326. }
  327. // 获取一级分类-子目录列表
  328. menuListMap := make(map[int][]*models.ClassifyMenu, 0)
  329. var menuCond string
  330. var menuPars []interface{}
  331. menuCond += ` AND classify_id IN (` + utils.GetOrmInReplace(classifyLen) + `)`
  332. menuPars = append(menuPars, classifyIds)
  333. parentMenus, e := models.GetClassifyMenuList(menuCond, menuPars)
  334. if e != nil {
  335. br.Msg = "获取失败"
  336. br.ErrMsg = "获取一级分类子目录列表失败"
  337. return
  338. }
  339. for i := range parentMenus {
  340. if menuListMap[parentMenus[i].ClassifyId] == nil {
  341. menuListMap[parentMenus[i].ClassifyId] = make([]*models.ClassifyMenu, 0)
  342. }
  343. menuListMap[parentMenus[i].ClassifyId] = append(menuListMap[parentMenus[i].ClassifyId], parentMenus[i])
  344. }
  345. resp := make([]*models.ClassifyItem, 0)
  346. for i := range items {
  347. resp = append(resp, &models.ClassifyItem{
  348. Classify: *items[i],
  349. ClassifyMenuList: menuListMap[items[i].Id],
  350. })
  351. }
  352. resp = services.GetClassifyTreeRecursive(resp, 0)
  353. br.Data = resp
  354. br.Ret = 200
  355. br.Success = true
  356. br.Msg = "获取成功"
  357. }
  358. // @Title 根据id获取分类详情接口
  359. // @Description 根据id获取分类详情
  360. // @Param request body models.FindByIdClassifyReq true "type json string"
  361. // @Success 200 {object} models.Classify
  362. // @router /findById [get]
  363. func (this *ClassifyController) FindByIdClassify() {
  364. br := new(models.BaseResponse).Init()
  365. defer func() {
  366. this.Data["json"] = br
  367. this.ServeJSON()
  368. }()
  369. var req models.FindByIdClassifyReq
  370. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  371. if err != nil {
  372. br.Msg = "参数解析异常!"
  373. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  374. return
  375. }
  376. items, err := models.FindByIdClassify(req.ClassifyId)
  377. if err != nil {
  378. br.Msg = "获取失败"
  379. br.ErrMsg = "获取失败,Err:" + err.Error()
  380. return
  381. }
  382. br.Data = items
  383. br.Ret = 200
  384. br.Success = true
  385. br.Msg = "获取成功"
  386. }
  387. // @Title 获取分类列表
  388. // @Description 获取分类列表
  389. // @Param KeyWord query string true "检索关键词"
  390. // @Param CompanyType query string false "产品类型,枚举值:'ficc','权益';不传默认返回全部"
  391. // @Param HideDayWeek query int false "是否隐藏晨周报"
  392. // @Success 200 {object} models.Classify
  393. // @router /list [get]
  394. func (this *ClassifyController) ListClassify() {
  395. br := new(models.BaseResponse).Init()
  396. defer func() {
  397. this.Data["json"] = br
  398. this.ServeJSON()
  399. }()
  400. keyWord := this.GetString("KeyWord")
  401. reqEnabled, _ := this.GetInt("Enabled", -1)
  402. enabled := -1
  403. if reqEnabled == 1 {
  404. enabled = reqEnabled
  405. }
  406. list, err := models.GetClassifyListByKeyword(keyWord, enabled)
  407. if err != nil {
  408. br.Msg = "获取失败"
  409. br.ErrMsg = "获取失败,Err:" + err.Error()
  410. return
  411. }
  412. if keyWord != `` {
  413. idMap := make(map[int]bool)
  414. currParentClassifyIdList := make([]int, 0)
  415. for _, v := range list {
  416. idMap[v.Id] = true
  417. if v.ParentId > 0 {
  418. currParentClassifyIdList = append(currParentClassifyIdList, v.ParentId)
  419. }
  420. }
  421. findList := list
  422. list = make([]*models.ClassifyList, 0)
  423. tmpList, tmpErr := services.GetParentClassifyListByParentIdList(currParentClassifyIdList)
  424. if tmpErr != nil {
  425. br.Msg = "获取失败"
  426. br.ErrMsg = "获取上级分类信息失败,Err:" + tmpErr.Error()
  427. return
  428. }
  429. for _, v := range tmpList {
  430. if _, ok := idMap[v.Id]; !ok {
  431. list = append(list, v)
  432. }
  433. }
  434. list = append(list, findList...)
  435. }
  436. classifyIdList := make([]int, 0)
  437. for i := range list {
  438. classifyIdList = append(classifyIdList, list[i].Id)
  439. }
  440. parentIdLen := len(classifyIdList)
  441. if parentIdLen == 0 {
  442. resp := &models.ClassifyListResp{
  443. List: list,
  444. }
  445. br.Data = resp
  446. br.Ret = 200
  447. br.Success = true
  448. br.Msg = "获取成功"
  449. return
  450. }
  451. // 获取子目录列表
  452. menuListMap := make(map[int][]*models.ClassifyMenu, 0)
  453. var menuCond string
  454. var menuPars []interface{}
  455. menuCond += ` AND classify_id IN (` + utils.GetOrmInReplace(parentIdLen) + `)`
  456. menuPars = append(menuPars, classifyIdList)
  457. parentMenus, e := models.GetClassifyMenuList(menuCond, menuPars)
  458. if e != nil {
  459. br.Msg = "获取失败"
  460. br.ErrMsg = "获取一级分类子目录列表失败"
  461. return
  462. }
  463. for i := range parentMenus {
  464. if menuListMap[parentMenus[i].ClassifyId] == nil {
  465. menuListMap[parentMenus[i].ClassifyId] = make([]*models.ClassifyMenu, 0)
  466. }
  467. menuListMap[parentMenus[i].ClassifyId] = append(menuListMap[parentMenus[i].ClassifyId], parentMenus[i])
  468. }
  469. // 分类与子目录关联
  470. relateMap := make(map[int]int, 0)
  471. {
  472. var relateCond string
  473. var relatePars []interface{}
  474. relateCond += ` AND classify_id IN (` + utils.GetOrmInReplace(parentIdLen) + `)`
  475. relatePars = append(relatePars, classifyIdList)
  476. relates, e := models.GetClassifyMenuRelationList(relateCond, relatePars)
  477. if e != nil {
  478. br.Msg = "获取失败"
  479. br.ErrMsg = "获取二级分类子目录关联失败, Err: " + e.Error()
  480. return
  481. }
  482. for i := range relates {
  483. relateMap[relates[i].ClassifyId] = relates[i].MenuId
  484. }
  485. }
  486. // 查询分类绑定的权限
  487. permissionList, _ := models.GetAllPermissionMapping()
  488. classifyPermissionMap := make(map[int][]int)
  489. if len(permissionList) > 0 {
  490. for _, v := range permissionList {
  491. classifyPermissionMap[v.ClassifyId] = append(classifyPermissionMap[v.ClassifyId], v.ChartPermissionId)
  492. }
  493. }
  494. // 遍历分类并绑定子目录和权限
  495. for i, v := range list {
  496. list[i].ClassifyMenuList = menuListMap[v.Id]
  497. list[i].ClassifyMenuId = relateMap[v.Id]
  498. if permissionIds, ok := classifyPermissionMap[v.Id]; ok {
  499. list[i].ChartPermissionIdList = permissionIds
  500. }
  501. }
  502. err = services.MarkEnableDeleteClassify(list)
  503. if err != nil {
  504. br.Msg = "获取失败"
  505. br.ErrMsg = "标记可删除分类失败,Err:" + err.Error()
  506. return
  507. }
  508. // 先将分类列表排序
  509. services.SortClassifyListBySortAndCreateTime(list)
  510. // 接着转换结构
  511. list = services.GetClassifyListTreeRecursive(list, 0)
  512. resp := new(models.ClassifyListResp)
  513. resp.List = list
  514. br.Data = resp
  515. br.Ret = 200
  516. br.Success = true
  517. br.Msg = "获取成功"
  518. }
  519. // ClassifyPermission
  520. // @Title 获取分类权限列表
  521. // @Description 获取分类权限列表
  522. // @Param ClassifyId query int true "分类id"
  523. // @Success 200 {object} []models.ChartPermissionSearchKeyWordMapping
  524. // @router /permission_list [get]
  525. func (this *ClassifyController) ClassifyPermission() {
  526. br := new(models.BaseResponse).Init()
  527. defer func() {
  528. this.Data["json"] = br
  529. this.ServeJSON()
  530. }()
  531. classifyId, _ := this.GetInt("ClassifyId")
  532. if classifyId <= 0 {
  533. br.Msg = "参数错误"
  534. return
  535. }
  536. //获取报告分类详情
  537. classifyInfo, err := models.GetClassifyById(classifyId)
  538. if err != nil {
  539. br.Msg = "获取分类信息失败"
  540. br.ErrMsg = "获取失败,Err:" + err.Error()
  541. return
  542. }
  543. //获取报告分类权限列表
  544. list, err := models.GetPermissionByClassifyId(classifyInfo.Id)
  545. if err != nil {
  546. br.Msg = "获取分类信息失败"
  547. br.ErrMsg = "获取失败,Err:" + err.Error()
  548. return
  549. }
  550. br.Data = list
  551. br.Ret = 200
  552. br.Success = true
  553. br.Msg = "获取成功"
  554. }
  555. // EditClassifyPermission
  556. // @Title 编辑分类权限
  557. // @Description 编辑分类权限
  558. // @Param ClassifyId query int true "分类id"
  559. // @Success 200 {object} models.EditClassifyPermissionReq
  560. // @router /permission/edit [post]
  561. func (this *ClassifyController) EditClassifyPermission() {
  562. br := new(models.BaseResponse).Init()
  563. defer func() {
  564. this.Data["json"] = br
  565. this.ServeJSON()
  566. }()
  567. var req models.EditClassifyPermissionReq
  568. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  569. if err != nil {
  570. br.Msg = "参数解析异常!"
  571. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  572. return
  573. }
  574. if req.ClassifyId <= 0 {
  575. br.Msg = "参数错误"
  576. return
  577. }
  578. if len(req.ChartPermissionIdList) <= 0 {
  579. br.Msg = "请选择权限"
  580. return
  581. }
  582. //获取报告分类详情
  583. classifyInfo, err := models.GetClassifyById(req.ClassifyId)
  584. if err != nil {
  585. br.Msg = "获取分类信息失败"
  586. br.ErrMsg = "获取失败,Err:" + err.Error()
  587. return
  588. }
  589. //获取报告分类权限列表
  590. err = models.EditChartPermissionSearchKeyWordMappingMulti(classifyInfo.ClassifyName, req.ChartPermissionIdList, req.ClassifyId)
  591. if err != nil {
  592. br.Msg = "修改分类权限失败"
  593. br.ErrMsg = "修改分类权限失败,Err:" + err.Error()
  594. return
  595. }
  596. go func() {
  597. _ = services.EditClassifyChartPermissionSync(classifyInfo.ClassifyName, req.ClassifyId)
  598. }()
  599. // 是关联电话会二级分类修改了权限, 同步关联报告电话会的分类
  600. //if classifyInfo.ParentId > 0 && classifyInfo.RelateTel == 1 {
  601. // go func() {
  602. // _ = yb.SyncClassifyAndFiccActivityType()
  603. // }()
  604. //}
  605. br.Ret = 200
  606. br.Success = true
  607. br.Msg = "修改成功"
  608. }
  609. // @Title 含电话会分类列表
  610. // @Description 含电话会分类列表
  611. // @Success 200 {object} models.Classify
  612. // @router /tel_list [get]
  613. func (this *ClassifyController) TelListClassify() {
  614. br := new(models.BaseResponse).Init()
  615. defer func() {
  616. this.Data["json"] = br
  617. this.ServeJSON()
  618. }()
  619. resp := make([]*models.SimpleClassifyList, 0)
  620. var condition, orderRule string
  621. var pars []interface{}
  622. if utils.BusinessCode == utils.BusinessCodeRelease || utils.BusinessCode == utils.BusinessCodeSandbox {
  623. condition += ` AND classify_name <> '晨报' AND classify_name <> '周报' `
  624. }
  625. telList, e := models.GetClassifyByCondition(condition, orderRule, pars)
  626. if e != nil {
  627. return
  628. }
  629. firstList := make([]*models.SimpleClassifyList, 0)
  630. secondList := make([]*models.SimpleClassifyList, 0)
  631. secondMap := make(map[int][]*models.SimpleClassifyList, 0)
  632. for i := range telList {
  633. if telList[i].ParentId == 0 {
  634. firstList = append(firstList, telList[i])
  635. } else {
  636. secondList = append(secondList, telList[i])
  637. secondMap[telList[i].ParentId] = append(secondMap[telList[i].ParentId], telList[i])
  638. }
  639. }
  640. for i := range firstList {
  641. firstList[i].Child = secondMap[firstList[i].Id]
  642. }
  643. resp = firstList
  644. br.Data = resp
  645. br.Ret = 200
  646. br.Success = true
  647. br.Msg = "获取成功"
  648. }
  649. // Move
  650. // @Title 移动分类接口
  651. // @Description 移动分类
  652. // @Param request body models.ClassifyMoveReq true "type json string"
  653. // @Success 200 新增成功
  654. // @router /move [post]
  655. func (this *ClassifyController) Move() {
  656. br := new(models.BaseResponse).Init()
  657. defer func() {
  658. this.Data["json"] = br
  659. this.ServeJSON()
  660. }()
  661. var req models.ClassifyMoveReq
  662. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  663. if err != nil {
  664. br.Msg = "参数解析异常!"
  665. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  666. return
  667. }
  668. if req.ClassifyId <= 0 {
  669. br.Msg = "请选择分类"
  670. return
  671. }
  672. e, msg := services.MoveReportClassify(req)
  673. if e != nil {
  674. br.Msg = msg
  675. br.ErrMsg = "移动分类失败, Err: " + e.Error()
  676. return
  677. }
  678. br.Ret = 200
  679. br.Success = true
  680. br.Msg = "操作成功"
  681. }
  682. // SetEnabled
  683. // @Title 启用/禁用分类接口
  684. // @Description 启用/禁用分类
  685. // @Param request body models.ClassifyMoveReq true "type json string"
  686. // @Success 200 新增成功
  687. // @router /enabled/set [post]
  688. func (this *ClassifyController) SetEnabled() {
  689. br := new(models.BaseResponse).Init()
  690. defer func() {
  691. this.Data["json"] = br
  692. this.ServeJSON()
  693. }()
  694. var req models.ClassifySetEnabledReq
  695. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  696. if err != nil {
  697. br.Msg = "参数解析异常!"
  698. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  699. return
  700. }
  701. if req.ClassifyId <= 0 {
  702. br.Msg = "请选择分类"
  703. return
  704. }
  705. if req.Enabled != 0 && req.Enabled != 1 {
  706. br.Msg = "请选择正确的启用禁用状态"
  707. return
  708. }
  709. item, err := models.GetClassifyById(req.ClassifyId)
  710. if err != nil {
  711. if err.Error() == utils.ErrNoRow() {
  712. br.Msg = "分类不存在"
  713. return
  714. }
  715. br.Msg = "获取信息失败"
  716. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  717. return
  718. }
  719. if item == nil {
  720. br.Msg = "分类不存在"
  721. return
  722. }
  723. ob := new(models.Classify)
  724. //设置分类启用、禁用状态
  725. err = ob.SetEnabled(req.ClassifyId, req.Enabled)
  726. if err != nil {
  727. br.Msg = "操作失败"
  728. br.ErrMsg = "操作失败,Err:" + err.Error()
  729. return
  730. }
  731. br.Ret = 200
  732. br.Success = true
  733. br.Msg = "操作成功"
  734. }
  735. // ClassifyPermissionV2
  736. // @Title 获取权限设置基础信息
  737. // @Description 获取权限设置基础信息接口
  738. // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
  739. // @Param NoUpgrade query bool false "是否不展示升级权限,默认为 false"
  740. // @Success 200 {object} company.PermissionSetResp
  741. // @router /permission/list [get]
  742. func (this *ClassifyController) ClassifyPermissionV2() {
  743. br := new(models.BaseResponse).Init()
  744. defer func() {
  745. this.Data["json"] = br
  746. this.ServeJSON()
  747. }()
  748. sysUser := this.SysUser
  749. if sysUser == nil {
  750. br.Msg = "请登录"
  751. br.ErrMsg = "请登录,SysUser Is Empty"
  752. br.Ret = 408
  753. return
  754. }
  755. classifyId, _ := this.GetInt("ClassifyId")
  756. if classifyId <= 0 {
  757. br.Msg = "参数错误"
  758. return
  759. }
  760. resp := make([]*models.ChartPermissionItem, 0)
  761. // 拥有的品种ID列表
  762. permissionIdMap := make(map[int]bool)
  763. {
  764. //获取报告分类详情
  765. classifyInfo, err := models.GetClassifyById(classifyId)
  766. if err != nil {
  767. br.Msg = "获取分类信息失败"
  768. br.ErrMsg = "获取失败,Err:" + err.Error()
  769. return
  770. }
  771. //获取报告分类权限列表
  772. list, err := models.GetPermission(classifyInfo.Id)
  773. if err != nil {
  774. br.Msg = "获取分类信息失败"
  775. br.ErrMsg = "获取失败,Err:" + err.Error()
  776. return
  777. }
  778. for _, v := range list {
  779. permissionIdMap[v.ChartPermissionId] = true
  780. }
  781. }
  782. // 没有关联品种时,直接返回
  783. num := len(permissionIdMap)
  784. if num <= 0 {
  785. br.Ret = 200
  786. br.Success = true
  787. br.Msg = "获取成功"
  788. br.Data = resp
  789. return
  790. }
  791. cond := ` and product_id = ?`
  792. pars := make([]interface{}, 0)
  793. pars = append(pars, 1)
  794. list, e := services.GetChartPermissionList(cond, pars)
  795. if e != nil {
  796. br.Msg = "获取失败"
  797. br.ErrMsg = "获取品种列表失败, Err: " + e.Error()
  798. return
  799. }
  800. // 品种树
  801. childMap := make(map[int][]*models.ChartPermissionItem)
  802. tmpResp := make([]*models.ChartPermissionItem, 0)
  803. for _, v := range list {
  804. t := new(models.ChartPermissionItem)
  805. t.PermissionId = v.ChartPermissionId
  806. t.PermissionName = v.PermissionName
  807. t.ParentId = v.ParentId
  808. t.IsPublic = v.IsPublic
  809. t.Enabled = v.Enabled
  810. t.Sort = v.Sort
  811. t.CreateTime = v.CreatedTime.Format(utils.FormatDateTime)
  812. t.Child = make([]*models.ChartPermissionItem, 0)
  813. if v.ParentId == 0 {
  814. tmpResp = append(tmpResp, t)
  815. continue
  816. }
  817. if v.ParentId > 0 {
  818. if _, ok := permissionIdMap[v.ChartPermissionId]; ok {
  819. if childMap[v.ParentId] == nil {
  820. childMap[v.ParentId] = make([]*models.ChartPermissionItem, 0)
  821. }
  822. childMap[v.ParentId] = append(childMap[v.ParentId], t)
  823. }
  824. }
  825. }
  826. for _, r := range tmpResp {
  827. childList, ok := childMap[r.PermissionId]
  828. if !ok {
  829. continue
  830. }
  831. r.Child = childList
  832. resp = append(resp, r)
  833. }
  834. br.Ret = 200
  835. br.Success = true
  836. br.Msg = "获取成功"
  837. br.Data = resp
  838. }
  839. // 处理禅道bug6445,对数据进行补偿刷新
  840. /*func init() {
  841. err := services.DealBug6445()
  842. if err != nil {
  843. return
  844. }
  845. }
  846. */