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

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tuoheng.admin.entity.domain.Warning;
import com.tuoheng.admin.enums.MarkTypeEnum;
import com.tuoheng.admin.enums.MessageReadEnum;
import com.tuoheng.admin.mapper.WarningMapper;
import com.tuoheng.common.utils.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author ChengWang
 * @Date 2023/2/9
 */
@Service
@Slf4j
public class WarningStatusService {

    @Autowired
    private WarningMapper warningMapper;

    /**
     * 通知忽略与处理
     * @param id
     * @return
     */
    public JsonResult editStatusById(Integer id) {
        //根据id查询并更新预警状态
        Warning warning = warningMapper.selectById(id);
        if(ObjectUtils.isNotEmpty(warning)){
            warning.setMessageRead(MessageReadEnum.MESSAGE_IS_READ.getCode());
            int result = warningMapper.updateById(warning);
            if(result<=0){
                return JsonResult.error();
            }
        }

        return JsonResult.success();
    }
}
