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.EleLoadSetMapper;
import com.njcn.energy.pojo.param.EleParam;
import com.njcn.energy.pojo.po.EleLoadSet;
import com.njcn.energy.pojo.po.EleStatisticalSet;
import com.njcn.energy.pojo.vo.EleLoadSetTreeVO;
import com.njcn.energy.pojo.vo.EleLoadSetVO;
import com.njcn.energy.service.EleLoadSetService;
import com.njcn.energy.service.ILogicDeviceLineService;
import com.njcn.system.enums.DicDataTypeEnum;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用能负荷类型配置
 * @author denghuajun
 * @version 1.0.0
 * @date 2022年04月15日 14:31
 */
@Service
@AllArgsConstructor
public class EleLoadSetServiceImpl extends ServiceImpl<EleLoadSetMapper, EleLoadSet> implements EleLoadSetService {

    private final ILogicDeviceLineService iLogicDeviceLineService;
    @Override
    public List<EleLoadSetVO> getEleLoadSetDetail() {
        return this.baseMapper.getEleLoadSetDetail(DicDataTypeEnum.ELE_LOAD_TYPE.getName());
    }

    @Override
    public EleLoadSetTreeVO getEleLoadTree(EleLoadSetVO eleLoadSetVO) {
        return iLogicDeviceLineService.getEnergyLoadTree(eleLoadSetVO.getLoadId());
    }

    @Override
    public Boolean add(EleParam eleParam) {
        QueryWrapper<EleLoadSet> eleMdQueryWrapper = new QueryWrapper<>();
        eleMdQueryWrapper.eq("ele_load_set.id", eleParam.getId());
        this.baseMapper.delete(eleMdQueryWrapper);
        for (String index : eleParam.getIds()) {
            EleLoadSet eleLoadSet = new EleLoadSet();
            eleLoadSet.setId(eleParam.getId());
            eleLoadSet.setLineId(index);
            this.baseMapper.insert(eleLoadSet);
        }
        return true;
    }
}
