package com.gyee.frame.controller.admin;

import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.gyee.frame.common.base.BaseController;
import com.gyee.frame.model.auto.SysArea;
import com.gyee.frame.model.auto.SysAreaExample;
import com.gyee.frame.model.auto.SysCity;
import com.gyee.frame.model.auto.SysCityExample;
import com.gyee.frame.model.auto.SysProvinceExample;
import com.gyee.frame.model.auto.SysStreet;
import com.gyee.frame.model.auto.SysStreetExample;
import com.gyee.frame.model.custom.TitleVo;
import com.gyee.frame.service.SysAreaService;
import com.gyee.frame.service.SysCityService;
import com.gyee.frame.service.SysProvinceService;
import com.gyee.frame.service.SysStreetService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 省份联动controller
 * @ClassName: ProvinceLinkageController
 * @author gyee
 * @date 2019-10-05 11:19
 */
@Api(value = "省份联动controller")
@Controller
@RequestMapping("/ProvinceLinkageController")
public class ProvinceLinkageController  extends BaseController{
	@Resource
	private SysProvinceService sysProvinceService;
	@Resource
	private SysCityService sysCityService;
	@Resource
	private SysAreaService sysAreaService;
	
	@Resource
	private SysStreetService sysStreetService;
	
	private String prefix = "admin/province";
	
	/**
	 * 分页list页面
	 * @param model
	 * @param dictId
	 * @return
	 */
	@ApiOperation(value = "分页跳转", notes = "分页跳转")
	@GetMapping("/view")
    public String view(ModelMap model)
    {	
		String str="省份联动";
		setTitle(model, new TitleVo("列表", str+"管理", true,"欢迎进入"+str+"页面", true, false));
		model.addAttribute("provinceList",sysProvinceService.selectByExample(new SysProvinceExample()));
        return prefix + "/list";
    }
	
	/**
	 * 市查询
	 * @param pid
	 * @return
	 */
	@ApiOperation(value = "市查询", notes = "市查询")
	@GetMapping("/getCity")
	@ResponseBody
	public List<SysCity> getCity(String pid){
		SysCityExample example=new SysCityExample();
		example.createCriteria().andProvinceCodeEqualTo(pid);
		return sysCityService.selectByExample(example);
		
	}
	
	/**
	 * 区查询
	 * @param pid
	 * @return
	 */
	@ApiOperation(value = "区查询", notes = "区查询")
	@GetMapping("/getArea")
	@ResponseBody
	public List<SysArea> getArea(String pid){
		SysAreaExample example=new SysAreaExample();
		example.createCriteria().andCityCodeEqualTo(pid);
		return sysAreaService.selectByExample(example);
		
	}
	
	/**
	 * 街道查询
	 * @param pid
	 * @return
	 */
	@ApiOperation(value = "街道查询", notes = "街道查询")
	@GetMapping("/getStreet")
	@ResponseBody
	public List<SysStreet> getStreet(String pid){
		SysStreetExample example=new SysStreetExample();
		example.createCriteria().andAreaCodeEqualTo(pid);
		return sysStreetService.selectByExample(example);
		
	}
		
	
}
