package com.casic.missiles.modular.group.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.casic.missiles.modular.system.model.GroupWell;
import com.casic.missiles.modular.system.dao.GroupWellMapper;
import com.casic.missiles.modular.group.service.IGroupWellService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author lwh123
 * @since 2020-03-20
 */
@Service
public class GroupWellServiceImpl extends ServiceImpl<GroupWellMapper, GroupWell> implements IGroupWellService {

    @Override
    public void addWells(String id, List<String> wellIds) {
        try {
            EntityWrapper<GroupWell> query = new EntityWrapper<>();
            query.eq("GROUP_ID", id);
            query.in("WELL_ID", wellIds);
            this.delete(query);
            List<GroupWell> groupWellList = new ArrayList<>();
            for (String wellIdStr : wellIds) {
                GroupWell groupWell = new GroupWell();
                groupWell.setWellId(Long.valueOf(wellIdStr));
                groupWell.setGroupId(Long.valueOf(id));
                groupWellList.add(groupWell);
            }
            this.insertBatch(groupWellList);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public List<String> findListByGroupid(String id) {
        return this.baseMapper.findListByGroupid(id);
    }
}
