浏览代码

初始化

wujiefeng 9 月之前
父节点
当前提交
abf9f14119

+ 19 - 0
RewardClient/src/main/java/com/zhongshu/reward/client/model/InviteSuccessModel.java

@@ -0,0 +1,19 @@
+package com.zhongshu.reward.client.model;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+/**
+ * @author wjf
+ * @date 2024/8/13
+ */
+@Data
+public class InviteSuccessModel {
+
+    private String id;
+
+    private String userId;
+
+    private BigDecimal totalAmount;
+}

+ 15 - 3
RewardServer/src/main/java/com/zhongshu/reward/server/core/controller/wallet/InviteController.java

@@ -3,6 +3,7 @@ package com.zhongshu.reward.server.core.controller.wallet;
 import com.github.microservice.auth.security.annotations.ResourceAuth;
 import com.github.microservice.auth.security.type.AuthType;
 import com.zhongshu.reward.server.core.domain.WalletReceipts;
+import com.zhongshu.reward.server.core.service.StatisticsService;
 import com.zhongshu.reward.server.core.service.WalletReceiptsService;
 import io.swagger.annotations.Api;
 import io.swagger.v3.oas.annotations.Operation;
@@ -10,6 +11,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 /**
@@ -26,10 +28,20 @@ public class InviteController {
     @Autowired
     WalletReceiptsService walletReceiptsService;
 
+    @Autowired
+    StatisticsService statisticsService;
+
     @Operation(summary = "邀请奖励明细", description = "邀请奖励明细")
     @ResourceAuth(value = "user", type = AuthType.User)
-    @GetMapping(value = "inviteDetail")
-    public Object receiptsDetail(Integer year, Integer month){
-        return walletReceiptsService.receiptsDetail(year, month);
+    @GetMapping(value = "rewardDetailList")
+    public Object rewardDetailList(@RequestParam("year") Integer year, @RequestParam("month") Integer month){
+        return walletReceiptsService.rewardDetail(year, month);
+    }
+
+    @Operation(summary = "我的邀请", description = "我的邀请")
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @GetMapping(value = "myInvite")
+    public Object myInvite(){
+        return statisticsService.myInvite();
     }
 }

+ 1 - 1
RewardServer/src/main/java/com/zhongshu/reward/server/core/controller/wallet/WalletController.java

@@ -64,7 +64,7 @@ public class WalletController {
         return walletReceiptsService.listByWallet();
     }
 
-    @Operation(summary = "查询即将到账详情", description = "查询即将到账详情")
+    @Operation(summary = "即将到账详情", description = "邀请奖励明细")
     @ResourceAuth(value = "user", type = AuthType.User)
     @GetMapping (value = "receiptsDetail")
     public Object receiptsDetail(String receiptsId){

+ 24 - 0
RewardServer/src/main/java/com/zhongshu/reward/server/core/dao/Impl/WalletReceiptsDaoImpl.java

@@ -1,14 +1,19 @@
 package com.zhongshu.reward.server.core.dao.Impl;
 
+import com.zhongshu.reward.client.model.InviteSuccessModel;
+import com.zhongshu.reward.client.model.TotalStatisticsModel;
 import com.zhongshu.reward.client.type.ReceiptsStatus;
 import com.zhongshu.reward.client.type.ReceiptsType;
 import com.zhongshu.reward.server.core.dao.WalletReceiptsDao;
 import com.zhongshu.reward.server.core.dao.extend.WalletReceiptsDaoExtend;
 import com.zhongshu.reward.server.core.domain.WalletReceipts;
 import org.apache.commons.lang3.StringUtils;
+import org.hibernate.query.criteria.internal.compile.CriteriaCompiler;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Sort;
 import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.data.mongodb.core.aggregation.Aggregation;
+import org.springframework.data.mongodb.core.aggregation.AggregationResults;
 import org.springframework.data.mongodb.core.query.Criteria;
 import org.springframework.data.mongodb.core.query.Query;
 
@@ -61,4 +66,23 @@ public class WalletReceiptsDaoImpl implements WalletReceiptsDaoExtend {
 
         return mongoTemplate.find(query, WalletReceipts.class);
     }
+
+    @Override
+    public List<InviteSuccessModel> myInvite(String userId) {
+        Criteria criteria = new Criteria();
+        criteria.and("inviteUserId").is(userId);
+        criteria.and("status").in(List.of(ReceiptsStatus.WAIT, ReceiptsStatus.RECEIPTS));
+
+        Aggregation aggregation = Aggregation.newAggregation(
+                Aggregation.match(criteria),
+//                Aggregation.project("_id","amountTotal"),
+                Aggregation.group("userId").sum("total").as("totalAmount"),
+                Aggregation.project().and("_id").as("userId").and("totalAmount").as("totalAmount")
+//                Aggregation.group("tradeType").last("tradeType").as("_id")
+        );
+
+
+        AggregationResults<InviteSuccessModel> groupList = mongoTemplate.aggregate(aggregation, WalletReceipts.class, InviteSuccessModel.class);
+        return groupList.getMappedResults();
+    }
 }

+ 2 - 0
RewardServer/src/main/java/com/zhongshu/reward/server/core/dao/InviteRecordDao.java

@@ -14,4 +14,6 @@ public interface InviteRecordDao extends MongoDao<InviteRecord>, InviteRecordDao
 
     InviteRecord findTopByUserIdOrderByCreateTime(String userId);
 
+    Integer countByInviteUserId(String inviteUserId);
+
 }

+ 3 - 0
RewardServer/src/main/java/com/zhongshu/reward/server/core/dao/extend/WalletReceiptsDaoExtend.java

@@ -1,5 +1,6 @@
 package com.zhongshu.reward.server.core.dao.extend;
 
+import com.zhongshu.reward.client.model.InviteSuccessModel;
 import com.zhongshu.reward.server.core.domain.WalletReceipts;
 
 import java.util.List;
@@ -13,4 +14,6 @@ public interface WalletReceiptsDaoExtend {
     List<WalletReceipts> inviteDetail(String inviteUserId, Long startTime, Long endTime);
 
     List<WalletReceipts> listMonth(Long startTime, Long endTime);
+
+    List<InviteSuccessModel> myInvite(String userId);
 }

+ 44 - 0
RewardServer/src/main/java/com/zhongshu/reward/server/core/service/StatisticsService.java

@@ -0,0 +1,44 @@
+package com.zhongshu.reward.server.core.service;
+
+import com.github.microservice.auth.security.helper.AuthHelper;
+import com.github.microservice.core.util.iterator.IteratorUtil;
+import com.zhongshu.reward.client.model.InviteSuccessModel;
+import com.zhongshu.reward.client.ret.ResultContent;
+import com.zhongshu.reward.server.core.dao.InviteRecordDao;
+import com.zhongshu.reward.server.core.dao.WalletReceiptsDao;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+/**
+ * @author wjf
+ * @date 2024/8/13
+ */
+@Service
+public class StatisticsService {
+
+    @Autowired
+    AuthHelper authHelper;
+
+    @Autowired
+    InviteRecordDao inviteRecordDao;
+
+    @Autowired
+    WalletReceiptsDao walletReceiptsDao;
+
+    public Object myInvite(){
+        String userId = authHelper.getCurrentUser().getUserId();
+        Integer inviteCount = inviteRecordDao.countByInviteUserId(userId);
+        List<InviteSuccessModel> inviteSuccessModels = walletReceiptsDao.myInvite(userId);
+        BigDecimal totalAmount = BigDecimal.ZERO;
+        if (!inviteSuccessModels.isEmpty()){
+            totalAmount = inviteSuccessModels.stream().map(InviteSuccessModel::getTotalAmount).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
+        }
+        return ResultContent.buildContent(Map.of("inviteCount", inviteCount, "success", inviteSuccessModels.size(), "totalAmount", totalAmount));
+    }
+}

+ 1 - 1
RewardServer/src/main/java/com/zhongshu/reward/server/core/service/WalletReceiptsService.java

@@ -180,7 +180,7 @@ public class WalletReceiptsService {
         return ResultContent.buildContent(vipUserModel);
     }
 
-    public Object receiptsDetail(Integer year, Integer month){
+    public Object rewardDetail(Integer year, Integer month){
         String userId = authHelper.getCurrentUser().getUserId();
         Long monthStartTime = DateUtils.getMonthStartTime(year, month);
         Long monthEndTime = DateUtils.getMonthEndTime(year, month);