classify.go 28 KB

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