Merge remote-tracking branch 'origin/station' into station
This commit is contained in:
commit
abf5911ff4
|
@ -7,7 +7,9 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
|||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
|
@ -44,7 +46,7 @@ public class SysEmailLog implements Serializable {
|
|||
@TableField(value = "receive_time")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date receiveTime;
|
||||
private LocalDateTime receiveTime;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
|
|
|
@ -36,7 +36,7 @@ public class AlarmLogController {
|
|||
|
||||
@GetMapping("findInfo")
|
||||
@ApiOperation(value = "查询报警日志信息详情", notes = "查询报警日志信息详情")
|
||||
public Result findPage(String id){
|
||||
public Result findInfo(String id){
|
||||
return alarmLogService.findInfo(id);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,181 @@
|
|||
package org.jeecg.modules.controller;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.constant.EmailConstant;
|
||||
import org.jeecg.common.util.RedisUtil;
|
||||
import org.jeecg.modules.base.entity.SysEmailLog;
|
||||
import org.jeecg.modules.service.ISysEmailLogService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("sysEmailLog")
|
||||
@Api(value = "邮箱日志", tags = "邮箱日志")
|
||||
public class SysEmailLogController {
|
||||
@Autowired
|
||||
private ISysEmailLogService sysEmailLogService;
|
||||
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
/**
|
||||
* 邮箱服务器连接状态 正常/断开
|
||||
*
|
||||
* @param emailId 电子邮件id
|
||||
*/
|
||||
@GetMapping("status")
|
||||
public Result status(@RequestParam("emailId") String emailId){
|
||||
String key = EmailConstant.EMAIL_STATUS_PREFIX;
|
||||
Boolean emailSatus = (Boolean) redisUtil.hget(key, emailId);
|
||||
return Result.OK(emailSatus == null ? false : emailSatus);
|
||||
}
|
||||
|
||||
@GetMapping("space")
|
||||
public Result space(@RequestParam("emailId") String emailId){
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分别获取今天、昨天、过去一周邮件量
|
||||
*
|
||||
* @param emailId 电子邮件id
|
||||
*/
|
||||
@GetMapping("total")
|
||||
public Result totalEmail(@RequestParam("emailId") String emailId){
|
||||
// 当日邮件量
|
||||
LambdaQueryWrapper<SysEmailLog> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SysEmailLog::getEmailId,emailId);
|
||||
LocalDate today = LocalDate.now();
|
||||
String todayStart = today + " 00:00:00";
|
||||
String todayEnd = today + " 23:59:59";
|
||||
wrapper.between(SysEmailLog::getReceiveTime,todayStart,todayEnd);
|
||||
Long todayCount = sysEmailLogService.count(wrapper);
|
||||
// 昨日邮件量
|
||||
wrapper.clear();
|
||||
wrapper.eq(SysEmailLog::getEmailId,emailId);
|
||||
LocalDate yesterday = LocalDate.now().minusDays(1);
|
||||
String yesterdayStart = yesterday + " 00:00:00";
|
||||
String yesterdayEnd = yesterday + " 23:59:59";
|
||||
wrapper.between(SysEmailLog::getReceiveTime,yesterdayStart,yesterdayEnd);
|
||||
Long yesterdayCount = sysEmailLogService.count(wrapper);
|
||||
// 过去一周邮件量
|
||||
wrapper.clear();
|
||||
wrapper.eq(SysEmailLog::getEmailId,emailId);
|
||||
LocalDate passWeek = LocalDate.now().minusWeeks(1);
|
||||
String weekStart = passWeek + " 00:00:00";
|
||||
wrapper.between(SysEmailLog::getReceiveTime,weekStart,todayEnd);
|
||||
Long weekCount = sysEmailLogService.count(wrapper);
|
||||
|
||||
Map<String,Long> result = new HashMap<>();
|
||||
result.put("today",todayCount);
|
||||
result.put("yesterday",yesterdayCount);
|
||||
result.put("week",weekCount);
|
||||
return Result.OK(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 今天邮件接收量 按小时划分
|
||||
*
|
||||
* @param emailId 电子邮件id
|
||||
*/
|
||||
@GetMapping("today")
|
||||
public Result today(@RequestParam("emailId") String emailId){
|
||||
LambdaQueryWrapper<SysEmailLog> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SysEmailLog::getEmailId,emailId);
|
||||
LocalDate today = LocalDate.now();
|
||||
String todayStart = today + " 00:00:00";
|
||||
String todayEnd = today + " 23:59:59";
|
||||
wrapper.between(SysEmailLog::getReceiveTime,todayStart,todayEnd);
|
||||
List<SysEmailLog> emailLogs = sysEmailLogService.list(wrapper);
|
||||
List<LocalDateTime> allTime = emailLogs.stream()
|
||||
.map(SysEmailLog::getReceiveTime)
|
||||
.collect(Collectors.toList());
|
||||
// 按照小时分组
|
||||
Map<String,Integer> statistic = new TreeMap<>();
|
||||
Map<Integer, List<LocalDateTime>> groupTime = allTime.stream()
|
||||
.collect(Collectors.groupingBy(LocalDateTime::getHour));
|
||||
for (int i = 0; i < 24; i++) {
|
||||
if(groupTime.containsKey(i)){
|
||||
Integer count = groupTime.get(i).size();
|
||||
statistic.put(timeStr(i),count);
|
||||
}else {
|
||||
statistic.put(timeStr(i),0);
|
||||
}
|
||||
}
|
||||
return Result.OK(statistic);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据日期筛选(折线图)
|
||||
*
|
||||
* @param emailId 电子邮件id
|
||||
*/
|
||||
@GetMapping("analysis")
|
||||
public Result analysis(@RequestParam("emailId") String emailId,
|
||||
@RequestParam("startDate") String startDate,
|
||||
@RequestParam("endDate") String endDate){
|
||||
String startStr = startDate + " 00:00:00";
|
||||
String endStr = endDate + " 23:59:59";
|
||||
LambdaQueryWrapper<SysEmailLog> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SysEmailLog::getEmailId,emailId);
|
||||
wrapper.between(SysEmailLog::getReceiveTime,startStr,endStr);
|
||||
Set<String> xData = new HashSet<>();
|
||||
Collection<Integer> yData = new ArrayList<>();
|
||||
Map<String,Integer> statistic = new TreeMap<>();
|
||||
Map<String,Object> result = new HashMap<>();
|
||||
List<LocalDateTime> allDate = sysEmailLogService.listObjs(wrapper,
|
||||
emailLog -> ((SysEmailLog) emailLog).getReceiveTime());
|
||||
if (CollUtil.isEmpty(allDate)){
|
||||
result.put("xData",xData);
|
||||
result.put("yData",yData);
|
||||
return Result.OK(result);
|
||||
}
|
||||
|
||||
/* 支持跨年跨月选择 */
|
||||
// 通过年月日进行分组 例:2023-06-06
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE;
|
||||
Map<String, List<LocalDateTime>> group = allDate.stream()
|
||||
.collect(Collectors.groupingBy(datetime -> datetime.format(formatter)));
|
||||
|
||||
// 列举出startDate-endDate中所有日期(包括闰年)
|
||||
// 没有邮件的日期,对应的值设置为0
|
||||
LocalDate start = LocalDate.parse(startDate);
|
||||
LocalDate end = LocalDate.parse(endDate);
|
||||
while (!start.isAfter(end)) {
|
||||
String key = start.format(formatter);
|
||||
if (group.containsKey(key)){
|
||||
Integer count = group.get(key).size();
|
||||
statistic.put(key,count);
|
||||
}else {
|
||||
statistic.put(key,0);
|
||||
}
|
||||
start = start.plusDays(1);
|
||||
}
|
||||
// 返回结果
|
||||
xData = statistic.keySet();
|
||||
yData = statistic.values();
|
||||
result.put("xData",xData);
|
||||
result.put("yData",yData);
|
||||
return Result.OK(result);
|
||||
}
|
||||
|
||||
private String timeStr(Integer time){
|
||||
if (time < 10){
|
||||
return "0" + time + ":00";
|
||||
}
|
||||
return time + ":00";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,13 +7,14 @@ import org.jeecg.modules.entity.AlarmHistory;
|
|||
import org.jeecg.modules.entity.AlarmLog;
|
||||
import org.jeecg.modules.vo.AlarmVo;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface AlarmLogMapper extends BaseMapper<AlarmLog> {
|
||||
|
||||
List<Date> rangeDay(Map<String,Object> params);
|
||||
List<LocalDateTime> rangeDay(Map<String,Object> params);
|
||||
List<AlarmHistory> findPage(Map<String,Object> params);
|
||||
|
||||
List<TypeDto> typeAlarms(Map<String,Object> params);
|
||||
|
|
|
@ -3,5 +3,12 @@ package org.jeecg.modules.mapper;
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.jeecg.modules.base.entity.SysEmailLog;
|
||||
|
||||
/**
|
||||
* 系统邮件日志
|
||||
*
|
||||
* @author nieziyan
|
||||
* @date 2023-06-19
|
||||
*/
|
||||
public interface SysEmailLogMapper extends BaseMapper<SysEmailLog> {
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?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.AlarmLogMapper">
|
||||
<select id="rangeDay" parameterType="Map" resultType="Date">
|
||||
<select id="rangeDay" parameterType="Map" resultType="java.time.LocalDateTime">
|
||||
SELECT
|
||||
l.alarm_start_date
|
||||
FROM
|
||||
|
|
|
@ -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.SysEmailLogMapper">
|
||||
|
||||
</mapper>
|
|
@ -1,6 +1,6 @@
|
|||
<?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.SysEmailMapper">
|
||||
<mapper namespace="org.jeecg.modules.mapper.SysDatabaseMapper">
|
||||
|
||||
<select id="findAlarmHistory" resultType="org.jeecg.modules.entity.AlarmHistory">
|
||||
SELECT
|
||||
|
|
|
@ -43,25 +43,24 @@ public class AlarmLogServiceImpl extends ServiceImpl<AlarmLogMapper, AlarmLog> i
|
|||
alarmVo.setEndDate(endDate + " 23:59:59");
|
||||
// 定义返回结果
|
||||
Set<String> xData = new HashSet<>();
|
||||
Collection<Integer> YData = new ArrayList<>();
|
||||
Collection<Integer> yData = new ArrayList<>();
|
||||
Map<String,Integer> statistic = new TreeMap<>();
|
||||
Map<String,Object> result = new HashMap<>();
|
||||
// 转换参数 数据查询
|
||||
Map<String, Object> params = BeanUtil.beanToMap(alarmVo);
|
||||
List<Date> allDate = baseMapper.rangeDay(params);
|
||||
List<LocalDateTime> allDate = baseMapper.rangeDay(params);
|
||||
// 查询数据为空则直接返回空集合
|
||||
if (CollUtil.isEmpty(allDate)){
|
||||
result.put("xData",xData);
|
||||
result.put("yData",YData);
|
||||
result.put("yData",yData);
|
||||
return Result.OK(result);
|
||||
}
|
||||
// 分情况处理 1.按小时统计 2.按天统计
|
||||
|
||||
/* 1.选择日期为同一天 按照小时划分 0-23小时 */
|
||||
if (startDate.equals(endDate)){
|
||||
Map<Integer, List<Date>> groupTime = allDate.stream()
|
||||
.sorted(Comparator.comparing(Date::getHours))
|
||||
.collect(Collectors.groupingBy(Date::getHours));
|
||||
Map<String,Integer> statistic = new HashMap<>();
|
||||
Map<Integer, List<LocalDateTime>> groupTime = allDate.stream()
|
||||
.collect(Collectors.groupingBy(LocalDateTime::getHour));
|
||||
for (int i = 0; i < 24; i++) {
|
||||
if(groupTime.containsKey(i)){
|
||||
Integer count = groupTime.get(i).size();
|
||||
|
@ -72,61 +71,38 @@ public class AlarmLogServiceImpl extends ServiceImpl<AlarmLogMapper, AlarmLog> i
|
|||
}
|
||||
// 返回x轴和y轴数据
|
||||
xData = statistic.keySet();
|
||||
YData = statistic.values();
|
||||
yData = statistic.values();
|
||||
result.put("xData",xData);
|
||||
result.put("yData",YData);
|
||||
result.put("yData",yData);
|
||||
return Result.OK(result);
|
||||
}
|
||||
/* 2.选择日期不是同一天 按照天划分(可以跨月选择,但不包括跨年) */
|
||||
/* 2.选择日期不是同一天 按照天划分 */
|
||||
// 支持跨年跨月选择(包括闰年)
|
||||
else {
|
||||
Map<String,Integer> statistic = new HashMap<>();
|
||||
// 通过mounth分组
|
||||
Map<Integer, List<Date>> groupMounth = allDate.stream()
|
||||
.sorted(Comparator.comparing(Date::getMonth))
|
||||
.collect(Collectors.groupingBy(Date::getMonth));
|
||||
// 通过day分组
|
||||
for (Map.Entry<Integer, List<Date>> entry : groupMounth.entrySet()) {
|
||||
Integer mounth = entry.getKey() + 1;// 当前月份
|
||||
List<Date> allDay = entry.getValue(); // 当前月份有报警的day
|
||||
Map<Integer, List<Date>> groupDay = allDay.stream()
|
||||
.sorted(Comparator.comparing(Date::getDate))
|
||||
.collect(Collectors.groupingBy(Date::getDate));
|
||||
for (Map.Entry<Integer, List<Date>> entryDay : groupDay.entrySet()) {
|
||||
Integer day = entryDay.getKey(); // 当前是几号
|
||||
Integer count = entryDay.getValue().size();
|
||||
statistic.put(dateStr(mounth,day),count);
|
||||
}
|
||||
}
|
||||
// 通过年月日进行分组 例:2023-06-06
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE;
|
||||
Map<String, List<LocalDateTime>> group = allDate.stream()
|
||||
.collect(Collectors.groupingBy(datetime -> datetime.format(formatter)));
|
||||
|
||||
// 列举startDate和endDate之间所有日期(已考虑闰年情况)
|
||||
// 没有报警日志的日期,对应的值设置为0
|
||||
LocalDate start = LocalDate.parse(startDate);
|
||||
LocalDate end = LocalDate.parse(endDate);
|
||||
List<LocalDate> dateList = new ArrayList<>();
|
||||
LocalDate current = start;
|
||||
while (!current.isAfter(end)) {
|
||||
dateList.add(current);
|
||||
current = current.plusDays(1);
|
||||
}
|
||||
List<String> allDateStr = dateList.stream()
|
||||
.map(item -> {
|
||||
// 2023-06-15 格式截取为 06-15
|
||||
String dateStr = item
|
||||
.format(DateTimeFormatter.ISO_LOCAL_DATE)
|
||||
.substring(5);
|
||||
return dateStr;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
// startDate和endDate范围内无报警信息
|
||||
// 的日期(哪一天),将其报警数量设置为0
|
||||
for (String dateStr : allDateStr) {
|
||||
if (!allDateStr.contains(dateStr)){
|
||||
statistic.put(dateStr,0);
|
||||
while (!start.isAfter(end)) {
|
||||
String key = start.format(formatter);
|
||||
if (group.containsKey(key)){
|
||||
Integer count = group.get(key).size();
|
||||
statistic.put(key,count);
|
||||
}else {
|
||||
statistic.put(key,0);
|
||||
}
|
||||
start = start.plusDays(1);
|
||||
}
|
||||
// 返回x轴和y轴数据
|
||||
xData = statistic.keySet();
|
||||
YData = statistic.values();
|
||||
yData = statistic.values();
|
||||
result.put("xData",xData);
|
||||
result.put("yData",YData);
|
||||
result.put("yData",yData);
|
||||
return Result.OK(result);
|
||||
}
|
||||
}
|
||||
|
@ -260,30 +236,4 @@ public class AlarmLogServiceImpl extends ServiceImpl<AlarmLogMapper, AlarmLog> i
|
|||
}
|
||||
return time + ":00";
|
||||
}
|
||||
|
||||
private String dateStr(Integer mounth,Integer day){
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (mounth < 10){
|
||||
sb.append("0").append(mounth).append("-");
|
||||
}else {
|
||||
sb.append(mounth).append("-");
|
||||
}
|
||||
if (day < 10){
|
||||
sb.append("0").append(day);
|
||||
}else {
|
||||
sb.append(day);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws ParseException {
|
||||
List<Date> allDate = new ArrayList<>();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date date1 = sdf.parse("2013-04-29");
|
||||
Date date2 = sdf.parse("2013-04-29");
|
||||
Date date3 = sdf.parse("2013-05-01");
|
||||
Date date4 = sdf.parse("2013-05-02");
|
||||
allDate.addAll(Arrays.asList(date1,date2,date3,date4));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user