package com.community.huiju.controller;

import com.community.commom.mode.ResponseBean;
import com.community.huiju.common.base.BaseController;
import com.community.huiju.model.Communities;
import com.community.huiju.model.SysNation;
import com.community.huiju.service.CommonServiceI;
import com.community.huiju.service.CommunitiesServiceI;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author FXF
 * @date 2018-11-12
 */
@RestController
@RefreshScope
@RequestMapping("/")
@Api(value = "运营端公共API", description = "运营端公共API")
public class CommonController extends BaseController {
	@Autowired
	private CommunitiesServiceI communitiesServiceI;
	
	@Autowired
	private CommonServiceI commonService;
	
	@ApiOperation(value = "获取全部省数据", notes = "获取全部省数据")
	@ApiImplicitParams({
	})
	@RequestMapping(value = "/common/province",method = RequestMethod.GET)
	public ResponseBean getProvinceList(){
		ResponseBean responseBean = new ResponseBean();
		List<SysNation> nationList = commonService.getProvinceList();
		responseBean.addSuccess(nationList);
		return responseBean;
	}
	
	@ApiOperation(value = "根据省ID获取全部市数据", notes = "根据省ID获取全部市数据")
	@ApiImplicitParams({
			@ApiImplicitParam(paramType = "query", dataType = "integer", name = "provinceId", value = "省id")
	})
	@RequestMapping(value = "/common/city",method = RequestMethod.GET)
	public ResponseBean getCityList(@RequestParam("provinceId") Integer provinceId){
		ResponseBean responseBean = new ResponseBean();
		List<SysNation> nationList = commonService.getCityList(provinceId);
		responseBean.addSuccess(nationList);
		return responseBean;
	}
	
	@ApiOperation(value = "根据市ID获取全部区数据", notes = "根据市ID获取全部区数据")
	@ApiImplicitParams({
			@ApiImplicitParam(paramType = "query", dataType = "integer", name = "cityId", value = "市id")
	})
	@RequestMapping(value = "/common/district",method = RequestMethod.GET)
	public ResponseBean getDistrictList(@RequestParam("cityId") Integer cityId){
		ResponseBean responseBean = new ResponseBean();
		List<SysNation> nationList = commonService.getDistrictList(cityId);
		responseBean.addSuccess(nationList);
		return responseBean;
	}

	@ApiOperation(value = "获取所有小区经纬度", notes = "获取所有小区经纬度")
	@RequestMapping(value = "/communities",method = RequestMethod.GET)
	public ResponseBean getAgreement(){
		ResponseBean responseBean = new ResponseBean();
		List <Communities> communities= communitiesServiceI.getCommunities();
		responseBean.addSuccess(communities);
		return responseBean;
	}

}
