package com.template.services.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.template.model.enumModel.eOrgType;
import com.template.model.pojo.AlumniOrg;
import com.template.mapper.AlumniOrgMapper;
import com.template.services.AlumniOrgService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ceshi
 * @since 2024-11-19
 */
@Service
public class AlumniOrgServiceImpl extends ServiceImpl<AlumniOrgMapper, AlumniOrg> implements AlumniOrgService {

    @Autowired
    private AlumniOrgMapper alumniOrgMapper;

    @Override
    public int insertOrg(AlumniOrg ao) {
        int result = alumniOrgMapper.insert(ao);
        return ao.getId();
    }

    @Override
    public int updateOrg(AlumniOrg ao) {
        int result = alumniOrgMapper.updateById(ao);
        return result;
    }

    @Override
    public List<AlumniOrg> queryAlumniOrg() {
        List<AlumniOrg> result = alumniOrgMapper.selectList(null);
        return result;
    }

    @Override
    public List<AlumniOrg> queryColleges() {
        QueryWrapper<AlumniOrg> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("type_id", eOrgType.College.getValue());
        List<AlumniOrg> result = alumniOrgMapper.selectList(queryWrapper);
        return result;
    }

    @Override
    public List<AlumniOrg> queryPeriods(int collegeId) {
        QueryWrapper<AlumniOrg> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("parent_id", collegeId);
        queryWrapper.eq("type_id", eOrgType.Period.getValue());
        List<AlumniOrg> result = alumniOrgMapper.selectList(queryWrapper);
        return result;
    }

    @Override
    public List<AlumniOrg> queryMajors(int periodId) {
        QueryWrapper<AlumniOrg> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("parent_id", periodId);
        queryWrapper.eq("type_id", eOrgType.Major.getValue());
        List<AlumniOrg> result = alumniOrgMapper.selectList(queryWrapper);
        return result;
    }

    @Override
    public List<AlumniOrg> queryClasses(int majorId) {
        QueryWrapper<AlumniOrg> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("parent_id", majorId);
        queryWrapper.eq("type_id", eOrgType.ClassStr.getValue());
        List<AlumniOrg> result = alumniOrgMapper.selectList(queryWrapper);
        return result;
    }

    @Override
    public List<AlumniOrg> queryAlumniOrgsByName(List<String> names) {
        QueryWrapper<AlumniOrg> queryWrapper = new QueryWrapper<>();
        queryWrapper.in(names != null && names.size() > 0,"name",names);
        queryWrapper.ne("parent_id",0);
        List<AlumniOrg> result = alumniOrgMapper.selectList(queryWrapper);
        return result;
    }
}
