web端控制中心4
This commit is contained in:
@ -1,19 +1,20 @@
|
||||
package com.fuyuanshen.web.controller.device;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.fuyuanshen.app.domain.dto.APPReNameDTO;
|
||||
import com.fuyuanshen.app.domain.dto.AppRealTimeStatusDto;
|
||||
import com.fuyuanshen.app.domain.vo.APPDeviceTypeVo;
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
import com.fuyuanshen.common.excel.utils.ExcelUtil;
|
||||
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
import com.fuyuanshen.common.web.core.BaseController;
|
||||
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.web.service.device.DeviceBizService;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@ -101,4 +102,48 @@ public class DeviceControlCenterController extends BaseController {
|
||||
return appDeviceService.getInstructionRecord(dto,pageQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出
|
||||
*/
|
||||
@GetMapping("/export")
|
||||
public void export(InstructionRecordDto dto, PageQuery pageQuery, HttpServletResponse response) {
|
||||
pageQuery.setPageNum(1);
|
||||
pageQuery.setPageSize(2000);
|
||||
TableDataInfo<InstructionRecordVo> instructionRecord = appDeviceService.getInstructionRecord(dto, pageQuery);
|
||||
if(instructionRecord.getRows() == null){
|
||||
return;
|
||||
}
|
||||
ExcelUtil.exportExcel(instructionRecord.getRows(), "设备操作日志", InstructionRecordVo.class, response);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 历史轨迹查询
|
||||
*/
|
||||
@GetMapping("/locationHistory")
|
||||
public TableDataInfo<LocationHistoryVo> getLocationHistory(InstructionRecordDto dto, PageQuery pageQuery) {
|
||||
return appDeviceService.getLocationHistory(dto,pageQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* 历史轨迹导出
|
||||
*/
|
||||
@GetMapping("/locationHistoryExport")
|
||||
public void locationHistoryExport(InstructionRecordDto dto, PageQuery pageQuery, HttpServletResponse response) {
|
||||
pageQuery.setPageNum(1);
|
||||
pageQuery.setPageSize(2000);
|
||||
TableDataInfo<LocationHistoryVo> result = appDeviceService.getLocationHistory(dto, pageQuery);
|
||||
if(result.getRows() == null){
|
||||
return;
|
||||
}
|
||||
ExcelUtil.exportExcel(result.getRows(), "历史轨迹记录", LocationHistoryVo.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 历史轨迹导出
|
||||
*/
|
||||
@GetMapping("/getLocationHistoryDetail")
|
||||
public R<List<LocationHistoryDetailVo>> getLocationHistoryDetail(Long id) {
|
||||
return R.ok(appDeviceService.getLocationHistoryDetail(id));
|
||||
}
|
||||
}
|
||||
|
@ -27,9 +27,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 +39,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.*;
|
||||
@ -336,4 +333,60 @@ 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"));
|
||||
detailVo.setDetailList(entry.getValue());
|
||||
result.add(detailVo);
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user