package com.zcxk.service.impl.alarm;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zcxk.dao.alarm.DataAlarmDetailMapper;
import com.zcxk.dto.alarm.DataAlarmDto;
import com.zcxk.dto.alarm.DataAlarmQueryDto;
import com.zcxk.model.LoginUser;
import com.zcxk.service.DataAlarmDetailService;
import com.zcxk.util.UserUtil;
import com.zcxk.vo.DataAlarmDetailsVo;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 数据报警详情
 * @author lihui
 * @version V1.0
 * @date 2021/5/31
 **/
@Service
@Log4j2
public class DataAlarmDetailServiceImpl implements DataAlarmDetailService {

    @Resource
    private DataAlarmDetailMapper dataAlarmDetailMapper;


    @Override
    public Page<DataAlarmDetailsVo> findPage(DataAlarmDto dto, int isHistory) {
        DataAlarmQueryDto queryDto = new DataAlarmQueryDto();
        BeanUtils.copyProperties(dto, queryDto);
        LoginUser loginUser = UserUtil.getCurrentUser();
        queryDto.setTenantId(loginUser.getTenantId());
        queryDto.setProgramItems(loginUser.getProgramItemList());
        queryDto.setUserType(loginUser.getType());
        //1是公司，2是公司及以下，3部门，4部门及以下，5自定义
        queryDto.setPermissonType(loginUser.getPermissonType());
        return dataAlarmDetailMapper.findPage(new Page<>(dto.getPageNum(), dto.getPageSize()), queryDto, isHistory);
    }

    @Override
    public void hangUpAlarmDetails(Long alarmId,int status) {
        dataAlarmDetailMapper.hangUpAlarmDetails(alarmId, status);
    }
}
