package com.chinaitop.depot.intelligent.weather.service.impl;

import com.chinaitop.depot.intelligent.utils.DateUtils;
import com.chinaitop.depot.intelligent.weather.mapper.TWeatherhsitoryMapper;
import com.chinaitop.depot.intelligent.weather.model.TWeatherhsitory;
import com.chinaitop.depot.intelligent.weather.model.TWeatherhsitoryExample;
import com.chinaitop.depot.intelligent.weather.service.WeatherManagerService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class WeatherManagerServiceImpl implements WeatherManagerService {
    @Resource
    private TWeatherhsitoryMapper tWeatherhsitoryMapper;

    @Override
    public List<TWeatherhsitory> getList(String vqxzname,String searchStartDate,String searchEndDate) {
        TWeatherhsitoryExample example = new TWeatherhsitoryExample();
        TWeatherhsitoryExample.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotBlank(vqxzname)){
            criteria.andVqxznameLike("%"+vqxzname+"%");
        }
        if (StringUtils.isNotBlank(searchStartDate) && StringUtils.isNotBlank(searchEndDate)) {
            criteria.andUpdateTimeBetween(DateUtils.stringToData(searchStartDate + DateUtils.startTime), DateUtils.stringToData(searchEndDate + DateUtils.endTime));
        }
        example.setOrderByClause("update_time desc");
        List<TWeatherhsitory> tWeatherhsitories = tWeatherhsitoryMapper.selectByExample(example);
        return tWeatherhsitories;
    }
}
