瀏覽代碼

新增删除定时任务:删除三日前ws重试消息

jingyuanchao 11 月之前
父節點
當前提交
ed4be6f221

+ 11 - 0
project_data/sql/1.0.11/quartz.sql

@@ -0,0 +1,11 @@
+update sys_job
+set status = 1
+where invoke_target like 'MediatorTask%';
+
+delete
+from sys_job
+where invoke_target = 'HostTask.deletedRetryMsg()';
+INSERT INTO `sys_job`(`job_name`, `job_group`, `invoke_target`, `cron_expression`, `misfire_policy`,
+                      `concurrent`, `status`, `create_by`, `create_time`, `update_by`, `update_time`)
+VALUES ('删除三日前ws重试消息', 'DEFAULT', 'HostTask.deletedRetryMsg()', '0 0 1 * * ?', '1', '1', '0',
+        '超级管理员', '2024-11-28 15:26:34', '', NULL);

+ 3 - 0
soc-api/soc-api-system/src/main/java/com/xunmei/system/api/RemoteHostService.java

@@ -77,4 +77,7 @@ public interface RemoteHostService {
 
     @GetMapping("/deletedDeviceAndSyncToHost/{id}")
     AjaxResult deletedDeviceAndSyncToHost(@PathVariable("id") Long id);
+
+    @GetMapping("/deletedRetryMsg/{date}")
+    AjaxResult deletedRetryMsg(@PathVariable("date") String date);
 }

+ 5 - 0
soc-api/soc-api-system/src/main/java/com/xunmei/system/api/factory/RemoteHostFallbackFactory.java

@@ -91,6 +91,11 @@ public class RemoteHostFallbackFactory implements FallbackFactory<RemoteHostServ
             public AjaxResult deletedDeviceAndSyncToHost(Long id) {
                 return null;
             }
+
+            @Override
+            public AjaxResult deletedRetryMsg(String date) {
+                return AjaxResult.error();
+            }
         };
     }
 }

+ 8 - 2
soc-modules/soc-modules-host/src/main/java/com/xunmei/host/north/controller/HostController.java

@@ -7,8 +7,8 @@ import com.xunmei.common.core.web.domain.AjaxResult;
 import com.xunmei.host.alarm.service.IotAlarmRuleService;
 import com.xunmei.host.iot.service.IIotDeviceInfoService;
 import com.xunmei.host.iot.service.IotCameraMissionRuleService;
+import com.xunmei.host.north.service.IotWebsocketMsgService;
 import com.xunmei.host.protection.service.IIotAlarmHostService;
-import com.xunmei.host.server.service.IotServerInfoService;
 import com.xunmei.host.websocket.service.WebsocketService;
 import com.xunmei.system.api.Eto.SubSystemControlEto;
 import io.swagger.annotations.ApiOperation;
@@ -28,7 +28,7 @@ import java.util.List;
 @RestController
 public class HostController {
     @Resource
-    IotServerInfoService serverInfoService;
+    IotWebsocketMsgService websocketMsgService;
     @Resource
     WebsocketService websocketService;
 
@@ -132,4 +132,10 @@ public class HostController {
         deviceInfoService.deletedDeviceAndSyncToHost(id);
         return AjaxResult.success();
     }
+
+    @GetMapping("/deletedRetryMsg/{date}")
+    AjaxResult deletedRetryMsg(@PathVariable("date") String date){
+        websocketMsgService.deletedRetryMsg(date);
+        return AjaxResult.success();
+    }
 }

+ 2 - 0
soc-modules/soc-modules-host/src/main/java/com/xunmei/host/north/service/IotWebsocketMsgService.java

@@ -25,4 +25,6 @@ public interface IotWebsocketMsgService extends IService<IotWebsocketMsg> {
     void sendFailMsg(WebsocketResult res, String msgId);
 
     void afterConnect(String iotCode);
+
+    void deletedRetryMsg(String date);
 }

+ 8 - 0
soc-modules/soc-modules-host/src/main/java/com/xunmei/host/north/service/impl/IotWebsocketMsgServiceImpl.java

@@ -1,5 +1,6 @@
 package com.xunmei.host.north.service.impl;
 
+import cn.hutool.core.date.DateUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.xunmei.common.core.domain.iot.domain.IotServerInfo;
@@ -238,4 +239,11 @@ public class IotWebsocketMsgServiceImpl extends ServiceImpl<IotWebsocketMsgMappe
         wrapper.eq(IotWebsocketMsg::getStatus, MessageStatusEnum.RETRYING.getCode());
         return baseMapper.selectList(wrapper);
     }
+
+    @Override
+    public void deletedRetryMsg(String date) {
+        LambdaQueryWrapper<IotWebsocketMsg> wrapper = new LambdaQueryWrapper<IotWebsocketMsg>();
+        wrapper.ge(IotWebsocketMsg::getCreateTime, DateUtil.beginOfDay(DateUtil.parse(date)));
+        remove(wrapper);
+    }
 }

+ 11 - 1
soc-modules/soc-modules-job/src/main/java/com/xunmei/job/task/HostTask.java

@@ -1,11 +1,12 @@
 package com.xunmei.job.task;
 
 
+import cn.hutool.core.date.DateTime;
+import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.lang.UUID;
 import com.alibaba.fastjson2.JSON;
 import com.xunmei.common.core.web.domain.AjaxResult;
 import com.xunmei.system.api.RemoteHostService;
-import com.xunmei.system.api.RemoteMediatorService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
@@ -25,4 +26,13 @@ public class HostTask {
         AjaxResult result = hostService.getDevices();
         log.info("获取所有主机信息结束....,当前任务 id:{},当前时间:{},结果:{}", id, new Date(), JSON.toJSONString(result));
     }
+
+    public void deletedRetryMsg() {
+        String id = UUID.fastUUID().toString();
+        final DateTime beginOfDay = DateUtil.beginOfDay(new Date());
+        final DateTime dateTime = DateUtil.offsetDay(beginOfDay, -3);
+        log.info("开始删除三天之前的所有重试消息数据,当前任务 id:{}", id);
+        AjaxResult result = hostService.deletedRetryMsg(DateUtil.format(dateTime, "yyyy-MM-dd"));
+        log.info("删除三天之前的所有重试消息数据任务结束....,当前任务 id:{},结果:{}", id, JSON.toJSONString(result));
+    }
 }