水情告警-查询

master
yangzhe123 2025-08-29 09:19:49 +08:00
parent b6cee9a13f
commit bd213e239d
7 changed files with 325 additions and 0 deletions

View File

@ -0,0 +1,86 @@
package com.gunshi.project.hsz.controller;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gunshi.core.result.R;
import com.gunshi.project.hsz.entity.so.AlarmSetPageSo;
import com.gunshi.project.hsz.entity.so.WaterAlarmPageSo;
import com.gunshi.project.hsz.entity.vo.WaterAlarmCount;
import com.gunshi.project.hsz.entity.vo.WaterAlarmTypeCount;
import com.gunshi.project.hsz.model.AlarmSet;
import com.gunshi.project.hsz.model.WaterAlarm;
import com.gunshi.project.hsz.service.WaterAlarmService;
import com.gunshi.project.hsz.validate.markers.Insert;
import com.gunshi.project.hsz.validate.markers.Update;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Tag(name = "水情告警")
@RestController
@RequestMapping(value="/waterAlarm")
public class WaterAlarmController {
@Autowired
private WaterAlarmService service;
@Operation(summary = "新增")
@PostMapping("/insert")
public R<WaterAlarm> insert(@Validated(Insert.class) @RequestBody WaterAlarm dto) {
boolean result = service.saveData(dto);
return R.ok(result ? dto : null);
}
@Operation(summary = "修改")
@PostMapping("/update")
public R<WaterAlarm> update(@Validated(Update.class) @RequestBody WaterAlarm dto) {
boolean result = service.updateById(dto);
return R.ok(result ? dto : null);
}
@Operation(summary = "删除")
@GetMapping("/del/{id}")
public R<Boolean> del(@Schema(name = "id") @PathVariable("id") Serializable id) {
boolean b = service.removeById(id);
return R.ok(b);
}
@Operation(summary = "分页")
@PostMapping("/page")
public R<Page<WaterAlarm>> page(@RequestBody WaterAlarmPageSo pageSo) {
return R.ok(service.queryPage(pageSo));
}
@Operation(summary = "列表")
@GetMapping("/list")
public List<WaterAlarm> list() {
List<WaterAlarm> list = service.lambdaQuery().list();
return list;
}
@Operation(summary = "根据年份进行统计柱形图")
@GetMapping("/count12")
public List<WaterAlarmCount> count12(@RequestParam(value = "year") Integer year){
List<WaterAlarmCount> counts = service.count12(year);
return counts;
}
@Operation(summary = "根据年份进行统计圆柱图")
@GetMapping("/countTypeByYear")
public List<WaterAlarmTypeCount> countTypeByYear(@RequestParam(value = "year") Integer year){
List<WaterAlarmTypeCount> res = service.countTypeByYear(year);
return res;
}
}

View File

@ -0,0 +1,25 @@
package com.gunshi.project.hsz.entity.so;
import com.gunshi.db.dto.DateTimeRangeSo;
import com.gunshi.db.dto.PageSo;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
@Data
public class WaterAlarmPageSo {
@NotNull(message = "分页参数不能为空")
@Schema(description = "分页参数")
private PageSo pageSo;
@Schema(description = "测点名称")
private String name;
@Schema(description = "告警类型")
private Integer type;
@Schema(description="告警时间段")
private DateTimeRangeSo timeRangeSo;
}

View File

@ -0,0 +1,13 @@
package com.gunshi.project.hsz.entity.vo;
import lombok.Data;
@Data
public class WaterAlarmCount {
private String year;
private String month;
private String alarmCount;
}

View File

@ -0,0 +1,13 @@
package com.gunshi.project.hsz.entity.vo;
import lombok.Data;
@Data
public class WaterAlarmTypeCount {
private Integer year;
private Integer type;
private Integer count;
}

View File

@ -0,0 +1,55 @@
package com.gunshi.project.hsz.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gunshi.project.hsz.entity.vo.WaterAlarmCount;
import com.gunshi.project.hsz.entity.vo.WaterAlarmTypeCount;
import com.gunshi.project.hsz.model.WaterAlarm;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
import java.util.Map;
@Mapper
public interface WaterAlarmMapper extends BaseMapper<WaterAlarm> {
@Select("""
SELECT
EXTRACT(YEAR FROM alarm_time)::INTEGER AS year,
TO_CHAR(alarm_time, 'MM') AS month,
COUNT(*) AS alarmCount
FROM
water_alarm
WHERE
EXTRACT(YEAR FROM alarm_time) = #{year}
GROUP BY
EXTRACT(YEAR FROM alarm_time),
TO_CHAR(alarm_time, 'MM')
--
ORDER BY
TO_CHAR(alarm_time, 'MM') ASC;
""")
List<WaterAlarmCount> count12(@Param("year") Integer year);
@Select("""
SELECT
EXTRACT(YEAR FROM alarm_time)::INTEGER AS year,
alarm_type as type,
COUNT(id) as count
FROM
water_alarm
WHERE
EXTRACT(YEAR FROM alarm_time) = #{year}
AND alarm_type IS NOT NULL
GROUP BY
-- +
EXTRACT(YEAR FROM alarm_time),
alarm_type
ORDER BY
alarm_type ASC;
""")
List<WaterAlarmTypeCount> countTypeByYear(@Param("year") Integer year);
}

View File

@ -0,0 +1,76 @@
package com.gunshi.project.hsz.model;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Date;
/**
*
*
* @author gunshi
* @version 1.0
*/
@Data
@TableName("water_alarm")
@Schema(description = "水情告警信息")
public class WaterAlarm {
/**
* ID
*/
@TableId(value = "id")
@Schema(description = "主键ID")
private Long id;
/**
*
*/
@Schema(description = "站点编码")
private String stcd;
/**
*
*/
@Schema(description = "站点名称")
private String stnm;
/**
*
* 1-, 2-, 3-, 4-, 5-
*/
@Schema(description = "告警类型 1-水库超汛限, 2-水库超设计, 3-水库超校核, 4-河道超警戒, 5-河道超保证")
private Integer alarmType;
/**
*
*/
@Schema(description = "监测值")
private BigDecimal curValue;
/**
*
*/
@Schema(description = "告警值")
private BigDecimal alarmValue;
/**
*
*/
@Schema(description = "超告警值")
private BigDecimal overValue;
/**
*
*/
@Schema(description = "告警时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime alarmTime;
}

View File

@ -0,0 +1,57 @@
package com.gunshi.project.hsz.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gunshi.project.hsz.entity.so.WaterAlarmPageSo;
import com.gunshi.project.hsz.entity.vo.WaterAlarmCount;
import com.gunshi.project.hsz.entity.vo.WaterAlarmTypeCount;
import com.gunshi.project.hsz.mapper.WaterAlarmMapper;
import com.gunshi.project.hsz.model.WaterAlarm;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Map;
@Service
@Slf4j
@Transactional(rollbackFor = Exception.class)
public class WaterAlarmService extends ServiceImpl<WaterAlarmMapper, WaterAlarm> {
public boolean saveData(WaterAlarm dto) {
dto.setId(IdWorker.getId());
boolean save = save(dto);
return save;
}
public Page<WaterAlarm> queryPage(WaterAlarmPageSo pageSo) {
LambdaQueryWrapper<WaterAlarm> queryWrapper = new LambdaQueryWrapper<>();
if (pageSo.getName() != null) {
queryWrapper.like(WaterAlarm::getStnm,pageSo.getName());
}
if(pageSo.getType() != null){
queryWrapper.eq(WaterAlarm::getAlarmType,pageSo.getType());
}
if(pageSo.getTimeRangeSo() != null){
queryWrapper.between(WaterAlarm::getAlarmTime,pageSo.getTimeRangeSo().getStart(),pageSo.getTimeRangeSo().getEnd());
}
Page<WaterAlarm> waterAlarmPage = this.baseMapper.selectPage(pageSo.getPageSo().toPage(), queryWrapper);
return waterAlarmPage;
}
public List<WaterAlarmCount> count12(Integer year) {
return this.baseMapper.count12(year);
}
public List<WaterAlarmTypeCount> countTypeByYear(Integer year) {
List<WaterAlarmTypeCount> res = this.baseMapper.countTypeByYear(year);
return res;
}
}