Compare commits

...

3 Commits

Author SHA1 Message Date
xiaohuo 3756a61f9e 11.6站内信list修改 8 months ago
xiaohuo ba849694f1 11.6添加外部中断钩子 8 months ago
xiaohuo e52a5cd73b 11.6 采集改错 8 months ago
  1. 6
      ALOps_sys_backend/alops-admin/src/main/java/com/alops/web/controller/exceptionController/AlertMessageController.java
  2. 5
      ALOps_sys_backend/alops-system/src/main/java/com/alops/system/job/GatherJob.java
  3. 5
      ALOps_sys_backend/alops-system/src/main/java/com/alops/system/mapper/InternalMessageMapper.java
  4. 6
      ALOps_sys_backend/alops-system/src/main/java/com/alops/system/mapper/ScheduleRulesMapper.java
  5. 3
      ALOps_sys_backend/alops-system/src/main/java/com/alops/system/service/impl/AlertLaunchServiceImpl.java
  6. 14
      ALOps_sys_backend/alops-system/src/main/java/com/alops/system/service/impl/AlertRuleServiceImpl.java
  7. 1
      ALOps_sys_backend/alops-system/src/main/java/com/alops/system/service/impl/InternalMessageServiceImpl.java
  8. 15
      ALOps_sys_backend/alops-system/src/main/java/com/alops/system/service/impl/ScheduleRulesServiceImpl.java
  9. 57
      ALOps_sys_backend/alops-system/src/main/java/com/alops/system/service/impl/ScheduleShutdownHook.java
  10. 6
      ALOps_sys_backend/alops-system/src/main/resources/mapper/system/InternalMessageMapper.xml
  11. 9
      ALOps_sys_backend/alops-system/src/main/resources/mapper/system/ScheduleRulesMapper.xml

@ -48,12 +48,8 @@ public class AlertMessageController extends BaseController
@ApiOperation("立即执行预警")
@Log(title = "【立即执行预警】", businessType = BusinessType.DELETE)
@PostMapping("/executeImmediate")
public AjaxResult executeImmediate(@RequestBody Map<String, List<Long>> paramMap) {
public AjaxResult executeImmediate() {
try {
List<Long> ruleIds = paramMap.get("ruleIds");
if (ruleIds == null || ruleIds.isEmpty()) {
return AjaxResult.error("请选择至少一条规则");
}
iAlertLaunchService.executeImmediateAlerts(); // 调用 Service 执行
return AjaxResult.success("立即预警任务已触发,存入成功,请查看");

@ -40,8 +40,9 @@ public class GatherJob implements Job {
try {
if (rule == null) return;
// 1.状态为4时取消调度任务
if (rule.getStatus() == 4) {
// 1.状态为5时取消调度任务
if (rule.getStatus() == 5) {
rule.setStatus(4);
Scheduler scheduler = context.getScheduler();
JobKey jobKey = context.getJobDetail().getKey();
// scheduler.deleteJob(jobKey);

@ -16,7 +16,10 @@ import java.util.List;
public interface InternalMessageMapper
{
/**
* 根据用户ID将所有消息状态更新为已读
*/
int updateMessagesToReadByUserId(@Param("userId") Long userId);
/**
* 查询指定用户的所有消息按时间倒序
*/

@ -16,6 +16,12 @@ public interface ScheduleRulesMapper
{
/**
* status 1 5 的记录更新为 3
* @return 更新的记录数
*/
int updateStatusFrom1And5To3();
public List<ScheduleRules> selectList();
public List<ScheduleRules> selectListOne();

@ -341,7 +341,8 @@ public class AlertLaunchServiceImpl implements IAlertLaunchService {
" WHERE t3.equ_id = g1.equ_id " +
" ) " +
") " +
"AND (g1." + col + " <> g2." + col + " OR g1." + col + " IS NULL OR g2." + col + " IS NULL)";
"AND (g1." + col + " <> g2." + col + " OR g1." + col + " IS NULL OR g2." + col + " IS NULL)"+
"AND b.status = '1'";
System.out.println(sql);
System.out.println(jdbcTemplate.queryForList(sql));

@ -159,8 +159,10 @@ public class AlertRuleServiceImpl implements IAlertRuleService
.append(" FROM equ_gather ")
.append(" GROUP BY equ_id ")
.append(") latest ON g.equ_id = latest.equ_id AND g.gather_time = latest.latest_time ")
.append("WHERE ")
.append(buildConditionsSql(conditions));
.append("WHERE b.status = '1' "); // 先把固定条件放在前面
if (!buildConditionsSql(conditions).isEmpty()) {
sql.append(" AND ").append(buildConditionsSql(conditions));
}
} else {
// 其他表,需要连 equ_gather → equ_base → equ_type
sql.append("src.*, g.equ_id, t.name AS equ_type,b.name AS equ_name,b.equ_number ")
@ -168,8 +170,12 @@ public class AlertRuleServiceImpl implements IAlertRuleService
.append("JOIN equ_gather g ON src.equ_gather_id = g.id ")
.append("JOIN equ_base b ON g.equ_id = b.id ")
.append("JOIN equ_type t ON b.equ_type = t.id ") // ★ 新增关联
.append("WHERE ")
.append(buildConditionsSql(conditions));
.append("WHERE b.status = '1' "); // 先把固定条件放在前面
if (!buildConditionsSql(conditions).isEmpty()) {
sql.append(" AND ").append(buildConditionsSql(conditions));
}
}
return sql.toString();

@ -29,6 +29,7 @@ public class InternalMessageServiceImpl implements IInternalMessageService
if (userId == null) {
return Collections.emptyList();
}
internalMessageMapper.updateMessagesToReadByUserId(userId);
return internalMessageMapper.selectMessagesByUserId(userId);
}
@Override

@ -89,12 +89,13 @@ public class ScheduleRulesServiceImpl implements IScheduleRulesService {
switch (rule.getStatus()) {
case 1: // 正在执行
log.info("规则[{}]:正在执行上一个任务,等待上一个任务完成……", rule.getId());
if (rule.getRuleType() == 2 || rule.getRuleType() == 1) {
rule.setStatus(2);
} else if (rule.getRuleType() == 0) {
log.info("改变状态为4");
rule.setStatus(4);
}
// if (rule.getRuleType() == 2 || rule.getRuleType() == 1) {
//// rule.setStatus(2);
// } else
// if (rule.getRuleType() == 0) {
log.info("改变状态为5");
rule.setStatus(5);
// }
scheduleRulesMapper.updateScheduleRules(rule);
return true;
case 0: // 待执行
@ -105,6 +106,8 @@ public class ScheduleRulesServiceImpl implements IScheduleRulesService {
scheduleRulesMapper.updateScheduleRules(rule);
iAlertSenderService.sendInternalMessage("采集整体任务取消成功","任务执行完此次,已取消后续任务","2");
return false;
case 5:
return true;
default:
return true;
}

@ -0,0 +1,57 @@
package com.alops.system.service.impl;
import com.alops.system.mapper.ScheduleRulesMapper;
import com.alops.system.service.IAlertSenderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
@Component
public class ScheduleShutdownHook {
private static final Logger log = LoggerFactory.getLogger(ScheduleShutdownHook.class);
@Autowired
private ScheduleRulesMapper scheduleRulesMapper;
@Autowired
private IAlertSenderService iAlertSenderService;
private static ScheduleShutdownHook instance;
@PostConstruct
public void init() {
instance = this;
registerShutdownHook();
}
private void registerShutdownHook() {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
log.info("检测到应用关闭,开始更新任务状态...");
updateInterruptedStatus();
}));
}
private void updateInterruptedStatus() {
try {
// 将所有状态为1(执行中)、5(等待中)的任务更新为3(执行失败)
int affectedRows = scheduleRulesMapper.updateStatusFrom1And5To3();
log.info("成功更新 {} 个任务状态为中断", affectedRows);
// 发送站内信
if (affectedRows > 0) {
iAlertSenderService.sendInternalMessage(
"系统中断",
"采集任务被外部中断,已更新" + affectedRows + "个任务状态",
"2"
);
}
} catch (Exception e) {
log.error("中断处理失败: {}", e.getMessage(), e);
// 备用方案:直接输出到控制台
System.err.println("中断处理失败: " + e.getMessage());
}
}
}

@ -14,6 +14,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<!-- 根据用户ID将所有消息状态更新为已读 -->
<update id="updateMessagesToReadByUserId">
UPDATE internal_message
SET status = 'read' <!-- 假设1表示已读状态,请根据您的实际状态值调整 -->
WHERE user_id = #{userId}
</update>
<select id="selectMessagesByUserId" resultMap="InternalMessageResult">
SELECT *

@ -42,10 +42,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select id, rule_name, rule_type, frequency, gather_time, start_time, end_time, status,created_at ,created_by from schedule_rules
</sql>
<update id="updateStatusFrom1And5To3">
UPDATE schedule_rules
SET status = 3
WHERE status IN (1, 5)
</update>
<select id="selectList" resultMap="ScheduleRulesResult">
SELECT *
FROM schedule_rules
WHERE status IN (0, 1)
WHERE status IN (0, 1,5)
</select>

Loading…
Cancel
Save