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); } 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 上级行政区ID * @return 某一行政级别的下级行政区 */ List<BaDistrict> selectBySupperId(Long supperId) ; /** * update record selective * @param record the updated record * @return update count 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;//上级行政区ID public String name; public DistrictLevel level; @TableField(exist = false) public List<BaDistrict> subDistricts ; } 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> 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 = "返回所有行政区数据(BaseResponse是基类)", 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) ; } 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) ; } } } } } 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 = "上级行政区ID", requiredMode = Schema.RequiredMode.NOT_REQUIRED) public Long supperId ; @Schema(description = "行政区名称", requiredMode = Schema.RequiredMode.REQUIRED) @NotEmpty(message = "行政区名称不能为空") //不能为空也不能为null @Length(message = "行政区名称小于{max}字", min = 1, max = 25) 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);