package com.ycwl.basic.service.pc.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ycwl.basic.mapper.FaceDetectLogMapper;
import com.ycwl.basic.model.pc.faceDetectLog.entity.FaceDetectLog;
import com.ycwl.basic.model.pc.faceDetectLog.req.FaceDetectLogReqQuery;
import com.ycwl.basic.service.pc.FaceDetectLogService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

@Service
public class FaceDetectLogServiceImpl extends ServiceImpl<FaceDetectLogMapper, FaceDetectLog> implements FaceDetectLogService {
    @Override
    public List<FaceDetectLog> listByTimeDesc(FaceDetectLogReqQuery req) {
        LambdaQueryWrapper<FaceDetectLog> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.orderByDesc(FaceDetectLog::getCreateTime);
        queryWrapper.gt(Objects.nonNull(req.getStartTime()), FaceDetectLog::getCreateTime, req.getStartTime());
        queryWrapper.lt(Objects.nonNull(req.getEndTime()), FaceDetectLog::getCreateTime, req.getEndTime());
        queryWrapper.likeLeft(StringUtils.isNotBlank(req.getScenicId()), FaceDetectLog::getDbName, req.getScenicId());
        return list(queryWrapper);
    }
}
