forked from angelo/java-retail-app
## 行政区划更新(高德API)
This commit is contained in:
parent
e58078bc75
commit
745f68e64c
|
@ -1,5 +1,6 @@
|
||||||
package com.hzs.system.base;
|
package com.hzs.system.base;
|
||||||
|
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
import com.hzs.common.core.domain.R;
|
import com.hzs.common.core.domain.R;
|
||||||
import com.hzs.common.domain.system.base.BdArea;
|
import com.hzs.common.domain.system.base.BdArea;
|
||||||
import com.hzs.common.domain.system.base.ext.BdProductStorehouseExt;
|
import com.hzs.common.domain.system.base.ext.BdProductStorehouseExt;
|
||||||
|
@ -51,4 +52,5 @@ public interface IAreaServiceApi {
|
||||||
R<List<BdProductStorehouseExt>> queryBdProductStorehouseByCondition(List<Integer> productId, Integer province);
|
R<List<BdProductStorehouseExt>> queryBdProductStorehouseByCondition(List<Integer> productId, Integer province);
|
||||||
|
|
||||||
|
|
||||||
|
R<?> upAreaDate(JSONObject result);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
package com.hzs.system.base;
|
|
||||||
|
|
||||||
import cn.hutool.json.JSONObject;
|
|
||||||
import com.hzs.common.core.domain.R;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 服务类
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author hzs
|
|
||||||
* @since 2025-10-10
|
|
||||||
*/
|
|
||||||
public interface IBdAreaNewServiceApi {
|
|
||||||
|
|
||||||
R<?> upAreaDate(JSONObject result);
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
package com.hzs.system.base.mapper;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
||||||
import com.hzs.common.domain.system.base.BdAreaNew;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* Mapper 接口
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author hzs
|
|
||||||
* @since 2025-10-10
|
|
||||||
*/
|
|
||||||
public interface BdAreaNewMapper extends BaseMapper<BdAreaNew> {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,22 +1,35 @@
|
||||||
package com.hzs.system.base.provider;
|
package com.hzs.system.base.provider;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
|
import cn.hutool.json.JSONArray;
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import com.hzs.common.core.constant.CacheConstants;
|
||||||
|
import com.hzs.common.core.constant.CountryConstants;
|
||||||
|
import com.hzs.common.core.constant.MagicNumberConstants;
|
||||||
import com.hzs.common.core.domain.R;
|
import com.hzs.common.core.domain.R;
|
||||||
|
import com.hzs.common.core.enums.EMapStatus;
|
||||||
|
import com.hzs.common.core.enums.EYesNo;
|
||||||
|
import com.hzs.common.core.service.RedisService;
|
||||||
|
import com.hzs.common.domain.system.base.BdArea;
|
||||||
import com.hzs.common.domain.system.base.BdArea;
|
import com.hzs.common.domain.system.base.BdArea;
|
||||||
import com.hzs.common.domain.system.base.ext.AreaCache;
|
import com.hzs.common.domain.system.base.ext.AreaCache;
|
||||||
import com.hzs.common.domain.system.base.ext.BdProductStorehouseExt;
|
import com.hzs.common.domain.system.base.ext.BdProductStorehouseExt;
|
||||||
import com.hzs.system.base.IAreaServiceApi;
|
import com.hzs.system.base.IAreaServiceApi;
|
||||||
import com.hzs.system.base.dto.AreaDTO;
|
import com.hzs.system.base.dto.AreaDTO;
|
||||||
import com.hzs.system.base.service.IBdAreaService;
|
import com.hzs.system.base.service.IBdAreaService;
|
||||||
|
import com.hzs.system.base.service.IBdAreaService;
|
||||||
import com.hzs.system.base.service.IBdProductStorehouseService;
|
import com.hzs.system.base.service.IBdProductStorehouseService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.dubbo.config.annotation.DubboService;
|
import org.apache.dubbo.config.annotation.DubboService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.List;
|
import java.util.stream.Collectors;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 行政区划dubbo服务
|
* 行政区划dubbo服务
|
||||||
|
@ -31,6 +44,12 @@ public class AreaServiceProvider implements IAreaServiceApi {
|
||||||
@Autowired
|
@Autowired
|
||||||
private IBdProductStorehouseService iBdProductStorehouseService;
|
private IBdProductStorehouseService iBdProductStorehouseService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisService redisService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public R<Map<Integer, String>> getAreaMap(Integer pkCountry) {
|
public R<Map<Integer, String>> getAreaMap(Integer pkCountry) {
|
||||||
Map<Integer, String> resultMap = new HashMap<>();
|
Map<Integer, String> resultMap = new HashMap<>();
|
||||||
|
@ -79,4 +98,122 @@ public class AreaServiceProvider implements IAreaServiceApi {
|
||||||
return R.ok(iBdProductStorehouseService.queryBdProductStorehouseByCondition(productId, province));
|
return R.ok(iBdProductStorehouseService.queryBdProductStorehouseByCondition(productId, province));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public R<?> upAreaDate(JSONObject result) {
|
||||||
|
// 操作用户
|
||||||
|
Long userId = MagicNumberConstants.PK_ADMIN;
|
||||||
|
// 所属国家
|
||||||
|
Integer pkCountry = CountryConstants.CHINA_COUNTRY;
|
||||||
|
// 当前时间
|
||||||
|
Date nowDate = new Date();
|
||||||
|
Set<String> allCodesFromApi = new HashSet<>();
|
||||||
|
// 最外层,全国,直接过滤
|
||||||
|
JSONArray country = result.getJSONArray("districts");
|
||||||
|
// 省
|
||||||
|
JSONObject provinces = country.getJSONObject(0);
|
||||||
|
// 省列表
|
||||||
|
JSONArray provincesArray = provinces.getJSONArray("districts");
|
||||||
|
// 查询所有数据
|
||||||
|
List<BdArea> allDbAreas = iBdAreaService.list();
|
||||||
|
Map<String, BdArea> dbMap = allDbAreas.stream()
|
||||||
|
.collect(Collectors.toMap(BdArea::getCode, a -> a));
|
||||||
|
|
||||||
|
for (int i = 0; i < provincesArray.size(); i++) {
|
||||||
|
// 迭代处理数据
|
||||||
|
parseDistrict(provincesArray.getJSONObject(i), 0, allCodesFromApi, dbMap, userId, pkCountry, nowDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 对数据库中未出现的地区进行逻辑删除标记
|
||||||
|
for (BdArea bdArea : allDbAreas) {
|
||||||
|
if (!allCodesFromApi.contains(bdArea.getCode()) && bdArea.getEnableState() == 0) {
|
||||||
|
bdArea.setSyncStatus(EMapStatus.DELETE.getValue());
|
||||||
|
bdArea.setEnableState(1);
|
||||||
|
iBdAreaService.updateById(bdArea);
|
||||||
|
log.info("逻辑删除地区:{}", bdArea.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 更新缓存
|
||||||
|
String redisKey = CacheConstants.BD_AREA + pkCountry;
|
||||||
|
redisService.deleteObject(redisKey);
|
||||||
|
LambdaQueryWrapper<BdArea> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.eq(BdArea::getPkCountry, pkCountry);
|
||||||
|
queryWrapper.eq(BdArea::getEnableState, EYesNo.YES.getIntValue());
|
||||||
|
queryWrapper.orderByAsc(BdArea::getCode);
|
||||||
|
List<BdArea> areaNewList = iBdAreaService.selectList(queryWrapper);
|
||||||
|
if (!CollectionUtils.isEmpty(areaNewList)) {
|
||||||
|
List<AreaCache> areaCaches = BeanUtil.copyToList(areaNewList, AreaCache.class);
|
||||||
|
redisService.setCacheList(redisKey, areaCaches);
|
||||||
|
}
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void parseDistrict(JSONObject district, Integer parentId, Set<String> allCodesFromApi,
|
||||||
|
Map<String, BdArea> dbMap, Long userId, Integer pkCountry, Date nowDate) {
|
||||||
|
if ("street".equals(district.getStr("level")) || "990000".equals(district.getStr("code"))) {
|
||||||
|
// 第4级行政区划(街道)和990000这个地区不需要
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String name = district.getStr("name");
|
||||||
|
String code = district.getStr("adcode");
|
||||||
|
allCodesFromApi.add(code);
|
||||||
|
|
||||||
|
BdArea existing = dbMap.get(code);
|
||||||
|
|
||||||
|
if (existing == null) {
|
||||||
|
BdArea area = new BdArea();
|
||||||
|
Integer newId = getNextSeqId();
|
||||||
|
area.setPkId(newId);
|
||||||
|
area.setName(name);
|
||||||
|
area.setCode(code);
|
||||||
|
area.setParent(parentId == null ? 0 : parentId);
|
||||||
|
area.setEnableState(0);
|
||||||
|
area.setDelFlag(0);
|
||||||
|
area.setPkCountry(pkCountry);
|
||||||
|
area.setPkCreator(userId);
|
||||||
|
area.setCreationTime(nowDate);
|
||||||
|
area.setBindNum(1);
|
||||||
|
area.setSyncStatus(EMapStatus.NEW.getValue());
|
||||||
|
|
||||||
|
iBdAreaService.save(area);
|
||||||
|
dbMap.put(code, area);
|
||||||
|
existing = area;
|
||||||
|
log.info("新增地区:{} code={} pkId={}", name, code, newId);
|
||||||
|
} else {
|
||||||
|
boolean updated = false;
|
||||||
|
if (existing.getEnableState() == 1) {
|
||||||
|
existing.setEnableState(0);
|
||||||
|
updated = true;
|
||||||
|
}
|
||||||
|
if (!existing.getName().equals(name)) {
|
||||||
|
existing.setName(name);
|
||||||
|
updated = true;
|
||||||
|
}
|
||||||
|
if (!Objects.equals(existing.getParent(), parentId)) {
|
||||||
|
existing.setParent(parentId == null ? 0 : parentId);
|
||||||
|
updated = true;
|
||||||
|
existing.setSyncStatus(EMapStatus.MOVED.getValue());
|
||||||
|
}
|
||||||
|
if (updated) {
|
||||||
|
existing.setModifiedTime(new Date());
|
||||||
|
iBdAreaService.updateById(existing);
|
||||||
|
log.info("更新地区:{} code={}", name, code);
|
||||||
|
} else {
|
||||||
|
existing.setSyncStatus(EMapStatus.NORMAL.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Integer currentParentId = existing.getPkId();
|
||||||
|
JSONArray subList = district.getJSONArray("districts");
|
||||||
|
if (subList != null && !subList.isEmpty()) {
|
||||||
|
for (int i = 0; i < subList.size(); i++) {
|
||||||
|
parseDistrict(subList.getJSONObject(i), currentParentId, allCodesFromApi, dbMap, userId, pkCountry, nowDate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Integer getNextSeqId() {
|
||||||
|
return jdbcTemplate.queryForObject("SELECT BD_AREA_SEQ.NEXTVAL FROM dual", Integer.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,139 +0,0 @@
|
||||||
package com.hzs.system.base.provider;
|
|
||||||
|
|
||||||
import cn.hutool.json.JSONArray;
|
|
||||||
import cn.hutool.json.JSONObject;
|
|
||||||
import com.hzs.common.core.constant.CountryConstants;
|
|
||||||
import com.hzs.common.core.constant.MagicNumberConstants;
|
|
||||||
import com.hzs.common.core.domain.R;
|
|
||||||
import com.hzs.common.domain.system.base.BdAreaNew;
|
|
||||||
import com.hzs.system.base.IBdAreaNewServiceApi;
|
|
||||||
import com.hzs.system.base.service.IBdAreaNewService;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.dubbo.config.annotation.DubboService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 服务实现类
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author hzs
|
|
||||||
* @since 2025-10-10
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@DubboService
|
|
||||||
public class BdAreaNewServiceProvider implements IBdAreaNewServiceApi {
|
|
||||||
@Autowired
|
|
||||||
private IBdAreaNewService iBdAreaNewService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private JdbcTemplate jdbcTemplate;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public R<?> upAreaDate(JSONObject result) {
|
|
||||||
|
|
||||||
Set<String> allCodesFromApi = new HashSet<>();
|
|
||||||
// 最外层,全国,直接过滤
|
|
||||||
JSONArray country = result.getJSONArray("districts");
|
|
||||||
// 省
|
|
||||||
JSONObject provinces = country.getJSONObject(0);
|
|
||||||
// 省列表
|
|
||||||
JSONArray provincesArray = provinces.getJSONArray("districts");
|
|
||||||
// 查询所有数据
|
|
||||||
List<BdAreaNew> allDbAreas = iBdAreaNewService.list();
|
|
||||||
Map<String, BdAreaNew> dbMap = allDbAreas.stream()
|
|
||||||
.collect(Collectors.toMap(BdAreaNew::getCode, a -> a));
|
|
||||||
|
|
||||||
for (int i = 0; i < provincesArray.size(); i++) {
|
|
||||||
// 迭代处理数据
|
|
||||||
parseDistrict(provincesArray.getJSONObject(i), 0L, allCodesFromApi,dbMap);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 对数据库中未出现的地区进行逻辑删除标记
|
|
||||||
for (BdAreaNew bdAreaNew : allDbAreas) {
|
|
||||||
if (!allCodesFromApi.contains(bdAreaNew.getCode()) && bdAreaNew.getDelFlag() == 0) {
|
|
||||||
bdAreaNew.setSyncStatus("DELETED");
|
|
||||||
iBdAreaNewService.removeById(bdAreaNew);
|
|
||||||
iBdAreaNewService.updateById(bdAreaNew);
|
|
||||||
log.info("逻辑删除地区:{}", bdAreaNew.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return R.ok();
|
|
||||||
}
|
|
||||||
private void parseDistrict(JSONObject district, Long parentId, Set<String> allCodesFromApi,
|
|
||||||
Map<String, BdAreaNew> dbMap) {
|
|
||||||
if ("4".equals(district.getStr("level")) || "990000".equals(district.getStr("code"))) {
|
|
||||||
// 第4级行政区划(街道)和990000这个地区不需要
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 操作用户
|
|
||||||
Long userId = MagicNumberConstants.PK_ADMIN;
|
|
||||||
// 所属国家
|
|
||||||
Integer pkCountry = CountryConstants.CHINA_COUNTRY;
|
|
||||||
// 当前时间
|
|
||||||
Date nowDate = new Date();
|
|
||||||
String name = district.getStr("name");
|
|
||||||
String code = district.getStr("code");
|
|
||||||
allCodesFromApi.add(code);
|
|
||||||
|
|
||||||
BdAreaNew existing = dbMap.get(code);
|
|
||||||
|
|
||||||
if (existing == null) {
|
|
||||||
BdAreaNew area = new BdAreaNew();
|
|
||||||
Integer newId = getNextSeqId();
|
|
||||||
area.setPkId(newId);
|
|
||||||
area.setName(name);
|
|
||||||
area.setCode(code);
|
|
||||||
area.setParent(parentId == null ? 0L : parentId);
|
|
||||||
area.setEnableState(0);
|
|
||||||
area.setDelFlag(0);
|
|
||||||
area.setPkCountry(pkCountry);
|
|
||||||
area.setPkCreator(userId);
|
|
||||||
area.setCreationTime(nowDate);
|
|
||||||
area.setBindNum(1);
|
|
||||||
area.setSyncStatus("NEW");
|
|
||||||
|
|
||||||
iBdAreaNewService.save(area);
|
|
||||||
dbMap.put(code, area);
|
|
||||||
existing = area;
|
|
||||||
log.info("新增地区:{} code={} pkId={}", name, code, newId);
|
|
||||||
} else {
|
|
||||||
boolean updated = false;
|
|
||||||
if (!existing.getName().equals(name)) {
|
|
||||||
existing.setName(name);
|
|
||||||
updated = true;
|
|
||||||
}
|
|
||||||
if (!Objects.equals(existing.getParent(), parentId)) {
|
|
||||||
existing.setParent(parentId == null ? 0L : parentId);
|
|
||||||
updated = true;
|
|
||||||
existing.setSyncStatus("MOVED");
|
|
||||||
}
|
|
||||||
if (updated) {
|
|
||||||
existing.setModifiedTime(new Date());
|
|
||||||
iBdAreaNewService.updateById(existing);
|
|
||||||
log.info("更新地区:{} code={}", name, code);
|
|
||||||
} else {
|
|
||||||
existing.setSyncStatus("NORMAL");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Integer currentParentId = existing.getPkId();
|
|
||||||
JSONArray subList = district.getJSONArray("districts");
|
|
||||||
if (subList != null && !subList.isEmpty()) {
|
|
||||||
for (int i = 0; i < subList.size(); i++) {
|
|
||||||
parseDistrict(subList.getJSONObject(i), Long.valueOf(currentParentId), allCodesFromApi, dbMap);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private Integer getNextSeqId() {
|
|
||||||
return jdbcTemplate.queryForObject("SELECT BD_AREA_NEW_SEQ.NEXTVAL FROM dual", Integer.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
package com.hzs.system.base.service;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
|
||||||
import com.hzs.common.domain.system.base.BdAreaNew;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 服务类
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author hzs
|
|
||||||
* @since 2025-10-10
|
|
||||||
*/
|
|
||||||
public interface IBdAreaNewService extends IService<BdAreaNew> {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.hzs.system.base.service;
|
package com.hzs.system.base.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.hzs.common.domain.system.base.BdArea;
|
import com.hzs.common.domain.system.base.BdArea;
|
||||||
import com.hzs.common.domain.system.base.ext.AreaCache;
|
import com.hzs.common.domain.system.base.ext.AreaCache;
|
||||||
|
@ -29,4 +30,6 @@ public interface IBdAreaService extends IService<BdArea> {
|
||||||
String updateArea(List<AreaDTO> areaDTOList);
|
String updateArea(List<AreaDTO> areaDTOList);
|
||||||
|
|
||||||
List<BdArea> getAreaByParentId(Integer parentId);
|
List<BdArea> getAreaByParentId(Integer parentId);
|
||||||
|
|
||||||
|
List<BdArea> selectList(LambdaQueryWrapper<BdArea> queryWrapper);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
package com.hzs.system.base.service.impl;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
||||||
import com.hzs.common.domain.system.base.BdAreaNew;
|
|
||||||
import com.hzs.system.base.mapper.BdAreaNewMapper;
|
|
||||||
import com.hzs.system.base.service.IBdAreaNewService;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 服务实现类
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author hzs
|
|
||||||
* @since 2025-10-10
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
public class BdAreaNewServiceImpl extends ServiceImpl<BdAreaNewMapper, BdAreaNew> implements IBdAreaNewService {
|
|
||||||
|
|
||||||
}
|
|
|
@ -130,4 +130,9 @@ public class BdAreaServiceImpl extends ServiceImpl<BdAreaMapper, BdArea> impleme
|
||||||
return baseMapper.selectList(queryWrapper);
|
return baseMapper.selectList(queryWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<BdArea> selectList(LambdaQueryWrapper<BdArea> queryWrapper) {
|
||||||
|
return baseMapper.selectList(queryWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
<?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.hzs.system.base.mapper.BdAreaNewMapper">
|
|
||||||
|
|
||||||
</mapper>
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.hzs.common.core.enums;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 行政区划最后更新状态
|
||||||
|
*/
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Getter
|
||||||
|
public enum EMapStatus {
|
||||||
|
|
||||||
|
NEW(1,"新增"),
|
||||||
|
|
||||||
|
MOVED(2,"移动"),
|
||||||
|
|
||||||
|
DELETE(3,"删除"),
|
||||||
|
|
||||||
|
NORMAL(4,"正常");
|
||||||
|
|
||||||
|
private final Integer value;
|
||||||
|
|
||||||
|
private final String label;
|
||||||
|
}
|
|
@ -7,10 +7,14 @@ import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
|
||||||
import com.hzs.common.core.annotation.Excel;
|
import com.hzs.common.core.annotation.Excel;
|
||||||
import com.hzs.common.core.web.domain.BaseEntity;
|
import com.hzs.common.core.web.domain.BaseEntity;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 行政区划
|
* 行政区划
|
||||||
*/
|
*/
|
||||||
|
@ -60,5 +64,16 @@ public class BdArea extends BaseEntity {
|
||||||
*/
|
*/
|
||||||
@TableField("BIND_NUM")
|
@TableField("BIND_NUM")
|
||||||
private Integer bindNum;
|
private Integer bindNum;
|
||||||
|
/**
|
||||||
|
* 最后更新时间
|
||||||
|
*/
|
||||||
|
@TableField("LAST_SYNC_TIME")
|
||||||
|
private Date lastSyncTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新状态
|
||||||
|
*/
|
||||||
|
@TableField("SYNC_STATUS")
|
||||||
|
private Integer syncStatus;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,56 +0,0 @@
|
||||||
package com.hzs.common.domain.system.base;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.*;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import com.hzs.common.core.web.domain.BaseEntity;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
*
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author hzs
|
|
||||||
* @since 2025-10-10
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
@Accessors(chain = true)
|
|
||||||
@TableName("BD_AREA_NEW")
|
|
||||||
@KeySequence("BD_AREA_NEW_SEQ")
|
|
||||||
public class BdAreaNew extends BaseEntity {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
@TableField("PK_ID")
|
|
||||||
@TableId(type = IdType.INPUT)
|
|
||||||
private Integer pkId;
|
|
||||||
|
|
||||||
@TableField("NAME")
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@TableField("CODE")
|
|
||||||
private String code;
|
|
||||||
|
|
||||||
@TableField("PARENT")
|
|
||||||
private Long parent;
|
|
||||||
|
|
||||||
@TableField("ENABLE_STATE")
|
|
||||||
private Integer enableState;
|
|
||||||
|
|
||||||
@TableField("BIND_NUM")
|
|
||||||
private Integer bindNum;
|
|
||||||
|
|
||||||
@TableField("LAST_SYNC_TIME")
|
|
||||||
private Date lastSyncTime;
|
|
||||||
|
|
||||||
@TableField("SYNC_STATUS")
|
|
||||||
private String syncStatus;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -3,10 +3,9 @@ package com.hzs.third.job;
|
||||||
import cn.hutool.http.HttpUtil;
|
import cn.hutool.http.HttpUtil;
|
||||||
import cn.hutool.json.JSONObject;
|
import cn.hutool.json.JSONObject;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
|
||||||
import com.hzs.common.core.domain.R;
|
import com.hzs.common.core.domain.R;
|
||||||
import com.hzs.common.core.web.domain.AjaxResult;
|
import com.hzs.common.core.web.domain.AjaxResult;
|
||||||
import com.hzs.system.base.IBdAreaNewServiceApi;
|
import com.hzs.system.base.IAreaServiceApi;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.dubbo.config.annotation.DubboReference;
|
import org.apache.dubbo.config.annotation.DubboReference;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
@ -19,30 +18,30 @@ import java.util.*;
|
||||||
@RequestMapping("test-map")
|
@RequestMapping("test-map")
|
||||||
public class MapJob {
|
public class MapJob {
|
||||||
|
|
||||||
private static final String AK = "k5I8XpHFt78QaQ8GHclQ3wEN57XlvErC";
|
private static final String KEY = "fad2ab223b37747ef16c15ae3477b548";
|
||||||
|
|
||||||
private static final String API_URL = "https://api.map.baidu.com/api_region_search/v1/";
|
private static final String API_URL = "https://restapi.amap.com/v3/config/district?parameters";
|
||||||
|
|
||||||
@DubboReference(timeout = 60000)
|
@DubboReference(timeout = 600000)
|
||||||
IBdAreaNewServiceApi iBdAreaNewServiceApi;
|
IAreaServiceApi iAreaServiceApi;
|
||||||
|
|
||||||
@RequestMapping("map-job")
|
@RequestMapping("map-job")
|
||||||
public AjaxResult map() {
|
public AjaxResult map() {
|
||||||
|
|
||||||
Map<String, Object> params = new HashMap<>();
|
Map<String, Object> params = new HashMap<>();
|
||||||
params.put("ak", AK);
|
params.put("key", KEY);
|
||||||
params.put("keyword", "全国");
|
params.put("keywords", "中国");
|
||||||
params.put("extensions_code", "1");
|
params.put("extensions", "base");
|
||||||
params.put("sub_admin", "3");
|
params.put("subdistrict", "3");
|
||||||
|
|
||||||
String resultStr = HttpUtil.get(API_URL, params);
|
String resultStr = HttpUtil.get(API_URL, params);
|
||||||
JSONObject result = JSONUtil.parseObj(resultStr);
|
JSONObject result = JSONUtil.parseObj(resultStr);
|
||||||
if (result.getInt("status") != 0) {
|
if (result.getInt("status") != 1) {
|
||||||
log.error("百度地图API请求失败: {}", resultStr);
|
log.error("高德地图API请求失败: {}", resultStr);
|
||||||
return AjaxResult.error();
|
return AjaxResult.error();
|
||||||
}
|
}
|
||||||
// 对行政区划进行处理
|
// 对行政区划进行处理
|
||||||
R<?> R = iBdAreaNewServiceApi.upAreaDate(result);
|
R<?> R = iAreaServiceApi.upAreaDate(result);
|
||||||
if (R.isSuccess()) {
|
if (R.isSuccess()) {
|
||||||
return AjaxResult.success();
|
return AjaxResult.success();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue