|
|
@@ -0,0 +1,256 @@
|
|
|
+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.jutil.jdk.serializer.JsonConverter;
|
|
|
+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.content.app.geo.db.mapper.*;
|
|
|
+import cn.reghao.tnb.content.app.geo.model.po.CameraPhoto;
|
|
|
+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.MallReplyPhoto;
|
|
|
+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 com.google.gson.JsonObject;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.regex.Pattern;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author reghao
|
|
|
+ * @date 2023-08-31 17:49:48
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class MapService {
|
|
|
+ @DubboReference(check = false, retries = 0)
|
|
|
+ private OssService ossService;
|
|
|
+
|
|
|
+ private final MallReplyMapper mallReplyMapper;
|
|
|
+ private final MallReplyPhotoMapper mallReplyPhotoMapper;
|
|
|
+ private final GeoScopeMapper geoScopeMapper;
|
|
|
+ private final GeoItemMapper geoItemMapper;
|
|
|
+ private final GeoPointMapper geoPointMapper;
|
|
|
+ private final CameraPhotoMapper cameraPhotoMapper;
|
|
|
+ private JobLocationService jobLocationService;
|
|
|
+
|
|
|
+ public MapService(MallReplyMapper mallReplyMapper, MallReplyPhotoMapper mallReplyPhotoMapper,
|
|
|
+ GeoScopeMapper geoScopeMapper, GeoItemMapper geoItemMapper,
|
|
|
+ GeoPointMapper geoPointMapper, CameraPhotoMapper cameraPhotoMapper,
|
|
|
+ JobLocationService jobLocationService) {
|
|
|
+ this.mallReplyMapper = mallReplyMapper;
|
|
|
+ this.mallReplyPhotoMapper = mallReplyPhotoMapper;
|
|
|
+ this.geoScopeMapper = geoScopeMapper;
|
|
|
+ this.geoItemMapper = geoItemMapper;
|
|
|
+ this.geoPointMapper = geoPointMapper;
|
|
|
+ this.cameraPhotoMapper = cameraPhotoMapper;
|
|
|
+ this.jobLocationService = jobLocationService;
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean checkReplyId(String replyId) {
|
|
|
+ MallReply mallReply = mallReplyMapper.findByReplyId(replyId);
|
|
|
+ return mallReply != null;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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<MallReplyPhoto> list = mallReplyDto.getPhotos().stream()
|
|
|
+ .map(mallReplyPhotoDto -> {
|
|
|
+ MallReplyPhoto mallReplyPhoto = new MallReplyPhoto(mallReplyPhotoDto);
|
|
|
+ try {
|
|
|
+ String shotAtStr = mallReplyPhotoDto.getShotAt();
|
|
|
+ if (shotAtStr != null) {
|
|
|
+ LocalDateTime shotAt = DateTimeConverter.localDateTime2(mallReplyPhotoDto.getShotAt());
|
|
|
+ mallReplyPhoto.setShotAt(shotAt);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ return mallReplyPhoto;
|
|
|
+ })
|
|
|
+ .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 saveTmallReply(MallReply mallReply, List<MallReplyPhoto> list) {
|
|
|
+ mallReplyMapper.save(mallReply);
|
|
|
+ mallReplyPhotoMapper.saveAll(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<MapMarker> getMapMarkers(int itemType) {
|
|
|
+ int pageSize = 1000;
|
|
|
+ if (itemType == 1) {
|
|
|
+ List<MapMarker> list = mallReplyPhotoMapper.findAllByReplyIdGroup(pageSize);
|
|
|
+ //List<MapMarker> list = mallReplyPhotoMapper.findAllByGeoScope(pageSize, geoScope.getId());
|
|
|
+ return list;
|
|
|
+ } else if (itemType == 2) {
|
|
|
+ List<MapMarker> list = mallReplyPhotoMapper.findByWestChina(pageSize, itemType);
|
|
|
+ //List<MapMarker> list = mallReplyPhotoMapper.findByGeoScope(pageSize, itemType, geoScope1);
|
|
|
+ setMarkTitle(list);
|
|
|
+ return list;
|
|
|
+ } else if (itemType == 3) {
|
|
|
+ List<MapMarker> list = mallReplyPhotoMapper.findByReplyIdGroup(pageSize, itemType);
|
|
|
+ return list;
|
|
|
+ } else if (itemType == 4) {
|
|
|
+ List<MapMarker> list = mallReplyPhotoMapper.findByReplyIdGroup(pageSize, itemType);
|
|
|
+ return list;
|
|
|
+ } else if (itemType == 5) {
|
|
|
+ List<MapMarker> list = cameraPhotoMapper.findByWestGeoGroup(pageSize);
|
|
|
+ return list;
|
|
|
+ } else if (itemType == 6) {
|
|
|
+ List<MapMarker> list = cameraPhotoMapper.findByAlbumId(pageSize, 0);
|
|
|
+ list.forEach(mapMarker -> {
|
|
|
+ String objectId = mapMarker.getId();
|
|
|
+ });
|
|
|
+ return list;
|
|
|
+ } else if (itemType == 7) {
|
|
|
+ List<MapMarker> list = jobLocationService.getMapMarks();
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setMarkTitle(List<MapMarker> list) {
|
|
|
+ list.forEach(mapMarker -> {
|
|
|
+ String title = mapMarker.getTitle();
|
|
|
+ if (title == null) {
|
|
|
+ mapMarker.setTitle("标记");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ mapMarker.setTitle(getFormattedTitle1(title));
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getFormattedTitle1(String title) {
|
|
|
+ String extra1 = null;
|
|
|
+ if (title.startsWith("{")) {
|
|
|
+ JsonObject jsonObject = JsonConverter.jsonToJsonElement(title).getAsJsonObject();
|
|
|
+ extra1 = jsonObject.get("尺码").getAsString();
|
|
|
+ } else {
|
|
|
+ extra1 = title.split("尺码:")[1];
|
|
|
+ String[] arr = title.split("  ");
|
|
|
+ for (String str : arr) {
|
|
|
+ if (str.startsWith("尺码")) {
|
|
|
+ extra1 = str.split(":")[1];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return extra1;
|
|
|
+ }
|
|
|
+
|
|
|
+ public MarkerInfo getMarkerInfo(String id) {
|
|
|
+ MarkerInfo markerInfo;
|
|
|
+ if (isInteger(id)) {
|
|
|
+ markerInfo = mallReplyPhotoMapper.findMarkerInfoById(Integer.parseInt(id));
|
|
|
+ } else {
|
|
|
+ markerInfo = cameraPhotoMapper.findMarkerInfoById(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;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean isInteger(String str) {
|
|
|
+ Pattern pattern = Pattern.compile("^[-+]?[\\d]*$");
|
|
|
+ return pattern.matcher(str).matches();
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 MarkerInfo getMarkerInfo(int id) {
|
|
|
+ MarkerInfo markerInfo = mallReplyPhotoMapper.findMarkerInfoById(id);
|
|
|
+ int channelId = markerInfo.getChannelId();
|
|
|
+ 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 void addGeoPoint(MapPoint mapPoint) {
|
|
|
+ GeoPoint geoPoint = new GeoPoint(mapPoint);
|
|
|
+ geoPointMapper.save(geoPoint);
|
|
|
+ }
|
|
|
+
|
|
|
+ public List getGeoPoints() {
|
|
|
+ List<GeoPoint> list = geoPointMapper.findAll();
|
|
|
+ List<List<Double>> list1 = list.stream().map(geoPoint -> {
|
|
|
+ Double lng = geoPoint.getLongitude().doubleValue();
|
|
|
+ Double lat = geoPoint.getLatitude().doubleValue();
|
|
|
+ return List.of(lng, lat);
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ Map<String, List<List<Double>>> map = new HashMap<>();
|
|
|
+ map.put("path", list1);
|
|
|
+ return List.of(map);
|
|
|
+ }
|
|
|
+}
|