package com.ruoyi.app.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.app.mapper.InspectionItemMapper;
import com.ruoyi.app.model.InspectionItem;
import com.ruoyi.app.service.IInspectionItemService;

/**
 * 检查项目Service业务层处理
 * 
 * @author coede
 * @date 2025-03-19
 */
@Service
public class InspectionItemServiceImpl implements IInspectionItemService 
{
    @Autowired
    private InspectionItemMapper inspectionItemMapper;

    /**
     * 查询检查项目
     * 
     * @param id 检查项目主键
     * @return 检查项目
     */
    @Override
    public InspectionItem selectInspectionItemById(Long id)
    {
        return inspectionItemMapper.selectInspectionItemById(id);
    }

    /**
     * 查询检查项目列表
     * 
     * @param inspectionItem 检查项目
     * @return 检查项目
     */
    @Override
    public List<InspectionItem> selectInspectionItemList(InspectionItem inspectionItem)
    {
        return inspectionItemMapper.selectInspectionItemList(inspectionItem);
    }

    /**
     * 校验项目名称是否唯一
     *
     * @param inspectionItem 吊钩
     * @return 结果
     */
    @Override
    public boolean checkItemNameUnique(InspectionItem inspectionItem)
    {
        Long hookId = StringUtils.isNull(inspectionItem.getId()) ? -1L : inspectionItem.getId();
        InspectionItem info = inspectionItemMapper.checkItemNameUnique(inspectionItem.getItemName());
        if (StringUtils.isNotNull(info) && info.getId().longValue() != hookId.longValue())
        {
            return false;
        }
        return true;
    }

    /**
     * 新增检查项目
     * 
     * @param inspectionItem 检查项目
     * @return 结果
     */
    @Override
    public int insertInspectionItem(InspectionItem inspectionItem)
    {
        inspectionItem.setCreateTime(DateUtils.getNowDate());
        return inspectionItemMapper.insertInspectionItem(inspectionItem);
    }

    /**
     * 修改检查项目
     * 
     * @param inspectionItem 检查项目
     * @return 结果
     */
    @Override
    public int updateInspectionItem(InspectionItem inspectionItem)
    {
        inspectionItem.setUpdateTime(DateUtils.getNowDate());
        return inspectionItemMapper.updateInspectionItem(inspectionItem);
    }

    /**
     * 批量删除检查项目
     * 
     * @param ids 需要删除的检查项目主键
     * @return 结果
     */
    @Override
    public int deleteInspectionItemByIds(Long[] ids)
    {
        return inspectionItemMapper.deleteInspectionItemByIds(ids);
    }

    /**
     * 删除检查项目信息
     * 
     * @param id 检查项目主键
     * @return 结果
     */
    @Override
    public int deleteInspectionItemById(Long id)
    {
        return inspectionItemMapper.deleteInspectionItemById(id);
    }
}
