😎增加天地图行政区划接口

This commit is contained in:
zuohuaijun 2024-09-10 17:18:01 +08:00
parent 6d63f25703
commit 1e8a41dbdd
6 changed files with 219 additions and 10 deletions

View File

@ -657,7 +657,6 @@ public class SysCodeGenService : IDynamicApiController, ITransient
/// <returns></returns>
private async Task AddMenu(List<SysMenu> menus, long pid)
{
var pPath = string.Empty;
// 若 pid=0 为顶级则创建菜单目录
if (pid == 0)
@ -702,7 +701,6 @@ public class SysCodeGenService : IDynamicApiController, ITransient
await _db.Insertable(menus).ExecuteCommandAsync();
}
/// <summary>
/// 获得菜单列表
/// </summary>
@ -757,7 +755,6 @@ public class SysCodeGenService : IDynamicApiController, ITransient
CreateTime = DateTime.Now
};
var menuPid = menuType.Id;
int menuOrder = 100;
// 按钮-page

View File

@ -100,10 +100,59 @@ public class TiandituInput
/// true返回轮廓数据
/// false不返回轮廓数据
/// </summary>
public bool Extensions { get; set; }
public bool Extensions { get; set; } = false;
/// <summary>
/// 密钥
/// </summary>
public string Tk { get; set; }
}
public class TiandituDto
{
public List<TiandituInfo> District { get; set; }
}
public class TiandituInfo
{
/// <summary>
/// 行政编码
/// </summary>
public string Gb { get; set; }
/// <summary>
/// 名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 中心点
/// </summary>
public CenterPoint Center { get; set; }
/// <summary>
/// 级别
/// </summary>
public int Level { get; set; }
/// <summary>
/// 子项
/// </summary>
public List<TiandituInfo> Children { get; set; }
}
/// <summary>
/// 中心点经纬度
/// </summary>
public class CenterPoint
{
/// <summary>
/// 经度
/// </summary>
public decimal Lng { get; set; }
/// <summary>
/// 维度
/// </summary>
public decimal Lat { get; set; }
}

View File

@ -328,6 +328,12 @@ public class SysRegionService : IDynamicApiController, ITransient
}
}
// 如果存在指定行政区划则删除
if (await _sysRegionRep.IsAnyAsync(u => u.Id == code))
{
await DeleteRegion(new DeleteRegionInput { Id = code });
}
await _sysRegionRep.AsDeleteable().ExecuteCommandAsync();
return await _sysRegionRep.AsInsertable(areaList).ExecuteCommandAsync();
}
@ -342,9 +348,61 @@ public class SysRegionService : IDynamicApiController, ITransient
// 接口说明及地址http://lbs.tianditu.gov.cn/server/administrative2.html
var url = $"http://api.tianditu.gov.cn/v2/administrative?keyword={input.Keyword}&childLevel={input.ChildLevel}&extensions={input.Extensions}&tk={input.Tk}";
var areaList = new List<SysRegion>();
var httpClient = new HttpClient();
var res = await httpClient.GetAsync<TiandituDto>(url);
if (res == null) return 0;
var parent = res.District[0];
var areaList = new List<SysRegion>()
{
new SysRegion
{
Id = Convert.ToInt64(parent.Gb),
Pid = 0,
Code = parent.Gb,
Name = parent.Name,
Level = parent.Level,
Longitude = parent.Center.Lng,
Latitude = parent.Center.Lat
}
};
foreach (var item in parent.Children)
{
var region = new SysRegion
{
Id = Convert.ToInt64(item.Gb),
Pid = Convert.ToInt64(parent.Gb),
Code = item.Gb,
Name = item.Name,
Level = item.Level,
Longitude = item.Center.Lng,
Latitude = item.Center.Lat
};
areaList.Add(region);
foreach (var child in item.Children)
{
areaList.Add(new SysRegion
{
Id = Convert.ToInt64(child.Gb),
Pid = region.Id,
Code = child.Gb,
Name = child.Name,
Level = child.Level,
Longitude = child.Center.Lng,
Latitude = child.Center.Lat
});
}
}
// 若存在指定行政区划则删除
if (await _sysRegionRep.IsAnyAsync(u => u.Name.Contains(input.Keyword) || u.Id.ToString() == input.Keyword))
{
var region = await _sysRegionRep.GetFirstAsync(u => u.Name.Contains(input.Keyword) || u.Id.ToString() == input.Keyword);
await DeleteRegion(new DeleteRegionInput { Id = region.Id });
}
await _sysRegionRep.AsDeleteable().ExecuteCommandAsync();
return await _sysRegionRep.AsInsertable(areaList).ExecuteCommandAsync();
}

View File

@ -42,7 +42,7 @@
"jsplumb": "^2.15.6",
"jwchat": "^2.0.3",
"lodash-es": "^4.17.21",
"md-editor-v3": "^4.20.0",
"md-editor-v3": "^4.20.1",
"mitt": "^3.0.1",
"monaco-editor": "^0.51.0",
"mqtt": "^4.3.8",
@ -65,7 +65,7 @@
"vue-demi": "0.14.6",
"vue-draggable-plus": "^0.5.3",
"vue-grid-layout": "3.0.0-beta1",
"vue-i18n": "^9.14.0",
"vue-i18n": "^10.0.0",
"vue-json-pretty": "^2.4.0",
"vue-plugin-hiprint": "0.0.57-beta30",
"vue-router": "^4.4.3",

View File

@ -0,0 +1,102 @@
<template>
<div class="sys-region-container">
<el-dialog v-model="state.isShowDialog" draggable overflow destroy-on-close width="500px">
<template #header>
<div style="color: #fff">
<el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle"> <ele-Edit /> </el-icon>
<span> {{ props.title }} </span>
</div>
</template>
<el-form :model="state.ruleForm" ref="ruleFormRef" label-width="auto" label-position="top">
<el-row :gutter="10">
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
<el-form-item label="区划名称或编码" prop="keyword" :rules="[{ required: true, message: '区划名称或编码不能为空', trigger: 'blur' }]">
<el-input v-model="state.ruleForm.keyword" placeholder="区划名称或编码" clearable />
</el-form-item>
</el-col>
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
<el-form-item label="下级行政区级数">
<el-select v-model="state.ruleForm.childLevel" placeholder="下级行政区级数" clearable>
<el-option value="0" label="不返回下级行政区" />
<el-option value="1" label="返回下一级行政区" />
<el-option value="2" label="返回下两级行政区" />
<el-option value="3" label="返回下三级行政区" />
</el-select>
</el-form-item>
</el-col>
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
<el-form-item label="密钥" prop="tk" :rules="[{ required: true, message: '密钥不能为空', trigger: 'blur' }]">
<el-input v-model="state.ruleForm.tk" placeholder="输入密钥" clearable />
</el-form-item>
</el-col>
</el-row>
</el-form>
<template #footer>
<span class="dialog-footer">
<a href="http://lbs.tianditu.gov.cn/server/administrative2.html" target="_blank" style="float: left">查看行政区划编码天地图</a>
<el-button @click="cancel"> </el-button>
<el-button type="primary" :loading="state.loading" @click="submit"> </el-button>
</span>
</template>
</el-dialog>
</div>
</template>
<script lang="ts" setup>
import { reactive, ref } from 'vue';
import { ElMessage, ElNotification } from 'element-plus';
import { getAPI } from '/@/utils/axios-utils';
import { SysRegionApi } from '/@/api-services/api';
const props = defineProps({
title: String,
});
const emits = defineEmits(['handleQuery']);
const ruleFormRef = ref();
const state = reactive({
loading: false,
ruleForm: {} as any,
isShowDialog: false,
});
//
const openDialog = () => {
ruleFormRef.value?.resetFields();
state.ruleForm.childLevel = '2';
state.isShowDialog = true;
};
//
const closeDialog = () => {
emits('handleQuery');
state.isShowDialog = false;
};
//
const cancel = () => {
state.isShowDialog = false;
};
//
const submit = () => {
ruleFormRef.value.validate(async (valid: boolean) => {
if (!valid) return;
ElNotification({
title: '提示',
message: '努力同步中...',
type: 'success',
position: 'bottom-right',
});
state.loading = true;
await getAPI(SysRegionApi).apiSysRegionSyncRegionTiandituPost(state.ruleForm);
closeDialog();
ElMessage.success('生成成功');
});
};
//
defineExpose({ openDialog });
</script>

View File

@ -44,7 +44,7 @@
<el-button type="danger" icon="ele-Lightning" @click="syncRegionStats" v-auth="'sysRegion/add'"> 同步国家统计局 </el-button>
<el-button type="danger" icon="ele-Lightning" @click="syncRegionMca" v-auth="'sysRegion/add'"> 同步国家地名信息库 </el-button>
<el-button type="danger" icon="ele-Lightning" @click="syncRegionTianditu" v-auth="'sysRegion/add'"> 同步天地图行政区划 </el-button>
<el-button type="danger" icon="ele-Lightning" @click="syncRegionTianditu" v-auth="'sysRegion/add'"> 同步天地图 </el-button>
</template>
<template #toolbar_tools> </template>
<template #empty>
@ -67,6 +67,7 @@
<EditRegion ref="editRegionRef" :title="state.title" @handleQuery="handleQuery" />
<SyncStatsParam ref="syncStatsParamRef" :title="state.title" @handleQuery="handleQuery" />
<SyncMcaParam ref="syncMcaParamRef" :title="state.title" @handleQuery="handleQuery" />
<SyncTdtParam ref="syncTdtParamRef" :title="state.title" @handleQuery="handleQuery" />
<GenOrgLevel ref="genOrgLevelRef" :title="state.title" @handleQuery="handleQuery" />
</div>
</template>
@ -84,6 +85,7 @@ import RegionTree from '/@/views/system/region/component/regionTree.vue';
import EditRegion from '/@/views/system/region/component/editRegion.vue';
import SyncStatsParam from '/@/views/system/region/component/syncStatsParam.vue';
import SyncMcaParam from '/@/views/system/region/component/syncMcaParam.vue';
import SyncTdtParam from '/@/views/system/region/component/syncTdtParam.vue';
import GenOrgLevel from '/@/views/system/region/component/genOrgLevel.vue';
import { getAPI } from '/@/utils/axios-utils';
@ -94,6 +96,7 @@ const xGrid = ref<VxeGridInstance>();
const editRegionRef = ref<InstanceType<typeof EditRegion>>();
const syncStatsParamRef = ref<InstanceType<typeof SyncStatsParam>>();
const syncMcaParamRef = ref<InstanceType<typeof SyncMcaParam>>();
const syncTdtParamRef = ref<InstanceType<typeof SyncTdtParam>>();
const genOrgLevelRef = ref<InstanceType<typeof GenOrgLevel>>();
const regionTreeRef = ref<InstanceType<typeof RegionTree>>();
const state = reactive({
@ -246,7 +249,7 @@ const syncRegionMca = async () => {
//
const syncRegionTianditu = async () => {
state.title = '同步天地图行政区划';
// syncTdtParamRef.value?.openDialog();
syncTdtParamRef.value?.openDialog();
};
//