定位信息上报
This commit is contained in:
parent
f125c1d114
commit
5e530d4f5f
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CodeStream">
|
||||
<option name="webViewContext" value="{"chatProviderAccess":"strict","currentTeamId":"","currentStreamId":"","pullRequestCheckoutBranch":false,"isRepositioning":false,"onboardStep":0,"panelStack":["landing-redirect"],"hasFocus":false,"channelFilter":"all","channelsMuteAll":false,"codemarkFileFilter":"all","codemarkTypeFilter":"all","codemarkTagFilter":"all","codemarkBranchFilter":"all","codemarkAuthorFilter":"all","codemarksFileViewStyle":"inline","codemarksShowArchived":false,"codemarksShowResolved":false,"codemarksWrapComments":false,"showFeedbackSmiley":true,"route":{"name":"newUserEntry","params":{}},"spatialViewShowPRComments":false,"currentPullRequestNeedsRefresh":{"needsRefresh":false,"providerId":"","pullRequestId":""},"__teamless__":{"selectedRegion":"us"},"sessionStart":1681277419701}" />
|
||||
<option name="webViewContext" value="{"chatProviderAccess":"strict","currentTeamId":"","currentStreamId":"","pullRequestCheckoutBranch":false,"isRepositioning":false,"onboardStep":0,"panelStack":["landing-redirect"],"hasFocus":false,"channelFilter":"all","channelsMuteAll":false,"codemarkFileFilter":"all","codemarkTypeFilter":"all","codemarkTagFilter":"all","codemarkBranchFilter":"all","codemarkAuthorFilter":"all","codemarksFileViewStyle":"inline","codemarksShowArchived":false,"codemarksShowResolved":false,"codemarksWrapComments":false,"showFeedbackSmiley":true,"route":{"name":"newUserEntry","params":{}},"spatialViewShowPRComments":false,"currentPullRequestNeedsRefresh":{"needsRefresh":false,"providerId":"","pullRequestId":""},"__teamless__":{"selectedRegion":"us"},"sessionStart":1683633459106}" />
|
||||
</component>
|
||||
</project>
|
@ -2,11 +2,12 @@ package cn.skcks.matrix.v2.api.locatioin.record;
|
||||
|
||||
import cn.skcks.matrix.v2.annotation.web.JsonMapping;
|
||||
import cn.skcks.matrix.v2.annotation.web.auth.Auth;
|
||||
import cn.skcks.matrix.v2.auth.claims.Claim;
|
||||
import cn.skcks.matrix.v2.annotation.web.methods.PostJson;
|
||||
import cn.skcks.matrix.v2.auth.claims.Claim;
|
||||
import cn.skcks.matrix.v2.config.swagger.SwaggerConfig;
|
||||
import cn.skcks.matrix.v2.model.jwt.dto.Claims;
|
||||
import cn.skcks.matrix.v2.model.location.record.convert.LocationRecordConvertor;
|
||||
import cn.skcks.matrix.v2.model.location.record.dto.LocationRecordDto;
|
||||
import cn.skcks.matrix.v2.model.location.record.dto.LocationRecordParams;
|
||||
import cn.skcks.matrix.v2.model.location.record.dto.PageLocationRecordParams;
|
||||
import cn.skcks.matrix.v2.model.location.record.vo.LocationRecordVo;
|
||||
@ -24,7 +25,6 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springdoc.core.models.GroupedOpenApi;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Collection;
|
||||
@ -44,11 +44,18 @@ public class LocationRecordController {
|
||||
return SwaggerConfig.api("Location Record", "/location/record");
|
||||
}
|
||||
|
||||
@PostJson("/post")
|
||||
@Operation(summary = "上报定位记录")
|
||||
public JsonResponse<Void> postLocationRecord(@Claim Claims claims, @RequestBody LocationRecordDto dto) throws Exception {
|
||||
locationRecordService.postLocationRecord(dto,claims);
|
||||
return JsonResponse.success(null);
|
||||
}
|
||||
|
||||
|
||||
@PostJson("/list")
|
||||
@Operation(summary = "查询记录")
|
||||
public JsonResponse<Collection<LocationRecordVo>> getLocationRecord(@Claim Claims claims, @RequestBody LocationRecordParams params){
|
||||
log.info("claims {}", claims);
|
||||
ServiceResult<Collection<LocationRecord>> result = locationRecordService.getLocationRecord(params, claims.getUserId());
|
||||
ServiceResult<Collection<LocationRecord>> result = locationRecordService.getLocationRecord(params, claims);
|
||||
return JsonResponse.success(LocationRecordConvertor.INSTANCE.daoToVo(result.getResult()));
|
||||
}
|
||||
|
||||
@ -56,7 +63,7 @@ public class LocationRecordController {
|
||||
@Operation(summary = "分页查询记录")
|
||||
public JsonResponse<PageWrapper<LocationRecordVo>> getPageLocationRecord(@Claim Claims claims, @RequestBody PageLocationRecordParams params){
|
||||
PageInfo<LocationRecordVo> pageInfo =
|
||||
LocationRecordConvertor.INSTANCE.daoToVo(locationRecordService.getPageLocationRecord(params, claims.getUserId()).getResult());
|
||||
LocationRecordConvertor.INSTANCE.daoToVo(locationRecordService.getPageLocationRecord(params, claims).getResult());
|
||||
|
||||
return JsonResponse.success(PageWrapper.of(pageInfo));
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.skcks.matrix.v2.model.location.record.convert;
|
||||
|
||||
import cn.skcks.matrix.v2.model.location.record.dto.LocationRecordDto;
|
||||
import cn.skcks.matrix.v2.model.location.record.vo.LocationRecordVo;
|
||||
import cn.skcks.matrix.v2.orm.mybatis.dynamic.model.LocationRecord;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
@ -23,4 +24,6 @@ public abstract class LocationRecordConvertor {
|
||||
abstract public Collection<LocationRecordVo> daoToVo(Collection<LocationRecord> dao);
|
||||
|
||||
abstract public PageInfo<LocationRecordVo> daoToVo(PageInfo<LocationRecord> daoPageInfo);
|
||||
|
||||
abstract public LocationRecord dtoToDao(LocationRecordDto dto);
|
||||
}
|
||||
|
@ -0,0 +1,72 @@
|
||||
package cn.skcks.matrix.v2.model.location.record.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class LocationRecordDto {
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
@Schema(description = "回调时间", example = "2023-05-08 00:00:00")
|
||||
private Date callbackTime;
|
||||
|
||||
@Schema(description = "定位时间", example = "2023-05-08 00:00:00")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date locationTime;
|
||||
|
||||
@Schema(description = "定位类型")
|
||||
private Integer locationType;
|
||||
|
||||
@Schema(description = "(高德) 纬度")
|
||||
private Double latitude;
|
||||
|
||||
@Schema(description = "(高德) 经度")
|
||||
private Double longitude;
|
||||
|
||||
@Schema(description = "精度")
|
||||
private Double accuracy;
|
||||
|
||||
@Schema(description = "高度(m)")
|
||||
private Double altitude;
|
||||
|
||||
@Schema(description = "方向角(°)")
|
||||
private Double bearing;
|
||||
|
||||
@Schema(description = "速度(m/s)")
|
||||
private Double speed;
|
||||
|
||||
@Schema(description = "国家")
|
||||
private String country;
|
||||
|
||||
@Schema(description = "省份")
|
||||
private String province;
|
||||
|
||||
@Schema(description = "城市")
|
||||
private String city;
|
||||
|
||||
@Schema(description = "区")
|
||||
private String district;
|
||||
|
||||
@Schema(description = "街道")
|
||||
private String street;
|
||||
|
||||
@Schema(description = "街道号码")
|
||||
private String streetNumber;
|
||||
|
||||
@Schema(description = "城市代号")
|
||||
private String cityCode;
|
||||
|
||||
@Schema(description = "区域编码")
|
||||
private String adCode;
|
||||
|
||||
@Schema(description = "详细地址(大概)")
|
||||
private String address;
|
||||
|
||||
@Schema(description = "描述")
|
||||
private String description;
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package cn.skcks.matrix.v2.services.location.record;
|
||||
|
||||
import cn.skcks.matrix.v2.model.jwt.dto.Claims;
|
||||
import cn.skcks.matrix.v2.model.location.record.dto.LocationRecordDto;
|
||||
import cn.skcks.matrix.v2.model.location.record.dto.LocationRecordParams;
|
||||
import cn.skcks.matrix.v2.model.location.record.dto.PageLocationRecordParams;
|
||||
import cn.skcks.matrix.v2.model.services.ServiceResult;
|
||||
@ -9,7 +11,9 @@ import com.github.pagehelper.PageInfo;
|
||||
import java.util.Collection;
|
||||
|
||||
public interface LocationRecordService {
|
||||
ServiceResult<Collection<LocationRecord>> getLocationRecord(LocationRecordParams params, String userId);
|
||||
ServiceResult<Collection<LocationRecord>> getLocationRecord(LocationRecordParams params, Claims claims);
|
||||
|
||||
ServiceResult<PageInfo<LocationRecord>> getPageLocationRecord(PageLocationRecordParams params, String userId);
|
||||
ServiceResult<PageInfo<LocationRecord>> getPageLocationRecord(PageLocationRecordParams params, Claims claims);
|
||||
|
||||
ServiceResult<Void> postLocationRecord(LocationRecordDto locationRecordDto, Claims claims) throws Exception;
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
package cn.skcks.matrix.v2.services.location.record;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.skcks.matrix.v2.model.jwt.dto.Claims;
|
||||
import cn.skcks.matrix.v2.model.location.record.convert.LocationRecordConvertor;
|
||||
import cn.skcks.matrix.v2.model.location.record.dto.LocationRecordDto;
|
||||
import cn.skcks.matrix.v2.model.location.record.dto.LocationRecordParams;
|
||||
import cn.skcks.matrix.v2.model.location.record.dto.PageLocationRecordParams;
|
||||
import cn.skcks.matrix.v2.model.location.record.vo.LocationRecordVo;
|
||||
@ -14,6 +17,7 @@ import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.mybatis.dynamic.sql.SqlBuilder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -25,8 +29,30 @@ import java.util.List;
|
||||
@RequiredArgsConstructor
|
||||
public class LocationRecordServiceImpl implements LocationRecordService{
|
||||
private final LocationRecordMapper locationRecordMapper;
|
||||
|
||||
private RuntimeException checkClaims(Claims claims){
|
||||
if(claims == null){
|
||||
return new RuntimeException("无效的身份令牌");
|
||||
}
|
||||
|
||||
String userId = claims.getUserId();
|
||||
if (StringUtils.isEmpty(userId)) {
|
||||
return new RuntimeException("无效的用户Id");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServiceResult<Collection<LocationRecord>> getLocationRecord(LocationRecordParams params, String userId) {
|
||||
public ServiceResult<Collection<LocationRecord>> getLocationRecord(LocationRecordParams params, Claims claims) {
|
||||
ServiceResult.ServiceResultBuilder<Collection<LocationRecord>> result = ServiceResult.builder();
|
||||
Exception exception = checkClaims(claims);
|
||||
if (exception != null){
|
||||
return result.exception(exception.getMessage()).build();
|
||||
}
|
||||
|
||||
String userId = claims.getUserId();
|
||||
|
||||
List<LocationRecord> recordList = locationRecordMapper.select((s)-> s.applyWhere(dsl -> {
|
||||
if (params.getStartTime() != null) {
|
||||
dsl.and(LocationRecordDynamicSqlSupport.locationTime, SqlBuilder.isGreaterThanOrEqualTo(params.getStartTime()));
|
||||
@ -38,19 +64,17 @@ public class LocationRecordServiceImpl implements LocationRecordService{
|
||||
|
||||
dsl.and(LocationRecordDynamicSqlSupport.userId, SqlBuilder.isEqualTo(Long.valueOf(userId)));
|
||||
dsl.and(LocationRecordDynamicSqlSupport.id, SqlBuilder.isNotNull());
|
||||
}).orderBy((LocationRecordDynamicSqlSupport.id)));
|
||||
}).orderBy(LocationRecordDynamicSqlSupport.locationTime, LocationRecordDynamicSqlSupport.id));
|
||||
|
||||
return ServiceResult.<Collection<LocationRecord>>builder()
|
||||
.result(recordList)
|
||||
.build();
|
||||
return result.result(recordList).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServiceResult<PageInfo<LocationRecord>> getPageLocationRecord(PageLocationRecordParams params, String userId) {
|
||||
public ServiceResult<PageInfo<LocationRecord>> getPageLocationRecord(PageLocationRecordParams params, Claims claims) {
|
||||
PageInfo<LocationRecord> pageInfo;
|
||||
try(Page<LocationRecord> page = PageHelper.startPage(params.getPage(),params.getSize())){
|
||||
pageInfo = page.doSelectPageInfo(()->{
|
||||
getLocationRecord(params, userId);
|
||||
getLocationRecord(params, claims);
|
||||
});
|
||||
}
|
||||
|
||||
@ -58,4 +82,19 @@ public class LocationRecordServiceImpl implements LocationRecordService{
|
||||
.result(pageInfo)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServiceResult<Void> postLocationRecord(LocationRecordDto locationRecordDto, Claims claims) throws Exception {
|
||||
Exception exception = checkClaims(claims);
|
||||
if(exception != null){
|
||||
throw exception;
|
||||
}
|
||||
|
||||
LocationRecord dao = LocationRecordConvertor.INSTANCE.dtoToDao(locationRecordDto);
|
||||
dao.setId(IdUtil.getSnowflakeNextIdStr());
|
||||
dao.setUserId(Long.valueOf(claims.getUserId()));
|
||||
|
||||
locationRecordMapper.insert(dao);
|
||||
return ServiceResult.<Void>builder().build();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user