package com.tofly.watermeter.custom.service.meterBusiness.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.watermeter.custom.entity.meterBusiness.dto.StatisticalFormDto;
import com.tofly.watermeter.custom.mapper.meterBusiness.StatisticalFormMapper;
import com.tofly.watermeter.custom.service.meterBusiness.StatisticalFormService;
import com.tofly.watermeter.custom.service.meterBusiness.export.ExportCommonCodeService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@Service
@AllArgsConstructor
public class StatisticalFormServiceImpl implements StatisticalFormService {

    private final ExportCommonCodeService exportCommonCodeService;

    private final StatisticalFormMapper statisticalFormMapper;

    @Override
    public List<Map> outboundCount(HttpServletResponse response, StatisticalFormDto dto) {
        List<Map> maps = statisticalFormMapper. outboundCount(dto);
        if (dto.getExport() == 1) {
            exportCommonCodeService.exportCode(response, "outBoundCountNumService", maps);
        }
        return maps;
    }

    @Override
    public List<Map> outboundByCal(HttpServletResponse response, StatisticalFormDto dto) {
        List<Map> result = statisticalFormMapper.outboundByCal(dto);
        //导出
        if (dto.getExport() == 1) {
            exportCommonCodeService.exportCode(response, "outBoundByCalService", result);
        }
        return result;
    }

    /**
     * 出库统计 第三层
     */
    @Override
    public Page<Map> outboundInfo(HttpServletResponse response, Page page, StatisticalFormDto dto) {
        if (dto.getExport() == 1) {
            exportCommonCodeService.exportCode(response, "outBoundInfoService", statisticalFormMapper.outboundInfo(dto));
        }
        return statisticalFormMapper.outboundInfo(page, dto);
    }

    /**
     * 换表统计-第一层
     *
     * @param response
     * @param dto
     */
    @Override
    public List<Map> changeTableCount(HttpServletResponse response, StatisticalFormDto dto) {
        List<Map> maps = statisticalFormMapper.changeTableCount(dto);
        if (dto.getExport() == 1) {
            exportCommonCodeService.exportCode(response, "changeTableCountService", maps);
        }
        return maps;
    }

    /**
     * 换表统计-第二层
     */
    @Override
    public List<Map> changeTableByCal(HttpServletResponse response, StatisticalFormDto dto) {
        List<Map> maps = statisticalFormMapper.changeTableByCal(dto);
        if (dto.getExport() == 1) {
            exportCommonCodeService.exportCode(response, "changeTableByCalService", maps);
        }
        return maps;
    }

    /**
     * 换表统计-第三层
     */
    @Override
    public Page<Map> changeTableInfo(HttpServletResponse response, Page page, StatisticalFormDto dto) {
        if (dto.getExport() == 1) {
            exportCommonCodeService.exportCode(response, "changeTableInfoService", statisticalFormMapper.changeTableInfo(dto));
        }
        return statisticalFormMapper.changeTableInfo(page, dto);
    }

    /**
     * 报废统计-第一层
     */
    @Override
    public List<Map> scrapCount(HttpServletResponse response, StatisticalFormDto dto) {
        List<Map> maps = statisticalFormMapper.scrapCount(dto);
        if (dto.getExport() == 1) {
            exportCommonCodeService.exportCode(response, "scrapCountService", maps);
        }
        return maps;
    }

    /**
     * 报废统计-第二层
     */
    @Override
    public List<Map> scrapByCal(HttpServletResponse response, StatisticalFormDto dto) {
        List<Map> maps = statisticalFormMapper.scrapByCal(dto);
        if (dto.getExport() == 1) {
            exportCommonCodeService.exportCode(response, "scrapByCalService", maps);
        }
        return maps;
    }

    /**
     * 报废统计-第三层
     */
    @Override
    public Page<Map> scrapInfo(HttpServletResponse response, Page page, StatisticalFormDto dto) {
        if (dto.getExport() == 1) {
            exportCommonCodeService.exportCode(response, "scrapInfoService", statisticalFormMapper.scrapByInfo(dto));
        }
        return statisticalFormMapper.scrapByInfo(page, dto);
    }

    /**
     * 争议统计-第一层
     */
    @Override
    public List<Map> disputeCount(HttpServletResponse response, StatisticalFormDto dto) {
        List<Map> maps = statisticalFormMapper.disputeCount(dto);
        if (dto.getExport() == 1) {
            exportCommonCodeService.exportCode(response, "disputeCountService", maps);
        }
        return maps;
    }

    /**
     * 争议统计-第二层
     */
    @Override
    public List<Map> disputeByCal(HttpServletResponse response, StatisticalFormDto dto) {
        List<Map> maps = statisticalFormMapper.disputeByCal(dto);
        if (dto.getExport() == 1) {
            exportCommonCodeService.exportCode(response, "disputeByCalService", maps);
        }
        return maps;
    }

    /**
     * 争议统计-第三层
     */
    @Override
    public Page<Map> disputeInfo(HttpServletResponse response, Page page, StatisticalFormDto dto) {
        if (dto.getExport() == 1) {
            exportCommonCodeService.exportCode(response, "disputeInfoService", statisticalFormMapper.disputeByInfo(dto));
        }
        return statisticalFormMapper.disputeByInfo(page, dto);
    }
}
