merge upstream

This commit is contained in:
2025-09-02 09:06:54 +08:00
55 changed files with 2461 additions and 113 deletions

View File

@ -1,6 +1,7 @@
package com.fuyuanshen.web.service.device;
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
@ -27,9 +28,7 @@ import com.fuyuanshen.equipment.domain.Device;
import com.fuyuanshen.equipment.domain.dto.AppDeviceBo;
import com.fuyuanshen.equipment.domain.dto.InstructionRecordDto;
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
import com.fuyuanshen.equipment.domain.vo.AppDeviceVo;
import com.fuyuanshen.equipment.domain.vo.InstructionRecordVo;
import com.fuyuanshen.equipment.domain.vo.WebDeviceVo;
import com.fuyuanshen.equipment.domain.vo.*;
import com.fuyuanshen.equipment.enums.BindingStatusEnum;
import com.fuyuanshen.equipment.enums.CommunicationModeEnum;
import com.fuyuanshen.equipment.mapper.DeviceLogMapper;
@ -41,9 +40,8 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.time.*;
import java.util.*;
import static com.fuyuanshen.common.core.constant.GlobalConstants.GLOBAL_REDIS_KEY;
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.*;
@ -313,8 +311,8 @@ public class DeviceBizService {
public Map<String, Object> getRealTimeStatus(AppRealTimeStatusDto statusDto) {
try {
String commandType = statusDto.getTypeName()+"_" + statusDto.getFunctionMode();
DeviceStatusRule rule = realTimeStatusEngine.getDeviceStatusRule(commandType);
// String commandType = statusDto.getTypeName()+"_" + statusDto.getFunctionMode();"FunctionAccessBatchStatusRule"
DeviceStatusRule rule = realTimeStatusEngine.getDeviceStatusRule(statusDto.getTypeName());
if(rule == null){
throw new ServiceException("未匹配到处理命令");
}
@ -336,4 +334,63 @@ public class DeviceBizService {
Page<InstructionRecordVo> result = deviceLogMapper.getInstructionRecord(pageQuery.build(), bo);
return TableDataInfo.build(result);
}
public TableDataInfo<LocationHistoryVo> getLocationHistory(InstructionRecordDto bo, PageQuery pageQuery) {
Page<LocationHistoryVo> result = deviceMapper.getLocationHistory(pageQuery.build(), bo);
return TableDataInfo.build(result);
}
public List<LocationHistoryDetailVo> getLocationHistoryDetail(Long id) {
Device device = deviceMapper.selectById(id);
if (device == null) {
throw new ServiceException("设备不存在");
}
// 计算七天前的凌晨时间戳
LocalDateTime sevenDaysAgo = LocalDateTime.of(LocalDate.now().minusDays(7), LocalTime.MIDNIGHT);
long startTime = sevenDaysAgo.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
// 计算今天的凌晨时间戳
LocalDateTime today = LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
long endTime = today.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
String deviceImei = device.getDeviceImei();
String a = GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ deviceImei + DEVICE_LOCATION_KEY_PREFIX + ":history";
Collection<String> list = RedisUtils.zRangeByScore(a, startTime, endTime);
if (CollectionUtil.isEmpty(list)) {
return null;
}
Map<String, List<JSONObject>> map = new LinkedHashMap<>();
for (String obj : list){
JSONObject jsonObject = JSONObject.parseObject(obj);
Long timestamp = jsonObject.getLong("timestamp");
LocalDate date = LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault()).toLocalDate();
if (map.containsKey(date.toString())) {
map.get(date.toString()).add(jsonObject);
} else {
ArrayList<JSONObject> jsonList = new ArrayList<>();
jsonList.add(jsonObject);
map.put(date.toString(), jsonList);
}
}
List<LocationHistoryDetailVo> result = new ArrayList<>();
for (Map.Entry<String, List<JSONObject>> entry : map.entrySet()) {
LocationHistoryDetailVo detailVo = new LocationHistoryDetailVo();
detailVo.setDate(entry.getKey());
detailVo.setDeviceName(device.getDeviceName());
detailVo.setStartLocation(entry.getValue().get(0).getString("address"));
detailVo.setEndLocation(entry.getValue().get(entry.getValue().size()-1).getString("address"));
String jsonString = JSONArray.toJSONString(entry.getValue());
List<Object> strings = JSONArray.parseArray(jsonString);
detailVo.setDetailList(strings);
result.add(detailVo);
}
return result;
}
}

View File

@ -22,7 +22,7 @@ import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCES
public class FunctionAccessBatchStatusRule implements DeviceStatusRule {
@Override
public String getCommandType() {
return DeviceTypeConstants.TYPE_BJQ6170+"_2";
return "FunctionAccessBatchStatusRule";
}
@Override

View File

@ -21,7 +21,7 @@ import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCES
public class FunctionAccessStatusRule implements DeviceStatusRule {
@Override
public String getCommandType() {
return DeviceTypeConstants.TYPE_BJQ6170+"_1";
return "FunctionAccessStatusRule";
}
@Override