package com.gyee.runeconomy.service; import cn.hutool.core.util.NumberUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.gyee.runeconomy.model.auto.ProEconWtAlysisDay; import com.gyee.runeconomy.model.auto.TurbineInfoDay; import com.gyee.runeconomy.service.auto.IProEconWtAlysisDayService; import com.gyee.runeconomy.service.auto.ITurbineInfoDayService; import com.gyee.runeconomy.util.StringUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.LocalDate; import java.time.ZoneId; import java.util.Calendar; import java.util.Date; import java.util.List; import java.util.Map; import java.util.function.Function; import java.util.stream.Collectors; @Service public class WtAlysisDayService { @Resource private IProEconWtAlysisDayService proEconWtAlysisDayService; @Resource private ITurbineInfoDayService turbineInfoDayService; public Page wtAlysisDayList(Integer pageNum, Integer pageSize, String wtId, String beginDate, String endDate) { if (StringUtils.empty(pageNum)) { pageNum = 1; } if (StringUtils.empty(pageSize)) { pageSize = 10; } //构造分页构造器 Page pageInfo = new Page<>(pageNum, pageSize); if (StringUtils.notEmp(wtId) && StringUtils.notEmp(beginDate) && StringUtils.notEmp(endDate)) { String format = "yyyy-MM-dd"; SimpleDateFormat df = new SimpleDateFormat(format); Date begin = null; Date end = null; try { begin = df.parse(beginDate); end = df.parse(endDate); } catch (ParseException e) { e.printStackTrace(); } //构造条件构造器 LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); //添加过滤条件 queryWrapper.eq(ProEconWtAlysisDay::getWindturbineId, wtId). ge(ProEconWtAlysisDay::getRecordDate, begin). le(ProEconWtAlysisDay::getRecordDate, end); queryWrapper.orderByAsc(ProEconWtAlysisDay::getRecordDate); //执行查询 proEconWtAlysisDayService.page(pageInfo, queryWrapper); QueryWrapper qw = new QueryWrapper<>(); qw.lambda().eq(TurbineInfoDay::getTurbineId, wtId).between(TurbineInfoDay::getRecordDate, begin, end) .orderByAsc(TurbineInfoDay::getRecordDate); IPage page01 = new Page<>(pageNum, pageSize); IPage page1 = turbineInfoDayService.page(page01, qw); Map dayMap = page1.getRecords().stream().collect(Collectors.toMap(TurbineInfoDay::getRecordDate, Function.identity())); pageInfo.getRecords().forEach(rsl -> { TurbineInfoDay day = dayMap.get(rsl.getRecordDate()); Calendar calendar = Calendar.getInstance(); rsl.setRfdl(NumberUtil.round(day.getRfdl() / 1000, 2).doubleValue()); double yfdl = calFdl(rsl.getWindturbineId(), "month", rsl.getRecordDate(), calendar); rsl.setYfdl(NumberUtil.round(yfdl / 1000, 2).doubleValue()); double nfdl = calFdl(rsl.getWindturbineId(), "year", rsl.getRecordDate(), calendar); rsl.setNfdl(NumberUtil.round(nfdl / 1000, 2).doubleValue()); rsl.setRpjfs(NumberUtil.round(day.getPjfs(), 2).doubleValue()); double ypjfs = calPjfs(rsl.getWindturbineId(), "month", rsl.getRecordDate(), calendar); rsl.setYpjfs(NumberUtil.round(ypjfs, 2).doubleValue()); double npjfs = calPjfs(rsl.getWindturbineId(), "year", rsl.getRecordDate(), calendar); rsl.setNpjfs(NumberUtil.round(npjfs, 2).doubleValue()); double v = day.getGzss() + day.getJhjxss() + day.getXdss() + day.getXnss() + day.getSlss(); rsl.setRssdl(NumberUtil.round(v / 1000, 2).doubleValue()); double yssdl = calSsdl(rsl.getWindturbineId(), "month", rsl.getRecordDate(), calendar); rsl.setYssdl(NumberUtil.round(yssdl / 1000, 2).doubleValue()); double nssdl = calSsdl(rsl.getWindturbineId(), "year", rsl.getRecordDate(), calendar); rsl.setNssdl(NumberUtil.round(nssdl / 1000, 2).doubleValue()); rsl.setRgzxs(NumberUtil.round(day.getGzMin() / 60, 2).doubleValue()); double ygzxs = calGzxs(rsl.getWindturbineId(), "month", rsl.getRecordDate(), calendar); rsl.setYgzxs(NumberUtil.round(ygzxs / 60, 2).doubleValue()); double ngzxs = calGzxs(rsl.getWindturbineId(), "year", rsl.getRecordDate(), calendar); rsl.setNgzxs(NumberUtil.round(ngzxs / 60, 2).doubleValue()); rsl.setRjxxs(NumberUtil.round(day.getJxMin() / 60, 2).doubleValue()); double yjxxs = calJxxs(rsl.getWindturbineId(), "month", rsl.getRecordDate(), calendar); rsl.setYjxxs(NumberUtil.round(yjxxs / 60, 2).doubleValue()); double njxxs = calJxxs(rsl.getWindturbineId(), "year", rsl.getRecordDate(), calendar); rsl.setNjxxs(NumberUtil.round(njxxs / 60, 2).doubleValue()); rsl.setRyxxs(NumberUtil.round(day.getYxMin() / 60, 2).doubleValue()); double yyxxs = calYxxs(rsl.getWindturbineId(), "month", rsl.getRecordDate(), calendar); rsl.setYyxxs(NumberUtil.round(yyxxs / 60, 2).doubleValue()); double nyxxs = calYxxs(rsl.getWindturbineId(), "year", rsl.getRecordDate(), calendar); rsl.setNyxxs(NumberUtil.round(nyxxs / 60, 2).doubleValue()); rsl.setRdjxs(NumberUtil.round(day.getDjMin() / 60, 2).doubleValue()); double ydjxs = calDjxs(rsl.getWindturbineId(), "month", rsl.getRecordDate(), calendar); rsl.setYdjxs(NumberUtil.round(ydjxs / 60, 2).doubleValue()); double ndjxs = calDjxs(rsl.getWindturbineId(), "year", rsl.getRecordDate(), calendar); rsl.setNdjxs(NumberUtil.round(ndjxs / 60, 2).doubleValue()); rsl.setRtjcs(NumberUtil.round(day.getTjcs(), 2).doubleValue()); double ytjcs = calTjcs(rsl.getWindturbineId(), "month", rsl.getRecordDate(), calendar); rsl.setYtjcs(NumberUtil.round(ytjcs, 2).doubleValue()); double ntjcs = calTjcs(rsl.getWindturbineId(), "year", rsl.getRecordDate(), calendar); rsl.setNtjcs(NumberUtil.round(ntjcs, 2).doubleValue()); rsl.setRsbklyl(NumberUtil.round(day.getKlyl(), 2).doubleValue()); double ysbklyl = calSbklyl(rsl.getWindturbineId(), "month", rsl.getRecordDate(), calendar); rsl.setYsbklyl(NumberUtil.round(ysbklyl, 2).doubleValue()); double nsbklyl = calSbklyl(rsl.getWindturbineId(), "year", rsl.getRecordDate(), calendar); rsl.setNsbklyl(NumberUtil.round(nsbklyl, 2).doubleValue()); rsl.setRpjwd(NumberUtil.round(day.getHjwd(), 2).doubleValue()); double ypjwd = calPjwd(rsl.getWindturbineId(), "month", rsl.getRecordDate(), calendar); rsl.setYpjwd(NumberUtil.round(ypjwd, 2).doubleValue()); double npjwd = calPjwd(rsl.getWindturbineId(), "year", rsl.getRecordDate(), calendar); rsl.setNpjwd(NumberUtil.round(npjwd, 2).doubleValue()); }); } return pageInfo; } public double calSsdl(String windturbineId, String type, Date endDate, Calendar calendar) { calendar.setTime(endDate); Date firstDay = null; if ("month".equals(type)) { calendar.set(Calendar.DAY_OF_MONTH, 1); firstDay = calendar.getTime(); } else if ("year".equals(type)) { calendar.set(Calendar.MONTH, 0); calendar.set(Calendar.DAY_OF_YEAR, 1); firstDay = calendar.getTime(); } QueryWrapper currentqw = new QueryWrapper<>(); currentqw.select("station_id,MAX(record_date) AS record_date,SUM(gzss) AS gzss,SUM(jhjxss) AS jhjxss,SUM(xdss) AS xdss,SUM(xnss) AS xnss,SUM(slss) AS slss") .ge("record_date", firstDay) .le("record_date", endDate) .eq("turbine_id", windturbineId) .like("station_id", "_FDC_") .groupBy("station_id"); List monthData = turbineInfoDayService.list(currentqw); TurbineInfoDay tur = monthData.get(0); return tur.getGzss() + tur.getJhjxss() + tur.getXnss() + tur.getSlss() + tur.getXdss(); } public double calPjwd(String windturbineId, String type, Date endDate, Calendar calendar) { calendar.setTime(endDate); Date firstDay = null; LocalDate localDate = endDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); int d = 0; if ("month".equals(type)) { calendar.set(Calendar.DAY_OF_MONTH, 1); firstDay = calendar.getTime(); d = localDate.getDayOfMonth(); } else if ("year".equals(type)) { calendar.set(Calendar.MONTH, 0); calendar.set(Calendar.DAY_OF_YEAR, 1); firstDay = calendar.getTime(); d = localDate.getDayOfYear(); } QueryWrapper currentqw = new QueryWrapper<>(); currentqw.select("station_id,MAX(record_date) AS record_date,SUM(hjwd) AS hjwd") .ge("record_date", firstDay) .le("record_date", endDate) .eq("turbine_id", windturbineId) .like("station_id", "_FDC_") .groupBy("station_id"); List monthData = turbineInfoDayService.list(currentqw); if (d != 0) { return monthData.get(0).getHjwd() / (d); } else { return monthData.get(0).getHjwd(); } } public double calSbklyl(String windturbineId, String type, Date endDate, Calendar calendar) { calendar.setTime(endDate); Date firstDay = null; LocalDate localDate = endDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); int d = 0; if ("month".equals(type)) { calendar.set(Calendar.DAY_OF_MONTH, 1); firstDay = calendar.getTime(); d = localDate.getDayOfMonth(); } else if ("year".equals(type)) { calendar.set(Calendar.MONTH, 0); calendar.set(Calendar.DAY_OF_YEAR, 1); firstDay = calendar.getTime(); d = localDate.getDayOfYear(); } QueryWrapper currentqw = new QueryWrapper<>(); currentqw.select("station_id,MAX(record_date) AS record_date,SUM(klyl) AS klyl") .ge("record_date", firstDay) .le("record_date", endDate) .eq("turbine_id", windturbineId) .like("station_id", "_FDC_") .groupBy("station_id"); List monthData = turbineInfoDayService.list(currentqw); if (d != 0) { return monthData.get(0).getKlyl() / (d); } else { return monthData.get(0).getKlyl(); } } public double calTjcs(String windturbineId, String type, Date endDate, Calendar calendar) { calendar.setTime(endDate); Date firstDay = null; if ("month".equals(type)) { calendar.set(Calendar.DAY_OF_MONTH, 1); firstDay = calendar.getTime(); } else if ("year".equals(type)) { calendar.set(Calendar.MONTH, 0); calendar.set(Calendar.DAY_OF_YEAR, 1); firstDay = calendar.getTime(); } QueryWrapper currentqw = new QueryWrapper<>(); currentqw.select("station_id,MAX(record_date) AS record_date,SUM(tjcs) AS tjcs") .ge("record_date", firstDay) .le("record_date", endDate) .eq("turbine_id", windturbineId) .like("station_id", "_FDC_") .groupBy("station_id"); List monthData = turbineInfoDayService.list(currentqw); return monthData.get(0).getTjcs(); } public double calDjxs(String windturbineId, String type, Date endDate, Calendar calendar) { calendar.setTime(endDate); Date firstDay = null; if ("month".equals(type)) { calendar.set(Calendar.DAY_OF_MONTH, 1); firstDay = calendar.getTime(); } else if ("year".equals(type)) { calendar.set(Calendar.MONTH, 0); calendar.set(Calendar.DAY_OF_YEAR, 1); firstDay = calendar.getTime(); } QueryWrapper currentqw = new QueryWrapper<>(); currentqw.select("station_id,MAX(record_date) AS record_date,SUM(dj_min) AS dj_min") .ge("record_date", firstDay) .le("record_date", endDate) .eq("turbine_id", windturbineId) .like("station_id", "_FDC_") .groupBy("station_id"); List monthData = turbineInfoDayService.list(currentqw); return monthData.get(0).getDjMin(); } public double calYxxs(String windturbineId, String type, Date endDate, Calendar calendar) { calendar.setTime(endDate); Date firstDay = null; if ("month".equals(type)) { calendar.set(Calendar.DAY_OF_MONTH, 1); firstDay = calendar.getTime(); } else if ("year".equals(type)) { calendar.set(Calendar.MONTH, 0); calendar.set(Calendar.DAY_OF_YEAR, 1); firstDay = calendar.getTime(); } QueryWrapper currentqw = new QueryWrapper<>(); currentqw.select("station_id,MAX(record_date) AS record_date,SUM(yx_min) AS yx_min") .ge("record_date", firstDay) .le("record_date", endDate) .eq("turbine_id", windturbineId) .like("station_id", "_FDC_") .groupBy("station_id"); List monthData = turbineInfoDayService.list(currentqw); return monthData.get(0).getYxMin(); } public double calJxxs(String windturbineId, String type, Date endDate, Calendar calendar) { calendar.setTime(endDate); Date firstDay = null; if ("month".equals(type)) { calendar.set(Calendar.DAY_OF_MONTH, 1); firstDay = calendar.getTime(); } else if ("year".equals(type)) { calendar.set(Calendar.MONTH, 0); calendar.set(Calendar.DAY_OF_YEAR, 1); firstDay = calendar.getTime(); } QueryWrapper currentqw = new QueryWrapper<>(); currentqw.select("station_id,MAX(record_date) AS record_date,SUM(jx_min) AS jx_min") .ge("record_date", firstDay) .le("record_date", endDate) .eq("turbine_id", windturbineId) .like("station_id", "_FDC_") .groupBy("station_id"); List monthData = turbineInfoDayService.list(currentqw); return monthData.get(0).getJxMin(); } public double calGzxs(String windturbineId, String type, Date endDate, Calendar calendar) { calendar.setTime(endDate); Date firstDay = null; if ("month".equals(type)) { calendar.set(Calendar.DAY_OF_MONTH, 1); firstDay = calendar.getTime(); } else if ("year".equals(type)) { calendar.set(Calendar.MONTH, 0); calendar.set(Calendar.DAY_OF_YEAR, 1); firstDay = calendar.getTime(); } QueryWrapper currentqw = new QueryWrapper<>(); currentqw.select("station_id,MAX(record_date) AS record_date,SUM(gz_min) AS gz_min") .ge("record_date", firstDay) .le("record_date", endDate) .eq("turbine_id", windturbineId) .like("station_id", "_FDC_") .groupBy("station_id"); List monthData = turbineInfoDayService.list(currentqw); return monthData.get(0).getGzMin(); } public double calPjfs(String windturbineId, String type, Date endDate, Calendar calendar) { calendar.setTime(endDate); Date firstDay = null; LocalDate localDate = endDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); int d = 0; if ("month".equals(type)) { calendar.set(Calendar.DAY_OF_MONTH, 1); firstDay = calendar.getTime(); d = localDate.getDayOfMonth(); } else if ("year".equals(type)) { calendar.set(Calendar.MONTH, 0); calendar.set(Calendar.DAY_OF_YEAR, 1); firstDay = calendar.getTime(); d = localDate.getDayOfYear(); } QueryWrapper currentqw = new QueryWrapper<>(); currentqw.select("station_id,MAX(record_date) AS record_date,SUM(pjfs) AS pjfs") .ge("record_date", firstDay) .le("record_date", endDate) .eq("turbine_id", windturbineId) .like("station_id", "_FDC_") .groupBy("station_id"); List monthData = turbineInfoDayService.list(currentqw); if (d != 0) { return monthData.get(0).getPjfs() / (d); } else { return monthData.get(0).getPjfs(); } } public double calFdl(String windturbineId, String type, Date endDate, Calendar calendar) { calendar.setTime(endDate); Date firstDay = null; if ("month".equals(type)) { calendar.set(Calendar.DAY_OF_MONTH, 1); firstDay = calendar.getTime(); } else if ("year".equals(type)) { calendar.set(Calendar.MONTH, 0); calendar.set(Calendar.DAY_OF_YEAR, 1); firstDay = calendar.getTime(); } QueryWrapper currentqw = new QueryWrapper<>(); currentqw.select("station_id,MAX(record_date) AS record_date,SUM(rfdl) AS rfdl") .ge("record_date", firstDay) .le("record_date", endDate) .eq("turbine_id", windturbineId) .like("station_id", "_FDC_") .groupBy("station_id"); List monthData = turbineInfoDayService.list(currentqw); return monthData.get(0).getRfdl(); } }