package com.ruoyi.iot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.iot.domain.WeitiandiDeviceInfo;
import com.ruoyi.iot.mapper.WeitiandiDeviceInfoMapper;
import com.ruoyi.iot.service.IWeitiandiDeviceInfoService;
import com.ruoyi.iot.util.UrlUtil;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wzh
 * @since 2023-07-01
 */
@Service
public class WeitiandiDeviceInfoServiceImpl extends ServiceImpl<WeitiandiDeviceInfoMapper, WeitiandiDeviceInfo> implements IWeitiandiDeviceInfoService {

    @Override
    @DataSource(value = DataSourceType.SLAVE)
    public WeitiandiDeviceInfo getDeviceInfoByQrcode(String qrcode, Long userId) {
        Map<String, String> param = UrlUtil.getParam(qrcode);
        if(param != null){
            String sn = param.get("sn");
            LambdaQueryWrapper<WeitiandiDeviceInfo> objectLambdaQueryWrapper = Wrappers.lambdaQuery();
            objectLambdaQueryWrapper.eq(WeitiandiDeviceInfo::getQrcode,sn);
            WeitiandiDeviceInfo one = getOne(objectLambdaQueryWrapper);
            return one;
        }
        return null;
    }
}
