package com.huimv.lamp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huimv.lamp.dao.entity.LampEntity;
import com.huimv.lamp.dao.repo.LampRepo;
import com.huimv.lamp.pojo.Lamp;
import com.huimv.lamp.mapper.LampMapper;
import com.huimv.lamp.service.LampService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zn
 * @since 2022-08-02
 */
@Service
public class LampServiceImpl extends ServiceImpl<LampMapper, Lamp> implements LampService {
//    @Resource
    @Autowired
    private LampMapper lampMapper;

    @Autowired
    private LampRepo lampRepo;

    //返回亮度
    @Override
    public int getLighteness(String askText){
        Lamp lamp = lampMapper.selectOne2();
        System.out.println("lamp="+lamp.toString());
        int lightness = 30;
        if(lamp != null){
            lightness = lamp.getLightness();
        }
        return lightness;
    }

    //返回亮度
    @Override
    public Integer getLighteness(){
        QueryWrapper<Lamp> queryWrapper = new QueryWrapper<>();
        Lamp lamp = lampMapper.selectOne(queryWrapper);
        Integer lightness = 30;
        if(lamp != null){
            lightness = lamp.getLightness();
        }
        return lightness;
    }

    @Override
    public Boolean updateLightness(Integer lightness) {
        QueryWrapper<Lamp> queryWrapper = new QueryWrapper<>();
        Lamp lamp = lampMapper.selectOne(queryWrapper);
        lamp.setLightness(lightness);
        Integer rows = lampMapper.updateById(lamp);
        if(rows > 0){
            return true;
        }else{
            return false;
        }
    }

    @Override
    public int getLight(){
        LampEntity lampEntity = lampRepo.getLightness();
        System.out.println("lampEntity>>"+lampEntity.toString());
        int lightness = 50;
        if(lampEntity != null){
            lightness = lampEntity.getLightness();
        }
        return lightness;
    }
}
