package com.community.huiju.service.impl;

import com.community.huiju.dao.SysNationMapper;
import com.community.huiju.dao.ToCommunitiesMapper;
import com.community.huiju.model.SysNation;
import com.community.huiju.model.ToCommunities;
import com.community.huiju.service.CommunityServiceI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author FXF
 * @date 2018-10-22
 */
@Service("communityService")
public class CommunityServiceImpl implements CommunityServiceI {
	
	@Autowired
	private ToCommunitiesMapper toCommunitiesMapper;

	@Autowired
	private SysNationMapper sysNationMapper;
	
	@Override
	public List<ToCommunities> getCommunitys(String communityName) {
		List<ToCommunities> toCommunities = toCommunitiesMapper.selectByCommunityName(communityName);
		toCommunities.forEach(e -> {
			// 省
			SysNation province = sysNationMapper.selectByPrimaryKey(e.getProvinceId());
			// 市
			SysNation city = sysNationMapper.selectByPrimaryKey(e.getCityId());
			// 区
			SysNation district = sysNationMapper.selectByPrimaryKey(e.getDistrictId());
			e.setCommunityAddress(province.getProvince() + city.getCity() + district.getDistrict());
		});

		return toCommunities;
	}

	@Override
	public ToCommunities getByCommunityId(Integer communityId) {
		return toCommunitiesMapper.selectByPrimaryKey(communityId);
	}
}
