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 humidity = humAndTemDto.getHumidity(); if (ObjectUtil.isNotEmpty(humidity)){ try { sysHumidityService.saveBatch(humidity); }catch (Exception e){ System.out.println("湿度存储失败"); } }else { System.out.println("湿度数据为空"); } List temperature = humAndTemDto.getTemperature(); if (ObjectUtil.isNotEmpty(temperature)){ try { sysTemperatureService.saveBatch(temperature); }catch (Exception e){ System.out.println("温度存储失败"); } }else { System.out.println("温度数据为空"); } List warningInfos = humAndTemDto.getWarningInfos(); if (ObjectUtil.isNotEmpty(warningInfos)){ try { baseWarningInfoService.saveBatch(warningInfos); }catch (Exception e){ System.out.println("报警存储失败"); } }else { System.out.println("报警数据为空"); } List 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 monthWaters = humAndTemDto.getMonthWaters(); if (ObjectUtil.isNotEmpty(monthWaters)){ try { monthWaterService.saveBatch(monthWaters); }catch (Exception e){ System.out.println("月用水存储失败"); } }else { System.out.println("月用水数据为空"); } List 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 "成功"; } }