package com.ruoyi.system.service.impl;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.system.domain.EpsBusiness;
import com.ruoyi.system.mapper.EpsBusinessMapper;
import com.ruoyi.system.service.IEpsBusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 业务信息Service业务层处理
 * 
 * @author gyt
 * @date 2025-08-18
 */
@Service
public class EpsBusinessServiceImpl implements IEpsBusinessService 
{
    @Autowired
    private EpsBusinessMapper epsBusinessMapper;

    /**
     * 查询业务信息
     * 
     * @param id 业务信息主键
     * @return 业务信息
     */
    @Override
    public EpsBusiness selectEpsBusinessById(String id)
    {
        return epsBusinessMapper.selectEpsBusinessById(id);
    }

    /**
     * 查询业务信息列表
     * 
     * @param epsBusiness 业务信息
     * @return 业务信息
     */
    @Override
    public List<EpsBusiness> selectEpsBusinessList(EpsBusiness epsBusiness)
    {
        return epsBusinessMapper.selectEpsBusinessList(epsBusiness);
    }

    /**
     * 新增业务信息
     * 
     * @param epsBusiness 业务信息
     * @return 结果
     */
    @Override
    public int insertEpsBusiness(EpsBusiness epsBusiness)
    {
        epsBusiness.setCreateTime(DateUtils.getNowDate());
        // 查询业务名称是否存在
        Integer exits = epsBusinessMapper.countByBusinessName(epsBusiness);
        if(exits>0){
            return -1;
        }
        return epsBusinessMapper.insertEpsBusiness(epsBusiness);
    }

    /**
     * 修改业务信息
     * 
     * @param epsBusiness 业务信息
     * @return 结果
     */
    @Override
    public int updateEpsBusiness(EpsBusiness epsBusiness)
    {
        epsBusiness.setUpdateTime(DateUtils.getNowDate());
        // 查询业务名称是否存在
        Integer exits = epsBusinessMapper.countByBusinessName(epsBusiness);
        if(exits>0){
            return -1;
        }
        return epsBusinessMapper.updateEpsBusiness(epsBusiness);
    }

    /**
     * 批量删除业务信息
     * 
     * @param ids 需要删除的业务信息主键
     * @return 结果
     */
    @Override
    public int deleteEpsBusinessByIds(String[] ids)
    {
        return epsBusinessMapper.deleteEpsBusinessByIds(ids);
    }

    /**
     * 删除业务信息信息
     * 
     * @param id 业务信息主键
     * @return 结果
     */
    @Override
    public int deleteEpsBusinessById(String id)
    {
        return epsBusinessMapper.deleteEpsBusinessById(id);
    }

    /**
     * 验证业务名称是否存在
     * @param epsBusiness
     * @return
     */
    @Override
    public Integer countByBusinessName(EpsBusiness epsBusiness) {
        // 查询业务名称是否存在
        Integer rows = epsBusinessMapper.countByBusinessName(epsBusiness);
        return rows;
    }
}
