package com.muyu.enterprise.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.enterprise.domain.dateBase.FenceGroupMid;
import com.muyu.enterprise.domain.resp.ElectronicFenceResp;
import com.muyu.enterprise.mapper.FenceGroupMidMapper;
import com.muyu.enterprise.service.FenceGroupMidService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author：李庆帅
 * @Package：com.muyu.fence.service.impl
 * @Project：cloud-server
 * @name：FenceGroupMidServiceImpl
 * @Date：2024/9/20 11:34
 */

/**
 * 围栏链表业务实现层
 */
@Service
public class FenceGroupMidServiceImpl extends ServiceImpl<FenceGroupMidMapper, FenceGroupMid> implements FenceGroupMidService {

    @Autowired
    private FenceGroupMidMapper fenceGroupMidMapper;

    @Override
    public void addGroupAndFenceMid(Long id, List<ElectronicFenceResp> electronicFenceRespList) {
        for (ElectronicFenceResp electronicFenceResp : electronicFenceRespList) {
            fenceGroupMidMapper.insert(new FenceGroupMid(null, id, electronicFenceResp.getId()));
        }
    }

    @Override
    public List<FenceGroupMid> selectFenceGroupMidListById(Long groupId) {

        LambdaQueryWrapper<FenceGroupMid> queryWrapper = new LambdaQueryWrapper<>();

        queryWrapper.eq(FenceGroupMid::getGroupId, groupId);

        this.list(queryWrapper);


        return this.list(queryWrapper);
    }

    @Override
    public void deliteMid(Long id) {
        LambdaQueryWrapper<FenceGroupMid> wrapper = new LambdaQueryWrapper<>();

        wrapper.eq(FenceGroupMid::getGroupId, id);

        this.remove(wrapper);
    }

}
