Browse Source

update MallReplyRepository

reghao 7 tháng trước cách đây
mục cha
commit
bcbff171a8

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

@@ -4,6 +4,9 @@ import cn.reghao.tnb.content.app.geo.db.mapper.CameraPhotoMapper;
 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 org.springframework.cache.annotation.CacheEvict;
+import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Repository;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -23,9 +26,31 @@ public class MallReplyRepository {
         this.cameraPhotoMapper = cameraPhotoMapper;
     }
 
+    @CacheEvict(cacheNames = "tnb:geo:mark", key = "#mallReply.itemType")
     @Transactional(rollbackFor = Exception.class)
     public void saveTmallReply(MallReply mallReply, List<CameraPhoto> list) {
         mallReplyMapper.save(mallReply);
         cameraPhotoMapper.saveAll(list);
     }
+
+    @Cacheable(cacheNames = "tnb:geo:mark", key = "#itemType", unless = "#result == null")
+    public List<MapMarker> findMapMarkers(int itemType, int pageSize) {
+        List<MapMarker> list;
+        if (itemType == 1) {
+            pageSize = 1000;
+            list = cameraPhotoMapper.findAlbumIdGroup(pageSize);
+        } else if (itemType == 2) {
+            list = cameraPhotoMapper.findByImagePost(pageSize);
+        } else if (itemType == 3) {
+            pageSize = 1000;
+            list = cameraPhotoMapper.findByMallReply(pageSize);
+        } else if (itemType == 4) {
+            pageSize = 1000;
+            list = cameraPhotoMapper.findByMallReplyCup(pageSize, itemType);
+        } else {
+            list = cameraPhotoMapper.findByMallReplyItem(pageSize, itemType);
+        }
+
+        return list;
+    }
 }

+ 2 - 17
content/content-service/src/main/java/cn/reghao/tnb/content/app/geo/service/PhotoMapService.java

@@ -34,7 +34,7 @@ public class PhotoMapService {
 
     private final MallReplyMapper mallReplyMapper;
     private final CameraPhotoMapper cameraPhotoMapper;
-    private MallReplyRepository mallReplyRepository;
+    private final MallReplyRepository mallReplyRepository;
 
     public PhotoMapService(MallReplyMapper mallReplyMapper, CameraPhotoMapper cameraPhotoMapper,
                            MallReplyRepository mallReplyRepository) {
@@ -77,22 +77,7 @@ public class PhotoMapService {
     @Cacheable(cacheNames = "tnb:geo:mark", key = "#itemType", unless = "#result == null")
     public List<MapMarker> getPhotoMarks(int itemType) {
         int pageSize = 100;
-        List<MapMarker> list;
-        if (itemType == 1) {
-            pageSize = 1000;
-            list = cameraPhotoMapper.findAlbumIdGroup(pageSize);
-        } else if (itemType == 2) {
-            list = cameraPhotoMapper.findByImagePost(pageSize);
-        } else if (itemType == 3) {
-            pageSize = 1000;
-            list = cameraPhotoMapper.findByMallReply(pageSize);
-        } else if (itemType == 4) {
-            pageSize = 1000;
-            list = cameraPhotoMapper.findByMallReplyCup(pageSize, itemType);
-        } else {
-            list = cameraPhotoMapper.findByMallReplyItem(pageSize, itemType);
-        }
-
+        List<MapMarker> list = mallReplyRepository.findMapMarkers(itemType, pageSize);
         return list;
     }