package com.nantian.cloud.dbcapp.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nantian.cloud.dbcapp.dto.ResponseBo;
import com.nantian.cloud.dbcapp.dto.ResultBo;
import com.nantian.cloud.dbcapp.entity.DictEnergyUse;
import com.nantian.cloud.dbcapp.mapper.record.DictEnergyUseMapper;
import com.nantian.cloud.dbcapp.service.DictEnergyUseService;
import org.springframework.stereotype.Service;

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

/**
 * <p>
 * 能源用途编码表 服务实现类
 * </p>
 *
 * @author suixin
 * @since 2022-05-09
 */
@Service
public class DictEnergyUseServiceImpl extends ServiceImpl<DictEnergyUseMapper, DictEnergyUse> implements DictEnergyUseService {

    @Override
    public List<ResponseBo> getEnergyUseList() {
        List<ResponseBo> energyUseBoList = new ArrayList<>();
        List<ResultBo> energyUseClassList = this.baseMapper.getEnergyUseClassCode();
        for (ResultBo energyUseClass : energyUseClassList){
            ResponseBo energyUseBo = new ResponseBo();
            energyUseBo.setValue(energyUseClass.getValue());
            energyUseBo.setLabel(energyUseClass.getLabel());
            List<ResultBo> energyUseList = this.baseMapper.getEnergyUseList(energyUseClass.getValue());
            energyUseBo.setChildren(energyUseList);
            energyUseBoList.add(energyUseBo);
        }
        return energyUseBoList;
    }
}
