package com.aucma.report.service.impl;

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

import java.util.*;

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

    /**
     * 查询清单率报表
     */
    @Override
    public List<InventoryRateReport> inventoryRateReportList(Map hashMap) {
        return reportMapper.inventoryRateReportList(hashMap);
    }

    /**
     * 查询生产执行报表
     * @param hashMap
     * @return
     */
    @Override
    public List<ProductionExecutionReport> productionExecutionReportList(Map hashMap) {
        return reportMapper.productionExecutionReportList(hashMap);
    }

    /**
     * 查询在制品查询报表
     * @param hashMap
     * @return
     */
    @Override
    public List<WIPInquiryReport> WIPInquiryReportList(Map hashMap) {
        return reportMapper.WIPInquiryReportList(hashMap);
    }

    /**
     * 扫描下线记录报表
     * @param hashMap
     * @return
     */
    @Override
    public List<HashMap<String, Object>> ScanOfflineRecordReportList(Map hashMap) {
        return reportMapper.ScanOfflineRecordReportList(hashMap);
    }

    /**
     * 发泡箱体追溯报表
     * @param hashMap
     * @return
     */
    @Override
    public List<BoxTraceabilityReport> boxTraceabilityReport(Map hashMap) {
        return reportMapper.boxTraceabilityReport(hashMap);
    }

    /**
     * 发泡箱体追溯详情报表
     * @param hashMap
     * @return
     */
    @Override
    public List<BoxTraceabilityDetailReport> boxTraceabilityDetailReport(Map hashMap) {
//        List<BoxTraceabilityDetailReport> boxTraceabilityDetailReports = reportMapper.boxTraceabilityDetailReport(hashMap);
        List<BoxTraceabilityDetailReport> boxTraceabilityDetailReports = reportMapper.boxTraceabilityDetailReportUpdate(hashMap);
        return boxTraceabilityDetailReports;
    }

    /**
     * 箱体流转追溯报表
     * @param hashMap
     * @return
     */
    @Override
    public List<BoxTurnoverTraceabilityReport> boxTurnoverTraceabilityReportList(Map hashMap) {
        return reportMapper.boxTurnoverTraceabilityReportList(hashMap);
    }

    /**
     * 箱体流转追溯详情报表
     * @param hashMap
     * @return
     */
    @Override
    public List<BoxTurnoverTraceabilityDetailReport> boxTurnoverTraceabilityDetailReportList(Map hashMap) {
        return reportMapper.boxTurnoverTraceabilityDetailReportList(hashMap);
    }

    /**
     * 查询在制品查询明细
     * @param hashMap
     * @return
     */
    @Override
    public List<WIPInquiryDetailReport> WIPInquiryDetailReportList(Map hashMap) {
        return reportMapper.WIPInquiryDetailReportList(hashMap);
    }

    /**
     * 查询壳胆绑定报表
     * */
    @Override
    public List<codeBanding> codeBandingReportList(Map hashMap) {
        List<codeBanding> codeBandings = reportMapper.codeBandingReportList(hashMap);
        return codeBandings;
    }
    /**
     * 查询过点数报表
     * */
    public List<MaterialReport> materialReportList(Map hashMap){
        List<MaterialReport> Materials = reportMapper.materialReportList(hashMap);
        if (Materials.size() > 0){
            MaterialReport materialReport = new MaterialReport();
            materialReport.setMES_SN_BINDING_COUNT(0);
            materialReport.setFINISHED_PRODUCT_SCAN_COUNT(0);
            materialReport.setFINISHED_PRODUCT_PALLETIZING_COUNT(0);
            materialReport.setMATERIAL_NAME("合计");
            for (MaterialReport material : Materials) {
                Integer mesSnBindingCount = materialReport.getMES_SN_BINDING_COUNT() + material.getMES_SN_BINDING_COUNT();
                Integer finishedProductScanCount = materialReport.getFINISHED_PRODUCT_SCAN_COUNT() + material.getFINISHED_PRODUCT_SCAN_COUNT();
                Integer finishedProductPalletizingCount = materialReport.getFINISHED_PRODUCT_PALLETIZING_COUNT() + material.getFINISHED_PRODUCT_PALLETIZING_COUNT();
                materialReport.setMES_SN_BINDING_COUNT(mesSnBindingCount);
                materialReport.setFINISHED_PRODUCT_SCAN_COUNT(finishedProductScanCount);
                materialReport.setFINISHED_PRODUCT_PALLETIZING_COUNT(finishedProductPalletizingCount);
            }
            Materials.add(materialReport);
        }
        return Materials;
    }
}
