22 changed files with 476 additions and 13 deletions
@ -0,0 +1,42 @@ |
|||
package com.kms.yxgh.common.controller; |
|||
|
|||
import com.baomidou.mybatisplus.core.metadata.IPage; |
|||
import com.kms.yxgh.common.dto.WarningDto; |
|||
import com.kms.yxgh.common.dto.WarningQueDto; |
|||
import com.kms.yxgh.common.dto.WarningStatisticDto; |
|||
import com.kms.yxgh.common.dto.WarningStatisticQueDto; |
|||
import com.kms.yxgh.common.service.WarningService; |
|||
import com.shuili.common.core.domain.SearchParam; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import lombok.AllArgsConstructor; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.RequestBody; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
import com.kms.yxgh.base.Response; |
|||
|
|||
|
|||
@RestController |
|||
@AllArgsConstructor |
|||
@RequestMapping("/run/api/warning") |
|||
@Api(tags = "运行管理预警相关") |
|||
public class WarningController { |
|||
|
|||
private final WarningService warningService; |
|||
|
|||
@PostMapping("/list") |
|||
@ApiOperation("预警列表") |
|||
public IPage<WarningDto> list(@RequestBody SearchParam<WarningQueDto> sp) { |
|||
return warningService.selectPage(sp); |
|||
} |
|||
|
|||
/** |
|||
* 预警统计 |
|||
*/ |
|||
@PostMapping("/statistic") |
|||
@ApiOperation("预警统计") |
|||
public Response<WarningStatisticDto> statistic(@RequestBody WarningStatisticQueDto sp) { |
|||
return Response.ok(warningService.statistic(sp)); |
|||
} |
|||
} |
@ -0,0 +1,46 @@ |
|||
package com.kms.yxgh.common.domain; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.TableField; |
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import lombok.Data; |
|||
|
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* 动态检测记录视图 v_bs_sgc_dtsbr |
|||
* |
|||
* @author sy |
|||
* @date 2024-01-04 |
|||
*/ |
|||
@TableName("v_bs_sgc_dtsbr") |
|||
@Data |
|||
public class DeviceCheckingRecordView { |
|||
|
|||
@TableField("ID") |
|||
private String id; |
|||
|
|||
@TableField("CODE") |
|||
private String code; |
|||
|
|||
@TableField("NAME") |
|||
private String name; |
|||
|
|||
@TableField("TYPE") |
|||
private String type; |
|||
|
|||
@TableField("STATUS") |
|||
private String status; |
|||
|
|||
@TableField("ADCD") |
|||
private String adcd; |
|||
|
|||
@TableField("WARNING_TYPE") |
|||
private String warningType; |
|||
|
|||
@TableField("WARNING_LEVEL") |
|||
private String warningLevel; |
|||
|
|||
@TableField("WARNING_TIME") |
|||
private Date warningTime; |
|||
|
|||
} |
@ -1,4 +1,4 @@ |
|||
package com.kms.yxgh.common; |
|||
package com.kms.yxgh.common.dto; |
|||
|
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
@ -1,4 +1,4 @@ |
|||
package com.kms.yxgh.common; |
|||
package com.kms.yxgh.common.dto; |
|||
|
|||
import lombok.Data; |
|||
|
@ -0,0 +1,49 @@ |
|||
package com.kms.yxgh.common.dto; |
|||
|
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* @ClassName: WarningDto |
|||
* @Description: TODO |
|||
* @Date: 2024/3/18 上午11:11 |
|||
* * |
|||
* @author: hxh |
|||
* @version: 1.0 |
|||
*/ |
|||
|
|||
@Data |
|||
@ApiModel("预警信息") |
|||
public class WarningDto { |
|||
|
|||
@ApiModelProperty("id") |
|||
private String id; |
|||
|
|||
@ApiModelProperty("编码") |
|||
private String code; |
|||
|
|||
@ApiModelProperty("名称") |
|||
private String name; |
|||
|
|||
@ApiModelProperty("类型") |
|||
private String type; |
|||
|
|||
@ApiModelProperty("状态") |
|||
private String status; |
|||
|
|||
@ApiModelProperty("行政区划") |
|||
private String adcd; |
|||
|
|||
@ApiModelProperty("预警类型") |
|||
private String warningType; |
|||
|
|||
@ApiModelProperty("预警等级") |
|||
private String warningLevel; |
|||
|
|||
@ApiModelProperty("预警时间") |
|||
private Date warningTime; |
|||
|
|||
} |
@ -0,0 +1,41 @@ |
|||
package com.kms.yxgh.common.dto; |
|||
|
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
|||
import java.util.Date; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @ClassName: WarningQueDto |
|||
* @Description: TODO |
|||
* @Date: 2024/3/18 上午11:11 |
|||
* * |
|||
* @author: hxh |
|||
* @version: 1.0 |
|||
*/ |
|||
|
|||
@Data |
|||
@ApiModel("预警查询条件") |
|||
public class WarningQueDto { |
|||
|
|||
@ApiModelProperty("查询的小时数") |
|||
private Integer fromTime; |
|||
|
|||
@ApiModelProperty("开始时间") |
|||
private Date startTime; |
|||
|
|||
@ApiModelProperty("结束时间") |
|||
private Date endTime; |
|||
|
|||
@ApiModelProperty("行政区划") |
|||
private String adcd; |
|||
|
|||
@ApiModelProperty("名称") |
|||
private String name; |
|||
|
|||
@ApiModelProperty("类型:1堤防,2水闸") |
|||
private List<String> types; |
|||
|
|||
} |
@ -0,0 +1,36 @@ |
|||
package com.kms.yxgh.common.dto; |
|||
|
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @ClassName: WarningStatisticDto |
|||
* @Description: TODO |
|||
* @Date: 2024/3/18 下午2:01 |
|||
* * |
|||
* @author: hxh |
|||
* @version: 1.0 |
|||
*/ |
|||
|
|||
@Data |
|||
@ApiModel("预警统计") |
|||
public class WarningStatisticDto { |
|||
|
|||
private List<Statistic> statistics; |
|||
|
|||
|
|||
@Data |
|||
public static class Statistic { |
|||
|
|||
private String type; |
|||
@ApiModelProperty("名称") |
|||
private String name; |
|||
@ApiModelProperty("编码") |
|||
private String code; |
|||
@ApiModelProperty("数量") |
|||
private Long count; |
|||
} |
|||
} |
@ -0,0 +1,55 @@ |
|||
package com.kms.yxgh.common.dto; |
|||
|
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
import lombok.Getter; |
|||
|
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* @ClassName: WarningStatisticQueDto |
|||
* @Description: TODO |
|||
* @Date: 2024/3/18 下午1:57 |
|||
* * |
|||
* @author: hxh |
|||
* @version: 1.0 |
|||
*/ |
|||
|
|||
@Data |
|||
@ApiModel("预警统计查询") |
|||
public class WarningStatisticQueDto { |
|||
|
|||
@ApiModelProperty("查询的小时数") |
|||
private Integer fromTime; |
|||
|
|||
@ApiModelProperty("开始时间") |
|||
private Date startTime; |
|||
|
|||
@ApiModelProperty("结束时间") |
|||
private Date endTime; |
|||
|
|||
@ApiModelProperty("行政区划") |
|||
private String adcd; |
|||
|
|||
@ApiModelProperty("统计类型") |
|||
private StatisticType type; |
|||
|
|||
@ApiModelProperty("topN") |
|||
private Integer topN = 10; |
|||
|
|||
@ApiModelProperty("对象编码") |
|||
private String code; |
|||
|
|||
@Getter |
|||
public enum StatisticType { |
|||
/** |
|||
* 工程 |
|||
*/ |
|||
ENGINEERING, |
|||
/** |
|||
* 告警类型 |
|||
*/ |
|||
WARNING_TYPE |
|||
} |
|||
} |
@ -0,0 +1,60 @@ |
|||
package com.kms.yxgh.common.mapper; |
|||
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import com.baomidou.mybatisplus.core.metadata.IPage; |
|||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|||
import com.kms.yxgh.common.domain.DeviceCheckingRecordView; |
|||
import com.kms.yxgh.common.dto.WarningStatisticDto; |
|||
import com.kms.yxgh.common.dto.WarningStatisticQueDto; |
|||
import org.apache.ibatis.annotations.Param; |
|||
import org.apache.ibatis.annotations.Select; |
|||
import org.springframework.stereotype.Repository; |
|||
|
|||
|
|||
@Repository |
|||
public interface WarningMapper extends BaseMapper<DeviceCheckingRecordView> { |
|||
|
|||
//按条件统计预警信息,返回统计结果
|
|||
@Select("<script>" + |
|||
"SELECT " + |
|||
"CODE,NAME, " + |
|||
"count(1) as count " + |
|||
"FROM v_bs_sgc_dtsbr " + |
|||
"WHERE 1=1 " + |
|||
"<if test='sp.startTime != null'>" + |
|||
"AND warning_time >= #{sp.startTime} " + |
|||
"</if>" + |
|||
"<if test='sp.endTime != null'>" + |
|||
"AND warning_time <= #{sp.endTime} " + |
|||
"</if>" + |
|||
"<if test='sp.adcd != null and sp.adcd != \"\"'>" + |
|||
"AND adcd like concat(#{sp.adcd},'%') " + |
|||
"</if>" + |
|||
"GROUP BY CODE" + |
|||
"</script>") |
|||
IPage<WarningStatisticDto.Statistic> statisticByCode(Page<WarningStatisticDto.Statistic> page, @Param("sp") WarningStatisticQueDto sp); |
|||
|
|||
@Select("<script>" + |
|||
"SELECT " + |
|||
"WARNING_TYPE as code, " + |
|||
"TYPE," + |
|||
"count(1) as count " + |
|||
"FROM v_bs_sgc_dtsbr " + |
|||
"WHERE 1=1 " + |
|||
"<if test='sp.startTime != null'>" + |
|||
"AND warning_time >= #{sp.startTime} " + |
|||
"</if>" + |
|||
"<if test='sp.endTime != null'>" + |
|||
"AND warning_time <= #{sp.endTime} " + |
|||
"</if>" + |
|||
"<if test='sp.adcd != null and sp.adcd != \"\"'>" + |
|||
"AND adcd like concat(#{sp.adcd},'%') " + |
|||
"</if>" + |
|||
"<if test='sp.code != null and sp.code != \"\"'>" + |
|||
"AND CODE = #{sp.code} " + |
|||
"</if>" + |
|||
"GROUP BY WARNING_TYPE" + |
|||
"</script>") |
|||
IPage<WarningStatisticDto.Statistic> statisticByWarningType(Page<WarningStatisticDto.Statistic> page, @Param("sp") WarningStatisticQueDto sp); |
|||
|
|||
} |
@ -0,0 +1,122 @@ |
|||
package com.kms.yxgh.common.service; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|||
import com.baomidou.mybatisplus.core.metadata.IPage; |
|||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|||
import com.github.benmanes.caffeine.cache.Caffeine; |
|||
import com.github.benmanes.caffeine.cache.LoadingCache; |
|||
import com.kms.system.mapper.SysDictDataMapper; |
|||
import com.kms.yxgh.common.domain.DeviceCheckingRecordView; |
|||
import com.kms.yxgh.common.dto.WarningDto; |
|||
import com.kms.yxgh.common.dto.WarningQueDto; |
|||
import com.kms.yxgh.common.dto.WarningStatisticDto; |
|||
import com.kms.yxgh.common.dto.WarningStatisticQueDto; |
|||
import com.kms.yxgh.common.mapper.WarningMapper; |
|||
import com.kms.yxgh.util.BeanCopyUtils; |
|||
import com.shuili.common.core.domain.SearchParam; |
|||
import com.shuili.common.core.domain.entity.SysDictData; |
|||
import com.shuili.common.utils.StringUtils; |
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Data; |
|||
import lombok.NoArgsConstructor; |
|||
import lombok.RequiredArgsConstructor; |
|||
import org.apache.commons.collections.CollectionUtils; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import javax.annotation.PostConstruct; |
|||
import java.io.Serializable; |
|||
import java.util.Calendar; |
|||
import java.util.Date; |
|||
import java.util.Optional; |
|||
import java.util.concurrent.TimeUnit; |
|||
import java.util.stream.Collectors; |
|||
|
|||
/** |
|||
* @ClassName: WarningService |
|||
* @Description: TODO |
|||
* @Date: 2024/3/18 上午11:12 |
|||
* * |
|||
* @author: hxh |
|||
* @version: 1.0 |
|||
*/ |
|||
|
|||
@Service |
|||
@RequiredArgsConstructor |
|||
public class WarningService { |
|||
|
|||
private final WarningMapper warningMapper; |
|||
private final SysDictDataMapper dictDataMapper; |
|||
|
|||
private LoadingCache<DictKey, SysDictData> dictDataCache; |
|||
|
|||
@PostConstruct |
|||
private void init() { |
|||
this.dictDataCache = Caffeine.newBuilder() |
|||
.maximumSize(1000) |
|||
.expireAfterWrite(10, TimeUnit.MINUTES) |
|||
.build(key -> dictDataMapper.selectOne(Wrappers.<SysDictData>lambdaQuery() |
|||
.eq(SysDictData::getDictType, key.getDictType()) |
|||
.eq(SysDictData::getDictValue, key.getDictValue()))); |
|||
} |
|||
|
|||
public IPage<WarningDto> selectPage(SearchParam<WarningQueDto> sp) { |
|||
Page<DeviceCheckingRecordView> page = new Page<>(sp.getPageNum(), sp.getPageSize()); |
|||
WarningQueDto data = Optional.ofNullable(sp.getData()).orElse(new WarningQueDto()); |
|||
LambdaQueryWrapper<DeviceCheckingRecordView> wrapper = Wrappers.<DeviceCheckingRecordView>lambdaQuery() |
|||
.like(StringUtils.isNotBlank(data.getName()), DeviceCheckingRecordView::getName, sp.getData().getName()) |
|||
.likeLeft(StringUtils.isNotBlank(data.getAdcd()), DeviceCheckingRecordView::getAdcd, sp.getData().getAdcd()) |
|||
.in(CollectionUtils.isNotEmpty(data.getTypes()), DeviceCheckingRecordView::getType, sp.getData().getTypes()); |
|||
|
|||
if (data.getStartTime() != null && data.getEndTime() != null) { |
|||
wrapper.between(DeviceCheckingRecordView::getWarningTime, data.getStartTime(), data.getEndTime()); |
|||
} else if (data.getFromTime() != null) { |
|||
Date time = getBeforeTime(data.getFromTime()); |
|||
wrapper.ge(DeviceCheckingRecordView::getWarningTime, time); |
|||
} |
|||
IPage<DeviceCheckingRecordView> iPage = warningMapper.selectPage(page, wrapper); |
|||
return iPage.convert(item -> { |
|||
WarningDto warningDto = new WarningDto(); |
|||
BeanCopyUtils.copy(item, warningDto); |
|||
return warningDto; |
|||
}); |
|||
} |
|||
|
|||
|
|||
//计算指定小时数前的时间
|
|||
private Date getBeforeTime(Integer fromTime) { |
|||
Calendar calendar = Calendar.getInstance(); |
|||
calendar.add(Calendar.HOUR, -fromTime); |
|||
return calendar.getTime(); |
|||
} |
|||
|
|||
public WarningStatisticDto statistic(WarningStatisticQueDto sp) { |
|||
Page<WarningStatisticDto.Statistic> page = new Page<>(1, sp.getTopN()); |
|||
page.setMaxLimit(Long.valueOf(sp.getTopN())); |
|||
|
|||
IPage<WarningStatisticDto.Statistic> iPage; |
|||
WarningStatisticDto warningStatisticDto = new WarningStatisticDto(); |
|||
if (WarningStatisticQueDto.StatisticType.ENGINEERING.equals(sp.getType())) { |
|||
iPage = warningMapper.statisticByCode(page, sp); |
|||
warningStatisticDto.setStatistics(iPage.getRecords()); |
|||
} else { |
|||
iPage = warningMapper.statisticByWarningType(page, sp); |
|||
warningStatisticDto.setStatistics(iPage.getRecords().stream().peek(item -> { |
|||
SysDictData dictData = dictDataCache.get(new DictKey("xc_warnning_type", item.getCode())); |
|||
if (dictData != null) { |
|||
item.setName(dictData.getDictLabel()); |
|||
} |
|||
}).collect(Collectors.toList())); |
|||
} |
|||
return warningStatisticDto; |
|||
} |
|||
|
|||
@Data |
|||
@AllArgsConstructor |
|||
@NoArgsConstructor |
|||
private static class DictKey implements Serializable { |
|||
private String dictType; |
|||
private String dictValue; |
|||
} |
|||
|
|||
} |
Loading…
Reference in new issue