package com.jiayue.ipp.idp.service.impl.an;

import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiayue.ipp.common.data.entity.an.ChannelStatus;
import com.jiayue.ipp.idp.mapper.an.ChannelStatusMapper;
import com.jiayue.ipp.idp.service.an.ChannelStatusService;
import org.springframework.stereotype.Service;

/**
 * 通道状态表
 *
 * @author csc code generator
 * @date 2022-12-28 14:49:40
 */
@Service
public class ChannelStatusServiceImpl extends ServiceImpl<ChannelStatusMapper, ChannelStatus> implements ChannelStatusService {

    /**
     * 根据上报时间 场站编号 通道状态 通道类型 构造查询条件
     *
     * @param stationCode       场站编号
     * @param startTime         上报时间
     * @param endTime           上报时间
     * @param channelStatusCode 通道状态
     * @param channelTypeCode   通道类型
     * @return 查询条件
     */
    @Override
    public QueryWrapper<ChannelStatus> findByStationCodeAndStartTimeBetweenAndChannelStatusAndChannelType(String stationCode, Long startTime, Long endTime, String channelStatusCode, String channelTypeCode) {
        QueryWrapper<ChannelStatus> wrapper = new QueryWrapper<>();
        if (stationCode != null && !stationCode.equals("")) {
            wrapper.eq("station_code", stationCode);
        }
        if (startTime != null && endTime != null) {
            wrapper.between("upload_time", new DateTime(startTime), new DateTime(endTime));
        }
        if (channelStatusCode != null && !channelStatusCode.equals("")) {
            wrapper.eq("status", channelStatusCode);
        }
        if (channelTypeCode != null && !channelTypeCode.equals("")) {
            wrapper.eq("type", channelTypeCode);
        }
        return wrapper;
    }
}
