package com.ruoyi.business.service.impl;

import java.util.List;
import java.util.ArrayList;
import com.ruoyi.common.core.domain.Ztree;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.business.mapper.IndustryMapper;
import com.ruoyi.business.domain.Industry;
import com.ruoyi.business.service.IIndustryService;
import com.ruoyi.common.core.text.Convert;

/**
 * 行业Service业务层处理
 * 
 * @author xiatao
 * @date 2022-02-08
 */
@Service
public class IndustryServiceImpl implements IIndustryService 
{
    @Autowired
    private IndustryMapper industryMapper;

    /**
     * 查询行业
     * 
     * @param id 行业主键
     * @return 行业
     */
    @Override
    public Industry selectIndustryById(Long id)
    {
        return industryMapper.selectIndustryById(id);
    }

    /**
     * 查询行业列表
     * 
     * @param industry 行业
     * @return 行业
     */
    @Override
    public List<Industry> selectIndustryList(Industry industry)
    {
        return industryMapper.selectIndustryList(industry);
    }

    /**
     * 新增行业
     * 
     * @param industry 行业
     * @return 结果
     */
    @Override
    public int insertIndustry(Industry industry)
    {
        industry.setCreateTime(DateUtils.getNowDate());
        return industryMapper.insertIndustry(industry);
    }

    /**
     * 修改行业
     * 
     * @param industry 行业
     * @return 结果
     */
    @Override
    public int updateIndustry(Industry industry)
    {
        industry.setUpdateTime(DateUtils.getNowDate());
        return industryMapper.updateIndustry(industry);
    }

    /**
     * 批量删除行业
     * 
     * @param ids 需要删除的行业主键
     * @return 结果
     */
    @Override
    public int deleteIndustryByIds(String ids)
    {
        return industryMapper.deleteIndustryByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除行业信息
     * 
     * @param id 行业主键
     * @return 结果
     */
    @Override
    public int deleteIndustryById(Long id)
    {
        return industryMapper.deleteIndustryById(id);
    }

    /**
     * 查询行业树列表
     * 
     * @return 所有行业信息
     */
    @Override
    public List<Ztree> selectIndustryTree()
    {
        List<Industry> industryList = industryMapper.selectIndustryList(new Industry());
        List<Ztree> ztrees = new ArrayList<Ztree>();
        for (Industry industry : industryList)
        {
            Ztree ztree = new Ztree();
            ztree.setId(industry.getId());
            ztree.setpId(industry.getpId());
            ztree.setName(industry.getName());
            ztree.setTitle(industry.getName());
            ztrees.add(ztree);
        }
        return ztrees;
    }
}
