feat:新功能

This commit is contained in:
nieziyan 2023-07-28 19:31:26 +08:00
parent 1d3e2253aa
commit afd110d2b4
77 changed files with 1641 additions and 712 deletions

View File

@ -78,8 +78,7 @@ public class MessageDTO implements Serializable {
*/ */
private String copyToUser; private String copyToUser;
public MessageDTO(){ public MessageDTO(){}
}
/** /**
* 构造器1 系统消息 * 构造器1 系统消息
@ -89,7 +88,7 @@ public class MessageDTO implements Serializable {
this.toUser = toUser; this.toUser = toUser;
this.title = title; this.title = title;
this.content = content; this.content = content;
//默认 都是2系统消息 //默认都是 2:系统消息
this.category = CommonConstant.MSG_CATEGORY_2; this.category = CommonConstant.MSG_CATEGORY_2;
} }
@ -104,6 +103,11 @@ public class MessageDTO implements Serializable {
this.category = category; this.category = category;
} }
public MessageDTO(String title, String content) {
this.title = title;
this.content = content;
}
public boolean isMarkdown() { public boolean isMarkdown() {
return this.isMarkdown; return this.isMarkdown;
} }

View File

@ -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";
}

View File

@ -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!";
}

View File

@ -13,21 +13,22 @@ import java.util.List;
@EnumDict("messageType") @EnumDict("messageType")
public enum MessageTypeEnum { public enum MessageTypeEnum {
/* 发送全部 system|email|sms */
ALL("all","所有消息","0"),
/** 系统消息 */ /** 系统消息 */
XT("system", "系统消息"), XT("system", "系统消息", "1"),
/** 邮件消息 */ /** 邮件消息 */
YJ("email", "邮件消息"), YJ("email", "邮件消息", "2"),
/** 钉钉消息 */
DD("dingtalk", "钉钉消息"),
/** 企业微信 */
QYWX("wechat_enterprise", "企业微信"),
/* 邮箱消息 */
YX("email-self", "邮箱消息"),
/* 手机短信 */ /* 手机短信 */
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.type = type;
this.value = value;
this.note = note; this.note = note;
} }
@ -36,6 +37,8 @@ public enum MessageTypeEnum {
*/ */
String type; String type;
String value;
/** /**
* 类型说明 * 类型说明
*/ */
@ -57,6 +60,9 @@ public enum MessageTypeEnum {
this.type = type; this.type = type;
} }
public String getValue() {
return value;
}
/** /**
* 获取字典数据 * 获取字典数据
@ -74,15 +80,9 @@ public enum MessageTypeEnum {
return list; return list;
} }
/** public static MessageTypeEnum typeOf(String type) {
* 根据type获取枚举
*
* @param type
* @return
*/
public static MessageTypeEnum valueOfType(String type) {
for (MessageTypeEnum e : MessageTypeEnum.values()) { for (MessageTypeEnum e : MessageTypeEnum.values()) {
if (e.getType().equals(type)) { if (e.getValue().equals(type)) {
return e; return e;
} }
} }

View File

@ -8,6 +8,7 @@ import com.sun.mail.smtp.SMTPAddressFailedException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import org.jeecg.common.api.dto.message.MessageDTO; import org.jeecg.common.api.dto.message.MessageDTO;
import org.jeecg.common.constant.SymbolConstant;
import org.jeecg.common.email.emuns.MailContentType; import org.jeecg.common.email.emuns.MailContentType;
import org.jeecg.modules.base.entity.SysEmail; import org.jeecg.modules.base.entity.SysEmail;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -186,18 +187,18 @@ public class EmailServiceManager {
* @param messageDTO 消息dto * @param messageDTO 消息dto
*/ */
private void reSendMail(Address[] invalid,MessageDTO messageDTO){ private void reSendMail(Address[] invalid,MessageDTO messageDTO){
List<String> invalidList = Arrays.stream(invalid) List<String> invalidEmails = Arrays.stream(invalid)
.map(address -> address.toString()) .map(address -> address.toString())
.collect(Collectors.toList()); .collect(Collectors.toList());
log.warn("部分或者全部邮件发送失败,无效的电子邮箱:{}",invalidList); log.warn("部分或者全部邮件发送失败,无效的电子邮箱:{}",invalidEmails);
String[] allEmails = messageDTO.getToUser().split(","); String[] allEmails = messageDTO.getToUser().split(SymbolConstant.COMMA);
String[] emails = new String[]{}; String[] emails = new String[]{};
for (String address : invalidList) { for (String address : invalidEmails) {
emails = ArrayUtil.removeEle(allEmails,address); emails = ArrayUtil.removeEle(allEmails,address);
} }
// 如果移除无效电子邮箱后,待发送邮箱不为空 // 如果移除无效电子邮箱后,待发送邮箱不为空
String toUser = Arrays.stream(emails) String toUser = Arrays.stream(emails)
.collect(Collectors.joining(",")); .collect(Collectors.joining(SymbolConstant.COMMA));
if (StrUtil.isNotBlank(toUser)){ if (StrUtil.isNotBlank(toUser)){
messageDTO.setToUser(toUser); messageDTO.setToUser(toUser);
sendMail(messageDTO); sendMail(messageDTO);

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -1,25 +1,22 @@
package org.jeecg.modules.base.dto; package org.jeecg.modules.base.dto;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data; import lombok.Data;
import org.jeecg.modules.base.entity.monitor.Item;
import java.io.Serializable; import java.io.Serializable;
import java.util.List;
@Data @Data
public class ItemDto implements Serializable { public class ItemDto implements Serializable{
private Double min; private String itemId;
private Double max;
private Double avg;
private Double now;
private String name; private String name;
private String units; private String units;
private List<Object> list; public ItemDto(Item item) {
this.itemId = item.getItemId();
this.name = item.getName();
this.units = item.getUnits();
}
} }

View File

@ -3,7 +3,6 @@ package org.jeecg.modules.base.dto;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import org.jeecg.modules.base.enums.Item;
import org.jeecg.modules.base.enums.SourceType; import org.jeecg.modules.base.enums.SourceType;
import java.io.Serializable; import java.io.Serializable;

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -41,7 +41,7 @@ public class AlarmRule implements Serializable {
private Long silenceCycle; private Long silenceCycle;
/** /**
* 报警通知方式 1:短信 2.邮件 3.站内 * 报警通知方式 3:短信 2.邮件 1.站内 0.全部
*/ */
@TableField(value = "notification") @TableField(value = "notification")
private String notification; private String notification;
@ -74,7 +74,7 @@ public class AlarmRule implements Serializable {
* 监控项 * 监控项
*/ */
@TableField(value = "item_id") @TableField(value = "item_id")
private Integer itemId; private String itemId;
/** /**
* 创建时间 * 创建时间
@ -104,4 +104,9 @@ public class AlarmRule implements Serializable {
@TableField(value = "update_by") @TableField(value = "update_by")
private String updateBy; private String updateBy;
/**
* 用于新增报警规则
*/
@TableField(exist = false)
private Rule rule;
} }

View File

@ -12,6 +12,8 @@ public class Rule {
private Double threshold; // 阈值 private Double threshold; // 阈值
private String units; // 单位
@JsonIgnore @JsonIgnore
private Double current; // 当前值 private Double current; // 当前值
} }

View File

@ -22,6 +22,9 @@ public class SysEmail implements Serializable {
@TableId(value = "id", type = IdType.ASSIGN_ID) @TableId(value = "id", type = IdType.ASSIGN_ID)
private String id; private String id;
@TableField("name")
private String name;
/** /**
* email服务地址 * email服务地址
*/ */

View File

@ -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<String,Item> items;
private String status;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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<Host> records;
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -1,6 +1,8 @@
package org.jeecg.modules.base.enums; package org.jeecg.modules.base.enums;
import cn.hutool.core.util.StrUtil;
/** /**
* 资源类型 * 资源类型
* *
@ -22,4 +24,12 @@ public enum SourceType {
public String getType() { public String getType() {
return type; return type;
} }
public static SourceType typeOf(String type){
for (SourceType sourceType : SourceType.values()) {
if (StrUtil.equals(sourceType.getType(),type))
return sourceType;
}
return null;
}
} }

View File

@ -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;
}

View File

@ -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<String> sourceId;
private String startDate;
private String endDate;
private Integer pageStart;
}

View File

@ -1,5 +1,6 @@
package org.jeecg.modules.controller; package org.jeecg.modules.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.jeecg.common.api.QueryRequest; import org.jeecg.common.api.QueryRequest;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
@ -10,6 +11,7 @@ import org.springframework.web.bind.annotation.*;
@RestController @RestController
@RequestMapping("alarmContactGroup") @RequestMapping("alarmContactGroup")
@Api(value = "联系组管理", tags = "联系组管理")
public class AlarmContactGroupController { public class AlarmContactGroupController {
@Autowired @Autowired

View File

@ -1,5 +1,6 @@
package org.jeecg.modules.controller; package org.jeecg.modules.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.jeecg.common.api.QueryRequest; import org.jeecg.common.api.QueryRequest;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
@ -11,6 +12,7 @@ import org.springframework.web.bind.annotation.*;
@RestController @RestController
@RequestMapping("alarmContactGroupMember") @RequestMapping("alarmContactGroupMember")
@Api(value = "联系组成员管理", tags = "联系组成员管理")
public class AlarmContactGroupMemberController { public class AlarmContactGroupMemberController {
@Autowired @Autowired

View File

@ -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<AlarmItem, IAlarmItemService> {
@Autowired
private IAlarmItemService alarmItemService;
}

View File

@ -2,31 +2,41 @@ package org.jeecg.modules.controller;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.jeecg.common.api.QueryRequest;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.base.entity.AlarmRule; 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.jeecg.modules.service.IAlarmRuleService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.*;
import java.util.stream.Collectors;
@RestController @RestController
@RequestMapping("alarmRule") @RequestMapping("alarmRule")
@Api(value = "报警规则管理", tags = "报警规则管理") @Api(value = "报警规则管理", tags = "报警规则管理")
public class AlarmRuleController { public class AlarmRuleController {
@Autowired
private MonitorAlarm monitorAlarm;
@Autowired @Autowired
private IAlarmRuleService alarmRuleService; private IAlarmRuleService alarmRuleService;
@GetMapping("findPage") @GetMapping("findPage")
@ApiOperation(value = "分页查询报警规则信息", notes = "分页查询报警规则信息") @ApiOperation(value = "分页查询报警规则", notes = "分页查询报警规则")
public Result findPage(QueryRequest queryRequest, AlarmRule alarmRule){ public Result findPage(AlarmRuleVo alarmRuleVo){
return alarmRuleService.findPage(queryRequest, alarmRule); return alarmRuleService.findPage(alarmRuleVo);
} }
@GetMapping("findInfo") @GetMapping("findInfo")
@ApiOperation(value = "查看规则信息详情", notes = "查看规则信息详情") @ApiOperation(value = "查看规则信息详情", notes = "查看规则信息详情")
public Result findInfo(String id){ public Result findInfo(@RequestParam String alarmRuleId){
return alarmRuleService.findInfo(id); return alarmRuleService.findInfo(alarmRuleId);
} }
@PostMapping("create") @PostMapping("create")
@ -43,8 +53,36 @@ public class AlarmRuleController {
@DeleteMapping("deleteById") @DeleteMapping("deleteById")
@ApiOperation(value = "删除规则信息", notes = "删除规则信息") @ApiOperation(value = "删除规则信息", notes = "删除规则信息")
public Result deleteById(String id){ public Result deleteById(@RequestParam String alarmRuleId){
return alarmRuleService.deleteById(id); 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<Servers> result = monitorAlarm.listBack(sourceName);
List<Host> hosts = result.getResult().getRecords();
List<ItemDto> 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);
}
} }

View File

@ -4,14 +4,14 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.jeecg.common.api.QueryRequest; import org.jeecg.common.api.QueryRequest;
import org.jeecg.common.api.vo.Result; 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.entity.SysDatabase;
import org.jeecg.modules.service.ISysDatabaseService; import org.jeecg.modules.service.ISysDatabaseService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.validation.Valid; import java.util.List;
import java.util.Date;
@RestController @RestController
@RequestMapping("sysDatabase") @RequestMapping("sysDatabase")
@ -23,8 +23,8 @@ public class SysDatabaseController {
@GetMapping("findPage") @GetMapping("findPage")
@ApiOperation(value = "分页查询数据库配置信息", notes = "分页查询数据库配置信息") @ApiOperation(value = "分页查询数据库配置信息", notes = "分页查询数据库配置信息")
public Result findPage(QueryRequest queryRequest, SysDatabase sysDatabase){ public Result findPage(QueryRequest query){
return sysDatabaseService.findPage(queryRequest, sysDatabase); return sysDatabaseService.findPage(query);
} }
@GetMapping("findInfo") @GetMapping("findInfo")
@ -53,9 +53,14 @@ public class SysDatabaseController {
@GetMapping("findAlarmHistory") @GetMapping("findAlarmHistory")
@ApiOperation(value = "查询数据库历史报警信息", notes = "查询数据库历史报警信息") @ApiOperation(value = "查询数据库历史报警信息", notes = "查询数据库历史报警信息")
public Result findAlarmHistory(String databaseId, public Result findAlarmHistory(SourceVo sourceVo){
@DateTimeFormat(pattern = "yyyy-MM-dd") Date startTime, @DateTimeFormat(pattern = "yyyy-MM-dd") Date endTime){ return sysDatabaseService.findAlarmHistory(sourceVo);
return sysDatabaseService.findAlarmHistory(databaseId, startTime, endTime);
} }
@GetMapping("sourceList")
@ApiOperation(value = "数据库服务名列表",notes = "数据库服务名列表")
public Result sourceList(){
List<SourceDto> sourceDtos = sysDatabaseService.listAll();
return Result.OK(sourceDtos);
}
} }

View File

@ -5,16 +5,19 @@ import io.swagger.annotations.ApiOperation;
import org.jeecg.common.api.QueryRequest; import org.jeecg.common.api.QueryRequest;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.base.entity.SysEmail; 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.jeecg.modules.service.ISysEmailService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.Date; import java.util.Date;
import java.util.List;
@RestController @RestController
@RequestMapping("sysEmail") @RequestMapping("sysEmail")
@Api(value = "邮箱配置信息管理", tags = "邮箱配置信息管理") @Api(value = "邮箱配置管理", tags = "邮箱配置管理")
public class SysEmailController { public class SysEmailController {
@Autowired @Autowired
@ -22,8 +25,8 @@ public class SysEmailController {
@GetMapping("findPage") @GetMapping("findPage")
@ApiOperation(value = "分页查询邮箱配置信息", notes = "分页查询邮箱配置信息") @ApiOperation(value = "分页查询邮箱配置信息", notes = "分页查询邮箱配置信息")
public Result findPage(QueryRequest queryRequest, SysEmail sysEmail){ public Result findPage(QueryRequest query){
return sysEmailService.findPage(queryRequest, sysEmail); return sysEmailService.findPage(query);
} }
@GetMapping("findInfo") @GetMapping("findInfo")
@ -52,13 +55,20 @@ public class SysEmailController {
@GetMapping("findAlarmHistory") @GetMapping("findAlarmHistory")
@ApiOperation(value = "查询邮箱历史报警信息", notes = "查询邮箱历史报警信息") @ApiOperation(value = "查询邮箱历史报警信息", notes = "查询邮箱历史报警信息")
public Result findAlarmHistory(String emailId, public Result findAlarmHistory(SourceVo sourceVo){
@DateTimeFormat(pattern = "yyyy-MM-dd") Date startTime, @DateTimeFormat(pattern = "yyyy-MM-dd") Date endTime){ return sysEmailService.findAlarmHistory(sourceVo);
return sysEmailService.findAlarmHistory(emailId, startTime, endTime);
} }
@GetMapping("getSender") @GetMapping("getSender")
@ApiOperation(value = "获取发件邮箱服务器", notes = "获取发件邮箱服务器")
public Result<SysEmail> getSender(){ public Result<SysEmail> getSender(){
return sysEmailService.getSender(); return sysEmailService.getSender();
} }
@GetMapping("sourceList")
@ApiOperation(value = "邮箱服务名列表",notes = "邮箱服务名列表")
public Result sourceList(){
List<SourceDto> sourceDtos = sysEmailService.listAll();
return Result.OK(sourceDtos);
}
} }

View File

@ -4,6 +4,8 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.jeecg.common.api.QueryRequest; import org.jeecg.common.api.QueryRequest;
import org.jeecg.common.api.vo.Result; 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.entity.SysServer;
import org.jeecg.modules.service.ISysServerService; import org.jeecg.modules.service.ISysServerService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -11,10 +13,11 @@ import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.Date; import java.util.Date;
import java.util.List;
@RestController @RestController
@RequestMapping("sysServer") @RequestMapping("sysServer")
@Api(value = "服务器配置信息管理", tags = "服务器配置信息管理") @Api(value = "服务器配置管理", tags = "服务器配置管理")
public class SysServerController { public class SysServerController {
@Autowired @Autowired
@ -22,8 +25,8 @@ public class SysServerController {
@GetMapping("findPage") @GetMapping("findPage")
@ApiOperation(value = "分页查询服务器数据", notes = "分页查询服务器数据") @ApiOperation(value = "分页查询服务器数据", notes = "分页查询服务器数据")
public Result findPage(QueryRequest queryRequest, SysServer sysServer){ public Result findPage(QueryRequest query){
return sysServerService.findPage(queryRequest, sysServer); return sysServerService.findPage(query);
} }
@GetMapping("findInfo") @GetMapping("findInfo")
@ -52,9 +55,14 @@ public class SysServerController {
@GetMapping("findAlarmHistory") @GetMapping("findAlarmHistory")
@ApiOperation(value = "查询服务器历史报警信息", notes = "查询服务器历史报警信息") @ApiOperation(value = "查询服务器历史报警信息", notes = "查询服务器历史报警信息")
public Result findAlarmHistory(String serverId, public Result findAlarmHistory(SourceVo sourceVo){
@DateTimeFormat(pattern = "yyyy-MM-dd") Date startTime,@DateTimeFormat(pattern = "yyyy-MM-dd") Date endTime){ return sysServerService.findAlarmHistory(sourceVo);
return sysServerService.findAlarmHistory(serverId, startTime, endTime);
} }
@GetMapping("sourceList")
@ApiOperation(value = "服务器服务名列表",notes = "服务器服务名列表")
public Result sourceList(){
List<SourceDto> sourceDtos = sysServerService.listAll();
return Result.OK(sourceDtos);
}
} }

View File

@ -36,4 +36,9 @@ public class AlarmHistory {
* 来源类型 * 来源类型
*/ */
private String sourceType; private String sourceType;
/**
* 报警值
*/
private String alarmValue;
} }

View File

@ -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<Servers> listBack(@RequestParam String code);
@GetMapping("queryItemHistory")
Result<ItemHistory> 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);
}

View File

@ -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<AlarmItem> {
}

View File

@ -1,7 +1,16 @@
package org.jeecg.modules.mapper; package org.jeecg.modules.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; 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 org.jeecg.modules.base.entity.AlarmRule;
import java.util.List;
import java.util.Map;
public interface AlarmRuleMapper extends BaseMapper<AlarmRule> { public interface AlarmRuleMapper extends BaseMapper<AlarmRule> {
List<AlarmRuleDto> findPage(Map<String, Object> params);
AlarmRuleInfo findInfo(String alarmRuleId);
} }

View File

@ -2,14 +2,18 @@ package org.jeecg.modules.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param; 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.AlarmHistory;
import org.jeecg.modules.entity.SysDatabase; import org.jeecg.modules.entity.SysDatabase;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map;
public interface SysDatabaseMapper extends BaseMapper<SysDatabase> { public interface SysDatabaseMapper extends BaseMapper<SysDatabase> {
List<AlarmHistory> findAlarmHistory(@Param("databaseId") String databaseId, @Param("startDate") Date startDate, @Param("endDate") Date endDate); List<AlarmHistory> findAlarmHistory(Map<String,Object> params);
List<DatabaseDto> findPage(Map<String,Object> params);
} }

View File

@ -2,14 +2,18 @@ package org.jeecg.modules.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param; 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.entity.AlarmHistory;
import org.jeecg.modules.base.entity.SysEmail; import org.jeecg.modules.base.entity.SysEmail;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map;
public interface SysEmailMapper extends BaseMapper<SysEmail> { public interface SysEmailMapper extends BaseMapper<SysEmail> {
List<AlarmHistory> findAlarmHistory( @Param("emailId") String emailId, @Param("startDate") Date startDate, @Param("endDate") Date endDate); List<AlarmHistory> findAlarmHistory(Map<String,Object> params);
List<EmailDto> findPage(Map<String,Object> params);
} }

View File

@ -2,14 +2,18 @@ package org.jeecg.modules.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param; 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.AlarmHistory;
import org.jeecg.modules.entity.SysServer; import org.jeecg.modules.entity.SysServer;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map;
public interface SysServerMapper extends BaseMapper<SysServer> { public interface SysServerMapper extends BaseMapper<SysServer> {
List<AlarmHistory> findAlarmHistory(@Param("serverId")String serverId, @Param("startDate") Date startDate, @Param("endDate") Date endDate); List<AlarmHistory> findAlarmHistory(Map<String,Object> params);
List<ServerDto> findPage(Map<String,Object> params);
} }

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.jeecg.modules.mapper.AlarmItemMapper">
</mapper>

View File

@ -29,6 +29,7 @@
(SELECT (SELECT
l.alarm_start_date, l.alarm_start_date,
l.alarm_info, l.alarm_info,
l.alarm_value,
r.OPERATOR, r.OPERATOR,
r.source_type, r.source_type,
CASE CASE
@ -61,6 +62,7 @@
AND alarm_start_date &lt;= #{endDate} AND alarm_start_date &lt;= #{endDate}
</if> </if>
</where> </where>
ORDER BY alarm_start_date DESC
<if test="pageFlag == null"> <if test="pageFlag == null">
LIMIT #{pageSize} OFFSET #{pageStart} LIMIT #{pageSize} OFFSET #{pageStart}
</if> </if>

View File

@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.jeecg.modules.mapper.AlarmRuleMapper">
<select id="findPage" parameterType="Map" resultType="org.jeecg.modules.base.dto.AlarmRuleDto">
SELECT
*
FROM
(SELECT
r.id,
r.NAME,
r.enabled,
r.OPERATOR,
r.source_type,
r.source_id,
g.NAME AS groupName,
CASE
r.source_type
WHEN 'Server' THEN
( SELECT NAME FROM sys_server WHERE ID = r.source_id )
WHEN 'Database' THEN
( SELECT NAME FROM sys_database WHERE ID = r.source_id )
WHEN 'Email' THEN
( SELECT USERNAME FROM sys_email WHERE ID = r.source_id )
END AS sourceName
FROM
alarm_rule r
INNER JOIN alarm_contact_group g ON g.id = r.contact_id
) AS res
<where>
<if test="enabled != null">
enabled = #{enabled}
</if>
<if test="sourceType != null and sourceType != ''">
AND source_type = #{sourceType}
</if>
<if test="sourceId != null and sourceId != ''">
AND source_id = #{sourceId}
</if>
</where>
<if test="pageFlag == null">
LIMIT #{pageSize} OFFSET #{pageStart}
</if>
</select>
<select id="findInfo" parameterType="String" resultType="org.jeecg.modules.base.dto.AlarmRuleInfo">
SELECT
*
FROM
(SELECT
r.id,
r.NAME,
r.OPERATOR,
r.silence_cycle,
r.contact_id,
r.source_id,
r.source_type,
r.item_id,
CASE
r.source_type
WHEN 'Server' THEN
( SELECT NAME FROM sys_server WHERE ID = r.source_id )
WHEN 'Database' THEN
( SELECT NAME FROM sys_database WHERE ID = r.source_id )
WHEN 'Email' THEN
( SELECT USERNAME FROM sys_email WHERE ID = r.source_id )
END AS sourceName
FROM
alarm_rule r
) AS res
<where>
<if test="alarmRuleId != null and alarmRuleId != ''">
id = #{alarmRuleId}
</if>
</where>
</select>
</mapper>

View File

@ -1,23 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.jeecg.modules.mapper.SysEmailMapper"> <mapper namespace="org.jeecg.modules.mapper.SysEmailMapper">
<select id="findAlarmHistory" resultType="org.jeecg.modules.entity.AlarmHistory"> <select id="findAlarmHistory" resultType="org.jeecg.modules.entity.AlarmHistory">
SELECT SELECT
se.name, e.name,
l.alarm_start_date, l.alarm_start_date,
l.alarm_info, l.alarm_info,
r.operator r.operator,
l.alarm_value
FROM FROM
sys_email se sys_email e
inner join alarm_rule r on r.source_id = se.id INNER JOIN alarm_rule r ON r.source_id = e.id
inner join alarm_log l on l.rule_id = r.id INNER JOIN alarm_log l ON l.rule_id = r.id
<where> <where>
l.alarm_start_date between #{startDate} and #{endDate} <if test="sourceId != null and sourceId.size() > 0">
<if test=" emailId != null and emailId != '' "> e.id IN
and se.id = #{emailId} <foreach collection="sourceId" index="index" open="(" close=")" item="item" separator=",">
#{item}
</foreach>
</if>
<if test="startDate != null and startDate != ''">
AND l.alarm_start_date &gt;= #{startDate}
</if>
<if test="endDate != null and endDate != ''">
AND l.alarm_start_date &lt;= #{endDate}
</if> </if>
</where> </where>
ORDER BY alarm_start_date DESC
<if test="pageFlag == null">
LIMIT #{pageSize} OFFSET #{pageStart}
</if>
</select>
<select id="findPage" resultType="org.jeecg.modules.base.dto.EmailDto">
SELECT
e.ID,
e.NAME,
e.enabled,
e.email_server_address,
COUNT (l.id) AS alarms
FROM
sys_email e
LEFT JOIN alarm_rule r ON e.ID = r.source_id
LEFT JOIN alarm_log l ON r.ID = l.rule_id
AND l.alarm_start_date BETWEEN #{startDate} AND #{endDate}
GROUP BY e.ID, e.NAME, e.email_server_address
<if test="pageFlag == null">
LIMIT #{pageSize} OFFSET #{pageStart}
</if>
</select> </select>
</mapper> </mapper>

View File

@ -1,23 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.jeecg.modules.mapper.SysServerMapper"> <mapper namespace="org.jeecg.modules.mapper.SysServerMapper">
<select id="findAlarmHistory" resultType="org.jeecg.modules.entity.AlarmHistory"> <select id="findAlarmHistory" resultType="org.jeecg.modules.entity.AlarmHistory">
SELECT SELECT
se.name, s.name,
l.alarm_start_date, l.alarm_start_date,
l.alarm_info, l.alarm_info,
r.operator r.operator,
l.alarm_value
FROM FROM
sys_server se sys_server s
inner join alarm_rule r on r.source_id = se.id INNER JOIN alarm_rule r ON r.source_id = s.id
inner join alarm_log l on l.rule_id = r.id INNER JOIN alarm_log l ON l.rule_id = r.id
<where> <where>
l.alarm_start_date between #{startDate} and #{endDate} <if test="sourceId != null and sourceId.size() > 0">
<if test=" serverId != null and serverId != '' "> s.id IN
and se.id = #{serverId} <foreach collection="sourceId" index="index" open="(" close=")" item="item" separator=",">
#{item}
</foreach>
</if>
<if test="startDate != null and startDate != ''">
AND l.alarm_start_date &gt;= #{startDate}
</if>
<if test="endDate != null and endDate != ''">
AND l.alarm_start_date &lt;= #{endDate}
</if> </if>
</where> </where>
ORDER BY alarm_start_date DESC
<if test="pageFlag == null">
LIMIT #{pageSize} OFFSET #{pageStart}
</if>
</select>
<select id="findPage" resultType="org.jeecg.modules.base.dto.ServerDto">
SELECT
s.ID,
s.NAME,
s.ip_address,
COUNT (l.id) AS alarms
FROM
sys_server s
LEFT JOIN alarm_rule r ON s.ID = r.source_id
LEFT JOIN alarm_log l ON r.ID = l.rule_id
AND l.alarm_start_date BETWEEN #{startDate} AND #{endDate}
GROUP BY s.ID,s.NAME,s.ip_address
<if test="pageFlag == null">
LIMIT #{pageSize} OFFSET #{pageStart}
</if>
</select> </select>
</mapper> </mapper>

View File

@ -4,20 +4,50 @@
<select id="findAlarmHistory" resultType="org.jeecg.modules.entity.AlarmHistory"> <select id="findAlarmHistory" resultType="org.jeecg.modules.entity.AlarmHistory">
SELECT SELECT
se.name, d.name,
l.alarm_start_date, l.alarm_start_date,
l.alarm_info, l.alarm_info,
r.operator r.operator,
l.alarm_value
FROM FROM
sys_database se sys_database d
inner join alarm_rule r on r.source_id = se.id INNER JOIN alarm_rule r ON r.source_id = d.id
inner join alarm_log l on l.rule_id = r.id INNER JOIN alarm_log l ON l.rule_id = r.id
<where> <where>
l.alarm_start_date between #{startDate} and #{endDate} <if test="sourceId != null and sourceId.size() > 0">
<if test=" databaseId != null and databaseId != '' "> d.id IN
and se.id = #{databaseId} <foreach collection="sourceId" index="index" open="(" close=")" item="item" separator=",">
#{item}
</foreach>
</if>
<if test="startDate != null and startDate != ''">
AND l.alarm_start_date &gt;= #{startDate}
</if>
<if test="endDate != null and endDate != ''">
AND l.alarm_start_date &lt;= #{endDate}
</if> </if>
</where> </where>
ORDER BY alarm_start_date DESC
<if test="pageFlag == null">
LIMIT #{pageSize} OFFSET #{pageStart}
</if>
</select>
<select id="findPage" resultType="org.jeecg.modules.base.dto.DatabaseDto">
SELECT
d.ID,
d.NAME,
d.port,
d.ip_address,
COUNT (l.id) AS alarms
FROM
sys_database d
LEFT JOIN alarm_rule r ON d.ID = r.source_id
LEFT JOIN alarm_log l ON r.ID = l.rule_id
AND l.alarm_start_date BETWEEN #{startDate} AND #{endDate}
GROUP BY d.ID, d.NAME, d.port, d.ip_address
<if test="pageFlag == null">
LIMIT #{pageSize} OFFSET #{pageStart}
</if>
</select> </select>
</mapper> </mapper>

View File

@ -19,4 +19,5 @@ public interface IAlarmContactGroupService extends IService<AlarmContactGroup> {
Result deleteUserById(String id, String userId); Result deleteUserById(String id, String userId);
AlarmContactGroup getByName(String groupName);
} }

View File

@ -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<AlarmItem> {
Result syncItem(String sourceType,String code);
}

View File

@ -4,16 +4,21 @@ import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.common.api.QueryRequest; import org.jeecg.common.api.QueryRequest;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.base.entity.AlarmRule; import org.jeecg.modules.base.entity.AlarmRule;
import org.jeecg.modules.base.vo.AlarmRuleVo;
public interface IAlarmRuleService extends IService<AlarmRule> { public interface IAlarmRuleService extends IService<AlarmRule> {
Result findPage(QueryRequest queryRequest, AlarmRule alarmRule); Result findPage(AlarmRuleVo alarmRuleVo);
Result findInfo(String id); Result findInfo(String alarmRuleId);
Result create(AlarmRule alarmRule); Result create(AlarmRule alarmRule);
Result update(AlarmRule alarmRule); Result update(AlarmRule alarmRule);
Result deleteById(String id); Result deleteById(String alarmRuleId);
Result getSourceByType(String sourceType);
Result updateStatus(String alarmRuleId,Integer enabled);
} }

View File

@ -3,14 +3,16 @@ package org.jeecg.modules.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.common.api.QueryRequest; import org.jeecg.common.api.QueryRequest;
import org.jeecg.common.api.vo.Result; 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.entity.SysDatabase;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date; import java.util.Date;
import java.util.List;
public interface ISysDatabaseService extends IService<SysDatabase> { public interface ISysDatabaseService extends IService<SysDatabase> {
Result findPage(QueryRequest queryRequest, SysDatabase sysDatabase); Result findPage(QueryRequest query);
Result findInfo(String id); Result findInfo(String id);
@ -20,6 +22,7 @@ public interface ISysDatabaseService extends IService<SysDatabase> {
Result deleteById(String id); Result deleteById(String id);
Result findAlarmHistory(String databaseId, Date startTime, Date endTime); Result findAlarmHistory(SourceVo sourceVo);
List<SourceDto> listAll();
} }

View File

@ -4,12 +4,15 @@ import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.common.api.QueryRequest; import org.jeecg.common.api.QueryRequest;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.base.entity.SysEmail; 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.Date;
import java.util.List;
public interface ISysEmailService extends IService<SysEmail> { public interface ISysEmailService extends IService<SysEmail> {
Result findPage(QueryRequest queryRequest, SysEmail sysEmail); Result findPage(QueryRequest query);
Result findInfo(String id); Result findInfo(String id);
@ -19,8 +22,9 @@ public interface ISysEmailService extends IService<SysEmail> {
Result deleteById(String id); Result deleteById(String id);
Result findAlarmHistory(String emailId, Date startTime, Date endTime); Result findAlarmHistory(SourceVo sourceVo);
Result<SysEmail> getSender(); Result<SysEmail> getSender();
List<SourceDto> listAll();
} }

View File

@ -3,13 +3,16 @@ package org.jeecg.modules.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.common.api.QueryRequest; import org.jeecg.common.api.QueryRequest;
import org.jeecg.common.api.vo.Result; 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.entity.SysServer;
import java.util.Date; import java.util.Date;
import java.util.List;
public interface ISysServerService extends IService<SysServer> { public interface ISysServerService extends IService<SysServer> {
Result findPage(QueryRequest queryRequest, SysServer sysServer); Result findPage(QueryRequest query);
Result findInfo(String id); Result findInfo(String id);
@ -19,6 +22,9 @@ public interface ISysServerService extends IService<SysServer> {
Result deleteById(String id); Result deleteById(String id);
Result findAlarmHistory(String serverId, Date startTime, Date endTime); Result findAlarmHistory(SourceVo sourceVo);
List<SourceDto> listAll();
String getByName(String name);
} }

View File

@ -1,5 +1,7 @@
package org.jeecg.modules.service.impl; 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.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.IdWorker;
@ -38,6 +40,7 @@ public class AlarmContactGroupServiceImpl extends ServiceImpl<AlarmContactGroupM
Map<String ,SysUser> userList = systemClient.findUserMap(); Map<String ,SysUser> userList = systemClient.findUserMap();
Page<AlarmContactGroup> page = new Page<>(queryRequest.getPageNo(), queryRequest.getPageSize()); Page<AlarmContactGroup> page = new Page<>(queryRequest.getPageNo(), queryRequest.getPageSize());
LambdaQueryWrapper<AlarmContactGroup> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<AlarmContactGroup> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.orderByDesc(AlarmContactGroup::getCreateTime);
Page<AlarmContactGroup> alarmContactGroupPage = this.baseMapper.selectPage(page, queryWrapper); Page<AlarmContactGroup> alarmContactGroupPage = this.baseMapper.selectPage(page, queryWrapper);
LambdaQueryWrapper<AlarmContactGroupMember> contactGroupMemberQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<AlarmContactGroupMember> contactGroupMemberQueryWrapper = new LambdaQueryWrapper<>();
List<AlarmContactGroupMember> alarmContactGroupMembers = alarmContactGroupMemberMapper.selectList(contactGroupMemberQueryWrapper); List<AlarmContactGroupMember> alarmContactGroupMembers = alarmContactGroupMemberMapper.selectList(contactGroupMemberQueryWrapper);
@ -74,7 +77,7 @@ public class AlarmContactGroupServiceImpl extends ServiceImpl<AlarmContactGroupM
queryWrapper.eq(AlarmContactGroup::getId, id); queryWrapper.eq(AlarmContactGroup::getId, id);
AlarmContactGroup alarmContactGroup = this.baseMapper.selectOne(queryWrapper); AlarmContactGroup alarmContactGroup = this.baseMapper.selectOne(queryWrapper);
if (Objects.isNull(alarmContactGroup)){ if (Objects.isNull(alarmContactGroup)){
result.error500("查询数据失败,对应数据不存在"); result.error500("Failed to query the data because the corresponding data does not exist!");
return result; return result;
} }
//通过联系人组id查询出对应的联系人信息 //通过联系人组id查询出对应的联系人信息
@ -95,6 +98,12 @@ public class AlarmContactGroupServiceImpl extends ServiceImpl<AlarmContactGroupM
Result result = new Result(); Result result = new Result();
//获取request //获取request
HttpServletRequest request = SpringContextUtils.getHttpServletRequest(); HttpServletRequest request = SpringContextUtils.getHttpServletRequest();
String groupName = alarmContactGroup.getName();
if (StrUtil.isBlank(groupName))return Result.error("Please enter the contact group name!");
AlarmContactGroup contactGroup = getByName(groupName);
if (ObjectUtil.isNotNull(contactGroup))return Result.error("Contact group name cannot be repeated, please fill in again!");
//获取当前操作人用户名 //获取当前操作人用户名
String username = JwtUtil.getUserNameByToken(request); String username = JwtUtil.getUserNameByToken(request);
Long id = IdWorker.getId(); Long id = IdWorker.getId();
@ -114,7 +123,7 @@ public class AlarmContactGroupServiceImpl extends ServiceImpl<AlarmContactGroupM
} }
} }
result.setSuccess(true); result.setSuccess(true);
result.success("新增成功"); result.success("New success!");
return result; return result;
} }
@ -123,13 +132,24 @@ public class AlarmContactGroupServiceImpl extends ServiceImpl<AlarmContactGroupM
Result result = new Result(); Result result = new Result();
//获取request //获取request
HttpServletRequest request = SpringContextUtils.getHttpServletRequest(); HttpServletRequest request = SpringContextUtils.getHttpServletRequest();
String groupName = alarmContactGroup.getName();
if (StrUtil.isBlank(groupName))return Result.error("Please enter the contact group name!");
AlarmContactGroup groupById = this.getById(alarmContactGroup.getId());
boolean equals = groupById.getName().equals(alarmContactGroup.getName());
if (!equals){
AlarmContactGroup groupByName = getByName(groupName);
if (ObjectUtil.isNotNull(groupByName))
return Result.error("Contact group name cannot be repeated, please fill in again!");
}
//获取当前操作人用户名 //获取当前操作人用户名
String username = JwtUtil.getUserNameByToken(request); String username = JwtUtil.getUserNameByToken(request);
LambdaQueryWrapper<AlarmContactGroup> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<AlarmContactGroup> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(AlarmContactGroup::getId, alarmContactGroup.getId()); queryWrapper.eq(AlarmContactGroup::getId, alarmContactGroup.getId());
AlarmContactGroup contactGroup = this.baseMapper.selectOne(queryWrapper); AlarmContactGroup contactGroup = this.baseMapper.selectOne(queryWrapper);
if (Objects.isNull(contactGroup)){ if (Objects.isNull(contactGroup)){
result.error500("对应数据不存在"); result.error500("The corresponding data does not exist!");
return result; return result;
} }
if (CollectionUtils.isNotEmpty(alarmContactGroup.getUserIds())){ if (CollectionUtils.isNotEmpty(alarmContactGroup.getUserIds())){
@ -150,7 +170,7 @@ public class AlarmContactGroupServiceImpl extends ServiceImpl<AlarmContactGroupM
alarmContactGroup.setUpdateBy(username); alarmContactGroup.setUpdateBy(username);
this.baseMapper.updateById(alarmContactGroup); this.baseMapper.updateById(alarmContactGroup);
result.setSuccess(true); result.setSuccess(true);
result.success("修改成功"); result.success("Modified successfully!");
return result; return result;
} }
@ -164,7 +184,7 @@ public class AlarmContactGroupServiceImpl extends ServiceImpl<AlarmContactGroupM
//删除联系人组信息 //删除联系人组信息
this.baseMapper.deleteById(id); this.baseMapper.deleteById(id);
result.setSuccess(true); result.setSuccess(true);
result.success("删除成功"); result.success("Successfully deleted!");
return result; return result;
} }
@ -176,8 +196,15 @@ public class AlarmContactGroupServiceImpl extends ServiceImpl<AlarmContactGroupM
contactGroupMemberQueryWrapper.eq(AlarmContactGroupMember::getUserId, userId); contactGroupMemberQueryWrapper.eq(AlarmContactGroupMember::getUserId, userId);
alarmContactGroupMemberMapper.delete(contactGroupMemberQueryWrapper); alarmContactGroupMemberMapper.delete(contactGroupMemberQueryWrapper);
result.setSuccess(true); result.setSuccess(true);
result.success("删除成功"); result.success("Successfully deleted!");
return result; return result;
} }
@Override
public AlarmContactGroup getByName(String groupName) {
LambdaQueryWrapper<AlarmContactGroup> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(AlarmContactGroup::getName,groupName);
return getOne(wrapper);
}
} }

View File

@ -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<AlarmItemMapper, AlarmItem> 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<Servers> result = monitorAlarm.listBack(code);
List<Host> hosts = result.getResult().getRecords();
List<Item> 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<AlarmItem> 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);
}
}

View File

@ -2,6 +2,7 @@ package org.jeecg.modules.service.impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker; 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.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.DateConstant;
import org.jeecg.modules.dto.TypeDto; import org.jeecg.modules.dto.TypeDto;
import org.jeecg.modules.entity.AlarmHistory; import org.jeecg.modules.entity.AlarmHistory;
import org.jeecg.modules.base.entity.AlarmLog; import org.jeecg.modules.base.entity.AlarmLog;
@ -35,6 +37,8 @@ public class AlarmLogServiceImpl extends ServiceImpl<AlarmLogMapper, AlarmLog> i
public Result viewAll(AlarmVo alarmVo) { public Result viewAll(AlarmVo alarmVo) {
String startDate = alarmVo.getStartDate(); String startDate = alarmVo.getStartDate();
String endDate = alarmVo.getEndDate(); String endDate = alarmVo.getEndDate();
boolean startNotBlank = StrUtil.isNotBlank(startDate);
boolean endtNotBlank = StrUtil.isNotBlank(endDate);
// 拼接日期为合理的日期+时间范围 // 拼接日期为合理的日期+时间范围
alarmVo.setStartDate(startDate + " 00:00:00"); alarmVo.setStartDate(startDate + " 00:00:00");
alarmVo.setEndDate(endDate + " 23:59:59"); alarmVo.setEndDate(endDate + " 23:59:59");
@ -113,17 +117,22 @@ public class AlarmLogServiceImpl extends ServiceImpl<AlarmLogMapper, AlarmLog> i
public Result findPage(AlarmVo alarmVo) { public Result findPage(AlarmVo alarmVo) {
Integer pageNo = alarmVo.getPageNo(); Integer pageNo = alarmVo.getPageNo();
Integer pageSize = alarmVo.getPageSize(); Integer pageSize = alarmVo.getPageSize();
Page<AlarmHistory> 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; Integer pageStart = (pageNo - 1) * pageSize;
alarmVo.setPageStart(pageStart); alarmVo.setPageStart(pageStart);
Map<String, Object> params = BeanUtil.beanToMap(alarmVo); Map<String, Object> params = BeanUtil.beanToMap(alarmVo);
List<AlarmHistory> alarmHistories = baseMapper.findPage(params); List<AlarmHistory> alarmHistories = baseMapper.findPage(params);
// 当前页数据
page.setRecords(alarmHistories);
// 获取数据总条数(经过查询条件过滤后的) // 获取数据总条数(经过查询条件过滤后的)
params.put("pageFlag","noPage"); params.put("pageFlag","noPage");
Integer total = baseMapper.findPage(params).size(); Integer total = baseMapper.findPage(params).size();
page.setTotal(total); Page<AlarmHistory> page = new Page<>(pageNo,pageSize,total);
// 当前页数据
page.setRecords(alarmHistories);
return Result.OK(page); return Result.OK(page);
} }
@ -134,6 +143,12 @@ public class AlarmLogServiceImpl extends ServiceImpl<AlarmLogMapper, AlarmLog> i
@Override @Override
public Result typeAlarms(AlarmVo alarmVo) { 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<String, Object> params = BeanUtil.beanToMap(alarmVo); Map<String, Object> params = BeanUtil.beanToMap(alarmVo);
List<TypeDto> typeAlarms = baseMapper.typeAlarms(params); List<TypeDto> typeAlarms = baseMapper.typeAlarms(params);
@ -152,6 +167,12 @@ public class AlarmLogServiceImpl extends ServiceImpl<AlarmLogMapper, AlarmLog> i
@Override @Override
public Result ruleTop5(AlarmVo alarmVo) { 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<String, Object> params = BeanUtil.beanToMap(alarmVo); Map<String, Object> params = BeanUtil.beanToMap(alarmVo);
List<TypeDto> ruleTop5 = baseMapper.ruleTop5(params); List<TypeDto> ruleTop5 = baseMapper.ruleTop5(params);
// x轴数据 // x轴数据

View File

@ -1,130 +1,132 @@
package org.jeecg.modules.service.impl; package org.jeecg.modules.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 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.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 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.api.vo.Result;
import org.jeecg.common.constant.CommonConstant; import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.Prompt;
import org.jeecg.common.constant.SymbolConstant; import org.jeecg.common.constant.SymbolConstant;
import org.jeecg.common.system.util.JwtUtil;
import org.jeecg.common.util.RedisStreamUtil; import org.jeecg.common.util.RedisStreamUtil;
import org.jeecg.common.util.RedisUtil; import org.jeecg.modules.base.dto.AlarmRuleDto;
import org.jeecg.common.util.SpringContextUtils; import org.jeecg.modules.base.dto.AlarmRuleInfo;
import org.jeecg.modules.base.entity.AlarmRule; 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.mapper.AlarmRuleMapper;
import org.jeecg.modules.service.IAlarmRuleService; 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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import java.util.*; import java.util.*;
import static org.jeecg.modules.base.enums.SourceType.*;
@Service("alarmRuleService") @Service("alarmRuleService")
public class AlarmRuleServiceImpl extends ServiceImpl<AlarmRuleMapper, AlarmRule> implements IAlarmRuleService { public class AlarmRuleServiceImpl extends ServiceImpl<AlarmRuleMapper, AlarmRule> implements IAlarmRuleService {
@Autowired
private RedisUtil redisUtil;
@Autowired @Autowired
private RedisStreamUtil redisStreamUtil; private RedisStreamUtil redisStreamUtil;
@Autowired
private ISysEmailService emailService;
@Autowired
private ISysServerService serverService;
@Autowired
private ISysDatabaseService databaseService;
@Override @Override
public Result findPage(QueryRequest queryRequest, AlarmRule alarmRule) { public Result findPage(AlarmRuleVo alarmRuleVo) {
Result result = new Result(); Integer pageNo = alarmRuleVo.getPageNo();
Page<AlarmRule> page = new Page<>(queryRequest.getPageNo(), queryRequest.getPageSize()); Integer pageSize = alarmRuleVo.getPageSize();
LambdaQueryWrapper<AlarmRule> queryWrapper = new LambdaQueryWrapper<>(); Page<AlarmRuleDto> page = new Page<>(pageNo,pageSize);
queryWrapper.eq(Objects.nonNull(alarmRule.getEnabled()), AlarmRule::getEnabled, alarmRule.getEnabled()); Integer pageStart = (pageNo - 1) * pageSize;
queryWrapper.eq(StringUtils.isNotBlank(alarmRule.getSourceId()), AlarmRule::getSourceId, alarmRule.getSourceId()); alarmRuleVo.setPageStart(pageStart);
Page<AlarmRule> alarmRulePage = this.baseMapper.selectPage(page, queryWrapper); Map<String, Object> params = BeanUtil.beanToMap(alarmRuleVo);
result.setSuccess(true); List<AlarmRuleDto> alarmHistories = baseMapper.findPage(params);
result.setResult(alarmRulePage); // 当前页数据
return result; page.setRecords(alarmHistories);
// 获取数据总条数(经过查询条件过滤后的)
params.put("pageFlag","noPage");
Integer total = baseMapper.findPage(params).size();
page.setTotal(total);
return Result.OK(page);
} }
@Override @Override
public Result findInfo(String id) { public Result findInfo(String alarmRuleId) {
Result result = new Result(); AlarmRuleInfo alarmRuleInfo = baseMapper.findInfo(alarmRuleId);
//根据id查询对应数据信息 return Result.OK(alarmRuleInfo);
LambdaQueryWrapper<AlarmRule> 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;
} }
@Override @Override
public Result create(AlarmRule alarmRule) { public Result create(AlarmRule alarmRule) {
Result result = new Result(); Rule rule = alarmRule.getRule();
//获取request if (ObjectUtil.isNotNull(rule)){
HttpServletRequest request = SpringContextUtils.getHttpServletRequest(); String operator = JSON.toJSONString(rule);
//获取当前操作人用户名 alarmRule.setOperator(operator);
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);
} }
this.baseMapper.insert(alarmRule); this.baseMapper.insert(alarmRule);
result.setSuccess(true);
result.success("新增成功");
// 同步Redis
rule2Redis(); rule2Redis();
return result; return Result.OK(Prompt.ADD_SUCC);
} }
@Override @Override
public Result update(AlarmRule alarmRule) { public Result update(AlarmRule alarmRule) {
Result result = new Result(); LambdaQueryWrapper<AlarmRule> wrapper = new LambdaQueryWrapper<>();
//获取request wrapper.eq(AlarmRule::getId, alarmRule.getId());
HttpServletRequest request = SpringContextUtils.getHttpServletRequest(); AlarmRule alarmRuleOld = this.baseMapper.selectOne(wrapper);
//获取当前操作人用户名 if (ObjectUtil.isNull(alarmRuleOld)){
String username = JwtUtil.getUserNameByToken(request); return Result.error(Prompt.DATA_NOT_EXITS);
LambdaQueryWrapper<AlarmRule> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(AlarmRule::getId, alarmRule.getId());
AlarmRule rule = this.baseMapper.selectOne(queryWrapper);
if (Objects.isNull(rule)){
result.error500("对应数据不存在");
return result;
} }
alarmRule.setUpdateTime(new Date()); Rule rule = alarmRule.getRule();
alarmRule.setUpdateBy(username); if (ObjectUtil.isNotNull(rule)){
if (StringUtils.isNotBlank(alarmRule.getOperator())){ String operator = JSON.toJSONString(rule);
String jsonString = JSON.toJSONString(alarmRule.getOperator()); alarmRule.setOperator(operator);
alarmRule.setOperator(jsonString);
} }
this.baseMapper.updateById(alarmRule); this.baseMapper.updateById(alarmRule);
result.setSuccess(true);
result.success("修改成功");
// 同步Redis
rule2Redis(); rule2Redis();
return result; return Result.OK(Prompt.UPDATE_SUCC);
} }
@Override @Override
public Result deleteById(String id) { public Result deleteById(String alarmRuleId) {
Result result = new Result(); this.baseMapper.deleteById(alarmRuleId);
this.baseMapper.deleteById(id);
result.setSuccess(true);
result.success("删除成功");
// 同步Redis
rule2Redis(); rule2Redis();
return result; return Result.OK(Prompt.DELETE_SUCC);
}
@Override
public Result getSourceByType(String sourceType) {
List<SourceDto> 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);
} }
/* /*

View File

@ -1,14 +1,20 @@
package org.jeecg.modules.service.impl; 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.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.api.QueryRequest; import org.jeecg.common.api.QueryRequest;
import org.jeecg.common.api.vo.Result; 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.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.AlarmHistory;
import org.jeecg.modules.entity.SysDatabase; import org.jeecg.modules.entity.SysDatabase;
import org.jeecg.modules.mapper.SysDatabaseMapper; import org.jeecg.modules.mapper.SysDatabaseMapper;
@ -16,27 +22,40 @@ import org.jeecg.modules.service.ISysDatabaseService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletRequest;
import java.text.ParseException; import java.text.ParseException;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.Date; import java.time.format.DateTimeFormatter;
import java.util.List; import java.util.*;
import java.util.Objects;
@Service("sysDatabaseService") @Service("sysDatabaseService")
public class SysDatabaseServiceImpl extends ServiceImpl<SysDatabaseMapper, SysDatabase> implements ISysDatabaseService { public class SysDatabaseServiceImpl extends ServiceImpl<SysDatabaseMapper, SysDatabase> implements ISysDatabaseService {
@Override @Override
public Result findPage(QueryRequest queryRequest, SysDatabase sysDatabase) { public Result findPage(QueryRequest query) {
Result result = new Result(); Integer pageNo = query.getPageNo();
//声明page Integer pageSize = query.getPageSize();
Page<SysDatabase> page = new Page<>(queryRequest.getPageNo(), queryRequest.getPageSize()); Integer pageStart = (pageNo - 1) * pageSize;
//分页查询数据库配置信息 Map<String,Object> params = new HashMap<>();
LambdaQueryWrapper<SysDatabase> queryWrapper = new LambdaQueryWrapper<>(); params.put("pageSize",pageSize);
Page<SysDatabase> sysDatabasePage = this.baseMapper.selectPage(page, queryWrapper); params.put("pageStart",pageStart);
result.setSuccess(true); DateTimeFormatter formatter = DateTimeFormatter
result.setResult(sysDatabasePage); .ofPattern(DateConstant.DATE);
return result; 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<DatabaseDto> 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<DatabaseDto> page = new Page<>(pageNo, pageSize, total);
page.setRecords(databaseDtos);
return Result.OK(page);
} }
@Override @Override
@ -57,76 +76,92 @@ public class SysDatabaseServiceImpl extends ServiceImpl<SysDatabaseMapper, SysDa
@Override @Override
@Transactional @Transactional
public Result create(SysDatabase sysDatabase) { public Result create(SysDatabase sysDatabase) {
Result result = new Result(); String name = sysDatabase.getName();
//获取request String ipAddress = sysDatabase.getIpAddress();
HttpServletRequest request = SpringContextUtils.getHttpServletRequest(); LambdaQueryWrapper<SysDatabase> wrapper = new LambdaQueryWrapper<>();
//获取当前操作人用户名 wrapper.eq(SysDatabase::getName,name);
String username = JwtUtil.getUserNameByToken(request); if (CollUtil.isNotEmpty(list(wrapper)))
//声明id return Result.error("Name"+Prompt.NOT_REPEAT);
Long id = IdWorker.getId(); wrapper.clear();
sysDatabase.setId(id.toString()); wrapper.eq(SysDatabase::getIpAddress,ipAddress);
sysDatabase.setCreateTime(LocalDate.now()); if (CollUtil.isNotEmpty(list(wrapper)))
sysDatabase.setCreateBy(username); return Result.error("IP Address"+Prompt.NOT_REPEAT);
this.baseMapper.insert(sysDatabase);
result.setSuccess(true); int count = baseMapper.insert(sysDatabase);
result.success("新增成功"); if (count == 1)
return result; return Result.OK(Prompt.ADD_SUCC);
return Result.error(Prompt.ADD_ERR);
} }
@Override @Override
@Transactional @Transactional
public Result update(SysDatabase sysDatabase) { public Result update(SysDatabase sysDatabase) {
Result result = new Result(); SysDatabase database = getById(sysDatabase.getId());
//获取request if (ObjectUtil.isNull(database))
HttpServletRequest request = SpringContextUtils.getHttpServletRequest(); return Result.error(Prompt.DATA_NOT_EXITS);
//获取当前操作人用户名 String name = sysDatabase.getName();
String username = JwtUtil.getUserNameByToken(request); String ipAddress = sysDatabase.getIpAddress();
LambdaQueryWrapper<SysDatabase> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SysDatabase> wrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SysDatabase::getId, sysDatabase.getId()); if (!StrUtil.equals(name,database.getName())){
SysDatabase database = this.baseMapper.selectOne(queryWrapper); wrapper.eq(SysDatabase::getName,name);
if (Objects.isNull(database)){ if (CollUtil.isNotEmpty(list(wrapper)))
result.error500("对应数据不存在,修改失败"); return Result.error("Name" + Prompt.NOT_REPEAT);
return result; wrapper.clear();
} }
sysDatabase.setUpdateTime(LocalDate.now()); if (!StrUtil.equals(ipAddress,database.getIpAddress())){
sysDatabase.setUpdateBy(username); wrapper.eq(SysDatabase::getIpAddress,ipAddress);
this.baseMapper.updateById(sysDatabase); if (CollUtil.isNotEmpty(list(wrapper)))
result.setSuccess(true); return Result.error("IP Address" + Prompt.NOT_REPEAT);
result.success("修改成功"); }
return result; int count = baseMapper.updateById(sysDatabase);
if (count == 1)
return Result.OK(Prompt.UPDATE_SUCC);
return Result.error(Prompt.UPDATE_ERR);
} }
@Override @Override
@Transactional @Transactional
public Result deleteById(String id) { public Result deleteById(String id) {
Result result = new Result(); int count = baseMapper.deleteById(id);
this.baseMapper.deleteById(id); if(count == 1)
result.setSuccess(true); return Result.OK(Prompt.DELETE_SUCC);
result.success("删除成功"); return Result.error(Prompt.DELETE_ERR);
return result;
} }
@Override @Override
public Result findAlarmHistory(String databaseId, Date startTime, Date endTime) { public Result findAlarmHistory(SourceVo sourceVo) {
Result result = new Result(); String startDate = sourceVo.getStartDate();
try { String endDate = sourceVo.getEndDate();
if (Objects.isNull(startTime)){ if (StrUtil.isNotBlank(startDate))
result.error500("开始时间不能为空"); sourceVo.setStartDate(startDate + DateConstant.TIME_START);
return result; if (StrUtil.isNotBlank(endDate))
} sourceVo.setStartDate(endDate + DateConstant.TIME_END);
if (Objects.isNull(endTime)){ Integer pageNo = sourceVo.getPageNo();
result.error500("结束时间不能为空"); Integer pageSize = sourceVo.getPageSize();
return result; Integer pageStart = (pageNo - 1) * pageSize;
} sourceVo.setPageStart(pageStart);
Date startDate = DateUtils.parseDate(DateUtils.formatDate(startTime, "yyyy-MM-dd") + " 00:00:00", "yyyy-MM-dd HH:mm:ss"); Map<String, Object> params = BeanUtil.beanToMap(sourceVo);
Date endDate = DateUtils.parseDate(DateUtils.formatDate(endTime, "yyyy-MM-dd") + " 23:59:59", "yyyy-MM-dd HH:mm:ss"); List<AlarmHistory> alarmHistories = baseMapper.findAlarmHistory(params);
List<AlarmHistory> alarmHistory = this.baseMapper.findAlarmHistory(databaseId, startDate, endDate); // 获取数据总条数(经过查询条件过滤后的)
result.setSuccess(true); params.put("pageFlag","noPage");
result.setResult(alarmHistory); Integer total = baseMapper.findAlarmHistory(params).size();
} catch (ParseException e) { Page<AlarmHistory> page = new Page<>(pageNo,pageSize,total);
throw new RuntimeException(e); // 当前页数据
page.setRecords(alarmHistories);
return Result.OK(page);
}
@Override
public List<SourceDto> listAll() {
LambdaQueryWrapper<SysDatabase> wrapper = new LambdaQueryWrapper<>();
List<SourceDto> 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;
} }
} }

View File

@ -1,16 +1,22 @@
package org.jeecg.modules.service.impl; 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.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.api.QueryRequest; import org.jeecg.common.api.QueryRequest;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant; 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.email.emuns.SysMailType;
import org.jeecg.common.system.util.JwtUtil;
import org.jeecg.common.util.DateUtils; 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.entity.AlarmHistory;
import org.jeecg.modules.base.entity.SysEmail; import org.jeecg.modules.base.entity.SysEmail;
import org.jeecg.modules.mapper.SysEmailMapper; import org.jeecg.modules.mapper.SysEmailMapper;
@ -18,27 +24,40 @@ import org.jeecg.modules.service.ISysEmailService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletRequest;
import java.text.ParseException; import java.text.ParseException;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.Date; import java.time.format.DateTimeFormatter;
import java.util.List; import java.util.*;
import java.util.Objects;
@Service("sysEmailService") @Service("sysEmailService")
public class SysEmailServiceImpl extends ServiceImpl<SysEmailMapper, SysEmail> implements ISysEmailService { public class SysEmailServiceImpl extends ServiceImpl<SysEmailMapper, SysEmail> implements ISysEmailService {
@Override @Override
public Result findPage(QueryRequest queryRequest, SysEmail sysEmail) { public Result findPage(QueryRequest query) {
Result result = new Result(); Integer pageNo = query.getPageNo();
//声明page Integer pageSize = query.getPageSize();
Page<SysEmail> page = new Page<>(queryRequest.getPageNo(), queryRequest.getPageSize()); Integer pageStart = (pageNo - 1) * pageSize;
//分页查询邮箱配置数据 Map<String,Object> params = new HashMap<>();
LambdaQueryWrapper<SysEmail> queryWrapper = new LambdaQueryWrapper<>(); params.put("pageSize",pageSize);
Page<SysEmail> sysEmailPage = this.baseMapper.selectPage(page, queryWrapper); params.put("pageStart",pageStart);
result.setSuccess(true); DateTimeFormatter formatter = DateTimeFormatter
result.setResult(sysEmailPage); .ofPattern(DateConstant.DATE);
return result; 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<EmailDto> 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<EmailDto> page = new Page<>(pageNo, pageSize, total);
page.setRecords(emailDtos);
return Result.OK(page);
} }
@Override @Override
@ -60,79 +79,68 @@ public class SysEmailServiceImpl extends ServiceImpl<SysEmailMapper, SysEmail> i
@Override @Override
@Transactional @Transactional
public Result create(SysEmail sysEmail) { public Result create(SysEmail sysEmail) {
Result result = new Result(); String name = sysEmail.getName();
//获取request LambdaQueryWrapper<SysEmail> wrapper = new LambdaQueryWrapper<>();
HttpServletRequest request = SpringContextUtils.getHttpServletRequest(); wrapper.eq(SysEmail::getName,name);
//获取当前操作人用户名 if (CollUtil.isNotEmpty(list(wrapper)))
String username = JwtUtil.getUserNameByToken(request); return Result.error("Name"+Prompt.NOT_REPEAT);
//声明id
Long id = IdWorker.getId(); int count = baseMapper.insert(sysEmail);
sysEmail.setId(id.toString()); if (count == 1)
//创建时间 return Result.OK(Prompt.ADD_SUCC);
sysEmail.setCreateTime(LocalDate.now()); return Result.error(Prompt.ADD_ERR);
sysEmail.setCreateBy(username);
this.baseMapper.insert(sysEmail);
result.setSuccess(true);
result.success("新增成功");
return result;
} }
@Override @Override
@Transactional @Transactional
public Result update(SysEmail sysEmail) { public Result update(SysEmail sysEmail) {
Result result = new Result(); SysEmail email = getById(sysEmail.getId());
//获取request if (ObjectUtil.isNull(email))
HttpServletRequest request = SpringContextUtils.getHttpServletRequest(); return Result.error(Prompt.DATA_NOT_EXITS);
//获取当前操作人用户名 String name = sysEmail.getName();
String username = JwtUtil.getUserNameByToken(request); LambdaQueryWrapper<SysEmail> wrapper = new LambdaQueryWrapper<>();
//根据id查询数据 if (!StrUtil.equals(name,email.getName())){
LambdaQueryWrapper<SysEmail> queryWrapper = new LambdaQueryWrapper<>(); wrapper.eq(SysEmail::getName,name);
queryWrapper.eq(SysEmail::getId, sysEmail.getId()); if (CollUtil.isNotEmpty(list(wrapper)))
SysEmail email = this.baseMapper.selectOne(queryWrapper); return Result.error("Name" + Prompt.NOT_REPEAT);
if (Objects.isNull(email)){ wrapper.clear();
result.error500("对应数据不存在");
return result;
} }
//创建时间 int count = baseMapper.updateById(sysEmail);
sysEmail.setUpdateTime(LocalDate.now()); if (count == 1)
sysEmail.setUpdateBy(username); return Result.OK(Prompt.UPDATE_SUCC);
this.baseMapper.updateById(sysEmail); return Result.error(Prompt.UPDATE_ERR);
result.setSuccess(true);
result.success("修改成功");
return result;
} }
@Override @Override
@Transactional @Transactional
public Result deleteById(String id) { public Result deleteById(String id) {
Result result = new Result(); int count = baseMapper.deleteById(id);
this.baseMapper.deleteById(id); if(count == 1)
result.setSuccess(true); return Result.OK(Prompt.DELETE_SUCC);
result.success("删除成功"); return Result.error(Prompt.DELETE_ERR);
return result;
} }
@Override @Override
public Result findAlarmHistory(String emailId, Date startTime, Date endTime) { public Result findAlarmHistory(SourceVo sourceVo) {
Result result = new Result(); String startDate = sourceVo.getStartDate();
try { String endDate = sourceVo.getEndDate();
if (Objects.isNull(startTime)){ if (StrUtil.isNotBlank(startDate))
result.error500("开始时间不能为空"); sourceVo.setStartDate(startDate + DateConstant.TIME_START);
return result; if (StrUtil.isNotBlank(endDate))
} sourceVo.setStartDate(endDate + DateConstant.TIME_END);
if (Objects.isNull(endTime)){ Integer pageNo = sourceVo.getPageNo();
result.error500("结束时间不能为空"); Integer pageSize = sourceVo.getPageSize();
return result; Integer pageStart = (pageNo - 1) * pageSize;
} sourceVo.setPageStart(pageStart);
Date startDate = DateUtils.parseDate(DateUtils.formatDate(startTime, "yyyy-MM-dd") + " 00:00:00", "yyyy-MM-dd HH:mm:ss"); Map<String, Object> params = BeanUtil.beanToMap(sourceVo);
Date endDate = DateUtils.parseDate(DateUtils.formatDate(endTime, "yyyy-MM-dd") + " 23:59:59", "yyyy-MM-dd HH:mm:ss"); List<AlarmHistory> alarmHistories = baseMapper.findAlarmHistory(params);
List<AlarmHistory> alarmHistory = this.baseMapper.findAlarmHistory(emailId, startDate, endDate); // 获取数据总条数(经过查询条件过滤后的)
result.setSuccess(true); params.put("pageFlag","noPage");
result.setResult(alarmHistory); Integer total = baseMapper.findAlarmHistory(params).size();
} catch (ParseException e) { Page<AlarmHistory> page = new Page<>(pageNo,pageSize,total);
throw new RuntimeException(e); // 当前页数据
} page.setRecords(alarmHistories);
return result; return Result.OK(page);
} }
/** /**
@ -148,4 +156,17 @@ public class SysEmailServiceImpl extends ServiceImpl<SysEmailMapper, SysEmail> i
return Result.OK(sysEmail); return Result.OK(sysEmail);
} }
@Override
public List<SourceDto> listAll() {
LambdaQueryWrapper<SysEmail> wrapper = new LambdaQueryWrapper<>();
List<SourceDto> sourceDtos = new ArrayList<>();
for (SysEmail sysEmail : list()) {
SourceDto sourceDto = new SourceDto();
sourceDto.setSourceId(sysEmail.getId());
sourceDto.setSourceName(sysEmail.getName());
sourceDtos.add(sourceDto);
}
return sourceDtos;
}
} }

View File

@ -1,15 +1,21 @@
package org.jeecg.modules.service.impl; 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.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.api.QueryRequest; import org.jeecg.common.api.QueryRequest;
import org.jeecg.common.api.vo.Result; 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.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.AlarmHistory;
import org.jeecg.modules.entity.SysServer; import org.jeecg.modules.entity.SysServer;
import org.jeecg.modules.mapper.SysServerMapper; import org.jeecg.modules.mapper.SysServerMapper;
@ -17,25 +23,41 @@ import org.jeecg.modules.service.ISysServerService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletRequest;
import java.text.ParseException; import java.text.ParseException;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.Date; import java.time.format.DateTimeFormatter;
import java.util.List; import java.util.*;
import java.util.Objects;
@Service("sysServerService") @Service("sysServerService")
public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer> implements ISysServerService { public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer> implements ISysServerService {
@Override @Override
public Result findPage(QueryRequest queryRequest, SysServer sysServer) { public Result findPage(QueryRequest query) {
Result result = new Result(); Integer pageNo = query.getPageNo();
Page<SysServer> page = new Page<>(queryRequest.getPageNo(), queryRequest.getPageSize()); Integer pageSize = query.getPageSize();
LambdaQueryWrapper<SysServer> queryWrapper = new LambdaQueryWrapper<>(); Integer pageStart = (pageNo - 1) * pageSize;
Page<SysServer> sysServerPage = this.baseMapper.selectPage(page, queryWrapper); Map<String,Object> params = new HashMap<>();
result.setSuccess(true); params.put("pageSize",pageSize);
result.setResult(sysServerPage); params.put("pageStart",pageStart);
return result; 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<ServerDto> 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<ServerDto> page = new Page<>(pageNo, pageSize, total);
page.setRecords(serverDtos);
return Result.OK(page);
} }
@Override @Override
@ -60,78 +82,100 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
@Override @Override
@Transactional @Transactional
public Result create(SysServer sysServer) { public Result create(SysServer sysServer) {
Result result = new Result(); String name = sysServer.getName();
//获取request String ipAddress = sysServer.getIpAddress();
HttpServletRequest request = SpringContextUtils.getHttpServletRequest(); LambdaQueryWrapper<SysServer> wrapper = new LambdaQueryWrapper<>();
//获取当前操作人用户名 wrapper.eq(SysServer::getName,name);
String username = JwtUtil.getUserNameByToken(request); if (CollUtil.isNotEmpty(list(wrapper)))
//声明id return Result.error("Name"+Prompt.NOT_REPEAT);
Long id = IdWorker.getId(); wrapper.clear();
sysServer.setId(id.toString()); wrapper.eq(SysServer::getIpAddress,ipAddress);
//赋值创建时间 if (CollUtil.isNotEmpty(list(wrapper)))
sysServer.setCreateTime(LocalDate.now()); return Result.error("IP Address"+Prompt.NOT_REPEAT);
sysServer.setCreateBy(username);
this.baseMapper.insert(sysServer); int count = baseMapper.insert(sysServer);
result.setSuccess(true); if (count == 1)
result.success("新增成功"); return Result.OK(Prompt.ADD_SUCC);
return result; return Result.error(Prompt.ADD_ERR);
} }
@Override @Override
@Transactional @Transactional
public Result update(SysServer sysServer) { public Result update(SysServer sysServer) {
Result result = new Result(); SysServer server = getById(sysServer.getId());
//获取request if (ObjectUtil.isNull(server))
HttpServletRequest request = SpringContextUtils.getHttpServletRequest(); return Result.error(Prompt.DATA_NOT_EXITS);
//获取当前操作人用户名 String name = sysServer.getName();
String username = JwtUtil.getUserNameByToken(request); String ipAddress = sysServer.getIpAddress();
//根据id查询对应数据是否存在 LambdaQueryWrapper<SysServer> wrapper = new LambdaQueryWrapper<>();
LambdaQueryWrapper<SysServer> queryWrapper = new LambdaQueryWrapper<>(); if (!StrUtil.equals(name,server.getName())){
queryWrapper.eq(SysServer::getId, sysServer.getId()); wrapper.eq(SysServer::getName,name);
SysServer server = this.baseMapper.selectOne(queryWrapper); if (CollUtil.isNotEmpty(list(wrapper)))
if (Objects.isNull(server)){ return Result.error("Name" + Prompt.NOT_REPEAT);
result.error500("当前数据不存在"); wrapper.clear();
return result;
} }
sysServer.setUpdateTime(LocalDate.now()); if (!StrUtil.equals(ipAddress,server.getIpAddress())){
sysServer.setUpdateBy(username); wrapper.eq(SysServer::getIpAddress,ipAddress);
this.baseMapper.updateById(sysServer); if (CollUtil.isNotEmpty(list(wrapper)))
result.setSuccess(true); return Result.error("IP Address" + Prompt.NOT_REPEAT);
result.success("修改成功"); }
return result; int count = baseMapper.updateById(sysServer);
if (count == 1)
return Result.OK(Prompt.UPDATE_SUCC);
return Result.error(Prompt.UPDATE_ERR);
} }
@Override @Override
@Transactional @Transactional
public Result deleteById(String id) { public Result deleteById(String id) {
Result result = new Result(); int count = baseMapper.deleteById(id);
this.baseMapper.deleteById(id); if(count == 1)
result.setSuccess(true); return Result.OK(Prompt.DELETE_SUCC);
result.success("删除成功"); return Result.error(Prompt.DELETE_ERR);
return result;
} }
@Override @Override
public Result findAlarmHistory(String serverId, Date startTime, Date endTime) { public Result findAlarmHistory(SourceVo sourceVo) {
Result result = new Result(); String startDate = sourceVo.getStartDate();
try { String endDate = sourceVo.getEndDate();
if (Objects.isNull(startTime)){ if (StrUtil.isNotBlank(startDate))
result.error500("开始时间不能为空"); sourceVo.setStartDate(startDate + DateConstant.TIME_START);
return result; if (StrUtil.isNotBlank(endDate))
} sourceVo.setStartDate(endDate + DateConstant.TIME_END);
if (Objects.isNull(endTime)){ Integer pageNo = sourceVo.getPageNo();
result.error500("结束时间不能为空"); Integer pageSize = sourceVo.getPageSize();
return result; Integer pageStart = (pageNo - 1) * pageSize;
} sourceVo.setPageStart(pageStart);
Date startDate = DateUtils.parseDate(DateUtils.formatDate(startTime, "yyyy-MM-dd") + " 00:00:00", "yyyy-MM-dd HH:mm:ss"); Map<String, Object> params = BeanUtil.beanToMap(sourceVo);
Date endDate = DateUtils.parseDate(DateUtils.formatDate(endTime, "yyyy-MM-dd") + " 23:59:59", "yyyy-MM-dd HH:mm:ss"); List<AlarmHistory> alarmHistories = baseMapper.findAlarmHistory(params);
List<AlarmHistory> alarmHistory = this.baseMapper.findAlarmHistory(serverId, startDate, endDate); // 获取数据总条数(经过查询条件过滤后的)
result.setSuccess(true); params.put("pageFlag","noPage");
result.setResult(alarmHistory); Integer total = baseMapper.findAlarmHistory(params).size();
} catch (ParseException e) { Page<AlarmHistory> page = new Page<>(pageNo,pageSize,total);
throw new RuntimeException(e); // 当前页数据
} page.setRecords(alarmHistories);
return result; return Result.OK(page);
} }
@Override
public List<SourceDto> listAll() {
LambdaQueryWrapper<SysServer> wrapper = new LambdaQueryWrapper<>();
List<SourceDto> 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<SysServer> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(SysServer::getName,name);
String id = Optional.ofNullable(getOne(wrapper, false))
.orElse(new SysServer()).getId();
return id;
}
} }

View File

@ -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<ItemDto> 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);
}

View File

@ -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<ItemHistory> itemBack(@RequestParam String itemId,
@RequestParam Integer itemType,
@RequestParam String start,
@RequestParam String end);
}

View File

@ -1,27 +1,21 @@
package org.jeecg.modules.message; package org.jeecg.modules.message;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import org.jeecg.common.api.dto.message.MessageDTO; import org.jeecg.common.api.dto.message.MessageDTO;
import org.jeecg.common.config.mqtoken.UserTokenContext; import org.jeecg.common.config.mqtoken.UserTokenContext;
import org.jeecg.common.constant.enums.MessageTypeEnum;
import org.jeecg.common.system.api.ISysBaseAPI; 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.feignclient.AbnormalAlarmClient;
import org.jeecg.modules.system.entity.SysUser; import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.service.ISysUserService; import org.jeecg.modules.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.jeecg.common.constant.enums.MessageTypeEnum.*; import static org.jeecg.common.constant.enums.MessageTypeEnum.*;
import static org.jeecg.common.util.TokenUtils.getTempToken; 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()); UserTokenContext.setToken(getTempToken());
// 封装MessageDTO消息体 // 封装MessageDTO消息体
MessageDTO messageDTO = new MessageDTO(); String title = "系统预警消息";
messageDTO.setTitle("系统预警消息"); MessageDTO messageDTO = new MessageDTO(title,message);
messageDTO.setContent(message);
Map<String, String> contact = getContact(groupId); Map<String, String> contact = getContact(groupId);
if (StrUtil.isBlank(notific))return; if (StrUtil.isBlank(notific))return;
String[] ways = notific.split(","); List<String> ways = ListUtil.toList(notific.split(","));
if (ways.contains(ALL.getValue())){
ways = ListUtil.toList(XT.getValue(), YJ.getValue(),SMS.getValue());
}
for (String way : ways) { for (String way : ways) {
if(way.equals(SYSTEM.getWay())){// 1.推送系统消息 if(way.equals(XT.getValue())){// 1.推送系统消息
String toSys = contact.get(System); String toSys = contact.get(System);
if (StrUtil.isNotBlank(toSys)){ if (StrUtil.isNotBlank(toSys)){
messageDTO.setToUser(toSys); messageDTO.setToUser(toSys);
messageDTO.setType(XT.getType()); messageDTO.setType(XT.getType());
sysBaseAPI.sendTemplateMessage(messageDTO); sysBaseAPI.sendTemplateMessage(messageDTO);
} }
} else if (way.equals(EMAIL.getWay())) {// 2.推送邮箱 } else if (way.equals(YJ.getValue())) {// 2.推送邮箱
String toEmail = contact.get(Email); String toEmail = contact.get(Email);
if (StrUtil.isNotBlank(toEmail)){ if (StrUtil.isNotBlank(toEmail)){
messageDTO.setToUser(toEmail); messageDTO.setToUser(toEmail);
messageDTO.setType(YX.getType()); messageDTO.setType(YJ.getType());
sysBaseAPI.sendTemplateMessage(messageDTO); sysBaseAPI.sendTemplateMessage(messageDTO);
} }
} else if (way.equals(PHONE.getWay())) {// 3.推送短信 } else if (way.equals(SMS.getValue())) {// 3.推送短信
String toSms = contact.get(Sms); String toSms = contact.get(Sms);
if (StrUtil.isNotBlank(toSms)){ if (StrUtil.isNotBlank(toSms)){
messageDTO.setToUser(toSms); messageDTO.setToUser(toSms);

View File

@ -12,12 +12,6 @@ import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
/**
* @Description: 消息
* @Author: jeecg-boot
* @Date: 2019-04-09
* @Version: V1.0
*/
@Data @Data
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = false)
@Accessors(chain = true) @Accessors(chain = true)
@ -25,23 +19,23 @@ import lombok.experimental.Accessors;
public class SysMessage extends JeecgEntity { public class SysMessage extends JeecgEntity {
/**推送内容*/ /**推送内容*/
@Excel(name = "推送内容", width = 15) @Excel(name = "推送内容", width = 15)
private java.lang.String esContent; private String esContent;
/**推送所需参数Json格式*/ /**推送所需参数Json格式*/
@Excel(name = "推送所需参数Json格式", width = 15) @Excel(name = "推送所需参数Json格式", width = 15)
private java.lang.String esParam; private String esParam;
/**接收人*/ /**接收人*/
@Excel(name = "接收人", width = 15) @Excel(name = "接收人", width = 15)
private java.lang.String esReceiver; private String esReceiver;
/**推送失败原因*/ /**推送失败原因*/
@Excel(name = "推送失败原因", width = 15) @Excel(name = "推送失败原因", width = 15)
private java.lang.String esResult; private String esResult;
/**发送次数*/ /**发送次数*/
@Excel(name = "发送次数", width = 15) @Excel(name = "发送次数", width = 15)
private java.lang.Integer esSendNum; private Integer esSendNum;
/**推送状态 0未推送 1推送成功 2推送失败*/ /**推送状态 0未推送 1推送成功 2推送失败*/
@Excel(name = "推送状态 0未推送 1推送成功 2推送失败", width = 15) @Excel(name = "推送状态 0未推送 1推送成功 2推送失败", width = 15)
@Dict(dicCode = "msgSendStatus") @Dict(dicCode = "msgSendStatus")
private java.lang.String esSendStatus; private String esSendStatus;
/**推送时间*/ /**推送时间*/
@Excel(name = "推送时间", width = 20, format = "yyyy-MM-dd HH:mm:ss") @Excel(name = "推送时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(timezone = "GMT+8",pattern = "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; private java.util.Date esSendTime;
/**消息标题*/ /**消息标题*/
@Excel(name = "消息标题", width = 15) @Excel(name = "消息标题", width = 15)
private java.lang.String esTitle; private String esTitle;
/** /**
* 推送方式参考枚举类MessageTypeEnum * 推送方式参考枚举类MessageTypeEnum
*/ */
@Excel(name = "推送方式", width = 15) @Excel(name = "推送方式", width = 15)
@Dict(dicCode = "messageType") @Dict(dicCode = "messageType")
private java.lang.String esType; private String esType;
/**备注*/ /**备注*/
@Excel(name = "备注", width = 15) @Excel(name = "备注", width = 15)
private java.lang.String remark; private String remark;
} }

View File

@ -10,10 +10,7 @@ import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
/** /**
* @Description: 消息模板 * 消息模板
* @Author: jeecg-boot
* @Date: 2019-04-09
* @Version: V1.0
*/ */
@Data @Data
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = false)
@ -22,19 +19,19 @@ import lombok.experimental.Accessors;
public class SysMessageTemplate extends JeecgEntity{ public class SysMessageTemplate extends JeecgEntity{
/**模板CODE*/ /**模板CODE*/
@Excel(name = "模板CODE", width = 15) @Excel(name = "模板CODE", width = 15)
private java.lang.String templateCode; private String templateCode;
/**模板标题*/ /**模板标题*/
@Excel(name = "模板标题", width = 30) @Excel(name = "模板标题", width = 30)
private java.lang.String templateName; private String templateName;
/**模板内容*/ /**模板内容*/
@Excel(name = "模板内容", width = 50) @Excel(name = "模板内容", width = 50)
private java.lang.String templateContent; private String templateContent;
/**模板测试json*/ /**模板测试json*/
@Excel(name = "模板测试json", width = 15) @Excel(name = "模板测试json", width = 15)
private java.lang.String templateTestJson; private String templateTestJson;
/**模板类型*/ /**模板类型*/
@Excel(name = "模板类型", width = 15) @Excel(name = "模板类型", width = 15)
private java.lang.String templateType; private String templateType;
/**已经应用/未应用 1是0否*/ /**已经应用/未应用 1是0否*/
@Excel(name = "应用状态", width = 15) @Excel(name = "应用状态", width = 15)

View File

@ -6,6 +6,7 @@ import org.jeecg.common.email.EmailServiceManager;
import org.jeecg.modules.base.entity.SysEmail; import org.jeecg.modules.base.entity.SysEmail;
import org.jeecg.modules.feignclient.AbnormalAlarmClient; import org.jeecg.modules.feignclient.AbnormalAlarmClient;
import org.jeecg.modules.message.handle.ISendMsgHandle; import org.jeecg.modules.message.handle.ISendMsgHandle;
import org.jeecg.modules.message.service.ISysMessageService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -25,6 +26,9 @@ public class EmailPushMsgHandle implements ISendMsgHandle {
@Autowired @Autowired
private AbnormalAlarmClient alarmClient; private AbnormalAlarmClient alarmClient;
@Autowired
private ISysMessageService sysMessageService;
@Override @Override
public void sendMessage(MessageDTO messageDTO) { public void sendMessage(MessageDTO messageDTO) {
// 获取邮件发送服务器信息 // 获取邮件发送服务器信息
@ -35,6 +39,8 @@ public class EmailPushMsgHandle implements ISendMsgHandle {
emailService.init(sysEmail); emailService.init(sysEmail);
// 发送邮件 // 发送邮件
emailService.sendMail(messageDTO); emailService.sendMail(messageDTO);
sysMessageService.add(messageDTO);
} }
@Override @Override

View File

@ -1,15 +1,13 @@
package org.jeecg.modules.message.handle.impl; package org.jeecg.modules.message.handle.impl;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.dto.message.MessageDTO; import org.jeecg.common.api.dto.message.MessageDTO;
import org.jeecg.common.util.DySmsHelper;
import org.jeecg.modules.message.handle.ISendMsgHandle; import org.jeecg.modules.message.handle.ISendMsgHandle;
import org.springframework.stereotype.Component;
/** /**
* @Description: 短信发送 * @Description: 短信发送
* @author: jeecg-boot
*/ */
@Slf4j @Component
public class SmsSendMsgHandle implements ISendMsgHandle { public class SmsSendMsgHandle implements ISendMsgHandle {
@Override @Override

View File

@ -1,5 +1,7 @@
package org.jeecg.modules.message.handle.impl; 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 cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.jeecg.common.api.dto.message.MessageDTO; 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.common.util.oConvertUtils;
import org.jeecg.modules.message.enums.Vue3MessageHrefEnum; import org.jeecg.modules.message.enums.Vue3MessageHrefEnum;
import org.jeecg.modules.message.handle.ISendMsgHandle; 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.message.websocket.WebSocket;
import org.jeecg.modules.system.entity.SysAnnouncement; import org.jeecg.modules.system.entity.SysAnnouncement;
import org.jeecg.modules.system.entity.SysAnnouncementSend; 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.SysAnnouncementMapper;
import org.jeecg.modules.system.mapper.SysAnnouncementSendMapper; import org.jeecg.modules.system.mapper.SysAnnouncementSendMapper;
import org.jeecg.modules.system.mapper.SysUserMapper; import org.jeecg.modules.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.Map; import java.util.Map;
/**
* @Description: 发送系统消息
* @Author: wangshuai
* @Date: 2022年3月22日 18:48:20
*/
@Component("systemSendMsgHandle") @Component("systemSendMsgHandle")
public class SystemSendMsgHandle implements ISendMsgHandle { 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 @Resource
private SysAnnouncementMapper sysAnnouncementMapper; private SysAnnouncementMapper sysAnnouncementMapper;
@Resource
private SysUserMapper userMapper;
@Resource @Resource
private SysAnnouncementSendMapper sysAnnouncementSendMapper; 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种消息系统消息企业微信 钉钉 * 该方法会发送3种消息系统消息企业微信 钉钉
@ -61,68 +103,4 @@ public class SystemSendMsgHandle implements ISendMsgHandle {
MessageDTO messageDTO = new MessageDTO(FROM_USER,esReceiver,esTitle,esContent); MessageDTO messageDTO = new MessageDTO(FROM_USER,esReceiver,esTitle,esContent);
sysBaseApi.sendSysAnnouncement(messageDTO); 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<String,Object> 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<String, Object> 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());
}
}
} }

View File

@ -6,12 +6,6 @@ import org.apache.ibatis.annotations.Param;
import org.jeecg.modules.message.entity.SysMessage; import org.jeecg.modules.message.entity.SysMessage;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* @Description: 消息
* @Author: jeecg-boot
* @Date: 2019-04-09
* @Version: V1.0
*/
public interface SysMessageMapper extends BaseMapper<SysMessage> { public interface SysMessageMapper extends BaseMapper<SysMessage> {
} }

View File

@ -1,14 +1,9 @@
package org.jeecg.modules.message.service; 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.common.system.base.service.JeecgService;
import org.jeecg.modules.message.entity.SysMessage; import org.jeecg.modules.message.entity.SysMessage;
/**
* @Description: 消息
* @Author: jeecg-boot
* @Date: 2019-04-09
* @Version: V1.0
*/
public interface ISysMessageService extends JeecgService<SysMessage> { public interface ISysMessageService extends JeecgService<SysMessage> {
boolean add(MessageDTO messageDTO);
} }

View File

@ -1,18 +1,38 @@
package org.jeecg.modules.message.service.impl; 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.common.system.base.service.impl.JeecgServiceImpl;
import org.jeecg.modules.message.entity.SysMessage; import org.jeecg.modules.message.entity.SysMessage;
import org.jeecg.modules.message.mapper.SysMessageMapper; import org.jeecg.modules.message.mapper.SysMessageMapper;
import org.jeecg.modules.message.service.ISysMessageService; import org.jeecg.modules.message.service.ISysMessageService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
/** import java.util.ArrayList;
* @Description: 消息 import java.util.Date;
* @Author: jeecg-boot import java.util.List;
* @Date: 2019-04-09
* @Version: V1.0
*/
@Service @Service
public class SysMessageServiceImpl extends JeecgServiceImpl<SysMessageMapper, SysMessage> implements ISysMessageService { public class SysMessageServiceImpl extends JeecgServiceImpl<SysMessageMapper, SysMessage> implements ISysMessageService {
@Override
public boolean add(MessageDTO messageDTO) {
String toUser = messageDTO.getToUser();
List<SysMessage> sysMessages = new ArrayList<>();
List<String> 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);
}
} }

View File

@ -1,7 +1,6 @@
package org.jeecg.modules.quartz.job; package org.jeecg.modules.quartz.job;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
@ -10,31 +9,22 @@ import lombok.Data;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant; import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.enums.MessageTypeEnum;
import org.jeecg.common.util.RedisStreamUtil; import org.jeecg.common.util.RedisStreamUtil;
import org.jeecg.common.util.SpringContextUtils; import org.jeecg.common.util.SpringContextUtils;
import org.jeecg.modules.base.dto.ItemDto; import org.jeecg.modules.base.entity.monitor.ItemHistory;
import org.jeecg.modules.base.dto.RuleDto;
import org.jeecg.modules.base.entity.AlarmLog; import org.jeecg.modules.base.entity.AlarmLog;
import org.jeecg.modules.base.entity.AlarmRule; import org.jeecg.modules.base.entity.AlarmRule;
import org.jeecg.modules.base.entity.Rule; 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.AbnormalAlarmClient;
import org.jeecg.modules.feignclient.MonitorClient; import org.jeecg.modules.feignclient.MonitorSystem;
import org.jeecg.modules.message.SendMessage; import org.jeecg.modules.message.SendMessage;
import org.quartz.*; import org.quartz.*;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.util.List;
import java.util.Set; 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.Op.*;
import static org.jeecg.modules.base.enums.SourceType.EMAIL;
import static org.jeecg.modules.base.enums.SourceType.SERVER;
@Data @Data
@Slf4j @Slf4j
@ -53,7 +43,7 @@ public class SysInfoJob implements Job {
@Override @Override
public void execute(JobExecutionContext context) throws JobExecutionException { public void execute(JobExecutionContext context) throws JobExecutionException {
RedisStreamUtil redisStreamUtil = SpringContextUtils.getBean(RedisStreamUtil.class); RedisStreamUtil redisStreamUtil = SpringContextUtils.getBean(RedisStreamUtil.class);
MonitorClient monitorClient = SpringContextUtils.getBean(MonitorClient.class); MonitorSystem monitorSystem = SpringContextUtils.getBean(MonitorSystem.class);
SendMessage sendMessage = SpringContextUtils.getBean(SendMessage.class); SendMessage sendMessage = SpringContextUtils.getBean(SendMessage.class);
AbnormalAlarmClient alarmClient = SpringContextUtils.getBean(AbnormalAlarmClient.class); AbnormalAlarmClient alarmClient = SpringContextUtils.getBean(AbnormalAlarmClient.class);
@ -90,7 +80,7 @@ public class SysInfoJob implements Job {
// 向运管查询监控项数据 // 向运管查询监控项数据
String itemId = alarmRule.getItemId().toString(); String itemId = alarmRule.getItemId().toString();
Result<ItemDto> result = monitorClient.itemHistory(itemId, 0, start, end); Result<ItemHistory> result = monitorSystem.itemBack(itemId, 0, start, end);
Double current = result.getResult().getNow(); Double current = result.getResult().getNow();
// 解析预警规则,判断是否需要报警 // 解析预警规则,判断是否需要报警

View File

@ -63,7 +63,6 @@ public class SysDictItem implements Serializable {
@Excel(name = "排序", width = 15,type=4) @Excel(name = "排序", width = 15,type=4)
private Integer sortOrder; private Integer sortOrder;
/** /**
* 状态1启用 0不启用 * 状态1启用 0不启用
*/ */
@ -77,6 +76,4 @@ public class SysDictItem implements Serializable {
private String updateBy; private String updateBy;
private Date updateTime; private Date updateTime;
} }

View File

@ -1,5 +1,7 @@
package org.jeecg.modules.system.service.impl; 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.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@ -47,6 +49,8 @@ import java.sql.DatabaseMetaData;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.*; import java.util.*;
import static org.jeecg.common.constant.enums.MessageTypeEnum.*;
/** /**
* @Description: 底层共通业务API提供其他独立模块调用 * @Description: 底层共通业务API提供其他独立模块调用
* @Author: scott * @Author: scott
@ -1176,22 +1180,16 @@ public class SysBaseApiImpl implements ISysBaseAPI {
} }
//-------------------------------------流程节点发送模板消息----------------------------------------------- //-------------------------------------流程节点发送模板消息-----------------------------------------------
@Autowired
private QywxSendMsgHandle qywxSendMsgHandle;
@Autowired @Autowired
private SystemSendMsgHandle systemSendMsgHandle; private SystemSendMsgHandle systemSendMsgHandle;
@Autowired
private EmailSendMsgHandle emailSendMsgHandle;
@Autowired
private DdSendMsgHandle ddSendMsgHandle;
@Autowired @Autowired
private EmailPushMsgHandle emailPushMsgHandle; private EmailPushMsgHandle emailPushMsgHandle;
@Override @Autowired
private SmsSendMsgHandle smsSendMsgHandle;
/*@Override
public void sendTemplateMessage(MessageDTO message) { public void sendTemplateMessage(MessageDTO message) {
String messageType = message.getType(); String messageType = message.getType();
//update-begin-author:taoyan date:2022-7-9 for: 将模板解析代码移至消息发送, 而不是调用的地方 //update-begin-author:taoyan date:2022-7-9 for: 将模板解析代码移至消息发送, 而不是调用的地方
@ -1226,8 +1224,30 @@ public class SysBaseApiImpl implements ISysBaseAPI {
ddSendMsgHandle.sendMessage(message); ddSendMsgHandle.sendMessage(message);
}else if(MessageTypeEnum.QYWX.getType().equals(messageType)){ }else if(MessageTypeEnum.QYWX.getType().equals(messageType)){
qywxSendMsgHandle.sendMessage(message); 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<String, Object> 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); emailPushMsgHandle.sendMessage(message);
} else if (SMS.getType().equals(type)) { // 手机短信
smsSendMsgHandle.sendMessage(message);
} }
} }

View File

@ -1307,25 +1307,24 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
List<SysUserRole> sysUserRoles = sysUserRoleMapper.selectList(userRoleQueryWrapper); List<SysUserRole> sysUserRoles = sysUserRoleMapper.selectList(userRoleQueryWrapper);
LambdaQueryWrapper<SysRole> roleQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SysRole> roleQueryWrapper = new LambdaQueryWrapper<>();
List<SysRole> sysRoles = sysRoleMapper.selectList(roleQueryWrapper); List<SysRole> sysRoles = sysRoleMapper.selectList(roleQueryWrapper);
List<SysRole> roles = new LinkedList<>();
//遍历所有用户信息 //遍历所有用户信息
if (CollectionUtils.isNotEmpty(sysUsers)){ for (SysUser sysUser:sysUsers) {
for (SysUser sysUser:sysUsers) { String userId = sysUser.getId();
if (CollectionUtils.isNotEmpty(sysUserRoles)){ List<SysRole> roles = new LinkedList<>();
//获取各用户匹配的权限集合 //获取各用户匹配的权限集合
List<SysUserRole> userRoles = sysUserRoles.stream().filter(item -> item.getUserId().equals(sysUser.getId())).collect(Collectors.toList()); List<SysUserRole> userRoles = sysUserRoles.stream()
List<String> roleIds = userRoles.stream().map(SysUserRole::getRoleId).collect(Collectors.toList()); .filter(item -> item.getUserId().equals(userId))
if (CollectionUtils.isNotEmpty(sysRoles)){ .collect(Collectors.toList());
for (SysRole role:sysRoles) { List<String> roleIds = userRoles.stream()
if (roleIds.contains(role.getId())){ .map(SysUserRole::getRoleId)
roles.add(role); .collect(Collectors.toList());
} for (SysRole role:sysRoles) {
} if (roleIds.contains(role.getId())){
} roles.add(role);
sysUser.setRoles(roles);
} }
map.put(sysUser.getId(), sysUser);
} }
sysUser.setRoles(roles);
map.put(userId, sysUser);
} }
return map; return map;
} }

View File

@ -6,18 +6,18 @@
#database_name=jeecg-boot #database_name=jeecg-boot
#oracle #oracle
diver_name=oracle.jdbc.driver.OracleDriver #diver_name=oracle.jdbc.driver.OracleDriver
url=jdbc:oracle:thin:@82.157.234.81:1521:orcl #url=jdbc:oracle:thin:@82.157.234.81:1521:orcl
username=original #username=original
password=123456 #password=123456
database_name=original #database_name=original
#postgre #postgre
#diver_name=org.postgresql.Driver diver_name=org.postgresql.Driver
#url=jdbc:postgresql://localhost:5432/jeecg url=jdbc:postgresql://182.92.183.230:5432/jeecg-boot
#username=postgres username=postgres
#password=postgres password=U6D!TGH3
#database_name=jeecg database_name=public
#SQLServer2005\u4ee5\u4e0a #SQLServer2005\u4ee5\u4e0a
#diver_name=org.hibernate.dialect.SQLServerDialect #diver_name=org.hibernate.dialect.SQLServerDialect

View File

@ -11,6 +11,7 @@ import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile; import org.apache.commons.net.ftp.FTPFile;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.Prompt;
import org.jeecg.common.constant.SymbolConstant; import org.jeecg.common.constant.SymbolConstant;
import org.jeecg.common.enums.SampleFileHeader; import org.jeecg.common.enums.SampleFileHeader;
import org.jeecg.modules.entity.data.HistogramData; import org.jeecg.modules.entity.data.HistogramData;
@ -23,6 +24,8 @@ import javax.servlet.http.HttpServletResponse;
import java.io.*; import java.io.*;
import java.util.*; import java.util.*;
import static org.jeecg.common.constant.enums.FileTypeEnum.txt;
@Component @Component
@Slf4j @Slf4j
public class ReadLineUtil { public class ReadLineUtil {
@ -159,7 +162,7 @@ public class ReadLineUtil {
outputStream.write(buffer, 0, bytesRead); outputStream.write(buffer, 0, bytesRead);
} }
} catch (FileNotFoundException e){ } catch (FileNotFoundException e){
log.error("File["+filePath+"]does not exist!"); log.error("File ["+filePath+"] does not exist!");
e.printStackTrace(); e.printStackTrace();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
@ -179,7 +182,7 @@ public class ReadLineUtil {
FTPClient ftpClient = ftpUtil.LoginFTP(); FTPClient ftpClient = ftpUtil.LoginFTP();
// 判断FTP是否连接成功 // 判断FTP是否连接成功
if (Objects.isNull(ftpClient)){ if (Objects.isNull(ftpClient)){
throw new RuntimeException("FTP连接失败!"); throw new RuntimeException(Prompt.FTP_ERR);
} }
OutputStream outputStream = null; OutputStream outputStream = null;
@ -191,20 +194,21 @@ public class ReadLineUtil {
// 判断FTP服务器上是否存在此文件 // 判断FTP服务器上是否存在此文件
String[] files = ftpClient.listNames(filePath); String[] files = ftpClient.listNames(filePath);
if (ArrayUtil.isEmpty(files)){ if (ArrayUtil.isEmpty(files)){
String message = "File["+filePath+"]does not exist!"; String message = "File ["+filePath+"] does not exist!";
log.error(message); log.error(message);
return Result.error(message); return Result.error(message);
} }
// 存在多个文件名表示此路径为目录而非文件 // 存在多个文件名表示此路径为目录而非文件
if (ArrayUtil.length(files) > 1){ 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); log.error(message);
return Result.error(message); return Result.error(message);
} }
// 获取文件名 // 获取文件名
String fileName = FileUtil.getName(filePath); String fileName = FileUtil.getName(filePath);
if (!fileName.endsWith(txt.getType()))fileName += txt.getType();
// 在当前工作路径下读取文件 // 在当前工作路径下读取文件
ftpClient.enterLocalPassiveMode(); ftpClient.enterLocalPassiveMode();

View File

@ -7,6 +7,7 @@ import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.api.QueryRequest; import org.jeecg.common.api.QueryRequest;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.Prompt;
import org.jeecg.common.util.ReadLineUtil; import org.jeecg.common.util.ReadLineUtil;
import org.jeecg.modules.base.entity.GardsSampleData; import org.jeecg.modules.base.entity.GardsSampleData;
import org.jeecg.modules.base.entity.GardsSohData; import org.jeecg.modules.base.entity.GardsSohData;
@ -97,7 +98,7 @@ public class WebStatisticsController {
GardsSampleData sampleData = gardsSampleDataWebService.getOneSample(sampleId); GardsSampleData sampleData = gardsSampleDataWebService.getOneSample(sampleId);
String filePath = sampleData.getInputFileName(); String filePath = sampleData.getInputFileName();
if (StrUtil.isBlank(filePath)) 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); return readLineUtil.readFtpFile(filePath,response);
} }
@ -108,7 +109,7 @@ public class WebStatisticsController {
GardsSohData soh = gardsSohDataService.getOneSoh(sohId); GardsSohData soh = gardsSohDataService.getOneSoh(sohId);
String filePath = soh.getInputFileName(); String filePath = soh.getInputFileName();
if (StrUtil.isBlank(filePath)) 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); return readLineUtil.readFtpFile(filePath,response);
} }
@ -124,7 +125,7 @@ public class WebStatisticsController {
reportPath = reviewedService.getOne(sampleId).getReportPath(); reportPath = reviewedService.getOne(sampleId).getReportPath();
} }
if (StrUtil.isBlank(reportPath)) if (StrUtil.isBlank(reportPath))
return Result.error("The file you are looking for does not exist!"); return Result.error(Prompt.FILE_NOT_EXITS);
// 将FTP上的文件转为文件流返回到前端 // 将FTP上的文件转为文件流返回到前端
return readLineUtil.readFtpFile(reportPath,response); return readLineUtil.readFtpFile(reportPath,response);
} }