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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.watermeter.custom.entity.meterBusiness.dto.NewInstallDto;
import com.tofly.watermeter.custom.mapper.meterBusiness.NewInstallMapper;
import com.tofly.watermeter.custom.service.meterBusiness.NewInstallService;
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 NewInstallServiceImpl implements NewInstallService {

    private final NewInstallMapper newInstallMapper;
    private final ExportCommonCodeService exportCommonCodeService;

    @Override
    public List<Map> count(HttpServletResponse response, NewInstallDto dto) {
        List<Map> count = newInstallMapper.count(dto);
        if (dto.getExport() == 1) {
            exportCommonCodeService.exportCode(response, "newInstallCountService", count);
        }
        return count;
    }

    @Override
    public Page<Map> countByDept(HttpServletResponse response, Page page, NewInstallDto dto) {
        if (dto.getExport() == 1){
            exportCommonCodeService.exportCode(response,"newInstallByDeptService",newInstallMapper.countByDept(dto));
        }
        return newInstallMapper.countByDept(page,dto);
    }

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

}
