Bladeren bron

全域搜索

wangqifan 3 jaren geleden
bovenliggende
commit
b7731c0fd0

+ 45 - 0
src/main/java/com/izouma/nineth/dto/excel/GlobalSearchDTO.java

@@ -0,0 +1,45 @@
+package com.izouma.nineth.dto.excel;
+
+import com.izouma.nineth.domain.Collection;
+import com.izouma.nineth.domain.MintActivity;
+import com.izouma.nineth.domain.News;
+import com.izouma.nineth.domain.User;
+import com.izouma.nineth.service.LikeService;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.List;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class GlobalSearchDTO {
+    List<Collection> collections;
+
+    boolean collectionsAll;
+
+    List<Collection> domains;
+
+    boolean domainsAll;
+
+    List<Collection> pictures;
+
+    boolean picturesAll;
+
+    List<News> news;
+
+    boolean newsAll;
+
+    List<MintActivity> mintActivities;
+
+    boolean mintActivitiesAll;
+
+    List<User> minters;
+
+    boolean mintersAll;
+
+    List<User> users;
+
+    boolean usersAll;
+}

+ 5 - 1
src/main/java/com/izouma/nineth/repo/NewsRepo.java

@@ -4,6 +4,8 @@ import com.izouma.nineth.domain.News;
 import com.izouma.nineth.dto.RecommendCollection;
 import com.izouma.nineth.dto.RecommendNews;
 import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.jpa.repository.Modifying;
@@ -25,7 +27,9 @@ public interface NewsRepo extends JpaRepository<News, Long>, JpaSpecificationExe
     void addLike(Long id, int num);
 
     @Query("select new com.izouma.nineth.dto.RecommendNews(n,r) from News n join Recommend r on n.id = r.collectionId " +
-                "where n.del = false and r.companyId = ?2 and r.type = ?1 and r.category = 'NEWS' order by r.sort desc")
+            "where n.del = false and r.companyId = ?2 and r.type = ?1 and r.category = 'NEWS' order by r.sort desc")
     List<RecommendNews> recommend(String type, Long companyId);
 
+    Page<News> findByTitleLike(String name, Pageable pageable);
+
 }

+ 5 - 1
src/main/java/com/izouma/nineth/repo/UserRepo.java

@@ -5,6 +5,8 @@ import com.izouma.nineth.dto.InvitedUserDTO;
 import com.izouma.nineth.enums.AuthStatus;
 import com.izouma.nineth.security.Authority;
 import org.springframework.cache.annotation.Cacheable;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.jpa.repository.Modifying;
@@ -263,7 +265,9 @@ public interface UserRepo extends JpaRepository<User, Long>, JpaSpecificationExe
     @Query("update User set destroyPoint = destroyPoint + ?2 where id = ?1")
     void addDestroyPoint(Long id, int num);
 
-    @Query(nativeQuery = true, value ="SELECT user.avatar avatar, user.nickname nickname, user.level level FROM user WHERE user.id = ?1 AND user.del = false")
+    @Query(nativeQuery = true, value = "SELECT user.avatar avatar, user.nickname nickname, user.level level FROM user WHERE user.id = ?1 AND user.del = false")
     Map<String, String> websocketQuery(Long userId);
 
+    Page<User> findByNicknameLikeOrIntroLike(String search1, String search2, Pageable pageable);
+
 }

+ 69 - 10
src/main/java/com/izouma/nineth/service/StatisticService.java

@@ -5,10 +5,10 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.alipay.api.domain.PriceInfo;
 import com.github.kevinsawicki.http.HttpRequest;
-import com.izouma.nineth.domain.BalanceRecord;
-import com.izouma.nineth.domain.Order;
-import com.izouma.nineth.domain.RechargeOrder;
-import com.izouma.nineth.domain.User;
+import com.izouma.nineth.domain.*;
+import com.izouma.nineth.domain.Collection;
+import com.izouma.nineth.dto.PageQuery;
+import com.izouma.nineth.dto.excel.GlobalSearchDTO;
 import com.izouma.nineth.enums.BalanceType;
 import com.izouma.nineth.enums.CollectionSource;
 import com.izouma.nineth.enums.OrderStatus;
@@ -18,6 +18,8 @@ import com.izouma.nineth.repo.*;
 import com.izouma.nineth.utils.netease.CheckSumBuilder;
 import lombok.AllArgsConstructor;
 import org.apache.commons.lang.RandomStringUtils;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
 import org.springframework.stereotype.Service;
 
 import javax.xml.stream.events.EndDocument;
@@ -33,12 +35,17 @@ import java.util.stream.Collectors;
 @AllArgsConstructor
 public class StatisticService {
 
-    private UserRepo          userRepo;
-    private OrderRepo         orderRepo;
-    private TokenHistoryRepo  tokenHistoryRepo;
-    private BalanceRecordRepo balanceRecordRepo;
-    private PhotoAssetRepo    photoAssetRepo;
-    private DomainOrderRepo   domainOrderRepo;
+    private UserRepo                userRepo;
+    private OrderRepo               orderRepo;
+    private TokenHistoryRepo        tokenHistoryRepo;
+    private BalanceRecordRepo       balanceRecordRepo;
+    private PhotoAssetRepo          photoAssetRepo;
+    private DomainOrderRepo         domainOrderRepo;
+    private CollectionService       collectionService;
+    private NewsRepo                newsRepo;
+    private MintActivityService     mintActivityService;
+    private UserService             userService;
+    private CollectionPrivilegeRepo collectionPrivilegeRepo;
 
     public Map<String, Object> total(Long userId, Long companyId) {
         User user1 = userRepo.findByIdAndDelFalse(userId).orElseThrow(new BusinessException("无用户"));
@@ -462,4 +469,56 @@ public class StatisticService {
         today.put("saas", Optional.ofNullable(saas).orElse(BigDecimal.ZERO));
         return today;
     }
+
+    public GlobalSearchDTO globalSearch(String search) {
+        GlobalSearchDTO globalSearchDTO = new GlobalSearchDTO();
+        PageQuery pageQuery = new PageQuery();
+        pageQuery.setPage(0);
+        pageQuery.setSize(6);
+        pageQuery.setSort("createdAt,desc");
+        pageQuery.setSearch(search);
+        Map<String, Object> map = new HashMap<>();
+        map.put("type", "DEFAULT,BLIND_BOX");
+        map.put("onShelf", true);
+        map.put("del", false);
+        map.put("notLike", "星星的孩子,测试");
+        pageQuery.setQuery(map);
+        Page<Collection> collections1 = collectionService.all(pageQuery).toPage();
+        globalSearchDTO.setCollections(collections1.getContent());
+        globalSearchDTO.setCollectionsAll(collections1.getTotalElements() <= 6);
+        map.put("type", "PICTURE");
+        Page<Collection> collections2 = collectionService.all(pageQuery).toPage();
+        globalSearchDTO.setPictures(collections2.getContent());
+        globalSearchDTO.setPicturesAll(collections2.getTotalElements() <= 6);
+        map.put("type", "DOMAIN");
+        Page<Collection> collections3 = collectionService.all(pageQuery).toPage();
+        globalSearchDTO.setDomains(collections3.getContent());
+        globalSearchDTO.setDomainsAll(collections3.getTotalElements() <= 6);
+        PageRequest pageRequest = PageRequest.of(0, 6);
+        Page<News> news = newsRepo.findByTitleLike("%" + search + "%", pageRequest);
+        globalSearchDTO.setNews(news.getContent());
+        globalSearchDTO.setNewsAll(news.getTotalElements() <= 6);
+        Map<String, Object> mintMap = new HashMap<>();
+        mintMap.put("companyId", 1);
+        mintMap.put("del", false);
+        pageQuery.setQuery(mintMap);
+        Page<MintActivity> mints = mintActivityService.all(pageQuery);
+        globalSearchDTO.setMintActivities(mints.getContent());
+        globalSearchDTO.setMintActivitiesAll(mints.getTotalElements() <= 6);
+        Map<String, Object> minterMap = new HashMap<>();
+        minterMap.put("companyId", 1);
+        minterMap.put("del", false);
+        minterMap.put("minter", true);
+        pageQuery.setQuery(minterMap);
+        Page<User> minters = userService.all(pageQuery).toPage();
+        globalSearchDTO.setMinters(minters.getContent());
+        globalSearchDTO.setMintersAll(minters.getTotalElements() <= 6);
+        Page<User> userPage = userRepo
+                .findByNicknameLikeOrIntroLike("%" + search + "%", "%" + search + "%", pageRequest);
+        globalSearchDTO.setMinters(userPage.getContent());
+        globalSearchDTO.setMintersAll(userPage.getTotalElements() <= 6);
+        return globalSearchDTO;
+
+
+    }
 }

+ 7 - 0
src/main/java/com/izouma/nineth/web/StatisticController.java

@@ -1,5 +1,6 @@
 package com.izouma.nineth.web;
 
+import com.izouma.nineth.dto.excel.GlobalSearchDTO;
 import com.izouma.nineth.service.CacheService;
 import com.izouma.nineth.service.StatisticService;
 import com.izouma.nineth.utils.SecurityUtils;
@@ -122,4 +123,10 @@ public class StatisticController {
     public Map<String, Map<String, Object>> statisticDetail() {
         return statisticService.statisticDetail();
     }
+
+    @PostMapping("/globalSearch")
+    @Cacheable("globalSearch")
+    public GlobalSearchDTO globalSearch(String search) {
+        return statisticService.globalSearch(search);
+    }
 }

+ 1 - 1
src/main/vue/.env.development

@@ -1 +1 @@
-VUE_APP_BASE_URL=https://www.raex.vip/
+VUE_APP_BASE_URL=http://localhost:8080/