package com.gunshi.project.ss.service; import com.gunshi.project.ss.common.mapper.StPptnRRealMapper; import com.gunshi.project.ss.common.model.StFlowR; import com.gunshi.project.ss.common.model.StPptnRReal; import com.gunshi.project.ss.common.model.StRsvrR; import com.gunshi.project.ss.common.model.StStbprpB; import com.gunshi.project.ss.common.util.LocalDateTimeConverter; import com.gunshi.project.ss.entity.vo.AttResBaseVo; import com.gunshi.project.ss.entity.vo.ScreenRealFlowVo; import com.gunshi.project.ss.entity.vo.ScreenRealPptnVo; import com.gunshi.project.ss.entity.vo.ScreenRsvrVo; import com.gunshi.project.ss.mapper.RealRainMapper; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; import java.time.LocalDateTime; import java.time.ZoneId; import java.util.ArrayList; import java.util.Date; import java.util.List; @Service @Slf4j public class ScreenMoniotrService { @Autowired private StStbprpBService stStbprpBService; @Autowired private AttResBaseService attResBaseService; @Autowired private ReservoirWaterService reservoirWaterService; @Autowired private StRsvrRService stRsvrRService; public List getScreenRsvr() { //查询所有的水库水情站点 List res = new ArrayList<>(); List attResBaseVos = reservoirWaterService.listV2(); for (AttResBaseVo rsvrStation : attResBaseVos) { ScreenRsvrVo entity = new ScreenRsvrVo(); entity.setStcd(rsvrStation.getStcd()); entity.setStnm(rsvrStation.getStnm()); entity.setLgtd(rsvrStation.getLgtd()); entity.setLttd(rsvrStation.getLttd()); BigDecimal rz = rsvrStation.getRz(); entity.setRz(rz); BigDecimal nowCap = rsvrStation.getNowCap(); BigDecimal deadCap = rsvrStation.getDeadCap(); entity.setNowCap(rsvrStation.getNowCap()); if(nowCap != null && deadCap != null){ entity.setEffectiveCap(nowCap.subtract(deadCap)); } BigDecimal flLowLimLev = rsvrStation.getFlLowLimLev(); entity.setFlLowLimLev(rsvrStation.getFlLowLimLev()); if(rz != null && flLowLimLev != null){ entity.setGapFlLowLimLev(rz.subtract(flLowLimLev)); } Date tm = rsvrStation.getTm(); if(tm == null){ entity.setStatus(0); }else{ StRsvrR one = stRsvrRService.lambdaQuery() .eq(StRsvrR::getStcd, rsvrStation.getStcd()) .lt(StRsvrR::getTm, tm).orderByDesc(StRsvrR::getTm) .last("limit 1").one(); if(one == null){ entity.setStatus(0); }else{ entity.setTm(LocalDateTimeConverter.fromDate(one.getTm())); //如果过去时刻水位高于当前水位 ->表示下降 String lastRz = one.getRz(); BigDecimal decimalRz = new BigDecimal(lastRz); if(rz.compareTo(decimalRz) < 0){ entity.setStatus(2); }else if(rz.compareTo(decimalRz) > 0){ entity.setStatus(1); }else{ entity.setStatus(0); } } } res.add(entity); } return res; } @Autowired private RealRainMapper realRainMapper; @Autowired private RainBasinDivisionService rainBasinDivisionService; public List gerRealPptn() { List pptnStations = stStbprpBService.getPptnStations(); List res = new ArrayList<>(); for (StStbprpB pptnStation : pptnStations) { ScreenRealPptnVo vo = new ScreenRealPptnVo(); vo.setStcd(pptnStation.getStcd()); vo.setStnm(pptnStation.getStnm()); StPptnRReal stPptnRReal = realRainMapper.queryPptnByStcd(vo.getStcd()); if(stPptnRReal != null){ Date tm = stPptnRReal.getTm(); LocalDateTime nowTime = LocalDateTime.now(); LocalDateTime latestTime = LocalDateTime.ofInstant(tm.toInstant(), ZoneId.systemDefault()); boolean isToday = latestTime.toLocalDate().equals(nowTime.toLocalDate()); if(isToday){ Date date = new Date(); //今日雨量 BigDecimal todayDrp = rainBasinDivisionService.queryTodayDrpByStcdAndTime(vo.getStcd(), date); vo.setTodayDrp(todayDrp); //昨日雨量 BigDecimal yesterdayDrp = rainBasinDivisionService.queryYesterdayDrpByStcdAndTime(vo.getStcd(), date); vo.setYesterdayDrp(yesterdayDrp); //24h雨量 BigDecimal drp24 = rainBasinDivisionService.queryLast24HoursDrpByStcdAndTime(vo.getStcd(),date); vo.setDrp24(drp24); //48h雨量 BigDecimal drp48 = rainBasinDivisionService.queryLast48HoursDrpByStcdAndTime(vo.getStcd(),date); vo.setDrp48(drp48); //72h雨量 BigDecimal drp72 = rainBasinDivisionService.queryLast72HoursDrpByStcdAndTime(vo.getStcd(),date); vo.setDrp72(drp72); } } res.add(vo); } return res; } @Autowired private StFlowRService stFlowRService; public List getRealFlow() { List res = new ArrayList<>(); List flowStations = stStbprpBService.getFlowStations(); for (StStbprpB flowStation : flowStations) { ScreenRealFlowVo vo = new ScreenRealFlowVo(); vo.setStcd(flowStation.getStcd()); vo.setStnm(flowStation.getStnm()); StFlowR newDataByStcd = stFlowRService.getNewDataByStcd(flowStation.getStcd()); if(newDataByStcd != null){ vo.setQ(newDataByStcd.getQ()); vo.setTm(newDataByStcd.getTm()); } res.add(vo); } return res; } }