package com.community.huiju.service.impl;

import com.community.commom.constant.Constant;
import com.community.huiju.dao.SysNationMapper;
import com.community.huiju.model.SysNation;
import com.community.huiju.service.CommonServiceI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * @author FXF
 * @date 2018-11-12
 */
@Service("commonService")
public class CommonServiceImpl implements CommonServiceI {
	
	@Autowired
	private SysNationMapper sysNationMapper;
	
	/**
	 * 获取所有省份数据
	 *
	 * @return
	 */
	@Override
	public List<SysNation> getProvinceList() {
		return sysNationMapper.getNationList(1);
	}
	
	/**
	 * 根据省ID获取全部市区数据
	 *
	 * @param provinceId
	 * @return
	 */
	@Override
	public List<SysNation> getCityList(Integer provinceId) {
		//直辖市是自己本身
		if(provinceId.equals(Constant.Beijing) || provinceId.equals(Constant.Shanghai) ||
			provinceId.equals(Constant.Tianjin) || provinceId.equals(Constant.Chongqing)) {
			List<SysNation> list = new ArrayList<>();
			list.add(sysNationMapper.selectByPrimaryKey(provinceId));
			return list;
		}
		return sysNationMapper.getNationList(provinceId);
	}
	
	/**
	 * 根据市ID获取全部县数据
	 *
	 * @param cityId
	 * @return
	 */
	@Override
	public List<SysNation> getDistrictList(Integer cityId) {
		return sysNationMapper.getNationList(cityId);
	}
}
