EcoController.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. package com.huimv.receiver.eco.controller;
  2. import cn.hutool.core.util.ObjectUtil;
  3. import com.huimv.receiver.cloud.service.IWarningInfo;
  4. import com.huimv.receiver.eco.entity.*;
  5. import com.huimv.receiver.eco.service.*;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.web.bind.annotation.PostMapping;
  8. import org.springframework.web.bind.annotation.RequestBody;
  9. import org.springframework.web.bind.annotation.RequestMapping;
  10. import org.springframework.web.bind.annotation.RestController;
  11. import java.util.List;
  12. //接收温湿度数据
  13. @RestController
  14. @RequestMapping(value = "/receiver/eco")
  15. public class EcoController {
  16. @Autowired
  17. private ISysHumidityService sysHumidityService;
  18. @Autowired
  19. private ISysTemperatureService sysTemperatureService;
  20. @Autowired
  21. private IBaseWarningInfoService baseWarningInfoService;
  22. @Autowired
  23. private ISysFodderService fodderService;
  24. @Autowired
  25. private ISysMonthWaterService monthWaterService;
  26. @Autowired
  27. private ISysDayWaterService dayWaterService;
  28. @PostMapping(value = "/save")
  29. public String save(@RequestBody HumAndTemDto humAndTemDto){
  30. System.out.println("开始");
  31. if (ObjectUtil.isEmpty(humAndTemDto)){
  32. return "数据为空";
  33. }
  34. List<SysHumidity> humidity = humAndTemDto.getHumidity();
  35. if (ObjectUtil.isNotEmpty(humidity)){
  36. try {
  37. sysHumidityService.saveBatch(humidity);
  38. }catch (Exception e){
  39. System.out.println("湿度存储失败");
  40. }
  41. }else {
  42. System.out.println("湿度数据为空");
  43. }
  44. List<SysTemperature> temperature = humAndTemDto.getTemperature();
  45. if (ObjectUtil.isNotEmpty(temperature)){
  46. try {
  47. sysTemperatureService.saveBatch(temperature);
  48. }catch (Exception e){
  49. System.out.println("温度存储失败");
  50. }
  51. }else {
  52. System.out.println("温度数据为空");
  53. }
  54. List<BaseWarningInfo> warningInfos = humAndTemDto.getWarningInfos();
  55. if (ObjectUtil.isNotEmpty(warningInfos)){
  56. try {
  57. baseWarningInfoService.saveBatch(warningInfos);
  58. }catch (Exception e){
  59. System.out.println("报警存储失败");
  60. }
  61. }else {
  62. System.out.println("报警数据为空");
  63. }
  64. List<SysFodder> fodders = humAndTemDto.getFodders();
  65. if (ObjectUtil.isNotEmpty(fodders)){
  66. try {
  67. for (SysFodder fodder : fodders) {
  68. Integer fodderId = fodder.getFodderId();
  69. SysFodder byId = fodderService.getById(fodderId);
  70. if (ObjectUtil.isEmpty(byId)){
  71. fodderService.save(fodder);
  72. }else {
  73. fodderService.updateById(fodder);
  74. }
  75. }
  76. }catch (Exception e){
  77. System.out.println("用料存储失败");
  78. }
  79. }else {
  80. System.out.println("用料数据为空");
  81. }
  82. List<SysMonthWater> monthWaters = humAndTemDto.getMonthWaters();
  83. if (ObjectUtil.isNotEmpty(monthWaters)){
  84. try {
  85. monthWaterService.saveBatch(monthWaters);
  86. }catch (Exception e){
  87. System.out.println("月用水存储失败");
  88. }
  89. }else {
  90. System.out.println("月用水数据为空");
  91. }
  92. List<SysDayWater> dayWaters = humAndTemDto.getDayWaters();
  93. if (ObjectUtil.isNotEmpty(dayWaters)){
  94. try {
  95. dayWaterService.saveBatch(dayWaters);
  96. }catch (Exception e){
  97. System.out.println("日用水存储失败");
  98. }
  99. }else {
  100. System.out.println("日用水数据为空");
  101. }
  102. System.out.println("结束");
  103. return "成功";
  104. }
  105. }