package com.huimv.admin.jinghongtimer;


import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huimv.admin.common.utils.DataUill;
import com.huimv.admin.entity.EnergyEnvDevice;
import com.huimv.admin.entity.EnergyScreen;
import com.huimv.admin.entity.vo.EnergyDataScreenVo;
import com.huimv.admin.mapper.EnergyDataMapper;
import com.huimv.admin.mapper.EnergyEnvDeviceMapper;
import com.huimv.admin.mapper.EnergyScreenMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

@Configuration
@EnableScheduling
public class WaterAndElcTimer {

    @Autowired
    private EnergyEnvDeviceMapper envDeviceMapper;
    @Autowired
    private EnergyDataMapper dataMapper;
    @Autowired
    private EnergyScreenMapper screenMapper;


  //芙江28
  @Scheduled(cron = "0 59 * * * ? ")
  private void getShenChan19() throws Exception {
      QueryWrapper<EnergyEnvDevice> queryWrapper = new QueryWrapper<>();
      queryWrapper.eq("farm_id", 28);
      List<EnergyEnvDevice> envDevices = envDeviceMapper.selectList(queryWrapper);

      Date timesmorning = DataUill.getTimesmorning();
      DateTime dateTime = DateUtil.beginOfWeek(new Date());//本周
      Date timesMonthmorning = DataUill.getTimesMonthmorning();//本月
      Date dayStart = (Date) getYesterdayRange().get("startTime");
      Date dayEnd = (Date) getYesterdayRange().get("stopTime");
      Date weekStart = (Date) getLastWeekRange().get("startTime");
      Date weekEnd = (Date) getLastWeekRange().get("stopTime");
      Date monthStart = (Date) getLastMonthRange().get("startTime");
      Date monthEnd = (Date) getLastMonthRange().get("stopTime");
      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");


      for (EnergyEnvDevice envDevice : envDevices) {
          EnergyDataScreenVo dataScreenVo = dataMapper.listDataAll(sdf.format(timesmorning), sdf.format(dateTime), sdf.format(timesMonthmorning),
                  sdf.format(dayStart), sdf.format(dayEnd)
                  , sdf.format(weekStart), sdf.format(weekEnd)
                  , sdf.format(monthStart), sdf.format(monthEnd)
                  , envDevice.getUnitId(), "28");

          QueryWrapper<EnergyScreen> queryWrapper1 = new QueryWrapper<>();
          queryWrapper1.eq("farm_id", 28).ge("create_date", timesMonthmorning).eq("device_code", envDevice.getDeviceCode());
          EnergyScreen energyScreen = screenMapper.selectOne(queryWrapper1);

          if (ObjectUtil.isNotEmpty(energyScreen)) {
              //说明今天的数据已经存在 后续只需要更新即可
              if ("1".equals(envDevice.getRemark())) {
                  //用水
                  energyScreen.setCreateDate(new Date());
                  energyScreen.setTodayRead(dataScreenVo.getWaterValueToday());
                  energyScreen.setTodayConsume(dataScreenVo.getWaterValueTodayUsage());
                  energyScreen.setYesterdayConsume(dataScreenVo.getWaterValueYesterdayUsage());
                  energyScreen.setWeekConsume(dataScreenVo.getWaterValueThisWeekUsage());
                  energyScreen.setLastWeekConsume(dataScreenVo.getWaterValueLastWeekUsage());
                  energyScreen.setMonthConsume(dataScreenVo.getWaterValueThisMonthUsage());
                  energyScreen.setLastMonthConsume(dataScreenVo.getWaterValueLastMonthUsage());
                  double day2 = Double.parseDouble(dataScreenVo.getWaterValueTodayUsage());
                  double day3 = Double.parseDouble(dataScreenVo.getWaterValueYesterdayUsage());
                  double week1 = Double.parseDouble(dataScreenVo.getWaterValueThisWeekUsage());
                  double week2 = Double.parseDouble(dataScreenVo.getWaterValueLastWeekUsage());
                  double month1 = Double.parseDouble(dataScreenVo.getWaterValueThisMonthUsage());
                  double month2 = Double.parseDouble(dataScreenVo.getWaterValueLastMonthUsage());
                  DecimalFormat def = new DecimalFormat("0.00");
                  String day4 = def.format(day2 - day3);
                  String week3 = def.format(week1 - week2);
                  String month3 = def.format(month1 - month2);
                  energyScreen.setDayDifference(day4);
                  energyScreen.setWeekDifference(week3);
                  energyScreen.setMonthDifference(month3);
                  energyScreen.setBuildName(envDevice.getUnitName());
              } else if ("3".equals(envDevice.getRemark())) {
                  //用料
                  energyScreen.setCreateDate(new Date());
                  energyScreen.setTodayRead(dataScreenVo.getFeedValueToday());
                  energyScreen.setTodayConsume(dataScreenVo.getFeedValueTodayUsage());
                  energyScreen.setYesterdayConsume(dataScreenVo.getFeedValueYesterdayUsage());
                  energyScreen.setWeekConsume(dataScreenVo.getFeedValueThisWeekUsage());
                  energyScreen.setLastWeekConsume(dataScreenVo.getFeedValueLastWeekUsage());
                  energyScreen.setMonthConsume(dataScreenVo.getFeedValueThisMonthUsage());
                  energyScreen.setLastMonthConsume(dataScreenVo.getFeedValueLastMonthUsage());
                  double day2 = Double.parseDouble(dataScreenVo.getFeedValueTodayUsage());
                  double day3 = Double.parseDouble(dataScreenVo.getFeedValueYesterdayUsage());
                  double week1 = Double.parseDouble(dataScreenVo.getFeedValueThisWeekUsage());
                  double week2 = Double.parseDouble(dataScreenVo.getFeedValueLastWeekUsage());
                  double month1 = Double.parseDouble(dataScreenVo.getFeedValueThisMonthUsage());
                  double month2 = Double.parseDouble(dataScreenVo.getFeedValueLastMonthUsage());
                  DecimalFormat def = new DecimalFormat("0.00");
                  String day4 = def.format(day2 - day3);
                  String week3 = def.format(week1 - week2);
                  String month3 = def.format(month1 - month2);
                  energyScreen.setDayDifference(day4);
                  energyScreen.setWeekDifference(week3);
                  energyScreen.setBuildName(envDevice.getUnitName());
                  energyScreen.setMonthDifference(month3);
              } else {

                  //用电
                  energyScreen.setCreateDate(new Date());
                  energyScreen.setTodayRead(dataScreenVo.getElectricityValueToday());
                  energyScreen.setTodayConsume(dataScreenVo.getElectricityValueTodayUsage());
                  energyScreen.setYesterdayConsume(dataScreenVo.getElectricityValueYesterdayUsage());
                  energyScreen.setWeekConsume(dataScreenVo.getElectricityValueThisWeekUsage());
                  energyScreen.setLastWeekConsume(dataScreenVo.getElectricityValueLastWeekUsage());
                  energyScreen.setMonthConsume(dataScreenVo.getElectricityValueThisMonthUsage());
                  energyScreen.setLastMonthConsume(dataScreenVo.getElectricityValueLastMonthUsage());
                  energyScreen.setBuildName(envDevice.getUnitName());
                  double day2 = Double.parseDouble(dataScreenVo.getElectricityValueTodayUsage());
                  double day3 = Double.parseDouble(dataScreenVo.getElectricityValueYesterdayUsage());
                  double week1 = Double.parseDouble(dataScreenVo.getElectricityValueThisWeekUsage());
                  double week2 = Double.parseDouble(dataScreenVo.getElectricityValueLastWeekUsage());
                  double month1 = Double.parseDouble(dataScreenVo.getElectricityValueThisMonthUsage());
                  double month2 = Double.parseDouble(dataScreenVo.getElectricityValueLastMonthUsage());
                  DecimalFormat def = new DecimalFormat("0.00");
                  String day4 = def.format(day2 - day3);
                  String week3 = def.format(week1 - week2);
                  String month3 = def.format(month1 - month2);
                  energyScreen.setDayDifference(day4);
                  energyScreen.setWeekDifference(week3);
                  energyScreen.setMonthDifference(month3);
              }
              screenMapper.updateById(energyScreen);
          }else {
              //添加一天的第一条数据
              EnergyScreen screen = new EnergyScreen();
              if ("1".equals(envDevice.getRemark())) {
                  //添加用水
                  screen.setCreateDate(new Date());
                  screen.setTodayRead(dataScreenVo.getWaterValueToday());
                  screen.setTodayConsume(dataScreenVo.getWaterValueTodayUsage());
                  screen.setYesterdayConsume(dataScreenVo.getWaterValueYesterdayUsage());
                  screen.setWeekConsume(dataScreenVo.getWaterValueThisWeekUsage());
                  screen.setLastWeekConsume(dataScreenVo.getWaterValueLastWeekUsage());
                  screen.setMonthConsume(dataScreenVo.getWaterValueThisMonthUsage());
                  screen.setLastMonthConsume(dataScreenVo.getWaterValueLastMonthUsage());
                  double day2 = Double.parseDouble(dataScreenVo.getWaterValueTodayUsage());
                  double day3 = Double.parseDouble(dataScreenVo.getWaterValueYesterdayUsage());
                  double week1 = Double.parseDouble(dataScreenVo.getWaterValueThisWeekUsage());
                  double week2 = Double.parseDouble(dataScreenVo.getWaterValueLastWeekUsage());
                  double month1 = Double.parseDouble(dataScreenVo.getWaterValueThisMonthUsage());
                  double month2 = Double.parseDouble(dataScreenVo.getWaterValueLastMonthUsage());
                  DecimalFormat def = new DecimalFormat("0.00");
                  String day4 = def.format(day2 - day3);
                  String week3 = def.format(week1 - week2);
                  String month3 = def.format(month1 - month2);
                  screen.setDayDifference(day4);
                  screen.setWeekDifference(week3);
                  screen.setMonthDifference(month3);
                  screen.setFarmId(28);
                  screen.setBuildName(envDevice.getUnitName());
                  screen.setDeviceCode(envDevice.getDeviceCode());
                  screen.setType(1);
                  screen.setFarmName("芙江养殖基地");
              } else if ("3".equals(envDevice.getRemark())) {
                  screen.setCreateDate(new Date());
                  screen.setTodayRead(dataScreenVo.getFeedValueToday());
                  screen.setTodayConsume(dataScreenVo.getFeedValueTodayUsage());
                  screen.setYesterdayConsume(dataScreenVo.getFeedValueYesterdayUsage());
                  screen.setWeekConsume(dataScreenVo.getFeedValueThisWeekUsage());
                  screen.setLastWeekConsume(dataScreenVo.getFeedValueLastWeekUsage());
                  screen.setMonthConsume(dataScreenVo.getFeedValueThisMonthUsage());
                  screen.setLastMonthConsume(dataScreenVo.getFeedValueLastMonthUsage());
                  double day2 = Double.parseDouble(dataScreenVo.getFeedValueTodayUsage());
                  double day3 = Double.parseDouble(dataScreenVo.getFeedValueYesterdayUsage());
                  double week1 = Double.parseDouble(dataScreenVo.getFeedValueThisWeekUsage());
                  double week2 = Double.parseDouble(dataScreenVo.getFeedValueLastWeekUsage());
                  double month1 = Double.parseDouble(dataScreenVo.getFeedValueThisMonthUsage());
                  double month2 = Double.parseDouble(dataScreenVo.getFeedValueLastMonthUsage());
                  DecimalFormat def = new DecimalFormat("0.00");
                  String day4 = def.format(day2 - day3);
                  String week3 = def.format(week1 - week2);
                  String month3 = def.format(month1 - month2);
                  screen.setDayDifference(day4);
                  screen.setWeekDifference(week3);
                  screen.setMonthDifference(month3);
                  screen.setFarmId(28);
                  screen.setBuildName(envDevice.getUnitName());
                  screen.setDeviceCode(envDevice.getDeviceCode());
                  screen.setType(3);
                  screen.setFarmName("芙江养殖基地");
              } else {
                  screen.setCreateDate(new Date());
                  screen.setTodayRead(dataScreenVo.getElectricityValueToday());
                  screen.setTodayConsume(dataScreenVo.getElectricityValueTodayUsage());
                  screen.setYesterdayConsume(dataScreenVo.getElectricityValueYesterdayUsage());
                  screen.setWeekConsume(dataScreenVo.getElectricityValueThisWeekUsage());
                  screen.setLastWeekConsume(dataScreenVo.getElectricityValueLastWeekUsage());
                  screen.setMonthConsume(dataScreenVo.getElectricityValueThisMonthUsage());
                  screen.setLastMonthConsume(dataScreenVo.getElectricityValueLastMonthUsage());
                  double day2 = Double.parseDouble(dataScreenVo.getElectricityValueTodayUsage());
                  double day3 = Double.parseDouble(dataScreenVo.getElectricityValueYesterdayUsage());
                  double week1 = Double.parseDouble(dataScreenVo.getElectricityValueThisWeekUsage());
                  double week2 = Double.parseDouble(dataScreenVo.getElectricityValueLastWeekUsage());
                  double month1 = Double.parseDouble(dataScreenVo.getElectricityValueThisMonthUsage());
                  double month2 = Double.parseDouble(dataScreenVo.getElectricityValueLastMonthUsage());
                  DecimalFormat def = new DecimalFormat("0.00");
                  String day4 = def.format(day2 - day3);
                  String week3 = def.format(week1 - week2);
                  String month3 = def.format(month1 - month2);
                  screen.setDayDifference(day4);
                  screen.setWeekDifference(week3);
                  screen.setMonthDifference(month3);
                  screen.setFarmId(28);
                  screen.setBuildName(envDevice.getUnitName());
                  screen.setDeviceCode(envDevice.getDeviceCode());
                  screen.setType(2);
                  screen.setFarmName("芙江养殖基地");
              }
              screenMapper.insert(screen);
          }

      }
  }

    //庙贝29
    @Scheduled(cron = "0 59 * * * ? ")
    private void getShenChan20() throws Exception {
        QueryWrapper<EnergyEnvDevice> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("farm_id", 29);
        List<EnergyEnvDevice> envDevices = envDeviceMapper.selectList(queryWrapper);

        Date timesmorning = DataUill.getTimesmorning();
        DateTime dateTime = DateUtil.beginOfWeek(new Date());//本周
        Date timesMonthmorning = DataUill.getTimesMonthmorning();//本月
        Date dayStart = (Date) getYesterdayRange().get("startTime");
        Date dayEnd = (Date) getYesterdayRange().get("stopTime");
        Date weekStart = (Date) getLastWeekRange().get("startTime");
        Date weekEnd = (Date) getLastWeekRange().get("stopTime");
        Date monthStart = (Date) getLastMonthRange().get("startTime");
        Date monthEnd = (Date) getLastMonthRange().get("stopTime");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");


        for (EnergyEnvDevice envDevice : envDevices) {
            EnergyDataScreenVo dataScreenVo = dataMapper.listDataAll(sdf.format(timesmorning), sdf.format(dateTime), sdf.format(timesMonthmorning),
                    sdf.format(dayStart), sdf.format(dayEnd)
                    , sdf.format(weekStart), sdf.format(weekEnd)
                    , sdf.format(monthStart), sdf.format(monthEnd)
                    , envDevice.getUnitId(), "29");

            QueryWrapper<EnergyScreen> queryWrapper1 = new QueryWrapper<>();
            queryWrapper1.eq("farm_id", 29).ge("create_date", timesMonthmorning).eq("device_code", envDevice.getDeviceCode());
            EnergyScreen energyScreen = screenMapper.selectOne(queryWrapper1);

            if (ObjectUtil.isNotEmpty(energyScreen)) {
                //说明今天的数据已经存在 后续只需要更新即可
                if ("1".equals(envDevice.getRemark())) {
                    //用水
                    energyScreen.setCreateDate(new Date());
                    energyScreen.setTodayRead(dataScreenVo.getWaterValueToday());
                    energyScreen.setTodayConsume(dataScreenVo.getWaterValueTodayUsage());
                    energyScreen.setYesterdayConsume(dataScreenVo.getWaterValueYesterdayUsage());
                    energyScreen.setWeekConsume(dataScreenVo.getWaterValueThisWeekUsage());
                    energyScreen.setLastWeekConsume(dataScreenVo.getWaterValueLastWeekUsage());
                    energyScreen.setMonthConsume(dataScreenVo.getWaterValueThisMonthUsage());
                    energyScreen.setLastMonthConsume(dataScreenVo.getWaterValueLastMonthUsage());
                    energyScreen.setBuildName(envDevice.getUnitName());
                    double day2 = Double.parseDouble(dataScreenVo.getWaterValueTodayUsage());
                    double day3 = Double.parseDouble(dataScreenVo.getWaterValueYesterdayUsage());
                    double week1 = Double.parseDouble(dataScreenVo.getWaterValueThisWeekUsage());
                    double week2 = Double.parseDouble(dataScreenVo.getWaterValueLastWeekUsage());
                    double month1 = Double.parseDouble(dataScreenVo.getWaterValueThisMonthUsage());
                    double month2 = Double.parseDouble(dataScreenVo.getWaterValueLastMonthUsage());
                    DecimalFormat def = new DecimalFormat("0.00");
                    String day4 = def.format(day2 - day3);
                    String week3 = def.format(week1 - week2);
                    String month3 = def.format(month1 - month2);
                    energyScreen.setDayDifference(day4);
                    energyScreen.setWeekDifference(week3);
                    energyScreen.setMonthDifference(month3);
                } else if ("3".equals(envDevice.getRemark())) {
                    //用料
                    energyScreen.setCreateDate(new Date());
                    energyScreen.setTodayRead(dataScreenVo.getFeedValueToday());
                    energyScreen.setTodayConsume(dataScreenVo.getFeedValueTodayUsage());
                    energyScreen.setYesterdayConsume(dataScreenVo.getFeedValueYesterdayUsage());
                    energyScreen.setWeekConsume(dataScreenVo.getFeedValueThisWeekUsage());
                    energyScreen.setLastWeekConsume(dataScreenVo.getFeedValueLastWeekUsage());
                    energyScreen.setMonthConsume(dataScreenVo.getFeedValueThisMonthUsage());
                    energyScreen.setLastMonthConsume(dataScreenVo.getFeedValueLastMonthUsage());
                    energyScreen.setBuildName(envDevice.getUnitName());
                    double day2 = Double.parseDouble(dataScreenVo.getFeedValueTodayUsage());
                    double day3 = Double.parseDouble(dataScreenVo.getFeedValueYesterdayUsage());
                    double week1 = Double.parseDouble(dataScreenVo.getFeedValueThisWeekUsage());
                    double week2 = Double.parseDouble(dataScreenVo.getFeedValueLastWeekUsage());
                    double month1 = Double.parseDouble(dataScreenVo.getFeedValueThisMonthUsage());
                    double month2 = Double.parseDouble(dataScreenVo.getFeedValueLastMonthUsage());
                    DecimalFormat def = new DecimalFormat("0.00");
                    String day4 = def.format(day2 - day3);
                    String week3 = def.format(week1 - week2);
                    String month3 = def.format(month1 - month2);
                    energyScreen.setDayDifference(day4);
                    energyScreen.setWeekDifference(week3);
                    energyScreen.setMonthDifference(month3);
                } else {
                    //用电
                    energyScreen.setCreateDate(new Date());
                    energyScreen.setTodayRead(dataScreenVo.getElectricityValueToday());
                    energyScreen.setTodayConsume(dataScreenVo.getElectricityValueTodayUsage());
                    energyScreen.setYesterdayConsume(dataScreenVo.getElectricityValueYesterdayUsage());
                    energyScreen.setWeekConsume(dataScreenVo.getElectricityValueThisWeekUsage());
                    energyScreen.setLastWeekConsume(dataScreenVo.getElectricityValueLastWeekUsage());
                    energyScreen.setMonthConsume(dataScreenVo.getElectricityValueThisMonthUsage());
                    energyScreen.setLastMonthConsume(dataScreenVo.getElectricityValueLastMonthUsage());
                    energyScreen.setBuildName(envDevice.getUnitName());
                    double day2 = Double.parseDouble(dataScreenVo.getElectricityValueTodayUsage());
                    double day3 = Double.parseDouble(dataScreenVo.getElectricityValueYesterdayUsage());
                    double week1 = Double.parseDouble(dataScreenVo.getElectricityValueThisWeekUsage());
                    double week2 = Double.parseDouble(dataScreenVo.getElectricityValueLastWeekUsage());
                    double month1 = Double.parseDouble(dataScreenVo.getElectricityValueThisMonthUsage());
                    double month2 = Double.parseDouble(dataScreenVo.getElectricityValueLastMonthUsage());
                    DecimalFormat def = new DecimalFormat("0.00");
                    String day4 = def.format(day2 - day3);
                    String week3 = def.format(week1 - week2);
                    String month3 = def.format(month1 - month2);
                    energyScreen.setDayDifference(day4);
                    energyScreen.setWeekDifference(week3);
                    energyScreen.setMonthDifference(month3);
                }
                screenMapper.updateById(energyScreen);
            }else {
                //添加一天的第一条数据
                EnergyScreen screen = new EnergyScreen();
                if ("1".equals(envDevice.getRemark())) {
                    //添加用水
                    screen.setCreateDate(new Date());
                    screen.setTodayRead(dataScreenVo.getWaterValueToday());
                    screen.setTodayConsume(dataScreenVo.getWaterValueTodayUsage());
                    screen.setYesterdayConsume(dataScreenVo.getWaterValueYesterdayUsage());
                    screen.setWeekConsume(dataScreenVo.getWaterValueThisWeekUsage());
                    screen.setLastWeekConsume(dataScreenVo.getWaterValueLastWeekUsage());
                    screen.setMonthConsume(dataScreenVo.getWaterValueThisMonthUsage());
                    screen.setLastMonthConsume(dataScreenVo.getWaterValueLastMonthUsage());
                    double day2 = Double.parseDouble(dataScreenVo.getWaterValueTodayUsage());
                    double day3 = Double.parseDouble(dataScreenVo.getWaterValueYesterdayUsage());
                    double week1 = Double.parseDouble(dataScreenVo.getWaterValueThisWeekUsage());
                    double week2 = Double.parseDouble(dataScreenVo.getWaterValueLastWeekUsage());
                    double month1 = Double.parseDouble(dataScreenVo.getWaterValueThisMonthUsage());
                    double month2 = Double.parseDouble(dataScreenVo.getWaterValueLastMonthUsage());
                    DecimalFormat def = new DecimalFormat("0.00");
                    String day4 = def.format(day2 - day3);
                    String week3 = def.format(week1 - week2);
                    String month3 = def.format(month1 - month2);
                    screen.setDayDifference(day4);
                    screen.setWeekDifference(week3);
                    screen.setMonthDifference(month3);
                    screen.setFarmId(29);
                    screen.setBuildName(envDevice.getUnitName());
                    screen.setDeviceCode(envDevice.getDeviceCode());
                    screen.setType(1);
                    screen.setFarmName("庙贝养殖基地");
                }else if ("3".equals(envDevice.getRemark())) {
                    screen.setCreateDate(new Date());
                    screen.setTodayRead(dataScreenVo.getFeedValueToday());
                    screen.setTodayConsume(dataScreenVo.getFeedValueTodayUsage());
                    screen.setYesterdayConsume(dataScreenVo.getFeedValueYesterdayUsage());
                    screen.setWeekConsume(dataScreenVo.getFeedValueThisWeekUsage());
                    screen.setLastWeekConsume(dataScreenVo.getFeedValueLastWeekUsage());
                    screen.setMonthConsume(dataScreenVo.getFeedValueThisMonthUsage());
                    screen.setLastMonthConsume(dataScreenVo.getFeedValueLastMonthUsage());
                    double day2 = Double.parseDouble(dataScreenVo.getFeedValueTodayUsage());
                    double day3 = Double.parseDouble(dataScreenVo.getFeedValueYesterdayUsage());
                    double week1 = Double.parseDouble(dataScreenVo.getFeedValueThisWeekUsage());
                    double week2 = Double.parseDouble(dataScreenVo.getFeedValueLastWeekUsage());
                    double month1 = Double.parseDouble(dataScreenVo.getFeedValueThisMonthUsage());
                    double month2 = Double.parseDouble(dataScreenVo.getFeedValueLastMonthUsage());
                    DecimalFormat def = new DecimalFormat("0.00");
                    String day4 = def.format(day2 - day3);
                    String week3 = def.format(week1 - week2);
                    String month3 = def.format(month1 - month2);
                    screen.setDayDifference(day4);
                    screen.setWeekDifference(week3);
                    screen.setMonthDifference(month3);
                    screen.setFarmId(29);
                    screen.setBuildName(envDevice.getUnitName());
                    screen.setDeviceCode(envDevice.getDeviceCode());
                    screen.setType(3);
                    screen.setFarmName("庙贝养殖基地");
                }  else {
                    screen.setCreateDate(new Date());
                    screen.setTodayRead(dataScreenVo.getElectricityValueToday());
                    screen.setTodayConsume(dataScreenVo.getElectricityValueTodayUsage());
                    screen.setYesterdayConsume(dataScreenVo.getElectricityValueYesterdayUsage());
                    screen.setWeekConsume(dataScreenVo.getElectricityValueThisWeekUsage());
                    screen.setLastWeekConsume(dataScreenVo.getElectricityValueLastWeekUsage());
                    screen.setMonthConsume(dataScreenVo.getElectricityValueThisMonthUsage());
                    screen.setLastMonthConsume(dataScreenVo.getElectricityValueLastMonthUsage());
                    double day2 = Double.parseDouble(dataScreenVo.getElectricityValueTodayUsage());
                    double day3 = Double.parseDouble(dataScreenVo.getElectricityValueYesterdayUsage());
                    double week1 = Double.parseDouble(dataScreenVo.getElectricityValueThisWeekUsage());
                    double week2 = Double.parseDouble(dataScreenVo.getElectricityValueLastWeekUsage());
                    double month1 = Double.parseDouble(dataScreenVo.getElectricityValueThisMonthUsage());
                    double month2 = Double.parseDouble(dataScreenVo.getElectricityValueLastMonthUsage());
                    DecimalFormat def = new DecimalFormat("0.00");
                    String day4 = def.format(day2 - day3);
                    String week3 = def.format(week1 - week2);
                    String month3 = def.format(month1 - month2);
                    screen.setDayDifference(day4);
                    screen.setWeekDifference(week3);
                    screen.setMonthDifference(month3);
                    screen.setFarmId(29);
                    screen.setBuildName(envDevice.getUnitName());
                    screen.setDeviceCode(envDevice.getDeviceCode());
                    screen.setType(2);
                    screen.setFarmName("庙贝养殖基地");
                }
                screenMapper.insert(screen);
            }

        }
    }

    //潞水30
    @Scheduled(cron = "0 59 * * * ? ")
    private void getShenChan21() throws Exception {
        QueryWrapper<EnergyEnvDevice> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("farm_id", 30);
        List<EnergyEnvDevice> envDevices = envDeviceMapper.selectList(queryWrapper);

        Date timesmorning = DataUill.getTimesmorning();
        DateTime dateTime = DateUtil.beginOfWeek(new Date());//本周
        Date timesMonthmorning = DataUill.getTimesMonthmorning();//本月
        Date dayStart = (Date) getYesterdayRange().get("startTime");
        Date dayEnd = (Date) getYesterdayRange().get("stopTime");
        Date weekStart = (Date) getLastWeekRange().get("startTime");
        Date weekEnd = (Date) getLastWeekRange().get("stopTime");
        Date monthStart = (Date) getLastMonthRange().get("startTime");
        Date monthEnd = (Date) getLastMonthRange().get("stopTime");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");


        for (EnergyEnvDevice envDevice : envDevices) {
            EnergyDataScreenVo dataScreenVo = dataMapper.listDataAll(sdf.format(timesmorning), sdf.format(dateTime), sdf.format(timesMonthmorning),
                    sdf.format(dayStart), sdf.format(dayEnd)
                    , sdf.format(weekStart), sdf.format(weekEnd)
                    , sdf.format(monthStart), sdf.format(monthEnd)
                    , envDevice.getUnitId(), "30");

            QueryWrapper<EnergyScreen> queryWrapper1 = new QueryWrapper<>();
            queryWrapper1.eq("farm_id", 30).ge("create_date", timesMonthmorning).eq("device_code", envDevice.getDeviceCode());
            EnergyScreen energyScreen = screenMapper.selectOne(queryWrapper1);

            if (ObjectUtil.isNotEmpty(energyScreen)) {
                //说明今天的数据已经存在 后续只需要更新即可
                if ("1".equals(envDevice.getRemark())) {
                    //用水
                    energyScreen.setCreateDate(new Date());
                    energyScreen.setTodayRead(dataScreenVo.getWaterValueToday());
                    energyScreen.setTodayConsume(dataScreenVo.getWaterValueTodayUsage());
                    energyScreen.setYesterdayConsume(dataScreenVo.getWaterValueYesterdayUsage());
                    energyScreen.setWeekConsume(dataScreenVo.getWaterValueThisWeekUsage());
                    energyScreen.setLastWeekConsume(dataScreenVo.getWaterValueLastWeekUsage());
                    energyScreen.setMonthConsume(dataScreenVo.getWaterValueThisMonthUsage());
                    energyScreen.setLastMonthConsume(dataScreenVo.getWaterValueLastMonthUsage());
                    energyScreen.setBuildName(envDevice.getUnitName());
                    double day2 = Double.parseDouble(dataScreenVo.getWaterValueTodayUsage());
                    double day3 = Double.parseDouble(dataScreenVo.getWaterValueYesterdayUsage());
                    double week1 = Double.parseDouble(dataScreenVo.getWaterValueThisWeekUsage());
                    double week2 = Double.parseDouble(dataScreenVo.getWaterValueLastWeekUsage());
                    double month1 = Double.parseDouble(dataScreenVo.getWaterValueThisMonthUsage());
                    double month2 = Double.parseDouble(dataScreenVo.getWaterValueLastMonthUsage());
                    DecimalFormat def = new DecimalFormat("0.00");
                    String day4 = def.format(day2 - day3);
                    String week3 = def.format(week1 - week2);
                    String month3 = def.format(month1 - month2);
                    energyScreen.setDayDifference(day4);
                    energyScreen.setWeekDifference(week3);
                    energyScreen.setMonthDifference(month3);
                } else if ("3".equals(envDevice.getRemark())) {
                    //用料
                    energyScreen.setCreateDate(new Date());
                    energyScreen.setTodayRead(dataScreenVo.getFeedValueToday());
                    energyScreen.setTodayConsume(dataScreenVo.getFeedValueTodayUsage());
                    energyScreen.setYesterdayConsume(dataScreenVo.getFeedValueYesterdayUsage());
                    energyScreen.setWeekConsume(dataScreenVo.getFeedValueThisWeekUsage());
                    energyScreen.setLastWeekConsume(dataScreenVo.getFeedValueLastWeekUsage());
                    energyScreen.setMonthConsume(dataScreenVo.getFeedValueThisMonthUsage());
                    energyScreen.setLastMonthConsume(dataScreenVo.getFeedValueLastMonthUsage());
                    double day2 = Double.parseDouble(dataScreenVo.getFeedValueTodayUsage());
                    double day3 = Double.parseDouble(dataScreenVo.getFeedValueYesterdayUsage());
                    double week1 = Double.parseDouble(dataScreenVo.getFeedValueThisWeekUsage());
                    double week2 = Double.parseDouble(dataScreenVo.getFeedValueLastWeekUsage());
                    double month1 = Double.parseDouble(dataScreenVo.getFeedValueThisMonthUsage());
                    double month2 = Double.parseDouble(dataScreenVo.getFeedValueLastMonthUsage());
                    energyScreen.setBuildName(envDevice.getUnitName());
                    DecimalFormat def = new DecimalFormat("0.00");
                    String day4 = def.format(day2 - day3);
                    String week3 = def.format(week1 - week2);
                    String month3 = def.format(month1 - month2);
                    energyScreen.setDayDifference(day4);
                    energyScreen.setWeekDifference(week3);
                    energyScreen.setMonthDifference(month3);
                } else {
                    //用电
                    energyScreen.setCreateDate(new Date());
                    energyScreen.setTodayRead(dataScreenVo.getElectricityValueToday());
                    energyScreen.setTodayConsume(dataScreenVo.getElectricityValueTodayUsage());
                    energyScreen.setYesterdayConsume(dataScreenVo.getElectricityValueYesterdayUsage());
                    energyScreen.setWeekConsume(dataScreenVo.getElectricityValueThisWeekUsage());
                    energyScreen.setLastWeekConsume(dataScreenVo.getElectricityValueLastWeekUsage());
                    energyScreen.setMonthConsume(dataScreenVo.getElectricityValueThisMonthUsage());
                    energyScreen.setLastMonthConsume(dataScreenVo.getElectricityValueLastMonthUsage());
                    double day2 = Double.parseDouble(dataScreenVo.getElectricityValueTodayUsage());
                    double day3 = Double.parseDouble(dataScreenVo.getElectricityValueYesterdayUsage());
                    double week1 = Double.parseDouble(dataScreenVo.getElectricityValueThisWeekUsage());
                    double week2 = Double.parseDouble(dataScreenVo.getElectricityValueLastWeekUsage());
                    double month1 = Double.parseDouble(dataScreenVo.getElectricityValueThisMonthUsage());
                    double month2 = Double.parseDouble(dataScreenVo.getElectricityValueLastMonthUsage());
                    energyScreen.setBuildName(envDevice.getUnitName());
                    DecimalFormat def = new DecimalFormat("0.00");
                    String day4 = def.format(day2 - day3);
                    String week3 = def.format(week1 - week2);
                    String month3 = def.format(month1 - month2);
                    energyScreen.setDayDifference(day4);
                    energyScreen.setWeekDifference(week3);
                    energyScreen.setMonthDifference(month3);
                }
                screenMapper.updateById(energyScreen);
            }else {
                //添加一天的第一条数据
                EnergyScreen screen = new EnergyScreen();
                if ("1".equals(envDevice.getRemark())) {
                    //添加用水
                    screen.setCreateDate(new Date());
                    screen.setTodayRead(dataScreenVo.getWaterValueToday());
                    screen.setTodayConsume(dataScreenVo.getWaterValueTodayUsage());
                    screen.setYesterdayConsume(dataScreenVo.getWaterValueYesterdayUsage());
                    screen.setWeekConsume(dataScreenVo.getWaterValueThisWeekUsage());
                    screen.setLastWeekConsume(dataScreenVo.getWaterValueLastWeekUsage());
                    screen.setMonthConsume(dataScreenVo.getWaterValueThisMonthUsage());
                    screen.setLastMonthConsume(dataScreenVo.getWaterValueLastMonthUsage());
                    double day2 = Double.parseDouble(dataScreenVo.getWaterValueTodayUsage());
                    double day3 = Double.parseDouble(dataScreenVo.getWaterValueYesterdayUsage());
                    double week1 = Double.parseDouble(dataScreenVo.getWaterValueThisWeekUsage());
                    double week2 = Double.parseDouble(dataScreenVo.getWaterValueLastWeekUsage());
                    double month1 = Double.parseDouble(dataScreenVo.getWaterValueThisMonthUsage());
                    double month2 = Double.parseDouble(dataScreenVo.getWaterValueLastMonthUsage());
                    DecimalFormat def = new DecimalFormat("0.00");
                    String day4 = def.format(day2 - day3);
                    String week3 = def.format(week1 - week2);
                    String month3 = def.format(month1 - month2);
                    screen.setDayDifference(day4);
                    screen.setWeekDifference(week3);
                    screen.setMonthDifference(month3);
                    screen.setFarmId(30);
                    screen.setBuildName(envDevice.getUnitName());
                    screen.setDeviceCode(envDevice.getDeviceCode());
                    screen.setType(1);
                    screen.setFarmName("潞水养殖基地");
                } else if ("3".equals(envDevice.getRemark())) {
                    screen.setCreateDate(new Date());
                    screen.setTodayRead(dataScreenVo.getFeedValueToday());
                    screen.setTodayConsume(dataScreenVo.getFeedValueTodayUsage());
                    screen.setYesterdayConsume(dataScreenVo.getFeedValueYesterdayUsage());
                    screen.setWeekConsume(dataScreenVo.getFeedValueThisWeekUsage());
                    screen.setLastWeekConsume(dataScreenVo.getFeedValueLastWeekUsage());
                    screen.setMonthConsume(dataScreenVo.getFeedValueThisMonthUsage());
                    screen.setLastMonthConsume(dataScreenVo.getFeedValueLastMonthUsage());
                    double day2 = Double.parseDouble(dataScreenVo.getFeedValueTodayUsage());
                    double day3 = Double.parseDouble(dataScreenVo.getFeedValueYesterdayUsage());
                    double week1 = Double.parseDouble(dataScreenVo.getFeedValueThisWeekUsage());
                    double week2 = Double.parseDouble(dataScreenVo.getFeedValueLastWeekUsage());
                    double month1 = Double.parseDouble(dataScreenVo.getFeedValueThisMonthUsage());
                    double month2 = Double.parseDouble(dataScreenVo.getFeedValueLastMonthUsage());
                    DecimalFormat def = new DecimalFormat("0.00");
                    String day4 = def.format(day2 - day3);
                    String week3 = def.format(week1 - week2);
                    String month3 = def.format(month1 - month2);
                    screen.setDayDifference(day4);
                    screen.setWeekDifference(week3);
                    screen.setMonthDifference(month3);
                    screen.setFarmId(30);
                    screen.setBuildName(envDevice.getUnitName());
                    screen.setDeviceCode(envDevice.getDeviceCode());
                    screen.setType(3);
                    screen.setFarmName("潞水养殖基地");
                } else {
                    screen.setCreateDate(new Date());
                    screen.setTodayRead(dataScreenVo.getElectricityValueToday());
                    screen.setTodayConsume(dataScreenVo.getElectricityValueTodayUsage());
                    screen.setYesterdayConsume(dataScreenVo.getElectricityValueYesterdayUsage());
                    screen.setWeekConsume(dataScreenVo.getElectricityValueThisWeekUsage());
                    screen.setLastWeekConsume(dataScreenVo.getElectricityValueLastWeekUsage());
                    screen.setMonthConsume(dataScreenVo.getElectricityValueThisMonthUsage());
                    screen.setLastMonthConsume(dataScreenVo.getElectricityValueLastMonthUsage());
                    double day2 = Double.parseDouble(dataScreenVo.getElectricityValueTodayUsage());
                    double day3 = Double.parseDouble(dataScreenVo.getElectricityValueYesterdayUsage());
                    double week1 = Double.parseDouble(dataScreenVo.getElectricityValueThisWeekUsage());
                    double week2 = Double.parseDouble(dataScreenVo.getElectricityValueLastWeekUsage());
                    double month1 = Double.parseDouble(dataScreenVo.getElectricityValueThisMonthUsage());
                    double month2 = Double.parseDouble(dataScreenVo.getElectricityValueLastMonthUsage());
                    DecimalFormat def = new DecimalFormat("0.00");
                    String day4 = def.format(day2 - day3);
                    String week3 = def.format(week1 - week2);
                    String month3 = def.format(month1 - month2);
                    screen.setDayDifference(day4);
                    screen.setWeekDifference(week3);
                    screen.setMonthDifference(month3);
                    screen.setFarmId(30);
                    screen.setBuildName(envDevice.getUnitName());
                    screen.setDeviceCode(envDevice.getDeviceCode());
                    screen.setType(2);
                    screen.setFarmName("潞水养殖基地");
                }
                screenMapper.insert(screen);
            }

        }
    }

    //凤行31
    @Scheduled(cron = "0 59 * * * ? ")
    private void getShenChan22() throws Exception {
        QueryWrapper<EnergyEnvDevice> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("farm_id", 31);
        List<EnergyEnvDevice> envDevices = envDeviceMapper.selectList(queryWrapper);

        Date timesmorning = DataUill.getTimesmorning();
        DateTime dateTime = DateUtil.beginOfWeek(new Date());//本周
        Date timesMonthmorning = DataUill.getTimesMonthmorning();//本月
        Date dayStart = (Date) getYesterdayRange().get("startTime");
        Date dayEnd = (Date) getYesterdayRange().get("stopTime");
        Date weekStart = (Date) getLastWeekRange().get("startTime");
        Date weekEnd = (Date) getLastWeekRange().get("stopTime");
        Date monthStart = (Date) getLastMonthRange().get("startTime");
        Date monthEnd = (Date) getLastMonthRange().get("stopTime");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");


        for (EnergyEnvDevice envDevice : envDevices) {
            EnergyDataScreenVo dataScreenVo = dataMapper.listDataAll(sdf.format(timesmorning), sdf.format(dateTime), sdf.format(timesMonthmorning),
                    sdf.format(dayStart), sdf.format(dayEnd)
                    , sdf.format(weekStart), sdf.format(weekEnd)
                    , sdf.format(monthStart), sdf.format(monthEnd)
                    , envDevice.getUnitId(), "31");

            QueryWrapper<EnergyScreen> queryWrapper1 = new QueryWrapper<>();
            queryWrapper1.eq("farm_id", 31).ge("create_date", timesMonthmorning).eq("device_code", envDevice.getDeviceCode());
            EnergyScreen energyScreen = screenMapper.selectOne(queryWrapper1);

            if (ObjectUtil.isNotEmpty(energyScreen)) {
                //说明今天的数据已经存在 后续只需要更新即可
                if ("1".equals(envDevice.getRemark())) {
                    //用水
                    energyScreen.setCreateDate(new Date());
                    energyScreen.setTodayRead(dataScreenVo.getWaterValueToday());
                    energyScreen.setTodayConsume(dataScreenVo.getWaterValueTodayUsage());
                    energyScreen.setYesterdayConsume(dataScreenVo.getWaterValueYesterdayUsage());
                    energyScreen.setWeekConsume(dataScreenVo.getWaterValueThisWeekUsage());
                    energyScreen.setLastWeekConsume(dataScreenVo.getWaterValueLastWeekUsage());
                    energyScreen.setMonthConsume(dataScreenVo.getWaterValueThisMonthUsage());
                    energyScreen.setLastMonthConsume(dataScreenVo.getWaterValueLastMonthUsage());
                    double day2 = Double.parseDouble(dataScreenVo.getWaterValueTodayUsage());
                    double day3 = Double.parseDouble(dataScreenVo.getWaterValueYesterdayUsage());
                    double week1 = Double.parseDouble(dataScreenVo.getWaterValueThisWeekUsage());
                    double week2 = Double.parseDouble(dataScreenVo.getWaterValueLastWeekUsage());
                    double month1 = Double.parseDouble(dataScreenVo.getWaterValueThisMonthUsage());
                    double month2 = Double.parseDouble(dataScreenVo.getWaterValueLastMonthUsage());
                    energyScreen.setBuildName(envDevice.getUnitName());
                    DecimalFormat def = new DecimalFormat("0.00");
                    String day4 = def.format(day2 - day3);
                    String week3 = def.format(week1 - week2);
                    String month3 = def.format(month1 - month2);
                    energyScreen.setDayDifference(day4);
                    energyScreen.setWeekDifference(week3);
                    energyScreen.setMonthDifference(month3);
                } else if ("3".equals(envDevice.getRemark())) {
                    //用料
                    energyScreen.setCreateDate(new Date());
                    energyScreen.setTodayRead(dataScreenVo.getFeedValueToday());
                    energyScreen.setTodayConsume(dataScreenVo.getFeedValueTodayUsage());
                    energyScreen.setYesterdayConsume(dataScreenVo.getFeedValueYesterdayUsage());
                    energyScreen.setWeekConsume(dataScreenVo.getFeedValueThisWeekUsage());
                    energyScreen.setLastWeekConsume(dataScreenVo.getFeedValueLastWeekUsage());
                    energyScreen.setMonthConsume(dataScreenVo.getFeedValueThisMonthUsage());
                    energyScreen.setLastMonthConsume(dataScreenVo.getFeedValueLastMonthUsage());
                    energyScreen.setBuildName(envDevice.getUnitName());
                    double day2 = Double.parseDouble(dataScreenVo.getFeedValueTodayUsage());
                    double day3 = Double.parseDouble(dataScreenVo.getFeedValueYesterdayUsage());
                    double week1 = Double.parseDouble(dataScreenVo.getFeedValueThisWeekUsage());
                    double week2 = Double.parseDouble(dataScreenVo.getFeedValueLastWeekUsage());
                    double month1 = Double.parseDouble(dataScreenVo.getFeedValueThisMonthUsage());
                    double month2 = Double.parseDouble(dataScreenVo.getFeedValueLastMonthUsage());
                    DecimalFormat def = new DecimalFormat("0.00");
                    String day4 = def.format(day2 - day3);
                    String week3 = def.format(week1 - week2);
                    String month3 = def.format(month1 - month2);
                    energyScreen.setDayDifference(day4);
                    energyScreen.setWeekDifference(week3);
                    energyScreen.setMonthDifference(month3);
                } else {
                    //用电
                    energyScreen.setCreateDate(new Date());
                    energyScreen.setTodayRead(dataScreenVo.getElectricityValueToday());
                    energyScreen.setTodayConsume(dataScreenVo.getElectricityValueTodayUsage());
                    energyScreen.setYesterdayConsume(dataScreenVo.getElectricityValueYesterdayUsage());
                    energyScreen.setWeekConsume(dataScreenVo.getElectricityValueThisWeekUsage());
                    energyScreen.setLastWeekConsume(dataScreenVo.getElectricityValueLastWeekUsage());
                    energyScreen.setMonthConsume(dataScreenVo.getElectricityValueThisMonthUsage());
                    energyScreen.setLastMonthConsume(dataScreenVo.getElectricityValueLastMonthUsage());
                    energyScreen.setBuildName(envDevice.getUnitName());
                    double day2 = Double.parseDouble(dataScreenVo.getElectricityValueTodayUsage());
                    double day3 = Double.parseDouble(dataScreenVo.getElectricityValueYesterdayUsage());
                    double week1 = Double.parseDouble(dataScreenVo.getElectricityValueThisWeekUsage());
                    double week2 = Double.parseDouble(dataScreenVo.getElectricityValueLastWeekUsage());
                    double month1 = Double.parseDouble(dataScreenVo.getElectricityValueThisMonthUsage());
                    double month2 = Double.parseDouble(dataScreenVo.getElectricityValueLastMonthUsage());
                    DecimalFormat def = new DecimalFormat("0.00");
                    String day4 = def.format(day2 - day3);
                    String week3 = def.format(week1 - week2);
                    String month3 = def.format(month1 - month2);
                    energyScreen.setDayDifference(day4);
                    energyScreen.setWeekDifference(week3);
                    energyScreen.setMonthDifference(month3);
                }
                screenMapper.updateById(energyScreen);
            }else {
                //添加一天的第一条数据
                EnergyScreen screen = new EnergyScreen();
                if ("1".equals(envDevice.getRemark())) {
                    //添加用水
                    screen.setCreateDate(new Date());
                    screen.setTodayRead(dataScreenVo.getWaterValueToday());
                    screen.setTodayConsume(dataScreenVo.getWaterValueTodayUsage());
                    screen.setYesterdayConsume(dataScreenVo.getWaterValueYesterdayUsage());
                    screen.setWeekConsume(dataScreenVo.getWaterValueThisWeekUsage());
                    screen.setLastWeekConsume(dataScreenVo.getWaterValueLastWeekUsage());
                    screen.setMonthConsume(dataScreenVo.getWaterValueThisMonthUsage());
                    screen.setLastMonthConsume(dataScreenVo.getWaterValueLastMonthUsage());
                    double day2 = Double.parseDouble(dataScreenVo.getWaterValueTodayUsage());
                    double day3 = Double.parseDouble(dataScreenVo.getWaterValueYesterdayUsage());
                    double week1 = Double.parseDouble(dataScreenVo.getWaterValueThisWeekUsage());
                    double week2 = Double.parseDouble(dataScreenVo.getWaterValueLastWeekUsage());
                    double month1 = Double.parseDouble(dataScreenVo.getWaterValueThisMonthUsage());
                    double month2 = Double.parseDouble(dataScreenVo.getWaterValueLastMonthUsage());
                    DecimalFormat def = new DecimalFormat("0.00");
                    String day4 = def.format(day2 - day3);
                    String week3 = def.format(week1 - week2);
                    String month3 = def.format(month1 - month2);
                    screen.setDayDifference(day4);
                    screen.setWeekDifference(week3);
                    screen.setMonthDifference(month3);
                    screen.setFarmId(31);
                    screen.setBuildName(envDevice.getUnitName());
                    screen.setDeviceCode(envDevice.getDeviceCode());
                    screen.setType(1);
                    screen.setFarmName("凤形养殖基地");
                } else if ("3".equals(envDevice.getRemark())) {
                    screen.setCreateDate(new Date());
                    screen.setTodayRead(dataScreenVo.getFeedValueToday());
                    screen.setTodayConsume(dataScreenVo.getFeedValueTodayUsage());
                    screen.setYesterdayConsume(dataScreenVo.getFeedValueYesterdayUsage());
                    screen.setWeekConsume(dataScreenVo.getFeedValueThisWeekUsage());
                    screen.setLastWeekConsume(dataScreenVo.getFeedValueLastWeekUsage());
                    screen.setMonthConsume(dataScreenVo.getFeedValueThisMonthUsage());
                    screen.setLastMonthConsume(dataScreenVo.getFeedValueLastMonthUsage());
                    double day2 = Double.parseDouble(dataScreenVo.getFeedValueTodayUsage());
                    double day3 = Double.parseDouble(dataScreenVo.getFeedValueYesterdayUsage());
                    double week1 = Double.parseDouble(dataScreenVo.getFeedValueThisWeekUsage());
                    double week2 = Double.parseDouble(dataScreenVo.getFeedValueLastWeekUsage());
                    double month1 = Double.parseDouble(dataScreenVo.getFeedValueThisMonthUsage());
                    double month2 = Double.parseDouble(dataScreenVo.getFeedValueLastMonthUsage());
                    DecimalFormat def = new DecimalFormat("0.00");
                    String day4 = def.format(day2 - day3);
                    String week3 = def.format(week1 - week2);
                    String month3 = def.format(month1 - month2);
                    screen.setDayDifference(day4);
                    screen.setWeekDifference(week3);
                    screen.setMonthDifference(month3);
                    screen.setFarmId(31);
                    screen.setBuildName(envDevice.getUnitName());
                    screen.setDeviceCode(envDevice.getDeviceCode());
                    screen.setType(3);
                    screen.setFarmName("凤形养殖基地");
                } else {
                    screen.setCreateDate(new Date());
                    screen.setTodayRead(dataScreenVo.getElectricityValueToday());
                    screen.setTodayConsume(dataScreenVo.getElectricityValueTodayUsage());
                    screen.setYesterdayConsume(dataScreenVo.getElectricityValueYesterdayUsage());
                    screen.setWeekConsume(dataScreenVo.getElectricityValueThisWeekUsage());
                    screen.setLastWeekConsume(dataScreenVo.getElectricityValueLastWeekUsage());
                    screen.setMonthConsume(dataScreenVo.getElectricityValueThisMonthUsage());
                    screen.setLastMonthConsume(dataScreenVo.getElectricityValueLastMonthUsage());
                    double day2 = Double.parseDouble(dataScreenVo.getElectricityValueTodayUsage());
                    double day3 = Double.parseDouble(dataScreenVo.getElectricityValueYesterdayUsage());
                    double week1 = Double.parseDouble(dataScreenVo.getElectricityValueThisWeekUsage());
                    double week2 = Double.parseDouble(dataScreenVo.getElectricityValueLastWeekUsage());
                    double month1 = Double.parseDouble(dataScreenVo.getElectricityValueThisMonthUsage());
                    double month2 = Double.parseDouble(dataScreenVo.getElectricityValueLastMonthUsage());
                    DecimalFormat def = new DecimalFormat("0.00");
                    String day4 = def.format(day2 - day3);
                    String week3 = def.format(week1 - week2);
                    String month3 = def.format(month1 - month2);
                    screen.setDayDifference(day4);
                    screen.setWeekDifference(week3);
                    screen.setMonthDifference(month3);
                    screen.setFarmId(31);
                    screen.setBuildName(envDevice.getUnitName());
                    screen.setDeviceCode(envDevice.getDeviceCode());
                    screen.setType(2);
                    screen.setFarmName("凤形养殖基地");
                }
                screenMapper.insert(screen);
            }

        }
    }
    /**
     * 获取上周开始时间和结束时间
     */
    public static JSONObject getLastWeekRange() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
        calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
        calendar.add(Calendar.DAY_OF_WEEK, -7);
        Date startTime = calendar.getTime();
        calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), 23, 59, 59);
        calendar.add(Calendar.DAY_OF_WEEK, 6);
        Date stopTime = calendar.getTime();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("startTime", startTime);
        jsonObject.put("stopTime", stopTime);
        return jsonObject;
    }

    /**
     * 获取上月开始时间和结束时间
     */
    public static JSONObject getLastMonthRange() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
        calendar.add(Calendar.MONTH, -1);
        calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
        Date startTime = calendar.getTime();
        calendar.add(Calendar.DAY_OF_WEEK, 7);
        calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
        //calendar.set(Calendar.HOUR_OF_DAY, 24);
        calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), 23, 59, 59);
        Date stopTime = calendar.getTime();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("startTime", startTime);
        jsonObject.put("stopTime", stopTime);
        return jsonObject;
    }

    /**
     * 获取昨天开始时间和结束时间
     */
    public static JSONObject getYesterdayRange() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.MILLISECOND, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.HOUR_OF_DAY, -24);
        Date startTime = calendar.getTime();
        calendar.set(Calendar.MILLISECOND, 0);
        calendar.set(Calendar.SECOND, 59);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        Date stopTime = calendar.getTime();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("startTime", startTime);
        jsonObject.put("stopTime", stopTime);
        return jsonObject;
    }
}
