package com.ruoyi.inspection.service.impl;

import java.util.List;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.inspection.mapper.InspectionAbnormalMapper;
import com.ruoyi.inspection.domain.InspectionAbnormal;
import com.ruoyi.inspection.service.IInspectionAbnormalService;

/**
 * 巡检异常Service业务层处理
 *
 * @author LSD
 * @date 2025-10-24
 */
@Service
public class InspectionAbnormalServiceImpl implements IInspectionAbnormalService {
    @Autowired
    private InspectionAbnormalMapper inspectionAbnormalMapper;

    /**
     * 查询巡检异常
     *
     * @param id 巡检异常主键
     * @return 巡检异常
     */
    @Override
    public InspectionAbnormal selectInspectionAbnormalById(Long id) {
        return inspectionAbnormalMapper.selectInspectionAbnormalById(id);
    }

    /**
     * 查询巡检异常列表
     *
     * @param inspectionAbnormal 巡检异常
     * @return 巡检异常
     */
    @Override
    @DataScope(userAlias = "u")
    public List<InspectionAbnormal> selectInspectionAbnormalList(InspectionAbnormal inspectionAbnormal) {
        return inspectionAbnormalMapper.selectInspectionAbnormalList(inspectionAbnormal);
    }

    /**
     * 新增巡检异常
     *
     * @param inspectionAbnormal 巡检异常
     * @return 结果
     */
    @Override
    public int insertInspectionAbnormal(InspectionAbnormal inspectionAbnormal) {
        // 填充巡检时间与审计字段（创建者、创建时间）
        inspectionAbnormal.setInspectionTime(DateUtils.getNowDate());
        inspectionAbnormal.setCreateBy(SecurityUtils.getUsername());
        inspectionAbnormal.setCreateTime(DateUtils.getNowDate());
        return inspectionAbnormalMapper.insertInspectionAbnormal(inspectionAbnormal);
    }

    /**
     * 修改巡检异常
     *
     * @param inspectionAbnormal 巡检异常
     * @return 结果
     */
    @Override
    public int updateInspectionAbnormal(InspectionAbnormal inspectionAbnormal) {
        // 填充审计字段（更新者、更新时间）
        inspectionAbnormal.setUpdateBy(SecurityUtils.getUsername());
        inspectionAbnormal.setUpdateTime(DateUtils.getNowDate());
        return inspectionAbnormalMapper.updateInspectionAbnormal(inspectionAbnormal);
    }

    /**
     * 批量删除巡检异常
     *
     * @param ids 需要删除的巡检异常主键
     * @return 结果
     */
    @Override
    public int deleteInspectionAbnormalByIds(Long[] ids) {
        return inspectionAbnormalMapper.deleteInspectionAbnormalByIds(ids);
    }

    /**
     * 删除巡检异常信息
     *
     * @param id 巡检异常主键
     * @return 结果
     */
    @Override
    public int deleteInspectionAbnormalById(Long id) {
        return inspectionAbnormalMapper.deleteInspectionAbnormalById(id);
    }
}
