package com.muyu.fence.service.impl;

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

import java.util.List;

/**
 * @Author：yuping
 * @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);
    }

}
