english_classify.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  1. package english_report
  2. import (
  3. "encoding/json"
  4. "eta/eta_mobile/controllers"
  5. "eta/eta_mobile/models"
  6. "eta/eta_mobile/models/report_approve"
  7. "eta/eta_mobile/services"
  8. "eta/eta_mobile/utils"
  9. "fmt"
  10. "sort"
  11. "time"
  12. )
  13. // EnglishClassifyController 英文分类
  14. type EnglishClassifyController struct {
  15. controllers.BaseAuthController
  16. }
  17. // ListClassify
  18. // @Title 获取分类列表
  19. // @Description 获取分类列表
  20. // @Param PageSize query int true "每页数据条数"
  21. // @Param CurrentIndex query int true "当前页页码,从1开始"
  22. // @Param KeyWord query string true "检索关键词"
  23. // @Param CompanyType query string false "产品类型,枚举值:'ficc','权益';不传默认返回全部"
  24. // @Success 200 {object} models.EnglishClassifyListResp
  25. // @router /classify/list [get]
  26. func (this *EnglishReportController) ListClassify() {
  27. br := new(models.BaseResponse).Init()
  28. defer func() {
  29. this.Data["json"] = br
  30. this.ServeJSON()
  31. }()
  32. keyWord := this.GetString("KeyWord")
  33. reqEnabled, _ := this.GetInt("Enabled", -1)
  34. enabled := -1
  35. if reqEnabled == 1 {
  36. enabled = reqEnabled
  37. }
  38. resp := new(models.EnglishClassifyListResp)
  39. // 处理一级分类分页的情况
  40. rootList, err := models.GetEnglishClassifyRootId(keyWord, enabled)
  41. if err != nil {
  42. br.Msg = "获取失败"
  43. br.ErrMsg = "获取失败,Err:" + err.Error()
  44. return
  45. }
  46. if len(rootList) == 0 {
  47. resp.List = make([]*models.EnglishClassifyList, 0)
  48. br.Data = resp
  49. br.Ret = 200
  50. br.Success = true
  51. br.Msg = "获取成功"
  52. return
  53. }
  54. var ids []int
  55. var rootIds []int
  56. rootMap := make(map[int]struct{}, 0)
  57. for _, v := range rootList {
  58. rootIds = append(rootIds, v.Id)
  59. rootMap[v.Id] = struct{}{}
  60. }
  61. //获取相关的分类ID
  62. idList, err := models.GetEnglishClassifyListByRootId(rootIds, keyWord, enabled)
  63. if err != nil {
  64. br.Msg = "获取失败"
  65. br.ErrMsg = "获取失败,Err:" + err.Error()
  66. return
  67. }
  68. secondListMap := make(map[int][]*models.EnglishClassifyList)
  69. thirdListMap := make(map[int][]*models.EnglishClassifyList)
  70. var thirdIds []int
  71. var sortChildList models.RSChildClassifyList
  72. // 三级分类-品种权限
  73. permissionMap := make(map[int][]int)
  74. if len(idList) > 0 {
  75. childIdMap := make(map[int]struct{}, 0)
  76. for _, v := range idList {
  77. if _, ok := childIdMap[v.ParentId]; !ok {
  78. ids = append(ids, v.ParentId)
  79. childIdMap[v.ParentId] = struct{}{}
  80. }
  81. if _, ok := childIdMap[v.Id]; !ok {
  82. ids = append(ids, v.Id)
  83. childIdMap[v.Id] = struct{}{}
  84. }
  85. }
  86. tmpList, err := models.GetEnglishClassifyChildByIds(ids)
  87. if err != nil {
  88. br.Msg = "获取二级分类失败"
  89. br.ErrMsg = "获取二级分类失败,Err:" + err.Error()
  90. return
  91. }
  92. for _, v := range tmpList {
  93. if _, ok := rootMap[v.ParentId]; !ok {
  94. thirdIds = append(thirdIds, v.Id)
  95. }
  96. }
  97. {
  98. classifyIds := thirdIds
  99. if len(classifyIds) > 0 {
  100. cond := fmt.Sprintf(` AND %s IN (%s)`, models.EnClassifyPermissionColumns.EnClassifyId, utils.GetOrmInReplace(len(classifyIds)))
  101. pars := make([]interface{}, 0)
  102. pars = append(pars, classifyIds)
  103. ob := new(models.EnClassifyPermission)
  104. items, e := ob.GetItemsByCondition(cond, pars, []string{}, "")
  105. if e != nil {
  106. br.Msg = "获取失败"
  107. br.ErrMsg = "获取客户权限列表失败, Err: " + e.Error()
  108. return
  109. }
  110. for _, v := range items {
  111. if permissionMap[v.EnClassifyId] == nil {
  112. permissionMap[v.EnClassifyId] = make([]int, 0)
  113. }
  114. permissionMap[v.EnClassifyId] = append(permissionMap[v.EnClassifyId], v.EnPermissionId)
  115. }
  116. }
  117. }
  118. // 处理三级分类
  119. for _, v := range tmpList {
  120. if _, ok := rootMap[v.ParentId]; !ok {
  121. if p, ok1 := permissionMap[v.Id]; ok1 {
  122. v.EnPermissions = p
  123. }
  124. thirdListMap[v.ParentId] = append(thirdListMap[v.ParentId], v)
  125. }
  126. }
  127. //处理二级分类
  128. for _, v := range tmpList {
  129. if _, ok := rootMap[v.ParentId]; ok {
  130. if child, ok1 := thirdListMap[v.Id]; ok1 {
  131. sortChildList = child
  132. sort.Sort(sortChildList)
  133. v.Child = sortChildList
  134. }
  135. secondListMap[v.ParentId] = append(secondListMap[v.ParentId], v)
  136. }
  137. }
  138. }
  139. //处理一级分类
  140. var sortList models.RSClassifyList
  141. for _, v := range rootList {
  142. if child, ok := secondListMap[v.Id]; ok {
  143. sortChildList = child
  144. sort.Sort(sortChildList)
  145. v.Child = sortChildList
  146. }
  147. sortList = append(sortList, v)
  148. }
  149. sort.Sort(sortList)
  150. resp.List = sortList
  151. br.Data = resp
  152. br.Ret = 200
  153. br.Success = true
  154. br.Msg = "获取成功"
  155. }
  156. // @Title 新增分类
  157. // @Description 新增分类接口
  158. // @Param ClassifyName int true "分类名称"
  159. // @Param ParentId query int true "父级Id 添加父级时为0"
  160. // @Param Sort query string false "排序"
  161. // @Success 200 新增成功
  162. // @router /classify/add [post]
  163. func (this *EnglishReportController) AddClassify() {
  164. br := new(models.BaseResponse).Init()
  165. defer func() {
  166. this.Data["json"] = br
  167. this.ServeJSON()
  168. }()
  169. //classifyName := this.GetString("ClassifyName")
  170. //parentId, _ := this.GetInt("ParentId")
  171. var req models.EnClassifyAddReq
  172. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  173. if err != nil {
  174. br.Msg = "参数解析异常!"
  175. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  176. return
  177. }
  178. classifyName := req.ClassifyName
  179. parentId := req.ParentId
  180. ob := new(models.EnglishClassify)
  181. // 查新父级分类是否存在
  182. rootId := 0
  183. if parentId > 0 {
  184. parentClassify, err := models.GetEnglishReportClassifyById(parentId)
  185. if err != nil {
  186. if err.Error() == utils.ErrNoRow() {
  187. br.Msg = "上级分类不存在"
  188. return
  189. }
  190. br.Msg = "查询上级分类信息失败"
  191. br.ErrMsg = "查询上级分类信息失败,Err:" + err.Error()
  192. return
  193. }
  194. if parentClassify.RootId == 0 {
  195. rootId = parentClassify.Id
  196. } else {
  197. rootId = parentClassify.RootId
  198. }
  199. }
  200. maxSort, e := ob.GetMaxSort()
  201. if e != nil {
  202. br.Msg = "操作失败"
  203. br.ErrMsg = "查询品种排序失败, Err: " + e.Error()
  204. return
  205. }
  206. nowTime := time.Now().Local()
  207. item := &models.EnglishClassify{
  208. ClassifyName: classifyName,
  209. Sort: maxSort + 1,
  210. ParentId: parentId,
  211. RootId: rootId,
  212. CreateTime: nowTime,
  213. ModifyTime: nowTime,
  214. IsShow: 1,
  215. Enabled: 1,
  216. }
  217. counts, err := models.GetEnglishClassifyCountsByName(classifyName, parentId)
  218. if err != nil {
  219. br.Msg = "查询失败"
  220. br.ErrMsg = "查询失败,Err:" + err.Error()
  221. return
  222. }
  223. if counts > 0 {
  224. br.Msg = "该名称已存在"
  225. br.ErrMsg = "该名称已存在!"
  226. return
  227. }
  228. var newId int64
  229. newId, err = models.AddEnglishClassify(item)
  230. if err != nil {
  231. br.Msg = "保存失败"
  232. br.ErrMsg = "保存失败,Err:" + err.Error()
  233. return
  234. }
  235. item.Id = int(newId)
  236. if parentId == 0 { //一级目录的rootId等于自己本身
  237. item.RootId = int(newId)
  238. err = item.UpdateEnglishClassify([]string{"RootId"})
  239. if err != nil {
  240. br.Msg = "保存失败"
  241. br.ErrMsg = "保存失败,Err:" + err.Error()
  242. return
  243. }
  244. }
  245. if item.ParentId != item.RootId && item.ParentId > 0 { //三级分类才能绑定品种权限
  246. permissions := make([]*models.EnClassifyPermission, 0)
  247. for _, p := range req.EnPermissions {
  248. v := new(models.EnClassifyPermission)
  249. v.EnPermissionId = p
  250. v.EnClassifyId = item.Id
  251. v.CreateTime = nowTime
  252. permissions = append(permissions, v)
  253. }
  254. if e = models.CreateEnClassifyPermissions(permissions); e != nil {
  255. br.Msg = "保存失败"
  256. br.ErrMsg = "更新分类品种权限失败, Err: " + e.Error()
  257. return
  258. }
  259. }
  260. br.Ret = 200
  261. br.Success = true
  262. br.Msg = "新增成功"
  263. }
  264. // EditClassify
  265. // @Title 编辑分类
  266. // @Description 编辑分类接口
  267. // @Param ClassifyId int true "分类Id"
  268. // @Param ClassifyName string true "分类名称"
  269. // @Param ParentId query int true "父级Id 添加父级时为0"
  270. // @Param Sort query string false "排序"
  271. // @Success 200 保存成功
  272. // @router /classify/edit [post]
  273. func (this *EnglishReportController) EditClassify() {
  274. br := new(models.BaseResponse).Init()
  275. defer func() {
  276. this.Data["json"] = br
  277. this.ServeJSON()
  278. }()
  279. var req models.EnClassifyEditReq
  280. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  281. if err != nil {
  282. br.Msg = "参数解析异常!"
  283. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  284. return
  285. }
  286. classifyId := req.ClassifyId
  287. classifyName := req.ClassifyName
  288. parentId := req.ParentId
  289. //ob := new(models.EnglishClassify)
  290. if parentId == classifyId {
  291. br.Msg = "上级分类不能选择自己"
  292. return
  293. }
  294. if classifyId <= 0 {
  295. br.Msg = "参数错误"
  296. return
  297. }
  298. if classifyName == "" {
  299. br.Msg = "分类名称不可为空"
  300. return
  301. }
  302. oldItem, err := models.GetEnglishReportClassifyById(classifyId)
  303. if err != nil {
  304. if err.Error() == utils.ErrNoRow() {
  305. br.Msg = "当前分类不存在"
  306. return
  307. }
  308. br.Msg = "获取信息失败"
  309. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  310. return
  311. }
  312. if oldItem.ParentId == 0 && parentId > 0 {
  313. // 一级分类变更为二级分类,禁止
  314. br.Msg = "一级分类不允许更改为二级分类或三级分类"
  315. return
  316. }
  317. var parent *models.EnglishClassify
  318. rootId := 0
  319. if parentId > 0 {
  320. parent, err = models.GetEnglishReportClassifyById(parentId)
  321. if err != nil {
  322. if err.Error() == utils.ErrNoRow() {
  323. br.Msg = "上级分类不存在"
  324. return
  325. }
  326. br.Msg = "获取信息失败"
  327. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  328. return
  329. }
  330. //二级分类不允许改成三级分类
  331. if oldItem.ParentId > 0 && oldItem.ParentId == oldItem.RootId {
  332. if parent.ParentId > 0 {
  333. //即将改为为三级分类
  334. br.Msg = "二级分类不允许更改为三级分类"
  335. return
  336. }
  337. }
  338. if parent.RootId == 0 {
  339. rootId = parent.Id
  340. } else {
  341. rootId = parent.RootId
  342. }
  343. }
  344. //判断是否已存在同个名称的分类
  345. existItem, e := models.GetEnglishClassifyByClassifyNameParentId(classifyName, parentId)
  346. if e != nil {
  347. if e.Error() != utils.ErrNoRow() {
  348. br.Msg = "查询已存在的分类出错"
  349. br.ErrMsg = "查询已存在的分类出错, Err:" + e.Error()
  350. return
  351. }
  352. }
  353. if e == nil && existItem.Id != oldItem.Id {
  354. br.Msg = "分类名称:" + classifyName + "已存在"
  355. return
  356. }
  357. if parentId == 0 { //一级分类的顶级分类为自己的ID
  358. rootId = oldItem.Id
  359. }
  360. /*maxSort, e := ob.GetMaxSortByParentId(parentId)
  361. if e != nil {
  362. br.Msg = "操作失败"
  363. br.ErrMsg = "查询品种排序失败, Err: " + e.Error()
  364. return
  365. }*/
  366. nowTime := time.Now().Local()
  367. item := &models.EnglishClassify{
  368. Id: oldItem.Id,
  369. ClassifyName: classifyName,
  370. // Sort: maxSort + 1,
  371. ParentId: parentId,
  372. RootId: rootId,
  373. ModifyTime: nowTime,
  374. IsShow: 1,
  375. }
  376. {
  377. // 更新研报里的分类名称
  378. err = services.UpdateEnglishReportClassifyId(oldItem, item, classifyId)
  379. if err != nil {
  380. br.Msg = err.Error()
  381. return
  382. }
  383. //更新相关联的路演视频里的分类名称
  384. err = services.UpdateEnglishVideoClassifyId(oldItem, item, classifyId)
  385. if err != nil {
  386. br.Msg = err.Error()
  387. return
  388. }
  389. }
  390. err = models.ModifyEnglishClassify(item)
  391. if err != nil {
  392. br.Msg = "保存失败"
  393. br.ErrMsg = "保存失败,Err:" + err.Error()
  394. return
  395. }
  396. // 更新权限
  397. if item.ParentId != item.RootId && item.ParentId > 0 { //三级分类才能编辑品种
  398. permissions := make([]*models.EnClassifyPermission, 0)
  399. for _, p := range req.EnPermissions {
  400. v := new(models.EnClassifyPermission)
  401. v.EnPermissionId = p
  402. v.EnClassifyId = req.ClassifyId
  403. v.CreateTime = nowTime
  404. permissions = append(permissions, v)
  405. }
  406. if e = models.ClearAndCreateEnClassifyPermissions(req.ClassifyId, permissions); e != nil {
  407. br.Msg = "保存失败"
  408. br.ErrMsg = "更新分类品种权限失败, Err: " + e.Error()
  409. return
  410. }
  411. }
  412. err = models.UpdateEnglishReportClassifyByFirstSecondClassifyId(classifyId, parentId)
  413. if err != nil {
  414. br.Msg = "保存失败"
  415. br.ErrMsg = "保存失败,Err:" + err.Error()
  416. return
  417. }
  418. err = models.UpdateEnglishVideoClassifyByFirstSecondClassifyId(classifyId, parentId)
  419. if err != nil {
  420. br.Msg = "保存失败"
  421. br.ErrMsg = "保存失败,Err:" + err.Error()
  422. return
  423. }
  424. br.Ret = 200
  425. br.Success = true
  426. br.Msg = "保存成功"
  427. }
  428. // @Title 删除分类列表
  429. // @Description 删除分类列表
  430. // @Param ClassifyId int true "分类名称"
  431. // @Param ParentId query int true "父级Id"
  432. // @Success 200 保存成功
  433. // @router /classify/delete [get]
  434. func (this *EnglishReportController) DelClassify() {
  435. br := new(models.BaseResponse).Init()
  436. defer func() {
  437. this.Data["json"] = br
  438. this.ServeJSON()
  439. }()
  440. classifyId, _ := this.GetInt("ClassifyId")
  441. //parentId, _ := this.GetInt("ParentId")
  442. classifyInfo, err := models.GetEnglishReportClassifyById(classifyId)
  443. if err != nil {
  444. if err.Error() == utils.ErrNoRow() {
  445. br.Msg = "当前分类不存在"
  446. br.ErrMsg = "当前分类不存在"
  447. return
  448. }
  449. br.Msg = "获取分类信息失败"
  450. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  451. return
  452. }
  453. count, err := models.GetEnglishClassifyChildCounts(classifyId)
  454. if err != nil && err.Error() != utils.ErrNoRow() {
  455. br.Msg = "获取信息失败"
  456. br.ErrMsg = "获取失败,Err:" + err.Error()
  457. return
  458. }
  459. if count > 0 {
  460. br.Msg = "请先删除该分类下关联分类"
  461. br.Ret = 403
  462. return
  463. }
  464. reportCount, e := models.GetEnglishReportCounts(classifyId, classifyInfo.ParentId)
  465. if e != nil && e.Error() != utils.ErrNoRow() {
  466. br.Msg = "获取信息失败"
  467. br.ErrMsg = "获取失败,Err:" + e.Error()
  468. return
  469. }
  470. if reportCount > 0 {
  471. br.Msg = "该分类有关联报告,不允许删除"
  472. br.Ret = 403
  473. return
  474. }
  475. videoCount, e := models.GetEnglishVideoCounts(classifyId, classifyInfo.ParentId)
  476. if e != nil && e.Error() != utils.ErrNoRow() {
  477. br.Msg = "获取信息失败"
  478. br.ErrMsg = "获取失败,Err:" + e.Error()
  479. return
  480. }
  481. if videoCount > 0 {
  482. br.Msg = "该分类有关联的路演视频,不允许删除"
  483. br.Ret = 403
  484. return
  485. }
  486. // 查询该分类是否关联了审批流
  487. flowOb := new(report_approve.ReportApproveFlow)
  488. flowCond := fmt.Sprintf(` AND %s = ? AND (%s = ? Or %s = ?)`, report_approve.ReportApproveFlowCols.ReportType, report_approve.ReportApproveFlowCols.ClassifyFirstId, report_approve.ReportApproveFlowCols.ClassifySecondId)
  489. flowPars := make([]interface{}, 0)
  490. flowPars = append(flowPars, report_approve.FlowReportTypeEnglish, classifyId, classifyId)
  491. flowCount, e := flowOb.GetCountByCondition(flowCond, flowPars)
  492. if e != nil {
  493. br.Msg = "检测失败"
  494. br.ErrMsg = "获取关联审批流失败, Err: " + e.Error()
  495. return
  496. }
  497. if flowCount > 0 {
  498. br.Msg = "该分类关联审批流,不允许删除"
  499. br.Ret = 403
  500. return
  501. }
  502. if err = models.DeleteEnglishClassify(classifyId); err != nil {
  503. br.Msg = "删除失败"
  504. br.ErrMsg = "删除报告失败, Err: " + err.Error()
  505. return
  506. }
  507. br.Ret = 200
  508. br.Success = true
  509. br.Msg = "删除成功"
  510. }
  511. // @Title 获取一级分类列表
  512. // @Description 获取一级分类列表
  513. // @Param PageSize query int true "每页数据条数"
  514. // @Param CurrentIndex query int true "当前页页码,从1开始"
  515. // @Param CompanyType query string false "产品类型,枚举值:'ficc','权益';不传默认返回全部"
  516. // @Success 200 {object} models.EnglishClassifyListResp
  517. // @router /classify/first/list [get]
  518. func (this *EnglishReportController) FistListClassify() {
  519. br := new(models.BaseResponse).Init()
  520. defer func() {
  521. this.Data["json"] = br
  522. this.ServeJSON()
  523. }()
  524. rootList, err := models.GetEnglishFirstClassifyList()
  525. if err != nil {
  526. br.Msg = "获取失败"
  527. br.ErrMsg = "获取失败,Err:" + err.Error()
  528. return
  529. }
  530. total, err := models.GetEnglishFirstClassifyListCount()
  531. if err != nil {
  532. br.Msg = "获取失败"
  533. br.ErrMsg = "获取失败,Err:" + err.Error()
  534. return
  535. }
  536. resp := new(models.EnglishClassifyListResp)
  537. if total == 0 {
  538. resp.List = make([]*models.EnglishClassifyList, 0)
  539. br.Data = resp
  540. br.Ret = 200
  541. br.Success = true
  542. br.Msg = "获取成功"
  543. return
  544. }
  545. rootMap := make(map[int]struct{}, 0)
  546. var rootIds []int
  547. for _, v := range rootList {
  548. rootMap[v.Id] = struct{}{}
  549. rootIds = append(rootIds, v.Id)
  550. }
  551. tmpList, err := models.GetEnglishSecondClassifyList(rootIds)
  552. if err != nil {
  553. br.Msg = "获取失败"
  554. br.ErrMsg = "获取失败,Err:" + err.Error()
  555. return
  556. }
  557. secondListMap := make(map[int][]*models.EnglishClassifyList)
  558. //处理二级分类
  559. for _, v := range tmpList {
  560. if _, ok := rootMap[v.ParentId]; ok {
  561. secondListMap[v.ParentId] = append(secondListMap[v.ParentId], v)
  562. }
  563. }
  564. //处理一级分类
  565. var sortList models.RSClassifyList
  566. var sortChildList models.RSChildClassifyList
  567. for _, v := range rootList {
  568. if child, ok := secondListMap[v.Id]; ok {
  569. sortChildList = child
  570. sort.Sort(sortChildList)
  571. v.Child = sortChildList
  572. }
  573. sortList = append(sortList, v)
  574. }
  575. sort.Sort(sortList)
  576. resp.List = sortList
  577. br.Data = resp
  578. br.Ret = 200
  579. br.Success = true
  580. br.Msg = "获取成功"
  581. }
  582. // PermissionEdit
  583. // @Title 编辑品种权限
  584. // @Description 编辑品种权限
  585. // @Param request body models.EnPermissionAddReq true "type json string"
  586. // @Success 200 Ret=200 操作成功
  587. // @router /permission/edit [post]
  588. func (this *EnglishClassifyController) PermissionEdit() {
  589. br := new(models.BaseResponse).Init()
  590. defer func() {
  591. if br.ErrMsg == "" {
  592. br.IsSendEmail = false
  593. }
  594. this.Data["json"] = br
  595. this.ServeJSON()
  596. }()
  597. sysUser := this.SysUser
  598. if sysUser == nil {
  599. br.Msg = "请登录"
  600. br.ErrMsg = "请登录,SysUser Is Empty"
  601. br.Ret = 408
  602. return
  603. }
  604. var req models.EnClassifyPermissionEditReq
  605. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  606. br.Msg = "参数解析异常!"
  607. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  608. return
  609. }
  610. if req.ClassifyId <= 0 {
  611. br.Msg = "参数有误"
  612. return
  613. }
  614. // 更新品种权限
  615. nowTime := time.Now().Local()
  616. permissions := make([]*models.EnClassifyPermission, 0)
  617. for _, p := range req.EnPermissions {
  618. v := new(models.EnClassifyPermission)
  619. v.EnPermissionId = p
  620. v.EnClassifyId = req.ClassifyId
  621. v.CreateTime = nowTime
  622. permissions = append(permissions, v)
  623. }
  624. if e := models.ClearAndCreateEnClassifyPermissions(req.ClassifyId, permissions); e != nil {
  625. br.Msg = "保存失败"
  626. br.ErrMsg = "更新分类品种权限失败, Err: " + e.Error()
  627. return
  628. }
  629. br.Ret = 200
  630. br.Success = true
  631. br.Msg = "操作成功"
  632. }
  633. // MoveClassify
  634. // @Title 移动分类接口
  635. // @Description 移动分类
  636. // @Param request body models.EnglishClassifyMoveReq true "type json string"
  637. // @Success 200 新增成功
  638. // @router /classify/move [post]
  639. func (this *EnglishReportController) MoveClassify() {
  640. br := new(models.BaseResponse).Init()
  641. defer func() {
  642. this.Data["json"] = br
  643. this.ServeJSON()
  644. }()
  645. var req models.EnglishClassifyMoveReq
  646. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  647. if err != nil {
  648. br.Msg = "参数解析异常!"
  649. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  650. return
  651. }
  652. if req.ClassifyId <= 0 {
  653. br.Msg = "请选择分类"
  654. return
  655. }
  656. e, msg := services.MoveEnglishReportClassify(req)
  657. if e != nil {
  658. br.Msg = msg
  659. br.ErrMsg = "移动分类失败, Err: " + e.Error()
  660. return
  661. }
  662. br.Ret = 200
  663. br.Success = true
  664. br.Msg = "操作成功"
  665. }
  666. // SetEnabled
  667. // @Title 启用/禁用分类接口
  668. // @Description 启用/禁用分类
  669. // @Param request body models.ClassifyMoveReq true "type json string"
  670. // @Success 200 新增成功
  671. // @router /classify/enabled/set [post]
  672. func (this *EnglishReportController) SetEnabled() {
  673. br := new(models.BaseResponse).Init()
  674. defer func() {
  675. this.Data["json"] = br
  676. this.ServeJSON()
  677. }()
  678. var req models.EnglishClassifySetEnabledReq
  679. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  680. if err != nil {
  681. br.Msg = "参数解析异常!"
  682. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  683. return
  684. }
  685. if req.ClassifyId <= 0 {
  686. br.Msg = "请选择分类"
  687. return
  688. }
  689. if req.Enabled != 0 && req.Enabled != 1 {
  690. br.Msg = "请选择正确的启用禁用状态"
  691. return
  692. }
  693. item, err := models.GetEnglishReportClassifyById(req.ClassifyId)
  694. if err != nil {
  695. if err.Error() == utils.ErrNoRow() {
  696. br.Msg = "分类不存在"
  697. return
  698. }
  699. br.Msg = "获取信息失败"
  700. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  701. return
  702. }
  703. if item == nil {
  704. br.Msg = "分类不存在"
  705. return
  706. }
  707. ob := new(models.EnglishClassify)
  708. //设置分类启用、禁用状态
  709. err = ob.SetEnabled(req.ClassifyId, req.Enabled)
  710. if err != nil {
  711. br.Msg = "操作失败"
  712. br.ErrMsg = "操作失败,Err:" + err.Error()
  713. return
  714. }
  715. br.Ret = 200
  716. br.Success = true
  717. br.Msg = "操作成功"
  718. }