PreventDetectionController.java 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package com.huimv.cattle.controller;
  2. import cn.hutool.core.util.ObjectUtil;
  3. import com.alibaba.druid.wall.violation.ErrorCode;
  4. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  5. import com.huimv.cattle.pojo.PreventDetection;
  6. import com.huimv.cattle.service.PreventDetectionService;
  7. import com.huimv.common.utils.Result;
  8. import com.huimv.common.utils.ResultCode;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.web.bind.annotation.PostMapping;
  11. import org.springframework.web.bind.annotation.RequestBody;
  12. import org.springframework.web.bind.annotation.RequestMapping;
  13. import org.springframework.web.bind.annotation.RestController;
  14. import java.util.ArrayList;
  15. import java.util.List;
  16. import java.util.Map;
  17. /**
  18. * <p>
  19. * 前端控制器
  20. * </p>
  21. *
  22. * @author zn
  23. * @since 2022-12-14
  24. */
  25. @RestController
  26. @RequestMapping("/v1.0.0/preventDetection")
  27. public class PreventDetectionController {
  28. @Autowired
  29. private PreventDetectionService preventDetectionService;
  30. @PostMapping("/savePreventDetection")
  31. public Result add(@RequestBody PreventDetection preventDetection){
  32. preventDetectionService.save(preventDetection);
  33. return new Result(10000,"添加成功",true);
  34. }
  35. @PostMapping("/updatePreventDetection")
  36. public Result update(@RequestBody PreventDetection preventDetection){
  37. preventDetectionService.updateById(preventDetection);
  38. return new Result(10000,"修改成功",true);
  39. }
  40. @PostMapping("/deletePreventDetection")
  41. public Result delete(@RequestBody Map<String,String> paramMap){
  42. String ids = paramMap.get("ids");
  43. String[] split = ids.split(",");
  44. for (String s : split) {
  45. preventDetectionService.removeById(s);
  46. }
  47. return new Result(10000,"删除成功",true);
  48. }
  49. @PostMapping("/getPreventDetection")
  50. public Result list(@RequestBody PreventDetection preventDetection){
  51. List<PreventDetection> list = preventDetectionService.list(new QueryWrapper<PreventDetection>().orderByDesc("year").orderByDesc("month"));
  52. if (ObjectUtil.isEmpty(list)){
  53. return new Result(ResultCode.SUCCESS,new ArrayList<>());
  54. }
  55. return new Result(ResultCode.SUCCESS,list);
  56. }
  57. }