package com.seer.teach.iot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.seer.teach.iot.module.entity.DeviceModelsEntity;
import com.seer.teach.iot.module.mapper.DeviceModelsMapper;
import com.seer.teach.iot.service.DeviceModelsService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Wang
 * @since 2025-08-13 13:48:45
 */
@Service
public class DeviceModelsServiceImpl extends ServiceImpl<DeviceModelsMapper, DeviceModelsEntity> implements DeviceModelsService {

    @Override
    public DeviceModelsEntity getOrSaveByModelName(String modelName) {
        DeviceModelsEntity model = this.lambdaQuery()
                .eq(DeviceModelsEntity::getModel, modelName)
                .one();
        if (model != null) {
            return model;
        }
        model = new DeviceModelsEntity();
        model.setModel(modelName);
        this.save(model);
        return model;
    }
}
