classify.go 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/models"
  5. "eta/eta_api/models/system"
  6. "eta/eta_api/services"
  7. "eta/eta_api/utils"
  8. "github.com/rdlucklib/rdluck_tools/paging"
  9. "time"
  10. )
  11. // 分类
  12. type ClassifyController struct {
  13. BaseAuthController
  14. }
  15. // @Title 新增分类接口
  16. // @Description 新增分类
  17. // @Param request body models.ClassifyAddReq true "type json string"
  18. // @Success 200 新增成功
  19. // @router /add [post]
  20. func (this *ClassifyController) Add() {
  21. br := new(models.BaseResponse).Init()
  22. defer func() {
  23. this.Data["json"] = br
  24. this.ServeJSON()
  25. }()
  26. var req models.ClassifyAddReq
  27. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  28. if err != nil {
  29. br.Msg = "参数解析异常!"
  30. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  31. return
  32. }
  33. // 获取系统菜单, 如果没有对应的字段的特殊处理项, 则忽略必填
  34. menus, e := system.GetSysMenuItemsByCondition(` AND hidden = 0`, make([]interface{}, 0), []string{}, ``)
  35. if e != nil {
  36. br.Msg = "保存失败"
  37. br.ErrMsg = "获取菜单列表失败, Err: " + e.Error()
  38. return
  39. }
  40. menuMap := make(map[string]bool)
  41. for _, m := range menus {
  42. if m.ButtonCode != "" {
  43. menuMap[m.ButtonCode] = true
  44. }
  45. }
  46. if req.ClassifyName == "" {
  47. br.Msg = "分类名称不可为空"
  48. return
  49. }
  50. if menuMap[system.MenuSpecialHandleClassifyShowType] && req.ParentId != 0 && req.ShowType == 0 {
  51. br.Msg = "展示类型不可为空"
  52. return
  53. }
  54. if menuMap[system.MenuSpecialHandleClassifyChildMenu] && len(req.MenuList) > 0 && req.ParentId != 0 {
  55. br.Msg = "非一级分类不可添加子目录"
  56. return
  57. }
  58. if menuMap[system.MenuSpecialHandleClassifyReportImgs] && (req.ShowType == 1 || req.ShowType == 3) && req.YbRightBanner == "" && req.ParentId == 0 { //当一级报告分类为列表、品种时,增加“报告合集配图”的配置项
  59. br.Msg = "报告合集配图不可为空"
  60. return
  61. }
  62. item, err := models.GetClassifyByName(req.ClassifyName, req.ParentId)
  63. if err != nil && err.Error() != utils.ErrNoRow() {
  64. br.Msg = "获取分类信息失败"
  65. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  66. return
  67. }
  68. if item != nil {
  69. br.Msg = "分类名称:" + req.ClassifyName + "已存在"
  70. return
  71. }
  72. nowTime := time.Now().Local()
  73. classify := new(models.Classify)
  74. classify.ClassifyName = req.ClassifyName
  75. classify.ParentId = req.ParentId
  76. classify.CreateTime = nowTime
  77. classify.ModifyTime = nowTime
  78. classify.Abstract = req.Abstract
  79. classify.Descript = req.Descript
  80. classify.Abstract = req.Abstract
  81. classify.Descript = req.Descript
  82. classify.ReportAuthor = req.ReportAuthor
  83. classify.AuthorDescript = req.AuthorDescript
  84. classify.ColumnImgUrl = req.ColumnImgUrl
  85. classify.ReportImgUrl = req.ReportImgUrl
  86. classify.HeadImgUrl = req.HeadImgUrl
  87. classify.AvatarImgUrl = req.AvatarImgUrl
  88. classify.HomeImgUrl = req.HomeImgUrl
  89. classify.ClassifyLabel = req.ClassifyLabel
  90. classify.ShowType = req.ShowType
  91. classify.HasTeleconference = req.HasTeleconference
  92. classify.VipTitle = req.VipTitle
  93. classify.Sort = req.Sort
  94. classify.IsShow = req.IsShow
  95. classify.YbFiccSort = req.YbFiccSort
  96. classify.YbFiccIcon = req.YbFiccIcon
  97. classify.YbFiccPcIcon = req.YbFiccPcIcon
  98. classify.YbIconUrl = req.YbIconUrl
  99. classify.YbBgUrl = req.YbBgUrl
  100. classify.YbListImg = req.YbListImg
  101. classify.YbShareBgImg = req.YbShareBgImg
  102. classify.YbRightBanner = req.YbRightBanner
  103. classify.RelateTel = req.RelateTel
  104. classify.RelateVideo = req.RelateVideo
  105. if req.ParentId > 0 {
  106. parentClassify := new(models.Classify)
  107. if parentClassify, err = models.GetClassifyById(req.ParentId); err != nil {
  108. br.Msg = "获取父级分类信息失败"
  109. br.ErrMsg = "获取父级分类信息失败, Err:" + err.Error()
  110. return
  111. }
  112. updateParent := false
  113. updateCols := make([]string, 0)
  114. updateCols = append(updateCols, "HasTeleconference")
  115. if req.HasTeleconference == 1 {
  116. // 二级分类包含电话会,则一级分类也默认包含电话会
  117. if parentClassify.HasTeleconference == 0 {
  118. parentClassify.HasTeleconference = 1
  119. updateParent = true
  120. }
  121. } else {
  122. // 二级分类均无电话会,则一级分类也无电话会
  123. if parentClassify.HasTeleconference == 1 {
  124. child, err := models.GetClassifyChild(parentClassify.Id, "")
  125. if err != nil {
  126. br.Msg = "获取子分类失败"
  127. br.ErrMsg = "获取子分类失败,Err:" + err.Error()
  128. return
  129. }
  130. // 存在同一级分类下的二级分类有电话会则不变动
  131. hasTel := false
  132. for i := 0; i < len(child); i++ {
  133. if child[i].HasTeleconference == 1 {
  134. hasTel = true
  135. break
  136. }
  137. }
  138. if !hasTel {
  139. parentClassify.HasTeleconference = 0
  140. updateParent = true
  141. }
  142. }
  143. }
  144. if updateParent {
  145. if err = parentClassify.UpdateClassify(updateCols); err != nil {
  146. br.Msg = "更新父级分类失败"
  147. br.ErrMsg = "更新父级分类失败, Err:" + err.Error()
  148. return
  149. }
  150. }
  151. }
  152. err = models.AddClassify(classify)
  153. if err != nil {
  154. br.Msg = "新增失败"
  155. br.ErrMsg = "新增失败,Err:" + err.Error()
  156. return
  157. }
  158. // 一级分类-新增子目录
  159. if classify.ParentId == 0 && len(req.MenuList) > 0 {
  160. menus := make([]*models.ClassifyMenu, 0)
  161. for i := range req.MenuList {
  162. menus = append(menus, &models.ClassifyMenu{
  163. MenuName: req.MenuList[i].MenuName,
  164. ClassifyId: classify.Id,
  165. Sort: i + 1,
  166. CreateTime: nowTime,
  167. ModifyTime: nowTime,
  168. })
  169. }
  170. menuObj := new(models.ClassifyMenu)
  171. if e := menuObj.InsertMulti(menus); e != nil {
  172. br.Msg = "新增子目录失败"
  173. br.ErrMsg = "批量新增子目录失败, Err:" + e.Error()
  174. return
  175. }
  176. }
  177. // 二级分类-新增子目录关联
  178. if classify.ParentId > 0 && req.ClassifyMenuId > 0 {
  179. if e := models.DeleteAndInsertClassifyMenuRelation(classify.Id, req.ClassifyMenuId); e != nil {
  180. br.Msg = "新增子目录关联失败"
  181. br.ErrMsg = "新增子目录关联失败, Err:" + e.Error()
  182. return
  183. }
  184. }
  185. // 新增关联了电话会的二级分类时, 同步FICC活动分类
  186. //if req.ParentId > 0 && req.RelateTel == 1 {
  187. // go func() {
  188. // _ = yb.SyncClassifyAndFiccActivityType()
  189. // }()
  190. //}
  191. br.Ret = 200
  192. br.Success = true
  193. br.Msg = "新增成功"
  194. }
  195. // @Title 删除分类-检测接口
  196. // @Description 删除分类-信息检测,是否符合删除条件
  197. // @Param ClassifyId query int true "分类ID"
  198. // @Success 200 {object} models.CheckDeleteClassifyResp
  199. // @router /checkDeleteClassify [get]
  200. func (this *ClassifyController) CheckDeleteClassify() {
  201. br := new(models.BaseResponse).Init()
  202. defer func() {
  203. this.Data["json"] = br
  204. this.ServeJSON()
  205. }()
  206. classifyId, err := this.GetInt("ClassifyId")
  207. if classifyId <= 0 {
  208. br.Msg = "参数错误"
  209. return
  210. }
  211. classify, err := models.GetClassifyById(classifyId)
  212. if err != nil {
  213. br.Msg = "获取信息失败"
  214. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  215. return
  216. }
  217. resp := new(models.CheckDeleteClassifyResp)
  218. if classify == nil {
  219. br.Msg = "分类不存在"
  220. resp.Code = 1
  221. resp.Msg = "分类不存在"
  222. br.Data = resp
  223. br.Ret = 200
  224. br.Success = true
  225. return
  226. }
  227. //判断分类是否关联了报告
  228. if classify.ParentId > 0 {
  229. count, err := models.GetReportCountByClassifyId(classifyId)
  230. if err != nil {
  231. br.Msg = "获取信息失败"
  232. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  233. return
  234. }
  235. if count > 0 {
  236. resp.Code = 2
  237. resp.Msg = "该分类有关联报告,不允许删除"
  238. br.Data = resp
  239. br.Ret = 200
  240. br.Msg = "该分类有关联报告,不允许删除"
  241. br.Success = true
  242. return
  243. }
  244. } else {
  245. subCount, err := models.GetClassifySubCountByClassifyId(classifyId)
  246. if err != nil {
  247. br.Msg = "获取信息失败"
  248. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  249. return
  250. }
  251. if subCount > 0 {
  252. resp.Code = 3
  253. resp.Msg = "二级分类有关联报告,不允许删除"
  254. br.Data = resp
  255. br.Ret = 200
  256. br.Msg = "二级分类有关联报告,不允许删除"
  257. br.Success = true
  258. return
  259. }
  260. subTotal, err := models.GetClassifySubCountByParentId(classifyId)
  261. if err != nil {
  262. br.Msg = "获取信息失败"
  263. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  264. return
  265. }
  266. if subTotal > 0 {
  267. resp.Code = 4
  268. resp.Msg = "请先删除该分类下关联分类"
  269. br.Data = resp
  270. br.Ret = 200
  271. br.Msg = "请先删除该分类下关联分类"
  272. br.Success = true
  273. return
  274. }
  275. }
  276. resp.Code = 0
  277. resp.Msg = "检测完成,可进行删除操作"
  278. br.Ret = 200
  279. br.Data = resp
  280. br.Success = true
  281. br.Msg = "检测成功"
  282. }
  283. // @Title 删除分类接口
  284. // @Description 删除分类
  285. // @Param request body models.DeleteClassifyReq true "type json string"
  286. // @Success 200 Ret=200,删除成功
  287. // @router /delete [post]
  288. func (this *ClassifyController) Delete() {
  289. br := new(models.BaseResponse).Init()
  290. defer func() {
  291. this.Data["json"] = br
  292. this.ServeJSON()
  293. }()
  294. var req models.DeleteClassifyReq
  295. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  296. if err != nil {
  297. br.Msg = "参数解析异常!"
  298. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  299. return
  300. }
  301. if req.ClassifyId <= 0 {
  302. br.Msg = "参数错误"
  303. return
  304. }
  305. item, err := models.GetClassifyById(req.ClassifyId)
  306. if err != nil {
  307. br.Msg = "获取信息失败"
  308. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  309. return
  310. }
  311. if item == nil {
  312. br.Msg = "分类不存在"
  313. return
  314. }
  315. err = models.DeleteClassify(req.ClassifyId)
  316. if err != nil {
  317. br.Msg = "删除失败"
  318. br.ErrMsg = "删除失败,Err:" + err.Error()
  319. return
  320. }
  321. // 被删除是二级分类且关联电话会时, 同步FICC活动分类
  322. //if item.ParentId > 0 && item.RelateTel == 1 {
  323. // go func() {
  324. // _ = yb.SyncClassifyAndFiccActivityType()
  325. // }()
  326. //}
  327. br.Ret = 200
  328. br.Success = true
  329. br.Msg = "删除成功"
  330. }
  331. // @Title 修改分类接口
  332. // @Description 修改分类
  333. // @Param request body models.EditClassifyReq true "type json string"
  334. // @Success 200 Ret=200,修改成功
  335. // @router /edit [post]
  336. func (this *ClassifyController) Edit() {
  337. br := new(models.BaseResponse).Init()
  338. defer func() {
  339. this.Data["json"] = br
  340. this.ServeJSON()
  341. }()
  342. var req models.EditClassifyReq
  343. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  344. if err != nil {
  345. br.Msg = "参数解析异常!"
  346. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  347. return
  348. }
  349. // 获取系统菜单, 如果没有对应的字段的特殊处理项, 则忽略必填
  350. menus, e := system.GetSysMenuItemsByCondition(` AND hidden = 0`, make([]interface{}, 0), []string{}, ``)
  351. if e != nil {
  352. br.Msg = "保存失败"
  353. br.ErrMsg = "获取菜单列表失败, Err: " + e.Error()
  354. return
  355. }
  356. menuMap := make(map[string]bool)
  357. for _, m := range menus {
  358. if m.ButtonCode != "" {
  359. menuMap[m.ButtonCode] = true
  360. }
  361. }
  362. if req.ClassifyId <= 0 {
  363. br.Msg = "参数错误"
  364. return
  365. }
  366. if req.ClassifyName == "" {
  367. br.Msg = "分类名称不可为空"
  368. return
  369. }
  370. if menuMap[system.MenuSpecialHandleClassifyShowType] && req.ParentId != 0 && req.ShowType == 0 {
  371. br.Msg = "展示类型不可为空"
  372. return
  373. }
  374. if req.ParentId == req.ClassifyId {
  375. br.Msg = "上级分类不能选择自己"
  376. return
  377. }
  378. if menuMap[system.MenuSpecialHandleClassifyReportImgs] && (req.ShowType == 1 || req.ShowType == 3) && req.YbRightBanner == "" && req.ParentId == 0 { //当一级报告分类为列表、品种时,增加“报告合集配图”的配置项
  379. br.Msg = "报告合集配图不可为空"
  380. return
  381. }
  382. item, err := models.GetClassifyById(req.ClassifyId)
  383. if err != nil {
  384. if err.Error() == utils.ErrNoRow() {
  385. br.Msg = "分类不存在, 或已被删除"
  386. br.ErrMsg = "获取分类信息失败, Err: " + err.Error()
  387. return
  388. }
  389. br.Msg = "获取信息失败"
  390. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  391. return
  392. }
  393. originName := item.ClassifyName
  394. oldParentId := item.ParentId
  395. //originRelateTel := item.RelateTel
  396. // 重名校验
  397. existName, e := models.GetClassifyByName(req.ClassifyName, item.ParentId)
  398. if e != nil && e.Error() != utils.ErrNoRow() {
  399. br.Msg = "获取信息失败"
  400. br.ErrMsg = "获取重名分类失败, Err: " + err.Error()
  401. return
  402. }
  403. if existName != nil && existName.Id != item.Id {
  404. br.Msg = "分类名称:" + req.ClassifyName + "已存在"
  405. return
  406. }
  407. item.ClassifyName = req.ClassifyName
  408. item.Abstract = req.Abstract
  409. item.ParentId = req.ParentId
  410. item.Descript = req.Descript
  411. item.ReportAuthor = req.ReportAuthor
  412. item.AuthorDescript = req.AuthorDescript
  413. item.ColumnImgUrl = req.ColumnImgUrl
  414. item.HeadImgUrl = req.HeadImgUrl
  415. item.AvatarImgUrl = req.AvatarImgUrl
  416. item.ReportImgUrl = req.ReportImgUrl
  417. item.HomeImgUrl = req.HomeImgUrl
  418. item.ClassifyLabel = req.ClassifyLabel
  419. item.ShowType = req.ShowType
  420. item.HasTeleconference = req.HasTeleconference
  421. item.VipTitle = req.VipTitle
  422. item.Sort = req.Sort
  423. item.IsShow = req.IsShow
  424. item.YbFiccSort = req.YbFiccSort
  425. item.YbFiccIcon = req.YbFiccIcon
  426. item.YbFiccPcIcon = req.YbFiccPcIcon
  427. item.YbIconUrl = req.YbIconUrl
  428. item.YbBgUrl = req.YbBgUrl
  429. item.YbListImg = req.YbListImg
  430. item.YbShareBgImg = req.YbShareBgImg
  431. item.YbRightBanner = req.YbRightBanner
  432. item.RelateTel = req.RelateTel
  433. item.RelateVideo = req.RelateVideo
  434. item.ModifyTime = time.Now().Local()
  435. cols := make([]string, 0)
  436. cols = append(cols, "ClassifyName", "Abstract", "ParentId", "Descript", "ReportAuthor", "AuthorDescript", "ColumnImgUrl",
  437. "HeadImgUrl", "AvatarImgUrl", "ReportImgUrl", "HomeImgUrl", "ClassifyLabel", "ShowType", "HasTeleconference", "VipTitle", "Sort",
  438. "IsShow", "YbFiccSort", "YbFiccIcon", "YbFiccPcIcon", "YbIconUrl", "YbBgUrl", "YbListImg", "YbShareBgImg", "YbRightBanner",
  439. "RelateTel", "RelateVideo", "ModifyTime")
  440. if e := item.UpdateClassify(cols); e != nil {
  441. br.Msg = "修改失败"
  442. br.ErrMsg = "修改失败,Err:" + e.Error()
  443. return
  444. }
  445. // 一级分类关联设置会强制修改二级分类的所有关联设置
  446. if item.ParentId == 0 {
  447. if e = models.UpdateChildClassifyRelateSetting(item.Id, req.RelateTel, req.RelateVideo); e != nil {
  448. br.Msg = "更新二级分类关联设置失败"
  449. br.ErrMsg = "更新二级分类关联设置失败, Err: " + e.Error()
  450. return
  451. }
  452. }
  453. // 为二级分类时, 更新父级分类是否含电话会字段
  454. if req.ParentId > 0 {
  455. go func() {
  456. _ = services.UpdateParentClassifyHasTel(req.ClassifyId, req.ParentId, req.HasTeleconference)
  457. }()
  458. }
  459. // 更新报告分类名称/父级分类后
  460. go func() {
  461. _ = services.AfterUpdateClassifyNameOrParent(item.Id, item.ParentId, oldParentId, originName, item.ClassifyName)
  462. }()
  463. // 获取编辑前子目录列表
  464. classifyId := item.Id
  465. var menuCond string
  466. var menuPars []interface{}
  467. menuCond += ` AND classify_id = ?`
  468. menuPars = append(menuPars, classifyId)
  469. menuList, e := models.GetClassifyMenuList(menuCond, menuPars)
  470. if e != nil {
  471. br.Msg = "保存失败"
  472. br.ErrMsg = "获取分类子目录列表失败, Err:" + e.Error()
  473. return
  474. }
  475. oriMenuIds := make([]int, 0)
  476. for i := range menuList {
  477. oriMenuIds = append(oriMenuIds, menuList[i].MenuId)
  478. }
  479. // 一级分类-新增/编辑/删除子目录
  480. if item.ParentId == 0 && len(req.MenuList) > 0 {
  481. nowTime := time.Now().Local()
  482. insertMenus := make([]*models.ClassifyMenu, 0)
  483. editMenus := make([]*models.ClassifyMenu, 0)
  484. deleteMenuIds := make([]int, 0)
  485. menuIds := make([]int, 0)
  486. for i := range req.MenuList {
  487. m := req.MenuList[i]
  488. v := new(models.ClassifyMenu)
  489. v.MenuName = req.MenuList[i].MenuName
  490. v.ClassifyId = classifyId
  491. v.Sort = i + 1
  492. v.MenuId = m.MenuId
  493. v.ModifyTime = nowTime
  494. if v.MenuId > 0 {
  495. // 编辑
  496. editMenus = append(editMenus, v)
  497. menuIds = append(menuIds, m.MenuId)
  498. } else {
  499. // 新增
  500. v.CreateTime = nowTime
  501. insertMenus = append(insertMenus, v)
  502. }
  503. }
  504. // 编辑前存在子目录则取"编辑前子目录IDs与编辑时子目录IDs的差集"作为删除IDs
  505. if len(oriMenuIds) > 0 {
  506. deleteMenuIds = utils.MinusInt(oriMenuIds, menuIds)
  507. }
  508. if e = models.InsertAndUpdateClassifyMenu(insertMenus, editMenus, deleteMenuIds); e != nil {
  509. br.Msg = "保存失败"
  510. br.ErrMsg = "新增/编辑/删除分类子目录失败, Err:" + e.Error()
  511. return
  512. }
  513. }
  514. // 二级分类-新增子目录关联
  515. if item.ParentId > 0 {
  516. if e := models.DeleteAndInsertClassifyMenuRelation(classifyId, req.ClassifyMenuId); e != nil {
  517. br.Msg = "新增子目录关联失败"
  518. br.ErrMsg = "新增子目录关联失败, Err:" + e.Error()
  519. return
  520. }
  521. }
  522. // 关联电话会选项被更改时, 同步FICC活动分类
  523. //if originRelateTel != req.RelateTel {
  524. // go func() {
  525. // _ = yb.SyncClassifyAndFiccActivityType()
  526. // }()
  527. //}
  528. br.Ret = 200
  529. br.Success = true
  530. br.Msg = "修改成功"
  531. }
  532. // @Title 获取父级分类接口
  533. // @Description 获取父级分类
  534. // @Success 200 {object} models.Classify
  535. // @router /parent [get]
  536. func (this *ClassifyController) ParentClassify() {
  537. br := new(models.BaseResponse).Init()
  538. defer func() {
  539. this.Data["json"] = br
  540. this.ServeJSON()
  541. }()
  542. items, err := models.ParentClassify()
  543. if err != nil {
  544. br.Msg = "获取失败"
  545. br.ErrMsg = "获取失败,Err:" + err.Error()
  546. return
  547. }
  548. classifyIds := make([]int, 0)
  549. for i := range items {
  550. classifyIds = append(classifyIds, items[i].Id)
  551. }
  552. classifyLen := len(classifyIds)
  553. if classifyLen == 0 {
  554. br.Ret = 200
  555. br.Success = true
  556. br.Msg = "获取成功"
  557. return
  558. }
  559. // 获取一级分类-子目录列表
  560. menuListMap := make(map[int][]*models.ClassifyMenu, 0)
  561. var menuCond string
  562. var menuPars []interface{}
  563. menuCond += ` AND classify_id IN (` + utils.GetOrmInReplace(classifyLen) + `)`
  564. menuPars = append(menuPars, classifyIds)
  565. parentMenus, e := models.GetClassifyMenuList(menuCond, menuPars)
  566. if e != nil {
  567. br.Msg = "获取失败"
  568. br.ErrMsg = "获取一级分类子目录列表失败"
  569. return
  570. }
  571. for i := range parentMenus {
  572. if menuListMap[parentMenus[i].ClassifyId] == nil {
  573. menuListMap[parentMenus[i].ClassifyId] = make([]*models.ClassifyMenu, 0)
  574. }
  575. menuListMap[parentMenus[i].ClassifyId] = append(menuListMap[parentMenus[i].ClassifyId], parentMenus[i])
  576. }
  577. resp := make([]*models.ClassifyItem, 0)
  578. for i := range items {
  579. resp = append(resp, &models.ClassifyItem{
  580. Classify: *items[i],
  581. ClassifyMenuList: menuListMap[items[i].Id],
  582. })
  583. }
  584. br.Data = resp
  585. br.Ret = 200
  586. br.Success = true
  587. br.Msg = "获取成功"
  588. }
  589. // @Title 根据id获取分类详情接口
  590. // @Description 根据id获取分类详情
  591. // @Param request body models.FindByIdClassifyReq true "type json string"
  592. // @Success 200 {object} models.Classify
  593. // @router /findById [get]
  594. func (this *ClassifyController) FindByIdClassify() {
  595. br := new(models.BaseResponse).Init()
  596. defer func() {
  597. this.Data["json"] = br
  598. this.ServeJSON()
  599. }()
  600. var req models.FindByIdClassifyReq
  601. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  602. if err != nil {
  603. br.Msg = "参数解析异常!"
  604. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  605. return
  606. }
  607. items, err := models.FindByIdClassify(req.ClassifyId)
  608. if err != nil {
  609. br.Msg = "获取失败"
  610. br.ErrMsg = "获取失败,Err:" + err.Error()
  611. return
  612. }
  613. br.Data = items
  614. br.Ret = 200
  615. br.Success = true
  616. br.Msg = "获取成功"
  617. }
  618. // @Title 获取分类列表
  619. // @Description 获取分类列表
  620. // @Param PageSize query int true "每页数据条数"
  621. // @Param CurrentIndex query int true "当前页页码,从1开始"
  622. // @Param KeyWord query string true "检索关键词"
  623. // @Param CompanyType query string false "产品类型,枚举值:'ficc','权益';不传默认返回全部"
  624. // @Param HideDayWeek query int false "是否隐藏晨周报"
  625. // @Success 200 {object} models.Classify
  626. // @router /list [get]
  627. func (this *ClassifyController) ListClassify() {
  628. br := new(models.BaseResponse).Init()
  629. defer func() {
  630. this.Data["json"] = br
  631. this.ServeJSON()
  632. }()
  633. pageSize, _ := this.GetInt("PageSize")
  634. currentIndex, _ := this.GetInt("CurrentIndex")
  635. keyWord := this.GetString("KeyWord")
  636. companyType := this.GetString("CompanyType")
  637. hideDayWeek, _ := this.GetInt("HideDayWeek")
  638. var startSize int
  639. if pageSize <= 0 {
  640. pageSize = utils.PageSize20
  641. }
  642. if currentIndex <= 0 {
  643. currentIndex = 1
  644. }
  645. startSize = utils.StartIndex(currentIndex, pageSize)
  646. list, err := models.GetClassifyList(startSize, pageSize, keyWord, companyType, hideDayWeek)
  647. if err != nil {
  648. br.Msg = "获取失败"
  649. br.ErrMsg = "获取失败,Err:" + err.Error()
  650. return
  651. }
  652. total, err := models.GetClassifyListCount(keyWord, companyType, hideDayWeek)
  653. if err != nil {
  654. br.Msg = "获取失败"
  655. br.ErrMsg = "获取失败,Err:" + err.Error()
  656. return
  657. }
  658. parentIds := make([]int, 0)
  659. for i := range list {
  660. parentIds = append(parentIds, list[i].Id)
  661. }
  662. parentIdLen := len(parentIds)
  663. if parentIdLen == 0 {
  664. resp := &models.ClassifyListResp{
  665. List: list,
  666. Paging: paging.GetPaging(currentIndex, pageSize, 0),
  667. }
  668. br.Data = resp
  669. br.Ret = 200
  670. br.Success = true
  671. br.Msg = "获取成功"
  672. return
  673. }
  674. // 获取一级分类-子目录列表
  675. menuListMap := make(map[int][]*models.ClassifyMenu, 0)
  676. var menuCond string
  677. var menuPars []interface{}
  678. menuCond += ` AND classify_id IN (` + utils.GetOrmInReplace(parentIdLen) + `)`
  679. menuPars = append(menuPars, parentIds)
  680. parentMenus, e := models.GetClassifyMenuList(menuCond, menuPars)
  681. if e != nil {
  682. br.Msg = "获取失败"
  683. br.ErrMsg = "获取一级分类子目录列表失败"
  684. return
  685. }
  686. for i := range parentMenus {
  687. if menuListMap[parentMenus[i].ClassifyId] == nil {
  688. menuListMap[parentMenus[i].ClassifyId] = make([]*models.ClassifyMenu, 0)
  689. }
  690. menuListMap[parentMenus[i].ClassifyId] = append(menuListMap[parentMenus[i].ClassifyId], parentMenus[i])
  691. }
  692. // 获取子分类
  693. children, e := models.GetClassifyChildByParentIds(parentIds, keyWord)
  694. if e != nil {
  695. br.Msg = "获取失败"
  696. br.ErrMsg = "获取子分类失败"
  697. return
  698. }
  699. childrenIds := make([]int, 0)
  700. for i := range children {
  701. childrenIds = append(childrenIds, children[i].Id)
  702. }
  703. childrenIdsLen := len(childrenIds)
  704. // 获取二级分类-子目录关联
  705. relateMap := make(map[int]int, 0)
  706. if childrenIdsLen > 0 {
  707. var relateCond string
  708. var relatePars []interface{}
  709. relateCond += ` AND classify_id IN (` + utils.GetOrmInReplace(childrenIdsLen) + `)`
  710. relatePars = append(relatePars, childrenIds)
  711. relates, e := models.GetClassifyMenuRelationList(relateCond, relatePars)
  712. if e != nil {
  713. br.Msg = "获取失败"
  714. br.ErrMsg = "获取二级分类子目录关联失败, Err: " + e.Error()
  715. return
  716. }
  717. for i := range relates {
  718. relateMap[relates[i].ClassifyId] = relates[i].MenuId
  719. }
  720. }
  721. // 二级分类
  722. childrenMap := make(map[int][]*models.ClassifyItem, 0)
  723. for i := range children {
  724. if childrenMap[children[i].ParentId] == nil {
  725. childrenMap[children[i].ParentId] = make([]*models.ClassifyItem, 0)
  726. }
  727. childrenMap[children[i].ParentId] = append(childrenMap[children[i].ParentId], &models.ClassifyItem{
  728. Classify: *children[i],
  729. ClassifyMenuId: relateMap[children[i].Id],
  730. })
  731. }
  732. // 一级分类
  733. for i := range list {
  734. list[i].ClassifyMenuList = menuListMap[list[i].Id]
  735. list[i].Child = childrenMap[list[i].Id]
  736. }
  737. page := paging.GetPaging(currentIndex, pageSize, total)
  738. resp := new(models.ClassifyListResp)
  739. resp.List = list
  740. resp.Paging = page
  741. br.Data = resp
  742. br.Ret = 200
  743. br.Success = true
  744. br.Msg = "获取成功"
  745. }
  746. // ClassifyPermission
  747. // @Title 获取分类权限列表
  748. // @Description 获取分类权限列表
  749. // @Param ClassifyId query int true "分类id"
  750. // @Success 200 {object} []models.ChartPermissionSearchKeyWordMapping
  751. // @router /permission_list [get]
  752. func (this *ClassifyController) ClassifyPermission() {
  753. br := new(models.BaseResponse).Init()
  754. defer func() {
  755. this.Data["json"] = br
  756. this.ServeJSON()
  757. }()
  758. classifyId, _ := this.GetInt("ClassifyId")
  759. if classifyId <= 0 {
  760. br.Msg = "参数错误"
  761. return
  762. }
  763. //获取报告分类详情
  764. classifyInfo, err := models.GetClassifyById(classifyId)
  765. if err != nil {
  766. br.Msg = "获取分类信息失败"
  767. br.ErrMsg = "获取失败,Err:" + err.Error()
  768. return
  769. }
  770. //获取报告分类权限列表
  771. list, err := models.GetPermission(classifyInfo.ClassifyName)
  772. if err != nil {
  773. br.Msg = "获取分类信息失败"
  774. br.ErrMsg = "获取失败,Err:" + err.Error()
  775. return
  776. }
  777. br.Data = list
  778. br.Ret = 200
  779. br.Success = true
  780. br.Msg = "获取成功"
  781. }
  782. // EditClassifyPermission
  783. // @Title 编辑分类权限
  784. // @Description 编辑分类权限
  785. // @Param ClassifyId query int true "分类id"
  786. // @Success 200 {object} models.EditClassifyPermissionReq
  787. // @router /permission/edit [post]
  788. func (this *ClassifyController) EditClassifyPermission() {
  789. br := new(models.BaseResponse).Init()
  790. defer func() {
  791. this.Data["json"] = br
  792. this.ServeJSON()
  793. }()
  794. var req models.EditClassifyPermissionReq
  795. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  796. if err != nil {
  797. br.Msg = "参数解析异常!"
  798. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  799. return
  800. }
  801. if req.ClassifyId <= 0 {
  802. br.Msg = "参数错误"
  803. return
  804. }
  805. if len(req.ChartPermissionIdList) <= 0 {
  806. br.Msg = "请选择权限"
  807. return
  808. }
  809. //获取报告分类详情
  810. classifyInfo, err := models.GetClassifyById(req.ClassifyId)
  811. if err != nil {
  812. br.Msg = "获取分类信息失败"
  813. br.ErrMsg = "获取失败,Err:" + err.Error()
  814. return
  815. }
  816. //获取报告分类权限列表
  817. err = models.EditChartPermissionSearchKeyWordMappingMulti(classifyInfo.ClassifyName, req.ChartPermissionIdList)
  818. if err != nil {
  819. br.Msg = "修改分类权限失败"
  820. br.ErrMsg = "修改分类权限失败,Err:" + err.Error()
  821. return
  822. }
  823. // 是关联电话会二级分类修改了权限, 同步关联报告电话会的分类
  824. //if classifyInfo.ParentId > 0 && classifyInfo.RelateTel == 1 {
  825. // go func() {
  826. // _ = yb.SyncClassifyAndFiccActivityType()
  827. // }()
  828. //}
  829. br.Ret = 200
  830. br.Success = true
  831. br.Msg = "修改成功"
  832. }
  833. // @Title 含电话会分类列表
  834. // @Description 含电话会分类列表
  835. // @Success 200 {object} models.Classify
  836. // @router /tel_list [get]
  837. func (this *ClassifyController) TelListClassify() {
  838. br := new(models.BaseResponse).Init()
  839. defer func() {
  840. this.Data["json"] = br
  841. this.ServeJSON()
  842. }()
  843. resp := make([]*models.SimpleClassifyList, 0)
  844. var condition, orderRule string
  845. var pars []interface{}
  846. if utils.BusinessCode == utils.BusinessCodeRelease || utils.BusinessCode == utils.BusinessCodeSandbox {
  847. condition += ` AND classify_name <> '晨报' AND classify_name <> '周报' `
  848. }
  849. telList, e := models.GetClassifyByCondition(condition, orderRule, pars)
  850. if e != nil {
  851. return
  852. }
  853. firstList := make([]*models.SimpleClassifyList, 0)
  854. secondList := make([]*models.SimpleClassifyList, 0)
  855. secondMap := make(map[int][]*models.SimpleClassifyList, 0)
  856. for i := range telList {
  857. if telList[i].ParentId == 0 {
  858. firstList = append(firstList, telList[i])
  859. } else {
  860. secondList = append(secondList, telList[i])
  861. secondMap[telList[i].ParentId] = append(secondMap[telList[i].ParentId], telList[i])
  862. }
  863. }
  864. for i := range firstList {
  865. firstList[i].Child = secondMap[firstList[i].Id]
  866. }
  867. resp = firstList
  868. br.Data = resp
  869. br.Ret = 200
  870. br.Success = true
  871. br.Msg = "获取成功"
  872. }