english_classify.go 21 KB

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