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.DictCollectDataType;
import com.nantian.cloud.dbcapp.entity.DictEnergyType;
import com.nantian.cloud.dbcapp.mapper.record.DictEnergyTypeMapper;
import com.nantian.cloud.dbcapp.service.CompanyMaterielProductService;
import com.nantian.cloud.dbcapp.service.DictCollectDataTypeService;
import com.nantian.cloud.dbcapp.service.DictEnergyTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * <p>
 * 能源品种编码、计量单位及精度 服务实现类
 * </p>
 *
 * @author suixin
 * @since 2022-05-09
 */
@Service
public class DictEnergyTypeServiceImpl extends ServiceImpl<DictEnergyTypeMapper, DictEnergyType> implements DictEnergyTypeService {

    @Autowired
    private DictCollectDataTypeService dictCollectDataTypeService;

    @Autowired
    private CompanyMaterielProductService companyMaterielProductService;

    @Override
    public List<ResponseBo> getEnergyTypeList(String enterpriseCode) {
        List<ResponseBo> energyTypeBoList = new ArrayList<>();
        List<DictCollectDataType> dictCollectDataTypeList = dictCollectDataTypeService.getList();
        for (DictCollectDataType dictCollectDataType:dictCollectDataTypeList){
            ResponseBo energyTypeBo = new ResponseBo();
            energyTypeBo.setValue(dictCollectDataType.getCode());
            energyTypeBo.setLabel(dictCollectDataType.getMeaning());
            if ("04".equals(dictCollectDataType.getCode())){
                List<ResponseBo> productBoList = new ArrayList<>();
                // 有标产品
                ResponseBo standardProduct = new ResponseBo();
                standardProduct.setValue("01");
                standardProduct.setLabel("有标产品");
                standardProduct.setChildren(this.baseMapper.getEnergyByClassCodeList(dictCollectDataType.getCode()));
                productBoList.add(standardProduct);

                //无标产品
                ResponseBo noStandardProduct = new ResponseBo();
                noStandardProduct.setValue("02");
                noStandardProduct.setLabel("无标产品");
                noStandardProduct.setChildren(companyMaterielProductService.getProductResultBo(enterpriseCode));

                productBoList.add(noStandardProduct);
                // 非能源类产品【包含 有标，无标】
                energyTypeBo.setValue(dictCollectDataType.getCode());
                energyTypeBo.setLabel(dictCollectDataType.getMeaning());
                energyTypeBo.setChildren(productBoList);
                energyTypeBoList.add(energyTypeBo);
            }else {
                List<ResultBo> dictEnergyTypeList = this.baseMapper.getEnergyByClassCodeList(dictCollectDataType.getCode());
                energyTypeBo.setChildren(dictEnergyTypeList);
                energyTypeBoList.add(energyTypeBo);
            }
        }
        return energyTypeBoList;
    }
}
