package org.jeecg.modules.device.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.modules.device.entity.BuDevice;
import org.jeecg.modules.device.entity.DeviceBreakdownDossier;
import org.jeecg.modules.device.entity.Part;
import org.jeecg.modules.device.mapper.BuDeviceMapper;
import org.jeecg.modules.device.mapper.DeviceBreakdownDossierMapper;
import org.jeecg.modules.device.mapper.PartMapper;
import org.jeecg.modules.device.service.IDeviceBreakdownDossierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * @Description: 故障知识库
 * @Author: jeecg-boot
 * @Date:   2025-08-28
 * @Version: V1.0
 */
@Service
public class DeviceBreakdownDossierServiceImpl extends ServiceImpl<DeviceBreakdownDossierMapper, DeviceBreakdownDossier> implements IDeviceBreakdownDossierService {

    @Autowired
    private BuDeviceMapper deviceMapper;
    @Autowired
    private PartMapper partMapper;


    @Override
    public DeviceBreakdownDossier getBySpecific(DeviceBreakdownDossier dossier){
        if(StringUtils.isBlank(dossier.getDeviceId()) || StringUtils.isBlank(dossier.getDepartId())) {
            throw new RuntimeException("未指定设备或部件！");
        }
        BuDevice device = deviceMapper.selectById(dossier.getDeviceId());
        if(device == null) {
            throw new RuntimeException("设备不存在！");
        }
        Part part = partMapper.selectById(dossier.getDepartId());
        if(part == null) {
            throw new RuntimeException("部件不存在！");
        }

        return baseMapper.selectOne(new LambdaQueryWrapper<DeviceBreakdownDossier>()
                .eq(DeviceBreakdownDossier::getDeviceId, dossier.getDeviceId())
                .eq(DeviceBreakdownDossier::getDepartId,dossier.getDepartId())
                .eq(DeviceBreakdownDossier::getBreakdownType,dossier.getBreakdownType()));

    }
}
