package com.fs.watch.service.impl;

import com.fs.watch.domain.WatchAlarmData;
import com.fs.watch.domain.vo.AppWatchAlarmDataVo;
import com.fs.watch.mapper.WatchAlarmDataMapper;
import com.fs.watch.service.WatchAlarmDataService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author Administrator
* @description 针对表【watch_alarm_data(设备预警数据)】的数据库操作Service实现
* @createDate 2024-10-15 11:06:50
*/
@Service
@Slf4j
public class WatchAlarmDataServiceImpl implements WatchAlarmDataService {
    @Autowired
    private WatchAlarmDataMapper mapper;

    /**
     * 单条插入
     *
     * @param watchAlarmData
     * @return
     */
    @Override
    public Boolean insert(WatchAlarmData watchAlarmData) {
        try {
            mapper.insert(watchAlarmData);
        } catch (Exception e) {
            log.error("===============watchAlarmData:insert=========================={}", e.getMessage());
            return false;
        }
        return true;
    }

    /**
     * 批量插入
     *
     * @param list
     */
    @Override
    public Boolean batchInsertData(List<WatchAlarmData> list) {
        mapper.batchInsertData(list);
        return true;
    }

    @Override
    public List<WatchAlarmData> queryByStatus(Integer status) {
        return mapper.queryByStatus(status);

    }

    @Override
    public List<WatchAlarmData> queryPageByStatus(WatchAlarmData data) {
        return mapper.queryPageByStatus(data);
    }

    @Override
    public List<WatchAlarmData> queryByStatusAndDeviceid(Integer status, String deviceId) {
        return mapper.queryByStatusAndDeviceid(status, null,deviceId);
    }

    @Override
    public AppWatchAlarmDataVo queryByAppStatusAndDeviceid(Integer appStatus, String deviceId) {
        AppWatchAlarmDataVo vo = new AppWatchAlarmDataVo();
        vo.setData(mapper.queryByStatusAndDeviceid(null,appStatus, deviceId));
        vo.setUnreadNum(mapper.getUnreadNum(deviceId));
        return vo;
    }

    @Override
    public AppWatchAlarmDataVo queryPageByAppStatus(WatchAlarmData data) {
        AppWatchAlarmDataVo vo = new AppWatchAlarmDataVo();
        vo.setData(mapper.queryPageByStatus(data));
        vo.setUnreadNum(mapper.getUnreadNum(data.getDeviceId()));
        return vo;
    }

    @Override
    public Integer setAppStatusById(List<String> ids) {
        return mapper.setAppStatusById(ids);
    }

    @Override
    public Boolean deleteByIds(List<String> ids) {
        mapper.setIsDel(ids);
        return true;
    }

    @Override
    public Integer setStatusById(List<String> ids) {
        return mapper.setStatusById(ids);
    }

    @Override
    public Integer setAppStatusByDeviceId(String deviceId) {
        return mapper.setAppStatusByDeviceId(deviceId);
    }

    @Override
    public Boolean deleteByDeviceId(String deviceId) {
        mapper.deleteByDeviceId(deviceId);
        return true;
    }
}
