From 5bb475d48559ded3ac78d09599f74d38bfcc7f38 Mon Sep 17 00:00:00 2001
From: phpcjl <phpcjl@gmail.com>
Date: 星期二, 17 十二月 2024 11:09:50 +0800
Subject: [PATCH] 1

---
 ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/UserPointServiceImpl.java |   83 +++++++++++++++------------
 ruoyi-service/ruoyi-account/src/main/resources/mapper/account/UserPointMapper.xml                  |    4 
 ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java         |    4 +
 ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/UserPointController.java    |   19 +++++-
 ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/vo/CommissionStatistics.java           |   18 ++++++
 ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/GoodsServiceImpl.java         |   11 +++
 6 files changed, 94 insertions(+), 45 deletions(-)

diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/UserPointController.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/UserPointController.java
index fcd824e..708193d 100644
--- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/UserPointController.java
+++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/UserPointController.java
@@ -1,13 +1,12 @@
 package com.ruoyi.account.controller;
 
 
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.ruoyi.account.api.model.AppUser;
 import com.ruoyi.account.api.model.UserPoint;
 import com.ruoyi.account.service.AppUserService;
 import com.ruoyi.account.service.UserPointService;
+import com.ruoyi.account.vo.CommissionStatistics;
 import com.ruoyi.account.vo.UserPointDetailVO;
 import com.ruoyi.account.vo.UserPointStatistics;
 import com.ruoyi.account.vo.UserPointVO;
@@ -21,7 +20,6 @@
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 import org.springframework.format.annotation.DateTimeFormat;
-import org.springframework.util.CollectionUtils;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
@@ -146,6 +144,21 @@
         util.exportExcel(response, userPointList, "用户积分统计");
     }
 
+    /**
+     * 用户分佣统计
+     */
+    @GetMapping("/commissionStatistics")
+    @ApiOperation(value = "用户分佣统计", tags = "管理后台-财务统计-用户分佣统计")
+    public R<CommissionStatistics> commissionStatistics(UserPoint userPoint) {
+        userPoint.setType(2);
+        IPage<UserPoint> userPointPage = userPointService.getUserPointPage(Page.of(userPoint.getPageNum(), userPoint.getPageSize()), userPoint);
+        UserPointStatistics statistics = userPointService.getStatistics(userPoint);
+        CommissionStatistics commissionStatistics = new CommissionStatistics();
+        commissionStatistics.setStatistics(statistics);
+        commissionStatistics.setUserPointPage(userPointPage);
+        return R.ok(commissionStatistics);
+    }
+
 
 }
 
diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/UserPointServiceImpl.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/UserPointServiceImpl.java
index 2e58044..5751140 100644
--- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/UserPointServiceImpl.java
+++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/UserPointServiceImpl.java
@@ -163,47 +163,56 @@
 
     @Override
     public UserPointStatistics getStatistics(UserPoint userPoint) {
+        try {
+            if (StringUtils.isNotEmpty(userPoint.getUserName()) && StringUtils.isNotEmpty(userPoint.getPhone())) {
+                List<Long> userIds = appUserService.listObjs(new LambdaQueryWrapper<AppUser>()
+                                .select(AppUser::getId)
+                                .like(AppUser::getName, userPoint.getUserName())
+                                .like(AppUser::getPhone, userPoint.getPhone()))
+                        .stream()
+                        .map(appUserId -> (Long) appUserId)
+                        .collect(Collectors.toList());
+                userPoint.setUserIds(userIds);
+            }
 
-        if (StringUtils.isNotEmpty(userPoint.getUserName()) || StringUtils.isNotEmpty(userPoint.getPhone())) {
-            List<Long> userIds = appUserService.listObjs(new LambdaQueryWrapper<AppUser>()
-                            .select(AppUser::getId)
-                            .like(StringUtils.isNotEmpty(userPoint.getUserName()),AppUser::getName, userPoint.getUserName())
-                            .like(StringUtils.isNotEmpty(userPoint.getPhone()),AppUser::getPhone, userPoint.getPhone()))
-                    .stream()
-                    .map(appUserId -> (Long) appUserId)
-                    .collect(Collectors.toList());
-            userPoint.setUserIds(userIds);
+            List<UserPoint> userPointList = userPointMapper.findLatestChangeByType(userPoint);
+
+            Map<Integer, Integer> userBalanceMap = userPointList.stream()
+                    .collect(Collectors.groupingBy(
+                            UserPoint::getType,
+                            Collectors.summingInt(UserPoint::getBalance)
+                    ));
+
+            int consumePoint = userBalanceMap.getOrDefault(PointChangeType.CONSUME.getCode(), 0);
+            int sharePoint = userBalanceMap.getOrDefault(PointChangeType.COMMISSION_RETURN.getCode(), 0);
+            int pullNewPoint = userBalanceMap.getOrDefault(PointChangeType.NEW_USER_REFERRAL.getCode(), 0);
+            int registerPoint = userBalanceMap.getOrDefault(PointChangeType.REGISTRATION.getCode(), 0);
+            int workPoint = userBalanceMap.getOrDefault(PointChangeType.WORK_PERFORMANCE.getCode(), 0);
+            int shopAchievementPoint = userBalanceMap.getOrDefault(PointChangeType.TECHNICIAN_PERFORMANCE.getCode(), 0);
+            int exchangeGoodsPoint = userBalanceMap.getOrDefault(PointChangeType.EXCHANGE_GOODS.getCode(), 0);
+            int storeAchievementPoint = userBalanceMap.getOrDefault(PointChangeType.STORE_PERFORMANCE.getCode(), 0);
+            int storeCommissionPoint = userBalanceMap.getOrDefault(PointChangeType.STORE_COMMISSION_RETURN.getCode(), 0);
+            int transferPoint = userBalanceMap.getOrDefault(PointChangeType.TRANSFER_POINTS.getCode(), 0);
+            int totalPoint = consumePoint + sharePoint + pullNewPoint + registerPoint + workPoint + shopAchievementPoint + exchangeGoodsPoint + storeAchievementPoint + storeCommissionPoint + transferPoint;
+
+            UserPointStatistics userPointStatistics = new UserPointStatistics();
+            userPointStatistics.setTotalPoint(totalPoint);
+            userPointStatistics.setConsumePoint(consumePoint);
+            userPointStatistics.setSharePoint(sharePoint);
+            userPointStatistics.setPullNewPoint(pullNewPoint);
+            userPointStatistics.setRegisterPoint(registerPoint);
+            userPointStatistics.setWorkPoint(workPoint);
+            userPointStatistics.setShopAchievementPoint(shopAchievementPoint);
+
+            return userPointStatistics;
+        } catch (Exception e) {
+            // 记录异常日志
+            log.error("获取用户点统计信息时出错", e);
+            throw new RuntimeException("获取用户点统计信息时出错", e);
         }
-
-        List<UserPoint> userPointList = userPointMapper.findLatestChangeByType(userPoint);
-        Map<Integer, Integer> userBalanceMap = userPointList.stream()
-                .collect(Collectors.toMap(UserPoint::getType, UserPoint::getBalance));
-
-
-        Integer consumePoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.CONSUME.getCode())).orElse(0);
-        Integer sharePoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.COMMISSION_RETURN.getCode())).orElse(0);
-        Integer pullNewPoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.NEW_USER_REFERRAL.getCode())).orElse(0);
-        Integer registerPoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.REGISTRATION.getCode())).orElse(0);
-        Integer workPoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.WORK_PERFORMANCE.getCode())).orElse(0);
-        Integer shopAchievementPoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.TECHNICIAN_PERFORMANCE.getCode())).orElse(0);
-        Integer exchangeGoodsPoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.EXCHANGE_GOODS.getCode())).orElse(0);
-        Integer storeAchievementPoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.STORE_PERFORMANCE.getCode())).orElse(0);
-        Integer storeCommissionPoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.STORE_COMMISSION_RETURN.getCode())).orElse(0);
-        Integer transferPoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.TRANSFER_POINTS.getCode())).orElse(0);
-        Integer totalPoint = consumePoint + sharePoint + pullNewPoint + registerPoint + workPoint + shopAchievementPoint + exchangeGoodsPoint + storeAchievementPoint + storeCommissionPoint + transferPoint;
-
-
-        UserPointStatistics userPointStatistics = new UserPointStatistics();
-        userPointStatistics.setTotalPoint(totalPoint);
-        userPointStatistics.setConsumePoint(consumePoint);
-        userPointStatistics.setSharePoint(sharePoint);
-        userPointStatistics.setPullNewPoint(pullNewPoint);
-        userPointStatistics.setRegisterPoint(registerPoint);
-        userPointStatistics.setWorkPoint(workPoint);
-        userPointStatistics.setShopAchievementPoint(shopAchievementPoint);
-        return userPointStatistics;
     }
 
+
     @Override
     public IPage<UserPoint> getUserPointPage(Page<UserPoint> page, UserPoint userPoint) {
         List<AppUser> appUserList = appUserService.list(new LambdaQueryWrapper<AppUser>()
diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/vo/CommissionStatistics.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/vo/CommissionStatistics.java
new file mode 100644
index 0000000..720a03b
--- /dev/null
+++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/vo/CommissionStatistics.java
@@ -0,0 +1,18 @@
+package com.ruoyi.account.vo;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.ruoyi.account.api.model.UserPoint;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@ApiModel(description = "用户分佣统计响应")
+@Data
+public class CommissionStatistics {
+
+    @ApiModelProperty(value = "统计数据", required = true)
+    private UserPointStatistics statistics;
+
+    @ApiModelProperty(value = "分页数据", required = true)
+    private IPage<UserPoint> userPointPage;
+}
diff --git a/ruoyi-service/ruoyi-account/src/main/resources/mapper/account/UserPointMapper.xml b/ruoyi-service/ruoyi-account/src/main/resources/mapper/account/UserPointMapper.xml
index c045836..a0314df 100644
--- a/ruoyi-service/ruoyi-account/src/main/resources/mapper/account/UserPointMapper.xml
+++ b/ruoyi-service/ruoyi-account/src/main/resources/mapper/account/UserPointMapper.xml
@@ -47,7 +47,7 @@
                      create_time,
                      app_user_id,
                      object_id,
-                     ROW_NUMBER() OVER (PARTITION BY type ORDER BY create_time DESC) AS rn
+                     ROW_NUMBER() OVER (PARTITION BY `type`,app_user_id ORDER BY create_time DESC) AS rn
                  FROM
                      t_user_point
                  <where>
@@ -55,7 +55,7 @@
                              create_time BETWEEN #{startTime} AND #{endTime}
                          </if>
                          <if test="type != null">
-                             AND type = #{type}
+                             AND `type` = #{type}
                          </if>
                          <if test="userIds != null and userIds.size !=0">
                              AND app_user_id IN
diff --git a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java
index f68a9d5..c6c54c3 100644
--- a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java
+++ b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java
@@ -250,7 +250,9 @@
         String content = baseSetting.getContent();
         JSONObject jsonObject = JSONObject.parseObject(content);
         Long days = jsonObject.getLong("days");
-        commissionService.addToCommissionDelayQueue(order.getId(), LocalDateTime.now().plusDays(days));
+        if (days != null && days > 0){
+            commissionService.addToCommissionDelayQueue(order.getId(), LocalDateTime.now().plusDays(days));
+        }
     }
     
     
diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/GoodsServiceImpl.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/GoodsServiceImpl.java
index b080dee..b02d2b8 100644
--- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/GoodsServiceImpl.java
+++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/GoodsServiceImpl.java
@@ -277,8 +277,15 @@
         List<GoodsArea> goodsAreaList1 = new ArrayList<>();
         listMap.forEach((s, goodsAreas) -> {
             GoodsArea goodsArea = goodsAreas.get(0);
-            goodsArea.setGoodsAreaList(goodsAreas);
-            goodsAreaList1.add(goodsArea);
+            GoodsArea goodsArea1 = new GoodsArea();
+            goodsArea1.setProvinceCode(goodsArea.getProvinceCode());
+            goodsArea1.setCityCode(goodsArea.getCityCode());
+            goodsArea1.setDistrictsCode(goodsArea.getDistrictsCode());
+            goodsArea1.setProvince(goodsArea.getProvince());
+            goodsArea1.setCity(goodsArea.getCity());
+            goodsArea1.setDistricts(goodsArea.getDistricts());
+            goodsArea1.setGoodsAreaList(goodsAreas);
+            goodsAreaList1.add(goodsArea1);
         });
 
         goods.setGoodsAreaList(goodsAreaList1);

--
Gitblit v1.7.1