20 changed files with 511 additions and 22 deletions
@ -0,0 +1,16 @@ |
|||||
|
package cn.iocoder.yudao.module.alert.controller.admin.warn.vo; |
||||
|
|
||||
|
import cn.iocoder.yudao.framework.common.pojo.PageParam; |
||||
|
import io.swagger.v3.oas.annotations.media.Schema; |
||||
|
import lombok.Data; |
||||
|
import lombok.EqualsAndHashCode; |
||||
|
|
||||
|
@Schema(description = "运行中心 - 预警分页 Request VO") |
||||
|
@Data |
||||
|
@EqualsAndHashCode(callSuper = true) |
||||
|
public class WarnPageReqVO extends PageParam { |
||||
|
|
||||
|
@Schema(description = "实例id", example = "id") |
||||
|
private Long mpId; |
||||
|
|
||||
|
} |
@ -0,0 +1,89 @@ |
|||||
|
package cn.iocoder.yudao.module.alert.controller.admin.warn.vo; |
||||
|
|
||||
|
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; |
||||
|
import io.swagger.v3.oas.annotations.media.Schema; |
||||
|
import lombok.Data; |
||||
|
import org.springframework.format.annotation.DateTimeFormat; |
||||
|
|
||||
|
import java.time.LocalDateTime; |
||||
|
|
||||
|
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; |
||||
|
|
||||
|
@Schema(description = "运行中心 - 预警分页 Request VO") |
||||
|
@Data |
||||
|
@ExcelIgnoreUnannotated |
||||
|
public class WarnRespVO { |
||||
|
@Schema(description = "预警id", example = "id") |
||||
|
private Long id; |
||||
|
|
||||
|
@Schema(description = "实例id", example = "id") |
||||
|
|
||||
|
private Long mpId; |
||||
|
@Schema(description = "点号", example = "id") |
||||
|
|
||||
|
private String pointId; |
||||
|
|
||||
|
@Schema(description = "点号描述", example = "id") |
||||
|
|
||||
|
private String pointName; |
||||
|
@Schema(description = "实例名称", example = "id") |
||||
|
|
||||
|
private String mpName; |
||||
|
|
||||
|
|
||||
|
private String unit; |
||||
|
|
||||
|
|
||||
|
|
||||
|
private Long alarmLevel; |
||||
|
|
||||
|
//报警类型
|
||||
|
private String alarmModelRuleName; |
||||
|
|
||||
|
|
||||
|
private String warnConstraint; |
||||
|
private String warnConstraintName; |
||||
|
|
||||
|
|
||||
|
|
||||
|
private String timeDurationThreshold; |
||||
|
|
||||
|
//短信开关
|
||||
|
private Long shortMessageOnOff; |
||||
|
//光字牌
|
||||
|
private Long gzpOnOff; |
||||
|
|
||||
|
private String gzpName; |
||||
|
|
||||
|
//推送诊断
|
||||
|
private Long copyToDiagOnOff; |
||||
|
|
||||
|
//已有实例数量
|
||||
|
private Long number; |
||||
|
|
||||
|
//参与报警
|
||||
|
private Long warnStatus; |
||||
|
|
||||
|
|
||||
|
|
||||
|
private Double uplimit; |
||||
|
|
||||
|
private Double lowlimit; |
||||
|
|
||||
|
private String systemName; |
||||
|
|
||||
|
/** |
||||
|
* 创建者-名称 |
||||
|
* |
||||
|
* |
||||
|
*/ |
||||
|
|
||||
|
private String createName; |
||||
|
/** |
||||
|
* 更新者-名称 |
||||
|
* |
||||
|
* |
||||
|
*/ |
||||
|
|
||||
|
private String updateName; |
||||
|
} |
@ -0,0 +1,50 @@ |
|||||
|
package cn.iocoder.yudao.module.alert.controller.admin.warn.vo; |
||||
|
|
||||
|
import cn.iocoder.yudao.module.alert.controller.admin.instant.vo.InstantInfoVO; |
||||
|
import com.fasterxml.jackson.annotation.JsonIgnore; |
||||
|
import com.mzt.logapi.starter.annotation.DiffLogField; |
||||
|
import io.swagger.v3.oas.annotations.media.Schema; |
||||
|
import jakarta.validation.constraints.NotNull; |
||||
|
import jakarta.validation.constraints.Size; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
@Schema(description = "运行中心 - 预警创建/更新 Request VO") |
||||
|
@Data |
||||
|
public class WarnSaveReqVO { |
||||
|
@Schema(description = "预警编号", example = "1") |
||||
|
@NotNull(message = "预警编号不能为空") |
||||
|
|
||||
|
private Long id; |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
@Schema(description = "参与报警", requiredMode = Schema.RequiredMode.REQUIRED,example = "1") |
||||
|
@DiffLogField(name = "参与报警") |
||||
|
private Long warnStatus; |
||||
|
|
||||
|
private Long timeDurationThreshold; |
||||
|
|
||||
|
private Long alarmLevel; |
||||
|
private String warnConstraint; |
||||
|
private String warnConstraintName; |
||||
|
//短信开关
|
||||
|
private Long shortMessageOnOff; |
||||
|
//光字牌
|
||||
|
private Long gzpOnOff; |
||||
|
|
||||
|
private String gzpName; |
||||
|
//推送诊断
|
||||
|
private Long copyToDiagOnOff; |
||||
|
|
||||
|
//已有实例数量
|
||||
|
private Long number; |
||||
|
|
||||
|
private Double uplimit; |
||||
|
|
||||
|
private Double lowlimit; |
||||
|
|
||||
|
|
||||
|
} |
@ -0,0 +1,59 @@ |
|||||
|
package cn.iocoder.yudao.module.alert.controller.admin.warn; |
||||
|
|
||||
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
||||
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
||||
|
import cn.iocoder.yudao.module.alert.controller.admin.instant.vo.InstantPageReqVO; |
||||
|
import cn.iocoder.yudao.module.alert.controller.admin.instant.vo.InstantRespVO; |
||||
|
import cn.iocoder.yudao.module.alert.controller.admin.instant.vo.InstantSaveReqVO; |
||||
|
import cn.iocoder.yudao.module.alert.controller.admin.warn.vo.WarnPageReqVO; |
||||
|
import cn.iocoder.yudao.module.alert.controller.admin.warn.vo.WarnRespVO; |
||||
|
import cn.iocoder.yudao.module.alert.controller.admin.warn.vo.WarnSaveReqVO; |
||||
|
import cn.iocoder.yudao.module.alert.dal.dataobject.instant.InstantDO; |
||||
|
import cn.iocoder.yudao.module.alert.dal.dataobject.warn.WarnDO; |
||||
|
import cn.iocoder.yudao.module.alert.service.instant.InstantService; |
||||
|
import cn.iocoder.yudao.module.alert.service.warn.WarnService; |
||||
|
import io.swagger.v3.oas.annotations.Operation; |
||||
|
import io.swagger.v3.oas.annotations.tags.Tag; |
||||
|
import jakarta.annotation.Resource; |
||||
|
import jakarta.validation.Valid; |
||||
|
import org.springframework.security.access.prepost.PreAuthorize; |
||||
|
import org.springframework.validation.annotation.Validated; |
||||
|
import org.springframework.web.bind.annotation.*; |
||||
|
|
||||
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
||||
|
|
||||
|
@Tag(name = "运行中心 - 预警") |
||||
|
@RestController |
||||
|
@RequestMapping("/alert/warn") |
||||
|
@Validated |
||||
|
public class warnController { |
||||
|
|
||||
|
|
||||
|
@Resource |
||||
|
private WarnService warnService; |
||||
|
|
||||
|
@GetMapping("/page") |
||||
|
@Operation(summary = "获得预警分页列表") |
||||
|
@PreAuthorize("@ss.hasPermission('run:warn:query')") |
||||
|
public CommonResult<PageResult<WarnRespVO>> getInstantPage(@Valid WarnPageReqVO pageReqVO) { |
||||
|
PageResult<WarnDO> pageResult = warnService.getWarnPage(pageReqVO); |
||||
|
return success(BeanUtils.toBean(pageResult, WarnRespVO.class)); |
||||
|
} |
||||
|
|
||||
|
@GetMapping("/get") |
||||
|
@Operation(summary = "获得预警信息") |
||||
|
@PreAuthorize("@ss.hasPermission('run:warn:query')") |
||||
|
public CommonResult<WarnRespVO> getWarn(@RequestParam("id") Long id) { |
||||
|
WarnDO warn = warnService.getWarn(id); |
||||
|
return success(BeanUtils.toBean(warn, WarnRespVO.class)); |
||||
|
} |
||||
|
|
||||
|
@PutMapping("/update") |
||||
|
@Operation(summary = "修改预警") |
||||
|
@PreAuthorize("@ss.hasPermission('run:warn:update')") |
||||
|
public CommonResult<Boolean> updateInstant(@Valid @RequestBody WarnSaveReqVO updateReqVO) { |
||||
|
warnService.updateWarn(updateReqVO); |
||||
|
return success(true); |
||||
|
} |
||||
|
} |
@ -0,0 +1,68 @@ |
|||||
|
package cn.iocoder.yudao.module.alert.dal.dataobject.warn; |
||||
|
|
||||
|
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
||||
|
import com.baomidou.mybatisplus.annotation.KeySequence; |
||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||
|
import lombok.Data; |
||||
|
import lombok.EqualsAndHashCode; |
||||
|
|
||||
|
import java.time.LocalDateTime; |
||||
|
|
||||
|
@TableName(value = "warn_online_cfg_view", autoResultMap = true) |
||||
|
@KeySequence("system_role_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
|
@Data |
||||
|
@EqualsAndHashCode(callSuper = true) |
||||
|
public class WarnDO extends BaseDO { |
||||
|
|
||||
|
private Long id; |
||||
|
|
||||
|
private Long mpId; |
||||
|
|
||||
|
private String pointId; |
||||
|
|
||||
|
|
||||
|
private String pointName; |
||||
|
|
||||
|
private String mpName; |
||||
|
|
||||
|
private String formula; |
||||
|
|
||||
|
private String unit; |
||||
|
|
||||
|
//报警类型-id
|
||||
|
private Long alarmLevel; |
||||
|
//报警类型
|
||||
|
private String alarmModelRuleName; |
||||
|
|
||||
|
private String warnConstraint; |
||||
|
private String warnConstraintName; |
||||
|
|
||||
|
|
||||
|
|
||||
|
private Long timeDurationThreshold; |
||||
|
|
||||
|
//短信开关
|
||||
|
private Long shortMessageOnOff; |
||||
|
//光字牌
|
||||
|
private Long gzpOnOff; |
||||
|
private String gzpName; |
||||
|
//推送诊断
|
||||
|
private Long copyToDiagOnOff; |
||||
|
|
||||
|
//已有实例数量
|
||||
|
private Long number; |
||||
|
|
||||
|
//参与报警
|
||||
|
private Long warnStatus; |
||||
|
|
||||
|
|
||||
|
|
||||
|
private Double uplimit; |
||||
|
|
||||
|
private Double lowlimit; |
||||
|
|
||||
|
private String systemName; |
||||
|
|
||||
|
private String createName; |
||||
|
private String updateName; |
||||
|
} |
@ -0,0 +1,60 @@ |
|||||
|
package cn.iocoder.yudao.module.alert.dal.dataobject.warn; |
||||
|
|
||||
|
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
||||
|
import com.baomidou.mybatisplus.annotation.KeySequence; |
||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||
|
import lombok.Data; |
||||
|
import lombok.EqualsAndHashCode; |
||||
|
|
||||
|
import java.time.LocalDateTime; |
||||
|
|
||||
|
@TableName(value = "warn_online_cfg", autoResultMap = true) |
||||
|
@KeySequence("system_role_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
|
@Data |
||||
|
@EqualsAndHashCode(callSuper = true) |
||||
|
public class WarnTableDO extends BaseDO { |
||||
|
|
||||
|
private Long id; |
||||
|
|
||||
|
private Long mpId; |
||||
|
|
||||
|
private String pointId; |
||||
|
|
||||
|
|
||||
|
private String pointName; |
||||
|
|
||||
|
private String mpName; |
||||
|
|
||||
|
private String formula; |
||||
|
|
||||
|
private String unit; |
||||
|
|
||||
|
//报警类型
|
||||
|
private String modelOrRule; |
||||
|
|
||||
|
|
||||
|
private String warnConstraint; |
||||
|
private String warnConstraintName; |
||||
|
private Long alarmLevel; |
||||
|
|
||||
|
|
||||
|
private Long timeDurationThreshold; |
||||
|
|
||||
|
//短信开关
|
||||
|
private Long shortMessageOnOff; |
||||
|
//光字牌
|
||||
|
private Long gzpOnOff; |
||||
|
private String gzpName; |
||||
|
//推送诊断
|
||||
|
private Long copyToDiagOnOff; |
||||
|
|
||||
|
//参与报警
|
||||
|
private Long warnStatus; |
||||
|
|
||||
|
|
||||
|
private Double uplimit; |
||||
|
|
||||
|
private Double lowlimit; |
||||
|
|
||||
|
|
||||
|
} |
@ -0,0 +1,20 @@ |
|||||
|
package cn.iocoder.yudao.module.alert.dal.mysql.warn; |
||||
|
|
||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
||||
|
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
||||
|
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
||||
|
import cn.iocoder.yudao.module.alert.controller.admin.instant.vo.InstantPageReqVO; |
||||
|
import cn.iocoder.yudao.module.alert.controller.admin.warn.vo.WarnPageReqVO; |
||||
|
import cn.iocoder.yudao.module.alert.dal.dataobject.instant.InstantDO; |
||||
|
import cn.iocoder.yudao.module.alert.dal.dataobject.warn.WarnDO; |
||||
|
import org.apache.ibatis.annotations.Mapper; |
||||
|
|
||||
|
@Mapper |
||||
|
public interface WarnMapper extends BaseMapperX<WarnDO> { |
||||
|
default PageResult<WarnDO> selectPage(WarnPageReqVO reqVO) { |
||||
|
return selectPage(reqVO, new LambdaQueryWrapperX<WarnDO>() |
||||
|
.likeIfPresent(WarnDO::getMpId, reqVO.getMpId().toString()) |
||||
|
.orderByAsc(WarnDO::getId)); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,9 @@ |
|||||
|
package cn.iocoder.yudao.module.alert.dal.mysql.warn; |
||||
|
|
||||
|
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
||||
|
import cn.iocoder.yudao.module.alert.dal.dataobject.warn.WarnTableDO; |
||||
|
import org.apache.ibatis.annotations.Mapper; |
||||
|
|
||||
|
@Mapper |
||||
|
public interface WarnTableMapper extends BaseMapperX<WarnTableDO> { |
||||
|
} |
@ -0,0 +1,30 @@ |
|||||
|
package cn.iocoder.yudao.module.alert.service.warn; |
||||
|
|
||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
||||
|
import cn.iocoder.yudao.module.alert.controller.admin.instant.vo.InstantSaveReqVO; |
||||
|
import cn.iocoder.yudao.module.alert.controller.admin.warn.vo.WarnPageReqVO; |
||||
|
import cn.iocoder.yudao.module.alert.controller.admin.warn.vo.WarnSaveReqVO; |
||||
|
import cn.iocoder.yudao.module.alert.dal.dataobject.instant.InstantDO; |
||||
|
import cn.iocoder.yudao.module.alert.dal.dataobject.warn.WarnDO; |
||||
|
import jakarta.validation.Valid; |
||||
|
|
||||
|
public interface WarnService { |
||||
|
/** |
||||
|
* 获得预警分页 |
||||
|
* |
||||
|
* @param reqVO 预警分页查询 |
||||
|
* @return 预警分页结果 |
||||
|
*/ |
||||
|
PageResult<WarnDO> getWarnPage(WarnPageReqVO reqVO); |
||||
|
|
||||
|
|
||||
|
WarnDO getWarn(Long id); |
||||
|
|
||||
|
/** |
||||
|
* 更新预警 |
||||
|
* |
||||
|
* @param updateReqVO 更新预警 |
||||
|
*/ |
||||
|
void updateWarn(@Valid WarnSaveReqVO updateReqVO); |
||||
|
|
||||
|
} |
@ -0,0 +1,81 @@ |
|||||
|
package cn.iocoder.yudao.module.alert.service.warn; |
||||
|
|
||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
||||
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
||||
|
import cn.iocoder.yudao.module.alert.controller.admin.instant.vo.InstantSaveReqVO; |
||||
|
import cn.iocoder.yudao.module.alert.controller.admin.warn.vo.WarnPageReqVO; |
||||
|
import cn.iocoder.yudao.module.alert.controller.admin.warn.vo.WarnSaveReqVO; |
||||
|
import cn.iocoder.yudao.module.alert.dal.dataobject.instant.InstantDO; |
||||
|
import cn.iocoder.yudao.module.alert.dal.dataobject.warn.WarnDO; |
||||
|
import cn.iocoder.yudao.module.alert.dal.dataobject.warn.WarnTableDO; |
||||
|
import cn.iocoder.yudao.module.alert.dal.mysql.warn.WarnMapper; |
||||
|
import cn.iocoder.yudao.module.alert.dal.mysql.warn.WarnTableMapper; |
||||
|
import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants; |
||||
|
import com.google.common.annotations.VisibleForTesting; |
||||
|
import com.mzt.logapi.context.LogRecordContext; |
||||
|
import com.mzt.logapi.service.impl.DiffParseFunction; |
||||
|
import com.mzt.logapi.starter.annotation.LogRecord; |
||||
|
import jakarta.annotation.Resource; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.cache.annotation.CacheEvict; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
||||
|
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.WARN_NOT_EXISTS; |
||||
|
import static cn.iocoder.yudao.module.system.enums.LogRecordConstants.*; |
||||
|
|
||||
|
@Service |
||||
|
@Slf4j |
||||
|
public class WarnServiceImpl implements WarnService { |
||||
|
@Resource |
||||
|
private WarnMapper warnMapper; |
||||
|
@Resource |
||||
|
private WarnTableMapper warnTableMapper; |
||||
|
|
||||
|
|
||||
|
@Override |
||||
|
public PageResult<WarnDO> getWarnPage(WarnPageReqVO reqVO) { |
||||
|
return warnMapper.selectPage(reqVO); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
@Override |
||||
|
public WarnDO getWarn(Long id) { |
||||
|
return warnMapper.selectById(id); |
||||
|
} |
||||
|
@Override |
||||
|
@CacheEvict(value = RedisKeyConstants.WARN, key = "#updateReqVO.id") |
||||
|
@LogRecord(type = SYSTEM_WARN_TYPE, subType = SYSTEM_WARN_UPDATE_SUB_TYPE, bizNo = "{{#updateReqVO.id}}", |
||||
|
success = SYSTEM_WARN_UPDATE_SUCCESS) |
||||
|
public void updateWarn(WarnSaveReqVO updateReqVO) { |
||||
|
//为简单--省去检验步骤,之后根据情况增加
|
||||
|
// 1.1 校验是否可以更新
|
||||
|
WarnDO warn = validateWarnForUpdate(updateReqVO.getId()); |
||||
|
// 1.2 校验角色的唯一字段是否重复
|
||||
|
// validateRoleDuplicate(updateReqVO.getName(), updateReqVO.getCode(), updateReqVO.getId());
|
||||
|
|
||||
|
// 2. 更新到数据库
|
||||
|
WarnTableDO updateObj = BeanUtils.toBean(updateReqVO, WarnTableDO.class); |
||||
|
warnTableMapper.updateById(updateObj); |
||||
|
|
||||
|
// 3. 记录操作日志上下文
|
||||
|
LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(warn, WarnSaveReqVO.class)); |
||||
|
LogRecordContext.putVariable("warn", warn); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 校验预警是否可以被更新 |
||||
|
* |
||||
|
* @param id 编号 |
||||
|
*/ |
||||
|
@VisibleForTesting |
||||
|
WarnDO validateWarnForUpdate(Long id) { |
||||
|
WarnDO warn = warnMapper.selectById(id); |
||||
|
if (warn == null) { |
||||
|
throw exception(WARN_NOT_EXISTS); |
||||
|
} |
||||
|
|
||||
|
return warn; |
||||
|
} |
||||
|
|
||||
|
} |
Loading…
Reference in new issue