添加城市树
This commit is contained in:
parent
505dc2a173
commit
e47c708421
@ -0,0 +1,17 @@
|
||||
package io.modules.item.dao;
|
||||
|
||||
|
||||
import io.common.dao.BaseDao;
|
||||
import io.modules.item.entity.AreaEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 地区信息
|
||||
*
|
||||
* @author Mark #
|
||||
* @since 1.0.0 2025-02-14
|
||||
*/
|
||||
@Mapper
|
||||
public interface AreaDao extends BaseDao<AreaEntity> {
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package io.modules.item.dao;
|
||||
|
||||
|
||||
import io.common.dao.BaseDao;
|
||||
import io.modules.item.entity.CityEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 城市信息
|
||||
*
|
||||
* @author Mark #
|
||||
* @since 1.0.0 2025-02-14
|
||||
*/
|
||||
@Mapper
|
||||
public interface CityDao extends BaseDao<CityEntity> {
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package io.modules.item.dao;
|
||||
|
||||
|
||||
import io.common.dao.BaseDao;
|
||||
import io.modules.item.entity.ProvinceEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 省份信息
|
||||
*
|
||||
* @author Mark #
|
||||
* @since 1.0.0 2025-02-14
|
||||
*/
|
||||
@Mapper
|
||||
public interface ProvinceDao extends BaseDao<ProvinceEntity> {
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package io.modules.item.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.media.SchemaProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
/**
|
||||
* 地区信息
|
||||
*
|
||||
* @author Mark #
|
||||
* @since 1.0.0 2025-02-14
|
||||
*/
|
||||
@Data
|
||||
@Schema(name = "地区信息")
|
||||
public class AreaDTO implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@SchemaProperty(name = "")
|
||||
private Integer id;
|
||||
|
||||
@SchemaProperty(name = "")
|
||||
private String areaId;
|
||||
|
||||
@SchemaProperty(name = "")
|
||||
private String area;
|
||||
|
||||
@SchemaProperty(name = "")
|
||||
private String father;
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package io.modules.item.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class AreaTree {
|
||||
private Long id;
|
||||
private String area;
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package io.modules.item.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.media.SchemaProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
/**
|
||||
* 城市信息
|
||||
*
|
||||
* @author Mark #
|
||||
* @since 1.0.0 2025-02-14
|
||||
*/
|
||||
@Data
|
||||
@Schema(name = "城市信息")
|
||||
public class CityDTO implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@SchemaProperty(name = "")
|
||||
private Integer id;
|
||||
|
||||
@SchemaProperty(name = "")
|
||||
private String cityId;
|
||||
|
||||
@SchemaProperty(name = "")
|
||||
private String city;
|
||||
|
||||
@SchemaProperty(name = "")
|
||||
private String father;
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package io.modules.item.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class CityTree {
|
||||
|
||||
private Long id;
|
||||
private String city;
|
||||
private List<AreaTree> areaTrees;
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package io.modules.item.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.media.SchemaProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
/**
|
||||
* 省份信息
|
||||
*
|
||||
* @author Mark #
|
||||
* @since 1.0.0 2025-02-14
|
||||
*/
|
||||
@Data
|
||||
@Schema(name = "省份信息")
|
||||
public class ProvinceDTO implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@SchemaProperty(name = "")
|
||||
private Integer id;
|
||||
|
||||
@SchemaProperty(name = "")
|
||||
private String provinceId;
|
||||
|
||||
@SchemaProperty(name = "")
|
||||
private String province;
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package io.modules.item.dto;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ProvinceTree {
|
||||
|
||||
private Long id;
|
||||
private String province;
|
||||
private List<CityTree> cityTrees;
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package io.modules.item.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 地区信息
|
||||
*
|
||||
* @author Mark #
|
||||
* @since 1.0.0 2025-02-14
|
||||
*/
|
||||
@Data
|
||||
@TableName("tb_area")
|
||||
public class AreaEntity {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private Long id;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String areaId;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String area;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String father;
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package io.modules.item.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 城市信息
|
||||
*
|
||||
* @author Mark #
|
||||
* @since 1.0.0 2025-02-14
|
||||
*/
|
||||
@Data
|
||||
@TableName("tb_city")
|
||||
public class CityEntity {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private Long id;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String cityId;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String city;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String father;
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package io.modules.item.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 省份信息
|
||||
*
|
||||
* @author Mark #
|
||||
* @since 1.0.0 2025-02-14
|
||||
*/
|
||||
@Data
|
||||
@TableName("tb_province")
|
||||
public class ProvinceEntity {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private Long id;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String provinceId;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String province;
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package io.modules.item.service;
|
||||
|
||||
|
||||
import io.common.service.CrudService;
|
||||
import io.modules.item.dto.AreaDTO;
|
||||
import io.modules.item.entity.AreaEntity;
|
||||
|
||||
/**
|
||||
* 地区信息
|
||||
*
|
||||
* @author Mark #
|
||||
* @since 1.0.0 2025-02-14
|
||||
*/
|
||||
public interface AreaService extends CrudService<AreaEntity, AreaDTO> {
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package io.modules.item.service;
|
||||
|
||||
|
||||
import io.common.service.CrudService;
|
||||
import io.modules.item.dto.CityDTO;
|
||||
import io.modules.item.entity.CityEntity;
|
||||
|
||||
/**
|
||||
* 城市信息
|
||||
*
|
||||
* @author Mark #
|
||||
* @since 1.0.0 2025-02-14
|
||||
*/
|
||||
public interface CityService extends CrudService<CityEntity, CityDTO> {
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package io.modules.item.service;
|
||||
|
||||
|
||||
import io.common.service.CrudService;
|
||||
import io.modules.item.dto.ProvinceDTO;
|
||||
import io.modules.item.dto.ProvinceTree;
|
||||
import io.modules.item.entity.ProvinceEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 省份信息
|
||||
*
|
||||
* @author Mark #
|
||||
* @since 1.0.0 2025-02-14
|
||||
*/
|
||||
public interface ProvinceService extends CrudService<ProvinceEntity, ProvinceDTO> {
|
||||
|
||||
/**
|
||||
* 结构树
|
||||
* @return
|
||||
*/
|
||||
List<ProvinceTree> tree();
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package io.modules.item.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import io.common.service.impl.CrudServiceImpl;
|
||||
import io.modules.item.dao.AreaDao;
|
||||
import io.modules.item.dto.AreaDTO;
|
||||
import io.modules.item.entity.AreaEntity;
|
||||
import io.modules.item.service.AreaService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 地区信息
|
||||
*
|
||||
* @author Mark #
|
||||
* @since 1.0.0 2025-02-14
|
||||
*/
|
||||
@Service
|
||||
public class AreaServiceImpl extends CrudServiceImpl<AreaDao, AreaEntity, AreaDTO> implements AreaService {
|
||||
|
||||
@Override
|
||||
public QueryWrapper<AreaEntity> getWrapper(Map<String, Object> params){
|
||||
String areaId = (String)params.get("areaId");
|
||||
String father = (String)params.get("father");
|
||||
QueryWrapper<AreaEntity> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq(StrUtil.isNotBlank(areaId), "area_id", areaId);
|
||||
wrapper.eq(StrUtil.isNotBlank(father), "father", father);
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package io.modules.item.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import io.common.service.impl.CrudServiceImpl;
|
||||
import io.modules.item.dao.CityDao;
|
||||
import io.modules.item.dto.CityDTO;
|
||||
import io.modules.item.entity.CityEntity;
|
||||
import io.modules.item.service.CityService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 城市信息
|
||||
*
|
||||
* @author Mark #
|
||||
* @since 1.0.0 2025-02-14
|
||||
*/
|
||||
@Service
|
||||
public class CityServiceImpl extends CrudServiceImpl<CityDao, CityEntity, CityDTO> implements CityService {
|
||||
|
||||
@Override
|
||||
public QueryWrapper<CityEntity> getWrapper(Map<String, Object> params){
|
||||
String cityId = (String)params.get("cityId");
|
||||
String father = (String)params.get("father");
|
||||
|
||||
QueryWrapper<CityEntity> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq(StrUtil.isNotBlank(cityId), "city_id", cityId);
|
||||
wrapper.eq(StrUtil.isNotBlank(father), "father", father);
|
||||
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
package io.modules.item.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import io.common.service.impl.CrudServiceImpl;
|
||||
import io.modules.item.dao.AreaDao;
|
||||
import io.modules.item.dao.CityDao;
|
||||
import io.modules.item.dao.ProvinceDao;
|
||||
import io.modules.item.dto.AreaTree;
|
||||
import io.modules.item.dto.CityTree;
|
||||
import io.modules.item.dto.ProvinceDTO;
|
||||
import io.modules.item.dto.ProvinceTree;
|
||||
import io.modules.item.entity.AreaEntity;
|
||||
import io.modules.item.entity.CityEntity;
|
||||
import io.modules.item.entity.ProvinceEntity;
|
||||
import io.modules.item.service.CityService;
|
||||
import io.modules.item.service.ProvinceService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.awt.geom.Area;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 省份信息
|
||||
*/
|
||||
@Service
|
||||
public class ProvinceServiceImpl extends CrudServiceImpl<ProvinceDao, ProvinceEntity, ProvinceDTO> implements ProvinceService {
|
||||
|
||||
|
||||
@Autowired
|
||||
private CityDao cityRepository;
|
||||
|
||||
@Autowired
|
||||
private AreaDao areaRepository;
|
||||
|
||||
@Override
|
||||
public QueryWrapper<ProvinceEntity> getWrapper(Map<String, Object> params){
|
||||
String provinceId = (String)params.get("province_id");
|
||||
|
||||
QueryWrapper<ProvinceEntity> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq(StrUtil.isNotBlank(provinceId), "province_id", provinceId);
|
||||
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<ProvinceTree> tree() {
|
||||
List<ProvinceEntity> provinces = baseDao.selectList(null);
|
||||
List<ProvinceTree> provinceTrees = new ArrayList<>();
|
||||
for (ProvinceEntity province : provinces) {
|
||||
|
||||
ProvinceTree provinceTree = new ProvinceTree();
|
||||
provinceTree.setId(province.getId());
|
||||
provinceTree.setProvince(province.getProvince());
|
||||
provinceTree.setCityTrees(getCityTree(province.getProvinceId())); // 获取该省的城市树
|
||||
provinceTrees.add(provinceTree);
|
||||
}
|
||||
return provinceTrees;
|
||||
}
|
||||
private List<CityTree> getCityTree(String provinceId) {
|
||||
|
||||
LambdaQueryWrapper<CityEntity> lwq = new LambdaQueryWrapper<>();
|
||||
lwq.eq(CityEntity::getFather, provinceId);
|
||||
List<CityEntity> cities = cityRepository.selectList(lwq);
|
||||
List<CityTree> cityTrees = new ArrayList<>();
|
||||
for (CityEntity city : cities) {
|
||||
CityTree cityTree = new CityTree();
|
||||
cityTree.setId(city.getId());
|
||||
cityTree.setCity(city.getCity());
|
||||
cityTree.setAreaTrees(getAreaTree(city.getCityId())); // 获取该城市的地区树
|
||||
cityTrees.add(cityTree);
|
||||
}
|
||||
return cityTrees;
|
||||
}
|
||||
|
||||
|
||||
private List<AreaTree> getAreaTree(String cityId) {
|
||||
LambdaQueryWrapper<AreaEntity> lwq = new LambdaQueryWrapper<>();
|
||||
lwq.eq(AreaEntity::getFather, cityId);
|
||||
List<AreaEntity> areas = areaRepository.selectList(lwq);
|
||||
List<AreaTree> areaTrees = new ArrayList<>();
|
||||
for (AreaEntity area : areas) {
|
||||
AreaTree areaTree = new AreaTree();
|
||||
areaTree.setId(area.getId());
|
||||
areaTree.setArea(area.getArea());
|
||||
areaTrees.add(areaTree);
|
||||
}
|
||||
return areaTrees;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
package io.controller;
|
||||
|
||||
|
||||
import io.common.constant.Constant;
|
||||
import io.common.page.PageData;
|
||||
import io.common.utils.Result;
|
||||
import io.common.validator.AssertUtils;
|
||||
import io.common.validator.ValidatorUtils;
|
||||
import io.common.validator.group.AddGroup;
|
||||
import io.common.validator.group.DefaultGroup;
|
||||
import io.common.validator.group.UpdateGroup;
|
||||
import io.modules.item.dto.AreaDTO;
|
||||
import io.modules.item.dto.CityDTO;
|
||||
import io.modules.item.dto.ProvinceDTO;
|
||||
import io.modules.item.dto.ProvinceTree;
|
||||
import io.modules.item.service.AreaService;
|
||||
import io.modules.item.service.CityService;
|
||||
import io.modules.item.service.ProvinceService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 地区信息
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("api/area")
|
||||
@Tag(name="地区信息")
|
||||
public class AreaController {
|
||||
@Autowired
|
||||
private ProvinceService provinceService;
|
||||
|
||||
@Autowired
|
||||
private CityService cityService;
|
||||
|
||||
@Autowired
|
||||
private AreaService areaService;
|
||||
|
||||
|
||||
@GetMapping("tree")
|
||||
@Operation(summary = "结构树")
|
||||
public Result<List<ProvinceTree>> tree(){
|
||||
List<ProvinceTree> page = provinceService.tree();
|
||||
return new Result<List<ProvinceTree>>().ok(page);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("province")
|
||||
@Operation(summary = "省份分页")
|
||||
@Parameters({
|
||||
@Parameter(name = "provinceId", description = "城市编号", in = ParameterIn.QUERY, required = true, ref = "String") })
|
||||
public Result<List<ProvinceDTO>> ProvinceList(@Parameter(hidden = true) @RequestParam Map<String, Object> params){
|
||||
List<ProvinceDTO> page = provinceService.list(params);
|
||||
return new Result<List<ProvinceDTO>>().ok(page);
|
||||
}
|
||||
|
||||
@GetMapping("city")
|
||||
@Operation(summary = "城市分页")
|
||||
@Parameters({
|
||||
@Parameter(name = "cityId", description = "城市编号", in = ParameterIn.QUERY, required = true, ref = "String"),
|
||||
@Parameter(name = "father", description = "父编号", in = ParameterIn.QUERY, required = true, ref = "String"),
|
||||
})
|
||||
public Result<List<CityDTO>> CityList(@Parameter(hidden = true) @RequestParam Map<String, Object> params){
|
||||
List<CityDTO> page = cityService.list(params);
|
||||
return new Result<List<CityDTO>>().ok(page);
|
||||
}
|
||||
|
||||
@GetMapping("area")
|
||||
@Operation(summary = "区域分页")
|
||||
@Parameters({
|
||||
@Parameter(name = "areaId", description = " 区域编号", in = ParameterIn.QUERY, required = true, ref = "String"),
|
||||
@Parameter(name = "father", description = " 父编号", in = ParameterIn.QUERY, required = true, ref = "String"),
|
||||
})
|
||||
public Result<List<AreaDTO>> AreaList(@Parameter(hidden = true) @RequestParam Map<String, Object> params){
|
||||
List<AreaDTO> page = areaService.list(params);
|
||||
return new Result<List<AreaDTO>>().ok(page);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -3,7 +3,6 @@ server:
|
||||
servlet:
|
||||
context-path: /renren-generator
|
||||
|
||||
|
||||
spring:
|
||||
datasource:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
|
Loading…
Reference in New Issue
Block a user