classify.go 27 KB

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