Browse Source

省市区查询

Michael 8 years ago
parent
commit
bdcdb8e5bc

+ 43 - 0
src/main/java/com/goafanti/common/bo/AreaBo.java

@@ -0,0 +1,43 @@
+package com.goafanti.common.bo;
+
+public class AreaBo {
+	private Integer id;
+
+    private String name;
+
+    private Integer pid;
+
+    private Integer level;
+
+	public Integer getId() {
+		return id;
+	}
+
+	public void setId(Integer id) {
+		this.id = id;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public Integer getPid() {
+		return pid;
+	}
+
+	public void setPid(Integer pid) {
+		this.pid = pid;
+	}
+
+	public Integer getLevel() {
+		return level;
+	}
+
+	public void setLevel(Integer level) {
+		this.level = level;
+	}
+}

+ 55 - 0
src/main/java/com/goafanti/common/bo/CityBo.java

@@ -0,0 +1,55 @@
+package com.goafanti.common.bo;
+
+import java.util.List;
+
+public class CityBo {
+	private Integer id;
+
+    private String name;
+
+    private Integer pid;
+
+    private Integer level;
+    
+    private List<AreaBo> areaList;
+
+	public List<AreaBo> getAreaList() {
+		return areaList;
+	}
+
+	public void setAreaList(List<AreaBo> areaList) {
+		this.areaList = areaList;
+	}
+
+	public Integer getId() {
+		return id;
+	}
+
+	public void setId(Integer id) {
+		this.id = id;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public Integer getPid() {
+		return pid;
+	}
+
+	public void setPid(Integer pid) {
+		this.pid = pid;
+	}
+
+	public Integer getLevel() {
+		return level;
+	}
+
+	public void setLevel(Integer level) {
+		this.level = level;
+	}
+}

+ 57 - 0
src/main/java/com/goafanti/common/bo/ProvinceBo.java

@@ -0,0 +1,57 @@
+package com.goafanti.common.bo;
+
+import java.util.List;
+
+public class ProvinceBo {
+	private Integer id;
+
+    private String name;
+
+    private Integer pid;
+
+    private Integer level;
+    
+    private List<CityBo> cityList;
+
+	public List<CityBo> getCityList() {
+		return cityList;
+	}
+
+	public void setCityList(List<CityBo> cityList) {
+		this.cityList = cityList;
+	}
+
+	public Integer getId() {
+		return id;
+	}
+
+	public void setId(Integer id) {
+		this.id = id;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public Integer getPid() {
+		return pid;
+	}
+
+	public void setPid(Integer pid) {
+		this.pid = pid;
+	}
+
+	public Integer getLevel() {
+		return level;
+	}
+
+	public void setLevel(Integer level) {
+		this.level = level;
+	}
+    
+    
+}

+ 13 - 0
src/main/java/com/goafanti/common/controller/PublicController.java

@@ -26,6 +26,7 @@ import com.goafanti.common.constant.ErrorConstants;
 import com.goafanti.common.enums.UserType;
 import com.goafanti.common.model.User;
 import com.goafanti.common.service.DistrictGlossoryService;
+import com.goafanti.common.service.FieldGlossoryService;
 import com.goafanti.common.service.IndustryCategoryService;
 import com.goafanti.common.utils.LoggerUtils;
 import com.goafanti.common.utils.MobileMessageUtils;
@@ -63,6 +64,9 @@ public class PublicController extends BaseController {
 
 	@Resource
 	private AftFileService			aftFileService;
+	
+	@Resource
+	private FieldGlossoryService			fieldGlossoryService;
 
 	@Autowired
 	private IndustryCategoryService	industryCategoryService;
@@ -503,4 +507,13 @@ public class PublicController extends BaseController {
 		return res;
 	}
 	
+	/** 省市区查询 **/
+	@RequestMapping(value = "/listAllProvince" , method = RequestMethod.POST)
+	@ResponseBody
+	public Result listAllProvince(){
+		Result res = new Result();
+		res.setData(districtGlossoryService.getProvince());
+		return res;
+	}
+	
 }

+ 9 - 0
src/main/java/com/goafanti/common/dao/DistrictGlossoryMapper.java

@@ -2,6 +2,9 @@ package com.goafanti.common.dao;
 
 import java.util.List;
 
+import com.goafanti.common.bo.AreaBo;
+import com.goafanti.common.bo.CityBo;
+import com.goafanti.common.bo.ProvinceBo;
 import com.goafanti.common.model.DistrictGlossory;
 
 public interface DistrictGlossoryMapper {
@@ -20,4 +23,10 @@ public interface DistrictGlossoryMapper {
     List<DistrictGlossory> findByPid(Integer pid);
     
     String selectNameById(Integer id);
+    
+    List<ProvinceBo> getProvince();
+	
+	List<CityBo> getCity();
+	
+	List<AreaBo> getArea();
 }

+ 21 - 0
src/main/java/com/goafanti/common/mapper/DistrictGlossoryMapper.xml

@@ -90,4 +90,25 @@
   <select id="selectNameById" parameterType="java.lang.Integer" resultType="String">
     select name from aft.district_glossory where id=#{id,jdbcType=INTEGER}
   </select>
+  
+  <select id="getProvince" resultType="com.goafanti.common.bo.ProvinceBo">
+    select 
+    id,name,pid,level
+    from district_glossory
+    where level=1
+  </select>
+  
+  <select id="getCity" resultType="com.goafanti.common.bo.CityBo" >
+    select 
+    id,name,pid,level
+    from district_glossory
+    where level=2
+  </select>
+  
+  <select id="getArea" resultType="com.goafanti.common.bo.AreaBo" >
+    select 
+    id,name,pid,level
+    from district_glossory
+    where level=3
+  </select>
 </mapper>

+ 31 - 0
src/main/java/com/goafanti/common/service/DistrictGlossoryService.java

@@ -1,5 +1,6 @@
 package com.goafanti.common.service;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import org.slf4j.Logger;
@@ -9,6 +10,9 @@ import org.springframework.cache.annotation.CacheEvict;
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 
+import com.goafanti.common.bo.AreaBo;
+import com.goafanti.common.bo.CityBo;
+import com.goafanti.common.bo.ProvinceBo;
 import com.goafanti.common.dao.DistrictGlossoryMapper;
 import com.goafanti.common.model.DistrictGlossory;
 import com.goafanti.common.utils.LoggerUtils;
@@ -37,4 +41,31 @@ public class DistrictGlossoryService {
 	public String selectNameById(Integer id) {
 		return districtGlossoryMapper.selectNameById(id);
 	}
+	
+	public List<ProvinceBo> getProvince(){
+		List<ProvinceBo> provinces=districtGlossoryMapper.getProvince();
+		List<CityBo> city=districtGlossoryMapper.getCity();
+		List<AreaBo> Area=districtGlossoryMapper.getArea();		
+		for(ProvinceBo one:provinces){
+			List <CityBo> cc=new ArrayList<CityBo>();
+			int pbid = one.getId();
+			for(CityBo two:city){
+				List <AreaBo> aa=new ArrayList<AreaBo>();
+				int cbid=two.getId();
+				int cbpid=two.getPid();
+				if(cbpid==pbid){					
+					for(AreaBo three:Area){
+						int abpid=three.getPid();
+						if(abpid==cbid){
+							aa.add(three);
+							two.setAreaList(aa);
+						}
+					}
+					cc.add(two);
+					one.setCityList(cc);
+				}
+			}
+		}
+		return provinces;
+	}
 }