package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.XysCategoryMapper;
import com.ruoyi.system.domain.XysCategory;
import com.ruoyi.system.service.IXysCategoryService;

/**
 * 文章分类Service业务层处理
 *
 * @author libao
 * @date 2024-07-25
 */
@Service
public class XysCategoryServiceImpl implements IXysCategoryService
{
    @Autowired
    private XysCategoryMapper xysCategoryMapper;

    /**
     * 查询文章分类
     *
     * @param id 文章分类主键
     * @return 文章分类
     */
    @Override
    public XysCategory selectXysCategoryById(Long id)
    {
        return xysCategoryMapper.selectXysCategoryById(id);
    }

    /**
     * 查询文章分类列表
     *
     * @param xysCategory 文章分类
     * @return 文章分类
     */
    @Override
    public List<XysCategory> selectXysCategoryList(XysCategory xysCategory)
    {
        List<XysCategory> list = xysCategoryMapper.selectXysCategoryList(xysCategory);
        for(XysCategory category:list){
            if(category.getParentId() != null){
                XysCategory cg = xysCategoryMapper.selectXysCategoryById(category.getParentId());
                category.setParentName(cg.getTitle());
            }
        }
        return list;
    }

    /**
     * 新增文章分类
     *
     * @param xysCategory 文章分类
     * @return 结果
     */
    @Override
    public int insertXysCategory(XysCategory xysCategory)
    {
        xysCategory.setCreateTime(DateUtils.getNowDate());
        return xysCategoryMapper.insertXysCategory(xysCategory);
    }

    /**
     * 修改文章分类
     *
     * @param xysCategory 文章分类
     * @return 结果
     */
    @Override
    public int updateXysCategory(XysCategory xysCategory)
    {
        xysCategory.setUpdateTime(DateUtils.getNowDate());
        return xysCategoryMapper.updateXysCategory(xysCategory);
    }

    /**
     * 批量删除文章分类
     *
     * @param ids 需要删除的文章分类主键
     * @return 结果
     */
    @Override
    public int deleteXysCategoryByIds(Long[] ids)
    {
        return xysCategoryMapper.deleteXysCategoryByIds(ids);
    }

    /**
     * 删除文章分类信息
     *
     * @param id 文章分类主键
     * @return 结果
     */
    @Override
    public int deleteXysCategoryById(Long id)
    {
        return xysCategoryMapper.deleteXysCategoryById(id);
    }
}
