This commit is contained in:
2026-11-16 13:38:56 +08:00
parent c3a2aee8fb
commit 08888ab612
44 changed files with 1162 additions and 377 deletions

View File

@@ -1,26 +1,24 @@
package com.maibu.scheduled;
import com.maibu.constant.NettyCacheKey;
import com.maibu.core.business.DevicePlan;
import com.maibu.core.business.DeviceRunParam;
import com.maibu.core.business.DeviceStatusRecordDTO;
import com.maibu.core.redis.RedisCache;
import com.maibu.mapper.DeviceStatusHistoryMapper;
import com.maibu.memory.SiteMemory;
import com.maibu.utils.json.JsonUtils;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import com.maibu.constant.NettyCacheKey;
import com.maibu.core.business.DevicePlan;
import com.maibu.core.business.DeviceStatusRecordDTO;
import com.maibu.core.business.dto.VehicleMessageRecordDTO;
import com.maibu.core.redis.RedisCache;
import com.maibu.mapper.VehicleMessageMapper;
import com.maibu.memory.SiteMemory;
@Component
public class ScheduledTask {
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@@ -29,27 +27,25 @@ public class ScheduledTask {
private RedisCache redisCache;
@Autowired
private DeviceStatusHistoryMapper deviceStatusHistoryMapper;
private VehicleMessageMapper vehicleMessageMapper;
//整点更新设备状态
// 整点更新设备状态
@Scheduled(cron = "0 0 * * * ?")
// @Scheduled(cron = "0 * * * * ?")
// @Scheduled(cron = "0 * * * * ?")
public void executeHourlyTask() {
System.out.println("整点定时任务执行时间: " + dateFormat.format(new Date()));
String key = NettyCacheKey.deviceRunningStatusKey;
// Collection<String> keys = redisCache.keys(key);
String key = NettyCacheKey.vehicleMessageKey;
// Collection<String> keys = redisCache.keys(key);
Collection<String> keys = redisCache.getListKeyByPrefix(key);
if (!CollectionUtils.isEmpty(keys)) {
keys.forEach(k -> {
DeviceStatusRecordDTO recordDTO = redisCache.getCacheObject(k);
VehicleMessageRecordDTO recordDTO = redisCache.getCacheObject(k);
if (recordDTO != null && !CollectionUtils.isEmpty(recordDTO.getHistories())) {
// recordDTO.getHistories().forEach(x -> {
// deviceStatusHistoryMapper.insert(x);
// });
deviceStatusHistoryMapper.insertBatch(recordDTO.getHistories());
// recordDTO.getHistories().forEach(x -> {
// deviceStatusHistoryMapper.insert(x);
// });
vehicleMessageMapper.insertBatch(recordDTO.getHistories());
}
redisCache.deleteObject(k);
});
@@ -57,8 +53,7 @@ public class ScheduledTask {
System.out.println("任务执行完成");
}
//0点刷新任务创建状态
// 0点刷新任务创建状态
@Scheduled(cron = "0 0 0 * * ?")
public void refreshDevicePlanTask() {
System.out.println("0点定时刷新状态");
@@ -76,19 +71,26 @@ public class ScheduledTask {
}
// public static void main(String[] args) throws DecoderException {
// String hex = "AB AA 05 88 4D 43 37 30 30 50 4C 55 53 2D 43 4E 2D 4A 53 2D 31 37 38 34 38 37 31 39 37 39 31 39 30 2D 30 30 30 30 30 30 30 41 2D 36 30 00 B1 FB 7F FE FE FE 00 00 00 00 00 00 00 00 00 00 00 00 00 12 01 48 95 E8 03 E8 03 28 32 91 53 24 4D 43 37 30 30 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 31 32 33 34 35 36 37 38 00 00 00 00 00 00 00 00 00 00 00 00 00 08 00 00 00 CD CC A4 41 00 00 80 3F 33 33 33 3F B8 1E 05 3F 33 33 33 3F 9A 99 19 3E 00 00 80 3F 00 00 80 3F 00 00 80 3F 32 36 2D 34 2D 32 37 00 2D 32 37 00 50 B1 BF 00 00 AA AB";
// String cleanHex = hex.replaceAll("\\s+", ""); // 移除所有空白字符
// byte[] bytes = Hex.decodeHex(cleanHex);
// DeviceRunParam runParam = DeviceRunParam.fromBytes(bytes);
// System.out.println(JsonUtils.toJsonString(runParam));
// String hex = "AB AA 05 88 4D 43 37 30 30 50 4C 55 53 2D 43 4E 2D 4A 53 2D 31
// 37 38 34 38 37 31 39 37 39 31 39 30 2D 30 30 30 30 30 30 30 41 2D 36 30 00 B1
// FB 7F FE FE FE 00 00 00 00 00 00 00 00 00 00 00 00 00 12 01 48 95 E8 03 E8 03
// 28 32 91 53 24 4D 43 37 30 30 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 31
// 32 33 34 35 36 37 38 00 00 00 00 00 00 00 00 00 00 00 00 00 08 00 00 00 CD CC
// A4 41 00 00 80 3F 33 33 33 3F B8 1E 05 3F 33 33 33 3F 9A 99 19 3E 00 00 80 3F
// 00 00 80 3F 00 00 80 3F 32 36 2D 34 2D 32 37 00 2D 32 37 00 50 B1 BF 00 00 AA
// AB";
// String cleanHex = hex.replaceAll("\\s+", ""); // 移除所有空白字符
// byte[] bytes = Hex.decodeHex(cleanHex);
// DeviceRunParam runParam = DeviceRunParam.fromBytes(bytes);
// System.out.println(JsonUtils.toJsonString(runParam));
// runParam.setLeftBackwardGain(0.2f);
// runParam.setLeftForwardGain(0.2f);
// runParam.setRightForwardGain(0.2f);
// runParam.setRightBackwardGain(0.2f);
// runParam.setLeftBackwardGain(0.2f);
// runParam.setLeftForwardGain(0.2f);
// runParam.setRightForwardGain(0.2f);
// runParam.setRightBackwardGain(0.2f);
// byte[] newB = runParam.toWriteBytes();
// System.out.println(Hex.encodeHexString(newB));
// byte[] newB = runParam.toWriteBytes();
// System.out.println(Hex.encodeHexString(newB));
// }
}