package com.lantone.qc.dbanaly.facade.taizhou;

import com.google.common.collect.Lists;
import com.lantone.qc.dbanaly.facade.comsis.XmlDataAnalysisFacade;
import com.lantone.qc.dbanaly.lt.facade.ModeFacade;
import com.lantone.qc.pub.util.ListUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @author: rengb
 * @time: 2020/6/3 16:44
 */
@Slf4j
@Component
public class TaiZhouXmlDataAnalysisFacade {
    @Autowired
    private XmlDataAnalysisFacade xmlDataAnalysisFacade;
    @Autowired
    private ModeFacade modeFacade;

    public List<String> analyzeXml(List<Long> modeIds) {
        List<String> retList = Lists.newArrayList();
        if (ListUtil.isEmpty(modeIds)) {
            modeIds = Arrays.asList(1l, 2l, 3l, 4l, 5l, 7l, 8l, 9l, 10l, 11l, 17l, 18l, 19l, 22l, 23l, 24l, 25l, 26l, 27l, 28l, 29l, 30l, 31l, 32l, 34l, 35l);
        }
        Map<Long, String> modeMap = modeFacade.getModeMap();
        List<String> recTitles = null;
        String modeName = null;
        for (Long modeId : modeIds) {
            recTitles = xmlDataAnalysisFacade.getRecTitles(3l, modeId);
            modeName = modeMap.get(modeId);
            for (String recTitle : recTitles) {
                try {
                    xmlDataAnalysisFacade.analysisByRecTitle(3l, modeId, modeName, recTitle, null, "");
                } catch (Exception e) {
                    retList.add("[台州-" + modeId + "-" + recTitle + "]执行失败");
                    log.error("[台州-" + modeId + "-" + recTitle + "]执行失败--" + e.getMessage(), e);
                }
            }
        }
        return retList;
    }

}