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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.watermeter.custom.entity.meterBusiness.dto.WeekConditionDto;
import com.tofly.watermeter.custom.mapper.meterBusiness.WeeklyInspectionMapper;
import com.tofly.watermeter.custom.service.meterBusiness.WeeklyInspectionService;
import com.tofly.watermeter.custom.service.meterBusiness.export.ExportCommonCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

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

@Service
public class WeeklyInspectionServiceImpl implements WeeklyInspectionService {

    @Autowired
    private WeeklyInspectionMapper weeklyInspectionMapper;

    @Autowired
    private ExportCommonCodeService exportCommonCodeService;

    /**
     * 口径15-25周检月份
     */
    @Value("${meter.weekCheck.monthOne}")
    private String monthOne;
    /**
     * 口径40-50周检月份
     */
    @Value("${meter.weekCheck.monthTwo}")
    private String monthTwo;
    /**
     * 口径大于等于80周检月份
     */
    @Value("${meter.weekCheck.monthThree}")
    private String monthThree;
    /**
     * 表类型为网络表周检月份（优先）
     */
    @Value("${meter.weekCheck.monthFour}")
    private String monthFour;

    @Override
    public List<Map> count(HttpServletResponse response, WeekConditionDto dto) {

        dto.setMonthOne(Integer.parseInt(monthOne))
                .setMonthTwo(Integer.parseInt(monthTwo))
                .setMonthThree(Integer.parseInt(monthThree))
                .setMonthFour(Integer.parseInt(monthFour));

        List<Map> count = weeklyInspectionMapper.count(dto);

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

        return count;
    }

    @Override
    public Page<Map> queryInfo(HttpServletResponse response, Page page, WeekConditionDto dto) {
        dto.setMonthOne(Integer.parseInt(monthOne))
                .setMonthTwo(Integer.parseInt(monthTwo))
                .setMonthThree(Integer.parseInt(monthThree))
                .setMonthFour(Integer.parseInt(monthFour));
        if (dto.getExport() == 1) {
            exportCommonCodeService.exportCode(response, "weeklyInspectionQueryInfo", weeklyInspectionMapper.queryInfo(dto));
        }
        return weeklyInspectionMapper.queryInfo(page, dto);
    }
}
