Browse Source

update content-service/geo

reghao 9 months ago
parent
commit
af5282c810
22 changed files with 262 additions and 208 deletions
  1. 1 12
      content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/controller/SubjectController.java
  2. 20 0
      content/content-service/src/main/java/cn/reghao/tnb/content/app/geo/controller/MapController.java
  3. 14 0
      content/content-service/src/main/java/cn/reghao/tnb/content/app/geo/controller/PhotoMapController.java
  4. 5 2
      content/content-service/src/main/java/cn/reghao/tnb/content/app/geo/db/mapper/CameraPhotoMapper.java
  5. 1 3
      content/content-service/src/main/java/cn/reghao/tnb/content/app/geo/db/mapper/GeoChinaMapper.java
  6. 4 1
      content/content-service/src/main/java/cn/reghao/tnb/content/app/geo/db/mapper/GeoPointMapper.java
  7. 0 5
      content/content-service/src/main/java/cn/reghao/tnb/content/app/geo/db/mapper/MallReplyMapper.java
  8. 16 1
      content/content-service/src/main/java/cn/reghao/tnb/content/app/geo/db/repository/MallReplyRepository.java
  9. 2 0
      content/content-service/src/main/java/cn/reghao/tnb/content/app/geo/model/po/CameraPhoto.java
  10. 11 0
      content/content-service/src/main/java/cn/reghao/tnb/content/app/geo/model/po/GeoPoint.java
  11. 0 2
      content/content-service/src/main/java/cn/reghao/tnb/content/app/geo/model/po/MallReply.java
  12. 4 0
      content/content-service/src/main/java/cn/reghao/tnb/content/app/geo/model/vo/GeoArea.java
  13. 0 17
      content/content-service/src/main/java/cn/reghao/tnb/content/app/geo/model/vo/GeoMarker.java
  14. 7 0
      content/content-service/src/main/java/cn/reghao/tnb/content/app/geo/model/vo/MapMarker.java
  15. 0 1
      content/content-service/src/main/java/cn/reghao/tnb/content/app/geo/model/vo/MapPoint.java
  16. 25 11
      content/content-service/src/main/java/cn/reghao/tnb/content/app/geo/service/MapService.java
  17. 29 1
      content/content-service/src/main/java/cn/reghao/tnb/content/app/geo/service/PhotoMapService.java
  18. 35 15
      content/content-service/src/main/resources/mapper/geo/CameraPhotoMapper.xml
  19. 3 19
      content/content-service/src/main/resources/mapper/geo/GeoChinaMapper.xml
  20. 12 7
      content/content-service/src/main/resources/mapper/geo/GeoPointMapper.xml
  21. 4 20
      content/content-service/src/main/resources/mapper/geo/MallReplyMapper.xml
  22. 69 91
      content/content-service/src/test/java/cn/reghao/tnb/content/app/geo/service/GeoTest.java

+ 1 - 12
content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/controller/SubjectController.java

@@ -3,10 +3,8 @@ package cn.reghao.tnb.content.app.exam.controller;
 import cn.reghao.jutil.jdk.db.PageList;
 import cn.reghao.jutil.web.WebResult;
 import cn.reghao.tnb.common.db.KeyValue;
-import cn.reghao.tnb.content.app.geo.model.vo.CascadeOption;
 import cn.reghao.tnb.content.app.exam.model.vo.SubjectInfo;
 import cn.reghao.tnb.content.app.exam.service.SubjectService;
-import cn.reghao.tnb.content.app.geo.service.MapService;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import io.swagger.v3.oas.annotations.Operation;
 import org.springframework.http.MediaType;
@@ -26,11 +24,9 @@ import java.util.List;
 @RequestMapping("/api/content/exam/subject")
 public class SubjectController {
     private final SubjectService subjectService;
-    private final MapService mapService;
 
-    public SubjectController(SubjectService subjectService, MapService mapService) {
+    public SubjectController(SubjectService subjectService) {
         this.subjectService = subjectService;
-        this.mapService = mapService;
     }
 
     @Operation(summary = "获取科目列表", description = "N")
@@ -49,11 +45,4 @@ public class SubjectController {
         List<KeyValue> list = subjectService.getKeyValues();
         return WebResult.success(list);
     }
-
-    @Operation(summary = "获取三级联动列表", description = "N")
-    @GetMapping(value = "/cascade", produces = MediaType.APPLICATION_JSON_VALUE)
-    public String getLabelValues() {
-        List<CascadeOption> list = mapService.getChinaCascade();
-        return WebResult.success(list);
-    }
 }

+ 20 - 0
content/content-service/src/main/java/cn/reghao/tnb/content/app/geo/controller/MapController.java

@@ -1,6 +1,8 @@
 package cn.reghao.tnb.content.app.geo.controller;
 
 import cn.reghao.jutil.web.WebResult;
+import cn.reghao.tnb.common.auth.AuthUser;
+import cn.reghao.tnb.content.app.geo.model.vo.CascadeOption;
 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.service.MapService;
@@ -29,6 +31,7 @@ public class MapController {
         this.photoMapService = photoMapService;
     }
 
+    @AuthUser
     @Operation(summary = "添加一个经纬度坐标", description = "N")
     @PostMapping(value = "/position", produces = MediaType.APPLICATION_JSON_VALUE)
     public String addGeoPoint(@RequestBody @Validated MapPoint mapPoint) {
@@ -36,6 +39,15 @@ public class MapController {
         return WebResult.success();
     }
 
+    @AuthUser
+    @Operation(summary = "设置我的位置", description = "N")
+    @PostMapping(value = "/my_position", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String addMyPoint(@RequestBody @Validated MapPoint mapPoint) {
+        mapService.setMyPosition(mapPoint);
+        return WebResult.success();
+    }
+
+    @AuthUser
     @Operation(summary = "获取坐标列表构成的路径", description = "N")
     @GetMapping(value = "/trail", produces = MediaType.APPLICATION_JSON_VALUE)
     public String getTrailPath() {
@@ -43,6 +55,7 @@ public class MapController {
         return WebResult.success(list);
     }
 
+    @AuthUser
     @Operation(summary = "获取地图标记", description = "N")
     @GetMapping(value = "/marks", produces = MediaType.APPLICATION_JSON_VALUE)
     public String getTrailMarks() {
@@ -57,4 +70,11 @@ public class MapController {
         List<MapMarker> list = photoMapService.getPhotoMarks(4);
         return WebResult.success(list);
     }
+
+    @Operation(summary = "省市县三级联动列表", description = "N")
+    @GetMapping(value = "/cascade", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String getCascadeOptions() {
+        List<CascadeOption> list = mapService.getChinaCascade();
+        return WebResult.success(list);
+    }
 }

+ 14 - 0
content/content-service/src/main/java/cn/reghao/tnb/content/app/geo/controller/PhotoMapController.java

@@ -50,6 +50,20 @@ public class PhotoMapController {
         return WebResult.success(list);
     }
 
+    @Operation(summary = "获取照片地图中标记", description = "N")
+    @GetMapping(value = "/marks_area", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String getPhotoMarksArea(@RequestParam("areaCode") int areaCode) {
+        List<MapMarker> list = photoMapService.getPhotoMarksArea(areaCode);
+        return WebResult.success(list);
+    }
+
+    @Operation(summary = "获取我附近的地图标记", description = "N")
+    @GetMapping(value = "/marks_nearby", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String getMapDistance(@RequestParam("distance") int distance) {
+        List<MapMarker> list = photoMapService.getMapDistance(distance);
+        return WebResult.success(list);
+    }
+
     @AuthUser
     @Operation(summary = "获取地图中标记点的详情", description = "N")
     @GetMapping(value = "/mark/info", produces = MediaType.APPLICATION_JSON_VALUE)

+ 5 - 2
content/content-service/src/main/java/cn/reghao/tnb/content/app/geo/db/mapper/CameraPhotoMapper.java

@@ -3,6 +3,7 @@ package cn.reghao.tnb.content.app.geo.db.mapper;
 import cn.reghao.jutil.jdk.db.BaseMapper;
 import cn.reghao.tnb.content.app.geo.model.po.CameraPhoto;
 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 org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
@@ -15,15 +16,17 @@ import java.util.List;
  */
 @Mapper
 public interface CameraPhotoMapper extends BaseMapper<CameraPhoto> {
-    void updateSetAlbumType(@Param("objectId") String objectId, @Param("albumType") String albumType);
+    void updateSetAreaCode(@Param("objectId") String objectId, @Param("areaCode") int areaCode);
 
     List<MapMarker> findAlbumIdGroup(int pageSize);
     List<MapMarker> findByImagePost(int pageSize);
     List<MapMarker> findByMallReply(int pageSize);
-    List<MapMarker> findByMallReplyCup(@Param("pageSize") int pageSize, @Param("itemType") int itemType);
+    List<MapMarker> findByMallReplyCup(@Param("pageSize") int pageSize);
+    List<MapMarker> findByMallReplyCupArea(@Param("pageSize") int pageSize, @Param("areaCode") String areaCode);
     List<MapMarker> findByMallReplyItem(@Param("pageSize") int pageSize, @Param("itemType") int itemType);
 
     MarkerInfo findImagePostInfo(int id);
     MarkerInfo findMallReplyInfo(int id);
     MarkerInfo findMarkerInfo(int id);
+    List<MapMarker> findByDistance(@Param("mapPoint") MapPoint mapPoint, @Param("distance") int distance);
 }

+ 1 - 3
content/content-service/src/main/java/cn/reghao/tnb/content/app/geo/db/mapper/GeoChinaMapper.java

@@ -3,7 +3,6 @@ package cn.reghao.tnb.content.app.geo.db.mapper;
 import cn.reghao.jutil.jdk.db.BaseMapper;
 import cn.reghao.tnb.content.app.geo.model.po.GeoChina;
 import cn.reghao.tnb.content.app.geo.model.vo.GeoArea;
-import cn.reghao.tnb.content.app.geo.model.vo.GeoMarker;
 import cn.reghao.tnb.content.app.geo.model.vo.MapPoint;
 import org.apache.ibatis.annotations.Mapper;
 
@@ -16,7 +15,6 @@ import java.util.List;
 @Mapper
 public interface GeoChinaMapper extends BaseMapper<GeoChina> {
     void saveMultiPolygon(GeoChina geoChina);
-    List<GeoMarker> findByDeep(int deep);
-    GeoChina findByPoint(MapPoint mapPoint);
+    GeoArea findByPoint(MapPoint mapPoint);
     List<GeoArea> findAllArea();
 }

+ 4 - 1
content/content-service/src/main/java/cn/reghao/tnb/content/app/geo/db/mapper/GeoPointMapper.java

@@ -3,6 +3,7 @@ package cn.reghao.tnb.content.app.geo.db.mapper;
 import cn.reghao.jutil.jdk.db.BaseMapper;
 import cn.reghao.tnb.content.app.geo.model.po.GeoPoint;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -12,5 +13,7 @@ import java.util.List;
  */
 @Mapper
 public interface GeoPointMapper extends BaseMapper<GeoPoint> {
-    List<GeoPoint> findByUserId(long userId);
+    void updateUserPosition(GeoPoint geoPoint);
+
+    List<GeoPoint> findByPositionType(@Param("userId") long userId, @Param("pointType") int pointType);
 }

+ 0 - 5
content/content-service/src/main/java/cn/reghao/tnb/content/app/geo/db/mapper/MallReplyMapper.java

@@ -5,8 +5,6 @@ import cn.reghao.tnb.content.app.geo.model.po.MallReply;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
-import java.util.List;
-
 /**
  * @author reghao
  * @date 2023-08-27 13:23:13
@@ -14,9 +12,6 @@ import java.util.List;
 @Mapper
 public interface MallReplyMapper extends BaseMapper<MallReply> {
     void updateSetCup(@Param("replyId") long replyId, @Param("cup") String cup);
-    void updateSetAreaCode(@Param("replyId") long replyId, @Param("areaCode") int areaCode);
 
-    List<MallReply> findByItemType(int itemType);
-    List<MallReply> findByItemId(String itemId);
     MallReply findByReplyId(long replyId);
 }

+ 16 - 1
content/content-service/src/main/java/cn/reghao/tnb/content/app/geo/db/repository/MallReplyRepository.java

@@ -5,11 +5,13 @@ import cn.reghao.tnb.content.app.geo.db.mapper.MallReplyMapper;
 import cn.reghao.tnb.content.app.geo.model.po.CameraPhoto;
 import cn.reghao.tnb.content.app.geo.model.po.MallReply;
 import cn.reghao.tnb.content.app.geo.model.vo.MapMarker;
+import cn.reghao.tnb.content.app.geo.model.vo.MapPoint;
 import org.springframework.cache.annotation.CacheEvict;
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Repository;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.Collections;
 import java.util.List;
 
 /**
@@ -46,11 +48,24 @@ public class MallReplyRepository {
             list = cameraPhotoMapper.findByMallReply(pageSize);
         } else if (itemType == 4) {
             pageSize = 1000;
-            list = cameraPhotoMapper.findByMallReplyCup(pageSize, itemType);
+            list = cameraPhotoMapper.findByMallReplyCup(pageSize);
         } else {
             list = cameraPhotoMapper.findByMallReplyItem(pageSize, itemType);
         }
 
         return list;
     }
+
+    @Cacheable(cacheNames = "tnb:geo:mark:area", key = "#areaCode", unless = "#result == null")
+    public List<MapMarker> findMapMarkers(int areaCode) {
+        int pageSize = 1000;
+        String areaCodeStr = areaCode+"";
+        List<MapMarker> mapMarkerList = cameraPhotoMapper.findByMallReplyCupArea(pageSize, areaCodeStr);
+        return mapMarkerList;
+    }
+
+    public List<MapMarker> findMapMarkers(MapPoint mapPoint, int distance) {
+        List<MapMarker> mapMarkerList = cameraPhotoMapper.findByDistance(mapPoint, distance);
+        return mapMarkerList;
+    }
 }

+ 2 - 0
content/content-service/src/main/java/cn/reghao/tnb/content/app/geo/model/po/CameraPhoto.java

@@ -29,6 +29,7 @@ public class CameraPhoto extends BaseObject<Integer> {
     private BigDecimal longitude;
     private BigDecimal latitude;
     private Boolean geoValid;
+    private Integer areaCode;
 
     public CameraPhoto(long replyId, CamPhoto camPhoto) {
         this.albumType = "MallReply";
@@ -52,5 +53,6 @@ public class CameraPhoto extends BaseObject<Integer> {
         } else {
             this.geoValid = false;
         }
+        this.areaCode = 0;
     }
 }

+ 11 - 0
content/content-service/src/main/java/cn/reghao/tnb/content/app/geo/model/po/GeoPoint.java

@@ -23,11 +23,22 @@ public class GeoPoint extends BaseObject<Integer> {
     private BigDecimal longitude;
     // 纬度
     private BigDecimal latitude;
+    private Integer pointType;
     private String deviceId;
     private Long createBy;
     private LocalDateTime createAt;
 
     public GeoPoint(MapPoint mapPoint) {
+        this.pointType = 2;
+        this.longitude = BigDecimal.valueOf(mapPoint.getLng());
+        this.latitude = BigDecimal.valueOf(mapPoint.getLat());
+        this.deviceId = "xxx";
+        this.createBy = UserContext.getUser();
+        this.createAt = DateTimeConverter.localDateTime(System.currentTimeMillis());
+    }
+
+    public GeoPoint(MapPoint mapPoint, int pointType) {
+        this.pointType = pointType;
         this.longitude = BigDecimal.valueOf(mapPoint.getLng());
         this.latitude = BigDecimal.valueOf(mapPoint.getLat());
         this.deviceId = "xxx";

+ 0 - 2
content/content-service/src/main/java/cn/reghao/tnb/content/app/geo/model/po/MallReply.java

@@ -26,7 +26,6 @@ public class MallReply extends BaseObject<Integer> {
     private String userId;
     private String username;
     private String avatarUrl;
-    private Integer areaCode;
 
     public MallReply(long replyId, MallReplyDto mallReplyDto) {
         this.itemType = mallReplyDto.getItemType();
@@ -38,6 +37,5 @@ public class MallReply extends BaseObject<Integer> {
         this.userId = mallReplyDto.getUserId();
         this.username = mallReplyDto.getUsername();
         this.avatarUrl = mallReplyDto.getAvatarUrl();
-        this.areaCode = 0;
     }
 }

+ 4 - 0
content/content-service/src/main/java/cn/reghao/tnb/content/app/geo/model/vo/GeoArea.java

@@ -10,5 +10,9 @@ import lombok.Getter;
 public class GeoArea {
     private int id;
     private int pid;
+    private int deep;
     private String name;
+    private String extPath;
+    private double lng;
+    private double lat;
 }

+ 0 - 17
content/content-service/src/main/java/cn/reghao/tnb/content/app/geo/model/vo/GeoMarker.java

@@ -1,17 +0,0 @@
-package cn.reghao.tnb.content.app.geo.model.vo;
-
-import lombok.Getter;
-import lombok.NoArgsConstructor;
-
-/**
- * @author reghao
- * @date 2025-05-30 22:51:12
- */
-@NoArgsConstructor
-@Getter
-public class GeoMarker {
-    private Integer id;
-    private String name;
-    private Double lng;
-    private Double lat;
-}

+ 7 - 0
content/content-service/src/main/java/cn/reghao/tnb/content/app/geo/model/vo/MapMarker.java

@@ -23,4 +23,11 @@ public class MapMarker implements Serializable {
     private String id;
     private String title;
     private MapPoint position;
+    private Integer distance;
+
+    public MapMarker(String id, String title, MapPoint mapPoint) {
+        this.id = id;
+        this.title = title;
+        this.position = mapPoint;
+    }
 }

+ 0 - 1
content/content-service/src/main/java/cn/reghao/tnb/content/app/geo/model/vo/MapPoint.java

@@ -7,7 +7,6 @@ import lombok.Setter;
 
 import javax.validation.constraints.NotNull;
 import java.io.Serializable;
-import java.math.BigDecimal;
 
 /**
  * @author reghao

+ 25 - 11
content/content-service/src/main/java/cn/reghao/tnb/content/app/geo/service/MapService.java

@@ -9,10 +9,7 @@ import cn.reghao.tnb.content.app.geo.model.vo.*;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -40,9 +37,20 @@ public class MapService {
         geoPointMapper.save(geoPoint);
     }
 
+    public void setMyPosition(MapPoint mapPoint) {
+        int pointType = 1;
+        GeoPoint geoPoint = new GeoPoint(mapPoint, pointType);
+        long loginUser = geoPoint.getCreateBy();
+        List<GeoPoint> list = geoPointMapper.findByPositionType(loginUser, pointType);
+        if (list.isEmpty()) {
+            geoPointMapper.save(geoPoint);
+        } else {
+            geoPointMapper.updateUserPosition(geoPoint);
+        }
+    }
+
     public List<MapMarker> getTrailMarks() {
-        long userId = UserContext.getUserId();
-        List<GeoPoint> list = geoPointMapper.findByUserId(userId);
+        List<GeoPoint> list = getMyGeoPoints();
         return list.stream().map(geoPoint -> {
             String id = String.valueOf(geoPoint.getId());
             String dateStr = DateTimeConverter.format(geoPoint.getCreateAt());
@@ -54,8 +62,7 @@ public class MapService {
     }
 
     public List getTrailPath() {
-        long userId = UserContext.getUser();
-        List<GeoPoint> list = geoPointMapper.findByUserId(userId);
+        List<GeoPoint> list = getMyGeoPoints();
         List<List<Double>> list1 = list.stream().map(geoPoint -> {
             Double lng = geoPoint.getLongitude().doubleValue();
             Double lat = geoPoint.getLatitude().doubleValue();
@@ -67,6 +74,12 @@ public class MapService {
         return List.of(map);
     }
 
+    private List<GeoPoint> getMyGeoPoints() {
+        long userId = UserContext.getUser();
+        List<GeoPoint> list = geoPointMapper.findByPositionType(userId, 2);
+        return list;
+    }
+
     /**
      * 省市县三级联动数据
      *
@@ -92,21 +105,22 @@ public class MapService {
         for (GeoArea  geoChina1 : level1) {
             CascadeOption cascadeOption1 = new CascadeOption();
             cascadeOption1.setLabel(geoChina1.getName());
-            cascadeOption1.setValue(geoChina1.getName());
+            cascadeOption1.setValue(geoChina1.getId()+"");
 
             pid = geoChina1.getId();
             List<GeoArea> level2 = groupMap.get(pid);
             for (GeoArea geoChina2 : level2) {
                 CascadeOption cascadeOption2 = new CascadeOption();
                 cascadeOption2.setLabel(geoChina2.getName());
-                cascadeOption2.setValue(geoChina2.getName());
+                cascadeOption2.setValue(geoChina2.getId()+"");
 
                 pid = geoChina2.getId();
                 List<GeoArea> level3 = groupMap.get(pid);
                 for (GeoArea geoChina3 : level3) {
                     CascadeOption cascadeOption3 = new CascadeOption();
                     cascadeOption3.setLabel(geoChina3.getName());
-                    cascadeOption3.setValue(geoChina3.getName());
+                    cascadeOption3.setValue(geoChina3.getId()+"");
+
                     cascadeOption3.setChildren(null);
                     cascadeOption2.getChildren().add(cascadeOption3);
                 }

+ 29 - 1
content/content-service/src/main/java/cn/reghao/tnb/content/app/geo/service/PhotoMapService.java

@@ -2,15 +2,19 @@ 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.auth.UserContext;
 import cn.reghao.tnb.common.db.SelectOption;
 import cn.reghao.tnb.content.api.dto.geo.MallReplyDto;
 import cn.reghao.tnb.content.app.geo.db.mapper.CameraPhotoMapper;
+import cn.reghao.tnb.content.app.geo.db.mapper.GeoPointMapper;
 import cn.reghao.tnb.content.app.geo.db.mapper.MallReplyMapper;
 import cn.reghao.tnb.content.app.geo.db.repository.MallReplyRepository;
 import cn.reghao.tnb.content.app.geo.model.constant.GeoItem;
 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.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;
@@ -35,12 +39,14 @@ public class PhotoMapService {
     private final MallReplyMapper mallReplyMapper;
     private final CameraPhotoMapper cameraPhotoMapper;
     private final MallReplyRepository mallReplyRepository;
+    private final GeoPointMapper geoPointMapper;
 
     public PhotoMapService(MallReplyMapper mallReplyMapper, CameraPhotoMapper cameraPhotoMapper,
-                           MallReplyRepository mallReplyRepository) {
+                           MallReplyRepository mallReplyRepository, GeoPointMapper geoPointMapper) {
         this.mallReplyMapper = mallReplyMapper;
         this.cameraPhotoMapper = cameraPhotoMapper;
         this.mallReplyRepository = mallReplyRepository;
+        this.geoPointMapper = geoPointMapper;
     }
 
     public synchronized void addTmallReply(MallReplyDto mallReplyDto) {
@@ -81,6 +87,28 @@ public class PhotoMapService {
         return list;
     }
 
+    public List<MapMarker> getPhotoMarksArea(int areaCode) {
+        List<MapMarker> list = mallReplyRepository.findMapMarkers(areaCode);
+        return list;
+    }
+
+    public List<MapMarker> getMapDistance(int distance) {
+        long loginUser = UserContext.getUser();
+        List<GeoPoint> geoPointList = geoPointMapper.findByPositionType(loginUser, 1);
+        if (geoPointList.isEmpty()) {
+            return Collections.emptyList();
+        }
+
+        GeoPoint geoPoint = geoPointList.get(0);
+        double lng = geoPoint.getLongitude().doubleValue();
+        double lat = geoPoint.getLatitude().doubleValue();
+        MapPoint mapPoint = new MapPoint(lng, lat);
+        List<MapMarker> list = mallReplyRepository.findMapMarkers(mapPoint, distance);
+        MapMarker mapMarker = new MapMarker("0", "MyPosition", mapPoint);
+        list.add(mapMarker);
+        return list;
+    }
+
     public MarkerInfo getMarkerInfo(int id) {
         CameraPhoto cameraPhoto = cameraPhotoMapper.findById(id);
         if (cameraPhoto == null) {

+ 35 - 15
content/content-service/src/main/resources/mapper/geo/CameraPhotoMapper.xml

@@ -4,33 +4,30 @@
 <mapper namespace="cn.reghao.tnb.content.app.geo.db.mapper.CameraPhotoMapper">
     <insert id="save" useGeneratedKeys="true" keyProperty="id">
         insert into geo_camera_photo
-        (`album_type`,`album_id`,`object_id`,`channel_code`,`photo_url`,`manufacturer`,`model`,`software`,`shot_at`,`geo`,`geo_valid`)
+        (`album_type`,`album_id`,`object_id`,`channel_code`,`photo_url`,`manufacturer`,`model`,`software`,`shot_at`,`geo`,`geo_valid`,`area_code`)
         values 
-        (#{albumType},#{albumId},#{objectId},#{channelCode},#{photoUrl},#{manufacturer},#{model},#{software},#{shotAt},point(#{longitude},#{latitude}),#{geoValid})
+        (#{albumType},#{albumId},#{objectId},#{channelCode},#{photoUrl},#{manufacturer},#{model},#{software},#{shotAt},point(#{longitude},#{latitude}),#{geoValid},#{areaCode})
     </insert>
     <insert id="saveAll" useGeneratedKeys="true" keyProperty="id">
         insert ignore into geo_camera_photo
-        (`album_type`,`album_id`,`object_id`,`channel_code`,`photo_url`,`manufacturer`,`model`,`software`,`shot_at`,`geo`,`geo_valid`)
+        (`album_type`,`album_id`,`object_id`,`channel_code`,`photo_url`,`manufacturer`,`model`,`software`,`shot_at`,`geo`,`geo_valid`,`area_code`)
         values
         <foreach collection="list" item="item" index="index" separator=",">
-            (#{item.albumType},#{item.albumId},#{item.objectId},#{item.channelCode},#{item.photoUrl},#{item.manufacturer},#{item.model},#{item.software},#{item.shotAt},point(#{item.longitude},#{item.latitude}),#{item.geoValid})
+            (#{item.albumType},#{item.albumId},#{item.objectId},#{item.channelCode},#{item.photoUrl},
+            #{item.manufacturer},#{item.model},#{item.software},#{item.shotAt},point(#{item.longitude},#{item.latitude}),#{item.geoValid},#{item.areaCode})
         </foreach>
     </insert>
 
-    <update id="updateSetAlbumType">
+    <update id="updateSetAreaCode">
         update geo_camera_photo
-        set album_type=#{albumType}
+        set area_code=#{areaCode}
         where object_id=#{objectId}
     </update>
 
-    <delete id="deleteById">
-        delete from geo_camera_photo
-        where id=#{id}
-    </delete>
-
     <resultMap id="mapMarker" type="cn.reghao.tnb.content.app.geo.model.vo.MapMarker">
         <result property="id" column="id"/>
         <result property="title" column="title"/>
+        <result property="distance" column="distance"/>
         <association property="position" javaType="cn.reghao.tnb.content.app.geo.model.vo.MapPoint">
             <result property="lng" column="lng"/>
             <result property="lat" column="lat"/>
@@ -67,7 +64,17 @@
         from geo_camera_photo photo
         inner join geo_mall_reply reply
         on photo.album_id=reply.reply_id and photo.geo_valid=1 and photo.album_type='MallReply'
-        and reply.item_type=#{itemType}
+        and reply.item_type=4
+        group by photo.album_id
+        order by photo.id desc
+        limit #{pageSize}
+    </select>
+    <select id="findByMallReplyCupArea" resultMap="mapMarker">
+        select photo.id,reply.cup as title,photo.photo_url,x(photo.geo) as lng,y(photo.geo) as lat
+        from geo_camera_photo photo
+        inner join geo_mall_reply reply
+        on photo.album_id=reply.reply_id and photo.geo_valid=1 and photo.album_type='MallReply' and reply.item_type=4
+        where photo.area_code like concat(#{areaCode},'%')
         group by photo.album_id
         order by photo.id desc
         limit #{pageSize}
@@ -101,13 +108,26 @@
         where id=#{id} and geo is not null
     </select>
 
+    <select id="findAll" resultType="cn.reghao.tnb.content.app.geo.model.po.CameraPhoto">
+        select `id`,`album_type`,`album_id`,`object_id`,`channel_code`, `photo_url`,
+        `manufacturer`,`model`,`software`,`shot_at`,x(geo) as longitude,y(geo) as latitude,`geo_valid`
+        from geo_camera_photo
+        where geo_valid is true and area_code=0
+    </select>
     <select id="findById" resultType="cn.reghao.tnb.content.app.geo.model.po.CameraPhoto">
         select *
         from geo_camera_photo
         where id=#{id}
     </select>
-    <select id="findAll" resultType="cn.reghao.tnb.content.app.geo.model.po.CameraPhoto">
-        select *
-        from geo_camera_photo
+    <select id="findByDistance" resultMap="mapMarker">
+        select photo.id,reply.cup as title,photo.photo_url,x(photo.geo) as lng,y(photo.geo) as lat,
+            round(st_distance_sphere(point(#{mapPoint.lng}, #{mapPoint.lat}),point(x(geo), y(geo))), 2) as distance
+        from geo_camera_photo photo
+        inner join geo_mall_reply reply
+        on photo.album_id=reply.reply_id and photo.geo_valid=1 and photo.album_type='MallReply' and reply.item_type=4
+        group by photo.album_id
+        HAVING distance > 0 and distance &lt; #{distance}
+        order by distance
+        limit 1000
     </select>
 </mapper>

+ 3 - 19
content/content-service/src/main/resources/mapper/geo/GeoChinaMapper.xml

@@ -24,29 +24,13 @@
         </foreach>
     </insert>
 
-    <select id="findAll" resultType="cn.reghao.tnb.content.app.geo.model.po.GeoChina">
-        select *
-        from geo_china
-        limit 10
-    </select>
-    <select id="findById" resultType="cn.reghao.tnb.content.app.geo.model.po.GeoChina">
-        select *
-        from geo_china
-        where id=#{id}
-    </select>
-    <select id="findByDeep" resultType="cn.reghao.tnb.content.app.geo.model.vo.GeoMarker">
-        select id,`name`,x(geo) as lng,y(geo) as lat
-        from geo_china
-        where deep=#{deep}
-        limit 1000
-    </select>
-    <select id="findByPoint" resultType="cn.reghao.tnb.content.app.geo.model.po.GeoChina">
-        select *
+    <select id="findByPoint" resultType="cn.reghao.tnb.content.app.geo.model.vo.GeoArea">
+        select id,pid,deep,`name`,ext_path,x(geo) as lng,y(geo) as lat
         from geo_china
         where deep=2 and st_within(point(#{lng},#{lat}), polygon);
     </select>
     <select id="findAllArea" resultType="cn.reghao.tnb.content.app.geo.model.vo.GeoArea">
-        select id,pid,`name`
+        select id,pid,deep,`name`,ext_path,x(geo) as lng,y(geo) as lat
         from geo_china
     </select>
 </mapper>

+ 12 - 7
content/content-service/src/main/resources/mapper/geo/GeoPointMapper.xml

@@ -4,23 +4,28 @@
 <mapper namespace="cn.reghao.tnb.content.app.geo.db.mapper.GeoPointMapper">
     <insert id="save" useGeneratedKeys="true" keyProperty="id">
         insert into geo_point
-        (`geo`,`device_id`,`create_by`,`create_at`)
+        (`geo`,`point_type`,`device_id`,`create_by`,`create_at`)
         values 
-        (point(#{longitude},#{latitude}),#{deviceId},#{createBy},#{createAt})
+        (point(#{longitude},#{latitude}),#{pointType},#{deviceId},#{createBy},#{createAt})
     </insert>
     <insert id="saveAll" useGeneratedKeys="true" keyProperty="id">
         insert ignore into geo_point
-        (`geo`,`device_id`,`create_by`,`create_at`)
+        (`geo`,`point_type`,`device_id`,`create_by`,`create_at`)
         values
         <foreach collection="list" item="item" index="index" separator=",">
-            (point(#{item.longitude},#{item.latitude}),#{item.deviceId},#{item.createBy},#{item.createAt})
+            (point(#{item.longitude},#{item.latitude}),#{item.pointType},#{item.deviceId},#{item.createBy},#{item.createAt})
         </foreach>
     </insert>
 
-    <select id="findByUserId" resultType="cn.reghao.tnb.content.app.geo.model.po.GeoPoint">
+    <update id="updateUserPosition">
+        update geo_point
+        set update_time=now(),geo=point(#{longitude},#{latitude})
+        where point_type=#{pointType} and create_by=#{createBy}
+    </update>
+
+    <select id="findByPositionType" resultType="cn.reghao.tnb.content.app.geo.model.po.GeoPoint">
         select id,create_time,x(geo) as longitude,y(geo) as latitude,device_id,create_by,create_at
         from geo_point
-        where create_by=#{userId}
-        order by create_at asc
+        where point_type=#{pointType} and create_by=#{userId}
     </select>
 </mapper>

+ 4 - 20
content/content-service/src/main/resources/mapper/geo/MallReplyMapper.xml

@@ -3,10 +3,10 @@
 
 <mapper namespace="cn.reghao.tnb.content.app.geo.db.mapper.MallReplyMapper">
     <insert id="save" useGeneratedKeys="true" keyProperty="id">
-        insert into geo_mall_reply
-        (`item_type`,`item_id`,`reply_id`,`reply_content`,`extra`,`reply_date`,`user_id`,`username`,`avatar_url`,`area_code`)
+        insert ignore into geo_mall_reply
+        (`item_type`,`item_id`,`reply_id`,`reply_content`,`extra`,`reply_date`,`user_id`,`username`,`avatar_url`)
         values 
-        (#{itemType},#{itemId},#{replyId},#{replyContent},#{extra},#{replyDate},#{userId},#{username},#{avatarUrl},#{areaCode})
+        (#{itemType},#{itemId},#{replyId},#{replyContent},#{extra},#{replyDate},#{userId},#{username},#{avatarUrl})
     </insert>
 
     <update id="updateSetCup">
@@ -14,31 +14,15 @@
         set cup=#{cup}
         where reply_id=#{replyId}
     </update>
-    <update id="updateSetAreaCode">
-        update geo_mall_reply
-        set area_code=#{areaCode}
-        where reply_id=#{replyId}
-    </update>
 
     <select id="findAll" resultType="cn.reghao.tnb.content.app.geo.model.po.MallReply">
         select *
         from geo_mall_reply
-    </select>
-    <select id="findByItemType" resultType="cn.reghao.tnb.content.app.geo.model.po.MallReply">
-        select *
-        from geo_mall_reply
-        where item_type=#{itemType}
-        order by id asc
-        limit 500
+        where item_type=4 and cup is null
     </select>
     <select id="findByReplyId" resultType="cn.reghao.tnb.content.app.geo.model.po.MallReply">
         select *
         from geo_mall_reply
         where reply_id=#{reply_id}
     </select>
-    <select id="findByItemId" resultType="cn.reghao.tnb.content.app.geo.model.po.MallReply">
-        select *
-        from geo_mall_reply
-        where item_id=#{itemId}
-    </select>
 </mapper>

+ 69 - 91
content/content-service/src/test/java/cn/reghao/tnb/content/app/geo/service/GeoTest.java

@@ -4,10 +4,10 @@ import cn.reghao.jutil.jdk.serializer.JsonConverter;
 import cn.reghao.jutil.jdk.text.TextFile;
 import cn.reghao.oss.sdk.OssConsoleClient;
 import cn.reghao.oss.sdk.model.OssConsoleConfig;
-import cn.reghao.oss.sdk.model.dto.ObjectInfo;
 import cn.reghao.tnb.content.app.ContentApplication;
 import cn.reghao.tnb.content.app.geo.db.mapper.*;
 import cn.reghao.tnb.content.app.geo.model.po.*;
+import cn.reghao.tnb.content.app.geo.model.vo.GeoArea;
 import cn.reghao.tnb.content.app.geo.model.vo.MapMarker;
 import cn.reghao.tnb.content.app.geo.model.vo.MapPoint;
 import com.google.gson.JsonObject;
@@ -17,10 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.ActiveProfiles;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 /**
  * @author reghao
@@ -32,42 +29,6 @@ import java.util.Map;
 public class GeoTest {
     @Autowired
     MapService mapService;
-    @Autowired
-    GeoPointMapper geoPointMapper;
-    @Test
-    public void geoPointTest() {
-        String lngN = "123.266667";
-        String latN = "53.55";
-
-        String lngS = "112.283333";
-        String latS = "3.966667";
-
-        String lngE = "134.7738";
-        String latE = "47.7738";
-
-        String lngW = "73.5";
-        String latW = "39.38";
-
-        MapPoint mapPointN = new MapPoint(lngN, latN);
-        MapPoint mapPointS = new MapPoint(lngS, latS);
-        MapPoint mapPointE = new MapPoint(lngE, latE);
-        MapPoint mapPointW = new MapPoint(lngW, latW);
-
-        /*List<GeoPoint> list = new ArrayList<>();
-        list.add(new GeoPoint(mapPointN, "最北"));
-        list.add(new GeoPoint(mapPointS, "最南"));
-        list.add(new GeoPoint(mapPointE, "最东"));
-        list.add(new GeoPoint(mapPointW, "最西"));
-        geoPointMapper.saveAll(list);*/
-
-        double lng = 104.061745;
-        double lat = 30.658669;
-        MapPoint mapPoint = new MapPoint(lng, lat);
-        GeoChina geoChina = geoChinaMapper.findByPoint(mapPoint);
-        if (geoChina != null) {
-            System.out.printf("%s -> %s\n", geoChina.getId(), geoChina.getExtPath());
-        }
-    }
 
     @Autowired
     GeoChinaMapper geoChinaMapper;
@@ -160,10 +121,65 @@ public class GeoTest {
         return sb.toString().trim();
     }
 
+
+    OssConsoleClient getOssConsoleClient() {
+        String consoleUrl = "http://bnt.reghao.cn";
+        String accessKeyId = "ESCKn3Cd";
+        String accessKeySecret = "OL9SIOLoOqUjhMiQMv";
+        int videoChannelId = 101;
+        OssConsoleConfig ossConsoleConfig = new OssConsoleConfig(consoleUrl, accessKeyId, accessKeySecret);
+        try {
+            OssConsoleClient ossConsoleClient = new OssConsoleClient(ossConsoleConfig);
+            return ossConsoleClient;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return null;
+    }
+
+    @Autowired
+    CameraPhotoMapper cameraPhotoMapper;
+    @Test
+    void photoMapTest() {
+        //OssConsoleClient ossConsoleClient = getOssConsoleClient();
+        List<CameraPhoto> list = cameraPhotoMapper.findAll();
+        for (CameraPhoto cameraPhoto : list) {
+            /*String objectId = cameraPhoto.getObjectId();
+            int channelId = cameraPhoto.getChannelId();
+            try {
+                ObjectInfo objectInfo = ossConsoleClient.getObjectInfo(channelId, objectId);
+            } catch (Exception e) {
+                log.info("objectId {} not exist", objectId);
+            }*/
+        }
+    }
+
+    @Autowired
+    BusStationMapper busStationMapper;
+    @Test
+    void geoBusTest() {
+        List<BusStation> list = busStationMapper.findAll();
+        for (BusStation busStation : list) {
+            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);
+
+            MapMarker mapMarker = new MapMarker(id, stationName, mapPoint);
+        }
+    }
+
     @Autowired
     MallReplyMapper mallReplyMapper;
     @Test
-    public void test() {
+    public void updateCupTest() {
         List<MallReply> list = mallReplyMapper.findAll();
         list.forEach(mallReply -> {
             String extra = mallReply.getExtra();
@@ -238,59 +254,21 @@ public class GeoTest {
         return extra1;
     }
 
-
-    OssConsoleClient getOssConsoleClient() {
-        String consoleUrl = "http://bnt.reghao.cn";
-        String accessKeyId = "ESCKn3Cd";
-        String accessKeySecret = "OL9SIOLoOqUjhMiQMv";
-        int videoChannelId = 101;
-        OssConsoleConfig ossConsoleConfig = new OssConsoleConfig(consoleUrl, accessKeyId, accessKeySecret);
-        try {
-            OssConsoleClient ossConsoleClient = new OssConsoleClient(ossConsoleConfig);
-            return ossConsoleClient;
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-
-        return null;
-    }
-
-    @Autowired
-    CameraPhotoMapper cameraPhotoMapper;
     @Test
-    void photoMapTest() {
-        OssConsoleClient ossConsoleClient = getOssConsoleClient();
-
+    public void updateAreaCodeTest() {
         List<CameraPhoto> list = cameraPhotoMapper.findAll();
         for (CameraPhoto cameraPhoto : list) {
-            String objectId = cameraPhoto.getObjectId();
-            int channelId = cameraPhoto.getChannelId();
-            try {
-                ObjectInfo objectInfo = ossConsoleClient.getObjectInfo(channelId, objectId);
-            } catch (Exception e) {
-                log.info("objectId {} not exist", objectId);
-            }
-        }
-    }
-
-    @Autowired
-    BusStationMapper busStationMapper;
-    @Test
-    void geoBusTest() {
-        List<BusStation> list = busStationMapper.findAll();
-        for (BusStation busStation : list) {
-            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);
+            double lng = cameraPhoto.getLongitude().doubleValue();
+            double lat = cameraPhoto.getLatitude().doubleValue();
             MapPoint mapPoint = new MapPoint(lng, lat);
-
-            MapMarker mapMarker = new MapMarker(id, stationName, mapPoint);
+            GeoArea geoArea = geoChinaMapper.findByPoint(mapPoint);
+            if (geoArea != null) {
+                int areaCode = geoArea.getId();
+                String extPath = geoArea.getExtPath();
+                String objectId = cameraPhoto.getObjectId();
+                cameraPhotoMapper.updateSetAreaCode(objectId, areaCode);
+                log.info("update {} {} -> {}", objectId, areaCode, extPath);
+            }
         }
     }
 }