package com.pqs9300.serviceimpl.report;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.njcn.mapper.configuration.RptDataMapper;
import com.njcn.mapper.configuration.RptPloyMapper;
import com.njcn.pojo.configuration.RptData;
import com.njcn.pojo.configuration.RptPloy;
import com.pqs9300.mapper.report.ExcelReportMapper;
import com.pqs9300.pojo.report.PloySetting;
import com.pqs9300.service.report.ExcelReportService;

@Service
public class ExcelReportServiceImpl implements ExcelReportService {
    @Autowired
    private RptPloyMapper rptPloyMapper;
    @Autowired
    private RptDataMapper rptDataMapper;
    @Autowired
    private ExcelReportMapper excelReportMapper;

    @Override
    public List<RptPloy> getPloyData() {
        RptPloy rptPloy = new RptPloy();
        rptPloy.setState(new Integer(1));
        rptPloy.setPloyType(new Integer(2));
        return rptPloyMapper.select(rptPloy);
    }

    @Override
    public List<PloySetting> setPloy(String guid) {
        //获取最后一层选择
        List<RptData> list = excelReportMapper.getDatasByPloy(guid);

        //筛选出parentId
        Set<String> sets = new TreeSet<>();

        for (RptData rptData : list) {
            sets.add(rptData.getParentGUID());
        }

        //筛选的结果获取节点详细信息
        List<RptData> list1 = excelReportMapper.getDatas(sets);

        //转换结果
        List<PloySetting> listPloys = new ArrayList<>();

        for (RptData rptData : list1) {
            PloySetting ploySetting = new PloySetting();
            ploySetting.setName(rptData.getRdDescribe());
            List<Integer> list2 = new ArrayList<>();

            for (RptData rptData1 : list) {
                if (rptData1.getParentGUID().equals(rptData.getRdIndex())) {
                    switch (rptData1.getRdDescribe()) {
                        case "最大值":
                            list2.add(new Integer(1));
                            break;
                        case "最小值":
                            list2.add(new Integer(2));
                            break;
                        case "平均值":
                            list2.add(new Integer(3));
                            break;
                        case "CP95值":
                            list2.add(new Integer(4));
                            break;
                        case "谐波电压含有率":
                            list2.add(new Integer(5));
                            break;
                        case "谐波电流含有率":
                            list2.add(new Integer(6));
                            break;
                        case "电压偏差":
                            list2.add(new Integer(7));
                            break;
                        case "三相电压不平衡度":
                            list2.add(new Integer(8));
                            break;
                        case "电压谐波畸变率":
                            list2.add(new Integer(9));
                            break;
                        case "频率偏差":
                            list2.add(new Integer(10));
                            break;
                        case "电压长时闪变":
                            list2.add(new Integer(11));
                            break;
                    }
                }
            }

            ploySetting.setListTarget(list2);
            listPloys.add(ploySetting);
        }

        return listPloys;
    }
}
