classify.go 26 KB

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