master
parent
1ff801dd33
commit
db3a093461
|
|
@ -78,6 +78,12 @@ public class ReservoirWaterController {
|
|||
return R.ok(reservoirWaterService.list());
|
||||
}
|
||||
|
||||
|
||||
@Post(path = "/listV2", summary = "水库水情列表")
|
||||
public R<List<AttResBaseVo>> listV2() {
|
||||
return R.ok(reservoirWaterService.listV2());
|
||||
}
|
||||
|
||||
@Get(path = "/image/channel", summary = "图像监测视角下拉")
|
||||
public R<List<StStbprpB>> channel(@Schema(name = "resCode") @RequestParam("resCode") String resCode) {
|
||||
return R.ok(reservoirWaterService.channel(resCode));
|
||||
|
|
|
|||
|
|
@ -3,24 +3,29 @@ package com.gunshi.project.xyt.controller;
|
|||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
||||
import com.gunshi.core.annotation.Post;
|
||||
import com.gunshi.core.result.R;
|
||||
import com.gunshi.project.xyt.entity.dto.StZqrlBDto;
|
||||
import com.gunshi.project.xyt.entity.vo.StZqrlBCount24Vo;
|
||||
import com.gunshi.project.xyt.entity.vo.StZqrlBCountVo;
|
||||
import com.gunshi.project.xyt.entity.vo.StZqrlBVo;
|
||||
import com.gunshi.project.xyt.model.AttResBase;
|
||||
import com.gunshi.project.xyt.model.StZqrlB;
|
||||
import com.gunshi.project.xyt.service.AttResBaseService;
|
||||
import com.gunshi.project.xyt.service.StStbprpBService;
|
||||
import com.gunshi.project.xyt.service.StZqrlBService;
|
||||
import com.gunshi.project.xyt.service.StZvarlBService;
|
||||
import com.gunshi.project.xyt.validate.markers.Delete;
|
||||
import com.gunshi.project.xyt.validate.markers.Insert;
|
||||
import com.gunshi.project.xyt.validate.markers.Update;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
|
@ -44,6 +49,27 @@ public class StZqrlBController {
|
|||
@Autowired
|
||||
private StStbprpBService stStbprpBService;
|
||||
|
||||
@Autowired
|
||||
private StZvarlBService stZvarlBService;
|
||||
|
||||
|
||||
@Post(path = "/flowList", summary = "集合")
|
||||
public R<List<StZqrlBVo>> flowList(@RequestBody StZqrlBDto obj) {
|
||||
return R.ok(stStbprpBService.flowList(obj));
|
||||
}
|
||||
|
||||
@GetMapping(path = "/count/{stcd}")
|
||||
public R<StZqrlBCountVo> count(@Schema(name = "stcd") @PathVariable("stcd") Serializable stcd) {
|
||||
return R.ok(stStbprpBService.count(stcd));
|
||||
}
|
||||
|
||||
|
||||
@GetMapping(path = "/count24/{stcd}")
|
||||
public R<StZqrlBCount24Vo> count24(@Schema(name = "stcd") @PathVariable("stcd") Serializable stcd) {
|
||||
return R.ok(stStbprpBService.count24(stcd));
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "新增")
|
||||
@PostMapping("/insert")
|
||||
public R<StZqrlB> insert(@Validated(Insert.class) @RequestBody StZqrlB dto) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
package com.gunshi.project.xyt.entity.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.gunshi.db.dto.DateRangeSo;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 用户启停参数
|
||||
* Created by wanyan on 2024/1/22
|
||||
*
|
||||
* @author wanyan
|
||||
* @version 1.0
|
||||
*/
|
||||
@Data
|
||||
public class StZqrlBDto {
|
||||
|
||||
private String stcd;
|
||||
|
||||
@Schema(description = "时间范围")
|
||||
private DateRangeSo dateSo;
|
||||
|
||||
}
|
||||
|
|
@ -1,11 +1,14 @@
|
|||
package com.gunshi.project.xyt.entity.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.gunshi.core.dateformat.DateFormatString;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -20,6 +23,9 @@ public class SoilMoistureVO {
|
|||
|
||||
private BigDecimal currVal;
|
||||
|
||||
@JsonFormat(pattern = DateFormatString.YYYY_MM_DD_HH_MM_SS, timezone = "GMT+8")
|
||||
private Date createTime;
|
||||
|
||||
private BigDecimal nearWeekVal;
|
||||
|
||||
private BigDecimal nearMonthVal;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
package com.gunshi.project.xyt.entity.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.gunshi.core.dateformat.DateFormatString;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author xusan
|
||||
* @Date 2023/7/4 10:28
|
||||
* @Notes
|
||||
**/
|
||||
@Data
|
||||
public class StZqrlBCount24Vo {
|
||||
private String stcd;
|
||||
|
||||
private BigDecimal currWaterLevel;
|
||||
|
||||
private BigDecimal flowNum;
|
||||
|
||||
@JsonFormat(pattern = DateFormatString.YYYY_MM_DD_HH_MM_SS, timezone = "GMT+8")
|
||||
private Date createTime;
|
||||
|
||||
private BigDecimal sum24;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package com.gunshi.project.xyt.entity.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.gunshi.core.dateformat.DateFormatString;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author xusan
|
||||
* @Date 2023/7/4 10:28
|
||||
* @Notes
|
||||
**/
|
||||
@Data
|
||||
public class StZqrlBCountVo {
|
||||
private String stcd;
|
||||
|
||||
private BigDecimal val;
|
||||
|
||||
private BigDecimal currDayValSum;
|
||||
|
||||
@JsonFormat(pattern = DateFormatString.YYYY_MM_DD_HH_MM_SS, timezone = "GMT+8")
|
||||
private Date createTime;
|
||||
|
||||
private BigDecimal currMonthSum;
|
||||
|
||||
private BigDecimal currYearSum;
|
||||
|
||||
private Long currYearCount;
|
||||
|
||||
private BigDecimal currYearMaxVal;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
package com.gunshi.project.xyt.entity.vo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.gunshi.core.dateformat.DateFormatString;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author xusan
|
||||
* @Date 2023/7/4 10:28
|
||||
* @Notes
|
||||
**/
|
||||
@Data
|
||||
public class StZqrlBVo {
|
||||
|
||||
private String stcd;
|
||||
|
||||
@JsonFormat(pattern = DateFormatString.YYYY_MM_DD_HH_MM_SS, timezone = "GMT+8")
|
||||
private Date tm;
|
||||
|
||||
private BigDecimal waterLevel;
|
||||
|
||||
private BigDecimal flowNum;
|
||||
|
||||
private BigDecimal boxNum;
|
||||
|
||||
|
||||
@Schema(description="流量和")
|
||||
@TableField(exist = false)
|
||||
private BigDecimal qtotal;
|
||||
|
||||
public LocalDateTime getModitimeAsLocalDateTime() {
|
||||
if (tm == null) {
|
||||
return null;
|
||||
}
|
||||
return tm.toInstant()
|
||||
.atZone(ZoneId.systemDefault())
|
||||
.toLocalDateTime();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -43,6 +43,25 @@ public interface AttResBaseMapper extends BaseMapper<AttResBase> {
|
|||
""")
|
||||
List<AttResBaseVo> queryList();
|
||||
|
||||
@Select("""
|
||||
<script>
|
||||
select t.stcd,t.stnm,COALESCE(t.clgtd,t.lgtd) lgtd,COALESCE(t.clttd,t.lttd) lttd,t.source,t.sttp,t.stlc,t.adcd,t.esstym,s.res_code,s.fl_low_lim_lev,
|
||||
s.tot_cap,s.ben_res_cap,s.norm_wat_lev,s.crest_elev,s.des_flood_lev,s.dead_lev,s.cal_flood_lev,s.wat_shed_area,s.dead_cap,sad.adnm,
|
||||
m.tm,m.rz,(m.rz-s.fl_low_lim_lev) as aFsltdz,sprr.tm as drpTm,sprr.h1,sprr.h3,sprr.h6,sprr.h12,sprr.h24,sprr.today,
|
||||
case when s.cal_flood_lev is not null and m.rz-s.cal_flood_lev > 0 then 1 else 0 end as calState,
|
||||
case when s.des_flood_lev is not null and m.rz-s.des_flood_lev > 0 then 1 else 0 end as desState,
|
||||
case when s.fl_low_lim_lev is not null and m.rz-s.fl_low_lim_lev > 0 then 1 else 0 end as flState
|
||||
from public.st_stbprp_b t
|
||||
left join public.att_res_base s on t.stcd = s.stcd
|
||||
left join public.st_addvcd_d sad on t.adcd = sad.adcd
|
||||
left join public.st_rsvr_r_real m on t.stcd = m.stcd
|
||||
left join public.st_pptn_r_real sprr on t.stcd = sprr.stcd
|
||||
where t.sttp = 'RR' and s.res_code in('42120250085','42120250086')
|
||||
order by aFsltdz desc nulls last
|
||||
</script>
|
||||
""")
|
||||
List<AttResBaseVo> queryListV2();
|
||||
|
||||
@Select("""
|
||||
<script>
|
||||
select t.stcd,t.tm,t.drp from public.st_pptn_r t
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
package com.gunshi.project.xyt.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.gunshi.project.xyt.entity.dto.StZqrlBDto;
|
||||
import com.gunshi.project.xyt.entity.so.HomeStStbprpBSo;
|
||||
import com.gunshi.project.xyt.entity.vo.HomeStStbprpBVo;
|
||||
import com.gunshi.project.xyt.entity.vo.StStatusVo;
|
||||
import com.gunshi.project.xyt.entity.vo.StZqrlBVo;
|
||||
import com.gunshi.project.xyt.model.StStbprpB;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
|
@ -84,4 +86,22 @@ public interface StStbprpBMapper extends BaseMapper<StStbprpB> {
|
|||
</script>
|
||||
""")
|
||||
List<StStatusVo> rainList();
|
||||
|
||||
@Select("<script>" +
|
||||
"SELECT a.stcd AS stcd, a.moditime AS tm, a.z AS waterLevel, " +
|
||||
"a.q AS flowNum, b.w AS boxNum " +
|
||||
"FROM st_zqrl_b a " +
|
||||
"LEFT JOIN st_zvarl_b b ON a.z = b.rz " +
|
||||
"WHERE 1=1 " +
|
||||
"<if test='obj.stcd != null'> " +
|
||||
"AND a.stcd = #{obj.stcd} " +
|
||||
"</if> " +
|
||||
"<if test='obj.dateSo != null and obj.dateSo.start != null'> " +
|
||||
" AND a.moditime >= #{obj.dateSo.start} " +
|
||||
"</if> " +
|
||||
"<if test='obj.dateSo != null and obj.dateSo.end != null'> " +
|
||||
" AND a.moditime <= #{obj.dateSo.end} " +
|
||||
"</if>" +
|
||||
"</script>")
|
||||
List<StZqrlBVo> flowList(@Param("obj") StZqrlBDto obj);
|
||||
}
|
||||
|
|
@ -20,6 +20,8 @@ import lombok.Data;
|
|||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
|
|
@ -115,4 +117,18 @@ public class StZqrlB implements Serializable {
|
|||
@Schema(description="水库代码")
|
||||
@TableField(exist = false)
|
||||
private String resCode;
|
||||
|
||||
@Schema(description="流量和")
|
||||
@TableField(exist = false)
|
||||
private BigDecimal qtotal;
|
||||
|
||||
// 新增方法获取LocalDateTime
|
||||
public LocalDateTime getModitimeAsLocalDateTime() {
|
||||
if (moditime == null) {
|
||||
return null;
|
||||
}
|
||||
return moditime.toInstant()
|
||||
.atZone(ZoneId.systemDefault())
|
||||
.toLocalDateTime();
|
||||
}
|
||||
}
|
||||
|
|
@ -80,6 +80,43 @@ public class ReservoirWaterService {
|
|||
return attResBaseVos;
|
||||
}
|
||||
|
||||
|
||||
public List<AttResBaseVo> listV2() {
|
||||
List<AttResBaseVo> attResBaseVos = attResBaseMapper.queryListV2();
|
||||
if(CollectionUtils.isEmpty(attResBaseVos)){
|
||||
return attResBaseVos;
|
||||
}
|
||||
attResBaseVos.stream().map(o->{
|
||||
if(o.getCalState() == 1){
|
||||
o.setDesState(0);
|
||||
o.setFlState(0);
|
||||
}else if(o.getCalState() == 0 && o.getDesState() ==1){
|
||||
o.setFlState(0);
|
||||
}
|
||||
return o;
|
||||
}).collect(Collectors.toList());
|
||||
//查询所有测站的库容曲线
|
||||
List<StZvarlB> zvarlList = queryZval(attResBaseVos.stream().map(AttResBaseVo::getStcd).collect(Collectors.toList()));
|
||||
Map<String, List<StZvarlB>> zvalMap = zvarlList.stream().collect(Collectors.groupingBy(StZvarlB::getStcd));
|
||||
for(AttResBaseVo vo : attResBaseVos){
|
||||
String stcd = vo.getStcd();
|
||||
BigDecimal rz = vo.getRz();
|
||||
//计算当前库容
|
||||
List<StZvarlB> zvarlBS = zvalMap.get(stcd);
|
||||
if(rz != null && CollectionUtils.isNotEmpty(zvarlBS)){
|
||||
BigDecimal maxRz = zvarlBS.stream().max(Comparator.comparing(StZvarlB::getRz)).get().getRz();
|
||||
BigDecimal minRz = zvarlBS.stream().min(Comparator.comparing(StZvarlB::getRz)).get().getRz();
|
||||
if(rz.compareTo(minRz) < 0 || rz.compareTo(maxRz) > 0){
|
||||
continue;
|
||||
}
|
||||
Map<BigDecimal, BigDecimal> stZvalMap = zvarlBS.stream().collect(Collectors.toMap(StZvarlB::getRz, StZvarlB::getW));
|
||||
List<BigDecimal> list = zvarlBS.stream().map(StZvarlB::getRz).sorted().collect(Collectors.toList());
|
||||
vo.setNowCap(DataHandleUtil.calcData(rz,stZvalMap,list));
|
||||
}
|
||||
}
|
||||
return attResBaseVos;
|
||||
}
|
||||
|
||||
private List<StZvarlB> queryZval(List<String> stcdList) {
|
||||
LambdaQueryWrapper<StZvarlB> queryWrapper = Wrappers.lambdaQuery();
|
||||
queryWrapper.in(StZvarlB::getStcd, stcdList);
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ public class SoilMoistureDataService extends ServiceImpl<SoilMoistureDataMapper,
|
|||
LambdaQueryWrapper<SoilMoistureData> qw = new LambdaQueryWrapper();
|
||||
qw.eq(SoilMoistureData::getStcd,stcd).orderByDesc(SoilMoistureData::getCreateTime).last(" limit 1");
|
||||
SoilMoistureData max = baseMapper.selectOne(qw);
|
||||
vo.setCreateTime(max.getCreateTime());
|
||||
vo.setCurrVal(Objects.nonNull(max)? max.getVal(): null);
|
||||
|
||||
max = findMaxByRang(today, today.minusWeeks(1), stcd);
|
||||
|
|
|
|||
|
|
@ -1,23 +1,30 @@
|
|||
package com.gunshi.project.xyt.service;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.gunshi.project.xyt.entity.dto.StZqrlBDto;
|
||||
import com.gunshi.project.xyt.entity.so.HomeStStbprpBSo;
|
||||
import com.gunshi.project.xyt.entity.vo.*;
|
||||
import com.gunshi.project.xyt.mapper.OsmoticPressRMapper;
|
||||
import com.gunshi.project.xyt.mapper.OsmoticShiftRMapper;
|
||||
import com.gunshi.project.xyt.mapper.StStbprpBMapper;
|
||||
import com.gunshi.project.xyt.model.StStbprpB;
|
||||
import com.gunshi.project.xyt.model.StZqrlB;
|
||||
import com.gunshi.project.xyt.util.DateUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
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.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
|
@ -36,6 +43,9 @@ public class StStbprpBService extends ServiceImpl<StStbprpBMapper, StStbprpB>
|
|||
@Resource
|
||||
private OsmoticShiftRMapper shiftRMapper;
|
||||
|
||||
@Autowired
|
||||
private StZqrlBService stZqrlBService;
|
||||
|
||||
|
||||
public List<HomeStStbprpBVo> rainfallStationDetailsList(HomeStStbprpBSo dto) {
|
||||
return baseMapper.rainfallStationDetailsList(dto);
|
||||
|
|
@ -113,6 +123,163 @@ public class StStbprpBService extends ServiceImpl<StStbprpBMapper, StStbprpB>
|
|||
public List<StStatusVo> rainList() {
|
||||
return this.baseMapper.rainList();
|
||||
}
|
||||
|
||||
public List<StZqrlBVo> flowList(StZqrlBDto obj){
|
||||
List<StZqrlBVo> stZqrlBVos = baseMapper.flowList(obj);
|
||||
BigDecimal runningSum = BigDecimal.ZERO;
|
||||
|
||||
for (StZqrlBVo current : stZqrlBVos) {
|
||||
// 将当前记录的flowNum加到累计和中
|
||||
if (current.getFlowNum() != null) {
|
||||
runningSum = runningSum.add(current.getFlowNum());
|
||||
}
|
||||
// 设置当前记录的qtotal为之前所有flowNum的和
|
||||
current.setQtotal(runningSum);
|
||||
}
|
||||
return stZqrlBVos;
|
||||
}
|
||||
|
||||
public StZqrlBCountVo count(Serializable stcd) {
|
||||
StZqrlBCountVo vo = new StZqrlBCountVo();
|
||||
vo.setStcd(stcd.toString());
|
||||
if(Objects.isNull(stcd)){
|
||||
return vo;
|
||||
}
|
||||
String stcdstr = stcd.toString();
|
||||
|
||||
LambdaQueryWrapper<StZqrlB> qw = new LambdaQueryWrapper();
|
||||
qw.eq(StZqrlB::getStcd,stcdstr).orderByDesc(StZqrlB::getModitime).last(" limit 1");
|
||||
StZqrlB bean = stZqrlBService.getOne(qw);
|
||||
vo.setVal(bean.getQ());
|
||||
vo.setCreateTime(bean.getModitime());
|
||||
|
||||
// 获取今天开始时间 (00:00:00)
|
||||
LocalDateTime todayStart = LocalDate.now().atStartOfDay();
|
||||
// 获取当前时间 (带时分秒)
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
vo.setCurrDayValSum(sumVal(stcdstr,todayStart,now));
|
||||
|
||||
// 获取本月1号0点
|
||||
LocalDateTime firstDayOfMonth = LocalDate.now().withDayOfMonth(1).atStartOfDay();
|
||||
vo.setCurrMonthSum(sumVal(stcdstr,firstDayOfMonth,now));
|
||||
|
||||
// 获取本年第一天 00:00:00
|
||||
LocalDateTime firstDayOfYear = LocalDate.now().withDayOfYear(1).atStartOfDay();
|
||||
vo.setCurrYearSum(sumVal(stcdstr,firstDayOfYear,now));
|
||||
|
||||
//年次数
|
||||
vo.setCurrYearCount(countVal(stcdstr,firstDayOfYear,now));
|
||||
|
||||
//本年最大
|
||||
vo.setCurrYearMaxVal(maxVal(stcdstr,firstDayOfYear,now));
|
||||
|
||||
return vo;
|
||||
}
|
||||
|
||||
public StZqrlBCount24Vo count24(Serializable stcd) {
|
||||
StZqrlBCount24Vo vo = new StZqrlBCount24Vo();
|
||||
vo.setStcd(stcd.toString());
|
||||
String stcdstr = stcd.toString();
|
||||
|
||||
// LambdaQueryWrapper<StZqrlB> qw = new LambdaQueryWrapper();
|
||||
// qw.eq(StZqrlB::getStcd,stcdstr).orderByDesc(StZqrlB::getModitime).last(" limit 1");
|
||||
// StZqrlB bean = stZqrlBService.getOne(qw);
|
||||
// vo.setCurrWaterLevel(bean.getZ());
|
||||
// vo.setFlowNum(bean.getQ());
|
||||
// vo.setCreateTime(bean.getModitime());
|
||||
|
||||
//24小时溢洪量
|
||||
// 获取当前时间
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
// 获取24小时前的时间
|
||||
LocalDateTime before24 = now.minusHours(24);
|
||||
List<StZqrlB> list = getList(stcdstr, before24, now);
|
||||
if(CollectionUtil.isEmpty(list)){
|
||||
return vo;
|
||||
}
|
||||
StZqrlB stZqrlB = list.stream()
|
||||
.max(Comparator.comparing(StZqrlB::getModitimeAsLocalDateTime))
|
||||
.orElse(new StZqrlB());
|
||||
vo.setCurrWaterLevel(stZqrlB.getZ());
|
||||
vo.setFlowNum(stZqrlB.getQ());
|
||||
vo.setCreateTime(stZqrlB.getModitime());
|
||||
|
||||
|
||||
list = calculateQtotal(list);
|
||||
BigDecimal reduce = list.stream().map(StZqrlB::getQ).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
vo.setSum24(reduce);
|
||||
return vo;
|
||||
}
|
||||
|
||||
public List<StZqrlB> calculateQtotal(List<StZqrlB> list) {
|
||||
if (list == null || list.size() < 2) {
|
||||
return list;
|
||||
}
|
||||
|
||||
// 第一条数据设为0或null
|
||||
list.get(0).setQtotal(BigDecimal.ZERO);
|
||||
|
||||
for (int i = 1; i < list.size(); i++) {
|
||||
StZqrlB current = list.get(i);
|
||||
StZqrlB previous = list.get(i - 1);
|
||||
|
||||
// 使用Duration计算分钟差(精确到小数)
|
||||
Duration duration = Duration.between(previous.getModitimeAsLocalDateTime(), current.getModitimeAsLocalDateTime());
|
||||
double minutesDiff = duration.toMillis() / 60000.0; // 毫秒转分钟
|
||||
|
||||
// 使用BigDecimal的valueOf方法,避免new BigDecimal(double)的精度问题
|
||||
BigDecimal minutesDecimal = BigDecimal.valueOf(minutesDiff);
|
||||
|
||||
// 计算并设置qtotal
|
||||
current.setQtotal(current.getQ().multiply(minutesDecimal));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private List<StZqrlB> getList(String stcd, LocalDateTime start, LocalDateTime end){
|
||||
LambdaQueryWrapper<StZqrlB> qw = new LambdaQueryWrapper();
|
||||
qw.eq(StZqrlB::getStcd, stcd);
|
||||
qw.ge(StZqrlB::getModitime,start);
|
||||
qw.le(StZqrlB::getModitime,end);
|
||||
List<StZqrlB> list = stZqrlBService.list(qw);
|
||||
return list;
|
||||
}
|
||||
|
||||
private BigDecimal sumVal(String stcd, LocalDateTime start, LocalDateTime end){
|
||||
LambdaQueryWrapper<StZqrlB> qw = new LambdaQueryWrapper();
|
||||
qw.eq(StZqrlB::getStcd, stcd);
|
||||
qw.ge(StZqrlB::getModitime,start);
|
||||
qw.le(StZqrlB::getModitime,end);
|
||||
List<StZqrlB> list = stZqrlBService.list(qw);
|
||||
if(CollectionUtil.isNotEmpty(list)){
|
||||
return list.stream().map(StZqrlB::getQ).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private Long countVal(String stcd, LocalDateTime start, LocalDateTime end){
|
||||
LambdaQueryWrapper<StZqrlB> qw = new LambdaQueryWrapper();
|
||||
qw.eq(StZqrlB::getStcd, stcd);
|
||||
qw.ge(StZqrlB::getModitime,start);
|
||||
qw.le(StZqrlB::getModitime,end);
|
||||
List<StZqrlB> list = stZqrlBService.list(qw);
|
||||
if(CollectionUtil.isNotEmpty(list)){
|
||||
return list.stream().map(StZqrlB::getQ).filter(Objects::nonNull).filter(q -> q.compareTo(BigDecimal.ZERO) > 0).count();
|
||||
}
|
||||
return 0l;
|
||||
}
|
||||
|
||||
private BigDecimal maxVal(String stcd, LocalDateTime start, LocalDateTime end){
|
||||
LambdaQueryWrapper<StZqrlB> qw = new LambdaQueryWrapper();
|
||||
qw.eq(StZqrlB::getStcd, stcd);
|
||||
qw.ge(StZqrlB::getModitime,start);
|
||||
qw.le(StZqrlB::getModitime,end);
|
||||
List<StZqrlB> list = stZqrlBService.list(qw);
|
||||
if(CollectionUtil.isNotEmpty(list)){
|
||||
return list.stream().map(StZqrlB::getQ).filter(Objects::nonNull).max(Comparator.naturalOrder()).orElse(null);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue