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.ReportingRateRecords;
import com.jiayue.ipp.idp.mapper.an.ReportingRateRecordsMapper;
import com.jiayue.ipp.idp.service.an.ReportingRateRecordsService;
import org.springframework.stereotype.Service;

/**
 * 上报率记录表
 *
 * @author csc code generator
 * @date 2022-12-28 14:49:14
 */
@Service
public class ReportingRateRecordsServiceImpl extends ServiceImpl<ReportingRateRecordsMapper, ReportingRateRecords> implements ReportingRateRecordsService {


    /**
     * 根据场站编号 时间范围 文件类型构造查询条件
     *
     * @param stationCode 场站类型
     * @param startTime   开始时间
     * @param endTime     结束时间
     * @param reportType  上报文件类型
     * @return
     */
    @Override
    public QueryWrapper<ReportingRateRecords> findByStationCodeAndTimeBetweenAndReportType(String stationCode, Long startTime, Long endTime, String reportType) {
        QueryWrapper<ReportingRateRecords> 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 (reportType != null && !reportType.equals("")) {
            wrapper.eq("file_type", reportType);
        }
        wrapper.orderByDesc("upload_time");
        return wrapper;
    }
}
