package com.tuoheng.admin.service.warning.notice;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tuoheng.admin.entity.domain.Warning;
import com.tuoheng.admin.enums.FlagEnum;
import com.tuoheng.admin.enums.MarkTypeEnum;
import com.tuoheng.admin.enums.MessageReadEnum;
import com.tuoheng.admin.enums.WarningStatusEnum;
import com.tuoheng.admin.mapper.WarningMapper;
import com.tuoheng.common.utils.JsonResult;
import com.tuoheng.system.entity.User;
import com.tuoheng.system.utils.ShiroUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 火灾预警通知下发业务处理层
 * @Author ChengWang
 * @Date 2023/2/9
 */
@Service
@Slf4j
public class WarningNoticeService {

    @Autowired
    private WarningMapper warningMapper;

    /**
     * 火灾通知下发弹窗
     * @return
     */
    public JsonResult notice() {
        //当前登录用户
        User user = ShiroUtils.getUserInfo();
        Integer tenantId = ShiroUtils.getTenantId();
        //查询预警表是否有预警数据
        List<Warning> warningList = warningMapper.selectList(Wrappers.<Warning>lambdaQuery()
                .eq(Warning::getTenantId, tenantId)
                .eq(Warning::getStatus, WarningStatusEnum.WAIT_CONFIRM.getCode())
                .eq(Warning::getMessageRead, MessageReadEnum.MESSAGE_IS_NO_READ.getCode())
                .eq(Warning::getFlag, FlagEnum.INSPECTION_ACCIDENT.getCode())
                .eq(Warning::getMark, MarkTypeEnum.VALID.getCode()));
        if(CollectionUtils.isEmpty(warningList) || warningList.size() == 0){
            return JsonResult.success();
        }
        return JsonResult.success(warningList);
    }
}
