From cb457042886a416b855feb1ba617d20c3614196c Mon Sep 17 00:00:00 2001 From: yangzhe123 <2824096059@qq.com> Date: Wed, 24 Dec 2025 14:13:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AE=BE=E5=A4=87=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E7=9B=91=E6=B5=8B=E4=BB=A3=E7=A0=81=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project/hsz/entity/vo/StStatusListVo.java | 19 +-- .../project/hsz/entity/vo/StStatusVo.java | 3 - .../project/hsz/mapper/StbprpBVoMapper.java | 18 ++- .../project/hsz/service/StStbprpBService.java | 141 ++++++++++-------- src/main/resources/config-local.yml | 20 +-- 5 files changed, 114 insertions(+), 87 deletions(-) diff --git a/src/main/java/com/gunshi/project/hsz/entity/vo/StStatusListVo.java b/src/main/java/com/gunshi/project/hsz/entity/vo/StStatusListVo.java index 09f65b3..06d504e 100644 --- a/src/main/java/com/gunshi/project/hsz/entity/vo/StStatusListVo.java +++ b/src/main/java/com/gunshi/project/hsz/entity/vo/StStatusListVo.java @@ -7,6 +7,7 @@ import org.bouncycastle.cert.dane.DANEEntry; import java.math.BigDecimal; import java.util.List; +import java.util.Map; @Data public class StStatusListVo { @@ -21,22 +22,22 @@ public class StStatusListVo { private BigDecimal reportPercentage; @Schema(description = "雨量站") - private List rainStation; + private Map> rainStationMap; + @Schema(description = "水库水位站") - private List rsvrStation; + private Map> rsvrStationMap; + @Schema(description = "河道水位站") - private List riverStation; + private Map> riverStationMap; + @Schema(description = "流量站") - private List flowStation; + private Map> flowStationMap; - @Schema(description = "流量站") - private List online; - - @Schema(description = "流量站") - private List offLine; + @Schema(description = "视频站") + private Map> cctvStationMap; } diff --git a/src/main/java/com/gunshi/project/hsz/entity/vo/StStatusVo.java b/src/main/java/com/gunshi/project/hsz/entity/vo/StStatusVo.java index f9613b5..2bf5833 100644 --- a/src/main/java/com/gunshi/project/hsz/entity/vo/StStatusVo.java +++ b/src/main/java/com/gunshi/project/hsz/entity/vo/StStatusVo.java @@ -18,9 +18,6 @@ public class StStatusVo { @Schema(description = "测站名称") private String stnm; - @Schema(description = "状态 0 离线 1在线") - private Integer status; - @Schema(description = "经度") private BigDecimal lgtd; diff --git a/src/main/java/com/gunshi/project/hsz/mapper/StbprpBVoMapper.java b/src/main/java/com/gunshi/project/hsz/mapper/StbprpBVoMapper.java index e139a12..8ca3910 100644 --- a/src/main/java/com/gunshi/project/hsz/mapper/StbprpBVoMapper.java +++ b/src/main/java/com/gunshi/project/hsz/mapper/StbprpBVoMapper.java @@ -49,7 +49,7 @@ public interface StbprpBVoMapper { @Select(""" @@ -58,7 +58,7 @@ public interface StbprpBVoMapper { @Select(""" @@ -67,7 +67,7 @@ public interface StbprpBVoMapper { @Select(""" @@ -119,11 +119,21 @@ public interface StbprpBVoMapper { @Select(""" """) List zList(); + + @Select(""" + select t1.stcd,t1.stnm,t2.tm,t1,lgtd,t1.lttd from + st_stbprp_b t1 + left join st_water_r_real t2 + on t1.stcd = t2.stcd + where t1.stcd in ('1112','1113','1114') +""") + List flowStationList(); + } diff --git a/src/main/java/com/gunshi/project/hsz/service/StStbprpBService.java b/src/main/java/com/gunshi/project/hsz/service/StStbprpBService.java index 3559948..a494fa2 100644 --- a/src/main/java/com/gunshi/project/hsz/service/StStbprpBService.java +++ b/src/main/java/com/gunshi/project/hsz/service/StStbprpBService.java @@ -18,6 +18,7 @@ import com.gunshi.project.hsz.mapper.StbprpBVoMapper; import com.gunshi.project.hsz.common.model.StRsvrR; import com.gunshi.project.hsz.model.*; import com.gunshi.project.hsz.util.DateUtil; +import io.swagger.v3.oas.models.security.SecurityScheme; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -26,6 +27,7 @@ import org.springframework.transaction.annotation.Transactional; import java.io.Serializable; import java.math.BigDecimal; +import java.math.RoundingMode; import java.text.SimpleDateFormat; import java.time.Duration; import java.time.LocalDateTime; @@ -85,76 +87,93 @@ public class StStbprpBService extends ServiceImpl { public StStatusListVo statusList() { StStatusListVo res = new StStatusListVo(); + Integer onlineCount = 0; + Integer offlineCount = 0; //水雨情站超过2小时为离线;渗压,渗流,位移暂定超过24小时为离线 - List list = new ArrayList<>(); - List onLineList = new ArrayList<>(); - List offLineList = new ArrayList<>(); //雨量站 List rainList = stbprpBVoMapper.realRainList(); - //水位站 - List rzList = stbprpBVoMapper.rzList(); - //图像站 - List imgList = stbprpBVoMapper.imgList(); - //水库水情 - List zList = stbprpBVoMapper.zList(); - rainList.addAll(rzList); - rainList.addAll(imgList); - rainList.addAll(zList); - rainList.stream().collect(Collectors.toMap(obj -> obj.getStcd(), obj -> obj, (obj1, obj2) -> - DateUtil.convertStringToDate(obj1.getTm()).after(DateUtil.convertStringToDate(obj2.getTm())) ? obj1 : obj2 - )).values().stream().collect(Collectors.toList()); - for (StStatusVo statusVo : rainList) { - String tm = statusVo.getTm(); - if (StringUtils.isEmpty(tm) || DateUtil.hoursBetweenDate(DateUtil.convertStringToDate(tm), new Date()) > 2) { - offLineList.add(statusVo); - } else { - onLineList.add(statusVo); + Map> rainStationMap = new HashMap<>(); + rainStationMap.put("online",new ArrayList<>()); + rainStationMap.put("offline",new ArrayList<>()); + res.setRainStationMap(rainStationMap); + for (StStatusVo stStatusVo : rainList) { + String tm = stStatusVo.getTm(); + if(tm != null && !(DateUtil.hoursBetweenDate(DateUtil.convertStringToDate(tm), new Date()) > 24 )){ + rainStationMap.get("online").add(stStatusVo); + onlineCount++; + }else{ + rainStationMap.get("offline").add(stStatusVo); + offlineCount++; } } - //渗压 - List pressList = pressRMapper.listValue2(); - list.addAll(pressList.stream().map(o -> { - StStatusVo vo = new StStatusVo(); - vo.setStnm(o.getStationCode()); - vo.setTm(o.getTm()); - return vo; - }).collect(Collectors.toList())); - //渗流 - List flowList = pressRMapper.flowListValue2(); - list.addAll(flowList.stream().map(o -> { - StStatusVo vo = new StStatusVo(); - vo.setStnm(o.getStationCode()); - vo.setTm(o.getTm()); - return vo; - }).collect(Collectors.toList())); - //位移 - List shiftList = shiftRMapper.listValue2(); - list.addAll(shiftList.stream().map(o -> { - StStatusVo vo = new StStatusVo(); - vo.setStnm(o.getCdNm()); - vo.setTm(o.getTm()); - return vo; - }).collect(Collectors.toList())); - for (StStatusVo vo : list) { - String tm = vo.getTm(); - if (StringUtils.isEmpty(tm) || DateUtil.hoursBetweenDate(DateUtil.convertStringToDate(tm), new Date()) > 24) { - offLineList.add(vo); - } else { - onLineList.add(vo); + //河道水位站 + List rzList = stbprpBVoMapper.rzList(); + Map> riverStationMap = new HashMap<>(); + riverStationMap.put("online",new ArrayList<>()); + riverStationMap.put("offline",new ArrayList<>()); + res.setRiverStationMap(riverStationMap); + for (StStatusVo stStatusVo : rzList) { + String tm = stStatusVo.getTm(); + if(tm != null && !(DateUtil.hoursBetweenDate(DateUtil.convertStringToDate(tm), new Date()) > 24 )){ + riverStationMap.get("online").add(stStatusVo); + onlineCount++; + }else{ + riverStationMap.get("offline").add(stStatusVo); + offlineCount++; + } + } + //水库水情 + List zList = stbprpBVoMapper.zList(); + Map> rsvrStationMap = new HashMap<>(); + rsvrStationMap.put("online",new ArrayList<>()); + rsvrStationMap.put("offline",new ArrayList<>()); + res.setRsvrStationMap(rsvrStationMap); + for (StStatusVo stStatusVo : zList) { + String tm = stStatusVo.getTm(); + if(tm != null && !(DateUtil.hoursBetweenDate(DateUtil.convertStringToDate(tm), new Date()) > 24 )){ + rsvrStationMap.get("online").add(stStatusVo); + onlineCount++; + }else{ + rsvrStationMap.get("offline").add(stStatusVo); + offlineCount++; } } // 视频点 List attCctvBases = attCctvBaseService.queryList(); - List cctvVos = new ArrayList<>(); - cctvVos.addAll( attCctvBases.stream().map(o ->{ - StStatusVo vo = new StStatusVo(); - vo.setStnm(o.getName()); - vo.setTm(null); - return vo; - }).collect(Collectors.toList())); - offLineList.addAll(cctvVos); - res.setOnline(onLineList.stream().sorted(Comparator.comparing(StStatusVo::getTm, Comparator.nullsFirst(String::compareTo)).reversed()).collect(Collectors.toList())); - res.setOffLine(offLineList.stream().sorted(Comparator.comparing(StStatusVo::getTm, Comparator.nullsFirst(String::compareTo)).reversed()).collect(Collectors.toList())); + Map> cctvStationMap = new HashMap<>(); + cctvStationMap.put("online",new ArrayList<>()); + cctvStationMap.put("offline",new ArrayList<>()); + res.setCctvStationMap(cctvStationMap); + for (AttCctvBase attCctvBase : attCctvBases) { + StStatusVo stStatusVo = new StStatusVo(); + stStatusVo.setStnm(attCctvBase.getName()); + stStatusVo.setLgtd(attCctvBase.getLgtd() == null?null:new BigDecimal(attCctvBase.getLgtd())); + stStatusVo.setLttd(attCctvBase.getLttd() == null?null:new BigDecimal(attCctvBase.getLttd())); + cctvStationMap.get("offline").add(stStatusVo); + offlineCount++; + } + //流量站 + //TODO 站点编码等真实站点编码来之后需要更改 + List flowList = stbprpBVoMapper.flowStationList(); + Map> flowStationMap = new HashMap<>(); + flowStationMap.put("online",new ArrayList<>()); + flowStationMap.put("offline",new ArrayList<>()); + res.setFlowStationMap(flowStationMap); + for (StStatusVo stStatusVo : flowList) { + String tm = stStatusVo.getTm(); + if(tm != null && !(DateUtil.hoursBetweenDate(DateUtil.convertStringToDate(tm), new Date()) > 24 )){ + flowStationMap.get("online").add(stStatusVo); + onlineCount++; + }else{ + flowStationMap.get("offline").add(stStatusVo); + offlineCount++; + } + } + BigDecimal totalCount = new BigDecimal(onlineCount).add(new BigDecimal(offlineCount)); + BigDecimal reportPercentage =new BigDecimal(onlineCount).divide(totalCount).multiply(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP); + res.setOnlineCount(onlineCount); + res.setOffLineCount(offlineCount); + res.setReportPercentage(reportPercentage); return res; } diff --git a/src/main/resources/config-local.yml b/src/main/resources/config-local.yml index b912bf4..f34f567 100644 --- a/src/main/resources/config-local.yml +++ b/src/main/resources/config-local.yml @@ -5,18 +5,18 @@ spring: dynamic: datasource: master: - url: jdbc:postgresql://postgres:5432/hsz?stringtype=unspecified - username: gunshiiot - password: 1234567a + url: jdbc:postgresql://localhost:5432/hsz-dp?stringtype=unspecified + username: postgres + password: postgres driver-class-name: org.postgresql.Driver access-logging: - url: jdbc:postgresql://postgres:5432/hsz - username: gunshiiot - password: 1234567a + url: jdbc:postgresql://localhost:5432/hsz-dp + username: postgres + password: postgres driver-class-name: org.postgresql.Driver data: redis: - host: hsz-redis + host: localhost port: 6379 #password: 1234567a database: 0 @@ -38,9 +38,9 @@ gunshi: # 洪水预测数据库连接信息 algorithem: datasource: - url: jdbc:postgresql://postgres:5432/hsz?stringtype=unspecified - username: gunshiiot - password: 1234567a + url: jdbc:postgresql://localhost:5432/hsz-dp?stringtype=unspecified + username: postgres + password: postgres driver-class-name: org.postgresql.Driver jcskPath: http://64.97.142.113:8002/shareddata/api/v1/monitdata