package cn.sikey.hmd.dal.mysql;

import cn.sikey.hmd.dal.dataobject.DeviceActivationDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;

import java.time.LocalDateTime;

/**
 * 设备激活
 *
 * @author qin
 */
@Mapper
public interface DeviceActivationMapper extends BaseMapper<DeviceActivationDO> {

    default DeviceActivationDO queryDeviceActivation(String deviceId) {
        QueryWrapper<DeviceActivationDO> wrapper = new QueryWrapper<>();
        wrapper.eq("device_id", deviceId);
        return selectOne(wrapper);
    }

    default int updateDeviceActivation(String deviceId, LocalDateTime finalExpireTime,int plansValidity) {
        UpdateWrapper<DeviceActivationDO> wrapper = new UpdateWrapper<>();
        wrapper.eq("device_id", deviceId);
        wrapper.set("final_expire_time", finalExpireTime);
        wrapper.set("plans_validity", plansValidity);
        wrapper.set("updater", deviceId);
        wrapper.set("update_time", LocalDateTime.now());
        return update(wrapper);
    }
}


