package com.ruoyi.jarvis.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.jarvis.mapper.ErpProductRelationMapper;
import com.ruoyi.jarvis.domain.ErpProductRelation;
import com.ruoyi.jarvis.service.IErpProductRelationService;

/**
 * ERP商品关联Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-01-01
 */
@Service
public class ErpProductRelationServiceImpl implements IErpProductRelationService 
{
    @Autowired
    private ErpProductRelationMapper erpProductRelationMapper;

    /**
     * 查询ERP商品关联
     * 
     * @param id ERP商品关联主键
     * @return ERP商品关联
     */
    @Override
    public ErpProductRelation selectErpProductRelationById(Long id)
    {
        return erpProductRelationMapper.selectErpProductRelationById(id);
    }

    /**
     * 查询ERP商品关联列表
     * 
     * @param erpProductRelation ERP商品关联
     * @return ERP商品关联集合
     */
    @Override
    public List<ErpProductRelation> selectErpProductRelationList(ErpProductRelation erpProductRelation)
    {
        return erpProductRelationMapper.selectErpProductRelationList(erpProductRelation);
    }

    /**
     * 新增ERP商品关联
     * 
     * @param erpProductRelation ERP商品关联
     * @return 结果
     */
    @Override
    public int insertErpProductRelation(ErpProductRelation erpProductRelation)
    {
        return erpProductRelationMapper.insertErpProductRelation(erpProductRelation);
    }

    /**
     * 修改ERP商品关联
     * 
     * @param erpProductRelation ERP商品关联
     * @return 结果
     */
    @Override
    public int updateErpProductRelation(ErpProductRelation erpProductRelation)
    {
        return erpProductRelationMapper.updateErpProductRelation(erpProductRelation);
    }

    /**
     * 批量删除ERP商品关联
     * 
     * @param ids 需要删除的ERP商品关联主键集合
     * @return 结果
     */
    @Override
    public int deleteErpProductRelationByIds(Long[] ids)
    {
        return erpProductRelationMapper.deleteErpProductRelationByIds(ids);
    }

    /**
     * 删除ERP商品关联信息
     * 
     * @param id ERP商品关联主键
     * @return 结果
     */
    @Override
    public int deleteErpProductRelationById(Long id)
    {
        return erpProductRelationMapper.deleteErpProductRelationById(id);
    }

    /**
     * 根据常用商品ID查询ERP商品关联列表
     * 
     * @param favoriteProductId 常用商品ID
     * @return ERP商品关联集合
     */
    @Override
    public List<ErpProductRelation> selectErpProductRelationByFavoriteId(Long favoriteProductId)
    {
        return erpProductRelationMapper.selectErpProductRelationByFavoriteId(favoriteProductId);
    }

    /**
     * 根据应用ID查询ERP商品关联列表
     * 
     * @param appid 应用ID
     * @return ERP商品关联集合
     */
    @Override
    public List<ErpProductRelation> selectErpProductRelationByAppid(String appid)
    {
        return erpProductRelationMapper.selectErpProductRelationByAppid(appid);
    }

    /**
     * 根据常用商品ID删除ERP商品关联
     * 
     * @param favoriteProductId 常用商品ID
     * @return 结果
     */
    @Override
    public int deleteErpProductRelationByFavoriteId(Long favoriteProductId)
    {
        return erpProductRelationMapper.deleteErpProductRelationByFavoriteId(favoriteProductId);
    }

    /**
     * 统计常用商品的ERP关联数量
     * 
     * @param favoriteProductId 常用商品ID
     * @return 关联数量
     */
    @Override
    public int countErpProductRelationByFavoriteId(Long favoriteProductId)
    {
        return erpProductRelationMapper.countErpProductRelationByFavoriteId(favoriteProductId);
    }

    /**
     * 批量添加ERP商品关联
     * 
     * @param favoriteProductId 常用商品ID
     * @param erpProductRelations ERP商品关联列表
     * @return 结果
     */
    @Override
    public int batchInsertErpProductRelations(Long favoriteProductId, List<ErpProductRelation> erpProductRelations)
    {
        if (erpProductRelations == null || erpProductRelations.isEmpty()) {
            return 0;
        }
        
        int result = 0;
        for (ErpProductRelation erpProductRelation : erpProductRelations) {
            erpProductRelation.setFavoriteProductId(favoriteProductId);
            result += insertErpProductRelation(erpProductRelation);
        }
        return result;
    }
}
