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.LineInfoDay;
import com.ruoyi.ucp.entity.PointInfo;
import com.ruoyi.ucp.mapper.LineInfoDayMapper;
import com.ruoyi.ucp.service.ILineInfoDayService;
import org.springframework.stereotype.Service;

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-21
 */
@Service
@DataSource(DataSourceType.SLAVE)
public class LineInfoDayServiceImpl extends ServiceImpl<LineInfoDayMapper, LineInfoDay> implements ILineInfoDayService {

    @Override
    public Map<String, LineInfoDay> getByEntity(PointInfo pointInfo) {
        LambdaQueryWrapper<LineInfoDay> wrapper = new LambdaQueryWrapper<>();
        if (pointInfo.getLineId() != null) {
            if ("all".equals(pointInfo.getLineId()))
                wrapper.isNotNull(LineInfoDay::getLineId);
            else
                wrapper.eq(LineInfoDay::getLineId, pointInfo.getLineId());
        } else if (pointInfo.getProjectId() != null) {
            if ("all".equals(pointInfo.getProjectId()))
                wrapper.isNotNull(LineInfoDay::getProjectId).isNull(LineInfoDay::getLineId);
            else
                wrapper.eq(LineInfoDay::getProjectId, pointInfo.getProjectId());
        } else if (pointInfo.getStationId() != null) {
            if ("all".equals(pointInfo.getStationId()))
                wrapper.isNotNull(LineInfoDay::getStationId).isNull(LineInfoDay::getProjectId)
                        .isNull(LineInfoDay::getLineId);
            else
                wrapper.eq(LineInfoDay::getStationId, pointInfo.getStationId());
        }
        //wrapper.eq(pointInfo.getRecordDate() != null, LineInfoDay::getRecordDate, pointInfo.getRecordDate());
        List<LineInfoDay> lineInfoDays = baseMapper.selectList(wrapper);

        return lineInfoDays.stream().collect(Collectors.toMap(LineInfoDay::getLineId, Function.identity()));
    }

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

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