From 87a05df04f99e0ede4e72262bb5fa8a676944ec5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=85=E6=88=BF?= Date: Tue, 30 Dec 2025 17:43:45 +0800 Subject: [PATCH] =?UTF-8?q?fix(registration):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=88=91=E7=9A=84=E6=8A=A5=E5=90=8D=E5=88=97=E8=A1=A8=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E6=98=BE=E7=A4=BA=E4=B8=8D=E5=85=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改list接口返回VO而非Entity - 添加getListWithRelations方法批量加载关联数据 - 返回赛事名称、地点、时间、项目名称、选手名称等完整信息 - 优化批量查询减少数据库访问次数 --- .../buckets/.bloomcycle.bin/xl.meta | Bin 743 -> 743 bytes .../buckets/.usage-cache.bin.bkp/xl.meta | Bin 629 -> 627 bytes .../buckets/.usage-cache.bin/xl.meta | Bin 629 -> 627 bytes .../.minio.sys/buckets/.usage.json/xl.meta | Bin 2358 -> 2359 bytes .../.usage-cache.bin.bkp/xl.meta | Bin 636 -> 636 bytes .../000000-assets/.usage-cache.bin/xl.meta | Bin 636 -> 636 bytes .../assets/.usage-cache.bin.bkp/xl.meta | Bin 575 -> 575 bytes .../buckets/assets/.usage-cache.bin/xl.meta | Bin 575 -> 575 bytes .../tmp/840ecd84-f68f-43d3-93e2-726006f15654 | Bin 2049 -> 0 bytes .../MartialRegistrationOrderController.java | 38 ++-- .../IMartialRegistrationOrderService.java | 12 ++ .../MartialRegistrationOrderServiceImpl.java | 166 ++++++++++++++++-- 12 files changed, 174 insertions(+), 42 deletions(-) delete mode 100644 minio_data/.minio.sys/tmp/840ecd84-f68f-43d3-93e2-726006f15654 diff --git a/minio_data/.minio.sys/buckets/.bloomcycle.bin/xl.meta b/minio_data/.minio.sys/buckets/.bloomcycle.bin/xl.meta index fab703355eb3cd34ef849d6fca9deab387af8676..dcf2ebf0fd1628ce1940ea4574eddc429fb19c67 100644 GIT binary patch delta 445 zcmaFP`kZxw2G5soos#GIjucM3>2}OSYFQtQ8V$6 zje=#WL2{B|im|0pl8J$#Wm1}niBWQ5qFI`eQA(1Dq2=TVM!ovWD{VO#8<*sj=Hwh@ z3{IL}Z&cb+F0%R5JU@e9*&0IoS(&bHob+ESaW_Y4?~D5jgc-n~WqERGQBi7M3B!`S z)QXa`!V8ucmn0UIq^2C_VFjtk44yYbRy3<*U2`1>-3aazxyo7J;M{o%a=jZB5ZoBK O{)aaZ+!=DMm2Uw(d6TdJ delta 445 zcmaFP`kZxw2G8V|8-v*QA7P2Ob!GEJ6Jr6-^dsjUI=QFL_`GI|Lujq@#PWJJh?w35ysiBC+{qpSRSW-U{ye3 zQHf)4W>sqO#ET3EmVj75dZ}+nW^U?biB^aq6aUyKSXvmGCz%_hrKY8rT9})sBpI0} zr5c(Tr6eaCq!}eAO^#sHGoO5Z))vObC3&SeIY%DEedSB{s+C)@{#sUgV$xU73teJy z=QsD6EbJ@H+AQ^theKnl{$CdcQHIvZdl_YAgy*mFNh~f2El5c$Nj=WP$^ZnJ!SiOw zXJEJz19E>bT2VHx@WN{zgUoojg^5#aG`$3qU4N8oD2avPREQGSTh~s6-tCo SXg2xi&bVis&enE0Aprnh6Krw- delta 277 zcmey&@|9(R2G8V|8x{Eu9bvID$-X_^OaL35Pee3w_sqO#ET4vmVj75dZ}+nW^U?biB^aq6aUyKq#329rWhs}q**4Ln;V;(r`1gp` z(TOsXzcD)5F4XT>l$F*g%4GXpa>7sCP$1(Tx}9D5iPQVw)- VER)#7adSIQ)%iJ+eCMV}0RTA&Y9;^x diff --git a/minio_data/.minio.sys/buckets/.usage-cache.bin/xl.meta b/minio_data/.minio.sys/buckets/.usage-cache.bin/xl.meta index 09a6aff62fd0cc3fc086f6594f89fa336a46173e..b5bca56aab576e9e591062c565513f3b1dacb042 100644 GIT binary patch delta 289 zcmey$@|k6V2G5so9S71D9${H|?eLa~CdLAHtFOpKt?}dBkooT7agjF%Czi*lA6ONT zSXAN|oLQAxJnVsS}m zK}upt>Tw=c1|Y}`o;O2I(?V?WH%2GxwFY3Idx_!EJ&Q&8#ez(1tPCuI3-vn|C1*_H hWC+l4I%dScn&}X)P$G0fv&lzy#y#V7wzkU&2>>NYcE`L z7MKLxYRvch`l44ym2Hj5p_WN|JWITp*9tjI;n3Ks|JQ{cm{>JEJyHLMlQF6wlwFY3Idx>G@T;)ai#oSEH%nZ!j lTnr016ikj@aO`1FNIB5Su}oqQ$Ib0LRp;kO@|~L^1pwFRb+P~e diff --git a/minio_data/.minio.sys/buckets/.usage.json/xl.meta b/minio_data/.minio.sys/buckets/.usage.json/xl.meta index 047eb41cae7194891c2060d7b40cacbe47afe0e7..36006bc8ab37f2773e6a1003d693e7ed0ceef3ca 100644 GIT binary patch delta 313 zcmdlcv|VU|2G5soozlu1kFea`6E%0DiLrnSw{n`ckITdPvrj$seP!A-u{=(_dsRSU zQHf)4W>sqO#Eb0ROF%3jz0@}(GdK0JL@UIQiGQN%jZH0+jm*+4OpTHaEt5{j_SNmHRs^;=T1B=BY0j}^5|iG~ z`%mY`q$h?MmhWEnactA7R?0~%E(tA2Ni0cKvQjcKFf!FOG}1LT2r;m7piBi&0%1_ElO)e>R&M(a?QL-{LpZtc=j@`t<%)-FPWU?VsES$~AEIoMx y({e`h$q~%POoqmjdzcFuO(y?imSr@XEW;wrXu8>gMUIilycTGL;pR@(wafs-J#F9s delta 312 zcmdlkv`uJ&2G8V|8-pDd9br)u(_K2z#8}|BHOtiaLd%5SRSX|wJIR7 zsKhZivnsWC;zjnZB_I}%Ug{f?nVWi9q7`Du#6MB>rbfnw=4M8TW=0mKDVApDMoG!0 z7Dhq3(L->C!J^La5{pYh3sMqGQkATfj0}uSbq$SljVwb9Oss&&$Ux8B z(A?D0K-|L6C`w63DL*MIHMykNIlnZoM9Ip~aPk{QJ9YyDpnHr>CmS-w!r6?>(vvqZ vEoU^G9KmeNXfe5$xscI#@_%MoASuft&1k&Yl0}Y@$*>k^g5l;a*0sz4S%Yuw diff --git a/minio_data/.minio.sys/buckets/000000-assets/.usage-cache.bin.bkp/xl.meta b/minio_data/.minio.sys/buckets/000000-assets/.usage-cache.bin.bkp/xl.meta index d97965cdd9f0ed5f65b655e4416a1cf696029a74..9af19a7b49739d28ea7c2a91cbf8d095e94e7eb4 100644 GIT binary patch delta 232 zcmeyv@`q)D2G5so9df5)kFW%;{mwDb#8{wslZ?=Y2VP=3Z`R8vbju`9EU#ySsG0c3 zbaDivTFjEvlEn0z3g$^hW~ru@$rfhjmKH`SNoMBB=9bAOMh51oCPtkUwmIot1!BC=HALT6U*z_AZjN5 zF;!oZT9TN4Qz6kHIWfuH&?Lps(!$)_IMKu+#oW@+(!eOm+}O;-AZ4;4qnhc$vUBN4 zry0)W@GI&vHZI94&B;0P(zcgjLh*g=4R&i)KRgs-`ncy*cXG4(BfrYiM=w6kz4c=9 zW=2C9L9SIkiNz(M1u2OosmFO(8Gs-&@b3{V+k>5xnAB8f&Q)HNU(CIzte9bON-mHn ft}33*z`(@J%)ks%yQnNAW2vAmuQqGsYB z8+r32BePUf%VY~Pb4v@Olq56rWOK`86C(rjR1+i9l*!?Y`nq=+rXOT%T#{FslXK+d zm4j&;6I4EbN}KuU&|xO`r*FOQII@0s(3a70}~r70}Dv)qOy$X Pf|I?ObXg9xKT!h!!TMJT delta 217 zcmeyv@`q)D2G8V|8`5%59bq|W8+UG^iLn63jmAyoTRaxE^Eoj}yHwOnEU#ySsG0c3 zMn2IXIWfuH&?Lps(!$)_IMKu+#oW@+(!eOm+}O;-U~)L4zV6@EzX})|m*kb^@U*+ke7a!-|dNFx3qoIr-*D9aH;*!vUl*E$M z<2u_lTD5!OlrcYN|8mDlf_}=3Z1*%&<5m7f2LW70+g1U}9!wU|O zHOAStyG;(LT;5r$5hceGdgyhu@9WL7`6B#x_wZLt$nu)JnNdqdc>XG%#Nv|Bf|SIP d)Z;v?3_y?>Ja2~V-N}J&H)wgD%iLrpov+0!!xE-uE8GkHW^yyFc#PWJJh?;nNdqdkZYAsVsS}mK}upt d>Tw=c1|Y}`{Ch-o_l5e&KN+1^Ha?Mv0RXU=NL>H` diff --git a/minio_data/.minio.sys/buckets/assets/.usage-cache.bin/xl.meta b/minio_data/.minio.sys/buckets/assets/.usage-cache.bin/xl.meta index 7e9d6bea004c04ec1d4bee7bc35862667a05e135..bda67500e4bacbb1f1a5dbf7c6378d1087d9dd2a 100644 GIT binary patch delta 177 zcmdnbvY%yw2G5so9VNFJkFdO78Fpx*iLt;-`8}$7GrZEF$bTY+RC8nv-*6 zjk^MSQc1eI5Uby|tw$C`1gqF?hEyke=<6;Y> list(MartialRegistrationOrder registrationOrder, Query query) { - // 获取当前登录用户ID + public R> list(MartialRegistrationOrder registrationOrder, Query query) { Long userId = AuthUtil.getUserId(); + Integer status = registrationOrder.getStatus(); - // 构建查询条件 - 只查询当前用户的订单 - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(MartialRegistrationOrder::getUserId, userId); - - // 如果传入了状态参数,添加状态过滤 - if (registrationOrder.getStatus() != null) { - queryWrapper.eq(MartialRegistrationOrder::getStatus, registrationOrder.getStatus()); - } - - // 按创建时间倒序 - queryWrapper.orderByDesc(MartialRegistrationOrder::getCreateTime); - - // 分页查询 - IPage page = new Page<>(query.getCurrent(), query.getSize()); - IPage pages = registrationOrderService.page(page, queryWrapper); + IPage pages = registrationOrderService.getListWithRelations( + userId, status, query.getCurrent(), query.getSize()); return R.data(pages); } /** * 提交报名订单 - * 接收前端传来的 athleteIds 和 projectIds,更新选手的 orderId */ @PostMapping("/submit") @Operation(summary = "提交报名", description = "提交报名订单并关联选手") @@ -92,7 +78,7 @@ public class MartialRegistrationOrderController extends BladeController { log.info("联系电话: {}", dto.getContactPhone()); log.info("总金额: {}", dto.getTotalAmount()); - // 1. 创建订单实体 + // Create order entity MartialRegistrationOrder order = new MartialRegistrationOrder(); order.setOrderNo(dto.getOrderNo()); order.setCompetitionId(dto.getCompetitionId()); @@ -101,11 +87,11 @@ public class MartialRegistrationOrderController extends BladeController { order.setUserId(AuthUtil.getUserId()); order.setUserName(AuthUtil.getUserName()); - // 解析选手ID列表 + // Parse athlete IDs List athleteIds = Func.toLongList(dto.getAthleteIds()); order.setTotalParticipants(athleteIds.size()); - // 2. 保存订单 + // Save order boolean saved = registrationOrderService.save(order); if (!saved) { return R.fail("创建订单失败"); @@ -114,18 +100,17 @@ public class MartialRegistrationOrderController extends BladeController { Long orderId = order.getId(); log.info("订单创建成功,订单ID: {}", orderId); - // 3. 解析项目ID列表 + // Parse project IDs List projectIds = Func.toLongList(dto.getProjectIds()); Long firstProjectId = projectIds.isEmpty() ? null : projectIds.get(0); - // 4. 更新选手的 orderId、competitionId 和 projectId + // Update athletes with orderId, competitionId and projectId if (!athleteIds.isEmpty()) { LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); updateWrapper.in(MartialAthlete::getId, athleteIds) .set(MartialAthlete::getOrderId, orderId) .set(MartialAthlete::getCompetitionId, dto.getCompetitionId()); - // 如果只有一个项目,设置项目ID if (firstProjectId != null) { updateWrapper.set(MartialAthlete::getProjectId, firstProjectId); } @@ -134,7 +119,6 @@ public class MartialRegistrationOrderController extends BladeController { log.info("更新选手关联,选手数量: {}, 更新结果: {}", athleteIds.size(), updated); } - // 5. 返回订单信息 return R.data(order); } diff --git a/src/main/java/org/springblade/modules/martial/service/IMartialRegistrationOrderService.java b/src/main/java/org/springblade/modules/martial/service/IMartialRegistrationOrderService.java index 4c6acd2..cb8a77d 100644 --- a/src/main/java/org/springblade/modules/martial/service/IMartialRegistrationOrderService.java +++ b/src/main/java/org/springblade/modules/martial/service/IMartialRegistrationOrderService.java @@ -1,5 +1,6 @@ package org.springblade.modules.martial.service; +import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.IService; import org.springblade.modules.martial.pojo.entity.MartialRegistrationOrder; import org.springblade.modules.martial.pojo.vo.MartialRegistrationOrderVO; @@ -19,4 +20,15 @@ public interface IMartialRegistrationOrderService extends IService getListWithRelations(Long userId, Integer status, Integer current, Integer size); + } diff --git a/src/main/java/org/springblade/modules/martial/service/impl/MartialRegistrationOrderServiceImpl.java b/src/main/java/org/springblade/modules/martial/service/impl/MartialRegistrationOrderServiceImpl.java index 8c58cef..af4cf32 100644 --- a/src/main/java/org/springblade/modules/martial/service/impl/MartialRegistrationOrderServiceImpl.java +++ b/src/main/java/org/springblade/modules/martial/service/impl/MartialRegistrationOrderServiceImpl.java @@ -1,6 +1,8 @@ package org.springblade.modules.martial.service.impl; 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.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.AllArgsConstructor; import org.springblade.modules.martial.pojo.entity.MartialAthlete; @@ -16,7 +18,9 @@ import org.springblade.modules.martial.service.IMartialRegistrationOrderService; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; /** @@ -34,40 +38,176 @@ public class MartialRegistrationOrderServiceImpl extends ServiceImpl getListWithRelations(Long userId, Integer status, Integer current, Integer size) { + // Build query + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(MartialRegistrationOrder::getUserId, userId); + if (status != null) { + queryWrapper.eq(MartialRegistrationOrder::getStatus, status); + } + queryWrapper.orderByDesc(MartialRegistrationOrder::getCreateTime); + + // Paginate + IPage page = new Page<>(current, size); + IPage orderPage = this.page(page, queryWrapper); + + // Convert to VO page + IPage voPage = new Page<>(current, size, orderPage.getTotal()); + + if (orderPage.getRecords().isEmpty()) { + voPage.setRecords(new ArrayList<>()); + return voPage; + } + + // Batch load competition info + List competitionIds = orderPage.getRecords().stream() + .map(MartialRegistrationOrder::getCompetitionId) + .filter(id -> id != null) + .distinct() + .collect(Collectors.toList()); + + Map competitionMap = competitionIds.isEmpty() ? + Map.of() : + competitionService.listByIds(competitionIds).stream() + .collect(Collectors.toMap(MartialCompetition::getId, c -> c)); + + // Batch load athletes by order IDs + List orderIds = orderPage.getRecords().stream() + .map(MartialRegistrationOrder::getId) + .collect(Collectors.toList()); + + LambdaQueryWrapper athleteWrapper = new LambdaQueryWrapper<>(); + athleteWrapper.in(MartialAthlete::getOrderId, orderIds); + List allAthletes = athleteService.list(athleteWrapper); + + Map> athletesByOrder = allAthletes.stream() + .collect(Collectors.groupingBy(MartialAthlete::getOrderId)); + + // Batch load projects + List projectIds = allAthletes.stream() + .map(MartialAthlete::getProjectId) + .filter(id -> id != null) + .distinct() + .collect(Collectors.toList()); + + Map projectMap = projectIds.isEmpty() ? + Map.of() : + projectService.listByIds(projectIds).stream() + .collect(Collectors.toMap(MartialProject::getId, p -> p)); + + // Convert each order to VO + List voList = orderPage.getRecords().stream() + .map(order -> { + MartialRegistrationOrderVO vo = new MartialRegistrationOrderVO(); + BeanUtils.copyProperties(order, vo); + + // Set competition info + MartialCompetition competition = competitionMap.get(order.getCompetitionId()); + if (competition != null) { + vo.setCompetitionName(competition.getCompetitionName()); + vo.setLocation(competition.getLocation()); + vo.setStartTime(competition.getCompetitionStartTime() != null ? + competition.getCompetitionStartTime().toString() : null); + vo.setEndTime(competition.getCompetitionEndTime() != null ? + competition.getCompetitionEndTime().toString() : null); + } + + // Set athlete info + List athletes = athletesByOrder.getOrDefault(order.getId(), new ArrayList<>()); + if (!athletes.isEmpty()) { + String athleteNames = athletes.stream() + .map(MartialAthlete::getPlayerName) + .collect(Collectors.joining("、")); + vo.setAthleteNames(athleteNames); + + List athleteList = athletes.stream() + .map(athlete -> { + MartialRegistrationOrderVO.AthleteInfo info = new MartialRegistrationOrderVO.AthleteInfo(); + info.setId(athlete.getId()); + info.setPlayerName(athlete.getPlayerName()); + info.setGender(athlete.getGender()); + info.setIdCard(athlete.getIdCard()); + return info; + }) + .collect(Collectors.toList()); + vo.setAthleteList(athleteList); + + // Set project info + List orderProjectIds = athletes.stream() + .map(MartialAthlete::getProjectId) + .filter(id -> id != null) + .distinct() + .collect(Collectors.toList()); + + if (!orderProjectIds.isEmpty()) { + List projects = orderProjectIds.stream() + .map(projectMap::get) + .filter(p -> p != null) + .collect(Collectors.toList()); + + String projectNames = projects.stream() + .map(MartialProject::getProjectName) + .collect(Collectors.joining("、")); + vo.setProjectNames(projectNames); + + List projectList = projects.stream() + .map(project -> { + MartialRegistrationOrderVO.ProjectInfo info = new MartialRegistrationOrderVO.ProjectInfo(); + info.setId(project.getId()); + info.setProjectName(project.getProjectName()); + Integer type = project.getType(); + info.setProjectType(type == 1 ? "个人" : "集体"); + return info; + }) + .collect(Collectors.toList()); + vo.setProjectList(projectList); + } + } + + return vo; + }) + .collect(Collectors.toList()); + + voPage.setRecords(voList); + return voPage; + } + + private MartialRegistrationOrderVO convertToVO(MartialRegistrationOrder order) { MartialRegistrationOrderVO vo = new MartialRegistrationOrderVO(); BeanUtils.copyProperties(order, vo); - // 获取赛事信息 + // Get competition info if (order.getCompetitionId() != null) { MartialCompetition competition = competitionService.getById(order.getCompetitionId()); if (competition != null) { vo.setCompetitionName(competition.getCompetitionName()); vo.setLocation(competition.getLocation()); - vo.setStartTime(competition.getCompetitionStartTime() != null ? competition.getCompetitionStartTime().toString() : null); - vo.setEndTime(competition.getCompetitionEndTime() != null ? competition.getCompetitionEndTime().toString() : null); + vo.setStartTime(competition.getCompetitionStartTime() != null ? + competition.getCompetitionStartTime().toString() : null); + vo.setEndTime(competition.getCompetitionEndTime() != null ? + competition.getCompetitionEndTime().toString() : null); } } - // 获取该订单的所有选手 + // Get athletes for this order LambdaQueryWrapper athleteWrapper = new LambdaQueryWrapper<>(); - athleteWrapper.eq(MartialAthlete::getOrderId, id); + athleteWrapper.eq(MartialAthlete::getOrderId, order.getId()); List athletes = athleteService.list(athleteWrapper); if (!athletes.isEmpty()) { - // 设置选手名称列表 String athleteNames = athletes.stream() .map(MartialAthlete::getPlayerName) .collect(Collectors.joining("、")); vo.setAthleteNames(athleteNames); - // 设置选手详细列表 List athleteList = athletes.stream() .map(athlete -> { MartialRegistrationOrderVO.AthleteInfo info = new MartialRegistrationOrderVO.AthleteInfo(); @@ -80,7 +220,7 @@ public class MartialRegistrationOrderServiceImpl extends ServiceImpl projectIds = athletes.stream() .map(MartialAthlete::getProjectId) .filter(projectId -> projectId != null) @@ -90,22 +230,18 @@ public class MartialRegistrationOrderServiceImpl extends ServiceImpl projects = projectService.listByIds(projectIds); - // 设置项目名称列表 String projectNames = projects.stream() .map(MartialProject::getProjectName) .collect(Collectors.joining("、")); vo.setProjectNames(projectNames); - // 设置项目详细列表 List projectList = projects.stream() .map(project -> { MartialRegistrationOrderVO.ProjectInfo info = new MartialRegistrationOrderVO.ProjectInfo(); info.setId(project.getId()); info.setProjectName(project.getProjectName()); - //类型(1-个人,2-双人,3-集体) Integer type = project.getType(); - String strType = type == 1 ? "个人":"集体"; - info.setProjectType(strType); + info.setProjectType(type == 1 ? "个人" : "集体"); return info; }) .collect(Collectors.toList());