package com.tofly.xrtygis.custom.service.zsdata.impl;

import com.tofly.common.core.util.Date8Util;
import com.tofly.common.core.util.StringUtil;
import com.tofly.xrtygis.custom.entity.dataquery.WaterPlanSearch;
import com.tofly.xrtygis.custom.service.zsdata.DataOfferWaterService;
import com.tofly.xrtygis.mapper.CostrlwaterMapper;
import com.tofly.xrtygis.service.CostrlwaterService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

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

/**
 * @author FlashWJL
 * @date 2021/5/14 14:53
 */
@Service
@AllArgsConstructor
public class DataOfferWaterServiceImpl implements DataOfferWaterService {

    private final CostrlwaterMapper mapper;


    @Override
    public List<Map> quarterDataOffer(HttpServletResponse response, WaterPlanSearch search) {
        String year = search.getYear();
        if (StringUtil.isEmpty(year)){
            return null;
        }
        List<Map> quarterDataOffer = mapper.getQuarterDataOffer(year);
        return quarterDataOffer;
    }

    @Override
    public List<Map> monthDataOffer(HttpServletResponse response, WaterPlanSearch search) {
        Date startMonth = search.getStartMonth();
        if (StringUtil.isNull(startMonth)){
            return null;
        }
        String year = Date8Util.format(startMonth, "yyyy");
        String month = Date8Util.format(startMonth, "MM");

        List<Map> monthDataOffer = mapper.getMonthDataOffer(year , month);
        return monthDataOffer;
    }

    @Override
    public List<Map> yearDataOffer(HttpServletResponse response, WaterPlanSearch search) {
        String year = search.getYear();
        if (StringUtil.isEmpty(year)){
            return null;
        }
        List<Map> yearDataOffer = mapper.getYearDataOffer(year);
        return yearDataOffer;
    }


}
