package com.ruoyi.mall.service.impl;

import java.util.List;

import cn.hutool.core.date.DateUtil;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.mall.mapper.MallIndustryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.mall.mapper.MallIndustryClassMapper;
import com.ruoyi.mall.domain.MallIndustryClass;
import com.ruoyi.mall.service.IMallIndustryClassService;

/**
 * 行业分类Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-12-15
 */
@Service
public class MallIndustryClassServiceImpl implements IMallIndustryClassService 
{
    @Autowired
    private MallIndustryClassMapper mallIndustryClassMapper;

    /**
     * 查询行业分类
     * 
     * @param id 行业分类主键
     * @return 行业分类
     */
    @Override
    public MallIndustryClass selectMallIndustryClassById(Long id)
    {
        return mallIndustryClassMapper.selectMallIndustryClassById(id);
    }

    /**
     * 查询行业分类列表
     * 
     * @param mallIndustryClass 行业分类
     * @return 行业分类
     */
    @Override
    public List<MallIndustryClass> selectMallIndustryClassList(MallIndustryClass mallIndustryClass)
    {
        return mallIndustryClassMapper.selectMallIndustryClassList(mallIndustryClass);
    }

    /**
     * 新增行业分类
     * 
     * @param mallIndustryClass 行业分类
     * @return 结果
     */
    @Override
    public int insertMallIndustryClass(MallIndustryClass mallIndustryClass)
    {
        MallIndustryClass param = new MallIndustryClass();
        param.setClassName(mallIndustryClass.getClassName());
        List<MallIndustryClass> mallIndustryClasses = mallIndustryClassMapper.selectMallIndustryClassList(param);
        if(null != mallIndustryClasses && mallIndustryClasses.size()>0){
            throw new ServiceException("分类名已存在，新增失败");
        }
        mallIndustryClass.setCreateAt(DateUtils.getTime());
        return mallIndustryClassMapper.insertMallIndustryClass(mallIndustryClass);
    }

    /**
     * 修改行业分类
     * 
     * @param mallIndustryClass 行业分类
     * @return 结果
     */
    @Override
    public int updateMallIndustryClass(MallIndustryClass mallIndustryClass)
    {
        mallIndustryClass.setUpdateAt(DateUtils.getTime());
        return mallIndustryClassMapper.updateMallIndustryClass(mallIndustryClass);
    }

    /**
     * 批量删除行业分类
     * 
     * @param ids 需要删除的行业分类主键
     * @return 结果
     */
    @Override
    public int deleteMallIndustryClassByIds(Long[] ids)
    {
        MallIndustryClass param = new MallIndustryClass();
        param.setUpdateAt(DateUtils.getTime());
        return mallIndustryClassMapper.logicDeleteMallIndustryClassByIds(ids,param);
    }

    /**
     * 删除行业分类信息
     * 
     * @param id 行业分类主键
     * @return 结果
     */
    @Override
    public int deleteMallIndustryClassById(Long id)
    {
        MallIndustryClass param = new MallIndustryClass();
        param.setUpdateAt(DateUtils.getTime());
        return mallIndustryClassMapper.logicDeleteMallIndustryClassById(id,param);
    }
}
