package com.lightinit.hsdatashow.impl.admin;

import com.lightinit.hsdatashow.entity.ObjCategory;
import com.lightinit.hsdatashow.entity.ObjCategoryExample;
import com.lightinit.hsdatashow.mapper.ObjCategoryMapper;
import com.lightinit.hsdatashow.mapper.OrganizationMapper;
import com.lightinit.hsdatashow.model.admin.EducationOrganizationResultModel;
import com.lightinit.hsdatashow.service.admin.IEducationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EducationServiceImpl implements IEducationService {

    @Autowired
    private OrganizationMapper organizationMapper ;

    @Autowired
    private ObjCategoryMapper objCategoryMapper ;

    @Override
    public List<EducationOrganizationResultModel> getEducationOrganization(String categoryName,String name) {
        ObjCategoryExample example = new ObjCategoryExample() ;
        ObjCategoryExample.Criteria criteria = example.createCriteria() ;
        criteria.andCategoryNameEqualTo(categoryName) ;
        criteria.andParentCodeIsNull() ;
        List<ObjCategory> objCategories = objCategoryMapper.selectByExample(example) ;
        if (objCategories.size()>0){
            List<EducationOrganizationResultModel> educationOrganizationResultModels = organizationMapper.getEducationOrganization(objCategories.get(0).getCategoryCode(),name) ;
            return educationOrganizationResultModels;
        }else {
            return null ;
        }
    }
}
