CommonController.java
4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package com.sincere.student.controller;
import com.alibaba.fastjson.JSON;
import com.sincere.student.dto.Province;
import com.sincere.student.model.Area;
import com.sincere.student.service.CommonService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@RestController
@RequestMapping("/common")
public class CommonController {
@Autowired
CommonService commonService ;
private static List<Area> list = new ArrayList<>();
private static List<Province> provinces = new ArrayList<>();
@ApiOperation("省份")
@RequestMapping(value = "getProvince",method = RequestMethod.GET)
public List<Area> getProvince(){
if(list.size() == 0){
List<Area> areas = commonService.getProvince();
for(Area area : areas){
List<Area> cityList = commonService.getCity(area.getCode());
if(area.getName().contains("市")){
//获取全部
area.setList(cityList);
}else {
//获取4位的市
List<Area> trueCityList = new ArrayList<>();
for(Area city : cityList){
if(city.getCode().length() < 6){
trueCityList.add(city);
}
}
area.setList(trueCityList);
}
}
list = areas ;
}
return list ;
}
@ApiOperation("省份")
@RequestMapping(value = "getProvince2",method = RequestMethod.GET)
public List<Province> getProvince2(){
if(provinces.size() == 0){
if(list.size() == 0){
List<Area> areas = commonService.getProvince();
for(Area area : areas){
List<Area> cityList = commonService.getCity(area.getCode());
if(area.getName().contains("市")){
//获取全部
area.setList(cityList);
}else {
//获取4位的市
List<Area> trueCityList = new ArrayList<>();
for(Area city : cityList){
if(city.getCode().length() < 6){
trueCityList.add(city);
}
}
area.setList(trueCityList);
}
}
list = areas ;
}
for(Area area : list){
Province province = new Province() ;
province.setValue(area.getName());
province.setLabel(area.getName());
List<Province> cityList = new ArrayList<>();
for(Area city : area.getList()){
Province newCity = new Province();
newCity.setLabel(city.getName());
newCity.setValue(city.getName());
cityList.add(newCity);
}
province.setChildren(cityList);
provinces.add(province);
}
}
return provinces ;
}
@ApiOperation("市")
@RequestMapping(value = "getCity",method = RequestMethod.GET)
public List<Area> getCity(String code){
return commonService.getCity(code);
}
@ApiOperation("高校类型")
@RequestMapping(value = "getUniversityType",method = RequestMethod.GET)
public List<String> getUniversityType(){
String[] array = new String[]{"综合类","理工类","师范类","农林类","政法类","医药类"
,"财经类","民族类","语言类","艺术类","体育类","军事类","旅游类"};
List<String> list = Arrays.asList(array);
return list ;
}
@ApiOperation("高校教学层次")
@RequestMapping(value = "getUniversityLevel",method = RequestMethod.GET)
public List<String> getUniversityLevel(){
String[] array = new String[]{"本科","高职"};
List<String> list = Arrays.asList(array);
return list ;
}
}