yonghuifan 1 年間 前
コミット
e441d35f3b

+ 6 - 0
src/main/java/com/dragon/tj/portal/entity/AppInfo.java

@@ -137,4 +137,10 @@ public class AppInfo implements Serializable {
      * */
     @TableField(exist = false)
     private Integer isSpecial;
+
+    /**
+     * 用户是否收藏
+     */
+    @TableField(exist = false)
+    private Integer isStar;
 }

+ 6 - 0
src/main/java/com/dragon/tj/portal/entity/BusinessInfo.java

@@ -114,4 +114,10 @@ public class BusinessInfo {
      */
     @TableField(exist = false)
     private int seq;
+
+    /**
+     * 用户是否收藏
+     */
+    @TableField(exist = false)
+    private Integer isStar;
 }

+ 32 - 0
src/main/java/com/dragon/tj/portal/service/impl/AppServiceImpl.java

@@ -138,9 +138,41 @@ public class AppServiceImpl implements AppService {
 
         rowPage.addOrder(OrderItem.desc(appInfoPage.getOrder()));
 
+        if (appInfo.getIsStar() != null && appInfo.getIsStar() == 1) {
+            Page<AppInfo> appInfoPage1 = appInfoMapper.selectPage(rowPage, queryWrapper);
+
+            return checkFavorites(appInfoPage1);
+        }
+
         return appInfoMapper.selectPage(rowPage, queryWrapper);
     }
 
+    /*
+    * 热门应用是否收藏
+    * */
+    private Page<AppInfo> checkFavorites(Page<AppInfo> appInfoPage){
+        List<AppInfo> records = appInfoPage.getRecords();
+        List<Long> ids = records.stream().map(AppInfo::getId).collect(Collectors.toList());
+        if (ids.size() == 0){
+            return appInfoPage;
+        }
+        LambdaQueryWrapper<InstallInfo> wrapper = new LambdaQueryWrapper<>();
+        wrapper.select(InstallInfo::getAppId);
+        wrapper.eq(InstallInfo::getBusinessId,0);
+        wrapper.eq(SecurityUtils.getLoginUser() != null,
+                InstallInfo::getUserIdcard,SecurityUtils.getLoginUser().getIdCard());
+        wrapper.in(InstallInfo::getAppId,ids);
+        List<InstallInfo> installInfos = installInfoMapper.selectList(wrapper);
+
+        Map<Integer, List<InstallInfo>> collect = installInfos.stream()
+                .collect(Collectors.groupingBy(InstallInfo::getAppId));
+        //
+        for (AppInfo info : records) {
+            info.setIsStar(collect.get(info.getId().intValue()) != null ? 1: 0);
+        }
+
+        return appInfoPage;
+    }
 
     /*
      * 安装应用

+ 34 - 0
src/main/java/com/dragon/tj/portal/service/impl/BusinessServiceImpl.java

@@ -28,6 +28,7 @@ import java.time.LocalDateTime;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 @Service
 public class BusinessServiceImpl implements BusinessService {
@@ -133,9 +134,42 @@ public class BusinessServiceImpl implements BusinessService {
 
         rowPage.addOrder(OrderItem.desc(businessInfoPage.getOrder()));
 
+        if (businessInfo.getIsStar() != null && businessInfo.getIsStar() == 1){
+            Page<BusinessInfo> businessInfoPage1 = businessMapper.selectPage(rowPage, queryWrapper);
+
+            return checkFavorites(businessInfoPage1);
+        }
+
         return businessMapper.selectPage(rowPage, queryWrapper);
     }
 
+    /*
+     * 热门应用是否收藏
+     * */
+    private Page<BusinessInfo> checkFavorites(Page<BusinessInfo> businessInfoPage){
+        List<BusinessInfo> records = businessInfoPage.getRecords();
+        List<Long> ids = records.stream().map(BusinessInfo::getId).collect(Collectors.toList());
+        if (ids.size() == 0){
+            return businessInfoPage;
+        }
+        LambdaQueryWrapper<InstallInfo> wrapper = new LambdaQueryWrapper<>();
+        wrapper.select(InstallInfo::getBusinessId);
+        wrapper.ne(InstallInfo::getBusinessId,0);
+        wrapper.eq(SecurityUtils.getLoginUser() != null,
+                InstallInfo::getUserIdcard,SecurityUtils.getLoginUser().getIdCard());
+        wrapper.in(InstallInfo::getBusinessId,ids);
+        List<InstallInfo> installInfos = installInfoMapper.selectList(wrapper);
+
+        Map<Integer, List<InstallInfo>> collect = installInfos.stream()
+                .collect(Collectors.groupingBy(InstallInfo::getBusinessId));
+
+        for (BusinessInfo info : records) {
+            info.setIsStar(collect.get(info.getId().intValue()) != null ? 1: 0);
+        }
+
+        return businessInfoPage;
+    }
+
 
     /*
      * 安装业务