测值查询

master
wany 2024-07-10 16:28:20 +08:00
parent 3a1f393d57
commit 20119ee039
10 changed files with 350 additions and 2 deletions

View File

@ -3,6 +3,9 @@ package com.gunshi.project.xyt.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gunshi.core.result.R;
import com.gunshi.project.xyt.entity.so.OsmoticQueryPageSo;
import com.gunshi.project.xyt.entity.so.OsmoticQuerySo;
import com.gunshi.project.xyt.entity.vo.OsmoticChartVo;
import com.gunshi.project.xyt.entity.vo.OsmoticStationVo;
import com.gunshi.project.xyt.model.OsmoticPressR;
import com.gunshi.project.xyt.service.OsmoticPressRService;
import com.gunshi.project.xyt.validate.markers.Insert;
@ -62,4 +65,16 @@ public class OsmoticPressRController {
return R.ok(service.queryPage(osmoticQueryPageSo));
}
@Operation(summary = "测值查询(数据表)")
@PostMapping("/query/value")
public R<List<OsmoticStationVo>> queryValue(@RequestBody OsmoticQuerySo osmoticQuerySo) {
return R.ok(service.queryValue(osmoticQuerySo));
}
@Operation(summary = "测值查询(多图单表)")
@PostMapping("/query/chart")
public R<List<OsmoticChartVo>> queryChart(@RequestBody OsmoticQuerySo osmoticQuerySo) {
return R.ok(service.queryChart(osmoticQuerySo));
}
}

View File

@ -0,0 +1,26 @@
package com.gunshi.project.xyt.entity.so;
import com.gunshi.db.dto.DateTimeRangeSo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
/**
* Description:
* Created by wanyan on 2024/3/19
*
* @author wanyan
* @version 1.0
*/
@Data
@Schema(description = "测值查询对象")
public class OsmoticQuerySo {
@Schema(description = "时间")
private DateTimeRangeSo dateTimeRangeSo;
@Schema(description = "测点编号")
private List<String> stationCodes;
}

View File

@ -0,0 +1,37 @@
package com.gunshi.project.xyt.entity.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.math.BigDecimal;
/**
*
* Created by wanyan on 2024/3/13
*
* @author wanyan
* @version 1.0
*/
@Data
public class OsmoticChartDetailVo {
/**
*
*/
@Schema(description="时间")
private String tm;
/**
*
*/
@Schema(description="库水位")
private BigDecimal rz;
/**
*
*/
@Schema(description="管水位")
private BigDecimal value;
}

View File

@ -0,0 +1,51 @@
package com.gunshi.project.xyt.entity.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.math.BigDecimal;
import java.util.List;
/**
* Description:
* Created by wanyan on 2024/7/9
*
* @author wanyan
* @version 1.0
*/
@Data
public class OsmoticChartVo {
/**
*
*/
@Schema(description="测点编号")
private String stationCode;
/**
*
*/
@Schema(description="最大值")
private BigDecimal maxValue;
/**
*
*/
@Schema(description="最大值时间")
private String maxTm;
/**
*
*/
@Schema(description="最小值")
private BigDecimal minValue;
/**
*
*/
@Schema(description="最小值时间")
private String minTm;
@Schema(description = "数据")
private List<OsmoticChartDetailVo> detailVos;
}

View File

@ -0,0 +1,20 @@
package com.gunshi.project.xyt.entity.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
/**
* Description:
* Created by wanyan on 2024/7/9
*
* @author wanyan
* @version 1.0
*/
@Data
public class OsmoticStationVo extends StRzVo{
@Schema(description="测值")
private List<OsmoticValueVo> list;
}

View File

@ -0,0 +1,36 @@
package com.gunshi.project.xyt.entity.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.math.BigDecimal;
/**
*
* Created by wanyan on 2024/3/13
*
* @author wanyan
* @version 1.0
*/
@Data
public class OsmoticValueVo {
/**
*
*/
@Schema(description="时间")
private String tm;
/**
*
*/
@Schema(description="测点编号")
private String stationCode;
/**
*
*/
@Schema(description="管水位")
private BigDecimal value;
}

View File

@ -0,0 +1,29 @@
package com.gunshi.project.xyt.entity.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.math.BigDecimal;
/**
*
* Created by wanyan on 2024/2/20
*
* @author wanyan
* @version 1.0
*/
@Data
public class StRzVo {
/**
*
*/
@Schema(description="时间")
private String tm;
/**
*
*/
@Schema(description="库水位")
private BigDecimal rz;
}

View File

@ -3,11 +3,16 @@ package com.gunshi.project.xyt.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gunshi.project.xyt.entity.so.OsmoticQueryPageSo;
import com.gunshi.project.xyt.entity.so.OsmoticQuerySo;
import com.gunshi.project.xyt.entity.vo.OsmoticValueVo;
import com.gunshi.project.xyt.entity.vo.StRzVo;
import com.gunshi.project.xyt.model.OsmoticPressR;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/**
* :
* author: xusan
@ -40,4 +45,40 @@ public interface OsmoticPressRMapper extends BaseMapper<OsmoticPressR> {
</script>
""")
Page<OsmoticPressR> queryPage(Page<OsmoticPressR> page,@Param("obj") OsmoticQueryPageSo osmoticQueryPageSo);
@Select("""
<script>
select to_char(t.tm,'YYYY-MM-DD') as tm,t.rz
from public.st_rsvr_r t
where to_char(t.tm, 'HH24:MI:SS') = '08:00:00'
<if test="obj.dateTimeRangeSo != null and obj.dateTimeRangeSo.start != null">
and t.tm <![CDATA[>=]]> #{obj.dateTimeRangeSo.start}
</if>
<if test="obj.dateTimeRangeSo != null and obj.dateTimeRangeSo.end != null">
and t.tm <![CDATA[<=]]> #{obj.dateTimeRangeSo.end}
</if>
order by t.tm desc
</script>
""")
List<StRzVo> queryRz(@Param("obj") OsmoticQuerySo osmoticQuerySo);
@Select("""
<script>
select t.station_code as stationCode,to_char(t.tm,'YYYY-MM-DD') as tm,t.value
from public.osmotic_press_r t
where to_char(t.tm, 'HH24:MI:SS') = '08:00:00' and station_code in
<foreach collection="obj.stationCodes" item="code" separator="," open="(" close=")">
#{code}
</foreach>
<if test="obj.dateTimeRangeSo != null and obj.dateTimeRangeSo.start != null">
and t.tm <![CDATA[>=]]> #{obj.dateTimeRangeSo.start}
</if>
<if test="obj.dateTimeRangeSo != null and obj.dateTimeRangeSo.end != null">
and t.tm <![CDATA[<=]]> #{obj.dateTimeRangeSo.end}
</if>
order by t.tm desc
</script>
""")
List<OsmoticValueVo> queryValue(@Param("obj") OsmoticQuerySo osmoticQuerySo);
}

View File

@ -3,13 +3,21 @@ package com.gunshi.project.xyt.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gunshi.project.xyt.entity.so.OsmoticQueryPageSo;
import com.gunshi.project.xyt.entity.so.OsmoticQuerySo;
import com.gunshi.project.xyt.entity.vo.*;
import com.gunshi.project.xyt.mapper.OsmoticPressRMapper;
import com.gunshi.project.xyt.model.OsmoticPressR;
import com.gunshi.project.xyt.util.DateUtil;
import com.gunshi.project.xyt.util.MyBeanUtil;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
/**
* :
* author: xusan
@ -26,6 +34,80 @@ public class OsmoticPressRService extends ServiceImpl<OsmoticPressRMapper, Osmot
public Page<OsmoticPressR> queryPage(OsmoticQueryPageSo osmoticQueryPageSo) {
return mapper.queryPage(osmoticQueryPageSo.getPageSo().toPage(),osmoticQueryPageSo);
}
/**
* 8
* @param osmoticQuerySo
* @return
*/
public List<OsmoticStationVo> queryValue(OsmoticQuerySo osmoticQuerySo) {
List<String> dateList = DateUtil.getDatesBetween(osmoticQuerySo.getDateTimeRangeSo().getStart(), osmoticQuerySo.getDateTimeRangeSo().getEnd());
List<OsmoticStationVo> resList = new ArrayList<>();
//查询库水位
List<StRzVo> list = mapper.queryRz(osmoticQuerySo);
Map<String, BigDecimal> rzMap = list.stream().collect(Collectors.toMap(StRzVo::getTm, StRzVo::getRz));
//查询测站管水位
List<OsmoticValueVo> valueList = mapper.queryValue(osmoticQuerySo);
//数据处理
for(String str : dateList){
OsmoticStationVo vo = new OsmoticStationVo();
vo.setTm(str);
vo.setRz(rzMap.get(str));
vo.setList(valueList.stream().filter(o->str.equals(o.getTm())).collect(Collectors.toList()));
resList.add(vo);
}
return resList;
}
public List<OsmoticChartVo> queryChart(OsmoticQuerySo osmoticQuerySo) {
List<OsmoticChartVo> resList = new ArrayList<>();
//查询库水位
List<StRzVo> list = mapper.queryRz(osmoticQuerySo);
//查询测站管水位
List<OsmoticValueVo> valueList = mapper.queryValue(osmoticQuerySo);
//按测站分组
Map<String, List<OsmoticValueVo>> map = valueList.stream().collect(Collectors.groupingBy(OsmoticValueVo::getStationCode));
map.entrySet().forEach(o->{
OsmoticChartVo vo = new OsmoticChartVo();
List<OsmoticValueVo> voList = o.getValue();
OsmoticValueVo max = voList.stream().max(Comparator.comparing(OsmoticValueVo::getValue)).get();
OsmoticValueVo min = voList.stream().min(Comparator.comparing(OsmoticValueVo::getValue)).get();
vo.setStationCode(o.getKey());
vo.setMaxValue(max.getValue());
vo.setMaxTm(max.getTm());
vo.setMinValue(min.getValue());
vo.setMinTm(min.getTm());
vo.setDetailVos(bindData(MyBeanUtil.collectionCopy(list,OsmoticChartDetailVo.class),MyBeanUtil.collectionCopy(voList,OsmoticChartDetailVo.class)));
resList.add(vo);
});
return resList;
}
//根据监测时间合并管水位和库水位数据
private List<OsmoticChartDetailVo> bindData(List<OsmoticChartDetailVo> tmRzList, List<OsmoticChartDetailVo> voList) {
HashSet<String> strings = new HashSet<>();
tmRzList.stream().forEach(v1 -> strings.add(v1.getTm()));
voList.stream().forEach(v1 -> strings.add(v1.getTm()));
List<OsmoticChartDetailVo> result = new ArrayList<>();
strings.stream().forEach(v1 ->{
OsmoticChartDetailVo v = new OsmoticChartDetailVo();
v.setTm(v1);
result.add(v);
});
List<OsmoticChartDetailVo> list = result.stream().map(v1 -> {
tmRzList.stream().filter(v2 -> v1.getTm().equals(v2.getTm())).forEach(v2 -> {
v1.setRz(v2.getRz());
});
voList.stream().filter(v2 -> v1.getTm().equals(v2.getTm())).forEach(v2 -> {
v1.setValue(v2.getValue());
});
return v1;
}).collect(Collectors.toList());
return list.stream().sorted(Comparator.comparing(OsmoticChartDetailVo::getTm)).collect(Collectors.toList());
}
}

View File

@ -6,8 +6,7 @@ import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Optional;
import java.util.*;
/**
* Description:
@ -142,5 +141,17 @@ public class DateUtil {
return now.format(ym);
}
public static List<String> getDatesBetween(Date startDate, Date endDate) {
List<String> dates = new ArrayList<>();
Calendar calendar = Calendar.getInstance();
calendar.setTime(startDate);
while (calendar.getTime().before(endDate)) {
dates.add(convertDateToString(calendar.getTime()));
calendar.add(Calendar.DATE, 1);
}
return dates.reversed();
}
}