123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- package com.huimv.receiver.eco.controller;
- import cn.hutool.core.util.ObjectUtil;
- import com.huimv.receiver.cloud.service.IWarningInfo;
- import com.huimv.receiver.eco.entity.*;
- import com.huimv.receiver.eco.service.*;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.PostMapping;
- import org.springframework.web.bind.annotation.RequestBody;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
- import java.util.List;
- //接收温湿度数据
- @RestController
- @RequestMapping(value = "/receiver/eco")
- public class EcoController {
- @Autowired
- private ISysHumidityService sysHumidityService;
- @Autowired
- private ISysTemperatureService sysTemperatureService;
- @Autowired
- private IBaseWarningInfoService baseWarningInfoService;
- @Autowired
- private ISysFodderService fodderService;
- @Autowired
- private ISysMonthWaterService monthWaterService;
- @Autowired
- private ISysDayWaterService dayWaterService;
- @PostMapping(value = "/save")
- public String save(@RequestBody HumAndTemDto humAndTemDto){
- System.out.println("开始");
- if (ObjectUtil.isEmpty(humAndTemDto)){
- return "数据为空";
- }
- List<SysHumidity> humidity = humAndTemDto.getHumidity();
- if (ObjectUtil.isNotEmpty(humidity)){
- try {
- sysHumidityService.saveBatch(humidity);
- }catch (Exception e){
- System.out.println("湿度存储失败");
- }
- }else {
- System.out.println("湿度数据为空");
- }
- List<SysTemperature> temperature = humAndTemDto.getTemperature();
- if (ObjectUtil.isNotEmpty(temperature)){
- try {
- sysTemperatureService.saveBatch(temperature);
- }catch (Exception e){
- System.out.println("温度存储失败");
- }
- }else {
- System.out.println("温度数据为空");
- }
- List<BaseWarningInfo> warningInfos = humAndTemDto.getWarningInfos();
- if (ObjectUtil.isNotEmpty(warningInfos)){
- try {
- baseWarningInfoService.saveBatch(warningInfos);
- }catch (Exception e){
- System.out.println("报警存储失败");
- }
- }else {
- System.out.println("报警数据为空");
- }
- List<SysFodder> fodders = humAndTemDto.getFodders();
- if (ObjectUtil.isNotEmpty(fodders)){
- try {
- for (SysFodder fodder : fodders) {
- Integer fodderId = fodder.getFodderId();
- SysFodder byId = fodderService.getById(fodderId);
- if (ObjectUtil.isEmpty(byId)){
- fodderService.save(fodder);
- }else {
- fodderService.updateById(fodder);
- }
- }
- }catch (Exception e){
- System.out.println("用料存储失败");
- }
- }else {
- System.out.println("用料数据为空");
- }
- List<SysMonthWater> monthWaters = humAndTemDto.getMonthWaters();
- if (ObjectUtil.isNotEmpty(monthWaters)){
- try {
- monthWaterService.saveBatch(monthWaters);
- }catch (Exception e){
- System.out.println("月用水存储失败");
- }
- }else {
- System.out.println("月用水数据为空");
- }
- List<SysDayWater> dayWaters = humAndTemDto.getDayWaters();
- if (ObjectUtil.isNotEmpty(dayWaters)){
- try {
- dayWaterService.saveBatch(dayWaters);
- }catch (Exception e){
- System.out.println("日用水存储失败");
- }
- }else {
- System.out.println("日用水数据为空");
- }
- System.out.println("结束");
- return "成功";
- }
- }
|