package com.muyu.breakdown.service.impl;

import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.muyu.breakdown.domain.BreakDown;
import com.muyu.breakdown.domain.MessageMap;
import com.muyu.breakdown.domain.SysCarMessage;
import com.muyu.breakdown.mapper.BreakDownMapper;
import com.muyu.breakdown.service.BreakDownService;
import com.muyu.breakdown.service.SysCarMessageService;
import com.muyu.common.core.utils.StringUtils;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ Tool：IntelliJ IDEA
 * @ Author：CHX
 * @ Date：2024-09-17-15:31
 * @ Version：1.0
 * @ Description：故障管理业务实现层
 * @author Lenovo
 */
@Service
public class BreakDownServiceImpl extends ServiceImpl<BreakDownMapper, BreakDown> implements BreakDownService {

    @Autowired
    private SysCarMessageService sysCarMessageService;
    @Autowired
    private RabbitTemplate rabbitTemplate;
    /**
     * 精确查询车辆故障
     *
     * @param id 车辆故障主键
     * @return 车辆故障
     */
    @Override
    public BreakDown selectBreakDownById(Long id)
    {
        LambdaQueryWrapper<BreakDown> queryWrapper = new LambdaQueryWrapper<>();
        Assert.notNull(id, "id不可为空");
        queryWrapper.eq(BreakDown::getId, id);
        return this.getOne(queryWrapper);
    }


    /**
     * 查询车辆故障列表
     *
     * @param breakDown 车辆故障
     * @return 车辆故障
     */
    @Override
    public List<BreakDown> selectBreakDownList(BreakDown breakDown)
    {
        LambdaQueryWrapper<BreakDown> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotEmpty(breakDown.getFaultCode())){
            queryWrapper.eq(BreakDown::getFaultCode, breakDown.getFaultCode());
        }
        if (StringUtils.isNotEmpty(breakDown.getFaultType())){
            queryWrapper.eq(BreakDown::getFaultType, breakDown.getFaultType());
        }
        return this.list(queryWrapper);
    }

    /**
     * 唯一 判断
     * @param breakDown 车辆故障
     * @return 车辆故障
     */
    @Override
    public Boolean checkIdUnique(BreakDown breakDown) {
        LambdaQueryWrapper<BreakDown> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BreakDown::getId, breakDown.getId());
        return this.count(queryWrapper) > 0;
    }

    @Override
    public Map<String, String> getMessages(MessageMap messageMap) {

        return null;
    }

//    @RabbitListener(queues = "car.message.queue")
//    private void sendMessage(String message) {
//
//    }


}
