feat(sj_1.0.0): 通知配置添加删除接口
This commit is contained in:
parent
6a1196d0e0
commit
97237ac538
@ -78,6 +78,7 @@ public class EmailAlarm extends AbstractAlarm<AlarmContext> {
|
||||
}
|
||||
|
||||
mailAccount = initMailAccount(mailProperties);
|
||||
MailUtils.setMailAccount(mailAccount);
|
||||
}
|
||||
|
||||
private MailAccount initMailAccount(MailProperties mailProperties) {
|
||||
|
@ -5,7 +5,6 @@ import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.CharUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.aizuda.snailjob.common.core.context.SpringContext;
|
||||
import com.aizuda.snailjob.common.core.alarm.email.Mail;
|
||||
import com.aizuda.snailjob.common.core.alarm.email.MailAccount;
|
||||
import com.aizuda.snailjob.common.core.alarm.email.UserPassAuthenticator;
|
||||
@ -27,13 +26,20 @@ import java.util.Map;
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class MailUtils {
|
||||
|
||||
private static final MailAccount ACCOUNT = SpringContext.getBean(MailAccount.class);
|
||||
private static MailAccount account;
|
||||
|
||||
/**
|
||||
* 获取邮件发送实例
|
||||
*/
|
||||
public static MailAccount getMailAccount() {
|
||||
return ACCOUNT;
|
||||
return account;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取邮件发送实例
|
||||
*/
|
||||
public static void setMailAccount(MailAccount account) {
|
||||
MailUtils.account = account;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -43,10 +49,10 @@ public class MailUtils {
|
||||
* @param pass 授权码
|
||||
*/
|
||||
public static MailAccount getMailAccount(String from, String user, String pass) {
|
||||
ACCOUNT.setFrom(StrUtil.blankToDefault(from, ACCOUNT.getFrom()));
|
||||
ACCOUNT.setUser(StrUtil.blankToDefault(user, ACCOUNT.getUser()));
|
||||
ACCOUNT.setPass(StrUtil.blankToDefault(pass, ACCOUNT.getPass()));
|
||||
return ACCOUNT;
|
||||
account.setFrom(StrUtil.blankToDefault(from, account.getFrom()));
|
||||
account.setUser(StrUtil.blankToDefault(user, account.getUser()));
|
||||
account.setPass(StrUtil.blankToDefault(pass, account.getPass()));
|
||||
return account;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.aizuda.snailjob.server.retry.task.dto;
|
||||
|
||||
import com.aizuda.snailjob.server.common.dto.NotifyConfigInfo;
|
||||
import com.aizuda.snailjob.server.common.dto.NotifyConfigInfo.RecipientInfo;
|
||||
import com.aizuda.snailjob.server.common.dto.PartitionTask;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -18,12 +16,11 @@ import java.util.Set;
|
||||
@Data
|
||||
public class NotifyConfigPartitionTask extends PartitionTask {
|
||||
|
||||
|
||||
private String namespaceId;
|
||||
|
||||
private String groupName;
|
||||
|
||||
private String sceneName;
|
||||
private String businessId;
|
||||
|
||||
private Set<Long> recipientIds;
|
||||
|
||||
|
@ -96,7 +96,7 @@ public class RetryErrorMoreThresholdAlarmSchedule extends AbstractSchedule imple
|
||||
new LambdaQueryWrapper<RetryDeadLetter>().
|
||||
between(RetryDeadLetter::getCreateDt, now.minusMinutes(30), now)
|
||||
.eq(RetryDeadLetter::getGroupName, partitionTask.getGroupName())
|
||||
.eq(RetryDeadLetter::getSceneName, partitionTask.getSceneName()));
|
||||
.eq(RetryDeadLetter::getSceneName, partitionTask.getBusinessId()));
|
||||
if (count >= partitionTask.getNotifyThreshold()) {
|
||||
List<RecipientInfo> recipientInfos = partitionTask.getRecipientInfos();
|
||||
for (final RecipientInfo recipientInfo : recipientInfos) {
|
||||
@ -110,7 +110,7 @@ public class RetryErrorMoreThresholdAlarmSchedule extends AbstractSchedule imple
|
||||
count,
|
||||
partitionTask.getNamespaceId(),
|
||||
partitionTask.getGroupName(),
|
||||
partitionTask.getSceneName(),
|
||||
partitionTask.getBusinessId(),
|
||||
DateUtils.format(now.minusMinutes(30),
|
||||
DateUtils.NORM_DATETIME_PATTERN),
|
||||
DateUtils.toNowFormat(DateUtils.NORM_DATETIME_PATTERN), count)
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.aizuda.snailjob.server.retry.task.support.schedule;
|
||||
|
||||
import com.aizuda.snailjob.common.core.alarm.Alarm;
|
||||
import com.aizuda.snailjob.common.core.alarm.AlarmContext;
|
||||
import com.aizuda.snailjob.common.core.alarm.SnailJobAlarmFactory;
|
||||
import com.aizuda.snailjob.common.core.enums.RetryNotifySceneEnum;
|
||||
@ -10,6 +9,7 @@ import com.aizuda.snailjob.common.core.util.JsonUtil;
|
||||
import com.aizuda.snailjob.common.core.util.EnvironmentUtils;
|
||||
import com.aizuda.snailjob.server.common.Lifecycle;
|
||||
import com.aizuda.snailjob.server.common.dto.PartitionTask;
|
||||
import com.aizuda.snailjob.server.common.enums.SyetemTaskTypeEnum;
|
||||
import com.aizuda.snailjob.server.common.schedule.AbstractSchedule;
|
||||
import com.aizuda.snailjob.server.common.util.DateUtils;
|
||||
import com.aizuda.snailjob.server.common.util.PartitionTaskUtils;
|
||||
@ -89,7 +89,7 @@ public class RetryTaskMoreThresholdAlarmSchedule extends AbstractSchedule implem
|
||||
new LambdaQueryWrapper<RetryTask>()
|
||||
.eq(RetryTask::getNamespaceId, partitionTask.getNamespaceId())
|
||||
.eq(RetryTask::getGroupName, partitionTask.getGroupName())
|
||||
.eq(RetryTask::getSceneName, partitionTask.getSceneName())
|
||||
.eq(RetryTask::getSceneName, partitionTask.getBusinessId())
|
||||
.eq(RetryTask::getRetryStatus, RetryStatusEnum.RUNNING.getStatus()));
|
||||
if (count >= partitionTask.getNotifyThreshold()) {
|
||||
|
||||
@ -105,7 +105,7 @@ public class RetryTaskMoreThresholdAlarmSchedule extends AbstractSchedule implem
|
||||
count,
|
||||
partitionTask.getNamespaceId(),
|
||||
partitionTask.getGroupName(),
|
||||
partitionTask.getSceneName(),
|
||||
partitionTask.getBusinessId(),
|
||||
DateUtils.toNowFormat(DateUtils.NORM_DATETIME_PATTERN),
|
||||
count)
|
||||
.title("{}环境 场景重试数量超过阈值", EnvironmentUtils.getActiveProfile())
|
||||
@ -123,6 +123,7 @@ public class RetryTaskMoreThresholdAlarmSchedule extends AbstractSchedule implem
|
||||
List<NotifyConfig> notifyConfigs = accessTemplate.getNotifyConfigAccess()
|
||||
.listPage(new PageDTO<>(startId, 1000), new LambdaQueryWrapper<NotifyConfig>()
|
||||
.eq(NotifyConfig::getNotifyStatus, StatusEnum.YES.getStatus())
|
||||
.eq(NotifyConfig::getSystemTaskType, SyetemTaskTypeEnum.RETRY.getType())
|
||||
.eq(NotifyConfig::getNotifyScene, RetryNotifySceneEnum.MAX_RETRY.getNotifyScene())
|
||||
.orderByDesc(NotifyConfig::getId)) // SQLServer 分页必须 ORDER BY
|
||||
.getRecords();
|
||||
|
@ -11,6 +11,7 @@ import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 通知配置接口
|
||||
@ -36,7 +37,6 @@ public class NotifyConfigController {
|
||||
return notifyConfigService.getNotifyConfigDetail(id);
|
||||
}
|
||||
|
||||
|
||||
@LoginRequired
|
||||
@PostMapping
|
||||
public Boolean saveNotify(@RequestBody @Validated NotifyConfigRequestVO requestVO) {
|
||||
@ -54,4 +54,10 @@ public class NotifyConfigController {
|
||||
public Boolean updateStatus(@PathVariable("id") Long id, @PathVariable("status") Integer status) {
|
||||
return notifyConfigService.updateStatus(id, status);
|
||||
}
|
||||
|
||||
@LoginRequired
|
||||
@DeleteMapping("ids")
|
||||
public Boolean batchDeleteNotify(@RequestBody Set<Long> ids) {
|
||||
return notifyConfigService.batchDeleteNotify(ids);
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -50,4 +51,10 @@ public class NotifyRecipientController {
|
||||
public List<CommonLabelValueResponseVO> getNotifyRecipientList() {
|
||||
return notifyRecipientService.getNotifyRecipientList();
|
||||
}
|
||||
|
||||
@DeleteMapping("/ids")
|
||||
@LoginRequired
|
||||
public Boolean batchDeleteByIds(@RequestBody Set<Long> ids) {
|
||||
return notifyRecipientService.batchDeleteByIds(ids);
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import com.aizuda.snailjob.server.web.model.request.NotifyConfigRequestVO;
|
||||
import com.aizuda.snailjob.server.web.model.response.NotifyConfigResponseVO;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author: opensnail
|
||||
@ -27,4 +28,5 @@ public interface NotifyConfigService {
|
||||
|
||||
Boolean updateStatus(Long id, Integer status);
|
||||
|
||||
Boolean batchDeleteNotify(Set<Long> ids);
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import com.aizuda.snailjob.server.web.model.response.CommonLabelValueResponseVO;
|
||||
import com.aizuda.snailjob.server.web.model.response.NotifyRecipientResponseVO;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author opensnail
|
||||
@ -23,4 +24,5 @@ public interface NotifyRecipientService {
|
||||
|
||||
List<CommonLabelValueResponseVO> getNotifyRecipientList();
|
||||
|
||||
Boolean batchDeleteByIds(Set<Long> ids);
|
||||
}
|
||||
|
@ -196,4 +196,10 @@ public class NotifyConfigServiceImpl implements NotifyConfigService {
|
||||
.eq(NotifyConfig::getId, id)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean batchDeleteNotify(final Set<Long> ids) {
|
||||
return ids.size() == accessTemplate.getNotifyConfigAccess()
|
||||
.delete(new LambdaQueryWrapper<NotifyConfig>().in(NotifyConfig::getId, ids));
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author opensnail
|
||||
@ -27,6 +28,7 @@ import java.util.Objects;
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class NotifyRecipientServiceImpl implements NotifyRecipientService {
|
||||
|
||||
private final NotifyRecipientMapper notifyRecipientMapper;
|
||||
|
||||
@Override
|
||||
@ -44,7 +46,8 @@ public class NotifyRecipientServiceImpl implements NotifyRecipientService {
|
||||
queryWrapper.orderByDesc(NotifyRecipient::getCreateDt);
|
||||
PageDTO<NotifyRecipient> notifyRecipientPageDTO = notifyRecipientMapper.selectPage(pageDTO, queryWrapper);
|
||||
|
||||
return new PageResult<>(pageDTO, NotifyRecipientConverter.INSTANCE.toNotifyRecipientResponseVOs(notifyRecipientPageDTO.getRecords()));
|
||||
return new PageResult<>(pageDTO,
|
||||
NotifyRecipientConverter.INSTANCE.toNotifyRecipientResponseVOs(notifyRecipientPageDTO.getRecords()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -71,4 +74,9 @@ public class NotifyRecipientServiceImpl implements NotifyRecipientService {
|
||||
List<NotifyRecipient> notifyRecipients = notifyRecipientMapper.selectList(queryWrapper);
|
||||
return NotifyRecipientConverter.INSTANCE.toCommonLabelValueResponseVOs(notifyRecipients);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean batchDeleteByIds(final Set<Long> ids) {
|
||||
return ids.size() == notifyRecipientMapper.deleteBatchIds(ids);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user