zhubaomin
2024-08-30 264b5ede0e815999c589e411c597ea9fc010f3df
2024-08-30 朱宝民 根据区划代码获取指定级别的区划
5个文件已添加
2个文件已修改
301 ■■■■■ 已修改文件
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/AreaCode2023Mapper.java 38 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoBa/AreaCode2023.java 52 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voBa/VoDistrict.java 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-global/src/main/resources/mapper/AreaCode2023Mapper.xml 115 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictCtrl.java 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictSv.java 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/qo/DistrictQO.java 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/AreaCode2023Mapper.java
New file
@@ -0,0 +1,38 @@
package com.dy.pipIrrGlobal.daoBa;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dy.pipIrrGlobal.pojoBa.AreaCode2023;
import com.dy.pipIrrGlobal.voBa.VoDistrict;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
 * @author ZhuBaoMin
 * @date 2024-08-30 16:09
 * @LastEditTime 2024-08-30 16:09
 * @Description
 */
@Mapper
public interface AreaCode2023Mapper extends BaseMapper<AreaCode2023> {
    int deleteByPrimaryKey(Long code);
    int insert(AreaCode2023 record);
    int insertSelective(AreaCode2023 record);
    AreaCode2023 selectByPrimaryKey(Long code);
    int updateByPrimaryKeySelective(AreaCode2023 record);
    int updateByPrimaryKey(AreaCode2023 record);
    /**
     * 根据区划代码查询指定级别行政区划
     * @param aredCode
     * @param level
     * @return
     */
    List<VoDistrict> getDistrictS(@Param("aredCode") String aredCode, @Param("level") Integer level);
}
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoBa/AreaCode2023.java
New file
@@ -0,0 +1,52 @@
package com.dy.pipIrrGlobal.pojoBa;
import com.alibaba.fastjson2.annotation.JSONField;
import com.alibaba.fastjson2.writer.ObjectWriterImplToString;
import com.baomidou.mybatisplus.annotation.TableName;
import com.dy.common.po.BaseEntity;
import lombok.*;
/**
 * @author ZhuBaoMin
 * @date 2024-08-30 16:09
 * @LastEditTime 2024-08-30 16:09
 * @Description
 */
@TableName(value="area_code_2023", autoResultMap = true)
@Data
@Builder
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class AreaCode2023 implements BaseEntity {
    public static final long serialVersionUID = 202408301613001L;
    /**
    * 区划代码
    */
    @JSONField(serializeUsing= ObjectWriterImplToString.class)
    private Long code;
    /**
    * 名称
    */
    private String name;
    /**
    * 级别1-5,省市县镇村
    */
    private Boolean level;
    /**
    * 父级区划代码
    */
    @JSONField(serializeUsing= ObjectWriterImplToString.class)
    private Long pcode;
    /**
    * 城乡分类
    */
    private Integer category;
}
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voBa/VoDistrict.java
New file
@@ -0,0 +1,30 @@
package com.dy.pipIrrGlobal.voBa;
import lombok.Data;
/**
 * @author ZhuBaoMin
 * @date 2024-08-30 16:02
 * @LastEditTime 2024-08-30 16:02
 * @Description 区划视图对象
 */
@Data
public class VoDistrict {
    private static final long serialVersionUID = 202408301604001L;
    /**
     * 区划名称
     */
    private String name;
    /**
     * 区划代码
     */
    private String code;
    /**
     * 级别,1-5省市县镇村
     */
    private Integer level;
}
pipIrr-platform/pipIrr-global/src/main/resources/mapper/AreaCode2023Mapper.xml
New file
@@ -0,0 +1,115 @@
<?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.dy.pipIrrGlobal.daoBa.AreaCode2023Mapper">
  <resultMap id="BaseResultMap" type="com.dy.pipIrrGlobal.pojoBa.AreaCode2023">
    <!--@mbg.generated-->
    <!--@Table area_code_2023-->
    <id column="code" jdbcType="BIGINT" property="code" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="level" jdbcType="BOOLEAN" property="level" />
    <result column="pcode" jdbcType="BIGINT" property="pcode" />
    <result column="category" jdbcType="INTEGER" property="category" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    code, `name`, `level`, pcode, category
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    <!--@mbg.generated-->
    select
    <include refid="Base_Column_List" />
    from area_code_2023
    where code = #{code,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    <!--@mbg.generated-->
    delete from area_code_2023
    where code = #{code,jdbcType=BIGINT}
  </delete>
  <insert id="insert" parameterType="com.dy.pipIrrGlobal.pojoBa.AreaCode2023">
    <!--@mbg.generated-->
    insert into area_code_2023 (code, `name`, `level`,
      pcode, category)
    values (#{code,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, #{level,jdbcType=BOOLEAN},
      #{pcode,jdbcType=BIGINT}, #{category,jdbcType=INTEGER})
  </insert>
  <insert id="insertSelective" parameterType="com.dy.pipIrrGlobal.pojoBa.AreaCode2023">
    <!--@mbg.generated-->
    insert into area_code_2023
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="code != null">
        code,
      </if>
      <if test="name != null">
        `name`,
      </if>
      <if test="level != null">
        `level`,
      </if>
      <if test="pcode != null">
        pcode,
      </if>
      <if test="category != null">
        category,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="code != null">
        #{code,jdbcType=BIGINT},
      </if>
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="level != null">
        #{level,jdbcType=BOOLEAN},
      </if>
      <if test="pcode != null">
        #{pcode,jdbcType=BIGINT},
      </if>
      <if test="category != null">
        #{category,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.dy.pipIrrGlobal.pojoBa.AreaCode2023">
    <!--@mbg.generated-->
    update area_code_2023
    <set>
      <if test="name != null">
        `name` = #{name,jdbcType=VARCHAR},
      </if>
      <if test="level != null">
        `level` = #{level,jdbcType=BOOLEAN},
      </if>
      <if test="pcode != null">
        pcode = #{pcode,jdbcType=BIGINT},
      </if>
      <if test="category != null">
        category = #{category,jdbcType=INTEGER},
      </if>
    </set>
    where code = #{code,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.dy.pipIrrGlobal.pojoBa.AreaCode2023">
    <!--@mbg.generated-->
    update area_code_2023
    set `name` = #{name,jdbcType=VARCHAR},
      `level` = #{level,jdbcType=BOOLEAN},
      pcode = #{pcode,jdbcType=BIGINT},
      category = #{category,jdbcType=INTEGER}
    where code = #{code,jdbcType=BIGINT}
  </update>
  <!--根据区划代码查询指定级别行政区划-->
  <select id="getDistrictS" resultType="com.dy.pipIrrGlobal.voBa.VoDistrict">
    SELECT
        name,
        CASE
            WHEN level = 4 THEN SUBSTRING(code,7,3)
            WHEN level = 5 THEN SUBSTRING(code,10,3)
        END AS code,
        level
    FROM area_code_2023
    WHERE code LIKE CONCAT('%', #{aredCode}, '%') AND level = #{level}
  </select>
</mapper>
pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictCtrl.java
@@ -9,9 +9,11 @@
import com.dy.common.webUtil.BaseResponseUtils;
import com.dy.common.webUtil.QueryResultVo;
import com.dy.common.webUtil.ResultCodeMsg;
import com.dy.pipIrrBase.district.qo.DistrictQO;
import com.dy.pipIrrGlobal.pojoBa.BaClient;
import com.dy.pipIrrGlobal.pojoBa.BaDistrict;
import com.dy.pipIrrGlobal.util.DistrictLevel;
import com.dy.pipIrrGlobal.voBa.VoDistrict;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
@@ -324,4 +326,29 @@
        //return BaseResponseUtils.buildSuccess();
    }
    /**
     * 根据区划代码查询指定级别行政区划
     * @param qo
     * @return
     */
    @GetMapping(path = "/districts")
    @SsoAop()
    public BaseResponse<List<VoDistrict>> getDistrictS(DistrictQO qo) {
        String aredCode = qo.getAredCode();
        Integer level = qo.getLevel();
        if((aredCode.trim().length() == 6 && level == 4) || (aredCode.trim().length() == 9 && level == 5)) {
            try {
                return BaseResponseUtils.buildSuccess(sv.getDistrictS(qo));
            } catch (Exception e) {
                log.error("获取开卡记录异常", e);
                return BaseResponseUtils.buildException(e.getMessage());
            }
        }else {
            return BaseResponseUtils.buildErrorMsg("行政区划位数与级别不匹配");
        }
    }
}
pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictSv.java
@@ -1,8 +1,11 @@
package com.dy.pipIrrBase.district;
import com.dy.pipIrrBase.district.qo.DistrictQO;
import com.dy.pipIrrGlobal.daoBa.AreaCode2023Mapper;
import com.dy.pipIrrGlobal.daoBa.BaDistrictMapper;
import com.dy.pipIrrGlobal.pojoBa.BaDistrict;
import com.dy.pipIrrGlobal.util.DistrictLevel;
import com.dy.pipIrrGlobal.voBa.VoDistrict;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -16,10 +19,16 @@
public class DistrictSv {
    private BaDistrictMapper dao;
    private AreaCode2023Mapper areaCode2023Dao;
    @Autowired
    private void setDao(BaDistrictMapper dao){
        this.dao = dao;
    }
    @Autowired
    private void setDao(AreaCode2023Mapper areaCode2023Dao){
        this.areaCode2023Dao = areaCode2023Dao;
    }
    /**
@@ -117,4 +126,13 @@
    public List<Map<String, Object>> getDistrictsBySupperId(Long supperId) {
        return dao.getDistrictsBySupperId(supperId);
    }
    /**
     * 根据区划代码查询指定级别行政区划
     * @param qo
     * @return
     */
    public List<VoDistrict> getDistrictS(DistrictQO qo) {
        return areaCode2023Dao.getDistrictS(qo.getAredCode(), qo.getLevel());
    }
}
pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/qo/DistrictQO.java
New file
@@ -0,0 +1,21 @@
package com.dy.pipIrrBase.district.qo;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
 * @author ZhuBaoMin
 * @date 2024-08-30 16:28
 * @LastEditTime 2024-08-30 16:28
 * @Description
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class DistrictQO {
    private String aredCode;
    private Integer level;
}