|
@@ -6,7 +6,11 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.szwl.model.bean.AreaDTO;
|
|
|
import com.szwl.model.bo.R;
|
|
|
import com.szwl.model.bo.ResponseModel;
|
|
|
+import com.szwl.model.entity.Cities;
|
|
|
+import com.szwl.model.entity.Countries;
|
|
|
import com.szwl.model.entity.TArea;
|
|
|
+import com.szwl.service.CitiesService;
|
|
|
+import com.szwl.service.CountriesService;
|
|
|
import com.szwl.service.TAreaService;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -19,7 +23,7 @@ import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
|
- * 前端控制器
|
|
|
+ * 前端控制器
|
|
|
* </p>
|
|
|
*
|
|
|
* @author wuhs
|
|
@@ -30,38 +34,45 @@ import java.util.List;
|
|
|
public class TAreaController {
|
|
|
@Autowired
|
|
|
TAreaService areaService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ CitiesService citiesService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ CountriesService countriesService;
|
|
|
+
|
|
|
@ApiOperation(value = "")
|
|
|
@GetMapping("/getArea")
|
|
|
public ResponseModel<?> getArea(Long value) {
|
|
|
List<AreaDTO> areaDTOList = new ArrayList<>();
|
|
|
LambdaQueryWrapper<TArea> query = Wrappers.lambdaQuery();
|
|
|
- if(value==null){
|
|
|
+ if (value == null) {
|
|
|
//获取顶级地址
|
|
|
- query.eq(TArea::getTreePath,",");
|
|
|
- }else {
|
|
|
- query.eq(TArea::getParent,value);
|
|
|
+ query.eq(TArea::getTreePath, ",");
|
|
|
+ } else {
|
|
|
+ query.eq(TArea::getParent, value);
|
|
|
}
|
|
|
List<TArea> list = areaService.list(query);
|
|
|
Boolean hasChild = false;
|
|
|
- for(int i = 0;i<list.size();i++){
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
AreaDTO areaDTO = new AreaDTO();
|
|
|
areaDTO.setText(list.get(i).getName());
|
|
|
areaDTO.setValue(list.get(i).getId());
|
|
|
- if(list.get(i).getTreePath().equals(",")){
|
|
|
+ if (list.get(i).getTreePath().equals(",")) {
|
|
|
areaDTO.setHasChildren(true);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
String[] split = list.get(i).getTreePath().split(",");
|
|
|
- if(split.length==2){
|
|
|
- if(i==0){
|
|
|
+ if (split.length == 2) {
|
|
|
+ if (i == 0) {
|
|
|
LambdaQueryWrapper<TArea> query1 = Wrappers.lambdaQuery();
|
|
|
- query1.eq(TArea::getParent,list.get(i).getId());
|
|
|
+ query1.eq(TArea::getParent, list.get(i).getId());
|
|
|
List<TArea> list1 = areaService.list(query1);
|
|
|
- if(list1.size()>0){
|
|
|
- hasChild=true;
|
|
|
+ if (list1.size() > 0) {
|
|
|
+ hasChild = true;
|
|
|
}
|
|
|
}
|
|
|
areaDTO.setHasChildren(hasChild);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
areaDTO.setHasChildren(false);
|
|
|
}
|
|
|
}
|
|
@@ -70,22 +81,23 @@ public class TAreaController {
|
|
|
}
|
|
|
return R.ok(areaDTOList);
|
|
|
}
|
|
|
+
|
|
|
@ApiOperation(value = "")
|
|
|
@GetMapping("/getById")
|
|
|
public ResponseModel<?> getById(Long value) {
|
|
|
List<AreaDTO> areaDTOList = new ArrayList<>();
|
|
|
TArea area1 = areaService.getById(value);
|
|
|
- if(area1.getParent()==null){
|
|
|
+ if (area1.getParent() == null) {
|
|
|
//省级
|
|
|
AreaDTO areaDTO = new AreaDTO();
|
|
|
areaDTO.setText(area1.getName());
|
|
|
areaDTO.setValue(area1.getId());
|
|
|
areaDTO.setHasChildren(true);
|
|
|
areaDTOList.add(areaDTO);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
List<AreaDTO> areaDTOList1 = new ArrayList<>();
|
|
|
TArea byId = areaService.getById(area1.getParent());
|
|
|
- if(byId.getParent()==null){
|
|
|
+ if (byId.getParent() == null) {
|
|
|
//省级
|
|
|
AreaDTO areaDTO = new AreaDTO();
|
|
|
areaDTO.setText(byId.getName());
|
|
@@ -96,18 +108,18 @@ public class TAreaController {
|
|
|
areaDTO1.setText(area1.getName());
|
|
|
areaDTO1.setValue(area1.getId());
|
|
|
String[] split = area1.getTreePath().split(",");
|
|
|
- if(split.length==2){
|
|
|
+ if (split.length == 2) {
|
|
|
LambdaQueryWrapper<TArea> query1 = Wrappers.lambdaQuery();
|
|
|
- query1.eq(TArea::getParent,area1.getId());
|
|
|
+ query1.eq(TArea::getParent, area1.getId());
|
|
|
List<TArea> list1 = areaService.list(query1);
|
|
|
- if(list1.size()>0){
|
|
|
+ if (list1.size() > 0) {
|
|
|
areaDTO1.setHasChildren(true);
|
|
|
}
|
|
|
}
|
|
|
areaDTOList1.add(areaDTO1);
|
|
|
areaDTO.setChildren(areaDTOList1);
|
|
|
areaDTOList.add(areaDTO);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
List<AreaDTO> areaDTOList2 = new ArrayList<>();
|
|
|
TArea area = areaService.getById(byId.getParent());
|
|
|
//省级
|
|
@@ -136,5 +148,17 @@ public class TAreaController {
|
|
|
}
|
|
|
return R.ok(areaDTOList);
|
|
|
}
|
|
|
+
|
|
|
+ @ApiOperation("获取国外地址")
|
|
|
+ @GetMapping("/getForeignArea")
|
|
|
+ public ResponseModel<?> getForeignArea(Long id) {
|
|
|
+ String fullName = "";
|
|
|
+ Cities cities = citiesService.getById(id);
|
|
|
+ if (cities != null) {
|
|
|
+ Countries countries = countriesService.getById(cities.getCountryId());
|
|
|
+ fullName = countries.getName() + "/" + cities.getName();
|
|
|
+ }
|
|
|
+ return R.ok(fullName);
|
|
|
+ }
|
|
|
}
|
|
|
|