package com.njcn.energy.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.common.pojo.enums.common.DataStateEnum;
import com.njcn.energy.mapper.EleLineMapper;
import com.njcn.energy.pojo.param.LineParam;
import com.njcn.energy.pojo.po.EleLine;
import com.njcn.energy.service.IEleLineService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 类的介绍：
 *
 * @author xuyang
 * @version 1.0.0
 * @createTime 2022/3/8 14:31
 */
@Service
public class EleLineServiceImpl extends ServiceImpl<EleLineMapper, EleLine> implements IEleLineService {

    @Override
    public EleLine add(LineParam lineParam) {
        EleLine line = new EleLine();
        BeanUtil.copyProperties(lineParam,line);
        line.setState(DataStateEnum.ENABLE.getCode());
        this.save(line);
        return line;
    }

    @Override
    public boolean deleteByList(List<String> list) {
        QueryWrapper<EleLine> eleLineQueryWrapper = new QueryWrapper<>();
        eleLineQueryWrapper.in("Pid",list);
        return this.remove(eleLineQueryWrapper);
    }

    @Override
    public List<EleLine> getAllLine(String netDevName){
        return this.baseMapper.getAllLine(netDevName);
     }

    @Override
    public List<EleLine> getAllLines(List<String> list) {
        return this.lambdaQuery().in(EleLine::getPid,list).list();
    }

    @Override
    public List<EleLine> getLineInfo(List<String> list) {
        return this.lambdaQuery().in(EleLine::getLineId,list).list();
    }
}
