package com.cmvr.inspection.service.impl;

import java.util.List;
import java.util.UUID;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cmvr.common.utils.SecurityUtils;
import com.cmvr.inspection.domain.vo.InspectionAlarmVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.cmvr.common.utils.DateUtils;
import com.cmvr.inspection.mapper.InspectionAlarmMapper;
import com.cmvr.inspection.domain.InspectionAlarm;
import com.cmvr.inspection.service.IInspectionAlarmService;

/**
 * 巡检告警Service业务层处理
 * 
 * @author cmvr-iot
 * @since 2026-05-29
 */
@Service
public class InspectionAlarmServiceImpl extends ServiceImpl<InspectionAlarmMapper, InspectionAlarm> implements IInspectionAlarmService
{
    @Autowired
    private InspectionAlarmMapper inspectionAlarmMapper;

    /**
     * 查询巡检告警
     * 
     * @param id 巡检告警主键
     * @return 巡检告警
     */
    @Override
    public InspectionAlarm selectInspectionAlarmById(String id)
    {
        return inspectionAlarmMapper.selectInspectionAlarmById(id);
    }

    /**
     * 查询巡检告警列表
     * 
     * @param inspectionAlarm 巡检告警
     * @return 巡检告警
     */
    @Override
    public List<InspectionAlarmVo> selectInspectionAlarmList(InspectionAlarm inspectionAlarm)
    {
        return inspectionAlarmMapper.selectInspectionAlarmVoList(inspectionAlarm);
    }

    /**
     * 新增巡检告警
     * 
     * @param inspectionAlarm 巡检告警
     * @return 结果
     */
    @Override
    public int insertInspectionAlarm(InspectionAlarm inspectionAlarm)
    {
        // 生成UUID作为主键
        if (inspectionAlarm.getId() == null || inspectionAlarm.getId().isEmpty()) {
            inspectionAlarm.setId(UUID.randomUUID().toString().replace("-", ""));
        }
        inspectionAlarm.setCreateTime(DateUtils.getNowDate());
        inspectionAlarm.setCreateBy(SecurityUtils.getUsername());
        return inspectionAlarmMapper.insertInspectionAlarm(inspectionAlarm);
    }

    /**
     * 修改巡检告警
     * 
     * @param inspectionAlarm 巡检告警
     * @return 结果
     */
    @Override
    public int updateInspectionAlarm(InspectionAlarm inspectionAlarm)
    {
        inspectionAlarm.setUpdateTime(DateUtils.getNowDate());
        inspectionAlarm.setUpdateBy(SecurityUtils.getUsername());
        return inspectionAlarmMapper.updateInspectionAlarm(inspectionAlarm);
    }

    /**
     * 批量删除巡检告警
     * 
     * @param ids 需要删除的巡检告警主键
     * @return 结果
     */
    @Override
    public int deleteInspectionAlarmByIds(String[] ids)
    {
        return inspectionAlarmMapper.deleteInspectionAlarmByIds(ids);
    }

}
