package cn.hmsoft.frame.control;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.hmsoft.application.web.Ajax;
import cn.hmsoft.application.web.AjaxControl;
import cn.hmsoft.frame.data.dao.FrameRegionDao;
import cn.hmsoft.frame.util.FrameZoneUtil;
import cn.hmsoft.helper.StringHelper;

@RestController
public class FrameRegionControl extends AjaxControl {

	@Autowired
	private FrameRegionDao daoRegion;

	@RequestMapping("frame/region/province/list")
	public Ajax province() {
		;
		return new Ajax(FrameZoneUtil.getProvinceArray(false));
	}

	@RequestMapping("frame/region/area/list")
	public Ajax area(String province_id) {
		return new Ajax(FrameZoneUtil.getProvinceArea(province_id, false));
	}

	@RequestMapping("frame/region/city/list")
	public Ajax city(String area_id) {
		return new Ajax(FrameZoneUtil.getAreaCity(area_id, false));
	}

	@RequestMapping("frame/region/province/array")
	public Ajax listProvince() {
		return new Ajax(FrameZoneUtil.getProvinceArray(false));
	}

	@RequestMapping("frame/region/province/map")
	public Ajax mapProvince() {
		return new Ajax(FrameZoneUtil.getProvinceMap(false));
	}

	@RequestMapping("frame/region/province/page")
	public Ajax pageProvince(String query, Integer limit, Integer start, String order, String type) {
		if (StringHelper.isEmpty(order))
			order = "province_id";
		return new Ajax(this.daoRegion.pageProvince(start, limit, query, this.getQueryOrder(order, type)));
	}

	@RequestMapping("frame/region/area/array")
	public Ajax listArea() {
		return new Ajax(FrameZoneUtil.getAreaArray(false));
	}

	@RequestMapping("frame/region/area/province")
	public Ajax listAreaByProvince(String province_id) {
		return new Ajax(FrameZoneUtil.getProvinceArea(province_id, false));
	}

	@RequestMapping("frame/region/city/array")
	public Ajax listCity() {
		return new Ajax(FrameZoneUtil.getAreaArray(false));
	}

	@RequestMapping("frame/region/city/map")
	public Ajax mapCity() {
		return new Ajax(FrameZoneUtil.getCityMap(false));
	}

	@RequestMapping("frame/region/city/area")
	public Ajax listCityByArea(String area_id) {
		return new Ajax(FrameZoneUtil.getAreaCity(area_id, false));
	}

	@RequestMapping("frame/region/reload")
	public Ajax reload() {
		FrameZoneUtil.getProvinceArray(true);
		return new Ajax();
	}
}
