package com.zcxk.service;


import com.zcxk.dao.MonitorInfoMapper;
import com.zcxk.dto.SceneDeviceAttributeDto;
import com.zcxk.entity.MonitorInfoEntity;
import com.zcxk.model.LoginUser;
import com.zcxk.util.UserUtil;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.annotation.Resource;

import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.Arrays;

/**
 * 标签信息Service接口
 *
 * @author: WYY
 * @date 2020-12-02 09:29
 */
@Service
public class MonitorInfoService extends ServiceImpl<MonitorInfoMapper, MonitorInfoEntity> {

    @Resource
    private MonitorInfoMapper monitorInfoMapper;

    /**
     * 查列表
     */
    public List<MonitorInfoEntity> findList(MonitorInfoEntity monitorInfoEntity) {
        LoginUser currentUser = UserUtil.getCurrentUser();
        monitorInfoEntity.setTenantId(currentUser.getTenantId());
        return monitorInfoMapper.findList(monitorInfoEntity);
    }

    /**
     * 批量删除
     */
    @Transactional(rollbackFor = Exception.class)
    public boolean delMonitorInfoByIds(Long[] ids) {
        return this.removeByIds(Arrays.asList(ids));
    }

    /**
     * 单个删除
     */
    public boolean delMonitorInfoById(Long id) {
        return this.removeById(id);
    }

    /**
     * 保存
     */
    public boolean addMonitorInfo(MonitorInfoEntity monitorInfo) {
        LoginUser currentUser = UserUtil.getCurrentUser();
        if(currentUser!=null) {
            monitorInfo.setTenantId(currentUser.getTenantId());
            monitorInfo.setCreateBy(currentUser.getName());
            monitorInfo.setUpdateBy(currentUser.getName());
        }
        monitorInfo.setStatus(1);
        monitorInfo.setDateCreate(new Date());
        monitorInfo.setDateUpdate(new Date());
        if (this.save(monitorInfo)) {
            return true;
        }
        return false;
    }

    /**
     * 修改根居ID
     */
    public boolean updateMonitorInfoById(MonitorInfoEntity monitorInfo) {
        LoginUser currentUser = UserUtil.getCurrentUser();
        if(currentUser!=null) {
            monitorInfo.setTenantId(currentUser.getTenantId());
            monitorInfo.setUpdateBy(currentUser.getName());
        }
        monitorInfo.setDateUpdate(new Date());
        if (this.updateById(monitorInfo)) {
            return true;
        }
        return false;
    }

    /**
     * 根居ID获取对象
     */
    public MonitorInfoEntity findMonitorInfoById(Long id) {
        return monitorInfoMapper.findMonitorInfoById(id);
    }

    public List<SceneDeviceAttributeDto> findAttributeList(SceneDeviceAttributeDto sceneDeviceAttributeDto)
    {
        return monitorInfoMapper.findAttributeList(sceneDeviceAttributeDto);
    }

    public List<SceneDeviceAttributeDto> findAttributeListForLastDay(SceneDeviceAttributeDto sceneDeviceAttributeDto)
    {
        return monitorInfoMapper.findAttributeListForLastDay(sceneDeviceAttributeDto);
    }
}
