From 46f0777d5f93bf316821894552f8eaabafbd32f1 Mon Sep 17 00:00:00 2001 From: liurunyu <lry9898@163.com> Date: 星期四, 09 十一月 2023 14:50:25 +0800 Subject: [PATCH] 完善行政区划功能 --- pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/webUtil/BaseResponseUtils.java | 2 pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictSv.java | 32 ++++++++++ pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictVo.java | 3 + pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictCtrl.java | 21 ++++++ pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaDistrictMapper.xml | 38 ++++++++++-- pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoBa/BaDistrict.java | 8 ++ pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaDistrictMapper.java | 16 +++++ pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictVoMapper.java | 1 8 files changed, 112 insertions(+), 9 deletions(-) diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/webUtil/BaseResponseUtils.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/webUtil/BaseResponseUtils.java index b613d77..c55567e 100644 --- a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/webUtil/BaseResponseUtils.java +++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/webUtil/BaseResponseUtils.java @@ -3,8 +3,10 @@ /** * 杩斿洖鍊兼搷浣滃伐鍏� */ +@SuppressWarnings("rawtypes") public class BaseResponseUtils{ + @SuppressWarnings("unused") public static BaseResponse buildSuccess(){ return buildSuccess(null); } diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaDistrictMapper.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaDistrictMapper.java index 9e342c8..80b0136 100644 --- a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaDistrictMapper.java +++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaDistrictMapper.java @@ -5,6 +5,8 @@ import com.dy.pipIrrGlobal.pojoBa.BaPrivilege; import org.apache.ibatis.annotations.Mapper; +import java.util.List; + @Mapper public interface BaDistrictMapper extends BaseMapper<BaPrivilege> { /** @@ -36,6 +38,20 @@ BaDistrict selectByPrimaryKey(Long id); /** + * 鏌ヨ鏌愪竴琛屾斂绾у埆鐨勮鏀垮尯鍒� + * @param level 琛屾斂鍖哄垝绾у埆 + * @return 鏌愪竴琛屾斂绾у埆鐨勮鏀垮尯鍒� + */ + List<BaDistrict> selectByLevel(byte level) ; + + /** + * 鏌ヨ鏌愪竴琛屾斂绾у埆鐨勪笅绾ц鏀垮尯 + * @param supperId 涓婄骇琛屾斂鍖篒D + * @return 鏌愪竴琛屾斂绾у埆鐨勪笅绾ц鏀垮尯 + */ + List<BaDistrict> selectBySupperId(Long supperId) ; + + /** * update record selective * @param record the updated record * @return update count diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoBa/BaDistrict.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoBa/BaDistrict.java index ea2cc1d..9a0eb2c 100644 --- a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoBa/BaDistrict.java +++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoBa/BaDistrict.java @@ -3,11 +3,14 @@ import com.alibaba.fastjson2.annotation.JSONField; import com.alibaba.fastjson2.writer.ObjectWriterImplToString; import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.dy.common.po.BaseEntity; import com.dy.pipIrrGlobal.util.DistrictLevel; import lombok.*; + +import java.util.List; @TableName(value="ba_district", autoResultMap = true) @Data @@ -23,8 +26,13 @@ @TableId(type = IdType.INPUT) public Long id ; + public Long supperId;//涓婄骇琛屾斂鍖篒D + public String name; public DistrictLevel level; + @TableField(exist = false) + public List<BaDistrict> subDistricts ; + } \ No newline at end of file diff --git a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaDistrictMapper.xml b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaDistrictMapper.xml index e434616..0732885 100644 --- a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaDistrictMapper.xml +++ b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaDistrictMapper.xml @@ -5,13 +5,13 @@ <!--@mbg.generated--> <!--@Table ba_district--> <id column="id" jdbcType="BIGINT" property="id" /> + <id column="supperId" jdbcType="BIGINT" property="supperId" /> <result column="name" jdbcType="VARCHAR" property="name" /> <result property="level" column="level" typeHandler="com.dy.common.mybatis.envm.EnumCodeTypeHandler" javaType="com.dy.pipIrrGlobal.util.DistrictLevel"/> - </resultMap> <sql id="Base_Column_List"> <!--@mbg.generated--> - id, `name`, `level` + id, supperId, `name`, `level` </sql> <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap"> <!--@mbg.generated--> @@ -20,6 +20,20 @@ from ba_district where id = #{id,jdbcType=BIGINT} </select> + <select id="selectByLevel" parameterType="java.lang.Byte" resultMap="BaseResultMap"> + <!--@mbg.generated--> + select + <include refid="Base_Column_List" /> + from ba_district + where level = #{level,jdbcType=TINYINT} + </select> + <select id="selectBySupperId" parameterType="java.lang.Long" resultMap="BaseResultMap"> + <!--@mbg.generated--> + select + <include refid="Base_Column_List" /> + from ba_district + where supperId = #{supperId,jdbcType=BIGINT} + </select> <delete id="deleteByPrimaryKey" parameterType="java.lang.Long"> <!--@mbg.generated--> delete from ba_district @@ -27,10 +41,8 @@ </delete> <insert id="insert" parameterType="com.dy.pipIrrGlobal.pojoBa.BaDistrict"> <!--@mbg.generated--> - insert into ba_district (id, `name`, `level` - ) - values (#{id,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, #{level,jdbcType=TINYINT} - ) + insert into ba_district (id, supperId, `name`, `level`) + values (#{id,jdbcType=BIGINT}, #{supperId,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, #{level,jdbcType=TINYINT}) </insert> <insert id="insertSelective" parameterType="com.dy.pipIrrGlobal.pojoBa.BaDistrict"> <!--@mbg.generated--> @@ -38,6 +50,9 @@ <trim prefix="(" suffix=")" suffixOverrides=","> <if test="id != null"> id, + </if> + <if test="supperId != null"> + supperId, </if> <if test="name != null"> `name`, @@ -49,6 +64,9 @@ <trim prefix="values (" suffix=")" suffixOverrides=","> <if test="id != null"> #{id,jdbcType=BIGINT}, + </if> + <if test="supperId != null"> + #{supperId,jdbcType=BIGINT}, </if> <if test="name != null"> #{name,jdbcType=VARCHAR}, @@ -65,6 +83,9 @@ <if test="name != null"> `name` = #{name,jdbcType=VARCHAR}, </if> + <if test="supperId != null"> + supperId = #{supperId,jdbcType=BIGINT}, + </if> <if test="level != null"> `level` = #{level,jdbcType=TINYINT}, </if> @@ -74,8 +95,9 @@ <update id="updateByPrimaryKey" parameterType="com.dy.pipIrrGlobal.pojoBa.BaDistrict"> <!--@mbg.generated--> update ba_district - set `name` = #{name,jdbcType=VARCHAR}, - `level` = #{level,jdbcType=TINYINT} + set supperId = #{supperId,jdbcType=BIGINT}, + `name` = #{name,jdbcType=VARCHAR}, + `level` = #{level,jdbcType=TINYINT} where id = #{id,jdbcType=BIGINT} </update> </mapper> \ No newline at end of file diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictCtrl.java index a274591..eeb3fb0 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictCtrl.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictCtrl.java @@ -60,6 +60,25 @@ return BaseResponseUtils.buildSuccess(list); } + /** + * 瀹㈡埛绔姹傚緱鍒版墍鏈夎鏀垮尯鏁版嵁 + * @return 鎵�鏈夎鏀垮尯鏁版嵁 + */ + @Operation(summary = "鑾峰緱鎵�鏈夎鏀垮尯", description = "杩斿洖鎵�鏈夎鏀垮尯鏁版嵁") + @ApiResponses(value = { + @ApiResponse( + responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + description = "杩斿洖鎵�鏈夎鏀垮尯鏁版嵁锛圔aseResponse鏄熀绫伙級", + content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, + schema = @Schema(implementation = BaDistrict.class))} + ) + }) + @GetMapping(path = "allDistricts") + public BaseResponse<List<BaDistrict>> allDistricts(){ + List<BaDistrict> list = this.sv.getAll(DistrictLevel.City.code) ; + return BaseResponseUtils.buildSuccess(list); + } + /** * 淇濆瓨琛屾斂鍖� @@ -90,7 +109,7 @@ return BaseResponseUtils.buildException(e.getMessage()) ; } if(count <= 0){ - return BaseResponseUtils.buildSuccess(true) ; + return BaseResponseUtils.buildFail("鏁版嵁搴撳瓨鍌ㄥけ璐�") ; }else{ return BaseResponseUtils.buildSuccess(true) ; } diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictSv.java index 9faba57..27c5a85 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictSv.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictSv.java @@ -6,6 +6,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.List; + @Slf4j @Service public class DistrictSv { @@ -21,4 +23,34 @@ public int save(BaDistrict po){ return this.baDistrictMapper.insert(po) ; } + + /** + * 浠庣涓�绾ц鏀垮尯鍒掑紑濮嬶紝寰楀埌鎵�鏈夎鏀垮尯鍒掍俊鎭� + * @param firstLevel 绗竴绾ц涓嬪尯 level + * @return 鎵�鏈夎鏀垮尯鍒掗泦鍚� + */ + public List<BaDistrict> getAll(byte firstLevel){ + List<BaDistrict> list = this.baDistrictMapper.selectByLevel(firstLevel) ; + if(list != null && list.size() > 0){ + for(BaDistrict po : list){ + getSubDistrict(po) ; + } + } + return list ; + } + + /** + * 寰楀埌涓嬬骇琛屾斂鍖哄垝 + * @param po 涓婄骇琛屾斂鍖哄垝 + */ + private void getSubDistrict(BaDistrict po){ + if(po != null && po.id != null){ + po.subDistricts = this.baDistrictMapper.selectBySupperId(po.id) ; + if(po.subDistricts != null && po.subDistricts.size() > 0){ + for(BaDistrict subPo : po.subDistricts){ + getSubDistrict(subPo) ; + } + } + } + } } diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictVo.java b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictVo.java index 91d043c..06cdafa 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictVo.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictVo.java @@ -15,6 +15,9 @@ @Builder @Schema(name = "琛屾斂鍖哄垝鍊煎璞�") public class DistrictVo { + @Schema(description = "涓婄骇琛屾斂鍖篒D", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + public Long supperId ; + @Schema(description = "琛屾斂鍖哄悕绉�", requiredMode = Schema.RequiredMode.REQUIRED) @NotEmpty(message = "琛屾斂鍖哄悕绉颁笉鑳戒负绌�") //涓嶈兘涓虹┖涔熶笉鑳戒负null @Length(message = "琛屾斂鍖哄悕绉板皬浜巤max}瀛�", min = 1, max = 25) diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictVoMapper.java b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictVoMapper.java index 3b79344..90b5d8f 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictVoMapper.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictVoMapper.java @@ -15,6 +15,7 @@ * @return po */ @Mapping(target = "id", ignore = true) + @Mapping(target = "supperId", source = "supperId") @Mapping(target = "name", source = "name") @Mapping(target = "level", source = "level", qualifiedByName = "districtLevelByteToObj") BaDistrict convert(DistrictVo vo); -- Gitblit v1.8.0