package com.fs.company.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fs.company.domain.CompanyTrafficRecordLog;
import com.fs.company.mapper.CompanyTrafficRecordLogMapper;
import com.fs.company.param.CompanyTrafficRecordLogQueryParam;
import com.fs.company.service.ICompanyTrafficRecordLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class CompanyTrafficRecordLogServiceImpl extends ServiceImpl<CompanyTrafficRecordLogMapper, CompanyTrafficRecordLog> implements ICompanyTrafficRecordLogService {


    @Override
    public List<CompanyTrafficRecordLog> selectList(CompanyTrafficRecordLogQueryParam record) {
        return baseMapper.selectList(new LambdaQueryWrapper<CompanyTrafficRecordLog>()
                .eq(record.getCompanyId() != null ,CompanyTrafficRecordLog::getCompanyId, record.getCompanyId())
                .in(record.getCompanyIds() != null,CompanyTrafficRecordLog::getCompanyId, record.getCompanyIds())
                .eq(record.getUserId() != null ,CompanyTrafficRecordLog::getUserId, record.getUserId())
                .eq(record.getOperationType() != null ,CompanyTrafficRecordLog::getOperationType, record.getOperationType())
                .eq(record.getCreateTime() != null ,CompanyTrafficRecordLog::getCreateTime, record.getCreateTime())
                .between(record.getCreateTimeStart() != null && record.getCreateTimeEnd() != null,CompanyTrafficRecordLog::getCreateTime, record.getCreateTimeStart(), record.getCreateTimeEnd())
                .orderByDesc(CompanyTrafficRecordLog::getCreateTime));
    }

    @Override
    public CompanyTrafficRecordLog selectById(Long id) {
        return baseMapper.selectById(id);
    }

    @Override
    public boolean save(CompanyTrafficRecordLog entity) {
        return baseMapper.insert(entity)==1;
    }
}
