From dbcaaa33fdd45c704fd40926df0a542556e8e4f2 Mon Sep 17 00:00:00 2001
From: 刘帅 <rr.iii@qq.com>
Date: 星期五, 18 九月 2026 17:15:09 +0800
Subject: [PATCH] feat:门店店长手机号列表展示问题

---
 cloud-server-competition/src/main/java/com/dsh/competition/controller/CompetitionController.java |  211 +++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 140 insertions(+), 71 deletions(-)

diff --git a/cloud-server-competition/src/main/java/com/dsh/competition/controller/CompetitionController.java b/cloud-server-competition/src/main/java/com/dsh/competition/controller/CompetitionController.java
index 208c8bc..2dbded4 100644
--- a/cloud-server-competition/src/main/java/com/dsh/competition/controller/CompetitionController.java
+++ b/cloud-server-competition/src/main/java/com/dsh/competition/controller/CompetitionController.java
@@ -3,6 +3,7 @@
 
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.poi.excel.ExcelUtil;
+import cn.mb.cloud.common.core.exception.BusinessException;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -139,20 +140,6 @@
             List<Integer> operatorId = cttService.list(new QueryWrapper<Competition>()
                     .eq("operatorId", operatorId1)).stream().map(Competition::getId).collect(Collectors.toList());
             query.setUserIds(operatorId);
-        } else if (query.getStoreId() != null) {
-            List<Competition> list = cttService.list(new QueryWrapper<Competition>());
-            List<Integer> integers = new ArrayList<>();
-            for (Competition competition : list) {
-                for (String s : competition.getStoreId().split(",")) {
-                    if (s.equals(""+query.getStoreId())){
-                        integers.add(competition.getId());
-                    }
-                }
-            }
-            if (integers.isEmpty()){
-                integers.add(-1);
-            }
-            query.setUserIds(integers);
         }
         List<PaymentCompetition> paymentCompetitions = paymentCompetitionService.listAll(query);
         List<PaymentCompetition> result = new ArrayList<>();
@@ -171,17 +158,7 @@
             }
             return result;
         } else if (query.getStoreId() != null) {
-            for (PaymentCompetition paymentCompetition : paymentCompetitions) {
-                Integer competitionId = paymentCompetition.getCompetitionId();
-                Competition byId = cttService.getById(competitionId);
-                if (byId != null) {
-                    String storeId = byId.getStoreId();
-                    if (storeId.contains(query.getStoreId().toString())) {
-                        result.add(paymentCompetition);
-                    }
-                }
-            }
-            return result;
+            return paymentCompetitions;
         }
         return paymentCompetitions;
     }
@@ -769,7 +746,8 @@
                 wrapper.ne(Competition::getAuditStatus,2);
             }
             wrapper.in(Competition::getStoreId,listQuery.getIds());
-            wrapper.orderByDesc(Competition::getInsertTime);
+            wrapper.orderByDesc(Competition::getInsertTime)
+                    .orderByDesc(Competition::getId);
             Page<Competition> page = cttService.page(competitionPage, wrapper);
             for (Competition record : page.getRecords()) {
                 // 查询当前赛事有多少人报名了
@@ -812,7 +790,8 @@
             integers.add(1);
             integers.add(3);
             wrapper.in(Competition::getAuditStatus, integers);
-            wrapper.orderByDesc(Competition::getInsertTime);
+            wrapper.orderByDesc(Competition::getInsertTime)
+                    .orderByDesc(Competition::getId);
 
             Page<Competition> page = cttService.page(competitionPage, wrapper);
             return page;
@@ -861,41 +840,14 @@
         }
     }
 
+    /**
+     * 更新活动配置。
+     *
+     * @param competition 管理端提交的活动信息
+     */
     @PostMapping("/base/competition/update")
-    public void update(@RequestBody Competition competition) {
-        try {
-            if (competition.getStartTime().after(new Date())) {
-                competition.setStatus(1);
-            }
-            if (competition.getStartTime().before(new Date())) {
-                if (competition.getEndTime().after(new Date())) {
-                    competition.setStatus(2);
-                } else {
-                    competition.setStatus(3);
-                }
-
-                if(competition.getStatus() == 2){
-                    //添加勋章数据
-                    List<PaymentCompetition> list = paymentCompetitionService.list(new QueryWrapper<PaymentCompetition>()
-                            .eq("competitionId", competition.getId()).eq("payStatus", 2).eq("state", 1));
-                    Set<Integer> collect = list.stream().map(PaymentCompetition::getAppUserId).collect(Collectors.toSet());
-                    for (Integer integer : collect) {
-                        int count = paymentCompetitionService.count(new QueryWrapper<PaymentCompetition>()
-                                .eq("appUserId", integer).eq("payStatus", 2).eq("state", 1));
-                        StudentHonor studentHonor = new StudentHonor();
-                        studentHonor.setAppUserId(integer);
-                        studentHonor.setHonorType(2);
-                        studentHonor.setNumber(count);
-                        studentHonorClient.saveStudentHonor(studentHonor);
-                    }
-                }
-            }
-            cttService.updateById(competition);
-
-
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
+    public void update(@RequestBody Competition competition) throws BusinessException {
+        cttService.updateCompetition(competition);
     }
 
     @Resource
@@ -1060,10 +1012,11 @@
         if (ToolUtil.isNotEmpty(data)) {
             String stime = data.split(" - ")[0] + " 00:00:00";
             String etime = data.split(" - ")[1] + " 23:59:59";
-            vipPaymentLambdaQueryWrapper.between(PaymentCompetition::getInsertTime, stime, etime);
+            vipPaymentLambdaQueryWrapper.between(PaymentCompetition::getPayTime, stime, etime);
         }
         vipPaymentLambdaQueryWrapper.in(PaymentCompetition::getCompetitionId, ids);
         vipPaymentLambdaQueryWrapper.eq(PaymentCompetition::getPayStatus, 2);
+        vipPaymentLambdaQueryWrapper.eq(PaymentCompetition::getState, 1);
         ArrayList<Integer> objects = new ArrayList<>();
         objects.add(1);
         objects.add(2);
@@ -1142,13 +1095,11 @@
         // 年
         ArrayList<Integer> years = new ArrayList<>();
         ArrayList<Integer> yearsUser = new ArrayList<>();
-        Integer operatorId = vo.getOperatorId();
-        List<Integer> operatorId1 = cttService.list(new QueryWrapper<Competition>().eq("operatorId", operatorId))
-                .stream().map(Competition::getId).collect(Collectors.toList());
         for (Object o : collect) {
             String s = o.toString();
-            int count = cttService.count(new LambdaQueryWrapper<Competition>().like(Competition::getInsertTime, s).eq(Competition::getOperatorId, vo.getOperatorId()));
-            int count1 = ucttService.count(new LambdaQueryWrapper<UserCompetition>().in(UserCompetition::getAppUserId, vo.getIds()).like(UserCompetition::getInsertTime, s));
+            List<Integer> competitionIds = listCompetitionIds(vo, s);
+            int count = competitionIds.size();
+            int count1 = countUserCompetitions(vo, s, competitionIds);
             years.add(count);
             yearsUser.add(count1);
         }
@@ -1166,8 +1117,9 @@
                 m = "0" + i;
             }
             String s = year + "-" + m;
-            int count = cttService.count(new LambdaQueryWrapper<Competition>().like(Competition::getInsertTime, s).eq(Competition::getOperatorId, operatorId));
-            int count1 = ucttService.count(new LambdaQueryWrapper<UserCompetition>().in(UserCompetition::getAppUserId, vo.getIds()).like(UserCompetition::getInsertTime, s));
+            List<Integer> competitionIds = listCompetitionIds(vo, s);
+            int count = competitionIds.size();
+            int count1 = countUserCompetitions(vo, s, competitionIds);
             months.add(count);
             monthsUser.add(count1);
         }
@@ -1177,11 +1129,129 @@
         return map;
     }
 
+    /** 门店活动统计:仅统计指定门店的赛事及其报名记录。 */
+    @ResponseBody
+    @PostMapping("/base/competition/actStore")
+    public HashMap<String, Object> actStore(@RequestBody CompetionVO vo) {
+        HashMap<String, Object> map = new HashMap<>();
+        if (vo.getStoreIds() == null || vo.getStoreIds().isEmpty()) {
+            vo.setStoreIds(Collections.singletonList(-1));
+        }
+        ArrayList<Integer> years = new ArrayList<>();
+        ArrayList<Integer> yearsUser = new ArrayList<>();
+        int year = DateUtil.year(new Date());
+        for (int statisticYear = year - 9; statisticYear <= year; statisticYear++) {
+            String dateText = String.valueOf(statisticYear);
+            List<Integer> competitionIds = listStoreCompetitionIds(vo, dateText);
+            years.add(competitionIds.size());
+            yearsUser.add(countStoreUserCompetitions(dateText, competitionIds));
+        }
+        map.put("yearData", years);
+        map.put("yearsUser", yearsUser);
+
+        ArrayList<Integer> months = new ArrayList<>();
+        ArrayList<Integer> monthsUser = new ArrayList<>();
+        for (int month = 1; month <= 12; month++) {
+            String dateText = String.format("%d-%02d", year, month);
+            List<Integer> competitionIds = listStoreCompetitionIds(vo, dateText);
+            months.add(competitionIds.size());
+            monthsUser.add(countStoreUserCompetitions(dateText, competitionIds));
+        }
+        map.put("monthData", months);
+        map.put("monthsUser", monthsUser);
+        return map;
+    }
+
+    private List<Integer> listCompetitionIds(CompetionVO vo, String dateText) {
+        return cttService.list(buildCompetitionCountWrapper(vo, dateText))
+                .stream()
+                .map(Competition::getId)
+                .collect(Collectors.toList());
+    }
+
+    private List<Integer> listStoreCompetitionIds(CompetionVO vo, String dateText) {
+        Set<String> storeIds = vo.getStoreIds().stream()
+                .filter(Objects::nonNull)
+                .map(String::valueOf)
+                .collect(Collectors.toSet());
+        return cttService.list(new LambdaQueryWrapper<Competition>()
+                        .like(Competition::getInsertTime, dateText))
+                .stream()
+                .filter(competition -> containsStoreId(competition.getStoreId(), storeIds))
+                .map(Competition::getId)
+                .collect(Collectors.toList());
+    }
+
+    private boolean containsStoreId(String competitionStoreIds, Set<String> storeIds) {
+        if (competitionStoreIds == null || competitionStoreIds.trim().isEmpty()) {
+            return false;
+        }
+        return Arrays.stream(competitionStoreIds.split(","))
+                .map(String::trim)
+                .anyMatch(storeIds::contains);
+    }
+
+    private int countStoreUserCompetitions(String dateText, List<Integer> competitionIds) {
+        if (competitionIds.isEmpty()) {
+            return 0;
+        }
+        return ucttService.count(new LambdaQueryWrapper<UserCompetition>()
+                .in(UserCompetition::getCompetitionId, competitionIds)
+                .like(UserCompetition::getInsertTime, dateText));
+    }
+
+    private int countUserCompetitions(CompetionVO vo, String dateText, List<Integer> competitionIds) {
+        if (competitionIds.isEmpty()) {
+            return 0;
+        }
+        return ucttService.count(new LambdaQueryWrapper<UserCompetition>()
+                .in(UserCompetition::getAppUserId, vo.getIds())
+                .in(UserCompetition::getCompetitionId, competitionIds)
+                .like(UserCompetition::getInsertTime, dateText));
+    }
+
+    private LambdaQueryWrapper<Competition> buildCompetitionCountWrapper(CompetionVO vo, String dateText) {
+        LambdaQueryWrapper<Competition> wrapper = new LambdaQueryWrapper<Competition>()
+                .like(Competition::getInsertTime, dateText);
+        // 平台统计由平台门店范围决定,历史平台赛事的 operatorId 可能为空或为 0。
+        if (vo.getOperatorId() != null && !Integer.valueOf(0).equals(vo.getOperatorId())) {
+            wrapper.eq(Competition::getOperatorId, vo.getOperatorId());
+        }
+        appendStoreIdFilter(wrapper, vo.getStoreIds());
+        return wrapper;
+    }
+
+    private void appendStoreIdFilter(LambdaQueryWrapper<Competition> wrapper, List<Integer> storeIds) {
+        if (storeIds == null || storeIds.isEmpty()) {
+            return;
+        }
+
+        List<Integer> validStoreIds = storeIds.stream()
+                .filter(Objects::nonNull)
+                .collect(Collectors.toList());
+        if (validStoreIds.isEmpty()) {
+            return;
+        }
+
+        wrapper.and(item -> {
+            item.apply("FIND_IN_SET({0}, storeId)", validStoreIds.get(0));
+            for (int i = 1; i < validStoreIds.size(); i++) {
+                item.or().apply("FIND_IN_SET({0}, storeId)", validStoreIds.get(i));
+            }
+        });
+    }
+
 
     @ResponseBody
     @PostMapping("/base/competition/queryAppUserId")
     public List<Integer> queryAppUserId(@RequestBody List<Integer> storeIds){
-        List<Competition> list = competitionService.list(new QueryWrapper<Competition>().in("storeId", storeIds).eq("auditStatus", 2).eq("state", 1));
+        if (storeIds == null || storeIds.isEmpty()) {
+            return new ArrayList<>();
+        }
+        LambdaQueryWrapper<Competition> wrapper = new LambdaQueryWrapper<Competition>()
+                .eq(Competition::getAuditStatus, 2).eq(Competition::getState, 1);
+        appendStoreIdFilter(wrapper, storeIds);
+        List<Competition> list = competitionService.list(wrapper);
         List<Integer> collect = list.stream().map(Competition::getId).collect(Collectors.toList());
         if(collect.size() == 0){
             return new ArrayList<>();
@@ -1190,4 +1260,3 @@
         return list1.stream().map(PaymentCompetition::getAppUserId).collect(Collectors.toList());
     }
 }
-

--
Gitblit v1.7.1