获取MDM省市数据
This commit is contained in:
@@ -229,4 +229,18 @@ public class RedisConstant {
|
||||
|
||||
public static final String PHONE_NUMBER= "phone_number_";
|
||||
|
||||
/**
|
||||
* MDM 省市区数据缓存
|
||||
*/
|
||||
|
||||
/**
|
||||
* 省级数据缓存
|
||||
*/
|
||||
public static final String MDM_AREA_PROVINCE = "mdm:area:province";
|
||||
|
||||
/**
|
||||
* 其他区域数据缓存
|
||||
*/
|
||||
public static final String MDM_AREA_OTHERS = "mdm:area:others";
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.cool.store.mapper;
|
||||
|
||||
import com.cool.store.entity.MDMAreaDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface MdmAreaMapper {
|
||||
|
||||
/**
|
||||
* 获取 MDM 省级地区数据
|
||||
* @return
|
||||
*/
|
||||
List<MDMAreaDO> getProvince();
|
||||
|
||||
List<MDMAreaDO> getSonArea(@Param("code") String code);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?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.cool.store.mapper.MdmAreaMapper">
|
||||
|
||||
<!-- 获取 MDM 省级地区数据 -->
|
||||
<select id="getProvince" resultType="com.cool.store.entity.MDMAreaDO">
|
||||
SELECT id, instance_id, code, area_name, parent_code
|
||||
FROM mdm_area
|
||||
WHERE parent_code = '0'
|
||||
</select>
|
||||
|
||||
<!-- 获取子级区域 -->
|
||||
<select id="getSonArea" resultType="com.cool.store.entity.MDMAreaDO">
|
||||
SELECT id, instance_id, code, area_name, parent_code
|
||||
FROM mdm_area
|
||||
WHERE parent_code = #{code}
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.cool.store.dto.mdm;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class AreaSonDTO {
|
||||
|
||||
@ApiModelProperty("父级code")
|
||||
private String code;
|
||||
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ApprovalRegionDO {
|
||||
public class MDMAreaDO {
|
||||
|
||||
@ApiModelProperty("id")
|
||||
private Integer id;
|
||||
@@ -16,7 +16,7 @@ public class ApprovalRegionDO {
|
||||
private String code;
|
||||
|
||||
@ApiModelProperty("地区名")
|
||||
private String regionName;
|
||||
private String areaName;
|
||||
|
||||
@ApiModelProperty("地区父级编号")
|
||||
private String parentCode;
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.cool.store.service;
|
||||
|
||||
import com.cool.store.entity.MDMAreaDO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface MDMAreaService {
|
||||
|
||||
/**
|
||||
* 获取省级数据
|
||||
*/
|
||||
List<MDMAreaDO> getProvince();
|
||||
|
||||
/**
|
||||
* 获取子级地区
|
||||
* @param code 父级 code
|
||||
*/
|
||||
List<MDMAreaDO> getSonArea(String code);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.cool.store.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.cool.store.constants.RedisConstant;
|
||||
import com.cool.store.entity.MDMAreaDO;
|
||||
import com.cool.store.mapper.MdmAreaMapper;
|
||||
import com.cool.store.service.MDMAreaService;
|
||||
import com.cool.store.utils.RedisUtilPool;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class MDMAreaServiceImpl implements MDMAreaService {
|
||||
|
||||
@Autowired
|
||||
private RedisUtilPool redisUtilPool;
|
||||
|
||||
@Autowired
|
||||
private MdmAreaMapper mdmAreaMapper;
|
||||
|
||||
/**
|
||||
* 获取省级数据
|
||||
*/
|
||||
@Override
|
||||
public List<MDMAreaDO> getProvince() {
|
||||
String provincesJson = redisUtilPool.getString(RedisConstant.MDM_AREA_PROVINCE);
|
||||
if (StringUtils.isNotEmpty(provincesJson)) {
|
||||
return (List<MDMAreaDO>) JSONObject.parseObject(provincesJson, List.class);
|
||||
}
|
||||
List<MDMAreaDO> areaDOList = mdmAreaMapper.getProvince();
|
||||
//过期时间三小时
|
||||
redisUtilPool.setString(RedisConstant.MDM_AREA_PROVINCE, JSONObject.toJSONString(areaDOList), 3 * 60 * 60);
|
||||
return areaDOList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取子级地区
|
||||
* @param code 父级 code
|
||||
*/
|
||||
@Override
|
||||
public List<MDMAreaDO> getSonArea(String code) {
|
||||
String provincesJson = redisUtilPool.getString(RedisConstant.MDM_AREA_OTHERS);
|
||||
if (StringUtils.isNotEmpty(provincesJson)) {
|
||||
return (List<MDMAreaDO>) JSONObject.parseObject(provincesJson, List.class);
|
||||
}
|
||||
List<MDMAreaDO> areaDOList = mdmAreaMapper.getSonArea(code);
|
||||
//过期时间三小时
|
||||
redisUtilPool.setString(RedisConstant.MDM_AREA_PROVINCE, JSONObject.toJSONString(areaDOList), 3 * 60 * 60);
|
||||
return areaDOList;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.cool.store.controller;
|
||||
|
||||
import com.cool.store.dto.mdm.AreaSonDTO;
|
||||
import com.cool.store.entity.MDMAreaDO;
|
||||
import com.cool.store.response.ResponseResult;
|
||||
import com.cool.store.service.MDMAreaService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/mdm/area")
|
||||
@Api(tags = "MDM省市信息")
|
||||
public class MDMAreaController {
|
||||
|
||||
@Autowired
|
||||
private MDMAreaService mdmAreaService;
|
||||
|
||||
@PostMapping("/province")
|
||||
@ApiOperation("获取MDM省级信息")
|
||||
public ResponseResult<List<MDMAreaDO>> getProvince() {
|
||||
return ResponseResult.success(mdmAreaService.getProvince());
|
||||
}
|
||||
|
||||
@PostMapping("/son")
|
||||
@ApiOperation("获取子级区域数据")
|
||||
private ResponseResult<List<MDMAreaDO>> getSonArea(@RequestBody AreaSonDTO areaSon) {
|
||||
return ResponseResult.success(mdmAreaService.getSonArea(areaSon.getCode()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user