package com.ruoyi.dxp.service.impl;

import java.util.List;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.dxp.constant.DxpConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.dxp.mapper.TopicMapper;
import com.ruoyi.dxp.domain.Topic;
import com.ruoyi.dxp.service.ITopicService;

/**
 * 专题Service业务层处理
 * 
 * @author jy
 * @date 2022-11-06
 */
@Service
public class TopicServiceImpl implements ITopicService 
{
    @Autowired
    private TopicMapper topicMapper;

    /**
     * 查询专题
     * 
     * @param id 专题主键
     * @return 专题
     */
    @Override
    public Topic selectTopicById(Long id)
    {
        return topicMapper.selectTopicById(id);
    }

    /**
     * 查询专题列表
     * 
     * @param topic 专题
     * @return 专题
     */
    @Override
    public List<Topic> selectTopicList(Topic topic)
    {
        return topicMapper.selectTopicList(topic);
    }

    /**
     * 新增专题
     * 
     * @param topic 专题
     * @return 结果
     */
    @Override
    public int insertTopic(Topic topic)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        topic.setCreateBy(loginUser.getUsername());
        topic.setCreateTime(DateUtils.getNowDate());
        topic.setStatus(DxpConstants.STATUS_VALID);
        return topicMapper.insertTopic(topic);
    }

    /**
     * 修改专题
     * 
     * @param topic 专题
     * @return 结果
     */
    @Override
    public int updateTopic(Topic topic)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        topic.setUpdateBy(loginUser.getUsername());
        topic.setUpdateTime(DateUtils.getNowDate());
        return topicMapper.updateTopic(topic);
    }

    /**
     * 批量删除专题
     * 
     * @param ids 需要删除的专题主键
     * @return 结果
     */
    @Override
    public int deleteTopicByIds(Long[] ids)
    {
        return topicMapper.deleteTopicByIds(ids);
    }

    /**
     * 删除专题信息
     * 
     * @param id 专题主键
     * @return 结果
     */
    @Override
    public int deleteTopicById(Long id)
    {
        return topicMapper.deleteTopicById(id);
    }
}
