package com.rehome.jpahefengweather.service.Impl;


import com.rehome.jpahefengweather.dao.TyphoonInfoRepository;
import com.rehome.jpahefengweather.dao.ZjsltStormRepository;
import com.rehome.jpahefengweather.entity.TyphoonInfo;
import com.rehome.jpahefengweather.entity.ZjsltStorm;
import com.rehome.jpahefengweather.service.ZjsltStormService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class ZjsltStormServiceImpl implements ZjsltStormService {
    @Resource
    private ZjsltStormRepository zjsltStormRepository;
    @Resource
    private TyphoonInfoRepository typhoonInfoRepository;


    @Override
    public ZjsltStorm findByTfid(String tfid) {
        return this.zjsltStormRepository.findByTfid(tfid);
    }

    @Override
    public List<ZjsltStorm> findByYear(String year) {
        return this.zjsltStormRepository.findByYear(year);
    }

    @Override
    public List<ZjsltStorm> getTyhoonActivity() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
        List<ZjsltStorm> list = this.zjsltStormRepository.findByYearAndIsactiveOrderByCreateDateDesc(sdf.format(new Date()),"1");
        if(list!=null&&list.size()>0){
            return list;
        }
        return new ArrayList();
    }

    @Override
    public void saveZjsltStorm(ZjsltStorm zjsltStorm) {
        this.zjsltStormRepository.save(zjsltStorm);
    }

    @Override
    public TyphoonInfo findTyphoonInfoByTfid(String tfid) {
        return this.typhoonInfoRepository.findByTfid(tfid);
    }

    @Override
    public void saveTyphoonInfo(TyphoonInfo typhoonInfo) {
        this.typhoonInfoRepository.save(typhoonInfo);
    }
}
