diff --git a/src/main/java/com/gunshi/project/xyt/controller/OsmoticPressRController.java b/src/main/java/com/gunshi/project/xyt/controller/OsmoticPressRController.java index d8fd09d..f0b7cb4 100644 --- a/src/main/java/com/gunshi/project/xyt/controller/OsmoticPressRController.java +++ b/src/main/java/com/gunshi/project/xyt/controller/OsmoticPressRController.java @@ -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> queryValue(@RequestBody OsmoticQuerySo osmoticQuerySo) { + return R.ok(service.queryValue(osmoticQuerySo)); + } + + @Operation(summary = "测值查询(多图单表)") + @PostMapping("/query/chart") + public R> queryChart(@RequestBody OsmoticQuerySo osmoticQuerySo) { + return R.ok(service.queryChart(osmoticQuerySo)); + } + } \ No newline at end of file diff --git a/src/main/java/com/gunshi/project/xyt/entity/so/OsmoticQuerySo.java b/src/main/java/com/gunshi/project/xyt/entity/so/OsmoticQuerySo.java new file mode 100644 index 0000000..aa7574c --- /dev/null +++ b/src/main/java/com/gunshi/project/xyt/entity/so/OsmoticQuerySo.java @@ -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 stationCodes; +} diff --git a/src/main/java/com/gunshi/project/xyt/entity/vo/OsmoticChartDetailVo.java b/src/main/java/com/gunshi/project/xyt/entity/vo/OsmoticChartDetailVo.java new file mode 100644 index 0000000..a5b5587 --- /dev/null +++ b/src/main/java/com/gunshi/project/xyt/entity/vo/OsmoticChartDetailVo.java @@ -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; + +} diff --git a/src/main/java/com/gunshi/project/xyt/entity/vo/OsmoticChartVo.java b/src/main/java/com/gunshi/project/xyt/entity/vo/OsmoticChartVo.java new file mode 100644 index 0000000..f572a78 --- /dev/null +++ b/src/main/java/com/gunshi/project/xyt/entity/vo/OsmoticChartVo.java @@ -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 detailVos; +} diff --git a/src/main/java/com/gunshi/project/xyt/entity/vo/OsmoticStationVo.java b/src/main/java/com/gunshi/project/xyt/entity/vo/OsmoticStationVo.java new file mode 100644 index 0000000..c960153 --- /dev/null +++ b/src/main/java/com/gunshi/project/xyt/entity/vo/OsmoticStationVo.java @@ -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 list; +} diff --git a/src/main/java/com/gunshi/project/xyt/entity/vo/OsmoticValueVo.java b/src/main/java/com/gunshi/project/xyt/entity/vo/OsmoticValueVo.java new file mode 100644 index 0000000..0205cfd --- /dev/null +++ b/src/main/java/com/gunshi/project/xyt/entity/vo/OsmoticValueVo.java @@ -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; + +} diff --git a/src/main/java/com/gunshi/project/xyt/entity/vo/StRzVo.java b/src/main/java/com/gunshi/project/xyt/entity/vo/StRzVo.java new file mode 100644 index 0000000..6ce0cf2 --- /dev/null +++ b/src/main/java/com/gunshi/project/xyt/entity/vo/StRzVo.java @@ -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; +} diff --git a/src/main/java/com/gunshi/project/xyt/mapper/OsmoticPressRMapper.java b/src/main/java/com/gunshi/project/xyt/mapper/OsmoticPressRMapper.java index 9b9d3a5..3b9882c 100644 --- a/src/main/java/com/gunshi/project/xyt/mapper/OsmoticPressRMapper.java +++ b/src/main/java/com/gunshi/project/xyt/mapper/OsmoticPressRMapper.java @@ -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 { """) Page queryPage(Page page,@Param("obj") OsmoticQueryPageSo osmoticQueryPageSo); + + @Select(""" + + """) + List queryRz(@Param("obj") OsmoticQuerySo osmoticQuerySo); + + @Select(""" + + """) + List queryValue(@Param("obj") OsmoticQuerySo osmoticQuerySo); + } \ No newline at end of file diff --git a/src/main/java/com/gunshi/project/xyt/service/OsmoticPressRService.java b/src/main/java/com/gunshi/project/xyt/service/OsmoticPressRService.java index dcb5100..3282903 100644 --- a/src/main/java/com/gunshi/project/xyt/service/OsmoticPressRService.java +++ b/src/main/java/com/gunshi/project/xyt/service/OsmoticPressRService.java @@ -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 queryPage(OsmoticQueryPageSo osmoticQueryPageSo) { return mapper.queryPage(osmoticQueryPageSo.getPageSo().toPage(),osmoticQueryPageSo); } + + /** + * 测值查询,管水位和库水位数据固定查询每日早8点 + * @param osmoticQuerySo + * @return + */ + public List queryValue(OsmoticQuerySo osmoticQuerySo) { + List dateList = DateUtil.getDatesBetween(osmoticQuerySo.getDateTimeRangeSo().getStart(), osmoticQuerySo.getDateTimeRangeSo().getEnd()); + List resList = new ArrayList<>(); + //查询库水位 + List list = mapper.queryRz(osmoticQuerySo); + Map rzMap = list.stream().collect(Collectors.toMap(StRzVo::getTm, StRzVo::getRz)); + //查询测站管水位 + List 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 queryChart(OsmoticQuerySo osmoticQuerySo) { + List resList = new ArrayList<>(); + //查询库水位 + List list = mapper.queryRz(osmoticQuerySo); + //查询测站管水位 + List valueList = mapper.queryValue(osmoticQuerySo); + //按测站分组 + Map> map = valueList.stream().collect(Collectors.groupingBy(OsmoticValueVo::getStationCode)); + map.entrySet().forEach(o->{ + OsmoticChartVo vo = new OsmoticChartVo(); + List 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 bindData(List tmRzList, List voList) { + HashSet strings = new HashSet<>(); + tmRzList.stream().forEach(v1 -> strings.add(v1.getTm())); + voList.stream().forEach(v1 -> strings.add(v1.getTm())); + + List result = new ArrayList<>(); + strings.stream().forEach(v1 ->{ + OsmoticChartDetailVo v = new OsmoticChartDetailVo(); + v.setTm(v1); + result.add(v); + }); + + List 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()); + } } diff --git a/src/main/java/com/gunshi/project/xyt/util/DateUtil.java b/src/main/java/com/gunshi/project/xyt/util/DateUtil.java index 20d8f9c..ceccc66 100644 --- a/src/main/java/com/gunshi/project/xyt/util/DateUtil.java +++ b/src/main/java/com/gunshi/project/xyt/util/DateUtil.java @@ -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 getDatesBetween(Date startDate, Date endDate) { + List 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(); + } + }