package com.lightinit.hsdatashow.impl.admin;

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

import java.util.List;

/**
 * @Author: sunxiang
 * @Date: 2018/12/9 14:01
 * @Description:
 **/
@Service
public class TrafficMonitorServiceImpl implements ITrafficMonitorService {

    @Autowired
    private TrafficMonitorMapper trafficMonitorMapper;

    @Autowired
    private OrganizationMapper organizationMapper ;

    @Autowired
    private ObjCategoryMapper objCategoryMapper ;

    @Override
    public ResultState getTrafficCondition(String chinaType) {
        ResultState resultState = new ResultState();
        TrafficMonitorExample example = new TrafficMonitorExample();
        example.createCriteria().andTypeEqualTo(chinaType);
        List<TrafficMonitor> trafficMonitors = trafficMonitorMapper.selectByExample(example);
        resultState.setData(trafficMonitors);
        return resultState;
    }

    @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 ;
        }
    }
}
