Newer
Older
huludao / src / main / java / com / newfiber / api / mobile / controller / AdministrativeDivisionController.java
package com.newfiber.api.mobile.controller;

import com.newfiber.api.core.annotation.SysLog;
import com.newfiber.api.core.base.BaseController;
import com.newfiber.api.core.base.BaseUrl;
import com.newfiber.api.core.bean.ReqBodyObj;
import com.newfiber.api.core.bean.RespBodyObj;
import com.newfiber.api.core.support.HttpCode;
import com.newfiber.api.core.utils.JsonTools;
import com.newfiber.api.mobile.service.AdministrativeDivisionService;
import com.newfiber.api.pc.dao.EventsManage.AdministrativeDivisionDao;
import com.newfiber.api.pc.model.EventsManage.AdministrativeDivision;
import io.swagger.annotations.Api;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 行政区划表 Controller
 * @author xcc
 * @date 2018-12-04 16:39:34
 */
@RestController
@RequestMapping("/administrativedivision")
@Api
public class AdministrativeDivisionController extends BaseController{
	@Autowired
	private AdministrativeDivisionService administrativeDivisionService;

	@Autowired
	private AdministrativeDivisionDao administrativeDivisionDao;

	/** 
	 * @Description: 按照用户编号查询所属的下级行政区划
	 * @param param 
	 * @return: com.newfiber.api.core.bean.RespBodyObj<com.newfiber.api.mobile.model.domain.AdministrativeDivision>
	 * @Author: Wmj 
	 * @Date: 2018/12/8 11:13 
	 */ 
	@PostMapping(BaseUrl.QUERY_BY_PARAM)
	@SysLog(value="查询",actionType="4")
	public RespBodyObj<List> queryInfoBySid(@RequestBody ReqBodyObj<AdministrativeDivision> param){
		if( param == null ){
			return RespBodyObj.error(HttpCode.BAD_REQUEST);
		}
		Map<String,Object> map = JsonTools.transBean2Map(param.getData());
		List administrativeDivisionList = administrativeDivisionService.queryListByUserNo(map);
		return RespBodyObj.ok(administrativeDivisionList);
	}

	@SysLog("获取当前用户下级所有区划")
	@PostMapping("selectDivisionByUserNo")
	public RespBodyObj<List<AdministrativeDivision>> selectDivisionByUserNo(HttpServletRequest request){
		String sid = request.getHeader("sid");
		return RespBodyObj.ok(administrativeDivisionService.queryDivisionsubordinate(sid));
	}

	/**
	 * 获取行政区划树形
	 * @return
	 */
	@RequestMapping(value = "division/getDivisionTree",produces = "application/json;charset=UTF-8")
	@ResponseBody
	public RespBodyObj getDivisionTree(){
		List<AdministrativeDivision> provinceList = administrativeDivisionDao.queryListByDivisionNo("0");

		List<Map<String,Object>> list1 = new ArrayList<>();//存放省集合
		if (provinceList.size()>0){
			for (AdministrativeDivision aa : provinceList){
				Map<String,Object> map1 = new HashMap<>();
				String id = aa.getDivisionNo();
				String name = aa.getDivisionName();
				map1.put("id",id);
				map1.put("text",name);
				List<AdministrativeDivision> cityList = administrativeDivisionDao.queryListByDivisionNo(id);

				if (cityList.size()>0){
					List<Map<String,Object>> list2 = new ArrayList<>();
					for (AdministrativeDivision bb : cityList){
						Map<String,Object> map2 = new HashMap<>();
						String id2 = bb.getDivisionNo();
						String name2 = bb.getDivisionName();
						map2.put("id",id2);
						map2.put("text",name2);

						List<AdministrativeDivision> districtList = administrativeDivisionDao.queryListByDivisionNo(id2);

						if (districtList.size()>0){
							List<Map<String,Object>> list3 = new ArrayList<>();
							for (AdministrativeDivision cc : districtList){
								Map<String,Object> map3 = new HashMap<>();
								String id3 = cc.getDivisionNo();
								String name3 = cc.getDivisionName();
								map3.put("id",id3);
								map3.put("text",name3);
								list3.add(map3);
							}
							if (list3.size()>0){
								map2.put("children",list3);
							}
						}

						list2.add(map2);
					}
					if (list2.size()>0){
						map1.put("children",list2);
					}
				}
				list1.add(map1);
			}


		}
		return RespBodyObj.ok(list1);

	}
}