|
@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollectionUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
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.RequiredArgsConstructor;
|
|
|
import org.apache.ibatis.annotations.Param;
|
|
@@ -12,6 +13,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
import shop.alien.entity.second.SecondGoods;
|
|
|
import shop.alien.entity.second.vo.SecondGoodsVo;
|
|
|
+import shop.alien.entity.second.vo.SellGoodsVo;
|
|
|
import shop.alien.entity.store.*;
|
|
|
import shop.alien.entity.store.vo.LifeUserVo;
|
|
|
import shop.alien.mapper.*;
|
|
@@ -573,6 +575,27 @@ public class SecondGoodsServiceImpl extends ServiceImpl<SecondGoodsMapper, Secon
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 获取交易列表
|
|
|
+ * @param page 分页参数
|
|
|
+ * @param userId 用户ID
|
|
|
+ * @return IPage<SecondGoodsVo> 交易列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public IPage<SellGoodsVo> getTransactionList(IPage<SellGoodsVo> page, Integer userId) {
|
|
|
+ IPage<SellGoodsVo> result = new Page<>();
|
|
|
+ QueryWrapper<SellGoodsVo> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("sg.delete_flag", 0)
|
|
|
+ .eq("str.delete_flag", 0)
|
|
|
+ .and(wrapper -> wrapper.eq("str.buyer_id", userId)
|
|
|
+ .or()
|
|
|
+ .eq("str.seller_id", userId));
|
|
|
+ result = secondGoodsMapper.getTransactionList(page, userId, queryWrapper);
|
|
|
+ // 批量设置用户信息
|
|
|
+ batchSetSellUserInfo(result);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 查询搜索结果
|
|
|
* @param page 分页参数
|
|
|
* @param secondGoodsVo 查询参数
|
|
@@ -628,40 +651,35 @@ public class SecondGoodsServiceImpl extends ServiceImpl<SecondGoodsMapper, Secon
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 批量设置用户信息
|
|
|
+ * 批量设置用户信息(用于SecondGoodsVo列表)
|
|
|
* @param searchGoodsList 搜索结果
|
|
|
*/
|
|
|
private void batchSetUserInfo(IPage<SecondGoodsVo> searchGoodsList) {
|
|
|
- // 批量获取用户信息(头像,用户姓名,用户id)
|
|
|
- if (CollectionUtil.isNotEmpty(searchGoodsList.getRecords())) {
|
|
|
- List<Integer> userIds = searchGoodsList.getRecords().stream()
|
|
|
- .map(SecondGoodsVo::getUserId)
|
|
|
- .collect(Collectors.toList());
|
|
|
- // 批量获取用户信息
|
|
|
- QueryWrapper<LifeUserVo> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.in("id", userIds); // 使用字符串 "user_id" 直接指定数据库列名
|
|
|
- queryWrapper.in("delete_flag", 0);
|
|
|
- List<LifeUserVo> userInfoList = lifeUserMapper.getUserByIds(queryWrapper);
|
|
|
- // 根据用户id进行分组 返回map
|
|
|
- Map<Integer, LifeUserVo> userInfoMap = userInfoList.stream()
|
|
|
- .collect(Collectors.toMap(LifeUserVo::getId, lifeUserVo -> lifeUserVo));
|
|
|
- // 获取用户信息
|
|
|
- for (SecondGoodsVo goods : searchGoodsList.getRecords()) {
|
|
|
- LifeUserVo userInfo = userInfoMap.get(goods.getUserId());
|
|
|
- if (userInfo != null){
|
|
|
- // 用户名称
|
|
|
+ batchSetUserInfo(searchGoodsList,
|
|
|
+ SecondGoodsVo::getUserId,
|
|
|
+ (goods, userInfo) -> {
|
|
|
goods.setUserName(userInfo.getUserName());
|
|
|
- // 用户真实姓名
|
|
|
goods.setRealName(userInfo.getRealName());
|
|
|
- // 用户头像
|
|
|
goods.setUserImage(userInfo.getUserImage());
|
|
|
- // 用户id
|
|
|
goods.setUserId(userInfo.getId());
|
|
|
- // 用户手机号
|
|
|
goods.setUserPhone(userInfo.getUserPhone());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量设置用户信息(用于SellGoodsVo列表)
|
|
|
+ * @param sellGoodsList 搜索结果
|
|
|
+ */
|
|
|
+ private void batchSetSellUserInfo(IPage<SellGoodsVo> sellGoodsList) {
|
|
|
+ batchSetUserInfo(sellGoodsList,
|
|
|
+ SellGoodsVo::getUserId,
|
|
|
+ (goods, userInfo) -> {
|
|
|
+ goods.setUserName(userInfo.getUserName());
|
|
|
+ goods.setRealName(userInfo.getRealName());
|
|
|
+ goods.setUserImage(userInfo.getUserImage());
|
|
|
+ goods.setUserId(userInfo.getId());
|
|
|
+ goods.setUserPhone(userInfo.getUserPhone());
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -696,4 +714,37 @@ public class SecondGoodsServiceImpl extends ServiceImpl<SecondGoodsMapper, Secon
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量设置用户信息
|
|
|
+ * @param <T> 任意商品VO类型
|
|
|
+ * @param goodsList 商品列表
|
|
|
+ * @param userIdMapper 从商品VO获取用户ID的函数
|
|
|
+ * @param userSetter 从用户信息设置到商品VO的函数
|
|
|
+ */
|
|
|
+ private <T> void batchSetUserInfo(IPage<T> goodsList,
|
|
|
+ java.util.function.Function<T, Integer> userIdMapper,
|
|
|
+ java.util.function.BiConsumer<T, LifeUserVo> userSetter) {
|
|
|
+ if (CollectionUtil.isNotEmpty(goodsList.getRecords())) {
|
|
|
+ List<Integer> userIds = goodsList.getRecords().stream()
|
|
|
+ .map(userIdMapper)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ QueryWrapper<LifeUserVo> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.in("id", userIds)
|
|
|
+ .eq("delete_flag", 0);
|
|
|
+
|
|
|
+ List<LifeUserVo> userInfoList = lifeUserMapper.getUserByIds(queryWrapper);
|
|
|
+ Map<Integer, LifeUserVo> userInfoMap = userInfoList.stream()
|
|
|
+ .collect(Collectors.toMap(LifeUserVo::getId, lifeUserVo -> lifeUserVo));
|
|
|
+
|
|
|
+ for (T goods : goodsList.getRecords()) {
|
|
|
+ LifeUserVo userInfo = userInfoMap.get(userIdMapper.apply(goods));
|
|
|
+ if (userInfo != null && userSetter != null) {
|
|
|
+ userSetter.accept(goods, userInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|