定位信息上报

This commit is contained in:
Shikong 2023-05-09 20:54:07 +08:00
parent f125c1d114
commit 5e530d4f5f
6 changed files with 140 additions and 15 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="CodeStream"> <component name="CodeStream">
<option name="webViewContext" value="{&quot;chatProviderAccess&quot;:&quot;strict&quot;,&quot;currentTeamId&quot;:&quot;&quot;,&quot;currentStreamId&quot;:&quot;&quot;,&quot;pullRequestCheckoutBranch&quot;:false,&quot;isRepositioning&quot;:false,&quot;onboardStep&quot;:0,&quot;panelStack&quot;:[&quot;landing-redirect&quot;],&quot;hasFocus&quot;:false,&quot;channelFilter&quot;:&quot;all&quot;,&quot;channelsMuteAll&quot;:false,&quot;codemarkFileFilter&quot;:&quot;all&quot;,&quot;codemarkTypeFilter&quot;:&quot;all&quot;,&quot;codemarkTagFilter&quot;:&quot;all&quot;,&quot;codemarkBranchFilter&quot;:&quot;all&quot;,&quot;codemarkAuthorFilter&quot;:&quot;all&quot;,&quot;codemarksFileViewStyle&quot;:&quot;inline&quot;,&quot;codemarksShowArchived&quot;:false,&quot;codemarksShowResolved&quot;:false,&quot;codemarksWrapComments&quot;:false,&quot;showFeedbackSmiley&quot;:true,&quot;route&quot;:{&quot;name&quot;:&quot;newUserEntry&quot;,&quot;params&quot;:{}},&quot;spatialViewShowPRComments&quot;:false,&quot;currentPullRequestNeedsRefresh&quot;:{&quot;needsRefresh&quot;:false,&quot;providerId&quot;:&quot;&quot;,&quot;pullRequestId&quot;:&quot;&quot;},&quot;__teamless__&quot;:{&quot;selectedRegion&quot;:&quot;us&quot;},&quot;sessionStart&quot;:1681277419701}" /> <option name="webViewContext" value="{&quot;chatProviderAccess&quot;:&quot;strict&quot;,&quot;currentTeamId&quot;:&quot;&quot;,&quot;currentStreamId&quot;:&quot;&quot;,&quot;pullRequestCheckoutBranch&quot;:false,&quot;isRepositioning&quot;:false,&quot;onboardStep&quot;:0,&quot;panelStack&quot;:[&quot;landing-redirect&quot;],&quot;hasFocus&quot;:false,&quot;channelFilter&quot;:&quot;all&quot;,&quot;channelsMuteAll&quot;:false,&quot;codemarkFileFilter&quot;:&quot;all&quot;,&quot;codemarkTypeFilter&quot;:&quot;all&quot;,&quot;codemarkTagFilter&quot;:&quot;all&quot;,&quot;codemarkBranchFilter&quot;:&quot;all&quot;,&quot;codemarkAuthorFilter&quot;:&quot;all&quot;,&quot;codemarksFileViewStyle&quot;:&quot;inline&quot;,&quot;codemarksShowArchived&quot;:false,&quot;codemarksShowResolved&quot;:false,&quot;codemarksWrapComments&quot;:false,&quot;showFeedbackSmiley&quot;:true,&quot;route&quot;:{&quot;name&quot;:&quot;newUserEntry&quot;,&quot;params&quot;:{}},&quot;spatialViewShowPRComments&quot;:false,&quot;currentPullRequestNeedsRefresh&quot;:{&quot;needsRefresh&quot;:false,&quot;providerId&quot;:&quot;&quot;,&quot;pullRequestId&quot;:&quot;&quot;},&quot;__teamless__&quot;:{&quot;selectedRegion&quot;:&quot;us&quot;},&quot;sessionStart&quot;:1683633459106}" />
</component> </component>
</project> </project>

View File

@ -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.JsonMapping;
import cn.skcks.matrix.v2.annotation.web.auth.Auth; 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.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.config.swagger.SwaggerConfig;
import cn.skcks.matrix.v2.model.jwt.dto.Claims; 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.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.LocationRecordParams;
import cn.skcks.matrix.v2.model.location.record.dto.PageLocationRecordParams; import cn.skcks.matrix.v2.model.location.record.dto.PageLocationRecordParams;
import cn.skcks.matrix.v2.model.location.record.vo.LocationRecordVo; 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.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.Collection; import java.util.Collection;
@ -44,11 +44,18 @@ public class LocationRecordController {
return SwaggerConfig.api("Location Record", "/location/record"); 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") @PostJson("/list")
@Operation(summary = "查询记录") @Operation(summary = "查询记录")
public JsonResponse<Collection<LocationRecordVo>> getLocationRecord(@Claim Claims claims, @RequestBody LocationRecordParams params){ public JsonResponse<Collection<LocationRecordVo>> getLocationRecord(@Claim Claims claims, @RequestBody LocationRecordParams params){
log.info("claims {}", claims); ServiceResult<Collection<LocationRecord>> result = locationRecordService.getLocationRecord(params, claims);
ServiceResult<Collection<LocationRecord>> result = locationRecordService.getLocationRecord(params, claims.getUserId());
return JsonResponse.success(LocationRecordConvertor.INSTANCE.daoToVo(result.getResult())); return JsonResponse.success(LocationRecordConvertor.INSTANCE.daoToVo(result.getResult()));
} }
@ -56,7 +63,7 @@ public class LocationRecordController {
@Operation(summary = "分页查询记录") @Operation(summary = "分页查询记录")
public JsonResponse<PageWrapper<LocationRecordVo>> getPageLocationRecord(@Claim Claims claims, @RequestBody PageLocationRecordParams params){ public JsonResponse<PageWrapper<LocationRecordVo>> getPageLocationRecord(@Claim Claims claims, @RequestBody PageLocationRecordParams params){
PageInfo<LocationRecordVo> pageInfo = 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)); return JsonResponse.success(PageWrapper.of(pageInfo));
} }

View File

@ -1,5 +1,6 @@
package cn.skcks.matrix.v2.model.location.record.convert; 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.model.location.record.vo.LocationRecordVo;
import cn.skcks.matrix.v2.orm.mybatis.dynamic.model.LocationRecord; import cn.skcks.matrix.v2.orm.mybatis.dynamic.model.LocationRecord;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
@ -23,4 +24,6 @@ public abstract class LocationRecordConvertor {
abstract public Collection<LocationRecordVo> daoToVo(Collection<LocationRecord> dao); abstract public Collection<LocationRecordVo> daoToVo(Collection<LocationRecord> dao);
abstract public PageInfo<LocationRecordVo> daoToVo(PageInfo<LocationRecord> daoPageInfo); abstract public PageInfo<LocationRecordVo> daoToVo(PageInfo<LocationRecord> daoPageInfo);
abstract public LocationRecord dtoToDao(LocationRecordDto dto);
} }

View File

@ -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;
}

View File

@ -1,5 +1,7 @@
package cn.skcks.matrix.v2.services.location.record; 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.LocationRecordParams;
import cn.skcks.matrix.v2.model.location.record.dto.PageLocationRecordParams; import cn.skcks.matrix.v2.model.location.record.dto.PageLocationRecordParams;
import cn.skcks.matrix.v2.model.services.ServiceResult; import cn.skcks.matrix.v2.model.services.ServiceResult;
@ -9,7 +11,9 @@ import com.github.pagehelper.PageInfo;
import java.util.Collection; import java.util.Collection;
public interface LocationRecordService { 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;
} }

View File

@ -1,6 +1,9 @@
package cn.skcks.matrix.v2.services.location.record; 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.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.LocationRecordParams;
import cn.skcks.matrix.v2.model.location.record.dto.PageLocationRecordParams; import cn.skcks.matrix.v2.model.location.record.dto.PageLocationRecordParams;
import cn.skcks.matrix.v2.model.location.record.vo.LocationRecordVo; 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.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.mybatis.dynamic.sql.SqlBuilder; import org.mybatis.dynamic.sql.SqlBuilder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -25,8 +29,30 @@ import java.util.List;
@RequiredArgsConstructor @RequiredArgsConstructor
public class LocationRecordServiceImpl implements LocationRecordService{ public class LocationRecordServiceImpl implements LocationRecordService{
private final LocationRecordMapper locationRecordMapper; 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 @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 -> { List<LocationRecord> recordList = locationRecordMapper.select((s)-> s.applyWhere(dsl -> {
if (params.getStartTime() != null) { if (params.getStartTime() != null) {
dsl.and(LocationRecordDynamicSqlSupport.locationTime, SqlBuilder.isGreaterThanOrEqualTo(params.getStartTime())); 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.userId, SqlBuilder.isEqualTo(Long.valueOf(userId)));
dsl.and(LocationRecordDynamicSqlSupport.id, SqlBuilder.isNotNull()); dsl.and(LocationRecordDynamicSqlSupport.id, SqlBuilder.isNotNull());
}).orderBy((LocationRecordDynamicSqlSupport.id))); }).orderBy(LocationRecordDynamicSqlSupport.locationTime, LocationRecordDynamicSqlSupport.id));
return ServiceResult.<Collection<LocationRecord>>builder() return result.result(recordList).build();
.result(recordList)
.build();
} }
@Override @Override
public ServiceResult<PageInfo<LocationRecord>> getPageLocationRecord(PageLocationRecordParams params, String userId) { public ServiceResult<PageInfo<LocationRecord>> getPageLocationRecord(PageLocationRecordParams params, Claims claims) {
PageInfo<LocationRecord> pageInfo; PageInfo<LocationRecord> pageInfo;
try(Page<LocationRecord> page = PageHelper.startPage(params.getPage(),params.getSize())){ try(Page<LocationRecord> page = PageHelper.startPage(params.getPage(),params.getSize())){
pageInfo = page.doSelectPageInfo(()->{ pageInfo = page.doSelectPageInfo(()->{
getLocationRecord(params, userId); getLocationRecord(params, claims);
}); });
} }
@ -58,4 +82,19 @@ public class LocationRecordServiceImpl implements LocationRecordService{
.result(pageInfo) .result(pageInfo)
.build(); .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();
}
} }