package com.aucma.report.service.impl;

import com.aucma.report.domain.*;
import com.aucma.report.mapper.GeneralReportMapper;
import com.aucma.report.service.IQualityReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * PDA管理Service业务层处理
 *
 * @author Yinq
 * @date 2023-11-21
 */
@Service
public class QualityReportServiceImpl implements IQualityReportService {
    @Autowired
    private GeneralReportMapper reportMapper;

    /**
     * 质量缺陷统计分析
     * @param hashMap
     * @return
     */
    @Override
    public List<QualityDefectsStatisticalAnalysis> qualityDefectsStatisticalAnalysisList(Map hashMap) {
        if (hashMap.containsKey("stationCodeList")){
            hashMap.put("stationCodeList",String.valueOf(hashMap.get("stationCodeList")).split(","));
        }
        return reportMapper.qualityDefectsStatisticalAnalysisList(hashMap);
    }

    /**
     * 少错件报表
     * @param hashMap
     * @return
     */
    @Override
    public List<FewerMistakesReport> fewerMistakesReportList(Map hashMap) {
        return reportMapper.fewerMistakesReportList(hashMap);
    }

    /**
     * 质量问题前80报表
     * @param hashMap
     * @return
     */
    @Override
    public List<QualityIssuesReport> qualityIssuesReportList(Map hashMap) {
        return reportMapper.qualityIssuesReportList(hashMap);
    }


    /**
     * 产品追溯报表
     * @param hashMap
     * @return
     */
    @Override
    public List<ProductTraceabilityReport> productTraceabilityReportList(Map hashMap) {
        return reportMapper.productTraceabilityReportList(hashMap);
    }

    /**
     * 测温记录报表
     * @param hashMap
     * @return
     */
    @Override
    public List<HashMap<String, Object>> temperatureRecordReportList(Map hashMap) {
        return reportMapper.temperatureRecordReportList(hashMap);
    }

    /**
     * 灌注记录报表
     * @param hashMap
     * @return
     */
    @Override
    public List<HashMap<String, Object>> pourRecordReportList(Map hashMap) {
        return reportMapper.pourRecordReportList(hashMap);
    }

    /**
     * 质量缺陷统计分析明细
     * @param hashMap
     * @return
     */
    @Override
    public List<HashMap<String, Object>> qualityDefectsDetailList(Map hashMap) {
        return reportMapper.qualityDefectsDetailList(hashMap);
    }

    /**
     * 产品追溯明细
     * @param hashMap
     * @return
     */
    @Override
    public List<HashMap<String, Object>> productTraceabilityDetailList(Map hashMap) {
        return reportMapper.productTraceabilityDetailList(hashMap);
    }

    /**
     * 质量缺陷统计分析明细导出
     * @param hashMap
     * @return
     */
    @Override
    public List<QualityDefectsDetail> qualityDefectsDetailListExport(Map hashMap) {
        ArrayList<QualityDefectsDetail> defectsDetailArrayList = new ArrayList<>();
        List<QualityDefectsStatisticalAnalysis> analysisList = this.qualityDefectsStatisticalAnalysisList(hashMap);
        for (QualityDefectsStatisticalAnalysis item : analysisList) {
            hashMap.put("stationCode",item.getSTATION_CODE());
            List<HashMap<String, Object>> hashMaps = this.qualityDefectsDetailList(hashMap);
            for (HashMap<String, Object> map : hashMaps) {
                QualityDefectsDetail defectsDetail = new QualityDefectsDetail();
                defectsDetail.setFACTORY_NAME(item.getFACTORY_NAME());
                defectsDetail.setPRODUCT_LINE_NAME(item.getPRODUCT_LINE_NAME());
                defectsDetail.setSTATION_CODE(item.getSTATION_CODE());
                defectsDetail.setSTATION_NAME(item.getSTATION_NAME());
                defectsDetail.setREWORK_NUMBER(item.getREWORK_NUMBER());
                defectsDetail.setSEQ(Long.valueOf(String.valueOf(map.get("SEQ"))));
                defectsDetail.setQUALITY_DEFECT_NAME(String.valueOf(map.get("QUALITY_DEFECT_NAME")));
                defectsDetail.setDEFECT_NUMBER(Long.valueOf(String.valueOf(map.get("DEFECT_NUMBER"))));
                defectsDetail.setRATE(String.valueOf(map.get("RATE")));
                defectsDetailArrayList.add(defectsDetail);


            }
        }
        return defectsDetailArrayList;
    }

}
