|
|
@@ -1,24 +1,20 @@
|
|
|
package cn.reghao.tnb.content.app.geo.service;
|
|
|
|
|
|
-import cn.reghao.file.api.iface.OssService;
|
|
|
import cn.reghao.jutil.jdk.converter.DateTimeConverter;
|
|
|
-import cn.reghao.tnb.common.db.SelectOption;
|
|
|
-import cn.reghao.tnb.content.api.dto.geo.MallReplyDto;
|
|
|
-import cn.reghao.tnb.content.api.dto.geo.MallReplyPhotoDto;
|
|
|
+import cn.reghao.tnb.common.auth.UserContext;
|
|
|
import cn.reghao.tnb.content.app.geo.db.mapper.*;
|
|
|
-import cn.reghao.tnb.content.app.geo.model.po.CameraPhoto;
|
|
|
+import cn.reghao.tnb.content.app.geo.model.po.BusStation;
|
|
|
+import cn.reghao.tnb.content.app.geo.model.po.GeoChina;
|
|
|
import cn.reghao.tnb.content.app.geo.model.po.GeoPoint;
|
|
|
-import cn.reghao.tnb.content.app.geo.model.po.MallReply;
|
|
|
+import cn.reghao.tnb.content.app.geo.model.po.GeoPolygon;
|
|
|
+import cn.reghao.tnb.content.app.geo.model.vo.GeoMarker;
|
|
|
import cn.reghao.tnb.content.app.geo.model.vo.MapMarker;
|
|
|
import cn.reghao.tnb.content.app.geo.model.vo.MapPoint;
|
|
|
-import cn.reghao.tnb.content.app.geo.model.vo.MarkerInfo;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
|
|
|
-import java.time.LocalDateTime;
|
|
|
-import java.util.Collections;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
@@ -31,154 +27,81 @@ import java.util.stream.Collectors;
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
public class MapService {
|
|
|
- @DubboReference(check = false, retries = 0)
|
|
|
- private OssService ossService;
|
|
|
-
|
|
|
- private final MallReplyMapper mallReplyMapper;
|
|
|
- private final GeoItemMapper geoItemMapper;
|
|
|
+ private final GeoChinaMapper geoChinaMapper;
|
|
|
+ private final GeoPolygonMapper geoPolygonMapper;
|
|
|
private final GeoPointMapper geoPointMapper;
|
|
|
- private final CameraPhotoMapper cameraPhotoMapper;
|
|
|
+ private final BusStationMapper busStationMapper;
|
|
|
|
|
|
- public MapService(MallReplyMapper mallReplyMapper, GeoItemMapper geoItemMapper,
|
|
|
- GeoPointMapper geoPointMapper, CameraPhotoMapper cameraPhotoMapper) {
|
|
|
- this.mallReplyMapper = mallReplyMapper;
|
|
|
- this.geoItemMapper = geoItemMapper;
|
|
|
+ public MapService(GeoChinaMapper geoChinaMapper, GeoPolygonMapper geoPolygonMapper,
|
|
|
+ GeoPointMapper geoPointMapper, BusStationMapper busStationMapper) {
|
|
|
+ this.geoChinaMapper = geoChinaMapper;
|
|
|
+ this.geoPolygonMapper = geoPolygonMapper;
|
|
|
this.geoPointMapper = geoPointMapper;
|
|
|
- this.cameraPhotoMapper = cameraPhotoMapper;
|
|
|
- }
|
|
|
-
|
|
|
- public boolean checkReplyId(String replyId) {
|
|
|
- MallReply mallReply = mallReplyMapper.findByReplyId(replyId);
|
|
|
- return mallReply != null;
|
|
|
+ this.busStationMapper = busStationMapper;
|
|
|
}
|
|
|
|
|
|
- public synchronized void addTmallReply(MallReplyDto mallReplyDto) {
|
|
|
- String replyId = mallReplyDto.getReplyId();
|
|
|
- MallReply mallReply = mallReplyMapper.findByReplyId(replyId);
|
|
|
- if (mallReply != null) {
|
|
|
- log.info("{} 已存在", replyId);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- mallReply = new MallReply(mallReplyDto);
|
|
|
- List<CameraPhoto> list = mallReplyDto.getPhotos().stream()
|
|
|
- .map(mallReplyPhotoDto -> {
|
|
|
- CameraPhoto cameraPhoto = new CameraPhoto(mallReplyPhotoDto);
|
|
|
- try {
|
|
|
- String shotAtStr = mallReplyPhotoDto.getShotAt();
|
|
|
- if (shotAtStr != null) {
|
|
|
- LocalDateTime shotAt = DateTimeConverter.localDateTime2(mallReplyPhotoDto.getShotAt());
|
|
|
- cameraPhoto.setShotAt(shotAt);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- return cameraPhoto;
|
|
|
- })
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
- if (!list.isEmpty()) {
|
|
|
- saveTmallReply(mallReply, list);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void addCameraPhotos(List<MallReplyPhotoDto> list) {
|
|
|
- List<CameraPhoto> locations = list.stream().map(mallReplyPhotoDto -> {
|
|
|
- CameraPhoto cameraPhoto = new CameraPhoto(mallReplyPhotoDto);
|
|
|
- try {
|
|
|
- String shotAtStr = mallReplyPhotoDto.getShotAt();
|
|
|
- if (shotAtStr != null) {
|
|
|
- LocalDateTime shotAt = DateTimeConverter.localDateTime2(mallReplyPhotoDto.getShotAt());
|
|
|
- cameraPhoto.setShotAt(shotAt);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- return cameraPhoto;
|
|
|
- }).collect(Collectors.toList());
|
|
|
-
|
|
|
- if (!locations.isEmpty()) {
|
|
|
- cameraPhotoMapper.saveAll(locations);
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void add(GeoChina geoChina, GeoPolygon geoPolygon) {
|
|
|
+ try {
|
|
|
+ //geoChinaMapper.save(geoChina);
|
|
|
+ geoPolygonMapper.save(geoPolygon);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("insert {} -> {} error", geoChina.getId(), geoChina.getExtName());
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public void saveTmallReply(MallReply mallReply, List<CameraPhoto> list) {
|
|
|
- mallReplyMapper.save(mallReply);
|
|
|
- cameraPhotoMapper.saveAll(list);
|
|
|
+ public void addGeoPoint(MapPoint mapPoint) {
|
|
|
+ GeoPoint geoPoint = new GeoPoint(mapPoint);
|
|
|
+ geoPointMapper.save(geoPoint);
|
|
|
}
|
|
|
|
|
|
- public List<MapMarker> getMapMarkers(int itemType) {
|
|
|
- int pageSize = 1000;
|
|
|
- if (itemType == 1) {
|
|
|
- List<MapMarker> list = cameraPhotoMapper.findAllByReplyIdGroup(pageSize);
|
|
|
- return list;
|
|
|
- } else if (itemType == 2) {
|
|
|
- List<MapMarker> list = cameraPhotoMapper.findByWestChina(pageSize, itemType);
|
|
|
- return list;
|
|
|
- } else if (itemType == 3) {
|
|
|
- List<MapMarker> list = cameraPhotoMapper.findByWestGeoGroup(pageSize, itemType);
|
|
|
- return list;
|
|
|
- } else if (itemType == 4) {
|
|
|
- List<MapMarker> list = cameraPhotoMapper.findByWestGeoGroup(pageSize, itemType);
|
|
|
- list.forEach(mapMarker -> {
|
|
|
- String objectId = mapMarker.getId();
|
|
|
- });
|
|
|
- return list;
|
|
|
- }
|
|
|
-
|
|
|
- return Collections.emptyList();
|
|
|
+ public List<MapMarker> getCityMarks() {
|
|
|
+ int deep = 2;
|
|
|
+ List<GeoMarker> list = geoChinaMapper.findByDeep(deep);
|
|
|
+ return list.stream().map(geoMarker -> {
|
|
|
+ String id = String.valueOf(geoMarker.getId());
|
|
|
+ String name = geoMarker.getName();
|
|
|
+ double lng = geoMarker.getLng();
|
|
|
+ double lat = geoMarker.getLat();
|
|
|
+ MapPoint mapPoint = new MapPoint(lng, lat);
|
|
|
+ return new MapMarker(id, name, mapPoint);
|
|
|
+ }).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
- public MarkerInfo getMarkerInfo(int id) {
|
|
|
- CameraPhoto cameraPhoto = cameraPhotoMapper.findById(id);
|
|
|
- if (cameraPhoto == null) {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- int type = cameraPhoto.getType();
|
|
|
- MarkerInfo markerInfo;
|
|
|
- if (type == 1) {
|
|
|
- markerInfo = cameraPhotoMapper.findMarkerInfo(id);
|
|
|
- } else if (type == 2) {
|
|
|
- markerInfo = cameraPhotoMapper.findMarkerInfoById(id);
|
|
|
- } else {
|
|
|
- markerInfo = cameraPhotoMapper.findMarkerInfo(id);
|
|
|
- }
|
|
|
-
|
|
|
- int channelId = markerInfo.getChannelId();
|
|
|
- if (channelId != 0) {
|
|
|
- String uploadId = markerInfo.getUploadId();
|
|
|
- try {
|
|
|
- String signedUrl = ossService.getSignedUrl(channelId, uploadId);
|
|
|
- if (signedUrl != null) {
|
|
|
- markerInfo.setPhotoUrl(signedUrl);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return markerInfo;
|
|
|
- }
|
|
|
-
|
|
|
- public List<SelectOption> getGeoItems() {
|
|
|
- return geoItemMapper.findAll().stream()
|
|
|
- .map(geoItem -> {
|
|
|
- String name = geoItem.getName();
|
|
|
- int id = geoItem.getId();
|
|
|
- return new SelectOption(name, id);
|
|
|
- }).collect(Collectors.toList());
|
|
|
+ public List<MapMarker> getTrailMarks() {
|
|
|
+ long userId = UserContext.getUserId();
|
|
|
+ List<GeoPoint> list = geoPointMapper.findByUserId(userId);
|
|
|
+ return list.stream().map(geoPoint -> {
|
|
|
+ String id = String.valueOf(geoPoint.getId());
|
|
|
+ String dateStr = DateTimeConverter.format(geoPoint.getCreateAt());
|
|
|
+ double lng = geoPoint.getLongitude().doubleValue();
|
|
|
+ double lat = geoPoint.getLatitude().doubleValue();
|
|
|
+ MapPoint mapPoint = new MapPoint(lng, lat);
|
|
|
+ return new MapMarker(id, dateStr, mapPoint);
|
|
|
+ }).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
- public void addGeoPoint(MapPoint mapPoint) {
|
|
|
- GeoPoint geoPoint = new GeoPoint(mapPoint);
|
|
|
- geoPointMapper.save(geoPoint);
|
|
|
+ public List<MapMarker> getStationMarks() {
|
|
|
+ List<BusStation> list = busStationMapper.findAll();
|
|
|
+ return list.stream().map(busStation -> {
|
|
|
+ String id = busStation.getId()+"";
|
|
|
+ String stationName = busStation.getStationName();
|
|
|
+ String latStr = String.valueOf(busStation.getLat());
|
|
|
+ String latStr1 = String.format("%s.%s", latStr.substring(0, 2), latStr.substring(2));
|
|
|
+ double lat = Double.parseDouble(latStr1);
|
|
|
+
|
|
|
+ String lngStr = String.valueOf(busStation.getLng());
|
|
|
+ String lngStr1 = String.format("%s.%s", lngStr.substring(0, 3), lngStr.substring(3));
|
|
|
+ double lng = Double.parseDouble(lngStr1);
|
|
|
+ MapPoint mapPoint = new MapPoint(lng, lat);
|
|
|
+ return new MapMarker(id, stationName, mapPoint);
|
|
|
+ }).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
- public List getGeoPoints() {
|
|
|
- List<GeoPoint> list = geoPointMapper.findAll();
|
|
|
+ public List getTrailPath() {
|
|
|
+ long userId = UserContext.getUser();
|
|
|
+ List<GeoPoint> list = geoPointMapper.findByUserId(userId);
|
|
|
List<List<Double>> list1 = list.stream().map(geoPoint -> {
|
|
|
Double lng = geoPoint.getLongitude().doubleValue();
|
|
|
Double lat = geoPoint.getLatitude().doubleValue();
|