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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.watermeter.custom.entity.meterBusiness.dto.ReturnTableDto;
import com.tofly.watermeter.custom.mapper.meterBusiness.ReturnTableMapper;
import com.tofly.watermeter.custom.service.meterBusiness.ReturnTableService;
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 ReturnTableServiceImpl implements ReturnTableService {

    private final ReturnTableMapper returnTableMapper;
    private final ExportCommonCodeService exportCommonCodeService;

    @Override
    public List<Map> countReturnTable(HttpServletResponse response, ReturnTableDto dto) {
        List<Map> maps = returnTableMapper.countReturnTable(dto);
        if (dto.getExport() == 1){
            exportCommonCodeService.exportCode(response,"rtCountService",maps);
        }
        return maps;
    }

    @Override
    public List<Map> countByVendor(HttpServletResponse response,ReturnTableDto dto) {
        List<Map> maps = returnTableMapper.countByVendor(dto);
        if (dto.getExport() == 1){
            exportCommonCodeService.exportCode(response,"returnTableCountService",maps);
        }
        return maps;
    }

    @Override
    public Page<Map> queryInfoReturnTable(HttpServletResponse response, Page page, ReturnTableDto dto) {
        if (dto.getExport() == 1){
            exportCommonCodeService.exportCode(response,"returnTableQueryService",returnTableMapper.queryInfoReturnTable(dto));
        }
        return returnTableMapper.queryInfoReturnTable(page, dto);
    }
}
