修改设备状态监测代码逻辑

master
yangzhe123 2025-12-24 14:13:27 +08:00
parent 36df0cb787
commit cb45704288
5 changed files with 114 additions and 87 deletions

View File

@ -7,6 +7,7 @@ import org.bouncycastle.cert.dane.DANEEntry;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.List; import java.util.List;
import java.util.Map;
@Data @Data
public class StStatusListVo { public class StStatusListVo {
@ -21,22 +22,22 @@ public class StStatusListVo {
private BigDecimal reportPercentage; private BigDecimal reportPercentage;
@Schema(description = "雨量站") @Schema(description = "雨量站")
private List<StStatusVo> rainStation; private Map<String,List<StStatusVo>> rainStationMap;
@Schema(description = "水库水位站") @Schema(description = "水库水位站")
private List<StStatusVo> rsvrStation; private Map<String,List<StStatusVo>> rsvrStationMap;
@Schema(description = "河道水位站") @Schema(description = "河道水位站")
private List<StStatusVo> riverStation; private Map<String,List<StStatusVo>> riverStationMap;
@Schema(description = "流量站") @Schema(description = "流量站")
private List<StStatusVo> flowStation; private Map<String,List<StStatusVo>> flowStationMap;
@Schema(description = "流量站") @Schema(description = "视频站")
private List<StStatusVo> online; private Map<String,List<StStatusVo>> cctvStationMap;
@Schema(description = "流量站")
private List<StStatusVo> offLine;
} }

View File

@ -18,9 +18,6 @@ public class StStatusVo {
@Schema(description = "测站名称") @Schema(description = "测站名称")
private String stnm; private String stnm;
@Schema(description = "状态 0 离线 1在线")
private Integer status;
@Schema(description = "经度") @Schema(description = "经度")
private BigDecimal lgtd; private BigDecimal lgtd;

View File

@ -49,7 +49,7 @@ public interface StbprpBVoMapper {
@Select(""" @Select("""
<script> <script>
SELECT st.stcd,st.stnm,r.tm FROM st_stbprp_b st SELECT st.stcd,st.stnm,r.tm,st.lgtd,st.lttd FROM st_stbprp_b st
LEFT JOIN st_pptn_r_real r ON st.stcd = r.stcd LEFT JOIN st_pptn_r_real r ON st.stcd = r.stcd
WHERE st.stcd in (select distinct(stcd) from st_stbprp_b_elem where elem ='drp') WHERE st.stcd in (select distinct(stcd) from st_stbprp_b_elem where elem ='drp')
</script> </script>
@ -58,7 +58,7 @@ public interface StbprpBVoMapper {
@Select(""" @Select("""
<script> <script>
SELECT st.stcd,st.stnm,r.tm FROM st_stbprp_b st SELECT st.stcd,st.stnm,r.tm,st.lgtd,st.lttd FROM st_stbprp_b st
LEFT JOIN st_rsvr_r_real r ON st.stcd = r.stcd LEFT JOIN st_rsvr_r_real r ON st.stcd = r.stcd
WHERE st.stcd in (select distinct(stcd) from st_stbprp_b_elem where elem ='z') WHERE st.stcd in (select distinct(stcd) from st_stbprp_b_elem where elem ='z')
</script> </script>
@ -67,7 +67,7 @@ public interface StbprpBVoMapper {
@Select(""" @Select("""
<script> <script>
SELECT st.stcd,st.stnm,r.tm FROM st_stbprp_b st SELECT st.stcd,st.stnm,r.tm,st.lgtd,st.lttd FROM st_stbprp_b st
LEFT JOIN st_img_r_real r ON st.stcd = r.stcd LEFT JOIN st_img_r_real r ON st.stcd = r.stcd
WHERE st.stcd in (select distinct(stcd) from st_stbprp_b_elem where elem ='img') WHERE st.stcd in (select distinct(stcd) from st_stbprp_b_elem where elem ='img')
</script> </script>
@ -119,11 +119,21 @@ public interface StbprpBVoMapper {
@Select(""" @Select("""
<script> <script>
SELECT st.stcd,st.stnm,r.tm FROM st_stbprp_b st SELECT st.stcd,st.stnm,r.tm,st.lgtd,st.lttd FROM st_stbprp_b st
JOIN st_rsvr_r_real r ON st.stcd = r.stcd JOIN st_rsvr_r_real r ON st.stcd = r.stcd
WHERE st.stcd in (select distinct(stcd) from st_stbprp_b_elem where elem ='z') WHERE st.stcd in (select distinct(stcd) from st_stbprp_b_elem where elem ='z')
</script> </script>
""") """)
List<StStatusVo> zList(); List<StStatusVo> 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<StStatusVo> flowStationList();
} }

View File

@ -18,6 +18,7 @@ import com.gunshi.project.hsz.mapper.StbprpBVoMapper;
import com.gunshi.project.hsz.common.model.StRsvrR; import com.gunshi.project.hsz.common.model.StRsvrR;
import com.gunshi.project.hsz.model.*; import com.gunshi.project.hsz.model.*;
import com.gunshi.project.hsz.util.DateUtil; import com.gunshi.project.hsz.util.DateUtil;
import io.swagger.v3.oas.models.security.SecurityScheme;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -26,6 +27,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.Duration; import java.time.Duration;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -85,76 +87,93 @@ public class StStbprpBService extends ServiceImpl<StStbprpBMapper, StStbprpB> {
public StStatusListVo statusList() { public StStatusListVo statusList() {
StStatusListVo res = new StStatusListVo(); StStatusListVo res = new StStatusListVo();
Integer onlineCount = 0;
Integer offlineCount = 0;
//水雨情站超过2小时为离线渗压渗流位移暂定超过24小时为离线 //水雨情站超过2小时为离线渗压渗流位移暂定超过24小时为离线
List<StStatusVo> list = new ArrayList<>();
List<StStatusVo> onLineList = new ArrayList<>();
List<StStatusVo> offLineList = new ArrayList<>();
//雨量站 //雨量站
List<StStatusVo> rainList = stbprpBVoMapper.realRainList(); List<StStatusVo> rainList = stbprpBVoMapper.realRainList();
//水位站 Map<String,List<StStatusVo>> 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<StStatusVo> rzList = stbprpBVoMapper.rzList(); List<StStatusVo> rzList = stbprpBVoMapper.rzList();
//图像站 Map<String,List<StStatusVo>> riverStationMap = new HashMap<>();
List<StStatusVo> imgList = stbprpBVoMapper.imgList(); 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<StStatusVo> zList = stbprpBVoMapper.zList(); List<StStatusVo> zList = stbprpBVoMapper.zList();
rainList.addAll(rzList); Map<String,List<StStatusVo>> rsvrStationMap = new HashMap<>();
rainList.addAll(imgList); rsvrStationMap.put("online",new ArrayList<>());
rainList.addAll(zList); rsvrStationMap.put("offline",new ArrayList<>());
rainList.stream().collect(Collectors.toMap(obj -> obj.getStcd(), obj -> obj, (obj1, obj2) -> res.setRsvrStationMap(rsvrStationMap);
DateUtil.convertStringToDate(obj1.getTm()).after(DateUtil.convertStringToDate(obj2.getTm())) ? obj1 : obj2 for (StStatusVo stStatusVo : zList) {
)).values().stream().collect(Collectors.toList()); String tm = stStatusVo.getTm();
for (StStatusVo statusVo : rainList) { if(tm != null && !(DateUtil.hoursBetweenDate(DateUtil.convertStringToDate(tm), new Date()) > 24 )){
String tm = statusVo.getTm(); rsvrStationMap.get("online").add(stStatusVo);
if (StringUtils.isEmpty(tm) || DateUtil.hoursBetweenDate(DateUtil.convertStringToDate(tm), new Date()) > 2) { onlineCount++;
offLineList.add(statusVo);
}else{ }else{
onLineList.add(statusVo); rsvrStationMap.get("offline").add(stStatusVo);
} offlineCount++;
}
//渗压
List<OsmoticPressVo> 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<OsmoticPressVo> 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<OsmoticShiftListVo2> 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<AttCctvBase> attCctvBases = attCctvBaseService.queryList(); List<AttCctvBase> attCctvBases = attCctvBaseService.queryList();
List<StStatusVo> cctvVos = new ArrayList<>(); Map<String,List<StStatusVo>> cctvStationMap = new HashMap<>();
cctvVos.addAll( attCctvBases.stream().map(o ->{ cctvStationMap.put("online",new ArrayList<>());
StStatusVo vo = new StStatusVo(); cctvStationMap.put("offline",new ArrayList<>());
vo.setStnm(o.getName()); res.setCctvStationMap(cctvStationMap);
vo.setTm(null); for (AttCctvBase attCctvBase : attCctvBases) {
return vo; StStatusVo stStatusVo = new StStatusVo();
}).collect(Collectors.toList())); stStatusVo.setStnm(attCctvBase.getName());
offLineList.addAll(cctvVos); stStatusVo.setLgtd(attCctvBase.getLgtd() == null?null:new BigDecimal(attCctvBase.getLgtd()));
res.setOnline(onLineList.stream().sorted(Comparator.comparing(StStatusVo::getTm, Comparator.nullsFirst(String::compareTo)).reversed()).collect(Collectors.toList())); stStatusVo.setLttd(attCctvBase.getLttd() == null?null:new BigDecimal(attCctvBase.getLttd()));
res.setOffLine(offLineList.stream().sorted(Comparator.comparing(StStatusVo::getTm, Comparator.nullsFirst(String::compareTo)).reversed()).collect(Collectors.toList())); cctvStationMap.get("offline").add(stStatusVo);
offlineCount++;
}
//流量站
//TODO 站点编码等真实站点编码来之后需要更改
List<StStatusVo> flowList = stbprpBVoMapper.flowStationList();
Map<String,List<StStatusVo>> 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; return res;
} }

View File

@ -5,18 +5,18 @@ spring:
dynamic: dynamic:
datasource: datasource:
master: master:
url: jdbc:postgresql://postgres:5432/hsz?stringtype=unspecified url: jdbc:postgresql://localhost:5432/hsz-dp?stringtype=unspecified
username: gunshiiot username: postgres
password: 1234567a password: postgres
driver-class-name: org.postgresql.Driver driver-class-name: org.postgresql.Driver
access-logging: access-logging:
url: jdbc:postgresql://postgres:5432/hsz url: jdbc:postgresql://localhost:5432/hsz-dp
username: gunshiiot username: postgres
password: 1234567a password: postgres
driver-class-name: org.postgresql.Driver driver-class-name: org.postgresql.Driver
data: data:
redis: redis:
host: hsz-redis host: localhost
port: 6379 port: 6379
#password: 1234567a #password: 1234567a
database: 0 database: 0
@ -38,9 +38,9 @@ gunshi:
# 洪水预测数据库连接信息 # 洪水预测数据库连接信息
algorithem: algorithem:
datasource: datasource:
url: jdbc:postgresql://postgres:5432/hsz?stringtype=unspecified url: jdbc:postgresql://localhost:5432/hsz-dp?stringtype=unspecified
username: gunshiiot username: postgres
password: 1234567a password: postgres
driver-class-name: org.postgresql.Driver driver-class-name: org.postgresql.Driver
jcskPath: http://64.97.142.113:8002/shareddata/api/v1/monitdata jcskPath: http://64.97.142.113:8002/shareddata/api/v1/monitdata