完成首页雨情监测板块,完善监测设备运行状况

master
hqx 2024-02-06 17:28:09 +08:00
parent df18e330a7
commit d58fc49be5
6 changed files with 438 additions and 8 deletions

View File

@ -3,11 +3,10 @@ package com.gunshi.project.xyt.controller;
import com.gunshi.core.annotation.Get;
import com.gunshi.core.result.R;
import com.gunshi.project.xyt.entity.vo.ReservoirLevelVo;
import com.gunshi.project.xyt.entity.vo.StPptnVo;
import com.gunshi.project.xyt.model.StRcvReal;
import com.gunshi.project.xyt.model.StResPersonRef;
import com.gunshi.project.xyt.service.MonitorEquipmentHealthService;
import com.gunshi.project.xyt.service.ReservoirLevelService;
import com.gunshi.project.xyt.service.StResPersonRefService;
import com.gunshi.project.xyt.service.WarningInfoService;
import com.gunshi.project.xyt.service.*;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
@ -36,6 +35,8 @@ public class HomePageController {
@Resource
private ReservoirLevelService reservoirLevelService;
@Resource
private RainMonitoringService rainMonitoringService;
@Resource
private StResPersonRefService stResPersonRefService;
@Resource
private WarningInfoService warningInfoService;
@ -82,26 +83,59 @@ public class HomePageController {
return R.ok(reservoirLevelService.queryRzHalfYearByResId(resId));
}
@Get(path = "/rainMonitoring/queryTodayDrp",summary = "根据水库ID查询今天降雨量")
public R<List<StPptnVo>> queryTodayDrpByResId(@Parameter(description = "水库ID") @RequestParam("resId") String resId){
return R.ok(rainMonitoringService.queryTodayDrpByResId(resId));
}
@Get(path = "/rainMonitoring/queryYesterdayDrp",summary = "根据水库ID查询昨天降雨量")
public R<List<StPptnVo>> queryYesterdayDrpByResId(@Parameter(description = "水库ID") @RequestParam("resId") String resId){
return R.ok(rainMonitoringService.queryYesterdayDrpByResId(resId));
}
@Get(path = "/rainMonitoring/query24HourDrp",summary = "根据水库ID查询24小时内的降雨量")
public R<List<StPptnVo>> query24HourDrpByResId(@Parameter(description = "水库ID") @RequestParam("resId") String resId){
return R.ok(rainMonitoringService.query24HourDrpByResId(resId));
}
@Get(path = "/rainMonitoring/query72HourDrp",summary = "根据水库ID查询72小时内的降雨量")
public R<List<StPptnVo>> query72HourDrpByResId(@Parameter(description = "水库ID") @RequestParam("resId") String resId){
return R.ok(rainMonitoringService.query72HourDrpByResId(resId));
}
@Get(path = "/rainMonitoring/querySevenDayDrp",summary = "根据水库ID查询七日的降雨量")
public R<List<StPptnVo>> querySevenDayDrpByResId(@Parameter(description = "水库ID") @RequestParam("resId") String resId){
return R.ok(rainMonitoringService.querySevenDayDrpByResId(resId));
}
@Get(path = "/personInCharge/queryStResPersonRef",summary = "根据水库ID查询责任人信息")
public R<List<StResPersonRef>> queryStResPersonRefByResId(@Parameter(description = "水库ID") @RequestParam("resId") String resId){
return R.ok(stResPersonRefService.queryStResPersonRefByResId(resId));
}
@Get(path = "/WarningInfo/ReservoirExceededLimit",summary = "判断水库超汛限是否正常")
@Get(path = "/warningInfo/reservoirExceededLimit",summary = "判断水库超汛限是否正常")
public R<Boolean> ReservoirExceededLimit(@Parameter(description = "水库ID") @RequestParam("resId") String resId){
return R.ok(warningInfoService.ReservoirExceededLimit(resId));
}
@Get(path = "/MonitorEquipmentHealth/queryAllStcdCount",summary = "查看监测设备总数")
@Get(path = "/monitorEquipmentHealth/queryAllStcdCount",summary = "查看监测设备总数")
public R<Long> queryAllStcdCount(){
return R.ok(monitorEquipmentHealthService.queryAllStcdCount());
}
@Get(path = "/MonitorEquipmentHealth/queryOnlineStcdCount",summary = "查看近一个小时检测设备在线数量")
@Get(path = "/monitorEquipmentHealth/queryOnlineStcdCount",summary = "查看近一个小时检测设备在线数量")
public R<Long> queryOnlineStcdCount(){
return R.ok(monitorEquipmentHealthService.queryOnlineStcdCount());
}
@Get(path = "/monitorEquipmentHealth/queryOffLineStcd",summary = "查看离线设备清单")
public R<List<StRcvReal>> queryOffLineStcd(){
return R.ok(monitorEquipmentHealthService.queryOffLineStcd());
}
@Get(path = "/monitorEquipmentHealth/queryOnLineStcd",summary = "查看在线设备清单")
public R<List<StRcvReal>> queryOnLineStcd(){
return R.ok(monitorEquipmentHealthService.queryOnLineStcd());
}
}

View File

@ -0,0 +1,30 @@
package com.gunshi.project.xyt.entity.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.gunshi.core.dateformat.DateFormatString;
import lombok.Data;
import java.math.BigDecimal;
import java.util.Date;
/**
* TODO
*
* @ClassName StPptnVo
* @Author Huang Qianxiang
* @Date 2024/2/6 10:48
*/
@Data
public class StPptnVo {
/**
*
*/
@JsonFormat(pattern = DateFormatString.YYYY_MM_DD_HH_MM_SS, timezone = "GMT+8")
private Date time;
/**
*
*/
private BigDecimal sumDrp;
}

View File

@ -0,0 +1,72 @@
package com.gunshi.project.xyt.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gunshi.project.xyt.entity.vo.StPptnVo;
import com.gunshi.project.xyt.model.StPptnR;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.Date;
import java.util.List;
@Mapper
public interface StPptnRMapper extends BaseMapper<StPptnR> {
@Select("""
<script>
SELECT DATEADD(HOUR, DATEDIFF(HOUR, 0, ST_PPTN_R.TM), 0) as time,
SUM(DRP) as sumDRP
FROM ST_RES_STCD_REF,ST_PPTN_R
WHERE ST_PPTN_R.TM &gt;= #{startTime} AND
ST_PPTN_R.TM &lt; #{endTime} AND
ST_RES_STCD_REF.STCD = ST_PPTN_R.STCD AND
ST_RES_STCD_REF.RES_ID = #{resId}
GROUP BY DATEADD(HOUR, DATEDIFF(HOUR, 0, ST_PPTN_R.TM), 0)
</script>
""")
List<StPptnVo> queryHourTimeQuantumDrpByResId(@Param("resId") String resId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);
@Select("""
<script>
SELECT DATEADD(DAY, DATEDIFF(DAY, 0, ST_PPTN_R.TM), 0) as time,
SUM(DRP) as sumDRP
FROM ST_RES_STCD_REF,ST_PPTN_R
WHERE ST_PPTN_R.TM &gt;= #{startTime} AND
ST_PPTN_R.TM &lt; #{endTime} AND
ST_RES_STCD_REF.STCD = ST_PPTN_R.STCD AND
ST_RES_STCD_REF.RES_ID = #{resId}
GROUP BY DATEADD(DAY, DATEDIFF(DAY, 0, ST_PPTN_R.TM), 0)
</script>
""")
List<StPptnVo> queryDayTimeQuantumDrpByResId(@Param("resId") String resId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);
@Select("""
<script>
SELECT DATEADD(HOUR, DATEDIFF(HOUR, 0, ST_PPTN_R.TM), 0) as time,
SUM(DRP) as sumDRP
FROM ST_RES_STCD_REF,ST_PPTN_R
WHERE ST_PPTN_R.TM &gt;= dateadd(HOUR,-24,getdate()) AND
ST_PPTN_R.TM &lt; GETDATE() AND
ST_RES_STCD_REF.STCD = ST_PPTN_R.STCD and
ST_RES_STCD_REF.RES_ID = #{resId}
GROUP BY DATEADD(HOUR, DATEDIFF(HOUR, 0, ST_PPTN_R.TM), 0)
</script>
""")
List<StPptnVo> query24HourDrpByResId(@Param("resId") String resId);
@Select("""
<script>
SELECT DATEADD(HOUR, DATEDIFF(HOUR, 0, ST_PPTN_R.TM), 0) as time,
SUM(DRP) as sumDRP
FROM ST_RES_STCD_REF,ST_PPTN_R
WHERE ST_PPTN_R.TM &gt;= dateadd(HOUR,-72,getdate()) AND
ST_PPTN_R.TM &lt; GETDATE() AND
ST_RES_STCD_REF.STCD = ST_PPTN_R.STCD and
ST_RES_STCD_REF.RES_ID = #{resId}
GROUP BY DATEADD(HOUR, DATEDIFF(HOUR, 0, ST_PPTN_R.TM), 0)
</script>
""")
List<StPptnVo> query72HourDrpByResId(@Param("resId") String resId);
}

View File

@ -1,15 +1,48 @@
package com.gunshi.project.xyt.mapper;
import com.gunshi.project.xyt.model.StRcvReal;
import org.apache.ibatis.annotations.Select;
import java.util.List;
public interface StRcvRealMapper {
@Select("""
<script>
SELECT count(*)from ST_RCV_REAL
WHERE TM >= DATEADD(HOUR, -1, GETDATE());
WHERE TM &gt;= DATEADD(HOUR, -1, GETDATE());
</script>
""")
Long queryOnlineStcdCount();
@Select("""
<script>
SELECT ST_RCV_REAL.STCD,
ST_RCV_REAL.TM,
ST_RCV_REAL.STNM,
ST_RCV_REAL.STTP,
ST_RCV_REAL.DATA,
ST_RCV_REAL.PROTOCOL_ID,
ST_RCV_REAL.PROTOCOL_NAME
FROM ST_RCV_REAL
WHERE TM &lt; DATEADD(HOUR, -1, GETDATE())
</script>
""")
List<StRcvReal> queryOffLineStcd();
@Select("""
<script>
SELECT ST_RCV_REAL.STCD,
ST_RCV_REAL.TM,
ST_RCV_REAL.STNM,
ST_RCV_REAL.STTP,
ST_RCV_REAL.DATA,
ST_RCV_REAL.PROTOCOL_ID,
ST_RCV_REAL.PROTOCOL_NAME
FROM ST_RCV_REAL
WHERE TM &gt;= DATEADD(HOUR, -1, GETDATE())
</script>
""")
List<StRcvReal> queryOnLineStcd();
}

View File

@ -9,6 +9,8 @@ import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* TODO
*
@ -41,6 +43,22 @@ public class MonitorEquipmentHealthService {
return stRcvRealMapper.queryOnlineStcdCount();
}
/**
* 线
* @return
*/
public List<StRcvReal> queryOffLineStcd(){
return stRcvRealMapper.queryOffLineStcd();
}
/**
* 线
* @return
*/
public List<StRcvReal> queryOnLineStcd(){
return stRcvRealMapper.queryOnLineStcd();
}
}

View File

@ -0,0 +1,243 @@
package com.gunshi.project.xyt.service;
import com.gunshi.project.xyt.entity.vo.StPptnVo;
import com.gunshi.project.xyt.mapper.StPptnRMapper;
import com.gunshi.project.xyt.model.StResB;
import com.gunshi.project.xyt.model.StResBAutoDao;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* TODO
*
* @ClassName RainMonitoringService
* @Author Huang Qianxiang
* @Date 2024/2/6 10:44
*/
@Service
@Slf4j
public class RainMonitoringService {
@Resource
private StResBAutoDao stResBAutoDao;
@Resource
private StPptnRMapper stPptnRMapper;
/**
* ID
* @param resId ID
* @return
*/
public List<StPptnVo> queryTodayDrpByResId(String resId){
StResB stResB = stResBAutoDao.getById(resId);
if (stResB == null){
throw new IllegalArgumentException("该水库ID不存在");
}
LocalDateTime now = LocalDateTime.now();
LocalDateTime startTime = null;
LocalDateTime endTime = null;
if (now.getHour() < 8){
LocalDateTime time = now.minusDays(1);
//当前时间未到 8:00
startTime = LocalDateTime.of(
time.getYear(),
time.getMonth(),
time.getDayOfMonth(),
8,
0,
0
);
}else {
startTime = LocalDateTime.of(
now.getYear(),
now.getMonth(),
now.getDayOfMonth(),
8,
0,
0
);
}
endTime = now;
return stPptnRMapper.queryHourTimeQuantumDrpByResId(
resId,
Date.from(startTime.atZone(ZoneId.systemDefault()).toInstant()),
Date.from(endTime.atZone(ZoneId.systemDefault()).toInstant())
);
}
/**
* ID
* @param resId ID
* @return
*/
public List<StPptnVo> queryYesterdayDrpByResId(String resId){
StResB stResB = stResBAutoDao.getById(resId);
if (stResB == null){
throw new IllegalArgumentException("该水库ID不存在");
}
LocalDateTime now = LocalDateTime.now();
LocalDateTime startTime = null;
LocalDateTime endTime = null;
if (now.getHour() < 8){
LocalDateTime time1 = now.minusDays(2);
//当前时间未到 8:00
startTime = LocalDateTime.of(
time1.getYear(),
time1.getMonth(),
time1.getDayOfMonth(),
8,
0,
0
);
LocalDateTime time2 = now.minusDays(1);
endTime = LocalDateTime.of(
time2.getYear(),
time2.getMonth(),
time2.getDayOfMonth(),
8,
0,
0
);
}else {
LocalDateTime time = now.minusDays(1);
startTime = LocalDateTime.of(
time.getYear(),
time.getMonth(),
time.getDayOfMonth(),
8,
0,
0
);
endTime = LocalDateTime.of(
now.getYear(),
now.getMonth(),
now.getDayOfMonth(),
8,
0,
0
);
}
return stPptnRMapper.queryHourTimeQuantumDrpByResId(
resId,
Date.from(startTime.atZone(ZoneId.systemDefault()).toInstant()),
Date.from(endTime.atZone(ZoneId.systemDefault()).toInstant())
);
}
/**
* ID24
* @param resId ID
* @return
*/
public List<StPptnVo> query24HourDrpByResId(String resId){
StResB stResB = stResBAutoDao.getById(resId);
if (stResB == null){
throw new IllegalArgumentException("该水库ID不存在");
}
return stPptnRMapper.query24HourDrpByResId(resId);
}
/**
* ID72
* @param resId ID
* @return
*/
public List<StPptnVo> query72HourDrpByResId(String resId){
StResB stResB = stResBAutoDao.getById(resId);
if (stResB == null){
throw new IllegalArgumentException("该水库ID不存在");
}
return stPptnRMapper.query72HourDrpByResId(resId);
}
/**
* ID
* @param resId ID
* @return
*/
public List<StPptnVo> querySevenDayDrpByResId(String resId){
StResB stResB = stResBAutoDao.getById(resId);
if (stResB == null){
throw new IllegalArgumentException("该水库ID不存在");
}
LocalDateTime now = LocalDateTime.now();
LocalDateTime startTime = null;
LocalDateTime endTime = null;
List<StPptnVo> stPptnVoList = new ArrayList<StPptnVo>();
if (now.getHour() < 8){
now = now.minusDays(1);
}
for (int i = 0; i < 7; i++) {
//获取每一天累计降水量
if (i == 0){
startTime = LocalDateTime.of(
now.getYear(),
now.getMonth(),
now.getDayOfMonth(),
8,
0,
0
);
endTime = now;
}else {
startTime = LocalDateTime.of(
now.getYear(),
now.getMonth(),
now.getDayOfMonth(),
8,
0,
0
);
LocalDateTime time = now.plusDays(1);
endTime = LocalDateTime.of(
time.getYear(),
time.getMonth(),
time.getDayOfMonth(),
8,
0,
0
);
}
List<StPptnVo> stPptnVoList1 = stPptnRMapper.queryDayTimeQuantumDrpByResId(
resId,
Date.from(startTime.atZone(ZoneId.systemDefault()).toInstant()),
Date.from(endTime.atZone(ZoneId.systemDefault()).toInstant())
);
//对结果进行处理
BigDecimal sumDrp = BigDecimal.valueOf(0);
for (StPptnVo stPptnVo : stPptnVoList1) {
sumDrp = sumDrp.add(stPptnVo.getSumDrp());
}
StPptnVo stPptnVo = new StPptnVo();
stPptnVo.setTime(Date.from(
LocalDateTime.of(now.getYear(),now.getMonth(),now.getDayOfMonth(),0,0,0)
.atZone(ZoneId.systemDefault())
.toInstant())
);
stPptnVo.setSumDrp(sumDrp);
stPptnVoList.add(stPptnVo);
now = now.minusDays(1);
}
return stPptnVoList;
}
}