소스 검색

地址字典

小么熊🐻 2 년 전
부모
커밋
4c19e28b8e

+ 58 - 0
nbjk-admin/src/main/java/com/miaxis/app/controller/dict/DictCityController.java

@@ -0,0 +1,58 @@
+package com.miaxis.app.controller.dict;
+
+import com.miaxis.common.constant.Constants;
+import com.miaxis.common.core.controller.BaseController;
+import com.miaxis.common.core.domain.Response;
+import com.miaxis.common.core.page.ResponsePageInfo;
+import com.miaxis.dict.domain.DictCity;
+import com.miaxis.dict.service.IDictCityService;
+import io.swagger.annotations.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+/**
+ * 【全国城市】Controller
+ *
+ * @author miaxis
+ * @date 2023-03-23
+ */
+@RestController
+@RequestMapping(Constants.STUDENT_PREFIX+"/dict/city")
+@Api(tags={"【APP-全国城市】"})
+public class DictCityController extends BaseController{
+    @Autowired
+    private IDictCityService dictCityService;
+
+    /**
+     * 查询全国城市列表
+     */
+    @GetMapping("/list")
+    @ApiOperation("查询全国城市列表")
+        @ApiImplicitParams({
+            @ApiImplicitParam(name = "pageNum",value = "当前页码" ,dataType = "int", paramType = "query", required = false),
+            @ApiImplicitParam(name = "pageSize",value = "每页数据量" , dataType = "int", paramType = "query", required = false),
+    })
+    public ResponsePageInfo<DictCity> list(@ModelAttribute DictCity dictCity){
+        startPage();
+        List<DictCity> list = dictCityService.selectDictCityList(dictCity);
+        return toResponsePageInfo(list);
+    }
+    
+
+
+    /**
+     * 获取全国城市详细信息
+     */
+    @GetMapping(value = "/{code}")
+    @ApiOperation("获取全国城市详细信息")
+    public Response<DictCity> getDictCityByCode(
+            @ApiParam(name = "code", value = "全国城市参数", required = true)
+            @PathVariable("code") String code
+    ){
+        return Response.success(dictCityService.getDictCityByCode(code));
+    }
+
+
+}

+ 47 - 15
nbjk-admin/src/main/java/com/miaxis/app/controller/exam/ExamInfoController.java

@@ -9,6 +9,8 @@ import com.miaxis.common.core.domain.Response;
 import com.miaxis.common.core.page.ResponsePageInfo;
 import com.miaxis.common.utils.ServletUtils;
 import com.miaxis.common.utils.ip.IpUtils;
+import com.miaxis.dict.domain.DictCity;
+import com.miaxis.dict.service.IDictCityService;
 import com.miaxis.exam.domain.ExamInfo;
 import com.miaxis.exam.service.IExamInfoService;
 import com.miaxis.exam.vo.ExamInfoCityVo;
@@ -35,24 +37,28 @@ import java.util.Map;
  * @date 2023-03-20
  */
 @RestController
-@RequestMapping(Constants.STUDENT_PREFIX+"/exam/info")
-@Api(tags={"【APP-考场信息】"})
-public class ExamInfoController extends BaseController{
+@RequestMapping(Constants.STUDENT_PREFIX + "/exam/info")
+@Api(tags = {"【APP-考场信息】"})
+public class ExamInfoController extends BaseController {
     @Autowired
     private IExamInfoService examInfoService;
 
+    @Autowired
+    private IDictCityService dictCityService;
+
     @Value("${geo.path}")
     private String dbPath;
+
     /**
      * 查询考场信息列表
      */
     @GetMapping("/list")
     @ApiOperation("查询考场信息列表")
-        @ApiImplicitParams({
-            @ApiImplicitParam(name = "pageNum",value = "当前页码" ,dataType = "int", paramType = "query", required = false),
-            @ApiImplicitParam(name = "pageSize",value = "每页数据量" , dataType = "int", paramType = "query", required = false),
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "pageNum", value = "当前页码", dataType = "int", paramType = "query", required = false),
+            @ApiImplicitParam(name = "pageSize", value = "每页数据量", dataType = "int", paramType = "query", required = false),
     })
-    public ResponsePageInfo<ExamInfo> list(@ModelAttribute ExamInfo examInfo){
+    public ResponsePageInfo<ExamInfo> list(@ModelAttribute ExamInfo examInfo) {
         startPage();
         List<ExamInfo> list = examInfoService.selectExamInfoList(examInfo);
         return toResponsePageInfo(list);
@@ -66,7 +72,7 @@ public class ExamInfoController extends BaseController{
     public Response<ExamInfo> getInfo(
             @ApiParam(name = "id", value = "考场信息参数", required = true)
             @PathVariable("id") Long id
-    ){
+    ) {
         return Response.success(examInfoService.getById(id));
     }
 
@@ -76,7 +82,7 @@ public class ExamInfoController extends BaseController{
      */
     @GetMapping("/getProvice")
     @ApiOperation("获取考场省份")
-    public Response<List<ExamInfoProviceVo>> getProvice(){
+    public Response<List<ExamInfoProviceVo>> getProvice() {
         List<ExamInfoProviceVo> list = examInfoService.getProvice();
         return Response.success(list);
     }
@@ -90,18 +96,18 @@ public class ExamInfoController extends BaseController{
     public Response<List<ExamInfoCityVo>> getCity(
             @ApiParam(name = "proviceId", value = "考场信息参数", required = true)
             @PathVariable("proviceId") String proviceId
-    ){
+    ) {
         return Response.success(examInfoService.getCity(proviceId));
     }
 
     @GetMapping(value = "/ip")
     @ApiOperation("获取访问IP")
-    public Response<Map<String,Object>> exampleMethod() throws IOException, GeoIp2Exception {
+    public Response<Map<String, Object>> exampleMethod() throws IOException, GeoIp2Exception {
 
         String ipAddr = IpUtils.getIpAddr(ServletUtils.getRequest());
         System.out.println(ipAddr);
 
-       // File database = new ClassPathResource("geolite/GeoLite2-City.mmdb").getFile();
+        // File database = new ClassPathResource("geolite/GeoLite2-City.mmdb").getFile();
         File database = new File(dbPath);
 
         // 初始化 GeoIP 数据库
@@ -114,9 +120,35 @@ public class ExamInfoController extends BaseController{
         System.out.println(response.getCountry().getNames().get("zh-CN"));
         System.out.println(response.getMostSpecificSubdivision().getNames().get("zh-CN"));
         System.out.println(response.getCity().getNames().get("zh-CN"));
-        Map<String,Object> resultMap = new HashMap<String,Object>();
-        resultMap.put("provice",response.getMostSpecificSubdivision().getNames().get("zh-CN"));
-        resultMap.put("city",response.getCity().getNames().get("zh-CN"));
+
+        String countryName = response.getCountry().getNames().get("zh-CN");
+        String proviceName = response.getMostSpecificSubdivision().getNames().get("zh-CN");
+        String cityName = response.getMostSpecificSubdivision().getNames().get("zh-CN");
+
+        DictCity provice = null;
+        DictCity city = null;
+        if (proviceName != null) {
+            provice = dictCityService.getDictCityByName(proviceName);
+        }
+        if (cityName != null) {
+            city = dictCityService.getDictCityByName(cityName);
+        }
+
+        Map<String, Object> resultMap = new HashMap<String, Object>();
+        if (provice != null) {
+            resultMap.put("provice", provice.getCode());
+            resultMap.put("proviceName", provice.getName());
+        } else {
+            resultMap.put("provice", null);
+            resultMap.put("proviceName", null);
+        }
+        if (city != null) {
+            resultMap.put("city", city.getCode());
+            resultMap.put("cityName", city.getName());
+        } else {
+            resultMap.put("city", null);
+            resultMap.put("cityName", null);
+        }
         return Response.success(resultMap);
     }
 

+ 62 - 0
nbjk-admin/src/main/java/com/miaxis/pc/controller/PcDictCityController.java

@@ -0,0 +1,62 @@
+package com.miaxis.pc.controller;
+
+import com.miaxis.common.annotation.Log;
+import com.miaxis.common.core.controller.BaseController;
+import com.miaxis.common.core.domain.Response;
+import com.miaxis.common.core.page.ResponsePageInfo;
+import com.miaxis.common.enums.BusinessTypeEnum;
+import com.miaxis.common.utils.poi.ExcelUtil;
+import com.miaxis.dict.domain.DictCity;
+import com.miaxis.dict.service.IDictCityService;
+import io.swagger.annotations.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * 【全国城市】Controller
+ *
+ * @author miaxis
+ * @date 2023-03-23
+ */
+@RestController
+@RequestMapping("/dict/city")
+@Api(tags={"【PC-全国城市】"})
+public class PcDictCityController extends BaseController{
+    @Autowired
+    private IDictCityService dictCityService;
+
+    /**
+     * 查询全国城市列表
+     */
+    @GetMapping("/list")
+    @ApiOperation("查询全国城市列表")
+        @ApiImplicitParams({
+            @ApiImplicitParam(name = "pageNum",value = "当前页码" ,dataType = "int", paramType = "query", required = false),
+            @ApiImplicitParam(name = "pageSize",value = "每页数据量" , dataType = "int", paramType = "query", required = false),
+    })
+    public ResponsePageInfo<DictCity> list(@ModelAttribute DictCity dictCity){
+        startPage();
+        List<DictCity> list = dictCityService.selectDictCityList(dictCity);
+        return toResponsePageInfo(list);
+    }
+    
+
+
+    /**
+     * 获取全国城市详细信息
+     */
+    @GetMapping(value = "/{id}")
+    @ApiOperation("获取全国城市详细信息")
+    public Response<DictCity> getInfo(
+            @ApiParam(name = "id", value = "全国城市参数", required = true)
+            @PathVariable("id") Long id
+    ){
+        return Response.success(dictCityService.getById(id));
+    }
+
+
+}

+ 130 - 0
nbjk-service/src/main/java/com/miaxis/dict/domain/DictCity.java

@@ -0,0 +1,130 @@
+package com.miaxis.dict.domain;
+
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+import com.miaxis.common.annotation.Excel;
+import com.miaxis.common.core.domain.BaseEntity;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.miaxis.common.core.domain.BaseBusinessEntity;
+import lombok.Data;
+/**
+ * 全国城市对象 dict_city
+ *
+ * @author miaxis
+ * @date 2023-03-23
+ */
+@Data
+@TableName("dict_city")
+@ApiModel(value = "DictCity", description = "全国城市对象 dict_city")
+public class DictCity extends BaseBusinessEntity{
+    private static final long serialVersionUID = 1L;
+
+    /** 主键 */
+    @TableId(value = "id")
+    @ApiModelProperty(value = "主键")
+    private Long id;
+
+    /** 编码 */
+    @Excel(name = "编码")
+    @TableField("code")
+    @ApiModelProperty(value = "编码")
+    private String code;
+
+    /** 上级编码 */
+    @Excel(name = "上级编码")
+    @TableField("parentCode")
+    @ApiModelProperty(value = "上级编码")
+    private String parentcode;
+
+    /** 名称 */
+    @Excel(name = "名称")
+    @TableField("name")
+    @ApiModelProperty(value = "名称")
+    private String name;
+
+    /** 等级1省 2市 3区 4街道 */
+    @Excel(name = "等级1省 2市 3区 4街道")
+    @TableField("level")
+    @ApiModelProperty(value = "等级1省 2市 3区 4街道")
+    private Integer level;
+
+    /** 是否末级 1是 0否 */
+    @Excel(name = "是否末级 1是 0否")
+    @TableField("last")
+    @ApiModelProperty(value = "是否末级 1是 0否")
+    private Integer last;
+
+    /** 状态 1正常 2禁用 */
+    @Excel(name = "状态 1正常 2禁用")
+    @TableField("status")
+    @ApiModelProperty(value = "状态 1正常 2禁用")
+    private Long status;
+
+    public void setId(Long id){
+        this.id = id;
+    }
+
+    public Long getId(){
+        return id;
+    }
+    public void setCode(String code){
+        this.code = code;
+    }
+
+    public String getCode(){
+        return code;
+    }
+    public void setParentcode(String parentcode){
+        this.parentcode = parentcode;
+    }
+
+    public String getParentcode(){
+        return parentcode;
+    }
+    public void setName(String name){
+        this.name = name;
+    }
+
+    public String getName(){
+        return name;
+    }
+    public void setLevel(Integer level){
+        this.level = level;
+    }
+
+    public Integer getLevel(){
+        return level;
+    }
+    public void setLast(Integer last){
+        this.last = last;
+    }
+
+    public Integer getLast(){
+        return last;
+    }
+    public void setStatus(Long status){
+        this.status = status;
+    }
+
+    public Long getStatus(){
+        return status;
+    }
+
+    @Override
+    public String toString() {
+        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
+            .append("id", getId())
+            .append("code", getCode())
+            .append("parentcode", getParentcode())
+            .append("name", getName())
+            .append("level", getLevel())
+            .append("last", getLast())
+            .append("status", getStatus())
+            .toString();
+    }
+}

+ 26 - 0
nbjk-service/src/main/java/com/miaxis/dict/mapper/DictCityMapper.java

@@ -0,0 +1,26 @@
+package com.miaxis.dict.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.miaxis.dict.domain.DictCity;
+
+import java.util.List;
+
+/**
+ * 全国城市Mapper接口
+ *
+ * @author miaxis
+ * @date 2023-03-23
+ */
+public interface DictCityMapper extends BaseMapper<DictCity> {
+    /**
+     * 查询全国城市列表
+     *
+     * @param dictCity 全国城市
+     * @return 全国城市集合
+     */
+    List<DictCity> selectDictCityList(DictCity dictCity);
+
+    DictCity getDictCityByCode(String code);
+
+    DictCity getDictCityByName(String name);
+}

+ 44 - 0
nbjk-service/src/main/java/com/miaxis/dict/service/IDictCityService.java

@@ -0,0 +1,44 @@
+package com.miaxis.dict.service;
+
+import java.util.List;
+
+import com.miaxis.common.core.domain.Response;
+import com.miaxis.dict.domain.DictCity;
+import com.baomidou.mybatisplus.extension.service.IService;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+
+/**
+ * 全国城市Service接口
+ *
+ * @author miaxis
+ * @date 2023-03-23
+ */
+public interface IDictCityService extends IService<DictCity>{
+    /**
+     * 查询全国城市列表
+     *
+     * @param dictCity 全国城市
+     * @return 全国城市集合
+     */
+    public List<DictCity> selectDictCityList(DictCity dictCity);
+
+
+    /**
+     * 根据地区编号获取全国城市详细信息
+     * @param code 地编编号
+     * @return 城市
+     */
+    public DictCity getDictCityByCode(String code);
+
+
+    /**
+     * 根据获取名称全国城市详细信息
+     * @param name 地区名称
+     * @return 城市
+     */
+    public DictCity getDictCityByName(String name);
+
+}

+ 47 - 0
nbjk-service/src/main/java/com/miaxis/dict/service/impl/DictCityServiceImpl.java

@@ -0,0 +1,47 @@
+package com.miaxis.dict.service.impl;
+
+import java.util.List;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.miaxis.common.core.domain.Response;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.apache.commons.lang3.StringUtils;
+import com.miaxis.dict.mapper.DictCityMapper;
+import com.miaxis.dict.domain.DictCity;
+import com.miaxis.dict.service.IDictCityService;
+
+/**
+ * 全国城市Service业务层处理
+ *
+ * @author miaxis
+ * @date 2023-03-23
+ */
+@Service
+public class DictCityServiceImpl extends ServiceImpl<DictCityMapper, DictCity> implements IDictCityService {
+    @Autowired
+    private DictCityMapper dictCityMapper;
+
+    /**
+     * 查询全国城市列表
+     *
+     * @param dictCity 全国城市
+     * @return 全国城市
+     */
+    @Override
+    public List<DictCity> selectDictCityList(DictCity dictCity){
+        return dictCityMapper.selectDictCityList(dictCity);
+    }
+
+
+    @Override
+    public DictCity getDictCityByCode(String code) {
+        return dictCityMapper.getDictCityByCode(code);
+    }
+
+    @Override
+    public DictCity getDictCityByName(String name) {
+        return dictCityMapper.getDictCityByName(name);
+    }
+}

+ 41 - 0
nbjk-service/src/main/resources/mapper/dict/DictCityMapper.xml

@@ -0,0 +1,41 @@
+<?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.miaxis.dict.mapper.DictCityMapper">
+
+    <resultMap type="DictCity" id="DictCityResult">
+        <result property="id"    column="id"    />
+        <result property="code"    column="code"    />
+        <result property="parentcode"    column="parentCode"    />
+        <result property="name"    column="name"    />
+        <result property="level"    column="level"    />
+        <result property="last"    column="last"    />
+        <result property="status"    column="status"    />
+    </resultMap>
+
+    <sql id="selectDictCityVo">
+        select * from dict_city
+    </sql>
+
+    <select id="selectDictCityList" parameterType="DictCity" resultMap="DictCityResult">
+        <include refid="selectDictCityVo"/>
+        <where>
+            <if test="code != null  and code != ''"> and code = #{code}</if>
+            <if test="parentcode != null  and parentcode != ''"> and parentCode = #{parentcode}</if>
+            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
+            <if test="level != null "> and level = #{level}</if>
+            <if test="last != null "> and last = #{last}</if>
+            <if test="status != null "> and status = #{status}</if>
+        </where>
+    </select>
+    <select id="getDictCityByCode" resultType="com.miaxis.dict.domain.DictCity">
+        select * from dict_city where code = #{code}
+    </select>
+
+
+    <select id="getDictCityByName" resultType="com.miaxis.dict.domain.DictCity">
+        select * from dict_city where name = #{name}
+    </select>
+
+</mapper>