package org.jeecg.pm.service.impl.event;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.pm.entity.event.PmEventInfo;
import org.jeecg.pm.mapper.event.PmEventInfoMapper;
import org.jeecg.pm.service.event.IPmEventInfoService;
import org.springframework.stereotype.Service;

/**
 * @Description: pm_event_info
 * @Author: jeecg-boot
 * @Date: 2022-04-01
 * @Version: V1.0
 */
@Slf4j
@Service
public class PmEventInfoServiceImpl extends ServiceImpl<PmEventInfoMapper, PmEventInfo> implements IPmEventInfoService {

    @Override
    public void saveEvent(PmEventInfo pmEventInfo) {
        final PmEventInfo eventInfo = baseMapper.selectOne(new QueryWrapper<PmEventInfo>().lambda().eq(PmEventInfo::getLogId, pmEventInfo.getLogId()));//事件唯一ID
        if (eventInfo == null) {
            pmEventInfo.setId(IdWorker.getId());
            baseMapper.insert(pmEventInfo);
            return;
        }
        eventInfo.setEventLevel(pmEventInfo.getEventLevel()).setEventState(pmEventInfo.getEventState()).setStopTime(pmEventInfo.getStopTime());
        baseMapper.updateById(eventInfo);
    }


}
