|
@@ -3,6 +3,7 @@ package com.citu.module.promotion.service.luck;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
import com.baomidou.lock.annotation.Lock4j;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.citu.framework.common.pojo.PageResult;
|
|
|
import com.citu.framework.common.util.object.BeanUtils;
|
|
|
import com.citu.framework.mybatis.core.query.LambdaQueryWrapperX;
|
|
@@ -25,9 +26,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Random;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.ThreadLocalRandom;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -326,22 +325,55 @@ public class LuckLotteryRecordServiceImpl implements LuckLotteryRecordService {
|
|
|
|
|
|
@Override
|
|
|
public List<LuckLotteryRecordDetailRespVO> getByOrderId(Long orderId, Long userId) {
|
|
|
- List<LuckLotteryRecordDO> list = luckLotteryRecordMapper
|
|
|
- .selectList(LuckLotteryRecordDO::getOrderId, orderId);
|
|
|
- if (CollUtil.isEmpty(list)) {
|
|
|
- return null;
|
|
|
+ Map<Long, List<LuckLotteryRecordDetailRespVO>> resultMap = getByOrderId(Collections.singletonList(orderId), userId);
|
|
|
+ return resultMap.getOrDefault(orderId, Collections.emptyList());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<Long, List<LuckLotteryRecordDetailRespVO>> getByOrderId(List<Long> orderIds, Long userId) {
|
|
|
+ if (CollUtil.isEmpty(orderIds)) {
|
|
|
+ return Map.of();
|
|
|
}
|
|
|
- // 同一个订单下单的绝对只有一个用户
|
|
|
- UserInfoRespDTO user =
|
|
|
- mendunerUserApi.getUser(userId).getCheckedData();
|
|
|
- List<LuckLotteryRecordDetailRespVO> respList = new ArrayList<>();
|
|
|
- for (LuckLotteryRecordDO record : list) {
|
|
|
- respList.add(LuckLotteryRecordConvert.INSTANCE.convertDetail(
|
|
|
- LuckLotteryRecordConvert.INSTANCE.convert(record),
|
|
|
- luckLotteryService.detail(record.getLotteryId()),
|
|
|
- luckPrizeService.detail(record.getPrizeId()),
|
|
|
- user));
|
|
|
+
|
|
|
+ // 根据 orderIds 批量查询 LuckLotteryRecordDO
|
|
|
+ List<LuckLotteryRecordDO> recordList = luckLotteryRecordMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<LuckLotteryRecordDO>()
|
|
|
+ .in(LuckLotteryRecordDO::getOrderId, orderIds)
|
|
|
+ );
|
|
|
+
|
|
|
+ if (CollUtil.isEmpty(recordList)) {
|
|
|
+ return Map.of();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取用户信息
|
|
|
+ UserInfoRespDTO user = mendunerUserApi.getUser(userId).getCheckedData();
|
|
|
+
|
|
|
+ // 构建结果 Map
|
|
|
+ Map<Long, List<LuckLotteryRecordDetailRespVO>> resultMap = new HashMap<>();
|
|
|
+
|
|
|
+ // 按 orderId 分组
|
|
|
+ Map<Long, List<LuckLotteryRecordDO>> recordMap = recordList.stream()
|
|
|
+ .collect(Collectors.groupingBy(LuckLotteryRecordDO::getOrderId));
|
|
|
+
|
|
|
+ // 遍历分组后的数据
|
|
|
+ for (Map.Entry<Long, List<LuckLotteryRecordDO>> entry : recordMap.entrySet()) {
|
|
|
+ Long orderId = entry.getKey();
|
|
|
+ List<LuckLotteryRecordDO> records = entry.getValue();
|
|
|
+
|
|
|
+ // 转换为 LuckLotteryRecordDetailRespVO 列表
|
|
|
+ List<LuckLotteryRecordDetailRespVO> respList = records.stream()
|
|
|
+ .map(record -> LuckLotteryRecordConvert.INSTANCE.convertDetail(
|
|
|
+ LuckLotteryRecordConvert.INSTANCE.convert(record),
|
|
|
+ luckLotteryService.detail(record.getLotteryId()),
|
|
|
+ luckPrizeService.detail(record.getPrizeId()),
|
|
|
+ user
|
|
|
+ ))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ resultMap.put(orderId, respList);
|
|
|
}
|
|
|
- return respList;
|
|
|
+
|
|
|
+ return resultMap;
|
|
|
}
|
|
|
}
|