PigController.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package com.huimv.apiservice.controller;
  2. import com.huimv.apiservice.entity.vo.*;
  3. import com.huimv.apiservice.limit.annotation.Limit;
  4. import com.huimv.apiservice.service.PigService;
  5. import com.huimv.common.utils.PageUtils;
  6. import com.huimv.common.utils.R;
  7. import com.huimv.common.validate.ListValue;
  8. import org.hibernate.validator.constraints.Range;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.validation.annotation.Validated;
  11. import org.springframework.web.bind.annotation.*;
  12. import javax.validation.constraints.NotBlank;
  13. import javax.validation.constraints.NotNull;
  14. import java.util.Objects;
  15. /**
  16. * @author yinhao
  17. * @date 2021/5/8 16:09
  18. */
  19. @CrossOrigin
  20. @RestController
  21. @RequestMapping("/pig")
  22. @Validated
  23. public class PigController {
  24. @Autowired
  25. private PigService pigService;
  26. /**
  27. * 获取猪基本信息
  28. *
  29. * @param accessToken token
  30. * @param pigEarTagNo 耳标号
  31. * @return
  32. */
  33. //@Limit(key = "pig_getPigInfo",name = "pig/getPigInfo",prefix = "apiservice")
  34. @GetMapping("/getPigInfo")
  35. public R getPigInfo(@RequestParam(value = "accessToken") String accessToken,
  36. @NotBlank(message = "耳标号不能为空!") @RequestParam("pigEarTagNo") String pigEarTagNo) {
  37. PigHealthStatusVo pigHealthStatusVo = pigService.getPigInfoByEarTagNo(pigEarTagNo);
  38. return Objects.requireNonNull(R.ok().put("code", 1000)).put("data", pigHealthStatusVo);
  39. }
  40. /**
  41. * 获取多媒体接口(照片/视频)
  42. *
  43. * @param accessToken token
  44. * @param pigEarTagNo 耳标号
  45. * @return
  46. */
  47. @GetMapping("/getImage")
  48. public R getImage(@RequestParam(value = "accessToken") String accessToken,
  49. @NotBlank(message = "耳标号不能为空!") @RequestParam("pigEarTagNo") String pigEarTagNo) {
  50. PigImageVo pigImageVo = pigService.getImageByEarTagNo(pigEarTagNo);
  51. return Objects.requireNonNull(R.ok().put("code", 1000)).put("data", pigImageVo);
  52. }
  53. /**
  54. * 根据品种名称获取猪的数量和基本信息
  55. *
  56. * @param accessToken token
  57. * @param breedName 品种名称
  58. * @return
  59. */
  60. @GetMapping("/getListByBreed")
  61. public R getListByBreed(@RequestParam(value = "accessToken") String accessToken,
  62. @NotBlank(message = "品种名称不能为空!") @RequestParam("breedName") String breedName,
  63. @RequestParam(value = "currentPage", defaultValue = "1") Integer currentPage,
  64. @Range(min = 1, max = 1000, message = "每页条数的范围为1-1000") @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize,
  65. @RequestParam(value = "period", required = false) String period) {
  66. PageUtils page = pigService.getPageByBreedAndFence(breedName, currentPage, pageSize, period);
  67. return Objects.requireNonNull(R.ok().put("code", 1000)).put("page", page);
  68. }
  69. /**
  70. * 获取环境数据
  71. *
  72. * @param accessToken token
  73. * @param pigEarTagNo 耳标号
  74. * @return
  75. */
  76. @GetMapping("/getIndoorEnv")
  77. public R getIndoorEnv(@RequestParam(value = "accessToken") String accessToken,
  78. @NotBlank(message = "耳标号不能为空!") @RequestParam("pigEarTagNo") String pigEarTagNo) {
  79. EnvVo envVo = pigService.getIndoorEnv(pigEarTagNo);
  80. return Objects.requireNonNull(R.ok().put("code", 1000)).put("data", envVo);
  81. }
  82. /**
  83. * 修改认养状态
  84. *
  85. * @param accessToken token
  86. * @param pigEarTagNo 耳标号
  87. * @return
  88. */
  89. @GetMapping("/adopt")
  90. public R adopt(@RequestParam(value = "accessToken") String accessToken,
  91. @NotBlank(message = "耳标号不能为空!") @RequestParam("pigEarTagNo") String pigEarTagNo) {
  92. pigService.adopt(pigEarTagNo);
  93. return Objects.requireNonNull(R.ok().put("code", 1000)).put("msg", "认养成功!");
  94. }
  95. /**
  96. * 出栏
  97. *
  98. * @param accessToken token
  99. * @param pigEarTagNo 耳标号
  100. * @return
  101. */
  102. @GetMapping("/outFence")
  103. public R outFence(@RequestParam(value = "accessToken", required = false) String accessToken,
  104. @NotBlank(message = "耳标号不能为空!") @RequestParam("pigEarTagNo") String pigEarTagNo,
  105. @NotNull(message = "出栏状态不能为空!") @ListValue(vals = {1, 2, 3}) @RequestParam("status") Integer status) {
  106. pigService.outFence(pigEarTagNo, status);
  107. return Objects.requireNonNull(R.ok().put("code", 1000)).put("msg", "出栏成功!");
  108. }
  109. }