123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391 |
- 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<ProEconWtAlysisDay> wtAlysisDayList(Integer pageNum, Integer pageSize, String wtId, String beginDate, String endDate) {
- if (StringUtils.empty(pageNum)) {
- pageNum = 1;
- }
- if (StringUtils.empty(pageSize)) {
- pageSize = 10;
- }
- //构造分页构造器
- Page<ProEconWtAlysisDay> 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<ProEconWtAlysisDay> 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<TurbineInfoDay> qw = new QueryWrapper<>();
- qw.lambda().eq(TurbineInfoDay::getTurbineId, wtId).between(TurbineInfoDay::getRecordDate, begin, end)
- .orderByAsc(TurbineInfoDay::getRecordDate);
- IPage<TurbineInfoDay> page01 = new Page<>(pageNum, pageSize);
- IPage<TurbineInfoDay> page1 = turbineInfoDayService.page(page01, qw);
- Map<Date, TurbineInfoDay> 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<TurbineInfoDay> 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<TurbineInfoDay> 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<TurbineInfoDay> 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<TurbineInfoDay> 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<TurbineInfoDay> 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<TurbineInfoDay> 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<TurbineInfoDay> 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<TurbineInfoDay> 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<TurbineInfoDay> 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<TurbineInfoDay> 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<TurbineInfoDay> 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<TurbineInfoDay> 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<TurbineInfoDay> 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<TurbineInfoDay> 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<TurbineInfoDay> 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<TurbineInfoDay> 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<TurbineInfoDay> 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<TurbineInfoDay> 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<TurbineInfoDay> 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<TurbineInfoDay> monthData = turbineInfoDayService.list(currentqw);
- return monthData.get(0).getRfdl();
- }
- }
|