Commit 2f54e640 by 向延琳

停留点服务

1 parent 8bb77b1f
package cn.com.glsx.devicemonitor.modules.api;
import cn.com.glsx.devicemonitor.api.dto.request.StayPointRequest;
import cn.com.glsx.devicemonitor.api.dto.response.StayPointRecordDTO;
import cn.com.glsx.devicemonitor.api.feign.StayPointFeignService;
import cn.com.glsx.devicemonitor.modules.service.StayPointService;
import com.glsx.plat.core.web.R;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* @author xiangyanlin
* @date 2022/5/7
*/
@Slf4j
@Validated
@RestController
@RequestMapping("/api/stayPoint")
@Api(value = "stayPoint", tags = "停留点服务")
public class FeignStayPointController implements StayPointFeignService {
@Autowired
private StayPointService stayPointService;
@GetMapping("/queryList")
@Override
public R<List<StayPointRecordDTO>> getStayPointRecord(StayPointRequest stayPointRequest) {
List<StayPointRecordDTO> list = stayPointService.getStayPointRecord(stayPointRequest);
return R.ok().data(list);
}
}
...@@ -12,10 +12,12 @@ import org.apache.commons.lang.math.NumberUtils; ...@@ -12,10 +12,12 @@ import org.apache.commons.lang.math.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Optional;
/** /**
* @program: ne-shield-devicemonitor * @program: ne-shield-devicemonitor
...@@ -77,6 +79,41 @@ public class HDaoMileComponent { ...@@ -77,6 +79,41 @@ public class HDaoMileComponent {
} }
/** /**
* 停留点数据查询
*
*/
public List<StayPointRecord> listStayPointQuery(String sn, Date beginTime, Date endTime, Integer periodType, Integer min, Integer max) {
List<StayPointRecord> resultList = Lists.newArrayList();
cn.com.glsx.devicemonitor.iceprotocol.mile.Date beginDate = javaDate2CustomerDate(beginTime);
cn.com.glsx.devicemonitor.iceprotocol.mile.Date endDate = javaDate2CustomerDate(endTime);
//最大最小值没有时默认-1,有值时转换为秒
min = Optional.ofNullable(min).map(e -> e * 60).orElse(Integer.MIN_VALUE);
max = Optional.ofNullable(max).map(e -> e * 60).orElse(Integer.MAX_VALUE);
GetStayPointRecordsReq getStayPointRecordsReq = new GetStayPointRecordsReq(NumberUtils.toLong(sn), 5, beginDate, endDate, periodType, min, max, 1);
GetStayPointRecordsResHolder getStayPointRecordsResHolder = new GetStayPointRecordsResHolder();
try {
if (daoMileServicePrx == null) {
throw new ConnectionRefusedException();
}
boolean result = daoMileServicePrx.getStayPointRecords(getStayPointRecordsReq, getStayPointRecordsResHolder);
if (result) {
GetStayPointRecordsRes stayPointRecordsRes = getStayPointRecordsResHolder.value;
StayPointRecord[] stayPointRecords = stayPointRecordsRes.stayPoints;
if (stayPointRecords == null || stayPointRecords.length == 0) {
return resultList;
}
resultList = Lists.newArrayList(stayPointRecords);
}
} catch (Exception e) {
log.error("停留点服务异常:" + e.getMessage(), e);
log.error(e.getMessage(), e);
}
return resultList;
}
/**
* java 日期转需要的日期格式 * java 日期转需要的日期格式
* *
* @param date jav 日期格式 * @param date jav 日期格式
......
package cn.com.glsx.devicemonitor.modules.converter;
import cn.com.glsx.devicemonitor.api.dto.response.GpsLocation;
import cn.com.glsx.devicemonitor.api.dto.response.StayPointRecordDTO;
import cn.com.glsx.devicemonitor.iceprotocol.mile.StayPointRecord;
import cn.com.glsx.devicemonitor.modules.utils.DateUtils;
import cn.com.glsx.devicemonitor.modules.utils.LocationUtil;
import com.google.common.collect.Lists;
import org.apache.commons.collections4.CollectionUtils;
import org.mapstruct.Mapper;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* @author xiangyanlin
* @date 2022/5/7
*/
public class StayPointConvert {
public static List<StayPointRecordDTO> convertTo(List<StayPointRecord> stayPointRecord) {
if (CollectionUtils.isEmpty(stayPointRecord)) {
return Lists.newArrayList();
}
return stayPointRecord.stream().map(StayPointConvert::convertTo).collect(Collectors.toList());
}
public static StayPointRecordDTO convertTo(StayPointRecord stayPointRecord) {
if (Objects.isNull(stayPointRecord)) {
return null;
}
StayPointRecordDTO stayPointRecordDTO = new StayPointRecordDTO();
Optional.of(stayPointRecord.bgnTime)
.map(bgnTime -> new Date((long) stayPointRecord.bgnTime * 1000))
.map(DateUtils::formatNormal)
.ifPresent(stayPointRecordDTO::setBeginTime);
Optional.of(stayPointRecord.endTime)
.map(bgnTime -> new Date((long) stayPointRecord.bgnTime * 1000))
.map(DateUtils::formatNormal)
.ifPresent(stayPointRecordDTO::setEndTime);
stayPointRecordDTO.setDuration(stayPointRecord.duration);
GpsLocation gpsLocation = new GpsLocation();
Optional.ofNullable(stayPointRecord.stayGps)
.map(e -> e.lat)
.map(LocationUtil::latlng)
.ifPresent(gpsLocation::setLat);
Optional.ofNullable(stayPointRecord.stayGps)
.map(e -> e.lng)
.map(LocationUtil::latlng)
.ifPresent(gpsLocation::setLng);
Optional.ofNullable(stayPointRecord.stayGps)
.map(e -> e.blat)
.map(LocationUtil::latlng)
.ifPresent(gpsLocation::setBlat);
Optional.ofNullable(stayPointRecord.stayGps)
.map(e -> e.blng)
.map(LocationUtil::latlng)
.ifPresent(gpsLocation::setBlat);
Optional.ofNullable(stayPointRecord.stayGps)
.map(e -> e.glat)
.map(LocationUtil::latlng)
.ifPresent(gpsLocation::setElat);
Optional.ofNullable(stayPointRecord.stayGps)
.map(e -> e.glng)
.map(LocationUtil::latlng)
.ifPresent(gpsLocation::setElng);
stayPointRecordDTO.setStayGps(gpsLocation);
return stayPointRecordDTO;
}
}
package cn.com.glsx.devicemonitor.modules.service;
import cn.com.glsx.devicemonitor.api.dto.request.StayPointRequest;
import cn.com.glsx.devicemonitor.api.dto.response.StayPointRecordDTO;
import java.util.List;
/**
* 停留点服务
* @author xiangyanlin
* @date 2022/5/7
*/
public interface StayPointService {
/**
* 停留点列表
* @param stayPointRequest 查询参数
* @return 实例集合
*/
List<StayPointRecordDTO> getStayPointRecord(StayPointRequest stayPointRequest);
}
package cn.com.glsx.devicemonitor.modules.service.impl;
import cn.com.glsx.devicemonitor.api.dto.request.StayPointRequest;
import cn.com.glsx.devicemonitor.api.dto.response.StayPointRecordDTO;
import cn.com.glsx.devicemonitor.iceprotocol.mile.StayPointRecord;
import cn.com.glsx.devicemonitor.modules.components.HDaoMileComponent;
import cn.com.glsx.devicemonitor.modules.converter.StayPointConvert;
import cn.com.glsx.devicemonitor.modules.service.StayPointService;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 停留点服务
* @author xiangyanlin
* @date 2022/5/7
*/
@Slf4j
@Service
public class StayPointServiceImpl implements StayPointService {
@Autowired
private HDaoMileComponent hDaoMileComponent;
@Override
public List<StayPointRecordDTO> getStayPointRecord(StayPointRequest stayPointRequest) {
List<StayPointRecord> stayPointRecords = hDaoMileComponent.listStayPointQuery(stayPointRequest.getSn(),
stayPointRequest.getBeginTime(), stayPointRequest.getEndTime(),
stayPointRequest.getPeriodType(), stayPointRequest.getMin(), stayPointRequest.getMax());
if(CollectionUtils.isEmpty(stayPointRecords)) {
return Lists.newArrayList();
}
return StayPointConvert.convertTo(stayPointRecords);
}
}
package cn.com.glsx.devicemonitor.modules.service.impl;
import cn.com.glsx.Application;
import cn.com.glsx.devicemonitor.api.dto.request.StayPointRequest;
import cn.com.glsx.devicemonitor.api.dto.response.StayPointRecordDTO;
import cn.com.glsx.devicemonitor.modules.service.StayPointService;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Date;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
/**
* @author xiangyanlin
* @date 2022/5/7
*/
@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class StayPointServiceImplTest {
@Autowired
private StayPointService stayPointService;
@Test
public void testGetStayPointRecord() {
StayPointRequest request = new StayPointRequest();
request.setSn("1274977336");
request.setBeginTime(new Date(1648742400000L));
request.setEndTime(new Date(1651161600000L));
request.setPeriodType(0);
List<StayPointRecordDTO> stayPointRecord = stayPointService.getStayPointRecord(request);
System.out.println(JSON.toJSONString(stayPointRecord));
}
}
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!