package com.ygtx.gxt.service.impl;

import java.util.List;
import com.ygtx.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ygtx.gxt.mapper.GxtFaultCodesMapper;
import com.ygtx.gxt.domain.GxtFaultCodes;
import com.ygtx.gxt.service.IGxtFaultCodesService;

/**
 * 故障代码管理Service业务层处理
 * 
 * @author ouyj
 * @date 2025-10-29
 */
@Service
public class GxtFaultCodesServiceImpl implements IGxtFaultCodesService 
{
    @Autowired
    private GxtFaultCodesMapper gxtFaultCodesMapper;

    /**
     * 查询故障代码管理
     * 
     * @param id 故障代码管理主键
     * @return 故障代码管理
     */
    @Override
    public GxtFaultCodes selectGxtFaultCodesById(Long id)
    {
        return gxtFaultCodesMapper.selectGxtFaultCodesById(id);
    }

    /**
     * 查询故障代码管理列表
     * 
     * @param gxtFaultCodes 故障代码管理
     * @return 故障代码管理
     */
    @Override
    public List<GxtFaultCodes> selectGxtFaultCodesList(GxtFaultCodes gxtFaultCodes)
    {
        return gxtFaultCodesMapper.selectGxtFaultCodesList(gxtFaultCodes);
    }

    /**
     * 验证故障代码是否唯一
     * 
     * @param gxtFaultCodes 故障代码信息
     * @return 结果
     */
    @Override
    public boolean checkFaultCodeUnique(GxtFaultCodes gxtFaultCodes) {
        Long id = gxtFaultCodes.getId() == null ? -1L : gxtFaultCodes.getId();
        GxtFaultCodes info = gxtFaultCodesMapper.selectGxtFaultCodesByFaultCode(gxtFaultCodes.getFaultCode());
        if (info != null && info.getId().longValue() != id.longValue()) {
            return false;
        }
        return true;
    }

    /**
     * 新增故障代码管理
     * 
     * @param gxtFaultCodes 故障代码管理
     * @return 结果
     */
    @Override
    public int insertGxtFaultCodes(GxtFaultCodes gxtFaultCodes)
    {
        gxtFaultCodes.setCreateTime(DateUtils.getNowDate());
        return gxtFaultCodesMapper.insertGxtFaultCodes(gxtFaultCodes);
    }

    /**
     * 修改故障代码管理
     * 
     * @param gxtFaultCodes 故障代码管理
     * @return 结果
     */
    @Override
    public int updateGxtFaultCodes(GxtFaultCodes gxtFaultCodes)
    {
        gxtFaultCodes.setUpdateTime(DateUtils.getNowDate());
        return gxtFaultCodesMapper.updateGxtFaultCodes(gxtFaultCodes);
    }

    /**
     * 批量删除故障代码管理
     * 
     * @param ids 需要删除的故障代码管理主键
     * @return 结果
     */
    @Override
    public int deleteGxtFaultCodesByIds(Long[] ids)
    {
        return gxtFaultCodesMapper.deleteGxtFaultCodesByIds(ids);
    }

    /**
     * 删除故障代码管理信息
     * 
     * @param id 故障代码管理主键
     * @return 结果
     */
    @Override
    public int deleteGxtFaultCodesById(Long id)
    {
        return gxtFaultCodesMapper.deleteGxtFaultCodesById(id);
    }
}