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

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 ShaoyfXmlDataAnalysisFacade {
    @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, 11l, 17l, 18l, 19l, 22l, 24l, 25l, 27l, 28l, 30l, 31l);
        }
        Map<Long, String> modeMap = modeFacade.getModeMap();
        List<String> recTitles = null;
        String modeName = null;
        for (Long modeId : modeIds) {
            recTitles = xmlDataAnalysisFacade.getRecTitles(2l, modeId);
            modeName = modeMap.get(modeId);
            for (String recTitle : recTitles) {
                try {
                    xmlDataAnalysisFacade.analysisByRecTitle(2l, modeId, modeName, recTitle, null, "");
                } catch (Exception e) {
                    retList.add("[邵逸夫-" + modeId + "-" + recTitle + "]执行失败");
                    log.error("[邵逸夫-" + modeId + "-" + recTitle + "]执行失败--" + e.getMessage(), e);
                }
            }
        }
        return retList;
    }

}