package com.goldenwater.yjjt.service.impl;

import com.goldenwater.yjjt.domain.YjjtStation;
import com.goldenwater.yjjt.mapper.YjjtStationMapper;
import com.goldenwater.yjjt.service.IYjjtStationService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

@Service("yjjtStationService")
public class YjjtStationServiceImpl implements IYjjtStationService {

    @Resource
    private YjjtStationMapper yjjtStationMapper;

    @Override
    public List<YjjtStation> selectYjjtStationList(YjjtStation yjjtStation) {
        return yjjtStationMapper.selectYjjtStationList(yjjtStation);
    }

    @Override
    public YjjtStation selectYjjtStationByPk(String stcd, String year) {
        return yjjtStationMapper.selectYjjtStationByPk(stcd, year);
    }

    @Override
    public int insertYjjtStation(YjjtStation yjjtStation) {
        return yjjtStationMapper.insertYjjtStation(yjjtStation);
    }

    @Override
    public int updateYjjtStation(YjjtStation yjjtStation) {
        return yjjtStationMapper.updateYjjtStation(yjjtStation);
    }

    @Override
    public int deleteYjjtStationByPk(String stcd, String year) {
        return yjjtStationMapper.deleteYjjtStationByPk(stcd, year);
    }

    @Override
    public int deleteYjjtStationByPks(List<YjjtStation> list) {
        return yjjtStationMapper.deleteYjjtStationByPks(list);
    }

    @Override
    @Transactional
    public void importStation(List<YjjtStation> stationList) {
        for (YjjtStation station : stationList) {
            YjjtStation existing = yjjtStationMapper.selectYjjtStationByPk(station.getStcd(), station.getYear());
            if (existing != null) {
                yjjtStationMapper.updateYjjtStation(station);
            } else {
                yjjtStationMapper.insertYjjtStation(station);
            }
        }
    }

    @Override
    public List<YjjtStation> selectYjjtStationAll() {
        return yjjtStationMapper.selectYjjtStationList(new YjjtStation());
    }
}
