package com.pqs9000.serviceimpl.common;

import com.pqs9000.mapper.common.HarmIMapper;
import com.pqs9000.pojo.common.HarmI;
import com.pqs9000.pojo.report.Condition;
import com.pqs9000.service.common.HarmIService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
 * @Author denghuajun
 * @Description //TODO 谐波电流幅值逻辑层
 * @Date 2018/11/28 15:24
 **/
@Service
public class HarmIServiceImpl implements HarmIService {

    @Autowired
    private HarmIMapper harmIMapper;

    @Override
    public List<List> getHarmI(long lineId, Date startTime, Date endTime) {
        List<List> lists = new ArrayList<>();
        List<HarmI> harmonics = harmIMapper.getHarmI(lineId, startTime, endTime);
        harmonics.removeAll(Collections.singleton(null));
        if (!harmonics.isEmpty()) {
            for (HarmI harmI : harmonics) {
                List<String> str = new ArrayList<>();
                str.add("谐波电流幅值(A)");
                str.add(String.valueOf(harmI.getI2()));
                str.add(String.valueOf(harmI.getI3()));
                str.add(String.valueOf(harmI.getI4()));
                str.add(String.valueOf(harmI.getI5()));
                str.add(String.valueOf(harmI.getI6()));
                str.add(String.valueOf(harmI.getI7()));
                str.add(String.valueOf(harmI.getI8()));
                str.add(String.valueOf(harmI.getI9()));
                str.add(String.valueOf(harmI.getI10()));
                str.add(String.valueOf(harmI.getI11()));
                str.add(String.valueOf(harmI.getI12()));
                str.add(String.valueOf(harmI.getI13()));
                str.add(String.valueOf(harmI.getI14()));
                str.add(String.valueOf(harmI.getI15()));
                str.add(String.valueOf(harmI.getI16()));
                str.add(String.valueOf(harmI.getI17()));
                str.add(String.valueOf(harmI.getI18()));
                str.add(String.valueOf(harmI.getI19()));
                str.add(String.valueOf(harmI.getI20()));
                str.add(String.valueOf(harmI.getI21()));
                str.add(String.valueOf(harmI.getI22()));
                str.add(String.valueOf(harmI.getI23()));
                str.add(String.valueOf(harmI.getI24()));
                str.add(String.valueOf(harmI.getI25()));
                if (harmI.getI26() == 0 && harmI.getI27() == 0 && harmI.getI28() == 0 && harmI.getI29() == 0 && harmI.getI30() == 0 && harmI.getI31() == 0 && harmI.getI32() == 0 && harmI.getI33() == 0 && harmI.getI34() == 0 && harmI.getI35() == 0 && harmI.getI36() == 0 && harmI.getI37() == 0 && harmI.getI38() == 0 && harmI.getI39() == 0 && harmI.getI40() == 0 && harmI.getI41() == 0 && harmI.getI42() == 0 && harmI.getI43() == 0 && harmI.getI44() == 0 && harmI.getI45() == 0 && harmI.getI46() == 0 && harmI.getI47() == 0 && harmI.getI48() == 0 && harmI.getI49() == 0 && harmI.getI50() == 0) {
                    
                }else {
                    str.add(String.valueOf(harmI.getI26()));
                    str.add(String.valueOf(harmI.getI27()));
                    str.add(String.valueOf(harmI.getI28()));
                    str.add(String.valueOf(harmI.getI29()));
                    str.add(String.valueOf(harmI.getI30()));
                    str.add(String.valueOf(harmI.getI31()));
                    str.add(String.valueOf(harmI.getI32()));
                    str.add(String.valueOf(harmI.getI33()));
                    str.add(String.valueOf(harmI.getI34()));
                    str.add(String.valueOf(harmI.getI35()));
                    str.add(String.valueOf(harmI.getI36()));
                    str.add(String.valueOf(harmI.getI37()));
                    str.add(String.valueOf(harmI.getI38()));
                    str.add(String.valueOf(harmI.getI39()));
                    str.add(String.valueOf(harmI.getI40()));
                    str.add(String.valueOf(harmI.getI41()));
                    str.add(String.valueOf(harmI.getI42()));
                    str.add(String.valueOf(harmI.getI43()));
                    str.add(String.valueOf(harmI.getI44()));
                    str.add(String.valueOf(harmI.getI45()));
                    str.add(String.valueOf(harmI.getI46()));
                    str.add(String.valueOf(harmI.getI47()));
                    str.add(String.valueOf(harmI.getI48()));
                    str.add(String.valueOf(harmI.getI49()));
                    str.add(String.valueOf(harmI.getI50()));
                }
                lists.add(str);
            }
        } else {
            List<String> str = new ArrayList<>();
            str.add("谐波电流幅值(A)");
            for(int i=0;i<24;i++){
                str.add("/");
            }
            lists.add(str);
        }
        return lists;
    }

    @Override
    public List<List> getoffHarmI(Condition condition) {
        List<List> lists = new ArrayList<>();
        List<String> str = new ArrayList<>();
        str.add("谐波电流幅值(A)");
        for(int i=2;i<51;i++){
        	Float harmI = harmIMapper.getoffHarmI(condition,i);
        	if(harmI == null){
        		str.add("/");
        	}else{
        		str.add(String.valueOf(harmI));
        	}
        }
        lists.add(str);
        return lists;
    }
}
