package com.njcn.excelreport;

import com.njcn.mapper.configuration.OverLimitMapper;
import com.njcn.pojo.commons.device.MachineAccount;
import com.njcn.pojo.configuration.OverLimit;
import com.njcn.pojo.excelreport.ConditionData;
import com.njcn.pojo.excelreport.OverLimitInfoData;
import com.njcn.service.configuration.LineService;
import com.njcn.service.excelreport.GetOverLimitService;
import com.njcn.utils.AppConfig;
import com.njcn.utils.COverlimit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

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


@Component
public class GetOverlimitInfo {
    @Autowired
    LineService lineService;
    @Autowired
    OverLimitMapper overLimitMapper;
    @Autowired
    COverlimit cOverlimit;
    @Autowired
    AppConfig appConfig;
    @Autowired
    private GetOverLimitService getOverLimitService;

    private ConditionData conditionData;

    public ConditionData getConditionData() {
        this.conditionData = new ConditionData(appConfig);
        return this.conditionData;
    }

    public void setConditionData(ConditionData conditionData) {
        this.conditionData = conditionData;
    }

    public OverLimitInfoData getOverLimit(Integer lineId) {
        this.conditionData.setPointIndex(lineId);
        this.conditionData.setB();

        OverLimit over = overLimitMapper.selectByPrimaryKey(lineId.longValue());
        MachineAccount machineAccount = lineService.getLineName(lineId);

        if (over == null) {
            cOverlimit.addOverLimit(lineId, machineAccount.getScale());
        }

        OverLimitInfoData overLimitInfoData = getOverLimitService.getOverLimitData(conditionData);
        conditionData.setCount(overLimitInfoData.getCount());
        conditionData.setPltCount(overLimitInfoData.getPltCount());
        conditionData.setPstCount(overLimitInfoData.getPstCount());
        overLimitInfoData.setMode(machineAccount.getPttype());

        List<String> list;
        switch (machineAccount.getPttype()) {
            case 0:
                list = new ArrayList<>();
                list.add("A");
                list.add("B");
                list.add("C");
                overLimitInfoData.setList(list);
                break;
            case 1:
                list = new ArrayList<>();
                list.add("AB");
                list.add("BC");
                list.add("CA");
                overLimitInfoData.setList(list);
                break;
            case 2:
                list = new ArrayList<>();
                list.add("AB");
                list.add("BC");
                list.add("-");
                overLimitInfoData.setList(list);
                break;
        }

        return overLimitInfoData;
    }
}
