/*
 * Author: wangjian
 * 生成ServiceImpl
 */
package com.tofly.xrtygis.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tofly.common.oauth.exception.ToflyDeniedException;
import com.tofly.common.oauth.util.SecurityUtils;
import com.tofly.xrtygis.entity.Costwarn;
import com.tofly.xrtygis.mapper.CostwarnMapper;
import com.tofly.xrtygis.service.CostwarnService;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * 报警提示信息表
 *
 * @author admin
 * @date Wed Jun 02 00:00:00 CST 2021
 */
@Service("costwarnService")
public class CostwarnServiceImpl extends ServiceImpl<CostwarnMapper, Costwarn> implements CostwarnService {

    /**
     * 关闭报警提示信息
     *
     * @param id id
     * @return true
     */
    @Override
    public boolean shutDownWarn(Long id) {
        Costwarn costwarn = this.getById(id);
        if ("0".equals(costwarn.getState())){
            throw new ToflyDeniedException("该报警提示信息已关闭");
        }
        if (!SecurityUtils.getUserId().equals(costwarn.getCreateUser())){
            throw new ToflyDeniedException("请联系创建人关闭");
        }

    return this.update(Wrappers.<Costwarn>lambdaUpdate()
            .eq(Costwarn::getId,id).set(Costwarn::getState,"0")
            .set(Costwarn::getCloseTime,new Date()));
    }
}
