fix:邮件服务器邮件量

This commit is contained in:
nieziyan 2023-10-24 17:13:49 +08:00
parent 74c54c98f0
commit 8472cf96fb
10 changed files with 62 additions and 26 deletions

View File

@ -1,7 +1,9 @@
package org.jeecg.modules.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.jeecg.modules.base.dto.EmailDto;
import org.jeecg.modules.base.dto.IdCount;
import org.jeecg.modules.base.entity.postgre.SysEmail;
import org.jeecg.modules.entity.AlarmHistory;
@ -13,4 +15,8 @@ public interface SysEmailMapper extends BaseMapper<SysEmail> {
List<AlarmHistory> findAlarmHistory(Map<String,Object> params);
List<EmailDto> findPage(Map<String,Object> params);
List<IdCount> counts(@Param("emailIds") List<String> emailIds,
@Param("startDate") String startDate,
@Param("endDate") String endDate);
}

View File

@ -49,5 +49,21 @@
LIMIT #{pageSize} OFFSET #{pageStart}
</if>
</select>
<select id="counts" resultType="org.jeecg.modules.base.dto.IdCount">
SELECT
email_id AS id,
count(email_id)
FROM
sys_email_log
<where>
receive_time BETWEEN #{startDate} AND #{endDate}
<if test="emailIds != null and emailIds.size() > 0">
AND email_id IN
<foreach collection="emailIds" index="index" open="(" close=")" item="item" separator=",">
#{item}
</foreach>
</if>
</where>
GROUP BY email_id
</select>
</mapper>

View File

@ -11,7 +11,7 @@ import java.util.List;
public interface ISysEmailService extends IService<SysEmail> {
Result findPage(QueryRequest query);
Result<?> findPage(QueryRequest query);
Result findInfo(String id);

View File

@ -2,6 +2,8 @@ package org.jeecg.modules.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@ -14,6 +16,7 @@ import org.jeecg.common.constant.DateConstant;
import org.jeecg.common.constant.Prompt;
import org.jeecg.common.email.emuns.SysMailType;
import org.jeecg.modules.base.dto.EmailDto;
import org.jeecg.modules.base.dto.IdCount;
import org.jeecg.modules.base.dto.SourceDto;
import org.jeecg.modules.base.entity.postgre.SysEmail;
import org.jeecg.modules.base.bizVo.SourceVo;
@ -26,12 +29,13 @@ import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
@Service("sysEmailService")
public class SysEmailServiceImpl extends ServiceImpl<SysEmailMapper, SysEmail> implements ISysEmailService {
@Override
public Result findPage(QueryRequest query) {
public Result<?> findPage(QueryRequest query) {
Integer pageNo = query.getPageNo();
Integer pageSize = query.getPageSize();
Integer pageStart = (pageNo - 1) * pageSize;
@ -45,12 +49,33 @@ public class SysEmailServiceImpl extends ServiceImpl<SysEmailMapper, SysEmail> i
String endDate = date + DateConstant.TIME_END;
params.put("startDate",startDate);
params.put("endDate",endDate);
List<EmailDto> emailDtos = baseMapper.findPage(params);
// 查询当日 昨日 最近一周邮件接受量
List<String> emailIds = emailDtos.stream()
.map(EmailDto::getId).collect(Collectors.toList());
LocalDate today = LocalDate.now();
String todayStart = today + DateConstant.TIME_START;
String todayEnd = today + DateConstant.TIME_END;
LocalDate yesterday = LocalDate.now().minusDays(1);
String yesterdayStart = yesterday + DateConstant.TIME_START;
String yesterdayEnd = yesterday + DateConstant.TIME_END;
LocalDate passWeek = LocalDate.now().minusWeeks(1);
String weekStart = passWeek + DateConstant.TIME_START;
Map<String, Integer> todayMap = baseMapper.counts(emailIds, todayStart, todayEnd)
.stream().collect(Collectors.toMap(IdCount::getId, IdCount::getCount));
Map<String, Integer> yestMap = baseMapper.counts(emailIds, yesterdayStart, yesterdayEnd)
.stream().collect(Collectors.toMap(IdCount::getId, IdCount::getCount));
Map<String, Integer> weekMap = baseMapper.counts(emailIds, weekStart, todayEnd)
.stream().collect(Collectors.toMap(IdCount::getId, IdCount::getCount));
for (EmailDto emailDto : emailDtos) {
emailDto.setOnline(true).setToday(2)
.setYesterday(5).setWeekly(7)
.setStoerCapacity("100%").setStoerRed(true);
String id = emailDto.getId();
emailDto.setOnline(true).setStoerCapacity("100%").setStoerRed(true)
.setToday(todayMap.getOrDefault(id, 0))
.setYesterday(yestMap.getOrDefault(id, 0))
.setWeekly(weekMap.getOrDefault(id, 0));
}
// 不分页 查询记录总数
params.put("pageFlag","noPage");
long total = baseMapper.findPage(params).size();
Page<EmailDto> page = new Page<>(pageNo, pageSize, total);

View File

@ -279,11 +279,12 @@ public class QuartzJobController {
return Result.error("The specified task entity class was not found");
}
try {
return quartzJobService.execute(quartzJob);
quartzJobService.execute(quartzJob);
} catch (Exception e) {
e.printStackTrace();
return Result.error(Prompt.EXEC_Faild);
}
return Result.ok(Prompt.EXEC_SUCC);
}
}

View File

@ -23,19 +23,15 @@ public class NuclideParamJob implements Job {
private AbnormalAlarmClient alarmClient;
private boolean success = true;
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
try {
init();
success = alarmClient.refreshParam();
alarmClient.refreshParam();
}catch (Exception e){
e.printStackTrace();
success = false;
}finally {
destroy();
context.getJobDetail().getJobDataMap().put("success",success);
}
}

View File

@ -23,19 +23,15 @@ public class NucliedAvgJob implements Job {
private AbnormalAlarmClient alarmClient;
private boolean success = true;
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
try {
init();
success = alarmClient.calculateConc();
alarmClient.calculateConc();
}catch (Exception e){
e.printStackTrace();
success = false;
}finally {
destroy();
context.getJobDetail().getJobDataMap().put("success",success);
}
}

View File

@ -17,19 +17,15 @@ public class SyncServerItemJob implements Job {
private AbnormalAlarmClient alarmClient;
private boolean success = true;
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
try {
init();
success = alarmClient.syncServerItem();
alarmClient.syncServerItem();
}catch (Exception e){
e.printStackTrace();
success = false;
}finally {
destroy();
context.getJobDetail().getJobDataMap().put("success",success);
}
}

View File

@ -56,7 +56,7 @@ public interface IQuartzJobService extends IService<QuartzJob> {
* @param quartzJob
* @throws Exception
*/
Result<?> execute(QuartzJob quartzJob) throws Exception;
void execute(QuartzJob quartzJob) throws Exception;
/**
* 暂停任务

View File

@ -106,7 +106,7 @@ public class QuartzJobServiceImpl extends ServiceImpl<QuartzJobMapper, QuartzJob
}
@Override
public Result<?> execute(QuartzJob quartzJob) throws Exception {
public void execute(QuartzJob quartzJob) throws Exception {
String jobName = quartzJob.getJobClassName().trim();
Date startDate = new Date();
String ymd = DateUtils.date2Str(startDate,DateUtils.yyyymmddhhmmss.get());
@ -130,12 +130,12 @@ public class QuartzJobServiceImpl extends ServiceImpl<QuartzJobMapper, QuartzJob
scheduler.scheduleJob(jobDetail, trigger);
// 启动scheduler
scheduler.start();
// TODO 获取 JobDetail 对象
/*// TODO 获取 JobDetail 对象
JobDetail detail = scheduler.getJobDetail(new JobKey(identity));
if (ObjectUtil.isNull(detail))
return Result.OK(Prompt.EXEC_SUCC);
boolean success = detail.getJobDataMap().getBoolean("success");
return success ? Result.OK(Prompt.EXEC_SUCC) : Result.error(Prompt.EXEC_Faild);
return success ? Result.OK(Prompt.EXEC_SUCC) : Result.error(Prompt.EXEC_Faild);*/
}
@Override