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

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

View File

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

View File

@ -49,7 +49,7 @@ public interface StbprpBVoMapper {
@Select("""
<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
WHERE st.stcd in (select distinct(stcd) from st_stbprp_b_elem where elem ='drp')
</script>
@ -58,7 +58,7 @@ public interface StbprpBVoMapper {
@Select("""
<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
WHERE st.stcd in (select distinct(stcd) from st_stbprp_b_elem where elem ='z')
</script>
@ -67,7 +67,7 @@ public interface StbprpBVoMapper {
@Select("""
<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
WHERE st.stcd in (select distinct(stcd) from st_stbprp_b_elem where elem ='img')
</script>
@ -119,11 +119,21 @@ public interface StbprpBVoMapper {
@Select("""
<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
WHERE st.stcd in (select distinct(stcd) from st_stbprp_b_elem where elem ='z')
</script>
""")
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.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<StStbprpBMapper, StStbprpB> {
public StStatusListVo statusList() {
StStatusListVo res = new StStatusListVo();
Integer onlineCount = 0;
Integer offlineCount = 0;
//水雨情站超过2小时为离线渗压渗流位移暂定超过24小时为离线
List<StStatusVo> list = new ArrayList<>();
List<StStatusVo> onLineList = new ArrayList<>();
List<StStatusVo> offLineList = new ArrayList<>();
//雨量站
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> imgList = stbprpBVoMapper.imgList();
Map<String,List<StStatusVo>> 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<StStatusVo> 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);
Map<String,List<StStatusVo>> 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{
onLineList.add(statusVo);
}
}
//渗压
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);
rsvrStationMap.get("offline").add(stStatusVo);
offlineCount++;
}
}
// 视频点
List<AttCctvBase> attCctvBases = attCctvBaseService.queryList();
List<StStatusVo> 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<String,List<StStatusVo>> 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<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;
}

View File

@ -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