package com.muyu.enterprise.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.core.utils.StringUtils;

import com.muyu.domain.FaultLog;
import com.muyu.enterprise.mapper.FaultLogMapper;
import com.muyu.enterprise.service.FaultLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
/**
 * @Author：ChenYan
 * @Project：2112-car-cloud-server
 * @Package：com.muyu.fault.service
 * @Filename：IFaultLogServiceImpl
 * @Description TODO
 * @Date：2024/9/16 20:37
 */
@Service
public class FaultLogServiceImpl extends ServiceImpl<FaultLogMapper, FaultLog> implements FaultLogService {


@Autowired
private FaultLogMapper faultLogMapper;

    @Override
    public List<FaultLog> pageQuery(FaultLog fault) {
        LambdaQueryWrapper<FaultLog> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotEmpty(fault.getFaultCode())) {
            queryWrapper.like(FaultLog::getFaultCode, fault.getFaultCode());
        }
        if (StringUtils.isNotEmpty(fault.getVin())) {
            queryWrapper.like(FaultLog::getVin, fault.getVin());
        }

        // 时间区间查询
        if (fault.getWarningTime() != null ) {
            queryWrapper.gt(FaultLog::getWarningTime, fault.getWarningTime());
        }



        if (fault.getNormalTime() != null ) {
            queryWrapper.lt(FaultLog::getNormalTime, fault.getNormalTime());
        }


        return this.list(queryWrapper);
    }

    /**
     * 添加
     * @param log
     */
    @Override
    public int insertFaultLog(FaultLog log) {

        return 0;
    }
    /**
     *修改
     * @param log
     */
    @Override
    public int updateFaultLogByStatus(FaultLog log) {
        log.setId(faultLogMapper.selectFaultId(log));
      return faultLogMapper.updateFaultLogByTime(log);
    }

}
