PigController.java 4.6 KB

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