package com.ruoyi.test.seriver.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.test.domain.DO.SubjectKnowledgeDO;
import com.ruoyi.test.domain.KnowledgeTree;
import com.ruoyi.test.domain.Subject;
import com.ruoyi.test.mapper.KnowledgeTreeMapper;
import com.ruoyi.test.mapper.SubjectKnowledgeDOMapper;
import com.ruoyi.test.mapper.SubjectMapper;
import com.ruoyi.test.seriver.ISubjectKnowledgeDOService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class SubjectKnowledgeDOServiceImpl extends ServiceImpl<SubjectKnowledgeDOMapper, SubjectKnowledgeDO> implements ISubjectKnowledgeDOService {
    @Autowired
    private SubjectKnowledgeDOMapper subjectKnowledgeDOMapper;

    @Autowired
    private SubjectMapper subjectMapper;

    @Autowired
    private KnowledgeTreeMapper knowledgeTreeMapper;

    @Override
    public List<SubjectKnowledgeDO> selectList() {
        List<SubjectKnowledgeDO> l = new ArrayList<>();
        LambdaQueryWrapper<Subject> queryWrapper = new LambdaQueryWrapper<>();
        List<Subject> list = subjectMapper.selectList(queryWrapper);

        for(Subject subject : list){
            LambdaQueryWrapper<KnowledgeTree> queryWrapper1 = new LambdaQueryWrapper<>();
            queryWrapper1.select(KnowledgeTree::getGrade, KnowledgeTree::getPid, KnowledgeTree::getSubject);
            queryWrapper1.eq(KnowledgeTree::getGrade,subject.getGrade());
            queryWrapper1.eq(KnowledgeTree::getSubject,subject.getSubject());
            queryWrapper1.eq(KnowledgeTree::getPid,0L);
            int s = knowledgeTreeMapper.selectList(queryWrapper1).size();
            if(s==0){
                continue;
            }
            SubjectKnowledgeDO subjectKnowledgeDO = new SubjectKnowledgeDO();
            subjectKnowledgeDO.setSubject(subject.getSubject());
            subjectKnowledgeDO.setGrade(subject.getGrade());
            subjectKnowledgeDO.setKnowledgenum(s);
            l.add(subjectKnowledgeDO);
        }
        return l;
    }
}
