|
|
@@ -1,6 +1,7 @@
|
|
|
package org.dromara.hotel.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
@@ -33,6 +34,7 @@ import java.util.Collection;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
/**
|
|
|
@@ -161,13 +163,25 @@ public class KfTeamServiceImpl implements IKfTeamService {
|
|
|
R<String> result = guestService.insertBatch(guests);
|
|
|
|
|
|
//2.新增客人客团关系
|
|
|
- List<Long> existGuestIdList =
|
|
|
+ //查询已经在该团的客人id
|
|
|
+ LambdaQueryWrapper warpper = new LambdaQueryWrapper<>(KfGuestTeamR.class)
|
|
|
+ .select(KfGuestTeamR::getGuestId)
|
|
|
+ .eq(KfGuestTeamR::getTeamId, teamId);
|
|
|
+ List<KfGuestTeamRVo> existsGuestList = relationMapper.selectVoList(warpper);
|
|
|
+ //从请求参数的人员列表中过滤出老的客人id集合
|
|
|
+ List<Long> oldGuestIdList =
|
|
|
boList.stream()
|
|
|
.filter(item -> item.getGuestId() != null)
|
|
|
- .map(item -> item.getGuestId()).toList();
|
|
|
- List<Long> existGuestIdList1 = guests.stream().map(KfGuest::getId).toList();
|
|
|
+ .map(item -> item.getGuestId()).collect(Collectors.toList());
|
|
|
+ //删除掉已经在该客团中的客人ID,避免一个人添加多次
|
|
|
+ if(ObjectUtil.isNotEmpty(existsGuestList)){
|
|
|
+ List<Long> existsGuestIds = existsGuestList.stream().map(item -> item.getGuestId()).toList();
|
|
|
+ oldGuestIdList.removeAll(existsGuestIds);
|
|
|
+ }
|
|
|
+ //获得本次新增的客人id集合
|
|
|
+ List<Long> newGuestIdList = guests.stream().map(KfGuest::getId).toList();
|
|
|
//合并两个list
|
|
|
- List<Long> allGuestIdList = Stream.concat(existGuestIdList.stream(), existGuestIdList1.stream()).toList();
|
|
|
+ List<Long> allGuestIdList = Stream.concat(oldGuestIdList.stream(), newGuestIdList.stream()).toList();
|
|
|
List<KfGuestTeamR> relations = initGuestTeamRList(teamId, allGuestIdList);
|
|
|
relationMapper.insertBatch(relations);
|
|
|
return result;
|