package com.ruoyi.ucp.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.ucp.entity.PointInfo;
import com.ruoyi.ucp.entity.StationInfoDay;
import com.ruoyi.ucp.mapper.StationInfoDayMapper;
import com.ruoyi.ucp.service.IStationInfoDayService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author gfhd
 * @since 2024-03-05
 */
@Service
@DataSource(DataSourceType.SLAVE)
public class StationInfoDayServiceImpl extends ServiceImpl<StationInfoDayMapper, StationInfoDay> implements IStationInfoDayService {

    @Override
    public Map<String, StationInfoDay> getByEntity(PointInfo pointInfo) {
        LambdaQueryWrapper<StationInfoDay> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(pointInfo.getStationId() != null, StationInfoDay::getStationId, pointInfo.getStationId());
        //wrapper.eq(pointInfo.getRecordDate() != null, StationInfoDay::getRecordDate, pointInfo.getRecordDate());
        List<StationInfoDay> stationInfoDays = baseMapper.selectList(wrapper);

        return stationInfoDays.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
    }

    @Override
    @Transactional
    public boolean saveOrUpdateBatch(Collection<StationInfoDay> entityList) {
        return super.saveOrUpdateBatch(entityList);
    }

    @Override
    public StationInfoDay getOne(Wrapper<StationInfoDay> queryWrapper) {
        return super.getOne(queryWrapper);
    }

    @Override
    public List<StationInfoDay> list(Wrapper<StationInfoDay> queryWrapper) {
        return super.list(queryWrapper);
    }
}
