package com.ruoyi.web.work.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.work.domain.Knowledge;
import com.ruoyi.web.work.domain.vo.KnowledgeVoList;
import com.ruoyi.web.work.mapper.KnowledgeMapper;
import com.ruoyi.web.work.service.IKnowledgeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author lsw
 * @date 2024-07-10
 */
@Service
public class KnowledgeServiceImpl extends ServiceImpl<KnowledgeMapper, Knowledge> implements IKnowledgeService {
    @Autowired
    private KnowledgeMapper knowledgeMapper;

    @Override
    public List<Knowledge> indexList() {
        return knowledgeMapper.indexList();
    }

    @Override
    public List<KnowledgeVoList> selectAppList(Knowledge knowledge) {
        return knowledgeMapper.selectAppList(knowledge);
    }

    @Override
    @DataScope(deptAlias = "k",userAlias = "k")
    public List<Knowledge> selectList(Knowledge knowledge) {
        knowledge.setState(0);
        return knowledgeMapper.selectList(knowledge);
    }

    @Override
    public AjaxResult detail(Long id) {
        Knowledge knowledge = getById(id);
        if (knowledge == null || knowledge.getState() != 0) {
            return AjaxResult.error("知识不存在或被下架");
        }
        return AjaxResult.success(knowledge);
    }
}
