Compare commits

..

No commits in common. '3756a61f9e70fe5d2ca2398a3a35ae65e82a569c' and 'd7ee5ad79f6ce792b5290372ce0c089f36680579' have entirely different histories.

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

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

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

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

@ -341,8 +341,7 @@ public class AlertLaunchServiceImpl implements IAlertLaunchService {
" WHERE t3.equ_id = g1.equ_id " + " 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(sql);
System.out.println(jdbcTemplate.queryForList(sql)); System.out.println(jdbcTemplate.queryForList(sql));

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

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

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

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

@ -42,17 +42,10 @@ 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 select id, rule_name, rule_type, frequency, gather_time, start_time, end_time, status,created_at ,created_by from schedule_rules
</sql> </sql>
<update id="updateStatusFrom1And5To3">
UPDATE schedule_rules
SET status = 3
WHERE status IN (1, 5)
</update>
<select id="selectList" resultMap="ScheduleRulesResult"> <select id="selectList" resultMap="ScheduleRulesResult">
SELECT * SELECT *
FROM schedule_rules FROM schedule_rules
WHERE status IN (0, 1,5) WHERE status IN (0, 1)
</select> </select>

Loading…
Cancel
Save