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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.watermeter.custom.entity.meterBusiness.dto.StatementConditionDto;
import com.tofly.watermeter.custom.mapper.meterBusiness.StatementMapper;
import com.tofly.watermeter.custom.service.meterBusiness.StatementService;
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 StatementServiceImpl implements StatementService {

    private final StatementMapper statementMapper;
    private final ExportCommonCodeService exportCommonCodeService;

    @Override
    public List<Map> count(HttpServletResponse response, StatementConditionDto dto) {
        List<Map> count = statementMapper.count(dto);

        if (dto.getExport() == 1) {
            exportCommonCodeService.exportCode(response, "statementCountService", count);
        }
        return count;
    }

    @Override
    public Page<Map> queryByVendor(HttpServletResponse response, Page page, StatementConditionDto dto) {
        if (dto.getExport() == 1) {
            exportCommonCodeService.exportCode(response, "statementByVendorService", statementMapper.queryByVendor(dto));
        }
        return statementMapper.queryByVendor(page, dto);
    }

    @Override
    public Page<Map> queryInfo(HttpServletResponse response, Page page, StatementConditionDto dto) {
        if (dto.getExport() == 1) {
            exportCommonCodeService.exportCode(response, "statementInfoService", statementMapper.queryInfo(dto));
        }
        return statementMapper.queryInfo(page, dto);
    }

}
