package org.jeecg.pm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.pm.entity.PmMonitoringDevice;
import org.jeecg.pm.hikvision.sdk.client.HikvisionClient;
import org.jeecg.pm.mapper.PmMonitoringDeviceMapper;
import org.jeecg.pm.service.IPmMonitoringDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * @Description: pm_monitoring_device
 * @Author: jeecg-boot
 * @Date: 2022-03-15
 * @Version: V1.0
 */
@Service
public class PmMonitoringDeviceServiceImpl extends ServiceImpl<PmMonitoringDeviceMapper, PmMonitoringDevice> implements IPmMonitoringDeviceService {

    @Autowired
    private HikvisionClient hikvisionClient;

    @Override
    public boolean save(PmMonitoringDevice entity) {
        entity.setId(IdWorker.getId())
                .setDeleted(false)
                .setCreateTime(new Date())
                .setModifyTime(new Date());
        return super.save(entity);
    }

    @Override
    public boolean updateById(PmMonitoringDevice entity) {
        entity.setModifyTime(new Date());
        return super.updateById(entity);
    }

    @Override
    public boolean removeById(Serializable id) {
        return update(
                new UpdateWrapper<PmMonitoringDevice>()
                        .lambda()
                        .eq(PmMonitoringDevice::getId, id)
                        .set(PmMonitoringDevice::getDeleted, true)
                        .set(PmMonitoringDevice::getModifyTime, new Date()));
    }

    @Override
    public List<PmMonitoringDevice> listByFloorId(Long floorId) {
        new QueryWrapper<PmMonitoringDevice>()
                .lambda()
                .eq(PmMonitoringDevice::getFloor, floorId);
        return null;
    }
}
