PastureAreaController.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package com.huimv.video.controller;
  2. import com.huimv.video.domain.PastureArea;
  3. import com.huimv.video.result.Result;
  4. import com.huimv.video.service.PastureAreaService;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.web.bind.annotation.CrossOrigin;
  7. import org.springframework.web.bind.annotation.RequestMapping;
  8. import org.springframework.web.bind.annotation.RequestParam;
  9. import org.springframework.web.bind.annotation.RestController;
  10. import java.util.List;
  11. /**
  12. * @Project : huimv.shiwan
  13. * @Package : com.huimv.video.controller
  14. * @Description : TODO
  15. * @Author : yuxuexuan
  16. * @Create : 2021/3/4 0007 10:34
  17. **/
  18. @CrossOrigin
  19. @RestController
  20. @RequestMapping("/pastureArea")
  21. public class PastureAreaController {
  22. @Autowired
  23. private PastureAreaService pastureAreaService;
  24. @RequestMapping("/add")
  25. private Result addArea(PastureArea pastureArea){
  26. try {
  27. if (pastureArea.getParentId() != null){
  28. pastureAreaService.save(pastureArea);
  29. return new Result(10000,"添加成功");
  30. }else {
  31. return new Result(10002,"请选择父级ID");
  32. }
  33. }catch (Exception e){
  34. return new Result(10001,"添加失败");
  35. }
  36. }
  37. @RequestMapping("/update")
  38. private Result updateArea(PastureArea pastureArea){
  39. try {
  40. if (pastureArea.getId()==0){
  41. return new Result(10002,"请选择修改数据");
  42. }
  43. if (pastureArea.getParentId() != null){
  44. pastureAreaService.update(pastureArea);
  45. return new Result(10000,"修改成功");
  46. }else {
  47. return new Result(10002,"请选择父级ID");
  48. }
  49. }catch (Exception e){
  50. return new Result(10001,"修改失败");
  51. }
  52. }
  53. @RequestMapping("/delete")
  54. private Result deleteArea(@RequestParam(required = false)List<Integer> ids){
  55. // try {
  56. pastureAreaService.delete(ids);
  57. return new Result(10000,"删除成功");
  58. // }catch (Exception e){
  59. // return new Result(10001,"删除失败");
  60. // }
  61. }
  62. @RequestMapping("/findAll")
  63. private Result findAll(Integer userId){
  64. try {
  65. List list = pastureAreaService.findAll(userId);
  66. if (list == null){
  67. return new Result(10000,"暂时没有数据");
  68. }
  69. return new Result(10000,"查询成功",list);
  70. }catch (Exception e){
  71. return new Result(10001,"查询失败");
  72. }
  73. }
  74. @RequestMapping("/findById")
  75. private Result findById(Integer id){
  76. try {
  77. PastureArea pastureArea = pastureAreaService.findById(id);
  78. return new Result(10000,"设置成功",pastureArea);
  79. }catch (Exception e){
  80. return new Result(10001,"设置失败");
  81. }
  82. }
  83. @RequestMapping("/findAllByAttention")
  84. private Result findAllByAttention(){
  85. try {
  86. List list = pastureAreaService.findAllByAttention();
  87. return new Result(10000,"查询成功",list);
  88. }catch (Exception e){
  89. return new Result(10001,"查询失败");
  90. }
  91. }
  92. @RequestMapping("/updateAttention")
  93. private Result updateAttention(Integer id,Integer attention){
  94. try {
  95. pastureAreaService.updateAttention(id,attention);
  96. if (attention == 0){
  97. return new Result(10000,"取消关注成功");
  98. }
  99. return new Result(10000,"关注成功");
  100. }catch (Exception e){
  101. return new Result(10001,"关注失败");
  102. }
  103. }
  104. }