
12 changed files with 533 additions and 0 deletions
@ -0,0 +1,30 @@ |
|||
package com.yxt.portal.apiadmin; |
|||
|
|||
import com.yxt.common.core.result.ResultBean; |
|||
import com.yxt.portal.biz.region.RegionChildTwoVo; |
|||
import com.yxt.portal.biz.region.RegionService; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.GetMapping; |
|||
import org.springframework.web.bind.annotation.ResponseBody; |
|||
|
|||
import java.util.List; |
|||
|
|||
public class RegionRest { |
|||
|
|||
@Autowired |
|||
private RegionService regionService; |
|||
|
|||
/** |
|||
* 区域获取省 |
|||
* |
|||
* @return 所有省的集合 |
|||
*/ |
|||
@ApiOperation("获取省") |
|||
@ResponseBody |
|||
@GetMapping("/getProvince") |
|||
public ResultBean getProvince() { |
|||
List<RegionChildTwoVo> regionList = regionService.getProvince(); |
|||
return ResultBean.fireSuccess().setData(regionList); |
|||
} |
|||
} |
@ -0,0 +1,29 @@ |
|||
package com.yxt.portal.biz.region; |
|||
|
|||
import com.yxt.common.core.domain.BaseEntity; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* @author dimengzhe |
|||
* @date 2021/7/2 14:21 |
|||
* @description |
|||
*/ |
|||
@Data |
|||
public class Region extends BaseEntity { |
|||
private static final long serialVersionUID = -2834981997098086066L; |
|||
@ApiModelProperty(value = "上级sid") |
|||
private String pSid; |
|||
@ApiModelProperty(value = "级别") |
|||
private Integer level; |
|||
@ApiModelProperty(value = "名称,区域名称") |
|||
private String name; |
|||
@ApiModelProperty(value = "行政区划代码") |
|||
private String districtCode; |
|||
@ApiModelProperty(value = "sid全路径") |
|||
private String sidPath; |
|||
@ApiModelProperty(value = "排序号") |
|||
private Integer sortNo; |
|||
|
|||
|
|||
} |
@ -0,0 +1,30 @@ |
|||
package com.yxt.portal.biz.region; |
|||
|
|||
import com.yxt.common.core.vo.Vo; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* @author dimengzhe |
|||
* @date 2021/7/2 23:15 |
|||
* @description |
|||
*/ |
|||
@Data |
|||
public class RegionChildTwoVo implements Vo { |
|||
private static final long serialVersionUID = 4618662603777612150L; |
|||
|
|||
@ApiModelProperty(value = "sid") |
|||
private String sid; |
|||
@ApiModelProperty(value = "上级sid") |
|||
private String pSid; |
|||
@ApiModelProperty(value = "级别") |
|||
private Integer level; |
|||
@ApiModelProperty(value = "名称,区域名称") |
|||
private String name; |
|||
@ApiModelProperty(value = "行政区划代码") |
|||
private String districtCode; |
|||
@ApiModelProperty(value = "sid全路径") |
|||
private String sidPath; |
|||
@ApiModelProperty(value = "排序号") |
|||
private Integer sortNo; |
|||
} |
@ -0,0 +1,34 @@ |
|||
package com.yxt.portal.biz.region; |
|||
|
|||
import com.yxt.common.core.vo.Vo; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @author dimengzhe |
|||
* @date 2021/7/2 23:14 |
|||
* @description |
|||
*/ |
|||
@Data |
|||
public class RegionChildVo implements Vo { |
|||
private static final long serialVersionUID = -4741874809037026585L; |
|||
|
|||
@ApiModelProperty(value = "sid") |
|||
private String sid; |
|||
@ApiModelProperty(value = "上级sid") |
|||
private String pSid; |
|||
@ApiModelProperty(value = "级别") |
|||
private Integer level; |
|||
@ApiModelProperty(value = "名称,区域名称") |
|||
private String name; |
|||
@ApiModelProperty(value = "行政区划代码") |
|||
private String districtCode; |
|||
@ApiModelProperty(value = "sid全路径") |
|||
private String sidPath; |
|||
@ApiModelProperty(value = "排序号") |
|||
private Integer sortNo; |
|||
|
|||
private List<RegionChildTwoVo> regionChildTwoVoList; |
|||
} |
@ -0,0 +1,46 @@ |
|||
package com.yxt.portal.biz.region; |
|||
|
|||
import com.yxt.common.core.dto.Dto; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
import javax.validation.constraints.Size; |
|||
|
|||
/** |
|||
* @Author dimengzhe |
|||
* @Date 2021/11/11 15:18 |
|||
* @Description |
|||
*/ |
|||
@Data |
|||
public class RegionDto implements Dto { |
|||
private static final long serialVersionUID = 1283045363206557586L; |
|||
/** |
|||
* 名称,区域名称 |
|||
*/ |
|||
@ApiModelProperty(value = "区域名称", required = true) |
|||
@NotBlank(message = "区域名称不能为空") |
|||
@Size(max = 64, min = 1) |
|||
private String name; |
|||
/** |
|||
* 行政区划代码 |
|||
*/ |
|||
@ApiModelProperty(value = "行政区划代码", required = true) |
|||
@NotBlank(message = "行政区划代码不能为空") |
|||
private String districtCode; |
|||
/** |
|||
* 上级sid |
|||
*/ |
|||
@ApiModelProperty(value = "上级sid", required = true, example = "0") |
|||
private String psid; |
|||
|
|||
/** |
|||
* 排序号 |
|||
*/ |
|||
@ApiModelProperty(value = "排序号", required = true) |
|||
private Integer sortNo; |
|||
@ApiModelProperty(value = "级别") |
|||
private int level; |
|||
|
|||
|
|||
} |
@ -0,0 +1,24 @@ |
|||
package com.yxt.portal.biz.region; |
|||
|
|||
import com.yxt.common.core.vo.Vo; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
|||
|
|||
/** |
|||
* @author dimengzhe |
|||
* @date 2021/7/13 21:41 |
|||
* @description |
|||
*/ |
|||
@Data |
|||
public class RegionListVo implements Vo { |
|||
private static final long serialVersionUID = 8123582673134551495L; |
|||
@ApiModelProperty(value = "sid") |
|||
private String sid; |
|||
@ApiModelProperty(value = "名称") |
|||
private String name; |
|||
@ApiModelProperty(value = "区划代码") |
|||
private String districtCode; |
|||
@ApiModelProperty(value = "排序") |
|||
private Integer sortNo; |
|||
} |
@ -0,0 +1,61 @@ |
|||
package com.yxt.portal.biz.region; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.Wrapper; |
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import com.baomidou.mybatisplus.core.metadata.IPage; |
|||
import com.baomidou.mybatisplus.core.toolkit.Constants; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
import org.apache.ibatis.annotations.Param; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @author dimengzhe |
|||
* @date 2021/7/2 15:10 |
|||
* @description |
|||
*/ |
|||
@Mapper |
|||
public interface RegionMapper extends BaseMapper<Region> { |
|||
/** |
|||
* 分页列表 |
|||
* |
|||
* @param page |
|||
* @param qw |
|||
* @return |
|||
*/ |
|||
IPage<RegionListVo> pageList(IPage<RegionQuery> page, @Param(Constants.WRAPPER) Wrapper<RegionListVo> qw); |
|||
|
|||
/** |
|||
* 区域的树形列表 |
|||
* |
|||
* @param psid |
|||
* @return |
|||
*/ |
|||
List<RegionVo> treeList(String psid); |
|||
|
|||
List<RegionChildTwoVo> getProvince(); |
|||
|
|||
List<RegionChildTwoVo> getCity(String sid); |
|||
|
|||
List<RegionChildTwoVo> getCounty(String sid); |
|||
|
|||
RegionThirdLevelNameVo selectThirdLevelNameByCode(@Param("districtCode") String districtCode); |
|||
|
|||
/** |
|||
* 获取省市县区域列表 |
|||
* |
|||
* @param pSid 上级sid,默认为0 |
|||
* @return |
|||
*/ |
|||
List<RegionChildTwoVo> selectsList(String pSid); |
|||
|
|||
Region selectByPsid(String pSid); |
|||
|
|||
/** |
|||
* 查询该区域是否有下级 |
|||
* |
|||
* @param sid 区域sid |
|||
* @return int |
|||
*/ |
|||
public int selectRegionBySid(String sid); |
|||
} |
@ -0,0 +1,74 @@ |
|||
<?xml version="1.0" encoding="UTF-8" ?> |
|||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
|||
<mapper namespace="com.yxt.portal.biz.region.RegionMapper"> |
|||
<resultMap id="regionMapNoChild" type="com.yxt.portal.biz.region.RegionChildTwoVo"> |
|||
<result column="name" jdbcType="VARCHAR" property="name"/> |
|||
<result column="sid" jdbcType="VARCHAR" property="sid"/> |
|||
<result column="pSid" jdbcType="VARCHAR" property="pSid"/> |
|||
<result column="districtCode" jdbcType="INTEGER" property="districtCode"/> |
|||
<result column="sidPath" jdbcType="VARCHAR" property="sidPath"/> |
|||
</resultMap> |
|||
|
|||
<select id="treeList" resultType="com.yxt.portal.biz.region.RegionVo"> |
|||
SELECT r.sid, r.pSid, r.level, r.name, r.districtCode, r.sidPath, r.sortNo |
|||
from region r |
|||
WHERE r.pSid = #{psid} |
|||
ORDER BY r.sortNo ASC |
|||
</select> |
|||
|
|||
<select id="getProvince" parameterType="com.yxt.portal.biz.region.RegionVo" resultMap="regionMapNoChild"> |
|||
SELECT name, sid, pSid, districtCode, sidPath |
|||
FROM region |
|||
WHERE level = 1 |
|||
AND pSid = 0 |
|||
</select> |
|||
|
|||
<select id="getCity" parameterType="com.yxt.portal.biz.region.RegionVo" resultMap="regionMapNoChild"> |
|||
SELECT name, sid, pSid, districtCode, sidPath |
|||
FROM region |
|||
WHERE level = 2 |
|||
AND pSid = #{sid} |
|||
ORDER BY sortNo + 0 |
|||
</select> |
|||
|
|||
<select id="getCounty" parameterType="com.yxt.portal.biz.region.RegionVo" resultMap="regionMapNoChild"> |
|||
SELECT name, sid, pSid, districtCode, sidPath |
|||
FROM region |
|||
WHERE level = 3 |
|||
AND pSid = #{sid} |
|||
</select> |
|||
|
|||
<select id="selectThirdLevelNameByCode" resultType="com.yxt.portal.biz.region.RegionThirdLevelNameVo"> |
|||
SELECT child.`name` county, father1.`name` city, father2.`name` province |
|||
FROM region child |
|||
LEFT JOIN region father1 ON child.psid = father1.sid |
|||
LEFT JOIN region father2 ON father1.psid = father2.sid |
|||
WHERE child.districtCode = #{districtCode} |
|||
</select> |
|||
|
|||
<!-- <cache/>--> |
|||
|
|||
<select id="selectsList" resultType="com.yxt.portal.biz.region.RegionChildTwoVo"> |
|||
SELECT r.sid, r.pSid, r.level, r.name, r.districtCode, r.sidPath, r.sortNo |
|||
from region r |
|||
WHERE pSid = #{pSid} |
|||
</select> |
|||
|
|||
<select id="selectByPsid" resultType="com.yxt.portal.biz.region.Region"> |
|||
SELECT * |
|||
FROM region |
|||
WHERE sid = #{pSid} |
|||
</select> |
|||
|
|||
<select id="selectRegionBySid" resultType="java.lang.Integer"> |
|||
SELECT count(*) |
|||
FROM region |
|||
WHERE pSid = #{sid} |
|||
</select> |
|||
|
|||
<select id="pageList" resultType="com.yxt.portal.biz.region.RegionListVo"> |
|||
SELECT r.name, r.districtCode, r.sortNo, r.sid |
|||
from region r |
|||
${ew.customSqlSegment} |
|||
</select> |
|||
</mapper> |
@ -0,0 +1,23 @@ |
|||
package com.yxt.portal.biz.region; |
|||
|
|||
import com.yxt.common.core.query.Query; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
|||
|
|||
/** |
|||
* @author dimengzhe |
|||
* @date 2021/7/13 21:55 |
|||
* @description |
|||
*/ |
|||
@Data |
|||
public class RegionQuery implements Query { |
|||
private static final long serialVersionUID = -3494331991678665867L; |
|||
|
|||
@ApiModelProperty(value = "行政区划") |
|||
private String districtCode; |
|||
@ApiModelProperty(value = "名称") |
|||
private String name; |
|||
@ApiModelProperty(value = "pSid,市级列表此值需要传省级列表sid", example = "0") |
|||
private String psid; |
|||
} |
@ -0,0 +1,123 @@ |
|||
package com.yxt.portal.biz.region; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|||
import com.baomidou.mybatisplus.core.metadata.IPage; |
|||
import com.yxt.common.base.service.MybatisBaseService; |
|||
import com.yxt.common.base.utils.PagerUtil; |
|||
import com.yxt.common.base.utils.StringUtils; |
|||
import com.yxt.common.core.query.PagerQuery; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @author dimengzhe |
|||
* @date 2021/7/2 15:06 |
|||
* @description |
|||
*/ |
|||
@Service |
|||
public class RegionService extends MybatisBaseService<RegionMapper, Region> { |
|||
|
|||
// 分页列表
|
|||
public IPage<RegionListVo> pageList(PagerQuery<RegionQuery> pagerQuery) { |
|||
// mybits所用的分页对对象
|
|||
IPage<RegionQuery> page = PagerUtil.queryToPage(pagerQuery); |
|||
// mybits所用的查询条件封装类
|
|||
QueryWrapper<RegionListVo> qw = buildQueryWrapper(pagerQuery.getParams()); |
|||
return baseMapper.pageList(page, qw); |
|||
} |
|||
|
|||
private QueryWrapper<RegionListVo> buildQueryWrapper(RegionQuery pagerQuery) { |
|||
QueryWrapper<RegionListVo> qw = new QueryWrapper<>(); |
|||
if (pagerQuery != null) { |
|||
String code = pagerQuery.getDistrictCode(); |
|||
if (StringUtils.isNotBlank(code)) { |
|||
qw.like("r.districtCode", code); |
|||
} |
|||
String pSid = pagerQuery.getPsid(); |
|||
qw.eq("r.pSid", pSid); |
|||
|
|||
String name = pagerQuery.getName(); |
|||
if (StringUtils.isNotBlank(name)) { |
|||
qw.like("r.name", name); |
|||
} |
|||
qw.orderByDesc("r.createTime"); |
|||
} |
|||
return qw; |
|||
} |
|||
|
|||
/** |
|||
* 区域树形列表 |
|||
* |
|||
* @return |
|||
*/ |
|||
public List<RegionVo> treeList() { |
|||
String psid = "0"; |
|||
List<RegionVo> list = baseMapper.treeList(psid); |
|||
getChildList(list); |
|||
return list; |
|||
} |
|||
|
|||
public void getChildList(List<RegionVo> list) { |
|||
list.forEach(regionTree -> { |
|||
String sid = regionTree.getSid(); |
|||
List<RegionVo> listChildren = baseMapper.treeList(sid); |
|||
regionTree.setChildren(listChildren); |
|||
getChildList(listChildren); |
|||
}); |
|||
} |
|||
|
|||
public List<RegionChildTwoVo> getProvince() { |
|||
return baseMapper.getProvince(); |
|||
} |
|||
|
|||
/** |
|||
* 获取某省下的所有市 |
|||
* |
|||
* @param sid 省sid |
|||
* @return 该省下的所有市的list |
|||
*/ |
|||
public List<RegionChildTwoVo> getCity(String sid) { |
|||
return baseMapper.getCity(sid); |
|||
|
|||
} |
|||
|
|||
/** |
|||
* 获取某市下的所有区县 |
|||
* |
|||
* @param sid 市sid |
|||
* @return 该市下的所有县区的list |
|||
*/ |
|||
public List<RegionChildTwoVo> getCounty(String sid) { |
|||
return baseMapper.getCounty(sid); |
|||
} |
|||
|
|||
RegionThirdLevelNameVo selectThirdLevelNameByCode(String districtCode) { |
|||
return baseMapper.selectThirdLevelNameByCode(districtCode); |
|||
} |
|||
|
|||
/** |
|||
* 获取省市县 |
|||
* |
|||
* @param pSid |
|||
* @return |
|||
*/ |
|||
public List<RegionChildTwoVo> selectsList(String pSid) { |
|||
return baseMapper.selectsList(pSid); |
|||
} |
|||
|
|||
public Region selectByPsid(String pSid) { |
|||
return baseMapper.selectByPsid(pSid); |
|||
} |
|||
|
|||
/** |
|||
* 根据sid查询该区域是否有下级 |
|||
* |
|||
* @param sid 区域sid |
|||
* @return int |
|||
*/ |
|||
public int selectRegionBySid(String sid) { |
|||
return baseMapper.selectRegionBySid(sid); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,24 @@ |
|||
package com.yxt.portal.biz.region; |
|||
|
|||
import com.yxt.common.core.vo.Vo; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* @Description |
|||
* @Author liuguohui |
|||
* @Date 2021/10/4 |
|||
*/ |
|||
@Data |
|||
public class RegionThirdLevelNameVo implements Vo { |
|||
|
|||
@ApiModelProperty(value = "省") |
|||
private String province; |
|||
|
|||
@ApiModelProperty(value = "市") |
|||
private String city; |
|||
|
|||
@ApiModelProperty(value = "县") |
|||
private String county; |
|||
|
|||
} |
@ -0,0 +1,35 @@ |
|||
package com.yxt.portal.biz.region; |
|||
|
|||
import com.yxt.common.core.vo.Vo; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @author dimengzhe |
|||
* @date 2021/7/2 14:22 |
|||
* @description |
|||
*/ |
|||
@Data |
|||
public class RegionVo implements Vo { |
|||
private static final long serialVersionUID = 3351684167946104384L; |
|||
|
|||
@ApiModelProperty(value = "sid") |
|||
private String sid; |
|||
@ApiModelProperty(value = "上级sid") |
|||
private String pSid; |
|||
@ApiModelProperty(value = "级别") |
|||
private Integer level; |
|||
@ApiModelProperty(value = "名称,区域名称") |
|||
private String name; |
|||
@ApiModelProperty(value = "行政区划代码") |
|||
private String districtCode; |
|||
@ApiModelProperty(value = "sid全路径") |
|||
private String sidPath; |
|||
@ApiModelProperty(value = "排序号") |
|||
private Integer sortNo; |
|||
|
|||
private List<RegionVo> children; |
|||
|
|||
} |
Loading…
Reference in new issue