package com.muyu.enterpise.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.domain.CarAndGroupMiddle;
import com.muyu.domain.FenceGroup;

import com.muyu.enterpise.mapper.CarAndFenceGroupMiddleMapper;
import com.muyu.enterpise.service.CarAndFenceGroupMiddleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 车辆和围栏组中间表
 * @Author：yan
 * @Package：com.muyu.service.impl
 * @Project：plues
 * @name：CarAndFenceGroupMiddleServiceImpl
 * @Date：2024/9/29 20:11
 */
@Service
public class CarAndFenceGroupMiddleServiceImpl extends ServiceImpl<CarAndFenceGroupMiddleMapper, CarAndGroupMiddle> implements CarAndFenceGroupMiddleService {
    @Autowired
    private CarAndFenceGroupMiddleMapper carAndFenceGroupMiddleMapper;

    /**
     * 根据围栏组和车辆的id添加中间表
     */
    @Override
    public boolean saveBatch(List<FenceGroup> fenceGroups, Integer carId) {
        List<CarAndGroupMiddle> list = fenceGroups.stream().map(fenceGroup -> {
            CarAndGroupMiddle carAndGroupMiddle = new CarAndGroupMiddle();
            //获取围栏组的id
            carAndGroupMiddle.setGroupId(fenceGroup.getGroupId());
            carAndGroupMiddle.setCarId(carId);
            return carAndGroupMiddle;
        }).toList();
        boolean b = this.saveBatch(list);
        return b;
    }
}
