diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/api/dto/message/MessageDTO.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/api/dto/message/MessageDTO.java index 0e7ee07b..a8c40b08 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/api/dto/message/MessageDTO.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/api/dto/message/MessageDTO.java @@ -78,8 +78,7 @@ public class MessageDTO implements Serializable { */ private String copyToUser; - public MessageDTO(){ - } + public MessageDTO(){} /** * 构造器1 系统消息 @@ -89,7 +88,7 @@ public class MessageDTO implements Serializable { this.toUser = toUser; this.title = title; this.content = content; - //默认 都是2系统消息 + //默认都是 2:系统消息 this.category = CommonConstant.MSG_CATEGORY_2; } @@ -104,6 +103,11 @@ public class MessageDTO implements Serializable { this.category = category; } + public MessageDTO(String title, String content) { + this.title = title; + this.content = content; + } + public boolean isMarkdown() { return this.isMarkdown; } diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/DateConstant.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/DateConstant.java new file mode 100644 index 00000000..98153e11 --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/DateConstant.java @@ -0,0 +1,14 @@ +package org.jeecg.common.constant; + +public interface DateConstant { + + String DATE = "yyyy-MM-dd"; + + String TIME = "HH:mm:ss"; + + String DATE_TIME = "yyyy-MM-dd HH:mm:ss"; + + String TIME_START = " 00:00:00"; + + String TIME_END = " 23:59:59"; +} diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/Prompt.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/Prompt.java new file mode 100644 index 00000000..9352948d --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/Prompt.java @@ -0,0 +1,29 @@ +package org.jeecg.common.constant; + +/** + * 提示信息公共常量类 + */ +public interface Prompt { + + String ADD_SUCC = "Add Success!"; + + String ADD_ERR = "Add Failure!"; + + String UPDATE_SUCC = "Modified Success!"; + + String UPDATE_ERR = "Modified Failure!"; + + String DELETE_SUCC = "Delete Success!"; + + String DELETE_ERR = "Delete Failure!"; + + String FILE_NOT_EXITS = "The File Does Not Exist!"; + + String DATA_NOT_EXITS = "The Query Data Does Not Exist!"; + + String DATA_IS_EMPTY = "The Query Data IS Empty!"; + + String FTP_ERR = "FTP Connection Failed!"; + + String NOT_REPEAT = " Can Not Repeat!"; +} diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/enums/MessageTypeEnum.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/enums/MessageTypeEnum.java index 1aa99ccb..679fdb83 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/enums/MessageTypeEnum.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/enums/MessageTypeEnum.java @@ -13,21 +13,22 @@ import java.util.List; @EnumDict("messageType") public enum MessageTypeEnum { + /* 发送全部 system|email|sms */ + ALL("all","所有消息","0"), /** 系统消息 */ - XT("system", "系统消息"), + XT("system", "系统消息", "1"), /** 邮件消息 */ - YJ("email", "邮件消息"), - /** 钉钉消息 */ - DD("dingtalk", "钉钉消息"), - /** 企业微信 */ - QYWX("wechat_enterprise", "企业微信"), - /* 邮箱消息 */ - YX("email-self", "邮箱消息"), + YJ("email", "邮件消息", "2"), /* 手机短信 */ - SMS("sms", "手机短信"); + SMS("sms", "手机短信", "3"), + /** 钉钉消息 */ + DD("dingtalk", "钉钉消息","4"), + /** 企业微信 */ + QYWX("wechat_enterprise", "企业微信", "5"); - MessageTypeEnum(String type, String note){ + MessageTypeEnum(String type, String note, String value){ this.type = type; + this.value = value; this.note = note; } @@ -36,6 +37,8 @@ public enum MessageTypeEnum { */ String type; + String value; + /** * 类型说明 */ @@ -57,6 +60,9 @@ public enum MessageTypeEnum { this.type = type; } + public String getValue() { + return value; + } /** * 获取字典数据 @@ -74,15 +80,9 @@ public enum MessageTypeEnum { return list; } - /** - * 根据type获取枚举 - * - * @param type - * @return - */ - public static MessageTypeEnum valueOfType(String type) { + public static MessageTypeEnum typeOf(String type) { for (MessageTypeEnum e : MessageTypeEnum.values()) { - if (e.getType().equals(type)) { + if (e.getValue().equals(type)) { return e; } } diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java index 91fdb36c..c23aa96a 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java @@ -8,6 +8,7 @@ import com.sun.mail.smtp.SMTPAddressFailedException; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ArrayUtils; import org.jeecg.common.api.dto.message.MessageDTO; +import org.jeecg.common.constant.SymbolConstant; import org.jeecg.common.email.emuns.MailContentType; import org.jeecg.modules.base.entity.SysEmail; import org.jetbrains.annotations.NotNull; @@ -186,18 +187,18 @@ public class EmailServiceManager { * @param messageDTO 消息dto */ private void reSendMail(Address[] invalid,MessageDTO messageDTO){ - List invalidList = Arrays.stream(invalid) + List invalidEmails = Arrays.stream(invalid) .map(address -> address.toString()) .collect(Collectors.toList()); - log.warn("部分或者全部邮件发送失败,无效的电子邮箱:{}",invalidList); - String[] allEmails = messageDTO.getToUser().split(","); + log.warn("部分或者全部邮件发送失败,无效的电子邮箱:{}",invalidEmails); + String[] allEmails = messageDTO.getToUser().split(SymbolConstant.COMMA); String[] emails = new String[]{}; - for (String address : invalidList) { + for (String address : invalidEmails) { emails = ArrayUtil.removeEle(allEmails,address); } // 如果移除无效电子邮箱后,待发送邮箱不为空 String toUser = Arrays.stream(emails) - .collect(Collectors.joining(",")); + .collect(Collectors.joining(SymbolConstant.COMMA)); if (StrUtil.isNotBlank(toUser)){ messageDTO.setToUser(toUser); sendMail(messageDTO); diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/AlarmRuleDto.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/AlarmRuleDto.java new file mode 100644 index 00000000..3c88ac32 --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/AlarmRuleDto.java @@ -0,0 +1,33 @@ +package org.jeecg.modules.base.dto; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.jeecg.modules.base.entity.Rule; +import org.springframework.format.annotation.DateTimeFormat; + +import java.io.Serializable; +import java.util.Date; + +@Data +public class AlarmRuleDto implements Serializable { + + private String id; + + private String name; + + private String operator; + + private Integer enabled; + + private String sourceName; + + private String groupName; + + private String sourceType; + + private String sourceId; +} diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/AlarmRuleInfo.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/AlarmRuleInfo.java new file mode 100644 index 00000000..e5572a70 --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/AlarmRuleInfo.java @@ -0,0 +1,27 @@ +package org.jeecg.modules.base.dto; + +import lombok.Data; +import java.io.Serializable; + + +@Data +public class AlarmRuleInfo implements Serializable { + + private String id; + + private String name; + + private String operator; + + private Long silenceCycle; + + private String contactId; + + private String sourceId; + + private String sourceType; + + private String itemId; + + private String sourceName; +} diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/DatabaseDto.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/DatabaseDto.java new file mode 100644 index 00000000..2e883212 --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/DatabaseDto.java @@ -0,0 +1,38 @@ +package org.jeecg.modules.base.dto; + +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; + +@Data +@Accessors(chain = true) +public class DatabaseDto implements Serializable { + private String id; + + private String name; + + private boolean online; + + private String ipAddress; + + private String port; + + private String slowQuery; + + private Integer alarms; + + private boolean alarmRed; + + private String cpuUutilzation; + + private boolean cpuRed; + + private String memoryUsage; + + private boolean memoryRed; + + private String diskUsage; + + private boolean diskRed; +} diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/EmailDto.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/EmailDto.java new file mode 100644 index 00000000..999524e9 --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/EmailDto.java @@ -0,0 +1,35 @@ +package org.jeecg.modules.base.dto; + +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; + +@Data +@Accessors(chain = true) +public class EmailDto implements Serializable { + + private String id; + + private String name; + + private Integer enabled; + + private boolean online; + + private String emailServerAddress; + + private Integer today; + + private Integer yesterday; + + private Integer weekly; + + private Integer alarms; + + private boolean alarmRed; + + private String stoerCapacity; + + private boolean stoerRed; +} diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/ItemDto.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/ItemDto.java index b3f6e889..4b9ac194 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/ItemDto.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/ItemDto.java @@ -1,25 +1,22 @@ package org.jeecg.modules.base.dto; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import lombok.Data; +import org.jeecg.modules.base.entity.monitor.Item; import java.io.Serializable; -import java.util.List; @Data -public class ItemDto implements Serializable { +public class ItemDto implements Serializable{ - private Double min; - - private Double max; - - private Double avg; - - private Double now; + private String itemId; private String name; private String units; - private List list; + public ItemDto(Item item) { + this.itemId = item.getItemId(); + this.name = item.getName(); + this.units = item.getUnits(); + } } diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/RuleDto.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/RuleDto.java index ed9e02f0..baa0ef1f 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/RuleDto.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/RuleDto.java @@ -3,7 +3,6 @@ package org.jeecg.modules.base.dto; import lombok.AllArgsConstructor; import lombok.Data; import lombok.experimental.Accessors; -import org.jeecg.modules.base.enums.Item; import org.jeecg.modules.base.enums.SourceType; import java.io.Serializable; diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/ServerDto.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/ServerDto.java new file mode 100644 index 00000000..f9fac5f1 --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/ServerDto.java @@ -0,0 +1,37 @@ +package org.jeecg.modules.base.dto; + +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; + +@Data +@Accessors(chain = true) +public class ServerDto implements Serializable { + + private String id; + + private String name; + + private boolean online; + + private String serverInfo; + + private String ipAddress; + + private Integer alarms; + + private boolean alarmRed; + + private String cpuUutilzation; + + private boolean cpuRed; + + private String memoryUsage; + + private boolean memoryRed; + + private String diskUsage; + + private boolean diskRed; +} diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/SourceDto.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/SourceDto.java new file mode 100644 index 00000000..2e20f8cb --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/SourceDto.java @@ -0,0 +1,12 @@ +package org.jeecg.modules.base.dto; + +import lombok.Data; +import java.io.Serializable; + +@Data +public class SourceDto implements Serializable { + + private String sourceId; + + private String sourceName; +} diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/AlarmItem.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/AlarmItem.java new file mode 100644 index 00000000..7e467055 --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/AlarmItem.java @@ -0,0 +1,23 @@ +package org.jeecg.modules.base.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import org.jeecg.common.system.base.entity.JeecgEntity; + +@Data +@TableName("alarm_item") +public class AlarmItem extends JeecgEntity { + + @TableField("name") + private String name; + + @TableField("units") + private String units; + + @TableField("description") + private String description; + + @TableField("source_id") + private String sourceId; +} diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/AlarmRule.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/AlarmRule.java index 84a6c898..be3a9ca9 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/AlarmRule.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/AlarmRule.java @@ -41,7 +41,7 @@ public class AlarmRule implements Serializable { private Long silenceCycle; /** - * 报警通知方式 1:短信 2.邮件 3.站内 + * 报警通知方式 3:短信 2.邮件 1.站内 0.全部 */ @TableField(value = "notification") private String notification; @@ -74,7 +74,7 @@ public class AlarmRule implements Serializable { * 监控项 */ @TableField(value = "item_id") - private Integer itemId; + private String itemId; /** * 创建时间 @@ -104,4 +104,9 @@ public class AlarmRule implements Serializable { @TableField(value = "update_by") private String updateBy; + /** + * 用于新增报警规则 + */ + @TableField(exist = false) + private Rule rule; } diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/Rule.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/Rule.java index ec1090fc..20ac0102 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/Rule.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/Rule.java @@ -12,6 +12,8 @@ public class Rule { private Double threshold; // 阈值 + private String units; // 单位 + @JsonIgnore private Double current; // 当前值 } diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/SysEmail.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/SysEmail.java index f890d35a..0d2c3573 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/SysEmail.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/SysEmail.java @@ -22,6 +22,9 @@ public class SysEmail implements Serializable { @TableId(value = "id", type = IdType.ASSIGN_ID) private String id; + @TableField("name") + private String name; + /** * email服务地址 */ diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/monitor/Host.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/monitor/Host.java new file mode 100644 index 00000000..190ef86c --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/monitor/Host.java @@ -0,0 +1,23 @@ +package org.jeecg.modules.base.entity.monitor; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.Data; +import java.io.Serializable; +import java.util.Map; + +@Data +@JsonIgnoreProperties(ignoreUnknown = true) +public class Host implements Serializable { + + private String code; + + private String name; + + private String hostId; + + private String status_dictText; + + private Map items; + + private String status; +} diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/monitor/Item.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/monitor/Item.java new file mode 100644 index 00000000..0b4196f7 --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/monitor/Item.java @@ -0,0 +1,21 @@ +package org.jeecg.modules.base.entity.monitor; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.Data; + +@Data +@JsonIgnoreProperties(ignoreUnknown = true) +public class Item { + + private String itemId; + + private String name; + + private String hostId; + + private String description; + + private String units; + + private String status; +} diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/monitor/ItemHistory.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/monitor/ItemHistory.java new file mode 100644 index 00000000..eb7e5bf3 --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/monitor/ItemHistory.java @@ -0,0 +1,24 @@ +package org.jeecg.modules.base.entity.monitor; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +@Data +@JsonIgnoreProperties(ignoreUnknown = true) +public class ItemHistory implements Serializable { + + private Double min; + + private Double max; + + private Double avg; + + private Double now; + + private String name; + + private String units; +} diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/monitor/Servers.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/monitor/Servers.java new file mode 100644 index 00000000..8bcf25f9 --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/monitor/Servers.java @@ -0,0 +1,13 @@ +package org.jeecg.modules.base.entity.monitor; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.Data; +import java.io.Serializable; +import java.util.List; + +@Data +@JsonIgnoreProperties(ignoreUnknown = true) +public class Servers implements Serializable { + + private List records; +} diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/enums/Item.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/enums/Item.java deleted file mode 100644 index 3061b959..00000000 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/enums/Item.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.jeecg.modules.base.enums; - -public enum Item { - - /* 服务器相关 */ - CPU_UTILIZ("cpu-utiliz"), - /* 邮箱服务相关 */ - CONN("conn"); - /* 数据库相关 */ - - - private String value; - - public String getValue() { - return value; - } - - Item(String value) { - this.value = value; - } -} diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/enums/Notific.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/enums/Notific.java deleted file mode 100644 index 5cdeaf76..00000000 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/enums/Notific.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.jeecg.modules.base.enums; - -public enum Notific { - SYSTEM("1"),EMAIL("2"),PHONE("3"); - - private String way; - - Notific(String way) { - this.way = way; - } - - public String getWay() { - return way; - } -} diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/enums/SourceType.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/enums/SourceType.java index 9550fd38..80d26281 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/enums/SourceType.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/enums/SourceType.java @@ -1,6 +1,8 @@ package org.jeecg.modules.base.enums; +import cn.hutool.core.util.StrUtil; + /** * 资源类型 * @@ -22,4 +24,12 @@ public enum SourceType { public String getType() { return type; } + + public static SourceType typeOf(String type){ + for (SourceType sourceType : SourceType.values()) { + if (StrUtil.equals(sourceType.getType(),type)) + return sourceType; + } + return null; + } } diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/vo/AlarmRuleVo.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/vo/AlarmRuleVo.java new file mode 100644 index 00000000..b363a0c7 --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/vo/AlarmRuleVo.java @@ -0,0 +1,21 @@ +package org.jeecg.modules.base.vo; + +import lombok.Data; +import org.jeecg.common.api.QueryRequest; + +import java.io.Serializable; + +@Data +public class AlarmRuleVo extends QueryRequest implements Serializable { + + private Integer enabled; + + private String sourceType; + + private String sourceId; + + private Integer pageStart; + + // 标记:根据条件查询但不进行分页 + private String pageFlag; +} diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/vo/SourceVo.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/vo/SourceVo.java new file mode 100644 index 00000000..fdc258b8 --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/vo/SourceVo.java @@ -0,0 +1,18 @@ +package org.jeecg.modules.base.vo; + +import lombok.Data; +import org.jeecg.common.api.QueryRequest; +import java.io.Serializable; +import java.util.List; + +@Data +public class SourceVo extends QueryRequest implements Serializable { + + private List sourceId; + + private String startDate; + + private String endDate; + + private Integer pageStart; +} diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/AlarmContactGroupController.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/AlarmContactGroupController.java index 25640db7..267bd125 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/AlarmContactGroupController.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/AlarmContactGroupController.java @@ -1,5 +1,6 @@ package org.jeecg.modules.controller; +import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.jeecg.common.api.QueryRequest; import org.jeecg.common.api.vo.Result; @@ -10,6 +11,7 @@ import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("alarmContactGroup") +@Api(value = "联系组管理", tags = "联系组管理") public class AlarmContactGroupController { @Autowired diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/AlarmContactGroupMemberController.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/AlarmContactGroupMemberController.java index 247bed1b..9fe3ac6f 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/AlarmContactGroupMemberController.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/AlarmContactGroupMemberController.java @@ -1,5 +1,6 @@ package org.jeecg.modules.controller; +import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.jeecg.common.api.QueryRequest; import org.jeecg.common.api.vo.Result; @@ -11,6 +12,7 @@ import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("alarmContactGroupMember") +@Api(value = "联系组成员管理", tags = "联系组成员管理") public class AlarmContactGroupMemberController { @Autowired diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/AlarmItemController.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/AlarmItemController.java new file mode 100644 index 00000000..4eb3fe0f --- /dev/null +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/AlarmItemController.java @@ -0,0 +1,31 @@ +package org.jeecg.modules.controller; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.jeecg.common.api.vo.Result; +import org.jeecg.common.aspect.annotation.AutoLog; +import org.jeecg.common.system.base.controller.JeecgController; +import org.jeecg.common.system.query.QueryGenerator; +import org.jeecg.modules.base.entity.AlarmItem; +import org.jeecg.modules.service.IAlarmItemService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.servlet.ModelAndView; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.Arrays; + +@Api(value = "监控项管理",tags = "监控项管理") +@RestController +@RequestMapping("/alarmitem") +public class AlarmItemController extends JeecgController { + + @Autowired + private IAlarmItemService alarmItemService; + + +} diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/AlarmRuleController.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/AlarmRuleController.java index 79e1bb50..4b181954 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/AlarmRuleController.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/AlarmRuleController.java @@ -2,31 +2,41 @@ package org.jeecg.modules.controller; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import org.jeecg.common.api.QueryRequest; import org.jeecg.common.api.vo.Result; import org.jeecg.modules.base.entity.AlarmRule; +import org.jeecg.modules.base.entity.monitor.Host; +import org.jeecg.modules.base.entity.monitor.Servers; +import org.jeecg.modules.base.vo.AlarmRuleVo; +import org.jeecg.modules.base.dto.ItemDto; +import org.jeecg.modules.feignclient.MonitorAlarm; import org.jeecg.modules.service.IAlarmRuleService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import java.util.*; +import java.util.stream.Collectors; + @RestController @RequestMapping("alarmRule") @Api(value = "报警规则管理", tags = "报警规则管理") public class AlarmRuleController { + @Autowired + private MonitorAlarm monitorAlarm; + @Autowired private IAlarmRuleService alarmRuleService; @GetMapping("findPage") - @ApiOperation(value = "分页查询报警规则信息", notes = "分页查询报警规则信息") - public Result findPage(QueryRequest queryRequest, AlarmRule alarmRule){ - return alarmRuleService.findPage(queryRequest, alarmRule); + @ApiOperation(value = "分页查询报警规则", notes = "分页查询报警规则") + public Result findPage(AlarmRuleVo alarmRuleVo){ + return alarmRuleService.findPage(alarmRuleVo); } @GetMapping("findInfo") @ApiOperation(value = "查看规则信息详情", notes = "查看规则信息详情") - public Result findInfo(String id){ - return alarmRuleService.findInfo(id); + public Result findInfo(@RequestParam String alarmRuleId){ + return alarmRuleService.findInfo(alarmRuleId); } @PostMapping("create") @@ -43,8 +53,36 @@ public class AlarmRuleController { @DeleteMapping("deleteById") @ApiOperation(value = "删除规则信息", notes = "删除规则信息") - public Result deleteById(String id){ - return alarmRuleService.deleteById(id); + public Result deleteById(@RequestParam String alarmRuleId){ + return alarmRuleService.deleteById(alarmRuleId); } + @GetMapping("getSources") + @ApiOperation(value = "根据资源类型获取资源",notes = "根据资源类型获取资源") + public Result getSources(@RequestParam String souceType){ + return alarmRuleService.getSourceByType(souceType); + } + + @GetMapping("getItems") + @ApiOperation(value = "根据资源名称获取监控项",notes = "根据资源名称获取监控项") + public Result getItems(@RequestParam String sourceName){ + Result result = monitorAlarm.listBack(sourceName); + List hosts = result.getResult().getRecords(); + List itemDtos = new ArrayList<>(); + for (Host host : hosts) { + boolean equals = host.getCode().equals(sourceName); + if(!equals)continue; + itemDtos = host.getItems().values().stream() + .map(ItemDto::new) + .collect(Collectors.toList()); + } + return Result.OK(itemDtos); + } + + @PutMapping("updateStatus") + @ApiOperation(value = "修改规则状态", notes = "修改规则状态") + public Result updateStatus(@RequestParam String alarmRuleId, + @RequestParam Integer enabled){ + return alarmRuleService.updateStatus(alarmRuleId,enabled); + } } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/SysDatabaseController.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/SysDatabaseController.java index b98a6045..8de5971f 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/SysDatabaseController.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/SysDatabaseController.java @@ -4,14 +4,14 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.jeecg.common.api.QueryRequest; import org.jeecg.common.api.vo.Result; +import org.jeecg.modules.base.dto.SourceDto; +import org.jeecg.modules.base.vo.SourceVo; import org.jeecg.modules.entity.SysDatabase; import org.jeecg.modules.service.ISysDatabaseService; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.format.annotation.DateTimeFormat; import org.springframework.web.bind.annotation.*; -import javax.validation.Valid; -import java.util.Date; +import java.util.List; @RestController @RequestMapping("sysDatabase") @@ -23,8 +23,8 @@ public class SysDatabaseController { @GetMapping("findPage") @ApiOperation(value = "分页查询数据库配置信息", notes = "分页查询数据库配置信息") - public Result findPage(QueryRequest queryRequest, SysDatabase sysDatabase){ - return sysDatabaseService.findPage(queryRequest, sysDatabase); + public Result findPage(QueryRequest query){ + return sysDatabaseService.findPage(query); } @GetMapping("findInfo") @@ -53,9 +53,14 @@ public class SysDatabaseController { @GetMapping("findAlarmHistory") @ApiOperation(value = "查询数据库历史报警信息", notes = "查询数据库历史报警信息") - public Result findAlarmHistory(String databaseId, - @DateTimeFormat(pattern = "yyyy-MM-dd") Date startTime, @DateTimeFormat(pattern = "yyyy-MM-dd") Date endTime){ - return sysDatabaseService.findAlarmHistory(databaseId, startTime, endTime); + public Result findAlarmHistory(SourceVo sourceVo){ + return sysDatabaseService.findAlarmHistory(sourceVo); } + @GetMapping("sourceList") + @ApiOperation(value = "数据库服务名列表",notes = "数据库服务名列表") + public Result sourceList(){ + List sourceDtos = sysDatabaseService.listAll(); + return Result.OK(sourceDtos); + } } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/SysEmailController.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/SysEmailController.java index c650ec73..382bae57 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/SysEmailController.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/SysEmailController.java @@ -5,16 +5,19 @@ import io.swagger.annotations.ApiOperation; import org.jeecg.common.api.QueryRequest; import org.jeecg.common.api.vo.Result; import org.jeecg.modules.base.entity.SysEmail; +import org.jeecg.modules.base.dto.SourceDto; +import org.jeecg.modules.base.vo.SourceVo; import org.jeecg.modules.service.ISysEmailService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.web.bind.annotation.*; import java.util.Date; +import java.util.List; @RestController @RequestMapping("sysEmail") -@Api(value = "邮箱配置信息管理", tags = "邮箱配置信息管理") +@Api(value = "邮箱配置管理", tags = "邮箱配置管理") public class SysEmailController { @Autowired @@ -22,8 +25,8 @@ public class SysEmailController { @GetMapping("findPage") @ApiOperation(value = "分页查询邮箱配置信息", notes = "分页查询邮箱配置信息") - public Result findPage(QueryRequest queryRequest, SysEmail sysEmail){ - return sysEmailService.findPage(queryRequest, sysEmail); + public Result findPage(QueryRequest query){ + return sysEmailService.findPage(query); } @GetMapping("findInfo") @@ -52,13 +55,20 @@ public class SysEmailController { @GetMapping("findAlarmHistory") @ApiOperation(value = "查询邮箱历史报警信息", notes = "查询邮箱历史报警信息") - public Result findAlarmHistory(String emailId, - @DateTimeFormat(pattern = "yyyy-MM-dd") Date startTime, @DateTimeFormat(pattern = "yyyy-MM-dd") Date endTime){ - return sysEmailService.findAlarmHistory(emailId, startTime, endTime); + public Result findAlarmHistory(SourceVo sourceVo){ + return sysEmailService.findAlarmHistory(sourceVo); } @GetMapping("getSender") + @ApiOperation(value = "获取发件邮箱服务器", notes = "获取发件邮箱服务器") public Result getSender(){ return sysEmailService.getSender(); } + + @GetMapping("sourceList") + @ApiOperation(value = "邮箱服务名列表",notes = "邮箱服务名列表") + public Result sourceList(){ + List sourceDtos = sysEmailService.listAll(); + return Result.OK(sourceDtos); + } } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/SysServerController.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/SysServerController.java index 73e45938..ca6f3488 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/SysServerController.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/SysServerController.java @@ -4,6 +4,8 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.jeecg.common.api.QueryRequest; import org.jeecg.common.api.vo.Result; +import org.jeecg.modules.base.dto.SourceDto; +import org.jeecg.modules.base.vo.SourceVo; import org.jeecg.modules.entity.SysServer; import org.jeecg.modules.service.ISysServerService; import org.springframework.beans.factory.annotation.Autowired; @@ -11,10 +13,11 @@ import org.springframework.format.annotation.DateTimeFormat; import org.springframework.web.bind.annotation.*; import java.util.Date; +import java.util.List; @RestController @RequestMapping("sysServer") -@Api(value = "服务器配置信息管理", tags = "服务器配置信息管理") +@Api(value = "服务器配置管理", tags = "服务器配置管理") public class SysServerController { @Autowired @@ -22,8 +25,8 @@ public class SysServerController { @GetMapping("findPage") @ApiOperation(value = "分页查询服务器数据", notes = "分页查询服务器数据") - public Result findPage(QueryRequest queryRequest, SysServer sysServer){ - return sysServerService.findPage(queryRequest, sysServer); + public Result findPage(QueryRequest query){ + return sysServerService.findPage(query); } @GetMapping("findInfo") @@ -52,9 +55,14 @@ public class SysServerController { @GetMapping("findAlarmHistory") @ApiOperation(value = "查询服务器历史报警信息", notes = "查询服务器历史报警信息") - public Result findAlarmHistory(String serverId, - @DateTimeFormat(pattern = "yyyy-MM-dd") Date startTime,@DateTimeFormat(pattern = "yyyy-MM-dd") Date endTime){ - return sysServerService.findAlarmHistory(serverId, startTime, endTime); + public Result findAlarmHistory(SourceVo sourceVo){ + return sysServerService.findAlarmHistory(sourceVo); } + @GetMapping("sourceList") + @ApiOperation(value = "服务器服务名列表",notes = "服务器服务名列表") + public Result sourceList(){ + List sourceDtos = sysServerService.listAll(); + return Result.OK(sourceDtos); + } } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/entity/AlarmHistory.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/entity/AlarmHistory.java index 8e5c4299..c9293c01 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/entity/AlarmHistory.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/entity/AlarmHistory.java @@ -36,4 +36,9 @@ public class AlarmHistory { * 来源类型 */ private String sourceType; + + /** + * 报警值 + */ + private String alarmValue; } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/feignclient/MonitorAlarm.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/feignclient/MonitorAlarm.java new file mode 100644 index 00000000..737ceba4 --- /dev/null +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/feignclient/MonitorAlarm.java @@ -0,0 +1,71 @@ +package org.jeecg.modules.feignclient; + +import org.jeecg.common.api.vo.Result; +import org.jeecg.modules.base.entity.monitor.ItemHistory; +import org.jeecg.modules.base.entity.monitor.Servers; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestParam; + +@Component +@FeignClient(name = "monitorAlarm",url = "http://218.249.158.97:7008/mobile/monitor") +public interface MonitorAlarm { + + // --------------------后端专用------------------- + @GetMapping("list") + Result listBack(@RequestParam String code); + + @GetMapping("queryItemHistory") + Result itemBack(@RequestParam String itemId, + @RequestParam Integer itemType, + @RequestParam String start, + @RequestParam String end); + + // --------------------返给前端------------------- + @GetMapping("list") + Result list(@RequestParam String code, + @RequestParam String hostId, + @RequestParam Integer pageNo, + @RequestParam Integer pageSize, + @RequestParam String status, + @RequestParam String type); + + @GetMapping("queryItemHistory") + Result item(@RequestParam String itemId, + @RequestParam Integer itemType, + @RequestParam String start, + @RequestParam String end); + + @GetMapping("queryItemHistoryData") + Result itemData(@RequestParam String itemId, + @RequestParam Integer itemType, + @RequestParam String start, + @RequestParam String end); + + @GetMapping("queryHostDetails") + Result detail(@RequestParam String hostId, + @RequestParam String pageName, + @RequestParam Integer pageNo, + @RequestParam Integer pageSize, + @RequestParam String start, + @RequestParam String end); + + @GetMapping("log") + Result log(@RequestParam String code, + @RequestParam String deviceType, + @RequestParam Integer pageNo, + @RequestParam Integer pageSize, + @RequestParam String start, + @RequestParam String end, + @RequestParam String status); + + @GetMapping("log/{hostId}") + Result OneLog(@PathVariable("hostId") String hostId, + @RequestParam Integer pageNo, + @RequestParam Integer pageSize, + @RequestParam String start, + @RequestParam String end, + @RequestParam String status); +} diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/AlarmItemMapper.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/AlarmItemMapper.java new file mode 100644 index 00000000..38dc9cd6 --- /dev/null +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/AlarmItemMapper.java @@ -0,0 +1,8 @@ +package org.jeecg.modules.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.jeecg.modules.base.entity.AlarmItem; + +public interface AlarmItemMapper extends BaseMapper { + +} diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/AlarmRuleMapper.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/AlarmRuleMapper.java index be5edef1..47c409df 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/AlarmRuleMapper.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/AlarmRuleMapper.java @@ -1,7 +1,16 @@ package org.jeecg.modules.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.jeecg.modules.base.dto.AlarmRuleDto; +import org.jeecg.modules.base.dto.AlarmRuleInfo; import org.jeecg.modules.base.entity.AlarmRule; +import java.util.List; +import java.util.Map; + public interface AlarmRuleMapper extends BaseMapper { + + List findPage(Map params); + + AlarmRuleInfo findInfo(String alarmRuleId); } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/SysDatabaseMapper.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/SysDatabaseMapper.java index c3be5b15..c55ef58e 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/SysDatabaseMapper.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/SysDatabaseMapper.java @@ -2,14 +2,18 @@ package org.jeecg.modules.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Param; +import org.jeecg.modules.base.dto.DatabaseDto; +import org.jeecg.modules.base.dto.ServerDto; import org.jeecg.modules.entity.AlarmHistory; import org.jeecg.modules.entity.SysDatabase; import java.util.Date; import java.util.List; +import java.util.Map; public interface SysDatabaseMapper extends BaseMapper { - List findAlarmHistory(@Param("databaseId") String databaseId, @Param("startDate") Date startDate, @Param("endDate") Date endDate); + List findAlarmHistory(Map params); + List findPage(Map params); } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/SysEmailMapper.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/SysEmailMapper.java index 69ea7234..8f6f68b8 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/SysEmailMapper.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/SysEmailMapper.java @@ -2,14 +2,18 @@ package org.jeecg.modules.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Param; +import org.jeecg.modules.base.dto.EmailDto; +import org.jeecg.modules.base.dto.ServerDto; import org.jeecg.modules.entity.AlarmHistory; import org.jeecg.modules.base.entity.SysEmail; import java.util.Date; import java.util.List; +import java.util.Map; public interface SysEmailMapper extends BaseMapper { - List findAlarmHistory( @Param("emailId") String emailId, @Param("startDate") Date startDate, @Param("endDate") Date endDate); + List findAlarmHistory(Map params); + List findPage(Map params); } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/SysServerMapper.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/SysServerMapper.java index 14a05596..04fbd07b 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/SysServerMapper.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/SysServerMapper.java @@ -2,14 +2,18 @@ package org.jeecg.modules.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; +import org.jeecg.modules.base.dto.ServerDto; import org.jeecg.modules.entity.AlarmHistory; import org.jeecg.modules.entity.SysServer; import java.util.Date; import java.util.List; +import java.util.Map; public interface SysServerMapper extends BaseMapper { - List findAlarmHistory(@Param("serverId")String serverId, @Param("startDate") Date startDate, @Param("endDate") Date endDate); + List findAlarmHistory(Map params); + List findPage(Map params); } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/xml/AlarmItemMapper.xml b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/xml/AlarmItemMapper.xml new file mode 100644 index 00000000..cee7fb37 --- /dev/null +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/xml/AlarmItemMapper.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/xml/AlarmLogMapper.xml b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/xml/AlarmLogMapper.xml index d2ee52ef..0efc08c0 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/xml/AlarmLogMapper.xml +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/xml/AlarmLogMapper.xml @@ -29,6 +29,7 @@ (SELECT l.alarm_start_date, l.alarm_info, + l.alarm_value, r.OPERATOR, r.source_type, CASE @@ -61,6 +62,7 @@ AND alarm_start_date <= #{endDate} + ORDER BY alarm_start_date DESC LIMIT #{pageSize} OFFSET #{pageStart} diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/xml/AlarmRuleMapper.xml b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/xml/AlarmRuleMapper.xml new file mode 100644 index 00000000..eeecf708 --- /dev/null +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/xml/AlarmRuleMapper.xml @@ -0,0 +1,76 @@ + + + + + + + \ No newline at end of file diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/xml/SysEmailMapper.xml b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/xml/SysEmailMapper.xml index 5d471498..0a0cbed5 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/xml/SysEmailMapper.xml +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/xml/SysEmailMapper.xml @@ -1,23 +1,52 @@ - + \ No newline at end of file diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/xml/SysServerMapper.xml b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/xml/SysServerMapper.xml index c8ff987a..2df95dba 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/xml/SysServerMapper.xml +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/xml/SysServerMapper.xml @@ -1,23 +1,51 @@ - + \ No newline at end of file diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/xml/sysDatabaseMapper.xml b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/xml/sysDatabaseMapper.xml index 5be1a952..5fcec19f 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/xml/sysDatabaseMapper.xml +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/xml/sysDatabaseMapper.xml @@ -4,20 +4,50 @@ + \ No newline at end of file diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/IAlarmContactGroupService.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/IAlarmContactGroupService.java index 7ce6721f..a3bf33e2 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/IAlarmContactGroupService.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/IAlarmContactGroupService.java @@ -19,4 +19,5 @@ public interface IAlarmContactGroupService extends IService { Result deleteUserById(String id, String userId); + AlarmContactGroup getByName(String groupName); } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/IAlarmItemService.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/IAlarmItemService.java new file mode 100644 index 00000000..ad0bda0c --- /dev/null +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/IAlarmItemService.java @@ -0,0 +1,9 @@ +package org.jeecg.modules.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import org.jeecg.common.api.vo.Result; +import org.jeecg.modules.base.entity.AlarmItem; + +public interface IAlarmItemService extends IService { + Result syncItem(String sourceType,String code); +} diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/IAlarmRuleService.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/IAlarmRuleService.java index 66c02eb8..c78db956 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/IAlarmRuleService.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/IAlarmRuleService.java @@ -4,16 +4,21 @@ import com.baomidou.mybatisplus.extension.service.IService; import org.jeecg.common.api.QueryRequest; import org.jeecg.common.api.vo.Result; import org.jeecg.modules.base.entity.AlarmRule; +import org.jeecg.modules.base.vo.AlarmRuleVo; public interface IAlarmRuleService extends IService { - Result findPage(QueryRequest queryRequest, AlarmRule alarmRule); + Result findPage(AlarmRuleVo alarmRuleVo); - Result findInfo(String id); + Result findInfo(String alarmRuleId); Result create(AlarmRule alarmRule); Result update(AlarmRule alarmRule); - Result deleteById(String id); + Result deleteById(String alarmRuleId); + + Result getSourceByType(String sourceType); + + Result updateStatus(String alarmRuleId,Integer enabled); } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/ISysDatabaseService.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/ISysDatabaseService.java index f5d6ced3..3435f05e 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/ISysDatabaseService.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/ISysDatabaseService.java @@ -3,14 +3,16 @@ package org.jeecg.modules.service; import com.baomidou.mybatisplus.extension.service.IService; import org.jeecg.common.api.QueryRequest; import org.jeecg.common.api.vo.Result; +import org.jeecg.modules.base.dto.SourceDto; +import org.jeecg.modules.base.vo.SourceVo; import org.jeecg.modules.entity.SysDatabase; -import org.springframework.format.annotation.DateTimeFormat; import java.util.Date; +import java.util.List; public interface ISysDatabaseService extends IService { - Result findPage(QueryRequest queryRequest, SysDatabase sysDatabase); + Result findPage(QueryRequest query); Result findInfo(String id); @@ -20,6 +22,7 @@ public interface ISysDatabaseService extends IService { Result deleteById(String id); - Result findAlarmHistory(String databaseId, Date startTime, Date endTime); + Result findAlarmHistory(SourceVo sourceVo); + List listAll(); } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/ISysEmailService.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/ISysEmailService.java index d4043716..07108647 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/ISysEmailService.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/ISysEmailService.java @@ -4,12 +4,15 @@ import com.baomidou.mybatisplus.extension.service.IService; import org.jeecg.common.api.QueryRequest; import org.jeecg.common.api.vo.Result; import org.jeecg.modules.base.entity.SysEmail; +import org.jeecg.modules.base.dto.SourceDto; +import org.jeecg.modules.base.vo.SourceVo; import java.util.Date; +import java.util.List; public interface ISysEmailService extends IService { - Result findPage(QueryRequest queryRequest, SysEmail sysEmail); + Result findPage(QueryRequest query); Result findInfo(String id); @@ -19,8 +22,9 @@ public interface ISysEmailService extends IService { Result deleteById(String id); - Result findAlarmHistory(String emailId, Date startTime, Date endTime); + Result findAlarmHistory(SourceVo sourceVo); Result getSender(); + List listAll(); } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/ISysServerService.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/ISysServerService.java index db5c97f0..593f8f9b 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/ISysServerService.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/ISysServerService.java @@ -3,13 +3,16 @@ package org.jeecg.modules.service; import com.baomidou.mybatisplus.extension.service.IService; import org.jeecg.common.api.QueryRequest; import org.jeecg.common.api.vo.Result; +import org.jeecg.modules.base.dto.SourceDto; +import org.jeecg.modules.base.vo.SourceVo; import org.jeecg.modules.entity.SysServer; import java.util.Date; +import java.util.List; public interface ISysServerService extends IService { - Result findPage(QueryRequest queryRequest, SysServer sysServer); + Result findPage(QueryRequest query); Result findInfo(String id); @@ -19,6 +22,9 @@ public interface ISysServerService extends IService { Result deleteById(String id); - Result findAlarmHistory(String serverId, Date startTime, Date endTime); + Result findAlarmHistory(SourceVo sourceVo); + List listAll(); + + String getByName(String name); } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmContactGroupServiceImpl.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmContactGroupServiceImpl.java index 75447336..bc9ef93b 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmContactGroupServiceImpl.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmContactGroupServiceImpl.java @@ -1,5 +1,7 @@ package org.jeecg.modules.service.impl; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.IdWorker; @@ -38,6 +40,7 @@ public class AlarmContactGroupServiceImpl extends ServiceImpl userList = systemClient.findUserMap(); Page page = new Page<>(queryRequest.getPageNo(), queryRequest.getPageSize()); LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.orderByDesc(AlarmContactGroup::getCreateTime); Page alarmContactGroupPage = this.baseMapper.selectPage(page, queryWrapper); LambdaQueryWrapper contactGroupMemberQueryWrapper = new LambdaQueryWrapper<>(); List alarmContactGroupMembers = alarmContactGroupMemberMapper.selectList(contactGroupMemberQueryWrapper); @@ -74,7 +77,7 @@ public class AlarmContactGroupServiceImpl extends ServiceImpl queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(AlarmContactGroup::getId, alarmContactGroup.getId()); AlarmContactGroup contactGroup = this.baseMapper.selectOne(queryWrapper); if (Objects.isNull(contactGroup)){ - result.error500("对应数据不存在"); + result.error500("The corresponding data does not exist!"); return result; } if (CollectionUtils.isNotEmpty(alarmContactGroup.getUserIds())){ @@ -150,7 +170,7 @@ public class AlarmContactGroupServiceImpl extends ServiceImpl wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(AlarmContactGroup::getName,groupName); + return getOne(wrapper); + } + } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmItemServiceImpl.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmItemServiceImpl.java new file mode 100644 index 00000000..3a94db81 --- /dev/null +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmItemServiceImpl.java @@ -0,0 +1,78 @@ +package org.jeecg.modules.service.impl; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.collection.ListUtil; +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.jeecg.common.api.vo.Result; +import org.jeecg.common.constant.Prompt; +import org.jeecg.modules.base.entity.AlarmItem; +import org.jeecg.modules.base.entity.monitor.Host; +import org.jeecg.modules.base.entity.monitor.Item; +import org.jeecg.modules.base.entity.monitor.Servers; +import org.jeecg.modules.feignclient.MonitorAlarm; +import org.jeecg.modules.mapper.AlarmItemMapper; +import org.jeecg.modules.service.IAlarmItemService; +import org.jeecg.modules.service.ISysDatabaseService; +import org.jeecg.modules.service.ISysServerService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +import static org.jeecg.modules.base.enums.SourceType.DATABASE; +import static org.jeecg.modules.base.enums.SourceType.SERVER; + + +@Service +public class AlarmItemServiceImpl extends ServiceImpl implements IAlarmItemService { + + @Autowired + private MonitorAlarm monitorAlarm; + + @Autowired + private ISysServerService serverService; + + @Autowired + private ISysDatabaseService databaseService; + + @Override + public Result syncItem(String type,String code) { + String sourceId = null; + if (SERVER.getType().equals(type)){ + sourceId = serverService.getByName(code); + } else if (DATABASE.getType().equals(type)) { + + }else { + return Result.error("Soucrce Type Not Extis!"); + } + if (StrUtil.isBlank(sourceId)) + return Result.error(Prompt.DATA_NOT_EXITS); + + Result result = monitorAlarm.listBack(code); + List hosts = result.getResult().getRecords(); + List items = new ArrayList<>(); + for (Host host : hosts) { + boolean equals = host.getCode().equals(code); + if(!equals) continue; + items = ListUtil.toList(host.getItems().values()); + } + if (CollUtil.isEmpty(items)) + return Result.error(Prompt.DATA_IS_EMPTY); + + List alarmItems = new ArrayList<>(); + for (Item item : items) { + AlarmItem alarmItem = new AlarmItem(); + alarmItem.setId(item.getItemId()); + alarmItem.setName(item.getName()); + alarmItem.setUnits(item.getUnits()); + alarmItem.setSourceId(sourceId); + alarmItem.setDescription(item.getDescription()); + alarmItems.add(alarmItem); + } + if(saveOrUpdateBatch(alarmItems)) + return Result.OK(Prompt.UPDATE_SUCC); + return Result.error(Prompt.UPDATE_ERR); + } +} diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmLogServiceImpl.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmLogServiceImpl.java index 18100f2a..f884fb90 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmLogServiceImpl.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmLogServiceImpl.java @@ -2,6 +2,7 @@ package org.jeecg.modules.service.impl; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.IdWorker; @@ -9,6 +10,7 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.jeecg.common.api.vo.Result; +import org.jeecg.common.constant.DateConstant; import org.jeecg.modules.dto.TypeDto; import org.jeecg.modules.entity.AlarmHistory; import org.jeecg.modules.base.entity.AlarmLog; @@ -35,6 +37,8 @@ public class AlarmLogServiceImpl extends ServiceImpl i public Result viewAll(AlarmVo alarmVo) { String startDate = alarmVo.getStartDate(); String endDate = alarmVo.getEndDate(); + boolean startNotBlank = StrUtil.isNotBlank(startDate); + boolean endtNotBlank = StrUtil.isNotBlank(endDate); // 拼接日期为合理的日期+时间范围 alarmVo.setStartDate(startDate + " 00:00:00"); alarmVo.setEndDate(endDate + " 23:59:59"); @@ -113,17 +117,22 @@ public class AlarmLogServiceImpl extends ServiceImpl i public Result findPage(AlarmVo alarmVo) { Integer pageNo = alarmVo.getPageNo(); Integer pageSize = alarmVo.getPageSize(); - Page page = new Page<>(pageNo,pageSize); + String startDate = alarmVo.getStartDate(); + String endDate = alarmVo.getEndDate(); + if (StrUtil.isNotBlank(startDate)) + alarmVo.setStartDate(startDate + DateConstant.TIME_START); + if (StrUtil.isNotBlank(endDate)) + alarmVo.setEndDate(endDate + DateConstant.TIME_END); Integer pageStart = (pageNo - 1) * pageSize; alarmVo.setPageStart(pageStart); Map params = BeanUtil.beanToMap(alarmVo); List alarmHistories = baseMapper.findPage(params); - // 当前页数据 - page.setRecords(alarmHistories); // 获取数据总条数(经过查询条件过滤后的) params.put("pageFlag","noPage"); Integer total = baseMapper.findPage(params).size(); - page.setTotal(total); + Page page = new Page<>(pageNo,pageSize,total); + // 当前页数据 + page.setRecords(alarmHistories); return Result.OK(page); } @@ -134,6 +143,12 @@ public class AlarmLogServiceImpl extends ServiceImpl i @Override public Result typeAlarms(AlarmVo alarmVo) { /* 饼图数据 */ + String startDate = alarmVo.getStartDate(); + String endDate = alarmVo.getEndDate(); + boolean startNotBlank = StrUtil.isNotBlank(startDate); + boolean endtNotBlank = StrUtil.isNotBlank(endDate); + if (startNotBlank) alarmVo.setStartDate(startDate +" 00:00:00"); + if (endtNotBlank)alarmVo.setEndDate(endDate +" 23:59:59"); // 警报类型-警报数 Map params = BeanUtil.beanToMap(alarmVo); List typeAlarms = baseMapper.typeAlarms(params); @@ -152,6 +167,12 @@ public class AlarmLogServiceImpl extends ServiceImpl i @Override public Result ruleTop5(AlarmVo alarmVo) { /* 柱状图数据 */ + String startDate = alarmVo.getStartDate(); + String endDate = alarmVo.getEndDate(); + boolean startNotBlank = StrUtil.isNotBlank(startDate); + boolean endtNotBlank = StrUtil.isNotBlank(endDate); + if (startNotBlank) alarmVo.setStartDate(startDate +" 00:00:00"); + if (endtNotBlank)alarmVo.setEndDate(endDate +" 23:59:59"); Map params = BeanUtil.beanToMap(alarmVo); List ruleTop5 = baseMapper.ruleTop5(params); // x轴数据 diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmRuleServiceImpl.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmRuleServiceImpl.java index fd0067f7..8658bc6b 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmRuleServiceImpl.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmRuleServiceImpl.java @@ -1,130 +1,132 @@ package org.jeecg.modules.service.impl; +import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.toolkit.IdWorker; -import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Multimap; -import org.jeecg.common.api.QueryRequest; import org.jeecg.common.api.vo.Result; import org.jeecg.common.constant.CommonConstant; +import org.jeecg.common.constant.Prompt; import org.jeecg.common.constant.SymbolConstant; -import org.jeecg.common.system.util.JwtUtil; import org.jeecg.common.util.RedisStreamUtil; -import org.jeecg.common.util.RedisUtil; -import org.jeecg.common.util.SpringContextUtils; +import org.jeecg.modules.base.dto.AlarmRuleDto; +import org.jeecg.modules.base.dto.AlarmRuleInfo; import org.jeecg.modules.base.entity.AlarmRule; +import org.jeecg.modules.base.entity.Rule; +import org.jeecg.modules.base.vo.AlarmRuleVo; +import org.jeecg.modules.base.dto.SourceDto; import org.jeecg.modules.mapper.AlarmRuleMapper; import org.jeecg.modules.service.IAlarmRuleService; +import org.jeecg.modules.service.ISysDatabaseService; +import org.jeecg.modules.service.ISysEmailService; +import org.jeecg.modules.service.ISysServerService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.annotation.PostConstruct; -import javax.servlet.http.HttpServletRequest; import java.util.*; +import static org.jeecg.modules.base.enums.SourceType.*; + @Service("alarmRuleService") public class AlarmRuleServiceImpl extends ServiceImpl implements IAlarmRuleService { - @Autowired - private RedisUtil redisUtil; - @Autowired private RedisStreamUtil redisStreamUtil; + @Autowired + private ISysEmailService emailService; + + @Autowired + private ISysServerService serverService; + + @Autowired + private ISysDatabaseService databaseService; + @Override - public Result findPage(QueryRequest queryRequest, AlarmRule alarmRule) { - Result result = new Result(); - Page page = new Page<>(queryRequest.getPageNo(), queryRequest.getPageSize()); - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(Objects.nonNull(alarmRule.getEnabled()), AlarmRule::getEnabled, alarmRule.getEnabled()); - queryWrapper.eq(StringUtils.isNotBlank(alarmRule.getSourceId()), AlarmRule::getSourceId, alarmRule.getSourceId()); - Page alarmRulePage = this.baseMapper.selectPage(page, queryWrapper); - result.setSuccess(true); - result.setResult(alarmRulePage); - return result; + public Result findPage(AlarmRuleVo alarmRuleVo) { + Integer pageNo = alarmRuleVo.getPageNo(); + Integer pageSize = alarmRuleVo.getPageSize(); + Page page = new Page<>(pageNo,pageSize); + Integer pageStart = (pageNo - 1) * pageSize; + alarmRuleVo.setPageStart(pageStart); + Map params = BeanUtil.beanToMap(alarmRuleVo); + List alarmHistories = baseMapper.findPage(params); + // 当前页数据 + page.setRecords(alarmHistories); + // 获取数据总条数(经过查询条件过滤后的) + params.put("pageFlag","noPage"); + Integer total = baseMapper.findPage(params).size(); + page.setTotal(total); + return Result.OK(page); } @Override - public Result findInfo(String id) { - Result result = new Result(); - //根据id查询对应数据信息 - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(AlarmRule::getId, id); - AlarmRule alarmRule = this.baseMapper.selectOne(queryWrapper); - if (Objects.isNull(alarmRule)){ - result.error500("查询数据不存在"); - return result; - } - result.setSuccess(true); - result.setResult(alarmRule); - return result; + public Result findInfo(String alarmRuleId) { + AlarmRuleInfo alarmRuleInfo = baseMapper.findInfo(alarmRuleId); + return Result.OK(alarmRuleInfo); } @Override public Result create(AlarmRule alarmRule) { - Result result = new Result(); - //获取request - HttpServletRequest request = SpringContextUtils.getHttpServletRequest(); - //获取当前操作人用户名 - String username = JwtUtil.getUserNameByToken(request); - Long id = IdWorker.getId(); - alarmRule.setId(id.toString()); - alarmRule.setCreateTime(new Date()); - alarmRule.setCreateBy(username); - if (StringUtils.isNotBlank(alarmRule.getOperator())){ - String jsonString = JSON.toJSONString(alarmRule.getOperator()); - alarmRule.setOperator(jsonString); + Rule rule = alarmRule.getRule(); + if (ObjectUtil.isNotNull(rule)){ + String operator = JSON.toJSONString(rule); + alarmRule.setOperator(operator); } this.baseMapper.insert(alarmRule); - result.setSuccess(true); - result.success("新增成功"); - // 同步Redis rule2Redis(); - return result; + return Result.OK(Prompt.ADD_SUCC); } @Override public Result update(AlarmRule alarmRule) { - Result result = new Result(); - //获取request - HttpServletRequest request = SpringContextUtils.getHttpServletRequest(); - //获取当前操作人用户名 - String username = JwtUtil.getUserNameByToken(request); - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(AlarmRule::getId, alarmRule.getId()); - AlarmRule rule = this.baseMapper.selectOne(queryWrapper); - if (Objects.isNull(rule)){ - result.error500("对应数据不存在"); - return result; + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(AlarmRule::getId, alarmRule.getId()); + AlarmRule alarmRuleOld = this.baseMapper.selectOne(wrapper); + if (ObjectUtil.isNull(alarmRuleOld)){ + return Result.error(Prompt.DATA_NOT_EXITS); } - alarmRule.setUpdateTime(new Date()); - alarmRule.setUpdateBy(username); - if (StringUtils.isNotBlank(alarmRule.getOperator())){ - String jsonString = JSON.toJSONString(alarmRule.getOperator()); - alarmRule.setOperator(jsonString); + Rule rule = alarmRule.getRule(); + if (ObjectUtil.isNotNull(rule)){ + String operator = JSON.toJSONString(rule); + alarmRule.setOperator(operator); } this.baseMapper.updateById(alarmRule); - result.setSuccess(true); - result.success("修改成功"); - // 同步Redis rule2Redis(); - return result; + return Result.OK(Prompt.UPDATE_SUCC); } @Override - public Result deleteById(String id) { - Result result = new Result(); - this.baseMapper.deleteById(id); - result.setSuccess(true); - result.success("删除成功"); - // 同步Redis + public Result deleteById(String alarmRuleId) { + this.baseMapper.deleteById(alarmRuleId); rule2Redis(); - return result; + return Result.OK(Prompt.DELETE_SUCC); + } + + @Override + public Result getSourceByType(String sourceType) { + List sourceDtos = new ArrayList<>(); + if (EMAIL.getType().equals(sourceType)){ + sourceDtos = emailService.listAll(); + } else if (DATABASE.getType().equals(sourceType)) { + sourceDtos = databaseService.listAll(); + } else if (SERVER.getType().equals(sourceType)) { + sourceDtos = serverService.listAll(); + } + return Result.OK(sourceDtos); + } + + @Override + public Result updateStatus(String alarmRuleId,Integer enabled) { + AlarmRule alarmRule = new AlarmRule(); + alarmRule.setId(alarmRuleId); + alarmRule.setEnabled(enabled); + if (updateById(alarmRule)) + return Result.OK(Prompt.UPDATE_SUCC); + return Result.error(Prompt.UPDATE_ERR); } /* diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysDatabaseServiceImpl.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysDatabaseServiceImpl.java index bc7eeeb7..9852202f 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysDatabaseServiceImpl.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysDatabaseServiceImpl.java @@ -1,14 +1,20 @@ package org.jeecg.modules.service.impl; +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; 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 org.jeecg.common.api.QueryRequest; import org.jeecg.common.api.vo.Result; -import org.jeecg.common.system.util.JwtUtil; +import org.jeecg.common.constant.DateConstant; +import org.jeecg.common.constant.Prompt; import org.jeecg.common.util.DateUtils; -import org.jeecg.common.util.SpringContextUtils; +import org.jeecg.modules.base.dto.DatabaseDto; +import org.jeecg.modules.base.dto.SourceDto; +import org.jeecg.modules.base.vo.SourceVo; import org.jeecg.modules.entity.AlarmHistory; import org.jeecg.modules.entity.SysDatabase; import org.jeecg.modules.mapper.SysDatabaseMapper; @@ -16,27 +22,40 @@ import org.jeecg.modules.service.ISysDatabaseService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import javax.servlet.http.HttpServletRequest; import java.text.ParseException; import java.time.LocalDate; -import java.util.Date; -import java.util.List; -import java.util.Objects; +import java.time.format.DateTimeFormatter; +import java.util.*; @Service("sysDatabaseService") public class SysDatabaseServiceImpl extends ServiceImpl implements ISysDatabaseService { @Override - public Result findPage(QueryRequest queryRequest, SysDatabase sysDatabase) { - Result result = new Result(); - //声明page - Page page = new Page<>(queryRequest.getPageNo(), queryRequest.getPageSize()); - //分页查询数据库配置信息 - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - Page sysDatabasePage = this.baseMapper.selectPage(page, queryWrapper); - result.setSuccess(true); - result.setResult(sysDatabasePage); - return result; + public Result findPage(QueryRequest query) { + Integer pageNo = query.getPageNo(); + Integer pageSize = query.getPageSize(); + Integer pageStart = (pageNo - 1) * pageSize; + Map params = new HashMap<>(); + params.put("pageSize",pageSize); + params.put("pageStart",pageStart); + DateTimeFormatter formatter = DateTimeFormatter + .ofPattern(DateConstant.DATE); + String date = LocalDate.now().format(formatter); + String startDate = date + DateConstant.TIME_START; + String endDate = date + DateConstant.TIME_END; + params.put("startDate",startDate); + params.put("endDate",endDate); + List databaseDtos = baseMapper.findPage(params); + for (DatabaseDto databaseDto : databaseDtos) { + databaseDto.setOnline(true).setSlowQuery("328/s") + .setAlarmRed(true).setCpuUutilzation("35.8%") + .setMemoryUsage("55.8%").setDiskUsage("35.68%"); + } + params.put("pageFlag","noPage"); + long total = baseMapper.findPage(params).size(); + Page page = new Page<>(pageNo, pageSize, total); + page.setRecords(databaseDtos); + return Result.OK(page); } @Override @@ -57,76 +76,92 @@ public class SysDatabaseServiceImpl extends ServiceImpl wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(SysDatabase::getName,name); + if (CollUtil.isNotEmpty(list(wrapper))) + return Result.error("Name"+Prompt.NOT_REPEAT); + wrapper.clear(); + wrapper.eq(SysDatabase::getIpAddress,ipAddress); + if (CollUtil.isNotEmpty(list(wrapper))) + return Result.error("IP Address"+Prompt.NOT_REPEAT); + + int count = baseMapper.insert(sysDatabase); + if (count == 1) + return Result.OK(Prompt.ADD_SUCC); + return Result.error(Prompt.ADD_ERR); } @Override @Transactional public Result update(SysDatabase sysDatabase) { - Result result = new Result(); - //获取request - HttpServletRequest request = SpringContextUtils.getHttpServletRequest(); - //获取当前操作人用户名 - String username = JwtUtil.getUserNameByToken(request); - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(SysDatabase::getId, sysDatabase.getId()); - SysDatabase database = this.baseMapper.selectOne(queryWrapper); - if (Objects.isNull(database)){ - result.error500("对应数据不存在,修改失败"); - return result; + SysDatabase database = getById(sysDatabase.getId()); + if (ObjectUtil.isNull(database)) + return Result.error(Prompt.DATA_NOT_EXITS); + String name = sysDatabase.getName(); + String ipAddress = sysDatabase.getIpAddress(); + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + if (!StrUtil.equals(name,database.getName())){ + wrapper.eq(SysDatabase::getName,name); + if (CollUtil.isNotEmpty(list(wrapper))) + return Result.error("Name" + Prompt.NOT_REPEAT); + wrapper.clear(); } - sysDatabase.setUpdateTime(LocalDate.now()); - sysDatabase.setUpdateBy(username); - this.baseMapper.updateById(sysDatabase); - result.setSuccess(true); - result.success("修改成功"); - return result; + if (!StrUtil.equals(ipAddress,database.getIpAddress())){ + wrapper.eq(SysDatabase::getIpAddress,ipAddress); + if (CollUtil.isNotEmpty(list(wrapper))) + return Result.error("IP Address" + Prompt.NOT_REPEAT); + } + int count = baseMapper.updateById(sysDatabase); + if (count == 1) + return Result.OK(Prompt.UPDATE_SUCC); + return Result.error(Prompt.UPDATE_ERR); } @Override @Transactional public Result deleteById(String id) { - Result result = new Result(); - this.baseMapper.deleteById(id); - result.setSuccess(true); - result.success("删除成功"); - return result; + int count = baseMapper.deleteById(id); + if(count == 1) + return Result.OK(Prompt.DELETE_SUCC); + return Result.error(Prompt.DELETE_ERR); } @Override - public Result findAlarmHistory(String databaseId, Date startTime, Date endTime) { - Result result = new Result(); - try { - if (Objects.isNull(startTime)){ - result.error500("开始时间不能为空"); - return result; - } - if (Objects.isNull(endTime)){ - result.error500("结束时间不能为空"); - return result; - } - Date startDate = DateUtils.parseDate(DateUtils.formatDate(startTime, "yyyy-MM-dd") + " 00:00:00", "yyyy-MM-dd HH:mm:ss"); - Date endDate = DateUtils.parseDate(DateUtils.formatDate(endTime, "yyyy-MM-dd") + " 23:59:59", "yyyy-MM-dd HH:mm:ss"); - List alarmHistory = this.baseMapper.findAlarmHistory(databaseId, startDate, endDate); - result.setSuccess(true); - result.setResult(alarmHistory); - } catch (ParseException e) { - throw new RuntimeException(e); + public Result findAlarmHistory(SourceVo sourceVo) { + String startDate = sourceVo.getStartDate(); + String endDate = sourceVo.getEndDate(); + if (StrUtil.isNotBlank(startDate)) + sourceVo.setStartDate(startDate + DateConstant.TIME_START); + if (StrUtil.isNotBlank(endDate)) + sourceVo.setStartDate(endDate + DateConstant.TIME_END); + Integer pageNo = sourceVo.getPageNo(); + Integer pageSize = sourceVo.getPageSize(); + Integer pageStart = (pageNo - 1) * pageSize; + sourceVo.setPageStart(pageStart); + Map params = BeanUtil.beanToMap(sourceVo); + List alarmHistories = baseMapper.findAlarmHistory(params); + // 获取数据总条数(经过查询条件过滤后的) + params.put("pageFlag","noPage"); + Integer total = baseMapper.findAlarmHistory(params).size(); + Page page = new Page<>(pageNo,pageSize,total); + // 当前页数据 + page.setRecords(alarmHistories); + return Result.OK(page); + } + + @Override + public List listAll() { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + List sourceDtos = new ArrayList<>(); + for (SysDatabase sysDatabase : list()) { + SourceDto sourceDto = new SourceDto(); + sourceDto.setSourceId(sysDatabase.getId()); + sourceDto.setSourceName(sysDatabase.getName()); + sourceDtos.add(sourceDto); } - return result; + return sourceDtos; } } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysEmailServiceImpl.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysEmailServiceImpl.java index 6ec374b3..68bdcc84 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysEmailServiceImpl.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysEmailServiceImpl.java @@ -1,16 +1,22 @@ package org.jeecg.modules.service.impl; +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; 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 org.jeecg.common.api.QueryRequest; import org.jeecg.common.api.vo.Result; import org.jeecg.common.constant.CommonConstant; +import org.jeecg.common.constant.DateConstant; +import org.jeecg.common.constant.Prompt; import org.jeecg.common.email.emuns.SysMailType; -import org.jeecg.common.system.util.JwtUtil; import org.jeecg.common.util.DateUtils; -import org.jeecg.common.util.SpringContextUtils; +import org.jeecg.modules.base.dto.EmailDto; +import org.jeecg.modules.base.dto.SourceDto; +import org.jeecg.modules.base.vo.SourceVo; import org.jeecg.modules.entity.AlarmHistory; import org.jeecg.modules.base.entity.SysEmail; import org.jeecg.modules.mapper.SysEmailMapper; @@ -18,27 +24,40 @@ import org.jeecg.modules.service.ISysEmailService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import javax.servlet.http.HttpServletRequest; import java.text.ParseException; import java.time.LocalDate; -import java.util.Date; -import java.util.List; -import java.util.Objects; +import java.time.format.DateTimeFormatter; +import java.util.*; @Service("sysEmailService") public class SysEmailServiceImpl extends ServiceImpl implements ISysEmailService { @Override - public Result findPage(QueryRequest queryRequest, SysEmail sysEmail) { - Result result = new Result(); - //声明page - Page page = new Page<>(queryRequest.getPageNo(), queryRequest.getPageSize()); - //分页查询邮箱配置数据 - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - Page sysEmailPage = this.baseMapper.selectPage(page, queryWrapper); - result.setSuccess(true); - result.setResult(sysEmailPage); - return result; + public Result findPage(QueryRequest query) { + Integer pageNo = query.getPageNo(); + Integer pageSize = query.getPageSize(); + Integer pageStart = (pageNo - 1) * pageSize; + Map params = new HashMap<>(); + params.put("pageSize",pageSize); + params.put("pageStart",pageStart); + DateTimeFormatter formatter = DateTimeFormatter + .ofPattern(DateConstant.DATE); + String date = LocalDate.now().format(formatter); + String startDate = date + DateConstant.TIME_START; + String endDate = date + DateConstant.TIME_END; + params.put("startDate",startDate); + params.put("endDate",endDate); + List emailDtos = baseMapper.findPage(params); + for (EmailDto emailDto : emailDtos) { + emailDto.setOnline(true).setToday(2) + .setYesterday(5).setWeekly(7) + .setStoerCapacity("100%").setStoerRed(true); + } + params.put("pageFlag","noPage"); + long total = baseMapper.findPage(params).size(); + Page page = new Page<>(pageNo, pageSize, total); + page.setRecords(emailDtos); + return Result.OK(page); } @Override @@ -60,79 +79,68 @@ public class SysEmailServiceImpl extends ServiceImpl i @Override @Transactional public Result create(SysEmail sysEmail) { - Result result = new Result(); - //获取request - HttpServletRequest request = SpringContextUtils.getHttpServletRequest(); - //获取当前操作人用户名 - String username = JwtUtil.getUserNameByToken(request); - //声明id - Long id = IdWorker.getId(); - sysEmail.setId(id.toString()); - //创建时间 - sysEmail.setCreateTime(LocalDate.now()); - sysEmail.setCreateBy(username); - this.baseMapper.insert(sysEmail); - result.setSuccess(true); - result.success("新增成功"); - return result; + String name = sysEmail.getName(); + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(SysEmail::getName,name); + if (CollUtil.isNotEmpty(list(wrapper))) + return Result.error("Name"+Prompt.NOT_REPEAT); + + int count = baseMapper.insert(sysEmail); + if (count == 1) + return Result.OK(Prompt.ADD_SUCC); + return Result.error(Prompt.ADD_ERR); } @Override @Transactional public Result update(SysEmail sysEmail) { - Result result = new Result(); - //获取request - HttpServletRequest request = SpringContextUtils.getHttpServletRequest(); - //获取当前操作人用户名 - String username = JwtUtil.getUserNameByToken(request); - //根据id查询数据 - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(SysEmail::getId, sysEmail.getId()); - SysEmail email = this.baseMapper.selectOne(queryWrapper); - if (Objects.isNull(email)){ - result.error500("对应数据不存在"); - return result; + SysEmail email = getById(sysEmail.getId()); + if (ObjectUtil.isNull(email)) + return Result.error(Prompt.DATA_NOT_EXITS); + String name = sysEmail.getName(); + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + if (!StrUtil.equals(name,email.getName())){ + wrapper.eq(SysEmail::getName,name); + if (CollUtil.isNotEmpty(list(wrapper))) + return Result.error("Name" + Prompt.NOT_REPEAT); + wrapper.clear(); } - //创建时间 - sysEmail.setUpdateTime(LocalDate.now()); - sysEmail.setUpdateBy(username); - this.baseMapper.updateById(sysEmail); - result.setSuccess(true); - result.success("修改成功"); - return result; + int count = baseMapper.updateById(sysEmail); + if (count == 1) + return Result.OK(Prompt.UPDATE_SUCC); + return Result.error(Prompt.UPDATE_ERR); } @Override @Transactional public Result deleteById(String id) { - Result result = new Result(); - this.baseMapper.deleteById(id); - result.setSuccess(true); - result.success("删除成功"); - return result; + int count = baseMapper.deleteById(id); + if(count == 1) + return Result.OK(Prompt.DELETE_SUCC); + return Result.error(Prompt.DELETE_ERR); } @Override - public Result findAlarmHistory(String emailId, Date startTime, Date endTime) { - Result result = new Result(); - try { - if (Objects.isNull(startTime)){ - result.error500("开始时间不能为空"); - return result; - } - if (Objects.isNull(endTime)){ - result.error500("结束时间不能为空"); - return result; - } - Date startDate = DateUtils.parseDate(DateUtils.formatDate(startTime, "yyyy-MM-dd") + " 00:00:00", "yyyy-MM-dd HH:mm:ss"); - Date endDate = DateUtils.parseDate(DateUtils.formatDate(endTime, "yyyy-MM-dd") + " 23:59:59", "yyyy-MM-dd HH:mm:ss"); - List alarmHistory = this.baseMapper.findAlarmHistory(emailId, startDate, endDate); - result.setSuccess(true); - result.setResult(alarmHistory); - } catch (ParseException e) { - throw new RuntimeException(e); - } - return result; + public Result findAlarmHistory(SourceVo sourceVo) { + String startDate = sourceVo.getStartDate(); + String endDate = sourceVo.getEndDate(); + if (StrUtil.isNotBlank(startDate)) + sourceVo.setStartDate(startDate + DateConstant.TIME_START); + if (StrUtil.isNotBlank(endDate)) + sourceVo.setStartDate(endDate + DateConstant.TIME_END); + Integer pageNo = sourceVo.getPageNo(); + Integer pageSize = sourceVo.getPageSize(); + Integer pageStart = (pageNo - 1) * pageSize; + sourceVo.setPageStart(pageStart); + Map params = BeanUtil.beanToMap(sourceVo); + List alarmHistories = baseMapper.findAlarmHistory(params); + // 获取数据总条数(经过查询条件过滤后的) + params.put("pageFlag","noPage"); + Integer total = baseMapper.findAlarmHistory(params).size(); + Page page = new Page<>(pageNo,pageSize,total); + // 当前页数据 + page.setRecords(alarmHistories); + return Result.OK(page); } /** @@ -148,4 +156,17 @@ public class SysEmailServiceImpl extends ServiceImpl i return Result.OK(sysEmail); } + @Override + public List listAll() { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + List sourceDtos = new ArrayList<>(); + for (SysEmail sysEmail : list()) { + SourceDto sourceDto = new SourceDto(); + sourceDto.setSourceId(sysEmail.getId()); + sourceDto.setSourceName(sysEmail.getName()); + sourceDtos.add(sourceDto); + } + return sourceDtos; + } + } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysServerServiceImpl.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysServerServiceImpl.java index 3f2d7113..e90c5ad6 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysServerServiceImpl.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysServerServiceImpl.java @@ -1,15 +1,21 @@ package org.jeecg.modules.service.impl; +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; 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 org.apache.commons.lang3.StringUtils; import org.jeecg.common.api.QueryRequest; import org.jeecg.common.api.vo.Result; -import org.jeecg.common.system.util.JwtUtil; +import org.jeecg.common.constant.DateConstant; +import org.jeecg.common.constant.Prompt; import org.jeecg.common.util.DateUtils; -import org.jeecg.common.util.SpringContextUtils; +import org.jeecg.modules.base.dto.ServerDto; +import org.jeecg.modules.base.dto.SourceDto; +import org.jeecg.modules.base.vo.SourceVo; import org.jeecg.modules.entity.AlarmHistory; import org.jeecg.modules.entity.SysServer; import org.jeecg.modules.mapper.SysServerMapper; @@ -17,25 +23,41 @@ import org.jeecg.modules.service.ISysServerService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import javax.servlet.http.HttpServletRequest; import java.text.ParseException; import java.time.LocalDate; -import java.util.Date; -import java.util.List; -import java.util.Objects; +import java.time.format.DateTimeFormatter; +import java.util.*; @Service("sysServerService") public class SysServerServiceImpl extends ServiceImpl implements ISysServerService { @Override - public Result findPage(QueryRequest queryRequest, SysServer sysServer) { - Result result = new Result(); - Page page = new Page<>(queryRequest.getPageNo(), queryRequest.getPageSize()); - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - Page sysServerPage = this.baseMapper.selectPage(page, queryWrapper); - result.setSuccess(true); - result.setResult(sysServerPage); - return result; + public Result findPage(QueryRequest query) { + Integer pageNo = query.getPageNo(); + Integer pageSize = query.getPageSize(); + Integer pageStart = (pageNo - 1) * pageSize; + Map params = new HashMap<>(); + params.put("pageSize",pageSize); + params.put("pageStart",pageStart); + DateTimeFormatter formatter = DateTimeFormatter + .ofPattern(DateConstant.DATE); + String date = LocalDate.now().format(formatter); + String startDate = date + DateConstant.TIME_START; + String endDate = date + DateConstant.TIME_END; + params.put("startDate",startDate); + params.put("endDate",endDate); + List serverDtos = baseMapper.findPage(params); + for (ServerDto serverDto : serverDtos) { + serverDto.setOnline(true) + .setServerInfo("(4-core (vCPU)16GiB)") + .setCpuUutilzation("35.8%").setMemoryUsage("55.8%") + .setDiskUsage("85.68%").setDiskRed(true); + } + params.put("pageFlag","noPage"); + long total = baseMapper.findPage(params).size(); + Page page = new Page<>(pageNo, pageSize, total); + page.setRecords(serverDtos); + return Result.OK(page); } @Override @@ -60,78 +82,100 @@ public class SysServerServiceImpl extends ServiceImpl wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(SysServer::getName,name); + if (CollUtil.isNotEmpty(list(wrapper))) + return Result.error("Name"+Prompt.NOT_REPEAT); + wrapper.clear(); + wrapper.eq(SysServer::getIpAddress,ipAddress); + if (CollUtil.isNotEmpty(list(wrapper))) + return Result.error("IP Address"+Prompt.NOT_REPEAT); + + int count = baseMapper.insert(sysServer); + if (count == 1) + return Result.OK(Prompt.ADD_SUCC); + return Result.error(Prompt.ADD_ERR); } @Override @Transactional public Result update(SysServer sysServer) { - Result result = new Result(); - //获取request - HttpServletRequest request = SpringContextUtils.getHttpServletRequest(); - //获取当前操作人用户名 - String username = JwtUtil.getUserNameByToken(request); - //根据id查询对应数据是否存在 - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(SysServer::getId, sysServer.getId()); - SysServer server = this.baseMapper.selectOne(queryWrapper); - if (Objects.isNull(server)){ - result.error500("当前数据不存在"); - return result; + SysServer server = getById(sysServer.getId()); + if (ObjectUtil.isNull(server)) + return Result.error(Prompt.DATA_NOT_EXITS); + String name = sysServer.getName(); + String ipAddress = sysServer.getIpAddress(); + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + if (!StrUtil.equals(name,server.getName())){ + wrapper.eq(SysServer::getName,name); + if (CollUtil.isNotEmpty(list(wrapper))) + return Result.error("Name" + Prompt.NOT_REPEAT); + wrapper.clear(); } - sysServer.setUpdateTime(LocalDate.now()); - sysServer.setUpdateBy(username); - this.baseMapper.updateById(sysServer); - result.setSuccess(true); - result.success("修改成功"); - return result; + if (!StrUtil.equals(ipAddress,server.getIpAddress())){ + wrapper.eq(SysServer::getIpAddress,ipAddress); + if (CollUtil.isNotEmpty(list(wrapper))) + return Result.error("IP Address" + Prompt.NOT_REPEAT); + } + int count = baseMapper.updateById(sysServer); + if (count == 1) + return Result.OK(Prompt.UPDATE_SUCC); + return Result.error(Prompt.UPDATE_ERR); } @Override @Transactional public Result deleteById(String id) { - Result result = new Result(); - this.baseMapper.deleteById(id); - result.setSuccess(true); - result.success("删除成功"); - return result; + int count = baseMapper.deleteById(id); + if(count == 1) + return Result.OK(Prompt.DELETE_SUCC); + return Result.error(Prompt.DELETE_ERR); } @Override - public Result findAlarmHistory(String serverId, Date startTime, Date endTime) { - Result result = new Result(); - try { - if (Objects.isNull(startTime)){ - result.error500("开始时间不能为空"); - return result; - } - if (Objects.isNull(endTime)){ - result.error500("结束时间不能为空"); - return result; - } - Date startDate = DateUtils.parseDate(DateUtils.formatDate(startTime, "yyyy-MM-dd") + " 00:00:00", "yyyy-MM-dd HH:mm:ss"); - Date endDate = DateUtils.parseDate(DateUtils.formatDate(endTime, "yyyy-MM-dd") + " 23:59:59", "yyyy-MM-dd HH:mm:ss"); - List alarmHistory = this.baseMapper.findAlarmHistory(serverId, startDate, endDate); - result.setSuccess(true); - result.setResult(alarmHistory); - } catch (ParseException e) { - throw new RuntimeException(e); - } - return result; + public Result findAlarmHistory(SourceVo sourceVo) { + String startDate = sourceVo.getStartDate(); + String endDate = sourceVo.getEndDate(); + if (StrUtil.isNotBlank(startDate)) + sourceVo.setStartDate(startDate + DateConstant.TIME_START); + if (StrUtil.isNotBlank(endDate)) + sourceVo.setStartDate(endDate + DateConstant.TIME_END); + Integer pageNo = sourceVo.getPageNo(); + Integer pageSize = sourceVo.getPageSize(); + Integer pageStart = (pageNo - 1) * pageSize; + sourceVo.setPageStart(pageStart); + Map params = BeanUtil.beanToMap(sourceVo); + List alarmHistories = baseMapper.findAlarmHistory(params); + // 获取数据总条数(经过查询条件过滤后的) + params.put("pageFlag","noPage"); + Integer total = baseMapper.findAlarmHistory(params).size(); + Page page = new Page<>(pageNo,pageSize,total); + // 当前页数据 + page.setRecords(alarmHistories); + return Result.OK(page); } + @Override + public List listAll() { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + List sourceDtos = new ArrayList<>(); + for (SysServer sysServer : list()) { + SourceDto sourceDto = new SourceDto(); + sourceDto.setSourceId(sysServer.getId()); + sourceDto.setSourceName(sysServer.getName()); + sourceDtos.add(sourceDto); + } + return sourceDtos; + } + + @Override + public String getByName(String name) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(SysServer::getName,name); + String id = Optional.ofNullable(getOne(wrapper, false)) + .orElse(new SysServer()).getId(); + return id; + } } diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/feignclient/MonitorClient.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/feignclient/MonitorClient.java deleted file mode 100644 index c587cc27..00000000 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/feignclient/MonitorClient.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.jeecg.modules.feignclient; - -import org.jeecg.common.api.vo.Result; -import org.jeecg.modules.base.dto.ItemDto; -import org.springframework.cloud.openfeign.FeignClient; -import org.springframework.stereotype.Component; -import org.springframework.web.bind.annotation.*; - -import java.util.Map; - -@Component -@FeignClient(name = "monitorClient",url = "${monitor.url}") -public interface MonitorClient { - @GetMapping("list") - Result monList(@RequestParam String code, - @RequestParam String hostId, - @RequestParam Integer pageNo, - @RequestParam Integer pageSize, - @RequestParam String status, - @RequestParam String type); - - @GetMapping("queryHostDetails") - Result monDetail(@RequestParam String hostId, - @RequestParam String pageName, - @RequestParam Integer pageNo, - @RequestParam Integer pageSize, - @RequestParam String start, - @RequestParam String end); - - @GetMapping("queryItemHistory") - Result itemHistory(@RequestParam String itemId, - @RequestParam Integer itemType, - @RequestParam String start, - @RequestParam String end); - - @GetMapping("queryItemHistoryData") - Result itemHistoryData(@RequestParam String itemId, - @RequestParam Integer itemType, - @RequestParam String start, - @RequestParam String end); - - @GetMapping("log") - Result monLog(@RequestParam String code, - @RequestParam String deviceType, - @RequestParam Integer pageNo, - @RequestParam Integer pageSize, - @RequestParam String start, - @RequestParam String end, - @RequestParam String status); - - @GetMapping("log/{hostId}") - Result monOneLog(@PathVariable("hostId") String hostId, - @RequestParam Integer pageNo, - @RequestParam Integer pageSize, - @RequestParam String start, - @RequestParam String end, - @RequestParam String status); -} diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/feignclient/MonitorSystem.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/feignclient/MonitorSystem.java new file mode 100644 index 00000000..94ebe5fe --- /dev/null +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/feignclient/MonitorSystem.java @@ -0,0 +1,18 @@ +package org.jeecg.modules.feignclient; + +import org.jeecg.common.api.vo.Result; +import org.jeecg.modules.base.entity.monitor.ItemHistory; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.*; + +@Component +@FeignClient(name = "monitorSystem",url = "${monitor.url}") +public interface MonitorSystem { + + @GetMapping("queryItemHistory") + Result itemBack(@RequestParam String itemId, + @RequestParam Integer itemType, + @RequestParam String start, + @RequestParam String end); +} diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/SendMessage.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/SendMessage.java index d117e87d..bd4d520e 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/SendMessage.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/SendMessage.java @@ -1,27 +1,21 @@ package org.jeecg.modules.message; - +import cn.hutool.core.collection.ListUtil; import cn.hutool.core.util.StrUtil; import org.jeecg.common.api.dto.message.MessageDTO; import org.jeecg.common.config.mqtoken.UserTokenContext; -import org.jeecg.common.constant.enums.MessageTypeEnum; import org.jeecg.common.system.api.ISysBaseAPI; -import org.jeecg.modules.base.entity.Rule; -import org.jeecg.modules.base.enums.Notific; import org.jeecg.modules.feignclient.AbnormalAlarmClient; import org.jeecg.modules.system.entity.SysUser; import org.jeecg.modules.system.service.ISysUserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; - import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; - import static org.jeecg.common.constant.enums.MessageTypeEnum.*; import static org.jeecg.common.util.TokenUtils.getTempToken; -import static org.jeecg.modules.base.enums.Notific.*; /** * 消息推送 (站内|邮箱|短信) @@ -54,29 +48,31 @@ public class SendMessage { UserTokenContext.setToken(getTempToken()); // 封装MessageDTO消息体 - MessageDTO messageDTO = new MessageDTO(); - messageDTO.setTitle("系统预警消息"); - messageDTO.setContent(message); + String title = "系统预警消息"; + MessageDTO messageDTO = new MessageDTO(title,message); Map contact = getContact(groupId); if (StrUtil.isBlank(notific))return; - String[] ways = notific.split(","); + List ways = ListUtil.toList(notific.split(",")); + if (ways.contains(ALL.getValue())){ + ways = ListUtil.toList(XT.getValue(), YJ.getValue(),SMS.getValue()); + } for (String way : ways) { - if(way.equals(SYSTEM.getWay())){// 1.推送系统消息 + if(way.equals(XT.getValue())){// 1.推送系统消息 String toSys = contact.get(System); if (StrUtil.isNotBlank(toSys)){ messageDTO.setToUser(toSys); messageDTO.setType(XT.getType()); sysBaseAPI.sendTemplateMessage(messageDTO); } - } else if (way.equals(EMAIL.getWay())) {// 2.推送邮箱 + } else if (way.equals(YJ.getValue())) {// 2.推送邮箱 String toEmail = contact.get(Email); if (StrUtil.isNotBlank(toEmail)){ messageDTO.setToUser(toEmail); - messageDTO.setType(YX.getType()); + messageDTO.setType(YJ.getType()); sysBaseAPI.sendTemplateMessage(messageDTO); } - } else if (way.equals(PHONE.getWay())) {// 3.推送短信 + } else if (way.equals(SMS.getValue())) {// 3.推送短信 String toSms = contact.get(Sms); if (StrUtil.isNotBlank(toSms)){ messageDTO.setToUser(toSms); diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/entity/SysMessage.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/entity/SysMessage.java index f3555e3e..3599efa1 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/entity/SysMessage.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/entity/SysMessage.java @@ -12,12 +12,6 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; -/** - * @Description: 消息 - * @Author: jeecg-boot - * @Date: 2019-04-09 - * @Version: V1.0 - */ @Data @EqualsAndHashCode(callSuper = false) @Accessors(chain = true) @@ -25,23 +19,23 @@ import lombok.experimental.Accessors; public class SysMessage extends JeecgEntity { /**推送内容*/ @Excel(name = "推送内容", width = 15) - private java.lang.String esContent; + private String esContent; /**推送所需参数Json格式*/ @Excel(name = "推送所需参数Json格式", width = 15) - private java.lang.String esParam; + private String esParam; /**接收人*/ @Excel(name = "接收人", width = 15) - private java.lang.String esReceiver; + private String esReceiver; /**推送失败原因*/ @Excel(name = "推送失败原因", width = 15) - private java.lang.String esResult; + private String esResult; /**发送次数*/ @Excel(name = "发送次数", width = 15) - private java.lang.Integer esSendNum; + private Integer esSendNum; /**推送状态 0未推送 1推送成功 2推送失败*/ @Excel(name = "推送状态 0未推送 1推送成功 2推送失败", width = 15) @Dict(dicCode = "msgSendStatus") - private java.lang.String esSendStatus; + private String esSendStatus; /**推送时间*/ @Excel(name = "推送时间", width = 20, format = "yyyy-MM-dd HH:mm:ss") @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") @@ -49,14 +43,14 @@ public class SysMessage extends JeecgEntity { private java.util.Date esSendTime; /**消息标题*/ @Excel(name = "消息标题", width = 15) - private java.lang.String esTitle; + private String esTitle; /** * 推送方式:参考枚举类MessageTypeEnum */ @Excel(name = "推送方式", width = 15) @Dict(dicCode = "messageType") - private java.lang.String esType; + private String esType; /**备注*/ @Excel(name = "备注", width = 15) - private java.lang.String remark; + private String remark; } diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/entity/SysMessageTemplate.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/entity/SysMessageTemplate.java index 1ea966e9..f1e8ca87 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/entity/SysMessageTemplate.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/entity/SysMessageTemplate.java @@ -10,10 +10,7 @@ import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; /** - * @Description: 消息模板 - * @Author: jeecg-boot - * @Date: 2019-04-09 - * @Version: V1.0 + * 消息模板 */ @Data @EqualsAndHashCode(callSuper = false) @@ -22,19 +19,19 @@ import lombok.experimental.Accessors; public class SysMessageTemplate extends JeecgEntity{ /**模板CODE*/ @Excel(name = "模板CODE", width = 15) - private java.lang.String templateCode; + private String templateCode; /**模板标题*/ @Excel(name = "模板标题", width = 30) - private java.lang.String templateName; + private String templateName; /**模板内容*/ @Excel(name = "模板内容", width = 50) - private java.lang.String templateContent; + private String templateContent; /**模板测试json*/ @Excel(name = "模板测试json", width = 15) - private java.lang.String templateTestJson; + private String templateTestJson; /**模板类型*/ @Excel(name = "模板类型", width = 15) - private java.lang.String templateType; + private String templateType; /**已经应用/未应用 1是0否*/ @Excel(name = "应用状态", width = 15) diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/handle/impl/EmailPushMsgHandle.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/handle/impl/EmailPushMsgHandle.java index 36ae47cb..44d6b04b 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/handle/impl/EmailPushMsgHandle.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/handle/impl/EmailPushMsgHandle.java @@ -6,6 +6,7 @@ import org.jeecg.common.email.EmailServiceManager; import org.jeecg.modules.base.entity.SysEmail; import org.jeecg.modules.feignclient.AbnormalAlarmClient; import org.jeecg.modules.message.handle.ISendMsgHandle; +import org.jeecg.modules.message.service.ISysMessageService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -25,6 +26,9 @@ public class EmailPushMsgHandle implements ISendMsgHandle { @Autowired private AbnormalAlarmClient alarmClient; + @Autowired + private ISysMessageService sysMessageService; + @Override public void sendMessage(MessageDTO messageDTO) { // 获取邮件发送服务器信息 @@ -35,6 +39,8 @@ public class EmailPushMsgHandle implements ISendMsgHandle { emailService.init(sysEmail); // 发送邮件 emailService.sendMail(messageDTO); + + sysMessageService.add(messageDTO); } @Override diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/handle/impl/SmsSendMsgHandle.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/handle/impl/SmsSendMsgHandle.java index 5ad17221..67c69b6b 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/handle/impl/SmsSendMsgHandle.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/handle/impl/SmsSendMsgHandle.java @@ -1,15 +1,13 @@ package org.jeecg.modules.message.handle.impl; -import lombok.extern.slf4j.Slf4j; import org.jeecg.common.api.dto.message.MessageDTO; -import org.jeecg.common.util.DySmsHelper; import org.jeecg.modules.message.handle.ISendMsgHandle; +import org.springframework.stereotype.Component; /** * @Description: 短信发送 - * @author: jeecg-boot */ -@Slf4j +@Component public class SmsSendMsgHandle implements ISendMsgHandle { @Override diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/handle/impl/SystemSendMsgHandle.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/handle/impl/SystemSendMsgHandle.java index a1503734..82794bf3 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/handle/impl/SystemSendMsgHandle.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/handle/impl/SystemSendMsgHandle.java @@ -1,5 +1,7 @@ package org.jeecg.modules.message.handle.impl; +import cn.hutool.core.util.ArrayUtil; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSONObject; import org.jeecg.common.api.dto.message.MessageDTO; @@ -11,6 +13,7 @@ import org.jeecg.common.util.SpringContextUtils; import org.jeecg.common.util.oConvertUtils; import org.jeecg.modules.message.enums.Vue3MessageHrefEnum; import org.jeecg.modules.message.handle.ISendMsgHandle; +import org.jeecg.modules.message.service.ISysMessageService; import org.jeecg.modules.message.websocket.WebSocket; import org.jeecg.modules.system.entity.SysAnnouncement; import org.jeecg.modules.system.entity.SysAnnouncementSend; @@ -18,33 +21,72 @@ import org.jeecg.modules.system.entity.SysUser; import org.jeecg.modules.system.mapper.SysAnnouncementMapper; import org.jeecg.modules.system.mapper.SysAnnouncementSendMapper; import org.jeecg.modules.system.mapper.SysUserMapper; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import javax.annotation.Resource; +import java.util.Arrays; import java.util.Date; import java.util.Map; -/** -* @Description: 发送系统消息 -* @Author: wangshuai -* @Date: 2022年3月22日 18:48:20 -*/ @Component("systemSendMsgHandle") public class SystemSendMsgHandle implements ISendMsgHandle { - public static final String FROM_USER="system"; + public static final String FROM_USER = "system"; + + @Resource + private WebSocket webSocket; + + @Resource + private SysUserMapper userMapper; + + @Autowired + private ISysMessageService sysMessageService; @Resource private SysAnnouncementMapper sysAnnouncementMapper; - @Resource - private SysUserMapper userMapper; - @Resource private SysAnnouncementSendMapper sysAnnouncementSendMapper; - @Resource - private WebSocket webSocket; + /** + * 仅发送系统消息 + * @param messageDTO + */ + @Override + public void sendMessage(MessageDTO messageDTO) { + String[] toUsers = messageDTO.getToUser().split(","); + for(String toUser: toUsers){ + SysUser sysUser = userMapper.getUserByName(toUser); + if (ObjectUtil.isNull(sysUser)) continue; + SysAnnouncement announcement = new SysAnnouncement(); + announcement.setTitile(messageDTO.getTitle()); + announcement.setMsgContent(messageDTO.getContent()); + announcement.setSender(messageDTO.getFromUser()); + announcement.setPriority(CommonConstant.PRIORITY_M); + announcement.setMsgType(CommonConstant.MSG_TYPE_UESR); + announcement.setSendStatus(CommonConstant.HAS_SEND); + announcement.setSendTime(new Date()); + announcement.setMsgCategory(CommonConstant.MSG_CATEGORY_2); + announcement.setDelFlag(String.valueOf(CommonConstant.DEL_FLAG_0)); + sysAnnouncementMapper.insert(announcement); + String anntId = announcement.getId(); + + SysAnnouncementSend announcementSend = new SysAnnouncementSend(); + announcementSend.setAnntId(anntId); + announcementSend.setUserId(sysUser.getId()); + announcementSend.setReadFlag(CommonConstant.NO_READ_FLAG); + sysAnnouncementSendMapper.insert(announcementSend); + + JSONObject obj = new JSONObject(); + obj.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_USER); + obj.put(WebsocketConst.MSG_USER_ID, sysUser.getId()); + obj.put(WebsocketConst.MSG_ID, announcement.getId()); + obj.put(WebsocketConst.MSG_TXT, announcement.getTitile()); + webSocket.sendMessage(sysUser.getId(), obj.toJSONString()); + } + sysMessageService.add(messageDTO); + } /** * 该方法会发送3种消息:系统消息、企业微信 钉钉 @@ -61,68 +103,4 @@ public class SystemSendMsgHandle implements ISendMsgHandle { MessageDTO messageDTO = new MessageDTO(FROM_USER,esReceiver,esTitle,esContent); sysBaseApi.sendSysAnnouncement(messageDTO); } - - /** - * 仅发送系统消息 - * @param messageDTO - */ - @Override - public void sendMessage(MessageDTO messageDTO) { - //原方法不支持 sysBaseApi.sendSysAnnouncement(messageDTO); 有企业微信消息逻辑, - String title = messageDTO.getTitle(); - String content = messageDTO.getContent(); - String fromUser = messageDTO.getFromUser(); - Map data = messageDTO.getData(); - String[] arr = messageDTO.getToUser().split(","); - for(String username: arr){ - doSend(title, content, fromUser, username, data); - } - } - - private void doSend(String title, String msgContent, String fromUser, String toUser, Map data){ - SysAnnouncement announcement = new SysAnnouncement(); - if(data!=null){ - //摘要信息 - Object msgAbstract = data.get(CommonConstant.NOTICE_MSG_SUMMARY); - if(msgAbstract!=null){ - announcement.setMsgAbstract(msgAbstract.toString()); - } - // 任务节点ID - Object taskId = data.get(CommonConstant.NOTICE_MSG_BUS_ID); - if(taskId!=null){ - announcement.setBusId(taskId.toString()); - announcement.setBusType(Vue3MessageHrefEnum.BPM_TASK.getBusType()); - } - } - announcement.setTitile(title); - announcement.setMsgContent(msgContent); - announcement.setSender(fromUser); - announcement.setPriority(CommonConstant.PRIORITY_M); - announcement.setMsgType(CommonConstant.MSG_TYPE_UESR); - announcement.setSendStatus(CommonConstant.HAS_SEND); - announcement.setSendTime(new Date()); - //系统消息 - announcement.setMsgCategory("2"); - announcement.setDelFlag(String.valueOf(CommonConstant.DEL_FLAG_0)); - sysAnnouncementMapper.insert(announcement); - // 2.插入用户通告阅读标记表记录 - String anntId = announcement.getId(); - if(StrUtil.isNotBlank(toUser)) { - SysUser sysUser = userMapper.getUserByName(toUser); - if(sysUser==null) { - return; - } - SysAnnouncementSend announcementSend = new SysAnnouncementSend(); - announcementSend.setAnntId(anntId); - announcementSend.setUserId(sysUser.getId()); - announcementSend.setReadFlag(CommonConstant.NO_READ_FLAG); - sysAnnouncementSendMapper.insert(announcementSend); - JSONObject obj = new JSONObject(); - obj.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_USER); - obj.put(WebsocketConst.MSG_USER_ID, sysUser.getId()); - obj.put(WebsocketConst.MSG_ID, announcement.getId()); - obj.put(WebsocketConst.MSG_TXT, announcement.getTitile()); - webSocket.sendMessage(sysUser.getId(), obj.toJSONString()); - } - } } \ No newline at end of file diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/mapper/SysMessageMapper.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/mapper/SysMessageMapper.java index 100d35ee..8deb2a0b 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/mapper/SysMessageMapper.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/mapper/SysMessageMapper.java @@ -6,12 +6,6 @@ import org.apache.ibatis.annotations.Param; import org.jeecg.modules.message.entity.SysMessage; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -/** - * @Description: 消息 - * @Author: jeecg-boot - * @Date: 2019-04-09 - * @Version: V1.0 - */ public interface SysMessageMapper extends BaseMapper { } diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/service/ISysMessageService.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/service/ISysMessageService.java index 744f35e7..97540e60 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/service/ISysMessageService.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/service/ISysMessageService.java @@ -1,14 +1,9 @@ package org.jeecg.modules.message.service; +import org.jeecg.common.api.dto.message.MessageDTO; import org.jeecg.common.system.base.service.JeecgService; import org.jeecg.modules.message.entity.SysMessage; -/** - * @Description: 消息 - * @Author: jeecg-boot - * @Date: 2019-04-09 - * @Version: V1.0 - */ public interface ISysMessageService extends JeecgService { - + boolean add(MessageDTO messageDTO); } diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/service/impl/SysMessageServiceImpl.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/service/impl/SysMessageServiceImpl.java index ff836a54..0aae61c3 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/service/impl/SysMessageServiceImpl.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/service/impl/SysMessageServiceImpl.java @@ -1,18 +1,38 @@ package org.jeecg.modules.message.service.impl; +import cn.hutool.core.collection.ListUtil; +import org.jeecg.common.api.dto.message.MessageDTO; +import org.jeecg.common.constant.CommonConstant; +import org.jeecg.common.constant.SymbolConstant; +import org.jeecg.common.constant.enums.MessageTypeEnum; import org.jeecg.common.system.base.service.impl.JeecgServiceImpl; import org.jeecg.modules.message.entity.SysMessage; import org.jeecg.modules.message.mapper.SysMessageMapper; import org.jeecg.modules.message.service.ISysMessageService; import org.springframework.stereotype.Service; -/** - * @Description: 消息 - * @Author: jeecg-boot - * @Date: 2019-04-09 - * @Version: V1.0 - */ +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + @Service public class SysMessageServiceImpl extends JeecgServiceImpl implements ISysMessageService { + @Override + public boolean add(MessageDTO messageDTO) { + String toUser = messageDTO.getToUser(); + List sysMessages = new ArrayList<>(); + List toUsers = ListUtil.toList(toUser.split(SymbolConstant.COMMA)); + Date now = new Date(); + for (String receiver : toUsers) { + SysMessage sms = new SysMessage(); + sms.setEsSendTime(now); + sms.setEsReceiver(receiver); + sms.setEsType(messageDTO.getType()); + sms.setEsTitle(messageDTO.getTitle()); + sms.setEsContent(messageDTO.getContent()); + sysMessages.add(sms); + } + return saveBatch(sysMessages); + } } diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/SysInfoJob.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/SysInfoJob.java index 18f441ff..7e25c188 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/SysInfoJob.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/SysInfoJob.java @@ -1,7 +1,6 @@ package org.jeecg.modules.quartz.job; import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.collection.ListUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.fasterxml.jackson.core.JsonProcessingException; @@ -10,31 +9,22 @@ import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.jeecg.common.api.vo.Result; import org.jeecg.common.constant.CommonConstant; -import org.jeecg.common.constant.enums.MessageTypeEnum; import org.jeecg.common.util.RedisStreamUtil; import org.jeecg.common.util.SpringContextUtils; -import org.jeecg.modules.base.dto.ItemDto; -import org.jeecg.modules.base.dto.RuleDto; +import org.jeecg.modules.base.entity.monitor.ItemHistory; import org.jeecg.modules.base.entity.AlarmLog; import org.jeecg.modules.base.entity.AlarmRule; import org.jeecg.modules.base.entity.Rule; -import org.jeecg.modules.base.enums.Item; -import org.jeecg.modules.base.enums.SourceType; import org.jeecg.modules.feignclient.AbnormalAlarmClient; -import org.jeecg.modules.feignclient.MonitorClient; +import org.jeecg.modules.feignclient.MonitorSystem; import org.jeecg.modules.message.SendMessage; import org.quartz.*; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; -import java.time.format.FormatStyle; -import java.util.List; import java.util.Set; -import static org.jeecg.common.constant.enums.MessageTypeEnum.QYWX; import static org.jeecg.modules.base.enums.Op.*; -import static org.jeecg.modules.base.enums.SourceType.EMAIL; -import static org.jeecg.modules.base.enums.SourceType.SERVER; @Data @Slf4j @@ -53,7 +43,7 @@ public class SysInfoJob implements Job { @Override public void execute(JobExecutionContext context) throws JobExecutionException { RedisStreamUtil redisStreamUtil = SpringContextUtils.getBean(RedisStreamUtil.class); - MonitorClient monitorClient = SpringContextUtils.getBean(MonitorClient.class); + MonitorSystem monitorSystem = SpringContextUtils.getBean(MonitorSystem.class); SendMessage sendMessage = SpringContextUtils.getBean(SendMessage.class); AbnormalAlarmClient alarmClient = SpringContextUtils.getBean(AbnormalAlarmClient.class); @@ -90,7 +80,7 @@ public class SysInfoJob implements Job { // 向运管查询监控项数据 String itemId = alarmRule.getItemId().toString(); - Result result = monitorClient.itemHistory(itemId, 0, start, end); + Result result = monitorSystem.itemBack(itemId, 0, start, end); Double current = result.getResult().getNow(); // 解析预警规则,判断是否需要报警 diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/entity/SysDictItem.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/entity/SysDictItem.java index 3757eb2e..e5e91ccd 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/entity/SysDictItem.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/entity/SysDictItem.java @@ -63,7 +63,6 @@ public class SysDictItem implements Serializable { @Excel(name = "排序", width = 15,type=4) private Integer sortOrder; - /** * 状态(1启用 0不启用) */ @@ -77,6 +76,4 @@ public class SysDictItem implements Serializable { private String updateBy; private Date updateTime; - - } diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysBaseApiImpl.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysBaseApiImpl.java index 67fcd877..24e1a7d0 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysBaseApiImpl.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysBaseApiImpl.java @@ -1,5 +1,7 @@ package org.jeecg.modules.system.service.impl; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; @@ -47,6 +49,8 @@ import java.sql.DatabaseMetaData; import java.sql.SQLException; import java.util.*; +import static org.jeecg.common.constant.enums.MessageTypeEnum.*; + /** * @Description: 底层共通业务API,提供其他独立模块调用 * @Author: scott @@ -1176,22 +1180,16 @@ public class SysBaseApiImpl implements ISysBaseAPI { } //-------------------------------------流程节点发送模板消息----------------------------------------------- - @Autowired - private QywxSendMsgHandle qywxSendMsgHandle; - @Autowired private SystemSendMsgHandle systemSendMsgHandle; - @Autowired - private EmailSendMsgHandle emailSendMsgHandle; - - @Autowired - private DdSendMsgHandle ddSendMsgHandle; - @Autowired private EmailPushMsgHandle emailPushMsgHandle; - @Override + @Autowired + private SmsSendMsgHandle smsSendMsgHandle; + + /*@Override public void sendTemplateMessage(MessageDTO message) { String messageType = message.getType(); //update-begin-author:taoyan date:2022-7-9 for: 将模板解析代码移至消息发送, 而不是调用的地方 @@ -1226,8 +1224,30 @@ public class SysBaseApiImpl implements ISysBaseAPI { ddSendMsgHandle.sendMessage(message); }else if(MessageTypeEnum.QYWX.getType().equals(messageType)){ qywxSendMsgHandle.sendMessage(message); - } else if (MessageTypeEnum.YX.getType().equals(messageType)) { // 新增邮件推送 2023-06-25 + } + }*/ + + public void sendTemplateMessage(MessageDTO message) { + String type = message.getType(); + String code = message.getTemplateCode(); + if(StrUtil.isNotBlank(code)){ + SysMessageTemplate template = getTemplateEntity(code); + String content = template.getTemplateContent(); + Map data = message.getData(); + boolean notBlank = StrUtil.isNotBlank(content); + boolean notEmpty = ObjectUtil.isNotEmpty(data); + if(notBlank && notEmpty){ + content = FreemarkerParseFactory + .parseTemplateContent(content, data, false); + } + message.setContent(content); + } + if(XT.getType().equals(type)){ // 站内消息 + systemSendMsgHandle.sendMessage(message); + }else if(YJ.getType().equals(type)){ // 邮箱消息 emailPushMsgHandle.sendMessage(message); + } else if (SMS.getType().equals(type)) { // 手机短信 + smsSendMsgHandle.sendMessage(message); } } diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysUserServiceImpl.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysUserServiceImpl.java index bbe79f18..b3911180 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysUserServiceImpl.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysUserServiceImpl.java @@ -1307,25 +1307,24 @@ public class SysUserServiceImpl extends ServiceImpl impl List sysUserRoles = sysUserRoleMapper.selectList(userRoleQueryWrapper); LambdaQueryWrapper roleQueryWrapper = new LambdaQueryWrapper<>(); List sysRoles = sysRoleMapper.selectList(roleQueryWrapper); - List roles = new LinkedList<>(); //遍历所有用户信息 - if (CollectionUtils.isNotEmpty(sysUsers)){ - for (SysUser sysUser:sysUsers) { - if (CollectionUtils.isNotEmpty(sysUserRoles)){ - //获取各用户匹配的权限集合 - List userRoles = sysUserRoles.stream().filter(item -> item.getUserId().equals(sysUser.getId())).collect(Collectors.toList()); - List roleIds = userRoles.stream().map(SysUserRole::getRoleId).collect(Collectors.toList()); - if (CollectionUtils.isNotEmpty(sysRoles)){ - for (SysRole role:sysRoles) { - if (roleIds.contains(role.getId())){ - roles.add(role); - } - } - } - sysUser.setRoles(roles); + for (SysUser sysUser:sysUsers) { + String userId = sysUser.getId(); + List roles = new LinkedList<>(); + //获取各用户匹配的权限集合 + List userRoles = sysUserRoles.stream() + .filter(item -> item.getUserId().equals(userId)) + .collect(Collectors.toList()); + List roleIds = userRoles.stream() + .map(SysUserRole::getRoleId) + .collect(Collectors.toList()); + for (SysRole role:sysRoles) { + if (roleIds.contains(role.getId())){ + roles.add(role); } - map.put(sysUser.getId(), sysUser); } + sysUser.setRoles(roles); + map.put(userId, sysUser); } return map; } diff --git a/jeecg-module-system/jeecg-system-start/src/main/resources/jeecg/jeecg_database.properties b/jeecg-module-system/jeecg-system-start/src/main/resources/jeecg/jeecg_database.properties index 10dad372..0c1e630c 100644 --- a/jeecg-module-system/jeecg-system-start/src/main/resources/jeecg/jeecg_database.properties +++ b/jeecg-module-system/jeecg-system-start/src/main/resources/jeecg/jeecg_database.properties @@ -6,18 +6,18 @@ #database_name=jeecg-boot #oracle -diver_name=oracle.jdbc.driver.OracleDriver -url=jdbc:oracle:thin:@82.157.234.81:1521:orcl -username=original -password=123456 -database_name=original +#diver_name=oracle.jdbc.driver.OracleDriver +#url=jdbc:oracle:thin:@82.157.234.81:1521:orcl +#username=original +#password=123456 +#database_name=original #postgre -#diver_name=org.postgresql.Driver -#url=jdbc:postgresql://localhost:5432/jeecg -#username=postgres -#password=postgres -#database_name=jeecg +diver_name=org.postgresql.Driver +url=jdbc:postgresql://182.92.183.230:5432/jeecg-boot +username=postgres +password=U6D!TGH3 +database_name=public #SQLServer2005\u4ee5\u4e0a #diver_name=org.hibernate.dialect.SQLServerDialect diff --git a/jeecg-module-web-statistics/src/main/java/org/jeecg/common/util/ReadLineUtil.java b/jeecg-module-web-statistics/src/main/java/org/jeecg/common/util/ReadLineUtil.java index f6667872..ca7d96d2 100644 --- a/jeecg-module-web-statistics/src/main/java/org/jeecg/common/util/ReadLineUtil.java +++ b/jeecg-module-web-statistics/src/main/java/org/jeecg/common/util/ReadLineUtil.java @@ -11,6 +11,7 @@ import org.apache.commons.net.ftp.FTP; import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPFile; import org.jeecg.common.api.vo.Result; +import org.jeecg.common.constant.Prompt; import org.jeecg.common.constant.SymbolConstant; import org.jeecg.common.enums.SampleFileHeader; import org.jeecg.modules.entity.data.HistogramData; @@ -23,6 +24,8 @@ import javax.servlet.http.HttpServletResponse; import java.io.*; import java.util.*; +import static org.jeecg.common.constant.enums.FileTypeEnum.txt; + @Component @Slf4j public class ReadLineUtil { @@ -159,7 +162,7 @@ public class ReadLineUtil { outputStream.write(buffer, 0, bytesRead); } } catch (FileNotFoundException e){ - log.error("File["+filePath+"]does not exist!"); + log.error("File ["+filePath+"] does not exist!"); e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); @@ -179,7 +182,7 @@ public class ReadLineUtil { FTPClient ftpClient = ftpUtil.LoginFTP(); // 判断FTP是否连接成功 if (Objects.isNull(ftpClient)){ - throw new RuntimeException("FTP连接失败!"); + throw new RuntimeException(Prompt.FTP_ERR); } OutputStream outputStream = null; @@ -191,20 +194,21 @@ public class ReadLineUtil { // 判断FTP服务器上是否存在此文件 String[] files = ftpClient.listNames(filePath); if (ArrayUtil.isEmpty(files)){ - String message = "File["+filePath+"]does not exist!"; + String message = "File ["+filePath+"] does not exist!"; log.error(message); return Result.error(message); } // 存在多个文件名表示此路径为目录而非文件 if (ArrayUtil.length(files) > 1){ - String message = "["+filePath+"]There are multiple files, possibly one directory!"; + String message = "["+filePath+"] There are multiple files, possibly one directory!"; log.error(message); return Result.error(message); } // 获取文件名 String fileName = FileUtil.getName(filePath); + if (!fileName.endsWith(txt.getType()))fileName += txt.getType(); // 在当前工作路径下读取文件 ftpClient.enterLocalPassiveMode(); diff --git a/jeecg-module-web-statistics/src/main/java/org/jeecg/modules/controller/WebStatisticsController.java b/jeecg-module-web-statistics/src/main/java/org/jeecg/modules/controller/WebStatisticsController.java index 4e6c9298..8f6ed90c 100644 --- a/jeecg-module-web-statistics/src/main/java/org/jeecg/modules/controller/WebStatisticsController.java +++ b/jeecg-module-web-statistics/src/main/java/org/jeecg/modules/controller/WebStatisticsController.java @@ -7,6 +7,7 @@ import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; import org.jeecg.common.api.QueryRequest; import org.jeecg.common.api.vo.Result; +import org.jeecg.common.constant.Prompt; import org.jeecg.common.util.ReadLineUtil; import org.jeecg.modules.base.entity.GardsSampleData; import org.jeecg.modules.base.entity.GardsSohData; @@ -97,7 +98,7 @@ public class WebStatisticsController { GardsSampleData sampleData = gardsSampleDataWebService.getOneSample(sampleId); String filePath = sampleData.getInputFileName(); if (StrUtil.isBlank(filePath)) - return Result.error("The file you are looking for does not exist!"); + return Result.error(Prompt.FILE_NOT_EXITS); return readLineUtil.readFtpFile(filePath,response); } @@ -108,7 +109,7 @@ public class WebStatisticsController { GardsSohData soh = gardsSohDataService.getOneSoh(sohId); String filePath = soh.getInputFileName(); if (StrUtil.isBlank(filePath)) - return Result.error("The file you are looking for does not exist!"); + return Result.error(Prompt.FILE_NOT_EXITS); return readLineUtil.readFtpFile(filePath,response); } @@ -124,7 +125,7 @@ public class WebStatisticsController { reportPath = reviewedService.getOne(sampleId).getReportPath(); } if (StrUtil.isBlank(reportPath)) - return Result.error("The file you are looking for does not exist!"); + return Result.error(Prompt.FILE_NOT_EXITS); // 将FTP上的文件转为文件流返回到前端 return readLineUtil.readFtpFile(reportPath,response); }