package com.njcn.energy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.energy.mapper.GroupArrayMapper;
import com.njcn.energy.pojo.po.GroupArray;
import com.njcn.energy.service.IGroupArrayService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * 类的介绍：
 *
 * @author xuyang
 * @version 1.0.0
 * @createTime 2022/3/16 13:27
 */
@Service
public class GroupArrayServiceImpl extends ServiceImpl<GroupArrayMapper, GroupArray> implements IGroupArrayService {

    @Override
    public void groupArrayRelation(String groupId, String arrId) {
        GroupArray groupArray = this.lambdaQuery().eq(GroupArray::getGroupId,groupId).eq(GroupArray::getArrId,arrId).one();
        if (Objects.isNull(groupArray)){
            GroupArray pojo = new GroupArray();
            pojo.setGroupId(groupId);
            pojo.setArrId(arrId);
            this.save(pojo);
        }
    }

    @Override
    public boolean batchAdd(List<GroupArray> list){
        return this.saveBatch(list);
    }
    @Override
    public boolean deleteGroupArray(List<String> list) {
        QueryWrapper<GroupArray> groupArrayQueryWrapper = new QueryWrapper<>();
        groupArrayQueryWrapper.in("Group_Id",list);
        return this.remove(groupArrayQueryWrapper);
    }

}
